Search…
Mint
The Mint Contract implements the logic for Collateralized Debt Positions (CDPs), through which users can mint or short new mAsset tokens against their deposited collateral (UST or mAssets).
Current prices of collateral and minted mAssets are read from the Collateral Oracle and Oracle Contract to determine the C-ratio of each CDP. Depending on which the type of asset used as the collateral, the minimum collateral ratio of each CDP may change. Collateral Oracle is responsible for feeding prices and collateral ratio multiplier of each collateral asset type.
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
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct InitMsg {
3
pub owner: HumanAddr,
4
pub oracle: HumanAddr,
5
pub collector: HumanAddr,
6
pub collateral_oracle: HumanAddr,
7
pub staking: HumanAddr,
8
pub terraswap_factory: HumanAddr,
9
pub lock: HumanAddr,
10
pub base_denom: String,
11
pub token_code_id: u64,
12
pub protocol_fee_rate: Decimal,
13
}
Copied!
1
{
2
"owner": "terra1...",
3
"oracle": "terra1...",
4
"collector": "terra1...",
5
"collateral_oracle": "terra1...",
6
"staking": "terra1...",
7
"terraswap_factory": "terra1...",
8
"lock": "terra1...",
9
"base_denom": "uusd",
10
"token_code_id": 8,
11
"protocol_fee_rate": "0.123
12
}
Copied!
Key
Type
Description
owner
HumanAddr
Owner of contract
oracle
HumanAddr
Contract address of Mirror Oracle
collector
HumanAddr
Contract address of Mirror Collector
collateral_oracle
HumanAddr
Contract address of Mirror Collateral Oracle
staking
HumanAddr
Contract address of Mirror Staking
terraswap_factory
HumanAddr
Contract address of Terraswap Factory
lock
HumanAddr
Contract address of Mirror Lock
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
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
Receive {
5
amount: Uint128,
6
sender: HumanAddr,
7
msg: Option<Binary>,
8
}
9
}
Copied!
1
{
2
"receive": {
3
"amount": "10000000",
4
"sender": "terra1...",
5
"msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmxhaCBibGFoIiB9"
6
}
7
}
Copied!
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
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
UpdateConfig {
5
owner: Option<HumanAddr>,
6
oracle: Option<HumanAddr>,
7
collector: Option<HumanAddr>,
8
collateral_oracle: Option<HumanAddr>,
9
terraswap_factory: Option<HumanAddr>,
10
lock: Option<HumanAddr>,
11
token_code_id: Option<u64>,
12
protocol_fee_rate: Option<Decimal>,
13
}
14
}
Copied!
1
{
2
"update_config": {
3
"owner": "terra1...",
4
"oracle": "terra1...",
5
"collector": "terra1...",
6
"collateral_oracle": "terra1...",
7
"staking": "terra1...",
8
"terraswap_factory": "terra1...",
9
"lock": "terra1...",
10
"token_code_id": 8,
11
"protocol_fee_rate": "0.123",
12
}
13
}
Copied!
Key
Type
Description
owner*
HumanAddr
New owner
oracle*
u64
New oracle contract address
collector*
HumanAddr
New collector contract address
terraswap_factory*
HumanAddr
Contract address of Terraswap Factory
lock*
HumanAddr
Contract address of Mirror Lock
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
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
UpdateAsset {
5
asset_info: AssetInfo,
6
auction_discount: Option<Decimal>,
7
min_collateral_ratio: Option<Decimal>,
8
ipo_params: Option<IPOParams>
9
}
10
}
11
12
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
13
pub struct IPOParams {
14
pub mint_end: u64,
15
pub pre_ipo_price: Decimal,
16
pub min_collateral_ratio_after_ipo: Decimal,
17
}
Copied!
1
{
2
"update_asset": {
3
"asset_info": {
4
"token": {
5
"contract_addr": "terra1..."
6
}
7
},
8
"auction_discount": "123.456789",
9
"min_collateral_ratio": "123.456789",
10
"ipo_params": {
11
"mint_end": "10000000",
12
"pre_ipo_price": "7.77",
13
"min_collateral_ratio_after_ipo": "1.5"
14
}
15
}
16
}
Copied!
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
ipo_params*
IPOParams
Parameters to be used for Pre-IPO asset
* = optional

IPOParams

Key
Type
Description
mint_end
u64
Time which mint_period ends
pre_ipo_price
Decimal
Fixed price to be used to mint during mint_period
min_collateral_ratio_after_ipo
Decimal
Minimum collateralization ratio to be used after IPO is triggered (Used for pre-IPO)

RegisterAsset

Registers a new mAsset to be mintable.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
RegisterAsset {
5
asset_token: HumanAddr,
6
auction_discount: Decimal,
7
min_collateral_ratio: Decimal,
8
ipo_params: Option<IPOParams>
9
},
Copied!
1
{
2
"register_asset": {
3
"asset_token": "terra1...",
4
"auction_discount": "0.2",
5
"min_collateral_ratio": "1.5",
6
"ipo_params": {
7
"mint_end": "10000000",
8
"pre_ipo_price": "7.77",
9
"min_collateral_ratio_after_ipo": "1.5"
10
}
11
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Contract address of mAsset to be registered
auction_discount
Decimal
Auction discount rate
min_collateral_ratio
Decimal
Minimum collateralization ratio
ipo_params*
IPOParams
Parameters to be used for Pre-IPO asset
*= optional

TriggerIPO

Asset feeder is allowed to trigger IPO event on pre-IPO asset to have the following characters:
  • Oracle feeder now feeds real-time price of the underlying asset
  • The asset becomes mintable again, even after the mint_period has ended
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
TriggerIPO {
5
asset_token: HumanAddr,
6
},
Copied!
1
{
2
"trigger_ipo": {
3
"asset_token": "terra1..."
4
}
5
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Contract address of the token

RegisterMigration

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
RegisterMigration {
5
asset_token: HumanAddr,
6
end_price: Decimal,
7
}
8
}
Copied!
1
{
2
"register_migration": {
3
"asset_token": "terra1...",
4
"end_price": "123.456789"
5
}
6
}
Copied!
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:
1
let mint_amount = collateral.amount
2
* collateral_price
3
* reverse_decimal(asset_price)
4
* reverse_decimal(collateral_ratio);
Copied!
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
OpenPosition {
5
collateral: Asset,
6
asset_info: AssetInfo,
7
collateral_ratio: Decimal,
8
short_params: Option<ShortParams>,
9
}
10
}
11
12
pub struct Asset {
13
pub info: AssetInfo,
14
pub amount: Uint128,
15
}
16
17
#[serde(rename_all = "snake_case")]
18
pub enum AssetInfo {
19
Token { contract_addr: HumanAddr },
20
NativeToken { denom: String },
21
}
Copied!
1
{
2
"open_position": {
3
"collateral": {
4
"info": {
5
"token": {
6
"contract_addr": "terra1..."
7
}
8
},
9
"amount": "1000000"
10
},
11
"asset_info": {
12
"token": {
13
"contract_addr": "terra1..."
14
}
15
},
16
"collateral_ratio": "1.5",
17
"short_params": {
18
"belief_price": "123.456789",
19
"max_spread": "0.1"
20
}
21
}
22
}
Copied!
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
short_params*
ShortParams
Terraswap Price and spread limit to immediately short tokens after CDP creation (used for "Short")
*= optional

ShortParams

If optional short_params is added, mint contract will immediately sell the minted mAssets andsLP tokens will be minted and sent to the user. The UST obtained from the operation will be added to the user's lock position in lock contract.
Rust
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct ShortParams {
3
pub belief_price: Option<Decimal>,
4
pub max_spread: Option<Decimal>,
5
}
Copied!
Key
Type
Description
belief_price*
Decimal
Price submitted to the Terraswap pool
max_spread*
Decimal
Maximum slippage accepted during swap transaction against the Terraswap Pool
*=optional

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
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
Deposit {
5
collateral: Asset,
6
position_idx: Uint128,
7
}
8
}
Copied!
1
{
2
"deposit": {
3
"collateral": {
4
"info": {
5
"native_token": {
6
"denom": "uusd",
7
}
8
},
9
"amount": "1000000"
10
},
11
"position_idx": "10000000"
12
}
13
}
Copied!
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
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
Withdraw {
5
collateral: Asset,
6
position_idx: Uint128,
7
}
8
}
Copied!
1
{
2
"withdraw": {
3
"collateral": {
4
"info": {
5
"token": {
6
"contract_address": "terra1..."
7
}
8
},
9
"amount": "1000000"
10
},
11
"position_idx": "10000000"
12
}
13
}
Copied!
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
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
Mint {
5
asset: Asset,
6
position_idx: Uint128,
7
short_params: Option<ShortParams>,
8
}
9
}
Copied!
1
{
2
"mint": {
3
"position_idx": "10000000",
4
"asset": {
5
"info": {
6
"token": {
7
"contract_address": "terra1..."
8
}
9
},
10
"amount": "1000000"
11
},
12
"short_params": {
13
"belief_price": "123.456789",
14
"max_spread": "0.1"
15
}
16
}
17
}
Copied!
Key
Type
Description
position_idx
Uint128
Index of position
asset
Asset
mAssets to be minted
short_params
ShortParams
Terraswap Price and maximum slippage tolerance to be applied for selling minted token after position creation (used for "Short")

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
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
OpenPosition {
5
asset_info: AssetInfo,
6
collateral_ratio: Decimal,
7
short_params: Option<ShortParams>,
8
}
9
}
Copied!
1
{
2
"open_position": {
3
"asset_info": {
4
"token": {
5
"contract_addr": "terra1..."
6
}
7
},
8
"collateral_ratio": "123.456789",
9
"short_params": {
10
"belief_price": "123.456789",
11
"max_spread": "0.1"
12
}
13
}
14
}
Copied!
Key
Type
Description
asset_info
AssetInfo
mAsset to be minted by CDP
collateral_ratio
Decimal
Initial collateralization ratio to use
short_params
ShortParams
Terraswap Price and spread limit to immediately short tokens after CDP creation (used for "Short")

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
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
Deposit {
5
position_idx: Uint128,
6
}
7
}
Copied!
1
{
2
"deposit": {
3
"position_idx": "10000000"
4
}
5
}
Copied!
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
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
Burn {
5
position_idx: Uint128,
6
}
7
}
Copied!
1
{
2
"burn": {
3
"position_idx": "10000000"
4
}
5
}
Copied!
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:
1
let discounted_price = price * (1 - config.auction_discount);
Copied!
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
Auction {
5
position_idx: Uint128,
6
}
7
}
Copied!
1
{
2
"auction": {
3
"position_idx": "10000000"
4
}
5
}
Copied!
Key
Type
Description
position_idx
Uint128
Index of position

QueryMsg

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!

Response

1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct ConfigResponse {
3
pub owner: HumanAddr,
4
pub oracle: HumanAddr,
5
pub collector: HumanAddr,
6
pub collateral_oracle: HumanAddr,
7
pub staking: HumanAddr,
8
pub terraswap_factory: HumanAddr,
9
pub lock: HumanAddr,
10
pub base_denom: String,
11
pub token_code_id: u64,
12
pub protocol_fee_rate: Decimal,
13
}
Copied!
Key
Type
Description
owner
HumanAddr
Owner of contract
oracle
HumanAddr
Contract address of Mirror Oracle
collector
HumanAddr
Contract address of Mirror Collector
collateral_oracle
HumanAddr
Contract address of Mirror Collateral Oracle
staking
HumanAddr
Contract address of Mirror Staking
terraswap_factory
HumanAddr
Contract address of Terraswap Factory
lock
HumanAddr
Contract address of Mirror Lock
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
1
{
2
"config": {}
3
}
Copied!

Response

1
{
2
"config_response": {
3
"owner": "terra1...",
4
"oracle": "terra1...",
5
"collector": "terra1...",
6
"collateral_oracle": "terra1...",
7
"staking": "terra1...",
8
"terraswap_factory": "terra1...",
9
"lock": "terra1...",
10
"base_denom": "uusd",
11
"token_code_id": 8,
12
"protocol_fee_rate": "123.456789"
13
}
14
}
Copied!
Key
Type
Description
owner
HumanAddr
Owner of contract
oracle
HumanAddr
Contract address of Mirror Oracle
collector
HumanAddr
Contract address of Mirror Collector
collateral_oracle
HumanAddr
Contract address of Mirror Collateral Oracle
staking
HumanAddr
Contract address of Mirror Staking
terraswap_factory
HumanAddr
Contract address of Terraswap Factory
lock
HumanAddr
Contract address of Mirror Lock
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

AssetConfig

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
AssetConfig {
5
asset_token: HumanAddr,
6
}
7
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Contract address of asset to query

Response

1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct AssetConfigResponse {
3
pub token: HumanAddr,
4
pub auction_discount: Decimal,
5
pub min_collateral_ratio: Decimal,
6
pub end_price: Option<Decimal>,
7
pub ipo_params: Option<IPOParams>,
8
}
Copied!
Key
Type
Description
token
HumanAddr
Contract address of asset to query
auction_discount
Decimal
Discount rate applied for liquidation auction
min_collateral_ratio
Decimal
Lowest collateral ratio to mint this mAsset
end_price*
Decimal
Fixed oracle price of mAsset when migration / Pre-IPO / Delisting occurs
ipo_params*
u64
Parameters to be used for Pre-IPO assets
*= optional
1
{
2
"asset_config": {
3
"asset_info": {
4
"token": {
5
"contract_addr": "terra1..."
6
}
7
}
8
}
9
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Contract address of asset to query

Response

1
{
2
"asset_config_response": {
3
"token": "terra1...",
4
"auction_discount": "0.2",
5
"min_collateral_ratio": "1.5",
6
"end_price": "123.456789",
7
"ipo_params": {
8
"mint_end": "10000000",
9
"pre_ipo_price": "7.77",
10
"min_collateral_ratio_after_ipo": "1.5"
11
}
12
}
13
}
Copied!
Key
Type
Description
token
HumanAddr
Contract address of asset to query
auction_discount
Decimal
Discount rate applied for liquidation auction
min_collateral_ratio
Decimal
Lowest collateral ratio to mint this mAsset
end_price*
Decimal
Fixed oracle price of mAsset when migration / Pre-IPO / Delisting occurs
ipo_params*
u64
Parameters to be used for Pre-IPO assets
*= optional

Position

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Position {
5
position_idx: Uint128,
6
}
7
}
Copied!
Key
Type
Description
position_idx
Uint128
Index of position to query

Response

1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct PositionResponse {
3
pub idx: Uint128,
4
pub owner: HumanAddr,
5
pub collateral: Asset,
6
pub asset: Asset,
7
pub is_short: bool,
8
}
Copied!
Name
Type
Description
idx
Uint128
Index of CDP
owner
HumanAddr
Address of CDP owner
collateral
Asset
Asset used as collateral
asset
Asset
Asset minted by CDP
is_short
bool
Determines if CDP is short position or not
1
{
2
"position": {
3
"position_idx": "10000000"
4
}
5
}
Copied!
Key
Type
Description
position_idx
Uint128
Index of position to query

Response

1
{
2
"position_response": {
3
"idx": "100",
4
"owner": "terra1...",
5
"collateral": {
6
"info": {
7
"token": {
8
"contract_addr": "terra1..."
9
}
10
},
11
"amount": "1000000"
12
},
13
"asset": {
14
"info": {
15
"token": {
16
"contract_addr": "terra1..."
17
}
18
},
19
"amount": "1000000"
20
},
21
"is_short": true
22
}
23
}
Copied!
Name
Type
Description
idx
Uint128
Index of CDP
owner
HumanAddr
Address of CDP owner
collateral
Asset
Asset used as collateral
asset
Asset
Asset minted by CDP
is_short
bool
Determines if CDP is short position or not

NextPositionIdx

Returns the most recent position ID +1.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
NextPositionIdx {}
5
}
Copied!

Response

1
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
2