> 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/vesting.md).

# Vesting

The Vesting contract handles vesting for contributor token allocations and their voting power for council proposals.

## Links

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

## Config

| Key                        | Type     | Description                                                           |
| -------------------------- | -------- | --------------------------------------------------------------------- |
| `address_provider_address` | String   | Address provider contract address                                     |
| `unlock_schedule`          | Schedule | Schedule for token unlocking; this schedule is the same for all users |

### `Schedule`

Schedule for token unlocking; this schedule is the same for all users.

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema, Copy)]
pub struct Schedule {
    pub start_time: u64,
    pub cliff: u64,
    pub duration: u64,
}
```

| Key          | Type | Description                                                                                                        |
| ------------ | ---- | ------------------------------------------------------------------------------------------------------------------ |
| `start_time` | u64  | Time when vesting/unlocking starts                                                                                 |
| `cliff`      | u64  | Time when vesting/unlocking starts                                                                                 |
| `duration`   | u64  | Duration of the vesting/unlocking process. At time `start_time + duration`, the tokens are vested/unlocked in full |

## InstantiateMsg

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

```rust
use super::*;

pub type InstantiateMsg = Config<String>;
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "config": {
    "address_provider_address": "terra...", 
    "schedule": {
      "start_time": 123,
      "cliff": 123,
      "duration": 123
    }
  }, 
}
```

{% endtab %}
{% endtabs %}

## ExecuteMsg

### `Receive`

Implementation of 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 %}

### `Withdraw`

Withdraw unlocked MARS token.

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

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

{% endtab %}

{% tab title="JSON" %}

```json
 {
  "withdraw": {}
}
```

{% endtab %}
{% endtabs %}

## ReceiveMsg

### `CreateAllocation`

Creates a new allocation for a recipient.

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

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

{% endtab %}

{% tab title="JSON" %}

```json
{
  "create_allocation": {
    "user_address": "terra...",
    "vest_schedule": 
  }
}
```

{% endtab %}
{% endtabs %}

| Key             | Type     | Description      |
| --------------- | -------- | ---------------- |
| `user_address`  | String   | User address     |
| `vest_schedule` | Schedule | Vesting schedule |

## 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 %}

### `Allocation`

Status of an allocation.&#x20;

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

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

{% endtab %}

{% tab title="JSON" %}

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

{% endtab %}
{% endtabs %}

| Key            |        |                                  |
| -------------- | ------ | -------------------------------- |
| `user_address` | String | User address to query allocation |

### `VotingPowerAt`

A user's locked voting power at a certain height, which equals the user's total allocated Mars token amount minus the amount they have already withdrawn up to that height.

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

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

{% endtab %}

{% tab title="JSON" %}

```json
{
  "voting_power_at": {
    "user_address": "terra...",
    "block": 999
  }
}
```

{% endtab %}
{% endtabs %}

| Key           | Type   | Description                        |
| ------------- | ------ | ---------------------------------- |
| user\_address | String | User address to query voting power |
| block         | u64    | Block height to query voting power |

### `TotalVotingPowerAt`

Total locked voting power owned by the vesting contract at a certain height. Used by Martian Council to calculate a governance proposal's quorum.

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

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

{% endtab %}

{% tab title="JSON" %}

```json
{
  "total_voting_power_at": {
    "block": 999
  }
}
```

{% endtab %}
{% endtabs %}

| Key     | Type | Description                              |
| ------- | ---- | ---------------------------------------- |
| `block` | u64  | Block height to query total voting power |
