From 738430f93028a0d3db0a8762882d0e44031dbf7f Mon Sep 17 00:00:00 2001 From: Sawit Trisirisatayawong Date: Tue, 5 Apr 2022 13:19:24 +0700 Subject: [PATCH] feat: use astroport crate v1.0 instead of package v0.31 --- contracts/nebula-cluster-factory/Cargo.toml | 2 +- contracts/nebula-cluster/Cargo.toml | 2 +- contracts/nebula-collector/Cargo.toml | 2 +- contracts/nebula-community/Cargo.toml | 2 +- contracts/nebula-incentives/Cargo.toml | 2 +- contracts/nebula-lp-staking/Cargo.toml | 2 +- contracts/nebula-oracle/Cargo.toml | 2 +- packages/astroport/.cargo/config | 4 - packages/astroport/Cargo.toml | 28 -- packages/astroport/README.md | 127 ------- packages/astroport/src/asset.rs | 371 -------------------- packages/astroport/src/common.rs | 141 -------- packages/astroport/src/factory.rs | 203 ----------- packages/astroport/src/generator.rs | 205 ----------- packages/astroport/src/generator_proxy.rs | 93 ----- packages/astroport/src/lib.rs | 63 ---- packages/astroport/src/maker.rs | 111 ------ packages/astroport/src/mock_querier.rs | 298 ---------------- packages/astroport/src/oracle.rs | 43 --- packages/astroport/src/pair.rs | 164 --------- packages/astroport/src/querier.rs | 264 -------------- packages/astroport/src/router.rs | 131 ------- packages/astroport/src/staking.rs | 58 --- packages/astroport/src/testing.rs | 354 ------------------- packages/astroport/src/token.rs | 81 ----- packages/astroport/src/vesting.rs | 161 --------- packages/nebula_protocol/Cargo.toml | 2 +- 27 files changed, 8 insertions(+), 2908 deletions(-) delete mode 100644 packages/astroport/.cargo/config delete mode 100644 packages/astroport/Cargo.toml delete mode 100644 packages/astroport/README.md delete mode 100644 packages/astroport/src/asset.rs delete mode 100644 packages/astroport/src/common.rs delete mode 100644 packages/astroport/src/factory.rs delete mode 100644 packages/astroport/src/generator.rs delete mode 100644 packages/astroport/src/generator_proxy.rs delete mode 100644 packages/astroport/src/lib.rs delete mode 100644 packages/astroport/src/maker.rs delete mode 100644 packages/astroport/src/mock_querier.rs delete mode 100644 packages/astroport/src/oracle.rs delete mode 100644 packages/astroport/src/pair.rs delete mode 100644 packages/astroport/src/querier.rs delete mode 100644 packages/astroport/src/router.rs delete mode 100644 packages/astroport/src/staking.rs delete mode 100644 packages/astroport/src/testing.rs delete mode 100644 packages/astroport/src/token.rs delete mode 100644 packages/astroport/src/vesting.rs diff --git a/contracts/nebula-cluster-factory/Cargo.toml b/contracts/nebula-cluster-factory/Cargo.toml index b50ffefb..0170c5b3 100644 --- a/contracts/nebula-cluster-factory/Cargo.toml +++ b/contracts/nebula-cluster-factory/Cargo.toml @@ -21,7 +21,7 @@ backtraces = ["cosmwasm-std/backtraces"] [dependencies] cw20 = { version = "0.8.0" } -astroport = { path = "../../packages/astroport" } +astroport = { version = "1.0" } cluster-math = { path = "../../libraries/cluster-math" } cosmwasm-std = { version = "0.16.2", default-features = false } cosmwasm-storage = { version = "0.16.2", default-features = false, features = ["iterator"] } diff --git a/contracts/nebula-cluster/Cargo.toml b/contracts/nebula-cluster/Cargo.toml index f2d49698..e360c427 100644 --- a/contracts/nebula-cluster/Cargo.toml +++ b/contracts/nebula-cluster/Cargo.toml @@ -28,7 +28,7 @@ serde = { version = "1.0.103", default-features = false, features = ["derive"] } snafu = { version = "0.6.3" } cw20 = { version = "0.8.0" } base64 = "*" -astroport = { path = "../../packages/astroport" } +astroport = { version = "1.0" } cluster-math = { path = "../../libraries/cluster-math" } nebula-protocol = { version = "1.0.0", path = "../../packages/nebula_protocol" } thiserror = { version = "1.0.30" } diff --git a/contracts/nebula-collector/Cargo.toml b/contracts/nebula-collector/Cargo.toml index 63f1773c..97158943 100644 --- a/contracts/nebula-collector/Cargo.toml +++ b/contracts/nebula-collector/Cargo.toml @@ -24,7 +24,7 @@ backtraces = ["cosmwasm-std/backtraces"] cw20 = { version = "0.8.0" } cosmwasm-std = { version = "0.16.2", default-features = false} cosmwasm-storage = { version = "0.16.2" } -astroport = { path = "../../packages/astroport" } +astroport = { version = "1.0" } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } nebula-protocol = { version = "1.0.0", path = "../../packages/nebula_protocol" } diff --git a/contracts/nebula-community/Cargo.toml b/contracts/nebula-community/Cargo.toml index 7fbae5d1..1ad90c8f 100644 --- a/contracts/nebula-community/Cargo.toml +++ b/contracts/nebula-community/Cargo.toml @@ -27,7 +27,7 @@ schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } snafu = { version = "0.6.3" } nebula-protocol = { version = "1.0.0", path = "../../packages/nebula_protocol" } -astroport = { path = "../../packages/astroport" } +astroport = { version = "1.0" } thiserror = { version = "1.0.30" } cw2 = { version = "0.9.1" } diff --git a/contracts/nebula-incentives/Cargo.toml b/contracts/nebula-incentives/Cargo.toml index 4624b38b..9eda3455 100644 --- a/contracts/nebula-incentives/Cargo.toml +++ b/contracts/nebula-incentives/Cargo.toml @@ -25,7 +25,7 @@ backtraces = ["cosmwasm-std/backtraces"] cw20 = { version = "0.8.0" } cosmwasm-std = { version = "0.16.2", default-features = false} cosmwasm-storage = { version = "0.16.2" } -astroport = { path = "../../packages/astroport" } +astroport = { version = "1.0" } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } cluster-math = { path = "../../libraries/cluster-math" } diff --git a/contracts/nebula-lp-staking/Cargo.toml b/contracts/nebula-lp-staking/Cargo.toml index 3418bc31..d84ce229 100644 --- a/contracts/nebula-lp-staking/Cargo.toml +++ b/contracts/nebula-lp-staking/Cargo.toml @@ -24,7 +24,7 @@ backtraces = ["cosmwasm-std/backtraces"] [dependencies] cw20 = { version = "0.8.0" } -astroport = { path = "../../packages/astroport" } +astroport = { version = "1.0" } terra-cosmwasm = { version = "2.0.0" } cosmwasm-std = { version = "0.16.2", default-features = false } cosmwasm-storage = { version = "0.16.2", default-features = false, features = ["iterator"] } diff --git a/contracts/nebula-oracle/Cargo.toml b/contracts/nebula-oracle/Cargo.toml index 74b6bd3a..4fcd0422 100644 --- a/contracts/nebula-oracle/Cargo.toml +++ b/contracts/nebula-oracle/Cargo.toml @@ -26,7 +26,7 @@ schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } snafu = { version = "0.6.3" } nebula-protocol = { version = "1.0.0", path = "../../packages/nebula_protocol" } -astroport = { path = "../../packages/astroport" } +astroport = { version = "1.0" } terra-cosmwasm = "2.2.0" tefi-oracle = { version = "0.1.0", path = "../../packages/tefi_oracle" } thiserror = { version = "1.0.30" } diff --git a/packages/astroport/.cargo/config b/packages/astroport/.cargo/config deleted file mode 100644 index 71deaf22..00000000 --- a/packages/astroport/.cargo/config +++ /dev/null @@ -1,4 +0,0 @@ -[alias] -wasm = "build --release --target wasm32-unknown-unknown" -wasm-debug = "build --target wasm32-unknown-unknown" -unit-test = "test --lib" diff --git a/packages/astroport/Cargo.toml b/packages/astroport/Cargo.toml deleted file mode 100644 index 981f731f..00000000 --- a/packages/astroport/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "astroport" -version = "0.3.1" -authors = ["Astroport"] -edition = "2018" -description = "Common astroport types" -license = "Apache-2.0" -repository = "https://github.com/astroport-fi/astroport" -homepage = "https://astroport.fi" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[features] -# for quicker tests, cargo test --lib -# for more explicit tests, cargo test --features=backtraces -backtraces = ["cosmwasm-std/backtraces"] - -[dependencies] -cw20 = { version = "0.8" } -terra-cosmwasm = { version = "2.2.0" } -cosmwasm-std = { version = "0.16.2", features = ["iterator"] } -schemars = "0.8.1" -serde = { version = "1.0.103", default-features = false, features = ["derive"] } -uint = "0.9.1" -cw-storage-plus = {version = "0.8.0", features = ['iterator']} - -[dev-dependencies] -cosmwasm-schema = "0.16.0" diff --git a/packages/astroport/README.md b/packages/astroport/README.md deleted file mode 100644 index b71c71bf..00000000 --- a/packages/astroport/README.md +++ /dev/null @@ -1,127 +0,0 @@ -# Astroport: Common Types - -This is a collection of common types and the queriers which are commonly used in astroport contracts. - -## Data Types - -### AssetInfo - -AssetInfo is a convenience wrapper to represent the native token and the contract token as a single type. - -```rust -#[serde(rename_all = "snake_case")] -pub enum AssetInfo { - Token { contract_addr: Addr }, - NativeToken { denom: String }, -} -``` - -### Asset - -It contains asset info with the amount of token. - -```rust -pub struct Asset { - pub info: AssetInfo, - pub amount: Uint128, -} -``` - -### PairInfo - -It is used to represent response data of [Pair-Info-Querier](#Pair-Info-Querier) - -```rust -pub struct PairInfo { - pub contract_addr: Addr, - pub asset_infos: [AssetInfo; 2], - pub liquidity_token: Addr, - pub pair_type: PairType, -} -``` - -## Queriers - -### Native Token Balance Querier - -It uses CosmWasm standard interface to query the account balance to chain. - -```rust -pub fn query_balance( - deps: &Extern, - account_addr: &Addr, - denom: String, -) -> StdResult -``` - -### Token Balance Querier - -It provides similar query interface with [Native-Token-Balance-Querier](Native-Token-Balance-Querier) for CW20 token balance. - -```rust -pub fn query_token_balance( - deps: &Extern, - contract_addr: &Addr, - account_addr: &Addr, -) -> StdResult -``` - -### Token Supply Querier - -It provides token supply querier for CW20 token contract. - -```rust -pub fn query_supply( - deps: &Extern, - contract_addr: &Addr, -) -> StdResult -``` - -### Pair Info Querier - -It also provides the query interface to query available astroport pair contract info. Any contract can query pair info to astroport factory contract. - -```rust -pub fn query_pair_contract( - deps: &Extern, - contract_addr: &Addr, - asset_infos: &[AssetInfo; 2], -) -> StdResult -``` - -### Liquidity Token Querier - -It returns liquidity token contract address of astroport pair contract. - -```rust -pub fn query_liquidity_token( - deps: &Extern, - contract_addr: &Addr, -) -> StdResult -``` - -## Swap Pairs Simulating - -### Simulate - -Returns simulation swap return, spread, commission amounts. - -```rust -pub fn simulate( - querier: &QuerierWrapper, - pair_contract: Addr, - offer_asset: &Asset, -) -> StdResult -``` - -### Reverse Simulate - -Returns simulation swap offer, spread, commission amounts. - -```rust -pub fn reverse_simulate( - querier: &QuerierWrapper, - pair_contract: Addr, - offer_asset: &Asset, -) -> StdResult -``` \ No newline at end of file diff --git a/packages/astroport/src/asset.rs b/packages/astroport/src/asset.rs deleted file mode 100644 index b7d72447..00000000 --- a/packages/astroport/src/asset.rs +++ /dev/null @@ -1,371 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use std::fmt; - -use crate::factory::PairType; -use crate::querier::{query_balance, query_token_balance, query_token_symbol}; -use cosmwasm_std::{ - to_binary, Addr, Api, BankMsg, Coin, CosmosMsg, Decimal, MessageInfo, QuerierWrapper, StdError, - StdResult, Uint128, WasmMsg, -}; -use cw20::Cw20ExecuteMsg; -use terra_cosmwasm::TerraQuerier; - -/// ## Description -/// This enum describes asset. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct Asset { - /// the available type of asset from [`AssetInfo`] - pub info: AssetInfo, - /// the amount of an asset - pub amount: Uint128, -} - -impl fmt::Display for Asset { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}{}", self.amount, self.info) - } -} - -/// the decimal fraction -static DECIMAL_FRACTION: Uint128 = Uint128::new(1_000_000_000_000_000_000u128); - -impl Asset { - /// ## Description - /// Returns true if token is native token. Otherwise returns false. - /// ## Params - /// * **self** is the type of the caller object. - pub fn is_native_token(&self) -> bool { - self.info.is_native_token() - } - - /// ## Description - /// Calculates and returns computed tax for native token. For other tokens returns zero. - /// ## Params - /// * **self** is the type of the caller object. - /// - /// * **querier** is the object of type [`QuerierWrapper`] - pub fn compute_tax(&self, querier: &QuerierWrapper) -> StdResult { - let amount = self.amount; - if let AssetInfo::NativeToken { denom } = &self.info { - let terra_querier = TerraQuerier::new(querier); - let tax_rate: Decimal = (terra_querier.query_tax_rate()?).rate; - let tax_cap: Uint128 = (terra_querier.query_tax_cap(denom.to_string())?).cap; - Ok(std::cmp::min( - (amount.checked_sub(amount.multiply_ratio( - DECIMAL_FRACTION, - DECIMAL_FRACTION * tax_rate + DECIMAL_FRACTION, - )))?, - tax_cap, - )) - } else { - Ok(Uint128::zero()) - } - } - - /// ## Description - /// Calculates and returns deducted tax for native token. For other tokens returns an [`Err`]. - /// ## Params - /// * **self** is the type of the caller object. - /// - /// * **querier** is the object of type [`QuerierWrapper`] - pub fn deduct_tax(&self, querier: &QuerierWrapper) -> StdResult { - let amount = self.amount; - if let AssetInfo::NativeToken { denom } = &self.info { - Ok(Coin { - denom: denom.to_string(), - amount: amount.checked_sub(self.compute_tax(querier)?)?, - }) - } else { - Err(StdError::generic_err("cannot deduct tax from token asset")) - } - } - - /// ## Description - /// Returns a message of type [`CosmosMsg`]. - /// - /// For native tokens of type [`AssetInfo`] used default method [`BankMsg::Send`] to send amount to recipient, - /// before sent we need to deduct tax. - /// - /// For token of type [`AssetInfo`] used default method [`Cw20ExecuteMsg::Transfer`] and no need to deduct any tax. - /// ## Params - /// * **self** is the type of the caller object. - /// - /// * **querier** is the object of type [`QuerierWrapper`] - /// - /// * **recepient** is the address where the funds will be sent. - pub fn into_msg(self, querier: &QuerierWrapper, recipient: Addr) -> StdResult { - let amount = self.amount; - - match &self.info { - AssetInfo::Token { contract_addr } => Ok(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: contract_addr.to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { - recipient: recipient.to_string(), - amount, - })?, - funds: vec![], - })), - AssetInfo::NativeToken { .. } => Ok(CosmosMsg::Bank(BankMsg::Send { - to_address: recipient.to_string(), - amount: vec![self.deduct_tax(querier)?], - })), - } - } - - /// ## Description - /// Approves the amount of native tokens. Returns [`Ok`] if successful, otherwise returns [`Err`]. - /// ## Params - /// * **self** is the type of the caller object. - /// - /// * **message_info** is the object of type [`MessageInfo`] - pub fn assert_sent_native_token_balance(&self, message_info: &MessageInfo) -> StdResult<()> { - if let AssetInfo::NativeToken { denom } = &self.info { - match message_info.funds.iter().find(|x| x.denom == *denom) { - Some(coin) => { - if self.amount == coin.amount { - Ok(()) - } else { - Err(StdError::generic_err("Native token balance mismatch between the argument and the transferred")) - } - } - None => { - if self.amount.is_zero() { - Ok(()) - } else { - Err(StdError::generic_err("Native token balance mismatch between the argument and the transferred")) - } - } - } - } else { - Ok(()) - } - } -} - -/// ## Description -/// This enum describes available types of Token. -/// ## Examples -/// ``` -/// # use cosmwasm_std::Addr; -/// # use astroport::asset::AssetInfo::{NativeToken, Token}; -/// Token { contract_addr: Addr::unchecked("terra...") }; -/// NativeToken { denom: String::from("uluna") }; -/// ``` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum AssetInfo { - /// Token - Token { contract_addr: Addr }, - /// Native token - NativeToken { denom: String }, -} - -impl fmt::Display for AssetInfo { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - AssetInfo::NativeToken { denom } => write!(f, "{}", denom), - AssetInfo::Token { contract_addr } => write!(f, "{}", contract_addr), - } - } -} - -impl AssetInfo { - /// ## Description - /// Returns true if the caller is a native token. Otherwise returns false. - /// ## Params - /// * **self** is the type of the caller object - pub fn is_native_token(&self) -> bool { - match self { - AssetInfo::NativeToken { .. } => true, - AssetInfo::Token { .. } => false, - } - } - - /// ## Description - /// Returns balance of token in a pool. - /// ## Params - /// * **self** is the type of the caller object. - /// - /// * **pool_addr** is the address of the contract from which the balance is requested. - pub fn query_pool(&self, querier: &QuerierWrapper, pool_addr: Addr) -> StdResult { - match self { - AssetInfo::Token { contract_addr, .. } => { - query_token_balance(querier, contract_addr.clone(), pool_addr) - } - AssetInfo::NativeToken { denom, .. } => { - query_balance(querier, pool_addr, denom.to_string()) - } - } - } - - /// ## Description - /// Returns True if the calling token is equal to the token specified in the input parameters. - /// Otherwise returns False. - /// ## Params - /// * **self** is the type of the caller object. - /// - /// * **asset** is object of type [`AssetInfo`]. - pub fn equal(&self, asset: &AssetInfo) -> bool { - match self { - AssetInfo::Token { contract_addr, .. } => { - let self_contract_addr = contract_addr; - match asset { - AssetInfo::Token { contract_addr, .. } => self_contract_addr == contract_addr, - AssetInfo::NativeToken { .. } => false, - } - } - AssetInfo::NativeToken { denom, .. } => { - let self_denom = denom; - match asset { - AssetInfo::Token { .. } => false, - AssetInfo::NativeToken { denom, .. } => self_denom == denom, - } - } - } - } - - /// ## Description - /// If caller object is a native token of type ['AssetInfo`] then his `denom` field convert to a byte string. - /// - /// If caller object is a token of type ['AssetInfo`] then his `contract_addr` field convert to a byte string. - /// ## Params - /// * **self** is the type of the caller object. - pub fn as_bytes(&self) -> &[u8] { - match self { - AssetInfo::NativeToken { denom } => denom.as_bytes(), - AssetInfo::Token { contract_addr } => contract_addr.as_bytes(), - } - } - - /// ## Description - /// Returns [`Ok`] if the token of type [`AssetInfo`] is in lowercase and valid. Otherwise returns [`Err`]. - /// ## Params - /// * **self** is the type of the caller object. - /// - /// * **api** is a object of type [`Api`] - pub fn check(&self, api: &dyn Api) -> StdResult<()> { - match self { - AssetInfo::Token { contract_addr } => { - addr_validate_to_lower(api, contract_addr.as_str())?; - } - AssetInfo::NativeToken { denom } => { - if denom != &denom.to_lowercase() { - return Err(StdError::generic_err(format!( - "Native token denom {} should be lowercase", - denom - ))); - } - } - } - Ok(()) - } -} - -/// ## Description -/// This structure describes the main controls configs of pair -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct PairInfo { - /// the type of asset infos available in [`AssetInfo`] - pub asset_infos: [AssetInfo; 2], - /// pair contract address - pub contract_addr: Addr, - /// pair liquidity token - pub liquidity_token: Addr, - /// the type of pair available in [`PairType`] - pub pair_type: PairType, -} - -impl PairInfo { - /// ## Description - /// Returns balance for each asset in the pool. - /// ## Params - /// * **self** is the type of the caller object - /// - /// * **querier** is the object of type [`QuerierWrapper`] - /// - /// * **contract_addr** is the pool address of the pair. - pub fn query_pools( - &self, - querier: &QuerierWrapper, - contract_addr: Addr, - ) -> StdResult<[Asset; 2]> { - Ok([ - Asset { - amount: self.asset_infos[0].query_pool(querier, contract_addr.clone())?, - info: self.asset_infos[0].clone(), - }, - Asset { - amount: self.asset_infos[1].query_pool(querier, contract_addr)?, - info: self.asset_infos[1].clone(), - }, - ]) - } -} - -/// ## Description -/// Returns the validated address in lowercase on success. Otherwise returns [`Err`] -/// ## Params -/// * **api** is a object of type [`Api`] -/// -/// * **addr** is the object of type [`Addr`] -pub fn addr_validate_to_lower(api: &dyn Api, addr: &str) -> StdResult { - if addr.to_lowercase() != addr { - return Err(StdError::generic_err(format!( - "Address {} should be lowercase", - addr - ))); - } - api.addr_validate(addr) -} - -const TOKEN_SYMBOL_MAX_LENGTH: usize = 4; - -/// ## Description -/// Returns formatted liquidity token name -/// ## Params -/// * **asset_infos** is array with two items the type of [`AssetInfo`]. -/// -/// * **querier** is the object of type [`QuerierWrapper`]. -pub fn format_lp_token_name( - asset_infos: [AssetInfo; 2], - querier: &QuerierWrapper, -) -> StdResult { - let mut short_symbols: Vec = vec![]; - for asset_info in asset_infos { - let short_symbol: String; - match asset_info { - AssetInfo::NativeToken { denom } => { - short_symbol = denom.chars().take(TOKEN_SYMBOL_MAX_LENGTH).collect(); - } - AssetInfo::Token { contract_addr } => { - let token_symbol = query_token_symbol(querier, contract_addr)?; - short_symbol = token_symbol.chars().take(TOKEN_SYMBOL_MAX_LENGTH).collect(); - } - } - short_symbols.push(short_symbol); - } - Ok(format!("{}-{}-LP", short_symbols[0], short_symbols[1]).to_uppercase()) -} - -pub fn native_asset(denom: String, amount: Uint128) -> Asset { - Asset { - info: AssetInfo::NativeToken { denom }, - amount, - } -} - -pub fn token_asset(contract_addr: Addr, amount: Uint128) -> Asset { - Asset { - info: AssetInfo::Token { contract_addr }, - amount, - } -} - -pub fn native_asset_info(denom: String) -> AssetInfo { - AssetInfo::NativeToken { denom } -} - -pub fn token_asset_info(contract_addr: Addr) -> AssetInfo { - AssetInfo::Token { contract_addr } -} diff --git a/packages/astroport/src/common.rs b/packages/astroport/src/common.rs deleted file mode 100644 index b64aadc5..00000000 --- a/packages/astroport/src/common.rs +++ /dev/null @@ -1,141 +0,0 @@ -use crate::asset::addr_validate_to_lower; -use cosmwasm_std::{attr, Addr, DepsMut, Env, MessageInfo, Response, StdError, StdResult}; -use cw_storage_plus::Item; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -/// ## Description -/// This structure describes the basic settings for creating a request for a change of ownership. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct OwnershipProposal { - /// a new ownership. - pub owner: Addr, - /// time to live a request - pub ttl: u64, -} - -/// ## Description -/// Creates a new request to change ownership. Returns an [`Err`] on failure or returns the [`Response`] with the specified attributes if the operation was successful. -/// ## Executor -/// Only owner can execute it -/// ## Params -/// `deps` is the object of type [`DepsMut`]. -/// -/// `info` is the object of type [`MessageInfo`]. -/// -/// `env` is the object of type [`Env`]. -/// -/// `new_owner` is a new owner. -/// -/// `expires_in` is the validity period of the offer to change the owner. -/// -/// `owner` is the current owner. -/// -/// `proposal` is the object of type [`OwnershipProposal`]. -pub fn propose_new_owner( - deps: DepsMut, - info: MessageInfo, - env: Env, - new_owner: String, - expires_in: u64, - owner: Addr, - proposal: Item, -) -> StdResult { - // permission check - if info.sender != owner { - return Err(StdError::generic_err("Unauthorized")); - } - - let new_owner = addr_validate_to_lower(deps.api, new_owner.as_str())?; - - // check that owner is not the same - if new_owner == owner { - return Err(StdError::generic_err("New owner cannot be same")); - } - - proposal.save( - deps.storage, - &OwnershipProposal { - owner: new_owner.clone(), - ttl: env.block.time.seconds() + expires_in, - }, - )?; - - Ok(Response::new().add_attributes(vec![ - attr("action", "propose_new_owner"), - attr("new_owner", new_owner), - ])) -} - -/// ## Description -/// Removes a request to change ownership. Returns an [`Err`] on failure or returns the [`Response`] with the specified attributes if the operation was successful. -/// ## Executor -/// Only owner can execute it -/// ## Params -/// `deps` is the object of type [`DepsMut`]. -/// -/// `info` is the object of type [`MessageInfo`]. -/// -/// `owner` is the current owner. -/// -/// `proposal` is the object of type [`OwnershipProposal`]. -pub fn drop_ownership_proposal( - deps: DepsMut, - info: MessageInfo, - owner: Addr, - proposal: Item, -) -> StdResult { - // permission check - if info.sender != owner { - return Err(StdError::generic_err("Unauthorized")); - } - - proposal.remove(deps.storage); - - Ok(Response::new().add_attributes(vec![attr("action", "drop_ownership_proposal")])) -} - -/// ## Description -/// Approves owner. Returns an [`Err`] on failure or returns the [`Response`] with the specified attributes if the operation was successful. -/// ## Executor -/// Only owner can execute it -/// ## Params -/// `deps` is the object of type [`DepsMut`]. -/// -/// `info` is the object of type [`MessageInfo`]. -/// -/// `env` is the object of type [`Env`]. -/// -/// `proposal` is the object of type [`OwnershipProposal`]. -/// -/// `cb` is a type of callback function that takes two parameters of type [`DepsMut`] and [`Addr`]. -pub fn claim_ownership( - deps: DepsMut, - info: MessageInfo, - env: Env, - proposal: Item, - cb: fn(DepsMut, Addr) -> StdResult<()>, -) -> StdResult { - let p: OwnershipProposal = proposal - .load(deps.storage) - .map_err(|_| StdError::generic_err("Ownership proposal not found"))?; - - // Check sender - if info.sender != p.owner { - return Err(StdError::generic_err("Unauthorized")); - } - - if env.block.time.seconds() > p.ttl { - return Err(StdError::generic_err("Ownership proposal expired")); - } - - proposal.remove(deps.storage); - - // run callback - cb(deps, p.owner.clone())?; - - Ok(Response::new().add_attributes(vec![ - attr("action", "claim_ownership"), - attr("new_owner", p.owner), - ])) -} diff --git a/packages/astroport/src/factory.rs b/packages/astroport/src/factory.rs deleted file mode 100644 index a8a7506c..00000000 --- a/packages/astroport/src/factory.rs +++ /dev/null @@ -1,203 +0,0 @@ -use crate::asset::{AssetInfo, PairInfo}; -use cosmwasm_std::{Addr, Binary}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use std::fmt::{Display, Formatter, Result}; - -/// ## Description -/// This enum describes available types of pair. -/// ## Available types -/// ``` -/// # use astroport::factory::PairType::{Custom, Stable, Xyk}; -/// Xyk {}; -/// Stable {}; -/// Custom(String::from("Custom")); -/// ``` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum PairType { - /// XYK pair type - Xyk {}, - /// Stable pair type - Stable {}, - /// Custom pair type - Custom(String), -} - -// Provide a string version of this to raw encode strings -impl Display for PairType { - fn fmt(&self, fmt: &mut Formatter) -> Result { - match self { - PairType::Xyk {} => fmt.write_str("xyk"), - PairType::Stable {} => fmt.write_str("stable"), - PairType::Custom(pair_type) => fmt.write_str(format!("custom-{}", pair_type).as_str()), - } - } -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -/// ## Description -/// This structure describes a configuration of pair. -pub struct PairConfig { - /// pair contract code ID which are allowed to create pair - pub code_id: u64, - /// the type of pair available in [`PairType`] - pub pair_type: PairType, - /// a pair total fees bps - pub total_fee_bps: u16, - /// a pair fees bps - pub maker_fee_bps: u16, - /// We disable pair configs instead of removing them. If it is disabled, new pairs cannot be - /// created, but existing ones can still obtain proper settings, such as fee amounts - pub is_disabled: Option, -} - -impl PairConfig { - /// ## Description - /// This method is used to check fee bps. - /// ## Params - /// `&self` is the type of the caller object. - pub fn valid_fee_bps(&self) -> bool { - self.total_fee_bps <= 10_000 && self.maker_fee_bps <= 10_000 - } -} - -/// ## Description -/// This structure describes the basic settings for creating a contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - /// pair contract code IDs which are allowed to create pairs - pub pair_configs: Vec, - /// CW20 token contract code identifier - pub token_code_id: u64, - /// contract address to send fees to - pub fee_address: Option, - /// contract address that used for auto_stake from pools - pub generator_address: Option, - /// contract address that used for controls settings for factory, pools and tokenomics contracts - pub owner: String, -} - -/// ## Description -/// This structure describes the execute messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - /// UpdateConfig updates relevant code IDs - UpdateConfig { - /// CW20 token contract code identifier - token_code_id: Option, - /// contract address to send fees to - fee_address: Option, - /// contract address that used for auto_stake from pools - generator_address: Option, - }, - /// UpdatePairConfig updates configs of pair - UpdatePairConfig { - /// new [`PairConfig`] settings for pair - config: PairConfig, - }, - /// CreatePair instantiates pair contract - CreatePair { - /// the type of pair available in [`PairType`] - pair_type: PairType, - /// the type of asset infos available in [`AssetInfo`] - asset_infos: [AssetInfo; 2], - /// Optional binary serialised parameters for custom pool types - init_params: Option, - }, - /// Deregister removes a previously created pair - Deregister { - /// the type of asset infos available in [`AssetInfo`] - asset_infos: [AssetInfo; 2], - }, - /// ProposeNewOwner creates an offer for a new owner. The validity period of the offer is set in the `expires_in` variable. - ProposeNewOwner { - /// contract address that used for controls settings for factory, pools and tokenomics contracts - owner: String, - /// the offer expiration date for the new owner - expires_in: u64, - }, - /// DropOwnershipProposal removes the existing offer for the new owner. - DropOwnershipProposal {}, - /// Used to claim(approve) new owner proposal, thus changing contract's owner - ClaimOwnership {}, -} - -/// ## Description -/// This structure describes the query messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - /// Config returns controls settings that specified in custom [`ConfigResponse`] structure - Config {}, - /// Pair returns a pair according to the specified parameters in `asset_infos` variable. - Pair { - /// the type of asset infos available in [`AssetInfo`] - asset_infos: [AssetInfo; 2], - }, - /// Pairs returns an array of pairs according to the specified parameters in `start_after` and `limit` variables. - Pairs { - /// the item to start reading from. It is an [`Option`] type that accepts two [`AssetInfo`] elements. - start_after: Option<[AssetInfo; 2]>, - /// the number of items to be read. It is an [`Option`] type. - limit: Option, - }, - /// FeeInfo returns settings that specified in custom [`FeeInfoResponse`] structure - FeeInfo { - ///s the type of pair available in [`PairType`] - pair_type: PairType, - }, -} - -/// ## Description -/// A custom struct for each query response that returns controls settings of contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct ConfigResponse { - /// Contract address that used for controls settings for factory, pools and tokenomics contracts - pub owner: Addr, - /// Pair contract code IDs which are allowed to create pairs - pub pair_configs: Vec, - /// CW20 token contract code identifier - pub token_code_id: u64, - /// Contract address to send fees to - pub fee_address: Option, - /// Contract address that used for auto_stake from pools - pub generator_address: Option, -} - -/// ## Description -/// This structure describes a migration message. -/// We currently take no arguments for migrations. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct MigrateMsg {} - -/// ## Description -/// A custom struct for each query response that returns an array of objects type [`PairInfo`]. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct PairsResponse { - pub pairs: Vec, -} - -/// ## Description -/// A custom struct for each query response that returns an object of type [`FeeInfoResponse`]. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct FeeInfoResponse { - /// Contract address to send fees to - pub fee_address: Option, - /// Pair total fees bps - pub total_fee_bps: u16, - /// Pair fees bps - pub maker_fee_bps: u16, -} - -/// ## Description -/// This is an enumeration for setting and unsetting a contract address. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum UpdateAddr { - /// Sets a new contract address. - Set(String), - /// Removes contract address. - Remove {}, -} diff --git a/packages/astroport/src/generator.rs b/packages/astroport/src/generator.rs deleted file mode 100644 index 4ede74bc..00000000 --- a/packages/astroport/src/generator.rs +++ /dev/null @@ -1,205 +0,0 @@ -use cosmwasm_std::{Addr, Uint128, Uint64}; -use cw20::Cw20ReceiveMsg; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -/// ## Description -/// This structure describes the basic settings for creating a contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - /// contract address that used for controls settings - pub owner: String, - /// ASTRO token contract address - pub astro_token: String, - /// tokens per block - pub tokens_per_block: Uint128, - /// start block - pub start_block: Uint64, - /// allowed reward proxies contracts - pub allowed_reward_proxies: Vec, - /// a vesting contract - pub vesting_contract: String, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - /// ## Description - /// Update current vesting contract - /// ## Executor - /// Only owner can execute it - UpdateConfig { - /// the vesting contract - vesting_contract: Option, - }, - /// ## Description - /// Add a new liquidity pool token: - /// ## Executor - /// Only owner can execute it - Add { - /// the LP token contract address - lp_token: Addr, - /// the allocation point of liquidity pool - alloc_point: Uint64, - /// the reward proxy contract - reward_proxy: Option, - }, - /// ## Description - /// Update the given pool's ASTRO allocation point - /// ## Executor - /// Only owner can execute it - Set { - /// the LP token contract address - lp_token: Addr, - /// the allocation point of liquidity pool - alloc_point: Uint64, - }, - /// ## Description - /// Updates reward variables for all pools - MassUpdatePools {}, - /// ## Description - /// Updates reward variables of the given pool to be up-to-date - UpdatePool { - /// the LP token contract address - lp_token: Addr, - }, - /// ## Description - /// Withdraw LP tokens from Generator. - Withdraw { - /// the LP token contract address - lp_token: Addr, - /// the amount of withdrawal - amount: Uint128, - }, - /// ## Description - /// Withdraw LP tokens from Generator without caring about rewards. - EmergencyWithdraw { - /// the LP token contract address - lp_token: Addr, - }, - /// ## Description - /// allowed reward proxies contracts - SetAllowedRewardProxies { - /// the list of allowed contracts - proxies: Vec, - }, - /// ## Description - /// Sends the orphan proxy rewards which are left by emergency withdrawals - SendOrphanProxyReward { - /// the recipient of withdraw - recipient: String, - /// the LP token contract address - lp_token: String, - }, - /// ## Description - /// Receives a message of type [`Cw20ReceiveMsg`] - Receive(Cw20ReceiveMsg), - /// ## Description - /// a new count of tokens per block - /// ## Executor - /// Only owner can execute it - SetTokensPerBlock { - /// the amount - amount: Uint128, - }, - /// ## Description - /// Creates a request to change ownership - /// ## Executor - /// Only owner can execute it - ProposeNewOwner { - /// a new ownership - owner: String, - /// the validity period of the offer to change the owner - expires_in: u64, - }, - /// ## Description - /// Removes a request to change ownership - /// ## Executor - /// Only owner can execute it - DropOwnershipProposal {}, - /// ## Description - /// Approves ownership - /// ## Executor - /// Only owner can execute it - ClaimOwnership {}, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - /// PoolLength - PoolLength {}, - /// Deposit - Deposit { lp_token: Addr, user: Addr }, - /// PendingToken - PendingToken { lp_token: Addr, user: Addr }, - /// Config returns the base setting of the generator - Config {}, - /// RewardInfo returns reward information for the specified token. - RewardInfo { lp_token: Addr }, - /// OrphanProxyRewards returns reward information for the specified token. - OrphanProxyRewards { lp_token: Addr }, -} - -/// ## Description -/// This structure describe response for pool length. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct PoolLengthResponse { - pub length: usize, -} - -/// ## Description -/// This structure describes the response to the pending token. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct PendingTokenResponse { - /// a pending token - pub pending: Uint128, - /// a pending token on proxy - pub pending_on_proxy: Option, -} - -/// ## Description -/// This structure describes the response to the reward information. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct RewardInfoResponse { - /// a base reward token - pub base_reward_token: Addr, - /// a proxy reward token - pub proxy_reward_token: Option, -} - -/// ## Description -/// This structure describes the response for base controls. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct ConfigResponse { - /// contract address that used for controls settings - pub owner: Addr, - /// ASTRO token contract address - pub astro_token: Addr, - /// tokens per block - pub tokens_per_block: Uint128, - /// total allocation point - pub total_alloc_point: Uint64, - /// start block - pub start_block: Uint64, - /// allowed reward proxies - pub allowed_reward_proxies: Vec, - /// a vesting contract - pub vesting_contract: Addr, -} - -/// ## Description -/// This structure describes a migration message. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct MigrateMsg {} - -/// ## Description -/// This structure describes the custom hooks for the CW20. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum Cw20HookMsg { - /// Deposit performs the operation of depositing to the sender. - Deposit {}, - /// DepositFor performs performs the operation of depositing to the recipient. - DepositFor(Addr), -} diff --git a/packages/astroport/src/generator_proxy.rs b/packages/astroport/src/generator_proxy.rs deleted file mode 100644 index 08e13b1b..00000000 --- a/packages/astroport/src/generator_proxy.rs +++ /dev/null @@ -1,93 +0,0 @@ -use cosmwasm_std::{Addr, Uint128}; -use cw20::Cw20ReceiveMsg; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -/// ## Description -/// This structure describes the basic settings for creating a contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - /// the generator contract address - pub generator_contract_addr: String, - /// the pair contract address - pub pair_addr: String, - /// the liquidity pool token contract address - pub lp_token_addr: String, - /// the reward contract address - pub reward_contract_addr: String, - /// the reward token contract address - pub reward_token_addr: String, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum Cw20HookMsg { - Deposit {}, -} - -/// ## Description -/// This structure describes the execute messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - /// Receives a message of type [`Cw20ReceiveMsg`] - Receive(Cw20ReceiveMsg), - /// Withdrawal pending rewards - UpdateRewards {}, - /// Sends rewards to the recipient - SendRewards { account: Addr, amount: Uint128 }, - /// Withdrawal the rewards - Withdraw { - /// the recipient for withdrawal - account: Addr, - /// the amount of withdraw - amount: Uint128, - }, - /// Withdrawal the rewards - EmergencyWithdraw { - /// the recipient for withdrawal - account: Addr, - /// the amount of withdraw - amount: Uint128, - }, - /// the callback of type [`CallbackMsg`] - Callback(CallbackMsg), -} - -/// ## Description -/// This structure describes the callback messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum CallbackMsg { - TransferLpTokensAfterWithdraw { - /// the recipient - account: Addr, - /// the previous lp balance for calculate withdraw amount - prev_lp_balance: Uint128, - }, -} - -/// ## Description -/// This structure describes the query messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - /// Returns the contract's configuration - Config {}, - /// Returns the deposit amount - Deposit {}, - /// Returns the balance of reward token - Reward {}, - /// Returns the pending rewards - PendingToken {}, - /// Returns the reward token contract address - RewardInfo {}, -} - -pub type ConfigResponse = InstantiateMsg; - -/// ## Description -/// This structure describes a migration message. -/// We currently take no arguments for migrations -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct MigrateMsg {} diff --git a/packages/astroport/src/lib.rs b/packages/astroport/src/lib.rs deleted file mode 100644 index b193f487..00000000 --- a/packages/astroport/src/lib.rs +++ /dev/null @@ -1,63 +0,0 @@ -pub mod asset; -pub mod common; -pub mod factory; -pub mod generator; -pub mod generator_proxy; -pub mod maker; -pub mod oracle; -pub mod pair; -pub mod querier; -pub mod router; -pub mod staking; -pub mod token; -pub mod vesting; - -#[cfg(test)] -mod mock_querier; - -#[cfg(test)] -mod testing; - -#[allow(clippy::all)] -mod uints { - use uint::construct_uint; - construct_uint! { - pub struct U256(4); - } -} - -mod decimal_checked_ops { - use cosmwasm_std::{Decimal, Fraction, OverflowError, Uint128, Uint256}; - use std::convert::TryInto; - pub trait DecimalCheckedOps { - fn checked_add(self, other: Decimal) -> Result; - fn checked_mul(self, other: Uint128) -> Result; - } - - impl DecimalCheckedOps for Decimal { - fn checked_add(self, other: Decimal) -> Result { - Uint128::from(self.numerator()) - .checked_add(other.numerator().into()) - .map(|_| self + other) - } - fn checked_mul(self, other: Uint128) -> Result { - if self.is_zero() || other.is_zero() { - return Ok(Uint128::zero()); - } - let multiply_ratio = - other.full_mul(self.numerator()) / Uint256::from(self.denominator()); - if multiply_ratio > Uint256::from(Uint128::MAX) { - Err(OverflowError::new( - cosmwasm_std::OverflowOperation::Mul, - self, - other, - )) - } else { - Ok(multiply_ratio.try_into().unwrap()) - } - } - } -} - -pub use decimal_checked_ops::DecimalCheckedOps; -pub use uints::U256; diff --git a/packages/astroport/src/maker.rs b/packages/astroport/src/maker.rs deleted file mode 100644 index df840ab7..00000000 --- a/packages/astroport/src/maker.rs +++ /dev/null @@ -1,111 +0,0 @@ -use crate::asset::{Asset, AssetInfo}; -use crate::factory::UpdateAddr; -use cosmwasm_std::{Addr, Decimal, Uint64}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -/// ## Description -/// This structure describes the basic settings for creating a contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - /// contract address that used for controls settings for maker - pub owner: String, - /// the ASTRO token contract address - pub astro_token_contract: String, - /// the factory contract address - pub factory_contract: String, - /// the staking contract address - pub staking_contract: String, - /// the governance contract address - pub governance_contract: Option, - /// the governance percent - pub governance_percent: Option, - /// the maximum spread - pub max_spread: Option, -} - -/// ## Description -/// This structure describes the execute messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - /// Collects astro tokens from the given pairs - Collect { - /// the pairs contracts - pair_addresses: Vec, - }, - /// Updates general settings that contains in the [`Config`] - UpdateConfig { - /// the factory contract address - factory_contract: Option, - /// the staking contract address - staking_contract: Option, - /// the governance contract address - governance_contract: Option, - /// the governance percent - governance_percent: Option, - /// the maximum spread - max_spread: Option, - }, - /// Add bridges - UpdateBridges { - add: Option>, - remove: Option>, - }, - /// Swap rewards via bridge assets - SwapBridgeAssets { assets: Vec, depth: u64 }, - /// Distribute rewards in ASTRO tokens - DistributeAstro {}, - /// Creates a request to change ownership. - ProposeNewOwner { - /// a new owner - owner: String, - /// the validity period of the offer to change the owner - expires_in: u64, - }, - /// Removes a request to change ownership. - DropOwnershipProposal {}, - /// Approves ownership. - ClaimOwnership {}, -} - -/// ## Description -/// This structure describes the query messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - /// Returns information about the maker configs that contains in the [`Config`] - Config {}, - /// Returns the balance for each asset in the specified input parameters - Balances { - assets: Vec, - }, - Bridges {}, -} - -/// ## Description -/// A custom struct for each query response that returns controls settings of contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct ConfigResponse { - /// Contract address that used for controls settings for factory, pools and tokenomics contracts - pub owner: Addr, - /// the ASTRO token contract address - pub astro_token_contract: Addr, - /// the factory contract address - pub factory_contract: Addr, - /// the staking contract address - pub staking_contract: Addr, - /// the governance contract address - pub governance_contract: Option, - /// the governance percent - pub governance_percent: Uint64, - /// the maximum spread - pub max_spread: Decimal, -} - -/// ## Description -/// A custom struct for each query response that returns the balance of asset. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct BalancesResponse { - pub balances: Vec, -} diff --git a/packages/astroport/src/mock_querier.rs b/packages/astroport/src/mock_querier.rs deleted file mode 100644 index de333e23..00000000 --- a/packages/astroport/src/mock_querier.rs +++ /dev/null @@ -1,298 +0,0 @@ -use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR}; -use cosmwasm_std::{ - from_binary, from_slice, to_binary, Coin, Decimal, OwnedDeps, Querier, QuerierResult, - QueryRequest, SystemError, SystemResult, Uint128, WasmQuery, -}; - -use std::collections::HashMap; - -use crate::asset::PairInfo; -use crate::factory::QueryMsg as FactoryQueryMsg; -use cw20::{BalanceResponse, Cw20QueryMsg, TokenInfoResponse}; -use terra_cosmwasm::{TaxCapResponse, TaxRateResponse, TerraQuery, TerraQueryWrapper, TerraRoute}; - -/// mock_dependencies is a drop-in replacement for cosmwasm_std::testing::mock_dependencies -/// this uses our CustomQuerier. -pub fn mock_dependencies( - contract_balance: &[Coin], -) -> OwnedDeps { - let custom_querier: WasmMockQuerier = - WasmMockQuerier::new(MockQuerier::new(&[(MOCK_CONTRACT_ADDR, contract_balance)])); - - OwnedDeps { - storage: MockStorage::default(), - api: MockApi::default(), - querier: custom_querier, - } -} -enum QueryHandler { - Default, - Cw20, -} - -pub struct WasmMockQuerier { - query_handler: DefaultQueryHandler, - cw20_query_handler: CW20QueryHandler, - handler: QueryHandler, -} - -#[derive(Clone, Default)] -pub struct TokenQuerier { - // this lets us iterate over all pairs that match the first string - balances: HashMap>, -} - -impl TokenQuerier { - pub fn new(balances: &[(&String, &[(&String, &Uint128)])]) -> Self { - TokenQuerier { - balances: balances_to_map(balances), - } - } -} - -pub(crate) fn balances_to_map( - balances: &[(&String, &[(&String, &Uint128)])], -) -> HashMap> { - let mut balances_map: HashMap> = HashMap::new(); - for (contract_addr, balances) in balances.iter() { - let mut contract_balances_map: HashMap = HashMap::new(); - for (addr, balance) in balances.iter() { - contract_balances_map.insert(addr.to_string(), **balance); - } - - balances_map.insert( - String::from(contract_addr.to_string()), - contract_balances_map, - ); - } - balances_map -} - -#[derive(Clone, Default)] -pub struct TaxQuerier { - rate: Decimal, - // this lets us iterate over all pairs that match the first string - caps: HashMap, -} - -impl TaxQuerier { - pub fn new(rate: Decimal, caps: &[(&String, &Uint128)]) -> Self { - TaxQuerier { - rate, - caps: caps_to_map(caps), - } - } -} - -pub(crate) fn caps_to_map(caps: &[(&String, &Uint128)]) -> HashMap { - let mut owner_map: HashMap = HashMap::new(); - for (denom, cap) in caps.iter() { - owner_map.insert(denom.to_string(), **cap); - } - owner_map -} - -#[derive(Clone, Default)] -pub struct AstroportFactoryQuerier { - pairs: HashMap, -} - -impl AstroportFactoryQuerier { - pub fn new(pairs: &[(&String, &PairInfo)]) -> Self { - AstroportFactoryQuerier { - pairs: pairs_to_map(pairs), - } - } -} - -pub(crate) fn pairs_to_map(pairs: &[(&String, &PairInfo)]) -> HashMap { - let mut pairs_map: HashMap = HashMap::new(); - for (key, pair) in pairs.iter() { - pairs_map.insert(key.to_string(), (*pair).clone()); - } - pairs_map -} - -impl Querier for WasmMockQuerier { - fn raw_query(&self, bin_request: &[u8]) -> QuerierResult { - // MockQuerier doesn't support Custom, so we ignore it completely here - let request: QueryRequest = match from_slice(bin_request) { - Ok(v) => v, - Err(e) => { - return SystemResult::Err(SystemError::InvalidRequest { - error: format!("Parsing query request: {}", e), - request: bin_request.into(), - }); - } - }; - self.handle_query(&request) - } -} - -impl WasmMockQuerier { - pub fn handle_query(&self, request: &QueryRequest) -> QuerierResult { - match self.handler { - QueryHandler::Default => self.query_handler.execute(request), - QueryHandler::Cw20 => self.cw20_query_handler.execute(request), - } - } -} - -struct CW20QueryHandler { - token_querier: TokenQuerier, -} - -impl CW20QueryHandler { - pub fn execute(&self, request: &QueryRequest) -> QuerierResult { - match &request { - QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => { - match from_binary(&msg).unwrap() { - Cw20QueryMsg::TokenInfo {} => { - let balances: &HashMap = - match self.token_querier.balances.get(contract_addr) { - Some(balances) => balances, - None => { - return SystemResult::Err(SystemError::Unknown {}); - } - }; - - let mut total_supply = Uint128::zero(); - - for balance in balances { - total_supply += *balance.1; - } - - SystemResult::Ok( - to_binary(&TokenInfoResponse { - name: "mAPPL".to_string(), - symbol: "mAPPL".to_string(), - decimals: 6, - total_supply: total_supply, - }) - .into(), - ) - } - Cw20QueryMsg::Balance { address } => { - let balances: &HashMap = - match self.token_querier.balances.get(contract_addr) { - Some(balances) => balances, - None => { - return SystemResult::Err(SystemError::Unknown {}); - } - }; - - let balance = match balances.get(&address) { - Some(v) => v, - None => { - return SystemResult::Err(SystemError::Unknown {}); - } - }; - - SystemResult::Ok(to_binary(&BalanceResponse { balance: *balance }).into()) - } - _ => panic!("DO NOT ENTER HERE"), - } - } - _ => panic!("DO NOT ENTER HERE"), - } - } -} - -struct DefaultQueryHandler { - base: MockQuerier, - tax_querier: TaxQuerier, - astroport_factory_querier: AstroportFactoryQuerier, -} - -impl DefaultQueryHandler { - pub fn execute(&self, request: &QueryRequest) -> QuerierResult { - match &request { - QueryRequest::Custom(TerraQueryWrapper { route, query_data }) => { - if &TerraRoute::Treasury == route { - match query_data { - TerraQuery::TaxRate {} => { - let res = TaxRateResponse { - rate: self.tax_querier.rate, - }; - SystemResult::Ok(to_binary(&res).into()) - } - TerraQuery::TaxCap { denom } => { - let cap = self - .tax_querier - .caps - .get(denom) - .copied() - .unwrap_or_default(); - let res = TaxCapResponse { cap }; - SystemResult::Ok(to_binary(&res).into()) - } - _ => panic!("DO NOT ENTER HERE"), - } - } else { - panic!("DO NOT ENTER HERE") - } - } - QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: _, - msg, - }) => match from_binary(&msg).unwrap() { - FactoryQueryMsg::Pair { asset_infos } => { - let key = asset_infos[0].to_string() + asset_infos[1].to_string().as_str(); - match self.astroport_factory_querier.pairs.get(&key) { - Some(v) => SystemResult::Ok(to_binary(&v).into()), - None => SystemResult::Err(SystemError::InvalidRequest { - error: "No pair info exists".to_string(), - request: msg.as_slice().into(), - }), - } - } - _ => panic!("DO NOT ENTER HERE"), - }, - _ => self.base.handle_query(request), - } - } -} - -impl WasmMockQuerier { - pub fn new(base: MockQuerier) -> Self { - WasmMockQuerier { - query_handler: DefaultQueryHandler { - base, - tax_querier: TaxQuerier::default(), - astroport_factory_querier: AstroportFactoryQuerier::default(), - }, - cw20_query_handler: CW20QueryHandler { - token_querier: TokenQuerier::default(), - }, - handler: QueryHandler::Default, - } - } - - // configure the mint whitelist mock querier - pub fn with_token_balances(&mut self, balances: &[(&String, &[(&String, &Uint128)])]) { - self.cw20_query_handler.token_querier = TokenQuerier::new(balances); - } - - // configure the token owner mock querier - pub fn with_tax(&mut self, rate: Decimal, caps: &[(&String, &Uint128)]) { - self.query_handler.tax_querier = TaxQuerier::new(rate, caps); - } - - // configure the astroport pair - pub fn with_astroport_pairs(&mut self, pairs: &[(&String, &PairInfo)]) { - self.query_handler.astroport_factory_querier = AstroportFactoryQuerier::new(pairs); - } - - pub fn with_default_query_handler(&mut self) { - self.handler = QueryHandler::Default; - } - - pub fn with_cw20_query_handler(&mut self) { - self.handler = QueryHandler::Cw20; - } - // pub fn with_balance(&mut self, balances: &[(&String, &[Coin])]) { - // for (addr, balance) in balances { - // self.base.update_balance(addr, balance.to_vec()); - // } - // } -} diff --git a/packages/astroport/src/oracle.rs b/packages/astroport/src/oracle.rs deleted file mode 100644 index b24fe7f0..00000000 --- a/packages/astroport/src/oracle.rs +++ /dev/null @@ -1,43 +0,0 @@ -use crate::asset::AssetInfo; -use cosmwasm_std::Uint128; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -/// ## Description -/// This structure describes the basic settings for creating a contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - /// the factory contract address - pub factory_contract: String, - /// the type of asset infos available in [`AssetInfo`] - pub asset_infos: [AssetInfo; 2], -} - -/// ## Description -/// This structure describes the execute messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - /// Update prices - Update {}, -} - -/// ## Description -/// This structure describes the query messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - /// Validates assets and calculates a new average amount with updated precision - Consult { - /// the assets to validate - token: AssetInfo, - /// the amount - amount: Uint128, - }, -} - -/// ## Description -/// This structure describes a migration message. -/// We currently take no arguments for migrations. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct MigrateMsg {} diff --git a/packages/astroport/src/pair.rs b/packages/astroport/src/pair.rs deleted file mode 100644 index 3ad9839a..00000000 --- a/packages/astroport/src/pair.rs +++ /dev/null @@ -1,164 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -use crate::asset::{Asset, AssetInfo}; - -use cosmwasm_std::{Addr, Binary, Decimal, Uint128}; -use cw20::Cw20ReceiveMsg; - -/// the default slippage -pub const DEFAULT_SLIPPAGE: &str = "0.005"; -/// the maximum allowed slippage -pub const MAX_ALLOWED_SLIPPAGE: &str = "0.5"; - -pub const TWAP_PRECISION: u8 = 6; - -/// ## Description -/// This structure describes the basic settings for creating a contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - /// the type of asset infos available in [`AssetInfo`] - pub asset_infos: [AssetInfo; 2], - /// the token contract code id for initialization - pub token_code_id: u64, - /// the factory contract address - pub factory_addr: Addr, - /// the optional binary serialised parameters for custom pool types - pub init_params: Option, -} - -/// ## Description -/// This structure describes the execute messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - /// ## Description - /// Receives a message of type [`Cw20ReceiveMsg`] - Receive(Cw20ReceiveMsg), - /// ProvideLiquidity a user provides pool liquidity - ProvideLiquidity { - /// the type of asset available in [`Asset`] - assets: [Asset; 2], - /// the slippage tolerance for sets the maximum percent of price movement - slippage_tolerance: Option, - /// Determines whether an autostake will be performed on the generator - auto_stake: Option, - /// the receiver of provide liquidity - receiver: Option, - }, - /// Swap an offer asset to the other - Swap { - offer_asset: Asset, - belief_price: Option, - max_spread: Option, - to: Option, - }, - /// Update pair config if required - UpdateConfig { params: Binary }, -} - -/// ## Description -/// This structure describes a CW20 hook message. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum Cw20HookMsg { - /// Sell a given amount of asset - Swap { - belief_price: Option, - max_spread: Option, - to: Option, - }, - /// Withdrawing liquidity from the pool - WithdrawLiquidity {}, -} - -/// ## Description -/// This structure describes the query messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - /// Returns information about a pair in an object of type [`PairInfo`]. - Pair {}, - /// Returns information about a pool in an object of type [`PoolResponse`]. - Pool {}, - /// Returns controls settings that specified in custom [`ConfigResponse`] structure. - Config {}, - /// Returns information about the share of the pool in a vector that contains objects of type [`Asset`]. - Share { amount: Uint128 }, - /// Returns information about the simulation of the swap in a [`SimulationResponse`] object. - Simulation { offer_asset: Asset }, - /// Returns information about the reverse simulation in a [`ReverseSimulationResponse`] object. - ReverseSimulation { ask_asset: Asset }, - /// Returns information about the cumulative prices in a [`CumulativePricesResponse`] object - CumulativePrices {}, -} - -/// ## Description -/// This structure describes the custom struct for each query response. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct PoolResponse { - pub assets: [Asset; 2], - pub total_share: Uint128, -} - -/// ## Description -/// This structure describes the custom struct for each query response. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct ConfigResponse { - /// the last time block - pub block_time_last: u64, - pub params: Option, -} - -/// ## Description -/// SimulationResponse returns swap simulation response -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct SimulationResponse { - pub return_amount: Uint128, - pub spread_amount: Uint128, - pub commission_amount: Uint128, -} - -/// ## Description -/// ReverseSimulationResponse returns reverse swap simulation response -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct ReverseSimulationResponse { - pub offer_amount: Uint128, - pub spread_amount: Uint128, - pub commission_amount: Uint128, -} - -/// ## Description -/// This structure describes the custom struct for each query response. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct CumulativePricesResponse { - pub assets: [Asset; 2], - pub total_share: Uint128, - pub price0_cumulative_last: Uint128, - pub price1_cumulative_last: Uint128, -} - -/// ## Description -/// This structure describes a migration message. -/// We currently take no arguments for migrations. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct MigrateMsg {} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct StablePoolParams { - pub amp: u64, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct StablePoolConfig { - pub amp: Decimal, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum StablePoolUpdateParams { - StartChangingAmp { next_amp: u64, next_amp_time: u64 }, - StopChangingAmp {}, -} diff --git a/packages/astroport/src/querier.rs b/packages/astroport/src/querier.rs deleted file mode 100644 index 621b5e86..00000000 --- a/packages/astroport/src/querier.rs +++ /dev/null @@ -1,264 +0,0 @@ -use crate::asset::{Asset, AssetInfo, PairInfo}; -use crate::factory::{ - ConfigResponse as FactoryConfigResponse, FeeInfoResponse, PairType, PairsResponse, - QueryMsg as FactoryQueryMsg, -}; -use crate::pair::{QueryMsg as PairQueryMsg, ReverseSimulationResponse, SimulationResponse}; - -use cosmwasm_std::{ - to_binary, Addr, AllBalanceResponse, BalanceResponse, BankQuery, Coin, Decimal, QuerierWrapper, - QueryRequest, StdResult, Uint128, WasmQuery, -}; - -use cw20::{BalanceResponse as Cw20BalanceResponse, Cw20QueryMsg, TokenInfoResponse}; - -// It's defined at https://github.com/terra-money/core/blob/d8e277626e74f9d6417dcd598574686882f0274c/types/assets/assets.go#L15 -const NATIVE_TOKEN_PRECISION: u8 = 6; - -/// ## Description -/// Returns the balance of the denom at the specified account address. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **account_addr** is the object of type [`Addr`]. -/// -/// * **denom** is the object of type [`String`]. -pub fn query_balance( - querier: &QuerierWrapper, - account_addr: Addr, - denom: String, -) -> StdResult { - let balance: BalanceResponse = querier.query(&QueryRequest::Bank(BankQuery::Balance { - address: String::from(account_addr), - denom, - }))?; - Ok(balance.amount.amount) -} - -/// ## Description -/// Returns the total balance for all coins at the specified account address. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **account_addr** is the object of type [`Addr`]. -pub fn query_all_balances(querier: &QuerierWrapper, account_addr: Addr) -> StdResult> { - let all_balances: AllBalanceResponse = - querier.query(&QueryRequest::Bank(BankQuery::AllBalances { - address: String::from(account_addr), - }))?; - Ok(all_balances.amount) -} - -/// ## Description -/// Returns the token balance at the specified contract address. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **contract_addr** is the object of type [`Addr`]. Sets the address of the contract for which -/// the balance will be requested -/// -/// * **account_addr** is the object of type [`Addr`]. -pub fn query_token_balance( - querier: &QuerierWrapper, - contract_addr: Addr, - account_addr: Addr, -) -> StdResult { - // load balance from the token contract - let res: Cw20BalanceResponse = querier - .query(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: String::from(contract_addr), - msg: to_binary(&Cw20QueryMsg::Balance { - address: String::from(account_addr), - })?, - })) - .unwrap_or_else(|_| Cw20BalanceResponse { - balance: Uint128::zero(), - }); - - Ok(res.balance) -} - -/// ## Description -/// Returns the token symbol at the specified contract address. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **contract_addr** is the object of type [`Addr`]. -pub fn query_token_symbol(querier: &QuerierWrapper, contract_addr: Addr) -> StdResult { - let res: TokenInfoResponse = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: String::from(contract_addr), - msg: to_binary(&Cw20QueryMsg::TokenInfo {})?, - }))?; - - Ok(res.symbol) -} - -/// ## Description -/// Returns the total supply at the specified contract address. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **contract_addr** is the object of type [`Addr`]. -pub fn query_supply(querier: &QuerierWrapper, contract_addr: Addr) -> StdResult { - let res: TokenInfoResponse = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: String::from(contract_addr), - msg: to_binary(&Cw20QueryMsg::TokenInfo {})?, - }))?; - - Ok(res.total_supply) -} - -/// ## Description -/// Returns the token precision at the specified asset of type [`AssetInfo`]. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **asset_info** is the object of type [`AssetInfo`]. -pub fn query_token_precision(querier: &QuerierWrapper, asset_info: AssetInfo) -> StdResult { - Ok(match asset_info { - AssetInfo::NativeToken { denom: _ } => NATIVE_TOKEN_PRECISION, - AssetInfo::Token { contract_addr } => { - let res: TokenInfoResponse = - querier.query_wasm_smart(contract_addr, &Cw20QueryMsg::TokenInfo {})?; - - res.decimals - } - }) -} - -/// ## Description -/// Returns the config of factory contract address. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **factory_contract** is the object of type [`Addr`]. -pub fn query_factory_config( - querier: &QuerierWrapper, - factory_contract: Addr, -) -> StdResult { - querier.query(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: factory_contract.to_string(), - msg: to_binary(&FactoryQueryMsg::Config {})?, - })) -} - -/// ## Description -/// This structure describes the basic fee information. -pub struct FeeInfo { - /// the fee address - pub fee_address: Option, - /// the total fee rate - pub total_fee_rate: Decimal, - /// the maker fee rate - pub maker_fee_rate: Decimal, -} - -/// ## Description -/// Returns the fee information at the specified pair type. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **factory_contract** is the object of type [`Addr`]. -/// -/// * **pair_type** is the object of type [`PairType`]. -pub fn query_fee_info( - querier: &QuerierWrapper, - factory_contract: Addr, - pair_type: PairType, -) -> StdResult { - let res: FeeInfoResponse = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: factory_contract.to_string(), - msg: to_binary(&FactoryQueryMsg::FeeInfo { pair_type })?, - }))?; - - Ok(FeeInfo { - fee_address: res.fee_address, - total_fee_rate: Decimal::from_ratio(Uint128::from(res.total_fee_bps), Uint128::new(10000)), - maker_fee_rate: Decimal::from_ratio(Uint128::from(res.maker_fee_bps), Uint128::new(10000)), - }) -} - -/// ## Description -/// Returns the pair information at the specified assets of type [`AssetInfo`]. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **factory_contract** is the object of type [`Addr`]. -/// -/// * **asset_infos** is an array that contains two items of type [`AssetInfo`]. -pub fn query_pair_info( - querier: &QuerierWrapper, - factory_contract: Addr, - asset_infos: &[AssetInfo; 2], -) -> StdResult { - querier.query(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: factory_contract.to_string(), - msg: to_binary(&FactoryQueryMsg::Pair { - asset_infos: asset_infos.clone(), - })?, - })) -} - -/// ## Description -/// Returns the vector that contains items of type [`PairInfo`] -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **factory_contract** is the object of type [`Addr`]. -/// -/// * **start_after** is an [`Option`] field that contains array with two items of type [`AssetInfo`]. -/// -/// * **limit** is an [`Option`] field of type [`u32`]. -pub fn query_pairs_info( - querier: &QuerierWrapper, - factory_contract: Addr, - start_after: Option<[AssetInfo; 2]>, - limit: Option, -) -> StdResult { - querier.query(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: factory_contract.to_string(), - msg: to_binary(&FactoryQueryMsg::Pairs { start_after, limit })?, - })) -} - -/// ## Description -/// Returns information about the simulation of the swap in a [`SimulationResponse`] object. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **pair_contract** is the object of type [`Addr`]. -/// -/// * **offer_asset** is the object of type [`Asset`]. -pub fn simulate( - querier: &QuerierWrapper, - pair_contract: Addr, - offer_asset: &Asset, -) -> StdResult { - querier.query(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: pair_contract.to_string(), - msg: to_binary(&PairQueryMsg::Simulation { - offer_asset: offer_asset.clone(), - })?, - })) -} - -/// ## Description -/// Returns information about the reverse simulation in a [`ReverseSimulationResponse`] object. -/// ## Params -/// * **querier** is the object of type [`QuerierWrapper`]. -/// -/// * **pair_contract** is the object of type [`Addr`]. -/// -/// * **ask_asset** is the object of type [`Asset`]. -pub fn reverse_simulate( - querier: &QuerierWrapper, - pair_contract: &Addr, - ask_asset: &Asset, -) -> StdResult { - querier.query(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: pair_contract.to_string(), - msg: to_binary(&PairQueryMsg::ReverseSimulation { - ask_asset: ask_asset.clone(), - })?, - })) -} diff --git a/packages/astroport/src/router.rs b/packages/astroport/src/router.rs deleted file mode 100644 index 7679b7f4..00000000 --- a/packages/astroport/src/router.rs +++ /dev/null @@ -1,131 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -use cosmwasm_std::{Addr, Uint128}; -use cw20::Cw20ReceiveMsg; - -use crate::asset::AssetInfo; - -pub const MAX_SWAP_OPERATIONS: usize = 50; - -/// ## Description -/// This structure describes the basic settings for creating a contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - /// the astroport factory contract address - pub astroport_factory: String, -} - -/// ## Description -/// This enum describes the swap operation. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum SwapOperation { - /// Native swap - NativeSwap { - /// the offer denom - offer_denom: String, - /// the asks denom - ask_denom: String, - }, - /// ASTRO swap - AstroSwap { - /// the offer asset info - offer_asset_info: AssetInfo, - /// the asks asset info - ask_asset_info: AssetInfo, - }, -} - -impl SwapOperation { - pub fn get_target_asset_info(&self) -> AssetInfo { - match self { - SwapOperation::NativeSwap { ask_denom, .. } => AssetInfo::NativeToken { - denom: ask_denom.clone(), - }, - SwapOperation::AstroSwap { ask_asset_info, .. } => ask_asset_info.clone(), - } - } -} - -/// ## Description -/// This structure describes the execute messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - /// Receives a message of type [`Cw20ReceiveMsg`] and processes it depending on the received - /// template. - Receive(Cw20ReceiveMsg), - /// Execute multiple BuyOperation - ExecuteSwapOperations { - operations: Vec, - minimum_receive: Option, - to: Option, - }, - - /// Internal use - /// Swap all offer tokens to ask token - ExecuteSwapOperation { - operation: SwapOperation, - to: Option, - }, - /// Internal use - /// Check the swap amount is exceed minimum_receive - AssertMinimumReceive { - asset_info: AssetInfo, - prev_balance: Uint128, - minimum_receive: Uint128, - receiver: String, - }, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum Cw20HookMsg { - ExecuteSwapOperations { - /// operations for swap - operations: Vec, - /// the minimum receive for swap - minimum_receive: Option, - /// the recipient - to: Option, - }, -} - -/// ## Description -/// This structure describes the query messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - /// Config returns controls settings that specified in custom [`ConfigResponse`] structure - Config {}, - /// Simulates multi-hop swap operations - SimulateSwapOperations { - /// the offer amount - offer_amount: Uint128, - /// operations for swap - operations: Vec, - }, -} - -/// ## Description -/// This structure describes the custom struct for each query response. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct ConfigResponse { - /// the astroport factory contract address - pub astroport_factory: String, -} - -/// ## Description -/// This structure describes the custom struct for each query response. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct SimulateSwapOperationsResponse { - /// the amount of swap - pub amount: Uint128, -} - -/// ## Description -/// This structure describes a migration message. -/// We currently take no arguments for migrations. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct MigrateMsg {} diff --git a/packages/astroport/src/staking.rs b/packages/astroport/src/staking.rs deleted file mode 100644 index 194fc2c9..00000000 --- a/packages/astroport/src/staking.rs +++ /dev/null @@ -1,58 +0,0 @@ -use cosmwasm_std::Addr; -use cw20::Cw20ReceiveMsg; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -/// ## Description -/// This structure describes the basic settings for creating a contract. -#[derive(Serialize, Deserialize, JsonSchema)] -pub struct InstantiateMsg { - /// the token code identifier - pub token_code_id: u64, - /// the deposit token address - pub deposit_token_addr: String, -} - -/// ## Description -/// This structure describes the execute messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - /// Receives a message of type [`Cw20ReceiveMsg`] and processes it depending on the received - /// template. - Receive(Cw20ReceiveMsg), -} - -/// ## Description -/// This structure describes the query messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - /// Config returns controls settings that specified in custom [`ConfigResponse`] structure - Config {}, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct ConfigResponse { - /// the deposit token address - pub deposit_token_addr: Addr, - /// the share token address - pub share_token_addr: Addr, -} - -/// ## Description -/// This structure describes a migration message. -/// We currently take no arguments for migrations. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct MigrateMsg {} - -/// ## Description -/// This structure describes a CW20 hook message. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum Cw20HookMsg { - /// Deposits token to get share token amount - Enter {}, - /// Unstakes share token to move back deposit token amount. Burns share. - Leave {}, -} diff --git a/packages/astroport/src/testing.rs b/packages/astroport/src/testing.rs deleted file mode 100644 index 61dbc78f..00000000 --- a/packages/astroport/src/testing.rs +++ /dev/null @@ -1,354 +0,0 @@ -use crate::asset::{format_lp_token_name, Asset, AssetInfo, PairInfo}; -use crate::mock_querier::mock_dependencies; -use crate::querier::{ - query_all_balances, query_balance, query_pair_info, query_supply, query_token_balance, -}; - -use crate::factory::PairType; -use crate::DecimalCheckedOps; -use cosmwasm_std::testing::MOCK_CONTRACT_ADDR; -use cosmwasm_std::{to_binary, Addr, BankMsg, Coin, CosmosMsg, Decimal, Uint128, WasmMsg}; -use cw20::Cw20ExecuteMsg; - -#[test] -fn token_balance_querier() { - let mut deps = mock_dependencies(&[]); - - deps.querier.with_token_balances(&[( - &String::from("liquidity0000"), - &[(&String::from(MOCK_CONTRACT_ADDR), &Uint128::new(123u128))], - )]); - - deps.querier.with_cw20_query_handler(); - assert_eq!( - Uint128::new(123u128), - query_token_balance( - &deps.as_ref().querier, - Addr::unchecked("liquidity0000"), - Addr::unchecked(MOCK_CONTRACT_ADDR), - ) - .unwrap() - ); - deps.querier.with_default_query_handler() -} - -#[test] -fn balance_querier() { - let deps = mock_dependencies(&[Coin { - denom: "uusd".to_string(), - amount: Uint128::new(200u128), - }]); - - assert_eq!( - query_balance( - &deps.as_ref().querier, - Addr::unchecked(MOCK_CONTRACT_ADDR), - "uusd".to_string() - ) - .unwrap(), - Uint128::new(200u128) - ); -} - -#[test] -fn all_balances_querier() { - let deps = mock_dependencies(&[ - Coin { - denom: "uusd".to_string(), - amount: Uint128::new(200u128), - }, - Coin { - denom: "ukrw".to_string(), - amount: Uint128::new(300u128), - }, - ]); - - assert_eq!( - query_all_balances(&deps.as_ref().querier, Addr::unchecked(MOCK_CONTRACT_ADDR),).unwrap(), - vec![ - Coin { - denom: "uusd".to_string(), - amount: Uint128::new(200u128), - }, - Coin { - denom: "ukrw".to_string(), - amount: Uint128::new(300u128), - } - ] - ); -} - -#[test] -fn supply_querier() { - let mut deps = mock_dependencies(&[]); - - deps.querier.with_token_balances(&[( - &String::from("liquidity0000"), - &[ - (&String::from(MOCK_CONTRACT_ADDR), &Uint128::new(123u128)), - (&String::from("addr00000"), &Uint128::new(123u128)), - (&String::from("addr00001"), &Uint128::new(123u128)), - (&String::from("addr00002"), &Uint128::new(123u128)), - ], - )]); - - deps.querier.with_cw20_query_handler(); - - assert_eq!( - query_supply(&deps.as_ref().querier, Addr::unchecked("liquidity0000")).unwrap(), - Uint128::new(492u128) - ) -} - -#[test] -fn test_asset_info() { - let token_info: AssetInfo = AssetInfo::Token { - contract_addr: Addr::unchecked("asset0000"), - }; - let native_token_info: AssetInfo = AssetInfo::NativeToken { - denom: "uusd".to_string(), - }; - - assert_eq!(false, token_info.equal(&native_token_info)); - - assert_eq!( - false, - token_info.equal(&AssetInfo::Token { - contract_addr: Addr::unchecked("asset0001"), - }) - ); - - assert_eq!( - true, - token_info.equal(&AssetInfo::Token { - contract_addr: Addr::unchecked("asset0000"), - }) - ); - - assert_eq!(true, native_token_info.is_native_token()); - assert_eq!(false, token_info.is_native_token()); - - let mut deps = mock_dependencies(&[Coin { - denom: "uusd".to_string(), - amount: Uint128::new(123), - }]); - deps.querier.with_token_balances(&[( - &String::from("asset0000"), - &[ - (&String::from(MOCK_CONTRACT_ADDR), &Uint128::new(123u128)), - (&String::from("addr00000"), &Uint128::new(123u128)), - (&String::from("addr00001"), &Uint128::new(123u128)), - (&String::from("addr00002"), &Uint128::new(123u128)), - ], - )]); - - assert_eq!( - native_token_info - .query_pool(&deps.as_ref().querier, Addr::unchecked(MOCK_CONTRACT_ADDR)) - .unwrap(), - Uint128::new(123u128) - ); - deps.querier.with_cw20_query_handler(); - assert_eq!( - token_info - .query_pool(&deps.as_ref().querier, Addr::unchecked(MOCK_CONTRACT_ADDR)) - .unwrap(), - Uint128::new(123u128) - ); -} - -#[test] -fn test_asset() { - let mut deps = mock_dependencies(&[Coin { - denom: "uusd".to_string(), - amount: Uint128::new(123), - }]); - - deps.querier.with_token_balances(&[( - &String::from("asset0000"), - &[ - (&String::from(MOCK_CONTRACT_ADDR), &Uint128::new(123u128)), - (&String::from("addr00000"), &Uint128::new(123u128)), - (&String::from("addr00001"), &Uint128::new(123u128)), - (&String::from("addr00002"), &Uint128::new(123u128)), - ], - )]); - - deps.querier.with_tax( - Decimal::percent(1), - &[(&"uusd".to_string(), &Uint128::new(1000000u128))], - ); - - let token_asset = Asset { - amount: Uint128::new(123123u128), - info: AssetInfo::Token { - contract_addr: Addr::unchecked("asset0000"), - }, - }; - - let native_token_asset = Asset { - amount: Uint128::new(123123u128), - info: AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - }; - - assert_eq!( - token_asset.compute_tax(&deps.as_ref().querier).unwrap(), - Uint128::zero() - ); - assert_eq!( - native_token_asset - .compute_tax(&deps.as_ref().querier) - .unwrap(), - Uint128::new(1220u128) - ); - - assert_eq!( - native_token_asset - .deduct_tax(&deps.as_ref().querier) - .unwrap(), - Coin { - denom: "uusd".to_string(), - amount: Uint128::new(121903u128), - } - ); - - assert_eq!( - token_asset - .into_msg(&deps.as_ref().querier, Addr::unchecked("addr0000")) - .unwrap(), - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: String::from("asset0000"), - msg: to_binary(&Cw20ExecuteMsg::Transfer { - recipient: String::from("addr0000"), - amount: Uint128::new(123123u128), - }) - .unwrap(), - funds: vec![], - }) - ); - - assert_eq!( - native_token_asset - .into_msg(&deps.as_ref().querier, Addr::unchecked("addr0000")) - .unwrap(), - CosmosMsg::Bank(BankMsg::Send { - to_address: String::from("addr0000"), - amount: vec![Coin { - denom: "uusd".to_string(), - amount: Uint128::new(121903u128), - }] - }) - ); -} - -#[test] -fn query_astroport_pair_contract() { - let mut deps = mock_dependencies(&[]); - - deps.querier.with_astroport_pairs(&[( - &"asset0000uusd".to_string(), - &PairInfo { - asset_infos: [ - AssetInfo::Token { - contract_addr: Addr::unchecked("asset0000"), - }, - AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - ], - contract_addr: Addr::unchecked("pair0000"), - liquidity_token: Addr::unchecked("liquidity0000"), - pair_type: PairType::Xyk {}, - }, - )]); - - let pair_info: PairInfo = query_pair_info( - &deps.as_ref().querier, - Addr::unchecked(MOCK_CONTRACT_ADDR), - &[ - AssetInfo::Token { - contract_addr: Addr::unchecked("asset0000"), - }, - AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - ], - ) - .unwrap(); - - assert_eq!(pair_info.contract_addr, String::from("pair0000"),); - assert_eq!(pair_info.liquidity_token, String::from("liquidity0000"),); -} - -#[test] -fn test_format_lp_token_name() { - let mut deps = mock_dependencies(&[]); - deps.querier.with_astroport_pairs(&[( - &"asset0000uusd".to_string(), - &PairInfo { - asset_infos: [ - AssetInfo::Token { - contract_addr: Addr::unchecked("asset0000"), - }, - AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - ], - contract_addr: Addr::unchecked("pair0000"), - liquidity_token: Addr::unchecked("liquidity0000"), - pair_type: PairType::Xyk {}, - }, - )]); - - let pair_info: PairInfo = query_pair_info( - &deps.as_ref().querier, - Addr::unchecked(MOCK_CONTRACT_ADDR), - &[ - AssetInfo::Token { - contract_addr: Addr::unchecked("asset0000"), - }, - AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - ], - ) - .unwrap(); - - deps.querier.with_token_balances(&[( - &String::from("asset0000"), - &[(&String::from(MOCK_CONTRACT_ADDR), &Uint128::new(123u128))], - )]); - - deps.querier.with_cw20_query_handler(); - - let lp_name = format_lp_token_name(pair_info.asset_infos, &deps.as_ref().querier).unwrap(); - assert_eq!(lp_name, "MAPP-UUSD-LP") -} - -#[test] -fn test_decimal_checked_ops() { - for i in 0u32..100u32 { - let dec = Decimal::from_ratio(i, 1u32); - assert_eq!(dec + dec, dec.checked_add(dec).unwrap()); - } - assert!( - Decimal::from_ratio(Uint128::MAX, Uint128::from(10u128.pow(18u32))) - .checked_add(Decimal::one()) - .is_err() - ); - - for i in 0u128..100u128 { - let dec = Decimal::from_ratio(i, 1u128); - assert_eq!( - dec * Uint128::new(i), - dec.checked_mul(Uint128::new(i)).unwrap() - ); - } - assert!( - Decimal::from_ratio(Uint128::MAX, Uint128::from(10u128.pow(18u32))) - .checked_mul(Uint128::from(10u128.pow(18u32) + 1)) - .is_err() - ); -} diff --git a/packages/astroport/src/token.rs b/packages/astroport/src/token.rs deleted file mode 100644 index 19cf020b..00000000 --- a/packages/astroport/src/token.rs +++ /dev/null @@ -1,81 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -use cosmwasm_std::{StdError, StdResult, Uint128}; -use cw20::{Cw20Coin, MinterResponse}; - -/// ## Description -/// This structure describes the basic settings for creating a token contract. -/// TokenContract InstantiateMsg -#[derive(Serialize, Deserialize, JsonSchema)] -pub struct InstantiateMsg { - /// the name - pub name: String, - /// the symbol - pub symbol: String, - /// the precision after the decimal point - pub decimals: u8, - /// the initial balance of token - pub initial_balances: Vec, - /// the controls configs of type [`MinterResponse`] - pub mint: Option, -} - -/// ## Description -/// This structure describes a migration message. -/// We currently take no arguments for migrations. -#[derive(Serialize, Deserialize, JsonSchema)] -pub struct MigrateMsg {} - -impl InstantiateMsg { - pub fn get_cap(&self) -> Option { - self.mint.as_ref().and_then(|v| v.cap) - } - - pub fn validate(&self) -> StdResult<()> { - // Check name, symbol, decimals - if !is_valid_name(&self.name) { - return Err(StdError::generic_err( - "Name is not in the expected format (3-50 UTF-8 bytes)", - )); - } - if !is_valid_symbol(&self.symbol) { - return Err(StdError::generic_err( - "Ticker symbol is not in expected format [a-zA-Z\\-]{3,12}", - )); - } - if self.decimals > 18 { - return Err(StdError::generic_err("Decimals must not exceed 18")); - } - Ok(()) - } -} - -/// ## Description -/// Checks the validity of the token name -/// ## Params -/// * **name** is the object of type [`str`]. the name to check -fn is_valid_name(name: &str) -> bool { - let bytes = name.as_bytes(); - if bytes.len() < 3 || bytes.len() > 50 { - return false; - } - true -} - -/// ## Description -/// Checks the validity of the token symbol -/// ## Params -/// * **symbol** is the object of type [`str`]. the symbol to check -fn is_valid_symbol(symbol: &str) -> bool { - let bytes = symbol.as_bytes(); - if bytes.len() < 3 || bytes.len() > 12 { - return false; - } - for byte in bytes.iter() { - if (*byte != 45) && (*byte < 65 || *byte > 90) && (*byte < 97 || *byte > 122) { - return false; - } - } - true -} diff --git a/packages/astroport/src/vesting.rs b/packages/astroport/src/vesting.rs deleted file mode 100644 index 86cc944e..00000000 --- a/packages/astroport/src/vesting.rs +++ /dev/null @@ -1,161 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -use cosmwasm_std::{Addr, Order, Timestamp, Uint128}; -use cw20::Cw20ReceiveMsg; - -/// ## Description -/// This structure describes the basic settings for creating a contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - /// the token address - pub token_addr: String, -} - -/// ## Description -/// This structure describes the execute messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - /// Claims the amount from Vesting for transfer to the recipient - Claim { - /// the recipient of claim - recipient: Option, - /// the amount of claim - amount: Option, - }, - /// Receives a message of type [`Cw20ReceiveMsg`] and processes it depending on the received - /// template. - Receive(Cw20ReceiveMsg), -} - -/// ## Description -/// This structure describes the basic settings for vesting account. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct VestingAccount { - /// the address of account - pub address: String, - /// the schedules of account - pub schedules: Vec, -} - -/// ## Description -/// This structure describes the basic settings for vesting information. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct VestingInfo { - /// the schedules - pub schedules: Vec, - /// the released amount - pub released_amount: Uint128, -} - -/// ## Description -/// This structure describes the basic settings for vesting schedule. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct VestingSchedule { - /// the start point of schedule - pub start_point: VestingSchedulePoint, - /// the end point of schedule - pub end_point: Option, -} - -/// ## Description -/// This structure describes the basic settings for vesting schedule point. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct VestingSchedulePoint { - /// the time - pub time: Timestamp, - /// the amount - pub amount: Uint128, -} - -/// ## Description -/// This structure describes the query messages of the contract. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - /// ## Description - /// Returns information about the vesting configs in the [`ConfigResponse`] object. - Config {}, - /// ## Description - /// Returns information about the vesting account in the [`VestingAccountResponse`] object. - VestingAccount { address: Addr }, - /// ## Description - /// Returns a list of accounts, for the given input parameters, in the [`VestingAccountsResponse`] object. - VestingAccounts { - start_after: Option, - limit: Option, - order_by: Option, - }, - /// ## Description - /// Returns the available amount for specified account. - AvailableAmount { address: Addr }, -} - -/// ## Description -/// This structure describes the custom struct for each query response. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct ConfigResponse { - /// the token address - pub token_addr: Addr, -} - -/// ## Description -/// This structure describes the custom struct for each query response. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct VestingAccountResponse { - /// the token address - pub address: Addr, - /// the information object of type [`VestingInfo`] - pub info: VestingInfo, -} - -/// ## Description -/// This structure describes the custom struct for each query response. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct VestingAccountsResponse { - /// the vesting accounts information - pub vesting_accounts: Vec, -} - -/// ## Description -/// This enum describes the type of sort -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum OrderBy { - /// Ascending - Asc, - /// Descending - Desc, -} - -// We suppress this clippy warning because Order in cosmwasm doesn't implement Debug and -// PartialEq for usage in QueryMsg, we need to use our own OrderBy and -// convert it finally to cosmwasm's Order -#[allow(clippy::from_over_into)] -impl Into for OrderBy { - fn into(self) -> Order { - if self == OrderBy::Asc { - Order::Ascending - } else { - Order::Descending - } - } -} - -/// ## Description -/// This structure describes a migration message. -/// We currently take no arguments for migrations. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct MigrateMsg {} - -/// ## Description -/// This structure describes a CW20 hook message. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum Cw20HookMsg { - /// Register vesting accounts - RegisterVestingAccounts { - vesting_accounts: Vec, - }, -} diff --git a/packages/nebula_protocol/Cargo.toml b/packages/nebula_protocol/Cargo.toml index 4d5bddd8..4ba100d3 100644 --- a/packages/nebula_protocol/Cargo.toml +++ b/packages/nebula_protocol/Cargo.toml @@ -24,7 +24,7 @@ backtraces = ["cosmwasm-std/backtraces"] cw20 = { version = "0.8.0" } cosmwasm-std = { version = "0.16.2", default-features = false } cosmwasm-storage = { version = "0.16.2", default-features = false, features = ["iterator"] } -astroport = { path = "../astroport" } +astroport = { version = "1.0" } schemars = "0.8.1" cluster-math = { path = "../../libraries/cluster-math" } serde = { version = "1.0.103", default-features = false, features = ["derive"] }