astroport/
factory.rs

1use crate::asset::{AssetInfo, PairInfo};
2
3use cosmwasm_schema::{cw_serde, QueryResponses};
4use cosmwasm_std::{Addr, Binary};
5use std::fmt::{Display, Formatter, Result};
6
7const MAX_TOTAL_FEE_BPS: u16 = 10_000;
8const MAX_MAKER_FEE_BPS: u16 = 10_000;
9
10/// This structure holds the main contract parameters.
11#[cw_serde]
12pub struct Config {
13    /// Address allowed to change contract parameters
14    pub owner: Addr,
15    /// CW20 token contract code identifier
16    pub token_code_id: u64,
17    /// Incentives contract address
18    pub generator_address: Option<Addr>,
19    /// Contract address to send governance fees to (the Maker contract)
20    pub fee_address: Option<Addr>,
21    /// CW1 whitelist contract code id used to store 3rd party incentives staking rewards
22    pub whitelist_code_id: u64,
23    /// The address of the contract that contains the coins with their precision
24    pub coin_registry_address: Addr,
25}
26
27/// This enum describes available pair types.
28/// ## Available pool types
29/// ```
30/// # use astroport::factory::PairType::{Custom, Stable, Xyk};
31/// Xyk {};
32/// Stable {};
33/// Custom(String::from("Custom"));
34/// ```
35#[derive(Eq)]
36#[cw_serde]
37pub enum PairType {
38    /// XYK pair type
39    Xyk {},
40    /// Stable pair type
41    Stable {},
42    /// Custom pair type
43    Custom(String),
44}
45
46/// Returns a raw encoded string representing the name of each pool type
47impl Display for PairType {
48    fn fmt(&self, fmt: &mut Formatter) -> Result {
49        match self {
50            PairType::Xyk {} => fmt.write_str("xyk"),
51            PairType::Stable {} => fmt.write_str("stable"),
52            PairType::Custom(pair_type) => fmt.write_str(format!("custom-{}", pair_type).as_str()),
53        }
54    }
55}
56
57/// This structure stores a pair type's configuration.
58#[cw_serde]
59pub struct PairConfig {
60    /// ID of contract which is allowed to create pairs of this type
61    pub code_id: u64,
62    /// The pair type (provided in a [`PairType`])
63    pub pair_type: PairType,
64    /// The total fees (in bps) charged by a pair of this type
65    pub total_fee_bps: u16,
66    /// The amount of fees (in bps) collected by the Maker contract from this pair type
67    pub maker_fee_bps: u16,
68    /// Whether a pair type is disabled or not. If it is disabled, new pairs cannot be
69    /// created, but existing ones can still read the pair configuration
70    /// Default is false.
71    #[serde(default)]
72    pub is_disabled: bool,
73    /// Setting this to true means that pairs of this type will not be able
74    /// to get an ASTRO generator
75    /// Default is false.
76    #[serde(default)]
77    pub is_generator_disabled: bool,
78    /// If pool type is permissioned, only factory owner can create pairs of this type.
79    /// Default is false.
80    #[serde(default)]
81    pub permissioned: bool,
82}
83
84impl PairConfig {
85    /// This method is used to check fee bps.
86    pub fn valid_fee_bps(&self) -> bool {
87        self.total_fee_bps <= MAX_TOTAL_FEE_BPS && self.maker_fee_bps <= MAX_MAKER_FEE_BPS
88    }
89}
90
91/// This structure stores the basic settings for creating a new factory contract.
92#[cw_serde]
93pub struct InstantiateMsg {
94    /// IDs of contracts that are allowed to instantiate pairs
95    pub pair_configs: Vec<PairConfig>,
96    /// CW20 token contract code identifier
97    pub token_code_id: u64,
98    /// Contract address to send governance fees to (the Maker)
99    pub fee_address: Option<String>,
100    /// Address of contract that is used to auto_stake LP tokens once someone provides liquidity in a pool
101    pub generator_address: Option<String>,
102    /// Address of owner that is allowed to change factory contract parameters
103    pub owner: String,
104    /// CW1 whitelist contract code id used to store 3rd party rewards for staking Astroport LP tokens
105    pub whitelist_code_id: u64,
106    /// The address of the contract that contains the coins and their accuracy
107    pub coin_registry_address: String,
108    /// Config for the tracking contract
109    pub tracker_config: Option<TrackerConfig>,
110}
111
112/// This structure describes the execute messages of the contract.
113#[cw_serde]
114pub enum ExecuteMsg {
115    /// UpdateConfig updates relevant code IDs
116    UpdateConfig {
117        /// CW20 token contract code identifier
118        token_code_id: Option<u64>,
119        /// Contract address to send governance fees to (the Maker)
120        fee_address: Option<String>,
121        /// Contract address where Lp tokens can be auto_staked after someone provides liquidity in an incentivized Astroport pool
122        generator_address: Option<String>,
123        /// CW1 whitelist contract code id used to store 3rd party rewards for staking Astroport LP tokens
124        whitelist_code_id: Option<u64>,
125        /// The address of the contract that contains the coins and their accuracy
126        coin_registry_address: Option<String>,
127    },
128    UpdateTrackerConfig {
129        /// Tracking contract code id
130        tracker_code_id: u64,
131        /// Token factory module address
132        token_factory_addr: Option<String>,
133    },
134    /// UpdatePairConfig updates the config for a pair type.
135    UpdatePairConfig {
136        /// New [`PairConfig`] settings for a pair type
137        config: PairConfig,
138    },
139    /// CreatePair instantiates a new pair contract.
140    CreatePair {
141        /// The pair type (exposed in [`PairType`])
142        pair_type: PairType,
143        /// The assets to create the pool for
144        asset_infos: Vec<AssetInfo>,
145        /// Optional binary serialised parameters for custom pool types
146        init_params: Option<Binary>,
147    },
148    /// Deregister removes a previously created pair.
149    Deregister {
150        /// The assets for which we deregister a pool
151        asset_infos: Vec<AssetInfo>,
152    },
153    /// ProposeNewOwner creates a proposal to change contract ownership.
154    /// The validity period for the proposal is set in the `expires_in` variable.
155    ProposeNewOwner {
156        /// Newly proposed contract owner
157        owner: String,
158        /// The date after which this proposal expires
159        expires_in: u64,
160    },
161    /// DropOwnershipProposal removes the existing offer to change contract ownership.
162    DropOwnershipProposal {},
163    /// Used to claim contract ownership.
164    ClaimOwnership {},
165}
166
167/// This structure describes the available query messages for the factory contract.
168#[cw_serde]
169#[derive(QueryResponses)]
170pub enum QueryMsg {
171    /// Config returns contract settings specified in the custom [`ConfigResponse`] structure.
172    #[returns(ConfigResponse)]
173    Config {},
174    /// Pair returns information about a specific pair according to the specified assets.
175    #[returns(PairInfo)]
176    Pair {
177        /// The assets for which we return a pair
178        asset_infos: Vec<AssetInfo>,
179    },
180    /// Pairs returns an array of pairs and their information according to the specified parameters in `start_after` and `limit` variables.
181    #[returns(PairsResponse)]
182    Pairs {
183        /// The pair item to start reading from. It is an [`Option`] type that accepts [`AssetInfo`] elements.
184        start_after: Option<Vec<AssetInfo>>,
185        /// The number of pairs to read and return. It is an [`Option`] type.
186        limit: Option<u32>,
187    },
188    /// FeeInfo returns fee parameters for a specific pair. The response is returned using a [`FeeInfoResponse`] structure
189    #[returns(FeeInfoResponse)]
190    FeeInfo {
191        /// The pair type for which we return fee information. Pair type is a [`PairType`] struct
192        pair_type: PairType,
193    },
194    /// Returns a vector that contains blacklisted pair types
195    #[returns(Vec<PairType>)]
196    BlacklistedPairTypes {},
197    #[returns(TrackerConfig)]
198    TrackerConfig {},
199}
200
201#[cw_serde]
202pub struct MigrateMsg {
203    pub tracker_config: Option<TrackerConfig>,
204}
205
206/// A custom struct for each query response that returns general contract settings/configs.
207#[cw_serde]
208pub struct ConfigResponse {
209    /// Addres of owner that is allowed to change contract parameters
210    pub owner: Addr,
211    /// IDs of contracts which are allowed to create pairs
212    pub pair_configs: Vec<PairConfig>,
213    /// CW20 token contract code identifier
214    pub token_code_id: u64,
215    /// Address of contract to send governance fees to (the Maker)
216    pub fee_address: Option<Addr>,
217    /// Address of contract used to auto_stake LP tokens for Astroport pairs that are incentivized
218    pub generator_address: Option<Addr>,
219    /// CW1 whitelist contract code id used to store 3rd party rewards for staking Astroport LP tokens
220    pub whitelist_code_id: u64,
221    /// The address of the contract that contains the coins and their accuracy
222    pub coin_registry_address: Addr,
223}
224
225/// A custom struct for each query response that returns an array of objects of type [`PairInfo`].
226#[cw_serde]
227pub struct PairsResponse {
228    /// Arrays of structs containing information about multiple pairs
229    pub pairs: Vec<PairInfo>,
230}
231
232/// A custom struct for each query response that returns an object of type [`FeeInfoResponse`].
233#[cw_serde]
234pub struct FeeInfoResponse {
235    /// Contract address to send governance fees to
236    pub fee_address: Option<Addr>,
237    /// Total amount of fees (in bps) charged on a swap
238    pub total_fee_bps: u16,
239    /// Amount of fees (in bps) sent to the Maker contract
240    pub maker_fee_bps: u16,
241}
242
243/// This is an enum used for setting and removing a contract address.
244#[cw_serde]
245pub enum UpdateAddr {
246    /// Sets a new contract address.
247    Set(String),
248    /// Removes a contract address.
249    Remove {},
250}
251
252#[cw_serde]
253pub struct TrackerConfig {
254    /// Tracking contract code id
255    pub code_id: u64,
256    /// Token factory module address
257    pub token_factory_addr: String,
258}