> 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/protocol-rewards-collector.md).

# Protocol Rewards Collector

The Protocol Rewards Collector contract receives and distributes protocol fees.

## Links

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

## Config

| Key                         | Type          | Description                                                   |
| --------------------------- | ------------- | ------------------------------------------------------------- |
| `owner`                     | CanonicalAddr | Contract owner                                                |
| `address_provider_address`  | CanonicalAddr | Address provider returns addresses for all protocol contracts |
| `safety_fund_fee_share`     | Decimal       | Percentage of fees that are sent to the safety fund           |
| `treasury_fee_share`        | Decimal       | Percentage of fees that are sent to the treasury              |
| `astroport_factory_address` | CanonicalAddr | Astroport factory contract address                            |
| `astroport_max_spread`      | StdDecimal    | Astroport max spread                                          |

## 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", 
    "safety_fund_fee_share": 0.01,
    "treasury_fee_share": 0.01,
    "astroport_factory_address": "terra...",
    "astroport_max_spread": 0.01
  }
}
```

{% 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 safety_fund_fee_share: Option<Decimal>,
    pub treasury_fee_share: Option<Decimal>,
    pub astroport_factory_address: Option<String>,
    pub astroport_max_spread: Option<StdDecimal>
}
```

| Key                           | Type       | Description                                                   |
| ----------------------------- | ---------- | ------------------------------------------------------------- |
| `owner`\*                     | String     | Contract owner                                                |
| `address_provider_address`\*  | String     | Address provider returns addresses for all protocol contracts |
| `safety_fund_fee_share`\*     | Decimal    | Percentage of fees that are sent to the safety fund           |
| `treasury_fee_share`\*        | Decimal    | Percentage of fees that are sent to the treasury              |
| `astroport_factory_address`\* | String     | Astroport factory contract address                            |
| `astroport_max_spread`\*      | StdDecimal | Astroport max spread                                          |

\* = optional

## ExecuteMsg

### `UpdateConfig`

Update contract 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", 
      "safety_fund_fee_share": 0.01,
      "treasury_fee_share": 0.01,
      "astroport_factory_address": "terra...",
      "astroport_max_spread": 0.01
    }
  }
}
```

{% endtab %}
{% endtabs %}

### `UpdateAssetConfig`

Update asset config.

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

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    UpdateAssetConfig {
        asset: Asset, 
        enabled: bool
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "update_asset_config": {
    "asset": {},
    "enabled": true
  }
}
```

{% endtab %}
{% endtabs %}

| Key       | Type   | Description    |
| --------- | ------ | -------------- |
| `asset`   | String | Asset address  |
| `enabled` | Bool   | Enabled status |

### `WithdrawFromRedBank`

Withdraw maTokens from the red bank.

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

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

{% endtab %}

{% tab title="JSON" %}

```json
{
  "withdraw_from_red_bank": {
    "asset": {},
    "amount": 100000
  }
}
```

{% endtab %}
{% endtabs %}

| Key        | Type    | Description        |
| ---------- | ------- | ------------------ |
| `asset`    | String  | Asset address      |
| `amount`\* | Uint128 | Amount to withdraw |

\* = optional

### `DistributeProtocolRewards`

Distribute the accrued protocol income to the safety fund, treasury, and staking contracts, according to the split set in config. Callable by any address.

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

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

{% endtab %}

{% tab title="JSON" %}

```json
{
  "distribute_protocol_rewards": {
    "asset": {},
    "amount": 100000
  }
}
```

{% endtab %}
{% endtabs %}

| Key        | Type    | Description                                                                               |
| ---------- | ------- | ----------------------------------------------------------------------------------------- |
| `asset`    | String  | Asset market fees to distribute                                                           |
| `amount`\* | Uint128 | Amount to distribute to protocol contracts, defaults to contract balance if not specified |

\* = optional

### `SwapAssetToUusd`

Swap any asset on the contract to uusd.

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

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
    SwapAssetToUusd {
        offer_asset_info: AssetInfo, 
        amount: Otional<Uint128>
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
  "swap_asset_to_uusd": {
    "offer_asset_info": "terra...",
    "amount": 100000
  }
}
```

{% endtab %}
{% endtabs %}

| Key                | Type    | Description                        |
| ------------------ | ------- | ---------------------------------- |
| `offer_asset_info` | String  | Offer asset being swapped for uusd |
| `amount`\*         | Uint128 | Amount being swapped               |

\* = optional

### `ExecuteCosmosMsg`

Execute Cosmos msg (only callable by owner).

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

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

{% endtab %}

{% tab title="JSON" %}

```json
{
  "execute_cosmos_msg": {}
}
```

{% endtab %}
{% endtabs %}

## QueryMsg

### `Config`

Get config parameters.

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

### `AssetConfig`

Get asset config parameters.

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

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

{% endtab %}

{% tab title="JSON" %}

```json
{
  "asset_config": {
    "asset": {}
  }
}
```

{% endtab %}
{% endtabs %}

| Key     | Type   | Description |
| ------- | ------ | ----------- |
| `asset` | String | Asset       |
