Skip to main content
logo

red-bank

The Red Bank exposes all interactions that are done between the user and the money market. It also holds all protocol liquidity.

InstantiateMsg

Instantiates the Red Bank contract.

json
msg.rs
Copy

_8
{
_8
"owner": "...",
_8
"emergency_owner": "...",
_8
"config": {
_8
"address_provider": "...",
_8
"close_factor": 0.123
_8
}
_8
}

ParamsTypeDescription
ownerStringContract's owner
emergency_ownerStringContract's emergency owner
configCreateOrUpdateConfigMarket configuration

CreateOrUpdateConfig

json
msg.rs
Copy

_4
{
_4
"address_provider": "...",
_4
"close_factor": 0.123
_4
}

ParamsTypeDescription
address_providerOption<String>Address provider returns addresses for all protocol contracts
close_factorOption<Decimal>Maximum percentage of outstanding debt that can be covered by a liquidator

ExecuteMsg

update_owner

Manages owner state.

json
address_provider.rs
Copy

_7
{
_7
"update_owner": {
_7
"propose_new_owner": {
_7
"proposed": "..."
_7
}
_7
}
_7
}

update_emergency_owner

Manages emergency owner state.

json
address_provider.rs
Copy

_7
{
_7
"update_emergency_owner": {
_7
"propose_new_owner": {
_7
"proposed": "..."
_7
}
_7
}
_7
}

update_config

Updates the contract's config (only the owner of the contract can call)

json
msg.rs
Copy

_8
{
_8
"update_config": {
_8
"config": {
_8
"address_provider": "...",
_8
"closer_factor": 0.123
_8
}
_8
}
_8
}

ParamsTypeDescription
configCreateOrUpdateConfigMarket configuration

init_asset

Initializes an asset on the money market (only the owner of the contract can call)

json
msg.rs
Copy

_20
{
_20
"init_asset": {
_20
"denom": "...",
_20
"params": {
_20
"initial_borrow_rate": 0.123,
_20
"reserve_factor": 0.123,
_20
"max_loan_to_value": 0.123,
_20
"liquidation_threshold": 0.123,
_20
"interest_rate_model": {
_20
"optimal_utilization_rate": 0.123,
_20
"base": 0.123,
_20
"slope_1": 0.123,
_20
"slope_2": 0.123
_20
},
_20
"desposit_enabled": true,
_20
"borrow_enabled": true,
_20
"deposit_cap": 123
_20
}
_20
}
_20
}

ParamsTypeDescription
denomStringAsset related info
paramsInitOrUpdateAssetParamsAsset parameters

InitOrUpdateAssetParams

json
msg.rs
Copy

_16
{
_16
"initial_borrow_rate": 0.123,
_16
"reserve_factor": 0.123,
_16
"max_loan_to_value": 0.123,
_16
"liquidation_treshold": 0.123,
_16
"liquidation_bonus": 0.123,
_16
"interest_rate_model": {
_16
"optimal_utilization_rate": 0.123,
_16
"base": 0.123,
_16
"slope_1": 0.123,
_16
"slope_2": 0.123
_16
},
_16
"desposit_enabled": true,
_16
"borrow_enabled": true,
_16
"deposit_cap": 123
_16
}

ParamsTypeDescription
initial_borrow_rateOption<Decimal>Initial borrow rate
reserve_factorOption<Decimal>Portion of the borrow rate that is kept as protocol rewards
max_loan_to_valueOption<Decimal>Max base_denom that can be borrowed per uusd of collateral when using the asset as collateral
liquidation_thresholdOption<Decimal>uusd amount in debt position per uusd of asset collateral that if surpassed makes the user's position liquidatable
liquidation_bonusOption<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_modelOption<InterestRateModel>Interest rate strategy to calculate borrow_rate and liquidity_rate
deposit_enabledOption<bool>If false cannot deposit
borrow_enabledOption<bool>If false cannot borrow
deposit_capOption<Uint128>Deposit Cap defined in terms of the asset (Unlimited by default)

InterestRateModel

json
interest_rate_model.rs
Copy

_6
{
_6
"optimal_utilization_rate": 0.123,
_6
"base": 0.123,
_6
"slope_1": 0.123,
_6
"slope_2": 0.123
_6
}

ParamsTypeDescription
optimal_utilization_rateDecimalOptimal utilization rate
baseDecimalBase rate
slope_1DecimalSlope parameter for interest rate model function when utilization_rate < optimal_utilization_rate
slope_2DecimalSlope 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)

json
msg.rs
Copy

_20
{
_20
"update_asset": {
_20
"denom": "...",
_20
"params": {
_20
"initial_borrow_rate": 0.123,
_20
"reserve_factor": 0.123,
_20
"max_loan_to_value": 0.123,
_20
"liquidation_threshold": 0.123,
_20
"interest_rate_model": {
_20
"optimal_utilization_rate": 0.123,
_20
"base": 0.123,
_20
"slope_1": 0.123,
_20
"slope_2": 0.123
_20
},
_20
"desposit_enabled": true,
_20
"borrow_enabled": true,
_20
"deposit_cap": 123
_20
}
_20
}
_20
}

ParamsTypeDescription
denomStringAsset related info
paramsInitOrUpdateAssetParamsAsset 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).

json
msg.rs
Copy

_7
{
_7
"update_uncollateralized_loan_limit": {
_7
"user": "...",
_7
"denom": "...",
_7
"new_limit": 123
_7
}
_7
}

ParamsTypeDescription
userStringAddress that receives the credit
denomStringAsset the user receives the credit in
new_limitUint128Limit for the uncolateralize loan

deposit

Deposits native coins. Deposited coins must be sent in the transaction this call is made.

json
msg.rs
Copy

_5
{
_5
"deposit": {
_5
"on_behalf_of": "..."
_5
}
_5
}

ParamsTypeDescription
on_behalf_ofOption<String>Address that will receive deposited tokens

withdraw

Withdraws an amount of the asset burning an equivalent amount deposited tokens.

json
msg.rs
Copy

_7
{
_7
"withdraw": {
_7
"denom": "...",
_7
"amount": 123,
_7
"recipient": "..."
_7
}
_7
}

ParamsTypeDescription
denomStringAsset to withdraw
amountOption<Uint128>Amount to be withdrawn. If None is specified, the full amount will be withdrawn
recipientOption<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.

json
msg.rs
Copy

_7
{
_7
"borrow": {
_7
"denom": "...",
_7
"amount": 123,
_7
"recipient" "mars..."
_7
}
_7
}

ParamsTypeDescription
denomStringAsset to borrow
amountOption<Uint128>Amount to borrow
recipientOption<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.

json
msg.rs
Copy

_5
{
_5
"repay": {
_5
"on_behalf_of": "..."
_5
}
_5
}

ParamsTypeDescription
on_behalf_ofOption<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.

json
msg.rs
Copy

_7
{
_7
"liquidate": {
_7
"user": "mars...",
_7
"collateral_denom": "...",
_7
"recipient": "..."
_7
}
_7
}

ParamsTypeDescription
userStringThe address of the borrower getting liquidated
collateral_denomStringDenom of the collateral asset, which liquidator gets from the borrower
recipientOption<String>The address for receiving underlying collateral

update_asset_collateral_status

Update (enable/disable) asset as collateral for the caller.

json
msg.rs
Copy

_6
{
_6
"update_asset_collateral_status": {
_6
"denom": "...",
_6
"enable": true
_6
}
_6
}

ParamsTypeDescription
denomStringAsset to update status for
enableboolOption to enable (true) / disable (false) asset as collateral

QueryMsg

config

Get config.

json
msg.rs
Copy

_3
{
_3
"config": {}
_3
}

ConfigResponse

json
types.rs
Copy

_8
{
_8
"owner": "...",
_8
"proposed_new_owner": "...",
_8
"emergency_owner": "...",
_8
"proposed_new_emergency_owner": "...",
_8
"address_provider": "...",
_8
"close_factor": 0.123
_8
}

ParamsTypeDescription
ownerOption<String>The contract's owner
proposed_new_ownerOption<String>The contract's proposed owner
emergency_ownerOption<String>The contract's emergency owner
proposed_new_emergency_ownerOption<String>The contract's proposed emergency owner
address_providerStringAddress provider returns addresses for all protocol contracts
close_factorDecimalMaximum percentage of outstanding debt that can be covered by a liquidator

market

Get asset market.

json
msg.rs
Copy

_5
{
_5
"market": {
_5
"denom": "..."
_5
}
_5
}

Market (response)

json
market.rs
Copy

_23
{
_23
"denom": "...",
_23
"max_loan_to_value": 0.123,
_23
"liquidation_threshold": 0.123,
_23
"liquidation_bonus": 0.123,
_23
"reserve_factor": 0.123,
_23
"interest_rate_model": {
_23
"optimal_utilization_rate": 0.123,
_23
"base": 0.123,
_23
"slope_1": 0.123,
_23
"slope_2": 0.123
_23
},
_23
"borrow_index": 0.123,
_23
"liquidity_index": 0.123,
_23
"borrow_rate": 0.123,
_23
"liquidity_rate": 0.123,
_23
"indexes_last_updated": 123,
_23
"collateral_total_scaled": 123,
_23
"debt_total_scaled": 123,
_23
"deposit_enabled": true,
_23
"borrow_enabled": true,
_23
"deposit_cap": 123456
_23
}

ParamsTypeDescription
denomStringDenom of the asset
max_loan_to_valueDecimalMax base asset that can be borrowed per "base asset" collateral when using the asset as collateral
liquidation_thresholdDecimalBase asset amount in debt position per "base asset" of asset collateral that if surpassed makes the user's position liquidatable
liquidation_bonusDecimalBonus amount of collateral liquidator get when repaying user's debt (Will get collateral from user in an amount equal to debt repayed + bonus)
reserve_factorDecimalPortion of the borrow rate that is kept as protocol rewards
interest_rate_modelInterestRateModelmodel (params + internal state) that defines how interest rate behaves
borrow_indexDecimalBorrow index (Used to compute borrow interest)
liquidity_indexDecimalLiquidity index (Used to compute deposit interest)
borrow_rateDecimalRate charged to borrowers
liquidity_rateDecimalRate paid to depositors
indexes_last_updatedu64Timestamp (seconds) where indexes and where last updated
collateral_total_scaledUint128Total collateral scaled for the market's currency
debt_total_scaledUint128Total debt scaled for the market's currency
deposit_enabledboolIf false cannot deposit
borrow_enabledboolIf false cannot borrow
deposit_capUint128Deposit Cap (defined in terms of the asset)

markets

Enumerate markets with pagination.

json
msg.rs
Copy

_6
{
_6
"markets": {
_6
"start_after": "...",
_6
"limit": 10
_6
}
_6
}

ParamsTypeDescription
start_afterOption<String>A market to start after
limitOption<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.

json
msg.rs
Copy

_6
{
_6
"uncollateralized_loan_limit": {
_6
"user": "mars...",
_6
"denom": "..."
_6
}
_6
}

ParamsTypeDescription
userStringUser address with uncollateralized loan
denomStringAsset denom

UncollateralizedLoanLimitResponse

json
types.rs
Copy

_4
{
_4
"denom": "...",
_4
"limit": 123
_4
}

ParamsTypeDescription
denomStringAsset denom
limitUint128Limit for uncollateralized loan

uncollateralized_loan_limits

Get all uncollateralized limits for a given user.

json
msg.rs
Copy

_7
{
_7
"uncollateralized_loan_limits": {
_7
"user": "mars...",
_7
"start_after": "...",
_7
"limit": 123
_7
}
_7
}

ParamsTypeDescription
userStringUser address with uncollateralized loans
start_afterOption<String>The amount of loans to list
limitOption<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.

json
msg.rs
Copy

_6
{
_6
"user_debt": {
_6
"user": "mars...",
_6
"denom": "..."
_6
}
_6
}

ParamsTypeDescription
userStringUser address with debt
denomStringAsset denom

UserDebtResponse

json
types.rs
Copy

_6
{
_6
"denom": "...",
_6
"amount_scaled": 123,
_6
"amount": 123,
_6
"uncollateralized": false
_6
}

ParamsTypeDescription
denomStringAsset denom
amount_scaledUint128Scaled debt amount stored in contract state
amountUint128Underlying asset amount that is actually owed at the current block
uncollateralizedboolMarker for uncollateralized debt

user_debts

Get all debt positions for a user.

json
msg.rs
Copy

_7
{
_7
"user_debts": {
_7
"user": "...",
_7
"start_after": "...",
_7
"limit": 123
_7
}
_7
}

ParamsTypeDescription
userStringUser address with debt
start_afterOption<String>Position to start after
limitOption<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.

json
msg.rs
Copy

_6
{
_6
"user_collateral": {
_6
"user": "mars...",
_6
"denom": "..."
_6
}
_6
}

ParamsTypeDescription
userStringUser address with collateral
denomStringDenom of the asset

UserCollateralResponse

json
types.rs
Copy

_6
{
_6
"denom": "...",
_6
"amount_scaled": 123,
_6
"amount": 123,
_6
"enabled": true
_6
}

ParamsTypeDescription
denomStringAsset denom
amount_scaledUint128Scaled collateral amount stored in contract state
amountUint128Underlying asset amount that is actually deposited at the current block
enabledbooldWether the user is using asset as collateral or not

user_collaterals

Get all collateral positions for a user.

json
msg.rs
Copy

_7
{
_7
"user_collaterals": {
_7
"user": "...",
_7
"start_after": "...",
_7
"limit": 123
_7
}
_7
}

ParamsTypeDescription
userStringUser address with collateral
start_afterOption<String>Position to start after
limitOption<u32>The amount of positions to list

UserCollateralResponse

user_collaterals returns a vector of the UserCollateralResponse struct defined above.

user_position

Get user position.

json
msg.rs
Copy

_5
{
_5
"user_position": {
_5
"user": "mars..."
_5
}
_5
}

ParamsTypeDescription
userStringUser address

UserPositionResponse

json
types.rs
Copy

_11
{
_11
_11
"total_enabled_collateral": "123",
_11
"total_collateralized_debt": "123",
_11
"weighted_max_ltv_collateral": "123",
_11
"weighted_liquidation_threshold_collateral": "123",
_11
"health_status": {
_11
"max_ltv_hf": 0.123,
_11
"liq_threshold_hf": 0.123
_11
}
_11
}

ParamsTypeDescription
total_enabled_collateralUint128Total value of all enabled collateral assets. If an asset is disabled as collateral, it will not be included.
total_collateralized_debtUint128Total 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_collateralUint128
weighted_liquidation_threshold_collateralUint128
health_statusUserHealthStatus

UserHealthStatus

json
types.rs
Copy

_9
{
_9
"user_health_status": {
_9
"not_borrowing": {},
_9
"borrowing": {
_9
"max_ltv_hf": 0.123,
_9
"liq_threshold_hf": 0.123
_9
}
_9
}
_9
}

Params when borrowing.

ParamsTypeDescription
max_ltv_hfDecimal
liq_threshold_hfDecimal

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).

json
msg.rs
Copy

_6
{
_6
"scaled_liquidity_amount": {
_6
"denom": "...",
_6
"amount_scaled": 123
_6
}
_6
}

ParamsTypeDescription
denomStringDenom of the asset
amount_scaledUint128Amount 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).

json
msg.rs
Copy

_6
{
_6
"scaled_debt_amount": {
_6
"denom": "...",
_6
"amount": 123
_6
}
_6
}

ParamsTypeDescription
denomStringDenom of the asset
amountUint128Amount 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).

json
msg.rs
Copy

_6
{
_6
"underlying_liquidity_amount": {
_6
"denom": "...",
_6
"amount_scaled": 123
_6
}
_6
}

ParamsTypeDescription
denomStringDenom of the asset
amount_scaledUint128Amount 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).

json
msg.rs
Copy

_6
{
_6
"underlying_debt_amount": {
_6
"denom": "...",
_6
"amount_scaled": 123
_6
}
_6
}

ParamsTypeDescription
denomStringDenom of the asset
amount_scaledUint128Amount scaled by

Returns Uint128