owned this note
owned this note
Published
Linked with GitHub
# Loan Messages
Here's a set of json parsed eventlogs
# SICXICX Price
### Eventlogs
##### PriceUpdated
{"price":"0.9952", "timestamp": "1111111.111"}
### Logic
On receiving a new SICXICX price, update to value to persistent storage.
Send a message to users on the publicly authenticated websocket.
### API
##### Get SICXICX Price
Gets the latest SICXICX price from persistent storage.
`GET /prices/SICXICX`
```
{"price":"0.9952", "timestamp": "1111111.111"}
```
### WS
```
method: sicxicx.price
{"price":"0.9952", "timestamp": "1111111.111"}
```
# Oracle Price
### Eventlogs
##### OraclePriceUpdated
{"price":"0.4023", "market":"ICXUSD", "timestamp": "111111.111"}
### Logic
On updating oracle price, write value to persistent storage.
On each updated price, send to the publicly authenticated socket endpoint.
### API
##### Get Market Oracle Price
Returns the most recent value of the oracle price for the queried market.
`GET /prices/{market}`
```
{"price":"0.9952", "timestamp": "1111111.111"}
```
### Get All Market Oracle Prices
Returns the most recent value of the oracle price for all markets.
`GET /prices`
```
[
{"market":"ICXUSD", "price":"0.9952", "timestamp": "1111111.111"},
{"market":"GLDUSD", "price":"0.9952", "timestamp": "1111111.111"}
]
```
### WS
```
method: oracle.price
{"market":"ICXUSD", "price":"0.9952", "timestamp": "1111111.111"}
```
# Loans
### Eventlogs
##### OriginateLoan
OriginateLoan(self, recipient: Address, symbol: str, amount: int, note: str)
##### LoanRepaid
LoanRepaid(self, account: Address, symbol: str, amount: int, note: str)
##### AssetRedeemed
AssetRedeemed(self, account: Address, symbol: str, amount: int, note: str)
##### Liquidate
Liquidate(self, account: Address, amount: int, note: str)
##### BadDebt
BadDebt(self, account: Address, symbol: str, amount: int, note: str)
##### CollateralDeposited
CollateralDeposited(address: Address, amount: int)
##### CollateralWithdrawn
CollateralWithdrawn(address: Address, amount: int)
##### FeePaid
FeePaid(address: Address, symbol: str, amount: int)
### Logic
##### On Collateral Deposited
On collateral deposited, find the user's `Collateral`
1. Create the user's collateral entry in the database if it does not exist
2. Increase by amount
3. Send a message over private socket (for that address) indicating that the transaction has occurred
##### On Collateral Withdrawn
On collateral withdrawn, find the user's `Collateral`
1. Locate the user's collateral entry in the database
2. Decrease by amount
3. Send a message over private socket (for that address) indicating that the transaction has occurred
#####
# Models
### Collateral
_each user has a single pool of collateral, used cross margin to back many loans, built from eventlogs_
Primary Key (address)
- Address (string)
- Amount (int)
- UnrealizedLosses (int)
### Loans
_each user has a loan for each asset they have borrowed, built from everntlogs_
Primary Key (address, asset)
- Address
- Asset
- Amount (int)
- UnrealizedRepayment (int)
### AssetLoans
_the sum of all loans across an asset, derived from sum(loans)_
Primary Key (asset)
- Asset (string)
- Amount (int)
- Repaid (int)