Skip to main content

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.

InstantiateMsg

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.

json
factory.rs
Copy

_17
{
_17
"pair_configs:": [{
_17
"code_id": 123,
_17
"pair_type": {
_17
"xyk": {}
_17
},
_17
"total_fee_bps": 100,
_17
"maker_fee_bps": 10,
_17
"is_disabled": false,
_17
"is_generator_disabled": false
_17
}],
_17
"token_code_id": 123,
_17
"fee_address": "...",
_17
"generator_address": "terra...",
_17
"owner": "terra...",
_17
"whitelist_code_id": 123
_17
}

ParamsTypeDescription
pair_configsVec<PairConfig>IDs of contracts that are allowed to instantiate pairs
token_code_idu64CW20 token contract code identifier
fee_addressOption<String>Contract address to send governance fees to (the Maker)
generator_addressOption<String>Address of contract that is used to auto_stake LP tokens once someone provides liquidity in a pool
ownerStringAddress of owner that is allowed to change factory contract parameters
whitelist_code_idu64CW1 whitelist contract code id used to store 3rd party rewards for staking Astroport LP tokens

PairConfig

This struct stores a pair type's configuration.

json
factory.rs
Copy

_10
{
_10
"code_id": 123,
_10
"pair_type": {
_10
"xyk": {}
_10
},
_10
"total_fee_bps": 100,
_10
"maker_fee_bps": 10,
_10
"is_disabled": false,
_10
"is_generator_disabled": false
_10
}

ParamsTypeDescription
code_idu64ID of contract which is allowed to create pairs of this type
pair_typePairTypeThe pair type (provided in a [PairType])
total_fee_bpsu16The total fees (in bps) charged by a pair of this type
maker_fee_bpsu16The amount of fees (in bps) collected by the Maker contract from this pair type
is_disabledboolWhether 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_disabledboolSetting this to true means that pairs of this type will not be able to get an ASTRO generator

PairType

This enum describes available pair types.

factory.rs
Copy

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

VariantsDescription
XykXYK pair type
StableStable pair type
CustomCustom pair type

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.

json
factory.rs
Copy

_8
{
_8
"update_config": {
_8
"token_code_id": 123,
_8
"fee_address": "terra...",
_8
"generator_address": "terra...",
_8
"whitelist_code_id": 123
_8
}
_8
}

ParamsTypeDescription
token_code_idu64CW20 token contract code identifier
fee_addressOption<String>Contract address to send governance fees to (the Maker)
generator_addressOption<String>Address of contract that is used to auto_stake LP tokens once someone provides liquidity in a pool
whitelist_code_idu64CW1 whitelist contract code id used to store 3rd party rewards for staking Astroport LP tokens

update_pair_config

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%

json
factory.rs
Copy

_14
{
_14
"update_pair_config": {
_14
"config": {
_14
"code_id": 123,
_14
"pair_type": {
_14
"xyk": {}
_14
},
_14
"total_fee_bps": 100,
_14
"maker_fee_bps": 10,
_14
"is_disabled": false,
_14
"is_generator_disabled": false
_14
}
_14
}
_14
}

ParamsTypeDescription
configPairConfigNew [PairConfig] settings for a pair type

create_pair

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.

json
factory.rs
Copy

_20
{
_20
"create_pair": {
_20
"pair_type": {
_20
"xyk": {}
_20
},
_20
"asset_infos": [
_20
{
_20
"token": {
_20
"contract_addr": "..."
_20
}
_20
},
_20
{
_20
"native_token": {
_20
"denom": "..."
_20
}
_20
}
_20
],
_20
"init_params": "<base64_encoded_json_string>"
_20
}
_20
}

ParamsTypeDescription
pair_typePairTypeThe pair type (exposed in [PairType])
asset_infosVec<AssetInfo>The assets to create the pool for
init_paramsOption<Binary>Optional binary serialised parameters for custom pool types

deregister

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".

json
factory.rs
Copy

_16
{
_16
"deregister": {
_16
"asset_infos": [
_16
{
_16
"token": {
_16
"contract_addr": "..."
_16
}
_16
},
_16
{
_16
"native_token": {
_16
"denom": "..."
_16
}
_16
}
_16
]
_16
}
_16
}

ParamsTypeDescription
asset_infosVec<AssetInfo>The assets for which we deregister a pool

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.

json
factory.rs
Copy

_6
{
_6
"propose_new_owner": {
_6
"owner": "...",
_6
"expires_in": 1234567
_6
}
_6
}

ParamsTypeDescription
ownerStringNewly proposed contract owner
expires_inu64The date after which this proposal expires

drop_ownership_proposal

Removes an existing offer to change the contract owner.

json
factory.rs
Copy

_3
{
_3
"drop_ownership_proposal": {}
_3
}

claim_ownership

Used to claim contract ownership.

json
factory.rs
Copy

_3
{
_3
"claim_ownership": {}
_3
}

mark_as_migrated

Mark pairs as migrated.

json
factory.rs
Copy

_8
{
_8
"mask_as_migrated": {
_8
"pairs": [
_8
"terra...",
_8
"terra..."
_8
]
_8
}
_8
}

ParamsTypeDescription
pairsVec<String>Migrated pairs

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).

json
factory.rs
Copy

_3
{
_3
"config": {}
_3
}

ConfigResponse

json
factory.rs
Copy

_29
{
_29
"owner": "terra...",
_29
"pair_configs": [
_29
{
_29
"code_id": 428,
_29
"pair_type": {
_29
"stable": {}
_29
},
_29
"total_fee_bps": 5,
_29
"maker_fee_bps": 5000,
_29
"is_disabled": false,
_29
"is_generator_disabled": false
_29
},
_29
{
_29
"code_id": 392,
_29
"pair_type": {
_29
"xyk": {}
_29
},
_29
"total_fee_bps": 30,
_29
"maker_fee_bps": 3333,
_29
"is_disabled": false,
_29
"is_generator_disabled": false
_29
}
_29
],
_29
"token_code_id": 123,
_29
"fee_address": "terra...",
_29
"generator_address": "terra...",
_29
"whitelist_code_id": 123
_29
}

ParamsTypeDescription
ownerAddrAddres of owner that is allowed to change contract parameters
pair_configsVec<PairConfig>IDs of contracts which are allowed to create pairs
token_code_idu64CW20 token contract code identifier
fee_addressOption<Addr>Address of contract to send governance fees to (the Maker)
generator_addressOption<Addr>Address of contract used to auto_stake LP tokens for Astroport pairs that are incentivized
whitelist_code_idu64CW1 whitelist contract code id used to store 3rd party rewards for staking Astroport LP tokens

pair

Queries information about a specific pair.

json
factory.rs
Copy

_16
{
_16
"pair": {
_16
"asset_infos": [
_16
{
_16
"token": {
_16
"contract_addr": "..."
_16
}
_16
},
_16
{
_16
"native_token": {
_16
"denom": "..."
_16
}
_16
}
_16
]
_16
}
_16
}

ParamsTypeDescription
asset_infosVec<AssetInfo>The assets in the pair

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.

json
factory.rs
Copy

_17
{
_17
"pairs": {
_17
"start_after": [
_17
{
_17
"token": {
_17
"contract_addr": "..."
_17
}
_17
},
_17
{
_17
"native_token": {
_17
"denom": "..."
_17
}
_17
}
_17
],
_17
"limit": 10
_17
}
_17
}

ParamsTypeDescription
start_afterOption<Vec<AssetInfo>>The pair item to start reading from. It is an [Option] type that accepts [AssetInfo] elements
limitOption<u32>The number of pairs to read and return. It is an [Option] type

PairsResponse

json
factory.rs
Copy

_25
{
_25
"pairs": [
_25
{
_25
"asset_infos": [
_25
{
_25
"token": {
_25
"contract_addr": "..."
_25
}
_25
_25
},
_25
{
_25
"native_token": {
_25
"denom": "..."
_25
}
_25
}
_25
],
_25
"contract_addr": "...",
_25
"liquidity_token": "...",
_25
"pair_type": {
_25
"xyk": {}
_25
}
_25
},
_25
...etc
_25
]
_25
}

ParamsTypeDescription
pairsVec<PairInfo>Arrays of structs containing information about multiple pairs

fee_info

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

json
factory.rs
Copy

_7
{
_7
"fee_info": {
_7
"pair_type": {
_7
"xyk": {}
_7
}
_7
}
_7
}

ParamsTypeDescription
pair_typePairTypeThe pair type for which we return fee information. Pair type is a [PairType] struct

FeeInfoResponse

json
factory.rs
Copy

_5
{
_5
"fee_address": "...",
_5
"total_fee_bps": 123,
_5
"maker_fee_bps": 123
_5
}

ParamsTypeDescription
fee_addressOption<Addr>Contract address to send governance fees to
total_fee_bpsu16Total amount of fees (in bps) charged on a swap
maker_fee_bpsu16Amount of fees (in bps) sent to the Maker contract

blacklisted_pair_types

Returns a vector that contains blacklisted pair types.

json
factory.rs
Copy

_3
{
_3
"blacklisted_pair_types": {}
_3
}

blacklisted_pair_types returns a Vec<PairType>

pairs_to_migrate

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

json
factory.rs
Copy

_3
{
_3
"pairs_to_migrate": {}
_3
}