Skip to content

Latest commit

 

History

History
1082 lines (896 loc) · 25.8 KB

factory.mdx

File metadata and controls

1082 lines (896 loc) · 25.8 KB
sidebar_position
3

Factory

Overview

The factory contract can create new Astroport pair contracts (and associated LP token contracts) which are tracked in a registry and used as a directory for all pairs. The default pair types are constant product and stableswap but governance may decide to add custom pools that can have any implementation.

Links

InstantiateMsg

<CH.Section>

The instantiation message takes in the token code ID for the token type supported on Astroport. It also takes in the fee_address that collects fees for governance, the contract owner, the Generator contract address and the initial pair types available to create.

<CH.Code>

{
    "pair_configs:": [{
        "code_id": 123, 
        "pair_type": {
            "xyk": {}
        }, 
        "total_fee_bps": 100, 
        "maker_fee_bps": 10,
        "is_disabled": false, 
        "is_generator_disabled": false
    }], 
    "token_code_id": 123, 
    "fee_address": "...", 
    "generator_address": "terra...", 
    "owner": "terra...", 
    "whitelist_code_id": 123
}
#[cw_serde]
pub struct InstantiateMsg {
    pub pair_configs: Vec<PairConfig>,
    pub token_code_id: u64,
    pub fee_address: Option<String>,
    pub generator_address: Option<String>,
    pub owner: String,
    pub whitelist_code_id: u64,
}

</CH.Code>

Params Type Description
pair_configs Vec<PairConfig> IDs of contracts that are allowed to instantiate pairs
token_code_id u64 CW20 token contract code identifier
fee_address Option<String> Contract address to send governance fees to (the Maker)
generator_address Option<String> Address of contract that is used to auto_stake LP tokens once someone provides liquidity in a pool
owner String Address of owner that is allowed to change factory contract parameters
whitelist_code_id u64 CW1 whitelist contract code id used to store 3rd party rewards for staking Astroport LP tokens

</CH.Section>

PairConfig

This struct stores a pair type's configuration.

<CH.Section> <CH.Code>

{
    "code_id": 123, 
    "pair_type": {
        "xyk": {}
    }, 
    "total_fee_bps": 100, 
    "maker_fee_bps": 10,
    "is_disabled": false, 
    "is_generator_disabled": false
}
#[cw_serde]
pub struct PairConfig {
    pub code_id: u64,
    pub pair_type: PairType,
    pub total_fee_bps: u16,
    pub maker_fee_bps: u16,
    pub is_disabled: bool,
    pub is_generator_disabled: bool,
}

</CH.Code>

Params Type Description
code_id u64 ID of contract which is allowed to create pairs of this type
pair_type PairType The pair type (provided in a [PairType])
total_fee_bps u16 The total fees (in bps) charged by a pair of this type
maker_fee_bps u16 The amount of fees (in bps) collected by the Maker contract from this pair type
is_disabled bool Whether a pair type is disabled or not. If it is disabled, new pairs cannot be created, but existing ones can still read the pair configuration
is_generator_disabled bool Setting this to true means that pairs of this type will not be able to get an ASTRO generator

</CH.Section>

PairType

This enum describes available pair types.

<CH.Section> <CH.Code>

#[cw_serde]
pub enum PairType {
    Xyk {},
    Stable {},
    Custom(String),
}

</CH.Code>

Variants Description
Xyk XYK pair type
Stable Stable pair type
Custom Custom pair type

</CH.Section>

ExecuteMsg

update_config

Updates contract variables, namely the code ID of the token implementation used in Astroport, the address that receives governance fees and the Generator contract address.

<CH.Section> <CH.Code>

{
  "update_config": {
    "token_code_id": 123,
    "fee_address": "terra...",
    "generator_address": "terra...", 
    "whitelist_code_id": 123
  }
}
#[cw_serde]
pub enum ExecuteMsg {
    UpdateConfig {
        token_code_id: Option<u64>,
        fee_address: Option<String>,
        generator_address: Option<String>,
        whitelist_code_id: Option<u64>,
    },
    UpdatePairConfig {
        config: PairConfig,
    },
    CreatePair {
        pair_type: PairType,
        asset_infos: Vec<AssetInfo>,
        init_params: Option<Binary>,
    },
    Deregister {
        asset_infos: Vec<AssetInfo>,
    },
    ProposeNewOwner {
        owner: String,
        expires_in: u64,
    },
    DropOwnershipProposal {},
    ClaimOwnership {},
    MarkAsMigrated { pairs: Vec<String> },
}

</CH.Code>

Params Type Description
token_code_id u64 CW20 token contract code identifier
fee_address Option<String> Contract address to send governance fees to (the Maker)
generator_address Option<String> Address of contract that is used to auto_stake LP tokens once someone provides liquidity in a pool
whitelist_code_id u64 CW1 whitelist contract code id used to store 3rd party rewards for staking Astroport LP tokens

</CH.Section>

update_pair_config

<CH.Section>

This function can be used to:

  • Update the code ID used to instantiate new pairs of a specific type
  • Change the fee structure for a pair
  • Disable the pair type so no other pairs can be instantiated

Note that all fields are optional.

The fee structure for a pair is set up as follows:

  • total_fee_bps is the total amount of fees (in bps) that are charged on each swap
  • maker_fee_bps is the percentage of fees out of total_fee_bps that is sent to governance. 100% is 10,000

As an example, let's say a pool charged 30bps (total_fee_bps is 30) and we want 1/3r of the fees to go to governance. In this case, maker_fee_bps should be 3333 because 3333 / 10,000 * 30 / 100 = 0.1%

<CH.Code>

{
    "update_pair_config": {
        "config": {
            "code_id": 123, 
            "pair_type": {
                "xyk": {}
            }, 
            "total_fee_bps": 100, 
            "maker_fee_bps": 10,
            "is_disabled": false, 
            "is_generator_disabled": false
        }
    }
}
#[cw_serde]
pub enum ExecuteMsg {
    UpdateConfig {
        token_code_id: Option<u64>,
        fee_address: Option<String>,
        generator_address: Option<String>,
        whitelist_code_id: Option<u64>,
    },
    UpdatePairConfig {
        config: PairConfig,
    },
    CreatePair {
        pair_type: PairType,
        asset_infos: Vec<AssetInfo>,
        init_params: Option<Binary>,
    },
    Deregister {
        asset_infos: Vec<AssetInfo>,
    },
    ProposeNewOwner {
        owner: String,
        expires_in: u64,
    },
    DropOwnershipProposal {},
    ClaimOwnership {},
    MarkAsMigrated { pairs: Vec<String> },
}

</CH.Code>

Params Type Description
config PairConfig New [PairConfig] settings for a pair type

</CH.Section>

create_pair

<CH.Section>

Anyone can execute this function to create an Astroport pair. CreatePair creates both a Pair contract and a LP(liquidity provider) token contract. The account that instantiates the pair must specify the pair type they want as well as the assets for which the pool is created.

Custom pool types may also need extra parameters which can be packed in init_params.

<CH.Code>

{
  "create_pair": {
    "pair_type": {
      "xyk": {}
    },
    "asset_infos": [
      {
        "token": {
          "contract_addr": "..."
        }
      },
      {
        "native_token": {
          "denom": "..."
        }
      }
    ],
    "init_params": "<base64_encoded_json_string>"
  }
}
#[cw_serde]
pub enum ExecuteMsg {
    UpdateConfig {
        token_code_id: Option<u64>,
        fee_address: Option<String>,
        generator_address: Option<String>,
        whitelist_code_id: Option<u64>,
    },
    UpdatePairConfig {
        config: PairConfig,
    },
    CreatePair {
        pair_type: PairType,
        asset_infos: Vec<AssetInfo>,
        init_params: Option<Binary>,
    },
    Deregister {
        asset_infos: Vec<AssetInfo>,
    },
    ProposeNewOwner {
        owner: String,
        expires_in: u64,
    },
    DropOwnershipProposal {},
    ClaimOwnership {},
    MarkAsMigrated { pairs: Vec<String> },
}

</CH.Code>

Params Type Description
pair_type PairType The pair type (exposed in [PairType])
asset_infos Vec<AssetInfo> The assets to create the pool for
init_params Option<Binary> Optional binary serialised parameters for custom pool types

</CH.Section>

deregister

<CH.Section>

Deregisters an already registered pair. This allows someone else to create a new pair (of any type) for the tokens that don't have a registered pair anymore. This is how pairs can be "upgraded".

<CH.Code>

{
    "deregister": {
        "asset_infos": [
            {
                "token": {
                    "contract_addr": "..."
                }
            },
            {
                "native_token": {
                    "denom": "..."
                }
            }
        ]
    }
}
#[cw_serde]
pub enum ExecuteMsg {
    UpdateConfig {
        token_code_id: Option<u64>,
        fee_address: Option<String>,
        generator_address: Option<String>,
        whitelist_code_id: Option<u64>,
    },
    UpdatePairConfig {
        config: PairConfig,
    },
    CreatePair {
        pair_type: PairType,
        asset_infos: Vec<AssetInfo>,
        init_params: Option<Binary>,
    },
    Deregister {
        asset_infos: Vec<AssetInfo>,
    },
    ProposeNewOwner {
        owner: String,
        expires_in: u64,
    },
    DropOwnershipProposal {},
    ClaimOwnership {},
    MarkAsMigrated { pairs: Vec<String> },
}

</CH.Code>

Params Type Description
asset_infos Vec<AssetInfo> The assets for which we deregister a pool

</CH.Section>

propose_new_owner

Creates an offer to change the contract ownership. The validity period of the offer is set in the expires_in variable. After expires_in seconds pass, the proposal expires and cannot be accepted anymore.

<CH.Section> <CH.Code>

{
  "propose_new_owner": {
    "owner": "...",
    "expires_in": 1234567
  }
}
#[cw_serde]
pub enum ExecuteMsg {
    UpdateConfig {
        token_code_id: Option<u64>,
        fee_address: Option<String>,
        generator_address: Option<String>,
        whitelist_code_id: Option<u64>,
    },
    UpdatePairConfig {
        config: PairConfig,
    },
    CreatePair {
        pair_type: PairType,
        asset_infos: Vec<AssetInfo>,
        init_params: Option<Binary>,
    },
    Deregister {
        asset_infos: Vec<AssetInfo>,
    },
    ProposeNewOwner {
        owner: String,
        expires_in: u64,
    },
    DropOwnershipProposal {},
    ClaimOwnership {},
    MarkAsMigrated { pairs: Vec<String> },
}

</CH.Code>

Params Type Description
owner String Newly proposed contract owner
expires_in u64 The date after which this proposal expires

</CH.Section>

drop_ownership_proposal

Removes an existing offer to change the contract owner.

<CH.Code>

{
  "drop_ownership_proposal": {}
}
#[cw_serde]
pub enum ExecuteMsg {
    UpdateConfig {
        token_code_id: Option<u64>,
        fee_address: Option<String>,
        generator_address: Option<String>,
        whitelist_code_id: Option<u64>,
    },
    UpdatePairConfig {
        config: PairConfig,
    },
    CreatePair {
        pair_type: PairType,
        asset_infos: Vec<AssetInfo>,
        init_params: Option<Binary>,
    },
    Deregister {
        asset_infos: Vec<AssetInfo>,
    },
    ProposeNewOwner {
        owner: String,
        expires_in: u64,
    },
    DropOwnershipProposal {},
    ClaimOwnership {},
    MarkAsMigrated { pairs: Vec<String> },
}

</CH.Code>

claim_ownership

Used to claim contract ownership.

<CH.Code>

{
  "claim_ownership": {}
}
#[cw_serde]
pub enum ExecuteMsg {
    UpdateConfig {
        token_code_id: Option<u64>,
        fee_address: Option<String>,
        generator_address: Option<String>,
        whitelist_code_id: Option<u64>,
    },
    UpdatePairConfig {
        config: PairConfig,
    },
    CreatePair {
        pair_type: PairType,
        asset_infos: Vec<AssetInfo>,
        init_params: Option<Binary>,
    },
    Deregister {
        asset_infos: Vec<AssetInfo>,
    },
    ProposeNewOwner {
        owner: String,
        expires_in: u64,
    },
    DropOwnershipProposal {},
    ClaimOwnership {},
    MarkAsMigrated { pairs: Vec<String> },
}

</CH.Code>

mark_as_migrated

Mark pairs as migrated.

<CH.Section> <CH.Code>

{
    "mask_as_migrated": {
        "pairs": [
            "terra...", 
            "terra..."
        ]
    }
}
#[cw_serde]
pub enum ExecuteMsg {
    UpdateConfig {
        token_code_id: Option<u64>,
        fee_address: Option<String>,
        generator_address: Option<String>,
        whitelist_code_id: Option<u64>,
    },
    UpdatePairConfig {
        config: PairConfig,
    },
    CreatePair {
        pair_type: PairType,
        asset_infos: Vec<AssetInfo>,
        init_params: Option<Binary>,
    },
    Deregister {
        asset_infos: Vec<AssetInfo>,
    },
    ProposeNewOwner {
        owner: String,
        expires_in: u64,
    },
    DropOwnershipProposal {},
    ClaimOwnership {},
    MarkAsMigrated { pairs: Vec<String> },
}

</CH.Code>

Params Type Description
pairs Vec<String> Migrated pairs

</CH.Section>

QueryMsg

All query messages are described below. A custom struct is defined for each query response.

config

Queries general factory parameters (owner, token code ID, pair type configurations).

<CH.Section> <CH.Code>

{
  "config": {}
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(ConfigResponse)]
    Config {},
    #[returns(PairInfo)]
    Pair {
        asset_infos: Vec<AssetInfo>,
    },
    #[returns(PairsResponse)]
    Pairs {
        start_after: Option<Vec<AssetInfo>>,
        limit: Option<u32>,
    },
    #[returns(FeeInfoResponse)]
    FeeInfo {
        pair_type: PairType,
    },
    #[returns(Vec<PairType>)]
    BlacklistedPairTypes {},
    #[returns(Vec<Addr>)]
    PairsToMigrate {},
}

</CH.Code> </CH.Section>

ConfigResponse

<CH.Section> <CH.Code>

{
    "owner": "terra...", 
    "pair_configs": [
        {
            "code_id": 428, 
            "pair_type": {
                "stable": {}
            },
            "total_fee_bps": 5, 
            "maker_fee_bps": 5000, 
            "is_disabled": false, 
            "is_generator_disabled": false
        }, 
        {
            "code_id": 392, 
            "pair_type": {
                "xyk": {}
            },
            "total_fee_bps": 30, 
            "maker_fee_bps": 3333, 
            "is_disabled": false, 
            "is_generator_disabled": false
        }
    ],
    "token_code_id": 123, 
    "fee_address": "terra...", 
    "generator_address": "terra...", 
    "whitelist_code_id": 123
}
#[cw_serde]
pub struct ConfigResponse {
    pub owner: Addr,
    pub pair_configs: Vec<PairConfig>,
    pub token_code_id: u64,
    pub fee_address: Option<Addr>,
    pub generator_address: Option<Addr>,
    pub whitelist_code_id: u64,
}

</CH.Code>

Params Type Description
owner Addr Addres of owner that is allowed to change contract parameters
pair_configs Vec<PairConfig> IDs of contracts which are allowed to create pairs
token_code_id u64 CW20 token contract code identifier
fee_address Option<Addr> Address of contract to send governance fees to (the Maker)
generator_address Option<Addr> Address of contract used to auto_stake LP tokens for Astroport pairs that are incentivized
whitelist_code_id u64 CW1 whitelist contract code id used to store 3rd party rewards for staking Astroport LP tokens

</CH.Section>

pair

Queries information about a specific pair.

<CH.Section> <CH.Code>

{
    "pair": {
        "asset_infos": [
            {
                "token": {
                    "contract_addr": "..."
                }
            },
            {
                "native_token": {
                    "denom": "..."
                }
            }
        ]
    }
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(ConfigResponse)]
    Config {},
    #[returns(PairInfo)]
    Pair {
        asset_infos: Vec<AssetInfo>,
    },
    #[returns(PairsResponse)]
    Pairs {
        start_after: Option<Vec<AssetInfo>>,
        limit: Option<u32>,
    },
    #[returns(FeeInfoResponse)]
    FeeInfo {
        pair_type: PairType,
    },
    #[returns(Vec<PairType>)]
    BlacklistedPairTypes {},
    #[returns(Vec<Addr>)]
    PairsToMigrate {},
}

</CH.Code>

Params Type Description
asset_infos Vec<AssetInfo> The assets in the pair

</CH.Section>

Returns a PairInfo response struct.

pairs

Queries information about multiple pairs (the result is paginated). The function starts returning pair information starting after the pair start_after. The function returns maximum limit pairs.

<CH.Section> <CH.Code>

{
    "pairs": {
        "start_after": [
            {
                "token": {
                    "contract_addr": "..."
                }
            }, 
            {
                "native_token": {
                    "denom": "..."
                }
            }
        ], 
        "limit": 10
    }
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(ConfigResponse)]
    Config {},
    #[returns(PairInfo)]
    Pair {
        asset_infos: Vec<AssetInfo>,
    },
    #[returns(PairsResponse)]
    Pairs {
        start_after: Option<Vec<AssetInfo>>,
        limit: Option<u32>,
    },
    #[returns(FeeInfoResponse)]
    FeeInfo {
        pair_type: PairType,
    },
    #[returns(Vec<PairType>)]
    BlacklistedPairTypes {},
    #[returns(Vec<Addr>)]
    PairsToMigrate {},
}

</CH.Code>

Params Type Description
start_after Option<Vec<AssetInfo>> The pair item to start reading from. It is an [Option] type that accepts [AssetInfo] elements
limit Option<u32> The number of pairs to read and return. It is an [Option] type

</CH.Section>

PairsResponse

<CH.Section> <CH.Code>

{
    "pairs": [
        {
            "asset_infos": [
                {
                    "token": {
                        "contract_addr": "..."
                    }

                },
                {
                    "native_token": {
                        "denom": "..."
                    }
                }
            ], 
            "contract_addr": "...", 
            "liquidity_token": "...", 
            "pair_type": {
                "xyk": {}
            }
        }, 
        ...etc
    ]
}
#[cw_serde]
pub struct PairsResponse {
    pub pairs: Vec<PairInfo>,
}

</CH.Code>

Params Type Description
pairs Vec<PairInfo> Arrays of structs containing information about multiple pairs

</CH.Section>

fee_info

Queries fee information for a specific pair type (total_fee_bps and maker_fee_bps).

<CH.Section> <CH.Code>

{
    "fee_info": {
        "pair_type": {
            "xyk": {}
        }
    }
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(ConfigResponse)]
    Config {},
    #[returns(PairInfo)]
    Pair {
        asset_infos: Vec<AssetInfo>,
    },
    #[returns(PairsResponse)]
    Pairs {
        start_after: Option<Vec<AssetInfo>>,
        limit: Option<u32>,
    },
    #[returns(FeeInfoResponse)]
    FeeInfo {
        pair_type: PairType,
    },
    #[returns(Vec<PairType>)]
    BlacklistedPairTypes {},
    #[returns(Vec<Addr>)]
    PairsToMigrate {},
}

</CH.Code>

Params Type Description
pair_type PairType The pair type for which we return fee information. Pair type is a [PairType] struct

</CH.Section>

FeeInfoResponse

<CH.Section> <CH.Code>

{
    "fee_address": "...", 
    "total_fee_bps": 123, 
    "maker_fee_bps": 123
}
#[cw_serde]
pub struct FeeInfoResponse {
    pub fee_address: Option<Addr>,
    pub total_fee_bps: u16,
    pub maker_fee_bps: u16,
}

</CH.Code>

Params Type Description
fee_address Option<Addr> Contract address to send governance fees to
total_fee_bps u16 Total amount of fees (in bps) charged on a swap
maker_fee_bps u16 Amount of fees (in bps) sent to the Maker contract

</CH.Section>

blacklisted_pair_types

Returns a vector that contains blacklisted pair types.

<CH.Code>

{
  "blacklisted_pair_types": {}
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(ConfigResponse)]
    Config {},
    #[returns(PairInfo)]
    Pair {
        asset_infos: Vec<AssetInfo>,
    },
    #[returns(PairsResponse)]
    Pairs {
        start_after: Option<Vec<AssetInfo>>,
        limit: Option<u32>,
    },
    #[returns(FeeInfoResponse)]
    FeeInfo {
        pair_type: PairType,
    },
    #[returns(Vec<PairType>)]
    BlacklistedPairTypes {},
    #[returns(Vec<Addr>)]
    PairsToMigrate {},
}

</CH.Code>

blacklisted_pair_types returns a Vec<PairType>

pairs_to_migrate

Returns a vector that contains pair addresses that are not migrated.

<CH.Section> <CH.Code>

{
  "pairs_to_migrate": {}
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(ConfigResponse)]
    Config {},
    #[returns(PairInfo)]
    Pair {
        asset_infos: Vec<AssetInfo>,
    },
    #[returns(PairsResponse)]
    Pairs {
        start_after: Option<Vec<AssetInfo>>,
        limit: Option<u32>,
    },
    #[returns(FeeInfoResponse)]
    FeeInfo {
        pair_type: PairType,
    },
    #[returns(Vec<PairType>)]
    BlacklistedPairTypes {},
    #[returns(Vec<Addr>)]
    PairsToMigrate {},
}

</CH.Code> </CH.Section>