🧰Maker

Contract that accrues and swaps protocol fees to ASTRO

1. Overview

The Maker contract collects fees from each Astroport pair (according to the factory's maker_fee) and tries to swap them to ASTRO. The ASTRO received from each swap is sent to xASTRO stakers and to vxASTRO stakers as well (according to the governance_percent).

The Maker contract code can be found here.

2. Variables & Functions

Constants

Name
Description

BRIDGES_INITIAL_DEPTH

The default bridge depth for a fee token

BRIDGES_MAX_DEPTH

The max amount of bridges that a fee token can have

BRIDGES_EXECUTION_MAX_DEPTH

Swap depth limit when swapping to ASTRO

UUSD_DENOM

UST token denomination

ULUNA_DENOM

LUNA token denomination

CONFIG

Stores the contract configuration at the given key

OWNERSHIP_PROPOSAL

Stores the latest proposal to change contract ownership

BRIDGES

Stores bridge tokens used to swap fee tokens to ASTRO

CONTRACT_NAME

Contract name

CONTRACT_VERSION

Contract version

DEFAULT_MAX_SPREAD

Default maximum spread used when swapping fee tokens to ASTRO

Structs

Name
Description
Contains

InstantiateMsg

This struct holds parameters used to instantiate the Maker contract

  • owner - Address allowed to change contract parameters

  • astro_token_contract - The ASTRO token contract address

  • factory_contract - The factory contract address

  • staking_contract - The xASTRO staking contract address

  • governance_contract - The governance contract address (fee distributor for vxASTRO)

  • governance_percent - The percentage of fees that go to governance_contract

  • max_spread - The maximum spread used when swapping fee tokens to ASTRO

ConfigResponse

This structure describes a custom struct used to return the contract configuration

  • owner - Address allowed to set contract parameters

  • astro_token_contract - The ASTRO token contract address

  • factory_contract - The factory contract address

  • staking_contract - The xASTRO staking contract address

  • governance_contract - The governance contract address (fee distributor for vxASTRO stakers)

  • governance_percent - The percentage of fees that go to governance_contract

  • max_spread - The maximum spread used when swapping fee tokens to ASTRO

  • remainder_reward - The remainder ASTRO tokens (accrued before the Maker is upgraded) to be distributed to xASTRO stakers

  • pre_upgrade_astro_amount - The amount of ASTRO tokens accrued before upgrading the Maker implementation and enabling the reward distribution

BalancesResponse

This struct is used to return multiple asset balances

  • balances - A vector of asset balances

AssetWithLimit

This struct holds parameters to help with swapping a specific amount of a fee token to ASTRO

  • info - Information about the fee token to swap

  • limit - The amount of tokens to swap

Config

This structure stores the main parameters for the Maker contract

  • owner - Address that's allowed to change contract parameters

  • factory_contract - The factory contract address

  • staking_contract - The xASTRO staking contract address

  • governance_contract - The governance contract address (fee distributor for vxASTRO stakers)

  • governance_percent - The percentage of fees that go to governance_contract

  • astro_token_contract - The ASTRO token contract address

  • max_spread - The maximum spread used when swapping fee tokens to ASTRO

  • rewards_enabled - Whether reward distribution is enabled

  • pre_upgrade_blocks - The number of blocks over which ASTRO that accrued pre Maker upgrade will be distributed

  • last_distribution_block - The last block until which pre-upgrade ASTRO will be distributed

  • remainder_reward - The remainder of pre-upgrade ASTRO to distribute

  • pre_upgrade_astro_amount - The amount of collected ASTRO before enabling rewards distribution

Functions

Name
Params
Description

instantiate

(deps: DepsMut, _env: Env, _info: MessageInfo, msg: InstantiateMsg) -> StdResult<Response>

Instantiate the Vesting contract

execute

(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> Result<Response, ContractError>

Execute a function from the contract

collect

(deps: DepsMut, env: Env, assets: Vec<AssetWithLimit>) -> Result<Response, ContractError>

Swaps fee tokens to ASTRO and distribute the resulting ASTRO to xASTRO and vxASTRO stakers

swap_assets

(deps: Deps, env: Env, cfg: &Config, assets: Vec<AssetWithLimit>, with_validation: bool) -> Result<(Response, Vec), ContractError>

Swap non ASTRO tokens to ASTRO

swap

(deps: Deps, cfg: &Config, from_token: AssetInfo, amount_in: Uint128) -> Result<SwapTarget, ContractError>

Internal function that checks if all required pools and bridges exists and performs a swap operation to ASTRO. AssetInfo is imported from the asset file

swap_no_validate

(deps: Deps, cfg: &Config, from_token: AssetInfo, amount_in: Uint128) -> Result<SwapTarget, ContractError>

Internal function that performs a swap operation to ASTRO without additional checks. AssetInfo is imported from the asset file

swap_bridge_assets

(deps: DepsMut, env: Env, info: MessageInfo, assets: Vec<AssetInfo>, depth: u64) -> Result<Response, ContractError>

Internal function that swaps collected fees using bridge assets. AssetInfo is imported from the asset file

update_config

(deps: DepsMut, info: MessageInfo, factory_contract: Option<String>, staking_contract: Option<String>, governance_contract: Option<UpdateAddr>, governance_percent: Option<Uint64>, max_spread: Option<Decimal>) -> Result<Response, ContractError>

Updates general contract parameters

update_bridges

(deps: DepsMut, info: MessageInfo, add: Option<Vec<(AssetInfo, AssetInfo)>>, remove: Option<Vec<AssetInfo>>) -> Result<Response, ContractError>

Adds or removes bridge tokens used to swap fee tokens to ASTRO. Can only be called by governance. AssetInfo is imported from the asset file

query

(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary>

Exposes all the queries available in the contract

query_get_config

(deps: Deps) -> StdResult<ConfigResponse>

Returns information about the Maker configuration

query_get_balances

(deps: Deps, env: Env, assets: Vec) -> StdResult<BalancesResponse>

Returns the Maker's fee token balances for specific tokens

query_bridges

(deps: Deps, _env: Env) -> StdResult<Vec<(String, String)>>

Returns bridge tokens used for swapping fee tokens to ASTRO

query_pair

(deps: Deps, contract_addr: Addr) -> StdResult<[AssetInfo; 2]>

Returns asset information for the specified pair. AssetInfo is imported from the asset file

migrate

(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError>

Used for contract migration

3. Walkthrough

Part of the swap fees from each Astroport pool are sent to the Maker contract. The Maker is designed to swap fee tokens to ASTRO and then send ASTRO to xASTRO and vxASTRO stakers.

collect

Any address can execute the collect operation to swap all the available fee token balances to the ASTRO token and send ASTRO to stakers.

{
  "collect": {
    "pair_addresses": [
      "terra...",
      "terra..."
    ]
  }
}

balances

An address can query for balances to return token balances for each specified asset held by the Maker.

{
  "balances": {
    "assets": [
      {
        "token": {
          "contract_addr": "terra..."
        }
      },
      {
        "native_token": {
          "denom": "uusd"
        }
      }
    ]
  }
}

query_bridges

An address can query the query_bridges operation to return the bridges used for swapping fee tokens denoting Asset -> Bridge connections.

{
  "query_bridges": {}
}

4. Swap Details

Bridges

The Maker contract uses bridge tokens in order to swap different fee tokens to ASTRO. Each fee token can have up to two bridge tokens (e.g A -> B -> UST -> ASTRO). The reason is that many tokens may not have direct pairs with UST, LUNA, or ASTRO and so they cannot be easily swapped to ASTRO without specifying a custom path.

swap_bridge_assets

The Maker contract executes the swap_bridge_assetsoperation to swap collected fees using bridge assets. There is an option to use one or two bridge tokens to swap a fee token to ASTRO. Each fee token can have bridge_1 and bridge_2 set up for this purpose.

  • In some cases, only bridge_1 is specified and bridge_2 will be null. If that's the case, the Maker performs the following swaps: Fee Token → bridge_1 → ASTRO. If this fails, the function reverts

  • In other cases, both bridge_1 and bridge_2 will be specified. If that's the case, the contract performs the following swaps: Fee Token → bridge_1 → bridge_2 → ASTRO. If this fails, the call reverts

  • If both bridges are null, the swap cannot be executed

Restrictions:

  • If only bridge_1 is specified, the contract will check if the bridge_1 token has a direct pair with ASTRO

  • If both bridges are specified, the contract will check if bridge_2 has a direct pair with ASTRO

Flow of Swapping Fee Tokens to ASTRO

The latest flow to swap fee tokens is the following:

  1. Check if the fee token is UST, in which case, swap directly to ASTRO

  2. Check if the fee token is ASTRO itself, in which case there's no need for a swap

  3. Check if the fee token has bridges set up. If yes, use the bridges to swap to ASTRO

  4. Check if the token has a direct pair with UST. If yes, execute the following swaps: Fee Token → UST → ASTRO

  5. Check if the token has a direct pair with LUNA. If yes, execute the following swaps: Fee Token → LUNA -> UST → ASTRO

  6. If all the above fails, check if the token has a direct pair with ASTRO. If yes, swap it directly

Swapping a Portion of the Total Fees

collect and swap_bridge_assets have the option to specify an amount of fee tokens to swap that is smaller than the total amount of fee tokens that the Maker accrued.

This option exists because in some cases, the Maker may accumulate so much of a particular token that swapping everything at once becomes unfeasible.

Checks & restrictions:

  • If the collect or swap_bridge_assets caller specifies an amount of tokens that’s higher than the amount held by the Maker, the Maker will use the total amount of fee tokens it holds

  • If the collect or swap_bridge_assets caller specifies 0 or NULL for the amount of tokens to swap, the Maker will use the total amount of fee tokens it holds

5. Risks

  1. Fee swaps to ASTRO can be frontrun, resulting in suboptimal execution.

  2. Bridge tokens may be set up incorrectly, resulting in suboptimal fee token swaps.

  3. A major bug may lead to the Maker being drained of most or all fee tokens accrued in it.

Last updated

Was this helpful?