From 4e0336a4a9ed4d60b0b7e96aafc5a4ad22373d3b Mon Sep 17 00:00:00 2001 From: Dowland Aiello Date: Sat, 7 Sep 2024 21:08:56 +0000 Subject: [PATCH] astroport: Add .with_chain builder calls. --- src/types/mod.rs | 2 - src/utils/setup/astroport.rs | 78 ++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/types/mod.rs b/src/types/mod.rs index 762819d..8ef094a 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -5,5 +5,3 @@ pub mod config; pub mod contract; pub mod ibc; - -pub mod osmosis; diff --git a/src/utils/setup/astroport.rs b/src/utils/setup/astroport.rs index 2191b60..7aae346 100644 --- a/src/utils/setup/astroport.rs +++ b/src/utils/setup/astroport.rs @@ -1,8 +1,7 @@ use super::super::{ super::{ - error::Error, CW1_WHITELIST_NAME, DEFAULT_KEY, FACTORY_NAME, FACTORY_ON_OSMOSIS_NAME, - NEUTRON_CHAIN_ADMIN_ADDR, NEUTRON_CHAIN_NAME, OSMOSIS_CHAIN_NAME, PAIR_NAME, - STABLE_PAIR_NAME, TOKEN_NAME, TOKEN_REGISTRY_NAME, WHITELIST_NAME, + error::Error, DEFAULT_KEY, FACTORY_NAME, NEUTRON_CHAIN_ADMIN_ADDR, NEUTRON_CHAIN_NAME, + PAIR_NAME, STABLE_PAIR_NAME, TOKEN_NAME, TOKEN_REGISTRY_NAME, WHITELIST_NAME, }, test_context::TestContext, }; @@ -16,6 +15,7 @@ use cosmwasm_std::Decimal; /// A tx creating a token registry. pub struct CreateTokenRegistryTxBuilder<'a> { key: Option<&'a str>, + chain: &'a str, owner: Option, test_ctx: &'a mut TestContext, } @@ -44,6 +44,7 @@ impl<'a> CreateTokenRegistryTxBuilder<'a> { self.test_ctx.tx_create_token_registry( self.key .ok_or(Error::MissingBuilderParam(String::from("key")))?, + self.chain, self.owner .clone() .ok_or(Error::MissingBuilderParam(String::from("owner")))?, @@ -54,6 +55,7 @@ impl<'a> CreateTokenRegistryTxBuilder<'a> { /// A tx creating a token registry. pub struct CreatePoolTxBuilder<'a> { key: &'a str, + chain: &'a str, pair_type: PairType, denom_a: Option, denom_b: Option, @@ -67,6 +69,12 @@ impl<'a> CreatePoolTxBuilder<'a> { self } + pub fn with_chain(&mut self, chain: &'a str) -> &mut Self { + self.chain = chain; + + self + } + pub fn with_pairtype(&mut self, pairtype: PairType) -> &mut Self { self.pair_type = pairtype; @@ -89,6 +97,7 @@ impl<'a> CreatePoolTxBuilder<'a> { pub fn send(&mut self) -> Result<(), Error> { self.test_ctx.tx_create_pool( self.key, + self.chain, self.pair_type.clone(), self.denom_a .clone() @@ -103,6 +112,7 @@ impl<'a> CreatePoolTxBuilder<'a> { /// A tx creating an astroport factory. pub struct CreateFactoryTxBuilder<'a> { key: &'a str, + chain: &'a str, owner: String, test_ctx: &'a mut TestContext, } @@ -114,6 +124,12 @@ impl<'a> CreateFactoryTxBuilder<'a> { self } + pub fn with_chain(&mut self, chain: &'a str) -> &mut Self { + self.chain = chain; + + self + } + pub fn with_owner(&mut self, owner: impl Into) -> &mut Self { self.owner = owner.into(); @@ -123,13 +139,14 @@ impl<'a> CreateFactoryTxBuilder<'a> { /// Sends the transaction. pub fn send(&mut self) -> Result<(), Error> { self.test_ctx - .tx_create_factory(self.key, self.owner.clone()) + .tx_create_factory(self.key, self.chain, self.owner.clone()) } } /// A tx funding an astroport pool. pub struct FundPoolTxBuilder<'a> { key: &'a str, + chain: &'a str, denom_a: Option, denom_b: Option, amt_denom_a: Option, @@ -146,6 +163,12 @@ impl<'a> FundPoolTxBuilder<'a> { self } + pub fn with_chain(&mut self, chain: &'a str) -> &mut Self { + self.chain = chain; + + self + } + pub fn with_denom_a(&mut self, denom_a: impl Into) -> &mut Self { self.denom_a = Some(denom_a.into()); @@ -186,6 +209,7 @@ impl<'a> FundPoolTxBuilder<'a> { pub fn send(&mut self) -> Result<(), Error> { self.test_ctx.tx_fund_pool( self.key, + self.chain, self.denom_a .clone() .ok_or(Error::MissingBuilderParam(String::from("denom_a")))?, @@ -212,6 +236,7 @@ impl TestContext { pub fn build_tx_create_token_registry(&mut self) -> CreateTokenRegistryTxBuilder { CreateTokenRegistryTxBuilder { key: Some(DEFAULT_KEY), + chain: NEUTRON_CHAIN_NAME, owner: Some(NEUTRON_CHAIN_ADMIN_ADDR.to_owned()), test_ctx: self, } @@ -221,11 +246,12 @@ impl TestContext { fn tx_create_token_registry( &mut self, key: &str, + chain: &str, owner_addr: impl Into, ) -> Result<(), Error> { let mut contract_a = self .get_contract() - .src(NEUTRON_CHAIN_NAME) + .src(chain) .contract(TOKEN_REGISTRY_NAME) .get_cw(); @@ -241,7 +267,7 @@ impl TestContext { )?; let addr = contract.address; - let neutron = self.get_mut_chain(NEUTRON_CHAIN_NAME); + let neutron = self.get_mut_chain(chain); neutron .contract_addrs @@ -254,6 +280,7 @@ impl TestContext { pub fn build_tx_create_factory(&mut self) -> CreateFactoryTxBuilder { CreateFactoryTxBuilder { key: DEFAULT_KEY, + chain: NEUTRON_CHAIN_NAME, owner: NEUTRON_CHAIN_ADMIN_ADDR.to_owned(), test_ctx: self, } @@ -263,40 +290,37 @@ impl TestContext { fn tx_create_factory( &mut self, key: &str, + chain: &str, factory_owner: impl Into, ) -> Result<(), Error> { - let chain = self.get_chain(chain_name); + let local_chain = self.get_chain(chain); let pair_xyk_code_id = - neutron + local_chain .contract_codes .get(PAIR_NAME) .ok_or(Error::MissingContextVariable(String::from( "contract_codes::astroport_pair", )))?; - let pair_stable_code_id = - neutron - .contract_codes - .get(STABLE_PAIR_NAME) - .ok_or(Error::MissingContextVariable(String::from( - "contract_codes::astroport_pair_stable", - )))?; + let pair_stable_code_id = local_chain.contract_codes.get(STABLE_PAIR_NAME).ok_or( + Error::MissingContextVariable(String::from("contract_codes::astroport_pair_stable")), + )?; let token_code_id = - neutron + local_chain .contract_codes .get(TOKEN_NAME) .ok_or(Error::MissingContextVariable(String::from( "contract_codes::cw20_base", )))?; let whitelist_code_id = - neutron + local_chain .contract_codes .get(WHITELIST_NAME) .ok_or(Error::MissingContextVariable(String::from( "contract_codes::astroport_whitelist", )))?; - let native_registry_addr = neutron.contract_addrs.get(TOKEN_REGISTRY_NAME).ok_or( + let native_registry_addr = local_chain.contract_addrs.get(TOKEN_REGISTRY_NAME).ok_or( Error::MissingContextVariable(String::from( "contract_ddrs::astroport_native_coin_registry", )), @@ -304,7 +328,7 @@ impl TestContext { let mut contract_a = self .get_contract() - .src(NEUTRON_CHAIN_NAME) + .src(chain) .contract(FACTORY_NAME) .get_cw(); @@ -345,9 +369,9 @@ impl TestContext { "", )?; - let neutron = self.get_mut_chain(NEUTRON_CHAIN_NAME); + let local_chain = self.get_mut_chain(chain); - neutron + local_chain .contract_addrs .insert(FACTORY_NAME.to_owned(), contract.address); @@ -358,6 +382,7 @@ impl TestContext { pub fn build_tx_create_pool(&mut self) -> CreatePoolTxBuilder { CreatePoolTxBuilder { key: DEFAULT_KEY, + chain: NEUTRON_CHAIN_NAME, pair_type: PairType::Xyk {}, denom_a: Default::default(), denom_b: Default::default(), @@ -369,12 +394,13 @@ impl TestContext { fn tx_create_pool( &self, key: &str, + chain: &str, pair_type: PairType, denom_a: impl Into, denom_b: impl Into, ) -> Result<(), Error> { // Factory contract instance - let contract_a = self.get_factory().src(NEUTRON_CHAIN_NAME).get_cw(); + let contract_a = self.get_factory().src(chain).get_cw(); // Create the pair let tx = contract_a.execute( @@ -400,7 +426,7 @@ impl TestContext { "transaction did not produce a tx hash", )))?; - self.guard_tx_errors(NEUTRON_CHAIN_NAME, tx_hash.as_str())?; + self.guard_tx_errors(chain, tx_hash.as_str())?; Ok(()) } @@ -409,6 +435,7 @@ impl TestContext { pub fn build_tx_fund_pool(&mut self) -> FundPoolTxBuilder { FundPoolTxBuilder { key: DEFAULT_KEY, + chain: NEUTRON_CHAIN_NAME, denom_a: Default::default(), denom_b: Default::default(), amt_denom_a: Default::default(), @@ -424,6 +451,7 @@ impl TestContext { fn tx_fund_pool( &mut self, key: &str, + chain: &str, denom_a: String, denom_b: String, amt_denom_a: u128, @@ -434,7 +462,7 @@ impl TestContext { // Get the instance from the address let pool = self .get_astro_pool() - .src(NEUTRON_CHAIN_NAME) + .src(chain) .denoms(denom_a.clone(), denom_b.clone()) .get_cw(); @@ -468,7 +496,7 @@ impl TestContext { .tx_hash .ok_or(Error::TxMissingLogs)?; - self.guard_tx_errors(NEUTRON_CHAIN_NAME, tx.as_str())?; + self.guard_tx_errors(chain, tx.as_str())?; Ok(()) }