> For the complete documentation index, see [llms.txt](https://mars-protocol.gitbook.io/mars-protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mars-protocol.gitbook.io/mars-protocol/contracts-core/tokenomics/staking.md).

# Staking

The Staking contract handles the staking of MARS and the minting of xMARS.

## Links

* package (msgs and types): <https://github.com/mars-protocol/mars-core/blob/master/packages/mars-core/src/staking.rs>
* contract:  <https://github.com/mars-protocol/mars-core/blob/master/contracts/mars-staking/src/contract.rs>
* schema: <https://github.com/mars-protocol/mars-core/tree/master/contracts/mars-staking/schema>

## Config

| Key                         | Type          | Description                        |
| --------------------------- | ------------- | ---------------------------------- |
| `owner`                     | CanonicalAddr | Contract owner                     |
| `address_provider_address`  | CanonicalAddr | Address provider address           |
| `astroport_factory_address` | CanonicalAddr | Astroport factory contract address |
| `astroport_max_spread`      | StdDecimal    | Astroport max spread               |
| `cooldown_duration`         | u64           | Cooldown duration in seconds       |

## InstantiateMsg

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InstantiateMsg {
    pub config: CreateOrUpdateConfig
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "config": {
    "owner": "terra...", 
    "address_provider_address": "terra...", 
    "astroport_factory_address": "terra...",
    "astroport_max_spread": 0.1,
    "cooldown_duration": 123
  }
}
```

{% endtab %}
{% endtabs %}

### `CreateOrUpdateConfig`

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct CreateOrUpdateConfig {
    pub owner: Option<String>, 
    pub address_provider_address: Option<String>,
    pub astroport_factory_address: Option<String>,
    pub astroport_max_spread: Option<StdDecimal>,
    pub cooldown_duration: Option<u64>
}
```

| Key                         | Type       | Description                                      |
| --------------------------- | ---------- | ------------------------------------------------ |
| `owner`                     | String     | Address of contract owner that can update config |
| `address_provider_address`  | String     | Address provider address                         |
| `astroport_factory_address` | String     | Astroport factory address                        |
| `astroport_max_spread`      | StdDecimal | Astroport max spread                             |
| `cooldown_duration`         | u64        | Cooldown duration                                |

## ExecuteMsg

### `UpdateConfig`

Update staking config.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    UpdateConfig {
        config: CreateOrUpdateConfig
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "update_config": {
    "config": {
      "owner": "terra...", 
      "address_provider_address": "terra...", 
      "astroport_factory_address": "terra...",
      "astroport_max_spread": 0.1,
      "cooldown_duration": 123
   } 
  }
}
```

{% endtab %}
{% endtabs %}

### `Receive`

Implementation for cw20 receive msg.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    Receive(Cw20ReceiveMsg)
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "receive": 
}
```

{% endtab %}
{% endtabs %}

### `Claim`

Close claim sending the claimable Mars to the specified address (sender is the default).

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    Claim {
        recipient: Option<String>
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "claim": {
    "recipient": "terra..." 
  }
}
```

{% endtab %}
{% endtabs %}

| Key           |        |                          |
| ------------- | ------ | ------------------------ |
| `recipient`\* | String | Recient contract address |

\* = optional

### `TransferMars`

Transfer Mars, deducting it proportionally from both xMars holders and addresses with an open claim.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    TransferMars {
        amount: Uint128,
        recipient: String
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "transfer_mars": {
    "amount": 10000,
    "recipient": "terra..." 
  }
}
```

{% endtab %}
{% endtabs %}

| Key         | Type    | Description                |
| ----------- | ------- | -------------------------- |
| `amount`    | Uint128 | Amount of Mars to transfer |
| `recipient` | String  | Recipient of transfer      |

### `SwapUusdToMars`

Swap uusd on the contract to Mars. Meant for received protocol rewards in order for them to belong to xMars holders as underlying Mars.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    SwapUusdToMars {
        amount: Option<uint128>
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```rust
{
  "swap_uusd_to_mars": {
    "amount": 10000
  }
}
```

{% endtab %}
{% endtabs %}

| Key        | Type    | Description            |
| ---------- | ------- | ---------------------- |
| `amount`\* | uint128 | Amount of uusd to swap |

\* = optional

## ReceiveMsg

### `Stake`

Stake Mars and mint xMars in return

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ReceiveMsg {
    Stake {
        recipient: Option<String>
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "stake": {
    "recipient": "terra..."
  }
}
```

{% endtab %}
{% endtabs %}

| Key         | Type   | Description                                                         |
| ----------- | ------ | ------------------------------------------------------------------- |
| `recipient` | String | Address to receive the xMars tokens. Set to sender if not specified |

### `Unstake`

Burn xMars and initiate a cooldown period on which the underlying Mars will be claimable. Only one open claim per address is allowed.

{% tabs %}
{% tab title="Rust" %}

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ReceiveMsg {
    Unstake {
        recipient: Option<String>
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "unstake": {
    "recipient": "terra..."
  }
}
```

{% endtab %}
{% endtabs %}

| Key           | Type   | Description                                                                     |
| ------------- | ------ | ------------------------------------------------------------------------------- |
| `recipient`\* | String | Address to claim the Mars tokens after cooldown. Set to sender is not specified |

## QueryMsg

### `Config`

Get contract config.&#x20;

{% tabs %}
{% tab title="Rust" %}

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

{% endtab %}

{% tab title="JSON" %}

```json
 {
  "config": {}
}
```

{% endtab %}
{% endtabs %}

### `GlobalState`

Get contract global state.

{% tabs %}
{% tab title="Rust" %}

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

{% endtab %}

{% tab title="JSON" %}

```json
 {
  "global_state": {}
}
```

{% endtab %}
{% endtabs %}

### `XMarsPerMars`

Compute the amount of xMars token to be minted by staking 1 unit of Mars token. The ratio may be undefined, in which case the contract returns `Ok(None).`

{% tabs %}
{% tab title="Rust" %}

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

{% endtab %}

{% tab title="JSON" %}

```json
 {
  "x_mars_per_mars": {}
}
```

{% endtab %}
{% endtabs %}

### `MarsPerXMars`

Compute the amount of Mars token to be claimed by burning 1 unit of xMars token. The ratio may be undefined, in which case the contract returns `Ok(None).`

{% tabs %}
{% tab title="Rust" %}

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

{% endtab %}

{% tab title="JSON" %}

```json
 {
  "mars_per_x_mars": {}
}
```

{% endtab %}
{% endtabs %}

### `Claim`

Get open claim for given user. If claim exists, slash events are applied to the amount so actual amount of Mars received is given.

{% tabs %}
{% tab title="Rust" %}

```rust
[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
    Claim {
        user_address: String
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "claim": {
    "user_address": "terra..."
  }
}
```

{% endtab %}
{% endtabs %}

| Key            | Type   | Description                      |
| -------------- | ------ | -------------------------------- |
| `user_address` | String | User address to query open claim |
