Market
The Market contract acts as the point of interaction for all lending and borrowing related activities. New stablecoin deposits are added to this contract's balance, while borrows are subtracted from the contract balance.

Config

Key
Type
Description
contract_addr
CanonicalAddr
Address of itself (Market contract)
owner_addr
CanonicalAddr
Address of contract owner that can update config
aterra_contract
CanonicalAddr
Contract address of aTerra
interest_model
CanonicalAddr
Contract address of Interest Model
distribution_model
CanonicalAddr
Contract address of Distribution Model
overseer_contract
CanonicalAddr
Contract address of Overseer
collector_contract
CanonicalAddr
Contract address of Collector
distributor_contract
CanonicalAddr
Contract address of Distributor
stable_denom
String
Native token denomination for stablecoin
max_borrow_factor
Decimal256
Maximum portion of stablecoin liquidity available for borrows

InstantiateMsg

Instantiates the money market Market contract. Requires the owner to make an initial deposit of 1 Terra stablecoin and mints 1 aTerra to the Market contract (inaccessible). The creator's initial stablecoin deposit ensures the aTerra supply to always be a high enough value to prevent rounding errors in the aTerra exchange rate calculation.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub struct InstantiateMsg {
4
pub owner_addr: String,
5
pub stable_denom: String,
6
pub aterra_code_id: u64,
7
pub anc_emission_rate: Decimal256,
8
pub max_borrow_factor: Decimal256,
9
}
Copied!
1
{
2
"owner_addr": "terra1...",
3
"stable_denom": "uusd", // Terra USD
4
"aterra_code_id": 5,
5
"anc_emission_rate": "0.05",
6
"max_borrow_factor": "0.95"
7
}
Copied!
Key
Type
Description
owner_addr
String
Address of contract owner
stable_denom
String
Native token denomination for stablecoin
aterra_code_id
u64
Code ID for aTerra contract
anc_emission_rate
Decimal256
Initial per-block ANC emission rate to borrowers
max_borrow_factor
Decimal256
Maximum portion of stablecoin liquidity available for borrows

ExecuteMsg

Receive

Can be called during a CW20 token transfer when the Mint contract is the recipient. Allows the token transfer to execute a Receive Hook as a subsequent action within the same transaction.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
Receive {
5
sender: String,
6
amount: Uint128,
7
msg: Binary,
8
}
9
}
Copied!
1
{
2
"receive": {
3
"sender": "terra1...",
4
"amount": "10000000",
5
"msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmxhaCBibGFoIiB9"
6
}
7
}
Copied!
Key
Type
Description
sender
String
Sender of token transfer
amount
Uint128
Amount of tokens received
msg
Binary
Base64-encoded string of JSON of Receive Hook

RegisterContracts

Registers the addresses of other Money Market contracts. Can only be issued by the owner.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
RegisterContracts {
5
overseer_contract: String,
6
interest_model: String,
7
distribution_model: String,
8
collector_contract: String,
9
distributor_contract: String,
10
}
11
}
Copied!
1
{
2
"register_contracts": {
3
"overseer_contract": "terra1...",
4
"interest_model": "terra1...",
5
"distribution_model": "terra1...",
6
"collector_contract": "terra1...",
7
"distributor_contract": "terra1..."
8
}
9
}
Copied!
Key
Type
Description
overseer_contract
String
Contract address of Overseer
interest_model
String
Contract address of Interest Model
distribution_model
String
Contract address of Distribution Model
collector_contract
String
Contract address of Collector
distributor_contract
String
Contract address of Distributor

[Internal] RegisterATerra

Registers the contract address of aTerra Cw20 Token contract. Issued by aTerra after initialization.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
RegisterATerra {}
5
}
Copied!
1
{
2
"register_a_terra": {}
3
}
Copied!
Key
Type
Description

UpdateConfig

Updates the configuration of the contract. Can be only issued by the owner.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
UpdateConfig {
5
owner_addr: Option<String>,
6
max_borrow_factor: Option<Decimal256>,
7
interest_model: Option<String>,
8
distribution_model: Option<String>,
9
}
10
}
Copied!
1
{
2
"update_config": {
3
"owner_addr": "terra1...",
4
"max_borrow_factor": "0.95",
5
"interest_model": "terra1...",
6
"distribution_model": "terra1..."
7
}
8
}
Copied!
Key
Type
Description
owner_addr*
String
Address of new owner
max_borrow_factor*
Decimal256
New maximum portion of stablecoin liquidity available for borrows
interest_model*
String
New interest model contract address
distribution_model*
String
New contract address of Distribution Model
* = optional

[Internal] RepayStableFromLiquidation

Repays a liquidated loan using stablecoins gained from liquidated collaterals. Can only be issued by Overseer.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
RepayStableFromLiquidation {
5
borrower: String,
6
prev_balance: Uint256,
7
}
8
}
Copied!
1
{
2
"repay_stable_from_liquidation": {
3
"borrower": "terra1...",
4
"prev_balance": "1000000000"
5
}
6
}
Copied!
Key
Type
Description
borrower
String
Address of loan borrower
prev_balance
Uint256
Balance of Market contract prior to collateral liquidation

[Internal] ExecuteEpochOperations

Adjusts the borrower ANC emission rate and sends accumulated ANC excess yield reserves to Overseer. Can only be issued by Overseer.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
ExecuteEpochOperations {
5
deposit_rate: Decimal256,
6
target_deposit_rate: Decimal256,
7
threshold_deposit_rate: Decimal256,
8
distributed_interest: Uint256,
9
}
10
}
Copied!
1
{
2
"execute_epoch_operations": {
3
"deposit_rate": "0.000000002",
4
"target_deposit_rate": "0.000000002",
5
"threshold_deposit_rate": "0.000000001",
6
"distributed_interest": "100000000"
7
}
8
}
Copied!
Key
Type
Description
deposit_rate
Decimal256
Calculated per-block deposit of the last epoch
target_deposit_rate
Decimal256
Target per-block deposit rate of Anchor
threshold_deposit_rate
Decimal256
Threshold per-block deposit rate of Anchor
distributed_interest
Uint256
Amount of depositor subsidies distributed in this epoch

DepositStable

Deposits stablecoins to Anchor. Requires stablecoins to be sent with the message.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
DepositStable {}
5
}
Copied!
1
{
2
"deposit_stable": {}
3
}
Copied!
Key
Type
Description

BorrowStable

Borrows stablecoins from Anchor.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
BorrowStable {
5
borrow_amount: Uint256,
6
to: Option<String>,
7
}
8
}
Copied!
1
{
2
"borrow_stable": {
3
"borrow_amount": "1000000000",
4
"to": "terra1..."
5
}
6
}
Copied!
Key
Type
Description
borrow_amount
Uint256
Amount of stablecoins to borrow
to*
String
Withdrawal address for borrowed stablecoins
* = optional

RepayStable

Repays previous stablecoin liability. Requires stablecoins to be sent with the message.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
RepayStable {}
5
}
Copied!
1
{
2
"repay_stable": {}
3
}
Copied!
Key
Type
Description

ClaimRewards

Claims accrued ANC rewards. Can designate an optional recipient. Sends rewards to message sender if to is not specified.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
ClaimRewards {
5
to: Option<String>,
6
}
7
}
Copied!
1
{
2
"claim_rewards": {
3
"to": "terra1..."
4
}
5
}
Copied!
Key
Type
Description
to*
String
Optional recipient of accrued ANC rewards
* = optional

Receive Hooks

RedeemStable

Redeems aTerra to their underlying stablecoins.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
RedeemStable {}
5
}
Copied!
1
{
2
"redeem_stable": {}
3
}
Copied!
Key
Type
Description

QueryMsg

Config

Gets the Market contract configuration.
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!
Key
Type
Description

ConfigResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct ConfigResponse {
3
pub owner_addr: String,
4
pub aterra_contract: String,
5
pub interest_model: String,
6
pub distribution_model: String,
7
pub overseer_contract: String,
8
pub collector_contract: String,
9
pub distributor_contract: String,
10
pub stable_denom: String,
11
pub max_borrow_factor: Decimal256,
12
}
Copied!
1
{
2
"owner_addr": "terra1...",
3
"aterra_contract": "terra1...",
4
"interest_model": "terra1...",
5
"distribution_model": "terra1...",
6
"overseer_contract": "terra1...",
7
"collector_contract": "terra1...",
8
"distributor_contract": "terra1...",
9
"stable_denom": "uusd",
10
"max_borrow_factor": "1.0"
11
}
Copied!
Key
Type
Description
owner_addr
String
Address of contract owner
aterra_contract
String
Contract address of aTerra
interest_model
String
Contract address of Interest Model
distribution_model
String
Contract address of Distribution Model
overseer_contract
String
Contract address of Overseer
collector_contract
String
Contract address of Collector
distributor_contract
String
Contract address of Distributor
stable_denom
String
Native token denomination for stablecoin
max_borrow_factor
Decimal256
Maximum portion of stablecoin liquidity available for borrows

State

Gets state information of Market. Returns an interest-accrued value if block_height field is filled. Returns the stored (no interest accrued) state if not filled.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
State {
5
block_height: Option<u64>,
6
}
7
}
Copied!
1
{
2
"state": {
3
"block_height": 123456,
4
}
5
}
Copied!
Key
Type
Description
block_height
u64
Block number to use in query
* = optional

StateResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct State {
3
pub total_liabilites: Decimal256,
4
pub total_reserves: Decimal256,
5
pub last_interest_updated: u64,
6
pub last_reward_updated: u64,
7
pub global_interest_index: Decimal256,
8
pub global_reward_index: Decimal256,
9
pub anc_emission_rate: Decimal256,
10
pub prev_aterra_supply: Uint256,
11
pub prev_exchange_rate: Decimal256,
12
}
Copied!
1
{
2
"total_liabilities": "123.456789",
3
"total_reserves": "12.3456789",
4
"last_interest_updated": 123456789,
5
"last_reward_updated": 123456789,
6
"global_interest_index": "1.23456789",
7
"global_reward_index": "123456.789",
8
"anc_emission_rate": "0.05",
9
"prev_aterra_supply": "100000000",
10
"prev_exchange_rate": "1.23456789"
11
}
Copied!
Key
Type
Description
total_liabilities
Decimal256
Total amount of liabilities of all borrowers
total_reserves
Decimal256
Total amount of ANC purchase reserves
last_interest_updated
u64
Block number when interest was last accrued
last_reward_updated
u64
Block number when rewards were last accrued
global_interest_index
Decimal256
Current global interest index
global_reward_index
Decimal256
Current ANC global reward index
anc_emission_rate
Decimal256
Current per-block ANC emission rate to borrowers
prev_aterra_supply
Uint256
aTerra supply when interest was last accrued
prev_exchange_rate
Decimal256
aTerra exchange rate when interest was last accrued

EpochState

Gets state information related to epoch operations. Returns an interest-accrued value if block_height field is filled. Returns the stored (no interest accrued) state if not filled.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
EpochState {
5
block_height: Option<u64>,
6
distributed_interest: Option<Uint256>,
7
}
8
}
Copied!
1
{
2
"epoch_state": {
3
"block_height": 123456,
4
"distributed_interest": "100000000"
5
}
6
}
Copied!
Key
Type
Description
block_height*
u64
Block number to use in query
distributed_interest*
Uint256
Amount of depositor subsidies distributed in this epoch
* = optional

EpochStateResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct EpochStateResponse {
3
pub exchange_rate: Decimal256,
4
pub aterra_supply: Uint256,
5
}
Copied!
1
{
2
"exchange_rate": "1.23",
3
"aterra_supply": "100000000"
4
}
Copied!
Key
Type
Description
exchange_rate
Decimal256
Current aTerra exchange rate
aterra_supply
Uint256
Current aTerra supply

BorrowerInfo

Gets information for the specified borrower. Returns an interest-and-reward-accrued value if block_height field is filled. Returns the stored (no interest / reward accrued) state if not filled.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
BorrowerInfo {
5
borrower: String,
6
block_height: Option<u64>,
7
}
8
}
Copied!
1
{
2
"borrower_info": {
3
"borrower": "terra1...",
4
"block_height": 123456
5
}
6
}
Copied!
Key
Type
Description
borrower
String
Address of borrower
block_height*
u64
Current block number
* = optional

BorrowerInfoResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct BorrowInfoResponse {
3
pub borrower: String,
4
pub interest_index: Decimal256,
5
pub reward_index: Decimal256,
6
pub loan_amount: Uint256,
7
pub pending_rewards: Decimal256,
8
}
Copied!
1
{
2
"borrower": "terra1...",
3
"interest_index": "1.23456789",
4
"reward_index": "123.456789",
5
"loan_amount": "123456789",
6
"pending_rewards": "123456.789"
7
}
Copied!
Key
Type
Description
borrower
String
Address of borrower
interest_index
Decimal256
Interest index of borrower
reward_index
Decimal256
ANC reward index of borrower
loan_amount
Uint256
Amount of borrower's liability
pending_rewards
Decimal256
Amount of ANC rewards accrued to borrower

BorrowInfos

Gets information for all borrowers.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
BorrowInfos {
5
start_after: Option<String>,
6
limit: Option<u32>,
7
}
8
}
Copied!
1
{
2
"borrower_infos": {
3
"start_after": "terra1...",
4
"limit": 10
5
}
6
}
Copied!
Key
Type