From 4968d5a2466c4f54c5abd4a700bda5558549c4c1 Mon Sep 17 00:00:00 2001 From: bekauz Date: Thu, 25 Jul 2024 18:21:24 +0200 Subject: [PATCH] updated tf liquid pooler --- .../astroport-tf-liquid-pooler/Cargo.toml | 15 +- .../astroport-tf-liquid-pooler/src/lib.rs | 4 - .../src/suite_tests/mod.rs | 100 ------- .../src/suite_tests/suite.rs | 55 ---- .../src/suite_tests/suite_builder.rs | 263 ------------------ .../src/suite_tests/tests.rs | 6 - 6 files changed, 3 insertions(+), 440 deletions(-) delete mode 100644 contracts/astroport-tf-liquid-pooler/src/suite_tests/mod.rs delete mode 100644 contracts/astroport-tf-liquid-pooler/src/suite_tests/suite.rs delete mode 100644 contracts/astroport-tf-liquid-pooler/src/suite_tests/suite_builder.rs delete mode 100644 contracts/astroport-tf-liquid-pooler/src/suite_tests/tests.rs diff --git a/contracts/astroport-tf-liquid-pooler/Cargo.toml b/contracts/astroport-tf-liquid-pooler/Cargo.toml index e946d682..87b26db8 100644 --- a/contracts/astroport-tf-liquid-pooler/Cargo.toml +++ b/contracts/astroport-tf-liquid-pooler/Cargo.toml @@ -20,8 +20,8 @@ backtraces = ["cosmwasm-std/backtraces"] library = [] [dependencies] -covenant-macros = { workspace = true } -valence-clock = { workspace = true, features = ["library"] } +covenant-macros = { git = "https://github.com/timewave-computer/covenants", tag = "v0.1.0" } +valence-clock = { git = "https://github.com/timewave-computer/covenants", tag = "v0.1.0", features = ["library"] } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } @@ -42,7 +42,6 @@ bech32 = { workspace = true } astroport = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v5.0.0" } astroport-xastro-token = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v5.0.0" } -astroport-whitelist = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v5.0.0" } astroport-factory = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v5.0.0" } astroport-native-coin-registry = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v5.0.0" } astroport-pair-stable = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v5.0.0" } @@ -50,12 +49,4 @@ astroport-pair-concentrated = { git = "https://github.com/astroport-fi/astrop astroport-pair = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v5.0.0" } cw20 = { workspace = true } -covenant-utils = { workspace = true } - -[dev-dependencies] -cw-multi-test = { workspace = true } -anyhow = { workspace = true } -valence-single-party-pol-holder = { workspace = true } -# unit-tests = { workspace = true } -# neutron-sdk = { workspace = true } -cw1-whitelist = { version = "1.1", features = ["library"] } +covenant-utils = { git = "https://github.com/timewave-computer/covenants", tag = "v0.1.0" } diff --git a/contracts/astroport-tf-liquid-pooler/src/lib.rs b/contracts/astroport-tf-liquid-pooler/src/lib.rs index 2b0564e6..0faea8f4 100644 --- a/contracts/astroport-tf-liquid-pooler/src/lib.rs +++ b/contracts/astroport-tf-liquid-pooler/src/lib.rs @@ -6,7 +6,3 @@ pub mod contract; pub mod error; pub mod msg; pub mod state; - -#[allow(clippy::unwrap_used)] -#[cfg(test)] -pub mod suite_tests; diff --git a/contracts/astroport-tf-liquid-pooler/src/suite_tests/mod.rs b/contracts/astroport-tf-liquid-pooler/src/suite_tests/mod.rs deleted file mode 100644 index bb9b4437..00000000 --- a/contracts/astroport-tf-liquid-pooler/src/suite_tests/mod.rs +++ /dev/null @@ -1,100 +0,0 @@ -pub mod suite; -pub mod suite_builder; -pub mod tests; - -use cosmwasm_std::{DepsMut, Empty, Env, MessageInfo}; -use cw_multi_test::{Contract, ContractWrapper}; - -pub fn liquid_pooler_contract() -> Box> { - let contract = ContractWrapper::new( - crate::contract::execute, - crate::contract::instantiate, - crate::contract::query, - ) - .with_reply(crate::contract::reply) - .with_migrate(crate::contract::migrate); - - Box::new(contract) -} - -pub fn holder_contract() -> Box> { - let contract = ContractWrapper::new( - valence_single_party_pol_holder::contract::execute, - valence_single_party_pol_holder::contract::instantiate, - valence_single_party_pol_holder::contract::query, - ) - .with_migrate(valence_single_party_pol_holder::contract::migrate); - - Box::new(contract) -} - -pub fn astro_whitelist_contract() -> Box> { - let contract = ContractWrapper::new( - cw1_whitelist::contract::execute, - cw1_whitelist::contract::instantiate, - cw1_whitelist::contract::query, - ); - - Box::new(contract) -} - -pub fn astro_token_contract() -> Box> { - let contract = ContractWrapper::new( - astroport_xastro_token::contract::execute, - astroport_xastro_token::contract::instantiate, - astroport_xastro_token::contract::query); - - Box::new(contract) -} - -pub fn astro_factory_contract() -> Box> { - let contract = ContractWrapper::new( - astroport_factory::contract::execute, - astroport_factory::contract::instantiate, - astroport_factory::contract::query, - ).with_reply(astroport_factory::contract::reply); - - Box::new(contract) -} - -pub fn astro_pair_stable_contract() -> Box> { - let contract = ContractWrapper::new( - astroport_pair_stable::contract::execute, - astroport_pair_stable::contract::instantiate, - astroport_pair_stable::contract::query, - ) - .with_reply(astroport_pair_stable::contract::reply); - - Box::new(contract) -} - -pub fn astro_pair_custom_concentrated_contract() -> Box> { - let contract = ContractWrapper::new( - astroport_pair_concentrated::contract::execute, - astroport_pair_concentrated::contract::instantiate, - astroport_pair_stable::contract::query, - ); - - Box::new(contract) -} - -pub fn astro_pair_xyk_contract() -> Box> { - let contract = ContractWrapper::new( - astroport_pair::contract::execute, - astroport_pair::contract::instantiate, - astroport_pair::contract::query, - ) - .with_reply(astroport_pair::contract::reply); - - Box::new(contract) -} - -pub fn astro_coin_registry_contract() -> Box> { - let contract = ContractWrapper::new( - astroport_native_coin_registry::contract::execute, - astroport_native_coin_registry::contract::instantiate, - astroport_native_coin_registry::contract::query, - ); - - Box::new(contract) -} diff --git a/contracts/astroport-tf-liquid-pooler/src/suite_tests/suite.rs b/contracts/astroport-tf-liquid-pooler/src/suite_tests/suite.rs deleted file mode 100644 index 3542883c..00000000 --- a/contracts/astroport-tf-liquid-pooler/src/suite_tests/suite.rs +++ /dev/null @@ -1,55 +0,0 @@ -use crate::msg::{ContractState, ExecuteMsg, LpConfig, QueryMsg}; -use cosmwasm_std::Addr; -use cw_multi_test::{App, AppResponse, Executor}; - -pub const ADMIN: &str = "admin"; -pub const CLOCK: &str = "clock"; -pub const ATOM: &str = "uatom"; -pub const NEUTRON: &str = "untrn"; - -pub struct Suite { - pub app: App, - pub astroport_tf_liquid_pooler: Addr, - pub liquidity_pool: Addr, -} - -// actions -impl Suite { - pub fn tick(&mut self, caller: &str) -> AppResponse { - self.app - .execute_contract( - Addr::unchecked(caller), - self.astroport_tf_liquid_pooler.clone(), - &ExecuteMsg::Tick {}, - &[], - ) - .unwrap() - } -} - -// queries -impl Suite { - pub fn query_clock_addr(&self) -> Addr { - self.app - .wrap() - .query_wasm_smart(&self.astroport_tf_liquid_pooler, &QueryMsg::ClockAddress {}) - .unwrap() - } - - pub fn query_contract_state(&self) -> ContractState { - self.app - .wrap() - .query_wasm_smart( - &self.astroport_tf_liquid_pooler, - &QueryMsg::ContractState {}, - ) - .unwrap() - } - - pub fn query_lp_config(&self) -> LpConfig { - self.app - .wrap() - .query_wasm_smart(&self.astroport_tf_liquid_pooler, &QueryMsg::LpConfig {}) - .unwrap() - } -} diff --git a/contracts/astroport-tf-liquid-pooler/src/suite_tests/suite_builder.rs b/contracts/astroport-tf-liquid-pooler/src/suite_tests/suite_builder.rs deleted file mode 100644 index 6be9ad45..00000000 --- a/contracts/astroport-tf-liquid-pooler/src/suite_tests/suite_builder.rs +++ /dev/null @@ -1,263 +0,0 @@ -use std::str::FromStr; - -use astroport::{factory::PairType, native_coin_registry::CoinResponse}; -use cosmwasm_std::{to_json_binary, Addr, Decimal, Uint128}; -use covenant_utils::{PoolPriceConfig, SingleSideLpLimits}; -use cw_multi_test::{App, Executor}; - -use crate::{msg::{AssetData, InstantiateMsg}, suite_tests::{astro_pair_custom_concentrated_contract, astro_pair_stable_contract, astro_pair_xyk_contract, astro_token_contract, astro_whitelist_contract}}; - -use super::{ - astro_coin_registry_contract, astro_factory_contract, holder_contract, liquid_pooler_contract, suite::{Suite, ADMIN, ATOM, CLOCK, NEUTRON} -}; - -pub struct SuiteBuilder { - pub pool_address: String, - pub clock_address: String, - pub slippage_tolerance: Option, - pub assets: AssetData, - pub single_side_lp_limits: SingleSideLpLimits, - pub pool_price_config: PoolPriceConfig, - pub pair_type: PairType, - pub holder_address: String, - pub app: App, -} - -impl Default for SuiteBuilder { - fn default() -> Self { - Self { - app: App::default(), - pool_address: "todo".to_string(), - clock_address: CLOCK.to_string(), - slippage_tolerance: None, - assets: AssetData { - asset_a_denom: ATOM.to_string(), - asset_b_denom: NEUTRON.to_string(), - }, - single_side_lp_limits: SingleSideLpLimits { - asset_a_limit: Uint128::new(10_000), - asset_b_limit: Uint128::new(10_000), - }, - pool_price_config: PoolPriceConfig { - expected_spot_price: Decimal::from_str("0.1").unwrap(), - acceptable_price_spread: Decimal::from_str("0.01").unwrap(), - }, - pair_type: PairType::Xyk {}, - holder_address: "todo".to_string(), - } - } -} - -impl SuiteBuilder { - pub fn with_slippage_tolerance(mut self, slippage_tolerance: Option) -> Self { - self.slippage_tolerance = slippage_tolerance; - self - } - - pub fn with_assets(mut self, assets: AssetData) -> Self { - self.assets = assets; - self - } - - pub fn with_single_side_lp_limits(mut self, single_side_lp_limits: SingleSideLpLimits) -> Self { - self.single_side_lp_limits = single_side_lp_limits; - self - } - - pub fn with_pool_price_config(mut self, pool_price_config: PoolPriceConfig) -> Self { - self.pool_price_config = pool_price_config; - self - } - - pub fn with_pair_type(mut self, pair_type: PairType) -> Self { - self.pair_type = pair_type; - self - } - - pub fn with_holder_address(mut self, holder_address: String) -> Self { - self.holder_address = holder_address; - self - } - - - pub fn setup_astroport(&mut self) { - let astroport_native_coin_registry_code = self.app.store_code(astro_coin_registry_contract()); - let astro_factory_code = self.app.store_code(astro_factory_contract()); - let astroport_pair_stable_code = self.app.store_code(astro_pair_stable_contract()); - let astroport_pair_concentrated_code = self.app.store_code(astro_pair_custom_concentrated_contract()); - let astroport_pair_xyk_code = self.app.store_code(astro_pair_xyk_contract()); - let astroport_whitelist_code = self.app.store_code(astro_whitelist_contract()); - let astroport_token_code = self.app.store_code(astro_token_contract()); - - let token_addr = self.app - .instantiate_contract( - astroport_token_code, - Addr::unchecked(ADMIN), - &astroport::token::InstantiateMsg { - name: "nativetoken".to_string(), - symbol: "ntk".to_string(), - decimals: 5, - initial_balances: vec![], - mint: None, - marketing: None, - }, - &[], - "token", - None, - ) - .unwrap(); - - println!("token_addr: {:?}", token_addr); - - let astroport_whitelist = self - .app - .instantiate_contract( - astroport_whitelist_code, - Addr::unchecked(ADMIN), - &cw1_whitelist::msg::InstantiateMsg { - admins: vec![ADMIN.to_string()], - mutable: false, - }, - &[], - "whitelist", - None, - ) - .unwrap(); - - println!("astroport_whitelist: {:?}", astroport_whitelist); - - let native_coins_registry = self - .app - .instantiate_contract( - astroport_native_coin_registry_code, - Addr::unchecked(ADMIN), - &astroport::native_coin_registry::InstantiateMsg { - owner: ADMIN.to_string(), - }, - &[], - "coin_registry", - None, - ) - .unwrap(); - - println!("native_coins_registry: {:?}", native_coins_registry); - - let register_coins_response = self.app - .execute_contract( - Addr::unchecked(ADMIN.to_string()), - native_coins_registry.clone(), - &astroport::native_coin_registry::ExecuteMsg::Add { - native_coins: vec![(ATOM.to_string(), 6), (NEUTRON.to_string(), 6)], - }, - &[], - ) - .unwrap(); - println!("register_coins_response: {:?}", register_coins_response); - - let resp: Vec = self.app.wrap() - .query_wasm_smart( - native_coins_registry.clone(), - &astroport::native_coin_registry::QueryMsg::NativeTokens { start_after: None, limit: None }, - ) - .unwrap(); - - println!("coin registry query response: {:?}", resp); - - let astroport_factory = self.app.instantiate_contract( - astro_factory_code, - Addr::unchecked(ADMIN), - &astroport::factory::InstantiateMsg { - pair_configs: vec![ - astroport::factory::PairConfig { - code_id: astroport_pair_xyk_code, - pair_type: astroport::factory::PairType::Xyk {}, - total_fee_bps: 0, - maker_fee_bps: 0, - is_disabled: false, - is_generator_disabled: true, - permissioned: false, - }, - ], - token_code_id: astroport_token_code, - fee_address: None, - generator_address: None, - owner: ADMIN.to_string(), - whitelist_code_id: astroport_whitelist_code, - coin_registry_address: native_coins_registry.to_string(), - tracker_config: None, - }, - &[], - "factory", - None, - ).unwrap(); - - println!("\nastroport_factory: {:?}\n", astroport_factory); - - let xyk_init_params = to_json_binary(&astroport::pair::XYKPoolParams { - track_asset_balances: None, - }) - .unwrap(); - - let create_pair_execute_msg = astroport::factory::ExecuteMsg::CreatePair { - pair_type: PairType::Xyk {}, - asset_infos: vec![ - astroport::asset::AssetInfo::NativeToken { - denom: ATOM.to_string(), - }, - astroport::asset::AssetInfo::NativeToken { - denom: NEUTRON.to_string(), - }, - ], - init_params: Some(xyk_init_params), - }; - - println!("create_pair_execute_msg: {:?}", create_pair_execute_msg); - let astroport_pair_instance = self.app.execute_contract( - Addr::unchecked(ADMIN.to_string()), - astroport_factory.clone(), - &create_pair_execute_msg, - &[], - ).unwrap(); - - println!("astroport_pair_instance: {:?}", astroport_pair_instance); - } - - pub fn build(mut self) -> Suite { - let mut app = App::default(); - - let holder_code = app.store_code(holder_contract()); - let liquid_pooler_code = app.store_code(liquid_pooler_contract()); - - self.setup_astroport(); - - let instantiate_msg = InstantiateMsg { - pool_address: self.pool_address, - clock_address: self.clock_address, - slippage_tolerance: self.slippage_tolerance, - assets: self.assets, - single_side_lp_limits: self.single_side_lp_limits, - pool_price_config: self.pool_price_config, - pair_type: self.pair_type, - holder_address: self.holder_address, - }; - - // let liquid_pooler = app - // .instantiate_contract( - // liquid_pooler_code, - // Addr::unchecked(ADMIN), - // &instantiate_msg, - // &[], - // "liquid_pooler", - // Some(ADMIN.to_string()), - // ) - // .unwrap(); - - let liquidity_pool = Addr::unchecked("todo".to_string()); - - Suite { - app, - astroport_tf_liquid_pooler: Addr::unchecked("todo".to_string()), - liquidity_pool, - } - } -} diff --git a/contracts/astroport-tf-liquid-pooler/src/suite_tests/tests.rs b/contracts/astroport-tf-liquid-pooler/src/suite_tests/tests.rs deleted file mode 100644 index b5eaead8..00000000 --- a/contracts/astroport-tf-liquid-pooler/src/suite_tests/tests.rs +++ /dev/null @@ -1,6 +0,0 @@ -use super::suite_builder::SuiteBuilder; - -#[test] -fn test_instantiate_and_query_all() { - let suite = SuiteBuilder::default().build(); -}