Positions
The Positions contract implements the logic for Collateralized Debt Positions (CDPs), through which users can receive debt tokens against their deposited collateral.
The contract also contains the logic for initiating liquidations of CDPs and sending assets to the DEX router but external debt repayment logic goes through the Queue and Stability Pool contracts.
WARNING: Having more than 3-4 separate Positions will make it impossible to unstake in Staking & withdraw in the Stability Pool/Discount Vault, due to the gas cost of the accrual messages.
Notes:
Deposits take asset data directly from the message to ensure correctness.
Withdrawals are checked for validity (in the SubMsg reply) before state is permanently changed.
Supply caps only restrict users that are causing the overage
Adding collateral assets adds a queue for them in Liq Queue contract and a price feed for them in the Oracle contract
LP share supply caps are based on its ratio without double counting its assets, though its debt is counted towards its pool assets' caps.
Each credit_asset has a contract level liquidity multiplier calculated as the sum of all multipliers of basket's with the same credit_asset
Negative rates are turned off when total basket debt is above the desired debt utilization
Hardcoded interest rate cap of 100%
InstantiateMsg
Key | Type | Description |
---|---|---|
| String | Contract owner that defaults to info.sender |
| u64 | Limit in seconds that the oracle has before the values are invalid |
| Uint128 | Minimum value in debt per position |
| Decimal | Fee that goes to the protocol during liquidations |
| u64 | TWAP length in minutes |
| u64 | TWAP length in minutes |
| Decimal | Interest rate slope multiplier |
| Uint128 | Base debt cap multiplier |
| String | Stability Pool Contract |
| String | DEX Router Contract |
| String | MBRN staking contract |
| String | Oracle contract |
| String | Osmosis Proxy contract to use SDK modules |
| String | Auction Contract that sells protocol tokens to repay debt |
| String | Liquidity Check contract address |
| String | System Discounts contract address |
| CreateBasket | Struct to create the contract's basket |
* = optional
ExecuteMsg
UpdateConfig
UpdateConfig
Update Config by the current config.owner
Key | Type | Description |
---|---|---|
| String | Owner of contract |
| String | Stability Pool contract |
| String | Dex Router contract |
| String | Osmosis Proxy contract |
| String | Debt Auction contract |
| String | MBRN Staking contract |
| String | Oracle contract |
| String | Liquidity Check contract |
| String | System Discounts contract |
| Decimal | Liquidation fee |
| Uint128 | Debt minimum in terms of value |
| Uint128 | Debt Minimum Multiplier for a base debt cap |
| u64 | Oracle expiration time limit in seconds |
| u64 | TWAP length in minutes |
| u64 | TWAP length in minutes |
| Decimal | Multiplier for credit price difference to augment redemption price rate |
| Decimal | Multiplier for the 2nd slope in the interest rate formula |
* = optional
Deposit
Deposit
Deposits basket accepted collateral to a new or existing position.
Key | Type | Description |
---|---|---|
* | Uint128 | Position ID to deposit to. If none is passed, a new position is created. |
* | String | Owner of the position, defaults to info.sender |
* = optional
IncreaseDebt
IncreaseDebt
Increase debt of a position. Only callable by the position owner and limited by the position's max borrow LTV.
Key | Type | Description |
---|---|---|
| Uint128 | ID of position |
| Uint128 | Amount to increase debt by |
| Decimal | Increase debt to an LTV |
| String | Address to mint credit to |
* = optional
Withdraw
Withdraw
Withdraw assets from the caller's position as long as it leaves the position solvent in relation to the max borrow LTV
Key | Type | Description |
---|---|---|
| Uint128 | ID of position |
| Vec<Asset> | Assets to withdraw from the position |
| String | Address to send withdrawn assets to, defaults to sender |
Repay
Repay
Repay outstanding debt for a position, not exclusive to the position owner.
Key | Type | Description |
---|---|---|
| Uint128 | ID of Position |
| String | Owner of Position to repay |
| String | Address to send excess repayment assets to |
* = optional
Accrue
Accrue
Accrue interest for a Position. Allows external control of rate discounts, i.e. accrue before withdrawing capital that makes the user eligible for discounts.
Key | Type | Description |
---|---|---|
| String | Position owner |
| Vec<Uint128> | List of Position IDs |
* = optional
LiqRepay
LiqRepay
Repay function for Stability Pool liquidations. Used to repay insolvent positions and distribute liquidated funds.
Liquidate
Liquidate
Assert's the position is insolvent and calculates the distribution of repayment to the various liquidation modules. Does a bad debt check at the end of the procedure that starts a MBRN auction if necessary.
Key | Type | Description |
---|---|---|
| Uint128 | ID of Position |
| String | Owner of Position |
RedeemCollateral
RedeemCollateral
This function allows the redemption of the debt token for collateral assets within Positions that have opted in for redemption. The redemption process involves calculating the redeemable amount based on the credit amount, collateral premium, and collateral ratios. The collateral assets are then transferred to the sender's address, redeemed credit subtracted from the Position's debt and any excess credit is returned to the sender.
Choosing max_collateral_premium is based on what price the debt token was purchased. If purchased 4% below peg, then break-even starts at a 4% premium.
Key | Type | Description |
---|---|---|
| u128 | Max collateral premium you're willing to pay when redeeming debt tokens |
* = optional
EditRedeemability
EditRedeemability
This function allows for the flexible editing and enabling of debt token redemption for specific positions owned by an address, with options to modify redeemability, premiums, maximum loan repayment, and restricted collateral assets.
Key | Type | Description |
---|---|---|
| Vec<Uint128> | Positions to act on |
| bool | Toggle to add or remove redeemability |
| u128 | Desired premium for the Position's redeemable collateral |
| Decimal | Max % of the outstanding loan that can be used to redeem collateral |
| Vec<String> | Collateral assets restricted from redemption, swaps the full list. |
* = optional
MintRevenue
MintRevenue
Mint pending revenue from the contract's Basket, only usable by config
Key | Type | Description |
---|---|---|
| String | Address to send revenue to, |
| UserInfo | Position Info to repay for w/ revenue. To be used for BadDebt situations. |
| Uint128 | Amount to mint, defaults to all |
* = optional
EditBasket
EditBasket
Add cAsset, change owner and/or change credit_interest of an existing Basket.
Key | Type | Description |
---|---|---|
| cAsset | cAsset object to add to accepted basket objects |
| String | Liq Queue contract for the credit asset |
| Vec<PoolType> | Osmosis Pool IDs to query credit liquidity from |
| Vec<SupplyCap> | Collateral supply caps |
| Vec<MultiAssetSupplyCap> | Multi-asset collateral supply caps |
| Decimal | Base interest rate for collateral types |
| TWAPPoolInfo | Oracle information to store for credit price queries |
| bool | Toggle to allow negative repayment interest |
| Decimal | Margin of Error before the credit interest is effected by the TWAP price |
| bool | Freeze withdrawals & debt increases to fix bugs |
| bool | Toggle revenue to stakers |
* = optional
EditcAsset
EditcAsset
Edit a basket's cAsset
Key | Type | Description |
---|---|---|
asset | AssetInfo | Asset to edit |
| Decimal | Maximum borrowable LTV |
| Decimal | Point of Liquidation LTV |
* = optional
Callback
Callback
Messages usable only by the contract to enable functionality in line with message semantics
CallbackMsg
BadDebtCheck
BadDebtCheck
After liquidations, this checks for bad debt in the liquidated position.
Key | Type | Description |
---|---|---|
| Uint128 | ID of Position |
| Addr | Owner of Position |
QueryMsg
Config
Config
Returns Config
GetBasketRedeemability
GetBasketRedeemability
Returns redemption info for viable basket positions
Key | Type | Description |
---|---|---|
| String | Specific owner to query for |
| u128 | Premium to start after |
| u32 | Response limiter |
* = optional
GetBasketPositions
GetBasketPositions
Returns all positions in a basket with optional limits
Key | Type | Description |
---|---|---|
| String | User address to start after |
| u32 | Limit to # of users parsed through |
| UserInfo | Position info for a singe position |
| String | User address to query positions for |
* = optional
GetBasket
GetBasket
Returns Basket parameters
GetBasketDebtCaps
GetBasketDebtCaps
Returns a basket's debt caps per collateral asset, calculates on every call
GetBasketBadDebt
GetBasketBadDebt
Returns a basket's bad debt
GetCreditRate
GetCreditRate
Returns basket's redemption price interest and its sign
GetCollateralInterest
GetCollateralInterest
Get collateral interest rates from a Basket
Propagation
Propagation
Returns RepayPropagation.
Used internally to test state propagation.
Last updated