red-bank
The Red Bank exposes all interactions that are done between the user and the money market. It also holds all protocol liquidity.
Links
- Contract address:
osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg
- Testnet address:
osmo1t0dl6r27phqetfu0geaxrng0u9zn8qgrdwztapt5xr32adtwptaq6vwg36
- Contract repo: https://github.com/mars-protocol/outposts/tree/master/contracts/red-bank
- Audits: https://github.com/mars-protocol/mars-audits/tree/main/red-bank
InstantiateMsg
Instantiates the Red Bank contract.
Params | Type | Description |
---|---|---|
owner | String | Contract's owner |
emergency_owner | String | Contract's emergency owner |
config | CreateOrUpdateConfig | Market configuration |
CreateOrUpdateConfig
Params | Type | Description |
---|---|---|
address_provider | Option<String> | Address provider returns addresses for all protocol contracts |
close_factor | Option<Decimal> | Maximum percentage of outstanding debt that can be covered by a liquidator |
ExecuteMsg
update_owner
Manages owner state.
update_emergency_owner
Manages emergency owner state.
update_config
Updates the contract's config (only the owner of the contract can call)
Params | Type | Description |
---|---|---|
config | CreateOrUpdateConfig | Market configuration |
init_asset
Initializes an asset on the money market (only the owner of the contract can call)
Params | Type | Description |
---|---|---|
denom | String | Asset related info |
params | InitOrUpdateAssetParams | Asset parameters |
InitOrUpdateAssetParams
Params | Type | Description |
---|---|---|
initial_borrow_rate | Option<Decimal> | Initial borrow rate |
reserve_factor | Option<Decimal> | Portion of the borrow rate that is kept as protocol rewards |
max_loan_to_value | Option<Decimal> | Max base_denom that can be borrowed per uusd of collateral when using the asset as collateral |
liquidation_threshold | Option<Decimal> | uusd amount in debt position per uusd of asset collateral that if surpassed makes the user's position liquidatable |
liquidation_bonus | Option<Decimal> | Bonus amount of collateral liquidator get when repaying user's debt (Will get collateral from user in an amount equal to debt repayed + bonus) |
interest_rate_model | Option<InterestRateModel> | Interest rate strategy to calculate borrow_rate and liquidity_rate |
deposit_enabled | Option<bool> | If false cannot deposit |
borrow_enabled | Option<bool> | If false cannot borrow |
deposit_cap | Option<Uint128> | Deposit Cap defined in terms of the asset (Unlimited by default) |
InterestRateModel
Params | Type | Description |
---|---|---|
optimal_utilization_rate | Decimal | Optimal utilization rate |
base | Decimal | Base rate |
slope_1 | Decimal | Slope parameter for interest rate model function when utilization_rate < optimal_utilization_rate |
slope_2 | Decimal | Slope parameter for interest rate model function when utilization_rate >= optimal_utilization_rate |
update_asset
Update an asset on the money market (only owner can call)
Params | Type | Description |
---|---|---|
denom | String | Asset related info |
params | InitOrUpdateAssetParams | Asset parameters |
update_uncollateralized_loan_limit
Update uncollateralized loan limit for a given user and asset. Overrides previous value if any. A limit of zero means no uncollateralized limit and the debt in that asset needs to be collateralized (only owner can call).
Params | Type | Description |
---|---|---|
user | String | Address that receives the credit |
denom | String | Asset the user receives the credit in |
new_limit | Uint128 | Limit for the uncolateralize loan |
deposit
Deposits native coins. Deposited coins must be sent in the transaction this call is made.
Params | Type | Description |
---|---|---|
on_behalf_of | Option<String> | Address that will receive deposited tokens |
withdraw
Withdraws an amount of the asset burning an equivalent amount deposited tokens.
Params | Type | Description |
---|---|---|
denom | String | Asset to withdraw |
amount | Option<Uint128> | Amount to be withdrawn. If None is specified, the full amount will be withdrawn |
recipient | Option<String> | The address where the withdrawn amount is sent |
borrow
Borrows native coins. If borrow allowed, amount is added to caller's debt and sent to the address.
Params | Type | Description |
---|---|---|
denom | String | Asset to borrow |
amount | Option<Uint128> | Amount to borrow |
recipient | Option<String> | The address where the borrowed amount is sent |
repay
Repay native coins loan. Coins used to repay must be sent in the transaction this call is made.
Params | Type | Description |
---|---|---|
on_behalf_of | Option<String> | Repay the funds for the user |
liquidate
Liquidate under-collateralized native loans. Coins used to repay must be sent in the transaction this call is made. The liquidator will receive collateral shares. To get the underlying asset, consider sending a separate withdraw
execute message.
Params | Type | Description |
---|---|---|
user | String | The address of the borrower getting liquidated |
collateral_denom | String | Denom of the collateral asset, which liquidator gets from the borrower |
recipient | Option<String> | The address for receiving underlying collateral |
update_asset_collateral_status
Update (enable/disable) asset as collateral for the caller.
Params | Type | Description |
---|---|---|
denom | String | Asset to update status for |
enable | bool | Option to enable (true) / disable (false) asset as collateral |
QueryMsg
config
Get config.
ConfigResponse
Params | Type | Description |
---|---|---|
owner | Option<String> | The contract's owner |
proposed_new_owner | Option<String> | The contract's proposed owner |
emergency_owner | Option<String> | The contract's emergency owner |
proposed_new_emergency_owner | Option<String> | The contract's proposed emergency owner |
address_provider | String | Address provider returns addresses for all protocol contracts |
close_factor | Decimal | Maximum percentage of outstanding debt that can be covered by a liquidator |
market
Get asset market.
Market
(response)
Params | Type | Description |
---|---|---|
denom | String | Denom of the asset |
max_loan_to_value | Decimal | Max base asset that can be borrowed per "base asset" collateral when using the asset as collateral |
liquidation_threshold | Decimal | Base asset amount in debt position per "base asset" of asset collateral that if surpassed makes the user's position liquidatable |
liquidation_bonus | Decimal | Bonus amount of collateral liquidator get when repaying user's debt (Will get collateral from user in an amount equal to debt repayed + bonus) |
reserve_factor | Decimal | Portion of the borrow rate that is kept as protocol rewards |
interest_rate_model | InterestRateModel | model (params + internal state) that defines how interest rate behaves |
borrow_index | Decimal | Borrow index (Used to compute borrow interest) |
liquidity_index | Decimal | Liquidity index (Used to compute deposit interest) |
borrow_rate | Decimal | Rate charged to borrowers |
liquidity_rate | Decimal | Rate paid to depositors |
indexes_last_updated | u64 | Timestamp (seconds) where indexes and where last updated |
collateral_total_scaled | Uint128 | Total collateral scaled for the market's currency |
debt_total_scaled | Uint128 | Total debt scaled for the market's currency |
deposit_enabled | bool | If false cannot deposit |
borrow_enabled | bool | If false cannot borrow |
deposit_cap | Uint128 | Deposit Cap (defined in terms of the asset) |
markets
Enumerate markets with pagination.
Params | Type | Description |
---|---|---|
start_after | Option<String> | A market to start after |
limit | Option<u32> | The amount of markets to list |
Vec<crate::red_bank::Market>
markets
returns a vector of the Market
response struct defined above.
uncollateralized_loan_limit
Get uncollateralized limit for given user and asset.
Params | Type | Description |
---|---|---|
user | String | User address with uncollateralized loan |
denom | String | Asset denom |
UncollateralizedLoanLimitResponse
Params | Type | Description |
---|---|---|
denom | String | Asset denom |
limit | Uint128 | Limit for uncollateralized loan |
uncollateralized_loan_limits
Get all uncollateralized limits for a given user.
Params | Type | Description |
---|---|---|
user | String | User address with uncollateralized loans |
start_after | Option<String> | The amount of loans to list |
limit | Option<u32> | Limit for uncollateralized loan |
Vec<crate::red_bank::UncollateralizedLoanLimitResponse>
uncollateralized_loan_limits
returns a vector of the UncollateralizedLoanLimitResponse
struct defined above.
user_debt
Get user debt position for a specific asset.
Params | Type | Description |
---|---|---|
user | String | User address with debt |
denom | String | Asset denom |
UserDebtResponse
Params | Type | Description |
---|---|---|
denom | String | Asset denom |
amount_scaled | Uint128 | Scaled debt amount stored in contract state |
amount | Uint128 | Underlying asset amount that is actually owed at the current block |
uncollateralized | bool | Marker for uncollateralized debt |
user_debts
Get all debt positions for a user.
Params | Type | Description |
---|---|---|
user | String | User address with debt |
start_after | Option<String> | Position to start after |
limit | Option<u32> | The amount of positions to list |
Vec<crate::red_bank::UserDebtResponse>
user_debts
returns a vector of the UserDebtResponse
struct defined above.
user_collateral
Get user collateral position for a specific asset.
Params | Type | Description |
---|---|---|
user | String | User address with collateral |
denom | String | Denom of the asset |
UserCollateralResponse
Params | Type | Description |
---|---|---|
denom | String | Asset denom |
amount_scaled | Uint128 | Scaled collateral amount stored in contract state |
amount | Uint128 | Underlying asset amount that is actually deposited at the current block |
enabled | boold | Wether the user is using asset as collateral or not |
user_collaterals
Get all collateral positions for a user.
Params | Type | Description |
---|---|---|
user | String | User address with collateral |
start_after | Option<String> | Position to start after |
limit | Option<u32> | The amount of positions to list |
UserCollateralResponse
user_collaterals
returns a vector of the UserCollateralResponse
struct defined above.
user_position
Get user position.
Params | Type | Description |
---|---|---|
user | String | User address |
UserPositionResponse
Params | Type | Description |
---|---|---|
total_enabled_collateral | Uint128 | Total value of all enabled collateral assets. If an asset is disabled as collateral, it will not be included. |
total_collateralized_debt | Uint128 | Total value of all collateralized debts. If the user has an uncollateralized loan limit in an asset, the debt in this asset will not be included. |
weighted_max_ltv_collateral | Uint128 | |
weighted_liquidation_threshold_collateral | Uint128 | |
health_status | UserHealthStatus |
UserHealthStatus
Params when borrowing.
Params | Type | Description |
---|---|---|
max_ltv_hf | Decimal | |
liq_threshold_hf | Decimal |
scaled_liquidity_amount
Get liquidity scaled amount for a given underlying asset amount. (i.e: how much scaled collateral is added if the given amount is deposited).
Params | Type | Description |
---|---|---|
denom | String | Denom of the asset |
amount_scaled | Uint128 | Amount scaled by |
Returns Uint128
scaled_debt_amount
Get equivalent scaled debt for a given underlying asset amount. (i.e: how much scaled debt is added if the given amount is borrowed).
Params | Type | Description |
---|---|---|
denom | String | Denom of the asset |
amount | Uint128 | Amount scaled by |
Returns Uint128
underlying_liquidity_amount
Get underlying asset amount for a given asset and scaled amount. (i.e. How much underlying asset will be released if withdrawing by burning a given scaled collateral amount stored in state).
Params | Type | Description |
---|---|---|
denom | String | Denom of the asset |
amount_scaled | Uint128 | Amount scaled by |
Returns Uint128
underlying_debt_amount
Get underlying debt amount for a given asset and scaled amounts. (i.e: How much underlying asset needs to be repaid to cancel a given scaled debt amount stored in state).
Params | Type | Description |
---|---|---|
denom | String | Denom of the asset |
amount_scaled | Uint128 | Amount scaled by |
Returns Uint128