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
#[cw_serde]
pub struct InstantiateMsg {
pub owner: Option<String>,
pub oracle_time_limit: u64,
pub debt_minimum: Uint128,
pub liq_fee: Decimal,
pub collateral_twap_timeframe: u64,
pub credit_twap_timeframe: u64,
//Contracts
pub stability_pool: Option<String>,
pub dex_router: Option<String>,
pub staking_contract: Option<String>,
pub oracle_contract: Option<String>,
pub osmosis_proxy: Option<String>,
pub debt_auction: Option<String>,
pub liquidity_contract: Option<String>,
pub discounts_contract: Option<String>,
/// Basket Creation struct
pub create_basket: CreateBasket,
}
#[cw_serde]
pub struct CreateBasket {
/// Basket ID
pub basket_id: Uint128,
/// Collateral asset types.
/// Note: Also used to tally asset amounts for ease of calculation of Basket ratios
pub collateral_types: Vec<cAsset>,
/// Creates native denom for credit_asset
pub credit_asset: Asset,
/// Credit redemption price
pub credit_price: Decimal,
/// Base collateral interest rate.
/// Used to calculate the interest rate for each collateral type.
pub base_interest_rate: Option<Decimal>,
/// To measure liquidity for the credit asset
pub credit_pool_infos: Vec<PoolType>,
/// Liquidation queue for collateral assets
pub liq_queue: Option<String>,
}*owner
String
Contract owner that defaults to info.sender
oracle_time_limit
u64
Limit in seconds that the oracle has before the values are invalid
debt_minimum
Uint128
Minimum value in debt per position
liq_fee
Decimal
Fee that goes to the protocol during liquidations
collateral_twap_timeframe
u64
TWAP length in minutes
credit_twap_timeframe
u64
TWAP length in minutes
rate_slope_multiplier
Decimal
Interest rate slope multiplier
base_debt_cap_multiplier
Uint128
Base debt cap multiplier
*stability_pool
String
Stability Pool Contract
*dex_router
String
DEX Router Contract
*staking_contract
String
MBRN staking contract
*oracle_contract
String
Oracle contract
*osmosis_proxy
String
Osmosis Proxy contract to use SDK modules
*debt_auction
String
Auction Contract that sells protocol tokens to repay debt
*liquidity_contract
String
Liquidity Check contract address
*discounts_contract
String
System Discounts contract address
create_basket
CreateBasket
Struct to create the contract's basket
* = optional
ExecuteMsg
UpdateConfig
UpdateConfigUpdate Config by the current config.owner
*owner
String
Owner of contract
*stability_pool
String
Stability Pool contract
*dex_router
String
Dex Router contract
*osmosis_proxy
String
Osmosis Proxy contract
*debt_auction
String
Debt Auction contract
*staking_contract
String
MBRN Staking contract
*oracle_contract
String
Oracle contract
*liquidity_contract
String
Liquidity Check contract
*discounts_contract
String
System Discounts contract
*liq_fee
Decimal
Liquidation fee
*debt_minimum
Uint128
Debt minimum in terms of value
*base_debt_cap_multiplier
Uint128
Debt Minimum Multiplier for a base debt cap
*oracle_time_limit
u64
Oracle expiration time limit in seconds
*collateral_twap_timeframe
u64
TWAP length in minutes
*credit_twap_timeframe
u64
TWAP length in minutes
*cpc_multiplier
Decimal
Multiplier for credit price difference to augment redemption price rate
*rate_slope_multiplier
Decimal
Multiplier for the 2nd slope in the interest rate formula
* = optional
Deposit
DepositDeposits basket accepted collateral to a new or existing position.
*position_id
Uint128
Position ID to deposit to. If none is passed, a new position is created.
*position_owner
String
Owner of the position, defaults to info.sender
* = optional
IncreaseDebt
IncreaseDebtIncrease debt of a position. Only callable by the position owner and limited by the position's max borrow LTV.
position_id
Uint128
ID of position
amount
Uint128
Amount to increase debt by
*LTV
Decimal
Increase debt to an LTV
*mint_to_addr
String
Address to mint credit to
* = optional
Withdraw
WithdrawWithdraw assets from the caller's position as long as it leaves the position solvent in relation to the max borrow LTV
position_id
Uint128
ID of position
assets
Vec<Asset>
Assets to withdraw from the position
*send_to
String
Address to send withdrawn assets to, defaults to sender
Repay
RepayRepay outstanding debt for a position, not exclusive to the position owner.
position_id
Uint128
ID of Position
*position_owner
String
Owner of Position to repay
*send_excess_to
String
Address to send excess repayment assets to
* = optional
Accrue
AccrueAccrue interest for a Position. Allows external control of rate discounts, i.e. accrue before withdrawing capital that makes the user eligible for discounts.
*position_owner
String
Position owner
position_ids
Vec<Uint128>
List of Position IDs
* = optional
LiqRepay
LiqRepayRepay function for Stability Pool liquidations. Used to repay insolvent positions and distribute liquidated funds.
Liquidate
LiquidateAssert'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.
position_id
Uint128
ID of Position
position_owner
String
Owner of Position
RedeemCollateral
RedeemCollateralThis 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.
*max_collateral_premium
u128
Max collateral premium you're willing to pay when redeeming debt tokens
* = optional
EditRedeemability
EditRedeemabilityThis 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.
position_ids
Vec<Uint128>
Positions to act on
*redeemable
bool
Toggle to add or remove redeemability
*premium
u128
Desired premium for the Position's redeemable collateral
*max_loan_repayment
Decimal
Max % of the outstanding loan that can be used to redeem collateral
*restricted_collateral_assets
Vec<String>
Collateral assets restricted from redemption, swaps the full list.
* = optional
MintRevenue
MintRevenueMint pending revenue from the contract's Basket, only usable by config
*send_to
String
Address to send revenue to,
*repay_for
UserInfo
Position Info to repay for w/ revenue. To be used for BadDebt situations.
*amount
Uint128
Amount to mint, defaults to all
* = optional
EditBasket
EditBasketAdd cAsset, change owner and/or change credit_interest of an existing Basket.
*added_cAsset
cAsset
cAsset object to add to accepted basket objects
*liq_queue
String
Liq Queue contract for the credit asset
*credit_pool_ids
Vec<PoolType>
Osmosis Pool IDs to query credit liquidity from
*collateral_supply_caps
Vec<SupplyCap>
Collateral supply caps
*multi_asset_supply_caps
Vec<MultiAssetSupplyCap>
Multi-asset collateral supply caps
*base_interest_rate
Decimal
Base interest rate for collateral types
*credit_asset_twap_price_source
TWAPPoolInfo
Oracle information to store for credit price queries
*negative_rates
bool
Toggle to allow negative repayment interest
*cpc_margin_of_error
Decimal
Margin of Error before the credit interest is effected by the TWAP price
*frozen
bool
Freeze withdrawals & debt increases to fix bugs
*rev_to_stakers
bool
Toggle revenue to stakers
* = optional
EditcAsset
EditcAssetEdit a basket's cAsset
asset
AssetInfo
Asset to edit
*max_borrow_LTV
Decimal
Maximum borrowable LTV
*max_LTV
Decimal
Point of Liquidation LTV
* = optional
Callback
CallbackMessages usable only by the contract to enable functionality in line with message semantics
CallbackMsg
BadDebtCheck
BadDebtCheckAfter liquidations, this checks for bad debt in the liquidated position.
position_id
Uint128
ID of Position
position_owner
Addr
Owner of Position
QueryMsg
Config
ConfigReturns Config
GetBasketRedeemability
GetBasketRedeemabilityReturns redemption info for viable basket positions
*position_owner
String
Specific owner to query for
*start_after
u128
Premium to start after
*limit
u32
Response limiter
* = optional
GetBasketPositions
GetBasketPositionsReturns all positions in a basket with optional limits
*start_after
String
User address to start after
*limit
u32
Limit to # of users parsed through
*user_info
UserInfo
Position info for a singe position
*user
String
User address to query positions for
* = optional
GetBasket
GetBasketReturns Basket parameters
GetBasketDebtCaps
GetBasketDebtCapsReturns a basket's debt caps per collateral asset, calculates on every call
GetBasketBadDebt
GetBasketBadDebtReturns a basket's bad debt
GetCreditRate
GetCreditRateReturns basket's redemption price interest and its sign
GetCollateralInterest
GetCollateralInterestGet collateral interest rates from a Basket
Propagation
PropagationReturns RepayPropagation.Used internally to test state propagation.
Last updated