Mars Protocol
Search…
πŸ’±
Red Bank
The Red Bank contract exposes all interactions that are done between the user and the money market. It also holds all protocol liquidity.

Links

Config

Key
Type
Description
owner
CanonicalAddr
Contract owner
address_provider_address
CanonicalAddr
Address provider returns addresses for all protocol contracts
ma_token_code_id
u64
maToken code id used to instantiate new tokens
close_factor
Decimal
Maximum percentage of outstanding debt that can be covered by a liquidator

InstantiateMsg

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct InstantiateMsg {
3
pub config: CreateOrUpdateConfig
4
}
Copied!
1
{
2
"config": {
3
"owner": "terra...",
4
"address_provider_address": "terra...",
5
"ma_token_code_id": 123,
6
"close_factor": 0.01
7
}
8
}
Copied!

CreateOrUpdateConfig

1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct CreateOrUpdateConfig {
3
pub owner: Option<String>,
4
pub address_provider_address: Option<String>,
5
pub ma_token_code_id: Option<u64>,
6
pub close_factor: Option<Decimal>
7
}
Copied!
Key
Type
Description
owner*
String
Contract owner
address_provider_address*
String
Address provider returns addresses for all protocol contracts
ma_token_code_id*
u64
maToken code id used to instantiate new tokens
close_factor*
Decimal
Maximum percentage of outstanding debt that can be covered by a liquidator
* = optional

ExecuteMsg

UpdateConfig

Update contract config (only owner can call).
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
UpdateConfig {
6
config: CreateOrUpdateConfig
7
}
8
}
Copied!
1
{
2
"update_config": {
3
"config": {
4
"owner": "terra...",
5
"address_provider_address": "terra...",
6
"ma_token_code_id": 123,
7
"close_factor": 0.01
8
}
9
}
10
}
Copied!

Receive

Implementation of cw20 receive msg.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
Receive(Cw20ReceiveMsg)
6
}
Copied!
1
{
2
"receive":
3
}
Copied!

InitAsset

Initialize an asset on the money market (only owner can call).
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
InitAsset {
6
asset: Asset,
7
asset_params: InitOrUpdateAssetParams,
8
asset_symbol: Option<String>
9
}
10
}
Copied!
1
{
2
"init_asset": {
3
"asset": "terra...",
4
"asset_params": {
5
"initial_borrow_rate": 0.01,
6
"reserve_factor": 0.01,
7
"max_loan_to_value": 0.01,
8
"liquidation_threshold": 0.01,
9
"liquidation_bonus": 0.01,
10
"interest_rate_model_params": {},
11
"active": true,
12
"deposit_enabled": true,
13
"borrow_enabled": true
14
},
15
"asset_symbol": "optional_string"
16
}
17
}
Copied!
Key
Type
Description
asset
String
Asset related info
asset_params
InitOrUpdateAssetParams
Asset parameters
asset_symbol
String
Asset symbol to be used in maToken name and description. If none is provided denom will be used for native and token symbol will be used for cw20

InitOrUpdateAssetParams

1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct InitOrUpdateAssetParams {
3
pub initial_borrow_rate: Option<Decimal>,
4
pub reserve_factor: Option<Decimal>,
5
pub max_loan_to_value: Option<Decimal>,
6
pub liquidation_threshold: Option<Decimal>,
7
pub liquidation_bonus: Option<Decimal>,
8
pub interest_rate_model_params: Option<InterestRateModelParams>,
9
pub active: Option<bool>,
10
pub deposit_enabled: Option<bool>,
11
pub borrow_enabled: Option<bool>
12
}
Copied!
Key
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 uusd 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_params*
Option<InterestRateModelParams>
Interest rate strategy to calculate borrow_rate and liquidity_rate
active*
Option<bool>
If false cannot do any action (deposit/withdraw/borrow/repay/liquidate)
deposit_enabled*
Option<bool>
If false cannot deposit
borrow_enabled*
Option<bool>
If false cannot borrow
* = optional

InitAssetTokenCallback

Callback sent from maToken contract after instantiated.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
InitAssetTokenCallback {
6
reference: Vec<u8>
7
}
8
}
Copied!
1
{
2
"init_asset_token_callback": {
3
"reference": [
4
[123],
5
[123]
6
]
7
}
8
}
Copied!
Key
Type
Description
reference
Vec<u8>
Either the denom for a terra native asset or address for a cw20 token in bytes

UpdateAsset

Update an asset on the money market (only owner can call).
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
UpdateAsset {
6
asset: Asset,
7
asset_params: InitOrUpdateAssetParams
8
}
9
}
Copied!
1
{
2
"update_asset": {
3
"asset": "terra...",
4
"asset_params": {
5
"initial_borrow_rate": 0.01,
6
"reserve_factor": 0.01,
7
"max_loan_to_value": 0.01,
8
"liquidation_threshold": 0.01,
9
"liquidation_bonus": 0.01,
10
"interest_rate_model_params": {},
11
"active": true,
12
"deposit_enabled": true,
13
"borrow_enabled": true
14
}
15
}
16
}
Copied!
Key
Type
Description
asset
String
Asset related info
asset_params
InitOrUpdateAssetParams
Asset parameters

UpdateUncollateralizedLoanLimit

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 the owner can call).
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
UpdateUncollateralizedLoanLimit {
6
user_address: String,
7
asset: Asset,
8
new_limit: Uint128
9
}
10
}
Copied!
1
{
2
"update_uncollateralized_loan_limit": {
3
"user_address": "terra...",
4
"asset": "terra...",
5
"new_limit": 123
6
}
7
}
Copied!
Key
Type
Text
user_address
String
Address that receives the credit
asset
String
Asset the user receives the credit in
new_limit
Uint128
Limit for the uncolateralize loan

DepositNative

Deposit Terra native coins.
​
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
DepositNative {
6
denom: String,
7
on_behalf_of: Option<String>
8
}
9
}
Copied!
1
{
2
"deposit_native": {
3
"denom": "uusd",
4
"on_behalf_of": "terra..."
5
}
6
}
Copied!
Key
Type
Description
denom
String
Denom used in Terra (e.g: uluna, uusd)
on_behalf_of*
String
Address that will receive the maTokens
* = optional

Withdraw

Withdraw an amount of the asset burning an equivalent amount of maTokens. If asset is a Terra native token, the amount sent to the user is selected so that the sum of the transfered amount plus the stability tax payed is equal to the withdrawn amount.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
Withdraw {
6
asset: Asset,
7
amount: Option<Uint128>,
8
recipient: Option<String>
9
}
10
}
Copied!
1
{
2
"withdraw": {
3
"asset": {
4
"native": {
5
"denom": "uusd"
6
}
7
},
8
"amount": "10000",
9
"recipient": "terra..."
10
}
11
}
Copied!
Key
Type
Description
asset
String
Asset to withdraw
amount*
Uint128
Amount to be withdrawn. If None is specified, the full maToken balance will be burned in exchange for the equivalent asset amount.
recipient*
String
The address where the withdrawn amount is sent
* = optional

Borrow

Borrow Terra native coins. If borrow allowed, amount is added to caller's debt and sent to the address. If asset is a Terra native token, the amount sent is selected so that the sum of the transfered amount plus the stability tax payed is equal to the borrowed amount.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
Borrow {
6
asset: Asset,
7
amount: Uint128,
8
recipient: Option<String>
9
}
10
}
Copied!
1
{
2
"borrow": {
3
"asset": {
4
"native": {
5
"denom": "uluna"
6
}
7
},
8
"amount": "1000",
9
"recipient": "terra..."
10
}
11
}
Copied!
Key
Type
Description
asset
String
Asset to borrow
amount
Uint128
Amount to borrow
recipient*
String
The address where the borrowed amount is sent
* = optional

RepayNative

Repay Terra native coins loan. Coins used to repay must be sent in the transaction this call is made.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
RepayNative {
6
denom: String,
7
on_behalf_of: Option<String>
8
}
9
}
Copied!
1
{
2
"repay_native": {
3
"denom": "uusd",
4
"on_behalf_of": "terra..."
5
}
6
}
Copied!
Key
Type
Description
denom
String
Denom used in Terra (e.g: uluna, uusd)
on_behalf_of*
String
Repay the funds for the user
* = optional

LiquidateNative

Liquidate under-collateralized native loans. Coins used to repay must be sent in the transaction this call is made.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
LiquidateNative {
6
collateral_asset: Asset,
7
debt_asset_denom: String,
8
user_address: String,
9
receive_ma_token: bool
10
}
11
}
Copied!
1
{
2
"liquidate_native": {
3
"collateral_asset": "terra...",
4
"debt_asset_denom": "uusd",
5
"user_address": "terra...",
6
"receive_ma_token": true
7
}
8
}
Copied!
Key
Type
Description
collateral_asset
String
Collateral asset liquidator gets from the borrower
debt_asset_denom
String
Denom used in Terra (e.g: uluna, uusd) of the debt asset
user_address
String
The address of the borrower getting liquidated
receive_ma_token
Bool
Whether the liquidator gets liquidated collateral in maToken (true) or the underlying collateral asset (false)

UpdateAssetCollateralStatus

Update (enable / disable) asset as collateral for the caller.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
UpdateAssetCollateralStatus {
6
asset: Asset,
7
enable: bool
8
}
9
}
Copied!
1
{
2
"update_asset_collateral_status": {
3
"asset": "terra...",
4
"enable": true
5
}
6
}
Copied!
Key
Type
Description
asset
String
Asset to update status for
enable
Bool
Option to enable (true) / disable (false) asset as collateral

FinalizeLiquidityTokenTransfer

Called by liquidity token (maToken). Validate liquidity token transfer is valid and update collateral status.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
#[allow(clippy::large_enum_variant)]
4
pub enum ExecuteMsg {
5
FinalizeLiquidityTokenTransfer {
6
sender_address: Addr,
7
recipient_address: Addr,
8
sender_previous_balance: Uint128,
9
recipient_previous_balance: Uint128,
10
amount: Uint128
11
}
12
}
Copied!
1
{
2
"finalize_liquidity_token_transfer": {
3
"sender_address": "terra...",
4
"recipient_address": "terra...",
5
"sender_previous_balance": 123,
6
"recipient_previous_balance": 123,
7
"amount": 100000
8
}
9
}
Copied!
Key
Type
Description
sender_address
String
Token sender. Address is trusted because it should have been verified in the token contract
recipient_address
String
Token recipient. Address is trusted because it should have been verified in the token contract
sender_previous_balance
Uint128
Sender's balance before the token transfer
recipient_previous_balance
Uint128
Recipient's balance before the token transfer
amount
Uint128
Transfer amount

ReceiveMsg

DepositCw20

Deposit sent cw20 tokens.
Rust
JSON
Untitled
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ReceiveMsg {
4
DepositCw20 {
5
on_behalf_of: Option<String>
6
}
7
}
Copied!
1
{
2
"deposit_cw20": {
3
"on_behalf_of": "terra..."
4
}
5
}
Copied!
1
{
2
"withdraw": {
3
"asset": {
4
"cw20": {
5
"contract_addr": "terra1747mad58h0w4y589y3sk84r5efqdev9q4r02pc"
6
}
7
},
8
"amount": "10",
9
"recipient": "terra18mxdzx2mqs335k8avy24c5er0jx88a3gau0r2a"
10
}
11
}
Copied!
Key
Type
Description
on_behalf_of*
String
Deposit the funds for the user
* = optional

RepayCw20

Repay sent cw20 tokens.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ReceiveMsg {
4
RepayCw20 {
5
on_behalf_of: Option<String>
6
}
7
}
Copied!
1
{
2
"repay_cw20": {
3
"on_behalf_of": "terra..."
4
}
5
}
Copied!
Key
Type
Description
on_behalf_of*
String
Repay the funds for the user
* = optional

LiquidateCw20

Liquidate under-collateralized cw20 loan using the sent cw20 tokens.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ReceiveMsg {
4
LiquidateCw20 {
5
collateral_asset: Asset,
6
user_address: String,
7
receive_ma_token: bool
8
}
9
}
Copied!
1
{
2
"liquidate_cw_20": {
3
"collateral_asset": "terra...",
4
"user_address": "terra...",
5
"receive_ma_token": true
6
}
7
}
Copied!
Key
Type
Description
collateral_asset
String
Collateral asset liquidator gets from the borrower
user_address
String
The address of the borrower getting liquidated
receive_ma_token
Bool
Whether the liquidator gets liquidated collateral in maToken (true) or the underlying collateral asset (false)

QueryMsg

Config

Get contract config.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Config {}
5
}
Copied!
1
{
2
"config": {}
3
}
Copied!

Market

Get asset market.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Market {
5
asset: Asset
6
}
7
}
Copied!
1
{
2
"market": {
3
"asset": "terra..."
4
}
5
}
Copied!
Key
Type
Description
asset
String
Asset to return market for

MarketsList

Get a list of all markets.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
MarketsList {}
5
}
Copied!
1
{
2
"markets_list": {}
3
}
Copied!

UncollateralizedLoanLimit

Get uncollateralized limit for given asset and user.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
UncollateralizedLoanLimit {
5
user_address: String,
6
asset: Asset
7
}
8
}
Copied!
1
{
2
"uncollateralized_loan_limit": {
3
"user_address": "terra...",
4
"asset": "terra..."
5
}
6
}
Copied!
Key
Type
Description
user_address
String
User address to get uncollateralized limit for
asset
String
Asset address to get uncollateralized limit for

UserDebt

Get all debt positions for a user.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
UserDebt {
5
user_address: String
6
}
7
}
Copied!
1
{
2
"user_debt": {
3
"user_address": "terra..."
4
}
5
}
Copied!
Key
Type
Description
user_address
String
Address to get debt positions from

UserAssetDebt

Get user debt position for a specific asset.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
UserAssetDebt {
5
user_address: String,
6
asset: Asset
7
}
8
}
Copied!
1
{
2
"user_asset_debt": {
3
"user_address": "terra...",
4
"asset": "terra..."
5
}
6
}
Copied!
Key
Type
Description
user_address
String
Address to get debt position for
asset
String
Specific asset to get debt position for

UserCollateral

Get info about whether or not user is using each asset as collateral.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
UserCollateral {
5
user_address: String
6
}
7
}
Copied!
1
{
2
"user_collateral": {
3
"user_address": "terra..."
4
}
5
}
Copied!
Key
Text
Text
user_address
String
Address to get collateral info from

UserPosition

Get user position.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
UserPosition {
5
user_address: String
6
}
7
}
Copied!
1
{
2
"user_position": {
3
"user_address": "terra..."
4
}
5
}
Copied!
Key
Type
Description
user_address
String
Address to get position for

ScaledLiquidityAmount

Get liquidity scaled amount for a given underlying asset amount (i.e: how much maTokens will get minted if the given amount is deposited).
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
ScaledLiquidityAmount {
5
asset: Asset,
6
amount: Uint128
7
}
8
}
Copied!
1
{
2
"scaled_liquidity_amount": {
3
"asset": "terra...",
4
"amount": 123
5
}
6
}
Copied!
Key
Type
Description
asset
String
Asset to get liquidity scaled amount for
amount
Uint128
Amount to get liquidity scaled amount for

ScaledDebtAmount

Get equivalent scaled debt for a given underlying asset amount (i.e: how much scaled debt is added if the given amount is borrowed).
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
ScaledDebtAmount {
5
asset: Asset,
6
amount: Uint128
7
}
8
}
Copied!
1
{
2
"scaled_debt_amount": {
3
"asset": "terra...",
4
"amount": 123
5
}
6
}
Copied!
Key
Type
Description
asset
String
Asset to get equivalent scaled debt for
amount
Uint128
Amount to get equivalent scaled debt for

UnderlyingLiquidityAmount

Get underlying asset amount for a given maToken balance.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
UnderlyingLiquidityAmount {
5
ma_token_address: String,
6
amount_scaled: Uint128
7
}
8
}
Copied!
1
{
2
"underlying_liquidity_amount": {
3
"ma_token_address": "terra...",
4
"amount_scaled": 123
5
}
6
}
Copied!
Key
Type
Description
ma_token_address
String
maToken address
amount_scaled
Uint128
Scaled amount

UnderlyingDebtAmount

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