Mint

The Mint Contract implements the logic for Collateralized Debt Positions (CDPs), through which users can mint new mAsset tokens against their deposited collateral (UST or mAssets). Current prices of collateral and minted mAssets are read from the Oracle Contract determine the C-ratio of each CDP. The Mint Contract also contains the logic for liquidating CDPs with C-ratios below the minimum for their minted mAsset through auction.

InitMsg

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InitMsg {
pub owner: HumanAddr,
pub oracle: HumanAddr,
pub collector: HumanAddr,
pub base_denom: String,
pub token_code_id: u64,
pub protocol_fee_rate: Decimal,
}
JSON
{
"owner": "terra1...",
"oracle": "terra1...",
"collector": "terra1...",
"token_code_id": 8,
"protocol_fee_rate": "0.123",
}

Key

Type

Description

owner

HumanAddr

Owner of contract

oracle

HumanAddr

Contract address of Mirror Oracle

collector

HumanAddr

Contract address of Mirror Collector

base_denom

String

Native token denomination for stablecoin (TerraUSD)

token_code_id

u64

Code ID for Terraswap CW20 Token

protocol_fee_rate

Decimal

Protocol fee

HandleMsg

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
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
Receive {
amount: Uint128,
sender: HumanAddr,
msg: Option<Binary>,
}
}
JSON
{
"receive": {
"amount": "10000000",
"sender": "terra1...",
"msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmxhaCBibGFoIiB9"
}
}

Key

Type

Description

amount

Uint128

Amount of tokens received

sender

HumanAddr

Sender of the token transfer

msg*

Binary

Base64-encoded string of JSON of Receive Hook

* = optional

UpdateConfig

Updates the configuration of the Mint contract. Can only be issued by the owner of the Mint contract.

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
UpdateConfig {
owner: Option<HumanAddr>,
oracle: Option<HumanAddr>,
collector: Option<HumanAddr>,
token_code_id: Option<u64>,
protocol_fee_rate: Option<Decimal>,
}
}
JSON
{
"update_config": {
"owner": "terra1...",
"oracle": "terra1...",
"collector": "terra1...",
"token_code_id": 8,
"protocol_fee_rate": "0.123",
}
}

Key

Type

Description

owner*

HumanAddr

New owner

oracle*

u64

New oracle contract address

collector*

HumanAddr

New collector contract address

token_code_id*

u64

New token code ID

protocol_fee_rate*

Decimal

New protocol fee rate

* = optional

UpdateAsset

Updates mAsset's minting and liquidation parameters. Can only be issued by the owner of the Mint contract.

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
UpdateAsset {
asset_info: AssetInfo,
auction_discount: Option<Decimal>,
min_collateral_ratio: Option<Decimal>,
}
}
JSON
{
"update_asset": {
"asset_info": {
"token": {
"contract_addr": "terra1..."
}
},
"auction_discount": "123.456789",
"min_collateral_ratio": "123.456789"
}
}

Key

Type

Description

asset_info

AssetInfo

Asset to be updated

auction_discount*

Decimal

New auction discount rate

min_collateral_ratio*

Decimal

New minimum collateralization ratio

* = optional

RegisterAsset

Registers a new mAsset to be mintable.

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
RegisterAsset {
asset_token: HumanAddr,
auction_discount: Decimal,
min_collateral_ratio: Decimal,
}
}
JSON
{
"register_asset": {
"asset_token": "terra1...",
"auction_discount": "123.456789",
"min_collateral_ratio": "123.456789"
}
}

Key

Type

Description

asset_token

HumanAddr

Asset to be registered

auction_discount

Decimal

Auction discount rate

min_collateral_ratio

Decimal

Minimum collateralization ratio

RegisterMigration

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
RegisterMigration {
asset_token: HumanAddr,
end_price: Decimal,
}
}
JSON
{
"register_migration": {
"asset_token": "terra1...",
"end_price": "123.456789"
}
}

Key

Type

Description

asset_token

HumanAddr

Contract address of asset to be migrated

end_price

Decimal

Final price to freeze old mAsset

OpenPosition

Used for creating a new CDP with TerraUSD collateral. For creating a CDP using mAsset collateral, you need to use the Receive Hook variant.

Opens a new CDP with an initial deposit of collateral. The user specifies the target minted mAsset for the CDP, and sets the desired initial collateralization ratio, which must be greater or equal than the minimum for the mAsset. The initial amount of minted mAsset tokens are determined by:

let mint_amount = collateral.amount
* collateral_price
* reverse_decimal(asset_price)
* reverse_decimal(collateral_ratio);
Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
OpenPosition {
asset_info: AssetInfo,
collateral: Asset,
collateral_ratio: Decimal,
}
}
pub struct Asset {
pub info: AssetInfo,
pub amount: Uint128,
}
#[serde(rename_all = "snake_case")]
pub enum AssetInfo {
Token { contract_addr: HumanAddr },
NativeToken { denom: String },
}
JSON
{
"open_position": {
"asset_info": {
"token": {
"contract_addr": "terra1..."
}
},
"collateral": {
"info": {
"token": {
"contract_address": "terra1..."
}
},
"amount": "1000000"
},
"collateral_ratio": "123.456789"
}
}

Key

Type

Description

asset_info

AssetInfo

Asset to be minted by CDP

collateral

Asset

Initial collateral deposit for the CDP

collateral_ratio

Decimal

Initial desired collateralization ratio

Deposit

Used for depositing TerraUSD collateral. For depositing mAsset collateral to a CDP, you need to use the Receive Hook variant.

Deposits additional collateral to an existing CDP to raise its C-ratio.

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
Deposit {
collateral: Asset,
position_idx: Uint128,
}
}
JSON
{
"deposit": {
"collateral": {
"info": {
"native_token": {
"denom": "uusd",
}
},
"amount": "1000000"
},
"position_idx": "10000000"
}
}

Key

Type

Description

collateral

Asset

Collateral amount to be deposited

position_idx

Uint128

Index of position

Withdraw

Withdraws collateral from the CDP. Cannot withdraw more than an amount that would drop the CDP's C-ratio below the minted mAsset's mandated minimum.

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
Withdraw {
collateral: Asset,
position_idx: Uint128,
}
}
JSON
{
"withdraw": {
"collateral": {
"info": {
"token": {
"contract_address": "terra1..."
}
},
"amount": "1000000"
},
"position_idx": "10000000"
}
}

Key

Type

Description

collateral

Asset

Collateral to withdraw

position_idx

Uint128

Index of position

Mint

Mints new mAssets against an existing CDP. Cannot mint more than what would bring the CDP's C-ratio below its minted mAsset's mandated minimum.

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
Mint {
asset: Asset,
position_idx: Uint128,
}
}
JSON
{
"mint": {
"asset": {
"info": {
"token": {
"contract_address": "terra1..."
}
},
"amount": "1000000"
},
"position_idx": "10000000"
}
}

Key

Type

Description

asset

Asset

mAssets to be minted

position_idx

Uint128

Index of position

Receive Hooks

OpenPosition

Issued when a user sends mAsset tokens to the Mint contract.

Uses the sent amount to create a new CDP.

Used for creating a new CDP with mAsset collateral. For creating a CDP using TerraUSD collateral, you need to use the HandleMsg variant.

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Cw20HookMsg {
OpenPosition {
asset_info: AssetInfo,
collateral_ratio: Decimal,
}
}
JSON
{
"open_position": {
"asset_info": {
"token": {
"contract_addr": "terra1..."
}
},
"collateral_ratio": "123.456789"
}
}

Key

Type

Description

asset_info

AssetInfo

mAsset to be minted by CDP

collateral_ratio

Decimal

Initial collateralization ratio to use

Deposit

Issued when a user sends mAsset tokens to the Mint contract.

Deposits the amount as collateral to an open CDP.

Used for depositing mAsset collateral. For depositing TerraUSD collateral to a CDP, you need to use the HandleMsg variant.

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Cw20HookMsg {
Deposit {
position_idx: Uint128,
}
}
JSON
{
"deposit": {
"position_idx": "10000000"
}
}

Key

Type

Description

position_idx

Uint128

Index of position

Burn

Issued when a user sends mAsset tokens to the Mint contract.

Burns the sent tokens against a CDP and reduces the C-ratio. If all outstanding minted mAsset tokens are burned, the position is closed and the collateral is returned.

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Cw20HookMsg {
Burn {
position_idx: Uint128,
}
}
JSON
{
"burn": {
"position_idx": "10000000"
}
}

Key

Type

Description

position_idx

Uint128

Index of position

Auction

Issued when a user sends mAsset tokens to the Mint contract.

Purchases the collateral of a CDP subject to liquidation (whose C-ratio has fallen under its minted mAsset's minimum). The buyer cannot pay more than the CDP's current minted mAsset balance.

The discounted price for the collateral is calculated as follows:

let discounted_price = price * (1 - config.auction_discount);
Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Cw20HookMsg {
Auction {
position_idx: Uint128,
}
}
JSON
{
"auction": {
"position_idx": "10000000"
}
}

Key

Type

Description

position_idx

Uint128

Index of position

QueryMsg

Config

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
Config {}
}
JSON
{
"config": {}
}

Key

Type

Description

AssetConfig

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
AssetConfig {
asset_token: HumanAddr,
}
}
JSON
{
"asset_config": {
"asset_info": {
"token": {
"contract_addr": "terra1..."
}
}
}
}

Key

Type

Description

asset_token

HumanAddr

Contract address of asset to query

Position

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
Position {
position_idx: Uint128,
}
}
JSON
{
"position": {
"position_idx": "10000000"
}
}

Key

Type

Description

position_idx

Uint128

Index of position to query

Positions

Rust
JSON
Rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
Positions {
limit: Option<u32>,
owner_addr: Option<HumanAddr>,
asset_token: Option<HumanAddr>,
start_after: Option<Uint128>,
}
}
JSON
{
"positions": {
"limit": 8,
"owner_addr": "terra1...",
"start_after": "10000000"
}
}

Key

Type

Description

limit*

u32

Upper bound of number of entries to query

owner_addr*

HumanAddr

Owner of positions

asset_token*

HumanAddr

Contract address of asset token

start_after*

Uint128

Position index to start at

* = optional