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

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InitMsg {
    pub owner: HumanAddr,
    pub oracle: HumanAddr,
    pub collector: HumanAddr,
    pub collateral_oracle: HumanAddr,
    pub staking: HumanAddr,
    pub terraswap_factory: HumanAddr,
    pub lock: HumanAddr,
    pub base_denom: String,
    pub token_code_id: u64,
    pub protocol_fee_rate: Decimal,
}

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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
    Receive {
        amount: Uint128,
        sender: HumanAddr,
        msg: Option<Binary>,
    }
}

* = optional

UpdateConfig

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

#[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>,
        collateral_oracle: Option<HumanAddr>,
        terraswap_factory: Option<HumanAddr>,
        lock: Option<HumanAddr>,
        token_code_id: Option<u64>,
        protocol_fee_rate: Option<Decimal>,
    }
}

* = optional

UpdateAsset

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

#[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>,
        ipo_params: Option<IPOParams>
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct IPOParams {
    pub mint_end: u64,
    pub pre_ipo_price: Decimal,
    pub min_collateral_ratio_after_ipo: Decimal,
}

* = optional

IPOParams

RegisterAsset

Registers a new mAsset to be mintable.

#[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,
        ipo_params: Option<IPOParams>
    },

*= 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

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
    TriggerIPO {
        asset_token: HumanAddr, 
    },

RegisterMigration

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

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);
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {   
    OpenPosition {
        collateral: Asset,
        asset_info: AssetInfo,
        collateral_ratio: Decimal,
        short_params: Option<ShortParams>,
    }
}

pub struct Asset {
    pub info: AssetInfo,
    pub amount: Uint128,
}

#[serde(rename_all = "snake_case")]
pub enum AssetInfo {
    Token { contract_addr: HumanAddr },
    NativeToken { denom: String },
}

*= 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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct ShortParams {
    pub belief_price: Option<Decimal>,
    pub max_spread: Option<Decimal>,
}

*=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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
    Deposit {
        collateral: Asset,
        position_idx: Uint128,
    }
}

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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
    Withdraw {
        collateral: Asset,
        position_idx: Uint128,
    }
}

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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum HandleMsg {
    Mint {
        asset: Asset,
        position_idx: Uint128,
        short_params: Option<ShortParams>,
    }
}

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.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Cw20HookMsg {
    OpenPosition {
        asset_info: AssetInfo,
        collateral_ratio: Decimal,
        short_params: Option<ShortParams>,
    }
}

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.

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

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.

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

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);
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Cw20HookMsg {
    Auction {
        position_idx: Uint128,
    }
}

QueryMsg

Config

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

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct ConfigResponse {
    pub owner: HumanAddr,
    pub oracle: HumanAddr,
    pub collector: HumanAddr,
    pub collateral_oracle: HumanAddr,
    pub staking: HumanAddr,
    pub terraswap_factory: HumanAddr,
    pub lock: HumanAddr,
    pub base_denom: String,
    pub token_code_id: u64,
    pub protocol_fee_rate: Decimal,
}

AssetConfig

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
    AssetConfig {
        asset_token: HumanAddr,
    }
}

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct AssetConfigResponse {
    pub token: HumanAddr,
    pub auction_discount: Decimal,
    pub min_collateral_ratio: Decimal,
    pub end_price: Option<Decimal>,
    pub ipo_params: Option<IPOParams>,
}

*= optional

Position

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

Response

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct PositionResponse {
    pub idx: Uint128,
    pub owner: HumanAddr,
    pub collateral: Asset,
    pub asset: Asset,
    pub is_short: bool,
}

NextPositionIdx

Returns the most recent position ID +1.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
    NextPositionIdx {}
}

Response

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
pub struct NextPositionIdxResponse {
    pub next_position_idx: Uint128,
}

Positions

#[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>,
    }
}

* = optional

Last updated