Search…
Staking
The Staking Contract contains the logic for LP Token staking and reward distribution. Staking rewards for LP stakers come from the new MIR tokens generated at each block by the Factory Contract and are split between all combined staking pools. The new MIR tokens are distributed in proportion to size of staked LP tokens multiplied by the weight of that asset's staking pool.

InitMsg

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct InitMsg {
3
pub owner: HumanAddr,
4
pub mirror_token: HumanAddr,
5
pub mint_contract: HumanAddr,
6
pub oracle_contract: HumanAddr,
7
pub terraswap_factory: HumanAddr,
8
pub base_denom: String,
9
pub premium_min_update_interval: u64,
10
}
Copied!
1
{
2
"owner": "terra1...",
3
"mirror_token": "terra1...",
4
"mint_contract": "terra1...",
5
"oracle_contract": "terra1...",
6
"terraswap_factory": "terra1...",
7
"base_denom": "uusd",
8
"premium_min_update_interval": 8
9
}
Copied!
Key
Type
Description
owner
HumanAddr
Owner address of Staking contract
mirror_token
HumanAddr
Contract address of the Mirror Token (MIR)
mint_contract
HumanAddr
Contract address of Mirror Mint
oracle_contract
HumanAddr
Contract address of Mirror Oracle
terraswap_factory
HumanAddr
Contract address of Terraswap Factory
base_denom
String
Native token denom for Terraswap pairs (TerraUSD)
premium_min_update_interval
u64
Interval of time denominated in number of blocks which the collateral premium information is updated

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
Token amount received
sender
HumanAddr
Sender of token transaction
msg*
Binary
Base64-encoded JSON of Receive Hook message
* = optional

UpdateConfig

Updates the Staking contract's configuration. Can only be issued by the staking contract's owner.
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
premium_min_update_interval: Option<u64>,
7
}
8
Copied!
1
{
2
"update_config": {
3
"owner": "terra1...",
4
"premium_min_update_interval": 8
5
}
6
}
Copied!
Name
Type
Description
owner*
HumanAddr
Owner address of Staking contract
premium_min_update_interval*
u64
Interval of time denominated in number of blocks which the collateral premium information is updated
* = optional

RegisterAsset

Registers a new staking pool for an asset token and associates the LP token with the staking pool.
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
staking_token: HumanAddr,
7
}
8
}
Copied!
1
{
2
"register_asset": {
3
"asset_token": "terra1...",
4
"staking_token": "terra1..."
5
}
6
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Contract address of mAsset/MIR token (staking pool identifier)
staking_token
HumanAddr
Contract address of asset's corresponding LP Token

Unbond

Users can issue the unbond message at any time to remove their staked LP tokens from a staking position.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
Unbond {
5
amount: Uint128,
6
asset_token: HumanAddr,
7
}
8
}
Copied!
1
{
2
"unbond": {
3
"amount": "10000000",
4
"asset_token": "terra1..."
5
}
6
}
Copied!
Key
Type
Description
amount
Uint128
Amount of LP tokens to unbond
asset_token
HumanAddr
Contract address of mAsset/MIR token (staking pool identifier)

Withdraw

Withdraws a user's rewards for a specific staking position.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
Withdraw {
5
asset_token: Option<HumanAddr>,
6
}
7
}
Copied!
1
{
2
"withdraw": {
3
"asset_token": "terra1..."
4
}
5
}
Copied!
Key
Type
Description
asset_token*
HumanAddr
Contract address of asset token (staking pool identifier). If empty, withdraws all rewards from all staking pools involved.
* = optional

AutoStake

When providing liquidity in Mirror Protocol, asset pair is first sent to Staking contract, and it acts as a relay. When defined assets are sent to the contract, the contract provides liquidity to receive LP tokens and starts AutoStakeHook.
Note: Executor of the transaction should first increase allowance to spend CW20 tokens
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
AutoStake {
5
assets: [Asset; 2],
6
slippage_tolerance: Option<Decimal>,
7
}
8
}
Copied!
1
{
2
"auto_stake": {
3
"assets": [
4
"info": {
5
"native_token": {
6
"denom": "uusd",
7
}
8
},
9
"amount": "1000000",
10
"info": {
11
"token": {
12
"contract_address": "terra1..."
13
}
14
},
15
"amount": "1000000",
16
],
17
"slippage_tolerance": "1.234567"
18
}
19
}
Copied!
Key
Type
Description
assets*
Array[Assets]
Information of assets that are provided into liquidity pool
slippage_tolerance*
Decimal
Maximum price slippage allowed to execute this transaction
*= optional

AutoStakeHook

[INTERNAL]
Hook to stake the minted LP tokens from providing liquidity.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
AutoStakeHook {
5
asset_token: HumanAddr,
6
staking_token: HumanAddr,
7
staker_addr: HumanAddr,
8
prev_staking_token_amount: Uint128,
9
}
10
}
Copied!
1
{
2
"auto_stake_hook": {
3
"asset_token": "terra1...",
4
"staking_token": "terra1...",
5
"staker_addr": "terra1...",
6
"prev_staking_token_amount: "1000000"
7
},
8
}
Copied!
Key
Type
Description
assets_token
HumanAddr
Contract address of the asset token
staking_token
HumanAddr
Contract address of the LP token to be staked
staker_addr
HumanAddr
Address of the staker
prev_staking_token_amount
Uint128
LP staking balance of the staker before this transaction

AdjustPremium

[Permission-less operation] Changes the price premium rate for a specified mAsset, can be done by anyone. Message can be sent again after a defined premium_min_update_interval.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
AdjustPremium {
5
asset_tokens: Vec<HumanAddr>,
6
}
Copied!
1
{
2
"adjust_premium": {
3
"asset_tokens": [
4
"terra1...", "terra1..."
5
]
6
}
7
}
Copied!
Key
Type
Description
asset_tokens
Vec<HumanAddr>
Array of token contract addresses to update new price premium rate

IncreaseShortToken

[Mint contract operation] Increases the total staked supply of sLP tokens for a specific staker.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
IncreaseShortToken {
5
asset_token: HumanAddr,
6
staker_addr: HumanAddr,
7
amount: Uint128,
8
}
9
}
Copied!
1
{
2
"increase_short_token": {
3
"asset_token": "terra1...",
4
"staker_addr": "terra1...",
5
"amount": "1000000"
6
}
7
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Token contract address of sLP
staker_addr
HumanAddr
Address of the sLP staker
amount
Uint128
Amount of sLP supply to be increased

DecreaseShortToken

[Mint contract operations] Decreases the total staked supply of sLP tokens for a specific staker.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum HandleMsg {
4
DecreaseShortToken {
5
asset_token: HumanAddr,
6
staker_addr: HumanAddr,
7
amount: Uint128,
8
}
Copied!
1
{
2
"decrease_short_token": {
3
"asset_token": "terra1...",
4
"staker_addr": "terra1...",
5
"amount": "1000000"
6
}
7
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Token contract address of sLP
staker_addr
HumanAddr
Address of the sLP staker
amount
Uint128
Amount of sLP supply to be decreased

Receive Hooks

Bond

WARNING
If you send LP Tokens to the Staking contract without issuing this hook, they will not be staked and will BE LOST FOREVER.
Can be issued when the user sends LP Tokens to the Staking contract. The LP token must be recognized by the staking pool of the specified asset token.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
Bond {
5
asset_token: HumanAddr,
6
}
7
}
Copied!
1
{
2
"bond": {
3
"asset_token": "terra1..."
4
}
5
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Contract address of asset token (staking pool identifier).

DepositReward

[INTERNAL]
Can be issued when the user sends MIR tokens to the Staking contract, which will be used as rewards for the specified asset's staking pool. Used by Factory Contract to deposit newly minted MIR tokens.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
DepositReward {
5
asset_token: HumanAddr,
6
}
7
}
Copied!
1
{
2
"deposit_reward": {
3
"asset_token": "terra1..."
4
}
5
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Contract address of asset token (staking pool identifier)

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 mirror_token: HumanAddr,
5
pub mint_contract: HumanAddr,
6
pub oracle_contract: HumanAddr,
7
pub terraswap_factory: HumanAddr,
8
pub base_denom: String,
9
pub premium_min_update_interval: u64,
10
}
Copied!
Key
Type
Description
owner
HumanAddr
Owner address of Staking contract
mirror_token
HumanAddr
Contract address of the Mirror Token (MIR)
mint_contract
HumanAddr
Contract address of Mirror Mint
oracle_contract
HumanAddr
Contract address of Mirror Oracle
terraswap_factory
HumanAddr
Contract address of Terraswap Factory
base_denom
String
Native token denom for Terraswap pairs (TerraUSD)
premium_min_update_interval
u64
Interval of time denominated in number of blocks which the collateral premium information is updated
1
{
2
"config": {}
3
}
Copied!

Response

1
{
2
"config_response": {
3
"owner": "terra1...",
4
"mirror_token": "terra1...",
5
"mint_contract": "terra1...",
6
"oracle_contract": "terra1...",
7
"terraswap_factory": "terra1...",
8
"base_denom": "uusd",
9
"premium_min_update_interval": 8
10
}
11
}
Copied!
Name
Type
Description
owner
HumanAddr
Owner address of Staking contract
mirror_token
HumanAddr
Contract address of the Mirror Token (MIR)
mint_contract
HumanAddr
Contract address of Mirror Mint
oracle_contract
HumanAddr
Contract address of Mirror Oracle
terraswap_factory
HumanAddr
Contract address of Terraswap Factory
base_denom
String
Native token denom for Terraswap pairs (TerraUSD)
premium_min_update_interval
u64
Interval of time denominated in number of blocks which the collateral premium information is updated

PoolInfo

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
PoolInfo {
5
asset_token: HumanAddr,
6
}
7
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Asset token to query (staking pool identifier)

Response

1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct PoolInfoResponse {
3
pub asset_token: HumanAddr,
4
pub staking_token: HumanAddr,
5
pub total_bond_amount: Uint128,
6
pub total_short_amount: Uint128,
7
pub reward_index: Decimal,
8
pub short_reward_index: Decimal,
9
pub pending_reward: Uint128,
10
pub short_pending_reward: Uint128,
11
pub premium_rate: Decimal,
12
pub short_reward_weight: Decimal,
13
pub premium_updated_time: u64,
14
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Contract address of mAsset token
staking_token
HumanAddr
Contract address of LP or sLP token
total_bond_amount
Uint128
Amount of total LP staked
total_short_amount
Uint128
Amount of total sLP staked
reward_index
Decimal
Amount of reward distributed per 1 LP token
short_reward_index
Decimal
Amount of reward distributed per 1 sLP token
pending_reward
Uint128
Amount of unclaimed rewards by LP stakers
short_pending_reward
Uint128
Amount of unclaimed rewards by sLP stakers
premium_rate
Decimal
Current price premium of the asset pool
short_reward_weight
Decimal
Current reward weight for sLP staking
premium_updated_time
u64
Block height which the price premium data for this asset is most recently updated
1
{
2
"pool_info": {
3
"asset_token": "terra1..."
4
Key
Copied!
Type
Description
asset_token
HumanAddr
Asset token to query (staking pool identifier)

Response

1
{
2
"pool_info_response": {
3
"asset_token": "terra1...",
4
"staking_token": "terra1...",
5
"total_bond_amount": "1000000",
6
"total_short_amount": "1000000",
7
"reward_index": "123.456789",
8
"short_reward_index": "123.456789",
9
"pending_reward": "123.456789",
10
"short_pending_reward": "123.456789",
11
"premium_rate": "0.4",
12
"short_reward_weight": "0.4",
13
"premium_updated_time": 8
14
}
15
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Contract address of mAsset token
staking_token
HumanAddr
Contract address of LP or sLP token
total_bond_amount
Uint128
Amount of total LP staked
total_short_amount
Uint128
Amount of total sLP staked
reward_index
Decimal
Amount of reward distributed per 1 LP token
short_reward_index
Decimal
Amount of reward distributed per 1 sLP token
pending_reward
Uint128
Amount of unclaimed rewards by LP stakers
short_pending_reward
Uint128
Amount of unclaimed rewards by sLP stakers
premium_rate
Decimal
Current price premium of the asset pool
short_reward_weight
Decimal
Current reward weight for sLP staking
premium_updated_time
u64
Block height which the price premium data for this asset is most recently updated

RewardInfo

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
RewardInfo {
5
asset_token: Option<HumanAddr>,
6
staker: HumanAddr,
7
}
8
}
Copied!
Key
Type
Description
asset_token*
HumanAddr
Asset token to query. If empty, returns info for all staking pools.
staker
HumanAddr
Address of staker to query
*= optional

Response

1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct RewardInfoResponseItem {
3
pub asset_token: HumanAddr,
4
pub bond_amount: Uint128,
5
pub pending_reward: Uint128,
6
pub is_short: bool,
7
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Asset token being queried
bond_amount
Uint128
Amount of LP or sLP tokens staked
pending_reward
Uint128
Amount of reward that are not claimed
is_short
bool
Identifies of the pool os LP or sLP pool
1
{
2
"reward_info": {
3
"asset_token": "terra1...",
4
"staker": "terra1..."
5
}
6
}
Copied!
Key
Type
Description
asset_token*
HumanAddr
Asset token to query. If empty, returns info for all staking pools.
staker
HumanAddr
Address of staker to query
*= optional

Response

1
{
2
"reward_info_response_item": {
3
"asset_token": "terra1...",
4
"bond_amount": "1000000",
5
"pending_reward": "1000000",
6
"is_short": true
7
}
8
}
Copied!
Key
Type
Description
asset_token
HumanAddr
Asset token being queried
bond_amount
Uint128
Amount of LP or sLP tokens staked
pending_reward
Uint128
Amount of reward that are not claimed
is_short
bool
Identifies of the pool os LP or sLP pool
Last modified 5mo ago