From ee1f7b95df777c112a6428b64bec8479bb6fad32 Mon Sep 17 00:00:00 2001 From: bekauz Date: Wed, 13 Mar 2024 18:54:09 +0100 Subject: [PATCH 01/56] two party holder stores emergency committee address on instantiation --- .../two-party-pol-holder/src/contract.rs | 6 +++ contracts/two-party-pol-holder/src/msg.rs | 2 + .../src/test_two_party_pol_holder/suite.rs | 10 ++++ .../src/test_two_party_pol_holder/tests.rs | 52 +++++++++++++++++-- 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index 2710064c..c281c7a1 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -51,6 +51,11 @@ pub fn instantiate( ContractError::LockupValidationError {} ); + if let Some(addr) = &msg.emergency_committee_addr { + let committee_addr = deps.api.addr_validate(addr)?; + EMERGENCY_COMMITTEE_ADDR.save(deps.storage, &committee_addr)?; + } + msg.covenant_config.validate(deps.api)?; msg.ragequit_config.validate( msg.covenant_config.party_a.allocation, @@ -571,6 +576,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { QueryMsg::Config {} => Ok(to_json_binary(&COVENANT_CONFIG.load(deps.storage)?)?), QueryMsg::DepositAddress {} => Ok(to_json_binary(&env.contract.address)?), QueryMsg::DenomSplits {} => Ok(to_json_binary(&DENOM_SPLITS.load(deps.storage)?)?), + QueryMsg::EmergencyCommittee {} => Ok(to_json_binary(&EMERGENCY_COMMITTEE_ADDR.may_load(deps.storage)?)?), } } diff --git a/contracts/two-party-pol-holder/src/msg.rs b/contracts/two-party-pol-holder/src/msg.rs index a33ba79b..23d73528 100644 --- a/contracts/two-party-pol-holder/src/msg.rs +++ b/contracts/two-party-pol-holder/src/msg.rs @@ -444,6 +444,8 @@ pub enum QueryMsg { Config {}, #[returns(DenomSplits)] DenomSplits {}, + #[returns(Addr)] + EmergencyCommittee {}, } #[cw_serde] diff --git a/unit-tests/src/test_two_party_pol_holder/suite.rs b/unit-tests/src/test_two_party_pol_holder/suite.rs index 80a6ddad..82abca20 100644 --- a/unit-tests/src/test_two_party_pol_holder/suite.rs +++ b/unit-tests/src/test_two_party_pol_holder/suite.rs @@ -427,6 +427,16 @@ impl Suite { ) .unwrap() } + + pub fn query_emergency_committee(&mut self) -> Addr { + self.app + .wrap() + .query_wasm_smart( + self.holder_addr.clone(), + &covenant_two_party_pol_holder::msg::QueryMsg::EmergencyCommittee {}, + ) + .unwrap() + } } impl BaseSuiteMut for Suite { diff --git a/unit-tests/src/test_two_party_pol_holder/tests.rs b/unit-tests/src/test_two_party_pol_holder/tests.rs index 875fc056..6536e059 100644 --- a/unit-tests/src/test_two_party_pol_holder/tests.rs +++ b/unit-tests/src/test_two_party_pol_holder/tests.rs @@ -29,6 +29,14 @@ fn test_instantiate_validates_clock_addr() { .build(); } +#[test] +#[should_panic] +fn test_instantiate_validates_emergency_committee_addr() { + TwoPartyHolderBuilder::default() + .with_emergency_committee("invalid") + .build(); +} + #[test] #[should_panic(expected = "deposit deadline is already past")] fn test_instantiate_validates_deposit_deadline() { @@ -519,7 +527,7 @@ fn test_execute_claim_happy() { } #[test] -// #[should_panic(expected = "unauthorized")] TODO: enable +#[should_panic(expected = "unauthorized")] fn test_execute_emergency_withdraw_validates_committee_address() { let builder = TwoPartyHolderBuilder::default(); let clock = builder.instantiate_msg.msg.clock_address.clone(); @@ -535,9 +543,42 @@ fn test_execute_emergency_withdraw_validates_committee_address() { suite.tick_contract(suite.holder_addr.clone()); suite.tick_contract(suite.next_contract.clone()); - let _sender = suite.faucet.clone(); - // enable this after we save the address - // suite.emergency_withdraw(sender.as_str()); + let sender = suite.faucet.clone(); + + suite.emergency_withdraw(sender.as_str()); +} + +#[test] +fn test_execute_emergency_withdraw_happy() { + let builder = TwoPartyHolderBuilder::default(); + let clock = builder.instantiate_msg.msg.clock_address.clone(); + let mut suite = builder.with_emergency_committee(clock.as_str()).build(); + + suite.fund_contract( + &vec![ + coin(10_001, DENOM_ATOM_ON_NTRN), + coin(10_001, DENOM_LS_ATOM_ON_NTRN), + ], + suite.holder_addr.clone(), + ); + suite.tick_contract(suite.holder_addr.clone()); + suite.tick_contract(suite.next_contract.clone()); + + suite.emergency_withdraw(clock.as_str()); + + let party_a = Addr::unchecked(suite.covenant_config.party_a.router.to_string()); + let party_b = Addr::unchecked(suite.covenant_config.party_b.router.to_string()); + + let party_a_atom_bal = suite.query_balance(&party_a, DENOM_ATOM_ON_NTRN).amount; + let party_b_atom_bal = suite.query_balance(&party_b, DENOM_ATOM_ON_NTRN).amount; + let party_a_ls_atom_bal = suite.query_balance(&party_a, DENOM_LS_ATOM_ON_NTRN).amount; + let party_b_ls_atom_bal = suite.query_balance(&party_b, DENOM_LS_ATOM_ON_NTRN).amount; + + assert_eq!(5000, party_a_atom_bal.u128()); + assert_eq!(5000, party_b_atom_bal.u128()); + assert_eq!(5000, party_a_ls_atom_bal.u128()); + assert_eq!(5000, party_b_ls_atom_bal.u128()); + assert!(matches!(suite.query_contract_state(), ContractState::Complete{})); } #[test] @@ -584,6 +625,8 @@ fn test_migrate_update_config() { let deposit_deadline = suite.query_deposit_deadline(); let covenant_config = suite.query_covenant_config(); let denom_splits = suite.query_denom_splits(); + let emergency_committee = suite.query_emergency_committee(); + assert_eq!(random_split, &denom_splits.fallback_split.unwrap()); assert_eq!(Uint128::one(), covenant_config.party_a.contribution.amount); assert_eq!(Expiration::AtHeight(543210), deposit_deadline); @@ -597,4 +640,5 @@ fn test_migrate_update_config() { ); assert_eq!(next_contract, new_clock); assert_eq!(clock, new_next_contract); + assert_eq!(clock, emergency_committee); } From c4db8cdd90a2ef92a0bf9c53122cf13686646791 Mon Sep 17 00:00:00 2001 From: bekauz Date: Wed, 13 Mar 2024 19:33:46 +0100 Subject: [PATCH 02/56] single party holder lockup config update assertions fix --- .../single-party-pol-holder/src/contract.rs | 12 ++---- contracts/single-party-pol-holder/src/msg.rs | 4 ++ .../src/test_single_party_holder/suite.rs | 20 ++++++++++ .../src/test_single_party_holder/tests.rs | 40 ++++++++++++++++++- 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/contracts/single-party-pol-holder/src/contract.rs b/contracts/single-party-pol-holder/src/contract.rs index c6b244bb..6f1b2e14 100644 --- a/contracts/single-party-pol-holder/src/contract.rs +++ b/contracts/single-party-pol-holder/src/contract.rs @@ -52,6 +52,8 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { QueryMsg::Withdrawer {} => Ok(to_json_binary(&WITHDRAWER.may_load(deps.storage)?)?), QueryMsg::WithdrawTo {} => Ok(to_json_binary(&WITHDRAW_TO.may_load(deps.storage)?)?), QueryMsg::PoolerAddress {} => Ok(to_json_binary(&POOLER_ADDRESS.may_load(deps.storage)?)?), + QueryMsg::EmergencyCommitteeAddr {} => Ok(to_json_binary(&EMERGENCY_COMMITTEE_ADDR.may_load(deps.storage)?)?), + QueryMsg::LockupConfig {} => Ok(to_json_binary(&LOCKUP_PERIOD.load(deps.storage)?)?), } } @@ -183,17 +185,11 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result Option { + self.app + .wrap() + .query_wasm_smart( + self.holder_addr.clone(), + &covenant_single_party_pol_holder::msg::QueryMsg::EmergencyCommitteeAddr {}, + ) + .unwrap() + } + + pub fn query_lockup_period(&mut self) -> Expiration { + self.app + .wrap() + .query_wasm_smart( + self.holder_addr.clone(), + &covenant_single_party_pol_holder::msg::QueryMsg::LockupConfig {}, + ) + .unwrap() + } } impl BaseSuiteMut for Suite { diff --git a/unit-tests/src/test_single_party_holder/tests.rs b/unit-tests/src/test_single_party_holder/tests.rs index 9a74452a..0ef27507 100644 --- a/unit-tests/src/test_single_party_holder/tests.rs +++ b/unit-tests/src/test_single_party_holder/tests.rs @@ -1,5 +1,6 @@ use cosmwasm_std::{coin, Addr, Event}; use cw_multi_test::Executor; +use cw_utils::Expiration; use crate::setup::{base_suite::BaseSuite, ADMIN, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN}; @@ -196,6 +197,29 @@ fn test_execute_withdraw_failed_removes_withdraw_state() { // todo } +#[test] +#[should_panic(expected = "The lockup period must be in the future")] +fn test_migrate_update_config_validates_lockup_config() { + let mut suite = SinglePartyHolderBuilder::default().build(); + let current_block = suite.get_app().block_info().height; + let past_expiration = Expiration::AtHeight(current_block - 1); + + suite.app + .migrate_contract( + Addr::unchecked(ADMIN), + suite.holder_addr.clone(), + &covenant_single_party_pol_holder::msg::MigrateMsg::UpdateConfig { + withdrawer: None, + withdraw_to: None, + emergency_committee: None, + pooler_address: None, + lockup_period: Some(past_expiration), + }, + 5, + ) + .unwrap(); +} + #[test] fn test_migrate_update_config() { let mut suite = SinglePartyHolderBuilder::default().build(); @@ -212,7 +236,7 @@ fn test_migrate_update_config() { withdraw_to: Some(clock.to_string()), emergency_committee: Some(clock.to_string()), pooler_address: Some(clock.to_string()), - lockup_period: None, + lockup_period: Some(Expiration::AtHeight(192837465)), }, 5, ) @@ -223,6 +247,18 @@ fn test_migrate_update_config() { .add_attribute("withdrawer", clock.to_string()) .add_attribute("withdraw_to", clock.to_string()) .add_attribute("emergency_committee", clock.to_string()) - .add_attribute("pool_address", clock), + .add_attribute("pool_address", clock.to_string()), ); + + let withdrawer = suite.query_withdrawer().unwrap().to_string(); + let withdraw_to = suite.query_withdraw_to().unwrap().to_string(); + let emergency_committee = suite.query_emergency_committee().unwrap().to_string(); + let pooler_address = suite.query_pooler_address().to_string(); + let lockup_period = suite.query_lockup_period(); + + assert_eq!(clock, withdrawer); + assert_eq!(clock, withdraw_to); + assert_eq!(clock, emergency_committee); + assert_eq!(clock, pooler_address); + assert_eq!(Expiration::AtHeight(192837465), lockup_period); } From 68758e6bb206b65691ce108677dea7f0896efd94 Mon Sep 17 00:00:00 2001 From: bekauz Date: Wed, 13 Mar 2024 21:58:57 +0100 Subject: [PATCH 03/56] native router no longer reserves ntrn for gas --- contracts/native-router/src/contract.rs | 80 +++++------------------ unit-tests/src/test_swap_covenant/test.rs | 2 + 2 files changed, 17 insertions(+), 65 deletions(-) diff --git a/contracts/native-router/src/contract.rs b/contracts/native-router/src/contract.rs index 28d2a872..e38a4b66 100644 --- a/contracts/native-router/src/contract.rs +++ b/contracts/native-router/src/contract.rs @@ -3,11 +3,9 @@ use std::collections::BTreeSet; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_json_binary, Attribute, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, - StdError, StdResult, Uint128, + to_json_binary, Attribute, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; -use covenant_utils::get_default_ibc_fee_requirement; use cw2::set_contract_version; use crate::{ @@ -84,36 +82,13 @@ fn try_distribute_fallback( available_balances.push(queried_coin); } - let mut bank_sends: Vec = vec![]; - // we get the number of target denoms we have to reserve - // neutron fees for - let count = Uint128::from(denoms.len() as u128); - - for coin in available_balances { - let send_coin = if coin.denom != "untrn" { - Some(coin) - } else { - // if its neutron we're distributing we need to keep a - // reserve for ibc gas costs. - // this is safe because we pass target denoms. - let reserve_amount = count * get_default_ibc_fee_requirement(); - if coin.amount > reserve_amount { - Some(Coin { - denom: coin.denom, - amount: coin.amount - reserve_amount, - }) - } else { - None - } - }; - - if let Some(c) = send_coin { - bank_sends.push(CosmosMsg::Bank(cosmwasm_std::BankMsg::Send { - to_address: receiver_address.to_string(), - amount: vec![c], - })); - } - } + let bank_sends: Vec = available_balances + .into_iter() + .map(|c| BankMsg::Send { + to_address: receiver_address.to_string(), + amount: vec![c], + }.into()) + .collect(); Ok(Response::default() .add_attribute("method", "try_distribute_fallback") @@ -153,38 +128,13 @@ fn try_route_balances(deps: DepsMut, env: Env) -> Result = vec![]; - // we get the number of target denoms we have to reserve - // neutron fees for - let count = Uint128::from(1 + denom_balances.len() as u128); - - for coin in denom_balances { - // non-neutron coins get distributed entirely - let send_coin = if coin.denom != "untrn" { - Some(coin) - } else { - // if its neutron we're distributing we need to keep a - // reserve for ibc gas costs. - // this is safe because we pass target denoms. - let reserve_amount = count * get_default_ibc_fee_requirement(); - if coin.amount > reserve_amount { - Some(Coin { - denom: coin.denom, - amount: coin.amount - reserve_amount, - }) - } else { - None - } - }; - - if let Some(c) = send_coin { - bank_sends.push(CosmosMsg::Bank(cosmwasm_std::BankMsg::Send { - to_address: receiver_addr.to_string(), - amount: vec![c], - })); - } - } + let bank_sends: Vec = denom_balances + .into_iter() + .map(|c| BankMsg::Send { + to_address: receiver_addr.to_string(), + amount: vec![c], + }.into()) + .collect(); Ok(Response::default() .add_attribute("method", "try_route_balances") diff --git a/unit-tests/src/test_swap_covenant/test.rs b/unit-tests/src/test_swap_covenant/test.rs index f6d2e30f..78196b0a 100644 --- a/unit-tests/src/test_swap_covenant/test.rs +++ b/unit-tests/src/test_swap_covenant/test.rs @@ -409,6 +409,8 @@ fn test_covenant_native_refund() { block.time = block.time.plus_hours(1_000_000); block.height += 1_000_000; }); + // tick to trigger the expiration + suite.tick_contract(suite.holder_addr.clone()); // Tick until receiver_a gets his split while suite.query_all_balances(&suite.party_a_receiver).is_empty() { From b49f3ffa5afbac4a59d50e97baf88ae31e288f02 Mon Sep 17 00:00:00 2001 From: bekauz Date: Thu, 14 Mar 2024 13:48:39 +0100 Subject: [PATCH 04/56] interchain router distribute fallback expects sender to cover the ibc fee --- Cargo.lock | 1 + contracts/interchain-router/Cargo.toml | 1 + contracts/interchain-router/src/contract.rs | 22 +++- contracts/interchain-router/src/error.rs | 11 ++ .../src/suite_tests/tests.rs | 116 ++++++++++++++++-- packages/covenant-utils/src/neutron.rs | 12 +- unit-tests/src/setup/custom_module.rs | 18 ++- unit-tests/src/test_swap_covenant/test.rs | 30 ++--- 8 files changed, 174 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d0c506a..5644285c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -556,6 +556,7 @@ dependencies = [ "covenant-utils", "cw-multi-test", "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", "cw2 1.1.2", "neutron-sdk", "prost 0.11.9", diff --git a/contracts/interchain-router/Cargo.toml b/contracts/interchain-router/Cargo.toml index 4f862d5d..21253606 100644 --- a/contracts/interchain-router/Cargo.toml +++ b/contracts/interchain-router/Cargo.toml @@ -37,6 +37,7 @@ prost = { workspace = true } prost-types = { workspace = true } bech32 = { workspace = true } covenant-utils = { workspace = true } +cw-utils = { workspace = true } [dev-dependencies] cw-multi-test = { workspace = true } diff --git a/contracts/interchain-router/src/contract.rs b/contracts/interchain-router/src/contract.rs index 574d4055..a61b8f90 100644 --- a/contracts/interchain-router/src/contract.rs +++ b/contracts/interchain-router/src/contract.rs @@ -3,17 +3,17 @@ use std::collections::BTreeSet; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_json_binary, Attribute, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, - StdResult, + ensure, to_json_binary, Attribute, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint128 }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; +use covenant_utils::neutron::get_ibc_fee_total_amount; use cw2::set_contract_version; +use cw_utils::must_pay; use neutron_sdk::{ - bindings::{msg::NeutronMsg, query::NeutronQuery}, - NeutronError, NeutronResult, + bindings::{msg::NeutronMsg, query::NeutronQuery}, query::min_ibc_fee::MinIbcFeeResponse, NeutronError, NeutronResult }; -use crate::state::{DESTINATION_CONFIG, TARGET_DENOMS}; +use crate::{error::ContractError, state::{DESTINATION_CONFIG, TARGET_DENOMS}}; use crate::{ msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, state::CLOCK_ADDRESS, @@ -60,19 +60,29 @@ pub fn execute( verify_clock(&info.sender, &CLOCK_ADDRESS.load(deps.storage)?)?; try_route_balances(deps, env) } - ExecuteMsg::DistributeFallback { denoms } => try_distribute_fallback(deps, env, denoms), + ExecuteMsg::DistributeFallback { denoms } => try_distribute_fallback(deps, env, info, denoms), } } fn try_distribute_fallback( deps: ExecuteDeps, env: Env, + info: MessageInfo, denoms: Vec, ) -> NeutronResult> { let mut available_balances = Vec::with_capacity(denoms.len()); let destination_config = DESTINATION_CONFIG.load(deps.storage)?; let explicit_denoms = TARGET_DENOMS.load(deps.storage)?; + let min_fee_query_response: MinIbcFeeResponse = deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; + let total_fee = get_ibc_fee_total_amount(min_fee_query_response); + + // the caller must cover the ibc fees + match must_pay(&info, "untrn") { + Ok(amt) => ensure!(amt >= total_fee, NeutronError::Std(StdError::generic_err("insufficient fees"))), + Err(e) => return Err(ContractError::IbcFeeError(e).to_neutron_std()), + }; + for denom in denoms { // we do not distribute the main covenant denoms // according to the fallback split diff --git a/contracts/interchain-router/src/error.rs b/contracts/interchain-router/src/error.rs index 5fbe9a28..a062ec4b 100644 --- a/contracts/interchain-router/src/error.rs +++ b/contracts/interchain-router/src/error.rs @@ -1,4 +1,6 @@ use cosmwasm_std::StdError; +use cw_utils::PaymentError; +use neutron_sdk::NeutronError; use thiserror::Error; #[derive(Error, Debug)] @@ -11,4 +13,13 @@ pub enum ContractError { #[error("unauthorized to distribute explicitly defined denom")] UnauthorizedDenomDistribution {}, + + #[error("caller must cover ibc fees: {0}")] + IbcFeeError(PaymentError), +} + +impl ContractError { + pub fn to_neutron_std(&self) -> NeutronError { + NeutronError::Std(StdError::generic_err(self.to_string())) + } } diff --git a/contracts/interchain-router/src/suite_tests/tests.rs b/contracts/interchain-router/src/suite_tests/tests.rs index 9f5eadfa..a68d9cd2 100644 --- a/contracts/interchain-router/src/suite_tests/tests.rs +++ b/contracts/interchain-router/src/suite_tests/tests.rs @@ -4,15 +4,11 @@ use std::{ }; use cosmwasm_std::{ - coin, - testing::{mock_env, mock_info, MockApi, MockQuerier, MockStorage}, - Attribute, CosmosMsg, Empty, OwnedDeps, SubMsg, Uint128, Uint64, + coin, testing::{mock_env, mock_info, MockApi, MockQuerier, MockStorage}, to_json_binary, Attribute, CosmosMsg, Empty, OwnedDeps, SubMsg, Uint128, Uint64 }; use covenant_utils::DestinationConfig; use neutron_sdk::{ - bindings::msg::{IbcFee, NeutronMsg}, - sudo::msg::RequestPacketTimeoutHeight, - NeutronError, + bindings::msg::{IbcFee, NeutronMsg}, query::min_ibc_fee::MinIbcFeeResponse, sudo::msg::RequestPacketTimeoutHeight, NeutronError }; use crate::{ @@ -86,6 +82,103 @@ fn test_unauthorized_tick() { suite.tick("not_the_clock"); } +#[test] +#[should_panic(expected = "caller must cover ibc fees: No funds sent")] +fn test_tick_no_ibc_fee() { + let usdc_coin = coin(100, "usdc"); + let random_coin_1 = coin(100, "denom1"); + let random_coin_2 = coin(100, "denom2"); + let random_coin_3 = coin(100, "denom3"); + + let coins = vec![usdc_coin, random_coin_1, random_coin_2, random_coin_3]; + let querier: MockQuerier = MockQuerier::new(&[("cosmos2contract", &coins)]) + .with_custom_handler(|_| cosmwasm_std::SystemResult::Ok(to_json_binary( + &MinIbcFeeResponse { min_fee: IbcFee { + recv_fee: vec![], + ack_fee: vec![coin(100000, "untrn")], + timeout_fee: vec![coin(100000, "untrn")], + }} + ).into())); + + let mut deps = OwnedDeps { + storage: MockStorage::default(), + api: MockApi::default(), + querier: MockQuerier::new(&[]), + custom_query_type: PhantomData, + }; + // set the custom querier on our mock deps + deps.querier = querier; + + let no_ibc_fee_info = mock_info(CLOCK_ADDR, &[]); + + instantiate( + deps.as_mut(), + mock_env(), + no_ibc_fee_info.clone(), + SuiteBuilder::default() + .with_denoms(vec!["usdc".to_string()]) + .instantiate, + ) + .unwrap(); + + execute( + deps.as_mut(), + mock_env(), + no_ibc_fee_info.clone(), + crate::msg::ExecuteMsg::DistributeFallback { denoms: vec!["denom1".to_string()] }, + ) + .unwrap(); +} + + +#[test] +#[should_panic(expected = "insufficient fees")] +fn test_tick_insufficient_ibc_fee() { + let usdc_coin = coin(100, "usdc"); + let random_coin_1 = coin(100, "denom1"); + let random_coin_2 = coin(100, "denom2"); + let random_coin_3 = coin(100, "denom3"); + + let coins = vec![usdc_coin, random_coin_1, random_coin_2, random_coin_3]; + let querier: MockQuerier = MockQuerier::new(&[("cosmos2contract", &coins)]) + .with_custom_handler(|_| cosmwasm_std::SystemResult::Ok(to_json_binary( + &MinIbcFeeResponse { min_fee: IbcFee { + recv_fee: vec![], + ack_fee: vec![coin(100000, "untrn")], + timeout_fee: vec![coin(100000, "untrn")], + }} + ).into())); + + let mut deps = OwnedDeps { + storage: MockStorage::default(), + api: MockApi::default(), + querier: MockQuerier::new(&[]), + custom_query_type: PhantomData, + }; + // set the custom querier on our mock deps + deps.querier = querier; + + let no_ibc_fee_info = mock_info(CLOCK_ADDR, &[coin(100000, "untrn")]); + + instantiate( + deps.as_mut(), + mock_env(), + no_ibc_fee_info.clone(), + SuiteBuilder::default() + .with_denoms(vec!["usdc".to_string()]) + .instantiate, + ) + .unwrap(); + + execute( + deps.as_mut(), + mock_env(), + no_ibc_fee_info.clone(), + crate::msg::ExecuteMsg::DistributeFallback { denoms: vec!["denom1".to_string()] }, + ) + .unwrap(); +} + #[test] fn test_tick() { let usdc_coin = coin(100, "usdc"); @@ -94,7 +187,14 @@ fn test_tick() { let random_coin_3 = coin(100, "denom3"); let coins = vec![usdc_coin, random_coin_1, random_coin_2, random_coin_3]; - let querier: MockQuerier = MockQuerier::new(&[("cosmos2contract", &coins)]); + let querier: MockQuerier = MockQuerier::new(&[("cosmos2contract", &coins)]) + .with_custom_handler(|_| cosmwasm_std::SystemResult::Ok(to_json_binary( + &MinIbcFeeResponse { min_fee: IbcFee { + recv_fee: vec![], + ack_fee: vec![coin(100000, "untrn")], + timeout_fee: vec![coin(100000, "untrn")], + }} + ).into())); let mut deps = OwnedDeps { storage: MockStorage::default(), @@ -105,7 +205,7 @@ fn test_tick() { // set the custom querier on our mock deps deps.querier = querier; - let info = mock_info(CLOCK_ADDR, &[]); + let info = mock_info(CLOCK_ADDR, &[coin(10000000, "untrn")]); instantiate( deps.as_mut(), diff --git a/packages/covenant-utils/src/neutron.rs b/packages/covenant-utils/src/neutron.rs index 7612558b..7e8b0b8c 100644 --- a/packages/covenant-utils/src/neutron.rs +++ b/packages/covenant-utils/src/neutron.rs @@ -1,8 +1,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Attribute, Binary, Coin, StdError, Uint128, Uint64}; +use cosmwasm_std::{Attribute, Binary, Coin, StdError, StdResult, Uint128, Uint64}; use neutron_sdk::{ - bindings::{msg::IbcFee, types::ProtobufAny}, - NeutronResult, + bindings::{msg::IbcFee, types::ProtobufAny}, query::min_ibc_fee::MinIbcFeeResponse, NeutronResult }; use prost::Message; @@ -191,3 +190,10 @@ pub fn get_default_ica_fee() -> Coin { amount: Uint128::new(1000000), } } + +pub fn get_ibc_fee_total_amount(min_fee_query_response: MinIbcFeeResponse) -> Uint128 { + let ack_fee_total: Uint128 = min_fee_query_response.min_fee.ack_fee.iter().map(|c| c.amount).sum(); + let recv_fee_total: Uint128 = min_fee_query_response.min_fee.recv_fee.iter().map(|c| c.amount).sum(); + let timeout_fee_total: Uint128 = min_fee_query_response.min_fee.timeout_fee.iter().map(|c| c.amount).sum(); + ack_fee_total + recv_fee_total + timeout_fee_total +} \ No newline at end of file diff --git a/unit-tests/src/setup/custom_module.rs b/unit-tests/src/setup/custom_module.rs index a68082a3..db578b06 100644 --- a/unit-tests/src/setup/custom_module.rs +++ b/unit-tests/src/setup/custom_module.rs @@ -17,12 +17,12 @@ use neutron_sdk::{ bindings::{ msg::{MsgSubmitTxResponse, NeutronMsg}, query::NeutronQuery, - }, - interchain_txs::helpers::get_port_id, - sudo::msg::RequestPacket, + }, interchain_txs::helpers::get_port_id, query::min_ibc_fee::MinIbcFeeResponse, sudo::msg::RequestPacket }; use prost::Message; +use super::DENOM_NTRN; + pub const CHAIN_PREFIX: &str = "cosmos"; /// Namespace for neutron storage @@ -822,8 +822,16 @@ impl Module for NeutronKeeper { .unwrap(), ) .unwrap()), - NeutronQuery::MinIbcFee {} => todo!(), - + NeutronQuery::MinIbcFee {} => Ok(to_json_binary( + &MinIbcFeeResponse { + min_fee: neutron_sdk::bindings::msg::IbcFee { + recv_fee: vec![], + ack_fee: vec![coin(10000, DENOM_NTRN)], + timeout_fee: vec![coin(10000, DENOM_NTRN)], + }, + }) + .unwrap() + ), NeutronQuery::InterchainQueryResult { .. } => todo!(), NeutronQuery::RegisteredInterchainQueries { .. } => todo!(), NeutronQuery::RegisteredInterchainQuery { .. } => todo!(), diff --git a/unit-tests/src/test_swap_covenant/test.rs b/unit-tests/src/test_swap_covenant/test.rs index 78196b0a..629b2ea8 100644 --- a/unit-tests/src/test_swap_covenant/test.rs +++ b/unit-tests/src/test_swap_covenant/test.rs @@ -225,12 +225,12 @@ fn test_covenant_fallback_split() { suite .app .execute_contract( - suite.admin.clone(), + suite.fuacet.clone(), suite.splitter_addr.clone(), &covenant_native_splitter::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, - &[], + &[coin(1000000, DENOM_NTRN)] ) .unwrap(); @@ -238,24 +238,24 @@ fn test_covenant_fallback_split() { suite .app .execute_contract( - suite.admin.clone(), + suite.fuacet.clone(), suite.router_a_addr.clone(), &covenant_native_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, - &[], + &[coin(1000000, DENOM_NTRN)] ) .unwrap(); suite .app .execute_contract( - suite.admin.clone(), + suite.fuacet.clone(), suite.router_b_addr.clone(), &covenant_native_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, - &[], + &[coin(1000000, DENOM_NTRN)] ) .unwrap(); @@ -319,12 +319,12 @@ fn test_covenant_interchain_fallback_split() { suite .app .execute_contract( - suite.admin.clone(), + suite.fuacet.clone(), suite.splitter_addr.clone(), - &covenant_native_splitter::msg::ExecuteMsg::DistributeFallback { + &covenant_interchain_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, - &[], + &[coin(1000000, DENOM_NTRN)], ) .unwrap(); @@ -332,24 +332,24 @@ fn test_covenant_interchain_fallback_split() { suite .app .execute_contract( - suite.admin.clone(), + suite.fuacet.clone(), suite.router_a_addr.clone(), - &covenant_native_router::msg::ExecuteMsg::DistributeFallback { + &covenant_interchain_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, - &[], + &[coin(100000000, DENOM_NTRN)], ) .unwrap(); suite .app .execute_contract( - suite.admin.clone(), + suite.fuacet.clone(), suite.router_b_addr.clone(), - &covenant_native_router::msg::ExecuteMsg::DistributeFallback { + &covenant_interchain_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, - &[], + &[coin(100000000, DENOM_NTRN)], ) .unwrap(); From 3f3e7feba2aff940bd6f71596e036c57bb43a8fe Mon Sep 17 00:00:00 2001 From: bekauz Date: Thu, 14 Mar 2024 20:41:21 +0100 Subject: [PATCH 05/56] querying neutron ibc tx and ica registration fees on demand; removing all hardcoded IbcFee configurations --- Cargo.lock | 65 +++++++++++---- Cargo.toml | 2 +- contracts/ibc-forwarder/src/contract.rs | 41 +++++----- contracts/ibc-forwarder/src/error.rs | 7 ++ contracts/ibc-forwarder/src/msg.rs | 4 - contracts/interchain-router/src/contract.rs | 11 ++- contracts/osmo-liquid-pooler/src/contract.rs | 46 ++++++----- .../src/polytone_handlers.rs | 21 ++--- .../remote-chain-splitter/src/contract.rs | 13 +-- contracts/remote-chain-splitter/src/msg.rs | 4 - .../single-party-pol-covenant/src/contract.rs | 4 - .../single-party-pol-covenant/src/msg.rs | 25 ------ .../stride-liquid-staker/src/contract.rs | 10 +-- contracts/stride-liquid-staker/src/msg.rs | 5 -- contracts/swap-covenant/src/contract.rs | 2 - contracts/swap-covenant/src/msg.rs | 28 +------ .../two-party-pol-covenant/src/contract.rs | 2 - contracts/two-party-pol-covenant/src/msg.rs | 26 ------ .../single-party-pol/single_party_pol_test.go | 6 -- interchaintest/single-party-pol/types.go | 7 -- interchaintest/swap/tokenswap_test.go | 6 -- interchaintest/swap/types.go | 6 -- .../two-party-pol/two_party_osmo_pol_test.go | 5 -- .../two_party_pol_native_test.go | 20 ----- .../two-party-pol/two_party_pol_test.go | 20 ----- interchaintest/two-party-pol/types.go | 6 -- packages/covenant-utils/src/lib.rs | 35 +++++--- packages/covenant-utils/src/neutron.rs | 81 ++++--------------- packages/covenant-utils/src/polytone.rs | 3 +- unit-tests/Cargo.toml | 2 +- unit-tests/src/setup/custom_keepers.rs | 15 ++++ unit-tests/src/setup/custom_module.rs | 5 +- .../src/setup/instantiates/ibc_forwarder.rs | 12 --- .../instantiates/remote_chain_splitter.rs | 15 +--- .../instantiates/single_party_covenant.rs | 18 ----- .../src/setup/instantiates/swap_covenant.rs | 18 ----- .../setup/instantiates/two_party_covenant.rs | 11 +-- unit-tests/src/test_ibc_forwarder/suite.rs | 5 -- .../src/test_remote_chain_splitter/suite.rs | 10 --- .../src/test_two_party_covenant/suite.rs | 13 +-- 40 files changed, 199 insertions(+), 436 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5644285c..55774e2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1346,6 +1346,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.4" @@ -1454,19 +1460,21 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "neutron-sdk" -version = "0.7.0" -source = "git+https://github.com/neutron-org/neutron-sdk?branch=feat/cw-dex-bindings#90fa279ecc7bb996907488dcdf5545abd5c0b674" +version = "0.8.0" +source = "git+https://github.com/neutron-org/neutron-sdk?tag=v0.8.0#40f6592f1eec9e2e1bf0e0531a011294d70d1711" dependencies = [ "bech32", "cosmos-sdk-proto 0.20.0", "cosmwasm-schema", "cosmwasm-std", + "prost 0.12.3", + "prost-types 0.12.3", "protobuf 3.3.0", "schemars", "serde", "serde-json-wasm 1.0.0", - "serde_json", - "serde_repr", + "speedate", + "tendermint-proto 0.34.0", "thiserror", ] @@ -1746,6 +1754,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "ryu" version = "1.0.16" @@ -1883,17 +1897,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_repr" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "sha2" version = "0.9.9" @@ -1949,6 +1952,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "speedate" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "242f76c50fd18cbf098607090ade73a08d39cfd84ea835f3796a2c855223b19b" +dependencies = [ + "strum", + "strum_macros", +] + [[package]] name = "spki" version = "0.7.3" @@ -1965,6 +1978,28 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.48", +] + [[package]] name = "subtle" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index 2143c0d7..6c43fc1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,7 @@ covenant-utils = { path = "packages/covenant-utils" } # updated. to find cosmwasm_std's sha function: # ```cargo tree --package cosmwasm-std``` sha2 = "0.9.9" -neutron-sdk = { git = "https://github.com/neutron-org/neutron-sdk", branch = "feat/cw-dex-bindings" } +neutron-sdk = { git = "https://github.com/neutron-org/neutron-sdk", tag = "v0.8.0" } cosmos-sdk-proto = { version = "0.14.0", default-features = false } protobuf = { version = "3.2.0", features = ["with-bytes"] } serde-json-wasm = { version = "0.4.1" } diff --git a/contracts/ibc-forwarder/src/contract.rs b/contracts/ibc-forwarder/src/contract.rs index 8e354c69..b8948ba1 100644 --- a/contracts/ibc-forwarder/src/contract.rs +++ b/contracts/ibc-forwarder/src/contract.rs @@ -1,32 +1,25 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - from_json, to_json_binary, to_json_vec, Binary, Coin, CosmosMsg, CustomQuery, Deps, DepsMut, - Env, MessageInfo, Reply, Response, StdError, StdResult, Storage, SubMsg, + from_json, to_json_binary, to_json_vec, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult, Storage, SubMsg, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::neutron::{ - get_default_ica_fee, get_proto_coin, to_proto_msg_transfer, RemoteChainInfo, SudoPayload, + get_ictxs_module_params_query_msg, get_proto_coin, to_proto_msg_transfer, QueryParamsResponse, RemoteChainInfo, SudoPayload }; use cw2::set_contract_version; use neutron_sdk::{ bindings::{ msg::{MsgSubmitTxResponse, NeutronMsg}, query::NeutronQuery, - }, - interchain_txs::helpers::get_port_id, - sudo::msg::SudoMsg, - NeutronError, NeutronResult, + }, interchain_txs::helpers::get_port_id, query::min_ibc_fee::MinIbcFeeResponse, sudo::msg::SudoMsg, NeutronError, NeutronResult }; use crate::{ - helpers::{get_next_memo, MsgTransfer}, - msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, - state::{ + helpers::{get_next_memo, MsgTransfer}, msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, state::{ CLOCK_ADDRESS, CONTRACT_STATE, INTERCHAIN_ACCOUNTS, NEXT_CONTRACT, REMOTE_CHAIN_INFO, REPLY_ID_STORAGE, SUDO_PAYLOAD, TRANSFER_AMOUNT, - }, - sudo::{save_reply_payload, sudo_error, sudo_open_ack, sudo_response, sudo_timeout}, + }, sudo::{save_reply_payload, sudo_error, sudo_open_ack, sudo_response, sudo_timeout} }; const CONTRACT_NAME: &str = "crates.io:covenant-ibc-forwarder"; @@ -52,10 +45,9 @@ pub fn instantiate( NEXT_CONTRACT.save(deps.storage, &next_contract)?; TRANSFER_AMOUNT.save(deps.storage, &msg.amount)?; let remote_chain_info = RemoteChainInfo { - connection_id: msg.remote_chain_connection_id, - channel_id: msg.remote_chain_channel_id, - denom: msg.denom, - ibc_fee: msg.ibc_fee, + connection_id: msg.remote_chain_connection_id.to_string(), + channel_id: msg.remote_chain_channel_id.to_string(), + denom: msg.denom.to_string(), ica_timeout: msg.ica_timeout, ibc_transfer_timeout: msg.ibc_transfer_timeout, }; @@ -67,7 +59,7 @@ pub fn instantiate( .add_attribute("method", "ibc_forwarder_instantiate") .add_attribute("next_contract", next_contract) .add_attribute("contract_state", "instantiated") - .add_attributes(remote_chain_info.get_response_attributes())) + .add_attributes(msg.get_response_attributes())) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -100,11 +92,13 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult NeutronResult> { let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; - let register_fee: Option> = Some(vec![get_default_ica_fee()]); + + let ictxs_params_response: QueryParamsResponse = deps.querier.query(&get_ictxs_module_params_query_msg())?; + let register_msg = NeutronMsg::register_interchain_account( remote_chain_info.connection_id, INTERCHAIN_ACCOUNT_ID.to_string(), - register_fee, + Some(ictxs_params_response.params.register_fee), ); let key = get_port_id(env.contract.address.as_str(), INTERCHAIN_ACCOUNT_ID); @@ -132,6 +126,8 @@ fn try_forward_funds(env: Env, mut deps: ExecuteDeps) -> NeutronResult NeutronResult StdResult NeutronError { + NeutronError::Std(StdError::generic_err(self.to_string())) + } +} diff --git a/contracts/ibc-forwarder/src/msg.rs b/contracts/ibc-forwarder/src/msg.rs index 728054e8..b3da02ab 100644 --- a/contracts/ibc-forwarder/src/msg.rs +++ b/contracts/ibc-forwarder/src/msg.rs @@ -26,10 +26,6 @@ pub struct InstantiateMsg { pub denom: String, pub amount: Uint128, - /// neutron requires fees to be set to refund relayers for - /// submission of ack and timeout messages. - /// recv_fee and ack_fee paid in untrn from this contract - pub ibc_fee: IbcFee, /// timeout in seconds. this is used to craft a timeout timestamp /// that will be attached to the IBC transfer message from the ICA /// on the host chain to its destination. typically this timeout diff --git a/contracts/interchain-router/src/contract.rs b/contracts/interchain-router/src/contract.rs index a61b8f90..cb9acb78 100644 --- a/contracts/interchain-router/src/contract.rs +++ b/contracts/interchain-router/src/contract.rs @@ -3,10 +3,10 @@ use std::collections::BTreeSet; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - ensure, to_json_binary, Attribute, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint128 + ensure, to_json_binary, Attribute, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; -use covenant_utils::neutron::get_ibc_fee_total_amount; +use covenant_utils::sum_fees; use cw2::set_contract_version; use cw_utils::must_pay; use neutron_sdk::{ @@ -75,7 +75,7 @@ fn try_distribute_fallback( let explicit_denoms = TARGET_DENOMS.load(deps.storage)?; let min_fee_query_response: MinIbcFeeResponse = deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; - let total_fee = get_ibc_fee_total_amount(min_fee_query_response); + let total_fee = sum_fees(&min_fee_query_response.min_fee); // the caller must cover the ibc fees match must_pay(&info, "untrn") { @@ -97,10 +97,12 @@ fn try_distribute_fallback( available_balances.push(queried_coin); } + let min_ibc_fee: MinIbcFeeResponse = deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; let fallback_distribution_messages = destination_config.get_ibc_transfer_messages_for_coins( available_balances, env.block.time, env.contract.address.to_string(), + min_ibc_fee.min_fee )?; Ok(Response::default() @@ -141,11 +143,14 @@ fn try_route_balances(deps: ExecuteDeps, env: Env) -> NeutronResult = cosmwasm_std::DepsMut<'a, NeutronQuery>; +type QueryDeps<'a> = cosmwasm_std::Deps<'a, NeutronQuery>; + #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( - deps: DepsMut, + deps: ExecuteDeps, _env: Env, _info: MessageInfo, msg: InstantiateMsg, @@ -104,7 +107,7 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( - deps: DepsMut, + deps: ExecuteDeps, env: Env, info: MessageInfo, msg: ExecuteMsg, @@ -117,7 +120,7 @@ pub fn execute( } fn try_withdraw( - deps: DepsMut, + deps: ExecuteDeps, env: Env, info: MessageInfo, percent: Option, @@ -198,7 +201,7 @@ fn try_withdraw( } /// attempts to advance the state machine. performs `info.sender` validation. -fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult> { +fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult> { // Verify caller is the clock verify_clock(&info.sender, &CLOCK_ADDRESS.load(deps.storage)?)?; @@ -228,7 +231,7 @@ fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult, ) -> NeutronResult> { @@ -414,7 +417,7 @@ fn try_distribute( } } -fn try_sync_proxy_balances(deps: DepsMut, env: Env) -> NeutronResult> { +fn try_sync_proxy_balances(deps: ExecuteDeps, env: Env) -> NeutronResult> { let note_address = NOTE_ADDRESS.load(deps.storage)?; let ibc_config = IBC_CONFIG.load(deps.storage)?; let mut lp_config = LIQUIDITY_PROVISIONING_CONFIG.load(deps.storage)?; @@ -444,7 +447,7 @@ fn try_sync_proxy_balances(deps: DepsMut, env: Env) -> NeutronResult NeutronResult> { +fn try_create_proxy(deps: ExecuteDeps, env: Env) -> NeutronResult> { let note_address = NOTE_ADDRESS.load(deps.storage)?; let ibc_config = IBC_CONFIG.load(deps.storage)?; @@ -468,7 +471,7 @@ fn try_create_proxy(deps: DepsMut, env: Env) -> NeutronResult NeutronResult> { +fn try_deliver_funds(deps: ExecuteDeps, env: Env) -> NeutronResult> { let mut lp_config = LIQUIDITY_PROVISIONING_CONFIG.load(deps.storage)?; // check if both balances have a recent query @@ -505,7 +508,7 @@ fn try_deliver_funds(deps: DepsMut, env: Env) -> NeutronResult NeutronResult> { +fn try_fund_proxy(deps: ExecuteDeps, env: Env) -> NeutronResult> { let mut lp_config = LIQUIDITY_PROVISIONING_CONFIG.load(deps.storage)?; let proxy_address = PROXY_ADDRESS.load(deps.storage)?; let ibc_config = IBC_CONFIG.load(deps.storage)?; @@ -538,13 +541,14 @@ fn try_fund_proxy(deps: DepsMut, env: Env) -> NeutronResult } let mut transfer_messages = vec![]; - + let min_ibc_fee: MinIbcFeeResponse = deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; if coin_1_bal.amount > Uint128::zero() { transfer_messages.push(get_ibc_transfer_message( ibc_config.party_1_chain_info, env.clone(), coin_1_bal, proxy_address.to_string(), + &min_ibc_fee.min_fee )?); } if coin_2_bal.amount > Uint128::zero() { @@ -553,6 +557,7 @@ fn try_fund_proxy(deps: DepsMut, env: Env) -> NeutronResult env, coin_2_bal, proxy_address, + &min_ibc_fee.min_fee, )?); } @@ -561,7 +566,7 @@ fn try_fund_proxy(deps: DepsMut, env: Env) -> NeutronResult .add_attribute("method", "try_fund_proxy")) } -fn try_provide_liquidity(deps: DepsMut, env: Env) -> NeutronResult> { +fn try_provide_liquidity(deps: ExecuteDeps, env: Env) -> NeutronResult> { let note_address = NOTE_ADDRESS.load(deps.storage)?; let ibc_config = IBC_CONFIG.load(deps.storage)?; let mut lp_config = LIQUIDITY_PROVISIONING_CONFIG.load(deps.storage)?; @@ -602,7 +607,7 @@ fn try_provide_liquidity(deps: DepsMut, env: Env) -> NeutronResult NeutronResult> { +fn query_proxy_balances(deps: ExecuteDeps, env: Env) -> NeutronResult> { let note_address = NOTE_ADDRESS.load(deps.storage)?; let ibc_config = IBC_CONFIG.load(deps.storage)?; let proxy_address = PROXY_ADDRESS.load(deps.storage)?; @@ -626,6 +631,7 @@ fn get_ibc_transfer_message( env: Env, coin: Coin, proxy_address: String, + ibc_fee: &IbcFee, ) -> StdResult { // depending on whether pfm is configured, // we return a ibc transfer message @@ -653,7 +659,7 @@ fn get_ibc_transfer_message( channel: forward_metadata.channel, }), })?, - fee: default_ibc_fee(), + fee: ibc_fee.clone(), }), // no pfm necessary, we do a regular transfer None => Ok(NeutronMsg::IbcTransfer { @@ -672,13 +678,13 @@ fn get_ibc_transfer_message( .plus_seconds(party_chain_info.ibc_timeout.u64()) .nanos(), memo: "".to_string(), - fee: default_ibc_fee(), + fee: ibc_fee.clone(), }), } } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { +pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::ClockAddress {} => Ok(to_json_binary(&CLOCK_ADDRESS.may_load(deps.storage)?)?), QueryMsg::ContractState {} => Ok(to_json_binary(&CONTRACT_STATE.may_load(deps.storage)?)?), @@ -705,7 +711,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> NeutronResult { +pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> NeutronResult { match msg { MigrateMsg::UpdateConfig { clock_addr, diff --git a/contracts/osmo-liquid-pooler/src/polytone_handlers.rs b/contracts/osmo-liquid-pooler/src/polytone_handlers.rs index bc131638..231cdbc9 100644 --- a/contracts/osmo-liquid-pooler/src/polytone_handlers.rs +++ b/contracts/osmo-liquid-pooler/src/polytone_handlers.rs @@ -1,8 +1,7 @@ use std::str::FromStr; use cosmwasm_std::{ - coin, ensure, from_json, to_json_binary, Addr, Binary, Coin, CosmosMsg, DepsMut, Empty, Env, - IbcMsg, IbcTimeout, MessageInfo, QueryRequest, Response, StdResult, Uint128, Uint64, WasmMsg, + coin, ensure, from_json, to_json_binary, Addr, Binary, Coin, CosmosMsg, Deps, DepsMut, Empty, Env, IbcMsg, IbcTimeout, MessageInfo, QueryRequest, Response, StdResult, Uint128, Uint64, WasmMsg }; use covenant_utils::{ polytone::{ @@ -11,7 +10,7 @@ use covenant_utils::{ }, withdraw_lp_helper::WithdrawLPMsgs, }; -use neutron_sdk::{bindings::msg::NeutronMsg, NeutronResult}; +use neutron_sdk::{bindings::{msg::NeutronMsg, query::NeutronQuery}, NeutronResult}; use osmosis_std::types::cosmos::bank::v1beta1::QueryBalanceResponse; use crate::{ @@ -32,10 +31,14 @@ use polytone::callbacks::{ ExecutionResponse, }; +type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; +type QueryDeps<'a> = Deps<'a, NeutronQuery>; + + /// attempts to advance the state machine. performs `info.sender` validation. pub fn try_handle_callback( env: Env, - deps: DepsMut, + deps: ExecuteDeps, info: MessageInfo, msg: CallbackMessage, ) -> NeutronResult> { @@ -56,7 +59,7 @@ pub fn try_handle_callback( fn process_query_callback( env: Env, - deps: DepsMut, + deps: ExecuteDeps, query_callback_result: Result, ErrorResponse>, initiator_msg: Binary, ) -> NeutronResult> { @@ -80,7 +83,7 @@ fn process_query_callback( fn process_execute_callback( env: Env, - deps: DepsMut, + deps: ExecuteDeps, execute_callback_result: Result, initiator_msg: Binary, ) -> NeutronResult> { @@ -228,7 +231,7 @@ fn process_execute_callback( fn process_fatal_error_callback( env: Env, - deps: DepsMut, + deps: ExecuteDeps, response: String, ) -> NeutronResult> { POLYTONE_CALLBACKS.save( @@ -240,7 +243,7 @@ fn process_fatal_error_callback( } fn handle_withdraw_liquidity_proxy_balances_callback( - deps: DepsMut, + deps: ExecuteDeps, env: Env, query_callback_result: Result, ErrorResponse>, ) -> NeutronResult> { @@ -304,7 +307,7 @@ fn handle_withdraw_liquidity_proxy_balances_callback( } fn handle_proxy_balances_callback( - deps: DepsMut, + deps: ExecuteDeps, env: Env, query_callback_result: Result, ErrorResponse>, ) -> NeutronResult> { diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index 2f477e68..eebca2d2 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -10,11 +10,12 @@ use cosmwasm_std::{ MessageInfo, Reply, Response, StdError, StdResult, SubMsg, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; -use covenant_utils::neutron::{RemoteChainInfo, SudoPayload}; -use covenant_utils::{get_default_ica_fee, neutron}; +use covenant_utils::neutron::{get_ictxs_module_params_query_msg, QueryParamsResponse, RemoteChainInfo, SudoPayload}; +use covenant_utils::neutron; use cw2::set_contract_version; use neutron_sdk::bindings::types::ProtobufAny; use neutron_sdk::interchain_txs::helpers::get_port_id; +use neutron_sdk::query::min_ibc_fee::MinIbcFeeResponse; use neutron_sdk::sudo::msg::SudoMsg; use neutron_sdk::NeutronError; @@ -56,7 +57,6 @@ pub fn instantiate( denom: msg.denom, ibc_transfer_timeout: msg.ibc_transfer_timeout, ica_timeout: msg.ica_timeout, - ibc_fee: msg.ibc_fee, }; REMOTE_CHAIN_INFO.save(deps.storage, &remote_chain_info)?; CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; @@ -117,10 +117,12 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult NeutronResult> { let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; + let ictxs_params_response: QueryParamsResponse = deps.querier.query(&get_ictxs_module_params_query_msg())?; + let register: NeutronMsg = NeutronMsg::register_interchain_account( remote_chain_info.connection_id, INTERCHAIN_ACCOUNT_ID.to_string(), - Some(vec![get_default_ica_fee()]), + Some(ictxs_params_response.params.register_fee), ); let key = get_port_id(env.contract.address.as_str(), INTERCHAIN_ACCOUNT_ID); @@ -136,6 +138,7 @@ fn try_split_funds(mut deps: ExecuteDeps, env: Env) -> NeutronResult { @@ -214,7 +217,7 @@ fn try_split_funds(mut deps: ExecuteDeps, env: Env) -> NeutronResult, - /// Neutron requires fees to be set to refund relayers for - /// submission of ack and timeout messages. - /// recv_fee and ack_fee paid in untrn from this contract - pub ibc_fee: IbcFee, /// Time in seconds for ICA SubmitTX messages from Neutron /// Note that ICA uses ordered channels, a timeout implies /// channel closed. We can reopen the channel by reregistering diff --git a/contracts/single-party-pol-covenant/src/contract.rs b/contracts/single-party-pol-covenant/src/contract.rs index 6a1df329..245dda30 100644 --- a/contracts/single-party-pol-covenant/src/contract.rs +++ b/contracts/single-party-pol-covenant/src/contract.rs @@ -148,7 +148,6 @@ pub fn instantiate( neutron_stride_ibc_connection_id: msg.ls_info.ls_neutron_connection_id.to_string(), ica_timeout: msg.timeouts.ica_timeout, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, - ibc_fee: msg.preset_ibc_fee.to_ibc_fee(), clock_address: clock_instantiate2_config.addr.to_string(), next_contract: liquid_pooler_instantiate2_config.addr.to_string(), } @@ -191,7 +190,6 @@ pub fn instantiate( remote_chain_connection_id: msg.remote_chain_splitter_config.connection_id, denom: msg.remote_chain_splitter_config.denom.to_string(), amount: msg.remote_chain_splitter_config.amount, - ibc_fee: msg.preset_ibc_fee.to_ibc_fee(), ica_timeout: msg.timeouts.ica_timeout, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, splits, @@ -220,7 +218,6 @@ pub fn instantiate( remote_chain_channel_id: config.party_to_host_chain_channel_id, denom: config.remote_chain_denom, amount: config.contribution.amount, - ibc_fee: msg.preset_ibc_fee.to_ibc_fee(), ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, ica_timeout: msg.timeouts.ica_timeout, }; @@ -241,7 +238,6 @@ pub fn instantiate( remote_chain_channel_id: config.party_to_host_chain_channel_id, denom: config.remote_chain_denom, amount: config.contribution.amount, - ibc_fee: msg.preset_ibc_fee.to_ibc_fee(), ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, ica_timeout: msg.timeouts.ica_timeout, }; diff --git a/contracts/single-party-pol-covenant/src/msg.rs b/contracts/single-party-pol-covenant/src/msg.rs index 2699f204..3fffe22f 100644 --- a/contracts/single-party-pol-covenant/src/msg.rs +++ b/contracts/single-party-pol-covenant/src/msg.rs @@ -10,7 +10,6 @@ use covenant_utils::{ ReceiverConfig, }; use cw_utils::Expiration; -use neutron_sdk::bindings::msg::IbcFee; const NEUTRON_DENOM: &str = "untrn"; pub const DEFAULT_TIMEOUT: u64 = 60 * 60 * 5; // 5 hours @@ -19,7 +18,6 @@ pub const DEFAULT_TIMEOUT: u64 = 60 * 60 * 5; // 5 hours pub struct InstantiateMsg { pub label: String, pub timeouts: Timeouts, - pub preset_ibc_fee: PresetIbcFee, pub contract_codes: CovenantContractCodeIds, pub clock_tick_max_gas: Option, pub lockup_period: Expiration, @@ -175,29 +173,6 @@ impl Default for Timeouts { } } -#[cw_serde] -pub struct PresetIbcFee { - pub ack_fee: Uint128, - pub timeout_fee: Uint128, -} - -impl PresetIbcFee { - pub fn to_ibc_fee(&self) -> IbcFee { - IbcFee { - // must be empty - recv_fee: vec![], - ack_fee: vec![cosmwasm_std::Coin { - denom: NEUTRON_DENOM.to_string(), - amount: self.ack_fee, - }], - timeout_fee: vec![cosmwasm_std::Coin { - denom: NEUTRON_DENOM.to_string(), - amount: self.timeout_fee, - }], - } - } -} - #[cw_serde] #[derive(QueryResponses)] pub enum QueryMsg { diff --git a/contracts/stride-liquid-staker/src/contract.rs b/contracts/stride-liquid-staker/src/contract.rs index 13c0318c..181da3ba 100644 --- a/contracts/stride-liquid-staker/src/contract.rs +++ b/contracts/stride-liquid-staker/src/contract.rs @@ -8,6 +8,7 @@ use cosmwasm_std::{ use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::neutron::{self, get_proto_coin, OpenAckVersion, RemoteChainInfo, SudoPayload}; use cw2::set_contract_version; +use neutron_sdk::query::min_ibc_fee::MinIbcFeeResponse; use crate::helpers::{Autopilot, AutopilotConfig}; use crate::msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; @@ -57,7 +58,6 @@ pub fn instantiate( denom: msg.ls_denom, ibc_transfer_timeout: msg.ibc_transfer_timeout, ica_timeout: msg.ica_timeout, - ibc_fee: msg.ibc_fee, }; REMOTE_CHAIN_INFO.save(deps.storage, &remote_chain_info)?; CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; @@ -148,6 +148,7 @@ fn try_execute_transfer( let port_id = get_port_id(env.contract.address.as_str(), INTERCHAIN_ACCOUNT_ID); let interchain_account = INTERCHAIN_ACCOUNTS.load(deps.storage, port_id.clone())?; + let min_fee_query_response: MinIbcFeeResponse = deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; match interchain_account { Some((address, controller_conn_id)) => { @@ -181,7 +182,7 @@ fn try_execute_transfer( vec![protobuf], "".to_string(), remote_chain_info.ica_timeout.u64(), - remote_chain_info.ibc_fee, + min_fee_query_response.min_fee, ); let sudo_msg = msg_with_sudo_callback( @@ -463,9 +464,8 @@ pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult, // neutron_stride_ibc_connection_id: Option, // ls_denom: Option, - // ibc_fee: Option, // ibc_transfer_timeout: Option, // ica_timeout: Option, remote_chain_info: Option, diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index cc039364..012b917e 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -195,7 +195,6 @@ pub fn instantiate( amount: msg.party_a_config.get_contribution().amount, ica_timeout: msg.timeouts.ica_timeout, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, - ibc_fee: msg.preset_ibc_fee.to_ibc_fee(), clock_address: clock_instantiate2_config.addr.to_string(), next_contract: holder_instantiate2_config.addr.to_string(), } @@ -226,7 +225,6 @@ pub fn instantiate( amount: msg.party_b_config.get_contribution().amount, ica_timeout: msg.timeouts.ica_timeout, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, - ibc_fee: msg.preset_ibc_fee.to_ibc_fee(), clock_address: clock_instantiate2_config.addr.to_string(), next_contract: holder_instantiate2_config.addr.to_string(), } diff --git a/contracts/swap-covenant/src/msg.rs b/contracts/swap-covenant/src/msg.rs index 8ecff870..1bbff93d 100644 --- a/contracts/swap-covenant/src/msg.rs +++ b/contracts/swap-covenant/src/msg.rs @@ -1,22 +1,19 @@ use std::collections::{BTreeMap, BTreeSet}; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Addr, Binary, Coin, Deps, StdResult, Uint128, Uint64, WasmMsg}; +use cosmwasm_std::{Addr, Binary, Coin, Deps, StdResult, Uint64, WasmMsg}; use covenant_utils::{ instantiate2_helper::Instantiate2HelperConfig, split::SplitConfig, CovenantParty, DestinationConfig, InterchainCovenantParty, NativeCovenantParty, ReceiverConfig, }; use cw_utils::Expiration; -use neutron_sdk::bindings::msg::IbcFee; -const NEUTRON_DENOM: &str = "untrn"; pub const DEFAULT_TIMEOUT: u64 = 60 * 60 * 5; // 5 hours #[cw_serde] pub struct InstantiateMsg { pub label: String, pub timeouts: Timeouts, - pub preset_ibc_fee: PresetIbcFee, pub contract_codes: SwapCovenantContractCodeIds, pub clock_tick_max_gas: Option, pub lockup_config: Expiration, @@ -168,29 +165,6 @@ impl Default for Timeouts { } } -#[cw_serde] -pub struct PresetIbcFee { - pub ack_fee: Uint128, - pub timeout_fee: Uint128, -} - -impl PresetIbcFee { - pub fn to_ibc_fee(&self) -> IbcFee { - IbcFee { - // must be empty - recv_fee: vec![], - ack_fee: vec![cosmwasm_std::Coin { - denom: NEUTRON_DENOM.to_string(), - amount: self.ack_fee, - }], - timeout_fee: vec![cosmwasm_std::Coin { - denom: NEUTRON_DENOM.to_string(), - amount: self.timeout_fee, - }], - } - } -} - #[cw_serde] pub enum ExecuteMsg {} diff --git a/contracts/two-party-pol-covenant/src/contract.rs b/contracts/two-party-pol-covenant/src/contract.rs index f46f170c..518040ff 100644 --- a/contracts/two-party-pol-covenant/src/contract.rs +++ b/contracts/two-party-pol-covenant/src/contract.rs @@ -187,7 +187,6 @@ pub fn instantiate( amount: config.contribution.amount, ica_timeout: msg.timeouts.ica_timeout, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, - ibc_fee: msg.preset_ibc_fee.to_ibc_fee(), }; messages.push(instantiate_msg.to_instantiate2_msg( @@ -210,7 +209,6 @@ pub fn instantiate( amount: config.contribution.amount, ica_timeout: msg.timeouts.ica_timeout, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, - ibc_fee: msg.preset_ibc_fee.to_ibc_fee(), }; messages.push(instantiate_msg.to_instantiate2_msg( diff --git a/contracts/two-party-pol-covenant/src/msg.rs b/contracts/two-party-pol-covenant/src/msg.rs index a53033a1..c78f1203 100644 --- a/contracts/two-party-pol-covenant/src/msg.rs +++ b/contracts/two-party-pol-covenant/src/msg.rs @@ -11,16 +11,13 @@ use covenant_utils::{ ReceiverConfig, }; use cw_utils::Expiration; -use neutron_sdk::bindings::msg::IbcFee; -const NEUTRON_DENOM: &str = "untrn"; pub const DEFAULT_TIMEOUT: u64 = 60 * 60 * 5; // 5 hours #[cw_serde] pub struct InstantiateMsg { pub label: String, pub timeouts: Timeouts, - pub preset_ibc_fee: PresetIbcFee, pub contract_codes: CovenantContractCodeIds, pub clock_tick_max_gas: Option, pub lockup_config: Expiration, @@ -251,29 +248,6 @@ impl Default for Timeouts { } } -#[cw_serde] -pub struct PresetIbcFee { - pub ack_fee: Uint128, - pub timeout_fee: Uint128, -} - -impl PresetIbcFee { - pub fn to_ibc_fee(&self) -> IbcFee { - IbcFee { - // must be empty - recv_fee: vec![], - ack_fee: vec![cosmwasm_std::Coin { - denom: NEUTRON_DENOM.to_string(), - amount: self.ack_fee, - }], - timeout_fee: vec![cosmwasm_std::Coin { - denom: NEUTRON_DENOM.to_string(), - amount: self.timeout_fee, - }], - } - } -} - #[cw_serde] pub enum ExecuteMsg {} diff --git a/interchaintest/single-party-pol/single_party_pol_test.go b/interchaintest/single-party-pol/single_party_pol_test.go index bb1d3cc5..4f7e37c5 100644 --- a/interchaintest/single-party-pol/single_party_pol_test.go +++ b/interchaintest/single-party-pol/single_party_pol_test.go @@ -669,11 +669,6 @@ func TestSinglePartyPol(t *testing.T) { }) t.Run("init covenant", func(t *testing.T) { - presetIbcFee := PresetIbcFee{ - AckFee: "100000", - TimeoutFee: "100000", - } - timeouts := Timeouts{ IcaTimeout: "10000", // sec IbcTransferTimeout: "10000", // sec @@ -796,7 +791,6 @@ func TestSinglePartyPol(t *testing.T) { covenantInstantiationMsg := CovenantInstantiationMsg{ Label: "single_party_pol_covenant", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, ContractCodeIds: contractCodes, LockupConfig: lockupConfig, LsInfo: lsInfo, diff --git a/interchaintest/single-party-pol/types.go b/interchaintest/single-party-pol/types.go index f20c6a9f..71ae439e 100644 --- a/interchaintest/single-party-pol/types.go +++ b/interchaintest/single-party-pol/types.go @@ -218,7 +218,6 @@ type NativeBalQueryResponse struct { type CovenantInstantiationMsg struct { Label string `json:"label"` Timeouts Timeouts `json:"timeouts"` - PresetIbcFee PresetIbcFee `json:"preset_ibc_fee"` ContractCodeIds ContractCodeIds `json:"contract_codes"` TickMaxGas string `json:"clock_tick_max_gas,omitempty"` LockupConfig Expiration `json:"lockup_period"` @@ -355,12 +354,6 @@ type Timeouts struct { IcaTimeout string `json:"ica_timeout"` IbcTransferTimeout string `json:"ibc_transfer_timeout"` } - -type PresetIbcFee struct { - AckFee string `json:"ack_fee"` - TimeoutFee string `json:"timeout_fee"` -} - type Timestamp string type Block uint64 diff --git a/interchaintest/swap/tokenswap_test.go b/interchaintest/swap/tokenswap_test.go index fa6c4e1f..4f5bf4da 100644 --- a/interchaintest/swap/tokenswap_test.go +++ b/interchaintest/swap/tokenswap_test.go @@ -368,11 +368,6 @@ func TestTokenSwap(t *testing.T) { AtHeight: &depositBlock, } - presetIbcFee := PresetIbcFee{ - AckFee: "100000", - TimeoutFee: "100000", - } - neutronReceiverAddr = neutronAccount.Bech32Address(cosmosNeutron.Config().Bech32Prefix) hubReceiverAddr = gaiaUser.Bech32Address(cosmosAtom.Config().Bech32Prefix) @@ -423,7 +418,6 @@ func TestTokenSwap(t *testing.T) { covenantMsg := CovenantInstantiateMsg{ Label: "swap-covenant", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, SwapCovenantContractCodeIds: codeIds, LockupConfig: lockupConfig, PartyAConfig: CovenantPartyConfig{ diff --git a/interchaintest/swap/types.go b/interchaintest/swap/types.go index f900db5a..8beb976a 100644 --- a/interchaintest/swap/types.go +++ b/interchaintest/swap/types.go @@ -8,7 +8,6 @@ package covenant_swap type CovenantInstantiateMsg struct { Label string `json:"label"` Timeouts Timeouts `json:"timeouts"` - PresetIbcFee PresetIbcFee `json:"preset_ibc_fee"` SwapCovenantContractCodeIds SwapCovenantContractCodeIds `json:"contract_codes"` TickMaxGas string `json:"clock_tick_max_gas,omitempty"` LockupConfig Expiration `json:"lockup_config"` @@ -77,11 +76,6 @@ type Timeouts struct { IbcTransferTimeout string `json:"ibc_transfer_timeout"` } -type PresetIbcFee struct { - AckFee string `json:"ack_fee"` - TimeoutFee string `json:"timeout_fee"` -} - type PresetClockFields struct { TickMaxGas string `json:"tick_max_gas,omitempty"` ClockCode uint64 `json:"clock_code"` diff --git a/interchaintest/two-party-pol/two_party_osmo_pol_test.go b/interchaintest/two-party-pol/two_party_osmo_pol_test.go index c35d98c9..abd06d09 100644 --- a/interchaintest/two-party-pol/two_party_osmo_pol_test.go +++ b/interchaintest/two-party-pol/two_party_osmo_pol_test.go @@ -505,10 +505,6 @@ func TestTwoPartyOsmoPol(t *testing.T) { depositDeadline := Expiration{ AtHeight: &depositBlock, } - presetIbcFee := PresetIbcFee{ - AckFee: "10000", - TimeoutFee: "10000", - } hubReceiverAddr := happyCaseHubAccount.Bech32Address(cosmosAtom.Config().Bech32Prefix) osmoReceiverAddr := happyCaseOsmoAccount.Bech32Address(cosmosOsmosis.Config().Bech32Prefix) @@ -644,7 +640,6 @@ func TestTwoPartyOsmoPol(t *testing.T) { covenantInstantiateMsg := CovenantInstantiateMsg{ Label: "covenant-osmo", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, ContractCodeIds: codeIds, LockupConfig: lockupConfig, PartyAConfig: CovenantPartyConfig{Interchain: &partyAConfig}, diff --git a/interchaintest/two-party-pol/two_party_pol_native_test.go b/interchaintest/two-party-pol/two_party_pol_native_test.go index 88891f7c..0761b18d 100644 --- a/interchaintest/two-party-pol/two_party_pol_native_test.go +++ b/interchaintest/two-party-pol/two_party_pol_native_test.go @@ -443,10 +443,6 @@ func TestTwoPartyNativePartyPol(t *testing.T) { depositDeadline := Expiration{ AtHeight: &depositBlock, } - presetIbcFee := PresetIbcFee{ - AckFee: "100000", - TimeoutFee: "100000", - } atomCoin := Coin{ Denom: cosmosAtom.Config().Denom, @@ -539,7 +535,6 @@ func TestTwoPartyNativePartyPol(t *testing.T) { covenantMsg := CovenantInstantiateMsg{ Label: "two-party-pol-covenant-happy", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, ContractCodeIds: codeIds, LockupConfig: lockupConfig, PartyAConfig: CovenantPartyConfig{ @@ -801,10 +796,6 @@ func TestTwoPartyNativePartyPol(t *testing.T) { depositDeadline := Expiration{ AtHeight: &depositBlock, } - presetIbcFee := PresetIbcFee{ - AckFee: "100000", - TimeoutFee: "100000", - } atomCoin := Coin{ Denom: cosmosAtom.Config().Denom, @@ -874,7 +865,6 @@ func TestTwoPartyNativePartyPol(t *testing.T) { covenantMsg := CovenantInstantiateMsg{ Label: "two-party-pol-covenant-ragequit", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, ContractCodeIds: codeIds, LockupConfig: lockupConfig, PartyAConfig: CovenantPartyConfig{Interchain: &partyAConfig}, @@ -1085,10 +1075,6 @@ func TestTwoPartyNativePartyPol(t *testing.T) { depositDeadline := Expiration{ AtHeight: &depositBlock, } - presetIbcFee := PresetIbcFee{ - AckFee: "100000", - TimeoutFee: "100000", - } atomCoin := Coin{ Denom: cosmosAtom.Config().Denom, @@ -1157,7 +1143,6 @@ func TestTwoPartyNativePartyPol(t *testing.T) { covenantMsg := CovenantInstantiateMsg{ Label: "two-party-pol-covenant-side-ragequit", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, ContractCodeIds: codeIds, LockupConfig: lockupConfig, PartyAConfig: CovenantPartyConfig{Interchain: &partyAConfig}, @@ -1352,10 +1337,6 @@ func TestTwoPartyNativePartyPol(t *testing.T) { depositDeadline := Expiration{ AtHeight: &depositBlock, } - presetIbcFee := PresetIbcFee{ - AckFee: "100000", - TimeoutFee: "100000", - } atomCoin := Coin{ Denom: cosmosAtom.Config().Denom, @@ -1424,7 +1405,6 @@ func TestTwoPartyNativePartyPol(t *testing.T) { covenantMsg := CovenantInstantiateMsg{ Label: "two-party-pol-covenant-side-happy", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, ContractCodeIds: codeIds, LockupConfig: lockupConfig, PartyAConfig: CovenantPartyConfig{Interchain: &partyAConfig}, diff --git a/interchaintest/two-party-pol/two_party_pol_test.go b/interchaintest/two-party-pol/two_party_pol_test.go index 0c3a338b..85046ea6 100644 --- a/interchaintest/two-party-pol/two_party_pol_test.go +++ b/interchaintest/two-party-pol/two_party_pol_test.go @@ -521,10 +521,6 @@ func TestTwoPartyPol(t *testing.T) { depositDeadline := Expiration{ AtHeight: &depositBlock, } - presetIbcFee := PresetIbcFee{ - AckFee: "10000", - TimeoutFee: "10000", - } atomCoin := Coin{ Denom: cosmosAtom.Config().Denom, @@ -616,7 +612,6 @@ func TestTwoPartyPol(t *testing.T) { covenantMsg := CovenantInstantiateMsg{ Label: "two-party-pol-covenant-happy", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, ContractCodeIds: codeIds, LockupConfig: lockupConfig, PartyAConfig: CovenantPartyConfig{ @@ -825,10 +820,6 @@ func TestTwoPartyPol(t *testing.T) { depositDeadline := Expiration{ AtHeight: &depositBlock, } - presetIbcFee := PresetIbcFee{ - AckFee: "10000", - TimeoutFee: "10000", - } atomCoin := Coin{ Denom: cosmosAtom.Config().Denom, @@ -903,7 +894,6 @@ func TestTwoPartyPol(t *testing.T) { covenantMsg := CovenantInstantiateMsg{ Label: "two-party-pol-covenant-ragequit", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, ContractCodeIds: codeIds, LockupConfig: lockupConfig, PartyAConfig: CovenantPartyConfig{Interchain: &partyAConfig}, @@ -1121,10 +1111,6 @@ func TestTwoPartyPol(t *testing.T) { depositDeadline := Expiration{ AtHeight: &depositBlock, } - presetIbcFee := PresetIbcFee{ - AckFee: "10000", - TimeoutFee: "10000", - } atomCoin := Coin{ Denom: cosmosAtom.Config().Denom, @@ -1199,7 +1185,6 @@ func TestTwoPartyPol(t *testing.T) { covenantMsg := CovenantInstantiateMsg{ Label: "two-party-pol-covenant-side-ragequit", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, ContractCodeIds: codeIds, LockupConfig: lockupConfig, PartyAConfig: CovenantPartyConfig{Interchain: &partyAConfig}, @@ -1386,10 +1371,6 @@ func TestTwoPartyPol(t *testing.T) { depositDeadline := Expiration{ AtHeight: &depositBlock, } - presetIbcFee := PresetIbcFee{ - AckFee: "10000", - TimeoutFee: "10000", - } atomCoin := Coin{ Denom: cosmosAtom.Config().Denom, @@ -1464,7 +1445,6 @@ func TestTwoPartyPol(t *testing.T) { covenantMsg := CovenantInstantiateMsg{ Label: "two-party-pol-covenant-side-happy", Timeouts: timeouts, - PresetIbcFee: presetIbcFee, ContractCodeIds: codeIds, LockupConfig: lockupConfig, PartyAConfig: CovenantPartyConfig{Interchain: &partyAConfig}, diff --git a/interchaintest/two-party-pol/types.go b/interchaintest/two-party-pol/types.go index 2b9380d0..12d637c0 100644 --- a/interchaintest/two-party-pol/types.go +++ b/interchaintest/two-party-pol/types.go @@ -12,7 +12,6 @@ import ( type CovenantInstantiateMsg struct { Label string `json:"label"` Timeouts Timeouts `json:"timeouts"` - PresetIbcFee PresetIbcFee `json:"preset_ibc_fee"` ContractCodeIds ContractCodeIds `json:"contract_codes"` TickMaxGas string `json:"clock_tick_max_gas,omitempty"` LockupConfig Expiration `json:"lockup_config"` @@ -92,11 +91,6 @@ type Timeouts struct { IbcTransferTimeout string `json:"ibc_transfer_timeout"` } -type PresetIbcFee struct { - AckFee string `json:"ack_fee"` - TimeoutFee string `json:"timeout_fee"` -} - type Timestamp string type Block uint64 diff --git a/packages/covenant-utils/src/lib.rs b/packages/covenant-utils/src/lib.rs index 583935ee..16463b68 100644 --- a/packages/covenant-utils/src/lib.rs +++ b/packages/covenant-utils/src/lib.rs @@ -1,12 +1,12 @@ use std::collections::BTreeMap; +use cosmos_sdk_proto::ibc; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ to_json_string, Addr, Attribute, BankMsg, BlockInfo, Coin, CosmosMsg, Decimal, IbcMsg, IbcTimeout, StdError, StdResult, Timestamp, Uint128, Uint64, }; -use neutron::{default_ibc_ack_fee_amount, default_ibc_fee, default_ibc_timeout_fee_amount}; -use neutron_sdk::{bindings::msg::NeutronMsg, sudo::msg::RequestPacketTimeoutHeight}; +use neutron_sdk::{bindings::msg::{IbcFee, NeutronMsg}, sudo::msg::RequestPacketTimeoutHeight}; pub mod astroport; pub mod deadline; @@ -207,10 +207,6 @@ pub struct PacketForwardMiddlewareConfig { pub hop_chain_receiver_address: String, } -pub fn get_default_ibc_fee_requirement() -> Uint128 { - default_ibc_ack_fee_amount() + default_ibc_timeout_fee_amount() -} - pub fn get_default_ica_fee() -> Coin { Coin { denom: "untrn".to_string(), @@ -231,18 +227,39 @@ pub struct ForwardMetadata { pub channel: String, } +pub fn sum_fees(ibc_fee: &IbcFee) -> Uint128 { + let mut total_amount = Uint128::zero(); + + for coin in &ibc_fee.recv_fee { + total_amount += coin.amount; + } + + for coin in &ibc_fee.ack_fee { + total_amount += coin.amount; + } + + for coin in &ibc_fee.timeout_fee { + total_amount += coin.amount; + } + + total_amount +} + impl DestinationConfig { pub fn get_ibc_transfer_messages_for_coins( &self, coins: Vec, current_timestamp: Timestamp, sender_address: String, + ibc_fee: IbcFee, ) -> StdResult>> { let mut messages: Vec> = vec![]; // we get the number of target denoms we have to reserve // neutron fees for let count = Uint128::from(1 + coins.len() as u128); + let total_fee = sum_fees(&ibc_fee); + for coin in coins { let send_coin = if coin.denom != "untrn" { Some(coin) @@ -250,7 +267,7 @@ impl DestinationConfig { // if its neutron we're distributing we need to keep a // reserve for ibc gas costs. // this is safe because we pass target denoms. - let reserve_amount = count * get_default_ibc_fee_requirement(); + let reserve_amount = count * total_fee; if coin.amount > reserve_amount { Some(Coin { denom: coin.denom, @@ -288,7 +305,7 @@ impl DestinationConfig { .to_string(), }), })?, - fee: default_ibc_fee(), + fee: ibc_fee.clone(), })) } None => { @@ -307,7 +324,7 @@ impl DestinationConfig { .nanos(), memo: format!("ibc_distribution: {:?}:{:?}", c.denom, c.amount,) .to_string(), - fee: default_ibc_fee(), + fee: ibc_fee.clone(), })); } } diff --git a/packages/covenant-utils/src/neutron.rs b/packages/covenant-utils/src/neutron.rs index 7e8b0b8c..60a322ea 100644 --- a/packages/covenant-utils/src/neutron.rs +++ b/packages/covenant-utils/src/neutron.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Attribute, Binary, Coin, StdError, StdResult, Uint128, Uint64}; +use cosmwasm_std::{Attribute, Binary, Coin, Deps, QueryRequest, StdError, Uint128, Uint64}; use neutron_sdk::{ - bindings::{msg::IbcFee, types::ProtobufAny}, query::min_ibc_fee::MinIbcFeeResponse, NeutronResult + bindings::{query::NeutronQuery, types::ProtobufAny}, query::min_ibc_fee::MinIbcFeeResponse, NeutronResult }; use prost::Message; @@ -43,15 +43,10 @@ pub struct RemoteChainInfo { pub denom: String, pub ibc_transfer_timeout: Uint64, pub ica_timeout: Uint64, - pub ibc_fee: IbcFee, } impl RemoteChainInfo { pub fn get_response_attributes(&self) -> Vec { - let recv_fee = coin_vec_to_string(&self.ibc_fee.recv_fee); - let ack_fee = coin_vec_to_string(&self.ibc_fee.ack_fee); - let timeout_fee = coin_vec_to_string(&self.ibc_fee.timeout_fee); - vec![ Attribute::new("connection_id", &self.connection_id), Attribute::new("channel_id", &self.channel_id), @@ -61,34 +56,8 @@ impl RemoteChainInfo { self.ibc_transfer_timeout.to_string(), ), Attribute::new("ica_timeout", self.ica_timeout.to_string()), - Attribute::new("ibc_recv_fee", recv_fee), - Attribute::new("ibc_ack_fee", ack_fee), - Attribute::new("ibc_timeout_fee", timeout_fee), ] } - - pub fn validate(self) -> Result { - if self.ibc_fee.ack_fee.is_empty() - || self.ibc_fee.timeout_fee.is_empty() - || !self.ibc_fee.recv_fee.is_empty() - { - return Err(StdError::generic_err("invalid IbcFee".to_string())); - } - - Ok(self) - } -} - -fn coin_vec_to_string(coins: &Vec) -> String { - let mut str = "".to_string(); - if coins.is_empty() { - str.push_str("[]"); - } else { - for coin in coins { - str.push_str(&coin.to_string()); - } - } - str.to_string() } pub fn get_proto_coin( @@ -157,43 +126,21 @@ pub fn to_proto_msg_multi_send(msg: impl Message) -> NeutronResult }) } -pub fn default_ibc_ack_fee_amount() -> Uint128 { - Uint128::new(100000) -} - -pub fn default_ibc_timeout_fee_amount() -> Uint128 { - Uint128::new(100000) -} - -pub fn default_ibc_fee() -> IbcFee { - IbcFee { - // must be empty - recv_fee: vec![], - ack_fee: vec![cosmwasm_std::Coin { - denom: "untrn".to_string(), - amount: default_ibc_ack_fee_amount(), - }], - timeout_fee: vec![cosmwasm_std::Coin { - denom: "untrn".to_string(), - amount: default_ibc_timeout_fee_amount(), - }], - } +// manual definitions for neutron ictxs module +#[cw_serde] +pub struct Params { + pub msg_submit_tx_max_messages: Uint64, + pub register_fee: Vec, } -pub fn get_default_ibc_fee_requirement() -> Uint128 { - default_ibc_ack_fee_amount() + default_ibc_timeout_fee_amount() +#[cw_serde] +pub struct QueryParamsResponse { + pub params: Params, } -pub fn get_default_ica_fee() -> Coin { - Coin { - denom: "untrn".to_string(), - amount: Uint128::new(1000000), +pub fn get_ictxs_module_params_query_msg() -> QueryRequest { + QueryRequest::Stargate { + path: "/neutron.interchaintxs.v1.Query/Params".to_string(), + data: Binary(Vec::new()), } -} - -pub fn get_ibc_fee_total_amount(min_fee_query_response: MinIbcFeeResponse) -> Uint128 { - let ack_fee_total: Uint128 = min_fee_query_response.min_fee.ack_fee.iter().map(|c| c.amount).sum(); - let recv_fee_total: Uint128 = min_fee_query_response.min_fee.recv_fee.iter().map(|c| c.amount).sum(); - let timeout_fee_total: Uint128 = min_fee_query_response.min_fee.timeout_fee.iter().map(|c| c.amount).sum(); - ack_fee_total + recv_fee_total + timeout_fee_total } \ No newline at end of file diff --git a/packages/covenant-utils/src/polytone.rs b/packages/covenant-utils/src/polytone.rs index c96793ac..e0d3ada1 100644 --- a/packages/covenant-utils/src/polytone.rs +++ b/packages/covenant-utils/src/polytone.rs @@ -3,6 +3,7 @@ use cosmwasm_std::{ to_json_binary, Binary, CosmosMsg, Empty, QuerierWrapper, QueryRequest, StdError, StdResult, Uint64, }; +use neutron_sdk::bindings::query::NeutronQuery; use polytone::callbacks::CallbackRequest; #[cw_serde] @@ -57,7 +58,7 @@ pub fn get_polytone_query_msg_binary( pub fn query_polytone_proxy_address( local_address: String, note_address: String, - querier: QuerierWrapper, + querier: QuerierWrapper, ) -> Result, StdError> { let remote_address_query = PolytoneQueryMsg::RemoteAddress { local_address }; diff --git a/unit-tests/Cargo.toml b/unit-tests/Cargo.toml index 97aa42b8..bb41d520 100644 --- a/unit-tests/Cargo.toml +++ b/unit-tests/Cargo.toml @@ -47,6 +47,6 @@ astroport-whitelist = { workspace = true } astroport-factory = { workspace = true } astroport-native-coin-registry = { workspace = true } astroport-pair-stable = { workspace = true } -astroport-pair = { workspace = true } +astroport-pair = { workspace = true } osmosis-std = "0.13.2" diff --git a/unit-tests/src/setup/custom_keepers.rs b/unit-tests/src/setup/custom_keepers.rs index e00eb088..fd999638 100644 --- a/unit-tests/src/setup/custom_keepers.rs +++ b/unit-tests/src/setup/custom_keepers.rs @@ -4,6 +4,7 @@ use cosmwasm_std::{ from_json, to_json_binary, Addr, Api, Binary, BlockInfo, CustomMsg, CustomQuery, Querier, Storage, }; +use covenant_utils::neutron::{Params, QueryParamsResponse}; use cw_multi_test::error::{AnyError, AnyResult}; use cw_multi_test::{AppResponse, CosmosRouter, Module, StargateQuery}; use osmosis_std::types::cosmos::base::v1beta1::Coin; @@ -84,6 +85,20 @@ where ) -> AnyResult { let query: StargateQuery = from_json(to_json_binary(&request).unwrap()).unwrap(); // TODO: these mocks should be configurable on top-level SuiteBuilder config, pre build + if query.path == "/neutron.interchaintxs.v1.Query/Params" { + let response = QueryParamsResponse { + params: Params { + msg_submit_tx_max_messages: cosmwasm_std::Uint64::new(1000), + register_fee: vec![cosmwasm_std::Coin { + amount: cosmwasm_std::Uint128::new(1000000), + denom: "untrn".to_string(), + }], + }, + }; + + return Ok(to_json_binary(&response).unwrap()); + } + if query.path == "/osmosis.gamm.v1beta1.Query/Pool" { let pool = osmosis_std::types::osmosis::gamm::v1beta1::Pool { address: "address".to_string(), diff --git a/unit-tests/src/setup/custom_module.rs b/unit-tests/src/setup/custom_module.rs index db578b06..434cdde0 100644 --- a/unit-tests/src/setup/custom_module.rs +++ b/unit-tests/src/setup/custom_module.rs @@ -1,8 +1,7 @@ use std::{collections::BTreeMap, str::FromStr}; use cosmwasm_std::{ - coin, coins, from_json, to_json_binary, to_json_string, Addr, BalanceResponse, BankMsg, - BankQuery, StdError, StdResult, Storage, Uint128, + coin, coins, from_json, to_json_binary, to_json_string, Addr, BalanceResponse, BankMsg, BankQuery, QueryRequest, StdError, StdResult, Storage, Uint128 }; use covenant_ibc_forwarder::helpers::MsgTransfer; use covenant_stride_liquid_staker::helpers::Autopilot; @@ -794,7 +793,6 @@ impl Module for NeutronKeeper { NeutronMsg::AddSchedule { .. } => unimplemented!(), NeutronMsg::RemoveSchedule { .. } => unimplemented!(), NeutronMsg::ResubmitFailure { .. } => unimplemented!(), - NeutronMsg::Dex(_) => unimplemented!(), } } @@ -840,7 +838,6 @@ impl Module for NeutronKeeper { NeutronQuery::DenomAdmin { .. } => todo!(), NeutronQuery::BeforeSendHook { .. } => todo!(), NeutronQuery::Failures { .. } => todo!(), - NeutronQuery::Dex(_) => todo!(), } } diff --git a/unit-tests/src/setup/instantiates/ibc_forwarder.rs b/unit-tests/src/setup/instantiates/ibc_forwarder.rs index 65c9b8e2..b145ca99 100644 --- a/unit-tests/src/setup/instantiates/ibc_forwarder.rs +++ b/unit-tests/src/setup/instantiates/ibc_forwarder.rs @@ -21,7 +21,6 @@ impl IbcForwarderInstantiate { remote_chain_channel_id: String, denom: String, amount: Uint128, - ibc_fee: IbcFee, ibc_transfer_timeout: Uint64, ica_timeout: Uint64, ) -> Self { @@ -33,7 +32,6 @@ impl IbcForwarderInstantiate { remote_chain_channel_id, denom, amount, - ibc_fee, ibc_transfer_timeout, ica_timeout, }, @@ -70,11 +68,6 @@ impl IbcForwarderInstantiate { self } - pub fn with_ibc_fee(&mut self, addr: IbcFee) -> &mut Self { - self.msg.ibc_fee = addr; - self - } - pub fn with_ibc_transfer_timeout(&mut self, addr: Uint64) -> &mut Self { self.msg.ibc_transfer_timeout = addr; self @@ -96,11 +89,6 @@ impl IbcForwarderInstantiate { remote_chain_channel_id: NTRN_HUB_CHANNEL.1.to_string(), denom: DENOM_ATOM_ON_NTRN.to_string(), amount: Uint128::new(100_000), - ibc_fee: IbcFee { - recv_fee: vec![], - ack_fee: vec![coin(100_000, DENOM_NTRN)], - timeout_fee: vec![coin(100_000, DENOM_NTRN)], - }, ica_timeout: Uint64::from(100u64), ibc_transfer_timeout: Uint64::from(100u64), }, diff --git a/unit-tests/src/setup/instantiates/remote_chain_splitter.rs b/unit-tests/src/setup/instantiates/remote_chain_splitter.rs index e6249dee..44d3c7c8 100644 --- a/unit-tests/src/setup/instantiates/remote_chain_splitter.rs +++ b/unit-tests/src/setup/instantiates/remote_chain_splitter.rs @@ -2,9 +2,8 @@ use std::{collections::BTreeMap, str::FromStr}; use cosmwasm_std::{coin, Decimal, Uint128, Uint64}; use covenant_utils::split::SplitConfig; -use neutron_sdk::bindings::msg::IbcFee; -use crate::setup::{DENOM_ATOM_ON_NTRN, DENOM_NTRN, NTRN_HUB_CHANNEL}; +use crate::setup::{DENOM_ATOM_ON_NTRN, NTRN_HUB_CHANNEL}; pub struct RemoteChainSplitterInstantiate { pub msg: covenant_remote_chain_splitter::msg::InstantiateMsg, @@ -23,7 +22,6 @@ impl RemoteChainSplitterInstantiate { denom: String, amount: Uint128, splits: BTreeMap, - ibc_fee: IbcFee, ica_timeout: Uint64, ibc_transfer_timeout: Uint64, ) -> Self { @@ -35,7 +33,6 @@ impl RemoteChainSplitterInstantiate { denom, amount, splits, - ibc_fee, ica_timeout, ibc_transfer_timeout, }, @@ -72,11 +69,6 @@ impl RemoteChainSplitterInstantiate { self } - pub fn with_ibc_fee(&mut self, ibc_fee: IbcFee) -> &mut Self { - self.msg.ibc_fee = ibc_fee; - self - } - pub fn with_ica_timeout(&mut self, ica_timeout: Uint64) -> &mut Self { self.msg.ica_timeout = ica_timeout; self @@ -106,11 +98,6 @@ impl RemoteChainSplitterInstantiate { denom: DENOM_ATOM_ON_NTRN.to_string(), amount: Uint128::from(10000u128), splits: denom_to_split_config_map, - ibc_fee: IbcFee { - recv_fee: vec![], - ack_fee: vec![coin(10000u128, DENOM_NTRN)], - timeout_fee: vec![coin(10000u128, DENOM_NTRN)], - }, ica_timeout: Uint64::from(100u64), ibc_transfer_timeout: Uint64::from(100u64), }, diff --git a/unit-tests/src/setup/instantiates/single_party_covenant.rs b/unit-tests/src/setup/instantiates/single_party_covenant.rs index 10302ccd..6f789a44 100644 --- a/unit-tests/src/setup/instantiates/single_party_covenant.rs +++ b/unit-tests/src/setup/instantiates/single_party_covenant.rs @@ -45,10 +45,6 @@ impl SinglePartyCovenantInstantiate { ica_timeout: 1000_u64.into(), ibc_transfer_timeout: 1000_u64.into(), }, - covenant_single_party_pol::msg::PresetIbcFee { - ack_fee: 100_000_u128.into(), - timeout_fee: 100_000_u128.into(), - }, contract_codes, None, Expiration::AtHeight(builder.app.block_info().height + 100000), @@ -181,7 +177,6 @@ impl SinglePartyCovenantInstantiate { pub fn new( label: String, timeouts: covenant_single_party_pol::msg::Timeouts, - preset_ibc_fee: covenant_single_party_pol::msg::PresetIbcFee, contract_codes: covenant_single_party_pol::msg::CovenantContractCodeIds, clock_tick_max_gas: Option, lockup_period: Expiration, @@ -198,7 +193,6 @@ impl SinglePartyCovenantInstantiate { msg: covenant_single_party_pol::msg::InstantiateMsg { label, timeouts, - preset_ibc_fee, contract_codes, clock_tick_max_gas, lockup_period, @@ -232,18 +226,6 @@ impl SinglePartyCovenantInstantiate { self } - pub fn with_ibc_fee( - &mut self, - ack_fee: impl Into, - timeout_fee: impl Into, - ) -> &mut Self { - self.msg.preset_ibc_fee = covenant_single_party_pol::msg::PresetIbcFee { - ack_fee: ack_fee.into(), - timeout_fee: timeout_fee.into(), - }; - self - } - pub fn with_contract_codes( &mut self, codes: covenant_single_party_pol::msg::CovenantContractCodeIds, diff --git a/unit-tests/src/setup/instantiates/swap_covenant.rs b/unit-tests/src/setup/instantiates/swap_covenant.rs index 57b346a6..ca058be5 100644 --- a/unit-tests/src/setup/instantiates/swap_covenant.rs +++ b/unit-tests/src/setup/instantiates/swap_covenant.rs @@ -38,10 +38,6 @@ impl SwapCovenantInstantiate { ica_timeout: 1000_u64.into(), ibc_transfer_timeout: 1000_u64.into(), }, - covenant_swap::msg::PresetIbcFee { - ack_fee: 100_000_u128.into(), - timeout_fee: 100_000_u128.into(), - }, contract_codes, None, Expiration::AtHeight(mock_env().block.height + 1000), @@ -115,7 +111,6 @@ impl SwapCovenantInstantiate { pub fn new( label: String, timeouts: covenant_swap::msg::Timeouts, - preset_ibc_fee: covenant_swap::msg::PresetIbcFee, contract_codes: covenant_swap::msg::SwapCovenantContractCodeIds, clock_tick_max_gas: Option, lockup_config: Expiration, @@ -128,7 +123,6 @@ impl SwapCovenantInstantiate { msg: covenant_swap::msg::InstantiateMsg { label, timeouts, - preset_ibc_fee, contract_codes, clock_tick_max_gas, lockup_config, @@ -158,18 +152,6 @@ impl SwapCovenantInstantiate { self } - pub fn with_ibc_fee( - &mut self, - ack_fee: impl Into, - timeout_fee: impl Into, - ) -> &mut Self { - self.msg.preset_ibc_fee = covenant_swap::msg::PresetIbcFee { - ack_fee: ack_fee.into(), - timeout_fee: timeout_fee.into(), - }; - self - } - pub fn with_contract_codes( &mut self, codes: covenant_swap::msg::SwapCovenantContractCodeIds, diff --git a/unit-tests/src/setup/instantiates/two_party_covenant.rs b/unit-tests/src/setup/instantiates/two_party_covenant.rs index c6fa24e6..8ab30886 100644 --- a/unit-tests/src/setup/instantiates/two_party_covenant.rs +++ b/unit-tests/src/setup/instantiates/two_party_covenant.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, str::FromStr}; use cosmwasm_std::{coin, Addr, Decimal, Uint128, Uint64}; use covenant_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; -use covenant_two_party_pol::msg::{CovenantPartyConfig, PresetIbcFee, Timeouts}; +use covenant_two_party_pol::msg::{CovenantPartyConfig, Timeouts}; use covenant_utils::{ split::SplitConfig, NativeCovenantParty, PoolPriceConfig, SingleSideLpLimits, }; @@ -27,11 +27,6 @@ impl TwoPartyCovenantInstantiate { self } - pub fn with_ibc_fee(&mut self, preset_ibc_fee: PresetIbcFee) -> &mut Self { - self.msg.preset_ibc_fee = preset_ibc_fee; - self - } - pub fn with_contract_codes( &mut self, contract_codes: covenant_two_party_pol::msg::CovenantContractCodeIds, @@ -158,10 +153,6 @@ impl TwoPartyCovenantInstantiate { ica_timeout: Uint64::new(100), ibc_transfer_timeout: Uint64::new(100), }, - preset_ibc_fee: PresetIbcFee { - ack_fee: Uint128::new(10_000), - timeout_fee: Uint128::new(10_000), - }, contract_codes, clock_tick_max_gas: None, lockup_config: Expiration::AtHeight(200000), diff --git a/unit-tests/src/test_ibc_forwarder/suite.rs b/unit-tests/src/test_ibc_forwarder/suite.rs index cb73630e..3b3ff672 100644 --- a/unit-tests/src/test_ibc_forwarder/suite.rs +++ b/unit-tests/src/test_ibc_forwarder/suite.rs @@ -73,11 +73,6 @@ impl IbcForwarderBuilder { self } - pub fn with_ibc_fee(mut self, ibc_fee: IbcFee) -> Self { - self.instantiate_msg.with_ibc_fee(ibc_fee); - self - } - pub fn with_ibc_transfer_timeout(mut self, ibc_transfer_timeout: Uint64) -> Self { self.instantiate_msg .with_ibc_transfer_timeout(ibc_transfer_timeout); diff --git a/unit-tests/src/test_remote_chain_splitter/suite.rs b/unit-tests/src/test_remote_chain_splitter/suite.rs index 0955cd01..0eb6285b 100644 --- a/unit-tests/src/test_remote_chain_splitter/suite.rs +++ b/unit-tests/src/test_remote_chain_splitter/suite.rs @@ -51,11 +51,6 @@ impl Default for RemoteChainSplitterBuilder { remote_chain_channel_id: NTRN_HUB_CHANNEL.0.to_string(), denom: DENOM_ATOM_ON_NTRN.to_string(), amount: Uint128::new(100), - ibc_fee: IbcFee { - recv_fee: vec![], - ack_fee: vec![coin(1u128, DENOM_NTRN)], - timeout_fee: vec![coin(1u128, DENOM_NTRN)], - }, ibc_transfer_timeout: Uint64::new(100), ica_timeout: Uint64::new(100), }; @@ -118,11 +113,6 @@ impl RemoteChainSplitterBuilder { self } - pub fn with_ibc_fee(mut self, ibc_fee: IbcFee) -> Self { - self.instantiate_msg.with_ibc_fee(ibc_fee); - self - } - pub fn with_ica_timeout(mut self, ica_timeout: Uint64) -> Self { self.instantiate_msg.with_ica_timeout(ica_timeout); self diff --git a/unit-tests/src/test_two_party_covenant/suite.rs b/unit-tests/src/test_two_party_covenant/suite.rs index 72cb5bed..1c9304d2 100644 --- a/unit-tests/src/test_two_party_covenant/suite.rs +++ b/unit-tests/src/test_two_party_covenant/suite.rs @@ -10,9 +10,8 @@ use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, instantiates::two_party_covenant::TwoPartyCovenantInstantiate, suite_builder::SuiteBuilder, - CustomApp, ADMIN, DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, - DENOM_LS_ATOM_ON_STRIDE, HUB_STRIDE_CHANNEL, NTRN_HUB_CHANNEL, NTRN_STRIDE_CHANNEL, - SINGLE_PARTY_COVENANT_SALT, TWO_PARTY_COVENANT_SALT, + CustomApp, ADMIN, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, + TWO_PARTY_COVENANT_SALT, }; pub struct TwoPartyCovenantBuilder { @@ -55,14 +54,6 @@ impl TwoPartyCovenantBuilder { self } - pub fn with_ibc_fee( - mut self, - preset_ibc_fee: covenant_two_party_pol::msg::PresetIbcFee, - ) -> Self { - self.instantiate_msg.with_ibc_fee(preset_ibc_fee); - self - } - pub fn with_contract_codes( mut self, contract_codes: covenant_two_party_pol::msg::CovenantContractCodeIds, From eb12937a47080712d592e735d822908dc1c998a7 Mon Sep 17 00:00:00 2001 From: bekauz Date: Thu, 14 Mar 2024 21:05:06 +0100 Subject: [PATCH 06/56] astro liquid pooler withdraw handles non-lp token withdrawal --- .../astroport-liquid-pooler/src/contract.rs | 34 ++++++++++++++++--- .../astroport-liquid-pooler/src/error.rs | 4 +-- contracts/ibc-forwarder/src/msg.rs | 1 - contracts/remote-chain-splitter/src/msg.rs | 1 - contracts/stride-liquid-staker/src/msg.rs | 1 - packages/covenant-utils/src/lib.rs | 1 - packages/covenant-utils/src/neutron.rs | 4 +-- .../src/test_astroport_liquid_pooler/tests.rs | 27 +++++++++++++-- 8 files changed, 59 insertions(+), 14 deletions(-) diff --git a/contracts/astroport-liquid-pooler/src/contract.rs b/contracts/astroport-liquid-pooler/src/contract.rs index bb93a56e..de125df1 100644 --- a/contracts/astroport-liquid-pooler/src/contract.rs +++ b/contracts/astroport-liquid-pooler/src/contract.rs @@ -124,10 +124,36 @@ fn try_withdraw( env.contract.address.to_string(), )?; - ensure!( - !lp_token_info.balance_response.balance.is_zero(), - ContractError::NoLpTokensAvailable {} - ); + // if no lp tokens are available, we attempt to withdraw any available denoms + if lp_token_info.balance_response.balance.is_zero() { + let asset_a_bal = deps.querier.query_balance( + env.contract.address.to_string(), + lp_config.asset_data.asset_a_denom.as_str(), + )?; + let asset_b_bal = deps.querier.query_balance( + env.contract.address.to_string(), + lp_config.asset_data.asset_b_denom.as_str(), + )?; + + let mut funds = vec![]; + + if !asset_a_bal.amount.is_zero() { + funds.push(asset_a_bal); + } + + if !asset_b_bal.amount.is_zero() { + funds.push(asset_b_bal); + } + + ensure!(!funds.is_empty(), ContractError::NothingToWithdraw {}); + + return Ok(Response::default() + .add_message(WasmMsg::Execute { + contract_addr: holder_addr.to_string(), + msg: to_json_binary(&WithdrawLPMsgs::Distribute {})?, + funds, + })) + } // If percentage is 100%, use the whole balance // If percentage is less than 100%, calculate the percentage of share we want to withdraw diff --git a/contracts/astroport-liquid-pooler/src/error.rs b/contracts/astroport-liquid-pooler/src/error.rs index a8d6fb9c..42c3ffc4 100644 --- a/contracts/astroport-liquid-pooler/src/error.rs +++ b/contracts/astroport-liquid-pooler/src/error.rs @@ -49,6 +49,6 @@ pub enum ContractError { #[error("Only holder can withdraw the position")] NotHolder {}, - #[error("no lp tokens available")] - NoLpTokensAvailable {}, + #[error("no covenant denom or lp tokens available")] + NothingToWithdraw {}, } diff --git a/contracts/ibc-forwarder/src/msg.rs b/contracts/ibc-forwarder/src/msg.rs index b3da02ab..dfd3287c 100644 --- a/contracts/ibc-forwarder/src/msg.rs +++ b/contracts/ibc-forwarder/src/msg.rs @@ -8,7 +8,6 @@ use covenant_macros::{ covenant_remote_chain, }; use covenant_utils::{instantiate2_helper::Instantiate2HelperConfig, neutron::RemoteChainInfo}; -use neutron_sdk::bindings::msg::IbcFee; use crate::state::CONTRACT_STATE; diff --git a/contracts/remote-chain-splitter/src/msg.rs b/contracts/remote-chain-splitter/src/msg.rs index d2cdcde7..93445a26 100644 --- a/contracts/remote-chain-splitter/src/msg.rs +++ b/contracts/remote-chain-splitter/src/msg.rs @@ -13,7 +13,6 @@ use covenant_macros::{ use covenant_utils::{ instantiate2_helper::Instantiate2HelperConfig, neutron::RemoteChainInfo, split::SplitConfig, }; -use neutron_sdk::bindings::msg::IbcFee; use crate::state::CONTRACT_STATE; diff --git a/contracts/stride-liquid-staker/src/msg.rs b/contracts/stride-liquid-staker/src/msg.rs index 3ea82fd0..39027a33 100644 --- a/contracts/stride-liquid-staker/src/msg.rs +++ b/contracts/stride-liquid-staker/src/msg.rs @@ -5,7 +5,6 @@ use covenant_macros::{ covenant_remote_chain, }; use covenant_utils::{instantiate2_helper::Instantiate2HelperConfig, neutron::RemoteChainInfo}; -use neutron_sdk::bindings::msg::IbcFee; #[cw_serde] pub struct InstantiateMsg { diff --git a/packages/covenant-utils/src/lib.rs b/packages/covenant-utils/src/lib.rs index 16463b68..0c7a2a31 100644 --- a/packages/covenant-utils/src/lib.rs +++ b/packages/covenant-utils/src/lib.rs @@ -1,6 +1,5 @@ use std::collections::BTreeMap; -use cosmos_sdk_proto::ibc; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ to_json_string, Addr, Attribute, BankMsg, BlockInfo, Coin, CosmosMsg, Decimal, IbcMsg, diff --git a/packages/covenant-utils/src/neutron.rs b/packages/covenant-utils/src/neutron.rs index 60a322ea..373e34e6 100644 --- a/packages/covenant-utils/src/neutron.rs +++ b/packages/covenant-utils/src/neutron.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Attribute, Binary, Coin, Deps, QueryRequest, StdError, Uint128, Uint64}; +use cosmwasm_std::{Attribute, Binary, Coin, QueryRequest, StdError, Uint128, Uint64}; use neutron_sdk::{ - bindings::{query::NeutronQuery, types::ProtobufAny}, query::min_ibc_fee::MinIbcFeeResponse, NeutronResult + bindings::{query::NeutronQuery, types::ProtobufAny}, NeutronResult }; use prost::Message; diff --git a/unit-tests/src/test_astroport_liquid_pooler/tests.rs b/unit-tests/src/test_astroport_liquid_pooler/tests.rs index 37e84dae..0ec4dda8 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/tests.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/tests.rs @@ -87,14 +87,37 @@ fn test_withdraw_validates_holder() { } #[test] -#[should_panic(expected = "no lp tokens available")] -fn test_withdraw_no_lp_tokens() { +#[should_panic(expected = "no covenant denom or lp tokens available")] +fn test_withdraw_no_lp_or_covenant_denoms() { let mut suite = AstroLiquidPoolerBuilder::default().build(); let withdrawer = suite.clock_addr.clone(); suite.withdraw(&withdrawer, None); } +#[test] +fn test_withdraw_no_lp_tokens_withdraws_covenant_assets() { + let mut suite = AstroLiquidPoolerBuilder::default().build(); + suite.fund_contract( + &coins(500_000, DENOM_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + suite.fund_contract( + &coins(500_000, DENOM_LS_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + + let withdrawer = suite.clock_addr.clone(); + + suite.assert_balance(suite.holder_addr.clone(), coin(0, DENOM_ATOM_ON_NTRN)); + suite.assert_balance(suite.holder_addr.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN)); + + suite.withdraw(&withdrawer, None); + + suite.assert_balance(&suite.holder_addr.clone(), coin(500_000, DENOM_ATOM_ON_NTRN)); + suite.assert_balance(&suite.holder_addr.clone(), coin(500_000, DENOM_LS_ATOM_ON_NTRN)); +} + #[test] fn test_withdraw_no_percentage_defaults_to_full_position() { let mut suite = AstroLiquidPoolerBuilder::default().build(); From 035d4b7d30ec45f2ddc37e7f41f1919ac82369bb Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 15 Mar 2024 12:14:49 +0100 Subject: [PATCH 07/56] remote chain splitter routes any rounding leftover denoms to first split receiver; removing duplicate denom validation on instantiation --- .../remote-chain-splitter/src/contract.rs | 29 +++++---- .../src/test_remote_chain_splitter/tests.rs | 59 ++++++++++++++++++- 2 files changed, 74 insertions(+), 14 deletions(-) diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index eebca2d2..8e32eaaa 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -1,4 +1,5 @@ use std::collections::HashSet; +use std::str::FromStr; use cosmos_sdk_proto::cosmos::bank::v1beta1::{Input, MsgMultiSend, Output}; use cosmos_sdk_proto::cosmos::base::v1beta1::Coin; @@ -7,7 +8,7 @@ use cosmos_sdk_proto::traits::Message; use cosmwasm_std::entry_point; use cosmwasm_std::{ to_json_binary, Attribute, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, Fraction, - MessageInfo, Reply, Response, StdError, StdResult, SubMsg, + MessageInfo, Reply, Response, StdError, StdResult, SubMsg, Uint128, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::neutron::{get_ictxs_module_params_query_msg, QueryParamsResponse, RemoteChainInfo, SudoPayload}; @@ -64,19 +65,11 @@ pub fn instantiate( // validate each split and store it in a map let mut split_resp_attributes: Vec = Vec::with_capacity(msg.splits.len()); - let mut encountered_denoms: HashSet = HashSet::with_capacity(msg.splits.len()); for (denom, split_config) in msg.splits { - // if denom had not yet been encountered we proceed, otherwise error - if encountered_denoms.insert(denom.to_string()) { - split_config.validate_shares()?; - split_resp_attributes.push(split_config.get_response_attribute(denom.to_string())); - SPLIT_CONFIG_MAP.save(deps.storage, denom, &split_config)?; - } else { - return Err(NeutronError::Std(StdError::GenericErr { - msg: format!("multiple {:?} entries", denom), - })); - } + split_config.validate_shares()?; + split_resp_attributes.push(split_config.get_response_attribute(denom.to_string())); + SPLIT_CONFIG_MAP.save(deps.storage, denom, &split_config)?; } Ok(Response::default() @@ -149,6 +142,7 @@ fn try_split_funds(mut deps: ExecuteDeps, env: Env) -> NeutronResult = Vec::with_capacity(splits.len()); + let mut total_allocated = Uint128::zero(); for (split_receiver, share) in splits.iter() { // query the ibc forwarders for their ICA addresses // if either does not exist yet, error out @@ -181,10 +175,19 @@ fn try_split_funds(mut deps: ExecuteDeps, env: Env) -> NeutronResult = Vec::new(); let input = Input { address: address.to_string(), diff --git a/unit-tests/src/test_remote_chain_splitter/tests.rs b/unit-tests/src/test_remote_chain_splitter/tests.rs index 062b6f9f..0de1c9a2 100644 --- a/unit-tests/src/test_remote_chain_splitter/tests.rs +++ b/unit-tests/src/test_remote_chain_splitter/tests.rs @@ -1,6 +1,6 @@ use std::{collections::BTreeMap, str::FromStr}; -use cosmwasm_std::{coin, coins, Addr, Decimal}; +use cosmwasm_std::{coin, coins, Addr, Decimal, Uint128}; use covenant_utils::split::SplitConfig; use cw_multi_test::Executor; @@ -126,6 +126,63 @@ fn test_execute_tick_splits_funds_happy() { suite.assert_balance(&splitter_ica, zero_bal.clone()); } +#[test] +fn test_execute_tick_splits_with_no_leftover() { + let mut builder = RemoteChainSplitterBuilder::default().with_amount(Uint128::new(100)); + let mut split_config = builder.instantiate_msg.msg.splits.get(DENOM_ATOM_ON_NTRN).unwrap().clone(); + let mut first_entry = split_config.receivers.pop_first().unwrap(); + let mut second_entry = split_config.receivers.pop_first().unwrap(); + + first_entry.1 = Decimal::from_str("0.107").unwrap(); + second_entry.1 = Decimal::from_str("0.893").unwrap(); + + split_config.receivers.insert(first_entry.0, first_entry.1); + split_config.receivers.insert(second_entry.0, second_entry.1); + + builder.instantiate_msg.msg.splits.insert(DENOM_ATOM_ON_NTRN.to_string(), split_config); + + let mut suite = builder.build(); + + let splitter = suite.splitter.clone(); + let receiver_1 = suite.receiver_1.clone(); + let receiver_2 = suite.receiver_2.clone(); + + suite.fund_contract(&coins(10000000, DENOM_NTRN), splitter.clone()); + suite.fund_contract(&coins(1000000, DENOM_NTRN), receiver_1.clone()); + suite.fund_contract(&coins(1000000, DENOM_NTRN), receiver_2.clone()); + + assert!(suite.query_deposit_address(splitter.clone()).is_none()); + assert!(suite.query_deposit_address(receiver_1.clone()).is_none()); + assert!(suite.query_deposit_address(receiver_2.clone()).is_none()); + + suite.tick_contract(splitter.clone()); + suite.tick_contract(receiver_1.clone()); + suite.tick_contract(receiver_2.clone()); + + let r1_ica = Addr::unchecked(suite.query_deposit_address(receiver_1.clone()).unwrap()); + let r2_ica = Addr::unchecked(suite.query_deposit_address(receiver_2.clone()).unwrap()); + let splitter_ica = Addr::unchecked(suite.query_deposit_address(splitter.clone()).unwrap()); + + let zero_bal = coin(0, DENOM_ATOM_ON_NTRN); + + suite.assert_balance(&r1_ica, zero_bal.clone()); + suite.assert_balance(&r2_ica, zero_bal.clone()); + suite.assert_balance(&splitter_ica, zero_bal.clone()); + + let amount = coins(100, DENOM_ATOM_ON_NTRN); + let expected_first_coin = coin(11, DENOM_ATOM_ON_NTRN); + let expected_second_coin = coin(89, DENOM_ATOM_ON_NTRN); + + suite.fund_contract(&amount, splitter_ica.clone()); + suite.assert_balance(&splitter_ica, amount[0].clone()); + + suite.tick_contract(splitter); + + suite.assert_balance(&r1_ica, expected_first_coin.clone()); + suite.assert_balance(&r2_ica, expected_second_coin.clone()); + suite.assert_balance(&splitter_ica, zero_bal.clone()); +} + #[test] fn test_migrate_update_config() { let mut suite = RemoteChainSplitterBuilder::default().build(); From dbf9bd04d3fabc9e1b476ea24b71390dc54e5d66 Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 15 Mar 2024 12:38:42 +0100 Subject: [PATCH 08/56] two party holder validation for lockup expiration to be after the deposit deadline --- .../two-party-pol-holder/src/contract.rs | 20 ++++++++++++----- contracts/two-party-pol-holder/src/error.rs | 5 ++++- .../src/test_two_party_pol_holder/tests.rs | 22 +++++++++++++++++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index c281c7a1..bcb17ad9 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -1,8 +1,8 @@ +use std::cmp::Ordering; use std::collections::BTreeMap; use cosmwasm_std::{ - ensure, to_json_binary, BankMsg, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, - MessageInfo, Response, StdError, StdResult, + ensure, to_json_binary, BankMsg, Binary, BlockInfo, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult }; #[cfg(not(feature = "library"))] @@ -12,6 +12,7 @@ use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::split::SplitConfig; use covenant_utils::withdraw_lp_helper::{generate_withdraw_msg, EMERGENCY_COMMITTEE_ADDR}; use cw2::set_contract_version; +use cw_utils::Expiration; use crate::msg::CovenantType; use crate::state::{WithdrawState, LIQUID_POOLER_ADDRESS, WITHDRAW_STATE}; @@ -42,14 +43,21 @@ pub fn instantiate( let next_contract = deps.api.addr_validate(&msg.next_contract)?; let clock_addr = deps.api.addr_validate(&msg.clock_address)?; + // ensure that the deposit deadline is in the future ensure!( !msg.deposit_deadline.is_expired(&env.block), ContractError::DepositDeadlineValidationError {} ); - ensure!( - !msg.lockup_config.is_expired(&env.block), - ContractError::LockupValidationError {} - ); + + // validate that lockup expiration is after the deposit deadline + match msg.deposit_deadline.partial_cmp(&msg.lockup_config) { + Some(ordering) => ensure!( + ordering == Ordering::Less, + ContractError::LockupValidationError {} + ), + // we validate incompatible expirations + None => return Err(ContractError::ExpirationValidationError {}), + }; if let Some(addr) = &msg.emergency_committee_addr { let committee_addr = deps.api.addr_validate(addr)?; diff --git a/contracts/two-party-pol-holder/src/error.rs b/contracts/two-party-pol-holder/src/error.rs index 061a2581..8d1cc090 100644 --- a/contracts/two-party-pol-holder/src/error.rs +++ b/contracts/two-party-pol-holder/src/error.rs @@ -36,9 +36,12 @@ pub enum ContractError { #[error("expiry block is already past")] InvalidExpiryBlockHeight {}, - #[error("lockup deadline is already past")] + #[error("lockup deadline must be after the deposit deadline")] LockupValidationError {}, + #[error("cannot validate deposit and lockup expirations")] + ExpirationValidationError {}, + #[error("deposit deadline is already past")] DepositDeadlineValidationError {}, diff --git a/unit-tests/src/test_two_party_pol_holder/tests.rs b/unit-tests/src/test_two_party_pol_holder/tests.rs index 6536e059..771ccc69 100644 --- a/unit-tests/src/test_two_party_pol_holder/tests.rs +++ b/unit-tests/src/test_two_party_pol_holder/tests.rs @@ -1,6 +1,6 @@ use std::{collections::BTreeMap, str::FromStr}; -use cosmwasm_std::{coin, Addr, Decimal, Event, Uint128}; +use cosmwasm_std::{coin, Addr, Decimal, Event, Timestamp, Uint128}; use covenant_two_party_pol_holder::msg::{ContractState, RagequitConfig, RagequitTerms}; use covenant_utils::split::SplitConfig; use cw_multi_test::Executor; @@ -46,13 +46,31 @@ fn test_instantiate_validates_deposit_deadline() { } #[test] -#[should_panic(expected = "lockup deadline is already past")] +#[should_panic(expected = "lockup deadline must be after the deposit deadline")] fn test_instantiate_validates_lockup_config() { TwoPartyHolderBuilder::default() .with_lockup_config(Expiration::AtHeight(1)) .build(); } +#[test] +#[should_panic(expected = "cannot validate deposit and lockup expirations")] +fn test_instantiate_validates_incompatible_deposit_and_lockup_expirations() { + TwoPartyHolderBuilder::default() + .with_deposit_deadline(Expiration::AtHeight(200000)) + .with_lockup_config(Expiration::AtTime(Timestamp::from_seconds(10000999990))) + .build(); +} + +#[test] +#[should_panic(expected = "lockup deadline must be after the deposit deadline")] +fn test_instantiate_validates_deposit_deadline_prior_to_lockup_expiration() { + TwoPartyHolderBuilder::default() + .with_deposit_deadline(Expiration::AtHeight(200000)) + .with_lockup_config(Expiration::AtHeight(100000)) + .build(); +} + #[test] #[should_panic] fn test_instantiate_validates_covenant_config_router_a_addr() { From 189907ade9300e5db70f87967a7adcc546c1086c Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 15 Mar 2024 13:52:54 +0100 Subject: [PATCH 09/56] two party holder party host_addr and contribution amount validation --- contracts/two-party-pol-holder/src/error.rs | 3 ++ contracts/two-party-pol-holder/src/msg.rs | 16 ++++++++-- .../src/test_two_party_pol_holder/tests.rs | 32 +++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/contracts/two-party-pol-holder/src/error.rs b/contracts/two-party-pol-holder/src/error.rs index 8d1cc090..4c6f6de8 100644 --- a/contracts/two-party-pol-holder/src/error.rs +++ b/contracts/two-party-pol-holder/src/error.rs @@ -74,4 +74,7 @@ pub enum ContractError { #[error("Claimer already claimed his share")] PartyAllocationIsZero {}, + + #[error("Party contribution cannot be zero")] + PartyContributionConfigError {}, } diff --git a/contracts/two-party-pol-holder/src/msg.rs b/contracts/two-party-pol-holder/src/msg.rs index 23d73528..1a8aeb37 100644 --- a/contracts/two-party-pol-holder/src/msg.rs +++ b/contracts/two-party-pol-holder/src/msg.rs @@ -276,9 +276,19 @@ impl TwoPartyPolCovenantConfig { pub fn validate(&self, api: &dyn Api) -> Result<(), ContractError> { api.addr_validate(&self.party_a.router)?; api.addr_validate(&self.party_b.router)?; - if self.party_a.allocation + self.party_b.allocation != Decimal::one() { - return Err(ContractError::AllocationValidationError {}); - } + api.addr_validate(&self.party_a.host_addr)?; + api.addr_validate(&self.party_b.host_addr)?; + + ensure!( + !self.party_a.contribution.amount.is_zero() && !self.party_b.contribution.amount.is_zero(), + ContractError::PartyContributionConfigError {} + ); + + ensure!( + self.party_a.allocation + self.party_b.allocation == Decimal::one(), + ContractError::AllocationValidationError {} + ); + Ok(()) } diff --git a/unit-tests/src/test_two_party_pol_holder/tests.rs b/unit-tests/src/test_two_party_pol_holder/tests.rs index 771ccc69..c359903e 100644 --- a/unit-tests/src/test_two_party_pol_holder/tests.rs +++ b/unit-tests/src/test_two_party_pol_holder/tests.rs @@ -53,6 +53,38 @@ fn test_instantiate_validates_lockup_config() { .build(); } +#[test] +#[should_panic(expected = "Party contribution cannot be zero")] +fn test_instantiate_validates_party_a_contribution_amount() { + let mut builder = TwoPartyHolderBuilder::default(); + builder.instantiate_msg.msg.covenant_config.party_a.contribution.amount = Uint128::zero(); + builder.build(); +} + +#[test] +#[should_panic(expected = "Party contribution cannot be zero")] +fn test_instantiate_validates_party_b_contribution_amount() { + let mut builder = TwoPartyHolderBuilder::default(); + builder.instantiate_msg.msg.covenant_config.party_b.contribution.amount = Uint128::zero(); + builder.build(); +} + +#[test] +#[should_panic] +fn test_instantiate_validates_party_a_host_addr() { + let mut builder = TwoPartyHolderBuilder::default(); + builder.instantiate_msg.msg.covenant_config.party_a.host_addr = "invalid".to_string(); + builder.build(); +} + +#[test] +#[should_panic] +fn test_instantiate_validates_party_b_host_addr() { + let mut builder = TwoPartyHolderBuilder::default(); + builder.instantiate_msg.msg.covenant_config.party_b.host_addr = "invalid".to_string(); + builder.build(); +} + #[test] #[should_panic(expected = "cannot validate deposit and lockup expirations")] fn test_instantiate_validates_incompatible_deposit_and_lockup_expirations() { From d1bff06beb786d1ecb62dd3a43b5a8d246720506 Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 15 Mar 2024 14:14:27 +0100 Subject: [PATCH 10/56] interchain router clock and destination receiver address validation --- contracts/interchain-router/src/contract.rs | 9 ++++++--- contracts/interchain-router/src/msg.rs | 2 +- .../interchain-router/src/suite_tests/suite.rs | 5 +++-- .../single-party-pol-covenant/src/contract.rs | 2 +- contracts/swap-covenant/src/msg.rs | 2 +- contracts/two-party-pol-covenant/src/msg.rs | 2 +- .../setup/instantiates/interchain_router.rs | 4 ++-- unit-tests/src/test_interchain_router/suite.rs | 2 +- unit-tests/src/test_interchain_router/tests.rs | 18 ++++++++++++++++-- 9 files changed, 32 insertions(+), 14 deletions(-) diff --git a/contracts/interchain-router/src/contract.rs b/contracts/interchain-router/src/contract.rs index cb9acb78..5845a058 100644 --- a/contracts/interchain-router/src/contract.rs +++ b/contracts/interchain-router/src/contract.rs @@ -34,15 +34,18 @@ pub fn instantiate( ) -> NeutronResult> { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - CLOCK_ADDRESS.save(deps.storage, &msg.clock_address)?; + let clock_address = deps.api.addr_validate(&msg.clock_address)?; + deps.api.addr_validate(&msg.destination_config.destination_receiver_addr)?; + + CLOCK_ADDRESS.save(deps.storage, &clock_address)?; DESTINATION_CONFIG.save(deps.storage, &msg.destination_config)?; TARGET_DENOMS.save(deps.storage, &msg.denoms)?; Ok(Response::default() .add_message(enqueue_msg(msg.clock_address.as_str())?) .add_attribute("method", "interchain_router_instantiate") - .add_attribute("clock_address", msg.clock_address.to_string())) - // .add_attributes(destination_config.get_response_attributes())) + .add_attribute("clock_address", clock_address.to_string()) + .add_attributes(msg.destination_config.get_response_attributes())) } #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/interchain-router/src/msg.rs b/contracts/interchain-router/src/msg.rs index b9326a85..f090940b 100644 --- a/contracts/interchain-router/src/msg.rs +++ b/contracts/interchain-router/src/msg.rs @@ -9,7 +9,7 @@ use covenant_utils::{instantiate2_helper::Instantiate2HelperConfig, DestinationC pub struct InstantiateMsg { /// address for the clock. this contract verifies /// that only the clock can execute ticks - pub clock_address: Addr, + pub clock_address: String, /// config that determines how to facilitate the ibc routing pub destination_config: DestinationConfig, /// specified denoms to route diff --git a/contracts/interchain-router/src/suite_tests/suite.rs b/contracts/interchain-router/src/suite_tests/suite.rs index 9df40549..a7ccd2e5 100644 --- a/contracts/interchain-router/src/suite_tests/suite.rs +++ b/contracts/interchain-router/src/suite_tests/suite.rs @@ -57,7 +57,7 @@ impl Default for SuiteBuilder { fn default() -> Self { Self { instantiate: InstantiateMsg { - clock_address: Addr::unchecked(CLOCK_ADDR.to_string()), + clock_address: CLOCK_ADDR.to_string(), destination_config: DestinationConfig { local_to_destination_chain_channel_id: DEFAULT_CHANNEL.to_string(), destination_receiver_addr: DEFAULT_RECEIVER.to_string(), @@ -99,7 +99,8 @@ impl SuiteBuilder { "clock", Some(ADMIN.to_string()), ) - .unwrap(); + .unwrap() + .to_string(); let router = app .instantiate_contract( diff --git a/contracts/single-party-pol-covenant/src/contract.rs b/contracts/single-party-pol-covenant/src/contract.rs index 245dda30..9568c554 100644 --- a/contracts/single-party-pol-covenant/src/contract.rs +++ b/contracts/single-party-pol-covenant/src/contract.rs @@ -108,7 +108,7 @@ pub fn instantiate( denoms.insert(msg.covenant_party_config.native_denom.to_string()); let router_instantiate2_msg = RouterInstantiateMsg { - clock_address: clock_instantiate2_config.addr.clone(), + clock_address: clock_instantiate2_config.addr.to_string(), destination_config: DestinationConfig { local_to_destination_chain_channel_id: msg .covenant_party_config diff --git a/contracts/swap-covenant/src/msg.rs b/contracts/swap-covenant/src/msg.rs index 1bbff93d..91bda66d 100644 --- a/contracts/swap-covenant/src/msg.rs +++ b/contracts/swap-covenant/src/msg.rs @@ -102,7 +102,7 @@ impl CovenantPartyConfig { denom_to_pfm_map: party.denom_to_pfm_map.clone(), }; let instantiate_msg = covenant_interchain_router::msg::InstantiateMsg { - clock_address: clock_addr, + clock_address: clock_addr.to_string(), destination_config, denoms: covenant_denoms, }; diff --git a/contracts/two-party-pol-covenant/src/msg.rs b/contracts/two-party-pol-covenant/src/msg.rs index c78f1203..f43b2afd 100644 --- a/contracts/two-party-pol-covenant/src/msg.rs +++ b/contracts/two-party-pol-covenant/src/msg.rs @@ -161,7 +161,7 @@ impl CovenantPartyConfig { match self { CovenantPartyConfig::Interchain(party) => { let instantiate_msg = covenant_interchain_router::msg::InstantiateMsg { - clock_address: clock_addr, + clock_address: clock_addr.to_string(), destination_config: DestinationConfig { local_to_destination_chain_channel_id: party .host_to_party_chain_channel_id diff --git a/unit-tests/src/setup/instantiates/interchain_router.rs b/unit-tests/src/setup/instantiates/interchain_router.rs index 7e424fd6..1f2b4716 100644 --- a/unit-tests/src/setup/instantiates/interchain_router.rs +++ b/unit-tests/src/setup/instantiates/interchain_router.rs @@ -23,14 +23,14 @@ impl InterchainRouterInstantiate { ) -> Self { Self { msg: covenant_interchain_router::msg::InstantiateMsg { - clock_address, + clock_address: clock_address.to_string(), destination_config, denoms, }, } } - pub fn with_clock_address(&mut self, addr: Addr) -> &mut Self { + pub fn with_clock_address(&mut self, addr: String) -> &mut Self { self.msg.clock_address = addr; self } diff --git a/unit-tests/src/test_interchain_router/suite.rs b/unit-tests/src/test_interchain_router/suite.rs index 7d1911c3..892d1aa3 100644 --- a/unit-tests/src/test_interchain_router/suite.rs +++ b/unit-tests/src/test_interchain_router/suite.rs @@ -46,7 +46,7 @@ impl Default for InterchainRouterBuilder { #[allow(dead_code)] impl InterchainRouterBuilder { - pub fn with_clock_address(mut self, clock_address: Addr) -> Self { + pub fn with_clock_address(mut self, clock_address: String) -> Self { self.instantiate_msg.with_clock_address(clock_address); self } diff --git a/unit-tests/src/test_interchain_router/tests.rs b/unit-tests/src/test_interchain_router/tests.rs index 3ffea8f7..72348553 100644 --- a/unit-tests/src/test_interchain_router/tests.rs +++ b/unit-tests/src/test_interchain_router/tests.rs @@ -1,6 +1,20 @@ use super::suite::InterchainRouterBuilder; #[test] -fn test_covenant() { - let _suite = InterchainRouterBuilder::default().build(); +#[should_panic] +fn test_instantiate_validates_clock_address() { + InterchainRouterBuilder::default() + .with_clock_address("invalid_clock".to_string()) + .build(); +} + +#[test] +#[should_panic] +fn test_instantiate_validates_destination_receiver_addr() { + let mut builder = InterchainRouterBuilder::default(); + builder.instantiate_msg + .msg + .destination_config + .destination_receiver_addr = "invalid_receiver".to_string(); + builder.build(); } From 5e102d63f2cd0c0570e85146e0737ed06884a4f4 Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 15 Mar 2024 14:22:15 +0100 Subject: [PATCH 11/56] native splitter validates clock address on instantiation --- contracts/native-splitter/src/contract.rs | 8 ++++++-- contracts/native-splitter/src/msg.rs | 2 +- contracts/swap-covenant/src/contract.rs | 2 +- unit-tests/src/setup/instantiates/native_splitter.rs | 6 +++--- unit-tests/src/test_native_splitter/suite.rs | 5 ++--- unit-tests/src/test_native_splitter/tests.rs | 8 ++++++++ unit-tests/src/test_swap_holder/suite.rs | 2 +- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/contracts/native-splitter/src/contract.rs b/contracts/native-splitter/src/contract.rs index e1eca85a..f26465f0 100644 --- a/contracts/native-splitter/src/contract.rs +++ b/contracts/native-splitter/src/contract.rs @@ -29,7 +29,8 @@ pub fn instantiate( let mut resp = Response::default().add_attribute("method", "native_splitter_instantiate"); - CLOCK_ADDRESS.save(deps.storage, &msg.clock_address)?; + let clock_address = deps.api.addr_validate(&msg.clock_address)?; + CLOCK_ADDRESS.save(deps.storage, &clock_address)?; resp = resp.add_attribute("clock_addr", msg.clock_address.to_string()); // we validate the splits and store them per-denom @@ -46,7 +47,10 @@ pub fn instantiate( resp = resp.add_attribute("fallback", "None"); } - Ok(resp.add_message(enqueue_msg(msg.clock_address.as_str())?)) + Ok(resp + .add_message(enqueue_msg(msg.clock_address.as_str())?) + .add_attribute("clock_address", clock_address) + ) } #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/native-splitter/src/msg.rs b/contracts/native-splitter/src/msg.rs index 928e4172..07601e99 100644 --- a/contracts/native-splitter/src/msg.rs +++ b/contracts/native-splitter/src/msg.rs @@ -8,7 +8,7 @@ use covenant_utils::{instantiate2_helper::Instantiate2HelperConfig, split::Split #[cw_serde] pub struct InstantiateMsg { /// address of the associated clock - pub clock_address: Addr, + pub clock_address: String, /// maps denom to its split configuration pub splits: BTreeMap, /// a split for all denoms that are not covered in the diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index 012b917e..97ccbadf 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -122,7 +122,7 @@ pub fn instantiate( )?; let splitter_instantiate2_msg = covenant_native_splitter::msg::InstantiateMsg { - clock_address: clock_instantiate2_config.addr.clone(), + clock_address: clock_instantiate2_config.addr.to_string(), splits: remap_splits( msg.splits.clone(), ( diff --git a/unit-tests/src/setup/instantiates/native_splitter.rs b/unit-tests/src/setup/instantiates/native_splitter.rs index 37c63c49..1d504610 100644 --- a/unit-tests/src/setup/instantiates/native_splitter.rs +++ b/unit-tests/src/setup/instantiates/native_splitter.rs @@ -17,7 +17,7 @@ impl From for covenant_native_splitter::msg::Instanti impl NativeSplitterInstantiate { pub fn new( - clock_address: Addr, + clock_address: String, splits: BTreeMap, fallback_split: Option, ) -> Self { @@ -30,7 +30,7 @@ impl NativeSplitterInstantiate { } } - pub fn with_clock_address(&mut self, addr: Addr) -> &mut Self { + pub fn with_clock_address(&mut self, addr: String) -> &mut Self { self.msg.clock_address = addr; self } @@ -47,7 +47,7 @@ impl NativeSplitterInstantiate { } impl NativeSplitterInstantiate { - pub fn default(clock_address: Addr, party_a_addr: String, party_b_addr: String) -> Self { + pub fn default(clock_address: String, party_a_addr: String, party_b_addr: String) -> Self { let mut splits = BTreeMap::new(); splits.insert(party_a_addr, Decimal::from_str("0.5").unwrap()); splits.insert(party_b_addr, Decimal::from_str("0.5").unwrap()); diff --git a/unit-tests/src/test_native_splitter/suite.rs b/unit-tests/src/test_native_splitter/suite.rs index ed80ade0..19e2b2a4 100644 --- a/unit-tests/src/test_native_splitter/suite.rs +++ b/unit-tests/src/test_native_splitter/suite.rs @@ -23,7 +23,6 @@ impl Default for NativeSplitterBuilder { let clock_addr = builder.get_contract_addr(builder.clock_code_id, CLOCK_SALT); let native_splitter_addr = builder.get_contract_addr(builder.native_splitter_code_id, NATIVE_SPLITTER_SALT); - println!("code {:?}", builder.native_splitter_code_id); let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { tick_max_gas: None, @@ -40,7 +39,7 @@ impl Default for NativeSplitterBuilder { let party_b_controller_addr = builder.get_random_addr(); let native_splitter_instantiate = NativeSplitterInstantiate::default( - clock_addr, + clock_addr.to_string(), party_a_controller_addr.to_string(), party_b_controller_addr.to_string(), ); @@ -54,7 +53,7 @@ impl Default for NativeSplitterBuilder { #[allow(dead_code)] impl NativeSplitterBuilder { - pub fn with_clock_address(mut self, addr: Addr) -> Self { + pub fn with_clock_address(mut self, addr: String) -> Self { self.instantiate_msg.with_clock_address(addr); self } diff --git a/unit-tests/src/test_native_splitter/tests.rs b/unit-tests/src/test_native_splitter/tests.rs index 1fa19605..8f8e62ea 100644 --- a/unit-tests/src/test_native_splitter/tests.rs +++ b/unit-tests/src/test_native_splitter/tests.rs @@ -31,6 +31,14 @@ fn test_instantiate_validates_explicit_splits() { .build(); } +#[test] +#[should_panic] +fn test_instantiate_validates_clock_address() { + NativeSplitterBuilder::default() + .with_clock_address("invalid_clock".to_string()) + .build(); +} + #[test] fn test_instantiate_validates_fallback_split() { let _suite = NativeSplitterBuilder::default().build(); diff --git a/unit-tests/src/test_swap_holder/suite.rs b/unit-tests/src/test_swap_holder/suite.rs index e8d71794..c1e6ac67 100644 --- a/unit-tests/src/test_swap_holder/suite.rs +++ b/unit-tests/src/test_swap_holder/suite.rs @@ -53,7 +53,7 @@ impl Default for SwapHolderBuilder { denom_to_split_config_map.insert(DENOM_LS_ATOM_ON_NTRN.to_string(), split_config.clone()); let native_splitter_instantiate_msg = covenant_native_splitter::msg::InstantiateMsg { - clock_address: clock_addr.clone(), + clock_address: clock_addr.to_string(), splits: denom_to_split_config_map, fallback_split: None, }; From 545c83e005fee3f2ba97857446849465257b0733 Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 15 Mar 2024 14:54:46 +0100 Subject: [PATCH 12/56] swap holder party address validation; native receiver config returns string address to be validated on destination contracts --- .../single-party-pol-covenant/src/msg.rs | 23 +++++++++---------- .../single-party-pol-holder/src/contract.rs | 2 +- contracts/swap-covenant/src/contract.rs | 4 ++-- contracts/swap-covenant/src/msg.rs | 23 +++++++++---------- contracts/swap-holder/src/contract.rs | 2 +- .../swap-holder/src/suite_tests/suite.rs | 8 ++----- .../swap-holder/src/suite_tests/tests.rs | 4 ++-- contracts/two-party-pol-covenant/src/msg.rs | 23 +++++++++---------- .../two-party-pol-holder/src/contract.rs | 3 +-- packages/covenant-utils/src/lib.rs | 20 +++++++++++++--- .../src/setup/instantiates/swap_holder.rs | 4 ++-- 11 files changed, 61 insertions(+), 55 deletions(-) diff --git a/contracts/single-party-pol-covenant/src/msg.rs b/contracts/single-party-pol-covenant/src/msg.rs index 3fffe22f..b5a833c3 100644 --- a/contracts/single-party-pol-covenant/src/msg.rs +++ b/contracts/single-party-pol-covenant/src/msg.rs @@ -92,19 +92,18 @@ pub struct LsInfo { } impl CovenantPartyConfig { - pub fn to_receiver_config(&self, deps: Deps) -> StdResult { + pub fn to_receiver_config(&self) -> ReceiverConfig { match self { - CovenantPartyConfig::Interchain(config) => Ok(ReceiverConfig::Ibc(DestinationConfig { + CovenantPartyConfig::Interchain(config) => ReceiverConfig::Ibc(DestinationConfig { local_to_destination_chain_channel_id: config .host_to_party_chain_channel_id .to_string(), destination_receiver_addr: config.party_receiver_addr.to_string(), ibc_transfer_timeout: config.ibc_transfer_timeout, denom_to_pfm_map: BTreeMap::new(), - })), + }), CovenantPartyConfig::Native(config) => { - let addr = deps.api.addr_validate(&config.party_receiver_addr)?; - Ok(ReceiverConfig::Native(addr)) + ReceiverConfig::Native(config.party_receiver_addr.to_string()) } } } @@ -116,18 +115,18 @@ impl CovenantPartyConfig { } } - pub fn to_covenant_party(&self, deps: Deps) -> StdResult { + pub fn to_covenant_party(&self) -> CovenantParty { match self { - CovenantPartyConfig::Interchain(config) => Ok(CovenantParty { + CovenantPartyConfig::Interchain(config) => CovenantParty { addr: config.addr.to_string(), native_denom: config.native_denom.to_string(), - receiver_config: self.to_receiver_config(deps)?, - }), - CovenantPartyConfig::Native(config) => Ok(CovenantParty { + receiver_config: self.to_receiver_config(), + }, + CovenantPartyConfig::Native(config) => CovenantParty { addr: config.addr.to_string(), native_denom: config.native_denom.to_string(), - receiver_config: self.to_receiver_config(deps)?, - }), + receiver_config: self.to_receiver_config(), + }, } } diff --git a/contracts/single-party-pol-holder/src/contract.rs b/contracts/single-party-pol-holder/src/contract.rs index 6f1b2e14..c1846c4c 100644 --- a/contracts/single-party-pol-holder/src/contract.rs +++ b/contracts/single-party-pol-holder/src/contract.rs @@ -23,7 +23,7 @@ pub fn instantiate( set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; deps.api.debug("WASMDEBUG: holder instantiate"); let mut resp = Response::default().add_attribute("method", "instantiate"); - + // withdrawer is optional on instantiation; can be set later if let Some(addr) = msg.withdrawer { WITHDRAWER.save(deps.storage, &deps.api.addr_validate(&addr)?)?; diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index 97ccbadf..3c4663e3 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -153,8 +153,8 @@ pub fn instantiate( let holder_instantiate2_msg = covenant_swap_holder::msg::InstantiateMsg { lockup_config: msg.lockup_config, parties_config: CovenantPartiesConfig { - party_a: msg.party_a_config.to_covenant_party(deps.as_ref())?, - party_b: msg.party_b_config.to_covenant_party(deps.as_ref())?, + party_a: msg.party_a_config.to_covenant_party(), + party_b: msg.party_b_config.to_covenant_party(), }, covenant_terms: CovenantTerms::TokenSwap(SwapCovenantTerms { party_a_amount: msg.party_a_config.get_contribution().amount, diff --git a/contracts/swap-covenant/src/msg.rs b/contracts/swap-covenant/src/msg.rs index 91bda66d..ab0b352e 100644 --- a/contracts/swap-covenant/src/msg.rs +++ b/contracts/swap-covenant/src/msg.rs @@ -30,19 +30,18 @@ pub enum CovenantPartyConfig { } impl CovenantPartyConfig { - pub fn to_receiver_config(&self, deps: Deps) -> StdResult { + pub fn to_receiver_config(&self) -> ReceiverConfig { match self { - CovenantPartyConfig::Interchain(config) => Ok(ReceiverConfig::Ibc(DestinationConfig { + CovenantPartyConfig::Interchain(config) => ReceiverConfig::Ibc(DestinationConfig { local_to_destination_chain_channel_id: config .host_to_party_chain_channel_id .to_string(), destination_receiver_addr: config.party_receiver_addr.to_string(), ibc_transfer_timeout: config.ibc_transfer_timeout, denom_to_pfm_map: config.denom_to_pfm_map.clone(), - })), + }), CovenantPartyConfig::Native(config) => { - let addr = deps.api.addr_validate(&config.party_receiver_addr)?; - Ok(ReceiverConfig::Native(addr)) + ReceiverConfig::Native(config.party_receiver_addr.to_string()) } } } @@ -54,18 +53,18 @@ impl CovenantPartyConfig { } } - pub fn to_covenant_party(&self, deps: Deps) -> StdResult { + pub fn to_covenant_party(&self) -> CovenantParty { match self { - CovenantPartyConfig::Interchain(config) => Ok(CovenantParty { + CovenantPartyConfig::Interchain(config) => CovenantParty { addr: config.addr.to_string(), native_denom: config.native_denom.to_string(), - receiver_config: self.to_receiver_config(deps)?, - }), - CovenantPartyConfig::Native(config) => Ok(CovenantParty { + receiver_config: self.to_receiver_config(), + }, + CovenantPartyConfig::Native(config) => CovenantParty { addr: config.addr.to_string(), native_denom: config.native_denom.to_string(), - receiver_config: self.to_receiver_config(deps)?, - }), + receiver_config: self.to_receiver_config(), + }, } } diff --git a/contracts/swap-holder/src/contract.rs b/contracts/swap-holder/src/contract.rs index 5de3100e..22ec0ddf 100644 --- a/contracts/swap-holder/src/contract.rs +++ b/contracts/swap-holder/src/contract.rs @@ -30,7 +30,7 @@ pub fn instantiate( let next_contract = deps.api.addr_validate(&msg.next_contract)?; let clock_addr = deps.api.addr_validate(&msg.clock_address)?; - + msg.parties_config.validate_party_addresses(deps.api)?; if msg.lockup_config.is_expired(&env.block) { return Err(ContractError::Std(StdError::generic_err( "past lockup config", diff --git a/contracts/swap-holder/src/suite_tests/suite.rs b/contracts/swap-holder/src/suite_tests/suite.rs index 2941842c..d677c663 100644 --- a/contracts/swap-holder/src/suite_tests/suite.rs +++ b/contracts/swap-holder/src/suite_tests/suite.rs @@ -50,16 +50,12 @@ impl Default for SuiteBuilder { parties_config: CovenantPartiesConfig { party_a: CovenantParty { addr: PARTY_A_ADDR.to_string(), - receiver_config: ReceiverConfig::Native(Addr::unchecked( - PARTY_A_ADDR.to_string(), - )), + receiver_config: ReceiverConfig::Native(PARTY_A_ADDR.to_string()), native_denom: DENOM_A.to_string(), }, party_b: CovenantParty { addr: PARTY_B_ADDR.to_string(), - receiver_config: ReceiverConfig::Native(Addr::unchecked( - PARTY_B_ADDR.to_string(), - )), + receiver_config: ReceiverConfig::Native(PARTY_B_ADDR.to_string()), native_denom: DENOM_B.to_string(), }, }, diff --git a/contracts/swap-holder/src/suite_tests/tests.rs b/contracts/swap-holder/src/suite_tests/tests.rs index da95c402..823e81ac 100644 --- a/contracts/swap-holder/src/suite_tests/tests.rs +++ b/contracts/swap-holder/src/suite_tests/tests.rs @@ -32,12 +32,12 @@ fn test_instantiate_happy_and_query_all() { party_a: CovenantParty { addr: PARTY_A_ADDR.to_string(), native_denom: DENOM_A.to_string(), - receiver_config: ReceiverConfig::Native(Addr::unchecked(PARTY_A_ADDR.to_string())), + receiver_config: ReceiverConfig::Native(PARTY_A_ADDR.to_string()), }, party_b: CovenantParty { native_denom: DENOM_B.to_string(), addr: PARTY_B_ADDR.to_string(), - receiver_config: ReceiverConfig::Native(Addr::unchecked(PARTY_B_ADDR.to_string())), + receiver_config: ReceiverConfig::Native(PARTY_B_ADDR.to_string()), }, } ); diff --git a/contracts/two-party-pol-covenant/src/msg.rs b/contracts/two-party-pol-covenant/src/msg.rs index f43b2afd..a31c4ae1 100644 --- a/contracts/two-party-pol-covenant/src/msg.rs +++ b/contracts/two-party-pol-covenant/src/msg.rs @@ -71,19 +71,18 @@ impl LiquidPoolerConfig { } impl CovenantPartyConfig { - pub fn to_receiver_config(&self, deps: Deps) -> StdResult { + pub fn to_receiver_config(&self) -> ReceiverConfig { match self { - CovenantPartyConfig::Interchain(config) => Ok(ReceiverConfig::Ibc(DestinationConfig { + CovenantPartyConfig::Interchain(config) => ReceiverConfig::Ibc(DestinationConfig { local_to_destination_chain_channel_id: config .host_to_party_chain_channel_id .to_string(), destination_receiver_addr: config.party_receiver_addr.to_string(), ibc_transfer_timeout: config.ibc_transfer_timeout, denom_to_pfm_map: config.denom_to_pfm_map.clone(), - })), + }), CovenantPartyConfig::Native(config) => { - let addr = deps.api.addr_validate(&config.party_receiver_addr)?; - Ok(ReceiverConfig::Native(addr)) + ReceiverConfig::Native(config.party_receiver_addr.to_string()) } } } @@ -95,18 +94,18 @@ impl CovenantPartyConfig { } } - pub fn to_covenant_party(&self, deps: Deps) -> StdResult { + pub fn to_covenant_party(&self) -> CovenantParty { match self { - CovenantPartyConfig::Interchain(config) => Ok(CovenantParty { + CovenantPartyConfig::Interchain(config) => CovenantParty { addr: config.addr.to_string(), native_denom: config.native_denom.to_string(), - receiver_config: self.to_receiver_config(deps)?, - }), - CovenantPartyConfig::Native(config) => Ok(CovenantParty { + receiver_config: self.to_receiver_config(), + }, + CovenantPartyConfig::Native(config) => CovenantParty { addr: config.addr.to_string(), native_denom: config.native_denom.to_string(), - receiver_config: self.to_receiver_config(deps)?, - }), + receiver_config: self.to_receiver_config(), + }, } } diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index bcb17ad9..7202cc23 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -2,7 +2,7 @@ use std::cmp::Ordering; use std::collections::BTreeMap; use cosmwasm_std::{ - ensure, to_json_binary, BankMsg, Binary, BlockInfo, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult + ensure, to_json_binary, BankMsg, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult }; #[cfg(not(feature = "library"))] @@ -12,7 +12,6 @@ use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::split::SplitConfig; use covenant_utils::withdraw_lp_helper::{generate_withdraw_msg, EMERGENCY_COMMITTEE_ADDR}; use cw2::set_contract_version; -use cw_utils::Expiration; use crate::msg::CovenantType; use crate::state::{WithdrawState, LIQUID_POOLER_ADDRESS, WITHDRAW_STATE}; diff --git a/packages/covenant-utils/src/lib.rs b/packages/covenant-utils/src/lib.rs index 0c7a2a31..ac7346cc 100644 --- a/packages/covenant-utils/src/lib.rs +++ b/packages/covenant-utils/src/lib.rs @@ -2,8 +2,7 @@ use std::collections::BTreeMap; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - to_json_string, Addr, Attribute, BankMsg, BlockInfo, Coin, CosmosMsg, Decimal, IbcMsg, - IbcTimeout, StdError, StdResult, Timestamp, Uint128, Uint64, + to_json_string, Addr, Api, Attribute, BankMsg, BlockInfo, Coin, CosmosMsg, Decimal, IbcMsg, IbcTimeout, StdError, StdResult, Timestamp, Uint128, Uint64 }; use neutron_sdk::{bindings::msg::{IbcFee, NeutronMsg}, sudo::msg::RequestPacketTimeoutHeight}; @@ -55,7 +54,7 @@ pub struct NativeCovenantParty { #[cw_serde] pub enum ReceiverConfig { /// party expects to receive funds on the same chain - Native(Addr), + Native(String), /// party expects to receive funds on a remote chain Ibc(DestinationConfig), } @@ -113,6 +112,15 @@ impl CovenantParty { }), } } + + pub fn validate_addresses(&self, api: &dyn Api) -> StdResult { + match &self.receiver_config { + ReceiverConfig::Native(addr) => api.addr_validate(&addr), + ReceiverConfig::Ibc(destination_config) => { + api.addr_validate(&destination_config.destination_receiver_addr) + }, + } + } } #[cw_serde] @@ -153,6 +161,12 @@ impl CovenantPartiesConfig { Err(StdError::generic_err("unauthorized")) } } + + pub fn validate_party_addresses(&self, api: &dyn Api) -> StdResult<()> { + self.party_a.validate_addresses(api)?; + self.party_b.validate_addresses(api)?; + Ok(()) + } } #[cw_serde] diff --git a/unit-tests/src/setup/instantiates/swap_holder.rs b/unit-tests/src/setup/instantiates/swap_holder.rs index 1a4ff0a4..949cced2 100644 --- a/unit-tests/src/setup/instantiates/swap_holder.rs +++ b/unit-tests/src/setup/instantiates/swap_holder.rs @@ -79,12 +79,12 @@ impl SwapHolderInstantiate { party_a: CovenantParty { addr: party_a_addr.to_string(), native_denom: DENOM_ATOM_ON_NTRN.to_string(), - receiver_config: ReceiverConfig::Native(party_a_addr), + receiver_config: ReceiverConfig::Native(party_a_addr.to_string()), }, party_b: CovenantParty { addr: party_b_addr.to_string(), native_denom: DENOM_LS_ATOM_ON_NTRN.to_string(), - receiver_config: ReceiverConfig::Native(party_b_addr), + receiver_config: ReceiverConfig::Native(party_b_addr.to_string()), }, }, }, From de1c3cbf30aa3c45bc96170dc3ea138eb0da9ee8 Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 15 Mar 2024 15:14:04 +0100 Subject: [PATCH 13/56] astroport liquid pooler validates withdraw percentage range --- .../astroport-liquid-pooler/src/contract.rs | 6 ++- .../astroport-liquid-pooler/src/error.rs | 3 ++ .../src/test_astroport_liquid_pooler/suite.rs | 6 +-- .../src/test_astroport_liquid_pooler/tests.rs | 47 ++++++++++++++++--- 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/contracts/astroport-liquid-pooler/src/contract.rs b/contracts/astroport-liquid-pooler/src/contract.rs index de125df1..d30c7237 100644 --- a/contracts/astroport-liquid-pooler/src/contract.rs +++ b/contracts/astroport-liquid-pooler/src/contract.rs @@ -109,7 +109,11 @@ fn try_withdraw( percent: Option, ) -> Result { let percent = percent.unwrap_or(Decimal::one()); - // Verify percentage is < 1 and > 0 + ensure!( + percent > Decimal::zero() && percent <= Decimal::one(), + ContractError::WithdrawPercentageRangeError {} + ); + let holder_addr = HOLDER_ADDRESS .load(deps.storage) .map_err(|_| ContractError::MissingHolderError {})?; diff --git a/contracts/astroport-liquid-pooler/src/error.rs b/contracts/astroport-liquid-pooler/src/error.rs index 42c3ffc4..67f10f19 100644 --- a/contracts/astroport-liquid-pooler/src/error.rs +++ b/contracts/astroport-liquid-pooler/src/error.rs @@ -51,4 +51,7 @@ pub enum ContractError { #[error("no covenant denom or lp tokens available")] NothingToWithdraw {}, + + #[error("Withdraw percentage range must belong to range (0.0, 1.0]")] + WithdrawPercentageRangeError {}, } diff --git a/unit-tests/src/test_astroport_liquid_pooler/suite.rs b/unit-tests/src/test_astroport_liquid_pooler/suite.rs index 38cbdb18..072f1c9e 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/suite.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/suite.rs @@ -2,7 +2,7 @@ use astroport::factory::PairType; use cosmwasm_std::{coin, Addr, Coin, Decimal}; use covenant_astroport_liquid_pooler::msg::{LpConfig, ProvidedLiquidityInfo, QueryMsg}; use covenant_utils::{PoolPriceConfig, SingleSideLpLimits}; -use cw_multi_test::Executor; +use cw_multi_test::{AppResponse, Executor}; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -209,7 +209,7 @@ pub struct Suite { #[allow(dead_code)] impl Suite { - pub(crate) fn withdraw(&mut self, sender: &Addr, _percentage: Option) { + pub(crate) fn withdraw(&mut self, sender: &Addr, _percentage: Option) -> AppResponse { let holder = self.holder_addr.clone(); let app = self.get_app(); app.execute_contract( @@ -218,7 +218,7 @@ impl Suite { &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) - .unwrap(); + .unwrap() } pub(crate) fn query_provided_liquidity_info(&self) -> ProvidedLiquidityInfo { diff --git a/unit-tests/src/test_astroport_liquid_pooler/tests.rs b/unit-tests/src/test_astroport_liquid_pooler/tests.rs index 0ec4dda8..11a6e6a5 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/tests.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/tests.rs @@ -48,10 +48,9 @@ fn test_instantiate_validates_pool_price_config() { } #[test] -// TODO: uncomment this #[should_panic(expected = "Cannot Sub with 1000000 and 101000000")] -fn test_withdraw_percentage_range() { +#[should_panic(expected = "Withdraw percentage range must belong to range (0.0, 1.0]")] +fn test_withdraw_validates_percentage_range_ceiling() { let mut suite = AstroLiquidPoolerBuilder::default().build(); - let withdrawer = suite.clock_addr.clone(); suite.fund_contract( &coins(1_000_000, DENOM_ATOM_ON_NTRN), @@ -64,9 +63,45 @@ fn test_withdraw_percentage_range() { suite.tick_contract(suite.liquid_pooler_addr.clone()); - // TODO: this should fail because of a percent validation in try_withdraw - // that validates 0 < percent <= 1 - suite.withdraw(&withdrawer, Some(Decimal::from_str("101.0").unwrap())); + let holder = suite.holder_addr.clone(); + suite.app.execute_contract( + holder.clone(), + suite.liquid_pooler_addr.clone(), + &covenant_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { + percentage: Some(Decimal::from_str("101.0").unwrap()), + }, + &[], + ) + .unwrap(); +} + + +#[test] +#[should_panic(expected = "Withdraw percentage range must belong to range (0.0, 1.0]")] +fn test_withdraw_validates_percentage_range_floor() { + let mut suite = AstroLiquidPoolerBuilder::default().build(); + + suite.fund_contract( + &coins(1_000_000, DENOM_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + suite.fund_contract( + &coins(500_000, DENOM_LS_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + + suite.tick_contract(suite.liquid_pooler_addr.clone()); + + let holder = suite.holder_addr.clone(); + suite.app.execute_contract( + holder.clone(), + suite.liquid_pooler_addr.clone(), + &covenant_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { + percentage: Some(Decimal::from_str("0.0").unwrap()), + }, + &[], + ) + .unwrap(); } #[test] From 70206193075be0f97043c4af2bb80cedba77da13 Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 15 Mar 2024 15:19:25 +0100 Subject: [PATCH 14/56] single party holder validates lockup config --- contracts/single-party-pol-holder/src/contract.rs | 4 ++++ unit-tests/src/test_single_party_holder/tests.rs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/contracts/single-party-pol-holder/src/contract.rs b/contracts/single-party-pol-holder/src/contract.rs index c1846c4c..9c8a2789 100644 --- a/contracts/single-party-pol-holder/src/contract.rs +++ b/contracts/single-party-pol-holder/src/contract.rs @@ -40,6 +40,10 @@ pub fn instantiate( resp = resp.add_attribute("emergency_committee", addr); }; + ensure!( + !msg.lockup_period.is_expired(&_env.block), + ContractError::MustBeFutureLockupPeriod {} + ); LOCKUP_PERIOD.save(deps.storage, &msg.lockup_period)?; POOLER_ADDRESS.save(deps.storage, &deps.api.addr_validate(&msg.pooler_address)?)?; diff --git a/unit-tests/src/test_single_party_holder/tests.rs b/unit-tests/src/test_single_party_holder/tests.rs index 0ef27507..d1a8fcbc 100644 --- a/unit-tests/src/test_single_party_holder/tests.rs +++ b/unit-tests/src/test_single_party_holder/tests.rs @@ -38,6 +38,14 @@ fn test_instantiate_invalid_emergency_committee_addr() { .build(); } +#[test] +#[should_panic(expected = "The lockup period must be in the future")] +fn test_instantiate_validates_lockup_period() { + SinglePartyHolderBuilder::default() + .with_lockup_period(Expiration::AtHeight(1)) + .build(); +} + #[test] // #[should_panic(expected = "A withdraw process already started")] fn test_execute_claim_validates_pending_withdrawals() { From 91e77aa8f24035d00727ca81bb6dda9beaee7a7c Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 15 Mar 2024 18:03:29 +0100 Subject: [PATCH 15/56] validating split receiver addresses & shares in native and remote chain splitters --- contracts/native-splitter/src/contract.rs | 3 +- .../remote-chain-splitter/src/contract.rs | 4 +- packages/covenant-utils/src/split.rs | 7 ++- .../src/test_astroport_liquid_pooler/suite.rs | 18 +++++- .../src/test_astroport_liquid_pooler/tests.rs | 10 ++-- unit-tests/src/test_native_splitter/tests.rs | 55 +++++++++++++------ .../src/test_remote_chain_splitter/tests.rs | 17 +++++- .../src/test_single_party_holder/suite.rs | 9 +++ .../src/test_single_party_holder/tests.rs | 33 +++++------ 9 files changed, 104 insertions(+), 52 deletions(-) diff --git a/contracts/native-splitter/src/contract.rs b/contracts/native-splitter/src/contract.rs index f26465f0..21e9e08c 100644 --- a/contracts/native-splitter/src/contract.rs +++ b/contracts/native-splitter/src/contract.rs @@ -35,13 +35,14 @@ pub fn instantiate( // we validate the splits and store them per-denom for (denom, split) in msg.splits { - split.validate_shares()?; + split.validate_shares_and_receiver_addresses(deps.api)?; SPLIT_CONFIG_MAP.save(deps.storage, denom.to_string(), &split)?; } // if a fallback split is provided we validate and store it if let Some(split) = msg.fallback_split { resp = resp.add_attributes(vec![split.get_response_attribute("fallback".to_string())]); + split.validate_shares_and_receiver_addresses(deps.api)?; FALLBACK_SPLIT.save(deps.storage, &split)?; } else { resp = resp.add_attribute("fallback", "None"); diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index 8e32eaaa..4ba94bab 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -67,7 +67,7 @@ pub fn instantiate( let mut split_resp_attributes: Vec = Vec::with_capacity(msg.splits.len()); for (denom, split_config) in msg.splits { - split_config.validate_shares()?; + split_config.validate_shares_and_receiver_addresses(deps.api)?; split_resp_attributes.push(split_config.get_response_attribute(denom.to_string())); SPLIT_CONFIG_MAP.save(deps.storage, denom, &split_config)?; } @@ -369,7 +369,7 @@ pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult Result<(), StdError> { + pub fn validate_shares_and_receiver_addresses(&self, api: &dyn Api) -> Result<(), StdError> { let mut total_shares = Decimal::zero(); - for (_, share) in self.receivers.clone() { + for (addr, share) in self.receivers.clone() { + api.addr_validate(&addr)?; total_shares += share; } diff --git a/unit-tests/src/test_astroport_liquid_pooler/suite.rs b/unit-tests/src/test_astroport_liquid_pooler/suite.rs index 072f1c9e..475ba0dc 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/suite.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/suite.rs @@ -3,6 +3,7 @@ use cosmwasm_std::{coin, Addr, Coin, Decimal}; use covenant_astroport_liquid_pooler::msg::{LpConfig, ProvidedLiquidityInfo, QueryMsg}; use covenant_utils::{PoolPriceConfig, SingleSideLpLimits}; use cw_multi_test::{AppResponse, Executor}; +use cw_utils::Expiration; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -42,7 +43,7 @@ impl Default for AstroLiquidPoolerBuilder { withdraw_to: Some(holder_addr.to_string()), emergency_committee_addr: None, pooler_address: liquid_pooler_addr.to_string(), - lockup_period: cw_utils::Expiration::AtHeight(12365), + lockup_period: cw_utils::Expiration::AtHeight(123665), }; let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { @@ -221,6 +222,21 @@ impl Suite { .unwrap() } + pub(crate) fn expire_lockup(&mut self) { + let holder = self.holder_addr.clone(); + let expiration: Expiration = self.app.wrap().query_wasm_smart( + holder.to_string(), + &covenant_single_party_pol_holder::msg::QueryMsg::LockupConfig {}, + ) + .unwrap(); + let app = self.get_app(); + app.update_block(|b| match expiration { + Expiration::AtHeight(h) => b.height = h + 1, + Expiration::AtTime(t) => b.time = t, + Expiration::Never {} => (), + }) + } + pub(crate) fn query_provided_liquidity_info(&self) -> ProvidedLiquidityInfo { self.get_app() .wrap() diff --git a/unit-tests/src/test_astroport_liquid_pooler/tests.rs b/unit-tests/src/test_astroport_liquid_pooler/tests.rs index 11a6e6a5..ffeace26 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/tests.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/tests.rs @@ -62,8 +62,8 @@ fn test_withdraw_validates_percentage_range_ceiling() { ); suite.tick_contract(suite.liquid_pooler_addr.clone()); - - let holder = suite.holder_addr.clone(); + suite.expire_lockup(); + let holder: Addr = suite.holder_addr.clone(); suite.app.execute_contract( holder.clone(), suite.liquid_pooler_addr.clone(), @@ -126,7 +126,7 @@ fn test_withdraw_validates_holder() { fn test_withdraw_no_lp_or_covenant_denoms() { let mut suite = AstroLiquidPoolerBuilder::default().build(); let withdrawer = suite.clock_addr.clone(); - + suite.expire_lockup(); suite.withdraw(&withdrawer, None); } @@ -146,7 +146,7 @@ fn test_withdraw_no_lp_tokens_withdraws_covenant_assets() { suite.assert_balance(suite.holder_addr.clone(), coin(0, DENOM_ATOM_ON_NTRN)); suite.assert_balance(suite.holder_addr.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN)); - + suite.expire_lockup(); suite.withdraw(&withdrawer, None); suite.assert_balance(&suite.holder_addr.clone(), coin(500_000, DENOM_ATOM_ON_NTRN)); @@ -169,7 +169,7 @@ fn test_withdraw_no_percentage_defaults_to_full_position() { ); suite.tick_contract(suite.liquid_pooler_addr.clone()); - + suite.expire_lockup(); suite.withdraw(&withdrawer, None); suite.assert_balance(&holder, coin(500_000, DENOM_ATOM_ON_NTRN)); diff --git a/unit-tests/src/test_native_splitter/tests.rs b/unit-tests/src/test_native_splitter/tests.rs index 8f8e62ea..9d8f9e0c 100644 --- a/unit-tests/src/test_native_splitter/tests.rs +++ b/unit-tests/src/test_native_splitter/tests.rs @@ -13,22 +13,26 @@ use super::suite::NativeSplitterBuilder; #[test] #[should_panic(expected = "shares must add up to 1.0")] -fn test_instantiate_validates_explicit_splits() { - let mut split_config = BTreeMap::new(); - split_config.insert("a".to_string(), Decimal::percent(50)); - split_config.insert("b".to_string(), Decimal::percent(60)); - - let mut invalid_splits = BTreeMap::new(); - invalid_splits.insert( - DENOM_ATOM_ON_NTRN.to_string(), - SplitConfig { - receivers: split_config, - }, - ); +fn test_instantiate_validates_explicit_split_shares() { + let mut builder = NativeSplitterBuilder::default(); + let (denom, mut split_config) = builder.instantiate_msg.msg.splits.pop_first().unwrap(); + let invalid_split_config: BTreeMap = split_config.receivers.iter_mut() + .map(|(k, _)| (k.to_string(), Decimal::percent(49))) + .collect(); + builder.instantiate_msg.msg.splits.insert(denom, SplitConfig { receivers: invalid_split_config }); + builder.build(); +} - NativeSplitterBuilder::default() - .with_splits(invalid_splits) - .build(); +#[test] +#[should_panic] +fn test_instantiate_validates_explicit_split_receiver_addresses() { + let mut builder = NativeSplitterBuilder::default(); + let (denom, mut split_config) = builder.instantiate_msg.msg.splits.pop_first().unwrap(); + let invalid_split_config: BTreeMap = split_config.receivers.iter_mut() + .map(|(k, v)| (format!("invalid_{:?}", k), v.clone())) + .collect(); + builder.instantiate_msg.msg.splits.insert(denom, SplitConfig { receivers: invalid_split_config }); + builder.build(); } #[test] @@ -40,9 +44,24 @@ fn test_instantiate_validates_clock_address() { } #[test] -fn test_instantiate_validates_fallback_split() { - let _suite = NativeSplitterBuilder::default().build(); - // should validate +#[should_panic] +fn test_instantiate_validates_fallback_split_receiver_addresses() { + let mut invalid_split_config = BTreeMap::new(); + invalid_split_config.insert("invalid_address".to_string(), Decimal::one()); + NativeSplitterBuilder::default() + .with_fallback_split(Some(SplitConfig { receivers: invalid_split_config })) + .build(); +} + +#[test] +#[should_panic(expected = "shares must add up to 1.0")] +fn test_instantiate_validates_fallback_split_shares() { + let builder = NativeSplitterBuilder::default(); + let mut invalid_split_config = BTreeMap::new(); + invalid_split_config.insert(builder.instantiate_msg.msg.clock_address.to_string(), Decimal::percent(50)); + builder + .with_fallback_split(Some(SplitConfig { receivers: invalid_split_config })) + .build(); } #[test] diff --git a/unit-tests/src/test_remote_chain_splitter/tests.rs b/unit-tests/src/test_remote_chain_splitter/tests.rs index 0de1c9a2..47373db0 100644 --- a/unit-tests/src/test_remote_chain_splitter/tests.rs +++ b/unit-tests/src/test_remote_chain_splitter/tests.rs @@ -21,10 +21,21 @@ fn test_instantiate_validates_clock_address() { #[test] #[should_panic(expected = "shares must add up to 1.0")] -fn test_instantiate_validates_splits() { +fn test_instantiate_validates_explicit_split_shares() { + let mut builder = RemoteChainSplitterBuilder::default(); + let (denom, mut split_config) = builder.instantiate_msg.msg.splits.pop_first().unwrap(); + let invalid_split_config: BTreeMap = split_config.receivers.iter_mut() + .map(|(k, _)| (k.to_string(), Decimal::percent(49))) + .collect(); + builder.instantiate_msg.msg.splits.insert(denom, SplitConfig { receivers: invalid_split_config }); + builder.build(); +} + +#[test] +#[should_panic] +fn test_instantiate_validates_explicit_split_receiver_addresses() { let mut split_config = BTreeMap::new(); - split_config.insert("a".to_string(), Decimal::percent(50)); - split_config.insert("b".to_string(), Decimal::percent(60)); + split_config.insert("invalid_address".to_string(), Decimal::one()); let mut invalid_splits = BTreeMap::new(); invalid_splits.insert( diff --git a/unit-tests/src/test_single_party_holder/suite.rs b/unit-tests/src/test_single_party_holder/suite.rs index d38da437..693865d7 100644 --- a/unit-tests/src/test_single_party_holder/suite.rs +++ b/unit-tests/src/test_single_party_holder/suite.rs @@ -239,6 +239,15 @@ impl Suite { .unwrap() } + pub fn expire_lockup(&mut self) { + let expiration = self.query_lockup_period(); + self.app.update_block(|b| match expiration { + Expiration::AtHeight(h) => b.height = h + 1, + Expiration::AtTime(t) => b.time = t, + Expiration::Never {} => (), + }) + } + pub fn fund_contract_coins(&mut self, funds: Vec, addr: Addr) { self.fund_contract(&funds, addr) } diff --git a/unit-tests/src/test_single_party_holder/tests.rs b/unit-tests/src/test_single_party_holder/tests.rs index d1a8fcbc..dfbe7d68 100644 --- a/unit-tests/src/test_single_party_holder/tests.rs +++ b/unit-tests/src/test_single_party_holder/tests.rs @@ -67,22 +67,21 @@ fn test_execute_claim_validates_lockup_period() { #[should_panic(expected = "No withdrawer address configured")] fn test_execute_claim_validates_withdrawer_set() { let mut suite = SinglePartyHolderBuilder::default() - .with_lockup_period(cw_utils::Expiration::AtHeight(12312)) .with_withdrawer(None) .build(); let sender = suite.liquid_pooler_address.clone(); + suite.expire_lockup(); suite.execute_claim(sender); } #[test] #[should_panic(expected = "Unauthorized")] fn test_execute_claim_validates_withdrawer_addr() { - let mut suite = SinglePartyHolderBuilder::default() - .with_lockup_period(cw_utils::Expiration::AtHeight(12312)) - .build(); + let mut suite = SinglePartyHolderBuilder::default().build(); let sender = suite.faucet.clone(); + suite.expire_lockup(); suite.execute_claim(sender); } @@ -91,24 +90,24 @@ fn test_execute_claim_validates_withdrawer_addr() { fn test_execute_claim_fails_with_no_withdraw_to() { let mut suite = SinglePartyHolderBuilder::default() .with_withdraw_to(None) - .with_lockup_period(cw_utils::Expiration::AtHeight(12312)) .build(); + suite.expire_lockup(); let sender = suite.liquid_pooler_address.clone(); + suite.expire_lockup(); suite.execute_claim(sender); } #[test] fn test_execute_claim_happy() { - let mut suite = SinglePartyHolderBuilder::default() - .with_lockup_period(cw_utils::Expiration::AtHeight(12312)) - .build(); + let mut suite = SinglePartyHolderBuilder::default().build(); suite.enter_pool(); let sender = suite.liquid_pooler_address.clone(); let bals = suite.query_all_balances(&suite.liquid_pooler_address); assert_eq!(bals.len(), 0); + suite.expire_lockup(); suite.execute_claim(sender); @@ -132,9 +131,7 @@ fn test_execute_emergency_withdraw_validates_emergency_committee() { #[test] fn test_execute_emergency_withdraw_happy() { - let mut suite = SinglePartyHolderBuilder::default() - .with_lockup_period(cw_utils::Expiration::AtHeight(12312)) - .build(); + let mut suite = SinglePartyHolderBuilder::default().build(); suite.enter_pool(); @@ -142,6 +139,7 @@ fn test_execute_emergency_withdraw_happy() { let bals = suite.query_all_balances(&suite.liquid_pooler_address); assert_eq!(bals.len(), 0); + suite.expire_lockup(); suite.execute_emergency_withdraw(sender); let bals = suite.query_all_balances(&suite.liquid_pooler_address); @@ -150,9 +148,7 @@ fn test_execute_emergency_withdraw_happy() { #[test] fn test_execute_distribute_validates_liquidity_pooler() { - let mut suite = SinglePartyHolderBuilder::default() - .with_lockup_period(cw_utils::Expiration::AtHeight(12312)) - .build(); + let mut suite = SinglePartyHolderBuilder::default().build(); let sender = suite.liquid_pooler_address.clone(); let funds = vec![ @@ -160,7 +156,7 @@ fn test_execute_distribute_validates_liquidity_pooler() { coin(1_000_000, DENOM_LS_ATOM_ON_NTRN), ]; suite.fund_contract_coins(funds.clone(), sender.clone()); - + suite.expire_lockup(); let resp = suite.execute_distribute(sender, funds); println!("resp: {:?}", resp); } @@ -169,24 +165,23 @@ fn test_execute_distribute_validates_liquidity_pooler() { #[should_panic(expected = "No withdraw_to address configured")] fn test_execute_distribute_validates_withdraw_to_addr() { let mut suite = SinglePartyHolderBuilder::default() - .with_lockup_period(cw_utils::Expiration::AtHeight(12312)) .with_withdraw_to(None) .build(); let sender = suite.liquid_pooler_address.clone(); + suite.expire_lockup(); suite.execute_distribute(sender, vec![]); } #[test] #[should_panic(expected = "We expect 2 denoms to be received from the liquidity pooler")] fn test_execute_distribute_ensures_two_denoms_sent() { - let mut suite = SinglePartyHolderBuilder::default() - .with_lockup_period(cw_utils::Expiration::AtHeight(12312)) - .build(); + let mut suite = SinglePartyHolderBuilder::default().build(); let sender = suite.liquid_pooler_address.clone(); let funds = vec![coin(1_000_000, DENOM_ATOM_ON_NTRN)]; suite.fund_contract_coins(funds.clone(), sender.clone()); + suite.expire_lockup(); suite.execute_distribute(sender, funds); } From ae907d83ee10dd406d12a3aeffd0efc7f0c7d4d3 Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 15 Mar 2024 21:46:34 +0100 Subject: [PATCH 16/56] top level covenant contract codes config migration --- .../single-party-pol-covenant/src/contract.rs | 11 +- .../single-party-pol-covenant/src/msg.rs | 8 +- contracts/swap-covenant/src/contract.rs | 9 ++ contracts/swap-covenant/src/msg.rs | 5 +- .../two-party-pol-covenant/src/contract.rs | 9 ++ contracts/two-party-pol-covenant/src/msg.rs | 5 +- unit-tests/src/setup/contracts.rs | 12 +- .../src/test_single_party_covenant/suite.rs | 11 ++ .../src/test_single_party_covenant/test.rs | 114 +++++++++++++++++- unit-tests/src/test_swap_covenant/suite.rs | 11 ++ unit-tests/src/test_swap_covenant/test.rs | 113 ++++++++++++++++- .../src/test_two_party_covenant/suite.rs | 12 +- .../src/test_two_party_covenant/test.rs | 33 ++--- 13 files changed, 322 insertions(+), 31 deletions(-) diff --git a/contracts/single-party-pol-covenant/src/contract.rs b/contracts/single-party-pol-covenant/src/contract.rs index 9568c554..5e47f55b 100644 --- a/contracts/single-party-pol-covenant/src/contract.rs +++ b/contracts/single-party-pol-covenant/src/contract.rs @@ -320,7 +320,8 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { )?; Ok(to_json_binary(&ica)?) - } + }, + QueryMsg::ContractCodes {} => Ok(to_json_binary(&CONTRACT_CODES.load(deps.storage)?)?), } } @@ -329,6 +330,7 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult deps.api.debug("WASMDEBUG: migrate"); match msg { MigrateMsg::MigrateContracts { + codes, clock, ls_forwarder, lp_forwarder, @@ -340,6 +342,13 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult } => { let mut migrate_msgs = vec![]; let mut resp = Response::default().add_attribute("method", "migrate_contracts"); + + if let Some(new_codes) = codes { + CONTRACT_CODES.save(deps.storage, &new_codes)?; + let code_binary = to_json_binary(&new_codes)?; + resp = resp.add_attribute("contract_codes_migrate", code_binary.to_base64()); + } + let contract_codes = CONTRACT_CODES.load(deps.storage)?; if let Some(clock) = clock { diff --git a/contracts/single-party-pol-covenant/src/msg.rs b/contracts/single-party-pol-covenant/src/msg.rs index b5a833c3..b1f46bd1 100644 --- a/contracts/single-party-pol-covenant/src/msg.rs +++ b/contracts/single-party-pol-covenant/src/msg.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Addr, Decimal, Deps, StdResult, Uint128, Uint64, WasmMsg}; +use cosmwasm_std::{Addr, Decimal, StdResult, Uint128, Uint64, WasmMsg}; use covenant_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; use covenant_osmo_liquid_pooler::msg::OsmosisLiquidPoolerConfig; use covenant_utils::{ @@ -11,7 +11,6 @@ use covenant_utils::{ }; use cw_utils::Expiration; -const NEUTRON_DENOM: &str = "untrn"; pub const DEFAULT_TIMEOUT: u64 = 60 * 60 * 5; // 5 hours #[cw_serde] @@ -191,16 +190,19 @@ pub enum QueryMsg { PartyDepositAddress {}, #[returns(Addr)] InterchainRouterAddress {}, + #[returns(CovenantContractCodeIds)] + ContractCodes {}, } #[cw_serde] pub enum MigrateMsg { MigrateContracts { + codes: Option, clock: Option, holder: Option, ls_forwarder: Option, lp_forwarder: Option, - splitter: Option, + splitter: Option, liquid_pooler: Option, liquid_staker: Option, router: Option, diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index 3c4663e3..0c02201f 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -347,6 +347,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { }; Ok(to_json_binary(&resp)?) } + QueryMsg::ContractCodes {} => Ok(to_json_binary(&CONTRACT_CODES.load(deps.storage)?)?), } } @@ -354,6 +355,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult { match msg { MigrateMsg::UpdateCovenant { + codes, clock, holder, splitter, @@ -364,6 +366,13 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult } => { let mut migrate_msgs = vec![]; let mut resp = Response::default().add_attribute("method", "migrate_contracts"); + + if let Some(new_codes) = codes { + CONTRACT_CODES.save(deps.storage, &new_codes)?; + let code_binary = to_json_binary(&new_codes)?; + resp = resp.add_attribute("contract_codes_migrate", code_binary.to_base64()); + } + let contract_codes = CONTRACT_CODES.load(deps.storage)?; if let Some(clock) = clock { diff --git a/contracts/swap-covenant/src/msg.rs b/contracts/swap-covenant/src/msg.rs index ab0b352e..7b9f65a7 100644 --- a/contracts/swap-covenant/src/msg.rs +++ b/contracts/swap-covenant/src/msg.rs @@ -182,11 +182,14 @@ pub enum QueryMsg { IbcForwarderAddress { party: String }, #[returns(Addr)] PartyDepositAddress { party: String }, + #[returns(CovenantContractCodes)] + ContractCodes {}, } #[cw_serde] pub enum MigrateMsg { UpdateCovenant { + codes: Option, clock: Option, holder: Option, splitter: Option, @@ -207,7 +210,7 @@ pub enum RouterMigrateMsg { } #[cw_serde] -pub(crate) struct CovenantContractCodes { +pub struct CovenantContractCodes { pub clock: u64, pub holder: u64, pub party_a_router: u64, diff --git a/contracts/two-party-pol-covenant/src/contract.rs b/contracts/two-party-pol-covenant/src/contract.rs index 518040ff..5590b5ba 100644 --- a/contracts/two-party-pol-covenant/src/contract.rs +++ b/contracts/two-party-pol-covenant/src/contract.rs @@ -325,6 +325,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { }; Ok(to_json_binary(&resp)?) } + QueryMsg::ContractCodes {} => Ok(to_json_binary(&CONTRACT_CODES.load(deps.storage)?)?), } } @@ -333,6 +334,7 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult deps.api.debug("WASMDEBUG: migrate"); match msg { MigrateMsg::UpdateCovenant { + codes, clock, holder, liquid_pooler, @@ -343,6 +345,13 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult } => { let mut migrate_msgs = vec![]; let mut resp = Response::default().add_attribute("method", "migrate_contracts"); + + if let Some(new_codes) = codes { + CONTRACT_CODES.save(deps.storage, &new_codes)?; + let code_binary = to_json_binary(&new_codes)?; + resp = resp.add_attribute("contract_codes_migrate", code_binary.to_base64()); + } + let contract_codes = CONTRACT_CODES.load(deps.storage)?; if let Some(clock) = clock { diff --git a/contracts/two-party-pol-covenant/src/msg.rs b/contracts/two-party-pol-covenant/src/msg.rs index a31c4ae1..980594e9 100644 --- a/contracts/two-party-pol-covenant/src/msg.rs +++ b/contracts/two-party-pol-covenant/src/msg.rs @@ -202,7 +202,7 @@ pub struct CovenantContractCodeIds { } #[cw_serde] -pub(crate) struct CovenantContractCodes { +pub struct CovenantContractCodes { pub clock: u64, pub holder: u64, pub liquid_pooler: u64, @@ -265,11 +265,14 @@ pub enum QueryMsg { LiquidPoolerAddress {}, #[returns(Addr)] PartyDepositAddress { party: String }, + #[returns(CovenantContractCodes)] + ContractCodes {}, } #[cw_serde] pub enum MigrateMsg { UpdateCovenant { + codes: Option, clock: Option, holder: Option, liquid_pooler: Option, diff --git a/unit-tests/src/setup/contracts.rs b/unit-tests/src/setup/contracts.rs index f107df36..c9ef3a81 100644 --- a/unit-tests/src/setup/contracts.rs +++ b/unit-tests/src/setup/contracts.rs @@ -399,7 +399,17 @@ pub fn swap_covenant_contract() -> Box> { covenant_swap::contract::query(get_empty_deps(deps), env, msg) }; - let contract = ContractWrapper::new(exec, init, query); + let migrate = + |deps: DepsMut, env: Env, msg: covenant_swap::msg::MigrateMsg| { + execute_into_neutron(covenant_swap::contract::migrate( + get_empty_depsmut(deps), + env, + msg, + )) + }; + + let contract = ContractWrapper::new(exec, init, query) + .with_migrate(migrate); Box::new(contract) } diff --git a/unit-tests/src/test_single_party_covenant/suite.rs b/unit-tests/src/test_single_party_covenant/suite.rs index b5eb2cde..b6025fd9 100644 --- a/unit-tests/src/test_single_party_covenant/suite.rs +++ b/unit-tests/src/test_single_party_covenant/suite.rs @@ -1,6 +1,7 @@ use std::{collections::BTreeMap, str::FromStr}; use cosmwasm_std::{coin, Addr, Coin, Decimal, StdResult}; +use covenant_single_party_pol::msg::CovenantContractCodeIds; use cw_multi_test::Executor; use crate::setup::{ @@ -461,4 +462,14 @@ impl Suite { &covenant_single_party_pol::msg::QueryMsg::PartyDepositAddress {}, ) } + + pub fn query_contract_codes(&self) -> CovenantContractCodeIds { + self.app + .wrap() + .query_wasm_smart::( + self.covenant_addr.clone(), + &covenant_two_party_pol::msg::QueryMsg::ContractCodes {}, + ) + .unwrap() + } } diff --git a/unit-tests/src/test_single_party_covenant/test.rs b/unit-tests/src/test_single_party_covenant/test.rs index 204d7f45..00000a78 100644 --- a/unit-tests/src/test_single_party_covenant/test.rs +++ b/unit-tests/src/test_single_party_covenant/test.rs @@ -1,9 +1,8 @@ -use cosmwasm_std::{coin, Addr, Uint128}; +use cosmwasm_std::{coin, to_json_binary, Addr, Event, Uint128, Uint64}; use cw_multi_test::Executor; use crate::setup::{ - base_suite::BaseSuiteMut, DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, - DENOM_LS_ATOM_ON_STRIDE, + base_suite::BaseSuiteMut, ADMIN, DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_STRIDE }; use super::suite::Suite; @@ -1017,3 +1016,112 @@ fn test_covenant_with_single_sided() { // We used pfm, so the receiver should have close to 1_000_000_000_000 uatom assert!(receiver_balance.amount.u128() > 900_000_000_000_u128); } + +#[test] +fn test_migrate_update_config_with_codes() { + let mut suite = Suite::new_with_stable_pool(); + let covenant_addr = suite.covenant_addr.clone(); + let mut contract_codes = suite.query_contract_codes(); + contract_codes.clock_code = 69; + + let holder_migrate_msg = covenant_single_party_pol_holder::msg::MigrateMsg::UpdateConfig { + withdrawer: Some(covenant_addr.to_string()), + withdraw_to: None, + emergency_committee: None, + pooler_address: None, + lockup_period: None, + }; + + let ibc_forwarder_migrate_msg = covenant_ibc_forwarder::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + next_contract: None, + remote_chain_info: Box::new(None), + transfer_amount: None, + }; + + let liquid_pooler_migrate_msg = covenant_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + holder_address: None, + lp_config: None, + }; + + let liquid_staker_migrate_msg = covenant_stride_liquid_staker::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + next_contract: None, + remote_chain_info: None, + }; + + let remote_chain_splitter_migrate_msg = covenant_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + remote_chain_info: None, + splits: None, + }; + + let resp = suite.app.migrate_contract( + Addr::unchecked(ADMIN), + covenant_addr, + &covenant_single_party_pol::msg::MigrateMsg::MigrateContracts { + codes: Some(contract_codes.clone()), + clock: None, + holder: Some(holder_migrate_msg.clone()), + ls_forwarder: Some(ibc_forwarder_migrate_msg.clone()), + lp_forwarder: Some(ibc_forwarder_migrate_msg.clone()), + splitter: Some(remote_chain_splitter_migrate_msg.clone()), + liquid_pooler: Some( + covenant_single_party_pol::msg::LiquidPoolerMigrateMsg::Astroport(liquid_pooler_migrate_msg.clone()) + ), + liquid_staker: Some(liquid_staker_migrate_msg.clone()), + router: None, + }, + 2, + ) + .unwrap(); + + resp.assert_event(&Event::new("wasm") + .add_attribute("contract_codes_migrate", to_json_binary(&contract_codes).unwrap().to_base64()) + .add_attribute("ls_forwarder_migrate", to_json_binary(&ibc_forwarder_migrate_msg).unwrap().to_base64()) + .add_attribute("lp_forwarder_migrate", to_json_binary(&ibc_forwarder_migrate_msg).unwrap().to_base64()) + .add_attribute("liquid_pooler_migrate", to_json_binary(&liquid_pooler_migrate_msg).unwrap().to_base64()) + .add_attribute("liquid_staker_migrate", to_json_binary(&liquid_staker_migrate_msg).unwrap().to_base64()) + .add_attribute("splitter_migrate", to_json_binary(&remote_chain_splitter_migrate_msg).unwrap().to_base64()) + .add_attribute("holder_migrate", to_json_binary(&holder_migrate_msg).unwrap().to_base64()) + ); + + let new_codes = suite.query_contract_codes(); + assert_eq!(new_codes.clock_code, 69); +} + +#[test] +fn test_migrate_update_config_no_codes() { + let mut suite = Suite::new_with_stable_pool(); + let covenant_addr = suite.covenant_addr.clone(); + + let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { new_value: Uint64::new(50000) }; + let router_migrate_msg = covenant_interchain_router::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + destination_config: None, + target_denoms: None, + }; + let resp = suite.app.migrate_contract( + Addr::unchecked(ADMIN), + covenant_addr, + &covenant_single_party_pol::msg::MigrateMsg::MigrateContracts { + codes: None, + clock: Some(clock_migrate_msg.clone()), + holder: None, + ls_forwarder: None, + lp_forwarder: None, + splitter: None, + liquid_pooler: None, + liquid_staker: None, + router: Some(router_migrate_msg.clone()), + }, + 2, + ) + .unwrap(); + + resp.assert_event(&Event::new("wasm") + .add_attribute("clock_migrate", to_json_binary(&clock_migrate_msg).unwrap().to_base64()) + .add_attribute("router_migrate", to_json_binary(&router_migrate_msg).unwrap().to_base64()) + ); +} \ No newline at end of file diff --git a/unit-tests/src/test_swap_covenant/suite.rs b/unit-tests/src/test_swap_covenant/suite.rs index 11cda83a..facf9d3a 100644 --- a/unit-tests/src/test_swap_covenant/suite.rs +++ b/unit-tests/src/test_swap_covenant/suite.rs @@ -1,6 +1,7 @@ use std::vec; use cosmwasm_std::{coins, Addr, Coin, Decimal, StdResult}; +use covenant_swap::msg::CovenantContractCodes; use cw_multi_test::Executor; use crate::setup::{ @@ -500,4 +501,14 @@ impl Suite { }, ) } + + pub fn query_contract_codes(&self) -> CovenantContractCodes { + self.app + .wrap() + .query_wasm_smart::( + self.covenant_addr.clone(), + &covenant_swap::msg::QueryMsg::ContractCodes {}, + ) + .unwrap() + } } diff --git a/unit-tests/src/test_swap_covenant/test.rs b/unit-tests/src/test_swap_covenant/test.rs index 629b2ea8..fa048cc7 100644 --- a/unit-tests/src/test_swap_covenant/test.rs +++ b/unit-tests/src/test_swap_covenant/test.rs @@ -1,11 +1,8 @@ -use cosmwasm_std::{coin, coins, Uint128}; +use cosmwasm_std::{coin, coins, to_json_binary, Addr, Event, Uint128, Uint64}; use cw_multi_test::Executor; use crate::setup::{ - base_suite::{BaseSuite, BaseSuiteMut}, - DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK, DENOM_FALLBACK_ON_HUB, DENOM_FALLBACK_ON_OSMO, - DENOM_HUB_ON_OSMO_FROM_NTRN, DENOM_NTRN, DENOM_NTRN_ON_HUB, DENOM_OSMO, - DENOM_OSMO_ON_HUB_FROM_NTRN, DENOM_OSMO_ON_NTRN, + base_suite::{BaseSuite, BaseSuiteMut}, instantiates::ibc_forwarder, ADMIN, DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK, DENOM_FALLBACK_ON_HUB, DENOM_FALLBACK_ON_OSMO, DENOM_HUB_ON_OSMO_FROM_NTRN, DENOM_NTRN, DENOM_NTRN_ON_HUB, DENOM_OSMO, DENOM_OSMO_ON_HUB_FROM_NTRN, DENOM_OSMO_ON_NTRN }; use super::suite::Suite; @@ -430,6 +427,112 @@ fn test_covenant_native_refund() { assert_eq!(receiver_b_balance_ntrn.amount.u128(), 10_000_000_u128); } +#[test] +fn test_migrate_update_with_codes() { + let mut suite = Suite::new_with_2_native_configs(); + let covenant_addr = suite.covenant_addr.to_string(); + + let mut contract_codes = suite.query_contract_codes(); + contract_codes.clock = 1; + + let native_router_migrate_msg = covenant_native_router::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + target_denoms: None, + receiver_address: None, + }; + + let holder_migrate_msg = covenant_swap_holder::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + next_contract: None, + lockup_config: None, + parites_config: Box::new(None), + covenant_terms: None, + }; + + let splitter_migrate_msg = covenant_native_splitter::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + fallback_split: None, + splits: None, + }; + + let resp = suite.app.migrate_contract( + Addr::unchecked(ADMIN), + Addr::unchecked(covenant_addr), + &covenant_swap::msg::MigrateMsg::UpdateCovenant { + codes: Some(contract_codes.clone()), + clock: None, + holder: Some(holder_migrate_msg.clone()), + splitter: Some(splitter_migrate_msg.clone()), + party_a_router: Some(covenant_swap::msg::RouterMigrateMsg::Native(native_router_migrate_msg.clone())), + party_b_router: Some(covenant_swap::msg::RouterMigrateMsg::Native(native_router_migrate_msg.clone())), + party_a_forwarder: None, + party_b_forwarder: Box::new(None), + }, + 1, + ) + .unwrap(); + + resp.assert_event(&Event::new("wasm") + .add_attribute("contract_codes_migrate", to_json_binary(&contract_codes).unwrap().to_base64()) + .add_attribute("holder_migrate", to_json_binary(&holder_migrate_msg).unwrap().to_base64()) + .add_attribute("splitter_migrate", to_json_binary(&splitter_migrate_msg).unwrap().to_base64()) + .add_attribute("party_a_router_migrate", to_json_binary(&native_router_migrate_msg).unwrap().to_base64()) + .add_attribute("party_b_router_migrate", to_json_binary(&native_router_migrate_msg).unwrap().to_base64()) + ); + + let new_codes = suite.query_contract_codes(); + assert_eq!(contract_codes, new_codes); +} + + +#[test] +fn test_migrate_update_without_codes() { + let mut suite = Suite::new_with_2_interchain_configs(); + let covenant_addr = suite.covenant_addr.to_string(); + + let interchain_router_migrate_msg = covenant_interchain_router::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + target_denoms: None, + destination_config: None, + }; + + let ibc_forwarder_migrate_msg = covenant_ibc_forwarder::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + next_contract: None, + remote_chain_info: Box::new(None), + transfer_amount: None, + }; + + let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { + new_value: Uint64::new(50000), + }; + + let resp = suite.app.migrate_contract( + Addr::unchecked(ADMIN), + Addr::unchecked(covenant_addr), + &covenant_swap::msg::MigrateMsg::UpdateCovenant { + codes: None, + clock: Some(clock_migrate_msg.clone()), + holder: None, + splitter: None, + party_a_router: Some(covenant_swap::msg::RouterMigrateMsg::Interchain(interchain_router_migrate_msg.clone())), + party_b_router: Some(covenant_swap::msg::RouterMigrateMsg::Interchain(interchain_router_migrate_msg.clone())), + party_a_forwarder: Some(ibc_forwarder_migrate_msg.clone()), + party_b_forwarder: Box::new(Some(ibc_forwarder_migrate_msg.clone())), + }, + 1, + ) + .unwrap(); + + resp.assert_event(&Event::new("wasm") + .add_attribute("clock_migrate", to_json_binary(&clock_migrate_msg).unwrap().to_base64()) + .add_attribute("party_a_router_migrate", to_json_binary(&interchain_router_migrate_msg).unwrap().to_base64()) + .add_attribute("party_b_router_migrate", to_json_binary(&interchain_router_migrate_msg).unwrap().to_base64()) + .add_attribute("party_a_forwarder_migrate", to_json_binary(&ibc_forwarder_migrate_msg).unwrap().to_base64()) + .add_attribute("party_b_forwarder_migrate", to_json_binary(&ibc_forwarder_migrate_msg).unwrap().to_base64()) + ); +} + // TODO: swap holder is using IBC transfer method isntead of the neutron msg, so this test is not working // #[test] // fn test_covenant_interchain_refund() { diff --git a/unit-tests/src/test_two_party_covenant/suite.rs b/unit-tests/src/test_two_party_covenant/suite.rs index 1c9304d2..15d5953b 100644 --- a/unit-tests/src/test_two_party_covenant/suite.rs +++ b/unit-tests/src/test_two_party_covenant/suite.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use cosmwasm_std::{coin, Addr, Uint64}; -use covenant_two_party_pol::msg::Timeouts; +use covenant_two_party_pol::msg::{CovenantContractCodes, Timeouts}; use covenant_utils::split::SplitConfig; use cw_multi_test::{AppResponse, Executor}; use cw_utils::Expiration; @@ -273,6 +273,16 @@ impl Suite { ) .unwrap() } + + pub fn query_contract_codes(&self) -> CovenantContractCodes { + self.app + .wrap() + .query_wasm_smart::( + self.covenant_addr.clone(), + &covenant_two_party_pol::msg::QueryMsg::ContractCodes {}, + ) + .unwrap() + } } impl BaseSuiteMut for Suite { diff --git a/unit-tests/src/test_two_party_covenant/test.rs b/unit-tests/src/test_two_party_covenant/test.rs index 38d616b1..2607e6fd 100644 --- a/unit-tests/src/test_two_party_covenant/test.rs +++ b/unit-tests/src/test_two_party_covenant/test.rs @@ -108,9 +108,6 @@ fn test_migrate_update_config_party_a_interchain() { .build(); let random_address = suite.faucet.clone(); - let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { - new_value: Uint64::new(500_000), - }; let holder_migrate_msg = covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), next_contract: None, @@ -155,11 +152,13 @@ fn test_migrate_update_config_party_a_interchain() { remote_chain_info: None.into(), transfer_amount: None, }; - + let mut contract_codes = suite.query_contract_codes(); + contract_codes.clock = 1; let resp = suite.migrate_update( 21, covenant_two_party_pol::msg::MigrateMsg::UpdateCovenant { - clock: Some(clock_migrate_msg.clone()), + codes: Some(contract_codes.clone()), + clock: None, holder: Some(holder_migrate_msg.clone()), liquid_pooler: Some(liquid_pooler_migrate_msg.clone()), party_a_router: Some(party_a_router_migrate_msg.clone()), @@ -172,8 +171,8 @@ fn test_migrate_update_config_party_a_interchain() { resp.assert_event( &Event::new("wasm") .add_attribute( - "clock_migrate", - to_json_binary(&clock_migrate_msg).unwrap().to_string(), + "contract_codes_migrate", + to_json_binary(&contract_codes).unwrap().to_string(), ) .add_attribute( "party_a_router_migrate", @@ -205,23 +204,17 @@ fn test_migrate_update_config_party_a_interchain() { ), ); - let clock_address = suite.query_clock_address(); let holder_address = suite.query_holder_address(); let liquid_pooler_address = suite.query_liquid_pooler_address(); let party_a_router_address = suite.query_interchain_router_address("party_a"); let party_b_router_address = suite.query_interchain_router_address("party_b"); let party_a_forwarder_address = suite.query_ibc_forwarder_address("party_a"); + let new_contract_codes = suite.query_contract_codes(); suite.tick_contract(suite.clock_addr.clone()); let app = suite.get_app(); - let clock_max_gas: Uint64 = app - .wrap() - .query_wasm_smart(clock_address, &covenant_clock::msg::QueryMsg::TickMaxGas {}) - .unwrap(); - assert_eq!(clock_max_gas, Uint64::new(500_000)); - let holder_clock_address: Addr = app .wrap() .query_wasm_smart( @@ -266,6 +259,8 @@ fn test_migrate_update_config_party_a_interchain() { ) .unwrap(); assert_eq!(party_a_forwarder_clock_address, random_address); + + assert_eq!(new_contract_codes, contract_codes); } #[test] @@ -343,10 +338,13 @@ fn test_migrate_update_config_party_b_interchain() { remote_chain_info: None.into(), transfer_amount: None, }; + let mut contract_codes = suite.query_contract_codes(); + contract_codes.party_a_forwarder = 1; let resp = suite.migrate_update( 21, covenant_two_party_pol::msg::MigrateMsg::UpdateCovenant { + codes: Some(contract_codes.clone()), clock: Some(clock_migrate_msg.clone()), holder: Some(holder_migrate_msg.clone()), liquid_pooler: Some(liquid_pooler_migrate_msg.clone()), @@ -359,6 +357,10 @@ fn test_migrate_update_config_party_b_interchain() { resp.assert_event( &Event::new("wasm") + .add_attribute( + "contract_codes_migrate", + to_json_binary(&contract_codes).unwrap().to_string(), + ) .add_attribute( "clock_migrate", to_json_binary(&clock_migrate_msg).unwrap().to_string(), @@ -399,7 +401,7 @@ fn test_migrate_update_config_party_b_interchain() { let party_a_router_address = suite.query_interchain_router_address("party_a"); let party_b_router_address = suite.query_interchain_router_address("party_b"); let party_b_forwarder_address = suite.query_ibc_forwarder_address("party_b"); - + let new_contract_codes = suite.query_contract_codes(); suite.tick_contract(suite.clock_addr.clone()); let app = suite.get_app(); @@ -454,4 +456,5 @@ fn test_migrate_update_config_party_b_interchain() { ) .unwrap(); assert_eq!(party_b_forwarder_clock_address, random_address); + assert_eq!(new_contract_codes, contract_codes); } From a00001a094774f4bdba815aff4eaeca788c2813c Mon Sep 17 00:00:00 2001 From: bekauz Date: Sat, 16 Mar 2024 16:50:11 +0100 Subject: [PATCH 17/56] swap covenant ensures party contribution denom on neutron is explicitly defined in native splitter --- contracts/swap-covenant/src/contract.rs | 14 ++++++- contracts/swap-covenant/src/error.rs | 3 ++ contracts/swap-covenant/src/msg.rs | 7 ++++ unit-tests/src/test_swap_covenant/suite.rs | 45 ++++++++++++++++++++++ unit-tests/src/test_swap_covenant/test.rs | 14 ++++++- 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index 0c02201f..d4d4e17c 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -3,8 +3,7 @@ use std::collections::BTreeSet; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_json_binary, to_json_string, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, - StdResult, WasmMsg, + ensure, to_json_binary, to_json_string, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, WasmMsg }; use covenant_utils::{ instantiate2_helper::get_instantiate2_salt_and_address, split::remap_splits, @@ -121,6 +120,17 @@ pub fn instantiate( party_b_router_instantiate2_config.clone(), )?; + // we validate that denoms explicitly defined in splits are the + // same denoms that parties are expected to contribute + ensure!( + msg.splits.contains_key(&msg.party_a_config.get_native_denom()), + ContractError::DenomMisconfigurationError(msg.party_a_config.get_native_denom(), format!("{:?}", covenant_denoms)) + ); + ensure!( + msg.splits.contains_key(&msg.party_b_config.get_native_denom()), + ContractError::DenomMisconfigurationError(msg.party_b_config.get_native_denom(), format!("{:?}", covenant_denoms)) + ); + let splitter_instantiate2_msg = covenant_native_splitter::msg::InstantiateMsg { clock_address: clock_instantiate2_config.addr.to_string(), splits: remap_splits( diff --git a/contracts/swap-covenant/src/error.rs b/contracts/swap-covenant/src/error.rs index a0840192..d80e4de1 100644 --- a/contracts/swap-covenant/src/error.rs +++ b/contracts/swap-covenant/src/error.rs @@ -27,4 +27,7 @@ pub enum ContractError { #[error("{0}")] InstantiationError(#[from] Instantiate2AddressError), + + #[error("{0} contribution missing an explicit split configuration (got {1})")] + DenomMisconfigurationError(String,String), } diff --git a/contracts/swap-covenant/src/msg.rs b/contracts/swap-covenant/src/msg.rs index 7b9f65a7..29c17d5a 100644 --- a/contracts/swap-covenant/src/msg.rs +++ b/contracts/swap-covenant/src/msg.rs @@ -75,6 +75,13 @@ impl CovenantPartyConfig { } } + pub fn get_native_denom(&self) -> String { + match self { + CovenantPartyConfig::Interchain(config) => config.native_denom.to_string(), + CovenantPartyConfig::Native(config) => config.native_denom.to_string(), + } + } + pub fn get_contribution(&self) -> Coin { match self { CovenantPartyConfig::Interchain(config) => config.contribution.clone(), diff --git a/unit-tests/src/test_swap_covenant/suite.rs b/unit-tests/src/test_swap_covenant/suite.rs index facf9d3a..57cd8976 100644 --- a/unit-tests/src/test_swap_covenant/suite.rs +++ b/unit-tests/src/test_swap_covenant/suite.rs @@ -229,6 +229,51 @@ impl Suite { Self::build(builder, covenant_addr, party_a_receiver, party_b_receiver) } + pub fn new_with_split_denoms(denom_1: &str, denom_2: &str) -> Self { + let mut builder = SuiteBuilder::new(); + + let covenant_addr = + builder.get_contract_addr(builder.swap_covenant_code_id, SWAP_COVENANT_SALT); + + let party_a_receiver = builder.get_random_addr(); + let party_a_on_ntrn = builder.get_random_addr(); + let party_b_receiver = builder.get_random_addr(); + + let recievers = vec![ + (&party_a_receiver, Decimal::bps(5000)), + (&party_b_receiver, Decimal::bps(5000)), + ]; + let splits = SwapCovenantInstantiate::get_split_custom(vec![ + (denom_1, &recievers), + (denom_2, &recievers), + ]); + let party_a_config = SwapCovenantInstantiate::get_party_config_interchain( + &party_a_receiver, + &party_a_on_ntrn, + DENOM_ATOM, + DENOM_ATOM_ON_NTRN, + NTRN_HUB_CHANNEL.0, + NTRN_HUB_CHANNEL.1, + 10_000_000_u128, + ); + let party_b_config = SwapCovenantInstantiate::get_party_config_native( + &party_b_receiver, + DENOM_NTRN, + 10_000_000_u128, + ); + let init_msg = + SwapCovenantInstantiate::default(&builder, party_a_config, party_b_config, splits).msg; + + builder.contract_init2( + builder.swap_covenant_code_id, + SWAP_COVENANT_SALT, + &init_msg, + &[], + ); + + Self::build(builder, covenant_addr, party_a_receiver, party_b_receiver) + } + /// Init covenant with 2 native parties and 50% split of both denoms pub fn new_with_2_native_configs() -> Self { let mut builder = SuiteBuilder::new(); diff --git a/unit-tests/src/test_swap_covenant/test.rs b/unit-tests/src/test_swap_covenant/test.rs index fa048cc7..49a36187 100644 --- a/unit-tests/src/test_swap_covenant/test.rs +++ b/unit-tests/src/test_swap_covenant/test.rs @@ -2,11 +2,23 @@ use cosmwasm_std::{coin, coins, to_json_binary, Addr, Event, Uint128, Uint64}; use cw_multi_test::Executor; use crate::setup::{ - base_suite::{BaseSuite, BaseSuiteMut}, instantiates::ibc_forwarder, ADMIN, DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK, DENOM_FALLBACK_ON_HUB, DENOM_FALLBACK_ON_OSMO, DENOM_HUB_ON_OSMO_FROM_NTRN, DENOM_NTRN, DENOM_NTRN_ON_HUB, DENOM_OSMO, DENOM_OSMO_ON_HUB_FROM_NTRN, DENOM_OSMO_ON_NTRN + base_suite::{BaseSuite, BaseSuiteMut}, ADMIN, DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK, DENOM_FALLBACK_ON_HUB, DENOM_FALLBACK_ON_OSMO, DENOM_HUB_ON_OSMO_FROM_NTRN, DENOM_NTRN, DENOM_NTRN_ON_HUB, DENOM_OSMO, DENOM_OSMO_ON_HUB_FROM_NTRN, DENOM_OSMO_ON_NTRN }; use super::suite::Suite; +#[test] +#[should_panic(expected = "uatom contribution missing an explicit split configuration")] +fn test_instantiate_validates_split_config_denom_1() { + Suite::new_with_split_denoms("invalid", DENOM_NTRN); +} + +#[test] +#[should_panic(expected = "untrn contribution missing an explicit split configuration")] +fn test_instantiate_validates_split_config_denom_2() { + Suite::new_with_split_denoms(DENOM_ATOM_ON_NTRN, "invalid"); +} + #[test] fn test_covenant() { let mut suite = Suite::new(); From 7efe6756a101cc83a0283bc14455df077a52abb7 Mon Sep 17 00:00:00 2001 From: bekauz Date: Sat, 16 Mar 2024 17:29:41 +0100 Subject: [PATCH 18/56] setting withdraw state on single party holder emergency withdrawal --- .../single-party-pol-holder/src/contract.rs | 2 ++ .../src/test_single_party_holder/tests.rs | 32 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/contracts/single-party-pol-holder/src/contract.rs b/contracts/single-party-pol-holder/src/contract.rs index 9c8a2789..929401a3 100644 --- a/contracts/single-party-pol-holder/src/contract.rs +++ b/contracts/single-party-pol-holder/src/contract.rs @@ -120,6 +120,8 @@ fn try_emergency_withdraw(deps: DepsMut, info: MessageInfo) -> Result Date: Sat, 16 Mar 2024 18:43:29 +0100 Subject: [PATCH 19/56] swap covenant refunds parties by bank sending respective denoms to preconfigured addresses --- contracts/swap-covenant/src/contract.rs | 5 + contracts/swap-holder/src/contract.rs | 58 +++++--- contracts/swap-holder/src/msg.rs | 11 ++ contracts/swap-holder/src/state.rs | 3 +- .../swap-holder/src/suite_tests/suite.rs | 6 +- packages/covenant-utils/src/lib.rs | 25 ---- .../src/setup/instantiates/swap_holder.rs | 14 ++ unit-tests/src/test_swap_covenant/test.rs | 5 +- unit-tests/src/test_swap_holder/suite.rs | 56 +++++++- unit-tests/src/test_swap_holder/tests.rs | 127 +++++++++++++++++- 10 files changed, 255 insertions(+), 55 deletions(-) diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index d4d4e17c..7a459422 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -5,6 +5,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ ensure, to_json_binary, to_json_string, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, WasmMsg }; +use covenant_swap_holder::msg::RefundConfig; use covenant_utils::{ instantiate2_helper::get_instantiate2_salt_and_address, split::remap_splits, CovenantPartiesConfig, CovenantTerms, SwapCovenantTerms, @@ -172,6 +173,10 @@ pub fn instantiate( }), clock_address: clock_instantiate2_config.addr.to_string(), next_contract: splitter_instantiate2_config.addr.to_string(), + refund_config: RefundConfig { + party_a_refund_address: party_a_router_instantiate2_config.addr.to_string(), + party_b_refund_address: party_b_router_instantiate2_config.addr.to_string(), + }, } .to_instantiate2_msg( &holder_instantiate2_config, diff --git a/contracts/swap-holder/src/contract.rs b/contracts/swap-holder/src/contract.rs index 22ec0ddf..82fa5197 100644 --- a/contracts/swap-holder/src/contract.rs +++ b/contracts/swap-holder/src/contract.rs @@ -1,6 +1,5 @@ use cosmwasm_std::{ - ensure, to_json_binary, Addr, BankMsg, Binary, Deps, DepsMut, Env, MessageInfo, Response, - StdError, StdResult, Uint128, + ensure, to_json_binary, Addr, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint128 }; use covenant_utils::CovenantTerms; @@ -8,7 +7,7 @@ use crate::{ error::ContractError, msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, state::{ - CLOCK_ADDRESS, CONTRACT_STATE, COVENANT_TERMS, LOCKUP_CONFIG, NEXT_CONTRACT, PARTIES_CONFIG, + CLOCK_ADDRESS, CONTRACT_STATE, COVENANT_TERMS, LOCKUP_CONFIG, NEXT_CONTRACT, PARTIES_CONFIG, REFUND_CONFIG, }, }; #[cfg(not(feature = "library"))] @@ -36,12 +35,16 @@ pub fn instantiate( "past lockup config", ))); } + deps.api.addr_validate(&msg.refund_config.party_a_refund_address)?; + deps.api.addr_validate(&msg.refund_config.party_b_refund_address)?; + NEXT_CONTRACT.save(deps.storage, &next_contract)?; CLOCK_ADDRESS.save(deps.storage, &clock_addr)?; LOCKUP_CONFIG.save(deps.storage, &msg.lockup_config)?; PARTIES_CONFIG.save(deps.storage, &msg.parties_config)?; COVENANT_TERMS.save(deps.storage, &msg.covenant_terms)?; CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; + REFUND_CONFIG.save(deps.storage, &msg.refund_config)?; Ok(Response::default() .add_message(enqueue_msg(clock_addr.as_str())?) @@ -153,7 +156,9 @@ fn try_refund(mut deps: DepsMut, env: Env, clock_addr: Addr) -> Result = match (party_a_coin.amount.is_zero(), party_b_coin.amount.is_zero()) { // both balances being zero means that either: // 1. neither party deposited any funds in the first place // 2. we have refunded both parties @@ -168,22 +173,34 @@ fn try_refund(mut deps: DepsMut, env: Env, clock_addr: Addr) -> Result vec![parties - .party_b - .get_refund_msg(party_b_coin.amount, &env.block)], + (true, false) => vec![ + BankMsg::Send { + to_address: refund_config.party_b_refund_address, + amount: vec![party_b_coin], + } + .into(), + ], // party B failed to deposit. refund party A - (false, true) => vec![parties - .party_a - .get_refund_msg(party_a_coin.amount, &env.block)], + (false, true) => vec![ + BankMsg::Send { + to_address: refund_config.party_a_refund_address, + amount: vec![party_a_coin], + } + .into(), + ], // not enough balances to perform the covenant swap. // refund denoms to both parties. (false, false) => vec![ - parties - .party_a - .get_refund_msg(party_a_coin.amount, &env.block), - parties - .party_b - .get_refund_msg(party_b_coin.amount, &env.block), + BankMsg::Send { + to_address: refund_config.party_a_refund_address, + amount: vec![party_a_coin], + } + .into(), + BankMsg::Send { + to_address: refund_config.party_b_refund_address, + amount: vec![party_b_coin], + } + .into(), ], }; @@ -205,6 +222,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { QueryMsg::ContractState {} => Ok(to_json_binary(&CONTRACT_STATE.may_load(deps.storage)?)?), // the deposit address for swap-holder is the contract itself QueryMsg::DepositAddress {} => Ok(to_json_binary(&Some(env.contract.address))?), + QueryMsg::RefundConfig {} => Ok(to_json_binary(&REFUND_CONFIG.may_load(deps.storage)?)?), } } @@ -218,6 +236,7 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult lockup_config, parites_config, covenant_terms, + refund_config, } => { let mut resp = Response::default().add_attribute("method", "update_config"); @@ -251,6 +270,13 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult resp = resp.add_attribute("covenant_terms", format!("{covenant_terms:?}")); } + if let Some(config) = refund_config { + deps.api.addr_validate(&config.party_a_refund_address)?; + deps.api.addr_validate(&config.party_b_refund_address)?; + REFUND_CONFIG.save(deps.storage, &config)?; + resp = resp.add_attribute("refund_config", format!("{config:?}")); + } + Ok(resp) } MigrateMsg::UpdateCodeId { data: _ } => todo!(), diff --git a/contracts/swap-holder/src/msg.rs b/contracts/swap-holder/src/msg.rs index 1708fb03..a98b410c 100644 --- a/contracts/swap-holder/src/msg.rs +++ b/contracts/swap-holder/src/msg.rs @@ -26,6 +26,8 @@ pub struct InstantiateMsg { pub parties_config: CovenantPartiesConfig, /// terms of the covenant pub covenant_terms: CovenantTerms, + /// refund configuration containing party router adresses + pub refund_config: RefundConfig, } impl InstantiateMsg { @@ -59,6 +61,12 @@ impl InstantiateMsg { } } +#[cw_serde] +pub struct RefundConfig { + pub party_a_refund_address: String, + pub party_b_refund_address: String, +} + #[clocked] #[cw_serde] pub enum ExecuteMsg {} @@ -78,6 +86,8 @@ pub enum QueryMsg { CovenantTerms {}, #[returns(ContractState)] ContractState {}, + #[returns(RefundConfig)] + RefundConfig {}, } #[cw_serde] @@ -104,6 +114,7 @@ pub enum MigrateMsg { lockup_config: Option, parites_config: Box>, covenant_terms: Option, + refund_config: Option, }, UpdateCodeId { data: Option, diff --git a/contracts/swap-holder/src/state.rs b/contracts/swap-holder/src/state.rs index 80463976..9b889c9a 100644 --- a/contracts/swap-holder/src/state.rs +++ b/contracts/swap-holder/src/state.rs @@ -3,7 +3,7 @@ use covenant_utils::{CovenantPartiesConfig, CovenantTerms}; use cw_storage_plus::Item; use cw_utils::Expiration; -use crate::msg::ContractState; +use crate::msg::{ContractState, RefundConfig}; pub const CONTRACT_STATE: Item = Item::new("contract_state"); pub const CLOCK_ADDRESS: Item = Item::new("clock_address"); @@ -11,3 +11,4 @@ pub const NEXT_CONTRACT: Item = Item::new("next_contract"); pub const PARTIES_CONFIG: Item = Item::new("parties_config"); pub const LOCKUP_CONFIG: Item = Item::new("lockup_config"); pub const COVENANT_TERMS: Item = Item::new("covenant_terms"); +pub const REFUND_CONFIG: Item = Item::new("refund_config"); diff --git a/contracts/swap-holder/src/suite_tests/suite.rs b/contracts/swap-holder/src/suite_tests/suite.rs index d677c663..4b988210 100644 --- a/contracts/swap-holder/src/suite_tests/suite.rs +++ b/contracts/swap-holder/src/suite_tests/suite.rs @@ -1,5 +1,5 @@ use crate::{ - msg::{ContractState, ExecuteMsg, InstantiateMsg, QueryMsg}, + msg::{ContractState, ExecuteMsg, InstantiateMsg, QueryMsg, RefundConfig}, suite_tests::mock_clock_deps_contract, }; use cosmwasm_std::{Addr, Coin, Uint128}; @@ -63,6 +63,10 @@ impl Default for SuiteBuilder { party_a_amount: Uint128::new(400), party_b_amount: Uint128::new(20), }), + refund_config: RefundConfig { + party_a_refund_address: PARTY_A_ADDR.to_string(), + party_b_refund_address: PARTY_B_ADDR.to_string(), + }, }, app: App::default(), } diff --git a/packages/covenant-utils/src/lib.rs b/packages/covenant-utils/src/lib.rs index ac7346cc..195304ad 100644 --- a/packages/covenant-utils/src/lib.rs +++ b/packages/covenant-utils/src/lib.rs @@ -88,31 +88,6 @@ pub struct CovenantParty { } impl CovenantParty { - pub fn get_refund_msg(self, amount: Uint128, block: &BlockInfo) -> CosmosMsg { - match self.receiver_config { - ReceiverConfig::Native(addr) => CosmosMsg::Bank(BankMsg::Send { - to_address: addr.to_string(), - amount: vec![cosmwasm_std::Coin { - denom: self.native_denom, - amount, - }], - }), - ReceiverConfig::Ibc(destination_config) => CosmosMsg::Ibc(IbcMsg::Transfer { - channel_id: destination_config.local_to_destination_chain_channel_id, - to_address: self.addr.to_string(), - amount: cosmwasm_std::Coin { - denom: self.native_denom, - amount, - }, - timeout: IbcTimeout::with_timestamp( - block - .time - .plus_seconds(destination_config.ibc_transfer_timeout.u64()), - ), - }), - } - } - pub fn validate_addresses(&self, api: &dyn Api) -> StdResult { match &self.receiver_config { ReceiverConfig::Native(addr) => api.addr_validate(&addr), diff --git a/unit-tests/src/setup/instantiates/swap_holder.rs b/unit-tests/src/setup/instantiates/swap_holder.rs index 949cced2..7266d4b4 100644 --- a/unit-tests/src/setup/instantiates/swap_holder.rs +++ b/unit-tests/src/setup/instantiates/swap_holder.rs @@ -1,4 +1,5 @@ use cosmwasm_std::{Addr, Uint128}; +use covenant_swap_holder::msg::RefundConfig; use covenant_utils::{CovenantPartiesConfig, CovenantParty, CovenantTerms, ReceiverConfig}; use cw_utils::Expiration; @@ -21,6 +22,7 @@ impl SwapHolderInstantiate { lockup_config: Expiration, covenant_terms: CovenantTerms, parties_config: CovenantPartiesConfig, + refund_config: RefundConfig, ) -> Self { Self { msg: covenant_swap_holder::msg::InstantiateMsg { @@ -29,6 +31,7 @@ impl SwapHolderInstantiate { lockup_config, covenant_terms, parties_config, + refund_config, }, } } @@ -57,6 +60,11 @@ impl SwapHolderInstantiate { self.msg.parties_config = config; self } + + pub fn with_refund_config(&mut self, config: RefundConfig) -> &mut Self { + self.msg.refund_config = config; + self + } } impl SwapHolderInstantiate { @@ -65,6 +73,8 @@ impl SwapHolderInstantiate { next_contract: String, party_a_addr: Addr, party_b_addr: Addr, + party_a_refund_address: String, + party_b_refund_address: String, ) -> Self { Self { msg: covenant_swap_holder::msg::InstantiateMsg { @@ -87,6 +97,10 @@ impl SwapHolderInstantiate { receiver_config: ReceiverConfig::Native(party_b_addr.to_string()), }, }, + refund_config: RefundConfig { + party_a_refund_address, + party_b_refund_address, + }, }, } } diff --git a/unit-tests/src/test_swap_covenant/test.rs b/unit-tests/src/test_swap_covenant/test.rs index 49a36187..9783782f 100644 --- a/unit-tests/src/test_swap_covenant/test.rs +++ b/unit-tests/src/test_swap_covenant/test.rs @@ -395,6 +395,7 @@ fn test_covenant_interchain_fallback_split() { #[test] fn test_covenant_native_refund() { let mut suite = Suite::new_with_2_native_configs(); + let init_ntrn_router_balance = suite.query_balance(&suite.router_b_addr, DENOM_NTRN); // Wait until depositors are ready and fund them suite.get_and_fund_depositors( @@ -436,7 +437,8 @@ fn test_covenant_native_refund() { assert_eq!(receiver_a_balance_atom.amount.u128(), 10_000_000_u128); let receiver_b_balance_ntrn = suite.query_balance(&suite.party_b_receiver, DENOM_NTRN); - assert_eq!(receiver_b_balance_ntrn.amount.u128(), 10_000_000_u128); + // router comes prefunded with some ntrn so we add that to the assertion + assert_eq!(receiver_b_balance_ntrn.amount.u128(), 10_000_000_u128 + init_ntrn_router_balance.amount.u128()); } #[test] @@ -459,6 +461,7 @@ fn test_migrate_update_with_codes() { lockup_config: None, parites_config: Box::new(None), covenant_terms: None, + refund_config: None, }; let splitter_migrate_msg = covenant_native_splitter::msg::MigrateMsg::UpdateConfig { diff --git a/unit-tests/src/test_swap_holder/suite.rs b/unit-tests/src/test_swap_holder/suite.rs index c1e6ac67..0f76b036 100644 --- a/unit-tests/src/test_swap_holder/suite.rs +++ b/unit-tests/src/test_swap_holder/suite.rs @@ -1,4 +1,4 @@ -use std::{collections::BTreeMap, str::FromStr}; +use std::{collections::{BTreeMap, BTreeSet}, str::FromStr}; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, instantiates::swap_holder::SwapHolderInstantiate, @@ -6,6 +6,7 @@ use crate::setup::{ NATIVE_SPLITTER_SALT, SWAP_HOLDER_SALT, }; use cosmwasm_std::{Addr, Decimal}; +use covenant_swap_holder::msg::RefundConfig; use covenant_utils::{split::SplitConfig, CovenantPartiesConfig, CovenantTerms}; use cw_utils::Expiration; @@ -23,9 +24,20 @@ impl Default for SwapHolderBuilder { let native_splitter_addr = builder.get_contract_addr(builder.native_splitter_code_id, NATIVE_SPLITTER_SALT); + let party_a_controller_addr = builder.get_random_addr(); + let party_b_controller_addr = builder.get_random_addr(); + + let party_a_router_addr = builder.get_contract_addr(builder.native_router_code_id, "party_a"); + let party_b_router_addr = builder.get_contract_addr(builder.native_router_code_id, "party_b"); + let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { tick_max_gas: None, - whitelist: vec![holder_addr.to_string(), native_splitter_addr.to_string()], + whitelist: vec![ + holder_addr.to_string(), + native_splitter_addr.to_string(), + party_a_router_addr.to_string(), + party_b_router_addr.to_string(), + ], }; builder.contract_init2( builder.clock_code_id, @@ -33,17 +45,35 @@ impl Default for SwapHolderBuilder { &clock_instantiate_msg, &[], ); - - let party_a_controller_addr = builder.get_random_addr(); - let party_b_controller_addr = builder.get_random_addr(); + let denom_set = BTreeSet::from_iter(vec![DENOM_ATOM_ON_NTRN.to_string(), DENOM_LS_ATOM_ON_NTRN.to_string()]); + builder.contract_init2( + builder.native_router_code_id, + "party_a", + &covenant_native_router::msg::InstantiateMsg { + clock_address: clock_addr.to_string(), + receiver_address: party_a_controller_addr.to_string(), + denoms: denom_set.clone(), + }, + &[], + ); + builder.contract_init2( + builder.native_router_code_id, + "party_b", + &covenant_native_router::msg::InstantiateMsg { + clock_address: clock_addr.to_string(), + receiver_address: party_b_controller_addr.to_string(), + denoms: denom_set.clone(), + }, + &[], + ); let mut splits = BTreeMap::new(); splits.insert( - party_a_controller_addr.to_string(), + party_a_router_addr.to_string(), Decimal::from_str("0.5").unwrap(), ); splits.insert( - party_b_controller_addr.to_string(), + party_b_router_addr.to_string(), Decimal::from_str("0.5").unwrap(), ); @@ -70,6 +100,8 @@ impl Default for SwapHolderBuilder { native_splitter_addr.to_string(), party_a_controller_addr, party_b_controller_addr, + party_a_router_addr.to_string(), + party_b_router_addr.to_string(), ); Self { @@ -259,6 +291,16 @@ impl Suite { ) .unwrap() } + + pub fn query_refund_config(&self) -> RefundConfig { + self.get_app() + .wrap() + .query_wasm_smart( + self.holder.clone(), + &covenant_swap_holder::msg::QueryMsg::RefundConfig {}, + ) + .unwrap() + } } #[allow(dead_code)] diff --git a/unit-tests/src/test_swap_holder/tests.rs b/unit-tests/src/test_swap_holder/tests.rs index f75bab70..74633ea2 100644 --- a/unit-tests/src/test_swap_holder/tests.rs +++ b/unit-tests/src/test_swap_holder/tests.rs @@ -1,10 +1,10 @@ -use cosmwasm_std::{coins, Addr, Event, Uint128}; -use covenant_swap_holder::msg::ContractState; +use cosmwasm_std::{coin, coins, Addr, Event, Uint128}; +use covenant_swap_holder::msg::{ContractState, RefundConfig}; use covenant_utils::{CovenantTerms, SwapCovenantTerms}; use cw_multi_test::Executor; use cw_utils::Expiration; -use crate::setup::{base_suite::BaseSuiteMut, ADMIN, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN}; +use crate::setup::{base_suite::{BaseSuite, BaseSuiteMut}, ADMIN, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN}; use super::suite::SwapHolderBuilder; @@ -32,6 +32,22 @@ fn test_instantiate_validates_lockup_config() { .build(); } +#[test] +#[should_panic] +fn test_instantiate_validates_party_a_refund_addr() { + let mut builder = SwapHolderBuilder::default(); + builder.instantiate_msg.msg.refund_config.party_a_refund_address = "invalid".to_string(); + builder.build(); +} + +#[test] +#[should_panic] +fn test_instantiate_validates_party_b_refund_addr() { + let mut builder = SwapHolderBuilder::default(); + builder.instantiate_msg.msg.refund_config.party_b_refund_address = "invalid".to_string(); + builder.build(); +} + #[test] #[should_panic(expected = "Unauthorized")] fn test_execute_tick_validates_clock() { @@ -91,19 +107,79 @@ fn test_execute_tick_instantiated_forwards_and_completes() { #[test] fn test_execute_expired_refund_both_parties() { + let mut suite = SwapHolderBuilder::default().build(); + + suite.fund_contract(&coins(10_000, DENOM_ATOM_ON_NTRN), suite.holder.clone()); + suite.fund_contract(&coins(10_000, DENOM_LS_ATOM_ON_NTRN), suite.holder.clone()); + + + suite.assert_balance(suite.holder.clone(), coin(10_000, DENOM_ATOM_ON_NTRN)); + suite.assert_balance(suite.holder.clone(), coin(10_000, DENOM_LS_ATOM_ON_NTRN)); + + suite.expire_lockup_config(); + suite.tick_contract(suite.holder.clone()); + let contract_state = suite.query_contract_state(); + assert!(matches!(contract_state, ContractState::Expired{})); + + suite.tick_contract(suite.holder.clone()); + suite.assert_balance(suite.holder.clone(), coin(0, DENOM_ATOM_ON_NTRN)); + suite.assert_balance(suite.holder.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN)); + suite.tick_contract(suite.holder.clone()); + let contract_state = suite.query_contract_state(); + assert!(matches!(contract_state, ContractState::Complete{})); + + let refund_config = suite.query_refund_config(); + suite.assert_balance(refund_config.party_a_refund_address, coin(10_000, DENOM_ATOM_ON_NTRN)); + suite.assert_balance(refund_config.party_b_refund_address, coin(10_000, DENOM_LS_ATOM_ON_NTRN)); } #[test] fn test_execute_expired_refund_party_a() { + let mut suite = SwapHolderBuilder::default().build(); + suite.fund_contract(&coins(10_000, DENOM_ATOM_ON_NTRN), suite.holder.clone()); + suite.assert_balance(suite.holder.clone(), coin(10_000, DENOM_ATOM_ON_NTRN)); + + suite.expire_lockup_config(); + suite.tick_contract(suite.holder.clone()); + let contract_state = suite.query_contract_state(); + assert!(matches!(contract_state, ContractState::Expired{})); + + suite.tick_contract(suite.holder.clone()); + suite.assert_balance(suite.holder.clone(), coin(0, DENOM_ATOM_ON_NTRN)); + + suite.tick_contract(suite.holder.clone()); + let contract_state = suite.query_contract_state(); + assert!(matches!(contract_state, ContractState::Complete{})); + + let refund_config = suite.query_refund_config(); + suite.assert_balance(refund_config.party_a_refund_address, coin(10_000, DENOM_ATOM_ON_NTRN)); } #[test] fn test_execute_expired_refund_party_b() { + let mut suite = SwapHolderBuilder::default().build(); + + suite.fund_contract(&coins(10_000, DENOM_LS_ATOM_ON_NTRN), suite.holder.clone()); + suite.assert_balance(suite.holder.clone(), coin(10_000, DENOM_LS_ATOM_ON_NTRN)); + suite.expire_lockup_config(); + suite.tick_contract(suite.holder.clone()); + let contract_state = suite.query_contract_state(); + assert!(matches!(contract_state, ContractState::Expired{})); + + suite.tick_contract(suite.holder.clone()); + suite.assert_balance(suite.holder.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN)); + + suite.tick_contract(suite.holder.clone()); + let contract_state = suite.query_contract_state(); + assert!(matches!(contract_state, ContractState::Complete{})); + + let refund_config = suite.query_refund_config(); + suite.assert_balance(refund_config.party_b_refund_address, coin(10_000, DENOM_LS_ATOM_ON_NTRN)); } @@ -119,6 +195,22 @@ fn test_execute_expired_no_refund_completes() { assert!(matches!(contract_state, ContractState::Complete{})); } +#[test] +fn test_execute_tick_on_complete_noop() { + let mut suite = SwapHolderBuilder::default().build(); + + suite.expire_lockup_config(); + suite.tick_contract(suite.holder.clone()); + suite.tick_contract(suite.holder.clone()); + + let contract_state = suite.query_contract_state(); + assert!(matches!(contract_state, ContractState::Complete{})); + + suite.tick_contract(suite.holder.clone()).assert_event( + &Event::new("wasm").add_attribute("contract_state", "completed") + ); +} + #[test] fn test_migrate_update_config() { let mut suite = SwapHolderBuilder::default().build(); @@ -133,7 +225,10 @@ fn test_migrate_update_config() { party_b_amount: Uint128::one(), }); let new_expiration = Expiration::AtHeight(192837465); - + let new_refund_config = RefundConfig { + party_a_refund_address: clock_address.to_string(), + party_b_refund_address: clock_address.to_string(), + }; let resp = suite.app.migrate_contract( Addr::unchecked(ADMIN), suite.holder.clone(), @@ -143,6 +238,7 @@ fn test_migrate_update_config() { lockup_config: Some(new_expiration.clone()), parites_config: Box::new(Some(parties_config.clone())), covenant_terms: Some(new_covenant_terms.clone()), + refund_config: Some(new_refund_config.clone()) }, 4, ) @@ -154,6 +250,7 @@ fn test_migrate_update_config() { .add_attribute("lockup_config", new_expiration.to_string()) .add_attribute("parites_config", format!("{parties_config:?}")) .add_attribute("covenant_terms", format!("{new_covenant_terms:?}")) + .add_attribute("refund_config", format!("{new_refund_config:?}")) ); assert_eq!(suite.query_clock_address(), next_contract); @@ -161,4 +258,26 @@ fn test_migrate_update_config() { assert_eq!(suite.query_contract_state(), ContractState::Instantiated{}); assert_eq!(suite.query_covenant_parties_config().party_a.native_denom, "new_native_denom"); assert_eq!(suite.query_covenant_terms(), new_covenant_terms); + assert_eq!(suite.query_refund_config(), new_refund_config); +} + + +#[test] +#[should_panic(expected = "lockup config is already past")] +fn test_migrate_update_config_validates_lockup_config_expiration() { + let mut suite = SwapHolderBuilder::default().build(); + suite.app.migrate_contract( + Addr::unchecked(ADMIN), + suite.holder.clone(), + &covenant_swap_holder::msg::MigrateMsg::UpdateConfig { + clock_addr: None, + next_contract: None, + lockup_config: Some(Expiration::AtHeight(1)), + parites_config: Box::new(None), + covenant_terms: None, + refund_config: None, + }, + 4, + ) + .unwrap(); } \ No newline at end of file From 5f41d28e080c40f414889e4ca7b58f80799ca7c6 Mon Sep 17 00:00:00 2001 From: bekauz Date: Sun, 17 Mar 2024 16:05:31 +0100 Subject: [PATCH 20/56] using verify_clock to validate clock address in swap holder --- Cargo.lock | 1 + contracts/swap-holder/Cargo.toml | 1 + contracts/swap-holder/src/contract.rs | 9 +++------ contracts/swap-holder/src/error.rs | 4 ++++ contracts/swap-holder/src/suite_tests/tests.rs | 13 ++++++------- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55774e2c..179aa1fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -815,6 +815,7 @@ dependencies = [ "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "cw2 1.1.2", + "neutron-sdk", "serde", "thiserror", ] diff --git a/contracts/swap-holder/Cargo.toml b/contracts/swap-holder/Cargo.toml index 6a6461d3..abb2cd78 100644 --- a/contracts/swap-holder/Cargo.toml +++ b/contracts/swap-holder/Cargo.toml @@ -28,6 +28,7 @@ thiserror = { workspace = true } covenant-macros = { workspace = true } covenant-utils = { workspace = true } cosmos-sdk-proto = { workspace = true } +neutron-sdk = { workspace = true } [dev-dependencies] cw-multi-test = { workspace = true } diff --git a/contracts/swap-holder/src/contract.rs b/contracts/swap-holder/src/contract.rs index 82fa5197..5fdd2219 100644 --- a/contracts/swap-holder/src/contract.rs +++ b/contracts/swap-holder/src/contract.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - ensure, to_json_binary, Addr, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint128 + to_json_binary, Addr, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint128 }; use covenant_utils::CovenantTerms; @@ -12,7 +12,7 @@ use crate::{ }; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use covenant_clock::helpers::enqueue_msg; +use covenant_clock::helpers::{enqueue_msg, verify_clock}; use cw2::set_contract_version; const CONTRACT_NAME: &str = "crates.io:covenant-swap-holder"; @@ -67,10 +67,7 @@ pub fn execute( /// attempts to advance the state machine. performs `info.sender` validation fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> Result { // Verify caller is the clock - ensure!( - info.sender == CLOCK_ADDRESS.load(deps.storage)?, - ContractError::Unauthorized {} - ); + verify_clock(&info.sender, &CLOCK_ADDRESS.load(deps.storage)?)?; let current_state = CONTRACT_STATE.load(deps.storage)?; match current_state { diff --git a/contracts/swap-holder/src/error.rs b/contracts/swap-holder/src/error.rs index bf088149..899a4ae5 100644 --- a/contracts/swap-holder/src/error.rs +++ b/contracts/swap-holder/src/error.rs @@ -1,4 +1,5 @@ use cosmwasm_std::StdError; +use neutron_sdk::NeutronError; use thiserror::Error; #[derive(Error, Debug)] @@ -6,6 +7,9 @@ pub enum ContractError { #[error("{0}")] Std(#[from] StdError), + #[error(transparent)] + NeutronError(#[from] NeutronError), + #[error("Unauthorized")] Unauthorized {}, diff --git a/contracts/swap-holder/src/suite_tests/tests.rs b/contracts/swap-holder/src/suite_tests/tests.rs index 823e81ac..3fc3f248 100644 --- a/contracts/swap-holder/src/suite_tests/tests.rs +++ b/contracts/swap-holder/src/suite_tests/tests.rs @@ -1,11 +1,10 @@ -use cosmwasm_std::{Addr, Coin, Timestamp, Uint128}; +use cosmwasm_std::{Coin, Timestamp, Uint128}; use covenant_utils::{ CovenantPartiesConfig, CovenantParty, CovenantTerms, ReceiverConfig, SwapCovenantTerms, }; use cw_utils::Expiration; use crate::{ - error::ContractError, msg::ContractState, suite_tests::suite::{ DENOM_A, DENOM_B, INITIAL_BLOCK_HEIGHT, INITIAL_BLOCK_NANOS, PARTY_A_ADDR, PARTY_B_ADDR, @@ -67,12 +66,12 @@ fn test_instantiate_past_lockup_block_time() { } #[test] +#[should_panic(expected = "Caller is not the clock, only clock can tick contracts")] fn test_tick_unauthorized() { - let mut suite = SuiteBuilder::default().build(); - println!("{}", suite.app.block_info().height); - let resp = suite.tick("not-the-clock").unwrap_err().downcast().unwrap(); - - assert!(matches!(resp, ContractError::Unauthorized {})) + SuiteBuilder::default() + .build() + .tick("not-the-clock") + .unwrap(); } #[test] From 67298055a7b35c003fdaa472b6e0f421ae7f0e8c Mon Sep 17 00:00:00 2001 From: bekauz Date: Sun, 17 Mar 2024 17:01:36 +0100 Subject: [PATCH 21/56] two party holder migration split validation --- .../two-party-pol-holder/src/contract.rs | 8 +- contracts/two-party-pol-holder/src/msg.rs | 1 + unit-tests/src/test_swap_holder/tests.rs | 2 +- .../src/test_two_party_pol_holder/tests.rs | 180 +++++++++++++++++- 4 files changed, 186 insertions(+), 5 deletions(-) diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index 7202cc23..95650258 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -645,10 +645,14 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult if let Some(config) = *covenant_config { COVENANT_CONFIG.save(deps.storage, &config)?; - resp = resp.add_attribute("todo", "todo"); + resp = resp.add_attribute("covenant_config", format!("{:?}", config)); } if let Some(splits) = denom_splits { + for (_, config) in &splits { + config.validate_shares_and_receiver_addresses(deps.api)?; + } + resp = resp.add_attribute("explicit_splist", format!("{:?}", splits)); DENOM_SPLITS.update(deps.storage, |mut current_splits| -> StdResult<_> { current_splits.explicit_splits = splits; Ok(current_splits) @@ -656,6 +660,8 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult } if let Some(split) = fallback_split { + split.validate_shares_and_receiver_addresses(deps.api)?; + resp = resp.add_attribute("fallback_split", format!("{:?}", split)); DENOM_SPLITS.update(deps.storage, |mut current_splits| -> StdResult<_> { current_splits.fallback_split = Some(split); Ok(current_splits) diff --git a/contracts/two-party-pol-holder/src/msg.rs b/contracts/two-party-pol-holder/src/msg.rs index 1a8aeb37..cff8e753 100644 --- a/contracts/two-party-pol-holder/src/msg.rs +++ b/contracts/two-party-pol-holder/src/msg.rs @@ -78,6 +78,7 @@ impl InstantiateMsg { ]; attrs.extend(self.ragequit_config.get_response_attributes()); attrs.extend(splits_attr); + attrs.extend(self.covenant_config.get_response_attributes()); attrs } } diff --git a/unit-tests/src/test_swap_holder/tests.rs b/unit-tests/src/test_swap_holder/tests.rs index 74633ea2..c13c7899 100644 --- a/unit-tests/src/test_swap_holder/tests.rs +++ b/unit-tests/src/test_swap_holder/tests.rs @@ -49,7 +49,7 @@ fn test_instantiate_validates_party_b_refund_addr() { } #[test] -#[should_panic(expected = "Unauthorized")] +#[should_panic(expected = "Caller is not the clock, only clock can tick contracts")] fn test_execute_tick_validates_clock() { let mut suite = SwapHolderBuilder::default().build(); diff --git a/unit-tests/src/test_two_party_pol_holder/tests.rs b/unit-tests/src/test_two_party_pol_holder/tests.rs index c359903e..efa0df4a 100644 --- a/unit-tests/src/test_two_party_pol_holder/tests.rs +++ b/unit-tests/src/test_two_party_pol_holder/tests.rs @@ -1,14 +1,13 @@ use std::{collections::BTreeMap, str::FromStr}; -use cosmwasm_std::{coin, Addr, Decimal, Event, Timestamp, Uint128}; +use cosmwasm_std::{coin, coins, Addr, Decimal, Event, Timestamp, Uint128}; use covenant_two_party_pol_holder::msg::{ContractState, RagequitConfig, RagequitTerms}; use covenant_utils::split::SplitConfig; use cw_multi_test::Executor; use cw_utils::Expiration; use crate::setup::{ - base_suite::{BaseSuite, BaseSuiteMut}, - ADMIN, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, + base_suite::{BaseSuite, BaseSuiteMut}, ADMIN, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK, DENOM_LS_ATOM_ON_NTRN }; use super::suite::TwoPartyHolderBuilder; @@ -631,6 +630,54 @@ fn test_execute_emergency_withdraw_happy() { assert!(matches!(suite.query_contract_state(), ContractState::Complete{})); } +#[test] +#[should_panic(expected = "unauthorized to distribute explicitly defined denom")] +fn test_distribute_fallback_validates_denoms() { + let mut suite = TwoPartyHolderBuilder::default().build(); + let sender = suite.clock_addr.to_string(); + suite.distribute_fallback_split(&sender, vec![DENOM_ATOM_ON_NTRN.to_string()]); +} + +#[test] +fn test_distribute_fallback_with_no_fallback_split_noop_happy() { + let mut suite = TwoPartyHolderBuilder::default().build(); + let sender = suite.clock_addr.to_string(); + + suite.fund_contract(&coins(1_000_000, DENOM_FALLBACK), suite.holder_addr.clone()); + + suite.distribute_fallback_split(&sender, vec![DENOM_FALLBACK.to_string()]); + + suite.assert_balance(suite.holder_addr.to_string(), coin(1_000_000, DENOM_FALLBACK)); +} + + +#[test] +fn test_distribute_fallback_happy() { + let mut builder = TwoPartyHolderBuilder::default(); + let router_a_addr = builder.instantiate_msg.msg.covenant_config.party_a.router.to_string(); + let router_b_addr = builder.instantiate_msg.msg.covenant_config.party_b.router.to_string(); + builder.instantiate_msg.msg.fallback_split = Some(SplitConfig { + receivers: vec![ + (router_a_addr.to_string(), Decimal::percent(50)), + (router_b_addr.to_string(), Decimal::percent(50)), + ] + .into_iter() + .collect(), + }); + + let mut suite = builder.build(); + + let sender = suite.clock_addr.to_string(); + + suite.fund_contract(&coins(1_000_000, DENOM_FALLBACK), suite.holder_addr.clone()); + + suite.distribute_fallback_split(&sender, vec![DENOM_FALLBACK.to_string()]); + + suite.assert_balance(suite.holder_addr.to_string(), coin(0, DENOM_FALLBACK)); + suite.assert_balance(router_a_addr, coin(500_000, DENOM_FALLBACK)); + suite.assert_balance(router_b_addr, coin(500_000, DENOM_FALLBACK)); +} + #[test] fn test_migrate_update_config() { let mut suite = TwoPartyHolderBuilder::default().build(); @@ -692,3 +739,130 @@ fn test_migrate_update_config() { assert_eq!(clock, new_next_contract); assert_eq!(clock, emergency_committee); } + +#[test] +#[should_panic] +fn test_migrate_update_config_invalid_fallback_split() { + let mut suite = TwoPartyHolderBuilder::default().build(); + + let denom_splits = suite.query_denom_splits(); + let mut receivers = denom_splits + .explicit_splits + .get(DENOM_ATOM_ON_NTRN) + .unwrap() + .clone() + .receivers; + let mut receiver = receivers.pop_first().unwrap(); + receiver.1 = Decimal::zero(); + receivers.insert(receiver.0, receiver.1); + + suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + suite.holder_addr.clone(), + &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + clock_addr: None, + next_contract: None, + emergency_committee: None, + lockup_config: None, + deposit_deadline: None, + ragequit_config: Box::new(None), + covenant_config: Box::new(None), + denom_splits: None, + fallback_split: Some(SplitConfig { + receivers + }), + }, + 13, + ) + .unwrap(); +} + +#[test] +#[should_panic] +fn test_migrate_update_config_invalid_explicit_splits() { + let mut suite = TwoPartyHolderBuilder::default().build(); + + let mut explicit_splits = suite.query_denom_splits() + .explicit_splits + .clone(); + + let mut receivers = explicit_splits + .get(DENOM_ATOM_ON_NTRN) + .unwrap() + .clone() + .receivers; + + let mut receiver = receivers.pop_first().unwrap(); + receiver.1 = Decimal::zero(); + receivers.insert(receiver.0, receiver.1); + + explicit_splits.insert(DENOM_ATOM_ON_NTRN.to_string(), SplitConfig { receivers }); + + suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + suite.holder_addr.clone(), + &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + clock_addr: None, + next_contract: None, + emergency_committee: None, + lockup_config: None, + deposit_deadline: None, + ragequit_config: Box::new(None), + covenant_config: Box::new(None), + denom_splits: Some(explicit_splits), + fallback_split: None, + }, + 13, + ) + .unwrap(); +} + +#[test] +#[should_panic(expected = "lockup config is already past")] +fn test_migrate_update_config_validates_lockup_config_expiration() { + let mut suite = TwoPartyHolderBuilder::default().build(); + suite.app.migrate_contract( + Addr::unchecked(ADMIN), + suite.holder_addr.clone(), + &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + clock_addr: None, + next_contract: None, + emergency_committee: None, + lockup_config: Some(Expiration::AtHeight(1)), + deposit_deadline: None, + ragequit_config: Box::new(None), + covenant_config: Box::new(None), + denom_splits: None, + fallback_split: None, + }, + 13, + ) + .unwrap(); +} + +#[test] +#[should_panic(expected = "deposit deadline is already past")] +fn test_migrate_update_config_validates_deposit_deadline_expiration() { + let mut suite = TwoPartyHolderBuilder::default().build(); + suite.app.migrate_contract( + Addr::unchecked(ADMIN), + suite.holder_addr.clone(), + &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + clock_addr: None, + next_contract: None, + emergency_committee: None, + lockup_config: None, + deposit_deadline: Some(Expiration::AtHeight(1)), + ragequit_config: Box::new(None), + covenant_config: Box::new(None), + denom_splits: None, + fallback_split: None, + }, + 13, + ) + .unwrap(); +} \ No newline at end of file From 072d9c75dad633774bbb797e4182b3b7dfa1e36b Mon Sep 17 00:00:00 2001 From: bekauz Date: Sun, 17 Mar 2024 18:42:58 +0100 Subject: [PATCH 22/56] swap and two party covenant conditional ibc forwarder instantiate2 config derivation --- contracts/swap-covenant/src/contract.rs | 45 +++++++++--------- .../two-party-pol-covenant/src/contract.rs | 47 ++++++++++--------- .../two-party-pol-holder/src/contract.rs | 2 +- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index 7a459422..e4a006ed 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -42,9 +42,9 @@ pub fn instantiate( ) -> Result { deps.api.debug("WASMDEBUG: instantiate"); set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + let mut resp = Response::default().add_attribute("method", "instantiate_swap_covenant"); let creator_address = deps.api.addr_canonicalize(env.contract.address.as_str())?; - let covenant_denoms: BTreeSet = msg.splits.keys().map(|k| k.to_string()).collect(); // first we generate the instantiate2 addresses for each contract @@ -78,18 +78,6 @@ pub fn instantiate( &creator_address, msg.contract_codes.splitter_code, )?; - let party_a_forwarder_instantiate2_config = get_instantiate2_salt_and_address( - deps.as_ref(), - PARTY_A_FORWARDER_SALT, - &creator_address, - msg.contract_codes.ibc_forwarder_code, - )?; - let party_b_forwarder_instantiate2_config = get_instantiate2_salt_and_address( - deps.as_ref(), - PARTY_B_FORWARDER_SALT, - &creator_address, - msg.contract_codes.ibc_forwarder_code, - )?; CONTRACT_CODES.save( deps.storage, @@ -196,6 +184,12 @@ pub fn instantiate( // its deposit address will be the holder contract. no // extra actions are neeed for that. if let CovenantPartyConfig::Interchain(config) = &msg.party_a_config { + let party_a_forwarder_instantiate2_config = get_instantiate2_salt_and_address( + deps.as_ref(), + PARTY_A_FORWARDER_SALT, + &creator_address, + msg.contract_codes.ibc_forwarder_code, + )?; // store its forwarder contract address PARTY_A_IBC_FORWARDER_ADDR .save(deps.storage, &party_a_forwarder_instantiate2_config.addr)?; @@ -219,6 +213,10 @@ pub fn instantiate( format!("{}_party_a_ibc_forwarder", msg.label), )?; messages.push(instantiate_msg); + resp = resp.add_attribute( + "party_a_ibc_forwarder_address", + party_a_forwarder_instantiate2_config.addr.to_string(), + ); } // if party B is an interchain party, we include it in the @@ -226,6 +224,12 @@ pub fn instantiate( // its deposit address will be the holder contract. no // extra actions are neeed for that. if let CovenantPartyConfig::Interchain(config) = &msg.party_b_config { + let party_b_forwarder_instantiate2_config = get_instantiate2_salt_and_address( + deps.as_ref(), + PARTY_B_FORWARDER_SALT, + &creator_address, + msg.contract_codes.ibc_forwarder_code, + )?; // store its forwarder contract address PARTY_B_IBC_FORWARDER_ADDR .save(deps.storage, &party_b_forwarder_instantiate2_config.addr)?; @@ -249,6 +253,10 @@ pub fn instantiate( format!("{}_party_b_ibc_forwarder", msg.label), )?; messages.push(instantiate_msg); + resp = resp.add_attribute( + "party_b_ibc_forwarder_address", + party_b_forwarder_instantiate2_config.addr.to_string(), + ); } // include the clock in instantiation flow @@ -273,8 +281,7 @@ pub fn instantiate( COVENANT_INTERCHAIN_SPLITTER_ADDR.save(deps.storage, &splitter_instantiate2_config.addr)?; COVENANT_SWAP_HOLDER_ADDR.save(deps.storage, &holder_instantiate2_config.addr)?; - Ok(Response::default() - .add_attribute("method", "instantiate_swap_covenant") + Ok(resp .add_attribute("clock_address", clock_instantiate2_config.addr.to_string()) .add_attribute( "party_a_router_address", @@ -292,14 +299,6 @@ pub fn instantiate( "splitter_address", splitter_instantiate2_config.addr.to_string(), ) - .add_attribute( - "party_a_ibc_forwarder_address", - party_a_forwarder_instantiate2_config.addr.to_string(), - ) - .add_attribute( - "party_b_ibc_forwarder_address", - party_b_forwarder_instantiate2_config.addr.to_string(), - ) .add_attribute("instantiation_messages", to_json_string(&messages)?) .add_messages(messages)) } diff --git a/contracts/two-party-pol-covenant/src/contract.rs b/contracts/two-party-pol-covenant/src/contract.rs index 5590b5ba..5ceca0ca 100644 --- a/contracts/two-party-pol-covenant/src/contract.rs +++ b/contracts/two-party-pol-covenant/src/contract.rs @@ -43,6 +43,7 @@ pub fn instantiate( msg: InstantiateMsg, ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + let mut resp = Response::default().add_attribute("method", "instantiate"); let creator_address: CanonicalAddr = deps.api.addr_canonicalize(env.contract.address.as_str())?; @@ -72,18 +73,6 @@ pub fn instantiate( &creator_address, msg.contract_codes.holder_code, )?; - let party_a_forwarder_instantiate2_config = get_instantiate2_salt_and_address( - deps.as_ref(), - PARTY_A_FORWARDER_SALT, - &creator_address, - msg.contract_codes.ibc_forwarder_code, - )?; - let party_b_forwarder_instantiate2_config = get_instantiate2_salt_and_address( - deps.as_ref(), - PARTY_B_FORWARDER_SALT, - &creator_address, - msg.contract_codes.ibc_forwarder_code, - )?; let liquid_pooler_instantiate2_config = get_instantiate2_salt_and_address( deps.as_ref(), LIQUID_POOLER_SALT, @@ -175,6 +164,12 @@ pub fn instantiate( ]; if let CovenantPartyConfig::Interchain(config) = &msg.party_a_config { + let party_a_forwarder_instantiate2_config = get_instantiate2_salt_and_address( + deps.as_ref(), + PARTY_A_FORWARDER_SALT, + &creator_address, + msg.contract_codes.ibc_forwarder_code, + )?; PARTY_A_IBC_FORWARDER_ADDR .save(deps.storage, &party_a_forwarder_instantiate2_config.addr)?; clock_whitelist.push(party_a_forwarder_instantiate2_config.addr.to_string()); @@ -194,9 +189,19 @@ pub fn instantiate( env.contract.address.to_string(), format!("{}_party_a_ibc_forwarder", msg.label), )?); + resp = resp.add_attribute( + "party_a_forwarder_addr", + party_a_forwarder_instantiate2_config.addr, + ); } if let CovenantPartyConfig::Interchain(config) = &msg.party_b_config { + let party_b_forwarder_instantiate2_config = get_instantiate2_salt_and_address( + deps.as_ref(), + PARTY_B_FORWARDER_SALT, + &creator_address, + msg.contract_codes.ibc_forwarder_code, + )?; PARTY_B_IBC_FORWARDER_ADDR .save(deps.storage, &party_b_forwarder_instantiate2_config.addr)?; clock_whitelist.push(party_b_forwarder_instantiate2_config.addr.to_string()); @@ -216,6 +221,10 @@ pub fn instantiate( env.contract.address.to_string(), format!("{}_party_b_ibc_forwarder", msg.label), )?); + resp = resp.add_attribute( + "party_b_forwarder_addr", + party_b_forwarder_instantiate2_config.addr, + ); } let clock_instantiate2_msg = covenant_clock::msg::InstantiateMsg { @@ -243,8 +252,7 @@ pub fn instantiate( PARTY_A_ROUTER_ADDR.save(deps.storage, &party_a_router_instantiate2_config.addr)?; COVENANT_CLOCK_ADDR.save(deps.storage, &clock_instantiate2_config.addr)?; - Ok(Response::default() - .add_attribute("method", "instantiate") + Ok(resp .add_attribute("clock_addr", clock_instantiate2_config.addr) .add_attribute("liquid_pooler_addr", liquid_pooler_instantiate2_config.addr) .add_attribute( @@ -256,15 +264,8 @@ pub fn instantiate( party_b_router_instantiate2_config.addr, ) .add_attribute("holder_addr", holder_instantiate2_config.addr) - .add_attribute( - "party_a_forwarder_addr", - party_a_forwarder_instantiate2_config.addr, - ) - .add_attribute( - "party_b_forwarder_addr", - party_b_forwarder_instantiate2_config.addr, - ) - .add_messages(messages)) + .add_messages(messages) + ) } #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index 95650258..6f6b8ff7 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -652,7 +652,7 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult for (_, config) in &splits { config.validate_shares_and_receiver_addresses(deps.api)?; } - resp = resp.add_attribute("explicit_splist", format!("{:?}", splits)); + resp = resp.add_attribute("explicit_splits", format!("{:?}", splits)); DENOM_SPLITS.update(deps.storage, |mut current_splits| -> StdResult<_> { current_splits.explicit_splits = splits; Ok(current_splits) From 36618bfa1a1f8a05c3cdd1446490ddab9344020d Mon Sep 17 00:00:00 2001 From: bekauz Date: Sun, 17 Mar 2024 19:05:22 +0100 Subject: [PATCH 23/56] two party holder dequeues on completion --- .../two-party-pol-holder/src/contract.rs | 38 +++++++++++-------- .../src/test_two_party_pol_holder/tests.rs | 7 +++- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index 6f6b8ff7..b9fd0bbe 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -172,10 +172,14 @@ fn try_claim(deps: DepsMut, info: MessageInfo) -> Result Result, mut covenant_config: TwoPartyPolCovenantConfig, denom_splits: DenomSplits, ) -> Result { - let messages = denom_splits + let mut messages = denom_splits .get_single_receiver_distribution_messages(funds, claim_party.router.to_string()); claim_party.allocation = Decimal::zero(); @@ -327,7 +331,9 @@ fn try_claim_share_based( counterparty.allocation = Decimal::one(); } else { // otherwise both parties claimed everything and we can complete - CONTRACT_STATE.save(deps.storage, &ContractState::Complete)?; + let clock_address = CLOCK_ADDRESS.load(deps.storage)?; + let dequeue_message = ContractState::complete_and_dequeue(deps.branch(), clock_address.as_str())?; + messages.push(dequeue_message.into()); }; covenant_config.update_parties(claim_party, counterparty); @@ -354,13 +360,16 @@ fn try_claim_side_based( counterparty.allocation = Decimal::zero(); covenant_config.update_parties(claim_party, counterparty); - // update the states + // update the states and dequeue from the clock COVENANT_CONFIG.save(deps.storage, &covenant_config)?; - CONTRACT_STATE.save(deps.storage, &ContractState::Complete)?; + let clock_address = CLOCK_ADDRESS.load(deps.storage)?; + let dequeue_message = ContractState::complete_and_dequeue(deps, clock_address.as_str())?; Ok(Response::default() .add_attribute("method", "claim_side_based") - .add_messages(messages)) + .add_messages(messages) + .add_message(dequeue_message) + ) } fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> Result { @@ -372,12 +381,11 @@ fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> Result try_deposit(deps, env, info, clock_addr.as_str()), ContractState::Active => check_expiration(deps, env), + ContractState::Expired | + ContractState::Ragequit | ContractState::Complete => Ok(Response::default() .add_attribute("method", "tick") .add_attribute("contract_state", state.to_string())), - ContractState::Expired | ContractState::Ragequit => Ok(Response::default() - .add_attribute("method", "tick") - .add_attribute("contract_state", state.to_string())), } } @@ -407,14 +415,13 @@ fn try_deposit( // it is important to trigger this method before the expiry block // if deposit deadline is due we complete and refund if deposit_deadline.is_expired(&env.block) { + let dequeue_message = ContractState::complete_and_dequeue(deps.branch(), clock_addr)?; let refund_messages: Vec = match (party_a_bal.amount.is_zero(), party_b_bal.amount.is_zero()) { // both balances empty, we complete (true, true) => { - let msg = ContractState::complete_and_dequeue(deps.branch(), clock_addr)?; - return Ok(Response::default() - .add_message(msg) + .add_message(dequeue_message) .add_attribute("method", "try_deposit") .add_attribute("state", "complete")); } @@ -443,7 +450,8 @@ fn try_deposit( return Ok(Response::default() .add_attribute("method", "try_deposit") .add_attribute("action", "refund") - .add_messages(refund_messages)); + .add_messages(refund_messages) + .add_message(dequeue_message)); } if !party_a_fulfilled || !party_b_fulfilled { diff --git a/unit-tests/src/test_two_party_pol_holder/tests.rs b/unit-tests/src/test_two_party_pol_holder/tests.rs index efa0df4a..afdb92ff 100644 --- a/unit-tests/src/test_two_party_pol_holder/tests.rs +++ b/unit-tests/src/test_two_party_pol_holder/tests.rs @@ -253,6 +253,8 @@ fn test_execute_tick_expired_deposit_refunds_both_parties() { &suite.covenant_config.party_b.router, coin(10_000, DENOM_LS_ATOM_ON_NTRN), ); + + assert!(matches!(suite.query_contract_state(), ContractState::Complete {})); } #[test] @@ -275,6 +277,7 @@ fn test_execute_tick_expired_deposit_refunds_party_a() { coin(10_000, DENOM_ATOM_ON_NTRN), ); suite.assert_balance(suite.holder_addr.clone(), coin(0, DENOM_ATOM_ON_NTRN)); + assert!(matches!(suite.query_contract_state(), ContractState::Complete {})); } #[test] @@ -297,6 +300,7 @@ fn test_execute_tick_expired_deposit_refunds_party_b() { coin(10_000, DENOM_LS_ATOM_ON_NTRN), ); suite.assert_balance(&suite.holder_addr.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN)); + assert!(matches!(suite.query_contract_state(), ContractState::Complete {})); } #[test] @@ -308,8 +312,7 @@ fn test_execute_tick_expired_deposit_completes() { .add_attribute("method", "try_deposit") .add_attribute("state", "complete"), ); - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Complete {}); + assert!(matches!(suite.query_contract_state(), ContractState::Complete {})); } #[test] From ee820add17549ca439d3b62e0f7086c1e0aaeecb Mon Sep 17 00:00:00 2001 From: bekauz Date: Sun, 17 Mar 2024 21:12:05 +0100 Subject: [PATCH 24/56] removing commented code blocks from native router and single party holder --- contracts/native-router/src/contract.rs | 1 - contracts/single-party-pol-holder/src/state.rs | 8 -------- 2 files changed, 9 deletions(-) diff --git a/contracts/native-router/src/contract.rs b/contracts/native-router/src/contract.rs index e38a4b66..9f8f65a0 100644 --- a/contracts/native-router/src/contract.rs +++ b/contracts/native-router/src/contract.rs @@ -37,7 +37,6 @@ pub fn instantiate( .add_message(enqueue_msg(clock_addr.as_str())?) .add_attribute("method", "interchain_router_instantiate") .add_attribute("clock_address", clock_addr)) - // .add_attributes(destination_config.get_response_attributes())) } #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/single-party-pol-holder/src/state.rs b/contracts/single-party-pol-holder/src/state.rs index 9d033c57..edc43d34 100644 --- a/contracts/single-party-pol-holder/src/state.rs +++ b/contracts/single-party-pol-holder/src/state.rs @@ -12,11 +12,3 @@ pub const POOLER_ADDRESS: Item = Item::new("pool_address"); pub const LOCKUP_PERIOD: Item = Item::new("lockup_period"); /// The state of the withdraw process pub const WITHDRAW_STATE: Item = Item::new("withdraw_state"); - -// /// The state of a withdraw process -// /// When a claim is called, we sett the storage with `WithdrawState::Processing` -// /// We remove the state from storage when the withdraw is done or if it failed -// #[cw_serde] -// pub enum WithdrawState { -// Processing {}, -// } From 72711c87060c163c7ae81c135c76ec6145dd9b2f Mon Sep 17 00:00:00 2001 From: bekauz Date: Sun, 17 Mar 2024 21:21:27 +0100 Subject: [PATCH 25/56] removing debug messages --- .../astroport-liquid-pooler/src/contract.rs | 5 +--- contracts/clock/src/contract.rs | 2 -- contracts/ibc-forwarder/src/contract.rs | 10 +------- contracts/ibc-forwarder/src/sudo.rs | 12 ---------- contracts/interchain-router/src/contract.rs | 4 ---- contracts/native-router/src/contract.rs | 4 ---- contracts/native-router/src/lib.rs | 4 ---- contracts/native-splitter/src/contract.rs | 6 ----- .../remote-chain-splitter/src/contract.rs | 8 ------- contracts/remote-chain-splitter/src/sudo.rs | 13 ----------- .../single-party-pol-covenant/src/contract.rs | 1 - .../single-party-pol-holder/src/contract.rs | 5 +--- .../stride-liquid-staker/src/contract.rs | 23 ------------------- contracts/swap-covenant/src/contract.rs | 1 - contracts/swap-holder/src/contract.rs | 1 - .../swap-holder/src/suite_tests/suite.rs | 2 -- .../swap-holder/src/suite_tests/tests.rs | 2 -- .../two-party-pol-covenant/src/contract.rs | 1 - .../two-party-pol-holder/src/contract.rs | 1 - contracts/two-party-pol-holder/src/msg.rs | 1 - 20 files changed, 3 insertions(+), 103 deletions(-) diff --git a/contracts/astroport-liquid-pooler/src/contract.rs b/contracts/astroport-liquid-pooler/src/contract.rs index d30c7237..a68413d8 100644 --- a/contracts/astroport-liquid-pooler/src/contract.rs +++ b/contracts/astroport-liquid-pooler/src/contract.rs @@ -250,7 +250,7 @@ fn try_lp(mut deps: DepsMut, env: Env) -> Result { let pool_response: PoolResponse = deps .querier .query_wasm_smart(&lp_config.pool_address, &astroport::pair::QueryMsg::Pool {})?; - + let (pool_token_a_bal, pool_token_b_bal) = get_pool_asset_amounts( pool_response.assets, lp_config.asset_data.asset_a_denom.as_str(), @@ -484,8 +484,6 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> NeutronResult { - deps.api.debug("WASMDEBUG: migrate"); - match msg { MigrateMsg::UpdateConfig { clock_addr, @@ -524,7 +522,6 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> NeutronResult Result { - deps.api.debug("WASMDEBUG: reply"); match msg.id { DOUBLE_SIDED_REPLY_ID => handle_double_sided_reply_id(deps, _env, msg), SINGLE_SIDED_REPLY_ID => handle_single_sided_reply_id(deps, _env, msg), diff --git a/contracts/clock/src/contract.rs b/contracts/clock/src/contract.rs index 67222c41..f5e58a59 100644 --- a/contracts/clock/src/contract.rs +++ b/contracts/clock/src/contract.rs @@ -24,8 +24,6 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> Result { - deps.api.debug("WASMDEBUG: clock instantiate"); - let tick_max_gas = if let Some(tick_max_gas) = msg.tick_max_gas { // at least MIN_MAX_GAS, at most the relayer limit tick_max_gas.max(MIN_TICK_MAX_GAS).min(MAX_TICK_MAX_GAS) diff --git a/contracts/ibc-forwarder/src/contract.rs b/contracts/ibc-forwarder/src/contract.rs index b8948ba1..945d8139 100644 --- a/contracts/ibc-forwarder/src/contract.rs +++ b/contracts/ibc-forwarder/src/contract.rs @@ -175,7 +175,7 @@ fn try_forward_funds(env: Env, mut deps: ExecuteDeps) -> NeutronResult StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo: received sudo msg: {msg:?}").as_str()); - match msg { // For handling successful (non-error) acknowledgements. SudoMsg::Response { request, data } => sudo_response(deps, request, data), @@ -282,8 +279,6 @@ pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> StdResult StdResult> { - deps.api - .debug(format!("WASMDEBUG: reply msg: {msg:?}").as_str()); match msg.id { SUDO_PAYLOAD_REPLY_ID => prepare_sudo_payload(deps, env, msg), _ => Err(StdError::generic_err(format!( @@ -308,8 +303,6 @@ fn prepare_sudo_payload( .as_slice(), ) .map_err(|e| StdError::generic_err(format!("failed to parse response: {e:?}")))?; - deps.api - .debug(format!("WASMDEBUG: reply msg: {resp:?}").as_str()); let seq_id = resp.sequence_id; let channel_id = resp.channel; save_sudo_payload(deps.branch().storage, channel_id, seq_id, payload)?; @@ -332,7 +325,6 @@ pub fn save_sudo_payload( #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult> { - deps.api.debug("WASMDEBUG: migrate"); match msg { MigrateMsg::UpdateConfig { clock_addr, diff --git a/contracts/ibc-forwarder/src/sudo.rs b/contracts/ibc-forwarder/src/sudo.rs index 649b3e22..7f7d9685 100644 --- a/contracts/ibc-forwarder/src/sudo.rs +++ b/contracts/ibc-forwarder/src/sudo.rs @@ -50,9 +50,6 @@ pub fn sudo_response( request: RequestPacket, data: Binary, ) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo_response: sudo received: {request:?} {data:?}").as_str()); - // either of these errors will close the channel request .sequence @@ -70,9 +67,6 @@ pub fn sudo_timeout( _env: Env, request: RequestPacket, ) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo timeout request: {request:?}").as_str()); - // revert the state to Instantiated to force re-creation of ICA CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; @@ -85,12 +79,6 @@ pub fn sudo_error( request: RequestPacket, details: String, ) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo error: {details}").as_str()); - - deps.api - .debug(format!("WASMDEBUG: request packet: {request:?}").as_str()); - // either of these errors will close the channel request .sequence diff --git a/contracts/interchain-router/src/contract.rs b/contracts/interchain-router/src/contract.rs index 5845a058..3d65ab18 100644 --- a/contracts/interchain-router/src/contract.rs +++ b/contracts/interchain-router/src/contract.rs @@ -55,8 +55,6 @@ pub fn execute( info: MessageInfo, msg: ExecuteMsg, ) -> NeutronResult> { - deps.api - .debug(format!("WASMDEBUG: execute: received msg: {msg:?}").as_str()); match msg { ExecuteMsg::Tick {} => { // Verify caller is the clock @@ -179,8 +177,6 @@ pub fn migrate( _env: Env, msg: MigrateMsg, ) -> NeutronResult> { - deps.api.debug("WASMDEBUG: migrate"); - match msg { MigrateMsg::UpdateConfig { clock_addr, diff --git a/contracts/native-router/src/contract.rs b/contracts/native-router/src/contract.rs index 9f8f65a0..e3f1c67b 100644 --- a/contracts/native-router/src/contract.rs +++ b/contracts/native-router/src/contract.rs @@ -46,8 +46,6 @@ pub fn execute( info: MessageInfo, msg: ExecuteMsg, ) -> Result { - deps.api - .debug(format!("WASMDEBUG: execute: received msg: {msg:?}").as_str()); match msg { ExecuteMsg::Tick {} => { // Verify caller is the clock @@ -154,8 +152,6 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result { - deps.api.debug("WASMDEBUG: migrate"); - match msg { MigrateMsg::UpdateConfig { clock_addr, diff --git a/contracts/native-router/src/lib.rs b/contracts/native-router/src/lib.rs index 8ae28828..0faea8f4 100644 --- a/contracts/native-router/src/lib.rs +++ b/contracts/native-router/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)] -// mod suite_tests; diff --git a/contracts/native-splitter/src/contract.rs b/contracts/native-splitter/src/contract.rs index 21e9e08c..85297266 100644 --- a/contracts/native-splitter/src/contract.rs +++ b/contracts/native-splitter/src/contract.rs @@ -24,7 +24,6 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> Result { - deps.api.debug("WASMDEBUG: instantiate"); set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; let mut resp = Response::default().add_attribute("method", "native_splitter_instantiate"); @@ -61,9 +60,6 @@ pub fn execute( info: MessageInfo, msg: ExecuteMsg, ) -> Result { - deps.api - .debug(format!("WASMDEBUG: execute: received msg: {msg:?}").as_str()); - match msg { ExecuteMsg::Tick {} => { verify_clock(&info.sender, &CLOCK_ADDRESS.load(deps.storage)?) @@ -173,8 +169,6 @@ pub fn query_split(deps: Deps, denom: String) -> Result { #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result { - deps.api.debug("WASMDEBUG: migrate"); - match msg { MigrateMsg::UpdateConfig { clock_addr, diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index 4ba94bab..86de2a7b 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -87,8 +87,6 @@ pub fn execute( info: MessageInfo, msg: ExecuteMsg, ) -> NeutronResult> { - deps.api - .debug(format!("WASMDEBUG: execute: received msg: {msg:?}").as_str()); match msg { ExecuteMsg::Tick {} => try_tick(deps, env, info), } @@ -312,9 +310,6 @@ fn get_ica( #[cfg_attr(not(feature = "library"), entry_point)] pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo: received sudo msg: {msg:?}").as_str()); - match msg { // For handling successful (non-error) acknowledgements. SudoMsg::Response { request, data } => sudo_response(deps, request, data), @@ -342,7 +337,6 @@ pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> StdResult StdResult> { - deps.api.debug("WASMDEBUG: migrate"); match msg { MigrateMsg::UpdateConfig { clock_addr, @@ -394,8 +388,6 @@ pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult StdResult> { - deps.api - .debug(format!("WASMDEBUG: reply msg: {msg:?}").as_str()); match msg.id { SUDO_PAYLOAD_REPLY_ID => prepare_sudo_payload(deps, env, msg), _ => Err(StdError::generic_err(format!( diff --git a/contracts/remote-chain-splitter/src/sudo.rs b/contracts/remote-chain-splitter/src/sudo.rs index eab63a8b..7a3f4af2 100644 --- a/contracts/remote-chain-splitter/src/sudo.rs +++ b/contracts/remote-chain-splitter/src/sudo.rs @@ -53,9 +53,6 @@ pub fn sudo_response( request: RequestPacket, data: Binary, ) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo_response: sudo received: {request:?} {data:?}").as_str()); - // either of these errors will close the channel request .sequence @@ -73,9 +70,6 @@ pub fn sudo_timeout( _env: Env, request: RequestPacket, ) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo timeout request: {request:?}").as_str()); - // revert the state to Instantiated to force re-creation of ICA CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; @@ -88,11 +82,6 @@ pub fn sudo_error( request: RequestPacket, details: String, ) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo error: {details}").as_str()); - deps.api - .debug(format!("WASMDEBUG: request packet: {request:?}").as_str()); - // either of these errors will close the channel request .sequence @@ -120,8 +109,6 @@ pub fn prepare_sudo_payload( .as_slice(), ) .map_err(|e| StdError::generic_err(format!("failed to parse response: {e:?}")))?; - deps.api - .debug(format!("WASMDEBUG: reply msg: {resp:?}").as_str()); let seq_id = resp.sequence_id; let channel_id = resp.channel; save_sudo_payload(deps.branch().storage, channel_id, seq_id, payload)?; diff --git a/contracts/single-party-pol-covenant/src/contract.rs b/contracts/single-party-pol-covenant/src/contract.rs index 5e47f55b..5a21b21f 100644 --- a/contracts/single-party-pol-covenant/src/contract.rs +++ b/contracts/single-party-pol-covenant/src/contract.rs @@ -327,7 +327,6 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult { - deps.api.debug("WASMDEBUG: migrate"); match msg { MigrateMsg::MigrateContracts { codes, diff --git a/contracts/single-party-pol-holder/src/contract.rs b/contracts/single-party-pol-holder/src/contract.rs index 929401a3..48939e68 100644 --- a/contracts/single-party-pol-holder/src/contract.rs +++ b/contracts/single-party-pol-holder/src/contract.rs @@ -21,7 +21,6 @@ pub fn instantiate( msg: InstantiateMsg, ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - deps.api.debug("WASMDEBUG: holder instantiate"); let mut resp = Response::default().add_attribute("method", "instantiate"); // withdrawer is optional on instantiation; can be set later @@ -34,7 +33,7 @@ pub fn instantiate( WITHDRAW_TO.save(deps.storage, &deps.api.addr_validate(&addr)?)?; resp = resp.add_attribute("withdraw_to", addr); }; - + if let Some(addr) = msg.emergency_committee_addr { EMERGENCY_COMMITTEE_ADDR.save(deps.storage, &deps.api.addr_validate(&addr)?)?; resp = resp.add_attribute("emergency_committee", addr); @@ -158,8 +157,6 @@ fn try_withdraw_failed(deps: DepsMut, info: MessageInfo) -> Result Result { - deps.api.debug("WASMDEBUG: migrate"); - match msg { MigrateMsg::UpdateConfig { withdrawer, diff --git a/contracts/stride-liquid-staker/src/contract.rs b/contracts/stride-liquid-staker/src/contract.rs index 181da3ba..4f24ae62 100644 --- a/contracts/stride-liquid-staker/src/contract.rs +++ b/contracts/stride-liquid-staker/src/contract.rs @@ -43,7 +43,6 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> NeutronResult> { - deps.api.debug("WASMDEBUG: instantiate"); set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; // validate the addresses @@ -77,8 +76,6 @@ pub fn execute( info: MessageInfo, msg: ExecuteMsg, ) -> NeutronResult> { - deps.api - .debug(format!("WASMDEBUG: execute: received msg: {msg:?}").as_str()); match msg { ExecuteMsg::Tick {} => try_tick(deps, env, info), ExecuteMsg::Transfer { amount } => { @@ -279,9 +276,6 @@ fn _query_deposit_address(deps: Deps, env: Env) -> Result Result, StdError> { - deps.api - .debug(format!("WASMDEBUG: sudo: received sudo msg: {msg:?}").as_str()); - match msg { // For handling successful (non-error) acknowledgements. SudoMsg::Response { request, data } => sudo_response(deps, request, data), @@ -344,9 +338,6 @@ fn sudo_open_ack( } fn sudo_response(deps: ExecuteDeps, request: RequestPacket, data: Binary) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo_response: sudo received: {request:?} {data:?}",).as_str()); - // either of these errors will close the channel request .sequence @@ -360,9 +351,6 @@ fn sudo_response(deps: ExecuteDeps, request: RequestPacket, data: Binary) -> Std } fn sudo_timeout(deps: ExecuteDeps, _env: Env, request: RequestPacket) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo timeout request: {request:?}").as_str()); - // revert the state to Instantiated to force re-creation of ICA CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; @@ -371,11 +359,6 @@ fn sudo_timeout(deps: ExecuteDeps, _env: Env, request: RequestPacket) -> StdResu } fn sudo_error(deps: ExecuteDeps, request: RequestPacket, details: String) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: sudo error: {details}").as_str()); - deps.api - .debug(format!("WASMDEBUG: request packet: {request:?}").as_str()); - // either of these errors will close the channel request .sequence @@ -406,8 +389,6 @@ fn prepare_sudo_payload(mut deps: ExecuteDeps, _env: Env, msg: Reply) -> StdResu .as_slice(), ) .map_err(|e| StdError::generic_err(format!("failed to parse response: {e:?}")))?; - deps.api - .debug(format!("WASMDEBUG: reply msg: {resp:?}").as_str()); let seq_id = resp.sequence_id; let channel_id = resp.channel; save_sudo_payload(deps.branch().storage, channel_id, seq_id, payload)?; @@ -428,8 +409,6 @@ fn get_ica( #[cfg_attr(not(feature = "library"), entry_point)] pub fn reply(deps: ExecuteDeps, env: Env, msg: Reply) -> StdResult> { - deps.api - .debug(format!("WASMDEBUG: reply msg: {msg:?}").as_str()); match msg.id { SUDO_PAYLOAD_REPLY_ID => prepare_sudo_payload(deps, env, msg), _ => Err(StdError::generic_err(format!( @@ -441,8 +420,6 @@ pub fn reply(deps: ExecuteDeps, env: Env, msg: Reply) -> StdResult StdResult> { - deps.api.debug("WASMDEBUG: migrate"); - match msg { MigrateMsg::UpdateConfig { clock_addr, diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index e4a006ed..e908918c 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -40,7 +40,6 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> Result { - deps.api.debug("WASMDEBUG: instantiate"); set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; let mut resp = Response::default().add_attribute("method", "instantiate_swap_covenant"); diff --git a/contracts/swap-holder/src/contract.rs b/contracts/swap-holder/src/contract.rs index 5fdd2219..5ab5f369 100644 --- a/contracts/swap-holder/src/contract.rs +++ b/contracts/swap-holder/src/contract.rs @@ -225,7 +225,6 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult { - deps.api.debug("WASMDEBUG: migrate"); match msg { MigrateMsg::UpdateConfig { clock_addr, diff --git a/contracts/swap-holder/src/suite_tests/suite.rs b/contracts/swap-holder/src/suite_tests/suite.rs index 4b988210..6cedb16a 100644 --- a/contracts/swap-holder/src/suite_tests/suite.rs +++ b/contracts/swap-holder/src/suite_tests/suite.rs @@ -97,8 +97,6 @@ impl SuiteBuilder { .unwrap(); self.instantiate.clock_address = clock_address.to_string(); - println!("clock address: {clock_address:?}"); - let mock_deposit = app .instantiate_contract( mock_deposit_code, diff --git a/contracts/swap-holder/src/suite_tests/tests.rs b/contracts/swap-holder/src/suite_tests/tests.rs index 3fc3f248..a962a9d4 100644 --- a/contracts/swap-holder/src/suite_tests/tests.rs +++ b/contracts/swap-holder/src/suite_tests/tests.rs @@ -160,8 +160,6 @@ fn test_covenant_query_endpoint() { &covenant_utils::neutron::QueryMsg::DepositAddress {}, ) .unwrap(); - - println!("resp: {resp:?}"); } #[test] diff --git a/contracts/two-party-pol-covenant/src/contract.rs b/contracts/two-party-pol-covenant/src/contract.rs index 5ceca0ca..f534fdde 100644 --- a/contracts/two-party-pol-covenant/src/contract.rs +++ b/contracts/two-party-pol-covenant/src/contract.rs @@ -332,7 +332,6 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult { - deps.api.debug("WASMDEBUG: migrate"); match msg { MigrateMsg::UpdateCovenant { codes, diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index b9fd0bbe..43005705 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -597,7 +597,6 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult { - deps.api.debug("WASMDEBUG: migrate"); match msg { MigrateMsg::UpdateConfig { clock_addr, diff --git a/contracts/two-party-pol-holder/src/msg.rs b/contracts/two-party-pol-holder/src/msg.rs index cff8e753..a3f38940 100644 --- a/contracts/two-party-pol-holder/src/msg.rs +++ b/contracts/two-party-pol-holder/src/msg.rs @@ -492,7 +492,6 @@ impl RagequitConfig { } // then validate that rq penalty does not exceed either party allocations if terms.penalty > a_allocation || terms.penalty > b_allocation { - println!("huh"); return Err(ContractError::RagequitPenaltyExceedsPartyAllocationError {}); } From a56136034d6b1ebec312b8fe53b0e526c7f5f1f7 Mon Sep 17 00:00:00 2001 From: bekauz Date: Sun, 17 Mar 2024 21:35:55 +0100 Subject: [PATCH 26/56] removing todo!() macros --- contracts/remote-chain-splitter/src/contract.rs | 7 ++++++- contracts/swap-holder/src/contract.rs | 7 ++++++- contracts/two-party-pol-holder/src/contract.rs | 7 ++++++- unit-tests/src/setup/custom_module.rs | 16 ++++++++-------- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index 86de2a7b..e0f93ec2 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -382,7 +382,12 @@ pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult todo!(), + MigrateMsg::UpdateCodeId { data: _ } => { + // This is a migrate message to update code id, + // Data is optional base64 that we can parse to any data we would like in the future + // let data: SomeStruct = from_binary(&data)?; + Ok(Response::default()) + } } } diff --git a/contracts/swap-holder/src/contract.rs b/contracts/swap-holder/src/contract.rs index 5ab5f369..3dec380f 100644 --- a/contracts/swap-holder/src/contract.rs +++ b/contracts/swap-holder/src/contract.rs @@ -275,6 +275,11 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult Ok(resp) } - MigrateMsg::UpdateCodeId { data: _ } => todo!(), + MigrateMsg::UpdateCodeId { data: _ } => { + // This is a migrate message to update code id, + // Data is optional base64 that we can parse to any data we would like in the future + // let data: SomeStruct = from_binary(&data)?; + Ok(Response::default()) + } } } diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index 43005705..b1802ff0 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -677,6 +677,11 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult Ok(resp) } - MigrateMsg::UpdateCodeId { data: _ } => todo!(), + MigrateMsg::UpdateCodeId { data: _ } => { + // This is a migrate message to update code id, + // Data is optional base64 that we can parse to any data we would like in the future + // let data: SomeStruct = from_binary(&data)?; + Ok(Response::default()) + } } } diff --git a/unit-tests/src/setup/custom_module.rs b/unit-tests/src/setup/custom_module.rs index 434cdde0..24163a57 100644 --- a/unit-tests/src/setup/custom_module.rs +++ b/unit-tests/src/setup/custom_module.rs @@ -830,14 +830,14 @@ impl Module for NeutronKeeper { }) .unwrap() ), - NeutronQuery::InterchainQueryResult { .. } => todo!(), - NeutronQuery::RegisteredInterchainQueries { .. } => todo!(), - NeutronQuery::RegisteredInterchainQuery { .. } => todo!(), - NeutronQuery::TotalBurnedNeutronsAmount {} => todo!(), - NeutronQuery::FullDenom { .. } => todo!(), - NeutronQuery::DenomAdmin { .. } => todo!(), - NeutronQuery::BeforeSendHook { .. } => todo!(), - NeutronQuery::Failures { .. } => todo!(), + NeutronQuery::InterchainQueryResult { .. } => unimplemented!(), + NeutronQuery::RegisteredInterchainQueries { .. } => unimplemented!(), + NeutronQuery::RegisteredInterchainQuery { .. } => unimplemented!(), + NeutronQuery::TotalBurnedNeutronsAmount {} => unimplemented!(), + NeutronQuery::FullDenom { .. } => unimplemented!(), + NeutronQuery::DenomAdmin { .. } => unimplemented!(), + NeutronQuery::BeforeSendHook { .. } => unimplemented!(), + NeutronQuery::Failures { .. } => unimplemented!(), } } From 93d32654da5a670957947601d204076a410c6b75 Mon Sep 17 00:00:00 2001 From: bekauz Date: Sun, 17 Mar 2024 22:11:43 +0100 Subject: [PATCH 27/56] removing old tests --- Cargo.lock | 241 +---- contracts/astroport-liquid-pooler/Cargo.toml | 12 - contracts/astroport-liquid-pooler/src/lib.rs | 4 - .../src/suite_test/mod.rs | 2 - .../src/suite_test/suite.rs | 653 -------------- .../src/suite_test/tests.rs | 206 ----- contracts/clock/Cargo.toml | 1 - contracts/ibc-forwarder/Cargo.toml | 4 - contracts/native-router/Cargo.toml | 5 - contracts/native-splitter/Cargo.toml | 4 - contracts/native-splitter/src/lib.rs | 4 - .../native-splitter/src/suite_test/mod.rs | 15 - .../native-splitter/src/suite_test/suite.rs | 176 ---- .../native-splitter/src/suite_test/tests.rs | 221 ----- contracts/osmo-liquid-pooler/Cargo.toml | 6 - contracts/remote-chain-splitter/src/lib.rs | 4 - .../src/suite_test/mod.rs | 2 - .../src/suite_test/suite.rs | 1 - .../src/suite_test/tests.rs | 1 - .../single-party-pol-covenant/Cargo.toml | 6 - contracts/single-party-pol-holder/Cargo.toml | 9 - contracts/single-party-pol-holder/src/lib.rs | 3 - .../src/suite_tests/mod.rs | 24 - .../src/suite_tests/suite.rs | 151 ---- .../src/suite_tests/tests.rs | 141 --- contracts/stride-liquid-staker/src/lib.rs | 4 - .../src/suite_test/mod.rs | 2 - .../src/suite_test/suite.rs | 1 - .../src/suite_test/tests.rs | 1 - contracts/swap-covenant/Cargo.toml | 6 - contracts/swap-covenant/src/lib.rs | 4 - contracts/swap-covenant/src/suite_test/mod.rs | 3 - .../swap-covenant/src/suite_test/suite.rs | 70 -- .../swap-covenant/src/suite_test/tests.rs | 1 - .../src/suite_test/unit_tests.rs | 1 - contracts/swap-holder/Cargo.toml | 4 - contracts/swap-holder/src/lib.rs | 3 - contracts/swap-holder/src/suite_tests/mod.rs | 50 -- .../swap-holder/src/suite_tests/suite.rs | 220 ----- .../swap-holder/src/suite_tests/tests.rs | 326 ------- contracts/two-party-pol-covenant/Cargo.toml | 6 - contracts/two-party-pol-holder/Cargo.toml | 4 - contracts/two-party-pol-holder/src/lib.rs | 3 - .../src/suite_tests/mod.rs | 132 --- .../src/suite_tests/suite.rs | 424 --------- .../src/suite_tests/tests.rs | 825 ------------------ unit-tests/Cargo.toml | 2 +- unit-tests/src/test.rs | 525 ----------- 48 files changed, 28 insertions(+), 4485 deletions(-) delete mode 100644 contracts/astroport-liquid-pooler/src/suite_test/mod.rs delete mode 100644 contracts/astroport-liquid-pooler/src/suite_test/suite.rs delete mode 100644 contracts/astroport-liquid-pooler/src/suite_test/tests.rs delete mode 100644 contracts/native-splitter/src/suite_test/mod.rs delete mode 100644 contracts/native-splitter/src/suite_test/suite.rs delete mode 100644 contracts/native-splitter/src/suite_test/tests.rs delete mode 100644 contracts/remote-chain-splitter/src/suite_test/mod.rs delete mode 100644 contracts/remote-chain-splitter/src/suite_test/suite.rs delete mode 100644 contracts/remote-chain-splitter/src/suite_test/tests.rs delete mode 100644 contracts/single-party-pol-holder/src/suite_tests/mod.rs delete mode 100644 contracts/single-party-pol-holder/src/suite_tests/suite.rs delete mode 100644 contracts/single-party-pol-holder/src/suite_tests/tests.rs delete mode 100644 contracts/stride-liquid-staker/src/suite_test/mod.rs delete mode 100644 contracts/stride-liquid-staker/src/suite_test/suite.rs delete mode 100644 contracts/stride-liquid-staker/src/suite_test/tests.rs delete mode 100644 contracts/swap-covenant/src/suite_test/mod.rs delete mode 100644 contracts/swap-covenant/src/suite_test/suite.rs delete mode 100644 contracts/swap-covenant/src/suite_test/tests.rs delete mode 100644 contracts/swap-covenant/src/suite_test/unit_tests.rs delete mode 100644 contracts/swap-holder/src/suite_tests/mod.rs delete mode 100644 contracts/swap-holder/src/suite_tests/suite.rs delete mode 100644 contracts/swap-holder/src/suite_tests/tests.rs delete mode 100644 contracts/two-party-pol-holder/src/suite_tests/mod.rs delete mode 100644 contracts/two-party-pol-holder/src/suite_tests/suite.rs delete mode 100644 contracts/two-party-pol-holder/src/suite_tests/tests.rs delete mode 100644 unit-tests/src/test.rs diff --git a/Cargo.lock b/Cargo.lock index 179aa1fd..63aa3cf3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,64 +28,20 @@ dependencies = [ "cosmwasm-std", "cw-storage-plus 0.15.1", "cw-utils 0.15.1", - "cw20 0.15.1", + "cw20", "itertools 0.10.5", "uint", ] -[[package]] -name = "astroport" -version = "3.9.0" -source = "git+https://github.com/astroport-fi/astroport-core.git#b08b4d86050f0c473673b363aa9a4e8e30cf7082" -dependencies = [ - "astroport-circular-buffer", - "cosmwasm-schema", - "cosmwasm-std", - "cw-asset", - "cw-storage-plus 0.15.1", - "cw-utils 1.0.3", - "cw20 0.15.1", - "cw3", - "itertools 0.10.5", - "uint", -] - -[[package]] -name = "astroport-circular-buffer" -version = "0.1.0" -source = "git+https://github.com/astroport-fi/astroport-core.git#b08b4d86050f0c473673b363aa9a4e8e30cf7082" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "thiserror", -] - [[package]] name = "astroport-factory" version = "1.5.1" source = "git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d#700f66d677a173686cb15cb9cb8c7a4d20c84ad8" dependencies = [ - "astroport 2.9.5", - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "cw2 0.15.1", - "itertools 0.10.5", - "protobuf 2.28.0", - "thiserror", -] - -[[package]] -name = "astroport-factory" -version = "1.6.0" -source = "git+https://github.com/astroport-fi/astroport-core.git#b08b4d86050f0c473673b363aa9a4e8e30cf7082" -dependencies = [ - "astroport 3.9.0", + "astroport", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 0.15.1", - "cw-utils 1.0.3", "cw2 0.15.1", "itertools 0.10.5", "protobuf 2.28.0", @@ -97,21 +53,7 @@ name = "astroport-native-coin-registry" version = "1.0.1" source = "git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d#700f66d677a173686cb15cb9cb8c7a4d20c84ad8" dependencies = [ - "astroport 2.9.5", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-storage-plus 0.15.1", - "cw2 0.15.1", - "thiserror", -] - -[[package]] -name = "astroport-native-coin-registry" -version = "1.0.1" -source = "git+https://github.com/astroport-fi/astroport-core.git#b08b4d86050f0c473673b363aa9a4e8e30cf7082" -dependencies = [ - "astroport 3.9.0", + "astroport", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", @@ -125,12 +67,12 @@ name = "astroport-pair" version = "1.3.3" source = "git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d#700f66d677a173686cb15cb9cb8c7a4d20c84ad8" dependencies = [ - "astroport 2.9.5", + "astroport", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 0.15.1", "cw2 0.15.1", - "cw20 0.15.1", + "cw20", "integer-sqrt", "protobuf 2.28.0", "thiserror", @@ -141,30 +83,13 @@ name = "astroport-pair-stable" version = "2.1.4" source = "git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d#700f66d677a173686cb15cb9cb8c7a4d20c84ad8" dependencies = [ - "astroport 2.9.5", - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "cw-utils 1.0.3", - "cw2 0.15.1", - "cw20 0.15.1", - "itertools 0.10.5", - "thiserror", -] - -[[package]] -name = "astroport-pair-stable" -version = "3.4.0" -source = "git+https://github.com/astroport-fi/astroport-core.git#b08b4d86050f0c473673b363aa9a4e8e30cf7082" -dependencies = [ - "astroport 3.9.0", - "astroport-circular-buffer", + "astroport", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 0.15.1", "cw-utils 1.0.3", "cw2 0.15.1", - "cw20 0.15.1", + "cw20", "itertools 0.10.5", "thiserror", ] @@ -174,25 +99,11 @@ name = "astroport-token" version = "1.1.1" source = "git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d#700f66d677a173686cb15cb9cb8c7a4d20c84ad8" dependencies = [ - "astroport 2.9.5", - "cosmwasm-schema", - "cosmwasm-std", - "cw2 0.15.1", - "cw20 0.15.1", - "cw20-base", - "snafu", -] - -[[package]] -name = "astroport-token" -version = "1.1.1" -source = "git+https://github.com/astroport-fi/astroport-core.git#b08b4d86050f0c473673b363aa9a4e8e30cf7082" -dependencies = [ - "astroport 3.9.0", + "astroport", "cosmwasm-schema", "cosmwasm-std", "cw2 0.15.1", - "cw20 0.15.1", + "cw20", "cw20-base", "snafu", ] @@ -202,20 +113,7 @@ name = "astroport-whitelist" version = "1.0.1" source = "git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d#700f66d677a173686cb15cb9cb8c7a4d20c84ad8" dependencies = [ - "astroport 2.9.5", - "cosmwasm-schema", - "cosmwasm-std", - "cw1-whitelist", - "cw2 0.15.1", - "thiserror", -] - -[[package]] -name = "astroport-whitelist" -version = "1.0.1" -source = "git+https://github.com/astroport-fi/astroport-core.git#b08b4d86050f0c473673b363aa9a4e8e30cf7082" -dependencies = [ - "astroport 3.9.0", + "astroport", "cosmwasm-schema", "cosmwasm-std", "cw1-whitelist", @@ -461,24 +359,17 @@ dependencies = [ name = "covenant-astroport-liquid-pooler" version = "1.0.0" dependencies = [ - "astroport 2.9.5", - "astroport-factory 1.5.1", - "astroport-native-coin-registry 1.0.1 (git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d)", - "astroport-pair-stable 2.1.4", - "astroport-token 1.1.1 (git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d)", - "astroport-whitelist 1.0.1 (git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d)", + "astroport", "bech32", "cosmwasm-schema", "cosmwasm-std", "covenant-clock", "covenant-macros", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", - "cw1-whitelist", "cw2 1.1.2", - "cw20 0.15.1", + "cw20", "neutron-sdk", "protobuf 3.3.0", "schemars", @@ -520,7 +411,6 @@ dependencies = [ name = "covenant-ibc-forwarder" version = "1.0.0" dependencies = [ - "anyhow", "bech32", "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", @@ -528,7 +418,6 @@ dependencies = [ "covenant-clock", "covenant-macros", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw2 1.1.2", "neutron-sdk", @@ -581,7 +470,6 @@ dependencies = [ name = "covenant-native-router" version = "1.0.0" dependencies = [ - "anyhow", "bech32", "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", @@ -589,7 +477,6 @@ dependencies = [ "covenant-clock", "covenant-macros", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw2 1.1.2", "neutron-sdk", @@ -606,13 +493,11 @@ dependencies = [ name = "covenant-native-splitter" version = "1.0.0" dependencies = [ - "anyhow", "cosmwasm-schema", "cosmwasm-std", "covenant-clock", "covenant-macros", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw2 1.1.2", "schemars", @@ -632,14 +517,11 @@ dependencies = [ "covenant-clock", "covenant-macros", "covenant-outpost-osmo-liquid-pooler", - "covenant-two-party-pol-holder", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", - "cw1-whitelist", "cw2 1.1.2", - "cw20 0.15.1", + "cw20", "neutron-sdk", "osmosis-std 0.20.1", "polytone", @@ -694,8 +576,7 @@ dependencies = [ name = "covenant-single-party-pol" version = "1.0.0" dependencies = [ - "anyhow", - "astroport 2.9.5", + "astroport", "base64 0.13.1", "bech32", "cosmos-sdk-proto 0.14.0", @@ -711,7 +592,6 @@ dependencies = [ "covenant-single-party-pol-holder", "covenant-stride-liquid-staker", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "cw2 1.1.2", @@ -730,17 +610,10 @@ dependencies = [ name = "covenant-single-party-pol-holder" version = "1.0.0" dependencies = [ - "anyhow", - "astroport-factory 1.6.0", - "astroport-native-coin-registry 1.0.1 (git+https://github.com/astroport-fi/astroport-core.git)", - "astroport-pair-stable 3.4.0", - "astroport-token 1.1.1 (git+https://github.com/astroport-fi/astroport-core.git)", - "astroport-whitelist 1.0.1 (git+https://github.com/astroport-fi/astroport-core.git)", "cosmwasm-schema", "cosmwasm-std", "covenant-macros", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "cw2 1.1.2", @@ -772,8 +645,6 @@ dependencies = [ name = "covenant-swap" version = "1.0.0" dependencies = [ - "anyhow", - "astroport 2.9.5", "bech32", "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", @@ -785,7 +656,6 @@ dependencies = [ "covenant-native-splitter", "covenant-swap-holder", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "cw2 1.1.2", @@ -804,14 +674,12 @@ dependencies = [ name = "covenant-swap-holder" version = "1.0.0" dependencies = [ - "anyhow", "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", "covenant-clock", "covenant-macros", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "cw2 1.1.2", @@ -824,8 +692,7 @@ dependencies = [ name = "covenant-two-party-pol" version = "1.0.0" dependencies = [ - "anyhow", - "astroport 2.9.5", + "astroport", "base64 0.13.1", "bech32", "cosmos-sdk-proto 0.14.0", @@ -839,7 +706,6 @@ dependencies = [ "covenant-osmo-liquid-pooler", "covenant-two-party-pol-holder", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "cw2 1.1.2", @@ -858,18 +724,16 @@ dependencies = [ name = "covenant-two-party-pol-holder" version = "1.0.0" dependencies = [ - "anyhow", - "astroport 2.9.5", + "astroport", "cosmwasm-schema", "cosmwasm-std", "covenant-clock", "covenant-macros", "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "cw2 1.1.2", - "cw20 0.15.1", + "cw20", "schemars", "serde", "thiserror", @@ -879,14 +743,14 @@ dependencies = [ name = "covenant-utils" version = "1.0.0" dependencies = [ - "astroport 2.9.5", + "astroport", "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", "covenant-macros", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", - "cw20 0.15.1", + "cw20", "neutron-sdk", "polytone", "prost 0.11.9", @@ -943,29 +807,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "cw-address-like" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "451a4691083a88a3c0630a8a88799e9d4cd6679b7ce8ff22b8da2873ff31d380" -dependencies = [ - "cosmwasm-std", -] - -[[package]] -name = "cw-asset" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "431e57314dceabd29a682c78bb3ff7c641f8bdc8b915400bb9956cb911e8e571" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-address-like", - "cw-storage-plus 1.2.0", - "cw20 1.1.2", - "thiserror", -] - [[package]] name = "cw-fifo" version = "1.0.0" @@ -1116,19 +957,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cw20" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "526e39bb20534e25a1cd0386727f0038f4da294e5e535729ba3ef54055246abd" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-utils 1.0.3", - "schemars", - "serde", -] - [[package]] name = "cw20-base" version = "0.15.1" @@ -1140,28 +968,13 @@ dependencies = [ "cw-storage-plus 0.15.1", "cw-utils 0.15.1", "cw2 0.15.1", - "cw20 0.15.1", + "cw20", "schemars", "semver", "serde", "thiserror", ] -[[package]] -name = "cw3" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2967fbd073d4b626dd9e7148e05a84a3bebd9794e71342e12351110ffbb12395" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-utils 1.0.3", - "cw20 1.1.2", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "der" version = "0.7.8" @@ -2145,13 +1958,13 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" name = "unit-tests" version = "0.1.0" dependencies = [ - "astroport 2.9.5", - "astroport-factory 1.5.1", - "astroport-native-coin-registry 1.0.1 (git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d)", + "astroport", + "astroport-factory", + "astroport-native-coin-registry", "astroport-pair", - "astroport-pair-stable 2.1.4", - "astroport-token 1.1.1 (git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d)", - "astroport-whitelist 1.0.1 (git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d)", + "astroport-pair-stable", + "astroport-token", + "astroport-whitelist", "colored", "const_format", "cosmos-sdk-proto 0.14.0", @@ -2178,7 +1991,7 @@ dependencies = [ "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "cw1-whitelist", - "cw20 0.15.1", + "cw20", "cw20-base", "neutron-sdk", "osmosis-std 0.13.2", diff --git a/contracts/astroport-liquid-pooler/Cargo.toml b/contracts/astroport-liquid-pooler/Cargo.toml index 1945ac64..53264767 100644 --- a/contracts/astroport-liquid-pooler/Cargo.toml +++ b/contracts/astroport-liquid-pooler/Cargo.toml @@ -42,15 +42,3 @@ bech32 = { workspace = true } astroport = { workspace = true } cw20 = { workspace = true } covenant-utils = { workspace = true } - -# dev-dependencies -[dev-dependencies] -cw-multi-test = { workspace = true } -astroport = { workspace = true } -cw1-whitelist = { workspace = true } -# covenant-two-party-pol-holder = { workspace = true } -astroport-token = { workspace = true } -astroport-whitelist = { workspace = true } -astroport-factory = { workspace = true } -astroport-native-coin-registry = { workspace = true } -astroport-pair-stable = { workspace = true } diff --git a/contracts/astroport-liquid-pooler/src/lib.rs b/contracts/astroport-liquid-pooler/src/lib.rs index 3b47dbd4..0faea8f4 100644 --- a/contracts/astroport-liquid-pooler/src/lib.rs +++ b/contracts/astroport-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)] -mod suite_test; diff --git a/contracts/astroport-liquid-pooler/src/suite_test/mod.rs b/contracts/astroport-liquid-pooler/src/suite_test/mod.rs deleted file mode 100644 index 7b881830..00000000 --- a/contracts/astroport-liquid-pooler/src/suite_test/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod suite; -mod tests; diff --git a/contracts/astroport-liquid-pooler/src/suite_test/suite.rs b/contracts/astroport-liquid-pooler/src/suite_test/suite.rs deleted file mode 100644 index 1da0bb37..00000000 --- a/contracts/astroport-liquid-pooler/src/suite_test/suite.rs +++ /dev/null @@ -1,653 +0,0 @@ -use astroport::{ - asset::{Asset, AssetInfo, PairInfo}, - factory::{PairConfig, PairType}, - pair::{Cw20HookMsg, PoolResponse, SimulationResponse, StablePoolParams}, -}; - -use cosmwasm_std::{ - testing::MockApi, to_json_binary, Addr, Coin, Decimal, Empty, MemoryStorage, QueryRequest, - Uint128, Uint64, WasmQuery, -}; -use covenant_utils::{PoolPriceConfig, SingleSideLpLimits}; -use cw20::Cw20ExecuteMsg; -use cw_multi_test::{ - App, AppResponse, BankKeeper, BankSudo, Contract, ContractWrapper, Executor, FailingModule, - SudoMsg, WasmKeeper, -}; -use neutron_sdk::bindings::{msg::NeutronMsg, query::NeutronQuery}; - -use crate::msg::{AssetData, InstantiateMsg, LpConfig, MigrateMsg, QueryMsg}; -use astroport::factory::InstantiateMsg as FactoryInstantiateMsg; -use astroport::native_coin_registry::InstantiateMsg as NativeCoinRegistryInstantiateMsg; -use astroport::pair::InstantiateMsg as PairInstantiateMsg; -use astroport::token::InstantiateMsg as TokenInstantiateMsg; -use cw1_whitelist::msg::InstantiateMsg as WhitelistInstantiateMsg; - -pub const CREATOR_ADDR: &str = "creator"; -pub const TOKEN_A_DENOM: &str = "uatom"; -pub const TOKEN_B_DENOM: &str = "untrn"; - -fn astro_token() -> Box> { - Box::new( - ContractWrapper::new( - astroport_token::contract::execute, - astroport_token::contract::instantiate, - astroport_token::contract::query, - ) - .with_migrate(astroport_token::contract::migrate), - ) -} - -fn astro_whitelist() -> Box> { - Box::new(ContractWrapper::new( - astroport_whitelist::contract::execute, - astroport_whitelist::contract::instantiate, - astroport_whitelist::contract::query, - )) -} - -fn astro_factory() -> Box> { - Box::new( - ContractWrapper::new( - astroport_factory::contract::execute, - astroport_factory::contract::instantiate, - astroport_factory::contract::query, - ) - .with_migrate(astroport_factory::contract::migrate) - .with_reply(astroport_factory::contract::reply), - ) -} - -fn astro_pair_stable() -> Box> { - Box::new( - ContractWrapper::new( - astroport_pair_stable::contract::execute, - astroport_pair_stable::contract::instantiate, - astroport_pair_stable::contract::query, - ) - .with_reply(astroport_pair_stable::contract::reply) - .with_migrate(astroport_pair_stable::contract::migrate), - ) -} - -fn astro_coin_registry() -> Box> { - let registry_contract = ContractWrapper::new( - astroport_native_coin_registry::contract::execute, - astroport_native_coin_registry::contract::instantiate, - astroport_native_coin_registry::contract::query, - ) - .with_migrate(astroport_native_coin_registry::contract::migrate); - - Box::new(registry_contract) -} - -fn lper_contract() -> Box> { - let lp_contract = ContractWrapper::new( - crate::contract::execute, - crate::contract::instantiate, - crate::contract::query, - ) - .with_reply(crate::contract::reply) - .with_migrate(crate::contract::migrate); - - Box::new(lp_contract) -} - -fn clock_contract() -> Box> { - Box::new( - ContractWrapper::new( - covenant_clock::contract::execute, - covenant_clock::contract::instantiate, - covenant_clock::contract::query, - ) - .with_reply(covenant_clock::contract::reply) - .with_migrate(covenant_clock::contract::migrate), - ) -} - -#[allow(unused)] -pub type BaseApp = App< - BankKeeper, - MockApi, - MemoryStorage, - FailingModule, - WasmKeeper, ->; -#[allow(unused)] -pub(crate) struct Suite { - pub app: App, - pub admin: Addr, - pub lp_token: Addr, - // (token_code, contract_address) - pub token: u64, - pub whitelist: (u64, String), - pub factory: (u64, String), - pub stable_pair: (u64, String), - pub coin_registry: (u64, String), - pub liquid_pooler: (u64, String), - pub clock_addr: String, - pub holder_addr: String, -} - -pub(crate) struct SuiteBuilder { - pub lp_instantiate: InstantiateMsg, - pub token_instantiate: TokenInstantiateMsg, - pub whitelist_instantiate: WhitelistInstantiateMsg, - pub factory_instantiate: FactoryInstantiateMsg, - pub stablepair_instantiate: PairInstantiateMsg, - pub registry_instantiate: NativeCoinRegistryInstantiateMsg, - pub clock_instantiate: covenant_clock::msg::InstantiateMsg, -} - -impl Default for SuiteBuilder { - fn default() -> Self { - Self { - lp_instantiate: InstantiateMsg { - clock_address: "clock-addr".to_string(), - pool_address: "lp-addr".to_string(), - slippage_tolerance: Some(Decimal::one()), - assets: AssetData { - asset_a_denom: "uatom".to_string(), - asset_b_denom: "untrn".to_string(), - }, - single_side_lp_limits: SingleSideLpLimits { - asset_a_limit: Uint128::new(100), - asset_b_limit: Uint128::new(1000), - }, - pool_price_config: PoolPriceConfig { - expected_spot_price: Decimal::from_ratio(Uint128::new(1), Uint128::new(10)), - acceptable_price_spread: Decimal::from_ratio(Uint128::one(), Uint128::new(100)), - }, - pair_type: PairType::Stable {}, - holder_address: "holder".to_string(), - }, - token_instantiate: TokenInstantiateMsg { - name: "nativetoken".to_string(), - symbol: "ntk".to_string(), - decimals: 20, - initial_balances: vec![], - mint: None, - marketing: None, - }, - whitelist_instantiate: WhitelistInstantiateMsg { - admins: vec![CREATOR_ADDR.to_string()], - mutable: false, - }, - factory_instantiate: FactoryInstantiateMsg { - pair_configs: vec![PairConfig { - code_id: u64::MAX, - pair_type: astroport::factory::PairType::Stable {}, - total_fee_bps: 0, - maker_fee_bps: 0, - is_disabled: false, - is_generator_disabled: true, - }], - token_code_id: u64::MAX, - fee_address: None, - generator_address: None, - owner: CREATOR_ADDR.to_string(), - whitelist_code_id: u64::MAX, - coin_registry_address: "TODO".to_string(), - }, - stablepair_instantiate: PairInstantiateMsg { - asset_infos: vec![ - astroport::asset::AssetInfo::NativeToken { - denom: TOKEN_A_DENOM.to_string(), - }, - astroport::asset::AssetInfo::NativeToken { - denom: TOKEN_B_DENOM.to_string(), - }, - ], - token_code_id: u64::MAX, - factory_addr: "TODO".to_string(), - init_params: Some( - to_json_binary(&StablePoolParams { - amp: 1000, - owner: Some(CREATOR_ADDR.to_string()), - }) - .unwrap(), - ), - }, - registry_instantiate: NativeCoinRegistryInstantiateMsg { - owner: CREATOR_ADDR.to_string(), - }, - clock_instantiate: covenant_clock::msg::InstantiateMsg { - tick_max_gas: Some(Uint64::new(50000)), - // this is the lper, if any instantiate flow changes, this needs to be updated - whitelist: vec!["contract8".to_string()], - }, - } - } -} - -#[allow(unused)] -impl SuiteBuilder { - fn with_slippage_tolerance(mut self, decimal: Decimal) -> Self { - self.lp_instantiate.slippage_tolerance = Some(decimal); - self - } - - fn with_assets(mut self, assets: AssetData) -> Self { - self.lp_instantiate.assets = assets; - self - } - - fn with_token_instantiate_msg(mut self, msg: TokenInstantiateMsg) -> Self { - self.token_instantiate = msg; - self - } - - pub fn with_expected_pair_type(mut self, pair_type: PairType) -> Self { - self.lp_instantiate.pair_type = pair_type; - self - } - - pub fn build(mut self) -> Suite { - // let mut app = BasicAppBuilder::::new_custom().build(|_,_,_| {}); - - let mut app = App::default(); - - let token_code = app.store_code(astro_token()); - let stablepair_code = app.store_code(astro_pair_stable()); - let whitelist_code = app.store_code(astro_whitelist()); - let coin_registry_code = app.store_code(astro_coin_registry()); - let factory_code = app.store_code(astro_factory()); - let lper_code = app.store_code(lper_contract()); - let clock_code = app.store_code(clock_contract()); - - self.factory_instantiate.token_code_id = token_code; - self.stablepair_instantiate.token_code_id = token_code; - self.factory_instantiate.whitelist_code_id = whitelist_code; - self.factory_instantiate.pair_configs[0].code_id = stablepair_code; - - let whitelist_addr = app - .instantiate_contract( - whitelist_code, - Addr::unchecked(CREATOR_ADDR), - &self.whitelist_instantiate, - &[], - "whitelist", - None, - ) - .unwrap(); - - app.update_block(|b: &mut cosmwasm_std::BlockInfo| b.height += 5); - - let coin_registry_addr = app - .instantiate_contract( - coin_registry_code, - Addr::unchecked(CREATOR_ADDR), - &self.registry_instantiate, - &[], - "native coin registry", - None, - ) - .unwrap(); - app.update_block(|b| b.height += 5); - - // add coins to registry - app.execute_contract( - Addr::unchecked(CREATOR_ADDR), - coin_registry_addr.clone(), - &astroport::native_coin_registry::ExecuteMsg::Add { - native_coins: vec![ - (TOKEN_A_DENOM.to_string(), 6), - (TOKEN_B_DENOM.to_string(), 6), - ], - }, - &[], - ) - .unwrap(); - app.update_block(|b| b.height += 5); - - self.factory_instantiate.coin_registry_address = coin_registry_addr.to_string(); - - let factory_addr = app - .instantiate_contract( - factory_code, - Addr::unchecked(CREATOR_ADDR), - &self.factory_instantiate, - &[], - "factory", - None, - ) - .unwrap(); - app.update_block(|b| b.height += 5); - - let init_pair_msg = astroport::factory::ExecuteMsg::CreatePair { - pair_type: PairType::Stable {}, - asset_infos: vec![ - AssetInfo::NativeToken { - denom: TOKEN_A_DENOM.to_string(), - }, - AssetInfo::NativeToken { - denom: TOKEN_B_DENOM.to_string(), - }, - ], - init_params: Some( - to_json_binary(&StablePoolParams { - owner: Some(CREATOR_ADDR.to_string()), - amp: 10, - }) - .unwrap(), - ), - }; - app.update_block(|b| b.height += 5); - - let pair_msg = app - .execute_contract( - Addr::unchecked(CREATOR_ADDR), - factory_addr.clone(), - &init_pair_msg, - &[], - ) - .unwrap(); - app.update_block(|b| b.height += 5); - - let pair_info: PairInfo = app - .wrap() - .query_wasm_smart( - &factory_addr, - &astroport::factory::QueryMsg::Pair { - asset_infos: vec![ - AssetInfo::NativeToken { - denom: TOKEN_A_DENOM.to_string(), - }, - AssetInfo::NativeToken { - denom: TOKEN_B_DENOM.to_string(), - }, - ], - }, - ) - .unwrap(); - - self.stablepair_instantiate.factory_addr = factory_addr.to_string(); - app.update_block(|b| b.height += 5); - - let stable_pair_addr = app - .instantiate_contract( - stablepair_code, - Addr::unchecked(CREATOR_ADDR), - &self.stablepair_instantiate, - &[], - "stableswap", - None, - ) - .unwrap(); - - app.update_block(|b| b.height += 5); - let clock_address = app - .instantiate_contract( - clock_code, - Addr::unchecked(CREATOR_ADDR), - &self.clock_instantiate, - &[], - "clock", - None, - ) - .unwrap(); - self.lp_instantiate.pool_address = stable_pair_addr.to_string(); - self.lp_instantiate.clock_address = clock_address.to_string(); - - let lper_address = app - .instantiate_contract( - lper_code, - Addr::unchecked(CREATOR_ADDR), - &self.lp_instantiate, - &[], - "lper contract", - Some(CREATOR_ADDR.to_string()), - ) - .unwrap(); - - app.update_block(|b| b.height += 5); - - app.migrate_contract( - Addr::unchecked(CREATOR_ADDR), - lper_address.clone(), - &MigrateMsg::UpdateConfig { - clock_addr: None, - holder_address: Some(CREATOR_ADDR.to_string()), - lp_config: None, - }, - lper_code, - ) - .unwrap(); - - Suite { - app, - admin: Addr::unchecked(CREATOR_ADDR), - lp_token: pair_info.liquidity_token, - token: token_code, - whitelist: (whitelist_code, whitelist_addr.to_string()), - factory: (factory_code, factory_addr.to_string()), - stable_pair: (stablepair_code, stable_pair_addr.to_string()), - coin_registry: (coin_registry_code, coin_registry_addr.to_string()), - liquid_pooler: (lper_code, lper_address.to_string()), - clock_addr: clock_address.to_string(), - holder_addr: CREATOR_ADDR.to_string(), - } - } -} - -// queries -#[allow(unused)] -impl Suite { - pub fn query_clock_address(&self) -> String { - self.app - .wrap() - .query_wasm_smart(&self.liquid_pooler.1, &QueryMsg::ClockAddress {}) - .unwrap() - } - - pub fn query_lp_position(&self) -> String { - let lp_config: LpConfig = self - .app - .wrap() - .query_wasm_smart(&self.liquid_pooler.1, &QueryMsg::LpConfig {}) - .unwrap(); - lp_config.pool_address.to_string() - } - - pub fn query_contract_state(&self) -> String { - self.app - .wrap() - .query_wasm_smart(&self.liquid_pooler.1, &QueryMsg::ContractState {}) - .unwrap() - } - - pub fn query_holder_address(&self) -> String { - self.app - .wrap() - .query_wasm_smart(&self.liquid_pooler.1, &QueryMsg::HolderAddress {}) - .unwrap() - } - - pub fn query_addr_balances(&self, addr: Addr) -> Vec { - self.app.wrap().query_all_balances(addr).unwrap() - } - - pub fn query_pool_info(&self) -> PoolResponse { - self.app - .wrap() - .query(&QueryRequest::Wasm(WasmQuery::Smart { - contract_addr: self.stable_pair.clone().1, - msg: to_json_binary(&astroport::pair::QueryMsg::Pool {}).unwrap(), - })) - .unwrap() - } - - pub fn query_pool_share(&self) -> Vec { - self.app - .wrap() - .query_wasm_smart( - Addr::unchecked(self.stable_pair.clone().1), - &astroport::pair::QueryMsg::Share { - amount: Uint128::one(), - }, - ) - .unwrap() - } - - pub fn query_simulation(&self, addr: String) -> SimulationResponse { - let query = astroport::pair::QueryMsg::Simulation { - offer_asset: Asset { - info: AssetInfo::NativeToken { - denom: TOKEN_A_DENOM.to_string(), - }, - amount: Uint128::one(), - }, - // ask_asset_info: None, - ask_asset_info: Some(AssetInfo::NativeToken { - denom: TOKEN_B_DENOM.to_string(), - }), - }; - println!("\nquerying simulation: {query:?}\n"); - - self.app.wrap().query_wasm_smart(addr, &query).unwrap() - } - - pub fn query_contract_config(&self, addr: String) -> String { - let bytes = self - .app - .wrap() - .query_wasm_raw(addr, b"config") - .transpose() - .unwrap() - .unwrap(); - match std::str::from_utf8(&bytes) { - Ok(v) => v.to_string(), - Err(e) => panic!("Invalid UTF-8 sequence: {e}"), - } - } - - pub fn query_cw20_bal(&self, token: String, addr: String) -> cw20::BalanceResponse { - self.app - .wrap() - .query_wasm_smart(token, &cw20::Cw20QueryMsg::Balance { address: addr }) - .unwrap() - } - - pub fn query_liquidity_token_addr(&self) -> astroport::asset::PairInfo { - self.app - .wrap() - .query_wasm_smart( - self.stable_pair.1.to_string(), - &astroport::pair::QueryMsg::Pair {}, - ) - .unwrap() - } -} - -// assertion helpers -impl Suite {} - -impl Suite { - // tick LPer - pub fn tick(&mut self) -> AppResponse { - let resp = self - .app - .execute_contract( - Addr::unchecked(self.clock_addr.to_string()), - Addr::unchecked(self.liquid_pooler.1.to_string()), - &crate::msg::ExecuteMsg::Tick {}, - &[], - ) - .unwrap(); - println!("response: {:?}", resp); - resp - } - - // mint coins - pub fn mint_coins_to_addr(&mut self, address: String, denom: String, amount: Uint128) { - self.app - .sudo(SudoMsg::Bank(BankSudo::Mint { - to_address: address, - amount: vec![Coin { amount, denom }], - })) - .unwrap(); - } - - // pass time - pub fn pass_blocks(&mut self, num: u64) { - self.app.update_block(|b| b.height += num) - } - - // withdraw liquidity from pool - #[allow(unused)] - pub fn withdraw_liquidity( - &mut self, - sender: Addr, - amount: u128, - assets: Vec, - ) -> AppResponse { - self.app - .execute_contract( - sender, - Addr::unchecked("contract6".to_string()), - &Cw20ExecuteMsg::Send { - contract: self.stable_pair.1.to_string(), - amount: Uint128::from(amount), - msg: to_json_binary(&Cw20HookMsg::WithdrawLiquidity { assets }).unwrap(), - }, - &[], - ) - .unwrap() - } - - pub fn provide_manual_liquidity( - &mut self, - from: String, - token_a_amt: Uint128, - token_b_amt: Uint128, - ) -> AppResponse { - let _stable_pair_addr = self.stable_pair.1.to_string(); - - let balances = vec![ - Coin { - denom: TOKEN_A_DENOM.to_string(), - amount: token_a_amt, - }, - Coin { - denom: TOKEN_B_DENOM.to_string(), - amount: token_b_amt, - }, - ]; - - let assets = vec![ - Asset { - info: AssetInfo::NativeToken { - denom: TOKEN_A_DENOM.to_string(), - }, - amount: token_a_amt, - }, - Asset { - info: AssetInfo::NativeToken { - denom: TOKEN_B_DENOM.to_string(), - }, - amount: token_b_amt, - }, - ]; - - self.mint_coins_to_addr(from.clone(), TOKEN_A_DENOM.to_string(), token_a_amt); - self.mint_coins_to_addr(from.clone(), TOKEN_B_DENOM.to_string(), token_b_amt); - - let provide_liquidity_msg = astroport::pair::ExecuteMsg::ProvideLiquidity { - assets, - slippage_tolerance: None, - auto_stake: Some(false), - receiver: Some(from.clone()), - }; - - self.pass_blocks(10); - - self.app - .execute_contract( - Addr::unchecked(from), - Addr::unchecked(self.stable_pair.1.to_string()), - &provide_liquidity_msg, - &balances, - ) - .unwrap() - } -} diff --git a/contracts/astroport-liquid-pooler/src/suite_test/tests.rs b/contracts/astroport-liquid-pooler/src/suite_test/tests.rs deleted file mode 100644 index d6ea53b8..00000000 --- a/contracts/astroport-liquid-pooler/src/suite_test/tests.rs +++ /dev/null @@ -1,206 +0,0 @@ -use cosmwasm_std::{Addr, Coin, Uint128}; - -use crate::suite_test::suite::{TOKEN_A_DENOM, TOKEN_B_DENOM}; - -use super::suite::SuiteBuilder; - -#[test] -fn test_double_sided_lp() { - let mut suite = SuiteBuilder::default().build(); - - // fund pool with balanced amounts of underlying tokens - let token_a_amt = Uint128::new(1000); - let token_b_amt = Uint128::new(10000); - suite.provide_manual_liquidity("alice".to_string(), token_a_amt, token_b_amt); - - // fund LP contract with some tokens to provide liquidity with - suite.mint_coins_to_addr( - suite.liquid_pooler.1.to_string(), - TOKEN_A_DENOM.to_string(), - token_a_amt, - ); - suite.mint_coins_to_addr( - suite.liquid_pooler.1.to_string(), - TOKEN_B_DENOM.to_string(), - token_b_amt, - ); - - let liquid_pooler_balances = - suite.query_addr_balances(Addr::unchecked(suite.liquid_pooler.1.to_string())); - assert_eq!(liquid_pooler_balances[0].amount, token_a_amt); - assert_eq!(liquid_pooler_balances[1].amount, token_b_amt); - - let liquidity_token_addr = suite - .query_liquidity_token_addr() - .liquidity_token - .to_string(); - - let holder_balances = - suite.query_cw20_bal(liquidity_token_addr.clone(), suite.holder_addr.to_string()); - assert_eq!(Uint128::zero(), holder_balances.balance); - - suite.pass_blocks(10); - suite.tick(); - - let liquid_pooler_balances = - suite.query_addr_balances(Addr::unchecked(suite.liquid_pooler.1.to_string())); - assert_eq!(0usize, liquid_pooler_balances.len()); - - let liquid_pooler_balances = - suite.query_cw20_bal(liquidity_token_addr, suite.liquid_pooler.1.to_string()); - assert_ne!(Uint128::zero(), liquid_pooler_balances.balance); -} - -#[test] -fn test_double_and_single_sided_lp() { - let mut suite = SuiteBuilder::default().build(); - - // fund pool with balanced amounts of underlying tokens at 1:10 ratio - - suite.provide_manual_liquidity( - "alice".to_string(), - Uint128::new(10000), - Uint128::new(100000), - ); - - // fund LP contract with some tokens to provide liquidity with - let token_a_amt = Uint128::new(1000); - let token_b_amt = Uint128::new(9000); - suite.mint_coins_to_addr( - suite.liquid_pooler.1.to_string(), - TOKEN_A_DENOM.to_string(), - token_a_amt, - ); - suite.mint_coins_to_addr( - suite.liquid_pooler.1.to_string(), - TOKEN_B_DENOM.to_string(), - token_b_amt, - ); - let liquid_pooler_balances = - suite.query_addr_balances(Addr::unchecked(suite.liquid_pooler.1.to_string())); - assert_eq!(liquid_pooler_balances[0].amount, token_a_amt); - assert_eq!(liquid_pooler_balances[1].amount, token_b_amt); - - let liquidity_token_addr = suite - .query_liquidity_token_addr() - .liquidity_token - .to_string(); - - let holder_balances = - suite.query_cw20_bal(liquidity_token_addr.clone(), suite.holder_addr.to_string()); - assert_eq!(Uint128::zero(), holder_balances.balance); - - suite.pass_blocks(10); - suite.tick(); - - let liquid_pooler_balances = - suite.query_addr_balances(Addr::unchecked(suite.liquid_pooler.1.to_string())); - - // assert there are 100 uatoms remaining because of missmatched pool/provision ratio - assert_eq!( - Coin { - denom: TOKEN_A_DENOM.to_string(), - amount: Uint128::new(100) - }, - liquid_pooler_balances[0], - ); - let liquid_pooler_balance = suite - .query_cw20_bal( - liquidity_token_addr.to_string(), - suite.liquid_pooler.1.to_string(), - ) - .balance; - assert_ne!(Uint128::zero(), liquid_pooler_balance); - - // tick again - suite.pass_blocks(10); - suite.tick(); - - let liquid_pooler_balances = - suite.query_addr_balances(Addr::unchecked(suite.liquid_pooler.1.to_string())); - assert_eq!(0, liquid_pooler_balances.len()); - - let new_holder_balance = suite - .query_cw20_bal(liquidity_token_addr, suite.holder_addr.to_string()) - .balance; - assert_ne!(liquid_pooler_balance, new_holder_balance); -} - -#[test] -#[should_panic(expected = "Pair type mismatch")] -fn test_migrated_pool_type_lp() { - let mut suite = SuiteBuilder::default() - .with_expected_pair_type(astroport::factory::PairType::Xyk {}) - .build(); - - // fund pool with balanced amounts of underlying tokens - let token_a_amt = Uint128::new(1000); - let token_b_amt = Uint128::new(10000); - suite.provide_manual_liquidity("alice".to_string(), token_a_amt, token_b_amt); - - // fund LP contract with some tokens to provide liquidity with - suite.mint_coins_to_addr( - suite.liquid_pooler.1.to_string(), - TOKEN_A_DENOM.to_string(), - token_a_amt, - ); - suite.mint_coins_to_addr( - suite.liquid_pooler.1.to_string(), - TOKEN_B_DENOM.to_string(), - token_b_amt, - ); - - suite.tick(); -} - -#[test] -#[should_panic(expected = "Price range error")] -fn test_lp_not_within_price_range_denom_a_dominant() { - let mut suite = SuiteBuilder::default().build(); - - // fund pool with 10:1 ratio of token a to b. - // Liquid Pooler is configured to expect 1:10 ratio. - // pool balances: [10000, 1000] - suite.provide_manual_liquidity("alice".to_string(), Uint128::new(10000), Uint128::new(1000)); - - let token_a_amt = Uint128::new(1000); - let token_b_amt = Uint128::new(10000); - // fund LP contract with some tokens to provide liquidity with - suite.mint_coins_to_addr( - suite.liquid_pooler.1.to_string(), - TOKEN_A_DENOM.to_string(), - token_a_amt, - ); - suite.mint_coins_to_addr( - suite.liquid_pooler.1.to_string(), - TOKEN_B_DENOM.to_string(), - token_b_amt, - ); - suite.tick(); -} - -#[test] -#[should_panic(expected = "Price range error")] -fn test_lp_not_within_price_range_denom_b_dominant() { - let mut suite = SuiteBuilder::default().build(); - - // fund pool with 1:20 ratio of token a to b. - // Liquid Pooler is configured to expect 1:10 ratio. - // pool balances: [1000, 20000] - suite.provide_manual_liquidity("alice".to_string(), Uint128::new(1000), Uint128::new(20000)); - - let token_a_amt = Uint128::new(1000); - let token_b_amt = Uint128::new(10000); - // fund LP contract with some tokens to provide liquidity with - suite.mint_coins_to_addr( - suite.liquid_pooler.1.to_string(), - TOKEN_A_DENOM.to_string(), - token_a_amt, - ); - suite.mint_coins_to_addr( - suite.liquid_pooler.1.to_string(), - TOKEN_B_DENOM.to_string(), - token_b_amt, - ); - suite.tick(); -} diff --git a/contracts/clock/Cargo.toml b/contracts/clock/Cargo.toml index 98617667..d82101bc 100644 --- a/contracts/clock/Cargo.toml +++ b/contracts/clock/Cargo.toml @@ -26,7 +26,6 @@ cw2 = { workspace = true } serde = { workspace = true } thiserror = { workspace = true } neutron-sdk = { workspace = true } -# covenant-utils = { workspace = true, features=["library"] } [dev-dependencies] cw-multi-test = { workspace = true } diff --git a/contracts/ibc-forwarder/Cargo.toml b/contracts/ibc-forwarder/Cargo.toml index debdc87c..5c947cbc 100644 --- a/contracts/ibc-forwarder/Cargo.toml +++ b/contracts/ibc-forwarder/Cargo.toml @@ -38,7 +38,3 @@ prost = { workspace = true } prost-types = { workspace = true } bech32 = { workspace = true } covenant-utils = { workspace = true } - -[dev-dependencies] -cw-multi-test = { workspace = true } -anyhow = { workspace = true } diff --git a/contracts/native-router/Cargo.toml b/contracts/native-router/Cargo.toml index 18be19e3..316f8b85 100644 --- a/contracts/native-router/Cargo.toml +++ b/contracts/native-router/Cargo.toml @@ -36,8 +36,3 @@ prost = { workspace = true } prost-types = { workspace = true } bech32 = { workspace = true } covenant-utils = { workspace = true } - -[dev-dependencies] -cw-multi-test = { workspace = true } -anyhow = { workspace = true } -covenant-clock = { workspace = true } diff --git a/contracts/native-splitter/Cargo.toml b/contracts/native-splitter/Cargo.toml index 314cf9e8..d5c001a9 100644 --- a/contracts/native-splitter/Cargo.toml +++ b/contracts/native-splitter/Cargo.toml @@ -30,7 +30,3 @@ thiserror = { workspace = true } schemars = { workspace = true } serde-json-wasm = { workspace = true } serde = { workspace = true } - -[dev-dependencies] -cw-multi-test = { workspace = true } -anyhow = { workspace = true } diff --git a/contracts/native-splitter/src/lib.rs b/contracts/native-splitter/src/lib.rs index 3b47dbd4..0faea8f4 100644 --- a/contracts/native-splitter/src/lib.rs +++ b/contracts/native-splitter/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)] -mod suite_test; diff --git a/contracts/native-splitter/src/suite_test/mod.rs b/contracts/native-splitter/src/suite_test/mod.rs deleted file mode 100644 index b6c3de42..00000000 --- a/contracts/native-splitter/src/suite_test/mod.rs +++ /dev/null @@ -1,15 +0,0 @@ -use cosmwasm_std::Empty; -use cw_multi_test::{Contract, ContractWrapper}; - -mod suite; -mod tests; - -pub fn _splitter_contract() -> Box> { - let contract = ContractWrapper::new( - crate::contract::execute, - crate::contract::instantiate, - crate::contract::query, - ) - .with_migrate(crate::contract::migrate); - Box::new(contract) -} diff --git a/contracts/native-splitter/src/suite_test/suite.rs b/contracts/native-splitter/src/suite_test/suite.rs deleted file mode 100644 index 3c8e6ace..00000000 --- a/contracts/native-splitter/src/suite_test/suite.rs +++ /dev/null @@ -1,176 +0,0 @@ -// use cosmwasm_std::{Addr, Coin, Uint128}; -// use cw_multi_test::{App, AppResponse, Executor, SudoMsg}; - -// use crate::msg::{ -// ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, -// }; - -// use super::splitter_contract; - -// pub const ADMIN: &str = "admin"; - -// pub const DENOM_A: &str = "denom_a"; -// pub const DENOM_B: &str = "denom_b"; -// pub const ALT_DENOM: &str = "alt_denom"; - -// pub const PARTY_A_ADDR: &str = "party_a"; -// pub const PARTY_B_ADDR: &str = "party_b"; - -// pub const CLOCK_ADDR: &str = "clock_addr"; - -// pub fn get_equal_split_config() -> SplitConfig { -// SplitConfig { -// receivers: vec![ -// Receiver { -// addr: PARTY_A_ADDR.to_string(), -// share: Uint128::new(50), -// }, -// Receiver { -// addr: PARTY_B_ADDR.to_string(), -// share: Uint128::new(50), -// }, -// ], -// } -// } - -// pub fn get_fallback_split_config() -> SplitConfig { -// SplitConfig { -// receivers: vec![Receiver { -// addr: "save_the_cats".to_string(), -// share: Uint128::new(100), -// }], -// } -// } - -// pub struct Suite { -// pub app: App, -// pub splitter: Addr, -// } - -// pub struct SuiteBuilder { -// pub instantiate: InstantiateMsg, -// pub app: App, -// } - -// impl Default for SuiteBuilder { -// fn default() -> Self { -// Self { -// instantiate: InstantiateMsg { -// clock_address: CLOCK_ADDR.to_string(), -// splits: vec![ -// ( -// DENOM_A.to_string(), -// SplitType::Custom(get_equal_split_config()), -// ), -// ( -// DENOM_B.to_string(), -// SplitType::Custom(get_equal_split_config()), -// ), -// ], -// fallback_split: None, -// }, -// app: App::default(), -// } -// } -// } - -// impl SuiteBuilder { -// pub fn with_custom_splits(mut self, splits: Vec<(String, SplitType)>) -> Self { -// self.instantiate.splits = splits; -// self -// } - -// pub fn with_fallback_split(mut self, split: SplitConfig) -> Self { -// self.instantiate.fallback_split = Some(split); -// self -// } - -// pub fn build(self) -> Suite { -// let mut app = self.app; - -// let splitter_code: u64 = app.store_code(splitter_contract()); -// let splitter = app -// .instantiate_contract( -// splitter_code, -// Addr::unchecked(ADMIN), -// &self.instantiate, -// &[], -// "splitter", -// Some(ADMIN.to_string()), -// ) -// .unwrap(); -// Suite { app, splitter } -// } -// } - -// // actions -// impl Suite { -// pub fn tick(&mut self, caller: &str) -> Result { -// self.app.execute_contract( -// Addr::unchecked(caller), -// self.splitter.clone(), -// &ExecuteMsg::Tick {}, -// &[], -// ) -// } - -// pub fn migrate(&mut self, msg: MigrateMsg) -> Result { -// self.app -// .migrate_contract(Addr::unchecked(ADMIN), self.splitter.clone(), &msg, 1) -// } -// } - -// // queries -// impl Suite { -// pub fn query_clock_address(&self) -> Addr { -// self.app -// .wrap() -// .query_wasm_smart(&self.splitter, &QueryMsg::ClockAddress {}) -// .unwrap() -// } - -// pub fn query_denom_split(&self, denom: String) -> SplitConfig { -// self.app -// .wrap() -// .query_wasm_smart(&self.splitter, &QueryMsg::DenomSplit { denom }) -// .unwrap() -// } - -// pub fn query_all_splits(&self) -> Vec<(String, SplitConfig)> { -// self.app -// .wrap() -// .query_wasm_smart(&self.splitter, &QueryMsg::Splits {}) -// .unwrap() -// } - -// pub fn query_fallback_split(&self) -> Option { -// self.app -// .wrap() -// .query_wasm_smart(&self.splitter, &QueryMsg::FallbackSplit {}) -// .unwrap() -// } -// } - -// // helper -// impl Suite { -// pub fn pass_blocks(&mut self, n: u64) { -// self.app.update_block(|b| b.height += n); -// } - -// pub fn fund_coin(&mut self, coin: Coin) -> AppResponse { -// self.app -// .sudo(SudoMsg::Bank(cw_multi_test::BankSudo::Mint { -// to_address: self.splitter.to_string(), -// amount: vec![coin], -// })) -// .unwrap() -// } - -// pub fn get_party_denom_balance(&self, denom: &str, party_addr: &str) -> Uint128 { -// self.app -// .wrap() -// .query_balance(party_addr, denom) -// .unwrap() -// .amount -// } -// } diff --git a/contracts/native-splitter/src/suite_test/tests.rs b/contracts/native-splitter/src/suite_test/tests.rs deleted file mode 100644 index 07fa0a11..00000000 --- a/contracts/native-splitter/src/suite_test/tests.rs +++ /dev/null @@ -1,221 +0,0 @@ -// use cosmwasm_std::{Coin, Uint128}; - -// use crate::{ -// msg::{MigrateMsg, SplitType}, -// suite_test::suite::{ -// get_equal_split_config, get_fallback_split_config, ALT_DENOM, CLOCK_ADDR, DENOM_B, -// }, -// }; - -// use super::suite::{SuiteBuilder, DENOM_A, PARTY_A_ADDR, PARTY_B_ADDR}; - -// #[test] -// fn test_instantiate_happy_and_query_all() { -// let suite = SuiteBuilder::default().build(); - -// let splits = suite.query_all_splits(); -// let token_a_split = suite.query_denom_split(DENOM_A.to_string()); -// let token_b_split = suite.query_denom_split(DENOM_B.to_string()); -// let clock_addr = suite.query_clock_address(); -// let fallback_split = suite.query_fallback_split(); - -// assert_eq!(get_equal_split_config(), token_a_split); -// assert_eq!(get_equal_split_config(), token_b_split); -// assert_eq!(CLOCK_ADDR.to_string(), clock_addr); -// assert_eq!( -// vec![ -// (DENOM_A.to_string(), get_equal_split_config()), -// (DENOM_B.to_string(), get_equal_split_config()), -// ], -// splits, -// ); -// assert_eq!(None, fallback_split); -// } - -// #[test] -// #[should_panic(expected = "misconfigured split")] -// fn test_instantiate_split_misconfig() { -// // SuiteBuilder::default() -// // .with_custom_splits(vec![( -// // DENOM_A.to_string(), -// // SplitType::Custom(SplitConfig { -// // receivers: vec![ -// // Receiver { -// // addr: PARTY_A_ADDR.to_string(), -// // share: Uint128::new(50), -// // }, -// // Receiver { -// // addr: PARTY_B_ADDR.to_string(), -// // share: Uint128::new(49), -// // }, -// // ], -// // }), -// // )]) -// // .build(); -// } - -// #[test] -// fn test_distribute_equal_split() { -// let mut suite = SuiteBuilder::default().build(); - -// // fund the splitter with 100 of each denom -// suite.fund_coin(Coin::new(100, DENOM_A)); -// suite.fund_coin(Coin::new(100, DENOM_B)); - -// suite.pass_blocks(10); - -// // assert splitter is funded -// let splitter_denom_a_bal = suite.get_party_denom_balance(DENOM_A, suite.splitter.as_str()); -// let splitter_denom_b_bal = suite.get_party_denom_balance(DENOM_B, suite.splitter.as_str()); -// assert_eq!(Uint128::new(100), splitter_denom_a_bal); -// assert_eq!(Uint128::new(100), splitter_denom_b_bal); - -// // tick initiates the distribution attempt -// suite.tick(CLOCK_ADDR).unwrap(); -// suite.pass_blocks(10); - -// let party_a_denom_a_bal = suite.get_party_denom_balance(DENOM_A, PARTY_A_ADDR); -// let party_a_denom_b_bal = suite.get_party_denom_balance(DENOM_B, PARTY_A_ADDR); -// let party_b_denom_a_bal = suite.get_party_denom_balance(DENOM_A, PARTY_B_ADDR); -// let party_b_denom_b_bal = suite.get_party_denom_balance(DENOM_B, PARTY_B_ADDR); -// let splitter_denom_a_bal = suite.get_party_denom_balance(DENOM_A, suite.splitter.as_str()); -// let splitter_denom_b_bal = suite.get_party_denom_balance(DENOM_B, suite.splitter.as_str()); - -// assert_eq!(Uint128::new(50), party_a_denom_a_bal); -// assert_eq!(Uint128::new(50), party_a_denom_b_bal); -// assert_eq!(Uint128::new(50), party_b_denom_a_bal); -// assert_eq!(Uint128::new(50), party_b_denom_b_bal); -// assert_eq!(Uint128::zero(), splitter_denom_a_bal); -// assert_eq!(Uint128::zero(), splitter_denom_b_bal); -// } - -// // #[test] -// // fn test_distribute_token_swap() { -// // let mut suite = SuiteBuilder::default() -// // .with_custom_splits(vec![ -// // ( -// // DENOM_A.to_string(), -// // SplitType::Custom(SplitConfig { -// // receivers: vec![Receiver { -// // addr: PARTY_B_ADDR.to_string(), -// // share: Uint128::new(100), -// // }], -// // }), -// // ), -// // ( -// // DENOM_B.to_string(), -// // SplitType::Custom(SplitConfig { -// // receivers: vec![Receiver { -// // addr: PARTY_A_ADDR.to_string(), -// // share: Uint128::new(100), -// // }], -// // }), -// // ), -// // ]) -// // .build(); - -// // // fund the splitter with 100 of each denom -// // suite.fund_coin(Coin::new(100, DENOM_A)); -// // suite.fund_coin(Coin::new(100, DENOM_B)); - -// // suite.pass_blocks(10); - -// // // assert splitter is funded -// // let splitter_denom_a_bal = suite.get_party_denom_balance(DENOM_A, suite.splitter.as_str()); -// // let splitter_denom_b_bal = suite.get_party_denom_balance(DENOM_B, suite.splitter.as_str()); -// // assert_eq!(Uint128::new(100), splitter_denom_a_bal); -// // assert_eq!(Uint128::new(100), splitter_denom_b_bal); - -// // // tick initiates the distribution attempt -// // suite.tick(CLOCK_ADDR).unwrap(); -// // suite.pass_blocks(10); - -// // let party_a_denom_a_bal = suite.get_party_denom_balance(DENOM_A, PARTY_A_ADDR); -// // let party_a_denom_b_bal = suite.get_party_denom_balance(DENOM_B, PARTY_A_ADDR); -// // let party_b_denom_a_bal = suite.get_party_denom_balance(DENOM_A, PARTY_B_ADDR); -// // let party_b_denom_b_bal = suite.get_party_denom_balance(DENOM_B, PARTY_B_ADDR); -// // let splitter_denom_a_bal = suite.get_party_denom_balance(DENOM_A, suite.splitter.as_str()); -// // let splitter_denom_b_bal = suite.get_party_denom_balance(DENOM_B, suite.splitter.as_str()); - -// // assert_eq!(Uint128::zero(), party_a_denom_a_bal); -// // assert_eq!(Uint128::new(100), party_a_denom_b_bal); -// // assert_eq!(Uint128::new(100), party_b_denom_a_bal); -// // assert_eq!(Uint128::zero(), party_b_denom_b_bal); -// // assert_eq!(Uint128::zero(), splitter_denom_a_bal); -// // assert_eq!(Uint128::zero(), splitter_denom_b_bal); -// // } - -// #[test] -// fn test_distribute_fallback() { -// let mut suite = SuiteBuilder::default() -// .with_fallback_split(get_fallback_split_config()) -// .build(); - -// // fund the splitter with 100 of some random token not part of the config -// suite.fund_coin(Coin::new(100, ALT_DENOM.to_string())); - -// suite.pass_blocks(10); - -// // assert splitter is funded -// let splitter_alt_denom_bal = suite.get_party_denom_balance(ALT_DENOM, suite.splitter.as_str()); -// assert_eq!(Uint128::new(100), splitter_alt_denom_bal); - -// // tick initiates the distribution attempt -// suite.tick(CLOCK_ADDR).unwrap(); -// suite.pass_blocks(10); - -// let save_the_cats_foundation_bal = suite.get_party_denom_balance(ALT_DENOM, "save_the_cats"); -// let splitter_alt_denom_bal = suite.get_party_denom_balance(ALT_DENOM, suite.splitter.as_str()); - -// assert_eq!(Uint128::zero(), splitter_alt_denom_bal); -// assert_eq!(Uint128::new(100), save_the_cats_foundation_bal); -// } - -// // #[test] -// // fn test_migrate_config() { -// // let mut suite = SuiteBuilder::default().build(); - -// // let new_clock = "new_clock".to_string(); -// // let new_fallback_split = SplitConfig { -// // receivers: vec![Receiver { -// // addr: "fallback_new".to_string(), -// // share: Uint128::new(100), -// // }], -// // }; -// // let new_splits = vec![( -// // "new_denom".to_string(), -// // SplitType::Custom(SplitConfig { -// // receivers: vec![Receiver { -// // addr: "new_receiver".to_string(), -// // share: Uint128::new(100), -// // }], -// // }), -// // )]; - -// // let migrate_msg = MigrateMsg::UpdateConfig { -// // clock_addr: Some(new_clock.clone()), -// // fallback_split: Some(new_fallback_split.clone()), -// // splits: Some(new_splits), -// // }; - -// // suite.migrate(migrate_msg).unwrap(); - -// // let splits = suite.query_all_splits(); -// // let clock_addr = suite.query_clock_address(); -// // let fallback_split = suite.query_fallback_split(); - -// // assert_eq!( -// // vec![( -// // "new_denom".to_string(), -// // SplitConfig { -// // receivers: vec![Receiver { -// // addr: "new_receiver".to_string(), -// // share: Uint128::new(100) -// // },], -// // }, -// // )], -// // splits -// // ); -// // assert_eq!(Some(new_fallback_split), fallback_split); -// // assert_eq!(new_clock, clock_addr); -// // } diff --git a/contracts/osmo-liquid-pooler/Cargo.toml b/contracts/osmo-liquid-pooler/Cargo.toml index fce24fda..0637deb0 100644 --- a/contracts/osmo-liquid-pooler/Cargo.toml +++ b/contracts/osmo-liquid-pooler/Cargo.toml @@ -45,9 +45,3 @@ osmosis-std = "0.20.1" base64 = { workspace = true } prost = { workspace = true } covenant-outpost-osmo-liquid-pooler = { workspace = true, features = ["library"] } - -# dev-dependencies -[dev-dependencies] -cw-multi-test = { workspace = true } -cw1-whitelist = { workspace = true } -covenant-two-party-pol-holder = { workspace = true } diff --git a/contracts/remote-chain-splitter/src/lib.rs b/contracts/remote-chain-splitter/src/lib.rs index db1ed601..4c36c82e 100644 --- a/contracts/remote-chain-splitter/src/lib.rs +++ b/contracts/remote-chain-splitter/src/lib.rs @@ -7,7 +7,3 @@ pub mod error; pub mod msg; pub mod state; pub mod sudo; - -#[allow(clippy::unwrap_used)] -#[cfg(test)] -mod suite_test; diff --git a/contracts/remote-chain-splitter/src/suite_test/mod.rs b/contracts/remote-chain-splitter/src/suite_test/mod.rs deleted file mode 100644 index 7b881830..00000000 --- a/contracts/remote-chain-splitter/src/suite_test/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod suite; -mod tests; diff --git a/contracts/remote-chain-splitter/src/suite_test/suite.rs b/contracts/remote-chain-splitter/src/suite_test/suite.rs deleted file mode 100644 index 8b137891..00000000 --- a/contracts/remote-chain-splitter/src/suite_test/suite.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/contracts/remote-chain-splitter/src/suite_test/tests.rs b/contracts/remote-chain-splitter/src/suite_test/tests.rs deleted file mode 100644 index 8b137891..00000000 --- a/contracts/remote-chain-splitter/src/suite_test/tests.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/contracts/single-party-pol-covenant/Cargo.toml b/contracts/single-party-pol-covenant/Cargo.toml index ab752a8c..83b06ff1 100644 --- a/contracts/single-party-pol-covenant/Cargo.toml +++ b/contracts/single-party-pol-covenant/Cargo.toml @@ -47,9 +47,3 @@ covenant-stride-liquid-staker = { workspace = true, features = ["library"] } covenant-remote-chain-splitter = { workspace = true, features = ["library"] } covenant-osmo-liquid-pooler = { workspace = true, features = ["library"] } astroport = { workspace = true } - -[dev-dependencies] -cw-multi-test = { workspace = true } -anyhow = { workspace = true } -astroport = { workspace = true } -prost = { workspace = true } diff --git a/contracts/single-party-pol-holder/Cargo.toml b/contracts/single-party-pol-holder/Cargo.toml index 245537bd..2c6d3fa5 100644 --- a/contracts/single-party-pol-holder/Cargo.toml +++ b/contracts/single-party-pol-holder/Cargo.toml @@ -26,12 +26,3 @@ thiserror = { workspace = true } cw-utils = { workspace = true } covenant-macros = { workspace = true } covenant-utils = { workspace = true } - -[dev-dependencies] -cw-multi-test = { workspace = true } -anyhow = { workspace = true } -astroport-token = { git = "https://github.com/astroport-fi/astroport-core.git" } -astroport-whitelist = { git = "https://github.com/astroport-fi/astroport-core.git" } -astroport-factory = { git = "https://github.com/astroport-fi/astroport-core.git" } -astroport-native-coin-registry = { git = "https://github.com/astroport-fi/astroport-core.git" } -astroport-pair-stable = { git = "https://github.com/astroport-fi/astroport-core.git" } diff --git a/contracts/single-party-pol-holder/src/lib.rs b/contracts/single-party-pol-holder/src/lib.rs index 20b2e3bb..a5abdbb0 100644 --- a/contracts/single-party-pol-holder/src/lib.rs +++ b/contracts/single-party-pol-holder/src/lib.rs @@ -2,6 +2,3 @@ pub mod contract; pub mod error; pub mod msg; pub mod state; - -#[cfg(test)] -mod suite_tests; diff --git a/contracts/single-party-pol-holder/src/suite_tests/mod.rs b/contracts/single-party-pol-holder/src/suite_tests/mod.rs deleted file mode 100644 index 1cc9bdf2..00000000 --- a/contracts/single-party-pol-holder/src/suite_tests/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -// use cosmwasm_std::Empty; -// use cw_multi_test::{Contract, ContractWrapper}; - -mod suite; -mod tests; - -// Advantage to using a macro for this is that the error trace links -// to the exact line that the error occured, instead of inside of a -// function where the assertion would otherwise happen. -// macro_rules! is_error { -// ($x:expr, $e:expr) => { -// assert!(format!("{:#}", $x).contains($e)) -// }; -// } -// pub(crate) use is_error; - -// pub fn holder_contract() -> Box> { -// let contract = ContractWrapper::new( -// crate::contract::execute, -// crate::contract::instantiate, -// crate::contract::query, -// ); -// Box::new(contract) -// } diff --git a/contracts/single-party-pol-holder/src/suite_tests/suite.rs b/contracts/single-party-pol-holder/src/suite_tests/suite.rs deleted file mode 100644 index fc65d9e1..00000000 --- a/contracts/single-party-pol-holder/src/suite_tests/suite.rs +++ /dev/null @@ -1,151 +0,0 @@ -// use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; -// use cosmwasm_std::{Addr, Coin}; -// use cw_multi_test::{App, AppResponse, Executor}; - -// use super::holder_contract; - -// const ADMIN: &str = "admin"; -// pub const DEFAULT_WITHDRAWER: &str = "authorizedwithdrawer"; - -// pub struct Suite { -// pub app: App, -// pub holder: Addr, -// pub admin: Addr, -// pub holder_code_id: u64, -// pub pool_address: String, -// } - -// pub struct SuiteBuilder { -// pub instantiate: InstantiateMsg, -// pub app: App, -// } - -// impl Default for SuiteBuilder { -// fn default() -> Self { -// Self { -// instantiate: InstantiateMsg { -// withdrawer: Some(DEFAULT_WITHDRAWER.to_string()), -// pool_address: "stablepairpool".to_string(), -// }, -// app: App::default(), -// } -// } -// } - -// impl SuiteBuilder { -// pub fn with_withdrawer(mut self, addr: Option) -> Self { -// self.instantiate.withdrawer = addr; -// self -// } - -// pub fn with_pool(mut self, addr: String) -> Self { -// self.instantiate.pool_address = addr; -// self -// } - -// pub fn build(self) -> Suite { -// let mut app = self.app; -// let holder_code = app.store_code(holder_contract()); -// let holder = app -// .instantiate_contract( -// holder_code, -// Addr::unchecked(ADMIN), -// &self.instantiate, -// &[], -// "holder", -// Some(ADMIN.to_string()), -// ) -// .unwrap(); -// Suite { -// app, -// holder, -// admin: Addr::unchecked(ADMIN), -// holder_code_id: holder_code, -// pool_address: self.instantiate.pool_address, -// } -// } -// } - -// // actions -// impl Suite { -// pub fn withdraw_liquidity(&mut self, caller: &str) -> AppResponse { -// self.app -// .execute_contract( -// Addr::unchecked(caller), -// self.holder.clone(), -// &ExecuteMsg::WithdrawLiquidity {}, -// &[], -// ) -// .unwrap() -// } - -// /// sends a message on caller's behalf to withdraw a specified amount of tokens -// pub fn withdraw_tokens(&mut self, caller: &str, quantity: Vec) -> AppResponse { -// self.app -// .execute_contract( -// Addr::unchecked(caller), -// self.holder.clone(), -// &ExecuteMsg::Withdraw { -// quantity: Some(quantity), -// }, -// &[], -// ) -// .unwrap() -// } - -// /// sends a message on caller's behalf to withdraw remaining balance -// pub fn withdraw_all(&mut self, caller: &str) -> anyhow::Result { -// self.app.execute_contract( -// Addr::unchecked(caller), -// self.holder.clone(), -// &ExecuteMsg::Withdraw { quantity: None }, -// &[], -// ) -// } -// } - -// // queries -// impl Suite { -// pub fn query_withdrawer(&self) -> Addr { -// self.app -// .wrap() -// .query_wasm_smart(&self.holder, &QueryMsg::Withdrawer {}) -// .unwrap() -// } -// } - -// // helper -// impl Suite { -// pub fn fund_holder(&mut self, tokens: Vec) -> AppResponse { -// self.app -// .sudo(cw_multi_test::SudoMsg::Bank( -// cw_multi_test::BankSudo::Mint { -// to_address: self.holder.to_string(), -// amount: tokens, -// }, -// )) -// .unwrap() -// } - -// pub fn assert_holder_balance(&mut self, tokens: Vec) { -// for c in &tokens { -// let queried_amount = self -// .app -// .wrap() -// .query_balance(self.holder.to_string(), c.denom.clone()) -// .unwrap(); -// assert_eq!(&queried_amount, c); -// } -// } - -// pub fn assert_withdrawer_balance(&mut self, tokens: Vec) { -// for c in &tokens { -// let queried_amount = self -// .app -// .wrap() -// .query_balance(DEFAULT_WITHDRAWER.to_string(), c.denom.clone()) -// .unwrap(); -// assert_eq!(&queried_amount, c); -// } -// } -// } diff --git a/contracts/single-party-pol-holder/src/suite_tests/tests.rs b/contracts/single-party-pol-holder/src/suite_tests/tests.rs deleted file mode 100644 index d7a61d69..00000000 --- a/contracts/single-party-pol-holder/src/suite_tests/tests.rs +++ /dev/null @@ -1,141 +0,0 @@ -// use super::suite::{SuiteBuilder, DEFAULT_WITHDRAWER}; -// use cosmwasm_std::{coin, coins, Addr}; - -// #[test] -// fn test_instantiate_and_query_withdrawer() { -// let suite = SuiteBuilder::default().build(); -// assert_eq!( -// suite.query_withdrawer(), -// Addr::unchecked(DEFAULT_WITHDRAWER.to_string()) -// ); -// } - -// #[test] -// #[should_panic(expected = "Invalid input: address not normalized")] -// fn test_instantiate_invalid_withdrawer() { -// SuiteBuilder::default() -// .with_withdrawer(Some("0Oo0Oo".to_string())) -// .build(); -// } - -// #[test] -// #[should_panic(expected = "Invalid input: address not normalized")] -// fn test_instantiate_invalid_lp_addr() { -// SuiteBuilder::default() -// .with_pool("0Oo0Oo".to_string()) -// .build(); -// } - -// #[test] -// #[should_panic(expected = "Unauthorized")] -// fn test_withdraw_all_unauthorized() { -// let mut suite = SuiteBuilder::default().build(); - -// suite.fund_holder(coins(100, "coin")); - -// // attacker attempts to withdraw, panic -// suite.withdraw_all("attacker").unwrap(); -// } - -// #[test] -// fn test_withdraw_all_single_denom() { -// let mut suite = SuiteBuilder::default().build(); - -// suite.fund_holder(coins(100, "coin")); - -// // withdraw all -// suite.withdraw_all(DEFAULT_WITHDRAWER).unwrap(); - -// // check to see there is no balance -// suite.assert_holder_balance(coins(0, "coin")); - -// // and withdrawer has them all -// suite.assert_withdrawer_balance(coins(100, "coin")); -// } - -// #[test] -// fn test_withdraw_all_two_denoms() { -// let mut suite = SuiteBuilder::default().build(); - -// let balances = vec![coin(80, "atom"), coin(70, "statom")]; -// suite.fund_holder(balances.clone()); - -// // withdraw all -// suite.withdraw_all(DEFAULT_WITHDRAWER).unwrap(); - -// // assert all funds are now in withdrawer address -// suite.assert_holder_balance(vec![coin(0, "atom"), coin(0, "statom")]); -// suite.assert_withdrawer_balance(balances); -// } - -// #[test] -// fn test_fund_single_withdraw_partial_single_denom() { -// let mut suite = SuiteBuilder::default().build(); - -// suite.fund_holder(vec![coin(80, "atom")]); - -// // withdraw 75 out of a total of 100 tokens -// suite.withdraw_tokens(DEFAULT_WITHDRAWER, coins(75, "atom")); - -// // check to see there are 25 tokens left in contract -// suite.assert_holder_balance(coins(5, "atom")); - -// // and holder has received 75 -// suite.assert_withdrawer_balance(coins(75, "atom")); -// } -// #[test] -// fn test_fund_multi_denom_withdraw_partial_two_denom() { -// let mut suite = SuiteBuilder::default().build(); - -// let balances = vec![coin(80, "atom"), coin(70, "statom")]; -// suite.fund_holder(balances); - -// let amt_to_withdraw = vec![coin(50, "atom"), coin(30, "statom")]; - -// suite.withdraw_tokens(DEFAULT_WITHDRAWER, amt_to_withdraw.clone()); - -// let expected_balance = vec![coin(30, "atom"), coin(40, "statom")]; -// suite.assert_holder_balance(expected_balance); -// suite.assert_withdrawer_balance(amt_to_withdraw); -// } - -// #[test] -// fn test_fund_multi_denom_withdraw_exact_single_denom() { -// let mut suite = SuiteBuilder::default().build(); - -// let balances = vec![coin(80, "atom"), coin(70, "stuatom")]; -// suite.fund_holder(balances); - -// suite.withdraw_tokens(DEFAULT_WITHDRAWER, coins(70, "stuatom")); - -// // check to see there are 0 tokens left -// suite.assert_holder_balance(vec![coin(80, "atom")]); - -// suite.assert_withdrawer_balance(coins(70, "stuatom")); -// } - -// #[test] -// #[should_panic(expected = "Cannot Sub with 70 and 100")] -// fn test_fund_single_and_withdraw_too_big_single_denom() { -// let mut suite = SuiteBuilder::default().build(); -// let holder_balances = vec![coin(80, "atom"), coin(70, "statom")]; -// suite.fund_holder(holder_balances); - -// suite.withdraw_tokens(DEFAULT_WITHDRAWER, coins(100, "statom")); -// } - -// #[test] -// #[should_panic(expected = "No withdrawer address configured")] -// fn test_withdraw_liquidity_no_withdrawer() { -// let mut suite = SuiteBuilder::default().with_withdrawer(None).build(); - -// suite.withdraw_liquidity(DEFAULT_WITHDRAWER); -// } - -// #[test] -// #[should_panic(expected = "No withdrawer address configured")] -// fn test_withdraw_balances_no_withdrawer() { -// let mut suite = SuiteBuilder::default().with_withdrawer(None).build(); - -// suite.withdraw_tokens(DEFAULT_WITHDRAWER, coins(100, "statom")); -// } diff --git a/contracts/stride-liquid-staker/src/lib.rs b/contracts/stride-liquid-staker/src/lib.rs index 8eaeae41..f1dc5a5a 100644 --- a/contracts/stride-liquid-staker/src/lib.rs +++ b/contracts/stride-liquid-staker/src/lib.rs @@ -7,7 +7,3 @@ pub mod error; pub mod helpers; pub mod msg; pub mod state; - -#[allow(clippy::unwrap_used)] -#[cfg(test)] -mod suite_test; diff --git a/contracts/stride-liquid-staker/src/suite_test/mod.rs b/contracts/stride-liquid-staker/src/suite_test/mod.rs deleted file mode 100644 index 7b881830..00000000 --- a/contracts/stride-liquid-staker/src/suite_test/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod suite; -mod tests; diff --git a/contracts/stride-liquid-staker/src/suite_test/suite.rs b/contracts/stride-liquid-staker/src/suite_test/suite.rs deleted file mode 100644 index 8b137891..00000000 --- a/contracts/stride-liquid-staker/src/suite_test/suite.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/contracts/stride-liquid-staker/src/suite_test/tests.rs b/contracts/stride-liquid-staker/src/suite_test/tests.rs deleted file mode 100644 index 8b137891..00000000 --- a/contracts/stride-liquid-staker/src/suite_test/tests.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/contracts/swap-covenant/Cargo.toml b/contracts/swap-covenant/Cargo.toml index 29ef7a43..3b104488 100644 --- a/contracts/swap-covenant/Cargo.toml +++ b/contracts/swap-covenant/Cargo.toml @@ -44,9 +44,3 @@ covenant-native-splitter = { workspace = true, features = ["library"] } covenant-ibc-forwarder = { workspace = true, features = ["library"] } covenant-interchain-router = { workspace = true, features = ["library"] } covenant-native-router = { workspace = true, features = ["library"] } - -[dev-dependencies] -cw-multi-test = { workspace = true } -anyhow = { workspace = true } -astroport = { workspace = true } -prost = { workspace = true } diff --git a/contracts/swap-covenant/src/lib.rs b/contracts/swap-covenant/src/lib.rs index 3b47dbd4..0faea8f4 100644 --- a/contracts/swap-covenant/src/lib.rs +++ b/contracts/swap-covenant/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)] -mod suite_test; diff --git a/contracts/swap-covenant/src/suite_test/mod.rs b/contracts/swap-covenant/src/suite_test/mod.rs deleted file mode 100644 index 93957587..00000000 --- a/contracts/swap-covenant/src/suite_test/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod suite; -mod tests; -mod unit_tests; diff --git a/contracts/swap-covenant/src/suite_test/suite.rs b/contracts/swap-covenant/src/suite_test/suite.rs deleted file mode 100644 index 8ffc79fb..00000000 --- a/contracts/swap-covenant/src/suite_test/suite.rs +++ /dev/null @@ -1,70 +0,0 @@ -// use cosmwasm_std::{Addr, Empty, Uint128, Uint64}; -// use cw_multi_test::{App, Contract, ContractWrapper}; - -// use crate::msg::{InstantiateMsg, PresetIbcFee, Timeouts}; - -// pub const _CREATOR_ADDR: &str = "admin"; -// pub const _TODO: &str = "replace"; - -// fn _covenant_clock() -> Box> { -// Box::new( -// ContractWrapper::new( -// covenant_clock::contract::execute, -// covenant_clock::contract::instantiate, -// covenant_clock::contract::query, -// ) -// .with_reply(covenant_clock::contract::reply) -// .with_migrate(covenant_clock::contract::migrate), -// ) -// } - -// pub(crate) struct Suite { -// pub app: App, -// pub covenant_address: Addr, -// } - -// pub(crate) struct SuiteBuilder { -// pub instantiate: InstantiateMsg, -// } - -// impl Default for SuiteBuilder { -// fn default() -> Self { -// Self { -// instantiate: InstantiateMsg { -// label: "swap-covenant".to_string(), -// preset_ibc_fee: PresetIbcFee { -// ack_fee: Uint128::new(1000), -// timeout_fee: Uint128::new(1000), -// }, -// timeouts: Timeouts { -// ica_timeout: Uint64::new(50), -// ibc_transfer_timeout: Uint64::new(50), -// }, -// contract_codes: todo!(), -// clock_tick_max_gas: todo!(), -// lockup_config: todo!(), -// covenant_terms: todo!(), -// party_a_config: todo!(), -// party_b_config: todo!(), -// splits: todo!(), -// fallback_split: todo!(), -// }, -// } -// } -// } - -// impl SuiteBuilder { -// pub fn build(self) -> Suite { -// let app = App::default(); -// Suite { -// app, -// covenant_address: todo!(), -// } -// } -// } - -// // assertion helpers -// impl Suite {} - -// // queries -// impl Suite {} diff --git a/contracts/swap-covenant/src/suite_test/tests.rs b/contracts/swap-covenant/src/suite_test/tests.rs deleted file mode 100644 index 8b137891..00000000 --- a/contracts/swap-covenant/src/suite_test/tests.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/contracts/swap-covenant/src/suite_test/unit_tests.rs b/contracts/swap-covenant/src/suite_test/unit_tests.rs deleted file mode 100644 index 8b137891..00000000 --- a/contracts/swap-covenant/src/suite_test/unit_tests.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/contracts/swap-holder/Cargo.toml b/contracts/swap-holder/Cargo.toml index abb2cd78..109d7d68 100644 --- a/contracts/swap-holder/Cargo.toml +++ b/contracts/swap-holder/Cargo.toml @@ -29,7 +29,3 @@ covenant-macros = { workspace = true } covenant-utils = { workspace = true } cosmos-sdk-proto = { workspace = true } neutron-sdk = { workspace = true } - -[dev-dependencies] -cw-multi-test = { workspace = true } -anyhow = { workspace = true } diff --git a/contracts/swap-holder/src/lib.rs b/contracts/swap-holder/src/lib.rs index 20b2e3bb..a5abdbb0 100644 --- a/contracts/swap-holder/src/lib.rs +++ b/contracts/swap-holder/src/lib.rs @@ -2,6 +2,3 @@ pub mod contract; pub mod error; pub mod msg; pub mod state; - -#[cfg(test)] -mod suite_tests; diff --git a/contracts/swap-holder/src/suite_tests/mod.rs b/contracts/swap-holder/src/suite_tests/mod.rs deleted file mode 100644 index 19de9384..00000000 --- a/contracts/swap-holder/src/suite_tests/mod.rs +++ /dev/null @@ -1,50 +0,0 @@ -use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{to_json_binary, Binary, Deps, Empty, Env, StdResult}; -use covenant_clock::test_helpers::helpers::{ - mock_clock_execute, mock_clock_instantiate, mock_clock_query, -}; -use covenant_macros::covenant_deposit_address; -use cw_multi_test::{Contract, ContractWrapper}; - -mod suite; -mod tests; - -pub fn swap_holder_contract() -> Box> { - let contract = ContractWrapper::new( - crate::contract::execute, - crate::contract::instantiate, - crate::contract::query, - ); - Box::new(contract) -} - -pub fn mock_deposit_contract() -> Box> { - let contract = ContractWrapper::new( - crate::contract::execute, - crate::contract::instantiate, - query, - ); - Box::new(contract) -} - -#[cfg(not(feature = "library"))] -use cosmwasm_std::entry_point; - -#[covenant_deposit_address] -#[cw_serde] -#[derive(QueryResponses)] -pub enum QueryMsg {} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(_deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - match msg { - QueryMsg::DepositAddress {} => Ok(to_json_binary(&"native-splitter")?), - } -} - -pub fn mock_clock_deps_contract() -> Box> { - let contract = - ContractWrapper::new(mock_clock_execute, mock_clock_instantiate, mock_clock_query); - - Box::new(contract) -} diff --git a/contracts/swap-holder/src/suite_tests/suite.rs b/contracts/swap-holder/src/suite_tests/suite.rs deleted file mode 100644 index 6cedb16a..00000000 --- a/contracts/swap-holder/src/suite_tests/suite.rs +++ /dev/null @@ -1,220 +0,0 @@ -use crate::{ - msg::{ContractState, ExecuteMsg, InstantiateMsg, QueryMsg, RefundConfig}, - suite_tests::mock_clock_deps_contract, -}; -use cosmwasm_std::{Addr, Coin, Uint128}; -use covenant_clock::test_helpers::helpers::mock_clock_instantiate_message; -use covenant_utils::{ - CovenantPartiesConfig, CovenantParty, CovenantTerms, ReceiverConfig, SwapCovenantTerms, -}; -use cw_multi_test::{App, AppResponse, Executor, SudoMsg}; -use cw_utils::Expiration; - -use super::{mock_deposit_contract, swap_holder_contract}; - -pub const ADMIN: &str = "admin"; - -pub const DENOM_A: &str = "denom_a"; -pub const DENOM_B: &str = "denom_b"; - -pub const PARTY_A_ADDR: &str = "party_a"; -pub const PARTY_B_ADDR: &str = "party_b"; - -pub const CLOCK_ADDR: &str = "clock_address"; -pub const NEXT_CONTRACT: &str = "next_contract"; - -pub const INITIAL_BLOCK_HEIGHT: u64 = 12345; -pub const INITIAL_BLOCK_NANOS: u64 = 1571797419879305533; - -pub struct Suite { - pub app: App, - pub holder: Addr, - pub mock_deposit: Addr, - pub party_a: CovenantParty, - pub party_b: CovenantParty, - pub clock: Addr, -} - -pub struct SuiteBuilder { - pub instantiate: InstantiateMsg, - pub app: App, -} - -impl Default for SuiteBuilder { - fn default() -> Self { - Self { - instantiate: InstantiateMsg { - clock_address: CLOCK_ADDR.to_string(), - next_contract: NEXT_CONTRACT.to_string(), - lockup_config: cw_utils::Expiration::Never {}, - parties_config: CovenantPartiesConfig { - party_a: CovenantParty { - addr: PARTY_A_ADDR.to_string(), - receiver_config: ReceiverConfig::Native(PARTY_A_ADDR.to_string()), - native_denom: DENOM_A.to_string(), - }, - party_b: CovenantParty { - addr: PARTY_B_ADDR.to_string(), - receiver_config: ReceiverConfig::Native(PARTY_B_ADDR.to_string()), - native_denom: DENOM_B.to_string(), - }, - }, - covenant_terms: CovenantTerms::TokenSwap(SwapCovenantTerms { - party_a_amount: Uint128::new(400), - party_b_amount: Uint128::new(20), - }), - refund_config: RefundConfig { - party_a_refund_address: PARTY_A_ADDR.to_string(), - party_b_refund_address: PARTY_B_ADDR.to_string(), - }, - }, - app: App::default(), - } - } -} - -impl SuiteBuilder { - pub fn with_lockup_config(mut self, config: Expiration) -> Self { - self.instantiate.lockup_config = config; - self - } - - pub fn build(mut self) -> Suite { - let mut app = self.app; - let holder_code = app.store_code(swap_holder_contract()); - let mock_deposit_code = app.store_code(mock_deposit_contract()); - let mock_clock_code = app.store_code(mock_clock_deps_contract()); - - let clock_address = app - .instantiate_contract( - mock_clock_code, - Addr::unchecked(ADMIN), - &mock_clock_instantiate_message(), - &[], - "clock", - Some(ADMIN.to_string()), - ) - .unwrap(); - self.instantiate.clock_address = clock_address.to_string(); - - let mock_deposit = app - .instantiate_contract( - mock_deposit_code, - Addr::unchecked(ADMIN), - &self.instantiate, - &[], - "holder", - Some(ADMIN.to_string()), - ) - .unwrap(); - - self.instantiate.next_contract = mock_deposit.to_string(); - let holder = app - .instantiate_contract( - holder_code, - Addr::unchecked(ADMIN), - &self.instantiate, - &[], - "holder", - Some(ADMIN.to_string()), - ) - .unwrap(); - - Suite { - app, - holder, - mock_deposit, - party_a: self.instantiate.parties_config.party_a, - party_b: self.instantiate.parties_config.party_b, - clock: clock_address, - } - } -} - -// actions -impl Suite { - pub fn tick(&mut self, caller: &str) -> Result { - self.app.execute_contract( - Addr::unchecked(caller), - self.holder.clone(), - &ExecuteMsg::Tick {}, - &[], - ) - } -} - -// queries -impl Suite { - pub fn query_next_contract(&self) -> Addr { - self.app - .wrap() - .query_wasm_smart(&self.holder, &QueryMsg::NextContract {}) - .unwrap() - } - - pub fn query_lockup_config(&self) -> Expiration { - self.app - .wrap() - .query_wasm_smart(&self.holder, &QueryMsg::LockupConfig {}) - .unwrap() - } - - pub fn query_covenant_parties(&self) -> CovenantPartiesConfig { - self.app - .wrap() - .query_wasm_smart(&self.holder, &QueryMsg::CovenantParties {}) - .unwrap() - } - - pub fn query_covenant_terms(&self) -> CovenantTerms { - self.app - .wrap() - .query_wasm_smart(&self.holder, &QueryMsg::CovenantTerms {}) - .unwrap() - } - - pub fn query_clock_address(&self) -> Addr { - self.app - .wrap() - .query_wasm_smart(&self.holder, &QueryMsg::ClockAddress {}) - .unwrap() - } - - pub fn query_contract_state(&self) -> ContractState { - self.app - .wrap() - .query_wasm_smart(&self.holder, &QueryMsg::ContractState {}) - .unwrap() - } - - pub fn query_remote_chain_splitter_balances(&self) -> Vec { - self.app - .wrap() - .query_all_balances("native-splitter") - .unwrap() - } - - pub fn query_party_denom(&self, denom: String, party: String) -> Coin { - self.app.wrap().query_balance(party, denom).unwrap() - } -} - -// helper -impl Suite { - pub fn pass_blocks(&mut self, n: u64) { - self.app.update_block(|b| b.height += n); - } - - pub fn pass_minutes(&mut self, n: u64) { - self.app.update_block(|b| b.time = b.time.plus_minutes(n)); - } - - pub fn fund_coin(&mut self, coin: Coin) -> AppResponse { - self.app - .sudo(SudoMsg::Bank(cw_multi_test::BankSudo::Mint { - to_address: self.holder.to_string(), - amount: vec![coin], - })) - .unwrap() - } -} diff --git a/contracts/swap-holder/src/suite_tests/tests.rs b/contracts/swap-holder/src/suite_tests/tests.rs deleted file mode 100644 index a962a9d4..00000000 --- a/contracts/swap-holder/src/suite_tests/tests.rs +++ /dev/null @@ -1,326 +0,0 @@ -use cosmwasm_std::{Coin, Timestamp, Uint128}; -use covenant_utils::{ - CovenantPartiesConfig, CovenantParty, CovenantTerms, ReceiverConfig, SwapCovenantTerms, -}; -use cw_utils::Expiration; - -use crate::{ - msg::ContractState, - suite_tests::suite::{ - DENOM_A, DENOM_B, INITIAL_BLOCK_HEIGHT, INITIAL_BLOCK_NANOS, PARTY_A_ADDR, PARTY_B_ADDR, - }, -}; - -use super::suite::SuiteBuilder; - -#[test] -fn test_instantiate_happy_and_query_all() { - let suite = SuiteBuilder::default().build(); - let next_contract = suite.query_next_contract(); - let clock_address = suite.query_clock_address(); - let lockup_config = suite.query_lockup_config(); - let covenant_parties = suite.query_covenant_parties(); - let covenant_terms = suite.query_covenant_terms(); - let clock = suite.clock; - assert_eq!(next_contract, "contract1"); - assert_eq!(clock_address, clock.as_str()); - assert_eq!(lockup_config, Expiration::Never {}); - assert_eq!( - covenant_parties, - CovenantPartiesConfig { - party_a: CovenantParty { - addr: PARTY_A_ADDR.to_string(), - native_denom: DENOM_A.to_string(), - receiver_config: ReceiverConfig::Native(PARTY_A_ADDR.to_string()), - }, - party_b: CovenantParty { - native_denom: DENOM_B.to_string(), - addr: PARTY_B_ADDR.to_string(), - receiver_config: ReceiverConfig::Native(PARTY_B_ADDR.to_string()), - }, - } - ); - assert_eq!( - covenant_terms, - CovenantTerms::TokenSwap(SwapCovenantTerms { - party_a_amount: Uint128::new(400), - party_b_amount: Uint128::new(20), - }) - ); -} - -#[test] -#[should_panic(expected = "past lockup config")] -fn test_instantiate_past_lockup_block_height() { - SuiteBuilder::default() - .with_lockup_config(cw_utils::Expiration::AtHeight(1)) - .build(); -} - -#[test] -#[should_panic(expected = "past lockup config")] -fn test_instantiate_past_lockup_block_time() { - SuiteBuilder::default() - .with_lockup_config(cw_utils::Expiration::AtTime(Timestamp::from_seconds(1))) - .build(); -} - -#[test] -#[should_panic(expected = "Caller is not the clock, only clock can tick contracts")] -fn test_tick_unauthorized() { - SuiteBuilder::default() - .build() - .tick("not-the-clock") - .unwrap(); -} - -#[test] -fn test_forward_block_expired_covenant() { - let mut suite = SuiteBuilder::default() - .with_lockup_config(cw_utils::Expiration::AtHeight(INITIAL_BLOCK_HEIGHT + 50)) - .build(); - suite.pass_blocks(100); - let clock = suite.clock.to_string(); - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Instantiated); - suite.tick(clock.as_str()).unwrap(); - - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Expired); -} - -#[test] -fn test_forward_time_expired_covenant() { - let mut suite = SuiteBuilder::default() - .with_lockup_config(cw_utils::Expiration::AtTime(Timestamp::from_nanos( - INITIAL_BLOCK_NANOS + 50, - ))) - .build(); - suite.pass_minutes(100); - let clock = suite.clock.to_string(); - - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Instantiated); - suite.tick(clock.as_str()).unwrap(); - - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Expired); -} - -#[test] -#[should_panic(expected = "Insufficient funds to forward")] -fn test_forward_tick_insufficient_funds() { - let mut suite = SuiteBuilder::default().build(); - let clock = suite.clock.to_string(); - - suite.fund_coin(Coin { - denom: DENOM_A.to_string(), - amount: Uint128::new(10), - }); - suite.fund_coin(Coin { - denom: DENOM_B.to_string(), - amount: Uint128::new(10), - }); - - suite.tick(clock.as_str()).unwrap(); -} - -#[test] -fn test_covenant_query_endpoint() { - let mut suite = SuiteBuilder::default().build(); - let clock = suite.clock.to_string(); - - let coin_a = Coin { - denom: DENOM_A.to_string(), - amount: Uint128::new(500), - }; - let coin_b = Coin { - denom: DENOM_B.to_string(), - amount: Uint128::new(500), - }; - suite.fund_coin(coin_a.clone()); - suite.fund_coin(coin_b.clone()); - - suite.tick(clock.as_str()).unwrap(); - suite.pass_blocks(10); - - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Complete); - - let splitter_balances = suite.query_remote_chain_splitter_balances(); - assert_eq!(2, splitter_balances.len()); - assert_eq!(coin_a, splitter_balances[0]); - assert_eq!(coin_b, splitter_balances[1]); - - let resp: String = suite - .app - .wrap() - .query_wasm_smart( - suite.mock_deposit, - &covenant_utils::neutron::QueryMsg::DepositAddress {}, - ) - .unwrap(); -} - -#[test] -fn test_forward_tick() { - let mut suite = SuiteBuilder::default().build(); - let clock = suite.clock.to_string(); - - let coin_a = Coin { - denom: DENOM_A.to_string(), - amount: Uint128::new(500), - }; - let coin_b = Coin { - denom: DENOM_B.to_string(), - amount: Uint128::new(500), - }; - - suite.fund_coin(coin_a.clone()); - suite.fund_coin(coin_b.clone()); - - suite.tick(clock.as_str()).unwrap(); - suite.pass_blocks(10); - - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Complete); - - let splitter_balances = suite.query_remote_chain_splitter_balances(); - assert_eq!(2, splitter_balances.len()); - assert_eq!(coin_a, splitter_balances[0]); - assert_eq!(coin_b, splitter_balances[1]); -} - -#[test] -fn test_refund_nothing_to_refund() { - let mut suite = SuiteBuilder::default() - .with_lockup_config(cw_utils::Expiration::AtHeight(21345)) - .build(); - let clock = suite.clock.to_string(); - - suite.pass_blocks(10000); - - // first tick acknowledges the expiration - suite.tick(clock.as_str()).unwrap(); - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Expired); - - // second tick completes - suite.tick(clock.as_str()).unwrap(); - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Complete); - - let party_a_bal = suite.query_party_denom(DENOM_A.to_string(), suite.party_a.addr.to_string()); - let party_b_bal = suite.query_party_denom(DENOM_B.to_string(), suite.party_b.addr.to_string()); - - assert_eq!(Uint128::zero(), party_a_bal.amount); - assert_eq!(Uint128::zero(), party_b_bal.amount); -} - -#[test] -fn test_refund_party_a() { - let mut suite = SuiteBuilder::default() - .with_lockup_config(cw_utils::Expiration::AtHeight(21345)) - .build(); - let clock = suite.clock.to_string(); - - let coin_a = Coin { - denom: DENOM_A.to_string(), - amount: Uint128::new(500), - }; - - suite.fund_coin(coin_a); - suite.pass_blocks(10000); - - // first tick acknowledges the expiration - suite.tick(clock.as_str()).unwrap(); - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Expired); - - // second tick refunds - suite.tick(clock.as_str()).unwrap(); - // third tick acknowledges the refund and completes - suite.tick(clock.as_str()).unwrap(); - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Complete); - - let party_a_bal = suite.query_party_denom(DENOM_A.to_string(), suite.party_a.addr.to_string()); - let party_b_bal = suite.query_party_denom(DENOM_B.to_string(), suite.party_b.addr.to_string()); - - assert_eq!(Uint128::new(500), party_a_bal.amount); - assert_eq!(Uint128::zero(), party_b_bal.amount); -} - -#[test] -fn test_refund_party_b() { - let mut suite = SuiteBuilder::default() - .with_lockup_config(cw_utils::Expiration::AtHeight(21345)) - .build(); - let clock = suite.clock.to_string(); - - let coin_b = Coin { - denom: DENOM_B.to_string(), - amount: Uint128::new(500), - }; - suite.fund_coin(coin_b); - - suite.pass_blocks(10000); - - // first tick acknowledges the expiration - suite.tick(clock.as_str()).unwrap(); - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Expired); - - // second refunds - suite.tick(clock.as_str()).unwrap(); - // third tick completes - suite.tick(clock.as_str()).unwrap(); - - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Complete); - - let party_a_bal = suite.query_party_denom(DENOM_A.to_string(), suite.party_a.addr.to_string()); - let party_b_bal = suite.query_party_denom(DENOM_B.to_string(), suite.party_b.addr.to_string()); - - assert_eq!(Uint128::zero(), party_a_bal.amount); - assert_eq!(Uint128::new(500), party_b_bal.amount); -} - -#[test] -fn test_refund_both_parties() { - let mut suite = SuiteBuilder::default() - .with_lockup_config(cw_utils::Expiration::AtHeight(21345)) - .build(); - let clock = suite.clock.to_string(); - let coin_a = Coin { - denom: DENOM_A.to_string(), - amount: Uint128::new(300), - }; - suite.fund_coin(coin_a); - let coin_b = Coin { - denom: DENOM_B.to_string(), - amount: Uint128::new(10), - }; - suite.fund_coin(coin_b); - - suite.pass_blocks(10000); - - // first tick acknowledges the expiration - suite.tick(clock.as_str()).unwrap(); - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Expired); - - // second tick refunds the parties - suite.tick(clock.as_str()).unwrap(); - // third tick acknowledges the refund and completes - suite.tick(clock.as_str()).unwrap(); - - let state = suite.query_contract_state(); - assert_eq!(state, ContractState::Complete); - - let party_a_bal = suite.query_party_denom(DENOM_A.to_string(), suite.party_a.addr.to_string()); - let party_b_bal = suite.query_party_denom(DENOM_B.to_string(), suite.party_b.addr.to_string()); - - assert_eq!(Uint128::new(300), party_a_bal.amount); - assert_eq!(Uint128::new(10), party_b_bal.amount); -} diff --git a/contracts/two-party-pol-covenant/Cargo.toml b/contracts/two-party-pol-covenant/Cargo.toml index d3256a8a..360b5664 100644 --- a/contracts/two-party-pol-covenant/Cargo.toml +++ b/contracts/two-party-pol-covenant/Cargo.toml @@ -47,9 +47,3 @@ covenant-two-party-pol-holder = { workspace = true, features = ["library"] } covenant-astroport-liquid-pooler = { workspace = true, features = ["library"] } covenant-osmo-liquid-pooler = { workspace = true, features = ["library"] } astroport = { workspace = true } - -[dev-dependencies] -cw-multi-test = { workspace = true } -anyhow = { workspace = true } -astroport = { workspace = true } -prost = { workspace = true } diff --git a/contracts/two-party-pol-holder/Cargo.toml b/contracts/two-party-pol-holder/Cargo.toml index 810af58d..a97f47a8 100644 --- a/contracts/two-party-pol-holder/Cargo.toml +++ b/contracts/two-party-pol-holder/Cargo.toml @@ -30,7 +30,3 @@ astroport = { workspace = true } cw20 = { workspace = true } cw-utils = { workspace = true } covenant-utils = { workspace = true } - -[dev-dependencies] -cw-multi-test = { workspace = true } -anyhow = { workspace = true } diff --git a/contracts/two-party-pol-holder/src/lib.rs b/contracts/two-party-pol-holder/src/lib.rs index eab0173f..0faea8f4 100644 --- a/contracts/two-party-pol-holder/src/lib.rs +++ b/contracts/two-party-pol-holder/src/lib.rs @@ -6,6 +6,3 @@ pub mod contract; pub mod error; pub mod msg; pub mod state; - -// #[cfg(test)] -// mod suite_tests; diff --git a/contracts/two-party-pol-holder/src/suite_tests/mod.rs b/contracts/two-party-pol-holder/src/suite_tests/mod.rs deleted file mode 100644 index 338bdb79..00000000 --- a/contracts/two-party-pol-holder/src/suite_tests/mod.rs +++ /dev/null @@ -1,132 +0,0 @@ -// use astroport::asset::{Asset, PairInfo}; -// use cosmwasm_schema::{cw_serde, QueryResponses}; -// use cosmwasm_std::{ -// to_json_binary, Addr, BankMsg, Binary, Coin, Deps, DepsMut, Empty, Env, MessageInfo, Response, -// StdResult, Uint128, -// }; -// use covenant_clock::test_helpers::helpers::{ -// mock_clock_execute, mock_clock_instantiate, mock_clock_query, -// }; -// use covenant_macros::covenant_deposit_address; -// use cw20::{BalanceResponse, Cw20ExecuteMsg, Cw20QueryMsg}; -// use cw_multi_test::{Contract, ContractWrapper}; - -// mod suite; -// mod tests; - -// pub fn two_party_pol_holder_contract() -> Box> { -// let contract = ContractWrapper::new( -// crate::contract::execute, -// crate::contract::instantiate, -// crate::contract::query, -// ); -// Box::new(contract) -// } - -// pub fn mock_deposit_contract() -> Box> { -// let contract = ContractWrapper::new( -// crate::contract::execute, -// crate::contract::instantiate, -// query, -// ); -// Box::new(contract) -// } - -// #[cfg(not(feature = "library"))] -// use cosmwasm_std::entry_point; - -// use crate::error::ContractError; - -// use self::suite::{DENOM_A, DENOM_B}; - -// #[covenant_deposit_address] -// #[cw_serde] -// #[derive(QueryResponses)] -// pub enum QueryMsg {} - -// #[cfg_attr(not(feature = "library"), entry_point)] -// pub fn query(_deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { -// match msg { -// QueryMsg::DepositAddress {} => Ok(to_json_binary(&"splitter")?), -// } -// } - -// pub fn mock_astro_pool_contract() -> Box> { -// let contract = ContractWrapper::new( -// crate::contract::execute, -// crate::contract::instantiate, -// query_astro_pool, -// ); -// Box::new(contract) -// } - -// pub fn mock_astro_lp_token_contract() -> Box> { -// let contract = ContractWrapper::new( -// execute_lp_token, -// crate::contract::instantiate, -// query_astro_lp_token, -// ); -// Box::new(contract) -// } - -// #[cfg_attr(not(feature = "library"), entry_point)] -// pub fn execute_lp_token( -// _deps: DepsMut, -// _env: Env, -// info: MessageInfo, -// _msg: Cw20ExecuteMsg, -// ) -> Result { -// let msg = BankMsg::Send { -// to_address: info.sender.to_string(), -// amount: vec![Coin::new(200, DENOM_A), Coin::new(200, DENOM_B)], -// }; -// Ok(Response::default().add_message(msg)) -// } - -// #[cfg_attr(not(feature = "library"), entry_point)] -// pub fn query_astro_pool( -// _deps: Deps, -// _env: Env, -// msg: astroport::pair::QueryMsg, -// ) -> StdResult { -// match msg { -// astroport::pair::QueryMsg::Pair {} => Ok(to_json_binary(&PairInfo { -// asset_infos: vec![], -// contract_addr: Addr::unchecked("contract1"), -// liquidity_token: Addr::unchecked("contract1"), -// pair_type: astroport::factory::PairType::Xyk {}, -// })?), -// astroport::pair::QueryMsg::Share { amount: _ } => Ok(to_json_binary(&vec![ -// Asset { -// info: astroport::asset::AssetInfo::NativeToken { -// denom: DENOM_A.to_string(), -// }, -// amount: Uint128::new(200), -// }, -// Asset { -// info: astroport::asset::AssetInfo::NativeToken { -// denom: DENOM_B.to_string(), -// }, -// amount: Uint128::new(200), -// }, -// ])?), -// _ => Ok(to_json_binary(&"-")?), -// } -// } - -// #[cfg_attr(not(feature = "library"), entry_point)] -// pub fn query_astro_lp_token(_deps: Deps, _env: Env, msg: cw20::Cw20QueryMsg) -> StdResult { -// match msg { -// Cw20QueryMsg::Balance { address: _ } => Ok(to_json_binary(&BalanceResponse { -// balance: Uint128::new(100), -// })?), -// _ => Ok(to_json_binary(&"-")?), -// } -// } - -// pub fn mock_clock_deps_contract() -> Box> { -// let contract = -// ContractWrapper::new(mock_clock_execute, mock_clock_instantiate, mock_clock_query); - -// Box::new(contract) -// } diff --git a/contracts/two-party-pol-holder/src/suite_tests/suite.rs b/contracts/two-party-pol-holder/src/suite_tests/suite.rs deleted file mode 100644 index 49a38388..00000000 --- a/contracts/two-party-pol-holder/src/suite_tests/suite.rs +++ /dev/null @@ -1,424 +0,0 @@ -// use std::{collections::BTreeMap, str::FromStr}; - -// use crate::{ -// msg::{ -// ContractState, CovenantType, ExecuteMsg, InstantiateMsg, QueryMsg, RagequitConfig, -// TwoPartyPolCovenantConfig, TwoPartyPolCovenantParty, -// }, -// suite_tests::mock_clock_deps_contract, -// }; -// use cosmwasm_std::{Addr, BlockInfo, Coin, Decimal, Timestamp, Uint128}; -// use covenant_clock::test_helpers::helpers::mock_clock_instantiate_message; -// use covenant_utils::{SplitConfig, SplitType}; -// use cw_multi_test::{App, AppResponse, Executor, SudoMsg}; -// use cw_utils::Expiration; - -// use super::{ -// mock_astro_lp_token_contract, mock_astro_pool_contract, mock_deposit_contract, -// two_party_pol_holder_contract, -// }; - -// pub const ADMIN: &str = "admin"; - -// pub const DENOM_A: &str = "denom_a"; -// pub const DENOM_B: &str = "denom_b"; - -// pub const PARTY_A_ADDR: &str = "party_a"; -// pub const PARTY_B_ADDR: &str = "party_b"; - -// pub const PARTY_A_ROUTER: &str = "party_a_router"; -// pub const PARTY_B_ROUTER: &str = "party_b_router"; - -// pub const CLOCK_ADDR: &str = "contract0"; -// pub const NEXT_CONTRACT: &str = "contract3"; - -// pub const POOL: &str = "contract2"; - -// pub const INITIAL_BLOCK_HEIGHT: u64 = 12345; -// pub const INITIAL_BLOCK_NANOS: u64 = 1571797419879305533; - -// pub struct Suite { -// pub app: App, -// pub holder: Addr, -// pub mock_deposit: Addr, -// } - -// pub struct SuiteBuilder { -// pub instantiate: InstantiateMsg, -// pub app: App, -// } - -// impl Default for SuiteBuilder { -// fn default() -> Self { -// let mut denom_a_split = BTreeMap::new(); -// denom_a_split.insert( -// PARTY_A_ROUTER.to_string(), -// Decimal::from_str("0.5").unwrap(), -// ); -// denom_a_split.insert( -// PARTY_B_ROUTER.to_string(), -// Decimal::from_str("0.5").unwrap(), -// ); -// let mut denom_b_split = BTreeMap::new(); -// denom_b_split.insert( -// PARTY_A_ROUTER.to_string(), -// Decimal::from_str("0.5").unwrap(), -// ); -// denom_b_split.insert( -// PARTY_B_ROUTER.to_string(), -// Decimal::from_str("0.5").unwrap(), -// ); - -// let mut splits = BTreeMap::new(); -// splits.insert( -// DENOM_A.to_string(), -// SplitType::Custom(SplitConfig { -// receivers: denom_a_split, -// }), -// ); -// splits.insert( -// DENOM_B.to_string(), -// SplitType::Custom(SplitConfig { -// receivers: denom_b_split, -// }), -// ); - -// Self { -// instantiate: InstantiateMsg { -// pool_address: "contract2".to_string(), -// ragequit_config: RagequitConfig::Disabled, -// deposit_deadline: Expiration::Never {}, -// clock_address: "contract0".to_string(), -// next_contract: "contract3".to_string(), -// lockup_config: Expiration::Never {}, -// covenant_config: TwoPartyPolCovenantConfig { -// party_a: TwoPartyPolCovenantParty { -// router: PARTY_A_ROUTER.to_string(), -// contribution: Coin { -// denom: DENOM_A.to_string(), -// amount: Uint128::new(200), -// }, -// allocation: Decimal::from_ratio(Uint128::one(), Uint128::new(2)), -// host_addr: PARTY_A_ADDR.to_string(), -// controller_addr: PARTY_A_ADDR.to_string(), -// }, -// party_b: TwoPartyPolCovenantParty { -// router: PARTY_B_ROUTER.to_string(), -// contribution: Coin { -// denom: DENOM_B.to_string(), -// amount: Uint128::new(200), -// }, -// host_addr: PARTY_B_ADDR.to_string(), -// controller_addr: PARTY_B_ADDR.to_string(), -// allocation: Decimal::from_ratio(Uint128::one(), Uint128::new(2)), -// }, -// covenant_type: crate::msg::CovenantType::Share {}, -// }, -// splits, -// fallback_split: None, -// }, -// app: App::default(), -// } -// } -// } - -// impl SuiteBuilder { -// pub fn with_lockup_config(mut self, config: Expiration) -> Self { -// self.instantiate.lockup_config = config; -// self -// } - -// pub fn with_covenant_config_type(mut self, config: CovenantType) -> Self { -// self.instantiate.covenant_config.covenant_type = config; -// self -// } - -// pub fn with_splits(mut self, splits: BTreeMap) -> Self { -// self.instantiate.splits = splits; -// self -// } - -// pub fn with_fallback_split(mut self, split: SplitConfig) -> Self { -// self.instantiate.fallback_split = Some(split); -// self -// } - -// pub fn with_ragequit_config(mut self, config: RagequitConfig) -> Self { -// self.instantiate.ragequit_config = config; -// self -// } - -// pub fn with_deposit_deadline(mut self, config: Expiration) -> Self { -// self.instantiate.deposit_deadline = config; -// self -// } - -// pub fn with_allocations(mut self, a_allocation: Decimal, b_allocation: Decimal) -> Self { -// self.instantiate.covenant_config.party_a.allocation = a_allocation; -// self.instantiate.covenant_config.party_b.allocation = b_allocation; -// self -// } - -// pub fn build(mut self) -> Suite { -// let mut app = self.app; -// let holder_code = app.store_code(two_party_pol_holder_contract()); -// let mock_deposit_code = app.store_code(mock_deposit_contract()); -// let astro_pool_mock_code = app.store_code(mock_astro_pool_contract()); -// let astro_lp_token_mock_code = app.store_code(mock_astro_lp_token_contract()); -// let clock_mock_code = app.store_code(mock_clock_deps_contract()); - -// let clock = app -// .instantiate_contract( -// clock_mock_code, -// Addr::unchecked(ADMIN), -// &mock_clock_instantiate_message(), -// &[], -// "clock_mock", -// Some(ADMIN.to_string()), -// ) -// .unwrap(); -// self.instantiate.clock_address = clock.to_string(); -// println!("clock address: {:?}", clock.to_string()); -// let astro_lp = app -// .instantiate_contract( -// astro_lp_token_mock_code, -// Addr::unchecked(ADMIN), -// &self.instantiate, -// &[], -// "astro_mock_lp_code", -// Some(ADMIN.to_string()), -// ) -// .unwrap(); -// println!("astro lp address: {:?}", astro_lp.to_string()); - -// let denom_b = Coin { -// denom: DENOM_B.to_string(), -// amount: Uint128::new(500), -// }; -// let denom_a = Coin { -// denom: DENOM_A.to_string(), -// amount: Uint128::new(500), -// }; -// app.sudo(SudoMsg::Bank(cw_multi_test::BankSudo::Mint { -// to_address: astro_lp.to_string(), -// amount: vec![denom_a, denom_b], -// })) -// .unwrap(); - -// let astro_mock = app -// .instantiate_contract( -// astro_pool_mock_code, -// Addr::unchecked(ADMIN), -// &self.instantiate, -// &[], -// "astro_mock", -// Some(ADMIN.to_string()), -// ) -// .unwrap(); -// println!("astro_mock address: {:?}", astro_mock.to_string()); - -// self.instantiate.pool_address = astro_mock.to_string(); - -// let mock_deposit = app -// .instantiate_contract( -// mock_deposit_code, -// Addr::unchecked(ADMIN), -// &self.instantiate, -// &[], -// "mock_deposit", -// Some(ADMIN.to_string()), -// ) -// .unwrap(); - -// println!("mock deposit: {:?}", mock_deposit.to_string()); -// self.instantiate.next_contract = mock_deposit.to_string(); - -// let holder = app -// .instantiate_contract( -// holder_code, -// Addr::unchecked(ADMIN), -// &self.instantiate, -// &[], -// "holder", -// Some(ADMIN.to_string()), -// ) -// .unwrap(); -// println!("holder address: {holder:?}"); - -// Suite { -// app, -// holder, -// mock_deposit, -// } -// } -// } - -// // actions -// impl Suite { -// pub fn tick(&mut self, caller: &str) -> Result { -// self.app.execute_contract( -// Addr::unchecked(caller), -// self.holder.clone(), -// &ExecuteMsg::Tick {}, -// &[], -// ) -// } - -// pub fn distribute_fallback( -// &mut self, -// caller: &str, -// denoms: Vec, -// ) -> Result { -// self.app.execute_contract( -// Addr::unchecked(caller), -// self.holder.clone(), -// &ExecuteMsg::DistributeFallbackSplit { denoms }, -// &[], -// ) -// } - -// pub fn rq(&mut self, caller: &str) -> Result { -// println!("hq holder {:?}", self.holder.to_string()); -// let resp = self.app.execute_contract( -// Addr::unchecked(caller), -// self.holder.clone(), -// &ExecuteMsg::Ragequit {}, -// &[], -// ); -// println!("rq response: {resp:?}"); -// resp -// } - -// pub fn claim(&mut self, caller: &str) -> Result { -// self.app.execute_contract( -// Addr::unchecked(caller), -// self.holder.clone(), -// &ExecuteMsg::Claim {}, -// &[], -// ) -// } -// } - -// // queries -// impl Suite { -// pub fn query_next_contract(&self) -> Addr { -// self.app -// .wrap() -// .query_wasm_smart(&self.holder, &QueryMsg::NextContract {}) -// .unwrap() -// } - -// pub fn query_covenant_config(&self) -> TwoPartyPolCovenantConfig { -// self.app -// .wrap() -// .query_wasm_smart(&self.holder, &QueryMsg::Config {}) -// .unwrap() -// } - -// pub fn query_pool(&self) -> Addr { -// self.app -// .wrap() -// .query_wasm_smart(&self.holder, &QueryMsg::PoolAddress {}) -// .unwrap() -// } - -// pub fn query_party_a(&self) -> TwoPartyPolCovenantParty { -// self.app -// .wrap() -// .query_wasm_smart(&self.holder, &QueryMsg::ConfigPartyA {}) -// .unwrap() -// } - -// pub fn query_party_b(&self) -> TwoPartyPolCovenantParty { -// self.app -// .wrap() -// .query_wasm_smart(&self.holder, &QueryMsg::ConfigPartyB {}) -// .unwrap() -// } - -// pub fn query_deposit_deadline(&self) -> Expiration { -// self.app -// .wrap() -// .query_wasm_smart(&self.holder, &QueryMsg::DepositDeadline {}) -// .unwrap() -// } - -// pub fn query_lockup_config(&self) -> Expiration { -// self.app -// .wrap() -// .query_wasm_smart(&self.holder, &QueryMsg::LockupConfig {}) -// .unwrap() -// } - -// pub fn query_clock_address(&self) -> Addr { -// self.app -// .wrap() -// .query_wasm_smart(&self.holder, &QueryMsg::ClockAddress {}) -// .unwrap() -// } - -// pub fn query_contract_state(&self) -> ContractState { -// self.app -// .wrap() -// .query_wasm_smart(&self.holder, &QueryMsg::ContractState {}) -// .unwrap() -// } -// } - -// // helper -// impl Suite { -// pub fn pass_blocks(&mut self, n: u64) { -// self.app.update_block(|b| b.height += n); -// } - -// pub fn pass_minutes(&mut self, n: u64) { -// self.app.update_block(|b| b.time = b.time.plus_minutes(n)); -// } - -// pub fn fund_coin(&mut self, coin: Coin) -> AppResponse { -// self.app -// .sudo(SudoMsg::Bank(cw_multi_test::BankSudo::Mint { -// to_address: self.holder.to_string(), -// amount: vec![coin], -// })) -// .unwrap() -// } - -// pub fn get_denom_a_balance(&mut self, addr: String) -> Uint128 { -// self.app.wrap().query_balance(addr, DENOM_A).unwrap().amount -// } - -// pub fn get_denom_b_balance(&mut self, addr: String) -> Uint128 { -// self.app.wrap().query_balance(addr, DENOM_B).unwrap().amount -// } - -// pub fn get_all_balances(&mut self, addr: String) -> Vec { -// self.app.wrap().query_all_balances(addr).unwrap() -// } - -// pub fn get_party_a_coin(&mut self, amount: Uint128) -> Coin { -// Coin { -// denom: DENOM_A.to_string(), -// amount, -// } -// } - -// pub fn get_party_b_coin(&mut self, amount: Uint128) -> Coin { -// Coin { -// denom: DENOM_B.to_string(), -// amount, -// } -// } - -// pub fn get_coin(&mut self, denom: String, amount: Uint128) -> Coin { -// Coin { denom, amount } -// } -// } - -// pub fn get_default_block_info() -> BlockInfo { -// BlockInfo { -// height: 12345, -// time: Timestamp::from_nanos(1571797419879305533), -// chain_id: "cosmos-testnet-14002".to_string(), -// } -// } diff --git a/contracts/two-party-pol-holder/src/suite_tests/tests.rs b/contracts/two-party-pol-holder/src/suite_tests/tests.rs deleted file mode 100644 index 8b9bab29..00000000 --- a/contracts/two-party-pol-holder/src/suite_tests/tests.rs +++ /dev/null @@ -1,825 +0,0 @@ -// use std::{collections::BTreeMap, str::FromStr}; - -// use cosmwasm_std::{Decimal, Timestamp, Uint128}; -// use covenant_utils::{SplitConfig, SplitType}; -// use cw_utils::Expiration; - -// use crate::{ -// error::ContractError, -// msg::{ContractState, RagequitConfig, RagequitTerms}, -// suite_tests::suite::{ -// get_default_block_info, CLOCK_ADDR, DENOM_A, DENOM_B, NEXT_CONTRACT, PARTY_A_ROUTER, -// PARTY_B_ADDR, PARTY_B_ROUTER, POOL, -// }, -// }; - -// use super::suite::{SuiteBuilder, INITIAL_BLOCK_HEIGHT, INITIAL_BLOCK_NANOS, PARTY_A_ADDR}; - -// #[test] -// fn test_instantiate_happy_and_query_all() { -// let suite = SuiteBuilder::default().build(); -// let clock = suite.query_clock_address(); -// let pool = suite.query_pool(); -// let next_contract = suite.query_next_contract(); -// let config_party_a = suite.query_party_a(); -// let config_party_b = suite.query_party_b(); -// let deposit_deadline = suite.query_deposit_deadline(); -// let contract_state = suite.query_contract_state(); -// let lockup_config = suite.query_lockup_config(); - -// assert_eq!(ContractState::Instantiated, contract_state); -// assert_eq!(CLOCK_ADDR, clock); -// assert_eq!(POOL, pool); -// assert_eq!(NEXT_CONTRACT, next_contract.to_string()); -// assert_eq!(PARTY_A_ROUTER, config_party_a.router); -// assert_eq!(PARTY_B_ROUTER, config_party_b.router); -// assert_eq!(Expiration::Never {}, deposit_deadline); -// assert_eq!(Expiration::Never {}, lockup_config); -// } - -// #[test] -// #[should_panic(expected = "Ragequit penalty must be in range of [0.0, 1.0)")] -// fn test_invalid_ragequit_penalty() { -// SuiteBuilder::default() -// .with_ragequit_config(RagequitConfig::Enabled(RagequitTerms { -// penalty: Decimal::one(), -// state: None, -// })) -// .build(); -// } - -// #[test] -// #[should_panic(expected = "Ragequit penalty exceeds party allocation")] -// fn test_ragequit_penalty_exceeds_either_party_allocation() { -// SuiteBuilder::default() -// .with_ragequit_config(RagequitConfig::Enabled(RagequitTerms { -// penalty: Decimal::percent(51), -// state: None, -// })) -// .build(); -// } - -// #[test] -// #[should_panic(expected = "party allocations must add up to 1.0")] -// fn test_instantiate_invalid_allocations() { -// SuiteBuilder::default() -// .with_allocations(Decimal::percent(4), Decimal::percent(20)) -// .build(); -// } - -// #[test] -// #[should_panic(expected = "deposit deadline is already past")] -// fn test_instantiate_invalid_deposit_deadline_block_based() { -// SuiteBuilder::default() -// .with_deposit_deadline(Expiration::AtHeight(1)) -// .build(); -// } - -// #[test] -// #[should_panic(expected = "deposit deadline is already past")] -// fn test_instantiate_invalid_deposit_deadline_time_based() { -// SuiteBuilder::default() -// .with_deposit_deadline(Expiration::AtTime(Timestamp::from_nanos(1))) -// .build(); -// } - -// #[test] -// #[should_panic(expected = "lockup deadline is already past")] -// fn test_instantiate_invalid_lockup_config_time_based() { -// SuiteBuilder::default() -// .with_lockup_config(Expiration::AtTime(Timestamp::from_nanos( -// INITIAL_BLOCK_NANOS - 1, -// ))) -// .build(); -// } - -// #[test] -// #[should_panic(expected = "lockup deadline is already past")] -// fn test_instantiate_invalid_lockup_config_height_based() { -// SuiteBuilder::default() -// .with_lockup_config(Expiration::AtHeight(INITIAL_BLOCK_HEIGHT - 1)) -// .build(); -// } - -// #[test] -// fn test_single_party_deposit_refund_block_based() { -// let mut suite = SuiteBuilder::default() -// .with_deposit_deadline(Expiration::AtHeight(12545)) -// .build(); - -// // party A fulfills their part of covenant but B fails to -// let coin = suite.get_party_a_coin(Uint128::new(500)); -// suite.fund_coin(coin); - -// // time passes, clock ticks.. -// suite.pass_blocks(250); -// suite.tick(CLOCK_ADDR).unwrap(); -// suite.tick(CLOCK_ADDR).unwrap(); - -// let holder_balance = suite.get_denom_a_balance(suite.holder.to_string()); -// let router_a_balance = suite.get_denom_a_balance(suite.query_party_a().router); -// let holder_state = suite.query_contract_state(); - -// assert_eq!(ContractState::Complete, holder_state); -// assert_eq!(Uint128::zero(), holder_balance); -// assert_eq!(Uint128::new(500), router_a_balance); -// } - -// #[test] -// fn test_single_party_deposit_refund_time_based() { -// let current_timestamp = get_default_block_info(); -// let mut suite = SuiteBuilder::default() -// .with_deposit_deadline(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // party A fulfills their part of covenant but B fails to -// let coin = suite.get_party_a_coin(Uint128::new(500)); -// suite.fund_coin(coin); - -// // time passes, clock ticks.. -// suite.pass_minutes(250); -// suite.tick(CLOCK_ADDR).unwrap(); -// suite.tick(CLOCK_ADDR).unwrap(); - -// let holder_balance = suite.get_denom_a_balance(suite.holder.to_string()); -// let router_a_balance = suite.get_denom_a_balance(suite.query_party_a().router); -// let holder_state = suite.query_contract_state(); - -// assert_eq!(ContractState::Complete, holder_state); -// assert_eq!(Uint128::zero(), holder_balance); -// assert_eq!(Uint128::new(500), router_a_balance); -// } - -// #[test] -// fn test_single_party_deposit_refund_no_deposit_deadline() { -// let mut suite = SuiteBuilder::default().build(); - -// // party A fulfills their part of covenant but B fails to -// let coin = suite.get_party_a_coin(Uint128::new(500)); -// suite.fund_coin(coin); - -// // time passes, clock ticks.. -// suite.pass_minutes(25000000); -// let resp: ContractError = suite.tick(CLOCK_ADDR).unwrap_err().downcast().unwrap(); - -// // we assert that holder still holds the tokens and did not advance the state -// let holder_balance = suite.get_denom_a_balance(suite.holder.to_string()); -// let holder_state = suite.query_contract_state(); - -// assert_eq!(ContractState::Instantiated, holder_state); -// assert_eq!(Uint128::new(500), holder_balance); -// assert_eq!(ContractError::InsufficientDeposits {}, resp); -// } - -// #[test] -// fn test_holder_active_does_not_allow_claims() { -// // unimplemented!() -// } - -// #[test] -// fn test_holder_active_not_expired_ticks() { -// let current_timestamp = get_default_block_info(); -// let mut suite = SuiteBuilder::default() -// .with_deposit_deadline(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(500)); -// let coin_b = suite.get_party_b_coin(Uint128::new(500)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// // time passes, clock ticks.. -// suite.pass_minutes(50); -// let resp = suite.tick(CLOCK_ADDR).unwrap(); - -// let has_not_due_attribute = resp -// .events -// .into_iter() -// .flat_map(|e| e.attributes) -// .any(|attr| attr.value == "not_due"); -// let holder_balance_a = suite.get_denom_a_balance(suite.holder.to_string()); -// let holder_balance_b = suite.get_denom_b_balance(suite.holder.to_string()); -// let splitter_balance_a = suite.get_denom_a_balance(suite.mock_deposit.to_string()); -// let splitter_balance_b = suite.get_denom_b_balance(suite.mock_deposit.to_string()); -// let holder_state = suite.query_contract_state(); - -// assert!(has_not_due_attribute); -// assert_eq!(ContractState::Active, holder_state); -// assert_eq!(Uint128::zero(), holder_balance_b); -// assert_eq!(Uint128::zero(), holder_balance_a); -// assert_eq!(Uint128::new(500), splitter_balance_b); -// assert_eq!(Uint128::new(500), splitter_balance_a); -// } - -// #[test] -// fn test_holder_active_expired_tick_advances_state() { -// let current_timestamp = get_default_block_info(); -// let mut suite = SuiteBuilder::default() -// .with_lockup_config(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(500)); -// let coin_b = suite.get_party_b_coin(Uint128::new(500)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// // time passes, clock ticks.. -// suite.pass_minutes(250); -// suite.tick(CLOCK_ADDR).unwrap(); - -// let holder_balance_a = suite.get_denom_a_balance(suite.holder.to_string()); -// let holder_balance_b = suite.get_denom_b_balance(suite.holder.to_string()); -// let splitter_balance_a = suite.get_denom_a_balance(suite.mock_deposit.to_string()); -// let splitter_balance_b = suite.get_denom_b_balance(suite.mock_deposit.to_string()); -// let holder_state = suite.query_contract_state(); - -// assert_eq!(ContractState::Expired, holder_state); -// assert_eq!(Uint128::zero(), holder_balance_b); -// assert_eq!(Uint128::zero(), holder_balance_a); -// assert_eq!(Uint128::new(500), splitter_balance_b); -// assert_eq!(Uint128::new(500), splitter_balance_a); -// } - -// #[test] -// fn test_holder_ragequit_disabled() { -// let mut suite = SuiteBuilder::default() -// .with_ragequit_config(RagequitConfig::Disabled) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(500)); -// let coin_b = suite.get_party_b_coin(Uint128::new(500)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// suite.pass_minutes(300); - -// // advance the state to expired -// suite.tick(CLOCK_ADDR).unwrap(); - -// let err: ContractError = suite.rq(PARTY_A_ADDR).unwrap_err().downcast().unwrap(); -// let state = suite.query_contract_state(); - -// assert_eq!(ContractState::Active {}, state); -// assert_eq!(ContractError::RagequitDisabled {}, err); -// } - -// #[test] -// fn test_holder_ragequit_unauthorized() { -// let mut suite = SuiteBuilder::default() -// .with_ragequit_config(RagequitConfig::Enabled(RagequitTerms { -// penalty: Decimal::from_ratio(Uint128::one(), Uint128::new(10)), -// state: None, -// })) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(500)); -// let coin_b = suite.get_party_b_coin(Uint128::new(500)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// suite.pass_minutes(50); - -// // advance the state to expired -// suite.tick(CLOCK_ADDR).unwrap(); - -// let err: ContractError = suite.rq("random_user").unwrap_err().downcast().unwrap(); -// let state = suite.query_contract_state(); - -// assert_eq!(ContractState::Active {}, state); -// assert_eq!(ContractError::Unauthorized {}, err); -// } - -// #[test] -// fn test_holder_ragequit_not_in_active_state() { -// let current_timestamp = get_default_block_info(); -// let mut suite = SuiteBuilder::default() -// .with_lockup_config(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(500)); -// let coin_b = suite.get_party_b_coin(Uint128::new(500)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// suite.pass_minutes(300); - -// // advance the state to expired -// suite.tick(CLOCK_ADDR).unwrap(); - -// let err: ContractError = suite.rq(PARTY_A_ADDR).unwrap_err().downcast().unwrap(); -// let state = suite.query_contract_state(); - -// assert_eq!(ContractState::Expired {}, state); -// assert_eq!(ContractError::RagequitDisabled {}, err); -// } - -// #[test] -// fn test_holder_ragequit_active_but_expired() { -// let current_timestamp = get_default_block_info(); -// let mut suite = SuiteBuilder::default() -// .with_ragequit_config(RagequitConfig::Enabled(RagequitTerms { -// penalty: Decimal::bps(10), -// state: None, -// })) -// .with_lockup_config(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(500)); -// let coin_b = suite.get_party_b_coin(Uint128::new(500)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// suite.pass_minutes(300); - -// let err: ContractError = suite.rq(PARTY_A_ADDR).unwrap_err().downcast().unwrap(); - -// assert_eq!(ContractError::Expired {}, err); -// } - -// #[test] -// #[should_panic(expected = "covenant is not in active state")] -// fn test_ragequit_double_claim_fails() { -// let current_timestamp = get_default_block_info(); -// let mut suite = SuiteBuilder::default() -// .with_ragequit_config(RagequitConfig::Enabled(RagequitTerms { -// penalty: Decimal::from_ratio(Uint128::one(), Uint128::new(10)), -// state: None, -// })) -// .with_lockup_config(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(500)); -// let coin_b = suite.get_party_b_coin(Uint128::new(500)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// // we ragequit and assert balances have reached router -// suite.rq(PARTY_A_ADDR).unwrap(); - -// let router_a_balance = suite.get_denom_a_balance(PARTY_A_ROUTER.to_string()); -// let router_b_balance = suite.get_denom_b_balance(PARTY_A_ROUTER.to_string()); -// assert_eq!(Uint128::new(200), router_a_balance); -// assert_eq!(Uint128::new(200), router_b_balance); - -// let state = suite.query_contract_state(); -// let config = suite.query_covenant_config(); -// assert_eq!(Decimal::one(), config.party_b.allocation); -// assert_eq!(Decimal::zero(), config.party_a.allocation); -// assert_eq!(ContractState::Ragequit {}, state); - -// // we attempt to rq again and panic -// suite.rq(PARTY_A_ADDR).unwrap(); -// } - -// #[test] -// fn test_share_based_ragequit_flow_to_completion() { -// let current_timestamp = get_default_block_info(); -// let mut suite = SuiteBuilder::default() -// .with_ragequit_config(RagequitConfig::Enabled(RagequitTerms { -// penalty: Decimal::from_ratio(Uint128::one(), Uint128::new(10)), -// state: None, -// })) -// .with_lockup_config(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(500)); -// let coin_b = suite.get_party_b_coin(Uint128::new(500)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// // party A ragequits; assert balances have reached router -// suite.rq(PARTY_A_ADDR).unwrap(); - -// let router_a_balance = suite.get_denom_a_balance(PARTY_A_ROUTER.to_string()); -// let router_b_balance = suite.get_denom_b_balance(PARTY_A_ROUTER.to_string()); -// assert_eq!(Uint128::new(200), router_a_balance); -// assert_eq!(Uint128::new(200), router_b_balance); - -// let state = suite.query_contract_state(); -// let config = suite.query_covenant_config(); -// assert_eq!(Decimal::one(), config.party_b.allocation); -// assert_eq!(Decimal::zero(), config.party_a.allocation); -// assert_eq!(ContractState::Ragequit {}, state); - -// // party B claims -// suite.claim(PARTY_B_ADDR).unwrap(); - -// let router_a_balance = suite.get_denom_a_balance(PARTY_B_ROUTER.to_string()); -// let router_b_balance = suite.get_denom_b_balance(PARTY_B_ROUTER.to_string()); -// assert_eq!(Uint128::new(200), router_a_balance); -// assert_eq!(Uint128::new(200), router_b_balance); - -// let state = suite.query_contract_state(); -// let config = suite.query_covenant_config(); -// assert_eq!(Decimal::zero(), config.party_b.allocation); -// assert_eq!(Decimal::zero(), config.party_a.allocation); -// assert_eq!(ContractState::Complete {}, state); -// } - -// #[test] -// fn test_share_based_expiry_happy_flow_to_completion() { -// let current_timestamp = get_default_block_info(); -// let mut suite = SuiteBuilder::default() -// .with_lockup_config(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(500)); -// let coin_b = suite.get_party_b_coin(Uint128::new(500)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// suite.pass_minutes(250); - -// suite.tick(CLOCK_ADDR).unwrap(); - -// assert_eq!(ContractState::Expired {}, suite.query_contract_state()); -// assert_eq!( -// Uint128::new(0), -// suite.get_denom_a_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(0), -// suite.get_denom_b_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(0), -// suite.get_denom_a_balance(PARTY_B_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(0), -// suite.get_denom_b_balance(PARTY_B_ROUTER.to_string()) -// ); - -// // party B claims -// suite.claim(PARTY_B_ADDR).unwrap(); - -// assert_eq!( -// Uint128::new(0), -// suite.get_denom_a_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(0), -// suite.get_denom_b_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(200), -// suite.get_denom_a_balance(PARTY_B_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(200), -// suite.get_denom_b_balance(PARTY_B_ROUTER.to_string()) -// ); - -// suite.pass_minutes(5); - -// // party A claims -// suite.claim(PARTY_A_ADDR).unwrap(); -// suite.tick(CLOCK_ADDR).unwrap(); - -// let config = suite.query_covenant_config(); -// assert_eq!(Decimal::zero(), config.party_b.allocation); -// assert_eq!(Decimal::zero(), config.party_a.allocation); -// assert_eq!( -// Uint128::new(200), -// suite.get_denom_a_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(200), -// suite.get_denom_b_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(200), -// suite.get_denom_a_balance(PARTY_B_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(200), -// suite.get_denom_b_balance(PARTY_B_ROUTER.to_string()) -// ); -// assert_eq!(ContractState::Complete {}, suite.query_contract_state()); -// } - -// #[test] -// fn test_side_based_expiry_happy_flow_to_completion() { -// let current_timestamp = get_default_block_info(); -// let mut denom_a_split = BTreeMap::new(); -// denom_a_split.insert( -// PARTY_A_ROUTER.to_string(), -// Decimal::from_str("1.0").unwrap(), -// ); -// denom_a_split.insert( -// PARTY_B_ROUTER.to_string(), -// Decimal::from_str("0.0").unwrap(), -// ); -// let mut denom_b_split = BTreeMap::new(); -// denom_b_split.insert( -// PARTY_A_ROUTER.to_string(), -// Decimal::from_str("0.0").unwrap(), -// ); -// denom_b_split.insert( -// PARTY_B_ROUTER.to_string(), -// Decimal::from_str("1.0").unwrap(), -// ); -// let mut splits = BTreeMap::new(); -// splits.insert( -// DENOM_A.to_string(), -// SplitType::Custom(SplitConfig { -// receivers: denom_a_split, -// }), -// ); -// splits.insert( -// DENOM_B.to_string(), -// SplitType::Custom(SplitConfig { -// receivers: denom_b_split, -// }), -// ); -// let mut suite = SuiteBuilder::default() -// .with_splits(splits) -// .with_covenant_config_type(crate::msg::CovenantType::Side) -// .with_lockup_config(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(200)); -// let coin_b = suite.get_party_b_coin(Uint128::new(200)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// suite.pass_minutes(250); - -// suite.tick(CLOCK_ADDR).unwrap(); - -// assert_eq!(ContractState::Expired {}, suite.query_contract_state()); -// assert_eq!( -// Uint128::new(0), -// suite.get_denom_a_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(0), -// suite.get_denom_b_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(0), -// suite.get_denom_a_balance(PARTY_B_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(0), -// suite.get_denom_b_balance(PARTY_B_ROUTER.to_string()) -// ); - -// // party B claims -// suite.claim(PARTY_B_ADDR).unwrap(); - -// assert_eq!( -// Uint128::new(200), -// suite.get_denom_a_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(200), -// suite.get_denom_b_balance(PARTY_B_ROUTER.to_string()) -// ); -// assert_eq!(ContractState::Complete {}, suite.query_contract_state()); -// } - -// #[test] -// fn test_side_based_ragequit_flow_to_completion() { -// let current_timestamp = get_default_block_info(); -// let mut denom_a_split = BTreeMap::new(); -// denom_a_split.insert( -// PARTY_A_ROUTER.to_string(), -// Decimal::from_str("1.0").unwrap(), -// ); -// denom_a_split.insert( -// PARTY_B_ROUTER.to_string(), -// Decimal::from_str("0.0").unwrap(), -// ); -// let mut denom_b_split = BTreeMap::new(); -// denom_b_split.insert( -// PARTY_A_ROUTER.to_string(), -// Decimal::from_str("0.0").unwrap(), -// ); -// denom_b_split.insert( -// PARTY_B_ROUTER.to_string(), -// Decimal::from_str("1.0").unwrap(), -// ); -// let mut splits = BTreeMap::new(); -// splits.insert( -// DENOM_A.to_string(), -// SplitType::Custom(SplitConfig { -// receivers: denom_a_split, -// }), -// ); -// splits.insert( -// DENOM_B.to_string(), -// SplitType::Custom(SplitConfig { -// receivers: denom_b_split, -// }), -// ); -// let mut suite = SuiteBuilder::default() -// .with_splits(splits) -// .with_covenant_config_type(crate::msg::CovenantType::Side) -// .with_ragequit_config(RagequitConfig::Enabled(RagequitTerms { -// penalty: Decimal::from_str("0.1").unwrap(), -// state: None, -// })) -// .with_lockup_config(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(200)); -// let coin_b = suite.get_party_b_coin(Uint128::new(200)); -// suite.fund_coin(coin_a); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// // party A ragequits, forfeiting 10% of their denom to counterparty -// suite.rq(PARTY_A_ADDR).unwrap(); - -// suite.tick(CLOCK_ADDR).unwrap(); - -// assert_eq!(ContractState::Complete {}, suite.query_contract_state()); -// assert_eq!( -// Uint128::new(180), -// suite.get_denom_a_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(200), -// suite.get_denom_b_balance(PARTY_B_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(20), -// suite.get_denom_a_balance(PARTY_B_ROUTER.to_string()) -// ); -// } - -// #[test] -// fn test_distribute_fallback_split() { -// let current_timestamp = get_default_block_info(); -// let mut denom_a_split = BTreeMap::new(); -// denom_a_split.insert( -// PARTY_A_ROUTER.to_string(), -// Decimal::from_str("1.0").unwrap(), -// ); -// denom_a_split.insert( -// PARTY_B_ROUTER.to_string(), -// Decimal::from_str("0.0").unwrap(), -// ); -// let mut denom_b_split = BTreeMap::new(); -// denom_b_split.insert( -// PARTY_A_ROUTER.to_string(), -// Decimal::from_str("0.0").unwrap(), -// ); -// denom_b_split.insert( -// PARTY_B_ROUTER.to_string(), -// Decimal::from_str("1.0").unwrap(), -// ); - -// let mut fallback_split = BTreeMap::new(); -// fallback_split.insert( -// PARTY_A_ROUTER.to_string(), -// Decimal::from_str("0.5").unwrap(), -// ); -// fallback_split.insert( -// PARTY_B_ROUTER.to_string(), -// Decimal::from_str("0.5").unwrap(), -// ); - -// let mut splits = BTreeMap::new(); -// splits.insert( -// DENOM_A.to_string(), -// SplitType::Custom(SplitConfig { -// receivers: denom_a_split, -// }), -// ); -// splits.insert( -// DENOM_B.to_string(), -// SplitType::Custom(SplitConfig { -// receivers: denom_b_split, -// }), -// ); - -// let mut suite = SuiteBuilder::default() -// .with_splits(splits) -// .with_covenant_config_type(crate::msg::CovenantType::Side) -// .with_ragequit_config(RagequitConfig::Enabled(RagequitTerms { -// penalty: Decimal::from_str("0.1").unwrap(), -// state: None, -// })) -// .with_fallback_split(SplitConfig { -// receivers: fallback_split, -// }) -// .with_lockup_config(Expiration::AtTime(current_timestamp.time.plus_minutes(200))) -// .build(); - -// // both parties fulfill their parts of the covenant -// let coin_a = suite.get_party_a_coin(Uint128::new(200)); -// let coin_b = suite.get_party_b_coin(Uint128::new(200)); -// suite.fund_coin(coin_a.clone()); -// suite.fund_coin(coin_b); - -// // we tick the holder to deposit the funds and activate -// suite.tick(CLOCK_ADDR).unwrap(); - -// // mint a bunch of coins to the holder and keep track of their denoms -// let mut denoms = Vec::new(); -// for i in 1..=100 { -// let token_denom = format!("shitcoin_{i:?}"); -// let shitcoin = suite.get_coin(token_denom.to_string(), Uint128::new(100)); -// suite.fund_coin(shitcoin); -// denoms.push(token_denom); -// } - -// // party A ragequits, forfeiting 10% of their denom to counterparty -// suite.rq(PARTY_A_ADDR).unwrap(); -// suite.tick(CLOCK_ADDR).unwrap(); - -// assert_eq!(ContractState::Complete {}, suite.query_contract_state()); -// assert_eq!( -// Uint128::new(180), -// suite.get_denom_a_balance(PARTY_A_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(200), -// suite.get_denom_b_balance(PARTY_B_ROUTER.to_string()) -// ); -// assert_eq!( -// Uint128::new(20), -// suite.get_denom_a_balance(PARTY_B_ROUTER.to_string()) -// ); -// assert_eq!(1, suite.get_all_balances(PARTY_A_ROUTER.to_string()).len()); -// assert_eq!(2, suite.get_all_balances(PARTY_B_ROUTER.to_string()).len()); - -// // first try to distribute the explicit denom which should fail -// suite.fund_coin(coin_a); -// let err: ContractError = suite -// .distribute_fallback("random", vec![DENOM_A.to_string()]) -// .unwrap_err() -// .downcast() -// .unwrap(); -// assert_eq!(err, ContractError::UnauthorizedDenomDistribution {}); - -// // try to distribute mix of explicitly defined denoms and fallback -// let mut random_denoms = Vec::new(); -// random_denoms.extend(denoms.clone()); -// random_denoms.push(DENOM_A.to_string()); -// let err: ContractError = suite -// .distribute_fallback("random", vec![DENOM_A.to_string()]) -// .unwrap_err() -// .downcast() -// .unwrap(); -// assert_eq!(err, ContractError::UnauthorizedDenomDistribution {}); - -// // distribute the fallback and assert it arrives -// suite.distribute_fallback("random", denoms).unwrap(); -// assert_eq!( -// 101, -// suite.get_all_balances(PARTY_A_ROUTER.to_string()).len() -// ); -// assert_eq!( -// 102, -// suite.get_all_balances(PARTY_B_ROUTER.to_string()).len() -// ); - -// // relevant denoms don't get distributed with fallback -// assert_eq!(1, suite.get_all_balances(suite.holder.to_string()).len()); -// } diff --git a/unit-tests/Cargo.toml b/unit-tests/Cargo.toml index bb41d520..31ecc68d 100644 --- a/unit-tests/Cargo.toml +++ b/unit-tests/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "unit-tests" # the name of the package version = "0.1.0" # the current version, obeying semver -authors = ["Art3miX "] +authors = ["Art3miX ", "benskey bekauz@protonmail.com"] edition = "2021" [dev-dependencies] diff --git a/unit-tests/src/test.rs b/unit-tests/src/test.rs deleted file mode 100644 index f847aa0f..00000000 --- a/unit-tests/src/test.rs +++ /dev/null @@ -1,525 +0,0 @@ -// use std::collections::BTreeMap; - -// use cosmwasm_std::{ -// coin, coins, instantiate2_address, Addr, Api, CodeInfoResponse, Decimal, MemoryStorage, -// }; -// use covenant_interchain_splitter::msg::SplitType; -// use covenant_utils::SplitConfig; -// use cw_multi_test::{ -// addons::{MockAddressGenerator, MockApiBech32}, -// App, BankKeeper, BasicAppBuilder, Executor, WasmKeeper, -// }; -// use neutron_sdk::bindings::{ -// msg::{IbcFee, NeutronMsg}, -// query::NeutronQuery, -// }; - -// use sha2::{Digest, Sha256}; - -// use crate::setup::{ -// contracts::{ -// clock_contract, ibc_forwarder_contract, interchain_splitter_contract, stride_lser_contract, -// }, -// custom_module::{NeutronKeeper, CHAIN_PREFIX}, -// DENOM_ATOM, DENOM_NTRN, FAUCET, -// }; - -// type CustomApp = App< -// BankKeeper, -// MockApiBech32, -// MemoryStorage, -// NeutronKeeper, -// WasmKeeper, -// >; - -// pub fn get_addr(addr: &str) -> Addr { -// cw_multi_test::addons::MockApiBech32::new(CHAIN_PREFIX).addr_make(addr) -// } - -// // Do init2 and return the salt and the addr -// fn get_salt_and_addr(app: &CustomApp, code_id: u64, str: &str) -> (Vec, Addr) { -// let mut hasher = Sha256::new(); -// hasher.update(str.to_string()); -// let salt = hasher.finalize().to_vec(); - -// let canonical_creator = app -// .api() -// .addr_canonicalize(get_addr("admin").as_str()) -// .unwrap(); -// let CodeInfoResponse { checksum, .. } = app.wrap().query_wasm_code_info(code_id).unwrap(); -// let canonical_addr = instantiate2_address(&checksum, &canonical_creator, &salt).unwrap(); -// let addr = app.api().addr_humanize(&canonical_addr).unwrap(); -// (salt, addr) -// } - -// /// Test flow: -// /// 1. IBC forwarder expects have X `DENOM_ATOM` (to forward it) -// /// 2. IBC forwarder forward the X `DENOM_ATOM` to stride lser -// /// 3. we manually transfer stride funds from lser ICA to spilitter -// /// 4. on the splitter we expect the funds in the correct denom with IBC trace of the 2 chains -// #[test] -// fn test_stride() { -// const NTRN_HUB_CHANNEL: &str = "channel-1"; -// const HUB_NTRN_CHANNEL: &str = "channel-10"; - -// const NTRN_STRIDE_CHANNEL: &str = "channel-2"; -// const STRIDE_NTRN_CHANNEL: &str = "channel-20"; - -// const HUB_STRIDE_CHANNEL: &str = "channel-3"; -// const STRIDE_HUB_CHANNEL: &str = "channel-30"; - -// // This mocks our ls token denom on stride -// let ATOM_ON_STRIDE_DENOM = format!("{STRIDE_HUB_CHANNEL}/{DENOM_ATOM}"); -// // This mocks our ls token denom on neutron -// let STRIDE_LS_ON_NTRN_DENOM = -// format!("{NTRN_STRIDE_CHANNEL}/{STRIDE_HUB_CHANNEL}/{DENOM_ATOM}"); - -// let admin_addr = get_addr("admin"); -// let faucet_addr = get_addr(FAUCET); - -// let mut app = BasicAppBuilder::new_custom() -// .with_custom(NeutronKeeper::new(CHAIN_PREFIX)) -// .with_api(MockApiBech32::new(CHAIN_PREFIX)) -// .with_wasm(WasmKeeper::default().with_address_generator(MockAddressGenerator)) -// .build(|router, _, storage| { -// router -// .bank -// .init_balance( -// storage, -// &faucet_addr, -// vec![ -// coin(1_000_000_000_000, DENOM_NTRN), -// coin(1_000_000_000_000, DENOM_ATOM), -// ], -// ) -// .unwrap(); - -// // add channels -// // Local channels from ntrn to other chains -// router -// .custom -// .add_local_channel(storage, NTRN_HUB_CHANNEL, HUB_NTRN_CHANNEL) -// .unwrap(); -// router -// .custom -// .add_local_channel(storage, NTRN_STRIDE_CHANNEL, STRIDE_NTRN_CHANNEL) -// .unwrap(); - -// // Remote channels from other chains to other chain -// router -// .custom -// .add_remote_channel(storage, HUB_STRIDE_CHANNEL, STRIDE_HUB_CHANNEL) -// .unwrap(); -// }); - -// // Upload contracts -// let clock_code_id = app.store_code(clock_contract()); -// let ibc_forwarder_code_id = app.store_code(ibc_forwarder_contract()); -// let stride_lser_code_id = app.store_code(stride_lser_contract()); -// let splitter_code_id = app.store_code(interchain_splitter_contract()); - -// // Get init 2 data -// let (forwarder_salt, forwarder_addr) = -// get_salt_and_addr(&app, ibc_forwarder_code_id, "ibc_forwarder"); -// let (stride_salt, stride_addr) = get_salt_and_addr(&app, stride_lser_code_id, "stride"); -// let (splitter_salt, splitter_addr) = get_salt_and_addr(&app, splitter_code_id, "splitter"); - -// // init clock -// let clock_addr = app -// .instantiate_contract( -// clock_code_id, -// admin_addr.clone(), -// &covenant_clock::msg::InstantiateMsg { -// tick_max_gas: None, -// whitelist: vec![ -// forwarder_addr.to_string(), -// splitter_addr.to_string(), -// stride_addr.to_string(), -// ], -// }, -// &[], -// "clock", -// Some(admin_addr.to_string()), -// ) -// .unwrap(); - -// // init forwarder -// app.instantiate2_contract( -// ibc_forwarder_code_id, -// admin_addr.clone(), -// &covenant_ibc_forwarder::msg::InstantiateMsg { -// clock_address: clock_addr.to_string(), -// next_contract: stride_addr.to_string(), -// remote_chain_connection_id: "conn-1".to_string(), -// remote_chain_channel_id: HUB_STRIDE_CHANNEL.to_string(), -// denom: DENOM_ATOM.to_string(), -// amount: 1000_u128.into(), -// ibc_fee: IbcFee { -// recv_fee: vec![], -// ack_fee: coins(100_u128, DENOM_NTRN), -// timeout_fee: coins(100_u128, DENOM_NTRN), -// }, -// ibc_transfer_timeout: 1000_u64.into(), -// ica_timeout: 1000_u64.into(), -// }, -// &[], -// "forwarder", -// Some(admin_addr.to_string()), -// forwarder_salt, -// ) -// .unwrap(); - -// // init stride -// app.instantiate2_contract( -// stride_lser_code_id, -// admin_addr.clone(), -// &covenant_stride_liquid_staker::msg::InstantiateMsg { -// clock_address: clock_addr.to_string(), -// stride_neutron_ibc_transfer_channel_id: STRIDE_NTRN_CHANNEL.to_string(), -// neutron_stride_ibc_connection_id: "conn-1".to_string(), -// next_contract: splitter_addr.to_string(), -// ls_denom: ATOM_ON_STRIDE_DENOM.clone(), -// ibc_fee: IbcFee { -// recv_fee: vec![], -// ack_fee: coins(100_u128, DENOM_NTRN), -// timeout_fee: coins(100_u128, DENOM_NTRN), -// }, -// ibc_transfer_timeout: 1000_u64.into(), -// ica_timeout: 1000_u64.into(), -// }, -// &[], -// "lser", -// Some(admin_addr.to_string()), -// stride_salt, -// ) -// .unwrap(); - -// // init splitter -// let mut splits: BTreeMap = BTreeMap::new(); -// splits.insert("addr".to_string(), Decimal::bps(5000)); -// splits.insert("addr2".to_string(), Decimal::bps(5000)); - -// app.instantiate2_contract( -// splitter_code_id, -// admin_addr.clone(), -// &covenant_interchain_splitter::msg::InstantiateMsg { -// clock_address: clock_addr.to_string(), -// splits: vec![( -// "denom".to_string(), -// SplitType::Custom(SplitConfig { receivers: splits }), -// )], -// fallback_split: None, -// }, -// &[], -// "splitter", -// Some(admin_addr.to_string()), -// splitter_salt, -// ) -// .unwrap(); - -// // fund contracts with neutron to do IBC stuff -// app.send_tokens( -// faucet_addr.clone(), -// forwarder_addr.clone(), -// &coins(1_100_000, DENOM_NTRN), -// ) -// .unwrap(); -// app.send_tokens( -// faucet_addr.clone(), -// stride_addr.clone(), -// &coins(1_100_000, DENOM_NTRN), -// ) -// .unwrap(); -// app.send_tokens( -// faucet_addr.clone(), -// splitter_addr.clone(), -// &coins(1_100_000, DENOM_NTRN), -// ) -// .unwrap(); - -// // Verify we don't have ICA yet -// app.wrap() -// .query_wasm_smart::>( -// forwarder_addr.clone(), -// &covenant_ibc_forwarder::msg::QueryMsg::IcaAddress {}, -// ) -// .unwrap_err(); - -// // Do tick on forwarder to create ICA -// app.execute_contract( -// clock_addr.clone(), -// forwarder_addr.clone(), -// &covenant_clock::msg::ExecuteMsg::Tick {}, -// &[], -// ) -// .unwrap(); - -// let forwarder_ica = app -// .wrap() -// .query_wasm_smart::>( -// forwarder_addr.clone(), -// &covenant_ibc_forwarder::msg::QueryMsg::IcaAddress {}, -// ) -// .unwrap() -// .unwrap(); -// let forwarder_ica = Addr::unchecked(forwarder_ica); - -// // Fund the forwarder ICA with the wanted amount (1_000 ATOM) -// app.send_tokens( -// faucet_addr, -// forwarder_ica.clone(), -// &coins(1_000, DENOM_ATOM), -// ) -// .unwrap(); - -// // Do tick on lser to create ICA on stride -// app.execute_contract( -// clock_addr.clone(), -// stride_addr.clone(), -// &covenant_clock::msg::ExecuteMsg::Tick {}, -// &[], -// ) -// .unwrap(); - -// let stride_ica = app -// .wrap() -// .query_wasm_smart::>( -// stride_addr.clone(), -// &covenant_stride_liquid_staker::msg::QueryMsg::IcaAddress {}, -// ) -// .unwrap() -// .unwrap(); -// let stride_ica = Addr::unchecked(stride_ica); - -// // Do tick on forwarder to send funds to the stride ICA ("results in ls tokens") -// app.execute_contract( -// clock_addr.clone(), -// forwarder_addr.clone(), -// &covenant_clock::msg::ExecuteMsg::Tick {}, -// &[], -// ) -// .unwrap(); - -// // Verify stride ICA holds the correct denom -// let stride_ica_balance = app -// .wrap() -// .query_balance(stride_ica.clone(), ATOM_ON_STRIDE_DENOM.clone()) -// .unwrap(); - -// assert_eq!( -// stride_ica_balance, -// coin(1_000_u128, ATOM_ON_STRIDE_DENOM.clone()) -// ); - -// // Transfer from stride ICA to splitter -// app.execute_contract( -// admin_addr.clone(), -// stride_addr, -// &covenant_stride_liquid_staker::msg::ExecuteMsg::Transfer { -// amount: 1_000_u128.into(), -// }, -// &[], -// ) -// .unwrap(); - -// // Verify we got the funds on the splitter, with the correct denom -// let splitter_balance = app -// .wrap() -// .query_balance(splitter_addr.clone(), STRIDE_LS_ON_NTRN_DENOM.clone()) -// .unwrap(); -// assert_eq!(splitter_balance, coin(1_000_u128, STRIDE_LS_ON_NTRN_DENOM)); -// } - -// #[test] -// fn test_timeout() { -// let admin_addr = get_addr("admin"); - -// let mut app = BasicAppBuilder::new_custom() -// .with_custom(NeutronKeeper::new(CHAIN_PREFIX)) -// .with_api(MockApiBech32::new(CHAIN_PREFIX)) -// .with_wasm(WasmKeeper::default().with_address_generator(MockAddressGenerator)) -// .build(|_, _, _| {}); - -// let clock_code_id = app.store_code(clock_contract()); -// let ibc_forwarder_code_id = app.store_code(ibc_forwarder_contract()); -// let stride_lser_code_id = app.store_code(stride_lser_contract()); - -// // Get init 2 data -// let (forwarder_salt, forwarder_addr) = -// get_salt_and_addr(&app, ibc_forwarder_code_id, "ibc_forwarder"); -// let (stride_salt, stride_addr) = get_salt_and_addr(&app, stride_lser_code_id, "stride"); - -// // fund contracts with ntrn for ibc stuff -// app.init_modules(|r, _, s| { -// r.bank -// .init_balance(s, &forwarder_addr, vec![coin(1_000_000_000, DENOM_NTRN)]) -// .unwrap(); - -// r.bank -// .init_balance(s, &stride_addr, vec![coin(1_000_000_000, DENOM_NTRN)]) -// .unwrap(); -// }); - -// let clock_addr = app -// .instantiate_contract( -// clock_code_id, -// admin_addr.clone(), -// &covenant_clock::msg::InstantiateMsg { -// tick_max_gas: None, -// whitelist: vec![forwarder_addr.to_string(), stride_addr.to_string()], -// }, -// &[], -// "clock", -// Some(admin_addr.to_string()), -// ) -// .unwrap(); - -// app.instantiate2_contract( -// ibc_forwarder_code_id, -// admin_addr.clone(), -// &covenant_ibc_forwarder::msg::InstantiateMsg { -// clock_address: clock_addr.to_string(), -// next_contract: stride_addr.to_string(), -// remote_chain_connection_id: "conn-1".to_string(), -// remote_chain_channel_id: "channel-1".to_string(), -// denom: DENOM_ATOM.to_string(), -// amount: 1000_u128.into(), -// ibc_fee: IbcFee { -// recv_fee: vec![], -// ack_fee: coins(100_u128, DENOM_NTRN), -// timeout_fee: coins(100_u128, DENOM_NTRN), -// }, -// ibc_transfer_timeout: 1000_u64.into(), -// ica_timeout: 1000_u64.into(), -// }, -// &[], -// "forwarder", -// Some(admin_addr.to_string()), -// forwarder_salt, -// ) -// .unwrap(); - -// app.instantiate2_contract( -// stride_lser_code_id, -// admin_addr.clone(), -// &covenant_stride_liquid_staker::msg::InstantiateMsg { -// clock_address: clock_addr.to_string(), -// stride_neutron_ibc_transfer_channel_id: "channel-2".to_string(), -// neutron_stride_ibc_connection_id: "conn-1".to_string(), -// next_contract: forwarder_addr.to_string(), -// ls_denom: "some_denom".to_string(), -// ibc_fee: IbcFee { -// recv_fee: vec![], -// ack_fee: coins(100_u128, DENOM_NTRN), -// timeout_fee: coins(100_u128, DENOM_NTRN), -// }, -// ibc_transfer_timeout: 1000_u64.into(), -// ica_timeout: 1000_u64.into(), -// }, -// &[], -// "lser", -// Some(admin_addr.to_string()), -// stride_salt, -// ) -// .unwrap(); - -// let forwarder_state = app -// .wrap() -// .query_wasm_smart::( -// forwarder_addr.clone(), -// &covenant_ibc_forwarder::msg::QueryMsg::ContractState {}, -// ) -// .unwrap(); - -// assert_eq!( -// forwarder_state, -// covenant_ibc_forwarder::msg::ContractState::Instantiated -// ); - -// // Do tick on forwarder to create ICA -// app.execute_contract( -// clock_addr.clone(), -// forwarder_addr.clone(), -// &covenant_clock::msg::ExecuteMsg::Tick {}, -// &[], -// ) -// .unwrap(); - -// // Do tick on stride lser to create ICA -// app.execute_contract( -// clock_addr.clone(), -// stride_addr.clone(), -// &covenant_clock::msg::ExecuteMsg::Tick {}, -// &[], -// ) -// .unwrap(); - -// let forwarder_state = app -// .wrap() -// .query_wasm_smart::( -// forwarder_addr.clone(), -// &covenant_ibc_forwarder::msg::QueryMsg::ContractState {}, -// ) -// .unwrap(); - -// assert_eq!( -// forwarder_state, -// covenant_ibc_forwarder::msg::ContractState::IcaCreated -// ); - -// // Set timeout to be called on the next tick -// app.init_modules(|r, _, _| { -// r.custom.set_timeout(true); -// }); - -// // Do tick on forwarder to trigger a timeout response -// app.execute_contract( -// clock_addr.clone(), -// forwarder_addr.clone(), -// &covenant_clock::msg::ExecuteMsg::Tick {}, -// &[], -// ) -// .unwrap(); - -// // The state now should be set back to Instantiated because we had a timeout -// let forwarder_state = app -// .wrap() -// .query_wasm_smart::( -// forwarder_addr.clone(), -// &covenant_ibc_forwarder::msg::QueryMsg::ContractState {}, -// ) -// .unwrap(); - -// assert_eq!( -// forwarder_state, -// covenant_ibc_forwarder::msg::ContractState::Instantiated -// ); - -// // Turn off the timeout flag -// app.init_modules(|r, _, _| { -// r.custom.set_timeout(false); -// }); - -// // Do another tick to create a new ICA -// app.execute_contract( -// clock_addr.clone(), -// forwarder_addr.clone(), -// &covenant_clock::msg::ExecuteMsg::Tick {}, -// &[], -// ) -// .unwrap(); - -// // The state should be back to IcaCreated now again -// let forwarder_state = app -// .wrap() -// .query_wasm_smart::( -// forwarder_addr.clone(), -// &covenant_ibc_forwarder::msg::QueryMsg::ContractState {}, -// ) -// .unwrap(); - -// assert_eq!( -// forwarder_state, -// covenant_ibc_forwarder::msg::ContractState::IcaCreated -// ); -// } From 54233e906b47704ee521c7537bb6ba49871d9d16 Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 18 Mar 2024 09:49:37 +0100 Subject: [PATCH 28/56] removing unused deps; clippy; fmt --- Cargo.lock | 104 ++-------- contracts/astroport-liquid-pooler/Cargo.toml | 1 - .../astroport-liquid-pooler/src/contract.rs | 11 +- contracts/clock-tester/src/bin/schema.rs | 11 - contracts/clock-tester/src/lib.rs | 3 - contracts/clock-tester/src/tests.rs | 1 - contracts/clock/src/bin/schema.rs | 11 - contracts/clock/src/test_helpers/helpers.rs | 47 +---- contracts/ibc-forwarder/Cargo.toml | 1 - contracts/ibc-forwarder/src/contract.rs | 25 ++- contracts/ibc-forwarder/src/lib.rs | 2 - contracts/ibc-forwarder/src/sudo.rs | 10 +- contracts/interchain-router/Cargo.toml | 2 +- contracts/interchain-router/src/contract.rs | 29 ++- contracts/interchain-router/src/lib.rs | 4 +- .../interchain-router/src/suite_tests/mod.rs | 6 +- .../src/suite_tests/tests.rs | 75 ++++--- contracts/native-router/Cargo.toml | 1 - contracts/native-router/src/contract.rs | 25 ++- contracts/native-router/src/lib.rs | 2 - contracts/native-splitter/Cargo.toml | 1 - contracts/native-splitter/src/contract.rs | 3 +- contracts/native-splitter/src/lib.rs | 2 - contracts/osmo-liquid-pooler/Cargo.toml | 2 - contracts/osmo-liquid-pooler/src/contract.rs | 18 +- contracts/osmo-liquid-pooler/src/lib.rs | 2 - .../src/polytone_handlers.rs | 10 +- .../outpost-osmo-liquid-pooler/Cargo.toml | 6 - .../outpost-osmo-liquid-pooler/src/lib.rs | 2 - contracts/remote-chain-splitter/Cargo.toml | 1 - .../remote-chain-splitter/src/contract.rs | 17 +- contracts/remote-chain-splitter/src/lib.rs | 2 - contracts/remote-chain-splitter/src/sudo.rs | 10 +- .../single-party-pol-covenant/Cargo.toml | 3 - .../single-party-pol-covenant/src/contract.rs | 2 +- .../single-party-pol-covenant/src/lib.rs | 2 - .../single-party-pol-holder/src/contract.rs | 4 +- contracts/single-party-pol-holder/src/msg.rs | 2 +- contracts/stride-liquid-staker/Cargo.toml | 1 - .../stride-liquid-staker/src/contract.rs | 27 ++- contracts/stride-liquid-staker/src/lib.rs | 2 - contracts/stride-liquid-staker/src/msg.rs | 5 - contracts/stride-liquid-staker/src/state.rs | 6 +- contracts/swap-covenant/Cargo.toml | 1 - contracts/swap-covenant/src/contract.rs | 19 +- contracts/swap-covenant/src/error.rs | 2 +- contracts/swap-covenant/src/lib.rs | 2 - contracts/swap-covenant/src/msg.rs | 2 +- contracts/swap-holder/src/contract.rs | 87 ++++---- contracts/two-party-pol-covenant/Cargo.toml | 2 - .../two-party-pol-covenant/src/contract.rs | 3 +- contracts/two-party-pol-covenant/src/lib.rs | 2 - contracts/two-party-pol-covenant/src/msg.rs | 2 +- .../two-party-pol-holder/src/contract.rs | 28 +-- contracts/two-party-pol-holder/src/lib.rs | 2 - contracts/two-party-pol-holder/src/msg.rs | 3 +- packages/covenant-utils/src/lib.rs | 12 +- packages/covenant-utils/src/neutron.rs | 5 +- packages/covenant-utils/src/split.rs | 2 +- unit-tests/src/lib.rs | 3 - unit-tests/src/setup/base_suite.rs | 2 +- unit-tests/src/setup/contracts.rs | 18 +- unit-tests/src/setup/custom_module.rs | 26 +-- .../src/setup/instantiates/ibc_forwarder.rs | 5 +- .../src/setup/instantiates/native_splitter.rs | 2 +- .../src/setup/instantiates/osmo_lp_outpost.rs | 4 +- .../instantiates/remote_chain_splitter.rs | 2 +- .../src/setup/instantiates/swap_covenant.rs | 2 +- .../src/test_astroport_liquid_pooler/suite.rs | 13 +- .../src/test_astroport_liquid_pooler/tests.rs | 76 +++---- unit-tests/src/test_ibc_forwarder/suite.rs | 1 - .../src/test_interchain_router/tests.rs | 3 +- unit-tests/src/test_native_splitter/tests.rs | 37 +++- .../src/test_remote_chain_splitter/suite.rs | 6 +- .../src/test_remote_chain_splitter/tests.rs | 31 ++- .../src/test_single_party_covenant/test.rs | 193 +++++++++++------ .../src/test_single_party_holder/tests.rs | 13 +- unit-tests/src/test_swap_covenant/test.rs | 169 ++++++++++----- unit-tests/src/test_swap_holder/suite.rs | 26 ++- unit-tests/src/test_swap_holder/tests.rs | 170 ++++++++------- .../src/test_two_party_covenant/suite.rs | 3 +- .../src/test_two_party_pol_holder/tests.rs | 194 +++++++++++------- 82 files changed, 928 insertions(+), 746 deletions(-) delete mode 100644 contracts/clock-tester/src/bin/schema.rs delete mode 100644 contracts/clock-tester/src/tests.rs delete mode 100644 contracts/clock/src/bin/schema.rs diff --git a/Cargo.lock b/Cargo.lock index 63aa3cf3..fc2c2fb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,12 +133,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.7" @@ -157,12 +151,6 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" -[[package]] -name = "bitflags" -version = "2.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" - [[package]] name = "block-buffer" version = "0.9.0" @@ -329,7 +317,7 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad011ae7447188e26e4a7dbca2fcd0fc186aa21ae5c86df0503ea44c78f9e469" dependencies = [ - "base64 0.21.7", + "base64", "bech32", "bnum", "cosmwasm-crypto", @@ -371,7 +359,6 @@ dependencies = [ "cw2 1.1.2", "cw20", "neutron-sdk", - "protobuf 3.3.0", "schemars", "serde", "sha2 0.9.9", @@ -423,7 +410,6 @@ dependencies = [ "neutron-sdk", "prost 0.11.9", "prost-types 0.11.9", - "protobuf 3.3.0", "schemars", "serde", "serde-json-wasm 0.4.1", @@ -450,7 +436,6 @@ dependencies = [ "neutron-sdk", "prost 0.11.9", "prost-types 0.11.9", - "protobuf 3.3.0", "schemars", "serde", "sha2 0.9.9", @@ -482,7 +467,6 @@ dependencies = [ "neutron-sdk", "prost 0.11.9", "prost-types 0.11.9", - "protobuf 3.3.0", "schemars", "serde", "sha2 0.9.9", @@ -502,7 +486,6 @@ dependencies = [ "cw2 1.1.2", "schemars", "serde", - "serde-json-wasm 0.4.1", "thiserror", ] @@ -510,7 +493,6 @@ dependencies = [ name = "covenant-osmo-liquid-pooler" version = "1.0.0" dependencies = [ - "base64 0.13.1", "bech32", "cosmwasm-schema", "cosmwasm-std", @@ -526,7 +508,6 @@ dependencies = [ "osmosis-std 0.20.1", "polytone", "prost 0.11.9", - "protobuf 3.3.0", "schemars", "serde", "sha2 0.9.9", @@ -537,13 +518,10 @@ dependencies = [ name = "covenant-outpost-osmo-liquid-pooler" version = "1.0.0" dependencies = [ - "base64 0.13.1", "cosmwasm-schema", "cosmwasm-std", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", - "cw1-whitelist", "cw2 1.1.2", "osmosis-std 0.13.2", "prost 0.11.9", @@ -565,7 +543,6 @@ dependencies = [ "cw-storage-plus 1.2.0", "cw2 1.1.2", "neutron-sdk", - "protobuf 3.3.0", "schemars", "serde", "serde-json-wasm 0.4.1", @@ -577,7 +554,6 @@ name = "covenant-single-party-pol" version = "1.0.0" dependencies = [ "astroport", - "base64 0.13.1", "bech32", "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", @@ -586,7 +562,6 @@ dependencies = [ "covenant-clock", "covenant-ibc-forwarder", "covenant-interchain-router", - "covenant-native-splitter", "covenant-osmo-liquid-pooler", "covenant-remote-chain-splitter", "covenant-single-party-pol-holder", @@ -598,7 +573,6 @@ dependencies = [ "neutron-sdk", "prost 0.11.9", "prost-types 0.11.9", - "protobuf 3.3.0", "schemars", "serde", "serde-json-wasm 0.4.1", @@ -634,7 +608,6 @@ dependencies = [ "cw-storage-plus 1.2.0", "cw2 1.1.2", "neutron-sdk", - "protobuf 3.3.0", "schemars", "serde", "serde-json-wasm 0.4.1", @@ -662,7 +635,6 @@ dependencies = [ "neutron-sdk", "prost 0.11.9", "prost-types 0.11.9", - "protobuf 3.3.0", "schemars", "serde", "serde-json-wasm 0.4.1", @@ -693,7 +665,6 @@ name = "covenant-two-party-pol" version = "1.0.0" dependencies = [ "astroport", - "base64 0.13.1", "bech32", "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", @@ -712,7 +683,6 @@ dependencies = [ "neutron-sdk", "prost 0.11.9", "prost-types 0.11.9", - "protobuf 3.3.0", "schemars", "serde", "serde-json-wasm 0.4.1", @@ -1083,16 +1053,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys", -] - [[package]] name = "ff" version = "0.13.0" @@ -1168,9 +1128,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.4" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -1198,12 +1158,12 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.10" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" dependencies = [ "hermit-abi", - "rustix", + "libc", "windows-sys", ] @@ -1266,12 +1226,6 @@ version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - [[package]] name = "neutron-sdk" version = "0.8.0" @@ -1506,7 +1460,6 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b65f4a8ec18723a734e5dc09c173e0abf9690432da5340285d536edcb4dac190" dependencies = [ - "bytes", "once_cell", "protobuf-support", "thiserror", @@ -1555,19 +1508,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "rustix" -version = "0.38.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] - [[package]] name = "rustversion" version = "1.0.14" @@ -2045,9 +1985,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -2060,45 +2000,45 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "zeroize" diff --git a/contracts/astroport-liquid-pooler/Cargo.toml b/contracts/astroport-liquid-pooler/Cargo.toml index 53264767..ed851941 100644 --- a/contracts/astroport-liquid-pooler/Cargo.toml +++ b/contracts/astroport-liquid-pooler/Cargo.toml @@ -36,7 +36,6 @@ thiserror = { workspace = true } # ```cargo tree --package cosmwasm-std``` sha2 = { workspace = true } neutron-sdk = { workspace = true } -protobuf = { workspace = true } schemars = { workspace = true } bech32 = { workspace = true } astroport = { workspace = true } diff --git a/contracts/astroport-liquid-pooler/src/contract.rs b/contracts/astroport-liquid-pooler/src/contract.rs index a68413d8..ed143463 100644 --- a/contracts/astroport-liquid-pooler/src/contract.rs +++ b/contracts/astroport-liquid-pooler/src/contract.rs @@ -151,12 +151,11 @@ fn try_withdraw( ensure!(!funds.is_empty(), ContractError::NothingToWithdraw {}); - return Ok(Response::default() - .add_message(WasmMsg::Execute { - contract_addr: holder_addr.to_string(), - msg: to_json_binary(&WithdrawLPMsgs::Distribute {})?, - funds, - })) + return Ok(Response::default().add_message(WasmMsg::Execute { + contract_addr: holder_addr.to_string(), + msg: to_json_binary(&WithdrawLPMsgs::Distribute {})?, + funds, + })); } // If percentage is 100%, use the whole balance diff --git a/contracts/clock-tester/src/bin/schema.rs b/contracts/clock-tester/src/bin/schema.rs deleted file mode 100644 index 6b26d02e..00000000 --- a/contracts/clock-tester/src/bin/schema.rs +++ /dev/null @@ -1,11 +0,0 @@ -use cosmwasm_schema::write_api; - -use covenant_clock_tester::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; - -fn main() { - write_api! { - instantiate: InstantiateMsg, - execute: ExecuteMsg, - query: QueryMsg, - } -} diff --git a/contracts/clock-tester/src/lib.rs b/contracts/clock-tester/src/lib.rs index f0e2fd34..a5abdbb0 100644 --- a/contracts/clock-tester/src/lib.rs +++ b/contracts/clock-tester/src/lib.rs @@ -2,6 +2,3 @@ pub mod contract; pub mod error; pub mod msg; pub mod state; - -#[cfg(test)] -mod tests; diff --git a/contracts/clock-tester/src/tests.rs b/contracts/clock-tester/src/tests.rs deleted file mode 100644 index 8b137891..00000000 --- a/contracts/clock-tester/src/tests.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/contracts/clock/src/bin/schema.rs b/contracts/clock/src/bin/schema.rs deleted file mode 100644 index defe5be2..00000000 --- a/contracts/clock/src/bin/schema.rs +++ /dev/null @@ -1,11 +0,0 @@ -use cosmwasm_schema::write_api; - -use covenant_clock::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; - -fn main() { - write_api! { - instantiate: InstantiateMsg, - execute: ExecuteMsg, - query: QueryMsg, - } -} diff --git a/contracts/clock/src/test_helpers/helpers.rs b/contracts/clock/src/test_helpers/helpers.rs index fb1a97a7..9dd60e1f 100644 --- a/contracts/clock/src/test_helpers/helpers.rs +++ b/contracts/clock/src/test_helpers/helpers.rs @@ -4,10 +4,7 @@ use neutron_sdk::{ NeutronResult, }; -use crate::{ - error::ContractError, - msg::{InstantiateMsg, QueryMsg}, -}; +use crate::msg::{InstantiateMsg, QueryMsg}; type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; type QueryDeps<'a> = Deps<'a, NeutronQuery>; @@ -21,15 +18,6 @@ pub fn mock_neutron_clock_instantiate( Ok(Response::default()) } -pub fn mock_clock_instantiate( - _deps: DepsMut, - _env: Env, - _info: MessageInfo, - _msg: InstantiateMsg, -) -> Result { - Ok(Response::default()) -} - pub fn mock_neutron_clock_execute( _deps: ExecuteDeps, _env: Env, @@ -43,19 +31,6 @@ pub fn mock_neutron_clock_execute( } } -pub fn mock_clock_execute( - _deps: DepsMut, - _env: Env, - _info: MessageInfo, - msg: crate::msg::ExecuteMsg, -) -> Result { - match msg { - crate::msg::ExecuteMsg::Enqueue {} => Ok(Response::default()), - crate::msg::ExecuteMsg::Dequeue {} => Ok(Response::default()), - crate::msg::ExecuteMsg::Tick {} => Ok(Response::default()), - } -} - pub fn mock_neutron_clock_query(_deps: QueryDeps, _env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::IsQueued { address: _ } => Ok(Binary::default()), @@ -68,23 +43,3 @@ pub fn mock_neutron_clock_query(_deps: QueryDeps, _env: Env, msg: QueryMsg) -> S QueryMsg::Whitelist {} => Ok(Binary::default()), } } - -pub fn mock_clock_query(_deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - match msg { - QueryMsg::IsQueued { address: _ } => Ok(Binary::default()), - QueryMsg::Queue { - start_after: _, - limit: _, - } => Ok(Binary::default()), - QueryMsg::TickMaxGas {} => Ok(Binary::default()), - QueryMsg::Paused {} => Ok(Binary::default()), - QueryMsg::Whitelist {} => Ok(Binary::default()), - } -} - -pub fn mock_clock_instantiate_message() -> InstantiateMsg { - InstantiateMsg { - tick_max_gas: None, - whitelist: vec![], - } -} diff --git a/contracts/ibc-forwarder/Cargo.toml b/contracts/ibc-forwarder/Cargo.toml index 5c947cbc..b639e8ae 100644 --- a/contracts/ibc-forwarder/Cargo.toml +++ b/contracts/ibc-forwarder/Cargo.toml @@ -31,7 +31,6 @@ thiserror = { workspace = true } sha2 = { workspace = true } neutron-sdk = { workspace = true } cosmos-sdk-proto = { workspace = true } -protobuf = { workspace = true } schemars = { workspace = true } serde-json-wasm = { workspace = true } prost = { workspace = true } diff --git a/contracts/ibc-forwarder/src/contract.rs b/contracts/ibc-forwarder/src/contract.rs index 945d8139..c6bfb14d 100644 --- a/contracts/ibc-forwarder/src/contract.rs +++ b/contracts/ibc-forwarder/src/contract.rs @@ -1,25 +1,34 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - from_json, to_json_binary, to_json_vec, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult, Storage, SubMsg, + from_json, to_json_binary, to_json_vec, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, + MessageInfo, Reply, Response, StdError, StdResult, Storage, SubMsg, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::neutron::{ - get_ictxs_module_params_query_msg, get_proto_coin, to_proto_msg_transfer, QueryParamsResponse, RemoteChainInfo, SudoPayload + get_ictxs_module_params_query_msg, get_proto_coin, to_proto_msg_transfer, QueryParamsResponse, + RemoteChainInfo, SudoPayload, }; use cw2::set_contract_version; use neutron_sdk::{ bindings::{ msg::{MsgSubmitTxResponse, NeutronMsg}, query::NeutronQuery, - }, interchain_txs::helpers::get_port_id, query::min_ibc_fee::MinIbcFeeResponse, sudo::msg::SudoMsg, NeutronError, NeutronResult + }, + interchain_txs::helpers::get_port_id, + query::min_ibc_fee::MinIbcFeeResponse, + sudo::msg::SudoMsg, + NeutronError, NeutronResult, }; use crate::{ - helpers::{get_next_memo, MsgTransfer}, msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, state::{ + helpers::{get_next_memo, MsgTransfer}, + msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, + state::{ CLOCK_ADDRESS, CONTRACT_STATE, INTERCHAIN_ACCOUNTS, NEXT_CONTRACT, REMOTE_CHAIN_INFO, REPLY_ID_STORAGE, SUDO_PAYLOAD, TRANSFER_AMOUNT, - }, sudo::{save_reply_payload, sudo_error, sudo_open_ack, sudo_response, sudo_timeout} + }, + sudo::{save_reply_payload, sudo_error, sudo_open_ack, sudo_response, sudo_timeout}, }; const CONTRACT_NAME: &str = "crates.io:covenant-ibc-forwarder"; @@ -93,7 +102,8 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult NeutronResult> { let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; - let ictxs_params_response: QueryParamsResponse = deps.querier.query(&get_ictxs_module_params_query_msg())?; + let ictxs_params_response: QueryParamsResponse = + deps.querier.query(&get_ictxs_module_params_query_msg())?; let register_msg = NeutronMsg::register_interchain_account( remote_chain_info.connection_id, @@ -126,7 +136,8 @@ fn try_forward_funds(env: Env, mut deps: ExecuteDeps) -> NeutronResult StdResult> { // either of these errors will close the channel request @@ -65,7 +65,7 @@ pub fn sudo_response( pub fn sudo_timeout( deps: ExecuteDeps, _env: Env, - request: RequestPacket, + _request: RequestPacket, ) -> StdResult> { // revert the state to Instantiated to force re-creation of ICA CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; @@ -75,9 +75,9 @@ pub fn sudo_timeout( } pub fn sudo_error( - deps: ExecuteDeps, + _deps: ExecuteDeps, request: RequestPacket, - details: String, + _details: String, ) -> StdResult> { // either of these errors will close the channel request diff --git a/contracts/interchain-router/Cargo.toml b/contracts/interchain-router/Cargo.toml index 21253606..7faa4bdb 100644 --- a/contracts/interchain-router/Cargo.toml +++ b/contracts/interchain-router/Cargo.toml @@ -31,7 +31,6 @@ thiserror = { workspace = true } sha2 = { workspace = true } neutron-sdk = { workspace = true } cosmos-sdk-proto = { workspace = true } -protobuf = { workspace = true } schemars = { workspace = true } prost = { workspace = true } prost-types = { workspace = true } @@ -43,3 +42,4 @@ cw-utils = { workspace = true } cw-multi-test = { workspace = true } anyhow = { workspace = true } covenant-clock = { workspace = true } + diff --git a/contracts/interchain-router/src/contract.rs b/contracts/interchain-router/src/contract.rs index 3d65ab18..875b250a 100644 --- a/contracts/interchain-router/src/contract.rs +++ b/contracts/interchain-router/src/contract.rs @@ -3,17 +3,23 @@ use std::collections::BTreeSet; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - ensure, to_json_binary, Attribute, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, + ensure, to_json_binary, Attribute, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, + StdResult, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::sum_fees; use cw2::set_contract_version; use cw_utils::must_pay; use neutron_sdk::{ - bindings::{msg::NeutronMsg, query::NeutronQuery}, query::min_ibc_fee::MinIbcFeeResponse, NeutronError, NeutronResult + bindings::{msg::NeutronMsg, query::NeutronQuery}, + query::min_ibc_fee::MinIbcFeeResponse, + NeutronError, NeutronResult, }; -use crate::{error::ContractError, state::{DESTINATION_CONFIG, TARGET_DENOMS}}; +use crate::{ + error::ContractError, + state::{DESTINATION_CONFIG, TARGET_DENOMS}, +}; use crate::{ msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, state::CLOCK_ADDRESS, @@ -35,7 +41,8 @@ pub fn instantiate( set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; let clock_address = deps.api.addr_validate(&msg.clock_address)?; - deps.api.addr_validate(&msg.destination_config.destination_receiver_addr)?; + deps.api + .addr_validate(&msg.destination_config.destination_receiver_addr)?; CLOCK_ADDRESS.save(deps.storage, &clock_address)?; DESTINATION_CONFIG.save(deps.storage, &msg.destination_config)?; @@ -61,7 +68,9 @@ pub fn execute( verify_clock(&info.sender, &CLOCK_ADDRESS.load(deps.storage)?)?; try_route_balances(deps, env) } - ExecuteMsg::DistributeFallback { denoms } => try_distribute_fallback(deps, env, info, denoms), + ExecuteMsg::DistributeFallback { denoms } => { + try_distribute_fallback(deps, env, info, denoms) + } } } @@ -75,12 +84,16 @@ fn try_distribute_fallback( let destination_config = DESTINATION_CONFIG.load(deps.storage)?; let explicit_denoms = TARGET_DENOMS.load(deps.storage)?; - let min_fee_query_response: MinIbcFeeResponse = deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; + let min_fee_query_response: MinIbcFeeResponse = + deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; let total_fee = sum_fees(&min_fee_query_response.min_fee); // the caller must cover the ibc fees match must_pay(&info, "untrn") { - Ok(amt) => ensure!(amt >= total_fee, NeutronError::Std(StdError::generic_err("insufficient fees"))), + Ok(amt) => ensure!( + amt >= total_fee, + NeutronError::Std(StdError::generic_err("insufficient fees")) + ), Err(e) => return Err(ContractError::IbcFeeError(e).to_neutron_std()), }; @@ -103,7 +116,7 @@ fn try_distribute_fallback( available_balances, env.block.time, env.contract.address.to_string(), - min_ibc_fee.min_fee + min_ibc_fee.min_fee, )?; Ok(Response::default() diff --git a/contracts/interchain-router/src/lib.rs b/contracts/interchain-router/src/lib.rs index d97a1fa6..ff7db88e 100644 --- a/contracts/interchain-router/src/lib.rs +++ b/contracts/interchain-router/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; @@ -9,4 +7,4 @@ pub mod state; #[allow(clippy::unwrap_used)] #[cfg(test)] -mod suite_tests; +pub mod suite_tests; diff --git a/contracts/interchain-router/src/suite_tests/mod.rs b/contracts/interchain-router/src/suite_tests/mod.rs index a16530ee..fa130dba 100644 --- a/contracts/interchain-router/src/suite_tests/mod.rs +++ b/contracts/interchain-router/src/suite_tests/mod.rs @@ -1,12 +1,12 @@ +pub mod suite; +pub mod tests; + use covenant_clock::test_helpers::helpers::{ mock_neutron_clock_execute, mock_neutron_clock_instantiate, mock_neutron_clock_query, }; use cw_multi_test::{Contract, ContractWrapper}; use neutron_sdk::bindings::{msg::NeutronMsg, query::NeutronQuery}; -pub mod suite; -mod tests; - pub fn mock_clock_neutron_deps_contract() -> Box> { let contract = ContractWrapper::new( mock_neutron_clock_execute, diff --git a/contracts/interchain-router/src/suite_tests/tests.rs b/contracts/interchain-router/src/suite_tests/tests.rs index a68d9cd2..5848d21e 100644 --- a/contracts/interchain-router/src/suite_tests/tests.rs +++ b/contracts/interchain-router/src/suite_tests/tests.rs @@ -4,11 +4,16 @@ use std::{ }; use cosmwasm_std::{ - coin, testing::{mock_env, mock_info, MockApi, MockQuerier, MockStorage}, to_json_binary, Attribute, CosmosMsg, Empty, OwnedDeps, SubMsg, Uint128, Uint64 + coin, + testing::{mock_env, mock_info, MockApi, MockQuerier, MockStorage}, + to_json_binary, Attribute, CosmosMsg, Empty, OwnedDeps, SubMsg, Uint128, Uint64, }; use covenant_utils::DestinationConfig; use neutron_sdk::{ - bindings::msg::{IbcFee, NeutronMsg}, query::min_ibc_fee::MinIbcFeeResponse, sudo::msg::RequestPacketTimeoutHeight, NeutronError + bindings::msg::{IbcFee, NeutronMsg}, + query::min_ibc_fee::MinIbcFeeResponse, + sudo::msg::RequestPacketTimeoutHeight, + NeutronError, }; use crate::{ @@ -92,13 +97,18 @@ fn test_tick_no_ibc_fee() { let coins = vec![usdc_coin, random_coin_1, random_coin_2, random_coin_3]; let querier: MockQuerier = MockQuerier::new(&[("cosmos2contract", &coins)]) - .with_custom_handler(|_| cosmwasm_std::SystemResult::Ok(to_json_binary( - &MinIbcFeeResponse { min_fee: IbcFee { - recv_fee: vec![], - ack_fee: vec![coin(100000, "untrn")], - timeout_fee: vec![coin(100000, "untrn")], - }} - ).into())); + .with_custom_handler(|_| { + cosmwasm_std::SystemResult::Ok( + to_json_binary(&MinIbcFeeResponse { + min_fee: IbcFee { + recv_fee: vec![], + ack_fee: vec![coin(100000, "untrn")], + timeout_fee: vec![coin(100000, "untrn")], + }, + }) + .into(), + ) + }); let mut deps = OwnedDeps { storage: MockStorage::default(), @@ -125,12 +135,13 @@ fn test_tick_no_ibc_fee() { deps.as_mut(), mock_env(), no_ibc_fee_info.clone(), - crate::msg::ExecuteMsg::DistributeFallback { denoms: vec!["denom1".to_string()] }, + crate::msg::ExecuteMsg::DistributeFallback { + denoms: vec!["denom1".to_string()], + }, ) .unwrap(); } - #[test] #[should_panic(expected = "insufficient fees")] fn test_tick_insufficient_ibc_fee() { @@ -141,13 +152,18 @@ fn test_tick_insufficient_ibc_fee() { let coins = vec![usdc_coin, random_coin_1, random_coin_2, random_coin_3]; let querier: MockQuerier = MockQuerier::new(&[("cosmos2contract", &coins)]) - .with_custom_handler(|_| cosmwasm_std::SystemResult::Ok(to_json_binary( - &MinIbcFeeResponse { min_fee: IbcFee { - recv_fee: vec![], - ack_fee: vec![coin(100000, "untrn")], - timeout_fee: vec![coin(100000, "untrn")], - }} - ).into())); + .with_custom_handler(|_| { + cosmwasm_std::SystemResult::Ok( + to_json_binary(&MinIbcFeeResponse { + min_fee: IbcFee { + recv_fee: vec![], + ack_fee: vec![coin(100000, "untrn")], + timeout_fee: vec![coin(100000, "untrn")], + }, + }) + .into(), + ) + }); let mut deps = OwnedDeps { storage: MockStorage::default(), @@ -174,7 +190,9 @@ fn test_tick_insufficient_ibc_fee() { deps.as_mut(), mock_env(), no_ibc_fee_info.clone(), - crate::msg::ExecuteMsg::DistributeFallback { denoms: vec!["denom1".to_string()] }, + crate::msg::ExecuteMsg::DistributeFallback { + denoms: vec!["denom1".to_string()], + }, ) .unwrap(); } @@ -188,13 +206,18 @@ fn test_tick() { let coins = vec![usdc_coin, random_coin_1, random_coin_2, random_coin_3]; let querier: MockQuerier = MockQuerier::new(&[("cosmos2contract", &coins)]) - .with_custom_handler(|_| cosmwasm_std::SystemResult::Ok(to_json_binary( - &MinIbcFeeResponse { min_fee: IbcFee { - recv_fee: vec![], - ack_fee: vec![coin(100000, "untrn")], - timeout_fee: vec![coin(100000, "untrn")], - }} - ).into())); + .with_custom_handler(|_| { + cosmwasm_std::SystemResult::Ok( + to_json_binary(&MinIbcFeeResponse { + min_fee: IbcFee { + recv_fee: vec![], + ack_fee: vec![coin(100000, "untrn")], + timeout_fee: vec![coin(100000, "untrn")], + }, + }) + .into(), + ) + }); let mut deps = OwnedDeps { storage: MockStorage::default(), diff --git a/contracts/native-router/Cargo.toml b/contracts/native-router/Cargo.toml index 316f8b85..112e5107 100644 --- a/contracts/native-router/Cargo.toml +++ b/contracts/native-router/Cargo.toml @@ -30,7 +30,6 @@ thiserror = { workspace = true } sha2 = { workspace = true } neutron-sdk = { workspace = true } cosmos-sdk-proto = { workspace = true } -protobuf = { workspace = true } schemars = { workspace = true } prost = { workspace = true } prost-types = { workspace = true } diff --git a/contracts/native-router/src/contract.rs b/contracts/native-router/src/contract.rs index e3f1c67b..f7da34f8 100644 --- a/contracts/native-router/src/contract.rs +++ b/contracts/native-router/src/contract.rs @@ -3,7 +3,8 @@ use std::collections::BTreeSet; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_json_binary, Attribute, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult + to_json_binary, Attribute, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, + Response, StdError, StdResult, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use cw2::set_contract_version; @@ -81,10 +82,13 @@ fn try_distribute_fallback( let bank_sends: Vec = available_balances .into_iter() - .map(|c| BankMsg::Send { - to_address: receiver_address.to_string(), - amount: vec![c], - }.into()) + .map(|c| { + BankMsg::Send { + to_address: receiver_address.to_string(), + amount: vec![c], + } + .into() + }) .collect(); Ok(Response::default() @@ -127,10 +131,13 @@ fn try_route_balances(deps: DepsMut, env: Env) -> Result = denom_balances .into_iter() - .map(|c| BankMsg::Send { - to_address: receiver_addr.to_string(), - amount: vec![c], - }.into()) + .map(|c| { + BankMsg::Send { + to_address: receiver_addr.to_string(), + amount: vec![c], + } + .into() + }) .collect(); Ok(Response::default() diff --git a/contracts/native-router/src/lib.rs b/contracts/native-router/src/lib.rs index 0faea8f4..47bc573c 100644 --- a/contracts/native-router/src/lib.rs +++ b/contracts/native-router/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; diff --git a/contracts/native-splitter/Cargo.toml b/contracts/native-splitter/Cargo.toml index d5c001a9..eb39aacb 100644 --- a/contracts/native-splitter/Cargo.toml +++ b/contracts/native-splitter/Cargo.toml @@ -28,5 +28,4 @@ cw-storage-plus = { workspace = true } cw2 = { workspace = true } thiserror = { workspace = true } schemars = { workspace = true } -serde-json-wasm = { workspace = true } serde = { workspace = true } diff --git a/contracts/native-splitter/src/contract.rs b/contracts/native-splitter/src/contract.rs index 85297266..812b1c42 100644 --- a/contracts/native-splitter/src/contract.rs +++ b/contracts/native-splitter/src/contract.rs @@ -49,8 +49,7 @@ pub fn instantiate( Ok(resp .add_message(enqueue_msg(msg.clock_address.as_str())?) - .add_attribute("clock_address", clock_address) - ) + .add_attribute("clock_address", clock_address)) } #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/native-splitter/src/lib.rs b/contracts/native-splitter/src/lib.rs index 0faea8f4..47bc573c 100644 --- a/contracts/native-splitter/src/lib.rs +++ b/contracts/native-splitter/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; diff --git a/contracts/osmo-liquid-pooler/Cargo.toml b/contracts/osmo-liquid-pooler/Cargo.toml index 0637deb0..91aea4f9 100644 --- a/contracts/osmo-liquid-pooler/Cargo.toml +++ b/contracts/osmo-liquid-pooler/Cargo.toml @@ -36,12 +36,10 @@ thiserror = { workspace = true } # ```cargo tree --package cosmwasm-std``` sha2 = { workspace = true } neutron-sdk = { workspace = true } -protobuf = { workspace = true } schemars = { workspace = true } bech32 = { workspace = true } cw20 = { workspace = true } polytone = { workspace = true } osmosis-std = "0.20.1" -base64 = { workspace = true } prost = { workspace = true } covenant-outpost-osmo-liquid-pooler = { workspace = true, features = ["library"] } diff --git a/contracts/osmo-liquid-pooler/src/contract.rs b/contracts/osmo-liquid-pooler/src/contract.rs index 9b057346..60574f16 100644 --- a/contracts/osmo-liquid-pooler/src/contract.rs +++ b/contracts/osmo-liquid-pooler/src/contract.rs @@ -3,18 +3,24 @@ use std::collections::HashMap; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - ensure, to_json_binary, to_json_string, Attribute, Binary, Coin, CosmosMsg, Decimal, - Env, Fraction, IbcTimeout, MessageInfo, Response, StdResult, Uint128, WasmMsg, + ensure, to_json_binary, to_json_string, Attribute, Binary, Coin, CosmosMsg, Decimal, Env, + Fraction, IbcTimeout, MessageInfo, Response, StdResult, Uint128, WasmMsg, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_outpost_osmo_liquid_pooler::msg::OutpostWithdrawLiquidityConfig; use covenant_utils::{ - polytone::get_polytone_execute_msg_binary, - withdraw_lp_helper::WithdrawLPMsgs, ForwardMetadata, PacketMetadata, + polytone::get_polytone_execute_msg_binary, withdraw_lp_helper::WithdrawLPMsgs, ForwardMetadata, + PacketMetadata, }; use cw2::set_contract_version; use neutron_sdk::{ - bindings::{msg::{IbcFee, NeutronMsg}, query::NeutronQuery}, query::min_ibc_fee::{self, MinIbcFeeResponse}, sudo::msg::RequestPacketTimeoutHeight, NeutronResult + bindings::{ + msg::{IbcFee, NeutronMsg}, + query::NeutronQuery, + }, + query::min_ibc_fee::MinIbcFeeResponse, + sudo::msg::RequestPacketTimeoutHeight, + NeutronResult, }; use polytone::callbacks::CallbackRequest; @@ -548,7 +554,7 @@ fn try_fund_proxy(deps: ExecuteDeps, env: Env) -> NeutronResult Uint128::zero() { diff --git a/contracts/osmo-liquid-pooler/src/lib.rs b/contracts/osmo-liquid-pooler/src/lib.rs index ebc6bf9c..da4a6ad7 100644 --- a/contracts/osmo-liquid-pooler/src/lib.rs +++ b/contracts/osmo-liquid-pooler/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; diff --git a/contracts/osmo-liquid-pooler/src/polytone_handlers.rs b/contracts/osmo-liquid-pooler/src/polytone_handlers.rs index 231cdbc9..d8dec9f4 100644 --- a/contracts/osmo-liquid-pooler/src/polytone_handlers.rs +++ b/contracts/osmo-liquid-pooler/src/polytone_handlers.rs @@ -1,7 +1,8 @@ use std::str::FromStr; use cosmwasm_std::{ - coin, ensure, from_json, to_json_binary, Addr, Binary, Coin, CosmosMsg, Deps, DepsMut, Empty, Env, IbcMsg, IbcTimeout, MessageInfo, QueryRequest, Response, StdResult, Uint128, Uint64, WasmMsg + coin, ensure, from_json, to_json_binary, Addr, Binary, Coin, CosmosMsg, DepsMut, Empty, Env, + IbcMsg, IbcTimeout, MessageInfo, QueryRequest, Response, StdResult, Uint128, Uint64, WasmMsg, }; use covenant_utils::{ polytone::{ @@ -10,7 +11,10 @@ use covenant_utils::{ }, withdraw_lp_helper::WithdrawLPMsgs, }; -use neutron_sdk::{bindings::{msg::NeutronMsg, query::NeutronQuery}, NeutronResult}; +use neutron_sdk::{ + bindings::{msg::NeutronMsg, query::NeutronQuery}, + NeutronResult, +}; use osmosis_std::types::cosmos::bank::v1beta1::QueryBalanceResponse; use crate::{ @@ -32,8 +36,6 @@ use polytone::callbacks::{ }; type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; -type QueryDeps<'a> = Deps<'a, NeutronQuery>; - /// attempts to advance the state machine. performs `info.sender` validation. pub fn try_handle_callback( diff --git a/contracts/outpost-osmo-liquid-pooler/Cargo.toml b/contracts/outpost-osmo-liquid-pooler/Cargo.toml index f60ab609..ffd61269 100644 --- a/contracts/outpost-osmo-liquid-pooler/Cargo.toml +++ b/contracts/outpost-osmo-liquid-pooler/Cargo.toml @@ -32,10 +32,4 @@ serde = { workspace = true } thiserror = { workspace = true } schemars = { workspace = true } osmosis-std = "0.13.2" -base64 = { workspace = true } prost = { workspace = true } - -# dev-dependencies -[dev-dependencies] -cw-multi-test = { workspace = true } -cw1-whitelist = { workspace = true } diff --git a/contracts/outpost-osmo-liquid-pooler/src/lib.rs b/contracts/outpost-osmo-liquid-pooler/src/lib.rs index 0faea8f4..47bc573c 100644 --- a/contracts/outpost-osmo-liquid-pooler/src/lib.rs +++ b/contracts/outpost-osmo-liquid-pooler/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; diff --git a/contracts/remote-chain-splitter/Cargo.toml b/contracts/remote-chain-splitter/Cargo.toml index ece89746..df53b50d 100644 --- a/contracts/remote-chain-splitter/Cargo.toml +++ b/contracts/remote-chain-splitter/Cargo.toml @@ -30,4 +30,3 @@ serde-json-wasm = { workspace = true } serde = { workspace = true } neutron-sdk = { workspace = true } cosmos-sdk-proto = { workspace = true } -protobuf = { workspace = true } diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index e0f93ec2..3eb35fd9 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -11,8 +11,10 @@ use cosmwasm_std::{ MessageInfo, Reply, Response, StdError, StdResult, SubMsg, Uint128, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; -use covenant_utils::neutron::{get_ictxs_module_params_query_msg, QueryParamsResponse, RemoteChainInfo, SudoPayload}; use covenant_utils::neutron; +use covenant_utils::neutron::{ + get_ictxs_module_params_query_msg, QueryParamsResponse, RemoteChainInfo, SudoPayload, +}; use cw2::set_contract_version; use neutron_sdk::bindings::types::ProtobufAny; use neutron_sdk::interchain_txs::helpers::get_port_id; @@ -108,7 +110,8 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult NeutronResult> { let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; - let ictxs_params_response: QueryParamsResponse = deps.querier.query(&get_ictxs_module_params_query_msg())?; + let ictxs_params_response: QueryParamsResponse = + deps.querier.query(&get_ictxs_module_params_query_msg())?; let register: NeutronMsg = NeutronMsg::register_interchain_account( remote_chain_info.connection_id, @@ -129,7 +132,8 @@ fn try_split_funds(mut deps: ExecuteDeps, env: Env) -> NeutronResult { @@ -180,10 +184,9 @@ fn try_split_funds(mut deps: ExecuteDeps, env: Env) -> NeutronResult = Vec::new(); diff --git a/contracts/remote-chain-splitter/src/lib.rs b/contracts/remote-chain-splitter/src/lib.rs index 4c36c82e..4e6a59d9 100644 --- a/contracts/remote-chain-splitter/src/lib.rs +++ b/contracts/remote-chain-splitter/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; diff --git a/contracts/remote-chain-splitter/src/sudo.rs b/contracts/remote-chain-splitter/src/sudo.rs index 7a3f4af2..049b7b2d 100644 --- a/contracts/remote-chain-splitter/src/sudo.rs +++ b/contracts/remote-chain-splitter/src/sudo.rs @@ -49,9 +49,9 @@ pub fn sudo_open_ack( } pub fn sudo_response( - deps: ExecuteDeps, + _deps: ExecuteDeps, request: RequestPacket, - data: Binary, + _data: Binary, ) -> StdResult> { // either of these errors will close the channel request @@ -68,7 +68,7 @@ pub fn sudo_response( pub fn sudo_timeout( deps: ExecuteDeps, _env: Env, - request: RequestPacket, + _request: RequestPacket, ) -> StdResult> { // revert the state to Instantiated to force re-creation of ICA CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; @@ -78,9 +78,9 @@ pub fn sudo_timeout( } pub fn sudo_error( - deps: ExecuteDeps, + _deps: ExecuteDeps, request: RequestPacket, - details: String, + _details: String, ) -> StdResult> { // either of these errors will close the channel request diff --git a/contracts/single-party-pol-covenant/Cargo.toml b/contracts/single-party-pol-covenant/Cargo.toml index 83b06ff1..70b691f4 100644 --- a/contracts/single-party-pol-covenant/Cargo.toml +++ b/contracts/single-party-pol-covenant/Cargo.toml @@ -29,10 +29,8 @@ thiserror = { workspace = true } sha2 = { workspace = true } neutron-sdk = { workspace = true } cosmos-sdk-proto = { workspace = true } -protobuf = { workspace = true } schemars = { workspace = true } serde-json-wasm = { workspace = true } -base64 = { workspace = true } prost = { workspace = true } prost-types = { workspace = true } bech32 = { workspace = true } @@ -42,7 +40,6 @@ covenant-ibc-forwarder = { workspace = true, features = ["library"] } covenant-interchain-router = { workspace = true, features = ["library"] } covenant-single-party-pol-holder = { workspace = true, features = ["library"] } covenant-astroport-liquid-pooler = { workspace = true, features = ["library"] } -covenant-native-splitter = { workspace = true, features = ["library"] } covenant-stride-liquid-staker = { workspace = true, features = ["library"] } covenant-remote-chain-splitter = { workspace = true, features = ["library"] } covenant-osmo-liquid-pooler = { workspace = true, features = ["library"] } diff --git a/contracts/single-party-pol-covenant/src/contract.rs b/contracts/single-party-pol-covenant/src/contract.rs index 5a21b21f..d475d41b 100644 --- a/contracts/single-party-pol-covenant/src/contract.rs +++ b/contracts/single-party-pol-covenant/src/contract.rs @@ -320,7 +320,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { )?; Ok(to_json_binary(&ica)?) - }, + } QueryMsg::ContractCodes {} => Ok(to_json_binary(&CONTRACT_CODES.load(deps.storage)?)?), } } diff --git a/contracts/single-party-pol-covenant/src/lib.rs b/contracts/single-party-pol-covenant/src/lib.rs index 0faea8f4..47bc573c 100644 --- a/contracts/single-party-pol-covenant/src/lib.rs +++ b/contracts/single-party-pol-covenant/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; diff --git a/contracts/single-party-pol-holder/src/contract.rs b/contracts/single-party-pol-holder/src/contract.rs index 48939e68..9ea0a2f3 100644 --- a/contracts/single-party-pol-holder/src/contract.rs +++ b/contracts/single-party-pol-holder/src/contract.rs @@ -55,7 +55,9 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { QueryMsg::Withdrawer {} => Ok(to_json_binary(&WITHDRAWER.may_load(deps.storage)?)?), QueryMsg::WithdrawTo {} => Ok(to_json_binary(&WITHDRAW_TO.may_load(deps.storage)?)?), QueryMsg::PoolerAddress {} => Ok(to_json_binary(&POOLER_ADDRESS.may_load(deps.storage)?)?), - QueryMsg::EmergencyCommitteeAddr {} => Ok(to_json_binary(&EMERGENCY_COMMITTEE_ADDR.may_load(deps.storage)?)?), + QueryMsg::EmergencyCommitteeAddr {} => Ok(to_json_binary( + &EMERGENCY_COMMITTEE_ADDR.may_load(deps.storage)?, + )?), QueryMsg::LockupConfig {} => Ok(to_json_binary(&LOCKUP_PERIOD.load(deps.storage)?)?), } } diff --git a/contracts/single-party-pol-holder/src/msg.rs b/contracts/single-party-pol-holder/src/msg.rs index 336362fe..12b7c3b8 100644 --- a/contracts/single-party-pol-holder/src/msg.rs +++ b/contracts/single-party-pol-holder/src/msg.rs @@ -59,7 +59,7 @@ pub enum QueryMsg { #[returns(Addr)] EmergencyCommitteeAddr {}, #[returns(Expiration)] - LockupConfig {} + LockupConfig {}, } #[cw_serde] diff --git a/contracts/stride-liquid-staker/Cargo.toml b/contracts/stride-liquid-staker/Cargo.toml index 5aedcf64..f80f0171 100644 --- a/contracts/stride-liquid-staker/Cargo.toml +++ b/contracts/stride-liquid-staker/Cargo.toml @@ -30,4 +30,3 @@ serde-json-wasm = { workspace = true } serde = { workspace = true } neutron-sdk = { workspace = true } cosmos-sdk-proto = { workspace = true } -protobuf = { workspace = true } diff --git a/contracts/stride-liquid-staker/src/contract.rs b/contracts/stride-liquid-staker/src/contract.rs index 4f24ae62..1a1c6e53 100644 --- a/contracts/stride-liquid-staker/src/contract.rs +++ b/contracts/stride-liquid-staker/src/contract.rs @@ -145,7 +145,8 @@ fn try_execute_transfer( let port_id = get_port_id(env.contract.address.as_str(), INTERCHAIN_ACCOUNT_ID); let interchain_account = INTERCHAIN_ACCOUNTS.load(deps.storage, port_id.clone())?; - let min_fee_query_response: MinIbcFeeResponse = deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; + let min_fee_query_response: MinIbcFeeResponse = + deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; match interchain_account { Some((address, controller_conn_id)) => { @@ -337,7 +338,11 @@ fn sudo_open_ack( Ok(Response::default().add_attribute("method", "sudo_open_ack")) } -fn sudo_response(deps: ExecuteDeps, request: RequestPacket, data: Binary) -> StdResult> { +fn sudo_response( + _deps: ExecuteDeps, + request: RequestPacket, + _data: Binary, +) -> StdResult> { // either of these errors will close the channel request .sequence @@ -350,7 +355,11 @@ fn sudo_response(deps: ExecuteDeps, request: RequestPacket, data: Binary) -> Std Ok(Response::default().add_attribute("method", "sudo_response")) } -fn sudo_timeout(deps: ExecuteDeps, _env: Env, request: RequestPacket) -> StdResult> { +fn sudo_timeout( + deps: ExecuteDeps, + _env: Env, + _request: RequestPacket, +) -> StdResult> { // revert the state to Instantiated to force re-creation of ICA CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; @@ -358,7 +367,11 @@ fn sudo_timeout(deps: ExecuteDeps, _env: Env, request: RequestPacket) -> StdResu Ok(Response::default()) } -fn sudo_error(deps: ExecuteDeps, request: RequestPacket, details: String) -> StdResult> { +fn sudo_error( + _deps: ExecuteDeps, + request: RequestPacket, + _details: String, +) -> StdResult> { // either of these errors will close the channel request .sequence @@ -378,7 +391,11 @@ fn sudo_error(deps: ExecuteDeps, request: RequestPacket, details: String) -> Std // allows you "attach" some payload to your SubmitTx message // and process this payload when an acknowledgement for the SubmitTx message // is received in Sudo handler -fn prepare_sudo_payload(mut deps: ExecuteDeps, _env: Env, msg: Reply) -> StdResult> { +fn prepare_sudo_payload( + mut deps: ExecuteDeps, + _env: Env, + msg: Reply, +) -> StdResult> { let payload = read_reply_payload(deps.storage)?; let resp: MsgSubmitTxResponse = serde_json_wasm::from_slice( msg.result diff --git a/contracts/stride-liquid-staker/src/lib.rs b/contracts/stride-liquid-staker/src/lib.rs index f1dc5a5a..3da36ff7 100644 --- a/contracts/stride-liquid-staker/src/lib.rs +++ b/contracts/stride-liquid-staker/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; diff --git a/contracts/stride-liquid-staker/src/msg.rs b/contracts/stride-liquid-staker/src/msg.rs index 39027a33..aa2fab6f 100644 --- a/contracts/stride-liquid-staker/src/msg.rs +++ b/contracts/stride-liquid-staker/src/msg.rs @@ -82,12 +82,7 @@ pub enum QueryMsg { pub enum MigrateMsg { UpdateConfig { clock_addr: Option, - // stride_neutron_ibc_transfer_channel_id: Option, next_contract: Option, - // neutron_stride_ibc_connection_id: Option, - // ls_denom: Option, - // ibc_transfer_timeout: Option, - // ica_timeout: Option, remote_chain_info: Option, }, UpdateCodeId { diff --git a/contracts/stride-liquid-staker/src/state.rs b/contracts/stride-liquid-staker/src/state.rs index c85496ef..eab90d05 100644 --- a/contracts/stride-liquid-staker/src/state.rs +++ b/contracts/stride-liquid-staker/src/state.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{from_json, to_json_vec, Addr, Binary, Order, StdResult, Storage, Uint128}; +use cosmwasm_std::{from_json, to_json_vec, Addr, Binary, Order, StdResult, Storage}; use covenant_utils::neutron::{RemoteChainInfo, SudoPayload}; use cw_storage_plus::{Item, Map}; @@ -12,8 +12,6 @@ pub const CLOCK_ADDRESS: Item = Item::new("clock_address"); /// next contract address to forward the liquid staked funds to pub const NEXT_CONTRACT: Item = Item::new("next_contract"); -pub const TRANSFER_AMOUNT: Item = Item::new("transfer_amount"); - /// information needed for an ibc transfer to the remote chain pub const REMOTE_CHAIN_INFO: Item = Item::new("r_c_info"); @@ -22,8 +20,6 @@ pub const INTERCHAIN_ACCOUNTS: Map> = Map::new("interchain_accounts"); /// interchain transaction responses - ack/err/timeout state to query later -// pub const ACKNOWLEDGEMENT_RESULTS: Map<(String, u64), AcknowledgementResult> = -// Map::new("acknowledgement_results"); pub const REPLY_ID_STORAGE: Item> = Item::new("reply_queue_id"); pub const SUDO_PAYLOAD: Map<(String, u64), Vec> = Map::new("sudo_payload"); pub const ERRORS_QUEUE: Map = Map::new("errors_queue"); diff --git a/contracts/swap-covenant/Cargo.toml b/contracts/swap-covenant/Cargo.toml index 3b104488..e05c57fb 100644 --- a/contracts/swap-covenant/Cargo.toml +++ b/contracts/swap-covenant/Cargo.toml @@ -31,7 +31,6 @@ thiserror = { workspace = true } sha2 = { workspace = true } neutron-sdk = { workspace = true } cosmos-sdk-proto = { workspace = true } -protobuf = { workspace = true } schemars = { workspace = true } serde-json-wasm = { workspace = true } prost = { workspace = true } diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index e908918c..b424baac 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -3,7 +3,8 @@ use std::collections::BTreeSet; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - ensure, to_json_binary, to_json_string, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, WasmMsg + ensure, to_json_binary, to_json_string, Binary, Deps, DepsMut, Env, MessageInfo, Response, + StdError, StdResult, WasmMsg, }; use covenant_swap_holder::msg::RefundConfig; use covenant_utils::{ @@ -111,12 +112,20 @@ pub fn instantiate( // we validate that denoms explicitly defined in splits are the // same denoms that parties are expected to contribute ensure!( - msg.splits.contains_key(&msg.party_a_config.get_native_denom()), - ContractError::DenomMisconfigurationError(msg.party_a_config.get_native_denom(), format!("{:?}", covenant_denoms)) + msg.splits + .contains_key(&msg.party_a_config.get_native_denom()), + ContractError::DenomMisconfigurationError( + msg.party_a_config.get_native_denom(), + format!("{:?}", covenant_denoms) + ) ); ensure!( - msg.splits.contains_key(&msg.party_b_config.get_native_denom()), - ContractError::DenomMisconfigurationError(msg.party_b_config.get_native_denom(), format!("{:?}", covenant_denoms)) + msg.splits + .contains_key(&msg.party_b_config.get_native_denom()), + ContractError::DenomMisconfigurationError( + msg.party_b_config.get_native_denom(), + format!("{:?}", covenant_denoms) + ) ); let splitter_instantiate2_msg = covenant_native_splitter::msg::InstantiateMsg { diff --git a/contracts/swap-covenant/src/error.rs b/contracts/swap-covenant/src/error.rs index d80e4de1..a897fa4f 100644 --- a/contracts/swap-covenant/src/error.rs +++ b/contracts/swap-covenant/src/error.rs @@ -29,5 +29,5 @@ pub enum ContractError { InstantiationError(#[from] Instantiate2AddressError), #[error("{0} contribution missing an explicit split configuration (got {1})")] - DenomMisconfigurationError(String,String), + DenomMisconfigurationError(String, String), } diff --git a/contracts/swap-covenant/src/lib.rs b/contracts/swap-covenant/src/lib.rs index 0faea8f4..47bc573c 100644 --- a/contracts/swap-covenant/src/lib.rs +++ b/contracts/swap-covenant/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; diff --git a/contracts/swap-covenant/src/msg.rs b/contracts/swap-covenant/src/msg.rs index 29c17d5a..96cc48de 100644 --- a/contracts/swap-covenant/src/msg.rs +++ b/contracts/swap-covenant/src/msg.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, BTreeSet}; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Addr, Binary, Coin, Deps, StdResult, Uint64, WasmMsg}; +use cosmwasm_std::{Addr, Binary, Coin, StdResult, Uint64, WasmMsg}; use covenant_utils::{ instantiate2_helper::Instantiate2HelperConfig, split::SplitConfig, CovenantParty, DestinationConfig, InterchainCovenantParty, NativeCovenantParty, ReceiverConfig, diff --git a/contracts/swap-holder/src/contract.rs b/contracts/swap-holder/src/contract.rs index 3dec380f..f49e671f 100644 --- a/contracts/swap-holder/src/contract.rs +++ b/contracts/swap-holder/src/contract.rs @@ -1,5 +1,6 @@ use cosmwasm_std::{ - to_json_binary, Addr, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint128 + to_json_binary, Addr, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, + StdError, StdResult, Uint128, }; use covenant_utils::CovenantTerms; @@ -7,7 +8,8 @@ use crate::{ error::ContractError, msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, state::{ - CLOCK_ADDRESS, CONTRACT_STATE, COVENANT_TERMS, LOCKUP_CONFIG, NEXT_CONTRACT, PARTIES_CONFIG, REFUND_CONFIG, + CLOCK_ADDRESS, CONTRACT_STATE, COVENANT_TERMS, LOCKUP_CONFIG, NEXT_CONTRACT, + PARTIES_CONFIG, REFUND_CONFIG, }, }; #[cfg(not(feature = "library"))] @@ -35,8 +37,10 @@ pub fn instantiate( "past lockup config", ))); } - deps.api.addr_validate(&msg.refund_config.party_a_refund_address)?; - deps.api.addr_validate(&msg.refund_config.party_b_refund_address)?; + deps.api + .addr_validate(&msg.refund_config.party_a_refund_address)?; + deps.api + .addr_validate(&msg.refund_config.party_b_refund_address)?; NEXT_CONTRACT.save(deps.storage, &next_contract)?; CLOCK_ADDRESS.save(deps.storage, &clock_addr)?; @@ -155,51 +159,48 @@ fn try_refund(mut deps: DepsMut, env: Env, clock_addr: Addr) -> Result = match (party_a_coin.amount.is_zero(), party_b_coin.amount.is_zero()) { - // both balances being zero means that either: - // 1. neither party deposited any funds in the first place - // 2. we have refunded both parties - // either way, this indicates completion - (true, true) => { - let msg = ContractState::complete_and_dequeue(deps.branch(), clock_addr.as_str())?; - - return Ok(Response::default() - .add_message(msg) - .add_attribute("method", "try_refund") - .add_attribute("result", "nothing_to_refund") - .add_attribute("contract_state", "complete")); - } - // party A failed to deposit. refund party B - (true, false) => vec![ - BankMsg::Send { + let messages: Vec = + match (party_a_coin.amount.is_zero(), party_b_coin.amount.is_zero()) { + // both balances being zero means that either: + // 1. neither party deposited any funds in the first place + // 2. we have refunded both parties + // either way, this indicates completion + (true, true) => { + let msg = ContractState::complete_and_dequeue(deps.branch(), clock_addr.as_str())?; + + return Ok(Response::default() + .add_message(msg) + .add_attribute("method", "try_refund") + .add_attribute("result", "nothing_to_refund") + .add_attribute("contract_state", "complete")); + } + // party A failed to deposit. refund party B + (true, false) => vec![BankMsg::Send { to_address: refund_config.party_b_refund_address, amount: vec![party_b_coin], } - .into(), - ], - // party B failed to deposit. refund party A - (false, true) => vec![ - BankMsg::Send { - to_address: refund_config.party_a_refund_address, - amount: vec![party_a_coin], - } - .into(), - ], - // not enough balances to perform the covenant swap. - // refund denoms to both parties. - (false, false) => vec![ - BankMsg::Send { + .into()], + // party B failed to deposit. refund party A + (false, true) => vec![BankMsg::Send { to_address: refund_config.party_a_refund_address, amount: vec![party_a_coin], } - .into(), - BankMsg::Send { - to_address: refund_config.party_b_refund_address, - amount: vec![party_b_coin], - } - .into(), - ], - }; + .into()], + // not enough balances to perform the covenant swap. + // refund denoms to both parties. + (false, false) => vec![ + BankMsg::Send { + to_address: refund_config.party_a_refund_address, + amount: vec![party_a_coin], + } + .into(), + BankMsg::Send { + to_address: refund_config.party_b_refund_address, + amount: vec![party_b_coin], + } + .into(), + ], + }; Ok(Response::default() .add_attribute("method", "try_refund") diff --git a/contracts/two-party-pol-covenant/Cargo.toml b/contracts/two-party-pol-covenant/Cargo.toml index 360b5664..ef13cc76 100644 --- a/contracts/two-party-pol-covenant/Cargo.toml +++ b/contracts/two-party-pol-covenant/Cargo.toml @@ -31,10 +31,8 @@ thiserror = { workspace = true } sha2 = { workspace = true } neutron-sdk = { workspace = true } cosmos-sdk-proto = { workspace = true } -protobuf = { workspace = true } schemars = { workspace = true } serde-json-wasm = { workspace = true } -base64 = { workspace = true } prost = { workspace = true } prost-types = { workspace = true } bech32 = { workspace = true } diff --git a/contracts/two-party-pol-covenant/src/contract.rs b/contracts/two-party-pol-covenant/src/contract.rs index f534fdde..8a85e0c1 100644 --- a/contracts/two-party-pol-covenant/src/contract.rs +++ b/contracts/two-party-pol-covenant/src/contract.rs @@ -264,8 +264,7 @@ pub fn instantiate( party_b_router_instantiate2_config.addr, ) .add_attribute("holder_addr", holder_instantiate2_config.addr) - .add_messages(messages) - ) + .add_messages(messages)) } #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/two-party-pol-covenant/src/lib.rs b/contracts/two-party-pol-covenant/src/lib.rs index 0faea8f4..47bc573c 100644 --- a/contracts/two-party-pol-covenant/src/lib.rs +++ b/contracts/two-party-pol-covenant/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; diff --git a/contracts/two-party-pol-covenant/src/msg.rs b/contracts/two-party-pol-covenant/src/msg.rs index 980594e9..f9b81d89 100644 --- a/contracts/two-party-pol-covenant/src/msg.rs +++ b/contracts/two-party-pol-covenant/src/msg.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, BTreeSet}; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{coin, Addr, Decimal, Deps, StdResult, Uint128, Uint64, WasmMsg}; +use cosmwasm_std::{coin, Addr, Decimal, StdResult, Uint128, Uint64, WasmMsg}; use covenant_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; use covenant_osmo_liquid_pooler::msg::OsmosisLiquidPoolerConfig; use covenant_two_party_pol_holder::msg::{CovenantType, RagequitConfig, TwoPartyPolCovenantParty}; diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index b1802ff0..048763d1 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -2,7 +2,8 @@ use std::cmp::Ordering; use std::collections::BTreeMap; use cosmwasm_std::{ - ensure, to_json_binary, BankMsg, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult + ensure, to_json_binary, BankMsg, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, + MessageInfo, Response, StdError, StdResult, }; #[cfg(not(feature = "library"))] @@ -178,8 +179,7 @@ fn try_claim(deps: DepsMut, info: MessageInfo) -> Result Result { @@ -381,11 +381,11 @@ fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> Result try_deposit(deps, env, info, clock_addr.as_str()), ContractState::Active => check_expiration(deps, env), - ContractState::Expired | - ContractState::Ragequit | - ContractState::Complete => Ok(Response::default() - .add_attribute("method", "tick") - .add_attribute("contract_state", state.to_string())), + ContractState::Expired | ContractState::Ragequit | ContractState::Complete => { + Ok(Response::default() + .add_attribute("method", "tick") + .add_attribute("contract_state", state.to_string())) + } } } @@ -591,7 +591,9 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { QueryMsg::Config {} => Ok(to_json_binary(&COVENANT_CONFIG.load(deps.storage)?)?), QueryMsg::DepositAddress {} => Ok(to_json_binary(&env.contract.address)?), QueryMsg::DenomSplits {} => Ok(to_json_binary(&DENOM_SPLITS.load(deps.storage)?)?), - QueryMsg::EmergencyCommittee {} => Ok(to_json_binary(&EMERGENCY_COMMITTEE_ADDR.may_load(deps.storage)?)?), + QueryMsg::EmergencyCommittee {} => Ok(to_json_binary( + &EMERGENCY_COMMITTEE_ADDR.may_load(deps.storage)?, + )?), } } @@ -656,7 +658,7 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> StdResult } if let Some(splits) = denom_splits { - for (_, config) in &splits { + for config in splits.values() { config.validate_shares_and_receiver_addresses(deps.api)?; } resp = resp.add_attribute("explicit_splits", format!("{:?}", splits)); diff --git a/contracts/two-party-pol-holder/src/lib.rs b/contracts/two-party-pol-holder/src/lib.rs index 0faea8f4..47bc573c 100644 --- a/contracts/two-party-pol-holder/src/lib.rs +++ b/contracts/two-party-pol-holder/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::unwrap_used, clippy::expect_used)] - extern crate core; pub mod contract; diff --git a/contracts/two-party-pol-holder/src/msg.rs b/contracts/two-party-pol-holder/src/msg.rs index a3f38940..81ec008f 100644 --- a/contracts/two-party-pol-holder/src/msg.rs +++ b/contracts/two-party-pol-holder/src/msg.rs @@ -281,7 +281,8 @@ impl TwoPartyPolCovenantConfig { api.addr_validate(&self.party_b.host_addr)?; ensure!( - !self.party_a.contribution.amount.is_zero() && !self.party_b.contribution.amount.is_zero(), + !self.party_a.contribution.amount.is_zero() + && !self.party_b.contribution.amount.is_zero(), ContractError::PartyContributionConfigError {} ); diff --git a/packages/covenant-utils/src/lib.rs b/packages/covenant-utils/src/lib.rs index 195304ad..2792ef37 100644 --- a/packages/covenant-utils/src/lib.rs +++ b/packages/covenant-utils/src/lib.rs @@ -2,9 +2,13 @@ use std::collections::BTreeMap; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - to_json_string, Addr, Api, Attribute, BankMsg, BlockInfo, Coin, CosmosMsg, Decimal, IbcMsg, IbcTimeout, StdError, StdResult, Timestamp, Uint128, Uint64 + to_json_string, Addr, Api, Attribute, Coin, CosmosMsg, Decimal, StdError, StdResult, Timestamp, + Uint128, Uint64, +}; +use neutron_sdk::{ + bindings::msg::{IbcFee, NeutronMsg}, + sudo::msg::RequestPacketTimeoutHeight, }; -use neutron_sdk::{bindings::msg::{IbcFee, NeutronMsg}, sudo::msg::RequestPacketTimeoutHeight}; pub mod astroport; pub mod deadline; @@ -90,10 +94,10 @@ pub struct CovenantParty { impl CovenantParty { pub fn validate_addresses(&self, api: &dyn Api) -> StdResult { match &self.receiver_config { - ReceiverConfig::Native(addr) => api.addr_validate(&addr), + ReceiverConfig::Native(addr) => api.addr_validate(addr), ReceiverConfig::Ibc(destination_config) => { api.addr_validate(&destination_config.destination_receiver_addr) - }, + } } } } diff --git a/packages/covenant-utils/src/neutron.rs b/packages/covenant-utils/src/neutron.rs index 373e34e6..ba3f9a13 100644 --- a/packages/covenant-utils/src/neutron.rs +++ b/packages/covenant-utils/src/neutron.rs @@ -1,7 +1,8 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Attribute, Binary, Coin, QueryRequest, StdError, Uint128, Uint64}; use neutron_sdk::{ - bindings::{query::NeutronQuery, types::ProtobufAny}, NeutronResult + bindings::{query::NeutronQuery, types::ProtobufAny}, + NeutronResult, }; use prost::Message; @@ -143,4 +144,4 @@ pub fn get_ictxs_module_params_query_msg() -> QueryRequest { path: "/neutron.interchaintxs.v1.Query/Params".to_string(), data: Binary(Vec::new()), } -} \ No newline at end of file +} diff --git a/packages/covenant-utils/src/split.rs b/packages/covenant-utils/src/split.rs index 60694ecb..e04d1e88 100644 --- a/packages/covenant-utils/src/split.rs +++ b/packages/covenant-utils/src/split.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - Api, Attribute, BankMsg, Coin, CosmosMsg, Decimal, Fraction, StdError, StdResult, Uint128 + Api, Attribute, BankMsg, Coin, CosmosMsg, Decimal, Fraction, StdError, StdResult, Uint128, }; #[cw_serde] diff --git a/unit-tests/src/lib.rs b/unit-tests/src/lib.rs index 1fb2ee10..2d6b3e53 100644 --- a/unit-tests/src/lib.rs +++ b/unit-tests/src/lib.rs @@ -4,9 +4,6 @@ #[cfg(test)] pub mod setup; -#[cfg(test)] -pub mod test; - #[cfg(test)] pub mod test_astroport_liquid_pooler; #[cfg(test)] diff --git a/unit-tests/src/setup/base_suite.rs b/unit-tests/src/setup/base_suite.rs index 9b4b4eea..2c606c1d 100644 --- a/unit-tests/src/setup/base_suite.rs +++ b/unit-tests/src/setup/base_suite.rs @@ -53,7 +53,7 @@ pub trait BaseSuiteMut { .unwrap() } - fn fund_contract(&mut self, amount: &Vec, to: Addr) { + fn fund_contract(&mut self, amount: &[Coin], to: Addr) { let faucet = self.get_faucet_addr().clone(); let app = self.get_app(); diff --git a/unit-tests/src/setup/contracts.rs b/unit-tests/src/setup/contracts.rs index c9ef3a81..34fc1bf5 100644 --- a/unit-tests/src/setup/contracts.rs +++ b/unit-tests/src/setup/contracts.rs @@ -399,17 +399,15 @@ pub fn swap_covenant_contract() -> Box> { covenant_swap::contract::query(get_empty_deps(deps), env, msg) }; - let migrate = - |deps: DepsMut, env: Env, msg: covenant_swap::msg::MigrateMsg| { - execute_into_neutron(covenant_swap::contract::migrate( - get_empty_depsmut(deps), - env, - msg, - )) - }; + let migrate = |deps: DepsMut, env: Env, msg: covenant_swap::msg::MigrateMsg| { + execute_into_neutron(covenant_swap::contract::migrate( + get_empty_depsmut(deps), + env, + msg, + )) + }; - let contract = ContractWrapper::new(exec, init, query) - .with_migrate(migrate); + let contract = ContractWrapper::new(exec, init, query).with_migrate(migrate); Box::new(contract) } diff --git a/unit-tests/src/setup/custom_module.rs b/unit-tests/src/setup/custom_module.rs index 24163a57..afcb9667 100644 --- a/unit-tests/src/setup/custom_module.rs +++ b/unit-tests/src/setup/custom_module.rs @@ -1,7 +1,8 @@ use std::{collections::BTreeMap, str::FromStr}; use cosmwasm_std::{ - coin, coins, from_json, to_json_binary, to_json_string, Addr, BalanceResponse, BankMsg, BankQuery, QueryRequest, StdError, StdResult, Storage, Uint128 + coin, coins, from_json, to_json_binary, to_json_string, Addr, BalanceResponse, BankMsg, + BankQuery, StdError, StdResult, Storage, Uint128, }; use covenant_ibc_forwarder::helpers::MsgTransfer; use covenant_stride_liquid_staker::helpers::Autopilot; @@ -16,7 +17,10 @@ use neutron_sdk::{ bindings::{ msg::{MsgSubmitTxResponse, NeutronMsg}, query::NeutronQuery, - }, interchain_txs::helpers::get_port_id, query::min_ibc_fee::MinIbcFeeResponse, sudo::msg::RequestPacket + }, + interchain_txs::helpers::get_port_id, + query::min_ibc_fee::MinIbcFeeResponse, + sudo::msg::RequestPacket, }; use prost::Message; @@ -820,16 +824,14 @@ impl Module for NeutronKeeper { .unwrap(), ) .unwrap()), - NeutronQuery::MinIbcFee {} => Ok(to_json_binary( - &MinIbcFeeResponse { - min_fee: neutron_sdk::bindings::msg::IbcFee { - recv_fee: vec![], - ack_fee: vec![coin(10000, DENOM_NTRN)], - timeout_fee: vec![coin(10000, DENOM_NTRN)], - }, - }) - .unwrap() - ), + NeutronQuery::MinIbcFee {} => Ok(to_json_binary(&MinIbcFeeResponse { + min_fee: neutron_sdk::bindings::msg::IbcFee { + recv_fee: vec![], + ack_fee: vec![coin(10000, DENOM_NTRN)], + timeout_fee: vec![coin(10000, DENOM_NTRN)], + }, + }) + .unwrap()), NeutronQuery::InterchainQueryResult { .. } => unimplemented!(), NeutronQuery::RegisteredInterchainQueries { .. } => unimplemented!(), NeutronQuery::RegisteredInterchainQuery { .. } => unimplemented!(), diff --git a/unit-tests/src/setup/instantiates/ibc_forwarder.rs b/unit-tests/src/setup/instantiates/ibc_forwarder.rs index b145ca99..25e549e9 100644 --- a/unit-tests/src/setup/instantiates/ibc_forwarder.rs +++ b/unit-tests/src/setup/instantiates/ibc_forwarder.rs @@ -1,7 +1,6 @@ -use cosmwasm_std::{coin, Uint128, Uint64}; -use neutron_sdk::bindings::msg::IbcFee; +use cosmwasm_std::{Uint128, Uint64}; -use crate::setup::{DENOM_ATOM_ON_NTRN, DENOM_NTRN, NTRN_HUB_CHANNEL}; +use crate::setup::{DENOM_ATOM_ON_NTRN, NTRN_HUB_CHANNEL}; pub struct IbcForwarderInstantiate { pub msg: covenant_ibc_forwarder::msg::InstantiateMsg, diff --git a/unit-tests/src/setup/instantiates/native_splitter.rs b/unit-tests/src/setup/instantiates/native_splitter.rs index 1d504610..796a3de3 100644 --- a/unit-tests/src/setup/instantiates/native_splitter.rs +++ b/unit-tests/src/setup/instantiates/native_splitter.rs @@ -1,6 +1,6 @@ use std::{collections::BTreeMap, str::FromStr}; -use cosmwasm_std::{Addr, Decimal}; +use cosmwasm_std::Decimal; use covenant_utils::split::SplitConfig; use crate::setup::{DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN}; diff --git a/unit-tests/src/setup/instantiates/osmo_lp_outpost.rs b/unit-tests/src/setup/instantiates/osmo_lp_outpost.rs index bc63e43b..e4dd9156 100644 --- a/unit-tests/src/setup/instantiates/osmo_lp_outpost.rs +++ b/unit-tests/src/setup/instantiates/osmo_lp_outpost.rs @@ -16,8 +16,8 @@ impl OsmpLpOutpostInstantiate { } } -impl OsmpLpOutpostInstantiate { - pub fn default() -> Self { +impl Default for OsmpLpOutpostInstantiate { + fn default() -> Self { Self::new() } } diff --git a/unit-tests/src/setup/instantiates/remote_chain_splitter.rs b/unit-tests/src/setup/instantiates/remote_chain_splitter.rs index 44d3c7c8..a3d69a14 100644 --- a/unit-tests/src/setup/instantiates/remote_chain_splitter.rs +++ b/unit-tests/src/setup/instantiates/remote_chain_splitter.rs @@ -1,6 +1,6 @@ use std::{collections::BTreeMap, str::FromStr}; -use cosmwasm_std::{coin, Decimal, Uint128, Uint64}; +use cosmwasm_std::{Decimal, Uint128, Uint64}; use covenant_utils::split::SplitConfig; use crate::setup::{DENOM_ATOM_ON_NTRN, NTRN_HUB_CHANNEL}; diff --git a/unit-tests/src/setup/instantiates/swap_covenant.rs b/unit-tests/src/setup/instantiates/swap_covenant.rs index ca058be5..ec7d2375 100644 --- a/unit-tests/src/setup/instantiates/swap_covenant.rs +++ b/unit-tests/src/setup/instantiates/swap_covenant.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use cosmwasm_std::{coin, testing::mock_env, Addr, Decimal, Uint128, Uint64}; +use cosmwasm_std::{coin, testing::mock_env, Addr, Decimal, Uint64}; use cw_utils::Expiration; use crate::setup::suite_builder::SuiteBuilder; diff --git a/unit-tests/src/test_astroport_liquid_pooler/suite.rs b/unit-tests/src/test_astroport_liquid_pooler/suite.rs index 475ba0dc..c724ed89 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/suite.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/suite.rs @@ -224,11 +224,14 @@ impl Suite { pub(crate) fn expire_lockup(&mut self) { let holder = self.holder_addr.clone(); - let expiration: Expiration = self.app.wrap().query_wasm_smart( - holder.to_string(), - &covenant_single_party_pol_holder::msg::QueryMsg::LockupConfig {}, - ) - .unwrap(); + let expiration: Expiration = self + .app + .wrap() + .query_wasm_smart( + holder.to_string(), + &covenant_single_party_pol_holder::msg::QueryMsg::LockupConfig {}, + ) + .unwrap(); let app = self.get_app(); app.update_block(|b| match expiration { Expiration::AtHeight(h) => b.height = h + 1, diff --git a/unit-tests/src/test_astroport_liquid_pooler/tests.rs b/unit-tests/src/test_astroport_liquid_pooler/tests.rs index ffeace26..c6840558 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/tests.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/tests.rs @@ -64,18 +64,19 @@ fn test_withdraw_validates_percentage_range_ceiling() { suite.tick_contract(suite.liquid_pooler_addr.clone()); suite.expire_lockup(); let holder: Addr = suite.holder_addr.clone(); - suite.app.execute_contract( - holder.clone(), - suite.liquid_pooler_addr.clone(), - &covenant_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { - percentage: Some(Decimal::from_str("101.0").unwrap()), - }, - &[], - ) - .unwrap(); + suite + .app + .execute_contract( + holder.clone(), + suite.liquid_pooler_addr.clone(), + &covenant_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { + percentage: Some(Decimal::from_str("101.0").unwrap()), + }, + &[], + ) + .unwrap(); } - #[test] #[should_panic(expected = "Withdraw percentage range must belong to range (0.0, 1.0]")] fn test_withdraw_validates_percentage_range_floor() { @@ -93,15 +94,17 @@ fn test_withdraw_validates_percentage_range_floor() { suite.tick_contract(suite.liquid_pooler_addr.clone()); let holder = suite.holder_addr.clone(); - suite.app.execute_contract( - holder.clone(), - suite.liquid_pooler_addr.clone(), - &covenant_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { - percentage: Some(Decimal::from_str("0.0").unwrap()), - }, - &[], - ) - .unwrap(); + suite + .app + .execute_contract( + holder.clone(), + suite.liquid_pooler_addr.clone(), + &covenant_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { + percentage: Some(Decimal::from_str("0.0").unwrap()), + }, + &[], + ) + .unwrap(); } #[test] @@ -149,8 +152,11 @@ fn test_withdraw_no_lp_tokens_withdraws_covenant_assets() { suite.expire_lockup(); suite.withdraw(&withdrawer, None); - suite.assert_balance(&suite.holder_addr.clone(), coin(500_000, DENOM_ATOM_ON_NTRN)); - suite.assert_balance(&suite.holder_addr.clone(), coin(500_000, DENOM_LS_ATOM_ON_NTRN)); + suite.assert_balance(suite.holder_addr.clone(), coin(500_000, DENOM_ATOM_ON_NTRN)); + suite.assert_balance( + suite.holder_addr.clone(), + coin(500_000, DENOM_LS_ATOM_ON_NTRN), + ); } #[test] @@ -281,11 +287,11 @@ fn test_provide_liquidity_single_side_asset_a() { suite.tick_contract(suite.liquid_pooler_addr.clone()); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(70_000, DENOM_ATOM_ON_NTRN), ); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN), ); assert_eq!( @@ -300,11 +306,11 @@ fn test_provide_liquidity_single_side_asset_a() { .tick_contract(suite.liquid_pooler_addr.clone()) .assert_event(&Event::new("wasm").add_attribute("method", "single_side_lp")); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(0, DENOM_ATOM_ON_NTRN), ); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN), ); assert_eq!( @@ -331,11 +337,11 @@ fn test_provide_liquidity_single_side_asset_a_exceeds_limits() { suite.tick_contract(suite.liquid_pooler_addr.clone()); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(500_000, DENOM_ATOM_ON_NTRN), ); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN), ); assert_eq!( @@ -374,11 +380,11 @@ fn test_provide_liquidity_single_side_asset_b() { suite.tick_contract(suite.liquid_pooler_addr.clone()); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(0, DENOM_ATOM_ON_NTRN), ); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(70_000, DENOM_LS_ATOM_ON_NTRN), ); assert_eq!( @@ -393,11 +399,11 @@ fn test_provide_liquidity_single_side_asset_b() { .tick_contract(suite.liquid_pooler_addr.clone()) .assert_event(&Event::new("wasm").add_attribute("method", "single_side_lp")); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(0, DENOM_ATOM_ON_NTRN), ); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN), ); assert_eq!( @@ -425,11 +431,11 @@ fn test_provide_liquidity_single_side_asset_b_exceeds_limits() { suite.tick_contract(suite.liquid_pooler_addr.clone()); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(0, DENOM_ATOM_ON_NTRN), ); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(500_000, DENOM_LS_ATOM_ON_NTRN), ); assert_eq!( @@ -468,11 +474,11 @@ fn test_provide_liquidity_double_side_excess_a_denom() { suite.tick_contract(suite.liquid_pooler_addr.clone()); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(500_000, DENOM_ATOM_ON_NTRN), ); suite.assert_balance( - &suite.liquid_pooler_addr.clone(), + suite.liquid_pooler_addr.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN), ); assert_eq!( diff --git a/unit-tests/src/test_ibc_forwarder/suite.rs b/unit-tests/src/test_ibc_forwarder/suite.rs index 3b3ff672..c3b36760 100644 --- a/unit-tests/src/test_ibc_forwarder/suite.rs +++ b/unit-tests/src/test_ibc_forwarder/suite.rs @@ -3,7 +3,6 @@ use std::str::FromStr; use cosmwasm_std::{Addr, Uint128, Uint64}; use covenant_utils::neutron::RemoteChainInfo; use cw_storage_plus::KeyDeserialize; -use neutron_sdk::bindings::msg::IbcFee; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, diff --git a/unit-tests/src/test_interchain_router/tests.rs b/unit-tests/src/test_interchain_router/tests.rs index 72348553..cf13a490 100644 --- a/unit-tests/src/test_interchain_router/tests.rs +++ b/unit-tests/src/test_interchain_router/tests.rs @@ -12,7 +12,8 @@ fn test_instantiate_validates_clock_address() { #[should_panic] fn test_instantiate_validates_destination_receiver_addr() { let mut builder = InterchainRouterBuilder::default(); - builder.instantiate_msg + builder + .instantiate_msg .msg .destination_config .destination_receiver_addr = "invalid_receiver".to_string(); diff --git a/unit-tests/src/test_native_splitter/tests.rs b/unit-tests/src/test_native_splitter/tests.rs index 9d8f9e0c..82c175ba 100644 --- a/unit-tests/src/test_native_splitter/tests.rs +++ b/unit-tests/src/test_native_splitter/tests.rs @@ -16,10 +16,17 @@ use super::suite::NativeSplitterBuilder; fn test_instantiate_validates_explicit_split_shares() { let mut builder = NativeSplitterBuilder::default(); let (denom, mut split_config) = builder.instantiate_msg.msg.splits.pop_first().unwrap(); - let invalid_split_config: BTreeMap = split_config.receivers.iter_mut() + let invalid_split_config: BTreeMap = split_config + .receivers + .iter_mut() .map(|(k, _)| (k.to_string(), Decimal::percent(49))) .collect(); - builder.instantiate_msg.msg.splits.insert(denom, SplitConfig { receivers: invalid_split_config }); + builder.instantiate_msg.msg.splits.insert( + denom, + SplitConfig { + receivers: invalid_split_config, + }, + ); builder.build(); } @@ -28,10 +35,17 @@ fn test_instantiate_validates_explicit_split_shares() { fn test_instantiate_validates_explicit_split_receiver_addresses() { let mut builder = NativeSplitterBuilder::default(); let (denom, mut split_config) = builder.instantiate_msg.msg.splits.pop_first().unwrap(); - let invalid_split_config: BTreeMap = split_config.receivers.iter_mut() - .map(|(k, v)| (format!("invalid_{:?}", k), v.clone())) + let invalid_split_config: BTreeMap = split_config + .receivers + .iter_mut() + .map(|(k, v)| (format!("invalid_{:?}", k), *v)) .collect(); - builder.instantiate_msg.msg.splits.insert(denom, SplitConfig { receivers: invalid_split_config }); + builder.instantiate_msg.msg.splits.insert( + denom, + SplitConfig { + receivers: invalid_split_config, + }, + ); builder.build(); } @@ -49,7 +63,9 @@ fn test_instantiate_validates_fallback_split_receiver_addresses() { let mut invalid_split_config = BTreeMap::new(); invalid_split_config.insert("invalid_address".to_string(), Decimal::one()); NativeSplitterBuilder::default() - .with_fallback_split(Some(SplitConfig { receivers: invalid_split_config })) + .with_fallback_split(Some(SplitConfig { + receivers: invalid_split_config, + })) .build(); } @@ -58,9 +74,14 @@ fn test_instantiate_validates_fallback_split_receiver_addresses() { fn test_instantiate_validates_fallback_split_shares() { let builder = NativeSplitterBuilder::default(); let mut invalid_split_config = BTreeMap::new(); - invalid_split_config.insert(builder.instantiate_msg.msg.clock_address.to_string(), Decimal::percent(50)); + invalid_split_config.insert( + builder.instantiate_msg.msg.clock_address.to_string(), + Decimal::percent(50), + ); builder - .with_fallback_split(Some(SplitConfig { receivers: invalid_split_config })) + .with_fallback_split(Some(SplitConfig { + receivers: invalid_split_config, + })) .build(); } diff --git a/unit-tests/src/test_remote_chain_splitter/suite.rs b/unit-tests/src/test_remote_chain_splitter/suite.rs index 0eb6285b..be11f355 100644 --- a/unit-tests/src/test_remote_chain_splitter/suite.rs +++ b/unit-tests/src/test_remote_chain_splitter/suite.rs @@ -1,15 +1,13 @@ use std::collections::BTreeMap; -use cosmwasm_std::{coin, Addr, Uint128, Uint64}; +use cosmwasm_std::{Addr, Uint128, Uint64}; use covenant_utils::{neutron::RemoteChainInfo, split::SplitConfig}; -use neutron_sdk::bindings::msg::IbcFee; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, instantiates::remote_chain_splitter::RemoteChainSplitterInstantiate, suite_builder::SuiteBuilder, - CustomApp, CLOCK_SALT, DENOM_ATOM_ON_NTRN, DENOM_NTRN, NTRN_HUB_CHANNEL, - REMOTE_CHAIN_SPLITTER_SALT, + CustomApp, CLOCK_SALT, DENOM_ATOM_ON_NTRN, NTRN_HUB_CHANNEL, REMOTE_CHAIN_SPLITTER_SALT, }; pub struct RemoteChainSplitterBuilder { diff --git a/unit-tests/src/test_remote_chain_splitter/tests.rs b/unit-tests/src/test_remote_chain_splitter/tests.rs index 47373db0..aa90a21c 100644 --- a/unit-tests/src/test_remote_chain_splitter/tests.rs +++ b/unit-tests/src/test_remote_chain_splitter/tests.rs @@ -24,10 +24,17 @@ fn test_instantiate_validates_clock_address() { fn test_instantiate_validates_explicit_split_shares() { let mut builder = RemoteChainSplitterBuilder::default(); let (denom, mut split_config) = builder.instantiate_msg.msg.splits.pop_first().unwrap(); - let invalid_split_config: BTreeMap = split_config.receivers.iter_mut() + let invalid_split_config: BTreeMap = split_config + .receivers + .iter_mut() .map(|(k, _)| (k.to_string(), Decimal::percent(49))) .collect(); - builder.instantiate_msg.msg.splits.insert(denom, SplitConfig { receivers: invalid_split_config }); + builder.instantiate_msg.msg.splits.insert( + denom, + SplitConfig { + receivers: invalid_split_config, + }, + ); builder.build(); } @@ -140,7 +147,13 @@ fn test_execute_tick_splits_funds_happy() { #[test] fn test_execute_tick_splits_with_no_leftover() { let mut builder = RemoteChainSplitterBuilder::default().with_amount(Uint128::new(100)); - let mut split_config = builder.instantiate_msg.msg.splits.get(DENOM_ATOM_ON_NTRN).unwrap().clone(); + let mut split_config = builder + .instantiate_msg + .msg + .splits + .get(DENOM_ATOM_ON_NTRN) + .unwrap() + .clone(); let mut first_entry = split_config.receivers.pop_first().unwrap(); let mut second_entry = split_config.receivers.pop_first().unwrap(); @@ -148,9 +161,15 @@ fn test_execute_tick_splits_with_no_leftover() { second_entry.1 = Decimal::from_str("0.893").unwrap(); split_config.receivers.insert(first_entry.0, first_entry.1); - split_config.receivers.insert(second_entry.0, second_entry.1); - - builder.instantiate_msg.msg.splits.insert(DENOM_ATOM_ON_NTRN.to_string(), split_config); + split_config + .receivers + .insert(second_entry.0, second_entry.1); + + builder + .instantiate_msg + .msg + .splits + .insert(DENOM_ATOM_ON_NTRN.to_string(), split_config); let mut suite = builder.build(); diff --git a/unit-tests/src/test_single_party_covenant/test.rs b/unit-tests/src/test_single_party_covenant/test.rs index 00000a78..29c1f7e9 100644 --- a/unit-tests/src/test_single_party_covenant/test.rs +++ b/unit-tests/src/test_single_party_covenant/test.rs @@ -1,8 +1,9 @@ use cosmwasm_std::{coin, to_json_binary, Addr, Event, Uint128, Uint64}; -use cw_multi_test::Executor; +use cw_multi_test::{AppResponse, Executor}; use crate::setup::{ - base_suite::BaseSuiteMut, ADMIN, DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_STRIDE + base_suite::BaseSuiteMut, ADMIN, DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, + DENOM_LS_ATOM_ON_STRIDE, }; use super::suite::Suite; @@ -10,6 +11,23 @@ use super::suite::Suite; #[test] fn test_covenant() { let mut suite = Suite::new_with_stable_pool(); + let resp: AppResponse = suite + .app + .execute_contract( + suite.admin.clone(), + suite.lser_addr.clone(), + &covenant_stride_liquid_staker::msg::ExecuteMsg::Transfer { + amount: 500_000_000_000_u128.into(), + }, + &[], + ) + .unwrap(); + + resp.assert_event( + &Event::new("wasm") + .add_attribute("method", "try_permisionless_transfer") + .add_attribute("ica_status", "not_created"), + ); suite.get_and_fund_depositors(coin(1_000_000_000_000_u128, DENOM_ATOM)); @@ -34,7 +52,7 @@ fn test_covenant() { .unwrap() .is_empty() { - suite.tick("Wait for lp_forwarder ICA to get its split"); + suite.tick("Wait for ls_forwarder ICA to get its split"); } let lp_forwarder_ica_balance = suite @@ -1039,11 +1057,12 @@ fn test_migrate_update_config_with_codes() { transfer_amount: None, }; - let liquid_pooler_migrate_msg = covenant_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { - clock_addr: Some(covenant_addr.to_string()), - holder_address: None, - lp_config: None, - }; + let liquid_pooler_migrate_msg = + covenant_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + holder_address: None, + lp_config: None, + }; let liquid_staker_migrate_msg = covenant_stride_liquid_staker::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), @@ -1051,40 +1070,77 @@ fn test_migrate_update_config_with_codes() { remote_chain_info: None, }; - let remote_chain_splitter_migrate_msg = covenant_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { - clock_addr: Some(covenant_addr.to_string()), - remote_chain_info: None, - splits: None, - }; + let remote_chain_splitter_migrate_msg = + covenant_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(covenant_addr.to_string()), + remote_chain_info: None, + splits: None, + }; + + let resp = suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + covenant_addr, + &covenant_single_party_pol::msg::MigrateMsg::MigrateContracts { + codes: Some(contract_codes.clone()), + clock: None, + holder: Some(holder_migrate_msg.clone()), + ls_forwarder: Some(ibc_forwarder_migrate_msg.clone()), + lp_forwarder: Some(ibc_forwarder_migrate_msg.clone()), + splitter: Some(remote_chain_splitter_migrate_msg.clone()), + liquid_pooler: Some( + covenant_single_party_pol::msg::LiquidPoolerMigrateMsg::Astroport( + liquid_pooler_migrate_msg.clone(), + ), + ), + liquid_staker: Some(liquid_staker_migrate_msg.clone()), + router: None, + }, + 2, + ) + .unwrap(); - let resp = suite.app.migrate_contract( - Addr::unchecked(ADMIN), - covenant_addr, - &covenant_single_party_pol::msg::MigrateMsg::MigrateContracts { - codes: Some(contract_codes.clone()), - clock: None, - holder: Some(holder_migrate_msg.clone()), - ls_forwarder: Some(ibc_forwarder_migrate_msg.clone()), - lp_forwarder: Some(ibc_forwarder_migrate_msg.clone()), - splitter: Some(remote_chain_splitter_migrate_msg.clone()), - liquid_pooler: Some( - covenant_single_party_pol::msg::LiquidPoolerMigrateMsg::Astroport(liquid_pooler_migrate_msg.clone()) + resp.assert_event( + &Event::new("wasm") + .add_attribute( + "contract_codes_migrate", + to_json_binary(&contract_codes).unwrap().to_base64(), + ) + .add_attribute( + "ls_forwarder_migrate", + to_json_binary(&ibc_forwarder_migrate_msg) + .unwrap() + .to_base64(), + ) + .add_attribute( + "lp_forwarder_migrate", + to_json_binary(&ibc_forwarder_migrate_msg) + .unwrap() + .to_base64(), + ) + .add_attribute( + "liquid_pooler_migrate", + to_json_binary(&liquid_pooler_migrate_msg) + .unwrap() + .to_base64(), + ) + .add_attribute( + "liquid_staker_migrate", + to_json_binary(&liquid_staker_migrate_msg) + .unwrap() + .to_base64(), + ) + .add_attribute( + "splitter_migrate", + to_json_binary(&remote_chain_splitter_migrate_msg) + .unwrap() + .to_base64(), + ) + .add_attribute( + "holder_migrate", + to_json_binary(&holder_migrate_msg).unwrap().to_base64(), ), - liquid_staker: Some(liquid_staker_migrate_msg.clone()), - router: None, - }, - 2, - ) - .unwrap(); - - resp.assert_event(&Event::new("wasm") - .add_attribute("contract_codes_migrate", to_json_binary(&contract_codes).unwrap().to_base64()) - .add_attribute("ls_forwarder_migrate", to_json_binary(&ibc_forwarder_migrate_msg).unwrap().to_base64()) - .add_attribute("lp_forwarder_migrate", to_json_binary(&ibc_forwarder_migrate_msg).unwrap().to_base64()) - .add_attribute("liquid_pooler_migrate", to_json_binary(&liquid_pooler_migrate_msg).unwrap().to_base64()) - .add_attribute("liquid_staker_migrate", to_json_binary(&liquid_staker_migrate_msg).unwrap().to_base64()) - .add_attribute("splitter_migrate", to_json_binary(&remote_chain_splitter_migrate_msg).unwrap().to_base64()) - .add_attribute("holder_migrate", to_json_binary(&holder_migrate_msg).unwrap().to_base64()) ); let new_codes = suite.query_contract_codes(); @@ -1096,32 +1152,43 @@ fn test_migrate_update_config_no_codes() { let mut suite = Suite::new_with_stable_pool(); let covenant_addr = suite.covenant_addr.clone(); - let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { new_value: Uint64::new(50000) }; + let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { + new_value: Uint64::new(50000), + }; let router_migrate_msg = covenant_interchain_router::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), destination_config: None, target_denoms: None, }; - let resp = suite.app.migrate_contract( - Addr::unchecked(ADMIN), - covenant_addr, - &covenant_single_party_pol::msg::MigrateMsg::MigrateContracts { - codes: None, - clock: Some(clock_migrate_msg.clone()), - holder: None, - ls_forwarder: None, - lp_forwarder: None, - splitter: None, - liquid_pooler: None, - liquid_staker: None, - router: Some(router_migrate_msg.clone()), - }, - 2, - ) - .unwrap(); - - resp.assert_event(&Event::new("wasm") - .add_attribute("clock_migrate", to_json_binary(&clock_migrate_msg).unwrap().to_base64()) - .add_attribute("router_migrate", to_json_binary(&router_migrate_msg).unwrap().to_base64()) + let resp = suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + covenant_addr, + &covenant_single_party_pol::msg::MigrateMsg::MigrateContracts { + codes: None, + clock: Some(clock_migrate_msg.clone()), + holder: None, + ls_forwarder: None, + lp_forwarder: None, + splitter: None, + liquid_pooler: None, + liquid_staker: None, + router: Some(router_migrate_msg.clone()), + }, + 2, + ) + .unwrap(); + + resp.assert_event( + &Event::new("wasm") + .add_attribute( + "clock_migrate", + to_json_binary(&clock_migrate_msg).unwrap().to_base64(), + ) + .add_attribute( + "router_migrate", + to_json_binary(&router_migrate_msg).unwrap().to_base64(), + ), ); -} \ No newline at end of file +} diff --git a/unit-tests/src/test_single_party_holder/tests.rs b/unit-tests/src/test_single_party_holder/tests.rs index 41ce7af7..67c7721a 100644 --- a/unit-tests/src/test_single_party_holder/tests.rs +++ b/unit-tests/src/test_single_party_holder/tests.rs @@ -58,7 +58,10 @@ fn test_execute_claim_validates_pending_withdrawals() { // manually setting the storage key to true let withdraw_state_key = "\0\u{4}wasm\0Ocontract_data/cosmos1lxsjav25s55mnxkfzkmvhdkqpsnmlm9whwk8ctqawgj438kda96s54a6mlwithdraw_state".as_bytes(); - suite.app.storage_mut().set(withdraw_state_key, "true".as_bytes()); + suite + .app + .storage_mut() + .set(withdraw_state_key, "true".as_bytes()); suite.execute_claim(sender); } @@ -138,7 +141,10 @@ fn test_execute_emergency_withdraw_validates_pending_withdrawals() { // manually setting the storage key to true let withdraw_state_key = "\0\u{4}wasm\0Ocontract_data/cosmos1lxsjav25s55mnxkfzkmvhdkqpsnmlm9whwk8ctqawgj438kda96s54a6mlwithdraw_state".as_bytes(); - suite.app.storage_mut().set(withdraw_state_key, "true".as_bytes()); + suite + .app + .storage_mut() + .set(withdraw_state_key, "true".as_bytes()); suite.execute_emergency_withdraw(sender); } @@ -229,7 +235,8 @@ fn test_migrate_update_config_validates_lockup_config() { let current_block = suite.get_app().block_info().height; let past_expiration = Expiration::AtHeight(current_block - 1); - suite.app + suite + .app .migrate_contract( Addr::unchecked(ADMIN), suite.holder_addr.clone(), diff --git a/unit-tests/src/test_swap_covenant/test.rs b/unit-tests/src/test_swap_covenant/test.rs index 9783782f..5eb97175 100644 --- a/unit-tests/src/test_swap_covenant/test.rs +++ b/unit-tests/src/test_swap_covenant/test.rs @@ -2,7 +2,10 @@ use cosmwasm_std::{coin, coins, to_json_binary, Addr, Event, Uint128, Uint64}; use cw_multi_test::Executor; use crate::setup::{ - base_suite::{BaseSuite, BaseSuiteMut}, ADMIN, DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK, DENOM_FALLBACK_ON_HUB, DENOM_FALLBACK_ON_OSMO, DENOM_HUB_ON_OSMO_FROM_NTRN, DENOM_NTRN, DENOM_NTRN_ON_HUB, DENOM_OSMO, DENOM_OSMO_ON_HUB_FROM_NTRN, DENOM_OSMO_ON_NTRN + base_suite::{BaseSuite, BaseSuiteMut}, + ADMIN, DENOM_ATOM, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK, DENOM_FALLBACK_ON_HUB, + DENOM_FALLBACK_ON_OSMO, DENOM_HUB_ON_OSMO_FROM_NTRN, DENOM_NTRN, DENOM_NTRN_ON_HUB, DENOM_OSMO, + DENOM_OSMO_ON_HUB_FROM_NTRN, DENOM_OSMO_ON_NTRN, }; use super::suite::Suite; @@ -239,7 +242,7 @@ fn test_covenant_fallback_split() { &covenant_native_splitter::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, - &[coin(1000000, DENOM_NTRN)] + &[coin(1000000, DENOM_NTRN)], ) .unwrap(); @@ -252,7 +255,7 @@ fn test_covenant_fallback_split() { &covenant_native_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, - &[coin(1000000, DENOM_NTRN)] + &[coin(1000000, DENOM_NTRN)], ) .unwrap(); @@ -264,7 +267,7 @@ fn test_covenant_fallback_split() { &covenant_native_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, - &[coin(1000000, DENOM_NTRN)] + &[coin(1000000, DENOM_NTRN)], ) .unwrap(); @@ -438,7 +441,10 @@ fn test_covenant_native_refund() { let receiver_b_balance_ntrn = suite.query_balance(&suite.party_b_receiver, DENOM_NTRN); // router comes prefunded with some ntrn so we add that to the assertion - assert_eq!(receiver_b_balance_ntrn.amount.u128(), 10_000_000_u128 + init_ntrn_router_balance.amount.u128()); + assert_eq!( + receiver_b_balance_ntrn.amount.u128(), + 10_000_000_u128 + init_ntrn_router_balance.amount.u128() + ); } #[test] @@ -455,7 +461,7 @@ fn test_migrate_update_with_codes() { receiver_address: None, }; - let holder_migrate_msg = covenant_swap_holder::msg::MigrateMsg::UpdateConfig { + let holder_migrate_msg = covenant_swap_holder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), next_contract: None, lockup_config: None, @@ -470,36 +476,61 @@ fn test_migrate_update_with_codes() { splits: None, }; - let resp = suite.app.migrate_contract( - Addr::unchecked(ADMIN), - Addr::unchecked(covenant_addr), - &covenant_swap::msg::MigrateMsg::UpdateCovenant { - codes: Some(contract_codes.clone()), - clock: None, - holder: Some(holder_migrate_msg.clone()), - splitter: Some(splitter_migrate_msg.clone()), - party_a_router: Some(covenant_swap::msg::RouterMigrateMsg::Native(native_router_migrate_msg.clone())), - party_b_router: Some(covenant_swap::msg::RouterMigrateMsg::Native(native_router_migrate_msg.clone())), - party_a_forwarder: None, - party_b_forwarder: Box::new(None), - }, - 1, - ) - .unwrap(); - - resp.assert_event(&Event::new("wasm") - .add_attribute("contract_codes_migrate", to_json_binary(&contract_codes).unwrap().to_base64()) - .add_attribute("holder_migrate", to_json_binary(&holder_migrate_msg).unwrap().to_base64()) - .add_attribute("splitter_migrate", to_json_binary(&splitter_migrate_msg).unwrap().to_base64()) - .add_attribute("party_a_router_migrate", to_json_binary(&native_router_migrate_msg).unwrap().to_base64()) - .add_attribute("party_b_router_migrate", to_json_binary(&native_router_migrate_msg).unwrap().to_base64()) + let resp = suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + Addr::unchecked(covenant_addr), + &covenant_swap::msg::MigrateMsg::UpdateCovenant { + codes: Some(contract_codes.clone()), + clock: None, + holder: Some(holder_migrate_msg.clone()), + splitter: Some(splitter_migrate_msg.clone()), + party_a_router: Some(covenant_swap::msg::RouterMigrateMsg::Native( + native_router_migrate_msg.clone(), + )), + party_b_router: Some(covenant_swap::msg::RouterMigrateMsg::Native( + native_router_migrate_msg.clone(), + )), + party_a_forwarder: None, + party_b_forwarder: Box::new(None), + }, + 1, + ) + .unwrap(); + + resp.assert_event( + &Event::new("wasm") + .add_attribute( + "contract_codes_migrate", + to_json_binary(&contract_codes).unwrap().to_base64(), + ) + .add_attribute( + "holder_migrate", + to_json_binary(&holder_migrate_msg).unwrap().to_base64(), + ) + .add_attribute( + "splitter_migrate", + to_json_binary(&splitter_migrate_msg).unwrap().to_base64(), + ) + .add_attribute( + "party_a_router_migrate", + to_json_binary(&native_router_migrate_msg) + .unwrap() + .to_base64(), + ) + .add_attribute( + "party_b_router_migrate", + to_json_binary(&native_router_migrate_msg) + .unwrap() + .to_base64(), + ), ); let new_codes = suite.query_contract_codes(); assert_eq!(contract_codes, new_codes); } - #[test] fn test_migrate_update_without_codes() { let mut suite = Suite::new_with_2_interchain_configs(); @@ -518,33 +549,63 @@ fn test_migrate_update_without_codes() { transfer_amount: None, }; - let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { + let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { new_value: Uint64::new(50000), }; - let resp = suite.app.migrate_contract( - Addr::unchecked(ADMIN), - Addr::unchecked(covenant_addr), - &covenant_swap::msg::MigrateMsg::UpdateCovenant { - codes: None, - clock: Some(clock_migrate_msg.clone()), - holder: None, - splitter: None, - party_a_router: Some(covenant_swap::msg::RouterMigrateMsg::Interchain(interchain_router_migrate_msg.clone())), - party_b_router: Some(covenant_swap::msg::RouterMigrateMsg::Interchain(interchain_router_migrate_msg.clone())), - party_a_forwarder: Some(ibc_forwarder_migrate_msg.clone()), - party_b_forwarder: Box::new(Some(ibc_forwarder_migrate_msg.clone())), - }, - 1, - ) - .unwrap(); - - resp.assert_event(&Event::new("wasm") - .add_attribute("clock_migrate", to_json_binary(&clock_migrate_msg).unwrap().to_base64()) - .add_attribute("party_a_router_migrate", to_json_binary(&interchain_router_migrate_msg).unwrap().to_base64()) - .add_attribute("party_b_router_migrate", to_json_binary(&interchain_router_migrate_msg).unwrap().to_base64()) - .add_attribute("party_a_forwarder_migrate", to_json_binary(&ibc_forwarder_migrate_msg).unwrap().to_base64()) - .add_attribute("party_b_forwarder_migrate", to_json_binary(&ibc_forwarder_migrate_msg).unwrap().to_base64()) + let resp = suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + Addr::unchecked(covenant_addr), + &covenant_swap::msg::MigrateMsg::UpdateCovenant { + codes: None, + clock: Some(clock_migrate_msg.clone()), + holder: None, + splitter: None, + party_a_router: Some(covenant_swap::msg::RouterMigrateMsg::Interchain( + interchain_router_migrate_msg.clone(), + )), + party_b_router: Some(covenant_swap::msg::RouterMigrateMsg::Interchain( + interchain_router_migrate_msg.clone(), + )), + party_a_forwarder: Some(ibc_forwarder_migrate_msg.clone()), + party_b_forwarder: Box::new(Some(ibc_forwarder_migrate_msg.clone())), + }, + 1, + ) + .unwrap(); + + resp.assert_event( + &Event::new("wasm") + .add_attribute( + "clock_migrate", + to_json_binary(&clock_migrate_msg).unwrap().to_base64(), + ) + .add_attribute( + "party_a_router_migrate", + to_json_binary(&interchain_router_migrate_msg) + .unwrap() + .to_base64(), + ) + .add_attribute( + "party_b_router_migrate", + to_json_binary(&interchain_router_migrate_msg) + .unwrap() + .to_base64(), + ) + .add_attribute( + "party_a_forwarder_migrate", + to_json_binary(&ibc_forwarder_migrate_msg) + .unwrap() + .to_base64(), + ) + .add_attribute( + "party_b_forwarder_migrate", + to_json_binary(&ibc_forwarder_migrate_msg) + .unwrap() + .to_base64(), + ), ); } diff --git a/unit-tests/src/test_swap_holder/suite.rs b/unit-tests/src/test_swap_holder/suite.rs index 0f76b036..41607eb0 100644 --- a/unit-tests/src/test_swap_holder/suite.rs +++ b/unit-tests/src/test_swap_holder/suite.rs @@ -1,9 +1,14 @@ -use std::{collections::{BTreeMap, BTreeSet}, str::FromStr}; +use std::{ + collections::{BTreeMap, BTreeSet}, + str::FromStr, +}; use crate::setup::{ - base_suite::{BaseSuite, BaseSuiteMut}, instantiates::swap_holder::SwapHolderInstantiate, - suite_builder::SuiteBuilder, CustomApp, CLOCK_SALT, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, - NATIVE_SPLITTER_SALT, SWAP_HOLDER_SALT, + base_suite::{BaseSuite, BaseSuiteMut}, + instantiates::swap_holder::SwapHolderInstantiate, + suite_builder::SuiteBuilder, + CustomApp, CLOCK_SALT, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, NATIVE_SPLITTER_SALT, + SWAP_HOLDER_SALT, }; use cosmwasm_std::{Addr, Decimal}; use covenant_swap_holder::msg::RefundConfig; @@ -27,8 +32,10 @@ impl Default for SwapHolderBuilder { let party_a_controller_addr = builder.get_random_addr(); let party_b_controller_addr = builder.get_random_addr(); - let party_a_router_addr = builder.get_contract_addr(builder.native_router_code_id, "party_a"); - let party_b_router_addr = builder.get_contract_addr(builder.native_router_code_id, "party_b"); + let party_a_router_addr = + builder.get_contract_addr(builder.native_router_code_id, "party_a"); + let party_b_router_addr = + builder.get_contract_addr(builder.native_router_code_id, "party_b"); let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { tick_max_gas: None, @@ -45,7 +52,10 @@ impl Default for SwapHolderBuilder { &clock_instantiate_msg, &[], ); - let denom_set = BTreeSet::from_iter(vec![DENOM_ATOM_ON_NTRN.to_string(), DENOM_LS_ATOM_ON_NTRN.to_string()]); + let denom_set = BTreeSet::from_iter(vec![ + DENOM_ATOM_ON_NTRN.to_string(), + DENOM_LS_ATOM_ON_NTRN.to_string(), + ]); builder.contract_init2( builder.native_router_code_id, "party_a", @@ -213,7 +223,7 @@ impl SwapHolderBuilder { impl Suite { pub fn expire_lockup_config(&mut self) { - let lockup_config = self.lockup_config.clone(); + let lockup_config = self.lockup_config; let app = self.get_app(); match lockup_config { Expiration::AtHeight(h) => app.update_block(|b| b.height = h), diff --git a/unit-tests/src/test_swap_holder/tests.rs b/unit-tests/src/test_swap_holder/tests.rs index c13c7899..ff67a644 100644 --- a/unit-tests/src/test_swap_holder/tests.rs +++ b/unit-tests/src/test_swap_holder/tests.rs @@ -4,7 +4,10 @@ use covenant_utils::{CovenantTerms, SwapCovenantTerms}; use cw_multi_test::Executor; use cw_utils::Expiration; -use crate::setup::{base_suite::{BaseSuite, BaseSuiteMut}, ADMIN, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN}; +use crate::setup::{ + base_suite::{BaseSuite, BaseSuiteMut}, + ADMIN, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, +}; use super::suite::SwapHolderBuilder; @@ -36,7 +39,11 @@ fn test_instantiate_validates_lockup_config() { #[should_panic] fn test_instantiate_validates_party_a_refund_addr() { let mut builder = SwapHolderBuilder::default(); - builder.instantiate_msg.msg.refund_config.party_a_refund_address = "invalid".to_string(); + builder + .instantiate_msg + .msg + .refund_config + .party_a_refund_address = "invalid".to_string(); builder.build(); } @@ -44,7 +51,11 @@ fn test_instantiate_validates_party_a_refund_addr() { #[should_panic] fn test_instantiate_validates_party_b_refund_addr() { let mut builder = SwapHolderBuilder::default(); - builder.instantiate_msg.msg.refund_config.party_b_refund_address = "invalid".to_string(); + builder + .instantiate_msg + .msg + .refund_config + .party_b_refund_address = "invalid".to_string(); builder.build(); } @@ -53,13 +64,15 @@ fn test_instantiate_validates_party_b_refund_addr() { fn test_execute_tick_validates_clock() { let mut suite = SwapHolderBuilder::default().build(); - suite.app.execute_contract( - suite.admin, - suite.holder.clone(), - &covenant_swap_holder::msg::ExecuteMsg::Tick {}, - &[], - ) - .unwrap(); + suite + .app + .execute_contract( + suite.admin, + suite.holder.clone(), + &covenant_swap_holder::msg::ExecuteMsg::Tick {}, + &[], + ) + .unwrap(); } #[test] @@ -70,7 +83,7 @@ fn test_execute_tick_instantiated_expires() { suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Expired{})); + assert!(matches!(contract_state, ContractState::Expired {})); } #[test] @@ -102,7 +115,7 @@ fn test_execute_tick_instantiated_forwards_and_completes() { suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Complete{})); + assert!(matches!(contract_state, ContractState::Complete {})); } #[test] @@ -112,14 +125,13 @@ fn test_execute_expired_refund_both_parties() { suite.fund_contract(&coins(10_000, DENOM_ATOM_ON_NTRN), suite.holder.clone()); suite.fund_contract(&coins(10_000, DENOM_LS_ATOM_ON_NTRN), suite.holder.clone()); - suite.assert_balance(suite.holder.clone(), coin(10_000, DENOM_ATOM_ON_NTRN)); suite.assert_balance(suite.holder.clone(), coin(10_000, DENOM_LS_ATOM_ON_NTRN)); suite.expire_lockup_config(); suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Expired{})); + assert!(matches!(contract_state, ContractState::Expired {})); suite.tick_contract(suite.holder.clone()); suite.assert_balance(suite.holder.clone(), coin(0, DENOM_ATOM_ON_NTRN)); @@ -127,14 +139,19 @@ fn test_execute_expired_refund_both_parties() { suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Complete{})); + assert!(matches!(contract_state, ContractState::Complete {})); let refund_config = suite.query_refund_config(); - suite.assert_balance(refund_config.party_a_refund_address, coin(10_000, DENOM_ATOM_ON_NTRN)); - suite.assert_balance(refund_config.party_b_refund_address, coin(10_000, DENOM_LS_ATOM_ON_NTRN)); + suite.assert_balance( + refund_config.party_a_refund_address, + coin(10_000, DENOM_ATOM_ON_NTRN), + ); + suite.assert_balance( + refund_config.party_b_refund_address, + coin(10_000, DENOM_LS_ATOM_ON_NTRN), + ); } - #[test] fn test_execute_expired_refund_party_a() { let mut suite = SwapHolderBuilder::default().build(); @@ -145,20 +162,22 @@ fn test_execute_expired_refund_party_a() { suite.expire_lockup_config(); suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Expired{})); + assert!(matches!(contract_state, ContractState::Expired {})); suite.tick_contract(suite.holder.clone()); suite.assert_balance(suite.holder.clone(), coin(0, DENOM_ATOM_ON_NTRN)); suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Complete{})); + assert!(matches!(contract_state, ContractState::Complete {})); let refund_config = suite.query_refund_config(); - suite.assert_balance(refund_config.party_a_refund_address, coin(10_000, DENOM_ATOM_ON_NTRN)); + suite.assert_balance( + refund_config.party_a_refund_address, + coin(10_000, DENOM_ATOM_ON_NTRN), + ); } - #[test] fn test_execute_expired_refund_party_b() { let mut suite = SwapHolderBuilder::default().build(); @@ -169,20 +188,22 @@ fn test_execute_expired_refund_party_b() { suite.expire_lockup_config(); suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Expired{})); + assert!(matches!(contract_state, ContractState::Expired {})); suite.tick_contract(suite.holder.clone()); suite.assert_balance(suite.holder.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN)); suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Complete{})); + assert!(matches!(contract_state, ContractState::Complete {})); let refund_config = suite.query_refund_config(); - suite.assert_balance(refund_config.party_b_refund_address, coin(10_000, DENOM_LS_ATOM_ON_NTRN)); + suite.assert_balance( + refund_config.party_b_refund_address, + coin(10_000, DENOM_LS_ATOM_ON_NTRN), + ); } - #[test] fn test_execute_expired_no_refund_completes() { let mut suite = SwapHolderBuilder::default().build(); @@ -192,7 +213,7 @@ fn test_execute_expired_no_refund_completes() { suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Complete{})); + assert!(matches!(contract_state, ContractState::Complete {})); } #[test] @@ -204,11 +225,11 @@ fn test_execute_tick_on_complete_noop() { suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Complete{})); + assert!(matches!(contract_state, ContractState::Complete {})); - suite.tick_contract(suite.holder.clone()).assert_event( - &Event::new("wasm").add_attribute("contract_state", "completed") - ); + suite + .tick_contract(suite.holder.clone()) + .assert_event(&Event::new("wasm").add_attribute("contract_state", "completed")); } #[test] @@ -229,55 +250,62 @@ fn test_migrate_update_config() { party_a_refund_address: clock_address.to_string(), party_b_refund_address: clock_address.to_string(), }; - let resp = suite.app.migrate_contract( - Addr::unchecked(ADMIN), - suite.holder.clone(), - &covenant_swap_holder::msg::MigrateMsg::UpdateConfig { - clock_addr: Some(next_contract.to_string()), - next_contract: Some(clock_address.to_string()), - lockup_config: Some(new_expiration.clone()), - parites_config: Box::new(Some(parties_config.clone())), - covenant_terms: Some(new_covenant_terms.clone()), - refund_config: Some(new_refund_config.clone()) - }, - 4, - ) - .unwrap(); - - resp.assert_event(&Event::new("wasm") - .add_attribute("clock_addr", next_contract.to_string()) - .add_attribute("next_contract", clock_address.to_string()) - .add_attribute("lockup_config", new_expiration.to_string()) - .add_attribute("parites_config", format!("{parties_config:?}")) - .add_attribute("covenant_terms", format!("{new_covenant_terms:?}")) - .add_attribute("refund_config", format!("{new_refund_config:?}")) + let resp = suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + suite.holder.clone(), + &covenant_swap_holder::msg::MigrateMsg::UpdateConfig { + clock_addr: Some(next_contract.to_string()), + next_contract: Some(clock_address.to_string()), + lockup_config: Some(new_expiration), + parites_config: Box::new(Some(parties_config.clone())), + covenant_terms: Some(new_covenant_terms.clone()), + refund_config: Some(new_refund_config.clone()), + }, + 4, + ) + .unwrap(); + + resp.assert_event( + &Event::new("wasm") + .add_attribute("clock_addr", next_contract.to_string()) + .add_attribute("next_contract", clock_address.to_string()) + .add_attribute("lockup_config", new_expiration.to_string()) + .add_attribute("parites_config", format!("{parties_config:?}")) + .add_attribute("covenant_terms", format!("{new_covenant_terms:?}")) + .add_attribute("refund_config", format!("{new_refund_config:?}")), ); assert_eq!(suite.query_clock_address(), next_contract); assert_eq!(suite.query_next_contract(), clock_address); - assert_eq!(suite.query_contract_state(), ContractState::Instantiated{}); - assert_eq!(suite.query_covenant_parties_config().party_a.native_denom, "new_native_denom"); + assert_eq!(suite.query_contract_state(), ContractState::Instantiated {}); + assert_eq!( + suite.query_covenant_parties_config().party_a.native_denom, + "new_native_denom" + ); assert_eq!(suite.query_covenant_terms(), new_covenant_terms); assert_eq!(suite.query_refund_config(), new_refund_config); } - #[test] #[should_panic(expected = "lockup config is already past")] fn test_migrate_update_config_validates_lockup_config_expiration() { let mut suite = SwapHolderBuilder::default().build(); - suite.app.migrate_contract( - Addr::unchecked(ADMIN), - suite.holder.clone(), - &covenant_swap_holder::msg::MigrateMsg::UpdateConfig { - clock_addr: None, - next_contract: None, - lockup_config: Some(Expiration::AtHeight(1)), - parites_config: Box::new(None), - covenant_terms: None, - refund_config: None, - }, - 4, - ) - .unwrap(); -} \ No newline at end of file + suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + suite.holder.clone(), + &covenant_swap_holder::msg::MigrateMsg::UpdateConfig { + clock_addr: None, + next_contract: None, + lockup_config: Some(Expiration::AtHeight(1)), + parites_config: Box::new(None), + covenant_terms: None, + refund_config: None, + }, + 4, + ) + .unwrap(); +} diff --git a/unit-tests/src/test_two_party_covenant/suite.rs b/unit-tests/src/test_two_party_covenant/suite.rs index 15d5953b..10cff6c7 100644 --- a/unit-tests/src/test_two_party_covenant/suite.rs +++ b/unit-tests/src/test_two_party_covenant/suite.rs @@ -10,8 +10,7 @@ use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, instantiates::two_party_covenant::TwoPartyCovenantInstantiate, suite_builder::SuiteBuilder, - CustomApp, ADMIN, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, - TWO_PARTY_COVENANT_SALT, + CustomApp, ADMIN, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, TWO_PARTY_COVENANT_SALT, }; pub struct TwoPartyCovenantBuilder { diff --git a/unit-tests/src/test_two_party_pol_holder/tests.rs b/unit-tests/src/test_two_party_pol_holder/tests.rs index afdb92ff..cd22c7b7 100644 --- a/unit-tests/src/test_two_party_pol_holder/tests.rs +++ b/unit-tests/src/test_two_party_pol_holder/tests.rs @@ -7,7 +7,8 @@ use cw_multi_test::Executor; use cw_utils::Expiration; use crate::setup::{ - base_suite::{BaseSuite, BaseSuiteMut}, ADMIN, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK, DENOM_LS_ATOM_ON_NTRN + base_suite::{BaseSuite, BaseSuiteMut}, + ADMIN, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK, DENOM_LS_ATOM_ON_NTRN, }; use super::suite::TwoPartyHolderBuilder; @@ -56,7 +57,13 @@ fn test_instantiate_validates_lockup_config() { #[should_panic(expected = "Party contribution cannot be zero")] fn test_instantiate_validates_party_a_contribution_amount() { let mut builder = TwoPartyHolderBuilder::default(); - builder.instantiate_msg.msg.covenant_config.party_a.contribution.amount = Uint128::zero(); + builder + .instantiate_msg + .msg + .covenant_config + .party_a + .contribution + .amount = Uint128::zero(); builder.build(); } @@ -64,7 +71,13 @@ fn test_instantiate_validates_party_a_contribution_amount() { #[should_panic(expected = "Party contribution cannot be zero")] fn test_instantiate_validates_party_b_contribution_amount() { let mut builder = TwoPartyHolderBuilder::default(); - builder.instantiate_msg.msg.covenant_config.party_b.contribution.amount = Uint128::zero(); + builder + .instantiate_msg + .msg + .covenant_config + .party_b + .contribution + .amount = Uint128::zero(); builder.build(); } @@ -72,7 +85,12 @@ fn test_instantiate_validates_party_b_contribution_amount() { #[should_panic] fn test_instantiate_validates_party_a_host_addr() { let mut builder = TwoPartyHolderBuilder::default(); - builder.instantiate_msg.msg.covenant_config.party_a.host_addr = "invalid".to_string(); + builder + .instantiate_msg + .msg + .covenant_config + .party_a + .host_addr = "invalid".to_string(); builder.build(); } @@ -80,7 +98,12 @@ fn test_instantiate_validates_party_a_host_addr() { #[should_panic] fn test_instantiate_validates_party_b_host_addr() { let mut builder = TwoPartyHolderBuilder::default(); - builder.instantiate_msg.msg.covenant_config.party_b.host_addr = "invalid".to_string(); + builder + .instantiate_msg + .msg + .covenant_config + .party_b + .host_addr = "invalid".to_string(); builder.build(); } @@ -233,7 +256,7 @@ fn test_execute_tick_expired_deposit_refunds_both_parties() { suite.expire_deposit_deadline(); suite.fund_contract( - &vec![ + &[ coin(10_000, DENOM_ATOM_ON_NTRN), coin(10_000, DENOM_LS_ATOM_ON_NTRN), ], @@ -254,7 +277,10 @@ fn test_execute_tick_expired_deposit_refunds_both_parties() { coin(10_000, DENOM_LS_ATOM_ON_NTRN), ); - assert!(matches!(suite.query_contract_state(), ContractState::Complete {})); + assert!(matches!( + suite.query_contract_state(), + ContractState::Complete {} + )); } #[test] @@ -263,7 +289,7 @@ fn test_execute_tick_expired_deposit_refunds_party_a() { suite.expire_deposit_deadline(); suite.fund_contract( - &vec![coin(10_000, DENOM_ATOM_ON_NTRN)], + &[coin(10_000, DENOM_ATOM_ON_NTRN)], suite.holder_addr.clone(), ); @@ -277,7 +303,10 @@ fn test_execute_tick_expired_deposit_refunds_party_a() { coin(10_000, DENOM_ATOM_ON_NTRN), ); suite.assert_balance(suite.holder_addr.clone(), coin(0, DENOM_ATOM_ON_NTRN)); - assert!(matches!(suite.query_contract_state(), ContractState::Complete {})); + assert!(matches!( + suite.query_contract_state(), + ContractState::Complete {} + )); } #[test] @@ -286,7 +315,7 @@ fn test_execute_tick_expired_deposit_refunds_party_b() { suite.app.update_block(|b| b.height = 200000); suite.fund_contract( - &vec![coin(10_000, DENOM_LS_ATOM_ON_NTRN)], + &[coin(10_000, DENOM_LS_ATOM_ON_NTRN)], suite.holder_addr.clone(), ); @@ -299,8 +328,11 @@ fn test_execute_tick_expired_deposit_refunds_party_b() { &suite.covenant_config.party_b.router, coin(10_000, DENOM_LS_ATOM_ON_NTRN), ); - suite.assert_balance(&suite.holder_addr.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN)); - assert!(matches!(suite.query_contract_state(), ContractState::Complete {})); + suite.assert_balance(suite.holder_addr.clone(), coin(0, DENOM_LS_ATOM_ON_NTRN)); + assert!(matches!( + suite.query_contract_state(), + ContractState::Complete {} + )); } #[test] @@ -312,7 +344,10 @@ fn test_execute_tick_expired_deposit_completes() { .add_attribute("method", "try_deposit") .add_attribute("state", "complete"), ); - assert!(matches!(suite.query_contract_state(), ContractState::Complete {})); + assert!(matches!( + suite.query_contract_state(), + ContractState::Complete {} + )); } #[test] @@ -321,7 +356,7 @@ fn test_execute_tick_deposit_validates_insufficient_deposits() { let mut suite = TwoPartyHolderBuilder::default().build(); suite.fund_contract( - &vec![ + &[ coin(10_000, DENOM_ATOM_ON_NTRN), coin(5_000, DENOM_LS_ATOM_ON_NTRN), ], @@ -334,7 +369,7 @@ fn test_execute_tick_deposit_validates_insufficient_deposits() { fn test_execute_tick_expired_noop() { let mut suite = TwoPartyHolderBuilder::default().build(); suite.fund_contract( - &vec![ + &[ coin(10_000, DENOM_ATOM_ON_NTRN), coin(10_000, DENOM_LS_ATOM_ON_NTRN), ], @@ -367,7 +402,7 @@ fn test_execute_tick_ragequit_noop() { )) .build(); suite.fund_contract( - &vec![ + &[ coin(10_000, DENOM_ATOM_ON_NTRN), coin(10_000, DENOM_LS_ATOM_ON_NTRN), ], @@ -395,7 +430,7 @@ fn test_execute_tick_ragequit_noop() { fn test_execute_ragequit_validates_ragequit_config() { let mut suite = TwoPartyHolderBuilder::default().build(); suite.fund_contract( - &vec![ + &[ coin(10_000, DENOM_ATOM_ON_NTRN), coin(10_000, DENOM_LS_ATOM_ON_NTRN), ], @@ -442,7 +477,7 @@ fn test_execute_ragequit_validates_lockup_config_expiration() { )) .build(); suite.fund_contract( - &vec![ + &[ coin(10_000, DENOM_ATOM_ON_NTRN), coin(10_000, DENOM_LS_ATOM_ON_NTRN), ], @@ -469,7 +504,7 @@ fn test_execute_ragequit_validates_sender() { )) .build(); suite.fund_contract( - &vec![ + &[ coin(10_000, DENOM_ATOM_ON_NTRN), coin(10_000, DENOM_LS_ATOM_ON_NTRN), ], @@ -480,7 +515,7 @@ fn test_execute_ragequit_validates_sender() { assert_eq!(suite.query_contract_state(), ContractState::Active {}); - suite.ragequit(&suite.faucet.to_string()); + suite.ragequit(suite.faucet.clone().as_ref()); } #[test] @@ -511,7 +546,7 @@ fn test_execute_claim_with_null_allocation() { )) .build(); suite.fund_contract( - &vec![ + &[ coin(10_000, DENOM_ATOM_ON_NTRN), coin(10_000, DENOM_LS_ATOM_ON_NTRN), ], @@ -533,7 +568,7 @@ fn test_execute_claim_with_null_allocation() { fn test_execute_claim_validates_claim_state() { let mut suite = TwoPartyHolderBuilder::default().build(); suite.fund_contract( - &vec![ + &[ coin(10_000, DENOM_ATOM_ON_NTRN), coin(10_000, DENOM_LS_ATOM_ON_NTRN), ], @@ -548,7 +583,7 @@ fn test_execute_claim_validates_claim_state() { fn test_execute_claim_happy() { let mut suite = TwoPartyHolderBuilder::default().build(); suite.fund_contract( - &vec![ + &[ coin(10_001, DENOM_ATOM_ON_NTRN), coin(10_001, DENOM_LS_ATOM_ON_NTRN), ], @@ -586,7 +621,7 @@ fn test_execute_emergency_withdraw_validates_committee_address() { let mut suite = builder.with_emergency_committee(clock.as_str()).build(); suite.fund_contract( - &vec![ + &[ coin(10_001, DENOM_ATOM_ON_NTRN), coin(10_001, DENOM_LS_ATOM_ON_NTRN), ], @@ -607,7 +642,7 @@ fn test_execute_emergency_withdraw_happy() { let mut suite = builder.with_emergency_committee(clock.as_str()).build(); suite.fund_contract( - &vec![ + &[ coin(10_001, DENOM_ATOM_ON_NTRN), coin(10_001, DENOM_LS_ATOM_ON_NTRN), ], @@ -630,7 +665,10 @@ fn test_execute_emergency_withdraw_happy() { assert_eq!(5000, party_b_atom_bal.u128()); assert_eq!(5000, party_a_ls_atom_bal.u128()); assert_eq!(5000, party_b_ls_atom_bal.u128()); - assert!(matches!(suite.query_contract_state(), ContractState::Complete{})); + assert!(matches!( + suite.query_contract_state(), + ContractState::Complete {} + )); } #[test] @@ -650,15 +688,29 @@ fn test_distribute_fallback_with_no_fallback_split_noop_happy() { suite.distribute_fallback_split(&sender, vec![DENOM_FALLBACK.to_string()]); - suite.assert_balance(suite.holder_addr.to_string(), coin(1_000_000, DENOM_FALLBACK)); + suite.assert_balance( + suite.holder_addr.to_string(), + coin(1_000_000, DENOM_FALLBACK), + ); } - #[test] fn test_distribute_fallback_happy() { let mut builder = TwoPartyHolderBuilder::default(); - let router_a_addr = builder.instantiate_msg.msg.covenant_config.party_a.router.to_string(); - let router_b_addr = builder.instantiate_msg.msg.covenant_config.party_b.router.to_string(); + let router_a_addr = builder + .instantiate_msg + .msg + .covenant_config + .party_a + .router + .to_string(); + let router_b_addr = builder + .instantiate_msg + .msg + .covenant_config + .party_b + .router + .to_string(); builder.instantiate_msg.msg.fallback_split = Some(SplitConfig { receivers: vec![ (router_a_addr.to_string(), Decimal::percent(50)), @@ -773,9 +825,7 @@ fn test_migrate_update_config_invalid_fallback_split() { ragequit_config: Box::new(None), covenant_config: Box::new(None), denom_splits: None, - fallback_split: Some(SplitConfig { - receivers - }), + fallback_split: Some(SplitConfig { receivers }), }, 13, ) @@ -787,9 +837,7 @@ fn test_migrate_update_config_invalid_fallback_split() { fn test_migrate_update_config_invalid_explicit_splits() { let mut suite = TwoPartyHolderBuilder::default().build(); - let mut explicit_splits = suite.query_denom_splits() - .explicit_splits - .clone(); + let mut explicit_splits = suite.query_denom_splits().explicit_splits.clone(); let mut receivers = explicit_splits .get(DENOM_ATOM_ON_NTRN) @@ -828,44 +876,48 @@ fn test_migrate_update_config_invalid_explicit_splits() { #[should_panic(expected = "lockup config is already past")] fn test_migrate_update_config_validates_lockup_config_expiration() { let mut suite = TwoPartyHolderBuilder::default().build(); - suite.app.migrate_contract( - Addr::unchecked(ADMIN), - suite.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { - clock_addr: None, - next_contract: None, - emergency_committee: None, - lockup_config: Some(Expiration::AtHeight(1)), - deposit_deadline: None, - ragequit_config: Box::new(None), - covenant_config: Box::new(None), - denom_splits: None, - fallback_split: None, - }, - 13, - ) - .unwrap(); + suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + suite.holder_addr.clone(), + &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + clock_addr: None, + next_contract: None, + emergency_committee: None, + lockup_config: Some(Expiration::AtHeight(1)), + deposit_deadline: None, + ragequit_config: Box::new(None), + covenant_config: Box::new(None), + denom_splits: None, + fallback_split: None, + }, + 13, + ) + .unwrap(); } #[test] #[should_panic(expected = "deposit deadline is already past")] fn test_migrate_update_config_validates_deposit_deadline_expiration() { let mut suite = TwoPartyHolderBuilder::default().build(); - suite.app.migrate_contract( - Addr::unchecked(ADMIN), - suite.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { - clock_addr: None, - next_contract: None, - emergency_committee: None, - lockup_config: None, - deposit_deadline: Some(Expiration::AtHeight(1)), - ragequit_config: Box::new(None), - covenant_config: Box::new(None), - denom_splits: None, - fallback_split: None, - }, - 13, - ) - .unwrap(); -} \ No newline at end of file + suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + suite.holder_addr.clone(), + &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + clock_addr: None, + next_contract: None, + emergency_committee: None, + lockup_config: None, + deposit_deadline: Some(Expiration::AtHeight(1)), + ragequit_config: Box::new(None), + covenant_config: Box::new(None), + denom_splits: None, + fallback_split: None, + }, + 13, + ) + .unwrap(); +} From 18c66e2185dcec3f6ea05f6e4d4d7feac5fc1472 Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 18 Mar 2024 15:44:15 +0100 Subject: [PATCH 29/56] removing remote chain splitter complete state; clearing INTERCHAIN_ACCOUNTS storage on sudo timeout --- contracts/remote-chain-splitter/README.md | 3 ++- contracts/remote-chain-splitter/src/contract.rs | 3 --- contracts/remote-chain-splitter/src/msg.rs | 15 +-------------- contracts/remote-chain-splitter/src/sudo.rs | 1 + 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/contracts/remote-chain-splitter/README.md b/contracts/remote-chain-splitter/README.md index 1e067670..70ce8d4f 100644 --- a/contracts/remote-chain-splitter/README.md +++ b/contracts/remote-chain-splitter/README.md @@ -8,5 +8,6 @@ Once the ICA address is known, splitter waits for the funds to arrive. During instantiation, a vector of forwarder modules along with their respective amounts (`Vec`) are specified. The forwarder modules are then queried for their deposit addresses, which are going to be their respective ICA addresses. -A combined `BankSend` is then performed to the ICAs on the same remote chain. If it suceeds, native splitter completes. +A combined `BankSend` is then performed to the ICAs on the same remote chain. +Remote chain splitter does not complete. In the future, it will be up to the top level covenant to dequeue it from the clock. diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index 3eb35fd9..6c019415 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -102,9 +102,6 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult try_register_ica(deps, env), ContractState::IcaCreated => try_split_funds(deps, env), - ContractState::Completed => { - Ok(Response::default().add_attribute("contract_state", "completed")) - } } } diff --git a/contracts/remote-chain-splitter/src/msg.rs b/contracts/remote-chain-splitter/src/msg.rs index 93445a26..2de9ea7d 100644 --- a/contracts/remote-chain-splitter/src/msg.rs +++ b/contracts/remote-chain-splitter/src/msg.rs @@ -1,10 +1,7 @@ use std::collections::BTreeMap; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{ - to_json_binary, Addr, Binary, DepsMut, StdError, StdResult, Uint128, Uint64, WasmMsg, -}; -use covenant_clock::helpers::dequeue_msg; +use cosmwasm_std::{to_json_binary, Addr, Binary, StdResult, Uint128, Uint64, WasmMsg}; use covenant_macros::{ clocked, covenant_clock_address, covenant_deposit_address, covenant_ica_address, covenant_remote_chain, @@ -14,8 +11,6 @@ use covenant_utils::{ instantiate2_helper::Instantiate2HelperConfig, neutron::RemoteChainInfo, split::SplitConfig, }; -use crate::state::CONTRACT_STATE; - #[cw_serde] pub struct InstantiateMsg { /// Address for the clock. This contract verifies @@ -84,14 +79,6 @@ pub enum QueryMsg { pub enum ContractState { Instantiated, IcaCreated, - Completed, -} - -impl ContractState { - pub fn complete_and_dequeue(deps: DepsMut, clock_addr: &str) -> Result { - CONTRACT_STATE.save(deps.storage, &ContractState::Completed)?; - dequeue_msg(clock_addr) - } } #[cw_serde] diff --git a/contracts/remote-chain-splitter/src/sudo.rs b/contracts/remote-chain-splitter/src/sudo.rs index 049b7b2d..f415bb4f 100644 --- a/contracts/remote-chain-splitter/src/sudo.rs +++ b/contracts/remote-chain-splitter/src/sudo.rs @@ -72,6 +72,7 @@ pub fn sudo_timeout( ) -> StdResult> { // revert the state to Instantiated to force re-creation of ICA CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; + INTERCHAIN_ACCOUNTS.clear(deps.storage); // returning Ok as this is anticipated. channel is already closed. Ok(Response::default()) From a1452af0196371028a8569b7e315b61c389650ad Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 18 Mar 2024 15:51:31 +0100 Subject: [PATCH 30/56] removing ibc forwarder complete state --- contracts/ibc-forwarder/src/contract.rs | 3 --- contracts/ibc-forwarder/src/msg.rs | 16 +--------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/contracts/ibc-forwarder/src/contract.rs b/contracts/ibc-forwarder/src/contract.rs index c6bfb14d..fa176640 100644 --- a/contracts/ibc-forwarder/src/contract.rs +++ b/contracts/ibc-forwarder/src/contract.rs @@ -92,9 +92,6 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult try_register_ica(deps, env), ContractState::IcaCreated => try_forward_funds(env, deps), - ContractState::Complete => { - Ok(Response::default().add_attribute("contract_state", "completed")) - } } } diff --git a/contracts/ibc-forwarder/src/msg.rs b/contracts/ibc-forwarder/src/msg.rs index dfd3287c..ec695729 100644 --- a/contracts/ibc-forwarder/src/msg.rs +++ b/contracts/ibc-forwarder/src/msg.rs @@ -1,16 +1,11 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{ - to_json_binary, Addr, Attribute, Binary, DepsMut, StdError, StdResult, Uint128, Uint64, WasmMsg, -}; -use covenant_clock::helpers::dequeue_msg; +use cosmwasm_std::{to_json_binary, Addr, Attribute, Binary, StdResult, Uint128, Uint64, WasmMsg}; use covenant_macros::{ clocked, covenant_clock_address, covenant_deposit_address, covenant_ica_address, covenant_remote_chain, }; use covenant_utils::{instantiate2_helper::Instantiate2HelperConfig, neutron::RemoteChainInfo}; -use crate::state::CONTRACT_STATE; - #[cw_serde] pub struct InstantiateMsg { /// address for the clock. this contract verifies @@ -111,15 +106,6 @@ pub enum ContractState { Instantiated, /// ICA was created, funds are ready to be forwarded IcaCreated, - /// forwarder is complete - Complete, -} - -impl ContractState { - pub fn complete_and_dequeue(deps: DepsMut, clock_addr: &str) -> Result { - CONTRACT_STATE.save(deps.storage, &ContractState::Complete)?; - dequeue_msg(clock_addr) - } } /// SudoPayload is a type that stores information about a transaction that we try to execute From 1a5236760a35fe83afe8a6f2ad199b90c6e04d2a Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 18 Mar 2024 16:11:39 +0100 Subject: [PATCH 31/56] removing dead code --- contracts/osmo-liquid-pooler/src/contract.rs | 1 - .../src/polytone_handlers.rs | 69 +------------------ contracts/two-party-pol-holder/src/msg.rs | 19 ----- 3 files changed, 1 insertion(+), 88 deletions(-) diff --git a/contracts/osmo-liquid-pooler/src/contract.rs b/contracts/osmo-liquid-pooler/src/contract.rs index 60574f16..dfc9b281 100644 --- a/contracts/osmo-liquid-pooler/src/contract.rs +++ b/contracts/osmo-liquid-pooler/src/contract.rs @@ -49,7 +49,6 @@ pub(crate) const PROVIDE_LIQUIDITY_CALLBACK_ID: u8 = 1; pub(crate) const PROXY_BALANCES_QUERY_CALLBACK_ID: u8 = 2; pub(crate) const CREATE_PROXY_CALLBACK_ID: u8 = 3; pub(crate) const WITHDRAW_LIQUIDITY_CALLBACK_ID: u8 = 4; -pub(crate) const WITHDRAW_LIQUIDITY_BALANCES_QUERY_CALLBACK_ID: u8 = 5; type ExecuteDeps<'a> = cosmwasm_std::DepsMut<'a, NeutronQuery>; type QueryDeps<'a> = cosmwasm_std::Deps<'a, NeutronQuery>; diff --git a/contracts/osmo-liquid-pooler/src/polytone_handlers.rs b/contracts/osmo-liquid-pooler/src/polytone_handlers.rs index d8dec9f4..412576a8 100644 --- a/contracts/osmo-liquid-pooler/src/polytone_handlers.rs +++ b/contracts/osmo-liquid-pooler/src/polytone_handlers.rs @@ -20,7 +20,7 @@ use osmosis_std::types::cosmos::bank::v1beta1::QueryBalanceResponse; use crate::{ contract::{ CREATE_PROXY_CALLBACK_ID, PROVIDE_LIQUIDITY_CALLBACK_ID, PROXY_BALANCES_QUERY_CALLBACK_ID, - WITHDRAW_LIQUIDITY_BALANCES_QUERY_CALLBACK_ID, WITHDRAW_LIQUIDITY_CALLBACK_ID, + WITHDRAW_LIQUIDITY_CALLBACK_ID, }, error::ContractError, msg::{ContractState, IbcConfig, LiquidityProvisionConfig}, @@ -72,9 +72,6 @@ fn process_query_callback( PROXY_BALANCES_QUERY_CALLBACK_ID => { handle_proxy_balances_callback(deps, env, query_callback_result) } - WITHDRAW_LIQUIDITY_BALANCES_QUERY_CALLBACK_ID => { - handle_withdraw_liquidity_proxy_balances_callback(deps, env, query_callback_result) - } _ => Err(ContractError::PolytoneError(format!( "unexpected callback id: {:?}", initiator_msg @@ -244,70 +241,6 @@ fn process_fatal_error_callback( Ok(Response::default()) } -fn handle_withdraw_liquidity_proxy_balances_callback( - deps: ExecuteDeps, - env: Env, - query_callback_result: Result, ErrorResponse>, -) -> NeutronResult> { - // decode the query callback result into a vec of binaries, - // or error out if it fails - let response_binaries = match query_callback_result { - Ok(val) => { - for bin in val.clone() { - POLYTONE_CALLBACKS.save( - deps.storage, - format!( - "proxy_balances_callback : {:?}", - env.block.height.to_string() - ), - &bin.to_base64(), - )?; - } - val - } - Err(err) => return Err(ContractError::PolytoneError(err.error).to_neutron_std()), - }; - - // we load the lp config that was present prior - // to attempting to exit the pool - let mut pre_withdraw_liquidity_lp_config = LIQUIDITY_PROVISIONING_CONFIG.load(deps.storage)?; - let pre_withdraw_lp_token_balance = match pre_withdraw_liquidity_lp_config - .latest_balances - .get(&pre_withdraw_liquidity_lp_config.lp_token_denom) - { - Some(bal) => bal.clone(), - None => Coin { - amount: Uint128::zero(), - denom: pre_withdraw_liquidity_lp_config.lp_token_denom.to_string(), - }, - }; - - for response_binary in response_binaries { - // parse binary into an osmosis QueryBalanceResponse - let balance_response: QueryBalanceResponse = from_json(response_binary.clone())?; - if let Some(balance) = balance_response.balance { - if balance.denom == pre_withdraw_lp_token_balance.denom { - // if proxy lp token balance did not decrease from the - // moment when we submitted the withdraw liquidity message, - // we assume that liquidity was withdrawn and we can - // proceed with the distribution flow. - if Uint128::from_str(&balance.amount)? >= pre_withdraw_lp_token_balance.amount { - CONTRACT_STATE.save(deps.storage, &ContractState::Active)?; - } - } - // update the latest balances map with the processed balance - pre_withdraw_liquidity_lp_config.latest_balances.insert( - balance.denom.to_string(), - coin(Uint128::from_str(&balance.amount)?.u128(), balance.denom), - ); - } - } - // store the latest prices in lp config - LIQUIDITY_PROVISIONING_CONFIG.save(deps.storage, &pre_withdraw_liquidity_lp_config)?; - - Ok(Response::default()) -} - fn handle_proxy_balances_callback( deps: ExecuteDeps, env: Env, diff --git a/contracts/two-party-pol-holder/src/msg.rs b/contracts/two-party-pol-holder/src/msg.rs index 81ec008f..9b4053d3 100644 --- a/contracts/two-party-pol-holder/src/msg.rs +++ b/contracts/two-party-pol-holder/src/msg.rs @@ -1,6 +1,5 @@ use std::{collections::BTreeMap, fmt}; -use astroport::asset::Asset; use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{ ensure, to_json_binary, Addr, Api, Attribute, Binary, Coin, CosmosMsg, Decimal, DepsMut, @@ -518,21 +517,3 @@ pub struct RagequitState { pub coins: Vec, pub rq_party: TwoPartyPolCovenantParty, } - -impl RagequitState { - pub fn from_share_response( - assets: Vec, - rq_party: TwoPartyPolCovenantParty, - ) -> Result { - let mut rq_coins: Vec = vec![]; - for asset in assets { - let coin = asset.to_coin()?; - rq_coins.push(coin); - } - - Ok(RagequitState { - coins: rq_coins, - rq_party, - }) - } -} From bb5107bca424f049676d3d935c792f9b65d70a6b Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 18 Mar 2024 20:17:01 +0100 Subject: [PATCH 32/56] enable fallback denom recovery from ibc-forwarder and remote-chain-splitter icas --- Cargo.lock | 146 +++++------ contracts/ibc-forwarder/Cargo.toml | 1 + contracts/ibc-forwarder/src/contract.rs | 143 +++++++++- contracts/ibc-forwarder/src/error.rs | 15 +- contracts/ibc-forwarder/src/msg.rs | 20 +- contracts/ibc-forwarder/src/state.rs | 1 + contracts/remote-chain-splitter/Cargo.toml | 1 + .../remote-chain-splitter/src/contract.rs | 143 +++++++++- contracts/remote-chain-splitter/src/error.rs | 23 ++ contracts/remote-chain-splitter/src/msg.rs | 17 +- contracts/remote-chain-splitter/src/state.rs | 2 + .../single-party-pol-covenant/src/contract.rs | 3 + .../single-party-pol-covenant/src/msg.rs | 1 + contracts/swap-covenant/src/contract.rs | 2 + contracts/swap-covenant/src/msg.rs | 1 + .../two-party-pol-covenant/src/contract.rs | 2 + contracts/two-party-pol-covenant/src/msg.rs | 1 + packages/covenant-utils/src/lib.rs | 2 + .../src/setup/instantiates/ibc_forwarder.rs | 8 + .../instantiates/remote_chain_splitter.rs | 8 + .../instantiates/single_party_covenant.rs | 2 + .../src/setup/instantiates/swap_covenant.rs | 9 + .../setup/instantiates/two_party_covenant.rs | 1 + unit-tests/src/setup/mod.rs | 2 + unit-tests/src/test_ibc_forwarder/suite.rs | 38 ++- unit-tests/src/test_ibc_forwarder/tests.rs | 242 ++++++++++++++++- .../src/test_remote_chain_splitter/suite.rs | 35 ++- .../src/test_remote_chain_splitter/tests.rs | 244 +++++++++++++++++- .../src/test_single_party_covenant/test.rs | 2 + unit-tests/src/test_swap_covenant/test.rs | 1 + .../src/test_two_party_covenant/test.rs | 6 + 31 files changed, 1024 insertions(+), 98 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc2c2fb1..c0d06f1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "ahash" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ "getrandom", "once_cell", @@ -15,9 +15,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" [[package]] name = "astroport" @@ -171,9 +171,9 @@ dependencies = [ [[package]] name = "bnum" -version = "0.8.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9008b6bb9fc80b5277f2fe481c09e828743d9151203e804583eb4c9e15b31d" +checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" [[package]] name = "byteorder" @@ -198,9 +198,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "num-traits", ] @@ -261,14 +261,14 @@ checksum = "32560304ab4c365791fd307282f76637213d8083c1a98490c35159cd67852237" dependencies = [ "prost 0.12.3", "prost-types 0.12.3", - "tendermint-proto 0.34.0", + "tendermint-proto 0.34.1", ] [[package]] name = "cosmwasm-crypto" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ed6aa9f904de106fa16443ad14ec2abe75e94ba003bb61c681c0e43d4c58d2a" +checksum = "9934c79e58d9676edfd592557dee765d2a6ef54c09d5aa2edb06156b00148966" dependencies = [ "digest 0.10.7", "ecdsa", @@ -280,18 +280,18 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40abec852f3d4abec6d44ead9a58b78325021a1ead1e7229c3471414e57b2e49" +checksum = "bc5e72e330bd3bdab11c52b5ecbdeb6a8697a004c57964caeb5d876f0b088b3c" dependencies = [ "syn 1.0.109", ] [[package]] name = "cosmwasm-schema" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b166215fbfe93dc5575bae062aa57ae7bb41121cffe53bac33b033257949d2a9" +checksum = "ac3e3a2136e2a60e8b6582f5dffca5d1a683ed77bf38537d330bc1dfccd69010" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -302,9 +302,9 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf12f8e20bb29d1db66b7ca590bc2f670b548d21e9be92499bc0f9022a994a8" +checksum = "f5d803bea6bd9ed61bd1ee0b4a2eb09ee20dbb539cc6e0b8795614d20952ebb1" dependencies = [ "proc-macro2", "quote", @@ -313,9 +313,9 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad011ae7447188e26e4a7dbca2fcd0fc186aa21ae5c86df0503ea44c78f9e469" +checksum = "ef8666e572a3a2519010dde88c04d16e9339ae751b56b2bb35081fe3f7d6be74" dependencies = [ "base64", "bech32", @@ -327,7 +327,7 @@ dependencies = [ "hex", "schemars", "serde", - "serde-json-wasm 0.5.1", + "serde-json-wasm 0.5.2", "sha2 0.10.8", "static_assertions", "thiserror", @@ -406,6 +406,7 @@ dependencies = [ "covenant-macros", "covenant-utils", "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", "cw2 1.1.2", "neutron-sdk", "prost 0.11.9", @@ -541,6 +542,7 @@ dependencies = [ "covenant-macros", "covenant-utils", "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", "cw2 1.1.2", "neutron-sdk", "schemars", @@ -797,7 +799,7 @@ dependencies = [ "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "derivative", - "itertools 0.12.0", + "itertools 0.12.1", "prost 0.12.3", "schemars", "serde", @@ -995,9 +997,9 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "dyn-clone" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "ecdsa" @@ -1030,9 +1032,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "elliptic-curve" @@ -1187,9 +1189,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] @@ -1202,9 +1204,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "k256" -version = "0.13.3" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" dependencies = [ "cfg-if", "ecdsa", @@ -1222,9 +1224,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.152" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "neutron-sdk" @@ -1237,12 +1239,12 @@ dependencies = [ "cosmwasm-std", "prost 0.12.3", "prost-types 0.12.3", - "protobuf 3.3.0", + "protobuf 3.4.0", "schemars", "serde", - "serde-json-wasm 1.0.0", + "serde-json-wasm 1.0.1", "speedate", - "tendermint-proto 0.34.0", + "tendermint-proto 0.34.1", "thiserror", ] @@ -1259,18 +1261,18 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] [[package]] name = "num_threads" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" dependencies = [ "libc", ] @@ -1283,9 +1285,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opaque-debug" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "osmosis-std" @@ -1374,9 +1376,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -1424,7 +1426,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.53", ] [[package]] @@ -1456,9 +1458,9 @@ dependencies = [ [[package]] name = "protobuf" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b65f4a8ec18723a734e5dc09c173e0abf9690432da5340285d536edcb4dac190" +checksum = "58678a64de2fced2bdec6bca052a6716a0efe692d6e3f53d1bda6a1def64cfc0" dependencies = [ "once_cell", "protobuf-support", @@ -1467,9 +1469,9 @@ dependencies = [ [[package]] name = "protobuf-support" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6872f4d4f4b98303239a2b5838f5bbbb77b01ffc892d627957f37a22d7cfe69c" +checksum = "e1ed294a835b0f30810e13616b1cd34943c6d1e84a8f3b0dcfe466d256c3e7e7" dependencies = [ "thiserror", ] @@ -1516,9 +1518,9 @@ checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "schemars" @@ -1560,15 +1562,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.195" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] @@ -1593,18 +1595,18 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +checksum = "9e9213a07d53faa0b8dd81e767a54a8188a242fdb9be99ab75ec576a774bfdd7" dependencies = [ "serde", ] [[package]] name = "serde-json-wasm" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c37d03f3b0f6b5f77c11af1e7c772de1c9af83e50bef7bb6069601900ba67b" +checksum = "f05da0d153dd4595bdffd5099dc0e9ce425b205ee648eb93437ff7302af8c9a5" dependencies = [ "serde", ] @@ -1620,13 +1622,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.53", ] [[package]] @@ -1642,9 +1644,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.111" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ "itoa", "ryu", @@ -1751,7 +1753,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.48", + "syn 2.0.53", ] [[package]] @@ -1782,9 +1784,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" dependencies = [ "proc-macro2", "quote", @@ -1811,9 +1813,9 @@ dependencies = [ [[package]] name = "tendermint-proto" -version = "0.34.0" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc728a4f9e891d71adf66af6ecaece146f9c7a11312288a3107b3e1d6979aaf" +checksum = "b797dd3d2beaaee91d2f065e7bdf239dc8d80bba4a183a288bc1279dd5a69a1e" dependencies = [ "bytes", "flex-error", @@ -1829,22 +1831,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.56" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.53", ] [[package]] diff --git a/contracts/ibc-forwarder/Cargo.toml b/contracts/ibc-forwarder/Cargo.toml index b639e8ae..4ad100a6 100644 --- a/contracts/ibc-forwarder/Cargo.toml +++ b/contracts/ibc-forwarder/Cargo.toml @@ -37,3 +37,4 @@ prost = { workspace = true } prost-types = { workspace = true } bech32 = { workspace = true } covenant-utils = { workspace = true } +cw-utils = { workspace = true } \ No newline at end of file diff --git a/contracts/ibc-forwarder/src/contract.rs b/contracts/ibc-forwarder/src/contract.rs index fa176640..34070bc2 100644 --- a/contracts/ibc-forwarder/src/contract.rs +++ b/contracts/ibc-forwarder/src/contract.rs @@ -1,26 +1,37 @@ +use std::collections::BTreeSet; + +use cosmos_sdk_proto::cosmos::bank::v1beta1::{Input, MsgMultiSend, Output}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - from_json, to_json_binary, to_json_vec, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, - MessageInfo, Reply, Response, StdError, StdResult, Storage, SubMsg, + ensure, from_json, to_json_binary, to_json_vec, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, + Env, MessageInfo, Reply, Response, StdError, StdResult, Storage, SubMsg, Uint128, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; -use covenant_utils::neutron::{ - get_ictxs_module_params_query_msg, get_proto_coin, to_proto_msg_transfer, QueryParamsResponse, - RemoteChainInfo, SudoPayload, +use covenant_utils::{ + neutron::{ + get_ictxs_module_params_query_msg, get_proto_coin, to_proto_msg_transfer, + QueryParamsResponse, RemoteChainInfo, SudoPayload, + }, + sum_fees, }; use cw2::set_contract_version; +use cw_utils::must_pay; use neutron_sdk::{ bindings::{ msg::{MsgSubmitTxResponse, NeutronMsg}, query::NeutronQuery, + types::ProtobufAny, }, interchain_txs::helpers::get_port_id, query::min_ibc_fee::MinIbcFeeResponse, sudo::msg::SudoMsg, NeutronError, NeutronResult, }; +use prost::Message; +use crate::state::FALLBACK_ADDRESS; +use crate::{error::ContractError, msg::FallbackAddressUpdateConfig}; use crate::{ helpers::{get_next_memo, MsgTransfer}, msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, @@ -62,6 +73,9 @@ pub fn instantiate( }; REMOTE_CHAIN_INFO.save(deps.storage, &remote_chain_info)?; CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; + if let Some(addr) = &msg.fallback_address { + FALLBACK_ADDRESS.save(deps.storage, addr)?; + } Ok(Response::default() .add_message(enqueue_msg(clock_addr.as_str())?) @@ -79,10 +93,112 @@ pub fn execute( msg: ExecuteMsg, ) -> NeutronResult> { match msg { + ExecuteMsg::DistributeFallback { coins } => try_distribute_fallback(deps, env, info, coins), ExecuteMsg::Tick {} => try_tick(deps, env, info), } } +fn try_distribute_fallback( + mut deps: ExecuteDeps, + env: Env, + info: MessageInfo, + coins: Vec, +) -> NeutronResult> { + // load the fallback address or error out if its not set + let destination = match FALLBACK_ADDRESS.may_load(deps.storage)? { + Some(addr) => addr, + None => return Err(ContractError::MissingFallbackAddress {}.into()), + }; + let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; + + let min_fee_query_response: MinIbcFeeResponse = + deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; + let total_fee_amount = sum_fees(&min_fee_query_response.min_fee); + // the caller must cover the ibc fees + match must_pay(&info, "untrn") { + Ok(amt) => ensure!( + amt >= total_fee_amount.checked_mul(Uint128::new(coins.len() as u128))?, + NeutronError::Std(StdError::generic_err("insufficient fees")) + ), + Err(_) => { + return Err(NeutronError::Std(StdError::generic_err( + "must cover ibc fees to distribute fallback denoms", + ))) + } + }; + + // we iterate over coins to be distributed, validate them, and generate the proto coins to be sent + let mut encountered_denoms: BTreeSet = BTreeSet::new(); + let mut proto_coins: Vec = vec![]; + + for coin in coins { + // validate that target denom is not passed for fallback distribution + ensure!( + coin.denom != remote_chain_info.denom, + Into::::into(ContractError::UnauthorizedDenomDistribution {}) + ); + + // error out if denom is duplicated + ensure!( + encountered_denoms.insert(coin.denom.to_string()), + Into::::into(ContractError::DuplicateDenomDistribution {}) + ); + + proto_coins.push(get_proto_coin(coin.denom, coin.amount)); + } + + let port_id = get_port_id(env.contract.address.as_str(), INTERCHAIN_ACCOUNT_ID); + let interchain_account = INTERCHAIN_ACCOUNTS.may_load(deps.storage, port_id.clone())?; + if let Some(Some((address, controller_conn_id))) = interchain_account { + let multi_send_msg = MsgMultiSend { + inputs: vec![Input { + address, + coins: proto_coins.clone(), + }], + outputs: vec![Output { + address: destination, + coins: proto_coins, + }], + }; + + // Serialize the multi send message. + let mut buf = Vec::with_capacity(multi_send_msg.encoded_len()); + + if let Err(e) = multi_send_msg.encode(&mut buf) { + return Err(NeutronError::Std(StdError::generic_err(format!( + "Encode error: {e:}", + )))); + } + + let any_msg = ProtobufAny { + type_url: "/cosmos.bank.v1beta1.MsgMultiSend".to_string(), + value: Binary::from(buf), + }; + let submit_msg = NeutronMsg::submit_tx( + controller_conn_id, + INTERCHAIN_ACCOUNT_ID.to_string(), + vec![any_msg], + "".to_string(), + remote_chain_info.ica_timeout.u64(), + min_fee_query_response.min_fee, + ); + let sudo_msg = msg_with_sudo_callback( + deps.branch(), + submit_msg, + SudoPayload { + port_id, + message: "distribute_fallback_multisend".to_string(), + }, + )?; + + Ok(Response::default() + .add_attribute("method", "try_forward_fallback") + .add_submessages(vec![sudo_msg])) + } else { + Err(NeutronError::Std(StdError::generic_err("no ica found"))) + } +} + /// attempts to advance the state machine. validates the caller to be the clock. fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult> { // Verify caller is the clock @@ -240,6 +356,9 @@ pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult Ok(to_json_binary(&REMOTE_CHAIN_INFO.may_load(deps.storage)?)?) } QueryMsg::ContractState {} => Ok(to_json_binary(&CONTRACT_STATE.may_load(deps.storage)?)?), + QueryMsg::FallbackAddress {} => { + Ok(to_json_binary(&FALLBACK_ADDRESS.may_load(deps.storage)?)?) + } } } @@ -339,6 +458,7 @@ pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult { let mut resp = Response::default().add_attribute("method", "update_config"); @@ -364,6 +484,19 @@ pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult { + FALLBACK_ADDRESS.save(deps.storage, &addr)?; + resp = resp.add_attribute("fallback_address", addr); + } + FallbackAddressUpdateConfig::Disable {} => { + FALLBACK_ADDRESS.remove(deps.storage); + resp = resp.add_attribute("fallback_address", "removed"); + } + } + } + Ok(resp) } MigrateMsg::UpdateCodeId { data: _ } => { diff --git a/contracts/ibc-forwarder/src/error.rs b/contracts/ibc-forwarder/src/error.rs index bb035528..05aa88e6 100644 --- a/contracts/ibc-forwarder/src/error.rs +++ b/contracts/ibc-forwarder/src/error.rs @@ -12,10 +12,19 @@ pub enum ContractError { #[error("Next contract is not ready for receiving the funds yet")] DepositAddressNotAvailable {}, + + #[error("Missing fallback address")] + MissingFallbackAddress {}, + + #[error("Cannot distribute target denom via fallback distribution")] + UnauthorizedDenomDistribution {}, + + #[error("Attempt to distribute duplicate denoms via fallback distribution")] + DuplicateDenomDistribution {}, } -impl ContractError { - pub fn to_neutron_std(&self) -> NeutronError { - NeutronError::Std(StdError::generic_err(self.to_string())) +impl From for NeutronError { + fn from(value: ContractError) -> Self { + NeutronError::Std(StdError::generic_err(value.to_string())) } } diff --git a/contracts/ibc-forwarder/src/msg.rs b/contracts/ibc-forwarder/src/msg.rs index ec695729..aa935027 100644 --- a/contracts/ibc-forwarder/src/msg.rs +++ b/contracts/ibc-forwarder/src/msg.rs @@ -1,5 +1,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{to_json_binary, Addr, Attribute, Binary, StdResult, Uint128, Uint64, WasmMsg}; +use cosmwasm_std::{ + to_json_binary, Addr, Attribute, Binary, Coin, StdResult, Uint128, Uint64, WasmMsg, +}; use covenant_macros::{ clocked, covenant_clock_address, covenant_deposit_address, covenant_ica_address, covenant_remote_chain, @@ -32,6 +34,8 @@ pub struct InstantiateMsg { /// channel closed. We can reopen the channel by reregistering /// the ICA with the same port id and connection id pub ica_timeout: Uint64, + // fallback address on the remote chain + pub fallback_address: Option, } impl InstantiateMsg { @@ -68,13 +72,16 @@ impl InstantiateMsg { self.ibc_transfer_timeout.to_string(), ), Attribute::new("ica_timeout", self.ica_timeout.to_string()), + Attribute::new("fallback_address", format!("{:?}", self.fallback_address)), ] } } #[clocked] #[cw_serde] -pub enum ExecuteMsg {} +pub enum ExecuteMsg { + DistributeFallback { coins: Vec }, +} #[cw_serde] pub enum MigrateMsg { @@ -83,12 +90,19 @@ pub enum MigrateMsg { next_contract: Option, remote_chain_info: Box>, transfer_amount: Option, + fallback_address: Option, }, UpdateCodeId { data: Option, }, } +#[cw_serde] +pub enum FallbackAddressUpdateConfig { + ExplicitAddress(String), + Disable {}, +} + #[covenant_deposit_address] #[covenant_remote_chain] #[covenant_clock_address] @@ -98,6 +112,8 @@ pub enum MigrateMsg { pub enum QueryMsg { #[returns(ContractState)] ContractState {}, + #[returns(Option)] + FallbackAddress {}, } #[cw_serde] diff --git a/contracts/ibc-forwarder/src/state.rs b/contracts/ibc-forwarder/src/state.rs index 10ad6012..80e28cbc 100644 --- a/contracts/ibc-forwarder/src/state.rs +++ b/contracts/ibc-forwarder/src/state.rs @@ -22,3 +22,4 @@ pub const INTERCHAIN_ACCOUNTS: Map> = pub const REPLY_ID_STORAGE: Item> = Item::new("reply_queue_id"); pub const SUDO_PAYLOAD: Map<(String, u64), Vec> = Map::new("sudo_payload"); +pub const FALLBACK_ADDRESS: Item = Item::new("fallback_address"); diff --git a/contracts/remote-chain-splitter/Cargo.toml b/contracts/remote-chain-splitter/Cargo.toml index df53b50d..1f91f694 100644 --- a/contracts/remote-chain-splitter/Cargo.toml +++ b/contracts/remote-chain-splitter/Cargo.toml @@ -30,3 +30,4 @@ serde-json-wasm = { workspace = true } serde = { workspace = true } neutron-sdk = { workspace = true } cosmos-sdk-proto = { workspace = true } +cw-utils = { workspace = true } \ No newline at end of file diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index 6c019415..727af325 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::collections::{BTreeSet, HashSet}; use std::str::FromStr; use cosmos_sdk_proto::cosmos::bank::v1beta1::{Input, MsgMultiSend, Output}; @@ -7,25 +7,30 @@ use cosmos_sdk_proto::traits::Message; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_json_binary, Attribute, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, Fraction, - MessageInfo, Reply, Response, StdError, StdResult, SubMsg, Uint128, + ensure, to_json_binary, Attribute, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, + Fraction, MessageInfo, Reply, Response, StdError, StdResult, SubMsg, Uint128, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; -use covenant_utils::neutron; use covenant_utils::neutron::{ - get_ictxs_module_params_query_msg, QueryParamsResponse, RemoteChainInfo, SudoPayload, + get_ictxs_module_params_query_msg, get_proto_coin, QueryParamsResponse, RemoteChainInfo, + SudoPayload, }; +use covenant_utils::{neutron, sum_fees}; use cw2::set_contract_version; +use cw_utils::must_pay; use neutron_sdk::bindings::types::ProtobufAny; use neutron_sdk::interchain_txs::helpers::get_port_id; use neutron_sdk::query::min_ibc_fee::MinIbcFeeResponse; use neutron_sdk::sudo::msg::SudoMsg; use neutron_sdk::NeutronError; -use crate::msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use crate::error::ContractError; +use crate::msg::{ + ContractState, ExecuteMsg, FallbackAddressUpdateConfig, InstantiateMsg, MigrateMsg, QueryMsg, +}; use crate::state::{ - save_reply_payload, CLOCK_ADDRESS, CONTRACT_STATE, INTERCHAIN_ACCOUNTS, REMOTE_CHAIN_INFO, - SPLIT_CONFIG_MAP, TRANSFER_AMOUNT, + save_reply_payload, CLOCK_ADDRESS, CONTRACT_STATE, FALLBACK_ADDRESS, INTERCHAIN_ACCOUNTS, + REMOTE_CHAIN_INFO, SPLIT_CONFIG_MAP, TRANSFER_AMOUNT, }; use crate::sudo::{prepare_sudo_payload, sudo_error, sudo_open_ack, sudo_response, sudo_timeout}; use neutron_sdk::{ @@ -64,6 +69,9 @@ pub fn instantiate( REMOTE_CHAIN_INFO.save(deps.storage, &remote_chain_info)?; CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; TRANSFER_AMOUNT.save(deps.storage, &msg.amount)?; + if let Some(addr) = &msg.fallback_address { + FALLBACK_ADDRESS.save(deps.storage, addr)?; + } // validate each split and store it in a map let mut split_resp_attributes: Vec = Vec::with_capacity(msg.splits.len()); @@ -91,6 +99,106 @@ pub fn execute( ) -> NeutronResult> { match msg { ExecuteMsg::Tick {} => try_tick(deps, env, info), + ExecuteMsg::DistributeFallback { coins } => try_distribute_fallback(deps, env, info, coins), + } +} + +fn try_distribute_fallback( + mut deps: ExecuteDeps, + env: Env, + info: MessageInfo, + coins: Vec, +) -> NeutronResult> { + // load the fallback address or error out if its not set + let destination = match FALLBACK_ADDRESS.may_load(deps.storage)? { + Some(addr) => addr, + None => return Err(ContractError::MissingFallbackAddress {}.into()), + }; + let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; + + let min_fee_query_response: MinIbcFeeResponse = + deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; + let total_fee_amount = sum_fees(&min_fee_query_response.min_fee); + // the caller must cover the ibc fees + match must_pay(&info, "untrn") { + Ok(amt) => ensure!( + amt >= total_fee_amount.checked_mul(Uint128::new(coins.len() as u128))?, + NeutronError::Std(StdError::generic_err("insufficient fees")) + ), + Err(_) => { + return Err(NeutronError::Std(StdError::generic_err( + "must cover ibc fees to distribute fallback denoms", + ))) + } + }; + + // we iterate over coins to be distributed, validate them, and generate the proto coins to be sent + let mut encountered_denoms: BTreeSet = BTreeSet::new(); + let mut proto_coins: Vec = vec![]; + + for coin in coins { + // validate that target denom is not passed for fallback distribution + ensure!( + coin.denom != remote_chain_info.denom, + Into::::into(ContractError::UnauthorizedDenomDistribution {}) + ); + + // error out if denom is duplicated + ensure!( + encountered_denoms.insert(coin.denom.to_string()), + Into::::into(ContractError::DuplicateDenomDistribution {}) + ); + + proto_coins.push(get_proto_coin(coin.denom, coin.amount)); + } + + let port_id = get_port_id(env.contract.address.as_str(), INTERCHAIN_ACCOUNT_ID); + let interchain_account = INTERCHAIN_ACCOUNTS.may_load(deps.storage, port_id.clone())?; + if let Some(Some((address, controller_conn_id))) = interchain_account { + let multi_send_msg = MsgMultiSend { + inputs: vec![Input { + address, + coins: proto_coins.clone(), + }], + outputs: vec![Output { + address: destination, + coins: proto_coins, + }], + }; + + let mut buf = Vec::with_capacity(multi_send_msg.encoded_len()); + if let Err(e) = multi_send_msg.encode(&mut buf) { + return Err(NeutronError::Std(StdError::generic_err(format!( + "Encode error: {e:}", + )))); + } + + let any_msg = ProtobufAny { + type_url: "/cosmos.bank.v1beta1.MsgMultiSend".to_string(), + value: Binary::from(buf), + }; + let submit_msg = NeutronMsg::submit_tx( + controller_conn_id, + INTERCHAIN_ACCOUNT_ID.to_string(), + vec![any_msg], + "".to_string(), + remote_chain_info.ica_timeout.u64(), + min_fee_query_response.min_fee, + ); + let sudo_msg = msg_with_sudo_callback( + deps.branch(), + submit_msg, + SudoPayload { + port_id, + message: "distribute_fallback_multisend".to_string(), + }, + )?; + + Ok(Response::default() + .add_attribute("method", "try_forward_fallback") + .add_submessages(vec![sudo_msg])) + } else { + Err(NeutronError::Std(StdError::generic_err("no ica found"))) } } @@ -198,7 +306,7 @@ fn try_split_funds(mut deps: ExecuteDeps, env: Env) -> NeutronResult NeutronResult QueryMsg::IcaAddress {} => Ok(to_json_binary( &get_ica(deps, &env, INTERCHAIN_ACCOUNT_ID)?.0, )?), + QueryMsg::FallbackAddress {} => { + Ok(to_json_binary(&FALLBACK_ADDRESS.may_load(deps.storage)?)?) + } } } @@ -342,6 +453,7 @@ pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult { let mut resp = Response::default().add_attribute("method", "update_config"); @@ -380,6 +492,19 @@ pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult { + FALLBACK_ADDRESS.save(deps.storage, &addr)?; + resp = resp.add_attribute("fallback_address", addr); + } + FallbackAddressUpdateConfig::Disable {} => { + FALLBACK_ADDRESS.remove(deps.storage); + resp = resp.add_attribute("fallback_address", "removed"); + } + } + } + Ok(resp) } MigrateMsg::UpdateCodeId { data: _ } => { diff --git a/contracts/remote-chain-splitter/src/error.rs b/contracts/remote-chain-splitter/src/error.rs index 8b137891..8c403f55 100644 --- a/contracts/remote-chain-splitter/src/error.rs +++ b/contracts/remote-chain-splitter/src/error.rs @@ -1 +1,24 @@ +use cosmwasm_std::StdError; +use neutron_sdk::NeutronError; +use thiserror::Error; +#[derive(Error, Debug)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("Missing fallback address")] + MissingFallbackAddress {}, + + #[error("Cannot distribute target denom via fallback distribution")] + UnauthorizedDenomDistribution {}, + + #[error("Attempt to distribute duplicate denoms via fallback distribution")] + DuplicateDenomDistribution {}, +} + +impl From for NeutronError { + fn from(value: ContractError) -> Self { + NeutronError::Std(StdError::generic_err(value.to_string())) + } +} diff --git a/contracts/remote-chain-splitter/src/msg.rs b/contracts/remote-chain-splitter/src/msg.rs index 2de9ea7d..af4687be 100644 --- a/contracts/remote-chain-splitter/src/msg.rs +++ b/contracts/remote-chain-splitter/src/msg.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{to_json_binary, Addr, Binary, StdResult, Uint128, Uint64, WasmMsg}; +use cosmwasm_std::{to_json_binary, Addr, Binary, Coin, StdResult, Uint128, Uint64, WasmMsg}; use covenant_macros::{ clocked, covenant_clock_address, covenant_deposit_address, covenant_ica_address, covenant_remote_chain, @@ -36,6 +36,8 @@ pub struct InstantiateMsg { /// if the ICA times out, the destination chain receiving the funds /// will also receive the IBC packet with an expired timestamp. pub ibc_transfer_timeout: Uint64, + // fallback address on the remote chain + pub fallback_address: Option, } impl InstantiateMsg { @@ -58,7 +60,9 @@ impl InstantiateMsg { #[clocked] #[cw_serde] -pub enum ExecuteMsg {} +pub enum ExecuteMsg { + DistributeFallback { coins: Vec }, +} #[covenant_clock_address] #[covenant_remote_chain] @@ -73,6 +77,8 @@ pub enum QueryMsg { SplitConfig {}, #[returns(Uint128)] TransferAmount {}, + #[returns(Option)] + FallbackAddress {}, } #[cw_serde] @@ -81,12 +87,19 @@ pub enum ContractState { IcaCreated, } +#[cw_serde] +pub enum FallbackAddressUpdateConfig { + ExplicitAddress(String), + Disable {}, +} + #[cw_serde] pub enum MigrateMsg { UpdateConfig { clock_addr: Option, remote_chain_info: Option, splits: Option>, + fallback_address: Option, }, UpdateCodeId { data: Option, diff --git a/contracts/remote-chain-splitter/src/state.rs b/contracts/remote-chain-splitter/src/state.rs index 13c9f075..db9e52ff 100644 --- a/contracts/remote-chain-splitter/src/state.rs +++ b/contracts/remote-chain-splitter/src/state.rs @@ -21,6 +21,8 @@ pub const SPLIT_CONFIG_MAP: Map = Map::new("split_config"); /// information needed for an ibc transfer to the remote chain pub const REMOTE_CHAIN_INFO: Item = Item::new("r_c_info"); +pub const FALLBACK_ADDRESS: Item = Item::new("fallback_address"); + /// interchain accounts storage in form of (port_id) -> (address, controller_connection_id) pub const INTERCHAIN_ACCOUNTS: Map> = Map::new("interchain_accounts"); diff --git a/contracts/single-party-pol-covenant/src/contract.rs b/contracts/single-party-pol-covenant/src/contract.rs index d475d41b..31788cbe 100644 --- a/contracts/single-party-pol-covenant/src/contract.rs +++ b/contracts/single-party-pol-covenant/src/contract.rs @@ -193,6 +193,7 @@ pub fn instantiate( ica_timeout: msg.timeouts.ica_timeout, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, splits, + fallback_address: msg.remote_chain_splitter_config.fallback_address, } .to_instantiate2_msg( &splitter_instantiate2_config, @@ -220,6 +221,7 @@ pub fn instantiate( amount: config.contribution.amount, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, ica_timeout: msg.timeouts.ica_timeout, + fallback_address: config.fallback_address, }; messages.push(instantiate_msg.to_instantiate2_msg( &ls_forwarder_instantiate2_config, @@ -240,6 +242,7 @@ pub fn instantiate( amount: config.contribution.amount, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, ica_timeout: msg.timeouts.ica_timeout, + fallback_address: config.fallback_address, }; messages.push(instantiate_msg.to_instantiate2_msg( &lp_forwarder_instantiate2_config, diff --git a/contracts/single-party-pol-covenant/src/msg.rs b/contracts/single-party-pol-covenant/src/msg.rs index b1f46bd1..c2978866 100644 --- a/contracts/single-party-pol-covenant/src/msg.rs +++ b/contracts/single-party-pol-covenant/src/msg.rs @@ -80,6 +80,7 @@ pub struct RemoteChainSplitterConfig { pub amount: Uint128, pub ls_share: Decimal, pub native_share: Decimal, + pub fallback_address: Option, } #[cw_serde] diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index b424baac..f7202fde 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -214,6 +214,7 @@ pub fn instantiate( ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, clock_address: clock_instantiate2_config.addr.to_string(), next_contract: holder_instantiate2_config.addr.to_string(), + fallback_address: msg.fallback_address.clone(), } .to_instantiate2_msg( &party_a_forwarder_instantiate2_config, @@ -254,6 +255,7 @@ pub fn instantiate( ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, clock_address: clock_instantiate2_config.addr.to_string(), next_contract: holder_instantiate2_config.addr.to_string(), + fallback_address: msg.fallback_address, } .to_instantiate2_msg( &party_b_forwarder_instantiate2_config, diff --git a/contracts/swap-covenant/src/msg.rs b/contracts/swap-covenant/src/msg.rs index 96cc48de..807634d6 100644 --- a/contracts/swap-covenant/src/msg.rs +++ b/contracts/swap-covenant/src/msg.rs @@ -21,6 +21,7 @@ pub struct InstantiateMsg { pub party_b_config: CovenantPartyConfig, pub splits: BTreeMap, pub fallback_split: Option, + pub fallback_address: Option, } #[cw_serde] diff --git a/contracts/two-party-pol-covenant/src/contract.rs b/contracts/two-party-pol-covenant/src/contract.rs index 8a85e0c1..e2ff82a7 100644 --- a/contracts/two-party-pol-covenant/src/contract.rs +++ b/contracts/two-party-pol-covenant/src/contract.rs @@ -182,6 +182,7 @@ pub fn instantiate( amount: config.contribution.amount, ica_timeout: msg.timeouts.ica_timeout, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, + fallback_address: msg.fallback_address.clone(), }; messages.push(instantiate_msg.to_instantiate2_msg( @@ -214,6 +215,7 @@ pub fn instantiate( amount: config.contribution.amount, ica_timeout: msg.timeouts.ica_timeout, ibc_transfer_timeout: msg.timeouts.ibc_transfer_timeout, + fallback_address: msg.fallback_address, }; messages.push(instantiate_msg.to_instantiate2_msg( diff --git a/contracts/two-party-pol-covenant/src/msg.rs b/contracts/two-party-pol-covenant/src/msg.rs index f9b81d89..a13cfb2f 100644 --- a/contracts/two-party-pol-covenant/src/msg.rs +++ b/contracts/two-party-pol-covenant/src/msg.rs @@ -33,6 +33,7 @@ pub struct InstantiateMsg { pub fallback_split: Option, pub emergency_committee: Option, pub liquid_pooler_config: LiquidPoolerConfig, + pub fallback_address: Option, } #[cw_serde] diff --git a/packages/covenant-utils/src/lib.rs b/packages/covenant-utils/src/lib.rs index 2792ef37..20e4cb63 100644 --- a/packages/covenant-utils/src/lib.rs +++ b/packages/covenant-utils/src/lib.rs @@ -41,6 +41,8 @@ pub struct InterchainCovenantParty { pub contribution: Coin, /// configuration for unwinding the denoms via pfm pub denom_to_pfm_map: BTreeMap, + /// fallback refund address on the remote chain + pub fallback_address: Option, } #[cw_serde] diff --git a/unit-tests/src/setup/instantiates/ibc_forwarder.rs b/unit-tests/src/setup/instantiates/ibc_forwarder.rs index 25e549e9..887cdd91 100644 --- a/unit-tests/src/setup/instantiates/ibc_forwarder.rs +++ b/unit-tests/src/setup/instantiates/ibc_forwarder.rs @@ -22,6 +22,7 @@ impl IbcForwarderInstantiate { amount: Uint128, ibc_transfer_timeout: Uint64, ica_timeout: Uint64, + fallback_address: Option, ) -> Self { Self { msg: covenant_ibc_forwarder::msg::InstantiateMsg { @@ -33,6 +34,7 @@ impl IbcForwarderInstantiate { amount, ibc_transfer_timeout, ica_timeout, + fallback_address, }, } } @@ -67,6 +69,11 @@ impl IbcForwarderInstantiate { self } + pub fn with_fallback_address(&mut self, addr: String) -> &mut Self { + self.msg.fallback_address = Some(addr); + self + } + pub fn with_ibc_transfer_timeout(&mut self, addr: Uint64) -> &mut Self { self.msg.ibc_transfer_timeout = addr; self @@ -90,6 +97,7 @@ impl IbcForwarderInstantiate { amount: Uint128::new(100_000), ica_timeout: Uint64::from(100u64), ibc_transfer_timeout: Uint64::from(100u64), + fallback_address: None, }, } } diff --git a/unit-tests/src/setup/instantiates/remote_chain_splitter.rs b/unit-tests/src/setup/instantiates/remote_chain_splitter.rs index a3d69a14..da0c05ff 100644 --- a/unit-tests/src/setup/instantiates/remote_chain_splitter.rs +++ b/unit-tests/src/setup/instantiates/remote_chain_splitter.rs @@ -24,6 +24,7 @@ impl RemoteChainSplitterInstantiate { splits: BTreeMap, ica_timeout: Uint64, ibc_transfer_timeout: Uint64, + fallback_address: Option, ) -> Self { Self { msg: covenant_remote_chain_splitter::msg::InstantiateMsg { @@ -35,6 +36,7 @@ impl RemoteChainSplitterInstantiate { splits, ica_timeout, ibc_transfer_timeout, + fallback_address, }, } } @@ -74,6 +76,11 @@ impl RemoteChainSplitterInstantiate { self } + pub fn with_fallback_address(&mut self, fallback_address: Option) -> &mut Self { + self.msg.fallback_address = fallback_address; + self + } + pub fn with_ibc_transfer_timeout(&mut self, ibc_transfer_timeout: Uint64) -> &mut Self { self.msg.ibc_transfer_timeout = ibc_transfer_timeout; self @@ -100,6 +107,7 @@ impl RemoteChainSplitterInstantiate { splits: denom_to_split_config_map, ica_timeout: Uint64::from(100u64), ibc_transfer_timeout: Uint64::from(100u64), + fallback_address: None, }, } } diff --git a/unit-tests/src/setup/instantiates/single_party_covenant.rs b/unit-tests/src/setup/instantiates/single_party_covenant.rs index 6f789a44..aafdefc2 100644 --- a/unit-tests/src/setup/instantiates/single_party_covenant.rs +++ b/unit-tests/src/setup/instantiates/single_party_covenant.rs @@ -85,6 +85,7 @@ impl SinglePartyCovenantInstantiate { native_denom: local_denom.to_string(), contribution: coin(amount, remote_denom), denom_to_pfm_map, + fallback_address: None, } } @@ -140,6 +141,7 @@ impl SinglePartyCovenantInstantiate { amount: amount.into(), ls_share, native_share, + fallback_address: None, } } diff --git a/unit-tests/src/setup/instantiates/swap_covenant.rs b/unit-tests/src/setup/instantiates/swap_covenant.rs index ec7d2375..4ddf4610 100644 --- a/unit-tests/src/setup/instantiates/swap_covenant.rs +++ b/unit-tests/src/setup/instantiates/swap_covenant.rs @@ -45,6 +45,7 @@ impl SwapCovenantInstantiate { party_b_config, splits, None, + None, ) } @@ -69,6 +70,7 @@ impl SwapCovenantInstantiate { native_denom: local_denom.to_string(), contribution: coin(amount, remote_denom), denom_to_pfm_map: BTreeMap::new(), + fallback_address: None, }, ) } @@ -118,6 +120,7 @@ impl SwapCovenantInstantiate { party_b_config: covenant_swap::msg::CovenantPartyConfig, splits: BTreeMap, fallback_split: Option, + fallback_address: Option, ) -> Self { Self { msg: covenant_swap::msg::InstantiateMsg { @@ -130,6 +133,7 @@ impl SwapCovenantInstantiate { party_b_config, splits, fallback_split, + fallback_address, }, } } @@ -203,4 +207,9 @@ impl SwapCovenantInstantiate { self.msg.fallback_split = Some(covenant_utils::split::SplitConfig { receivers }); self } + + pub fn with_fallback_address(&mut self, addr: String) -> &mut Self { + self.msg.fallback_address = Some(addr); + self + } } diff --git a/unit-tests/src/setup/instantiates/two_party_covenant.rs b/unit-tests/src/setup/instantiates/two_party_covenant.rs index 8ab30886..c219f109 100644 --- a/unit-tests/src/setup/instantiates/two_party_covenant.rs +++ b/unit-tests/src/setup/instantiates/two_party_covenant.rs @@ -192,6 +192,7 @@ impl TwoPartyCovenantInstantiate { }, }, ), + fallback_address: None, }, } } diff --git a/unit-tests/src/setup/mod.rs b/unit-tests/src/setup/mod.rs index 11535f2c..01f65430 100644 --- a/unit-tests/src/setup/mod.rs +++ b/unit-tests/src/setup/mod.rs @@ -51,6 +51,8 @@ pub const ALL_DENOMS: &[&str] = &[ DENOM_FALLBACK, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, + DENOM_FALLBACK_ON_HUB, + DENOM_OSMO_ON_HUB_FROM_NTRN, ]; // Addrs diff --git a/unit-tests/src/test_ibc_forwarder/suite.rs b/unit-tests/src/test_ibc_forwarder/suite.rs index c3b36760..6a4850d3 100644 --- a/unit-tests/src/test_ibc_forwarder/suite.rs +++ b/unit-tests/src/test_ibc_forwarder/suite.rs @@ -1,7 +1,8 @@ use std::str::FromStr; -use cosmwasm_std::{Addr, Uint128, Uint64}; +use cosmwasm_std::{Addr, Coin, Uint128, Uint64}; use covenant_utils::neutron::RemoteChainInfo; +use cw_multi_test::{AppResponse, Executor}; use cw_storage_plus::KeyDeserialize; use crate::setup::{ @@ -72,6 +73,11 @@ impl IbcForwarderBuilder { self } + pub fn with_fallback_address(mut self, fallback_address: String) -> Self { + self.instantiate_msg.with_fallback_address(fallback_address); + self + } + pub fn with_ibc_transfer_timeout(mut self, ibc_transfer_timeout: Uint64) -> Self { self.instantiate_msg .with_ibc_transfer_timeout(ibc_transfer_timeout); @@ -228,6 +234,16 @@ impl Suite { Addr::from_slice(&val).unwrap() } + pub fn query_fallback_address(&mut self) -> Option { + self.app + .wrap() + .query_wasm_smart( + self.ibc_forwarder.clone(), + &covenant_ibc_forwarder::msg::QueryMsg::FallbackAddress {}, + ) + .unwrap() + } + // temp fix until we add a query pub(crate) fn query_transfer_amount(&mut self) -> Uint128 { let resp = self @@ -243,6 +259,26 @@ impl Suite { Uint128::from_str(&transfer_amount).unwrap() } + + pub fn query_admin_address(&mut self) -> String { + self.app + .wrap() + .query_wasm_contract_info(self.ibc_forwarder.to_string()) + .unwrap() + .admin + .unwrap() + } + + pub fn distribute_fallback(&mut self, coins: Vec, funds: Vec) -> AppResponse { + self.app + .execute_contract( + self.faucet.clone(), + self.ibc_forwarder.clone(), + &covenant_ibc_forwarder::msg::ExecuteMsg::DistributeFallback { coins }, + &funds, + ) + .unwrap() + } } impl BaseSuiteMut for Suite { diff --git a/unit-tests/src/test_ibc_forwarder/tests.rs b/unit-tests/src/test_ibc_forwarder/tests.rs index f3d14619..55a76531 100644 --- a/unit-tests/src/test_ibc_forwarder/tests.rs +++ b/unit-tests/src/test_ibc_forwarder/tests.rs @@ -1,10 +1,10 @@ use cosmwasm_std::{coin, coins, Addr, Uint128}; -use covenant_ibc_forwarder::msg::ContractState; +use covenant_ibc_forwarder::msg::{ContractState, FallbackAddressUpdateConfig}; use cw_multi_test::Executor; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, - ADMIN, DENOM_ATOM_ON_NTRN, DENOM_NTRN, + ADMIN, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK_ON_HUB, DENOM_NTRN, DENOM_OSMO_ON_HUB_FROM_NTRN, }; use super::suite::IbcForwarderBuilder; @@ -159,6 +159,214 @@ fn test_forward_funds_happy() { ); } +#[test] +#[should_panic(expected = "Missing fallback address")] +fn test_distribute_fallback_errors_without_fallback_address() { + let mut suite = IbcForwarderBuilder::default().build(); + + let forwarder_addr = suite.ibc_forwarder.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(2_000_000, DENOM_NTRN), forwarder_addr.clone()); + + // register ica + suite.tick_contract(forwarder_addr.clone()); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![coin(100_000, DENOM_ATOM_ON_NTRN.to_string())], + coins(1_000_000, DENOM_NTRN), + ); +} + +#[test] +#[should_panic(expected = "Cannot distribute target denom via fallback distribution")] +fn test_distribute_fallback_validates_denom() { + let mut builder = IbcForwarderBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + let forwarder_addr = suite.ibc_forwarder.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(2_000_000, DENOM_NTRN), forwarder_addr.clone()); + + // register ica + suite.tick_contract(forwarder_addr.clone()); + + let forwarder_ica = suite.query_ica_address(forwarder_addr.clone()); + + // fund the ica with sufficient amount of DENOM_ATOM_ON_NTRN + suite.fund_contract(&coins(100_000, DENOM_ATOM_ON_NTRN), forwarder_ica.clone()); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_ATOM_ON_NTRN)); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![coin(100_000, DENOM_ATOM_ON_NTRN.to_string())], + coins(1_000_000, DENOM_NTRN), + ); +} + +#[test] +#[should_panic(expected = "must cover ibc fees to distribute fallback denoms")] +fn test_distribute_fallback_validates_ibc_fee_coverage() { + let mut builder = IbcForwarderBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + let forwarder_addr = suite.ibc_forwarder.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(2_000_000, DENOM_NTRN), forwarder_addr.clone()); + + // register ica + suite.tick_contract(forwarder_addr.clone()); + + let forwarder_ica = suite.query_ica_address(forwarder_addr.clone()); + + // fund the ica with sufficient amount of DENOM_ATOM_ON_NTRN + suite.fund_contract(&coins(100_000, DENOM_ATOM_ON_NTRN), forwarder_ica.clone()); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_ATOM_ON_NTRN)); + + // try to distribute fallback denom + suite.distribute_fallback(vec![coin(100_000, DENOM_ATOM_ON_NTRN.to_string())], vec![]); +} + +#[test] +#[should_panic(expected = "no ica found")] +fn test_distribute_fallback_validates_ica_exists() { + let mut builder = IbcForwarderBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![coin(100_000, DENOM_FALLBACK_ON_HUB.to_string())], + coins(1_000_000, DENOM_NTRN), + ); +} + +#[test] +#[should_panic(expected = "insufficient fees")] +fn test_distribute_fallback_validates_insufficient_ibc_fee_coverage() { + let mut builder = IbcForwarderBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + let forwarder_addr = suite.ibc_forwarder.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(2_000_000, DENOM_NTRN), forwarder_addr.clone()); + + // register ica + suite.tick_contract(forwarder_addr.clone()); + + let forwarder_ica = suite.query_ica_address(forwarder_addr.clone()); + + // fund the ica with sufficient amount of DENOM_ATOM_ON_NTRN + suite.fund_contract(&coins(100_000, DENOM_ATOM_ON_NTRN), forwarder_ica.clone()); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_ATOM_ON_NTRN)); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![coin(100_000, DENOM_ATOM_ON_NTRN.to_string())], + coins(5_000, DENOM_NTRN), + ); +} + +#[test] +#[should_panic(expected = "Attempt to distribute duplicate denoms via fallback distribution")] +fn test_distribute_fallback_validates_duplicate_input_denoms() { + let mut builder = IbcForwarderBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + let forwarder_addr = suite.ibc_forwarder.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(2_000_000, DENOM_NTRN), forwarder_addr.clone()); + + // register ica + suite.tick_contract(forwarder_addr.clone()); + + let forwarder_ica = suite.query_ica_address(forwarder_addr.clone()); + + // fund the ica with sufficient amount of DENOM_ATOM_ON_NTRN + suite.fund_contract( + &coins(100_000, DENOM_FALLBACK_ON_HUB), + forwarder_ica.clone(), + ); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_FALLBACK_ON_HUB)); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![ + coin(100_000, DENOM_FALLBACK_ON_HUB.to_string()), + coin(100_000, DENOM_FALLBACK_ON_HUB.to_string()), + ], + coins(1_000_000, DENOM_NTRN), + ); + + // assert that the funds were in fact forwarded + suite.assert_balance(&forwarder_ica, coin(0, DENOM_FALLBACK_ON_HUB)); +} + +#[test] +fn test_distribute_fallback_happy() { + let mut builder = IbcForwarderBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + let forwarder_addr = suite.ibc_forwarder.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(3_000_000, DENOM_NTRN), forwarder_addr.clone()); + + // register ica + suite.tick_contract(forwarder_addr.clone()); + + let forwarder_ica = suite.query_ica_address(forwarder_addr.clone()); + + // fund the ica with sufficient amount of DENOM_FALLBACK_ON_HUB and + suite.fund_contract( + &coins(100_000, DENOM_FALLBACK_ON_HUB), + forwarder_ica.clone(), + ); + suite.fund_contract( + &coins(100_000, DENOM_OSMO_ON_HUB_FROM_NTRN), + forwarder_ica.clone(), + ); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_FALLBACK_ON_HUB)); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_OSMO_ON_HUB_FROM_NTRN)); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![ + coin(100_000, DENOM_FALLBACK_ON_HUB.to_string()), + coin(100_000, DENOM_OSMO_ON_HUB_FROM_NTRN), + ], + vec![coin(2_000_000, DENOM_NTRN)], + ); + + // assert that the funds were in fact forwarded + suite.assert_balance(&forwarder_ica, coin(0, DENOM_ATOM_ON_NTRN)); + suite.assert_balance(&forwarder_ica, coin(0, DENOM_OSMO_ON_HUB_FROM_NTRN)); + suite.assert_balance( + suite.clock_addr.to_string(), + coin(100_000, DENOM_FALLBACK_ON_HUB), + ); + suite.assert_balance( + suite.clock_addr.to_string(), + coin(100_000, DENOM_OSMO_ON_HUB_FROM_NTRN), + ); +} + #[test] fn test_migrate_update_config() { let mut suite = IbcForwarderBuilder::default().build(); @@ -180,6 +388,9 @@ fn test_migrate_update_config() { next_contract: Some(clock_addr.to_string()), remote_chain_info: Box::new(Some(remote_chain_info)), transfer_amount: Some(Uint128::new(69)), + fallback_address: Some(FallbackAddressUpdateConfig::ExplicitAddress( + clock_addr.to_string(), + )), }, 10, ) @@ -189,4 +400,31 @@ fn test_migrate_update_config() { assert_eq!(suite.query_remote_chain_info().denom, "some new denom"); assert_eq!(suite.query_transfer_amount(), Uint128::new(69)); assert_eq!(suite.query_next_contract(), clock_addr); + assert_eq!(suite.query_fallback_address().unwrap(), clock_addr); +} + +#[test] +fn test_migrate_update_config_remove_fallback() { + let mut builder = IbcForwarderBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + suite.ibc_forwarder.clone(), + &covenant_ibc_forwarder::msg::MigrateMsg::UpdateConfig { + clock_addr: None, + next_contract: None, + remote_chain_info: Box::new(None), + transfer_amount: None, + fallback_address: Some(FallbackAddressUpdateConfig::Disable {}), + }, + 10, + ) + .unwrap(); + + assert!(suite.query_fallback_address().is_none()); } diff --git a/unit-tests/src/test_remote_chain_splitter/suite.rs b/unit-tests/src/test_remote_chain_splitter/suite.rs index be11f355..7d4171ae 100644 --- a/unit-tests/src/test_remote_chain_splitter/suite.rs +++ b/unit-tests/src/test_remote_chain_splitter/suite.rs @@ -1,7 +1,8 @@ use std::collections::BTreeMap; -use cosmwasm_std::{Addr, Uint128, Uint64}; +use cosmwasm_std::{Addr, Coin, Uint128, Uint64}; use covenant_utils::{neutron::RemoteChainInfo, split::SplitConfig}; +use cw_multi_test::{AppResponse, Executor}; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -51,6 +52,7 @@ impl Default for RemoteChainSplitterBuilder { amount: Uint128::new(100), ibc_transfer_timeout: Uint64::new(100), ica_timeout: Uint64::new(100), + fallback_address: None, }; builder.contract_init2( @@ -268,6 +270,37 @@ impl Suite { ) .unwrap() } + + pub fn query_fallback_address(&self) -> Option { + self.app + .wrap() + .query_wasm_smart( + self.splitter.clone(), + &covenant_remote_chain_splitter::msg::QueryMsg::FallbackAddress {}, + ) + .unwrap() + } + + pub fn distribute_fallback(&mut self, coins: Vec, funds: Vec) -> AppResponse { + self.app + .execute_contract( + self.faucet.clone(), + self.splitter.clone(), + &covenant_remote_chain_splitter::msg::ExecuteMsg::DistributeFallback { coins }, + &funds, + ) + .unwrap() + } + + pub fn query_ica_address(&mut self, addr: Addr) -> Addr { + self.app + .wrap() + .query_wasm_smart( + addr, + &covenant_remote_chain_splitter::msg::QueryMsg::IcaAddress {}, + ) + .unwrap() + } } impl BaseSuiteMut for Suite { diff --git a/unit-tests/src/test_remote_chain_splitter/tests.rs b/unit-tests/src/test_remote_chain_splitter/tests.rs index aa90a21c..e4a74ce0 100644 --- a/unit-tests/src/test_remote_chain_splitter/tests.rs +++ b/unit-tests/src/test_remote_chain_splitter/tests.rs @@ -1,12 +1,14 @@ use std::{collections::BTreeMap, str::FromStr}; use cosmwasm_std::{coin, coins, Addr, Decimal, Uint128}; +use covenant_remote_chain_splitter::msg::FallbackAddressUpdateConfig; use covenant_utils::split::SplitConfig; use cw_multi_test::Executor; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, - ADMIN, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN, DENOM_NTRN, + ADMIN, DENOM_ATOM_ON_NTRN, DENOM_FALLBACK_ON_HUB, DENOM_LS_ATOM_ON_NTRN, DENOM_NTRN, + DENOM_OSMO_ON_HUB_FROM_NTRN, }; use super::suite::RemoteChainSplitterBuilder; @@ -243,6 +245,9 @@ fn test_migrate_update_config() { clock_addr: Some(suite.faucet.to_string()), remote_chain_info: Some(remote_chain_info.clone()), splits: Some(split_config.clone()), + fallback_address: Some(FallbackAddressUpdateConfig::ExplicitAddress( + suite.faucet.to_string(), + )), }, 6, ) @@ -251,10 +256,38 @@ fn test_migrate_update_config() { let new_remote_chain_info = suite.query_remote_chain_info(); let new_split_config = suite.query_split_config(); let clock_addr = suite.query_clock_address(); + let fallback_addr = suite.query_fallback_address().unwrap(); assert_eq!(suite.faucet, clock_addr); assert_eq!(remote_chain_info, new_remote_chain_info); assert_eq!(split_config, new_split_config); + assert_eq!(suite.faucet, fallback_addr); +} + +#[test] +fn test_migrate_update_config_disable_fallback() { + let mut builder = RemoteChainSplitterBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + suite + .app + .migrate_contract( + Addr::unchecked(ADMIN), + suite.splitter.clone(), + &covenant_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { + clock_addr: None, + remote_chain_info: None, + splits: None, + fallback_address: Some(FallbackAddressUpdateConfig::Disable {}), + }, + 6, + ) + .unwrap(); + + let fallback_addr = suite.query_fallback_address(); + assert!(fallback_addr.is_none()); } #[test] @@ -286,8 +319,217 @@ fn test_migrate_update_config_validates_splits() { clock_addr: None, remote_chain_info: None, splits: Some(split_config.clone()), + fallback_address: None, }, 6, ) .unwrap(); } + +#[test] +#[should_panic(expected = "Missing fallback address")] +fn test_distribute_fallback_errors_without_fallback_address() { + let mut suite = RemoteChainSplitterBuilder::default().build(); + + let splitter_addr = suite.splitter.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(2_000_000, DENOM_NTRN), splitter_addr.clone()); + + // register ica + suite.tick_contract(splitter_addr.clone()); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![coin(100_000, DENOM_ATOM_ON_NTRN.to_string())], + coins(1_000_000, DENOM_NTRN), + ); +} + +#[test] +#[should_panic(expected = "Cannot distribute target denom via fallback distribution")] +fn test_distribute_fallback_validates_denom() { + let mut builder = RemoteChainSplitterBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + let splitter_addr = suite.splitter.clone(); + + // fund splitter to register the ica + suite.fund_contract(&coins(2_000_000, DENOM_NTRN), splitter_addr.clone()); + + // register ica + suite.tick_contract(splitter_addr.clone()); + + let splitter_ica = suite.query_ica_address(splitter_addr.clone()); + + // fund the ica with sufficient amount of DENOM_ATOM_ON_NTRN + suite.fund_contract(&coins(100_000, DENOM_ATOM_ON_NTRN), splitter_ica.clone()); + suite.assert_balance(&splitter_ica, coin(100_000, DENOM_ATOM_ON_NTRN)); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![coin(100_000, DENOM_ATOM_ON_NTRN.to_string())], + coins(1_000_000, DENOM_NTRN), + ); +} + +#[test] +#[should_panic(expected = "must cover ibc fees to distribute fallback denoms")] +fn test_distribute_fallback_validates_ibc_fee_coverage() { + let mut builder = RemoteChainSplitterBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + let splitter_addr = suite.splitter.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(2_000_000, DENOM_NTRN), splitter_addr.clone()); + + // register ica + suite.tick_contract(splitter_addr.clone()); + + let forwarder_ica = suite.query_ica_address(splitter_addr.clone()); + + // fund the ica with sufficient amount of DENOM_ATOM_ON_NTRN + suite.fund_contract(&coins(100_000, DENOM_ATOM_ON_NTRN), forwarder_ica.clone()); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_ATOM_ON_NTRN)); + + // try to distribute fallback denom + suite.distribute_fallback(vec![coin(100_000, DENOM_ATOM_ON_NTRN.to_string())], vec![]); +} + +#[test] +#[should_panic(expected = "insufficient fees")] +fn test_distribute_fallback_validates_insufficient_ibc_fee_coverage() { + let mut builder = RemoteChainSplitterBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + let splitter_addr = suite.splitter.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(2_000_000, DENOM_NTRN), splitter_addr.clone()); + + // register ica + suite.tick_contract(splitter_addr.clone()); + + let forwarder_ica = suite.query_ica_address(splitter_addr.clone()); + + // fund the ica with sufficient amount of DENOM_ATOM_ON_NTRN + suite.fund_contract(&coins(100_000, DENOM_ATOM_ON_NTRN), forwarder_ica.clone()); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_ATOM_ON_NTRN)); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![coin(100_000, DENOM_ATOM_ON_NTRN.to_string())], + coins(5_000, DENOM_NTRN), + ); +} + +#[test] +#[should_panic(expected = "Attempt to distribute duplicate denoms via fallback distribution")] +fn test_distribute_fallback_validates_duplicate_input_denoms() { + let mut builder = RemoteChainSplitterBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + let splitter_addr = suite.splitter.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(2_000_000, DENOM_NTRN), splitter_addr.clone()); + + // register ica + suite.tick_contract(splitter_addr.clone()); + + let forwarder_ica = suite.query_ica_address(splitter_addr.clone()); + + // fund the ica with sufficient amount of DENOM_ATOM_ON_NTRN + suite.fund_contract( + &coins(100_000, DENOM_FALLBACK_ON_HUB), + forwarder_ica.clone(), + ); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_FALLBACK_ON_HUB)); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![ + coin(100_000, DENOM_FALLBACK_ON_HUB.to_string()), + coin(100_000, DENOM_FALLBACK_ON_HUB.to_string()), + ], + coins(1_000_000, DENOM_NTRN), + ); + + // assert that the funds were in fact forwarded + suite.assert_balance(&forwarder_ica, coin(0, DENOM_FALLBACK_ON_HUB)); +} + +#[test] +#[should_panic(expected = "no ica found")] +fn test_distribute_fallback_validates_ica_exists() { + let mut builder = RemoteChainSplitterBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![coin(100_000, DENOM_FALLBACK_ON_HUB.to_string())], + coins(1_000_000, DENOM_NTRN), + ); +} + +#[test] +fn test_distribute_fallback_happy() { + let mut builder = RemoteChainSplitterBuilder::default(); + builder.instantiate_msg.msg.fallback_address = + Some(builder.instantiate_msg.msg.clock_address.to_string()); + let mut suite = builder.build(); + + let splitter_addr = suite.splitter.clone(); + + // fund forwarder to register the ica + suite.fund_contract(&coins(3_000_000, DENOM_NTRN), splitter_addr.clone()); + + // register ica + suite.tick_contract(splitter_addr.clone()); + + let forwarder_ica = suite.query_ica_address(splitter_addr.clone()); + + // fund the ica with sufficient amount of DENOM_FALLBACK_ON_HUB and + suite.fund_contract( + &coins(100_000, DENOM_FALLBACK_ON_HUB), + forwarder_ica.clone(), + ); + suite.fund_contract( + &coins(100_000, DENOM_OSMO_ON_HUB_FROM_NTRN), + forwarder_ica.clone(), + ); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_FALLBACK_ON_HUB)); + suite.assert_balance(&forwarder_ica, coin(100_000, DENOM_OSMO_ON_HUB_FROM_NTRN)); + + // try to distribute fallback denom + suite.distribute_fallback( + vec![ + coin(100_000, DENOM_FALLBACK_ON_HUB.to_string()), + coin(100_000, DENOM_OSMO_ON_HUB_FROM_NTRN), + ], + vec![coin(2_000_000, DENOM_NTRN)], + ); + + // assert that the funds were in fact forwarded + suite.assert_balance(&forwarder_ica, coin(0, DENOM_ATOM_ON_NTRN)); + suite.assert_balance(&forwarder_ica, coin(0, DENOM_OSMO_ON_HUB_FROM_NTRN)); + suite.assert_balance( + suite.clock_addr.to_string(), + coin(100_000, DENOM_FALLBACK_ON_HUB), + ); + suite.assert_balance( + suite.clock_addr.to_string(), + coin(100_000, DENOM_OSMO_ON_HUB_FROM_NTRN), + ); +} diff --git a/unit-tests/src/test_single_party_covenant/test.rs b/unit-tests/src/test_single_party_covenant/test.rs index 29c1f7e9..b0f4d10b 100644 --- a/unit-tests/src/test_single_party_covenant/test.rs +++ b/unit-tests/src/test_single_party_covenant/test.rs @@ -1055,6 +1055,7 @@ fn test_migrate_update_config_with_codes() { next_contract: None, remote_chain_info: Box::new(None), transfer_amount: None, + fallback_address: None, }; let liquid_pooler_migrate_msg = @@ -1075,6 +1076,7 @@ fn test_migrate_update_config_with_codes() { clock_addr: Some(covenant_addr.to_string()), remote_chain_info: None, splits: None, + fallback_address: None, }; let resp = suite diff --git a/unit-tests/src/test_swap_covenant/test.rs b/unit-tests/src/test_swap_covenant/test.rs index 5eb97175..627965d5 100644 --- a/unit-tests/src/test_swap_covenant/test.rs +++ b/unit-tests/src/test_swap_covenant/test.rs @@ -547,6 +547,7 @@ fn test_migrate_update_without_codes() { next_contract: None, remote_chain_info: Box::new(None), transfer_amount: None, + fallback_address: None, }; let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { diff --git a/unit-tests/src/test_two_party_covenant/test.rs b/unit-tests/src/test_two_party_covenant/test.rs index 2607e6fd..1036dfd4 100644 --- a/unit-tests/src/test_two_party_covenant/test.rs +++ b/unit-tests/src/test_two_party_covenant/test.rs @@ -33,6 +33,7 @@ fn test_instantiate_party_a_interchain() { native_denom: DENOM_ATOM_ON_NTRN.to_string(), contribution: coin(10_000, DENOM_ATOM_ON_NTRN), denom_to_pfm_map: BTreeMap::new(), + fallback_address: None, }, ), ) @@ -61,6 +62,7 @@ fn test_instantiate_party_b_interchain() { native_denom: DENOM_ATOM_ON_NTRN.to_string(), contribution: coin(10_000, DENOM_ATOM_ON_NTRN), denom_to_pfm_map: BTreeMap::new(), + fallback_address: None, }, ), ) @@ -102,6 +104,7 @@ fn test_migrate_update_config_party_a_interchain() { native_denom: DENOM_ATOM_ON_NTRN.to_string(), contribution: coin(10_000, DENOM_ATOM_ON_NTRN), denom_to_pfm_map: BTreeMap::new(), + fallback_address: None, }, ), ) @@ -151,6 +154,7 @@ fn test_migrate_update_config_party_a_interchain() { next_contract: None, remote_chain_info: None.into(), transfer_amount: None, + fallback_address: None, }; let mut contract_codes = suite.query_contract_codes(); contract_codes.clock = 1; @@ -285,6 +289,7 @@ fn test_migrate_update_config_party_b_interchain() { native_denom: DENOM_ATOM_ON_NTRN.to_string(), contribution: coin(10_000, DENOM_ATOM_ON_NTRN), denom_to_pfm_map: BTreeMap::new(), + fallback_address: None, }, ), ) @@ -337,6 +342,7 @@ fn test_migrate_update_config_party_b_interchain() { next_contract: None, remote_chain_info: None.into(), transfer_amount: None, + fallback_address: None, }; let mut contract_codes = suite.query_contract_codes(); contract_codes.party_a_forwarder = 1; From 1222928830ed046891cb485244c56f72f0759655 Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 18 Mar 2024 22:16:33 +0100 Subject: [PATCH 33/56] astro liquid pooler validating pair on instantiation instead of on demand pre liquidity provision --- .../astroport-liquid-pooler/src/contract.rs | 46 ++++++------------- .../astroport-liquid-pooler/src/error.rs | 3 -- .../src/test_astroport_liquid_pooler/tests.rs | 26 +++++++++-- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/contracts/astroport-liquid-pooler/src/contract.rs b/contracts/astroport-liquid-pooler/src/contract.rs index ed143463..a8a050e4 100644 --- a/contracts/astroport-liquid-pooler/src/contract.rs +++ b/contracts/astroport-liquid-pooler/src/contract.rs @@ -2,7 +2,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ ensure, to_json_binary, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, - QuerierWrapper, Reply, Response, StdError, StdResult, SubMsg, Uint128, WasmMsg, + Reply, Response, StdError, StdResult, SubMsg, Uint128, WasmMsg, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::{astroport::query_astro_pool_token, withdraw_lp_helper::WithdrawLPMsgs}; @@ -10,12 +10,11 @@ use cw2::set_contract_version; use astroport::{ asset::{Asset, PairInfo}, - factory::PairType, pair::{Cw20HookMsg, ExecuteMsg::ProvideLiquidity, PoolResponse}, DecimalCheckedOps, }; use cw20::Cw20ExecuteMsg; -use cw_utils::parse_reply_instantiate_data; +use cw_utils::parse_reply_execute_data; use crate::{ error::ContractError, @@ -50,6 +49,16 @@ pub fn instantiate( let pool_addr = deps.api.addr_validate(&msg.pool_address)?; let holder_addr = deps.api.addr_validate(&msg.holder_address)?; + // validate that the pool did not migrate to a new pair type + let pool_response: PairInfo = deps + .querier + .query_wasm_smart(pool_addr.to_string(), &astroport::pair::QueryMsg::Pair {})?; + + ensure!( + pool_response.pair_type.eq(&msg.pair_type), + ContractError::PairTypeMismatch {} + ); + // contract starts at Instantiated state CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; @@ -114,10 +123,7 @@ fn try_withdraw( ContractError::WithdrawPercentageRangeError {} ); - let holder_addr = HOLDER_ADDRESS - .load(deps.storage) - .map_err(|_| ContractError::MissingHolderError {})?; - + let holder_addr = HOLDER_ADDRESS.load(deps.storage)?; ensure!(info.sender == holder_addr, ContractError::NotHolder {}); // Query LP position of the LPer @@ -217,21 +223,6 @@ fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> Result Result<(), ContractError> { - let pool_response: PairInfo = - querier.query_wasm_smart(pool, &astroport::pair::QueryMsg::Pair {})?; - - ensure!( - &pool_response.pair_type == pair_type, - ContractError::PairTypeMismatch {} - ); - Ok(()) -} - /// method which attempts to provision liquidity to the pool. /// if both desired asset balances are non-zero, double sided liquidity /// is provided. @@ -239,13 +230,6 @@ fn validate_pair_type( fn try_lp(mut deps: DepsMut, env: Env) -> Result { let lp_config = LP_CONFIG.load(deps.storage)?; - // validate that the pool did not migrate to a new pair type - validate_pair_type( - deps.querier, - lp_config.pool_address.to_string(), - &lp_config.pair_type, - )?; - let pool_response: PoolResponse = deps .querier .query_wasm_smart(&lp_config.pool_address, &astroport::pair::QueryMsg::Pool {})?; @@ -535,7 +519,7 @@ fn handle_double_sided_reply_id( _env: Env, msg: Reply, ) -> Result { - match parse_reply_instantiate_data(msg) { + match parse_reply_execute_data(msg) { Ok(response) => Ok(Response::default() .add_attribute("method", "handle_double_sided_reply_id") .add_attribute( @@ -556,7 +540,7 @@ fn handle_single_sided_reply_id( _env: Env, msg: Reply, ) -> Result { - match parse_reply_instantiate_data(msg) { + match parse_reply_execute_data(msg) { Ok(response) => Ok(Response::default() .add_attribute("method", "handle_single_sided_reply_id") .add_attribute( diff --git a/contracts/astroport-liquid-pooler/src/error.rs b/contracts/astroport-liquid-pooler/src/error.rs index 67f10f19..d002ea46 100644 --- a/contracts/astroport-liquid-pooler/src/error.rs +++ b/contracts/astroport-liquid-pooler/src/error.rs @@ -40,9 +40,6 @@ pub enum ContractError { #[error("Price range error")] PriceRangeError {}, - #[error("Unknown holder address. Migrate update to set it.")] - MissingHolderError {}, - #[error("Pair type mismatch")] PairTypeMismatch {}, diff --git a/unit-tests/src/test_astroport_liquid_pooler/tests.rs b/unit-tests/src/test_astroport_liquid_pooler/tests.rs index c6840558..ab3c8974 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/tests.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/tests.rs @@ -47,6 +47,18 @@ fn test_instantiate_validates_pool_price_config() { .build(); } +#[test] +#[should_panic(expected = "Pair type mismatch")] +fn test_instantiate_validates_pool_pair_type() { + AstroLiquidPoolerBuilder::default() + .with_custom_astroport_pool( + astroport::factory::PairType::Xyk {}, + coin(1_000_000, DENOM_ATOM_ON_NTRN), + coin(1_000_000, DENOM_LS_ATOM_ON_NTRN), + ) + .build(); +} + #[test] #[should_panic(expected = "Withdraw percentage range must belong to range (0.0, 1.0]")] fn test_withdraw_validates_percentage_range_ceiling() { @@ -377,7 +389,11 @@ fn test_provide_liquidity_single_side_asset_b() { suite.liquid_pooler_addr.clone(), ); - suite.tick_contract(suite.liquid_pooler_addr.clone()); + let double_sided_response = suite.tick_contract(suite.liquid_pooler_addr.clone()); + double_sided_response + .assert_event(&Event::new("wasm").add_attribute("method", "double_side_lp")); + double_sided_response + .assert_event(&Event::new("wasm").add_attribute("method", "handle_double_sided_reply_id")); suite.assert_balance( suite.liquid_pooler_addr.clone(), @@ -395,9 +411,11 @@ fn test_provide_liquidity_single_side_asset_b() { } ); - suite - .tick_contract(suite.liquid_pooler_addr.clone()) - .assert_event(&Event::new("wasm").add_attribute("method", "single_side_lp")); + let app_response = suite.tick_contract(suite.liquid_pooler_addr.clone()); + app_response.assert_event(&Event::new("wasm").add_attribute("method", "single_side_lp")); + app_response + .assert_event(&Event::new("wasm").add_attribute("method", "handle_single_sided_reply_id")); + suite.assert_balance( suite.liquid_pooler_addr.clone(), coin(0, DENOM_ATOM_ON_NTRN), From dda2801841da51a8b4ac45f1e7f83d8f3d89cddb Mon Sep 17 00:00:00 2001 From: bekauz Date: Tue, 19 Mar 2024 15:48:43 +0100 Subject: [PATCH 34/56] astroport liquid pooler handles xyk pool single-side liquidity provision by manually swapping & lping --- Cargo.lock | 18 ++ Cargo.toml | 1 + .../astroport-liquid-pooler/src/contract.rs | 266 +++++++++++------- contracts/astroport-liquid-pooler/src/msg.rs | 4 - unit-tests/Cargo.toml | 1 + unit-tests/src/setup/astro_contracts.rs | 54 ++++ unit-tests/src/setup/suite_builder.rs | 35 ++- .../src/test_astroport_liquid_pooler/tests.rs | 195 ++++++++++++- .../src/test_two_party_covenant/test.rs | 4 +- 9 files changed, 468 insertions(+), 110 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0d06f1e..fb243ab0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,6 +78,23 @@ dependencies = [ "thiserror", ] +[[package]] +name = "astroport-pair-concentrated" +version = "1.2.13" +source = "git+https://github.com/astroport-fi/astroport-core.git?rev=700f66d#700f66d677a173686cb15cb9cb8c7a4d20c84ad8" +dependencies = [ + "astroport", + "astroport-factory", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw-utils 0.15.1", + "cw2 0.15.1", + "cw20", + "itertools 0.10.5", + "thiserror", +] + [[package]] name = "astroport-pair-stable" version = "2.1.4" @@ -1904,6 +1921,7 @@ dependencies = [ "astroport-factory", "astroport-native-coin-registry", "astroport-pair", + "astroport-pair-concentrated", "astroport-pair-stable", "astroport-token", "astroport-whitelist", diff --git a/Cargo.toml b/Cargo.toml index 6c43fc1e..3edfffcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,5 +94,6 @@ astroport-whitelist = { git = "https://github.com/astroport-fi/astrop astroport-factory = { git = "https://github.com/astroport-fi/astroport-core.git", rev = "700f66d" } astroport-native-coin-registry = { git = "https://github.com/astroport-fi/astroport-core.git", rev = "700f66d" } astroport-pair-stable = { git = "https://github.com/astroport-fi/astroport-core.git", rev = "700f66d" } +astroport-pair-concentrated = { git = "https://github.com/astroport-fi/astroport-core.git", rev = "700f66d" } astroport-pair = { git = "https://github.com/astroport-fi/astroport-core.git", rev = "700f66d" } unit-tests = { path = "unit-tests" } diff --git a/contracts/astroport-liquid-pooler/src/contract.rs b/contracts/astroport-liquid-pooler/src/contract.rs index a8a050e4..32ca235c 100644 --- a/contracts/astroport-liquid-pooler/src/contract.rs +++ b/contracts/astroport-liquid-pooler/src/contract.rs @@ -2,7 +2,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ ensure, to_json_binary, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, - Reply, Response, StdError, StdResult, SubMsg, Uint128, WasmMsg, + Reply, Response, StdError, StdResult, SubMsg, SubMsgResult, Uint128, WasmMsg, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::{astroport::query_astro_pool_token, withdraw_lp_helper::WithdrawLPMsgs}; @@ -10,11 +10,11 @@ use cw2::set_contract_version; use astroport::{ asset::{Asset, PairInfo}, - pair::{Cw20HookMsg, ExecuteMsg::ProvideLiquidity, PoolResponse}, + factory::PairType, + pair::{Cw20HookMsg, ExecuteMsg::ProvideLiquidity, PoolResponse, SimulationResponse}, DecimalCheckedOps, }; use cw20::Cw20ExecuteMsg; -use cw_utils::parse_reply_execute_data; use crate::{ error::ContractError, @@ -34,6 +34,7 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); const DOUBLE_SIDED_REPLY_ID: u64 = 321u64; const SINGLE_SIDED_REPLY_ID: u64 = 322u64; +const SWAP_REPLY_ID: u64 = 323u64; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( @@ -259,11 +260,11 @@ fn try_lp(mut deps: DepsMut, env: Env) -> Result { match (coin_a.amount.is_zero(), coin_b.amount.is_zero()) { // exactly one balance is non-zero, we attempt single-side (true, false) | (false, true) => { - let single_sided_submsg = + let single_sided_submsgs = try_get_single_side_lp_submsg(deps.branch(), env, (coin_a, coin_b), lp_config)?; - if let Some(msg) = single_sided_submsg { + if !single_sided_submsgs.is_empty() { return Ok(Response::default() - .add_submessage(msg) + .add_submessages(single_sided_submsgs) .add_attribute("method", "single_side_lp")); } } @@ -368,62 +369,146 @@ fn try_get_single_side_lp_submsg( env: Env, (coin_a, coin_b): (Coin, Coin), lp_config: LpConfig, -) -> Result, ContractError> { - let assets = lp_config +) -> Result, ContractError> { + let mut assets = lp_config .asset_data .to_asset_vec(coin_a.amount, coin_b.amount); - // given one non-zero asset, we build the ProvideLiquidity message - let single_sided_liq_msg = ProvideLiquidity { - assets, - slippage_tolerance: lp_config.slippage_tolerance, - auto_stake: Some(false), - receiver: Some(env.contract.address.to_string()), - }; - - // now we try to submit the message for either B or A token single side liquidity - if coin_a.amount.is_zero() && coin_b.amount <= lp_config.single_side_lp_limits.asset_b_limit { - // update the provided liquidity info - PROVIDED_LIQUIDITY_INFO.update(deps.storage, |mut info| -> StdResult<_> { - info.provided_amount_b = info.provided_amount_b.checked_add(coin_b.amount)?; - Ok(info) - })?; + match lp_config.pair_type { + // xyk pools do not allow for automatic single-sided liquidity provision. + // we therefore perform a manual swap with 1/2 of the available denom, and execute + // two-sided lp provision with the resulting assets. + PairType::Xyk {} => { + // find the offer asset and halve its amount. the halved coin amount here is + // the floor of the division result, so it is safe to assume that after the + // swap we will have at least the same amount of the offer asset left. + let (offer_asset, offer_coin, mut ask_asset) = if coin_a.amount.is_zero() { + let halved_coin = Coin { + denom: coin_b.denom.clone(), + amount: coin_b.amount / Uint128::from(2u128), + }; + assets[1].amount /= Uint128::from(2u128); + (assets[1].clone(), halved_coin, assets[0].clone()) + } else { + let halved_coin = Coin { + denom: coin_a.denom.clone(), + amount: coin_a.amount / Uint128::from(2u128), + }; + assets[0].amount /= Uint128::from(2u128); + (assets[0].clone(), halved_coin, assets[1].clone()) + }; + + // we simulate a swap with 1/2 of the offer asset + let simulation: SimulationResponse = deps.querier.query_wasm_smart( + &lp_config.pool_address, + &astroport::pair::QueryMsg::Simulation { + offer_asset: offer_asset.clone(), + ask_asset_info: None, + }, + )?; + ask_asset.amount = simulation.return_amount; + let ask_coin = ask_asset.to_coin()?; - // if available ls token amount is within single side limits we build a single side msg - let submsg = SubMsg::reply_on_success( - CosmosMsg::Wasm(WasmMsg::Execute { + let swap_wasm_msg: CosmosMsg = WasmMsg::Execute { contract_addr: lp_config.pool_address.to_string(), - msg: to_json_binary(&single_sided_liq_msg)?, - funds: vec![coin_b], - }), - SINGLE_SIDED_REPLY_ID, - ); - - return Ok(Some(submsg)); - } - - if coin_b.amount.is_zero() && coin_a.amount <= lp_config.single_side_lp_limits.asset_a_limit { - // update the provided liquidity info - PROVIDED_LIQUIDITY_INFO.update(deps.storage, |mut info| -> StdResult<_> { - info.provided_amount_a = info.provided_amount_a.checked_add(coin_a.amount)?; - Ok(info) - })?; - - // if available A token amount is within single side limits we build a single side msg - let submsg = SubMsg::reply_on_success( - CosmosMsg::Wasm(WasmMsg::Execute { + msg: to_json_binary(&astroport::pair::ExecuteMsg::Swap { + offer_asset: offer_asset.clone(), + max_spread: lp_config.slippage_tolerance, + belief_price: None, + to: None, + ask_asset_info: None, + })?, + funds: vec![offer_coin.clone()], + } + .into(); + + PROVIDED_LIQUIDITY_INFO.update(deps.storage, |mut info| -> StdResult<_> { + if offer_coin.denom == coin_a.denom { + info.provided_amount_a = + info.provided_amount_a.checked_add(offer_coin.amount)?; + info.provided_amount_b = info.provided_amount_b.checked_add(ask_coin.amount)?; + } else { + info.provided_amount_b = + info.provided_amount_b.checked_add(offer_coin.amount)?; + info.provided_amount_a = info.provided_amount_a.checked_add(ask_coin.amount)?; + } + Ok(info) + })?; + + let provide_liquidity_msg: CosmosMsg = WasmMsg::Execute { contract_addr: lp_config.pool_address.to_string(), - msg: to_json_binary(&single_sided_liq_msg)?, - funds: vec![coin_a], - }), - SINGLE_SIDED_REPLY_ID, - ); + msg: to_json_binary(&ProvideLiquidity { + assets: vec![offer_asset, ask_asset], + slippage_tolerance: lp_config.slippage_tolerance, + auto_stake: Some(false), + receiver: Some(env.contract.address.to_string()), + })?, + funds: vec![offer_coin, ask_coin], + } + .into(); + let swap_submsg = SubMsg::reply_on_success(swap_wasm_msg, SWAP_REPLY_ID); + let provide_liquidity_submsg = + SubMsg::reply_on_success(provide_liquidity_msg, DOUBLE_SIDED_REPLY_ID); - return Ok(Some(submsg)); - } + Ok(vec![swap_submsg, provide_liquidity_submsg]) + } + PairType::Stable {} | PairType::Custom(_) => { + // given one non-zero asset, we build the ProvideLiquidity message + let single_sided_liq_msg = ProvideLiquidity { + assets, + slippage_tolerance: lp_config.slippage_tolerance, + auto_stake: Some(false), + receiver: Some(env.contract.address.to_string()), + }; + + // now we try to submit the message for either B or A token single side liquidity + if coin_a.amount.is_zero() + && coin_b.amount <= lp_config.single_side_lp_limits.asset_b_limit + { + // update the provided liquidity info + PROVIDED_LIQUIDITY_INFO.update(deps.storage, |mut info| -> StdResult<_> { + info.provided_amount_b = info.provided_amount_b.checked_add(coin_b.amount)?; + Ok(info) + })?; + + // if available ls token amount is within single side limits we build a single side msg + let submsg = SubMsg::reply_on_success( + CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: lp_config.pool_address.to_string(), + msg: to_json_binary(&single_sided_liq_msg)?, + funds: vec![coin_b], + }), + SINGLE_SIDED_REPLY_ID, + ); + + return Ok(vec![submsg]); + } - // if neither a nor b token single side lp message was built, we just go back and wait - Ok(None) + if coin_b.amount.is_zero() + && coin_a.amount <= lp_config.single_side_lp_limits.asset_a_limit + { + // update the provided liquidity info + PROVIDED_LIQUIDITY_INFO.update(deps.storage, |mut info| -> StdResult<_> { + info.provided_amount_a = info.provided_amount_a.checked_add(coin_a.amount)?; + Ok(info) + })?; + + // if available A token amount is within single side limits we build a single side msg + let submsg = SubMsg::reply_on_success( + CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: lp_config.pool_address.to_string(), + msg: to_json_binary(&single_sided_liq_msg)?, + funds: vec![coin_a], + }), + SINGLE_SIDED_REPLY_ID, + ); + + return Ok(vec![submsg]); + } + // if neither a nor b token single side lp message was built, we just go back and wait + Ok(vec![]) + } + } } /// filters out irrelevant balances and returns a and b token amounts @@ -504,54 +589,37 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> NeutronResult Result { - match msg.id { - DOUBLE_SIDED_REPLY_ID => handle_double_sided_reply_id(deps, _env, msg), - SINGLE_SIDED_REPLY_ID => handle_single_sided_reply_id(deps, _env, msg), - _ => Err(ContractError::from(StdError::GenericErr { - msg: "err".to_string(), - })), +pub fn reply(_deps: DepsMut, _env: Env, msg: Reply) -> Result { + match msg.result { + SubMsgResult::Ok(val) => { + // astroport only sets SubMsgResponse data in case it's a multi-hop swap. + // we only deal with direct swaps so we ignore the data. + let response = Response::default() + .add_attribute("reply_id", msg.id.to_string()) + .add_events(val.events); + + match msg.id { + DOUBLE_SIDED_REPLY_ID => handle_double_sided_reply_id(response), + SINGLE_SIDED_REPLY_ID => handle_single_sided_reply_id(response), + SWAP_REPLY_ID => handle_swap_reply_id(response), + _ => Err(ContractError::from(StdError::generic_err(format!( + "unknown reply id: {}", + msg.id + )))), + } + } + SubMsgResult::Err(e) => Err(ContractError::from(StdError::generic_err(e))), } } -fn handle_double_sided_reply_id( - _deps: DepsMut, - _env: Env, - msg: Reply, -) -> Result { - match parse_reply_execute_data(msg) { - Ok(response) => Ok(Response::default() - .add_attribute("method", "handle_double_sided_reply_id") - .add_attribute( - "response", - match response.data { - Some(val) => val.to_base64(), - None => "none".to_string(), - }, - )), - Err(err) => Ok(Response::default() - .add_attribute("method", "handle_double_sided_reply_id") - .add_attribute("error", err.to_string())), - } +fn handle_swap_reply_id(response: Response) -> Result { + Ok(response.add_attribute("method", "handle_swap_reply_id")) } -fn handle_single_sided_reply_id( - _deps: DepsMut, - _env: Env, - msg: Reply, -) -> Result { - match parse_reply_execute_data(msg) { - Ok(response) => Ok(Response::default() - .add_attribute("method", "handle_single_sided_reply_id") - .add_attribute( - "response", - match response.data { - Some(val) => val.to_base64(), - None => "none".to_string(), - }, - )), - Err(err) => Ok(Response::default() - .add_attribute("method", "handle_single_sided_reply_id") - .add_attribute("error", err.to_string())), - } +fn handle_double_sided_reply_id(response: Response) -> Result { + Ok(response.add_attribute("method", "handle_double_sided_reply_id")) +} + +fn handle_single_sided_reply_id(response: Response) -> Result { + Ok(response.add_attribute("method", "handle_single_sided_reply_id")) } diff --git a/contracts/astroport-liquid-pooler/src/msg.rs b/contracts/astroport-liquid-pooler/src/msg.rs index a47fc88c..151a42b2 100644 --- a/contracts/astroport-liquid-pooler/src/msg.rs +++ b/contracts/astroport-liquid-pooler/src/msg.rs @@ -84,10 +84,6 @@ pub struct DecimalRange { } impl DecimalRange { - pub fn new(min: Decimal, max: Decimal) -> Self { - DecimalRange { min, max } - } - pub fn try_from(mid: Decimal, delta: Decimal) -> Result { Ok(DecimalRange { min: mid.checked_sub(delta)?, diff --git a/unit-tests/Cargo.toml b/unit-tests/Cargo.toml index 31ecc68d..b780dfb4 100644 --- a/unit-tests/Cargo.toml +++ b/unit-tests/Cargo.toml @@ -48,5 +48,6 @@ astroport-factory = { workspace = true } astroport-native-coin-registry = { workspace = true } astroport-pair-stable = { workspace = true } astroport-pair = { workspace = true } +astroport-pair-concentrated = { workspace = true } osmosis-std = "0.13.2" diff --git a/unit-tests/src/setup/astro_contracts.rs b/unit-tests/src/setup/astro_contracts.rs index d2223ffc..5d6937be 100644 --- a/unit-tests/src/setup/astro_contracts.rs +++ b/unit-tests/src/setup/astro_contracts.rs @@ -178,6 +178,60 @@ pub fn astro_pair_stable_contract() -> Box Box> { + let exec = |deps: DepsMut, + env: Env, + info: MessageInfo, + msg: astroport::pair::ExecuteMsg| { + execute_into_neutron(astroport_pair_concentrated::contract::execute( + get_empty_depsmut(deps), + env, + info, + msg, + )) + }; + + let init = |deps: DepsMut, + env: Env, + info: MessageInfo, + msg: astroport::pair::InstantiateMsg| { + execute_into_neutron(astroport_pair_concentrated::contract::instantiate( + get_empty_depsmut(deps), + env, + info, + msg, + )) + }; + + let query = + |deps: Deps, env: Env, msg: astroport::pair_concentrated::QueryMsg| { + astroport_pair_concentrated::queries::query(get_empty_deps(deps), env, msg) + }; + + let migrate = + |deps: DepsMut, env: Env, msg: astroport::pair_concentrated::MigrateMsg| { + execute_into_neutron(astroport_pair_concentrated::contract::migrate( + get_empty_depsmut(deps), + env, + msg, + )) + }; + + let reply = |deps: DepsMut, env: Env, reply: Reply| { + execute_into_neutron(astroport_pair_concentrated::contract::reply( + get_empty_depsmut(deps), + env, + reply, + )) + }; + + Box::new( + ContractWrapper::new(exec, init, query) + .with_migrate(migrate) + .with_reply(reply), + ) +} + pub fn astro_pair_xyk_contract() -> Box> { let exec = |deps: DepsMut, env: Env, diff --git a/unit-tests/src/setup/suite_builder.rs b/unit-tests/src/setup/suite_builder.rs index 4c8c2217..f4188cc1 100644 --- a/unit-tests/src/setup/suite_builder.rs +++ b/unit-tests/src/setup/suite_builder.rs @@ -1,6 +1,10 @@ +use std::str::FromStr; + +use astroport::pair_concentrated::ConcentratedPoolParams; use cosmwasm_schema::serde::Serialize; use cosmwasm_std::{ - coin, coins, instantiate2_address, to_json_binary, Addr, Api, CodeInfoResponse, Coin, Empty, + coin, coins, instantiate2_address, to_json_binary, Addr, Api, CodeInfoResponse, Coin, Decimal, + Empty, }; use cw_multi_test::{ addons::{MockAddressGenerator, MockApiBech32}, @@ -11,7 +15,8 @@ use sha2::{Digest, Sha256}; use super::{ astro_contracts::{ - astro_coin_registry_contract, astro_factory_contract, astro_pair_stable_contract, + astro_coin_registry_contract, astro_factory_contract, + astro_pair_custom_concentrated_contract, astro_pair_stable_contract, astro_pair_xyk_contract, astro_token_contract, astro_whitelist_contract, }, contracts::{ @@ -64,6 +69,7 @@ pub struct SuiteBuilder { pub astro_pair_stable_code_id: u64, pub astro_pair_xyk_code_id: u64, pub astro_coin_registry_code_id: u64, + pub astro_pair_concentrated_code_id: u64, } impl Default for SuiteBuilder { fn default() -> Self { @@ -132,6 +138,8 @@ impl SuiteBuilder { let astro_factory_code_id = app.store_code(astro_factory_contract()); let astro_pair_stable_code_id = app.store_code(astro_pair_stable_contract()); let astro_pair_xyk_code_id = app.store_code(astro_pair_xyk_contract()); + let astro_pair_concentrated_code_id = + app.store_code(astro_pair_custom_concentrated_contract()); let astro_coin_registry_code_id = app.store_code(astro_coin_registry_contract()); let two_party_covenant_code_id = app.store_code(two_party_covenant_contract()); @@ -166,6 +174,7 @@ impl SuiteBuilder { astro_pair_stable_code_id, astro_pair_xyk_code_id, astro_coin_registry_code_id, + astro_pair_concentrated_code_id, } } @@ -224,6 +233,14 @@ impl SuiteBuilder { is_disabled: false, is_generator_disabled: true, }, + astroport::factory::PairConfig { + code_id: self.astro_pair_concentrated_code_id, + pair_type: astroport::factory::PairType::Custom("concentrated".to_string()), + total_fee_bps: 0, + maker_fee_bps: 0, + is_disabled: false, + is_generator_disabled: false, + }, ], token_code_id: self.astro_token_code_id, fee_address: None, @@ -269,7 +286,19 @@ impl SuiteBuilder { .unwrap() } astroport::factory::PairType::Custom(_) => { - panic!("suite-builder: custom pair type is not supported") + let default_params = ConcentratedPoolParams { + amp: Decimal::from_ratio(40u128, 1u128), + gamma: Decimal::from_ratio(145u128, 1000000u128), + mid_fee: Decimal::from_str("0.0026").unwrap(), + out_fee: Decimal::from_str("0.0045").unwrap(), + fee_gamma: Decimal::from_ratio(23u128, 100000u128), + repeg_profit_threshold: Decimal::from_ratio(2u128, 1000000u128), + min_price_scale_delta: Decimal::from_ratio(146u128, 1000000u128), + price_scale: Decimal::one(), + ma_half_time: 600, + track_asset_balances: None, + }; + to_json_binary(&default_params).unwrap() } }; diff --git a/unit-tests/src/test_astroport_liquid_pooler/tests.rs b/unit-tests/src/test_astroport_liquid_pooler/tests.rs index ab3c8974..92f96865 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/tests.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/tests.rs @@ -38,7 +38,7 @@ fn test_instantiate_validates_holder_address() { #[test] #[should_panic(expected = "Cannot Sub with 1 and 2")] -fn test_instantiate_validates_pool_price_config() { +fn test_instantiate_validates_pool_price_config_upper_bound() { AstroLiquidPoolerBuilder::default() .with_pool_price_config(PoolPriceConfig { expected_spot_price: Decimal::from_str("1.0").unwrap(), @@ -47,6 +47,17 @@ fn test_instantiate_validates_pool_price_config() { .build(); } +#[test] +#[should_panic(expected = "Cannot Sub with 0.5 and 0.6")] +fn test_instantiate_validates_pool_price_config_lower_bound() { + AstroLiquidPoolerBuilder::default() + .with_pool_price_config(PoolPriceConfig { + expected_spot_price: Decimal::from_str("0.5").unwrap(), + acceptable_price_spread: Decimal::from_str("0.6").unwrap(), + }) + .build(); +} + #[test] #[should_panic(expected = "Pair type mismatch")] fn test_instantiate_validates_pool_pair_type() { @@ -284,7 +295,7 @@ fn test_provide_liquidity_no_assets() { } #[test] -fn test_provide_liquidity_single_side_asset_a() { +fn test_provide_stable_liquidity_single_side_asset_a() { let mut suite = AstroLiquidPoolerBuilder::default().build(); suite.fund_contract( @@ -334,6 +345,186 @@ fn test_provide_liquidity_single_side_asset_a() { ); } +#[test] +fn test_provide_custom_concentrated_liquidity_single_side_asset_a() { + let custom_concentrated_pair_type = + astroport::factory::PairType::Custom("concentrated".to_string()); + let mut suite = AstroLiquidPoolerBuilder::default() + .with_custom_astroport_pool( + custom_concentrated_pair_type.clone(), + coin(1_000_000_000, DENOM_ATOM_ON_NTRN), + coin(1_000_000_000, DENOM_LS_ATOM_ON_NTRN), + ) + .with_pair_type(custom_concentrated_pair_type) + .build(); + + suite.fund_contract( + &coins(570_000, DENOM_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + suite.fund_contract( + &coins(500_000, DENOM_LS_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + + suite.tick_contract(suite.liquid_pooler_addr.clone()); + + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(70_000, DENOM_ATOM_ON_NTRN), + ); + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_LS_ATOM_ON_NTRN), + ); + assert_eq!( + suite.query_provided_liquidity_info(), + ProvidedLiquidityInfo { + provided_amount_a: Uint128::new(500_000), + provided_amount_b: Uint128::new(500_000) + } + ); + + suite + .tick_contract(suite.liquid_pooler_addr.clone()) + .assert_event(&Event::new("wasm").add_attribute("method", "single_side_lp")); + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_ATOM_ON_NTRN), + ); + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_LS_ATOM_ON_NTRN), + ); + assert_eq!( + suite.query_provided_liquidity_info(), + ProvidedLiquidityInfo { + provided_amount_a: Uint128::new(570_000), + provided_amount_b: Uint128::new(500_000) + } + ); +} + +#[test] +fn test_provide_xyk_liquidity_single_side_asset_a() { + let mut suite = AstroLiquidPoolerBuilder::default() + .with_custom_astroport_pool( + astroport::factory::PairType::Xyk {}, + coin(1_000_000_000, DENOM_ATOM_ON_NTRN), + coin(1_000_000_000, DENOM_LS_ATOM_ON_NTRN), + ) + .with_pair_type(astroport::factory::PairType::Xyk {}) + .build(); + + suite.fund_contract( + &coins(570_000, DENOM_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + suite.fund_contract( + &coins(500_000, DENOM_LS_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + + // first tick double-side lps + suite.tick_contract(suite.liquid_pooler_addr.clone()); + + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(70_000, DENOM_ATOM_ON_NTRN), + ); + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_LS_ATOM_ON_NTRN), + ); + assert_eq!( + suite.query_provided_liquidity_info(), + ProvidedLiquidityInfo { + provided_amount_a: Uint128::new(500_000), + provided_amount_b: Uint128::new(500_000) + } + ); + + // second tick swaps and then double side lps + suite.tick_contract(suite.liquid_pooler_addr.clone()); + + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_ATOM_ON_NTRN), + ); + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_LS_ATOM_ON_NTRN), + ); + + let provided_liquidity_info = suite.query_provided_liquidity_info(); + assert_eq!( + provided_liquidity_info.provided_amount_a, + Uint128::new(500_000 + 70_000 / 2) + ); + // minus fees + assert!(provided_liquidity_info.provided_amount_b > Uint128::new(534_000)); +} + +#[test] +fn test_provide_xyk_liquidity_single_side_asset_b() { + let mut suite = AstroLiquidPoolerBuilder::default() + .with_custom_astroport_pool( + astroport::factory::PairType::Xyk {}, + coin(1_000_000_000, DENOM_ATOM_ON_NTRN), + coin(1_000_000_000, DENOM_LS_ATOM_ON_NTRN), + ) + .with_pair_type(astroport::factory::PairType::Xyk {}) + .build(); + + suite.fund_contract( + &coins(570_000, DENOM_LS_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + suite.fund_contract( + &coins(500_000, DENOM_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + + // first tick double-side lps + suite.tick_contract(suite.liquid_pooler_addr.clone()); + + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(70_000, DENOM_LS_ATOM_ON_NTRN), + ); + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_ATOM_ON_NTRN), + ); + assert_eq!( + suite.query_provided_liquidity_info(), + ProvidedLiquidityInfo { + provided_amount_a: Uint128::new(500_000), + provided_amount_b: Uint128::new(500_000) + } + ); + + // second tick swaps and then double side lps + suite.tick_contract(suite.liquid_pooler_addr.clone()); + + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_ATOM_ON_NTRN), + ); + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_LS_ATOM_ON_NTRN), + ); + + let provided_liquidity_info = suite.query_provided_liquidity_info(); + assert_eq!( + provided_liquidity_info.provided_amount_b, + Uint128::new(500_000 + 70_000 / 2) + ); + // minus fees + assert!(provided_liquidity_info.provided_amount_a > Uint128::new(534_000)); +} + #[test] fn test_provide_liquidity_single_side_asset_a_exceeds_limits() { let mut suite = AstroLiquidPoolerBuilder::default().build(); diff --git a/unit-tests/src/test_two_party_covenant/test.rs b/unit-tests/src/test_two_party_covenant/test.rs index 1036dfd4..993deb4f 100644 --- a/unit-tests/src/test_two_party_covenant/test.rs +++ b/unit-tests/src/test_two_party_covenant/test.rs @@ -159,7 +159,7 @@ fn test_migrate_update_config_party_a_interchain() { let mut contract_codes = suite.query_contract_codes(); contract_codes.clock = 1; let resp = suite.migrate_update( - 21, + 22, covenant_two_party_pol::msg::MigrateMsg::UpdateCovenant { codes: Some(contract_codes.clone()), clock: None, @@ -348,7 +348,7 @@ fn test_migrate_update_config_party_b_interchain() { contract_codes.party_a_forwarder = 1; let resp = suite.migrate_update( - 21, + 22, covenant_two_party_pol::msg::MigrateMsg::UpdateCovenant { codes: Some(contract_codes.clone()), clock: Some(clock_migrate_msg.clone()), From 08d864a6ec1eefe6bf6fb034ea52c4dac3b357c1 Mon Sep 17 00:00:00 2001 From: bekauz Date: Tue, 19 Mar 2024 21:29:24 +0100 Subject: [PATCH 35/56] soft remote chain address validation in interchain-router and remote-chain-splitter --- Cargo.lock | 1 + contracts/interchain-router/src/contract.rs | 5 +-- .../src/suite_tests/suite.rs | 24 ++++++++-- .../src/suite_tests/tests.rs | 19 ++++---- .../remote-chain-splitter/src/contract.rs | 3 +- .../stride-liquid-staker/src/contract.rs | 10 ----- contracts/swap-covenant/src/contract.rs | 2 +- contracts/swap-covenant/src/msg.rs | 2 +- .../single-party-pol/single_party_pol_test.go | 2 +- .../two-party-pol/two_party_osmo_pol_test.go | 6 +-- .../two_party_pol_native_test.go | 4 +- .../two-party-pol/two_party_pol_test.go | 26 +++++------ packages/covenant-utils/Cargo.toml | 1 + packages/covenant-utils/src/lib.rs | 44 +++++++++++++++++-- .../src/test_single_party_covenant/test.rs | 12 ++++- unit-tests/src/test_swap_covenant/test.rs | 4 +- 16 files changed, 110 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fb243ab0..02016fcc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -733,6 +733,7 @@ name = "covenant-utils" version = "1.0.0" dependencies = [ "astroport", + "bech32", "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", diff --git a/contracts/interchain-router/src/contract.rs b/contracts/interchain-router/src/contract.rs index 875b250a..185f29fe 100644 --- a/contracts/interchain-router/src/contract.rs +++ b/contracts/interchain-router/src/contract.rs @@ -7,7 +7,7 @@ use cosmwasm_std::{ StdResult, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; -use covenant_utils::sum_fees; +use covenant_utils::{soft_validate_remote_chain_addr, sum_fees}; use cw2::set_contract_version; use cw_utils::must_pay; use neutron_sdk::{ @@ -41,8 +41,7 @@ pub fn instantiate( set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; let clock_address = deps.api.addr_validate(&msg.clock_address)?; - deps.api - .addr_validate(&msg.destination_config.destination_receiver_addr)?; + soft_validate_remote_chain_addr(deps.api, &msg.destination_config.destination_receiver_addr)?; CLOCK_ADDRESS.save(deps.storage, &clock_address)?; DESTINATION_CONFIG.save(deps.storage, &msg.destination_config)?; diff --git a/contracts/interchain-router/src/suite_tests/suite.rs b/contracts/interchain-router/src/suite_tests/suite.rs index a7ccd2e5..96c31507 100644 --- a/contracts/interchain-router/src/suite_tests/suite.rs +++ b/contracts/interchain-router/src/suite_tests/suite.rs @@ -16,8 +16,7 @@ use neutron_sdk::bindings::{msg::NeutronMsg, query::NeutronQuery}; use super::mock_clock_neutron_deps_contract; pub const ADMIN: &str = "admin"; -pub const DEFAULT_RECEIVER: &str = "receiver"; -pub const CLOCK_ADDR: &str = "clock"; +pub const CLOCK_ADDR: &str = "neutron19yz8hu6dand9lchzrcwezug763h770cv8sfen7kc7gw0jtdqha8qsl7tp9"; pub const DEFAULT_CHANNEL: &str = "channel-1"; fn router_contract() -> Box> { @@ -46,6 +45,7 @@ type CustomApp = App< pub struct Suite { pub app: CustomApp, pub router: Addr, + pub destination_addr: Addr, } pub struct SuiteBuilder { @@ -55,12 +55,19 @@ pub struct SuiteBuilder { impl Default for SuiteBuilder { fn default() -> Self { + let hrp = "cosmos"; + + let canonical_address: Vec = vec![1; 90]; + let base32_address = bech32::ToBase32::to_base32(&canonical_address); + let destination_address = + bech32::encode(hrp, base32_address, bech32::Variant::Bech32).unwrap(); + Self { instantiate: InstantiateMsg { clock_address: CLOCK_ADDR.to_string(), destination_config: DestinationConfig { local_to_destination_chain_channel_id: DEFAULT_CHANNEL.to_string(), - destination_receiver_addr: DEFAULT_RECEIVER.to_string(), + destination_receiver_addr: destination_address.to_string(), ibc_transfer_timeout: Uint64::new(10), denom_to_pfm_map: BTreeMap::new(), }, @@ -82,6 +89,7 @@ impl SuiteBuilder { pub fn build(mut self) -> Suite { let mut app = BasicAppBuilder::::new_custom() .with_ibc(IbcAcceptingModule::new()) + .with_api(MockApi::default().with_prefix("cosmos")) .build(|_, _, _| ()); let router_code = app.store_code(router_contract()); @@ -113,7 +121,15 @@ impl SuiteBuilder { ) .unwrap(); - Suite { app, router } + Suite { + app, + router, + destination_addr: Addr::unchecked( + self.instantiate + .destination_config + .destination_receiver_addr, + ), + } } } diff --git a/contracts/interchain-router/src/suite_tests/tests.rs b/contracts/interchain-router/src/suite_tests/tests.rs index 5848d21e..5bae4d8f 100644 --- a/contracts/interchain-router/src/suite_tests/tests.rs +++ b/contracts/interchain-router/src/suite_tests/tests.rs @@ -19,7 +19,7 @@ use neutron_sdk::{ use crate::{ contract::{execute, instantiate}, msg::MigrateMsg, - suite_tests::suite::{DEFAULT_CHANNEL, DEFAULT_RECEIVER}, + suite_tests::suite::DEFAULT_CHANNEL, }; use super::suite::{SuiteBuilder, CLOCK_ADDR}; @@ -36,7 +36,7 @@ fn test_instantiate_and_query_all() { assert_eq!( DestinationConfig { local_to_destination_chain_channel_id: DEFAULT_CHANNEL.to_string(), - destination_receiver_addr: DEFAULT_RECEIVER.to_string(), + destination_receiver_addr: suite.destination_addr.to_string(), ibc_transfer_timeout: Uint64::new(10), denom_to_pfm_map: BTreeMap::new(), }, @@ -211,8 +211,8 @@ fn test_tick() { to_json_binary(&MinIbcFeeResponse { min_fee: IbcFee { recv_fee: vec![], - ack_fee: vec![coin(100000, "untrn")], - timeout_fee: vec![coin(100000, "untrn")], + ack_fee: vec![coin(100_000, "untrn")], + timeout_fee: vec![coin(100_000, "untrn")], }, }) .into(), @@ -230,13 +230,12 @@ fn test_tick() { let info = mock_info(CLOCK_ADDR, &[coin(10000000, "untrn")]); + let sb = SuiteBuilder::default().with_denoms(vec!["usdc".to_string()]); instantiate( deps.as_mut(), mock_env(), info.clone(), - SuiteBuilder::default() - .with_denoms(vec!["usdc".to_string()]) - .instantiate, + sb.instantiate.clone(), ) .unwrap(); @@ -337,7 +336,11 @@ fn test_tick() { source_channel: "channel-1".to_string(), token: cosmwasm_std::Coin::new(100, "denom1".to_string()), sender: "cosmos2contract".to_string(), - receiver: "receiver".to_string(), + receiver: sb + .instantiate + .destination_config + .destination_receiver_addr + .to_string(), timeout_height: RequestPacketTimeoutHeight { revision_number: None, revision_height: None diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index 727af325..223ae109 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -15,7 +15,7 @@ use covenant_utils::neutron::{ get_ictxs_module_params_query_msg, get_proto_coin, QueryParamsResponse, RemoteChainInfo, SudoPayload, }; -use covenant_utils::{neutron, sum_fees}; +use covenant_utils::{neutron, soft_validate_remote_chain_addr, sum_fees}; use cw2::set_contract_version; use cw_utils::must_pay; use neutron_sdk::bindings::types::ProtobufAny; @@ -70,6 +70,7 @@ pub fn instantiate( CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; TRANSFER_AMOUNT.save(deps.storage, &msg.amount)?; if let Some(addr) = &msg.fallback_address { + soft_validate_remote_chain_addr(deps.api, addr)?; FALLBACK_ADDRESS.save(deps.storage, addr)?; } diff --git a/contracts/stride-liquid-staker/src/contract.rs b/contracts/stride-liquid-staker/src/contract.rs index 1a1c6e53..8a8eaab3 100644 --- a/contracts/stride-liquid-staker/src/contract.rs +++ b/contracts/stride-liquid-staker/src/contract.rs @@ -245,7 +245,6 @@ pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult Ok(to_json_binary(&REMOTE_CHAIN_INFO.may_load(deps.storage)?)?) } QueryMsg::NextMemo {} => { - // let next_contract = NEXT_CONTRACT.load(deps.storage)?; // 1. receiver = query ICA let ica = get_ica(deps, &env, INTERCHAIN_ACCOUNT_ID)?.0; @@ -266,15 +265,6 @@ pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult } } -fn _query_deposit_address(deps: Deps, env: Env) -> Result, StdError> { - let key = get_port_id(env.contract.address.as_str(), INTERCHAIN_ACCOUNT_ID); - - // here we cover three cases: - INTERCHAIN_ACCOUNTS - .may_load(deps.storage, key) - .map(|entry| entry.flatten().map(|x| x.0)) -} - #[cfg_attr(not(feature = "library"), entry_point)] pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> Result, StdError> { match msg { diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index f7202fde..e315d950 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -436,7 +436,7 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult }); } - if let Some(forwarder) = party_a_forwarder { + if let Some(forwarder) = *party_a_forwarder { let msg: Binary = to_json_binary(&forwarder)?; resp = resp.add_attribute("party_a_forwarder_migrate", msg.to_base64()); migrate_msgs.push(WasmMsg::Migrate { diff --git a/contracts/swap-covenant/src/msg.rs b/contracts/swap-covenant/src/msg.rs index 807634d6..d935e852 100644 --- a/contracts/swap-covenant/src/msg.rs +++ b/contracts/swap-covenant/src/msg.rs @@ -203,7 +203,7 @@ pub enum MigrateMsg { splitter: Option, party_a_router: Option, party_b_router: Option, - party_a_forwarder: Option, + party_a_forwarder: Box>, party_b_forwarder: Box>, }, UpdateCodeId { diff --git a/interchaintest/single-party-pol/single_party_pol_test.go b/interchaintest/single-party-pol/single_party_pol_test.go index 4f7e37c5..26503b90 100644 --- a/interchaintest/single-party-pol/single_party_pol_test.go +++ b/interchaintest/single-party-pol/single_party_pol_test.go @@ -951,7 +951,7 @@ func TestSinglePartyPol(t *testing.T) { println("holderLpTokenBal: ", holderLpTokenBal) println("neutronUserLpTokenBal: ", neutronUserLpTokenBal) - if liquidPoolerLpTokenBal == 0 { + if neutronUserLpTokenBal == 0 { testCtx.TickStride(clockAddress, keyring.BackendTest, neutronUser.KeyName) } else { break diff --git a/interchaintest/two-party-pol/two_party_osmo_pol_test.go b/interchaintest/two-party-pol/two_party_osmo_pol_test.go index abd06d09..417ca025 100644 --- a/interchaintest/two-party-pol/two_party_osmo_pol_test.go +++ b/interchaintest/two-party-pol/two_party_osmo_pol_test.go @@ -498,7 +498,7 @@ func TestTwoPartyOsmoPol(t *testing.T) { currentHeight := testCtx.GetNeutronHeight() depositBlock := Block(currentHeight + 200) - lockupBlock := Block(currentHeight + 200) + lockupBlock := Block(currentHeight + 210) lockupConfig := Expiration{ AtHeight: &lockupBlock, } @@ -541,13 +541,13 @@ func TestTwoPartyOsmoPol(t *testing.T) { } denomSplits := map[string]SplitConfig{ - neutronAtomIbcDenom: SplitConfig{ + neutronAtomIbcDenom: { Receivers: map[string]string{ hubReceiverAddr: "0.5", osmoReceiverAddr: "0.5", }, }, - neutronOsmoIbcDenom: SplitConfig{ + neutronOsmoIbcDenom: { Receivers: map[string]string{ hubReceiverAddr: "0.5", osmoReceiverAddr: "0.5", diff --git a/interchaintest/two-party-pol/two_party_pol_native_test.go b/interchaintest/two-party-pol/two_party_pol_native_test.go index 0761b18d..38d83aa1 100644 --- a/interchaintest/two-party-pol/two_party_pol_native_test.go +++ b/interchaintest/two-party-pol/two_party_pol_native_test.go @@ -435,7 +435,7 @@ func TestTwoPartyNativePartyPol(t *testing.T) { currentHeight := testCtx.GetNeutronHeight() depositBlock = Block(currentHeight + 110) - lockupBlock = Block(currentHeight + 110) + lockupBlock = Block(currentHeight + 130) lockupConfig := Expiration{ AtHeight: &lockupBlock, @@ -1330,7 +1330,7 @@ func TestTwoPartyNativePartyPol(t *testing.T) { currentHeight := testCtx.GetNeutronHeight() depositBlock := Block(currentHeight + 180) - lockupBlock := Block(currentHeight + 180) + lockupBlock := Block(currentHeight + 200) lockupConfig := Expiration{ AtHeight: &lockupBlock, } diff --git a/interchaintest/two-party-pol/two_party_pol_test.go b/interchaintest/two-party-pol/two_party_pol_test.go index 85046ea6..e87280a8 100644 --- a/interchaintest/two-party-pol/two_party_pol_test.go +++ b/interchaintest/two-party-pol/two_party_pol_test.go @@ -513,7 +513,7 @@ func TestTwoPartyPol(t *testing.T) { currentHeight := testCtx.GetNeutronHeight() depositBlock = Block(currentHeight + 180) - lockupBlock = Block(currentHeight + 180) + lockupBlock = Block(currentHeight + 200) lockupConfig := Expiration{ AtHeight: &lockupBlock, @@ -706,7 +706,7 @@ func TestTwoPartyPol(t *testing.T) { t.Run("tick until holder sends funds to LiquidPooler and receives LP tokens in return", func(t *testing.T) { for { - if testCtx.QueryLpTokenBalance(liquidityTokenAddress, holderAddress) == 0 { + if testCtx.QueryLpTokenBalance(liquidityTokenAddress, liquidPoolerAddress) == 0 { testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) } else { break @@ -999,11 +999,11 @@ func TestTwoPartyPol(t *testing.T) { } }) - t.Run("tick until holder sends funds to LPer and receives LP tokens in return", func(t *testing.T) { + t.Run("tick until holder sends funds to LPer and liquidity is provided", func(t *testing.T) { for { - holderLpTokenBal := testCtx.QueryLpTokenBalance(liquidityTokenAddress, holderAddress) + lperLpTokenBal := testCtx.QueryLpTokenBalance(liquidityTokenAddress, liquidPoolerAddress) - if holderLpTokenBal == 0 { + if lperLpTokenBal == 0 { testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) } else { break @@ -1295,12 +1295,12 @@ func TestTwoPartyPol(t *testing.T) { } }) - t.Run("tick until holder sends the funds to LPer and receives LP tokens in return", func(t *testing.T) { + t.Run("tick until holder sends the funds to LPer it provides liquidity", func(t *testing.T) { for { - holderLpTokenBal := testCtx.QueryLpTokenBalance(liquidityTokenAddress, holderAddress) - println("holder lp token balance: ", holderLpTokenBal) + lperLpTokenBal := testCtx.QueryLpTokenBalance(liquidityTokenAddress, liquidPoolerAddress) + println("liquid pooler lp token balance: ", lperLpTokenBal) - if holderLpTokenBal == 0 { + if lperLpTokenBal == 0 { testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) } else { break @@ -1555,12 +1555,12 @@ func TestTwoPartyPol(t *testing.T) { } }) - t.Run("tick until holder sends the funds to LPer and receives LP tokens in return", func(t *testing.T) { + t.Run("tick until holder sends the funds to LPer and it provides liquidity", func(t *testing.T) { for { - holderLpTokenBal := testCtx.QueryLpTokenBalance(liquidityTokenAddress, holderAddress) - println("holder lp token balance: ", holderLpTokenBal) + lperLpTokenBal := testCtx.QueryLpTokenBalance(liquidityTokenAddress, liquidPoolerAddress) + println("liquid pooler lp token balance: ", lperLpTokenBal) - if holderLpTokenBal == 0 { + if lperLpTokenBal == 0 { testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) } else { break diff --git a/packages/covenant-utils/Cargo.toml b/packages/covenant-utils/Cargo.toml index 016e9d88..7a627de9 100644 --- a/packages/covenant-utils/Cargo.toml +++ b/packages/covenant-utils/Cargo.toml @@ -21,3 +21,4 @@ astroport = { workspace = true } polytone = "1.0.0" covenant-macros = { workspace = true } sha2 = { workspace = true } +bech32 = { workspace = true } diff --git a/packages/covenant-utils/src/lib.rs b/packages/covenant-utils/src/lib.rs index 20e4cb63..6261caf2 100644 --- a/packages/covenant-utils/src/lib.rs +++ b/packages/covenant-utils/src/lib.rs @@ -94,11 +94,19 @@ pub struct CovenantParty { } impl CovenantParty { - pub fn validate_addresses(&self, api: &dyn Api) -> StdResult { + pub fn validate_receiver_address(&self, api: &dyn Api) -> StdResult { match &self.receiver_config { ReceiverConfig::Native(addr) => api.addr_validate(addr), ReceiverConfig::Ibc(destination_config) => { - api.addr_validate(&destination_config.destination_receiver_addr) + match soft_validate_remote_chain_addr( + api, + &destination_config.destination_receiver_addr, + ) { + Ok(_) => Ok(Addr::unchecked( + &destination_config.destination_receiver_addr, + )), + Err(e) => Err(e), + } } } } @@ -144,8 +152,8 @@ impl CovenantPartiesConfig { } pub fn validate_party_addresses(&self, api: &dyn Api) -> StdResult<()> { - self.party_a.validate_addresses(api)?; - self.party_b.validate_addresses(api)?; + self.party_a.validate_receiver_address(api)?; + self.party_b.validate_receiver_address(api)?; Ok(()) } } @@ -366,3 +374,31 @@ pub struct PoolPriceConfig { pub expected_spot_price: Decimal, pub acceptable_price_spread: Decimal, } + +/// soft validation for addresses on remote chains. +/// skips the bech32 prefix and variant checks. +pub fn soft_validate_remote_chain_addr(api: &dyn Api, addr: &str) -> StdResult<()> { + let (_prefix, decoded, _variant) = bech32::decode(addr).map_err(|e| { + StdError::generic_err(format!( + "soft_addr_validation for address {:?} failed to bech32 decode: {:?}", + addr, + e.to_string() + )) + })?; + let decoded_bytes = as bech32::FromBase32>::from_base32(&decoded).map_err(|e| { + StdError::generic_err(format!( + "soft_addr_validation for address {:?} failed to get bytes from base32: {:?}", + addr, + e.to_string() + )) + })?; + + match api.addr_humanize(&decoded_bytes.into()) { + Ok(_) => Ok(()), + Err(e) => Err(StdError::generic_err(format!( + "soft_addr_validation for address {:?} failed to addr_humanize: {:?}", + addr, + e.to_string() + ))), + } +} diff --git a/unit-tests/src/test_single_party_covenant/test.rs b/unit-tests/src/test_single_party_covenant/test.rs index b0f4d10b..01ce9eb6 100644 --- a/unit-tests/src/test_single_party_covenant/test.rs +++ b/unit-tests/src/test_single_party_covenant/test.rs @@ -1,4 +1,5 @@ use cosmwasm_std::{coin, to_json_binary, Addr, Event, Uint128, Uint64}; +use covenant_utils::neutron::RemoteChainInfo; use cw_multi_test::{AppResponse, Executor}; use crate::setup::{ @@ -1065,10 +1066,17 @@ fn test_migrate_update_config_with_codes() { lp_config: None, }; + let new_remote_chain_info = RemoteChainInfo { + connection_id: "connection-id".to_string(), + channel_id: "channel-id".to_string(), + denom: "denom".to_string(), + ibc_transfer_timeout: Uint64::one(), + ica_timeout: Uint64::one(), + }; let liquid_staker_migrate_msg = covenant_stride_liquid_staker::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), - next_contract: None, - remote_chain_info: None, + next_contract: Some(covenant_addr.to_string()), + remote_chain_info: Some(new_remote_chain_info), }; let remote_chain_splitter_migrate_msg = diff --git a/unit-tests/src/test_swap_covenant/test.rs b/unit-tests/src/test_swap_covenant/test.rs index 627965d5..e2cf338e 100644 --- a/unit-tests/src/test_swap_covenant/test.rs +++ b/unit-tests/src/test_swap_covenant/test.rs @@ -492,7 +492,7 @@ fn test_migrate_update_with_codes() { party_b_router: Some(covenant_swap::msg::RouterMigrateMsg::Native( native_router_migrate_msg.clone(), )), - party_a_forwarder: None, + party_a_forwarder: Box::new(None), party_b_forwarder: Box::new(None), }, 1, @@ -570,7 +570,7 @@ fn test_migrate_update_without_codes() { party_b_router: Some(covenant_swap::msg::RouterMigrateMsg::Interchain( interchain_router_migrate_msg.clone(), )), - party_a_forwarder: Some(ibc_forwarder_migrate_msg.clone()), + party_a_forwarder: Box::new(Some(ibc_forwarder_migrate_msg.clone())), party_b_forwarder: Box::new(Some(ibc_forwarder_migrate_msg.clone())), }, 1, From 1e745567af0d146ba9e354bbd8659fddc9b4f592 Mon Sep 17 00:00:00 2001 From: bekauz Date: Wed, 20 Mar 2024 17:24:12 +0100 Subject: [PATCH 36/56] streamlining code duplicates from contracts that deal with icas --- Cargo.lock | 1 + contracts/ibc-forwarder/src/contract.rs | 109 +++------- contracts/ibc-forwarder/src/lib.rs | 1 - contracts/ibc-forwarder/src/msg.rs | 8 - contracts/ibc-forwarder/src/state.rs | 63 +++++- contracts/ibc-forwarder/src/sudo.rs | 96 --------- .../remote-chain-splitter/src/contract.rs | 69 +++--- contracts/remote-chain-splitter/src/lib.rs | 1 - contracts/remote-chain-splitter/src/state.rs | 103 +++++---- contracts/remote-chain-splitter/src/sudo.rs | 117 ---------- .../stride-liquid-staker/src/contract.rs | 202 +++++------------- contracts/stride-liquid-staker/src/state.rs | 94 ++++---- packages/covenant-utils/Cargo.toml | 1 + packages/covenant-utils/src/ica.rs | 200 +++++++++++++++++ packages/covenant-utils/src/lib.rs | 1 + packages/covenant-utils/src/neutron.rs | 23 +- unit-tests/src/setup/custom_keepers.rs | 2 +- 17 files changed, 488 insertions(+), 603 deletions(-) delete mode 100644 contracts/ibc-forwarder/src/sudo.rs delete mode 100644 contracts/remote-chain-splitter/src/sudo.rs create mode 100644 packages/covenant-utils/src/ica.rs diff --git a/Cargo.lock b/Cargo.lock index 02016fcc..19b3b580 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -744,6 +744,7 @@ dependencies = [ "neutron-sdk", "polytone", "prost 0.11.9", + "serde-json-wasm 0.4.1", "sha2 0.9.9", ] diff --git a/contracts/ibc-forwarder/src/contract.rs b/contracts/ibc-forwarder/src/contract.rs index 34070bc2..f3b037bd 100644 --- a/contracts/ibc-forwarder/src/contract.rs +++ b/contracts/ibc-forwarder/src/contract.rs @@ -4,25 +4,22 @@ use cosmos_sdk_proto::cosmos::bank::v1beta1::{Input, MsgMultiSend, Output}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - ensure, from_json, to_json_binary, to_json_vec, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, - Env, MessageInfo, Reply, Response, StdError, StdResult, Storage, SubMsg, Uint128, + ensure, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, + StdResult, Uint128, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::{ - neutron::{ - get_ictxs_module_params_query_msg, get_proto_coin, to_proto_msg_transfer, - QueryParamsResponse, RemoteChainInfo, SudoPayload, + ica::{ + get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, + sudo_error, sudo_open_ack, sudo_response, sudo_timeout, }, + neutron::{get_proto_coin, to_proto_msg_transfer, RemoteChainInfo, SudoPayload}, sum_fees, }; use cw2::set_contract_version; use cw_utils::must_pay; use neutron_sdk::{ - bindings::{ - msg::{MsgSubmitTxResponse, NeutronMsg}, - query::NeutronQuery, - types::ProtobufAny, - }, + bindings::{msg::NeutronMsg, query::NeutronQuery, types::ProtobufAny}, interchain_txs::helpers::get_port_id, query::min_ibc_fee::MinIbcFeeResponse, sudo::msg::SudoMsg, @@ -30,16 +27,15 @@ use neutron_sdk::{ }; use prost::Message; -use crate::state::FALLBACK_ADDRESS; +use crate::state::{IbcForwarderIcaStateHelper, FALLBACK_ADDRESS}; use crate::{error::ContractError, msg::FallbackAddressUpdateConfig}; use crate::{ helpers::{get_next_memo, MsgTransfer}, msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, state::{ CLOCK_ADDRESS, CONTRACT_STATE, INTERCHAIN_ACCOUNTS, NEXT_CONTRACT, REMOTE_CHAIN_INFO, - REPLY_ID_STORAGE, SUDO_PAYLOAD, TRANSFER_AMOUNT, + TRANSFER_AMOUNT, }, - sudo::{save_reply_payload, sudo_error, sudo_open_ack, sudo_response, sudo_timeout}, }; const CONTRACT_NAME: &str = "crates.io:covenant-ibc-forwarder"; @@ -182,13 +178,16 @@ fn try_distribute_fallback( remote_chain_info.ica_timeout.u64(), min_fee_query_response.min_fee, ); + let state_helper = IbcForwarderIcaStateHelper; let sudo_msg = msg_with_sudo_callback( + &state_helper, deps.branch(), submit_msg, SudoPayload { port_id, message: "distribute_fallback_multisend".to_string(), }, + SUDO_PAYLOAD_REPLY_ID, )?; Ok(Response::default() @@ -214,14 +213,12 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult NeutronResult> { let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; - - let ictxs_params_response: QueryParamsResponse = - deps.querier.query(&get_ictxs_module_params_query_msg())?; + let ica_registration_fee = query_ica_registration_fee(deps.querier)?; let register_msg = NeutronMsg::register_interchain_account( remote_chain_info.connection_id, INTERCHAIN_ACCOUNT_ID.to_string(), - Some(ictxs_params_response.params.register_fee), + Some(ica_registration_fee), ); let key = get_port_id(env.contract.address.as_str(), INTERCHAIN_ACCOUNT_ID); @@ -291,13 +288,16 @@ fn try_forward_funds(env: Env, mut deps: ExecuteDeps) -> NeutronResult NeutronResult>, T>( - deps: ExecuteDeps, - msg: C, - payload: SudoPayload, -) -> StdResult> { - save_reply_payload(deps.storage, payload)?; - Ok(SubMsg::reply_on_success(msg, SUDO_PAYLOAD_REPLY_ID)) -} - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult { match msg { @@ -350,7 +341,13 @@ pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult Ok(to_json_binary(&ica)?) } QueryMsg::IcaAddress {} => Ok(to_json_binary( - &get_ica(deps, &env, INTERCHAIN_ACCOUNT_ID)?.0, + &get_ica( + &IbcForwarderIcaStateHelper, + deps.storage, + env.contract.address.as_str(), + INTERCHAIN_ACCOUNT_ID, + )? + .0, )?), QueryMsg::RemoteChainInfo {} => { Ok(to_json_binary(&REMOTE_CHAIN_INFO.may_load(deps.storage)?)?) @@ -362,29 +359,19 @@ pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult } } -fn get_ica( - deps: Deps, - env: &Env, - interchain_account_id: &str, -) -> Result<(String, String), StdError> { - let key = get_port_id(env.contract.address.as_str(), interchain_account_id); - - INTERCHAIN_ACCOUNTS - .load(deps.storage, key)? - .ok_or_else(|| StdError::generic_err("Interchain account is not created yet")) -} - #[cfg_attr(not(feature = "library"), entry_point)] pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> StdResult> { match msg { // For handling successful (non-error) acknowledgements. - SudoMsg::Response { request, data } => sudo_response(deps, request, data), + SudoMsg::Response { request, data } => sudo_response(request, data), // For handling error acknowledgements. - SudoMsg::Error { request, details } => sudo_error(deps, request, details), + SudoMsg::Error { request, details } => sudo_error(request, details), // For handling error timeouts. - SudoMsg::Timeout { request } => sudo_timeout(deps, env, request), + SudoMsg::Timeout { request } => { + sudo_timeout(&IbcForwarderIcaStateHelper, deps, env, request) + } // For handling successful registering of ICA SudoMsg::OpenAck { @@ -393,6 +380,7 @@ pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> StdResult sudo_open_ack( + &IbcForwarderIcaStateHelper, deps, env, port_id, @@ -407,7 +395,7 @@ pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> StdResult StdResult> { match msg.id { - SUDO_PAYLOAD_REPLY_ID => prepare_sudo_payload(deps, env, msg), + SUDO_PAYLOAD_REPLY_ID => prepare_sudo_payload(&IbcForwarderIcaStateHelper, deps, env, msg), _ => Err(StdError::generic_err(format!( "unsupported reply message id {}", msg.id @@ -415,41 +403,6 @@ pub fn reply(deps: ExecuteDeps, env: Env, msg: Reply) -> StdResult StdResult> { - let payload = read_reply_payload(deps.storage)?; - let resp: MsgSubmitTxResponse = serde_json_wasm::from_slice( - msg.result - .into_result() - .map_err(StdError::generic_err)? - .data - .ok_or_else(|| StdError::generic_err("no result"))? - .as_slice(), - ) - .map_err(|e| StdError::generic_err(format!("failed to parse response: {e:?}")))?; - let seq_id = resp.sequence_id; - let channel_id = resp.channel; - save_sudo_payload(deps.branch().storage, channel_id, seq_id, payload)?; - Ok(Response::new()) -} - -pub fn read_reply_payload(store: &mut dyn Storage) -> StdResult { - let data = REPLY_ID_STORAGE.load(store)?; - from_json(Binary(data)) -} - -pub fn save_sudo_payload( - store: &mut dyn Storage, - channel_id: String, - seq_id: u64, - payload: SudoPayload, -) -> StdResult<()> { - SUDO_PAYLOAD.save(store, (channel_id, seq_id), &to_json_vec(&payload)?) -} - #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult> { match msg { diff --git a/contracts/ibc-forwarder/src/lib.rs b/contracts/ibc-forwarder/src/lib.rs index 1fa4e075..3da36ff7 100644 --- a/contracts/ibc-forwarder/src/lib.rs +++ b/contracts/ibc-forwarder/src/lib.rs @@ -5,4 +5,3 @@ pub mod error; pub mod helpers; pub mod msg; pub mod state; -pub mod sudo; diff --git a/contracts/ibc-forwarder/src/msg.rs b/contracts/ibc-forwarder/src/msg.rs index aa935027..38c79801 100644 --- a/contracts/ibc-forwarder/src/msg.rs +++ b/contracts/ibc-forwarder/src/msg.rs @@ -123,11 +123,3 @@ pub enum ContractState { /// ICA was created, funds are ready to be forwarded IcaCreated, } - -/// SudoPayload is a type that stores information about a transaction that we try to execute -/// on the host chain. This is a type introduced for our convenience. -#[cw_serde] -pub struct SudoPayload { - pub message: String, - pub port_id: String, -} diff --git a/contracts/ibc-forwarder/src/state.rs b/contracts/ibc-forwarder/src/state.rs index 80e28cbc..1b48469c 100644 --- a/contracts/ibc-forwarder/src/state.rs +++ b/contracts/ibc-forwarder/src/state.rs @@ -1,5 +1,8 @@ -use cosmwasm_std::{Addr, Uint128}; -use covenant_utils::neutron::RemoteChainInfo; +use cosmwasm_std::{from_json, to_json_vec, Addr, Binary, StdError, StdResult, Storage, Uint128}; +use covenant_utils::{ + ica::IcaStateHelper, + neutron::{RemoteChainInfo, SudoPayload}, +}; use cw_storage_plus::{Item, Map}; use crate::msg::ContractState; @@ -23,3 +26,59 @@ pub const INTERCHAIN_ACCOUNTS: Map> = pub const REPLY_ID_STORAGE: Item> = Item::new("reply_queue_id"); pub const SUDO_PAYLOAD: Map<(String, u64), Vec> = Map::new("sudo_payload"); pub const FALLBACK_ADDRESS: Item = Item::new("fallback_address"); + +pub(crate) struct IbcForwarderIcaStateHelper; + +impl IcaStateHelper for IbcForwarderIcaStateHelper { + fn reset_state(&self, storage: &mut dyn Storage) -> StdResult<()> { + CONTRACT_STATE.save(storage, &ContractState::Instantiated)?; + Ok(()) + } + + fn clear_ica(&self, storage: &mut dyn Storage) -> StdResult<()> { + INTERCHAIN_ACCOUNTS.clear(storage); + Ok(()) + } + + fn save_ica( + &self, + storage: &mut dyn Storage, + port_id: String, + address: String, + controller_connection_id: String, + ) -> StdResult<()> { + INTERCHAIN_ACCOUNTS.save(storage, port_id, &Some((address, controller_connection_id)))?; + Ok(()) + } + + fn save_state_ica_created(&self, storage: &mut dyn Storage) -> StdResult<()> { + CONTRACT_STATE.save(storage, &ContractState::IcaCreated)?; + Ok(()) + } + + fn save_reply_payload(&self, storage: &mut dyn Storage, payload: SudoPayload) -> StdResult<()> { + REPLY_ID_STORAGE.save(storage, &to_json_vec(&payload)?)?; + Ok(()) + } + + fn read_reply_payload(&self, storage: &mut dyn Storage) -> StdResult { + let data = REPLY_ID_STORAGE.load(storage)?; + from_json(Binary(data)) + } + + fn save_sudo_payload( + &self, + storage: &mut dyn Storage, + channel_id: String, + seq_id: u64, + payload: SudoPayload, + ) -> StdResult<()> { + SUDO_PAYLOAD.save(storage, (channel_id, seq_id), &to_json_vec(&payload)?) + } + + fn get_ica(&self, storage: &dyn Storage, key: String) -> StdResult<(String, String)> { + INTERCHAIN_ACCOUNTS + .load(storage, key)? + .ok_or_else(|| StdError::generic_err("Interchain account is not created yet")) + } +} diff --git a/contracts/ibc-forwarder/src/sudo.rs b/contracts/ibc-forwarder/src/sudo.rs deleted file mode 100644 index 9cf75342..00000000 --- a/contracts/ibc-forwarder/src/sudo.rs +++ /dev/null @@ -1,96 +0,0 @@ -use cosmwasm_std::{to_json_vec, Binary, DepsMut, Env, Response, StdError, StdResult, Storage}; -use covenant_utils::neutron::{OpenAckVersion, SudoPayload}; -use neutron_sdk::{ - bindings::{msg::NeutronMsg, query::NeutronQuery}, - sudo::msg::RequestPacket, -}; - -use crate::{ - msg::ContractState, - state::{CONTRACT_STATE, INTERCHAIN_ACCOUNTS, REPLY_ID_STORAGE}, -}; - -type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; - -// handler -pub fn sudo_open_ack( - deps: ExecuteDeps, - _env: Env, - port_id: String, - _channel_id: String, - _counterparty_channel_id: String, - counterparty_version: String, -) -> StdResult> { - // The version variable contains a JSON value with multiple fields, - // including the generated account address. - let parsed_version: Result = - serde_json_wasm::from_str(counterparty_version.as_str()); - - // get the parsed OpenAckVersion or return an error if we fail - let Ok(parsed_version) = parsed_version else { - return Err(StdError::generic_err("Can't parse counterparty_version")); - }; - - // Update the storage record associated with the interchain account. - INTERCHAIN_ACCOUNTS.save( - deps.storage, - port_id, - &Some(( - parsed_version.clone().address, - parsed_version.controller_connection_id, - )), - )?; - CONTRACT_STATE.save(deps.storage, &ContractState::IcaCreated)?; - - Ok(Response::default().add_attribute("method", "sudo_open_ack")) -} - -pub fn sudo_response( - _deps: ExecuteDeps, - request: RequestPacket, - _data: Binary, -) -> StdResult> { - // either of these errors will close the channel - request - .sequence - .ok_or_else(|| StdError::generic_err("sequence not found"))?; - - request - .source_channel - .ok_or_else(|| StdError::generic_err("channel_id not found"))?; - - Ok(Response::default().add_attribute("method", "sudo_response")) -} - -pub fn sudo_timeout( - deps: ExecuteDeps, - _env: Env, - _request: RequestPacket, -) -> StdResult> { - // revert the state to Instantiated to force re-creation of ICA - CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; - - // returning Ok as this is anticipated. channel is already closed. - Ok(Response::default()) -} - -pub fn sudo_error( - _deps: ExecuteDeps, - request: RequestPacket, - _details: String, -) -> StdResult> { - // either of these errors will close the channel - request - .sequence - .ok_or_else(|| StdError::generic_err("sequence not found"))?; - - request - .source_channel - .ok_or_else(|| StdError::generic_err("channel_id not found"))?; - - Ok(Response::default().add_attribute("method", "sudo_error")) -} - -pub fn save_reply_payload(store: &mut dyn Storage, payload: SudoPayload) -> StdResult<()> { - REPLY_ID_STORAGE.save(store, &to_json_vec(&payload)?) -} diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index 223ae109..082c1717 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -7,14 +7,15 @@ use cosmos_sdk_proto::traits::Message; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - ensure, to_json_binary, Attribute, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, - Fraction, MessageInfo, Reply, Response, StdError, StdResult, SubMsg, Uint128, + ensure, to_json_binary, Attribute, Binary, Deps, DepsMut, Env, Fraction, MessageInfo, Reply, + Response, StdError, StdResult, Uint128, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; -use covenant_utils::neutron::{ - get_ictxs_module_params_query_msg, get_proto_coin, QueryParamsResponse, RemoteChainInfo, - SudoPayload, +use covenant_utils::ica::{ + get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, sudo_error, + sudo_open_ack, sudo_response, sudo_timeout, }; +use covenant_utils::neutron::{get_proto_coin, RemoteChainInfo, SudoPayload}; use covenant_utils::{neutron, soft_validate_remote_chain_addr, sum_fees}; use cw2::set_contract_version; use cw_utils::must_pay; @@ -29,10 +30,9 @@ use crate::msg::{ ContractState, ExecuteMsg, FallbackAddressUpdateConfig, InstantiateMsg, MigrateMsg, QueryMsg, }; use crate::state::{ - save_reply_payload, CLOCK_ADDRESS, CONTRACT_STATE, FALLBACK_ADDRESS, INTERCHAIN_ACCOUNTS, - REMOTE_CHAIN_INFO, SPLIT_CONFIG_MAP, TRANSFER_AMOUNT, + RemoteChainSplitteIcaStateHelper, CLOCK_ADDRESS, CONTRACT_STATE, FALLBACK_ADDRESS, + INTERCHAIN_ACCOUNTS, REMOTE_CHAIN_INFO, SPLIT_CONFIG_MAP, TRANSFER_AMOUNT, }; -use crate::sudo::{prepare_sudo_payload, sudo_error, sudo_open_ack, sudo_response, sudo_timeout}; use neutron_sdk::{ bindings::{msg::NeutronMsg, query::NeutronQuery}, NeutronResult, @@ -45,7 +45,7 @@ const INTERCHAIN_ACCOUNT_ID: &str = "rc-ica"; const CONTRACT_NAME: &str = "crates.io:covenant-remote-chain-splitter"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); -const SUDO_PAYLOAD_REPLY_ID: u64 = 1u64; +pub const SUDO_PAYLOAD_REPLY_ID: u64 = 1u64; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( @@ -187,12 +187,14 @@ fn try_distribute_fallback( min_fee_query_response.min_fee, ); let sudo_msg = msg_with_sudo_callback( + &RemoteChainSplitteIcaStateHelper, deps.branch(), submit_msg, SudoPayload { port_id, message: "distribute_fallback_multisend".to_string(), }, + SUDO_PAYLOAD_REPLY_ID, )?; Ok(Response::default() @@ -216,13 +218,12 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult NeutronResult> { let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; - let ictxs_params_response: QueryParamsResponse = - deps.querier.query(&get_ictxs_module_params_query_msg())?; + let ica_registration_fee = query_ica_registration_fee(deps.querier)?; let register: NeutronMsg = NeutronMsg::register_interchain_account( remote_chain_info.connection_id, INTERCHAIN_ACCOUNT_ID.to_string(), - Some(ictxs_params_response.params.register_fee), + Some(ica_registration_fee), ); let key = get_port_id(env.contract.address.as_str(), INTERCHAIN_ACCOUNT_ID); @@ -330,12 +331,14 @@ fn try_split_funds(mut deps: ExecuteDeps, env: Env) -> NeutronResult NeutronResult>, T>( - deps: ExecuteDeps, - msg: C, - payload: SudoPayload, -) -> StdResult> { - save_reply_payload(deps.storage, payload)?; - Ok(SubMsg::reply_on_success(msg, SUDO_PAYLOAD_REPLY_ID)) -} - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult { match msg { @@ -386,7 +380,13 @@ pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult Ok(to_json_binary(&TRANSFER_AMOUNT.may_load(deps.storage)?)?) } QueryMsg::IcaAddress {} => Ok(to_json_binary( - &get_ica(deps, &env, INTERCHAIN_ACCOUNT_ID)?.0, + &get_ica( + &RemoteChainSplitteIcaStateHelper, + deps.storage, + env.contract.address.as_str(), + INTERCHAIN_ACCOUNT_ID, + )? + .0, )?), QueryMsg::FallbackAddress {} => { Ok(to_json_binary(&FALLBACK_ADDRESS.may_load(deps.storage)?)?) @@ -408,27 +408,17 @@ fn query_deposit_address(deps: QueryDeps, env: Env) -> Result, St .map(|entry| entry.flatten().map(|x| x.0)) } -fn get_ica( - deps: Deps, - env: &Env, - interchain_account_id: &str, -) -> Result<(String, String), StdError> { - let key = get_port_id(env.contract.address.as_str(), interchain_account_id); - - INTERCHAIN_ACCOUNTS - .load(deps.storage, key)? - .ok_or_else(|| StdError::generic_err("Interchain account is not created yet")) -} - #[cfg_attr(not(feature = "library"), entry_point)] pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> StdResult> { match msg { // For handling successful (non-error) acknowledgements. - SudoMsg::Response { request, data } => sudo_response(deps, request, data), + SudoMsg::Response { request, data } => sudo_response(request, data), // For handling error acknowledgements. - SudoMsg::Error { request, details } => sudo_error(deps, request, details), + SudoMsg::Error { request, details } => sudo_error(request, details), // For handling error timeouts. - SudoMsg::Timeout { request } => sudo_timeout(deps, env, request), + SudoMsg::Timeout { request } => { + sudo_timeout(&RemoteChainSplitteIcaStateHelper, deps, env, request) + } // For handling successful registering of ICA SudoMsg::OpenAck { port_id, @@ -436,6 +426,7 @@ pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> StdResult sudo_open_ack( + &RemoteChainSplitteIcaStateHelper, deps, env, port_id, @@ -520,7 +511,9 @@ pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult StdResult> { match msg.id { - SUDO_PAYLOAD_REPLY_ID => prepare_sudo_payload(deps, env, msg), + SUDO_PAYLOAD_REPLY_ID => { + prepare_sudo_payload(&RemoteChainSplitteIcaStateHelper, deps, env, msg) + } _ => Err(StdError::generic_err(format!( "unsupported reply message id {}", msg.id diff --git a/contracts/remote-chain-splitter/src/lib.rs b/contracts/remote-chain-splitter/src/lib.rs index 4e6a59d9..47bc573c 100644 --- a/contracts/remote-chain-splitter/src/lib.rs +++ b/contracts/remote-chain-splitter/src/lib.rs @@ -4,4 +4,3 @@ pub mod contract; pub mod error; pub mod msg; pub mod state; -pub mod sudo; diff --git a/contracts/remote-chain-splitter/src/state.rs b/contracts/remote-chain-splitter/src/state.rs index db9e52ff..05fa2953 100644 --- a/contracts/remote-chain-splitter/src/state.rs +++ b/contracts/remote-chain-splitter/src/state.rs @@ -1,5 +1,6 @@ -use cosmwasm_std::{from_json, to_json_vec, Addr, Binary, Order, StdResult, Storage, Uint128}; +use cosmwasm_std::{from_json, to_json_vec, Addr, Binary, StdError, StdResult, Storage, Uint128}; use covenant_utils::{ + ica::IcaStateHelper, neutron::{RemoteChainInfo, SudoPayload}, split::SplitConfig, }; @@ -31,50 +32,58 @@ pub const REPLY_ID_STORAGE: Item> = Item::new("reply_queue_id"); pub const SUDO_PAYLOAD: Map<(String, u64), Vec> = Map::new("sudo_payload"); pub const ERRORS_QUEUE: Map = Map::new("errors_queue"); -pub fn save_reply_payload(store: &mut dyn Storage, payload: SudoPayload) -> StdResult<()> { - REPLY_ID_STORAGE.save(store, &to_json_vec(&payload)?) -} - -pub fn read_reply_payload(store: &mut dyn Storage) -> StdResult { - let data = REPLY_ID_STORAGE.load(store)?; - from_json(Binary(data)) -} - -pub fn add_error_to_queue(store: &mut dyn Storage, error_msg: String) -> Option<()> { - let result = ERRORS_QUEUE - .keys(store, None, None, Order::Descending) - .next() - .and_then(|data| data.ok()) - .map(|c| c + 1) - .or(Some(0)); - - result.and_then(|idx| ERRORS_QUEUE.save(store, idx, &error_msg).ok()) -} - -pub fn read_errors_from_queue(store: &dyn Storage) -> StdResult, String)>> { - ERRORS_QUEUE - .range_raw(store, None, None, Order::Ascending) - .collect() -} - -pub fn read_sudo_payload( - store: &mut dyn Storage, - channel_id: String, - seq_id: u64, -) -> StdResult { - let data = SUDO_PAYLOAD.load(store, (channel_id, seq_id))?; - from_json(Binary(data)) -} - -pub fn save_sudo_payload( - store: &mut dyn Storage, - channel_id: String, - seq_id: u64, - payload: SudoPayload, -) -> StdResult<()> { - SUDO_PAYLOAD.save(store, (channel_id, seq_id), &to_json_vec(&payload)?) -} - -pub fn clear_sudo_payload(store: &mut dyn Storage, channel_id: String, seq_id: u64) { - SUDO_PAYLOAD.remove(store, (channel_id, seq_id)) +pub(crate) struct RemoteChainSplitteIcaStateHelper; + +impl IcaStateHelper for RemoteChainSplitteIcaStateHelper { + fn reset_state(&self, storage: &mut dyn Storage) -> StdResult<()> { + CONTRACT_STATE.save(storage, &ContractState::Instantiated)?; + Ok(()) + } + + fn clear_ica(&self, storage: &mut dyn Storage) -> StdResult<()> { + INTERCHAIN_ACCOUNTS.clear(storage); + Ok(()) + } + + fn save_ica( + &self, + storage: &mut dyn Storage, + port_id: String, + address: String, + controller_connection_id: String, + ) -> StdResult<()> { + INTERCHAIN_ACCOUNTS.save(storage, port_id, &Some((address, controller_connection_id)))?; + Ok(()) + } + + fn save_state_ica_created(&self, storage: &mut dyn Storage) -> StdResult<()> { + CONTRACT_STATE.save(storage, &ContractState::IcaCreated)?; + Ok(()) + } + + fn save_reply_payload(&self, storage: &mut dyn Storage, payload: SudoPayload) -> StdResult<()> { + REPLY_ID_STORAGE.save(storage, &to_json_vec(&payload)?)?; + Ok(()) + } + + fn read_reply_payload(&self, storage: &mut dyn Storage) -> StdResult { + let data = REPLY_ID_STORAGE.load(storage)?; + from_json(Binary(data)) + } + + fn save_sudo_payload( + &self, + storage: &mut dyn Storage, + channel_id: String, + seq_id: u64, + payload: SudoPayload, + ) -> StdResult<()> { + SUDO_PAYLOAD.save(storage, (channel_id, seq_id), &to_json_vec(&payload)?) + } + + fn get_ica(&self, storage: &dyn Storage, key: String) -> StdResult<(String, String)> { + INTERCHAIN_ACCOUNTS + .load(storage, key)? + .ok_or_else(|| StdError::generic_err("Interchain account is not created yet")) + } } diff --git a/contracts/remote-chain-splitter/src/sudo.rs b/contracts/remote-chain-splitter/src/sudo.rs deleted file mode 100644 index f415bb4f..00000000 --- a/contracts/remote-chain-splitter/src/sudo.rs +++ /dev/null @@ -1,117 +0,0 @@ -use cosmwasm_std::{Binary, DepsMut, Env, Reply, Response, StdError, StdResult}; -use covenant_utils::neutron::OpenAckVersion; -use neutron_sdk::{ - bindings::{ - msg::{MsgSubmitTxResponse, NeutronMsg}, - query::NeutronQuery, - }, - sudo::msg::RequestPacket, -}; - -use crate::{ - msg::ContractState, - state::{read_reply_payload, save_sudo_payload, CONTRACT_STATE, INTERCHAIN_ACCOUNTS}, -}; - -type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; - -// handler -pub fn sudo_open_ack( - deps: ExecuteDeps, - _env: Env, - port_id: String, - _channel_id: String, - _counterparty_channel_id: String, - counterparty_version: String, -) -> StdResult> { - // The version variable contains a JSON value with multiple fields, - // including the generated account address. - let parsed_version: Result = - serde_json_wasm::from_str(counterparty_version.as_str()); - - // get the parsed OpenAckVersion or return an error if we fail - let Ok(parsed_version) = parsed_version else { - return Err(StdError::generic_err("Can't parse counterparty_version")); - }; - - // Update the storage record associated with the interchain account. - INTERCHAIN_ACCOUNTS.save( - deps.storage, - port_id, - &Some(( - parsed_version.clone().address, - parsed_version.controller_connection_id, - )), - )?; - CONTRACT_STATE.save(deps.storage, &ContractState::IcaCreated)?; - - Ok(Response::default().add_attribute("method", "sudo_open_ack")) -} - -pub fn sudo_response( - _deps: ExecuteDeps, - request: RequestPacket, - _data: Binary, -) -> StdResult> { - // either of these errors will close the channel - request - .sequence - .ok_or_else(|| StdError::generic_err("sequence not found"))?; - - request - .source_channel - .ok_or_else(|| StdError::generic_err("channel_id not found"))?; - - Ok(Response::default().add_attribute("method", "sudo_response")) -} - -pub fn sudo_timeout( - deps: ExecuteDeps, - _env: Env, - _request: RequestPacket, -) -> StdResult> { - // revert the state to Instantiated to force re-creation of ICA - CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; - INTERCHAIN_ACCOUNTS.clear(deps.storage); - - // returning Ok as this is anticipated. channel is already closed. - Ok(Response::default()) -} - -pub fn sudo_error( - _deps: ExecuteDeps, - request: RequestPacket, - _details: String, -) -> StdResult> { - // either of these errors will close the channel - request - .sequence - .ok_or_else(|| StdError::generic_err("sequence not found"))?; - - request - .source_channel - .ok_or_else(|| StdError::generic_err("channel_id not found"))?; - - Ok(Response::default().add_attribute("method", "sudo_error")) -} - -pub fn prepare_sudo_payload( - mut deps: ExecuteDeps, - _env: Env, - msg: Reply, -) -> StdResult> { - let payload = read_reply_payload(deps.storage)?; - let resp: MsgSubmitTxResponse = serde_json_wasm::from_slice( - msg.result - .into_result() - .map_err(StdError::generic_err)? - .data - .ok_or_else(|| StdError::generic_err("no result"))? - .as_slice(), - ) - .map_err(|e| StdError::generic_err(format!("failed to parse response: {e:?}")))?; - let seq_id = resp.sequence_id; - let channel_id = resp.channel; - save_sudo_payload(deps.branch().storage, channel_id, seq_id, payload)?; - Ok(Response::new()) -} diff --git a/contracts/stride-liquid-staker/src/contract.rs b/contracts/stride-liquid-staker/src/contract.rs index 8a8eaab3..7d7d1134 100644 --- a/contracts/stride-liquid-staker/src/contract.rs +++ b/contracts/stride-liquid-staker/src/contract.rs @@ -2,27 +2,29 @@ use cosmos_sdk_proto::ibc::applications::transfer::v1::MsgTransfer; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - coins, to_json_binary, to_json_string, Binary, Coin, CosmosMsg, CustomQuery, Deps, DepsMut, - Env, MessageInfo, Reply, Response, StdError, StdResult, SubMsg, Uint128, + coins, to_json_binary, to_json_string, Binary, Deps, DepsMut, Env, MessageInfo, Reply, + Response, StdError, StdResult, Uint128, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; -use covenant_utils::neutron::{self, get_proto_coin, OpenAckVersion, RemoteChainInfo, SudoPayload}; +use covenant_utils::ica::{ + get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, sudo_error, + sudo_open_ack, sudo_response, sudo_timeout, +}; +use covenant_utils::neutron::{self, get_proto_coin, RemoteChainInfo, SudoPayload}; use cw2::set_contract_version; use neutron_sdk::query::min_ibc_fee::MinIbcFeeResponse; use crate::helpers::{Autopilot, AutopilotConfig}; use crate::msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use crate::state::{ - read_reply_payload, save_reply_payload, save_sudo_payload, CLOCK_ADDRESS, CONTRACT_STATE, - INTERCHAIN_ACCOUNTS, NEXT_CONTRACT, REMOTE_CHAIN_INFO, + LiquidStakerIcaStateHelper, CLOCK_ADDRESS, CONTRACT_STATE, INTERCHAIN_ACCOUNTS, NEXT_CONTRACT, + REMOTE_CHAIN_INFO, }; +pub const SUDO_PAYLOAD_REPLY_ID: u64 = 1u64; use neutron_sdk::{ - bindings::{ - msg::{MsgSubmitTxResponse, NeutronMsg}, - query::NeutronQuery, - }, + bindings::{msg::NeutronMsg, query::NeutronQuery}, interchain_txs::helpers::get_port_id, - sudo::msg::{RequestPacket, SudoMsg}, + sudo::msg::SudoMsg, NeutronError, NeutronResult, }; @@ -31,8 +33,6 @@ const INTERCHAIN_ACCOUNT_ID: &str = "stride-ica"; const CONTRACT_NAME: &str = "crates.io:covenant-stride-liquid-staker"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); -const SUDO_PAYLOAD_REPLY_ID: u64 = 1u64; - type QueryDeps<'a> = Deps<'a, NeutronQuery>; type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; @@ -79,7 +79,12 @@ pub fn execute( match msg { ExecuteMsg::Tick {} => try_tick(deps, env, info), ExecuteMsg::Transfer { amount } => { - let ica_address = get_ica(deps.as_ref(), &env, INTERCHAIN_ACCOUNT_ID); + let ica_address = get_ica( + &LiquidStakerIcaStateHelper, + deps.storage, + env.contract.address.as_ref(), + INTERCHAIN_ACCOUNT_ID, + ); match ica_address { Ok(_) => try_execute_transfer(deps, env, info, amount), Err(_) => Ok(Response::default() @@ -105,11 +110,11 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult NeutronResult> { let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; - let register_fee: Option> = Some(coins(1000001, "untrn")); + let ica_registration_fee = query_ica_registration_fee(deps.querier)?; let register: NeutronMsg = NeutronMsg::register_interchain_account( remote_chain_info.connection_id, INTERCHAIN_ACCOUNT_ID.to_string(), - register_fee, + Some(ica_registration_fee), ); let key = get_port_id(env.contract.address.as_str(), INTERCHAIN_ACCOUNT_ID); @@ -182,14 +187,16 @@ fn try_execute_transfer( remote_chain_info.ica_timeout.u64(), min_fee_query_response.min_fee, ); - + let state_helper = LiquidStakerIcaStateHelper; let sudo_msg = msg_with_sudo_callback( + &state_helper, deps, submit_msg, SudoPayload { port_id, message: "permisionless_transfer".to_string(), }, + SUDO_PAYLOAD_REPLY_ID, )?; Ok(Response::default() .add_submessage(sudo_msg) @@ -207,25 +214,28 @@ fn try_execute_transfer( } } -fn msg_with_sudo_callback>, T>( - deps: ExecuteDeps, - msg: C, - payload: SudoPayload, -) -> StdResult> { - save_reply_payload(deps.storage, payload)?; - Ok(SubMsg::reply_on_success(msg, SUDO_PAYLOAD_REPLY_ID)) -} - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult { match msg { QueryMsg::ClockAddress {} => Ok(to_json_binary(&CLOCK_ADDRESS.may_load(deps.storage)?)?), QueryMsg::IcaAddress {} => Ok(to_json_binary( - &get_ica(deps, &env, INTERCHAIN_ACCOUNT_ID)?.0, + &get_ica( + &LiquidStakerIcaStateHelper, + deps.storage, + env.contract.address.as_str(), + INTERCHAIN_ACCOUNT_ID, + )? + .0, )?), QueryMsg::ContractState {} => Ok(to_json_binary(&CONTRACT_STATE.may_load(deps.storage)?)?), QueryMsg::DepositAddress {} => { - let ica = get_ica(deps, &env, INTERCHAIN_ACCOUNT_ID)?.0; + let ica = get_ica( + &LiquidStakerIcaStateHelper, + deps.storage, + env.contract.address.as_str(), + INTERCHAIN_ACCOUNT_ID, + )? + .0; let autopilot = Autopilot { autopilot: AutopilotConfig { @@ -246,7 +256,13 @@ pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult } QueryMsg::NextMemo {} => { // 1. receiver = query ICA - let ica = get_ica(deps, &env, INTERCHAIN_ACCOUNT_ID)?.0; + let ica = get_ica( + &LiquidStakerIcaStateHelper, + deps.storage, + env.contract.address.as_str(), + INTERCHAIN_ACCOUNT_ID, + )? + .0; let autopilot = Autopilot { autopilot: AutopilotConfig { @@ -269,13 +285,15 @@ pub fn query(deps: QueryDeps, env: Env, msg: QueryMsg) -> NeutronResult pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> Result, StdError> { match msg { // For handling successful (non-error) acknowledgements. - SudoMsg::Response { request, data } => sudo_response(deps, request, data), + SudoMsg::Response { request, data } => sudo_response(request, data), // For handling error acknowledgements. - SudoMsg::Error { request, details } => sudo_error(deps, request, details), + SudoMsg::Error { request, details } => sudo_error(request, details), // For handling error timeouts. - SudoMsg::Timeout { request } => sudo_timeout(deps, env, request), + SudoMsg::Timeout { request } => { + sudo_timeout(&LiquidStakerIcaStateHelper, deps, env, request) + } // For handling successful registering of ICA SudoMsg::OpenAck { @@ -284,6 +302,7 @@ pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> Result sudo_open_ack( + &LiquidStakerIcaStateHelper, deps, env, port_id, @@ -295,129 +314,10 @@ pub fn sudo(deps: ExecuteDeps, env: Env, msg: SudoMsg) -> Result StdResult> { - // The version variable contains a JSON value with multiple fields, - // including the generated account address. - let parsed_version: Result = - serde_json_wasm::from_str(counterparty_version.as_str()); - - // get the parsed OpenAckVersion or return an error if we fail - let Ok(parsed_version) = parsed_version else { - return Err(StdError::generic_err("Can't parse counterparty_version")); - }; - - // Update the storage record associated with the interchain account. - INTERCHAIN_ACCOUNTS.save( - deps.storage, - port_id, - &Some(( - parsed_version.clone().address, - parsed_version.controller_connection_id, - )), - )?; - CONTRACT_STATE.save(deps.storage, &ContractState::IcaCreated)?; - - Ok(Response::default().add_attribute("method", "sudo_open_ack")) -} - -fn sudo_response( - _deps: ExecuteDeps, - request: RequestPacket, - _data: Binary, -) -> StdResult> { - // either of these errors will close the channel - request - .sequence - .ok_or_else(|| StdError::generic_err("sequence not found"))?; - - request - .source_channel - .ok_or_else(|| StdError::generic_err("channel_id not found"))?; - - Ok(Response::default().add_attribute("method", "sudo_response")) -} - -fn sudo_timeout( - deps: ExecuteDeps, - _env: Env, - _request: RequestPacket, -) -> StdResult> { - // revert the state to Instantiated to force re-creation of ICA - CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; - - // returning Ok as this is anticipated. channel is already closed. - Ok(Response::default()) -} - -fn sudo_error( - _deps: ExecuteDeps, - request: RequestPacket, - _details: String, -) -> StdResult> { - // either of these errors will close the channel - request - .sequence - .ok_or_else(|| StdError::generic_err("sequence not found"))?; - - request - .source_channel - .ok_or_else(|| StdError::generic_err("channel_id not found"))?; - - Ok(Response::default().add_attribute("method", "sudo_error")) -} - -// prepare_sudo_payload is called from reply handler -// The method is used to extract sequence id and channel from SubmitTxResponse to -// process sudo payload defined in msg_with_sudo_callback later in Sudo handler. -// Such flow msg_with_sudo_callback() -> reply() -> prepare_sudo_payload() -> sudo() -// allows you "attach" some payload to your SubmitTx message -// and process this payload when an acknowledgement for the SubmitTx message -// is received in Sudo handler -fn prepare_sudo_payload( - mut deps: ExecuteDeps, - _env: Env, - msg: Reply, -) -> StdResult> { - let payload = read_reply_payload(deps.storage)?; - let resp: MsgSubmitTxResponse = serde_json_wasm::from_slice( - msg.result - .into_result() - .map_err(StdError::generic_err)? - .data - .ok_or_else(|| StdError::generic_err("no result"))? - .as_slice(), - ) - .map_err(|e| StdError::generic_err(format!("failed to parse response: {e:?}")))?; - let seq_id = resp.sequence_id; - let channel_id = resp.channel; - save_sudo_payload(deps.branch().storage, channel_id, seq_id, payload)?; - Ok(Response::new()) -} - -fn get_ica( - deps: Deps, - env: &Env, - interchain_account_id: &str, -) -> Result<(String, String), StdError> { - let key = get_port_id(env.contract.address.as_str(), interchain_account_id); - - INTERCHAIN_ACCOUNTS - .load(deps.storage, key)? - .ok_or_else(|| StdError::generic_err("Interchain account is not created yet")) -} - #[cfg_attr(not(feature = "library"), entry_point)] pub fn reply(deps: ExecuteDeps, env: Env, msg: Reply) -> StdResult> { match msg.id { - SUDO_PAYLOAD_REPLY_ID => prepare_sudo_payload(deps, env, msg), + SUDO_PAYLOAD_REPLY_ID => prepare_sudo_payload(&LiquidStakerIcaStateHelper, deps, env, msg), _ => Err(StdError::generic_err(format!( "unsupported reply message id {}", msg.id diff --git a/contracts/stride-liquid-staker/src/state.rs b/contracts/stride-liquid-staker/src/state.rs index eab90d05..2bd4a5a4 100644 --- a/contracts/stride-liquid-staker/src/state.rs +++ b/contracts/stride-liquid-staker/src/state.rs @@ -1,5 +1,8 @@ -use cosmwasm_std::{from_json, to_json_vec, Addr, Binary, Order, StdResult, Storage}; -use covenant_utils::neutron::{RemoteChainInfo, SudoPayload}; +use cosmwasm_std::{from_json, to_json_vec, Addr, Binary, StdError, StdResult, Storage}; +use covenant_utils::{ + ica::IcaStateHelper, + neutron::{RemoteChainInfo, SudoPayload}, +}; use cw_storage_plus::{Item, Map}; use crate::msg::ContractState; @@ -22,52 +25,59 @@ pub const INTERCHAIN_ACCOUNTS: Map> = /// interchain transaction responses - ack/err/timeout state to query later pub const REPLY_ID_STORAGE: Item> = Item::new("reply_queue_id"); pub const SUDO_PAYLOAD: Map<(String, u64), Vec> = Map::new("sudo_payload"); -pub const ERRORS_QUEUE: Map = Map::new("errors_queue"); -pub fn save_reply_payload(store: &mut dyn Storage, payload: SudoPayload) -> StdResult<()> { - REPLY_ID_STORAGE.save(store, &to_json_vec(&payload)?) -} +pub(crate) struct LiquidStakerIcaStateHelper; -pub fn read_reply_payload(store: &mut dyn Storage) -> StdResult { - let data = REPLY_ID_STORAGE.load(store)?; - from_json(Binary(data)) -} +impl IcaStateHelper for LiquidStakerIcaStateHelper { + fn reset_state(&self, storage: &mut dyn Storage) -> StdResult<()> { + CONTRACT_STATE.save(storage, &ContractState::Instantiated)?; + Ok(()) + } -pub fn add_error_to_queue(store: &mut dyn Storage, error_msg: String) -> Option<()> { - let result = ERRORS_QUEUE - .keys(store, None, None, Order::Descending) - .next() - .and_then(|data| data.ok()) - .map(|c| c + 1) - .or(Some(0)); + fn clear_ica(&self, storage: &mut dyn Storage) -> StdResult<()> { + INTERCHAIN_ACCOUNTS.clear(storage); + Ok(()) + } - result.and_then(|idx| ERRORS_QUEUE.save(store, idx, &error_msg).ok()) -} + fn save_ica( + &self, + storage: &mut dyn Storage, + port_id: String, + address: String, + controller_connection_id: String, + ) -> StdResult<()> { + INTERCHAIN_ACCOUNTS.save(storage, port_id, &Some((address, controller_connection_id)))?; + Ok(()) + } -pub fn read_errors_from_queue(store: &dyn Storage) -> StdResult, String)>> { - ERRORS_QUEUE - .range_raw(store, None, None, Order::Ascending) - .collect() -} + fn save_state_ica_created(&self, storage: &mut dyn Storage) -> StdResult<()> { + CONTRACT_STATE.save(storage, &ContractState::IcaCreated)?; + Ok(()) + } -pub fn read_sudo_payload( - store: &mut dyn Storage, - channel_id: String, - seq_id: u64, -) -> StdResult { - let data = SUDO_PAYLOAD.load(store, (channel_id, seq_id))?; - from_json(Binary(data)) -} + fn save_reply_payload(&self, storage: &mut dyn Storage, payload: SudoPayload) -> StdResult<()> { + REPLY_ID_STORAGE.save(storage, &to_json_vec(&payload)?)?; + Ok(()) + } -pub fn save_sudo_payload( - store: &mut dyn Storage, - channel_id: String, - seq_id: u64, - payload: SudoPayload, -) -> StdResult<()> { - SUDO_PAYLOAD.save(store, (channel_id, seq_id), &to_json_vec(&payload)?) -} + fn read_reply_payload(&self, storage: &mut dyn Storage) -> StdResult { + let data = REPLY_ID_STORAGE.load(storage)?; + from_json(Binary(data)) + } + + fn save_sudo_payload( + &self, + storage: &mut dyn Storage, + channel_id: String, + seq_id: u64, + payload: SudoPayload, + ) -> StdResult<()> { + SUDO_PAYLOAD.save(storage, (channel_id, seq_id), &to_json_vec(&payload)?) + } -pub fn clear_sudo_payload(store: &mut dyn Storage, channel_id: String, seq_id: u64) { - SUDO_PAYLOAD.remove(store, (channel_id, seq_id)) + fn get_ica(&self, storage: &dyn Storage, key: String) -> StdResult<(String, String)> { + INTERCHAIN_ACCOUNTS + .load(storage, key)? + .ok_or_else(|| StdError::generic_err("Interchain account is not created yet")) + } } diff --git a/packages/covenant-utils/Cargo.toml b/packages/covenant-utils/Cargo.toml index 7a627de9..4769add9 100644 --- a/packages/covenant-utils/Cargo.toml +++ b/packages/covenant-utils/Cargo.toml @@ -22,3 +22,4 @@ polytone = "1.0.0" covenant-macros = { workspace = true } sha2 = { workspace = true } bech32 = { workspace = true } +serde-json-wasm = { workspace = true } diff --git a/packages/covenant-utils/src/ica.rs b/packages/covenant-utils/src/ica.rs new file mode 100644 index 00000000..432ccb73 --- /dev/null +++ b/packages/covenant-utils/src/ica.rs @@ -0,0 +1,200 @@ +use cosmwasm_schema::cw_serde; +use cosmwasm_std::{ + Binary, Coin, CosmosMsg, DepsMut, Env, QuerierWrapper, QueryRequest, Reply, Response, StdError, + StdResult, Storage, SubMsg, Uint64, +}; +use neutron_sdk::{ + bindings::{ + msg::{MsgSubmitTxResponse, NeutronMsg}, + query::NeutronQuery, + }, + interchain_txs::helpers::get_port_id, + sudo::msg::RequestPacket, +}; + +use crate::neutron::{OpenAckVersion, SudoPayload}; + +type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; + +pub trait IcaStateHelper { + fn reset_state(&self, storage: &mut dyn Storage) -> StdResult<()>; + fn clear_ica(&self, storage: &mut dyn Storage) -> StdResult<()>; + fn save_ica( + &self, + storage: &mut dyn Storage, + port_id: String, + address: String, + controller_connection_id: String, + ) -> StdResult<()>; + fn save_state_ica_created(&self, storage: &mut dyn Storage) -> StdResult<()>; + fn save_reply_payload(&self, storage: &mut dyn Storage, payload: SudoPayload) -> StdResult<()>; + fn read_reply_payload(&self, storage: &mut dyn Storage) -> StdResult; + fn save_sudo_payload( + &self, + storage: &mut dyn Storage, + channel_id: String, + seq_id: u64, + payload: SudoPayload, + ) -> StdResult<()>; + fn get_ica(&self, storage: &dyn Storage, key: String) -> StdResult<(String, String)>; +} + +/// reverts th contract state to Instantiated and clears the ICA storage. +/// channel is already closed. +pub fn sudo_timeout( + state_helper: &H, + deps: ExecuteDeps, + _env: Env, + _request: RequestPacket, +) -> StdResult> { + // revert the state to Instantiated to force re-creation of ICA + state_helper.reset_state(deps.storage)?; + state_helper.clear_ica(deps.storage)?; + + // returning Ok as this is anticipated. channel is already closed. + Ok(Response::default()) +} + +/// handles the response. if request sequence or source channel are missing, +/// it will return an error and close the channel. otherwise returns an Ok() +/// with data encoded in base64 as a response attribute. +pub fn sudo_response(request: RequestPacket, data: Binary) -> StdResult> { + // either of these errors will close the channel + request + .sequence + .ok_or_else(|| StdError::generic_err("sequence not found"))?; + + request + .source_channel + .ok_or_else(|| StdError::generic_err("channel_id not found"))?; + + Ok(Response::default() + .add_attribute("method", "sudo_response") + .add_attribute("data", data.to_base64())) +} + +/// handles the sudo error. if request sequence or source channel are missing, +/// it will return an error and close the channel. otherwise returns an Ok(). +pub fn sudo_error(request: RequestPacket, _details: String) -> StdResult> { + // either of these errors will close the channel + request + .sequence + .ok_or_else(|| StdError::generic_err("sequence not found"))?; + + request + .source_channel + .ok_or_else(|| StdError::generic_err("channel_id not found"))?; + + Ok(Response::default().add_attribute("method", "sudo_error")) +} + +pub fn sudo_open_ack( + state_helper: &H, + deps: ExecuteDeps, + _env: Env, + port_id: String, + _channel_id: String, + _counterparty_channel_id: String, + counterparty_version: String, +) -> StdResult> { + // The version variable contains a JSON value with multiple fields, + // including the generated account address. + let parsed_version: Result = + serde_json_wasm::from_str(counterparty_version.as_str()); + + // get the parsed OpenAckVersion or return an error if we fail + let Ok(parsed_version) = parsed_version else { + return Err(StdError::generic_err("Can't parse counterparty_version")); + }; + + state_helper.save_ica( + deps.storage, + port_id, + parsed_version.address, + parsed_version.controller_connection_id, + )?; + state_helper.save_state_ica_created(deps.storage)?; + + Ok(Response::default().add_attribute("method", "sudo_open_ack")) +} + +/// prepare_sudo_payload is called from reply handler +/// The method is used to extract sequence id and channel from SubmitTxResponse to +/// process sudo payload defined in msg_with_sudo_callback later in Sudo handler. +/// Such flow msg_with_sudo_callback() -> reply() -> prepare_sudo_payload() -> sudo() +/// allows you "attach" some payload to your SubmitTx message +/// and process this payload when an acknowledgement for the SubmitTx message +/// is received in Sudo handler +pub fn prepare_sudo_payload( + state_helper: &H, + deps: ExecuteDeps, + _env: Env, + msg: Reply, +) -> StdResult> { + let payload = state_helper.read_reply_payload(deps.storage)?; + + let resp: MsgSubmitTxResponse = serde_json_wasm::from_slice( + msg.result + .into_result() + .map_err(StdError::generic_err)? + .data + .ok_or_else(|| StdError::generic_err("no result"))? + .as_slice(), + ) + .map_err(|e| StdError::generic_err(format!("failed to parse response: {e:?}")))?; + + let seq_id = resp.sequence_id; + let channel_id = resp.channel; + + state_helper.save_sudo_payload(deps.storage, channel_id, seq_id, payload)?; + + Ok(Response::default()) +} + +pub fn get_ica( + state_helper: &H, + storage: &dyn Storage, + contract_addr: &str, + ica_id: &str, +) -> StdResult<(String, String)> { + let key = get_port_id(contract_addr, ica_id); + state_helper.get_ica(storage, key) +} + +pub fn msg_with_sudo_callback>, T, H: IcaStateHelper>( + state_helper: &H, + deps: ExecuteDeps, + msg: C, + payload: SudoPayload, + reply_id: u64, +) -> StdResult> { + state_helper.save_reply_payload(deps.storage, payload)?; + Ok(SubMsg::reply_on_success(msg, reply_id)) +} + +// manual definitions for neutron ictxs module +#[cw_serde] +pub struct Params { + pub msg_submit_tx_max_messages: Uint64, + pub register_fee: Vec, +} + +#[cw_serde] +pub struct QueryParamsResponse { + pub params: Params, +} + +pub fn get_ictxs_module_params_query_msg() -> QueryRequest { + QueryRequest::Stargate { + path: "/neutron.interchaintxs.v1.Query/Params".to_string(), + data: Binary(Vec::new()), + } +} + +pub fn query_ica_registration_fee( + querier: QuerierWrapper<'_, NeutronQuery>, +) -> StdResult> { + let query_msg = get_ictxs_module_params_query_msg(); + let response: QueryParamsResponse = querier.query(&query_msg)?; + Ok(response.params.register_fee) +} diff --git a/packages/covenant-utils/src/lib.rs b/packages/covenant-utils/src/lib.rs index 6261caf2..818cda4d 100644 --- a/packages/covenant-utils/src/lib.rs +++ b/packages/covenant-utils/src/lib.rs @@ -12,6 +12,7 @@ use neutron_sdk::{ pub mod astroport; pub mod deadline; +pub mod ica; pub mod instantiate2_helper; pub mod liquid_pooler_withdraw; pub mod neutron; diff --git a/packages/covenant-utils/src/neutron.rs b/packages/covenant-utils/src/neutron.rs index ba3f9a13..d167dc7b 100644 --- a/packages/covenant-utils/src/neutron.rs +++ b/packages/covenant-utils/src/neutron.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Attribute, Binary, Coin, QueryRequest, StdError, Uint128, Uint64}; +use cosmwasm_std::{Attribute, Binary, StdError, Uint128, Uint64}; use neutron_sdk::{ - bindings::{query::NeutronQuery, types::ProtobufAny}, + bindings::types::ProtobufAny, NeutronResult, }; use prost::Message; @@ -126,22 +126,3 @@ pub fn to_proto_msg_multi_send(msg: impl Message) -> NeutronResult value: Binary::from(buf), }) } - -// manual definitions for neutron ictxs module -#[cw_serde] -pub struct Params { - pub msg_submit_tx_max_messages: Uint64, - pub register_fee: Vec, -} - -#[cw_serde] -pub struct QueryParamsResponse { - pub params: Params, -} - -pub fn get_ictxs_module_params_query_msg() -> QueryRequest { - QueryRequest::Stargate { - path: "/neutron.interchaintxs.v1.Query/Params".to_string(), - data: Binary(Vec::new()), - } -} diff --git a/unit-tests/src/setup/custom_keepers.rs b/unit-tests/src/setup/custom_keepers.rs index fd999638..70328405 100644 --- a/unit-tests/src/setup/custom_keepers.rs +++ b/unit-tests/src/setup/custom_keepers.rs @@ -4,7 +4,7 @@ use cosmwasm_std::{ from_json, to_json_binary, Addr, Api, Binary, BlockInfo, CustomMsg, CustomQuery, Querier, Storage, }; -use covenant_utils::neutron::{Params, QueryParamsResponse}; +use covenant_utils::ica::{Params, QueryParamsResponse}; use cw_multi_test::error::{AnyError, AnyResult}; use cw_multi_test::{AppResponse, CosmosRouter, Module, StargateQuery}; use osmosis_std::types::cosmos::base::v1beta1::Coin; From 30374dcd17a70fe7595113b67dd024e0a10d3399 Mon Sep 17 00:00:00 2001 From: bekauz Date: Wed, 20 Mar 2024 19:24:27 +0100 Subject: [PATCH 37/56] moving ibc fee query and assertion to utils --- contracts/ibc-forwarder/src/contract.rs | 32 +++------ contracts/interchain-router/src/contract.rs | 36 ++++------ .../src/suite_tests/tests.rs | 2 +- contracts/native-splitter/src/contract.rs | 16 ++--- .../remote-chain-splitter/src/contract.rs | 26 ++------ .../stride-liquid-staker/src/contract.rs | 4 +- packages/covenant-utils/src/lib.rs | 21 +----- packages/covenant-utils/src/neutron.rs | 65 ++++++++++++++++++- 8 files changed, 104 insertions(+), 98 deletions(-) diff --git a/contracts/ibc-forwarder/src/contract.rs b/contracts/ibc-forwarder/src/contract.rs index f3b037bd..e974b980 100644 --- a/contracts/ibc-forwarder/src/contract.rs +++ b/contracts/ibc-forwarder/src/contract.rs @@ -13,15 +13,15 @@ use covenant_utils::{ get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, sudo_error, sudo_open_ack, sudo_response, sudo_timeout, }, - neutron::{get_proto_coin, to_proto_msg_transfer, RemoteChainInfo, SudoPayload}, - sum_fees, + neutron::{ + assert_ibc_fee_coverage, get_proto_coin, query_ibc_fee, to_proto_msg_transfer, + RemoteChainInfo, SudoPayload, + }, }; use cw2::set_contract_version; -use cw_utils::must_pay; use neutron_sdk::{ bindings::{msg::NeutronMsg, query::NeutronQuery, types::ProtobufAny}, interchain_txs::helpers::get_port_id, - query::min_ibc_fee::MinIbcFeeResponse, sudo::msg::SudoMsg, NeutronError, NeutronResult, }; @@ -107,21 +107,8 @@ fn try_distribute_fallback( }; let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; - let min_fee_query_response: MinIbcFeeResponse = - deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; - let total_fee_amount = sum_fees(&min_fee_query_response.min_fee); - // the caller must cover the ibc fees - match must_pay(&info, "untrn") { - Ok(amt) => ensure!( - amt >= total_fee_amount.checked_mul(Uint128::new(coins.len() as u128))?, - NeutronError::Std(StdError::generic_err("insufficient fees")) - ), - Err(_) => { - return Err(NeutronError::Std(StdError::generic_err( - "must cover ibc fees to distribute fallback denoms", - ))) - } - }; + let min_ibc_fee_config = query_ibc_fee(deps.querier)?; + assert_ibc_fee_coverage(info, min_ibc_fee_config.total_ntrn_fee, Uint128::one())?; // we iterate over coins to be distributed, validate them, and generate the proto coins to be sent let mut encountered_denoms: BTreeSet = BTreeSet::new(); @@ -176,7 +163,7 @@ fn try_distribute_fallback( vec![any_msg], "".to_string(), remote_chain_info.ica_timeout.u64(), - min_fee_query_response.min_fee, + min_ibc_fee_config.ibc_fee, ); let state_helper = IbcForwarderIcaStateHelper; let sudo_msg = msg_with_sudo_callback( @@ -246,8 +233,7 @@ fn try_forward_funds(env: Env, mut deps: ExecuteDeps) -> NeutronResult NeutronResult ensure!( - amt >= total_fee, - NeutronError::Std(StdError::generic_err("insufficient fees")) - ), - Err(e) => return Err(ContractError::IbcFeeError(e).to_neutron_std()), - }; + assert_ibc_fee_coverage( + info, + min_ibc_fee_config.total_ntrn_fee, + Uint128::from(denoms.len() as u128), + )?; for denom in denoms { // we do not distribute the main covenant denoms @@ -110,12 +103,11 @@ fn try_distribute_fallback( available_balances.push(queried_coin); } - let min_ibc_fee: MinIbcFeeResponse = deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; let fallback_distribution_messages = destination_config.get_ibc_transfer_messages_for_coins( available_balances, env.block.time, env.contract.address.to_string(), - min_ibc_fee.min_fee, + min_ibc_fee_config.ibc_fee, )?; Ok(Response::default() diff --git a/contracts/interchain-router/src/suite_tests/tests.rs b/contracts/interchain-router/src/suite_tests/tests.rs index 5bae4d8f..6689ab7e 100644 --- a/contracts/interchain-router/src/suite_tests/tests.rs +++ b/contracts/interchain-router/src/suite_tests/tests.rs @@ -88,7 +88,7 @@ fn test_unauthorized_tick() { } #[test] -#[should_panic(expected = "caller must cover ibc fees: No funds sent")] +#[should_panic(expected = "must cover ibc fees to distribute fallback denoms")] fn test_tick_no_ibc_fee() { let usdc_coin = coin(100, "usdc"); let random_coin_1 = coin(100, "denom1"); diff --git a/contracts/native-splitter/src/contract.rs b/contracts/native-splitter/src/contract.rs index 812b1c42..094f3048 100644 --- a/contracts/native-splitter/src/contract.rs +++ b/contracts/native-splitter/src/contract.rs @@ -3,8 +3,8 @@ use std::collections::BTreeMap; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Order, Response, StdError, - StdResult, + ensure, to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Order, Response, + StdError, StdResult, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::split::SplitConfig; @@ -101,17 +101,13 @@ fn try_distribute_fallback( let mut distribution_messages: Vec = vec![]; if let Some(split) = FALLBACK_SPLIT.may_load(deps.storage)? { - let explicit_denoms = SPLIT_CONFIG_MAP - .range(deps.storage, None, None, Order::Ascending) - .map(|split| Ok(split?.0)) - .collect::, ContractError>>()?; - for denom in denoms { // we do not distribute the main covenant denoms // according to the fallback split - if explicit_denoms.contains(&denom) { - return Err(StdError::generic_err("unauthorized denom distribution").into()); - } + ensure!( + !SPLIT_CONFIG_MAP.has(deps.storage, denom.to_string()), + ContractError::Std(StdError::generic_err("unauthorized denom distribution")) + ); let balance = deps .querier diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index 082c1717..a4b70877 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -15,10 +15,11 @@ use covenant_utils::ica::{ get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, sudo_error, sudo_open_ack, sudo_response, sudo_timeout, }; -use covenant_utils::neutron::{get_proto_coin, RemoteChainInfo, SudoPayload}; -use covenant_utils::{neutron, soft_validate_remote_chain_addr, sum_fees}; +use covenant_utils::neutron::{ + assert_ibc_fee_coverage, get_proto_coin, query_ibc_fee, RemoteChainInfo, SudoPayload, +}; +use covenant_utils::{neutron, soft_validate_remote_chain_addr}; use cw2::set_contract_version; -use cw_utils::must_pay; use neutron_sdk::bindings::types::ProtobufAny; use neutron_sdk::interchain_txs::helpers::get_port_id; use neutron_sdk::query::min_ibc_fee::MinIbcFeeResponse; @@ -116,22 +117,9 @@ fn try_distribute_fallback( None => return Err(ContractError::MissingFallbackAddress {}.into()), }; let remote_chain_info = REMOTE_CHAIN_INFO.load(deps.storage)?; + let ibc_fee_response = query_ibc_fee(deps.querier)?; - let min_fee_query_response: MinIbcFeeResponse = - deps.querier.query(&NeutronQuery::MinIbcFee {}.into())?; - let total_fee_amount = sum_fees(&min_fee_query_response.min_fee); - // the caller must cover the ibc fees - match must_pay(&info, "untrn") { - Ok(amt) => ensure!( - amt >= total_fee_amount.checked_mul(Uint128::new(coins.len() as u128))?, - NeutronError::Std(StdError::generic_err("insufficient fees")) - ), - Err(_) => { - return Err(NeutronError::Std(StdError::generic_err( - "must cover ibc fees to distribute fallback denoms", - ))) - } - }; + assert_ibc_fee_coverage(info, ibc_fee_response.total_ntrn_fee, Uint128::one())?; // we iterate over coins to be distributed, validate them, and generate the proto coins to be sent let mut encountered_denoms: BTreeSet = BTreeSet::new(); @@ -184,7 +172,7 @@ fn try_distribute_fallback( vec![any_msg], "".to_string(), remote_chain_info.ica_timeout.u64(), - min_fee_query_response.min_fee, + ibc_fee_response.ibc_fee, ); let sudo_msg = msg_with_sudo_callback( &RemoteChainSplitteIcaStateHelper, diff --git a/contracts/stride-liquid-staker/src/contract.rs b/contracts/stride-liquid-staker/src/contract.rs index 7d7d1134..3692d7da 100644 --- a/contracts/stride-liquid-staker/src/contract.rs +++ b/contracts/stride-liquid-staker/src/contract.rs @@ -2,8 +2,8 @@ use cosmos_sdk_proto::ibc::applications::transfer::v1::MsgTransfer; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - coins, to_json_binary, to_json_string, Binary, Deps, DepsMut, Env, MessageInfo, Reply, - Response, StdError, StdResult, Uint128, + to_json_binary, to_json_string, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, + StdError, StdResult, Uint128, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::ica::{ diff --git a/packages/covenant-utils/src/lib.rs b/packages/covenant-utils/src/lib.rs index 818cda4d..2d52b015 100644 --- a/packages/covenant-utils/src/lib.rs +++ b/packages/covenant-utils/src/lib.rs @@ -5,6 +5,7 @@ use cosmwasm_std::{ to_json_string, Addr, Api, Attribute, Coin, CosmosMsg, Decimal, StdError, StdResult, Timestamp, Uint128, Uint64, }; +use neutron::flatten_ibc_fee_total_amount; use neutron_sdk::{ bindings::msg::{IbcFee, NeutronMsg}, sudo::msg::RequestPacketTimeoutHeight, @@ -230,24 +231,6 @@ pub struct ForwardMetadata { pub channel: String, } -pub fn sum_fees(ibc_fee: &IbcFee) -> Uint128 { - let mut total_amount = Uint128::zero(); - - for coin in &ibc_fee.recv_fee { - total_amount += coin.amount; - } - - for coin in &ibc_fee.ack_fee { - total_amount += coin.amount; - } - - for coin in &ibc_fee.timeout_fee { - total_amount += coin.amount; - } - - total_amount -} - impl DestinationConfig { pub fn get_ibc_transfer_messages_for_coins( &self, @@ -261,7 +244,7 @@ impl DestinationConfig { // neutron fees for let count = Uint128::from(1 + coins.len() as u128); - let total_fee = sum_fees(&ibc_fee); + let total_fee = flatten_ibc_fee_total_amount(&ibc_fee); for coin in coins { let send_coin = if coin.denom != "untrn" { diff --git a/packages/covenant-utils/src/neutron.rs b/packages/covenant-utils/src/neutron.rs index d167dc7b..9ee900e4 100644 --- a/packages/covenant-utils/src/neutron.rs +++ b/packages/covenant-utils/src/neutron.rs @@ -1,7 +1,11 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Attribute, Binary, StdError, Uint128, Uint64}; +use cosmwasm_std::{ + Attribute, Binary, MessageInfo, QuerierWrapper, StdError, StdResult, Uint128, Uint64, +}; +use cw_utils::must_pay; use neutron_sdk::{ - bindings::types::ProtobufAny, + bindings::{msg::IbcFee, query::NeutronQuery, types::ProtobufAny}, + query::min_ibc_fee::MinIbcFeeResponse, NeutronResult, }; use prost::Message; @@ -126,3 +130,60 @@ pub fn to_proto_msg_multi_send(msg: impl Message) -> NeutronResult value: Binary::from(buf), }) } + +#[cw_serde] +pub struct MinIbcFeeConfig { + pub ibc_fee: IbcFee, + pub total_ntrn_fee: Uint128, +} + +pub fn query_ibc_fee(querier: QuerierWrapper<'_, NeutronQuery>) -> StdResult { + let min_fee_query_response: MinIbcFeeResponse = + querier.query(&NeutronQuery::MinIbcFee {}.into())?; + let total_fee_amount = flatten_ibc_fee_total_amount(&min_fee_query_response.min_fee); + + Ok(MinIbcFeeConfig { + ibc_fee: min_fee_query_response.min_fee, + total_ntrn_fee: total_fee_amount, + }) +} + +pub fn flatten_ibc_fee_total_amount(ibc_fee: &IbcFee) -> Uint128 { + let mut total_amount = Uint128::zero(); + + for coin in &ibc_fee.recv_fee { + total_amount += coin.amount; + } + + for coin in &ibc_fee.ack_fee { + total_amount += coin.amount; + } + + for coin in &ibc_fee.timeout_fee { + total_amount += coin.amount; + } + + total_amount +} + +/// assertion helper that checks if the caller has covered ibc fees +/// for `count` number of transactions +pub fn assert_ibc_fee_coverage( + info: MessageInfo, + total_fee: Uint128, + count: Uint128, +) -> StdResult<()> { + // the caller must cover the ibc fees + match must_pay(&info, "untrn") { + Ok(amt) => { + if amt < total_fee.checked_mul(count)? { + Err(StdError::generic_err("insufficient fees")) + } else { + Ok(()) + } + } + Err(_) => Err(StdError::generic_err( + "must cover ibc fees to distribute fallback denoms", + )), + } +} From dffb4d265a0d46e6e93eca62f0277767c57f9f3d Mon Sep 17 00:00:00 2001 From: bekauz Date: Thu, 28 Mar 2024 13:13:14 +0100 Subject: [PATCH 38/56] removing submsg events from astroport liquid pooler reply attributes --- contracts/astroport-liquid-pooler/src/contract.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/contracts/astroport-liquid-pooler/src/contract.rs b/contracts/astroport-liquid-pooler/src/contract.rs index 32ca235c..4ca97aa7 100644 --- a/contracts/astroport-liquid-pooler/src/contract.rs +++ b/contracts/astroport-liquid-pooler/src/contract.rs @@ -591,12 +591,8 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> NeutronResult Result { match msg.result { - SubMsgResult::Ok(val) => { - // astroport only sets SubMsgResponse data in case it's a multi-hop swap. - // we only deal with direct swaps so we ignore the data. - let response = Response::default() - .add_attribute("reply_id", msg.id.to_string()) - .add_events(val.events); + SubMsgResult::Ok(_) => { + let response = Response::default().add_attribute("reply_id", msg.id.to_string()); match msg.id { DOUBLE_SIDED_REPLY_ID => handle_double_sided_reply_id(response), From 59b723deabe72150df8377f953b5b37a065b9078 Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 5 Apr 2024 19:28:28 +0200 Subject: [PATCH 39/56] two party POL holder refunds from Complete state --- .../two-party-pol-holder/src/contract.rs | 113 ++++++++++-------- .../src/test_two_party_pol_holder/tests.rs | 54 ++++++++- 2 files changed, 110 insertions(+), 57 deletions(-) diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index 048763d1..89c1c8fe 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -379,24 +379,19 @@ fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> Result try_deposit(deps, env, info, clock_addr.as_str()), + ContractState::Instantiated => try_deposit(deps, env, info), ContractState::Active => check_expiration(deps, env), - ContractState::Expired | ContractState::Ragequit | ContractState::Complete => { - Ok(Response::default() - .add_attribute("method", "tick") - .add_attribute("contract_state", state.to_string())) - } + ContractState::Expired | ContractState::Ragequit => Ok(Response::default() + .add_attribute("method", "tick") + .add_attribute("contract_state", state.to_string())), + ContractState::Complete => try_refund(deps, env), } } -fn try_deposit( - mut deps: DepsMut, - env: Env, - _info: MessageInfo, - clock_addr: &str, -) -> Result { +/// attempts to route any available covenant party contribution denoms to +/// the parties that were responsible for contributing that denom. +fn try_refund(deps: DepsMut, env: Env) -> Result { let config = COVENANT_CONFIG.load(deps.storage)?; - let deposit_deadline = DEPOSIT_DEADLINE.load(deps.storage)?; // assert the balances let party_a_bal = deps.querier.query_balance( @@ -408,52 +403,64 @@ fn try_deposit( config.party_b.contribution.denom, )?; - let party_a_fulfilled = config.party_a.contribution.amount <= party_a_bal.amount; - let party_b_fulfilled = config.party_b.contribution.amount <= party_b_bal.amount; - - // note: even if both parties deposit their funds in time, - // it is important to trigger this method before the expiry block - // if deposit deadline is due we complete and refund - if deposit_deadline.is_expired(&env.block) { - let dequeue_message = ContractState::complete_and_dequeue(deps.branch(), clock_addr)?; - let refund_messages: Vec = - match (party_a_bal.amount.is_zero(), party_b_bal.amount.is_zero()) { - // both balances empty, we complete - (true, true) => { - return Ok(Response::default() - .add_message(dequeue_message) - .add_attribute("method", "try_deposit") - .add_attribute("state", "complete")); - } - // refund party B - (true, false) => vec![CosmosMsg::Bank(BankMsg::Send { + let refund_messages: Vec = + match (party_a_bal.amount.is_zero(), party_b_bal.amount.is_zero()) { + // both balances empty, nothing to refund + (true, true) => vec![], + // refund party B + (true, false) => vec![CosmosMsg::Bank(BankMsg::Send { + to_address: config.party_b.router, + amount: vec![party_b_bal], + })], + // refund party A + (false, true) => vec![CosmosMsg::Bank(BankMsg::Send { + to_address: config.party_a.router, + amount: vec![party_a_bal], + })], + // refund both + (false, false) => vec![ + CosmosMsg::Bank(BankMsg::Send { + to_address: config.party_a.router.to_string(), + amount: vec![party_a_bal], + }), + CosmosMsg::Bank(BankMsg::Send { to_address: config.party_b.router, amount: vec![party_b_bal], - })], - // refund party A - (false, true) => vec![CosmosMsg::Bank(BankMsg::Send { - to_address: config.party_a.router, - amount: vec![party_a_bal], - })], - // refund both - (false, false) => vec![ - CosmosMsg::Bank(BankMsg::Send { - to_address: config.party_a.router.to_string(), - amount: vec![party_a_bal], - }), - CosmosMsg::Bank(BankMsg::Send { - to_address: config.party_b.router, - amount: vec![party_b_bal], - }), - ], - }; + }), + ], + }; + + Ok(Response::default() + .add_attribute("contract_state", "complete") + .add_attribute("method", "try_refund") + .add_messages(refund_messages)) +} + +fn try_deposit(deps: DepsMut, env: Env, _info: MessageInfo) -> Result { + let deposit_deadline = DEPOSIT_DEADLINE.load(deps.storage)?; + if deposit_deadline.is_expired(&env.block) { + CONTRACT_STATE.save(deps.storage, &ContractState::Complete)?; return Ok(Response::default() .add_attribute("method", "try_deposit") - .add_attribute("action", "refund") - .add_messages(refund_messages) - .add_message(dequeue_message)); + .add_attribute("deposit_deadline", "expired") + .add_attribute("action", "complete")); } + let config = COVENANT_CONFIG.load(deps.storage)?; + + // assert the balances + let party_a_bal = deps.querier.query_balance( + env.contract.address.to_string(), + config.party_a.contribution.denom, + )?; + let party_b_bal = deps.querier.query_balance( + env.contract.address.to_string(), + config.party_b.contribution.denom, + )?; + + let party_a_fulfilled = config.party_a.contribution.amount <= party_a_bal.amount; + let party_b_fulfilled = config.party_b.contribution.amount <= party_b_bal.amount; + if !party_a_fulfilled || !party_b_fulfilled { // if deposit deadline is not yet due and both parties did not fulfill we error return Err(ContractError::InsufficientDeposits {}); diff --git a/unit-tests/src/test_two_party_pol_holder/tests.rs b/unit-tests/src/test_two_party_pol_holder/tests.rs index cd22c7b7..4442e569 100644 --- a/unit-tests/src/test_two_party_pol_holder/tests.rs +++ b/unit-tests/src/test_two_party_pol_holder/tests.rs @@ -266,8 +266,21 @@ fn test_execute_tick_expired_deposit_refunds_both_parties() { suite.tick_contract(suite.holder_addr.clone()).assert_event( &Event::new("wasm") .add_attribute("method", "try_deposit") - .add_attribute("action", "refund"), + .add_attribute("deposit_deadline", "expired") + .add_attribute("action", "complete"), ); + + assert!(matches!( + suite.query_contract_state(), + ContractState::Complete {} + )); + + suite.tick_contract(suite.holder_addr.clone()).assert_event( + &Event::new("wasm") + .add_attribute("contract_state", "complete") + .add_attribute("method", "try_refund"), + ); + suite.assert_balance( &suite.covenant_config.party_a.router, coin(10_000, DENOM_ATOM_ON_NTRN), @@ -296,8 +309,21 @@ fn test_execute_tick_expired_deposit_refunds_party_a() { suite.tick_contract(suite.holder_addr.clone()).assert_event( &Event::new("wasm") .add_attribute("method", "try_deposit") - .add_attribute("action", "refund"), + .add_attribute("deposit_deadline", "expired") + .add_attribute("action", "complete"), ); + + assert!(matches!( + suite.query_contract_state(), + ContractState::Complete {} + )); + + suite.tick_contract(suite.holder_addr.clone()).assert_event( + &Event::new("wasm") + .add_attribute("contract_state", "complete") + .add_attribute("method", "try_refund"), + ); + suite.assert_balance( &suite.covenant_config.party_a.router, coin(10_000, DENOM_ATOM_ON_NTRN), @@ -322,8 +348,21 @@ fn test_execute_tick_expired_deposit_refunds_party_b() { suite.tick_contract(suite.holder_addr.clone()).assert_event( &Event::new("wasm") .add_attribute("method", "try_deposit") - .add_attribute("action", "refund"), + .add_attribute("deposit_deadline", "expired") + .add_attribute("action", "complete"), + ); + + assert!(matches!( + suite.query_contract_state(), + ContractState::Complete {} + )); + + suite.tick_contract(suite.holder_addr.clone()).assert_event( + &Event::new("wasm") + .add_attribute("contract_state", "complete") + .add_attribute("method", "try_refund"), ); + suite.assert_balance( &suite.covenant_config.party_b.router, coin(10_000, DENOM_LS_ATOM_ON_NTRN), @@ -342,12 +381,19 @@ fn test_execute_tick_expired_deposit_completes() { suite.tick_contract(suite.holder_addr.clone()).assert_event( &Event::new("wasm") .add_attribute("method", "try_deposit") - .add_attribute("state", "complete"), + .add_attribute("deposit_deadline", "expired") + .add_attribute("action", "complete"), ); assert!(matches!( suite.query_contract_state(), ContractState::Complete {} )); + // no funds in the contract to refund, therefore noop + suite.tick_contract(suite.holder_addr.clone()).assert_event( + &Event::new("wasm") + .add_attribute("contract_state", "complete") + .add_attribute("method", "try_refund"), + ); } #[test] From b5a096b03448d6e52548def28c6a99ee11b696f1 Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 8 Apr 2024 15:44:37 +0200 Subject: [PATCH 40/56] swap holder indefinitely attempts party deposit refunds from expired state --- contracts/swap-holder/README.md | 7 +- contracts/swap-holder/src/contract.rs | 122 +++++++++++------------ unit-tests/src/test_swap_holder/tests.rs | 35 ++----- 3 files changed, 67 insertions(+), 97 deletions(-) diff --git a/contracts/swap-holder/README.md b/contracts/swap-holder/README.md index 3547be40..ade22b83 100644 --- a/contracts/swap-holder/README.md +++ b/contracts/swap-holder/README.md @@ -4,6 +4,9 @@ Swap Holder is a contract meant to facilitate a tokenswap covenant between two p It holds a list of parties participating in the swap with amount and denom theyre expected to provide. -If holder receives all expected tokens, it forwards them to the splitter module and completes. +If holder receives all expected tokens before the deposit deadline expires, +it forwards them to the splitter module, dequeues from the clock, and completes. -After a specified duration, parties that delivered their funds are allowed to withdraw (or are automatically refunded). +If either/both party contributions fail to reach this contract before the expiration deadline, +holder completes without dequeuing itself from the clock. This enables any late deposits +to be refunded to the parties. diff --git a/contracts/swap-holder/src/contract.rs b/contracts/swap-holder/src/contract.rs index f49e671f..db184213 100644 --- a/contracts/swap-holder/src/contract.rs +++ b/contracts/swap-holder/src/contract.rs @@ -76,13 +76,63 @@ fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> Result try_forward(deps, env, info.sender), - ContractState::Expired => try_refund(deps, env, info.sender), - ContractState::Complete => { - Ok(Response::default().add_attribute("contract_state", "completed")) - } + ContractState::Expired => try_refund(deps, env), + ContractState::Complete => Ok(Response::default() + .add_attribute("contract_state", "complete") + .add_attribute("method", "try_tick")), } } +/// attempts to route any available covenant party contribution denoms to +/// the parties that were responsible for contributing that denom. +fn try_refund(deps: DepsMut, env: Env) -> Result { + let parties = PARTIES_CONFIG.load(deps.storage)?; + let refund_config = REFUND_CONFIG.load(deps.storage)?; + + // query holder balances + let party_a_bal = deps.querier.query_balance( + env.contract.address.to_string(), + parties.party_a.native_denom, + )?; + let party_b_bal = deps.querier.query_balance( + env.contract.address.to_string(), + parties.party_b.native_denom, + )?; + + let refund_messages: Vec = + match (party_a_bal.amount.is_zero(), party_b_bal.amount.is_zero()) { + // both balances empty, nothing to refund + (true, true) => vec![], + // party A failed to deposit. refund party B + (true, false) => vec![CosmosMsg::Bank(BankMsg::Send { + to_address: refund_config.party_b_refund_address, + amount: vec![party_b_bal], + })], + // party B failed to deposit. refund party A + (false, true) => vec![CosmosMsg::Bank(BankMsg::Send { + to_address: refund_config.party_a_refund_address, + amount: vec![party_a_bal], + })], + // not enough balances to perform the covenant swap. + // refund denoms to both parties. + (false, false) => vec![ + CosmosMsg::Bank(BankMsg::Send { + to_address: refund_config.party_a_refund_address, + amount: vec![party_a_bal], + }), + CosmosMsg::Bank(BankMsg::Send { + to_address: refund_config.party_b_refund_address, + amount: vec![party_b_bal], + }), + ], + }; + + Ok(Response::default() + .add_attribute("contract_state", "expired") + .add_attribute("method", "try_refund") + .add_messages(refund_messages)) +} + fn try_forward(mut deps: DepsMut, env: Env, clock_addr: Addr) -> Result { let lockup_config = LOCKUP_CONFIG.load(deps.storage)?; // check if covenant is expired @@ -138,6 +188,8 @@ fn try_forward(mut deps: DepsMut, env: Env, clock_addr: Addr) -> Result Result Result { - let parties = PARTIES_CONFIG.load(deps.storage)?; - - // Query balance for the parties - let party_a_coin = deps.querier.query_balance( - env.contract.address.clone(), - parties.party_a.native_denom.clone(), - )?; - let party_b_coin = deps - .querier - .query_balance(env.contract.address, parties.party_b.native_denom.clone())?; - - let refund_config = REFUND_CONFIG.load(deps.storage)?; - - let messages: Vec = - match (party_a_coin.amount.is_zero(), party_b_coin.amount.is_zero()) { - // both balances being zero means that either: - // 1. neither party deposited any funds in the first place - // 2. we have refunded both parties - // either way, this indicates completion - (true, true) => { - let msg = ContractState::complete_and_dequeue(deps.branch(), clock_addr.as_str())?; - - return Ok(Response::default() - .add_message(msg) - .add_attribute("method", "try_refund") - .add_attribute("result", "nothing_to_refund") - .add_attribute("contract_state", "complete")); - } - // party A failed to deposit. refund party B - (true, false) => vec![BankMsg::Send { - to_address: refund_config.party_b_refund_address, - amount: vec![party_b_coin], - } - .into()], - // party B failed to deposit. refund party A - (false, true) => vec![BankMsg::Send { - to_address: refund_config.party_a_refund_address, - amount: vec![party_a_coin], - } - .into()], - // not enough balances to perform the covenant swap. - // refund denoms to both parties. - (false, false) => vec![ - BankMsg::Send { - to_address: refund_config.party_a_refund_address, - amount: vec![party_a_coin], - } - .into(), - BankMsg::Send { - to_address: refund_config.party_b_refund_address, - amount: vec![party_b_coin], - } - .into(), - ], - }; - - Ok(Response::default() - .add_attribute("method", "try_refund") - .add_messages(messages)) -} - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { diff --git a/unit-tests/src/test_swap_holder/tests.rs b/unit-tests/src/test_swap_holder/tests.rs index ff67a644..932e9fd3 100644 --- a/unit-tests/src/test_swap_holder/tests.rs +++ b/unit-tests/src/test_swap_holder/tests.rs @@ -94,17 +94,6 @@ fn test_execute_tick_instantiated_validates_sufficient_funds() { suite.tick_contract(suite.holder.clone()); } -#[test] -// #[should_panic(expected = "Next contract is not ready for receiving the funds yet")] -fn test_execute_tick_instantiated_validates_next_contract_deposit_addr() { - // let mut suite = SwapHolderBuilder::default().build(); - - // suite.fund_contract(&coins(100000, DENOM_ATOM_ON_NTRN), suite.holder.clone()); - // suite.fund_contract(&coins(100000, DENOM_LS_ATOM_ON_NTRN), suite.holder.clone()); - - // suite.tick_contract(suite.holder.clone()); -} - #[test] fn test_execute_tick_instantiated_forwards_and_completes() { let mut suite = SwapHolderBuilder::default().build(); @@ -139,7 +128,7 @@ fn test_execute_expired_refund_both_parties() { suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Complete {})); + assert!(matches!(contract_state, ContractState::Expired {})); let refund_config = suite.query_refund_config(); suite.assert_balance( @@ -169,7 +158,7 @@ fn test_execute_expired_refund_party_a() { suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Complete {})); + assert!(matches!(contract_state, ContractState::Expired {})); let refund_config = suite.query_refund_config(); suite.assert_balance( @@ -195,7 +184,7 @@ fn test_execute_expired_refund_party_b() { suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Complete {})); + assert!(matches!(contract_state, ContractState::Expired {})); let refund_config = suite.query_refund_config(); suite.assert_balance( @@ -204,24 +193,12 @@ fn test_execute_expired_refund_party_b() { ); } -#[test] -fn test_execute_expired_no_refund_completes() { - let mut suite = SwapHolderBuilder::default().build(); - - suite.expire_lockup_config(); - suite.tick_contract(suite.holder.clone()); - suite.tick_contract(suite.holder.clone()); - - let contract_state = suite.query_contract_state(); - assert!(matches!(contract_state, ContractState::Complete {})); -} - #[test] fn test_execute_tick_on_complete_noop() { let mut suite = SwapHolderBuilder::default().build(); + suite.fund_contract(&coins(100_000, DENOM_LS_ATOM_ON_NTRN), suite.holder.clone()); + suite.fund_contract(&coins(100_000, DENOM_ATOM_ON_NTRN), suite.holder.clone()); - suite.expire_lockup_config(); - suite.tick_contract(suite.holder.clone()); suite.tick_contract(suite.holder.clone()); let contract_state = suite.query_contract_state(); @@ -229,7 +206,7 @@ fn test_execute_tick_on_complete_noop() { suite .tick_contract(suite.holder.clone()) - .assert_event(&Event::new("wasm").add_attribute("contract_state", "completed")); + .assert_event(&Event::new("wasm").add_attribute("contract_state", "complete")); } #[test] From 55a03bd67a16a02570b72ffe34d78523f960d1b5 Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 8 Apr 2024 20:56:26 +0200 Subject: [PATCH 41/56] astro liquid pooler errors out if either of expected pool asset balances is 0 --- contracts/astroport-liquid-pooler/src/contract.rs | 7 +++++++ unit-tests/src/test_astroport_liquid_pooler/tests.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/contracts/astroport-liquid-pooler/src/contract.rs b/contracts/astroport-liquid-pooler/src/contract.rs index 4ca97aa7..30773735 100644 --- a/contracts/astroport-liquid-pooler/src/contract.rs +++ b/contracts/astroport-liquid-pooler/src/contract.rs @@ -240,7 +240,10 @@ fn try_lp(mut deps: DepsMut, env: Env) -> Result { lp_config.asset_data.asset_a_denom.as_str(), lp_config.asset_data.asset_b_denom.as_str(), )?; + + // `get_pool_asset_amounts` ensures that both a and b balances are non-zero so this is safe let a_to_b_ratio = Decimal::from_ratio(pool_token_a_bal, pool_token_b_bal); + // validate the current pool ratio against our expectations lp_config .expected_pool_ratio_range @@ -530,6 +533,10 @@ fn get_pool_asset_amounts( } } + if a_bal.is_zero() || b_bal.is_zero() { + return Err(StdError::generic_err("all pool assets must be non-zero")); + } + Ok((a_bal, b_bal)) } diff --git a/unit-tests/src/test_astroport_liquid_pooler/tests.rs b/unit-tests/src/test_astroport_liquid_pooler/tests.rs index 92f96865..263b1d7f 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/tests.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/tests.rs @@ -242,7 +242,7 @@ fn test_provide_liquidity_validates_pair_type() { } #[test] -#[should_panic(expected = "Denominator must not be zero")] +#[should_panic(expected = "all pool assets must be non-zero")] fn test_provide_liquidity_determine_pool_ratio_asset_b_denom_invalid() { let mut suite = AstroLiquidPoolerBuilder::default() .with_assets(AssetData { From 574fa1f0fc534d2a81f9d76c60b8fd8db54d30be Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 8 Apr 2024 22:02:35 +0200 Subject: [PATCH 42/56] single party holder withdrawer and withdraw_to fields no longer optional --- .../single-party-pol-covenant/src/contract.rs | 4 +- .../single-party-pol-holder/src/contract.rs | 54 +++++++++---------- .../single-party-pol-holder/src/error.rs | 6 --- contracts/single-party-pol-holder/src/msg.rs | 8 +-- .../setup/instantiates/single_party_holder.rs | 12 ++--- .../src/test_astroport_liquid_pooler/suite.rs | 4 +- .../src/test_single_party_holder/suite.rs | 4 +- .../src/test_single_party_holder/tests.rs | 41 +------------- 8 files changed, 42 insertions(+), 91 deletions(-) diff --git a/contracts/single-party-pol-covenant/src/contract.rs b/contracts/single-party-pol-covenant/src/contract.rs index 31788cbe..b63c1622 100644 --- a/contracts/single-party-pol-covenant/src/contract.rs +++ b/contracts/single-party-pol-covenant/src/contract.rs @@ -127,8 +127,8 @@ pub fn instantiate( )?; let holder_instantiate2_msg = HolderInstantiateMsg { - withdrawer: Some(msg.covenant_party_config.addr.to_string()), - withdraw_to: Some(router_instantiate2_config.addr.to_string()), + withdrawer: msg.covenant_party_config.addr.to_string(), + withdraw_to: router_instantiate2_config.addr.to_string(), emergency_committee_addr: msg.emergency_committee.clone(), lockup_period: msg.lockup_period, pooler_address: liquid_pooler_instantiate2_config.addr.to_string(), diff --git a/contracts/single-party-pol-holder/src/contract.rs b/contracts/single-party-pol-holder/src/contract.rs index 9ea0a2f3..94fbbdcc 100644 --- a/contracts/single-party-pol-holder/src/contract.rs +++ b/contracts/single-party-pol-holder/src/contract.rs @@ -21,32 +21,33 @@ pub fn instantiate( msg: InstantiateMsg, ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - let mut resp = Response::default().add_attribute("method", "instantiate"); - // withdrawer is optional on instantiation; can be set later - if let Some(addr) = msg.withdrawer { - WITHDRAWER.save(deps.storage, &deps.api.addr_validate(&addr)?)?; - resp = resp.add_attribute("withdrawer", addr); - }; + let withdrawer = deps.api.addr_validate(&msg.withdrawer)?; + let withdraw_to = deps.api.addr_validate(&msg.withdraw_to)?; + let liquidity_pooler_address = deps.api.addr_validate(&msg.pooler_address)?; - if let Some(addr) = msg.withdraw_to { - WITHDRAW_TO.save(deps.storage, &deps.api.addr_validate(&addr)?)?; - resp = resp.add_attribute("withdraw_to", addr); - }; - - if let Some(addr) = msg.emergency_committee_addr { - EMERGENCY_COMMITTEE_ADDR.save(deps.storage, &deps.api.addr_validate(&addr)?)?; - resp = resp.add_attribute("emergency_committee", addr); - }; + WITHDRAWER.save(deps.storage, &withdrawer)?; + WITHDRAW_TO.save(deps.storage, &withdraw_to)?; + POOLER_ADDRESS.save(deps.storage, &liquidity_pooler_address)?; ensure!( !msg.lockup_period.is_expired(&_env.block), ContractError::MustBeFutureLockupPeriod {} ); LOCKUP_PERIOD.save(deps.storage, &msg.lockup_period)?; - POOLER_ADDRESS.save(deps.storage, &deps.api.addr_validate(&msg.pooler_address)?)?; - Ok(resp.add_attribute("pool_address", msg.pooler_address)) + let resp = Response::default() + .add_attribute("method", "instantiate") + .add_attribute("pool_address", liquidity_pooler_address) + .add_attribute("withdrawer", withdrawer) + .add_attribute("withdraw_to", withdraw_to); + + if let Some(addr) = msg.emergency_committee_addr { + EMERGENCY_COMMITTEE_ADDR.save(deps.storage, &deps.api.addr_validate(&addr)?)?; + Ok(resp.add_attribute("emergency_committee", addr)) + } else { + Ok(resp) + } } #[cfg_attr(not(feature = "library"), entry_point)] @@ -88,15 +89,9 @@ fn try_claim(deps: DepsMut, env: Env, info: MessageInfo) -> Result Result Result { let pooler_addr = POOLER_ADDRESS.load(deps.storage)?; - ensure!(info.sender == pooler_addr, ContractError::Unauthorized {}); - - let withdraw_to_addr = WITHDRAW_TO - .load(deps.storage) - .map_err(|_| ContractError::NoWithdrawTo {})?; + let withdraw_to_addr = WITHDRAW_TO.load(deps.storage)?; + // only liquid pooler should call this method + ensure!(info.sender == pooler_addr, ContractError::Unauthorized {}); ensure!(info.funds.len() == 2, ContractError::InvalidFunds {}); + // clear the pending withdraw state WITHDRAW_STATE.remove(deps.storage); let send_msg = BankMsg::Send { @@ -167,7 +161,7 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result { - let mut response = Response::default().add_attribute("method", "update_withdrawer"); + let mut response = Response::default().add_attribute("method", "update_config"); if let Some(addr) = withdrawer { WITHDRAWER.save(deps.storage, &deps.api.addr_validate(&addr)?)?; diff --git a/contracts/single-party-pol-holder/src/error.rs b/contracts/single-party-pol-holder/src/error.rs index 7151d503..8a995ce3 100644 --- a/contracts/single-party-pol-holder/src/error.rs +++ b/contracts/single-party-pol-holder/src/error.rs @@ -12,12 +12,6 @@ pub enum ContractError { #[error("A withdraw process already started")] WithdrawAlreadyStarted {}, - #[error("No withdrawer address configured")] - NoWithdrawer {}, - - #[error("No withdraw_to address configured")] - NoWithdrawTo {}, - #[error("The position is still locked, unlock at: {0}")] LockupPeriodNotOver(String), diff --git a/contracts/single-party-pol-holder/src/msg.rs b/contracts/single-party-pol-holder/src/msg.rs index 12b7c3b8..ad9d8dc0 100644 --- a/contracts/single-party-pol-holder/src/msg.rs +++ b/contracts/single-party-pol-holder/src/msg.rs @@ -8,9 +8,9 @@ use cw_utils::Expiration; pub struct InstantiateMsg { /// A withdrawer is the only authorized address that can withdraw /// from the contract. - pub withdrawer: Option, + pub withdrawer: String, /// Withdraw the funds to this address - pub withdraw_to: Option, + pub withdraw_to: String, /// The address that is allowed to do emergency pull out pub emergency_committee_addr: Option, /// the neutron address of the liquid pooler @@ -49,9 +49,9 @@ pub enum ExecuteMsg { #[derive(QueryResponses)] pub enum QueryMsg { // Queries the withdrawer address - #[returns(Option)] + #[returns(Addr)] Withdrawer {}, - #[returns(Option)] + #[returns(Addr)] WithdrawTo {}, // Queries the pooler address #[returns(Addr)] diff --git a/unit-tests/src/setup/instantiates/single_party_holder.rs b/unit-tests/src/setup/instantiates/single_party_holder.rs index 2190aac1..52c9a07b 100644 --- a/unit-tests/src/setup/instantiates/single_party_holder.rs +++ b/unit-tests/src/setup/instantiates/single_party_holder.rs @@ -12,8 +12,8 @@ impl From for covenant_single_party_pol_holder::ms impl SinglePartyHolderInstantiate { pub fn new( - withdrawer: Option, - withdraw_to: Option, + withdrawer: String, + withdraw_to: String, emergency_committee_addr: Option, pooler_address: String, lockup_period: Expiration, @@ -29,12 +29,12 @@ impl SinglePartyHolderInstantiate { } } - pub fn with_withdrawer(&mut self, addr: Option) -> &mut Self { + pub fn with_withdrawer(&mut self, addr: String) -> &mut Self { self.msg.withdrawer = addr; self } - pub fn with_withdraw_to(&mut self, addr: Option) -> &mut Self { + pub fn with_withdraw_to(&mut self, addr: String) -> &mut Self { self.msg.withdraw_to = addr; self } @@ -59,8 +59,8 @@ impl SinglePartyHolderInstantiate { pub fn default(pooler_address: String) -> Self { Self { msg: covenant_single_party_pol_holder::msg::InstantiateMsg { - withdrawer: Some(pooler_address.to_string()), - withdraw_to: Some(pooler_address.to_string()), + withdrawer: pooler_address.to_string(), + withdraw_to: pooler_address.to_string(), emergency_committee_addr: Some(pooler_address.to_string()), pooler_address, lockup_period: Expiration::AtHeight(100000), diff --git a/unit-tests/src/test_astroport_liquid_pooler/suite.rs b/unit-tests/src/test_astroport_liquid_pooler/suite.rs index c724ed89..ed448e2a 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/suite.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/suite.rs @@ -39,8 +39,8 @@ impl Default for AstroLiquidPoolerBuilder { ); let holder_instantiate_msg = covenant_single_party_pol_holder::msg::InstantiateMsg { - withdrawer: Some(clock_addr.to_string()), - withdraw_to: Some(holder_addr.to_string()), + withdrawer: clock_addr.to_string(), + withdraw_to: holder_addr.to_string(), emergency_committee_addr: None, pooler_address: liquid_pooler_addr.to_string(), lockup_period: cw_utils::Expiration::AtHeight(123665), diff --git a/unit-tests/src/test_single_party_holder/suite.rs b/unit-tests/src/test_single_party_holder/suite.rs index 693865d7..9e91556e 100644 --- a/unit-tests/src/test_single_party_holder/suite.rs +++ b/unit-tests/src/test_single_party_holder/suite.rs @@ -86,12 +86,12 @@ impl Default for SinglePartyHolderBuilder { #[allow(dead_code)] impl SinglePartyHolderBuilder { - pub fn with_withdrawer(mut self, addr: Option) -> Self { + pub fn with_withdrawer(mut self, addr: String) -> Self { self.instantiate_msg.with_withdrawer(addr); self } - pub fn with_withdraw_to(mut self, addr: Option) -> Self { + pub fn with_withdraw_to(mut self, addr: String) -> Self { self.instantiate_msg.with_withdraw_to(addr); self } diff --git a/unit-tests/src/test_single_party_holder/tests.rs b/unit-tests/src/test_single_party_holder/tests.rs index 67c7721a..bd05d8cc 100644 --- a/unit-tests/src/test_single_party_holder/tests.rs +++ b/unit-tests/src/test_single_party_holder/tests.rs @@ -10,7 +10,7 @@ use super::suite::SinglePartyHolderBuilder; #[should_panic] fn test_instantiate_validates_withdrawer() { SinglePartyHolderBuilder::default() - .with_withdrawer(Some("0Oo0Oo".to_string())) + .with_withdrawer("0Oo0Oo".to_string()) .build(); } @@ -26,7 +26,7 @@ fn test_instantiate_invalid_liquid_pooler_addr() { #[should_panic] fn test_instantiate_invalid_withdraw_to_addr() { SinglePartyHolderBuilder::default() - .with_withdraw_to(Some("0Oo0Oo".to_string())) + .with_withdraw_to("0Oo0Oo".to_string()) .build(); } @@ -77,18 +77,6 @@ fn test_execute_claim_validates_lockup_period() { suite.execute_claim(sender); } -#[test] -#[should_panic(expected = "No withdrawer address configured")] -fn test_execute_claim_validates_withdrawer_set() { - let mut suite = SinglePartyHolderBuilder::default() - .with_withdrawer(None) - .build(); - - let sender = suite.liquid_pooler_address.clone(); - suite.expire_lockup(); - suite.execute_claim(sender); -} - #[test] #[should_panic(expected = "Unauthorized")] fn test_execute_claim_validates_withdrawer_addr() { @@ -99,19 +87,6 @@ fn test_execute_claim_validates_withdrawer_addr() { suite.execute_claim(sender); } -#[test] -#[should_panic(expected = "No withdraw_to address configured")] -fn test_execute_claim_fails_with_no_withdraw_to() { - let mut suite = SinglePartyHolderBuilder::default() - .with_withdraw_to(None) - .build(); - suite.expire_lockup(); - - let sender = suite.liquid_pooler_address.clone(); - suite.expire_lockup(); - suite.execute_claim(sender); -} - #[test] fn test_execute_claim_happy() { let mut suite = SinglePartyHolderBuilder::default().build(); @@ -189,18 +164,6 @@ fn test_execute_distribute_validates_liquidity_pooler() { println!("resp: {:?}", resp); } -#[test] -#[should_panic(expected = "No withdraw_to address configured")] -fn test_execute_distribute_validates_withdraw_to_addr() { - let mut suite = SinglePartyHolderBuilder::default() - .with_withdraw_to(None) - .build(); - - let sender = suite.liquid_pooler_address.clone(); - suite.expire_lockup(); - suite.execute_distribute(sender, vec![]); -} - #[test] #[should_panic(expected = "We expect 2 denoms to be received from the liquidity pooler")] fn test_execute_distribute_ensures_two_denoms_sent() { From 9f04b589beb3b1e52245d3784c81f8da876f2f55 Mon Sep 17 00:00:00 2001 From: bekauz Date: Tue, 9 Apr 2024 16:13:26 +0200 Subject: [PATCH 43/56] adding astro liquid pooler xyk single side lp limits validation; all pool types error if single side limits validation fails --- .../astroport-liquid-pooler/src/contract.rs | 168 +++++++++--------- contracts/astroport-liquid-pooler/src/msg.rs | 6 +- .../src/test_astroport_liquid_pooler/tests.rs | 131 ++++++++++---- 3 files changed, 178 insertions(+), 127 deletions(-) diff --git a/contracts/astroport-liquid-pooler/src/contract.rs b/contracts/astroport-liquid-pooler/src/contract.rs index 30773735..b67e770a 100644 --- a/contracts/astroport-liquid-pooler/src/contract.rs +++ b/contracts/astroport-liquid-pooler/src/contract.rs @@ -1,8 +1,8 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - ensure, to_json_binary, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, - Reply, Response, StdError, StdResult, SubMsg, SubMsgResult, Uint128, WasmMsg, + coin, ensure, to_json_binary, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, + MessageInfo, Reply, Response, StdError, StdResult, SubMsg, SubMsgResult, Uint128, WasmMsg, }; use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::{astroport::query_astro_pool_token, withdraw_lp_helper::WithdrawLPMsgs}; @@ -87,8 +87,8 @@ pub fn instantiate( PROVIDED_LIQUIDITY_INFO.save( deps.storage, &ProvidedLiquidityInfo { - provided_amount_a: Uint128::zero(), - provided_amount_b: Uint128::zero(), + provided_coin_a: coin(0, lp_config.asset_data.asset_a_denom.as_str()), + provided_coin_b: coin(0, lp_config.asset_data.asset_b_denom.as_str()), }, )?; @@ -258,13 +258,35 @@ fn try_lp(mut deps: DepsMut, env: Env) -> Result { env.contract.address.to_string(), lp_config.asset_data.asset_b_denom.as_str(), )?; + let assets = lp_config + .asset_data + .to_asset_vec(coin_a.amount, coin_b.amount); // depending on available balances we attempt a different action: match (coin_a.amount.is_zero(), coin_b.amount.is_zero()) { - // exactly one balance is non-zero, we attempt single-side - (true, false) | (false, true) => { + // asset_b balance is non-zero, we attempt single-side + (true, false) => { + ensure!( + coin_b.amount <= lp_config.single_side_lp_limits.asset_b_limit, + ContractError::SingleSideLpLimitError {} + ); + let single_sided_submsgs = - try_get_single_side_lp_submsg(deps.branch(), env, (coin_a, coin_b), lp_config)?; + try_get_single_side_lp_submsg(deps.branch(), env, coin_b, assets, lp_config)?; + if !single_sided_submsgs.is_empty() { + return Ok(Response::default() + .add_submessages(single_sided_submsgs) + .add_attribute("method", "single_side_lp")); + } + } + // asset_a balance is non-zero, we attempt single-side + (false, true) => { + ensure!( + coin_a.amount <= lp_config.single_side_lp_limits.asset_a_limit, + ContractError::SingleSideLpLimitError {} + ); + let single_sided_submsgs = + try_get_single_side_lp_submsg(deps.branch(), env, coin_a, assets, lp_config)?; if !single_sided_submsgs.is_empty() { return Ok(Response::default() .add_submessages(single_sided_submsgs) @@ -347,8 +369,8 @@ fn try_get_double_side_lp_submsg( PROVIDED_LIQUIDITY_INFO.update( deps.storage, |mut info: ProvidedLiquidityInfo| -> StdResult<_> { - info.provided_amount_b = info.provided_amount_b.checked_add(b_coin.amount)?; - info.provided_amount_a = info.provided_amount_a.checked_add(a_coin.amount)?; + info.provided_coin_b.amount = info.provided_coin_b.amount.checked_add(b_coin.amount)?; + info.provided_coin_a.amount = info.provided_coin_a.amount.checked_add(a_coin.amount)?; Ok(info) }, )?; @@ -364,41 +386,37 @@ fn try_get_double_side_lp_submsg( } /// attempts to build a single sided `ProvideLiquidity` message. -/// pool ratio does not get validated here. as long as the single -/// side asset amount being provided is within our predefined -/// single-side liquidity limits, we provide it. +/// pool ratio and single-side limit validations are performed by +/// the calling method. fn try_get_single_side_lp_submsg( deps: DepsMut, env: Env, - (coin_a, coin_b): (Coin, Coin), + coin: Coin, + mut assets: Vec, lp_config: LpConfig, ) -> Result, ContractError> { - let mut assets = lp_config - .asset_data - .to_asset_vec(coin_a.amount, coin_b.amount); - match lp_config.pair_type { // xyk pools do not allow for automatic single-sided liquidity provision. // we therefore perform a manual swap with 1/2 of the available denom, and execute // two-sided lp provision with the resulting assets. PairType::Xyk {} => { - // find the offer asset and halve its amount. the halved coin amount here is - // the floor of the division result, so it is safe to assume that after the - // swap we will have at least the same amount of the offer asset left. - let (offer_asset, offer_coin, mut ask_asset) = if coin_a.amount.is_zero() { - let halved_coin = Coin { - denom: coin_b.denom.clone(), - amount: coin_b.amount / Uint128::from(2u128), - }; - assets[1].amount /= Uint128::from(2u128); - (assets[1].clone(), halved_coin, assets[0].clone()) - } else { - let halved_coin = Coin { - denom: coin_a.denom.clone(), - amount: coin_a.amount / Uint128::from(2u128), - }; - assets[0].amount /= Uint128::from(2u128); - (assets[0].clone(), halved_coin, assets[1].clone()) + // we halve the non-zero coin we have in order to swap it for the other denom. + // the halved coin amount here is the floor of the division result, + // so it is safe to assume that after the swap we will have at least + // the same amount of the offer asset left. + let halved_coin = Coin { + denom: coin.denom.clone(), + amount: coin.amount / Uint128::from(2u128), + }; + + let (offer_asset, offer_coin, mut ask_asset) = { + if assets[0].to_coin()?.denom == halved_coin.denom { + assets[0].amount = halved_coin.amount; + (assets[0].clone(), halved_coin, assets[1].clone()) + } else { + assets[1].amount = halved_coin.amount; + (assets[1].clone(), halved_coin, assets[0].clone()) + } }; // we simulate a swap with 1/2 of the offer asset @@ -426,14 +444,16 @@ fn try_get_single_side_lp_submsg( .into(); PROVIDED_LIQUIDITY_INFO.update(deps.storage, |mut info| -> StdResult<_> { - if offer_coin.denom == coin_a.denom { - info.provided_amount_a = - info.provided_amount_a.checked_add(offer_coin.amount)?; - info.provided_amount_b = info.provided_amount_b.checked_add(ask_coin.amount)?; + if offer_coin.denom == info.provided_coin_a.denom { + info.provided_coin_a.amount = + info.provided_coin_a.amount.checked_add(offer_coin.amount)?; + info.provided_coin_b.amount = + info.provided_coin_b.amount.checked_add(ask_coin.amount)?; } else { - info.provided_amount_b = - info.provided_amount_b.checked_add(offer_coin.amount)?; - info.provided_amount_a = info.provided_amount_a.checked_add(ask_coin.amount)?; + info.provided_coin_b.amount = + info.provided_coin_b.amount.checked_add(offer_coin.amount)?; + info.provided_coin_a.amount = + info.provided_coin_a.amount.checked_add(ask_coin.amount)?; } Ok(info) })?; @@ -464,52 +484,28 @@ fn try_get_single_side_lp_submsg( receiver: Some(env.contract.address.to_string()), }; - // now we try to submit the message for either B or A token single side liquidity - if coin_a.amount.is_zero() - && coin_b.amount <= lp_config.single_side_lp_limits.asset_b_limit - { - // update the provided liquidity info - PROVIDED_LIQUIDITY_INFO.update(deps.storage, |mut info| -> StdResult<_> { - info.provided_amount_b = info.provided_amount_b.checked_add(coin_b.amount)?; - Ok(info) - })?; - - // if available ls token amount is within single side limits we build a single side msg - let submsg = SubMsg::reply_on_success( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: lp_config.pool_address.to_string(), - msg: to_json_binary(&single_sided_liq_msg)?, - funds: vec![coin_b], - }), - SINGLE_SIDED_REPLY_ID, - ); - - return Ok(vec![submsg]); - } + // update the provided liquidity info + PROVIDED_LIQUIDITY_INFO.update(deps.storage, |mut info| -> StdResult<_> { + if coin.denom == info.provided_coin_a.denom { + info.provided_coin_a.amount = + info.provided_coin_a.amount.checked_add(coin.amount)?; + } else { + info.provided_coin_b.amount = + info.provided_coin_b.amount.checked_add(coin.amount)?; + } + Ok(info) + })?; - if coin_b.amount.is_zero() - && coin_a.amount <= lp_config.single_side_lp_limits.asset_a_limit - { - // update the provided liquidity info - PROVIDED_LIQUIDITY_INFO.update(deps.storage, |mut info| -> StdResult<_> { - info.provided_amount_a = info.provided_amount_a.checked_add(coin_a.amount)?; - Ok(info) - })?; - - // if available A token amount is within single side limits we build a single side msg - let submsg = SubMsg::reply_on_success( - CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: lp_config.pool_address.to_string(), - msg: to_json_binary(&single_sided_liq_msg)?, - funds: vec![coin_a], - }), - SINGLE_SIDED_REPLY_ID, - ); - - return Ok(vec![submsg]); - } - // if neither a nor b token single side lp message was built, we just go back and wait - Ok(vec![]) + let submsg = SubMsg::reply_on_success( + CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: lp_config.pool_address.to_string(), + msg: to_json_binary(&single_sided_liq_msg)?, + funds: vec![coin], + }), + SINGLE_SIDED_REPLY_ID, + ); + + Ok(vec![submsg]) } } } diff --git a/contracts/astroport-liquid-pooler/src/msg.rs b/contracts/astroport-liquid-pooler/src/msg.rs index 151a42b2..5af6c8a7 100644 --- a/contracts/astroport-liquid-pooler/src/msg.rs +++ b/contracts/astroport-liquid-pooler/src/msg.rs @@ -4,7 +4,7 @@ use astroport::{ }; use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{ - ensure, to_json_binary, Addr, Attribute, Binary, Decimal, StdResult, Uint128, WasmMsg, + ensure, to_json_binary, Addr, Attribute, Binary, Coin, Decimal, StdResult, Uint128, WasmMsg, }; use covenant_macros::{ clocked, covenant_clock_address, covenant_deposit_address, covenant_lper_withdraw, @@ -218,8 +218,8 @@ pub enum MigrateMsg { /// keeps track of provided asset liquidities in `Uint128`. #[cw_serde] pub struct ProvidedLiquidityInfo { - pub provided_amount_a: Uint128, - pub provided_amount_b: Uint128, + pub provided_coin_a: Coin, + pub provided_coin_b: Coin, } /// state of the LP state machine diff --git a/unit-tests/src/test_astroport_liquid_pooler/tests.rs b/unit-tests/src/test_astroport_liquid_pooler/tests.rs index 263b1d7f..29fe421d 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/tests.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/tests.rs @@ -320,8 +320,8 @@ fn test_provide_stable_liquidity_single_side_asset_a() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); @@ -339,8 +339,8 @@ fn test_provide_stable_liquidity_single_side_asset_a() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(570_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(570_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); } @@ -380,8 +380,8 @@ fn test_provide_custom_concentrated_liquidity_single_side_asset_a() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); @@ -399,8 +399,8 @@ fn test_provide_custom_concentrated_liquidity_single_side_asset_a() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(570_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(570_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); } @@ -439,8 +439,8 @@ fn test_provide_xyk_liquidity_single_side_asset_a() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); @@ -458,11 +458,11 @@ fn test_provide_xyk_liquidity_single_side_asset_a() { let provided_liquidity_info = suite.query_provided_liquidity_info(); assert_eq!( - provided_liquidity_info.provided_amount_a, + provided_liquidity_info.provided_coin_a.amount, Uint128::new(500_000 + 70_000 / 2) ); // minus fees - assert!(provided_liquidity_info.provided_amount_b > Uint128::new(534_000)); + assert!(provided_liquidity_info.provided_coin_b.amount > Uint128::new(534_000)); } #[test] @@ -499,8 +499,8 @@ fn test_provide_xyk_liquidity_single_side_asset_b() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); @@ -518,14 +518,15 @@ fn test_provide_xyk_liquidity_single_side_asset_b() { let provided_liquidity_info = suite.query_provided_liquidity_info(); assert_eq!( - provided_liquidity_info.provided_amount_b, + provided_liquidity_info.provided_coin_b.amount, Uint128::new(500_000 + 70_000 / 2) ); // minus fees - assert!(provided_liquidity_info.provided_amount_a > Uint128::new(534_000)); + assert!(provided_liquidity_info.provided_coin_a.amount > Uint128::new(534_000)); } #[test] +#[should_panic(expected = "Single side LP limit exceeded")] fn test_provide_liquidity_single_side_asset_a_exceeds_limits() { let mut suite = AstroLiquidPoolerBuilder::default().build(); @@ -550,19 +551,74 @@ fn test_provide_liquidity_single_side_asset_a_exceeds_limits() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); - suite - .tick_contract(suite.liquid_pooler_addr.clone()) - .assert_event(&Event::new("wasm").add_attribute("status", "not enough funds")); + suite.tick_contract(suite.liquid_pooler_addr.clone()); + assert_eq!( + suite.query_provided_liquidity_info(), + ProvidedLiquidityInfo { + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) + } + ); +} + +#[test] +fn test_provide_liquidity_single_side_validates_single_side_limits() { + let mut suite = AstroLiquidPoolerBuilder::default().build(); + + suite.fund_contract( + &coins(500_000, DENOM_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + suite.fund_contract( + &coins(570_000, DENOM_LS_ATOM_ON_NTRN), + suite.liquid_pooler_addr.clone(), + ); + + let double_sided_response = suite.tick_contract(suite.liquid_pooler_addr.clone()); + double_sided_response + .assert_event(&Event::new("wasm").add_attribute("method", "double_side_lp")); + double_sided_response + .assert_event(&Event::new("wasm").add_attribute("method", "handle_double_sided_reply_id")); + + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_ATOM_ON_NTRN), + ); + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(70_000, DENOM_LS_ATOM_ON_NTRN), + ); + assert_eq!( + suite.query_provided_liquidity_info(), + ProvidedLiquidityInfo { + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) + } + ); + + let app_response = suite.tick_contract(suite.liquid_pooler_addr.clone()); + app_response.assert_event(&Event::new("wasm").add_attribute("method", "single_side_lp")); + app_response + .assert_event(&Event::new("wasm").add_attribute("method", "handle_single_sided_reply_id")); + + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_ATOM_ON_NTRN), + ); + suite.assert_balance( + suite.liquid_pooler_addr.clone(), + coin(0, DENOM_LS_ATOM_ON_NTRN), + ); assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(570_000, DENOM_LS_ATOM_ON_NTRN) } ); } @@ -597,8 +653,8 @@ fn test_provide_liquidity_single_side_asset_b() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); @@ -618,13 +674,14 @@ fn test_provide_liquidity_single_side_asset_b() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(570_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(570_000, DENOM_LS_ATOM_ON_NTRN) } ); } #[test] +#[should_panic(expected = "Single side LP limit exceeded")] fn test_provide_liquidity_single_side_asset_b_exceeds_limits() { let mut suite = AstroLiquidPoolerBuilder::default().build(); @@ -650,19 +707,17 @@ fn test_provide_liquidity_single_side_asset_b_exceeds_limits() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); - suite - .tick_contract(suite.liquid_pooler_addr.clone()) - .assert_event(&Event::new("wasm").add_attribute("status", "not enough funds")); + suite.tick_contract(suite.liquid_pooler_addr.clone()); assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); } @@ -693,8 +748,8 @@ fn test_provide_liquidity_double_side_excess_a_denom() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); } @@ -725,8 +780,8 @@ fn test_provide_liquidity_double_side_excess_b_denom() { assert_eq!( suite.query_provided_liquidity_info(), ProvidedLiquidityInfo { - provided_amount_a: Uint128::new(500_000), - provided_amount_b: Uint128::new(500_000) + provided_coin_a: coin(500_000, DENOM_ATOM_ON_NTRN), + provided_coin_b: coin(500_000, DENOM_LS_ATOM_ON_NTRN) } ); } From 49357643880ce05c79e38c32e4d4cf0f3b38509f Mon Sep 17 00:00:00 2001 From: bekauz Date: Wed, 10 Apr 2024 17:06:51 +0200 Subject: [PATCH 44/56] using common ica id across all ica-enabled contracts --- contracts/ibc-forwarder/src/contract.rs | 3 +-- contracts/remote-chain-splitter/src/contract.rs | 3 +-- contracts/stride-liquid-staker/src/contract.rs | 4 +--- packages/covenant-utils/src/ica.rs | 2 ++ 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/contracts/ibc-forwarder/src/contract.rs b/contracts/ibc-forwarder/src/contract.rs index e974b980..217efb46 100644 --- a/contracts/ibc-forwarder/src/contract.rs +++ b/contracts/ibc-forwarder/src/contract.rs @@ -11,7 +11,7 @@ use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::{ ica::{ get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, - sudo_error, sudo_open_ack, sudo_response, sudo_timeout, + sudo_error, sudo_open_ack, sudo_response, sudo_timeout, INTERCHAIN_ACCOUNT_ID, }, neutron::{ assert_ibc_fee_coverage, get_proto_coin, query_ibc_fee, to_proto_msg_transfer, @@ -40,7 +40,6 @@ use crate::{ const CONTRACT_NAME: &str = "crates.io:covenant-ibc-forwarder"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); -const INTERCHAIN_ACCOUNT_ID: &str = "ica"; pub const SUDO_PAYLOAD_REPLY_ID: u64 = 1; type QueryDeps<'a> = Deps<'a, NeutronQuery>; diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index a4b70877..1950add3 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -13,7 +13,7 @@ use cosmwasm_std::{ use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::ica::{ get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, sudo_error, - sudo_open_ack, sudo_response, sudo_timeout, + sudo_open_ack, sudo_response, sudo_timeout, INTERCHAIN_ACCOUNT_ID, }; use covenant_utils::neutron::{ assert_ibc_fee_coverage, get_proto_coin, query_ibc_fee, RemoteChainInfo, SudoPayload, @@ -42,7 +42,6 @@ use neutron_sdk::{ type QueryDeps<'a> = Deps<'a, NeutronQuery>; type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; -const INTERCHAIN_ACCOUNT_ID: &str = "rc-ica"; const CONTRACT_NAME: &str = "crates.io:covenant-remote-chain-splitter"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/contracts/stride-liquid-staker/src/contract.rs b/contracts/stride-liquid-staker/src/contract.rs index 3692d7da..ea93102d 100644 --- a/contracts/stride-liquid-staker/src/contract.rs +++ b/contracts/stride-liquid-staker/src/contract.rs @@ -8,7 +8,7 @@ use cosmwasm_std::{ use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::ica::{ get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, sudo_error, - sudo_open_ack, sudo_response, sudo_timeout, + sudo_open_ack, sudo_response, sudo_timeout, INTERCHAIN_ACCOUNT_ID, }; use covenant_utils::neutron::{self, get_proto_coin, RemoteChainInfo, SudoPayload}; use cw2::set_contract_version; @@ -28,8 +28,6 @@ use neutron_sdk::{ NeutronError, NeutronResult, }; -const INTERCHAIN_ACCOUNT_ID: &str = "stride-ica"; - const CONTRACT_NAME: &str = "crates.io:covenant-stride-liquid-staker"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/packages/covenant-utils/src/ica.rs b/packages/covenant-utils/src/ica.rs index 432ccb73..670bd580 100644 --- a/packages/covenant-utils/src/ica.rs +++ b/packages/covenant-utils/src/ica.rs @@ -16,6 +16,8 @@ use crate::neutron::{OpenAckVersion, SudoPayload}; type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; +pub const INTERCHAIN_ACCOUNT_ID: &str = "valence-ica"; + pub trait IcaStateHelper { fn reset_state(&self, storage: &mut dyn Storage) -> StdResult<()>; fn clear_ica(&self, storage: &mut dyn Storage) -> StdResult<()>; From e9ce3a3f66c8c081c37619a5a9945763b68ece53 Mon Sep 17 00:00:00 2001 From: bekauz Date: Wed, 10 Apr 2024 17:23:04 +0200 Subject: [PATCH 45/56] adding osmo outpost migration entrypoint; add missing code id migratemsg variants to single & two party pol top level covenants --- contracts/ibc-forwarder/src/contract.rs | 5 ++++- contracts/native-router/src/contract.rs | 2 +- .../outpost-osmo-liquid-pooler/src/contract.rs | 16 ++++++++++++++-- contracts/outpost-osmo-liquid-pooler/src/msg.rs | 7 ++++++- .../single-party-pol-covenant/src/contract.rs | 6 ++++++ contracts/single-party-pol-covenant/src/msg.rs | 6 +++++- contracts/two-party-pol-covenant/src/contract.rs | 6 ++++++ contracts/two-party-pol-covenant/src/msg.rs | 6 +++++- 8 files changed, 47 insertions(+), 7 deletions(-) diff --git a/contracts/ibc-forwarder/src/contract.rs b/contracts/ibc-forwarder/src/contract.rs index 217efb46..dd59c65f 100644 --- a/contracts/ibc-forwarder/src/contract.rs +++ b/contracts/ibc-forwarder/src/contract.rs @@ -438,7 +438,10 @@ pub fn migrate(deps: ExecuteDeps, _env: Env, msg: MigrateMsg) -> StdResult { - unimplemented!() + // This is a migrate message to update code id, + // Data is optional base64 that we can parse to any data we would like in the future + // let data: SomeStruct = from_binary(&data)?; + Ok(Response::default()) } } } diff --git a/contracts/native-router/src/contract.rs b/contracts/native-router/src/contract.rs index f7da34f8..a5c23b47 100644 --- a/contracts/native-router/src/contract.rs +++ b/contracts/native-router/src/contract.rs @@ -191,7 +191,7 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result Result StdResult { + match msg { + MigrateMsg::UpdateCodeId { data: _ } => { + // This is a migrate message to update code id, + // Data is optional base64 that we can parse to any data we would like in the future + // let data: SomeStruct = from_binary(&data)?; + Ok(Response::default()) + } + } +} + fn handle_pool_interaction_reply(deps: DepsMut, env: Env) -> Result { // load and clear the pending reply that we are processing let callback_ctx = PENDING_REPLY.load(deps.storage)?; diff --git a/contracts/outpost-osmo-liquid-pooler/src/msg.rs b/contracts/outpost-osmo-liquid-pooler/src/msg.rs index 5f47ed46..28d21e2c 100644 --- a/contracts/outpost-osmo-liquid-pooler/src/msg.rs +++ b/contracts/outpost-osmo-liquid-pooler/src/msg.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Coin, Decimal, Uint128, Uint64}; +use cosmwasm_std::{Binary, Coin, Decimal, Uint128, Uint64}; use osmosis_std::types::osmosis::gamm::v1beta1::Pool; use crate::error::ContractError; @@ -51,6 +51,11 @@ pub struct CallerContext { #[cw_serde] pub enum QueryMsg {} +#[cw_serde] +pub enum MigrateMsg { + UpdateCodeId { data: Option }, +} + pub trait OsmosisPool { fn validate_pool_assets_length(&self) -> Result<(), ContractError>; fn validate_pool_asset_weights(&self) -> Result<(), ContractError>; diff --git a/contracts/single-party-pol-covenant/src/contract.rs b/contracts/single-party-pol-covenant/src/contract.rs index b63c1622..f5c540a5 100644 --- a/contracts/single-party-pol-covenant/src/contract.rs +++ b/contracts/single-party-pol-covenant/src/contract.rs @@ -438,5 +438,11 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult Ok(resp.add_messages(migrate_msgs)) } + MigrateMsg::UpdateCodeId { data: _ } => { + // This is a migrate message to update code id, + // Data is optional base64 that we can parse to any data we would like in the future + // let data: SomeStruct = from_binary(&data)?; + Ok(Response::default()) + } } } diff --git a/contracts/single-party-pol-covenant/src/msg.rs b/contracts/single-party-pol-covenant/src/msg.rs index c2978866..58aab751 100644 --- a/contracts/single-party-pol-covenant/src/msg.rs +++ b/contracts/single-party-pol-covenant/src/msg.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Addr, Decimal, StdResult, Uint128, Uint64, WasmMsg}; +use cosmwasm_std::{Addr, Binary, Decimal, StdResult, Uint128, Uint64, WasmMsg}; use covenant_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; use covenant_osmo_liquid_pooler::msg::OsmosisLiquidPoolerConfig; use covenant_utils::{ @@ -195,6 +195,7 @@ pub enum QueryMsg { ContractCodes {}, } +#[allow(clippy::large_enum_variant)] #[cw_serde] pub enum MigrateMsg { MigrateContracts { @@ -208,6 +209,9 @@ pub enum MigrateMsg { liquid_staker: Option, router: Option, }, + UpdateCodeId { + data: Option, + }, } #[cw_serde] diff --git a/contracts/two-party-pol-covenant/src/contract.rs b/contracts/two-party-pol-covenant/src/contract.rs index e2ff82a7..9d3c6e55 100644 --- a/contracts/two-party-pol-covenant/src/contract.rs +++ b/contracts/two-party-pol-covenant/src/contract.rs @@ -437,5 +437,11 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult Ok(resp.add_messages(migrate_msgs)) } + MigrateMsg::UpdateCodeId { data: _ } => { + // This is a migrate message to update code id, + // Data is optional base64 that we can parse to any data we would like in the future + // let data: SomeStruct = from_binary(&data)?; + Ok(Response::default()) + } } } diff --git a/contracts/two-party-pol-covenant/src/msg.rs b/contracts/two-party-pol-covenant/src/msg.rs index a13cfb2f..2af970bd 100644 --- a/contracts/two-party-pol-covenant/src/msg.rs +++ b/contracts/two-party-pol-covenant/src/msg.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, BTreeSet}; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{coin, Addr, Decimal, StdResult, Uint128, Uint64, WasmMsg}; +use cosmwasm_std::{coin, Addr, Binary, Decimal, StdResult, Uint128, Uint64, WasmMsg}; use covenant_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; use covenant_osmo_liquid_pooler::msg::OsmosisLiquidPoolerConfig; use covenant_two_party_pol_holder::msg::{CovenantType, RagequitConfig, TwoPartyPolCovenantParty}; @@ -270,6 +270,7 @@ pub enum QueryMsg { ContractCodes {}, } +#[allow(clippy::large_enum_variant)] #[cw_serde] pub enum MigrateMsg { UpdateCovenant { @@ -282,6 +283,9 @@ pub enum MigrateMsg { party_a_forwarder: Option, party_b_forwarder: Option, }, + UpdateCodeId { + data: Option, + }, } #[cw_serde] From e3fc8706cb992de19b1ecb03f2366a8f87649e88 Mon Sep 17 00:00:00 2001 From: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Date: Wed, 10 Apr 2024 11:04:23 +0200 Subject: [PATCH 46/56] Tweak ci action (#201) (cherry picked from commit f7758ed0be1e9183594d30a6c5c77c4656ca7a0a) --- .github/workflows/{basic.yml => check.yml} | 84 ++++++++++----------- README.md | 16 ++++ v1/depositor/src/contract.rs | 3 +- v1/depositor/src/suite_test/unit_helpers.rs | 3 +- 4 files changed, 58 insertions(+), 48 deletions(-) rename .github/workflows/{basic.yml => check.yml} (51%) create mode 100644 README.md diff --git a/.github/workflows/basic.yml b/.github/workflows/check.yml similarity index 51% rename from .github/workflows/basic.yml rename to .github/workflows/check.yml index 60716a3d..cd6aad36 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/check.yml @@ -1,75 +1,71 @@ -# Based on https://github.com/actions-rs/example/blob/master/.github/workflows/quickstart.yml -on: [push, pull_request] +name: Check Build and Tests -name: Basic +on: + push: + branches: [ main ] + pull_request: -env: - RUST_BACKTRACE: 1 - CARGO_TERM_COLOR: always + workflow_dispatch: jobs: - unit-test: - name: Test Suite + check: runs-on: ubuntu-latest steps: - name: checkout sources uses: actions/checkout@v3 - - name: Install latest stable toolchain + - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.71.0 - target: wasm32-unknown-unknown + toolchain: 1.76.0 override: true + components: rustfmt, clippy - - name: Run tests + - name: Run cargo fmt uses: actions-rs/cargo@v1 with: - command: test - args: --locked + command: fmt + args: --all -- --check + + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-targets -- -D warnings + + # - name: Generate Schema + # run: ./scripts/schema.sh + + # - name: Schema Changes + # # fails if any changes not committed + # run: git diff --exit-code schema - lints: - name: Lints + test: runs-on: ubuntu-latest steps: - - name: checkout sources + - name: Checkout sources uses: actions/checkout@v3 - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.71.0 + toolchain: 1.76.0 + target: wasm32-unknown-unknown override: true - components: rustfmt, clippy - - - name: Run cargo fmt + - name: Run unit tests uses: actions-rs/cargo@v1 with: - command: fmt - args: --all -- --check + command: test + args: --locked + env: + RUST_BACKTRACE: 1 - - name: Run cargo clippy + - name: Compile WASM contract uses: actions-rs/cargo@v1 with: - command: clippy - args: --all-targets -- -D warnings - - # schema: - # name: Schema - # runs-on: ubuntu-latest - # steps: - # - name: Checkout sources - # uses: actions/checkout@v2 - - # - name: Install stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: 1.66.0 - # override: true - # components: rustfmt, clippy - - # - name: Gen schemas - # run: ./scripts/schema.sh + command: wasm + args: --locked + env: + RUSTFLAGS: "-C link-arg=-s" diff --git a/README.md b/README.md new file mode 100644 index 00000000..77f4ee5b --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Covenants + +[![Check Set-Up & Build](https://github.com/timewave-computer/covenants/actions/workflows/check.yml/badge.svg)](https://github.com/timewave-computer/covenants/actions/workflows/check.yml) + +**Covenants are interchain agreements**. They allow IBC enabled parties to establish multilateral alliances. Examples of covenants: + +* 🤝 token swap agreements between protocols +* 🤝 agreements for protocol-owned liquidity +* 🤝 an agreement to give a governance seat to another DAO + +Covenants are a modular system of contracts that can be deployed in various configurations. Timewave works closely with protocol representatives to design and configure covenants to suit their needs. + +We are currently working on exciting new covenants. Our completed covenants include: +* 🛠️ [Stride LP covenant](./stride-covenant/) + +Please reach out if you're interested in working with us! \ No newline at end of file diff --git a/v1/depositor/src/contract.rs b/v1/depositor/src/contract.rs index a7b68ede..89766925 100644 --- a/v1/depositor/src/contract.rs +++ b/v1/depositor/src/contract.rs @@ -152,8 +152,7 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult NeutronResult { // Serialize the Transfer message - let mut buf = Vec::new(); - buf.reserve(msg.encoded_len()); + let mut buf = Vec::with_capacity(msg.encoded_len()); if let Err(e) = msg.encode(&mut buf) { return Err(StdError::generic_err(format!("Encode error: {e}")).into()); } diff --git a/v1/depositor/src/suite_test/unit_helpers.rs b/v1/depositor/src/suite_test/unit_helpers.rs index bf168aa1..a48d697a 100644 --- a/v1/depositor/src/suite_test/unit_helpers.rs +++ b/v1/depositor/src/suite_test/unit_helpers.rs @@ -143,8 +143,7 @@ pub fn get_default_msg_transfer() -> MsgTransfer { pub fn to_proto(to_proto: impl Message) -> Vec { // Serialize the Transfer message - let mut buf = Vec::new(); - buf.reserve(to_proto.encoded_len()); + let mut buf = Vec::with_capacity(to_proto.encoded_len()); to_proto.encode(&mut buf).unwrap(); buf } From cac6109af2fe88414a9ee3013fbc9fc83859817f Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 12 Apr 2024 14:40:30 +0200 Subject: [PATCH 47/56] using decimal instead of uint64 for party allocation in 2p covenant instantiate msg --- contracts/two-party-pol-covenant/src/msg.rs | 12 ++++++------ .../src/setup/instantiates/two_party_covenant.rs | 8 ++++---- unit-tests/src/test_two_party_covenant/suite.rs | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/contracts/two-party-pol-covenant/src/msg.rs b/contracts/two-party-pol-covenant/src/msg.rs index 2af970bd..1302cf6d 100644 --- a/contracts/two-party-pol-covenant/src/msg.rs +++ b/contracts/two-party-pol-covenant/src/msg.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, BTreeSet}; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{coin, Addr, Binary, Decimal, StdResult, Uint128, Uint64, WasmMsg}; +use cosmwasm_std::{coin, Addr, Binary, Decimal, StdResult, Uint64, WasmMsg}; use covenant_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; use covenant_osmo_liquid_pooler::msg::OsmosisLiquidPoolerConfig; use covenant_two_party_pol_holder::msg::{CovenantType, RagequitConfig, TwoPartyPolCovenantParty}; @@ -26,8 +26,8 @@ pub struct InstantiateMsg { pub covenant_type: CovenantType, pub ragequit_config: Option, pub deposit_deadline: Expiration, - pub party_a_share: Uint64, - pub party_b_share: Uint64, + pub party_a_share: Decimal, + pub party_b_share: Decimal, pub pool_price_config: PoolPriceConfig, pub splits: BTreeMap, pub fallback_split: Option, @@ -112,7 +112,7 @@ impl CovenantPartyConfig { pub fn to_two_party_pol_party( &self, - party_share: Uint64, + allocation: Decimal, router: String, ) -> TwoPartyPolCovenantParty { match &self { @@ -123,14 +123,14 @@ impl CovenantPartyConfig { ), host_addr: config.addr.to_string(), controller_addr: config.party_receiver_addr.to_string(), - allocation: Decimal::from_ratio(party_share, Uint128::new(100)), + allocation, router, }, CovenantPartyConfig::Native(config) => TwoPartyPolCovenantParty { contribution: config.contribution.clone(), host_addr: config.addr.to_string(), controller_addr: config.party_receiver_addr.to_string(), - allocation: Decimal::from_ratio(party_share, Uint128::new(100)), + allocation, router, }, } diff --git a/unit-tests/src/setup/instantiates/two_party_covenant.rs b/unit-tests/src/setup/instantiates/two_party_covenant.rs index c219f109..bcb64603 100644 --- a/unit-tests/src/setup/instantiates/two_party_covenant.rs +++ b/unit-tests/src/setup/instantiates/two_party_covenant.rs @@ -82,12 +82,12 @@ impl TwoPartyCovenantInstantiate { self } - pub fn with_party_a_share(&mut self, party_a_share: Uint64) -> &mut Self { + pub fn with_party_a_share(&mut self, party_a_share: Decimal) -> &mut Self { self.msg.party_a_share = party_a_share; self } - pub fn with_party_b_share(&mut self, party_b_share: Uint64) -> &mut Self { + pub fn with_party_b_share(&mut self, party_b_share: Decimal) -> &mut Self { self.msg.party_b_share = party_b_share; self } @@ -171,8 +171,8 @@ impl TwoPartyCovenantInstantiate { contribution: coin(10_000, DENOM_LS_ATOM_ON_NTRN), }), covenant_type: covenant_two_party_pol_holder::msg::CovenantType::Share {}, - party_a_share: Uint64::new(50), - party_b_share: Uint64::new(50), + party_a_share: Decimal::from_str("0.5").unwrap(), + party_b_share: Decimal::from_str("0.5").unwrap(), pool_price_config: PoolPriceConfig { expected_spot_price: Decimal::from_str("1.0").unwrap(), acceptable_price_spread: Decimal::from_str("0.1").unwrap(), diff --git a/unit-tests/src/test_two_party_covenant/suite.rs b/unit-tests/src/test_two_party_covenant/suite.rs index 10cff6c7..8b6f00e5 100644 --- a/unit-tests/src/test_two_party_covenant/suite.rs +++ b/unit-tests/src/test_two_party_covenant/suite.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use cosmwasm_std::{coin, Addr, Uint64}; +use cosmwasm_std::{coin, Addr, Decimal, Uint64}; use covenant_two_party_pol::msg::{CovenantContractCodes, Timeouts}; use covenant_utils::split::SplitConfig; use cw_multi_test::{AppResponse, Executor}; @@ -109,12 +109,12 @@ impl TwoPartyCovenantBuilder { self } - pub fn with_party_a_share(mut self, party_a_share: Uint64) -> Self { + pub fn with_party_a_share(mut self, party_a_share: Decimal) -> Self { self.instantiate_msg.with_party_a_share(party_a_share); self } - pub fn with_party_b_share(mut self, party_b_share: Uint64) -> Self { + pub fn with_party_b_share(mut self, party_b_share: Decimal) -> Self { self.instantiate_msg.with_party_b_share(party_b_share); self } From 2adc5b2bed5df68ca9ff45212067761fa12f3ba3 Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 15 Apr 2024 20:53:33 +0200 Subject: [PATCH 48/56] pull CONTRACT_NAME from cargo via env!; adjust cargo package names --- Cargo.lock | 1422 ++++++++--------- Cargo.toml | 34 +- contracts/astroport-liquid-pooler/Cargo.toml | 4 +- .../examples/schema.rs | 2 +- .../astroport-liquid-pooler/src/contract.rs | 4 +- contracts/clock-tester/Cargo.toml | 2 +- contracts/clock-tester/src/contract.rs | 2 +- contracts/clock/Cargo.toml | 4 +- contracts/clock/src/contract.rs | 2 +- contracts/clock/src/suite_tests/mod.rs | 6 +- contracts/clock/src/suite_tests/suite.rs | 6 +- contracts/clock/src/suite_tests/tests.rs | 2 +- contracts/ibc-forwarder/Cargo.toml | 4 +- contracts/ibc-forwarder/src/contract.rs | 4 +- contracts/interchain-router/Cargo.toml | 6 +- contracts/interchain-router/src/contract.rs | 4 +- .../interchain-router/src/suite_tests/mod.rs | 6 +- .../src/suite_tests/suite.rs | 2 +- contracts/native-router/Cargo.toml | 4 +- contracts/native-router/src/contract.rs | 4 +- contracts/native-splitter/Cargo.toml | 4 +- contracts/native-splitter/src/contract.rs | 4 +- contracts/osmo-liquid-pooler/Cargo.toml | 6 +- contracts/osmo-liquid-pooler/src/contract.rs | 8 +- contracts/osmo-liquid-pooler/src/msg.rs | 4 +- .../outpost-osmo-liquid-pooler/Cargo.toml | 2 +- .../src/contract.rs | 2 +- contracts/remote-chain-splitter/Cargo.toml | 4 +- .../remote-chain-splitter/src/contract.rs | 4 +- .../single-party-pol-covenant/Cargo.toml | 18 +- .../single-party-pol-covenant/src/contract.rs | 14 +- .../single-party-pol-covenant/src/msg.rs | 22 +- contracts/single-party-pol-holder/Cargo.toml | 2 +- .../single-party-pol-holder/src/contract.rs | 2 +- contracts/stride-liquid-staker/Cargo.toml | 4 +- .../stride-liquid-staker/examples/schema.rs | 2 +- .../stride-liquid-staker/src/contract.rs | 4 +- contracts/swap-covenant/Cargo.toml | 14 +- contracts/swap-covenant/src/contract.rs | 14 +- contracts/swap-covenant/src/msg.rs | 18 +- contracts/swap-holder/Cargo.toml | 4 +- contracts/swap-holder/src/contract.rs | 4 +- contracts/swap-holder/src/msg.rs | 2 +- contracts/two-party-pol-covenant/Cargo.toml | 16 +- .../two-party-pol-covenant/src/contract.rs | 10 +- contracts/two-party-pol-covenant/src/msg.rs | 26 +- contracts/two-party-pol-holder/Cargo.toml | 4 +- .../two-party-pol-holder/src/contract.rs | 4 +- contracts/two-party-pol-holder/src/msg.rs | 2 +- unit-tests/Cargo.toml | 32 +- unit-tests/src/setup/base_suite.rs | 6 +- unit-tests/src/setup/contracts.rs | 255 +-- unit-tests/src/setup/custom_module.rs | 4 +- .../setup/instantiates/astro_liquid_pooler.rs | 14 +- unit-tests/src/setup/instantiates/clock.rs | 8 +- .../src/setup/instantiates/ibc_forwarder.rs | 8 +- .../setup/instantiates/interchain_router.rs | 6 +- .../src/setup/instantiates/native_router.rs | 6 +- .../src/setup/instantiates/native_splitter.rs | 8 +- .../src/setup/instantiates/osmo_lp_outpost.rs | 14 +- .../instantiates/remote_chain_splitter.rs | 8 +- .../instantiates/single_party_covenant.rs | 58 +- .../setup/instantiates/single_party_holder.rs | 8 +- .../src/setup/instantiates/swap_covenant.rs | 50 +- .../src/setup/instantiates/swap_holder.rs | 10 +- .../setup/instantiates/two_party_covenant.rs | 51 +- .../instantiates/two_party_pol_holder.rs | 26 +- .../src/test_astroport_liquid_pooler/suite.rs | 24 +- .../src/test_astroport_liquid_pooler/tests.rs | 14 +- unit-tests/src/test_ibc_forwarder/suite.rs | 24 +- unit-tests/src/test_ibc_forwarder/tests.rs | 8 +- .../src/test_interchain_router/suite.rs | 8 +- unit-tests/src/test_native_router/suite.rs | 16 +- unit-tests/src/test_native_router/tests.rs | 4 +- unit-tests/src/test_native_splitter/suite.rs | 20 +- unit-tests/src/test_native_splitter/tests.rs | 4 +- unit-tests/src/test_osmo_lp_outpost/suite.rs | 14 +- unit-tests/src/test_osmo_lp_outpost/tests.rs | 2 +- .../src/test_remote_chain_splitter/suite.rs | 32 +- .../src/test_remote_chain_splitter/tests.rs | 10 +- .../src/test_single_party_covenant/suite.rs | 26 +- .../src/test_single_party_covenant/test.rs | 62 +- .../src/test_single_party_holder/suite.rs | 34 +- .../src/test_single_party_holder/tests.rs | 4 +- unit-tests/src/test_swap_covenant/suite.rs | 24 +- unit-tests/src/test_swap_covenant/test.rs | 38 +- unit-tests/src/test_swap_holder/suite.rs | 38 +- unit-tests/src/test_swap_holder/tests.rs | 8 +- .../src/test_two_party_covenant/suite.rs | 32 +- .../src/test_two_party_covenant/test.rs | 88 +- .../src/test_two_party_pol_holder/suite.rs | 62 +- .../src/test_two_party_pol_holder/tests.rs | 30 +- 92 files changed, 1480 insertions(+), 1466 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19b3b580..f730a7fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -361,972 +361,613 @@ dependencies = [ ] [[package]] -name = "covenant-astroport-liquid-pooler" +name = "covenant-macros" +version = "1.0.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "covenant-utils" version = "1.0.0" dependencies = [ "astroport", "bech32", + "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", - "covenant-clock", "covenant-macros", - "covenant-utils", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", - "cw2 1.1.2", "cw20", "neutron-sdk", - "schemars", - "serde", + "polytone", + "prost 0.11.9", + "serde-json-wasm 0.4.1", "sha2 0.9.9", - "thiserror", ] [[package]] -name = "covenant-clock" -version = "1.0.0" +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ - "anyhow", - "cosmwasm-schema", - "cosmwasm-std", - "covenant-clock-tester", - "covenant-macros", - "cw-fifo", - "cw-multi-test", - "cw-storage-plus 1.2.0", - "cw2 1.1.2", - "neutron-sdk", - "serde", - "thiserror", + "libc", ] [[package]] -name = "covenant-clock-tester" -version = "1.0.0" +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.2.0", - "cw2 1.1.2", - "thiserror", + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", ] [[package]] -name = "covenant-ibc-forwarder" +name = "cw-fifo" version = "1.0.0" dependencies = [ - "bech32", - "cosmos-sdk-proto 0.14.0", - "cosmwasm-schema", "cosmwasm-std", - "covenant-clock", - "covenant-macros", - "covenant-utils", "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", - "neutron-sdk", - "prost 0.11.9", - "prost-types 0.11.9", - "schemars", "serde", - "serde-json-wasm 0.4.1", - "sha2 0.9.9", - "thiserror", ] [[package]] -name = "covenant-interchain-router" -version = "1.0.0" +name = "cw-multi-test" +version = "0.20.0" +source = "git+https://github.com/Art3miX/cw-multi-test?branch=main#a09a3c0c3672ee33565a0f5281a71786c491afe1" dependencies = [ "anyhow", "bech32", - "cosmos-sdk-proto 0.14.0", - "cosmwasm-schema", "cosmwasm-std", - "covenant-clock", - "covenant-macros", - "covenant-utils", - "cw-multi-test", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", - "cw2 1.1.2", - "neutron-sdk", - "prost 0.11.9", - "prost-types 0.11.9", + "derivative", + "itertools 0.12.1", + "prost 0.12.3", "schemars", "serde", - "sha2 0.9.9", + "sha2 0.10.8", "thiserror", ] [[package]] -name = "covenant-macros" -version = "1.0.0" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "covenant-native-router" -version = "1.0.0" +name = "cw-storage-plus" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6cf70ef7686e2da9ad7b067c5942cd3e88dd9453f7af42f54557f8af300fb0" dependencies = [ - "bech32", - "cosmos-sdk-proto 0.14.0", - "cosmwasm-schema", "cosmwasm-std", - "covenant-clock", - "covenant-macros", - "covenant-utils", - "cw-storage-plus 1.2.0", - "cw2 1.1.2", - "neutron-sdk", - "prost 0.11.9", - "prost-types 0.11.9", "schemars", "serde", - "sha2 0.9.9", - "thiserror", ] [[package]] -name = "covenant-native-splitter" -version = "1.0.0" +name = "cw-storage-plus" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5ff29294ee99373e2cd5fd21786a3c0ced99a52fec2ca347d565489c61b723c" dependencies = [ - "cosmwasm-schema", "cosmwasm-std", - "covenant-clock", - "covenant-macros", - "covenant-utils", - "cw-storage-plus 1.2.0", - "cw2 1.1.2", "schemars", "serde", - "thiserror", ] [[package]] -name = "covenant-osmo-liquid-pooler" -version = "1.0.0" +name = "cw-utils" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ae0b69fa7679de78825b4edeeec045066aa2b2c4b6e063d80042e565bb4da5c" dependencies = [ - "bech32", "cosmwasm-schema", "cosmwasm-std", - "covenant-clock", - "covenant-macros", - "covenant-outpost-osmo-liquid-pooler", - "covenant-utils", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", - "cw20", - "neutron-sdk", - "osmosis-std 0.20.1", - "polytone", - "prost 0.11.9", + "cw2 0.15.1", "schemars", + "semver", "serde", - "sha2 0.9.9", "thiserror", ] [[package]] -name = "covenant-outpost-osmo-liquid-pooler" -version = "1.0.0" +name = "cw-utils" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c4a657e5caacc3a0d00ee96ca8618745d050b8f757c709babafb81208d4239c" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", "cw2 1.1.2", - "osmosis-std 0.13.2", - "prost 0.11.9", "schemars", + "semver", "serde", "thiserror", ] [[package]] -name = "covenant-remote-chain-splitter" -version = "1.0.0" +name = "cw1" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbe0783ec4210ba4e0cdfed9874802f469c6db0880f742ad427cb950e940b21c" dependencies = [ - "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", - "covenant-clock", - "covenant-macros", - "covenant-utils", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", - "neutron-sdk", "schemars", "serde", - "serde-json-wasm 0.4.1", - "thiserror", ] [[package]] -name = "covenant-single-party-pol" -version = "1.0.0" +name = "cw1-whitelist" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233dd13f61495f1336da57c8bdca0536fa9f8dd59c12d2bbfc59928ea580e478" dependencies = [ - "astroport", - "bech32", - "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", - "covenant-astroport-liquid-pooler", - "covenant-clock", - "covenant-ibc-forwarder", - "covenant-interchain-router", - "covenant-osmo-liquid-pooler", - "covenant-remote-chain-splitter", - "covenant-single-party-pol-holder", - "covenant-stride-liquid-staker", - "covenant-utils", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", - "neutron-sdk", - "prost 0.11.9", - "prost-types 0.11.9", + "cw-storage-plus 0.15.1", + "cw-utils 0.15.1", + "cw1", + "cw2 0.15.1", "schemars", "serde", - "serde-json-wasm 0.4.1", - "sha2 0.9.9", "thiserror", ] [[package]] -name = "covenant-single-party-pol-holder" -version = "1.0.0" +name = "cw2" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5abb8ecea72e09afff830252963cb60faf945ce6cef2c20a43814516082653da" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "covenant-macros", - "covenant-utils", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", + "cw-storage-plus 0.15.1", + "schemars", "serde", - "thiserror", ] [[package]] -name = "covenant-stride-liquid-staker" -version = "1.0.0" +name = "cw2" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6c120b24fbbf5c3bedebb97f2cc85fbfa1c3287e09223428e7e597b5293c1fa" dependencies = [ - "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", - "covenant-clock", - "covenant-macros", - "covenant-utils", "cw-storage-plus 1.2.0", - "cw2 1.1.2", - "neutron-sdk", "schemars", + "semver", "serde", - "serde-json-wasm 0.4.1", "thiserror", ] [[package]] -name = "covenant-swap" -version = "1.0.0" +name = "cw20" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6025276fb6e603e974c21f3e4606982cdc646080e8fba3198816605505e1d9a" dependencies = [ - "bech32", - "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", - "covenant-clock", - "covenant-ibc-forwarder", - "covenant-interchain-router", - "covenant-native-router", - "covenant-native-splitter", - "covenant-swap-holder", - "covenant-utils", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", - "neutron-sdk", - "prost 0.11.9", - "prost-types 0.11.9", + "cw-utils 0.15.1", "schemars", "serde", - "serde-json-wasm 0.4.1", - "sha2 0.9.9", - "thiserror", ] [[package]] -name = "covenant-swap-holder" -version = "1.0.0" +name = "cw20-base" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0909c56d0c14601fbdc69382189799482799dcad87587926aec1f3aa321abc41" dependencies = [ - "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", - "covenant-clock", - "covenant-macros", - "covenant-utils", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", - "neutron-sdk", + "cw-storage-plus 0.15.1", + "cw-utils 0.15.1", + "cw2 0.15.1", + "cw20", + "schemars", + "semver", "serde", "thiserror", ] [[package]] -name = "covenant-two-party-pol" -version = "1.0.0" +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ - "astroport", - "bech32", - "cosmos-sdk-proto 0.14.0", - "cosmwasm-schema", - "cosmwasm-std", - "covenant-astroport-liquid-pooler", - "covenant-clock", - "covenant-ibc-forwarder", - "covenant-interchain-router", - "covenant-native-router", - "covenant-osmo-liquid-pooler", - "covenant-two-party-pol-holder", - "covenant-utils", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", - "neutron-sdk", - "prost 0.11.9", - "prost-types 0.11.9", - "schemars", - "serde", - "serde-json-wasm 0.4.1", - "sha2 0.9.9", - "thiserror", + "const-oid", + "zeroize", ] [[package]] -name = "covenant-two-party-pol-holder" -version = "1.0.0" +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "astroport", - "cosmwasm-schema", - "cosmwasm-std", - "covenant-clock", - "covenant-macros", - "covenant-utils", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw2 1.1.2", - "cw20", - "schemars", - "serde", - "thiserror", + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] -name = "covenant-utils" -version = "1.0.0" +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "astroport", - "bech32", - "cosmos-sdk-proto 0.14.0", - "cosmwasm-schema", - "cosmwasm-std", - "covenant-macros", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "cw20", - "neutron-sdk", - "polytone", - "prost 0.11.9", - "serde-json-wasm 0.4.1", - "sha2 0.9.9", + "generic-array", ] [[package]] -name = "cpufeatures" -version = "0.2.12" +name = "digest" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "libc", + "block-buffer 0.10.4", + "const-oid", + "crypto-common", + "subtle", ] [[package]] -name = "crunchy" -version = "0.2.2" +name = "doc-comment" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] -name = "crypto-bigint" -version = "0.5.5" +name = "dyn-clone" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ - "generic-array", - "rand_core 0.6.4", - "subtle", - "zeroize", + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", ] [[package]] -name = "crypto-common" -version = "0.1.6" +name = "ed25519-zebra" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" dependencies = [ - "generic-array", - "typenum", + "curve25519-dalek", + "hashbrown", + "hex", + "rand_core 0.6.4", + "serde", + "sha2 0.9.9", + "zeroize", ] [[package]] -name = "curve25519-dalek" -version = "3.2.0" +name = "either" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", "subtle", "zeroize", ] [[package]] -name = "cw-fifo" -version = "1.0.0" +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ - "cosmwasm-std", - "cw-storage-plus 1.2.0", - "serde", + "rand_core 0.6.4", + "subtle", ] [[package]] -name = "cw-multi-test" -version = "0.20.0" -source = "git+https://github.com/Art3miX/cw-multi-test?branch=main#a09a3c0c3672ee33565a0f5281a71786c491afe1" +name = "flex-error" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c606d892c9de11507fa0dcffc116434f94e105d0bbdc4e405b61519464c49d7b" dependencies = [ - "anyhow", - "bech32", - "cosmwasm-std", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "derivative", - "itertools 0.12.1", - "prost 0.12.3", - "schemars", - "serde", - "sha2 0.10.8", - "thiserror", + "paste", ] [[package]] -name = "cw-storage-plus" -version = "0.15.1" +name = "forward_ref" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6cf70ef7686e2da9ad7b067c5942cd3e88dd9453f7af42f54557f8af300fb0" +checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ - "cosmwasm-std", - "schemars", - "serde", + "typenum", + "version_check", + "zeroize", ] [[package]] -name = "cw-storage-plus" -version = "1.2.0" +name = "getrandom" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5ff29294ee99373e2cd5fd21786a3c0ced99a52fec2ca347d565489c61b723c" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ - "cosmwasm-std", - "schemars", - "serde", + "cfg-if", + "libc", + "wasi", ] [[package]] -name = "cw-utils" -version = "0.15.1" +name = "group" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ae0b69fa7679de78825b4edeeec045066aa2b2c4b6e063d80042e565bb4da5c" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw2 0.15.1", - "schemars", - "semver", - "serde", - "thiserror", + "ff", + "rand_core 0.6.4", + "subtle", ] [[package]] -name = "cw-utils" -version = "1.0.3" +name = "hashbrown" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c4a657e5caacc3a0d00ee96ca8618745d050b8f757c709babafb81208d4239c" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw2 1.1.2", - "schemars", - "semver", - "serde", - "thiserror", + "ahash", ] [[package]] -name = "cw1" -version = "0.15.1" +name = "heck" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbe0783ec4210ba4e0cdfed9874802f469c6db0880f742ad427cb950e940b21c" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "schemars", - "serde", -] +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] -name = "cw1-whitelist" -version = "0.15.1" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233dd13f61495f1336da57c8bdca0536fa9f8dd59c12d2bbfc59928ea580e478" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "cw-utils 0.15.1", - "cw1", - "cw2 0.15.1", - "schemars", - "serde", - "thiserror", -] +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] -name = "cw2" -version = "0.15.1" +name = "hex" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5abb8ecea72e09afff830252963cb60faf945ce6cef2c20a43814516082653da" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "schemars", - "serde", -] +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] -name = "cw2" -version = "1.1.2" +name = "hmac" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c120b24fbbf5c3bedebb97f2cc85fbfa1c3287e09223428e7e597b5293c1fa" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.2.0", - "schemars", - "semver", - "serde", - "thiserror", + "digest 0.10.7", ] [[package]] -name = "cw20" -version = "0.15.1" +name = "integer-sqrt" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6025276fb6e603e974c21f3e4606982cdc646080e8fba3198816605505e1d9a" +checksum = "276ec31bcb4a9ee45f58bec6f9ec700ae4cf4f4f8f2fa7e06cb406bd5ffdd770" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-utils 0.15.1", - "schemars", - "serde", + "num-traits", ] [[package]] -name = "cw20-base" -version = "0.15.1" +name = "is-terminal" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0909c56d0c14601fbdc69382189799482799dcad87587926aec1f3aa321abc41" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "cw-utils 0.15.1", - "cw2 0.15.1", - "cw20", - "schemars", - "semver", - "serde", - "thiserror", + "hermit-abi", + "libc", + "windows-sys", ] [[package]] -name = "der" -version = "0.7.8" +name = "itertools" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ - "const-oid", - "zeroize", + "either", ] [[package]] -name = "derivative" -version = "2.2.0" +name = "itertools" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", + "either", ] [[package]] -name = "digest" -version = "0.9.0" +name = "itertools" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ - "generic-array", + "either", ] [[package]] -name = "digest" -version = "0.10.7" +name = "itoa" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer 0.10.4", - "const-oid", - "crypto-common", - "subtle", -] +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] -name = "doc-comment" -version = "0.3.3" +name = "k256" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8", + "signature", +] [[package]] -name = "dyn-clone" -version = "1.0.17" +name = "lazy_static" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] -name = "ecdsa" -version = "0.16.9" +name = "libc" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest 0.10.7", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] -name = "ed25519-zebra" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +name = "neutron-sdk" +version = "0.8.0" +source = "git+https://github.com/neutron-org/neutron-sdk?tag=v0.8.0#40f6592f1eec9e2e1bf0e0531a011294d70d1711" dependencies = [ - "curve25519-dalek", - "hashbrown", - "hex", - "rand_core 0.6.4", + "bech32", + "cosmos-sdk-proto 0.20.0", + "cosmwasm-schema", + "cosmwasm-std", + "prost 0.12.3", + "prost-types 0.12.3", + "protobuf 3.4.0", + "schemars", "serde", - "sha2 0.9.9", - "zeroize", + "serde-json-wasm 1.0.1", + "speedate", + "tendermint-proto 0.34.1", + "thiserror", ] [[package]] -name = "either" -version = "1.10.0" +name = "num-derive" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] [[package]] -name = "elliptic-curve" -version = "0.13.8" +name = "num-traits" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ - "base16ct", - "crypto-bigint", - "digest 0.10.7", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core 0.6.4", - "sec1", - "subtle", - "zeroize", + "autocfg", ] [[package]] -name = "ff" -version = "0.13.0" +name = "num_threads" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" dependencies = [ - "rand_core 0.6.4", - "subtle", + "libc", ] [[package]] -name = "flex-error" -version = "0.4.4" +name = "once_cell" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c606d892c9de11507fa0dcffc116434f94e105d0bbdc4e405b61519464c49d7b" -dependencies = [ - "paste", -] +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] -name = "forward_ref" -version = "1.0.0" +name = "opaque-debug" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] -name = "generic-array" -version = "0.14.7" +name = "osmosis-std" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +checksum = "10d6fe6ac7fcba45ed61d738091d33c838c4cabbcf4892dc7aa56d19d39cc976" dependencies = [ - "typenum", - "version_check", - "zeroize", + "chrono", + "cosmwasm-std", + "osmosis-std-derive 0.13.2", + "prost 0.11.9", + "prost-types 0.11.9", + "schemars", + "serde", + "serde-cw-value", ] [[package]] -name = "getrandom" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core 0.6.4", - "subtle", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash", -] - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "integer-sqrt" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "276ec31bcb4a9ee45f58bec6f9ec700ae4cf4f4f8f2fa7e06cb406bd5ffdd770" -dependencies = [ - "num-traits", -] - -[[package]] -name = "is-terminal" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys", -] - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" - -[[package]] -name = "k256" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8", - "signature", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.153" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "neutron-sdk" -version = "0.8.0" -source = "git+https://github.com/neutron-org/neutron-sdk?tag=v0.8.0#40f6592f1eec9e2e1bf0e0531a011294d70d1711" -dependencies = [ - "bech32", - "cosmos-sdk-proto 0.20.0", - "cosmwasm-schema", - "cosmwasm-std", - "prost 0.12.3", - "prost-types 0.12.3", - "protobuf 3.4.0", - "schemars", - "serde", - "serde-json-wasm 1.0.1", - "speedate", - "tendermint-proto 0.34.1", - "thiserror", -] - -[[package]] -name = "num-derive" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "num-traits" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_threads" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" -dependencies = [ - "libc", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "opaque-debug" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" - -[[package]] -name = "osmosis-std" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10d6fe6ac7fcba45ed61d738091d33c838c4cabbcf4892dc7aa56d19d39cc976" -dependencies = [ - "chrono", - "cosmwasm-std", - "osmosis-std-derive 0.13.2", - "prost 0.11.9", - "prost-types 0.11.9", - "schemars", - "serde", - "serde-cw-value", -] - -[[package]] -name = "osmosis-std" -version = "0.20.1" +name = "osmosis-std" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47d7aa053bc3fad557ac90a0377688b400c395e2537f0f1de3293a15cad2e970" dependencies = [ @@ -1932,22 +1573,6 @@ dependencies = [ "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", - "covenant-astroport-liquid-pooler", - "covenant-clock", - "covenant-ibc-forwarder", - "covenant-interchain-router", - "covenant-native-router", - "covenant-native-splitter", - "covenant-osmo-liquid-pooler", - "covenant-outpost-osmo-liquid-pooler", - "covenant-remote-chain-splitter", - "covenant-single-party-pol", - "covenant-single-party-pol-holder", - "covenant-stride-liquid-staker", - "covenant-swap", - "covenant-swap-holder", - "covenant-two-party-pol", - "covenant-two-party-pol-holder", "covenant-utils", "cw-multi-test", "cw-storage-plus 1.2.0", @@ -1960,6 +1585,381 @@ dependencies = [ "prost 0.11.9", "prost-types 0.11.9", "sha2 0.9.9", + "valence-astroport-liquid-pooler", + "valence-clock", + "valence-covenant-single-party-pol", + "valence-covenant-swap", + "valence-covenant-two-party-pol", + "valence-ibc-forwarder", + "valence-interchain-router", + "valence-native-router", + "valence-native-splitter", + "valence-osmo-liquid-pooler", + "valence-outpost-osmo-liquid-pooler", + "valence-remote-chain-splitter", + "valence-single-party-pol-holder", + "valence-stride-liquid-staker", + "valence-swap-holder", + "valence-two-party-pol-holder", +] + +[[package]] +name = "valence-astroport-liquid-pooler" +version = "1.0.0" +dependencies = [ + "astroport", + "bech32", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "cw20", + "neutron-sdk", + "schemars", + "serde", + "sha2 0.9.9", + "thiserror", + "valence-clock", +] + +[[package]] +name = "valence-clock" +version = "1.0.0" +dependencies = [ + "anyhow", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "cw-fifo", + "cw-multi-test", + "cw-storage-plus 1.2.0", + "cw2 1.1.2", + "neutron-sdk", + "serde", + "thiserror", + "valence-clock-tester", +] + +[[package]] +name = "valence-clock-tester" +version = "1.0.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 1.2.0", + "cw2 1.1.2", + "thiserror", +] + +[[package]] +name = "valence-covenant-single-party-pol" +version = "1.0.0" +dependencies = [ + "astroport", + "bech32", + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "neutron-sdk", + "prost 0.11.9", + "prost-types 0.11.9", + "schemars", + "serde", + "serde-json-wasm 0.4.1", + "sha2 0.9.9", + "thiserror", + "valence-astroport-liquid-pooler", + "valence-clock", + "valence-ibc-forwarder", + "valence-interchain-router", + "valence-osmo-liquid-pooler", + "valence-remote-chain-splitter", + "valence-single-party-pol-holder", + "valence-stride-liquid-staker", +] + +[[package]] +name = "valence-covenant-swap" +version = "1.0.0" +dependencies = [ + "bech32", + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "neutron-sdk", + "prost 0.11.9", + "prost-types 0.11.9", + "schemars", + "serde", + "serde-json-wasm 0.4.1", + "sha2 0.9.9", + "thiserror", + "valence-clock", + "valence-ibc-forwarder", + "valence-interchain-router", + "valence-native-router", + "valence-native-splitter", + "valence-swap-holder", +] + +[[package]] +name = "valence-covenant-two-party-pol" +version = "1.0.0" +dependencies = [ + "astroport", + "bech32", + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "neutron-sdk", + "prost 0.11.9", + "prost-types 0.11.9", + "schemars", + "serde", + "serde-json-wasm 0.4.1", + "sha2 0.9.9", + "thiserror", + "valence-astroport-liquid-pooler", + "valence-clock", + "valence-ibc-forwarder", + "valence-interchain-router", + "valence-native-router", + "valence-osmo-liquid-pooler", + "valence-two-party-pol-holder", +] + +[[package]] +name = "valence-ibc-forwarder" +version = "1.0.0" +dependencies = [ + "bech32", + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "neutron-sdk", + "prost 0.11.9", + "prost-types 0.11.9", + "schemars", + "serde", + "serde-json-wasm 0.4.1", + "sha2 0.9.9", + "thiserror", + "valence-clock", +] + +[[package]] +name = "valence-interchain-router" +version = "1.0.0" +dependencies = [ + "anyhow", + "bech32", + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-multi-test", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "neutron-sdk", + "prost 0.11.9", + "prost-types 0.11.9", + "schemars", + "serde", + "sha2 0.9.9", + "thiserror", + "valence-clock", +] + +[[package]] +name = "valence-native-router" +version = "1.0.0" +dependencies = [ + "bech32", + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw2 1.1.2", + "neutron-sdk", + "prost 0.11.9", + "prost-types 0.11.9", + "schemars", + "serde", + "sha2 0.9.9", + "thiserror", + "valence-clock", +] + +[[package]] +name = "valence-native-splitter" +version = "1.0.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw2 1.1.2", + "schemars", + "serde", + "thiserror", + "valence-clock", +] + +[[package]] +name = "valence-osmo-liquid-pooler" +version = "1.0.0" +dependencies = [ + "bech32", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "cw20", + "neutron-sdk", + "osmosis-std 0.20.1", + "polytone", + "prost 0.11.9", + "schemars", + "serde", + "sha2 0.9.9", + "thiserror", + "valence-clock", + "valence-outpost-osmo-liquid-pooler", +] + +[[package]] +name = "valence-outpost-osmo-liquid-pooler" +version = "1.0.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "osmosis-std 0.13.2", + "prost 0.11.9", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "valence-remote-chain-splitter" +version = "1.0.0" +dependencies = [ + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "neutron-sdk", + "schemars", + "serde", + "serde-json-wasm 0.4.1", + "thiserror", + "valence-clock", +] + +[[package]] +name = "valence-single-party-pol-holder" +version = "1.0.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "serde", + "thiserror", +] + +[[package]] +name = "valence-stride-liquid-staker" +version = "1.0.0" +dependencies = [ + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw2 1.1.2", + "neutron-sdk", + "schemars", + "serde", + "serde-json-wasm 0.4.1", + "thiserror", + "valence-clock", +] + +[[package]] +name = "valence-swap-holder" +version = "1.0.0" +dependencies = [ + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "neutron-sdk", + "serde", + "thiserror", + "valence-clock", +] + +[[package]] +name = "valence-two-party-pol-holder" +version = "1.0.0" +dependencies = [ + "astroport", + "cosmwasm-schema", + "cosmwasm-std", + "covenant-macros", + "covenant-utils", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "cw20", + "schemars", + "serde", + "thiserror", + "valence-clock", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3edfffcd..96795441 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,23 +25,23 @@ panic = 'abort' rpath = false [workspace.dependencies] -covenant-clock = { path = "contracts/clock" } -covenant-clock-tester = { path = "contracts/clock-tester" } -covenant-ibc-forwarder = { path = "contracts/ibc-forwarder" } -covenant-remote-chain-splitter = { path = "contracts/remote-chain-splitter" } -covenant-native-splitter = { path = "contracts/native-splitter" } -covenant-swap-holder = { path = "contracts/swap-holder" } -covenant-swap = { path = "contracts/swap-covenant" } -covenant-interchain-router = { path = "contracts/interchain-router" } -covenant-two-party-pol-holder = { path = "contracts/two-party-pol-holder" } -covenant-two-party-pol = { path = "contracts/two-party-pol-covenant" } -covenant-astroport-liquid-pooler = { path = "contracts/astroport-liquid-pooler" } -covenant-native-router = { path = "contracts/native-router" } -covenant-osmo-liquid-pooler = { path = "contracts/osmo-liquid-pooler" } -covenant-outpost-osmo-liquid-pooler = { path = "contracts/outpost-osmo-liquid-pooler" } -covenant-single-party-pol-holder = { path = "contracts/single-party-pol-holder" } -covenant-single-party-pol = { path = "contracts/single-party-pol-covenant" } -covenant-stride-liquid-staker = { path = "contracts/stride-liquid-staker" } +valence-clock = { path = "contracts/clock" } +valence-clock-tester = { path = "contracts/clock-tester" } +valence-ibc-forwarder = { path = "contracts/ibc-forwarder" } +valence-remote-chain-splitter = { path = "contracts/remote-chain-splitter" } +valence-native-splitter = { path = "contracts/native-splitter" } +valence-swap-holder = { path = "contracts/swap-holder" } +valence-covenant-swap = { path = "contracts/swap-covenant" } +valence-interchain-router = { path = "contracts/interchain-router" } +valence-two-party-pol-holder = { path = "contracts/two-party-pol-holder" } +valence-covenant-two-party-pol = { path = "contracts/two-party-pol-covenant" } +valence-astroport-liquid-pooler = { path = "contracts/astroport-liquid-pooler" } +valence-native-router = { path = "contracts/native-router" } +valence-osmo-liquid-pooler = { path = "contracts/osmo-liquid-pooler" } +valence-outpost-osmo-liquid-pooler = { path = "contracts/outpost-osmo-liquid-pooler" } +valence-single-party-pol-holder = { path = "contracts/single-party-pol-holder" } +valence-covenant-single-party-pol = { path = "contracts/single-party-pol-covenant" } +valence-stride-liquid-staker = { path = "contracts/stride-liquid-staker" } # packages polytone = "1.0.0" diff --git a/contracts/astroport-liquid-pooler/Cargo.toml b/contracts/astroport-liquid-pooler/Cargo.toml index ed851941..8325b8f3 100644 --- a/contracts/astroport-liquid-pooler/Cargo.toml +++ b/contracts/astroport-liquid-pooler/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-astroport-liquid-pooler" +name = "valence-astroport-liquid-pooler" authors = ["benskey bekauz@protonmail.com"] description = "Astroport liquid pooler contract for covenants" license = { workspace = true } @@ -21,7 +21,7 @@ library = [] [dependencies] covenant-macros = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } diff --git a/contracts/astroport-liquid-pooler/examples/schema.rs b/contracts/astroport-liquid-pooler/examples/schema.rs index 8a393186..65623de2 100644 --- a/contracts/astroport-liquid-pooler/examples/schema.rs +++ b/contracts/astroport-liquid-pooler/examples/schema.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use covenant_astroport_liquid_pooler::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; use std::env::current_dir; use std::fs::create_dir_all; +use valence_astroport_liquid_pooler::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { let mut out_dir = current_dir().unwrap(); diff --git a/contracts/astroport-liquid-pooler/src/contract.rs b/contracts/astroport-liquid-pooler/src/contract.rs index b67e770a..8d07294f 100644 --- a/contracts/astroport-liquid-pooler/src/contract.rs +++ b/contracts/astroport-liquid-pooler/src/contract.rs @@ -4,9 +4,9 @@ use cosmwasm_std::{ coin, ensure, to_json_binary, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult, SubMsg, SubMsgResult, Uint128, WasmMsg, }; -use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::{astroport::query_astro_pool_token, withdraw_lp_helper::WithdrawLPMsgs}; use cw2::set_contract_version; +use valence_clock::helpers::{enqueue_msg, verify_clock}; use astroport::{ asset::{Asset, PairInfo}, @@ -29,7 +29,7 @@ use neutron_sdk::NeutronResult; use crate::state::{CLOCK_ADDRESS, CONTRACT_STATE}; -const CONTRACT_NAME: &str = "crates.io:covenant-astroport-liquid-pooler"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); const DOUBLE_SIDED_REPLY_ID: u64 = 321u64; diff --git a/contracts/clock-tester/Cargo.toml b/contracts/clock-tester/Cargo.toml index 16d5b261..12ad33be 100644 --- a/contracts/clock-tester/Cargo.toml +++ b/contracts/clock-tester/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-clock-tester" +name = "valence-clock-tester" authors = ["ekez "] edition = { workspace = true } license = { workspace = true } diff --git a/contracts/clock-tester/src/contract.rs b/contracts/clock-tester/src/contract.rs index a2d80daa..cf907542 100644 --- a/contracts/clock-tester/src/contract.rs +++ b/contracts/clock-tester/src/contract.rs @@ -9,7 +9,7 @@ use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, Mode, QueryMsg}; use crate::state::{MODE, TICK_COUNT}; -const CONTRACT_NAME: &str = "crates.io:covenant-clock-tester"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/clock/Cargo.toml b/contracts/clock/Cargo.toml index d82101bc..5a061d3c 100644 --- a/contracts/clock/Cargo.toml +++ b/contracts/clock/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-clock" +name = "valence-clock" authors = ["ekez "] description = "A clock that advances the covenant state machine." edition = { workspace = true } @@ -30,4 +30,4 @@ neutron-sdk = { workspace = true } [dev-dependencies] cw-multi-test = { workspace = true } anyhow = { workspace = true } -covenant-clock-tester = { workspace = true, features = ["library"] } +valence-clock-tester = { workspace = true, features = ["library"] } diff --git a/contracts/clock/src/contract.rs b/contracts/clock/src/contract.rs index f5e58a59..0fb86603 100644 --- a/contracts/clock/src/contract.rs +++ b/contracts/clock/src/contract.rs @@ -10,7 +10,7 @@ use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use crate::state::{PAUSED, QUEUE, TICK_MAX_GAS, WHITELIST}; -const CONTRACT_NAME: &str = "crates.io:covenant-clock"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const MIN_TICK_MAX_GAS: Uint64 = Uint64::new(200_000); diff --git a/contracts/clock/src/suite_tests/mod.rs b/contracts/clock/src/suite_tests/mod.rs index 83328d90..6b42309c 100644 --- a/contracts/clock/src/suite_tests/mod.rs +++ b/contracts/clock/src/suite_tests/mod.rs @@ -27,9 +27,9 @@ pub fn clock_contract() -> Box> { pub fn clock_tester_contract() -> Box> { let contract = ContractWrapper::new( - covenant_clock_tester::contract::execute, - covenant_clock_tester::contract::instantiate, - covenant_clock_tester::contract::query, + valence_clock_tester::contract::execute, + valence_clock_tester::contract::instantiate, + valence_clock_tester::contract::query, ); Box::new(contract) } diff --git a/contracts/clock/src/suite_tests/suite.rs b/contracts/clock/src/suite_tests/suite.rs index 5603cc0b..1c3036af 100644 --- a/contracts/clock/src/suite_tests/suite.rs +++ b/contracts/clock/src/suite_tests/suite.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{Addr, Uint64}; -use covenant_clock_tester::msg::Mode; use cw_multi_test::{App, AppResponse, Executor}; +use valence_clock_tester::msg::Mode; use crate::{ contract::DEFAULT_TICK_MAX_GAS, @@ -79,7 +79,7 @@ impl SuiteBuilder { .instantiate_contract( code_id, Addr::unchecked(ADMIN), - &covenant_clock_tester::msg::InstantiateMsg { mode }, + &valence_clock_tester::msg::InstantiateMsg { mode }, &[], "clock-tester", Some(ADMIN.to_string()), @@ -213,7 +213,7 @@ impl Suite { .wrap() .query_wasm_smart( tester.to_string(), - &covenant_clock_tester::msg::QueryMsg::TickCount {}, + &valence_clock_tester::msg::QueryMsg::TickCount {}, ) .unwrap(); res.u64() diff --git a/contracts/clock/src/suite_tests/tests.rs b/contracts/clock/src/suite_tests/tests.rs index b0c11751..a5c884a5 100644 --- a/contracts/clock/src/suite_tests/tests.rs +++ b/contracts/clock/src/suite_tests/tests.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{Addr, StdError, Uint64}; -use covenant_clock_tester::msg::Mode; +use valence_clock_tester::msg::Mode; use crate::contract::DEFAULT_TICK_MAX_GAS; use crate::error::ContractError; diff --git a/contracts/ibc-forwarder/Cargo.toml b/contracts/ibc-forwarder/Cargo.toml index 4ad100a6..f5c7ee0e 100644 --- a/contracts/ibc-forwarder/Cargo.toml +++ b/contracts/ibc-forwarder/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-ibc-forwarder" +name = "valence-ibc-forwarder" edition = { workspace = true } authors = ["benskey bekauz@protonmail.com"] description = "IBC Forwarder module for covenants" @@ -21,7 +21,7 @@ library = [] [dependencies] covenant-macros = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } diff --git a/contracts/ibc-forwarder/src/contract.rs b/contracts/ibc-forwarder/src/contract.rs index dd59c65f..2e94dee7 100644 --- a/contracts/ibc-forwarder/src/contract.rs +++ b/contracts/ibc-forwarder/src/contract.rs @@ -7,7 +7,6 @@ use cosmwasm_std::{ ensure, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult, Uint128, }; -use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::{ ica::{ get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, @@ -26,6 +25,7 @@ use neutron_sdk::{ NeutronError, NeutronResult, }; use prost::Message; +use valence_clock::helpers::{enqueue_msg, verify_clock}; use crate::state::{IbcForwarderIcaStateHelper, FALLBACK_ADDRESS}; use crate::{error::ContractError, msg::FallbackAddressUpdateConfig}; @@ -38,7 +38,7 @@ use crate::{ }, }; -const CONTRACT_NAME: &str = "crates.io:covenant-ibc-forwarder"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const SUDO_PAYLOAD_REPLY_ID: u64 = 1; diff --git a/contracts/interchain-router/Cargo.toml b/contracts/interchain-router/Cargo.toml index 7faa4bdb..417935b3 100644 --- a/contracts/interchain-router/Cargo.toml +++ b/contracts/interchain-router/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-interchain-router" +name = "valence-interchain-router" edition = { workspace = true } authors = ["benskey bekauz@protonmail.com"] description = "Interchain router contract for covenants" @@ -21,7 +21,7 @@ library = [] [dependencies] covenant-macros = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } @@ -41,5 +41,5 @@ cw-utils = { workspace = true } [dev-dependencies] cw-multi-test = { workspace = true } anyhow = { workspace = true } -covenant-clock = { workspace = true } +valence-clock = { workspace = true } diff --git a/contracts/interchain-router/src/contract.rs b/contracts/interchain-router/src/contract.rs index bb6e0152..36e64b7a 100644 --- a/contracts/interchain-router/src/contract.rs +++ b/contracts/interchain-router/src/contract.rs @@ -6,7 +6,6 @@ use cosmwasm_std::{ to_json_binary, Attribute, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint128, }; -use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::{ neutron::{assert_ibc_fee_coverage, query_ibc_fee}, soft_validate_remote_chain_addr, @@ -17,6 +16,7 @@ use neutron_sdk::{ query::min_ibc_fee::MinIbcFeeResponse, NeutronError, NeutronResult, }; +use valence_clock::helpers::{enqueue_msg, verify_clock}; use crate::state::{DESTINATION_CONFIG, TARGET_DENOMS}; use crate::{ @@ -27,7 +27,7 @@ use crate::{ type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; type QueryDeps<'a> = Deps<'a, NeutronQuery>; -const CONTRACT_NAME: &str = "crates.io:covenant-interchain-router"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/interchain-router/src/suite_tests/mod.rs b/contracts/interchain-router/src/suite_tests/mod.rs index fa130dba..ca2e314c 100644 --- a/contracts/interchain-router/src/suite_tests/mod.rs +++ b/contracts/interchain-router/src/suite_tests/mod.rs @@ -1,11 +1,11 @@ pub mod suite; pub mod tests; -use covenant_clock::test_helpers::helpers::{ - mock_neutron_clock_execute, mock_neutron_clock_instantiate, mock_neutron_clock_query, -}; use cw_multi_test::{Contract, ContractWrapper}; use neutron_sdk::bindings::{msg::NeutronMsg, query::NeutronQuery}; +use valence_clock::test_helpers::helpers::{ + mock_neutron_clock_execute, mock_neutron_clock_instantiate, mock_neutron_clock_query, +}; pub fn mock_clock_neutron_deps_contract() -> Box> { let contract = ContractWrapper::new( diff --git a/contracts/interchain-router/src/suite_tests/suite.rs b/contracts/interchain-router/src/suite_tests/suite.rs index 96c31507..c651ee3d 100644 --- a/contracts/interchain-router/src/suite_tests/suite.rs +++ b/contracts/interchain-router/src/suite_tests/suite.rs @@ -99,7 +99,7 @@ impl SuiteBuilder { .instantiate_contract( clock_code, Addr::unchecked(ADMIN), - &covenant_clock::msg::InstantiateMsg { + &valence_clock::msg::InstantiateMsg { tick_max_gas: None, whitelist: vec![], }, diff --git a/contracts/native-router/Cargo.toml b/contracts/native-router/Cargo.toml index 112e5107..3a170f6a 100644 --- a/contracts/native-router/Cargo.toml +++ b/contracts/native-router/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-native-router" +name = "valence-native-router" edition = { workspace = true } authors = ["benskey bekauz@protonmail.com"] description = "Native router contract for covenants" @@ -20,7 +20,7 @@ library = [] [dependencies] covenant-macros = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } diff --git a/contracts/native-router/src/contract.rs b/contracts/native-router/src/contract.rs index a5c23b47..d89b5801 100644 --- a/contracts/native-router/src/contract.rs +++ b/contracts/native-router/src/contract.rs @@ -6,8 +6,8 @@ use cosmwasm_std::{ to_json_binary, Attribute, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, }; -use covenant_clock::helpers::{enqueue_msg, verify_clock}; use cw2::set_contract_version; +use valence_clock::helpers::{enqueue_msg, verify_clock}; use crate::{ error::ContractError, @@ -15,7 +15,7 @@ use crate::{ state::{CLOCK_ADDRESS, RECEIVER_ADDRESS, TARGET_DENOMS}, }; -const CONTRACT_NAME: &str = "crates.io:covenant-native-router"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/native-splitter/Cargo.toml b/contracts/native-splitter/Cargo.toml index eb39aacb..5d249f15 100644 --- a/contracts/native-splitter/Cargo.toml +++ b/contracts/native-splitter/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-native-splitter" +name = "valence-native-splitter" authors = ["benskey bekauz@protonmail.com"] description = "Native Splitter module for covenants" edition = { workspace = true } @@ -23,7 +23,7 @@ covenant-macros = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } covenant-utils = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } cw-storage-plus = { workspace = true } cw2 = { workspace = true } thiserror = { workspace = true } diff --git a/contracts/native-splitter/src/contract.rs b/contracts/native-splitter/src/contract.rs index 094f3048..bad59d62 100644 --- a/contracts/native-splitter/src/contract.rs +++ b/contracts/native-splitter/src/contract.rs @@ -6,15 +6,15 @@ use cosmwasm_std::{ ensure, to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Order, Response, StdError, StdResult, }; -use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::split::SplitConfig; use cw2::set_contract_version; +use valence_clock::helpers::{enqueue_msg, verify_clock}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use crate::state::{CLOCK_ADDRESS, FALLBACK_SPLIT, SPLIT_CONFIG_MAP}; -const CONTRACT_NAME: &str = "crates.io:covenant-native-splitter"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/osmo-liquid-pooler/Cargo.toml b/contracts/osmo-liquid-pooler/Cargo.toml index 91aea4f9..ec150c67 100644 --- a/contracts/osmo-liquid-pooler/Cargo.toml +++ b/contracts/osmo-liquid-pooler/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-osmo-liquid-pooler" +name = "valence-osmo-liquid-pooler" authors = ["benskey bekauz@protonmail.com"] description = "Osmosis liquid pooler contract for covenants" license = { workspace = true } @@ -21,7 +21,7 @@ library = [] [dependencies] covenant-macros = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } @@ -42,4 +42,4 @@ cw20 = { workspace = true } polytone = { workspace = true } osmosis-std = "0.20.1" prost = { workspace = true } -covenant-outpost-osmo-liquid-pooler = { workspace = true, features = ["library"] } +valence-outpost-osmo-liquid-pooler = { workspace = true, features = ["library"] } diff --git a/contracts/osmo-liquid-pooler/src/contract.rs b/contracts/osmo-liquid-pooler/src/contract.rs index dfc9b281..faa678c2 100644 --- a/contracts/osmo-liquid-pooler/src/contract.rs +++ b/contracts/osmo-liquid-pooler/src/contract.rs @@ -6,8 +6,6 @@ use cosmwasm_std::{ ensure, to_json_binary, to_json_string, Attribute, Binary, Coin, CosmosMsg, Decimal, Env, Fraction, IbcTimeout, MessageInfo, Response, StdResult, Uint128, WasmMsg, }; -use covenant_clock::helpers::{enqueue_msg, verify_clock}; -use covenant_outpost_osmo_liquid_pooler::msg::OutpostWithdrawLiquidityConfig; use covenant_utils::{ polytone::get_polytone_execute_msg_binary, withdraw_lp_helper::WithdrawLPMsgs, ForwardMetadata, PacketMetadata, @@ -23,6 +21,8 @@ use neutron_sdk::{ NeutronResult, }; use polytone::callbacks::CallbackRequest; +use valence_clock::helpers::{enqueue_msg, verify_clock}; +use valence_outpost_osmo_liquid_pooler::msg::OutpostWithdrawLiquidityConfig; use crate::{ error::ContractError, @@ -42,7 +42,7 @@ use crate::{ use crate::state::{CLOCK_ADDRESS, CONTRACT_STATE}; -const CONTRACT_NAME: &str = "crates.io:covenant-osmo-liquid-pooler"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub(crate) const PROVIDE_LIQUIDITY_CALLBACK_ID: u8 = 1; @@ -167,7 +167,7 @@ fn try_withdraw( let exit_pool_message: CosmosMsg = WasmMsg::Execute { contract_addr: lp_config.outpost.to_string(), msg: to_json_binary( - &covenant_outpost_osmo_liquid_pooler::msg::ExecuteMsg::WithdrawLiquidity { + &valence_outpost_osmo_liquid_pooler::msg::ExecuteMsg::WithdrawLiquidity { config: OutpostWithdrawLiquidityConfig { pool_id: lp_config.pool_id, }, diff --git a/contracts/osmo-liquid-pooler/src/msg.rs b/contracts/osmo-liquid-pooler/src/msg.rs index 0d425eff..47a41e73 100644 --- a/contracts/osmo-liquid-pooler/src/msg.rs +++ b/contracts/osmo-liquid-pooler/src/msg.rs @@ -8,13 +8,13 @@ use cosmwasm_std::{ use covenant_macros::{ clocked, covenant_clock_address, covenant_deposit_address, covenant_lper_withdraw, }; -use covenant_outpost_osmo_liquid_pooler::msg::OutpostProvideLiquidityConfig; use covenant_utils::{ instantiate2_helper::Instantiate2HelperConfig, ForwardMetadata, PoolPriceConfig, SingleSideLpLimits, }; use cw_utils::{Duration, Expiration}; use polytone::callbacks::CallbackMessage; +use valence_outpost_osmo_liquid_pooler::msg::OutpostProvideLiquidityConfig; #[cw_serde] pub struct InstantiateMsg { @@ -175,7 +175,7 @@ impl LiquidityProvisionConfig { Ok(WasmMsg::Execute { contract_addr: self.outpost.to_string(), msg: to_json_binary( - &covenant_outpost_osmo_liquid_pooler::msg::ExecuteMsg::ProvideLiquidity { + &valence_outpost_osmo_liquid_pooler::msg::ExecuteMsg::ProvideLiquidity { config: outpost_config, }, )?, diff --git a/contracts/outpost-osmo-liquid-pooler/Cargo.toml b/contracts/outpost-osmo-liquid-pooler/Cargo.toml index ffd61269..cc8dc6f2 100644 --- a/contracts/outpost-osmo-liquid-pooler/Cargo.toml +++ b/contracts/outpost-osmo-liquid-pooler/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-outpost-osmo-liquid-pooler" +name = "valence-outpost-osmo-liquid-pooler" authors = ["benskey bekauz@protonmail.com"] description = "Osmosis outpost for liquid pooler contract for covenants" license = { workspace = true } diff --git a/contracts/outpost-osmo-liquid-pooler/src/contract.rs b/contracts/outpost-osmo-liquid-pooler/src/contract.rs index 1336379c..ee995086 100644 --- a/contracts/outpost-osmo-liquid-pooler/src/contract.rs +++ b/contracts/outpost-osmo-liquid-pooler/src/contract.rs @@ -31,7 +31,7 @@ use osmosis_std::{ }, }; -const CONTRACT_NAME: &str = "crates.io:covenant-outpost-osmo-liquid-pooler"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); const OSMO_POOL_REPLY_ID: u64 = 1; diff --git a/contracts/remote-chain-splitter/Cargo.toml b/contracts/remote-chain-splitter/Cargo.toml index 1f91f694..31199a4d 100644 --- a/contracts/remote-chain-splitter/Cargo.toml +++ b/contracts/remote-chain-splitter/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-remote-chain-splitter" +name = "valence-remote-chain-splitter" authors = ["benskey bekauz@protonmail.com"] description = "contract to split funds on a remote chain" edition = { workspace = true } @@ -18,7 +18,7 @@ library = [] [dependencies] covenant-macros = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } covenant-utils = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } diff --git a/contracts/remote-chain-splitter/src/contract.rs b/contracts/remote-chain-splitter/src/contract.rs index 1950add3..fbe72dd7 100644 --- a/contracts/remote-chain-splitter/src/contract.rs +++ b/contracts/remote-chain-splitter/src/contract.rs @@ -10,7 +10,6 @@ use cosmwasm_std::{ ensure, to_json_binary, Attribute, Binary, Deps, DepsMut, Env, Fraction, MessageInfo, Reply, Response, StdError, StdResult, Uint128, }; -use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::ica::{ get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, sudo_error, sudo_open_ack, sudo_response, sudo_timeout, INTERCHAIN_ACCOUNT_ID, @@ -25,6 +24,7 @@ use neutron_sdk::interchain_txs::helpers::get_port_id; use neutron_sdk::query::min_ibc_fee::MinIbcFeeResponse; use neutron_sdk::sudo::msg::SudoMsg; use neutron_sdk::NeutronError; +use valence_clock::helpers::{enqueue_msg, verify_clock}; use crate::error::ContractError; use crate::msg::{ @@ -42,7 +42,7 @@ use neutron_sdk::{ type QueryDeps<'a> = Deps<'a, NeutronQuery>; type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>; -const CONTRACT_NAME: &str = "crates.io:covenant-remote-chain-splitter"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const SUDO_PAYLOAD_REPLY_ID: u64 = 1u64; diff --git a/contracts/single-party-pol-covenant/Cargo.toml b/contracts/single-party-pol-covenant/Cargo.toml index 70b691f4..369ef664 100644 --- a/contracts/single-party-pol-covenant/Cargo.toml +++ b/contracts/single-party-pol-covenant/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-single-party-pol" +name = "valence-covenant-single-party-pol" edition = { workspace = true } authors = ["benskey bekauz@protonmail.com", "Art3miX "] description = "Single Party POL covenant" @@ -34,13 +34,13 @@ serde-json-wasm = { workspace = true } prost = { workspace = true } prost-types = { workspace = true } bech32 = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } covenant-utils = { workspace = true } -covenant-ibc-forwarder = { workspace = true, features = ["library"] } -covenant-interchain-router = { workspace = true, features = ["library"] } -covenant-single-party-pol-holder = { workspace = true, features = ["library"] } -covenant-astroport-liquid-pooler = { workspace = true, features = ["library"] } -covenant-stride-liquid-staker = { workspace = true, features = ["library"] } -covenant-remote-chain-splitter = { workspace = true, features = ["library"] } -covenant-osmo-liquid-pooler = { workspace = true, features = ["library"] } +valence-ibc-forwarder = { workspace = true, features = ["library"] } +valence-interchain-router = { workspace = true, features = ["library"] } +valence-single-party-pol-holder = { workspace = true, features = ["library"] } +valence-astroport-liquid-pooler = { workspace = true, features = ["library"] } +valence-stride-liquid-staker = { workspace = true, features = ["library"] } +valence-remote-chain-splitter = { workspace = true, features = ["library"] } +valence-osmo-liquid-pooler = { workspace = true, features = ["library"] } astroport = { workspace = true } diff --git a/contracts/single-party-pol-covenant/src/contract.rs b/contracts/single-party-pol-covenant/src/contract.rs index f5c540a5..7107a340 100644 --- a/contracts/single-party-pol-covenant/src/contract.rs +++ b/contracts/single-party-pol-covenant/src/contract.rs @@ -6,14 +6,14 @@ use cosmwasm_std::{ to_json_binary, Addr, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Response, StdResult, WasmMsg, }; -use covenant_ibc_forwarder::msg::InstantiateMsg as IbcForwarderInstantiateMsg; -use covenant_interchain_router::msg::InstantiateMsg as RouterInstantiateMsg; -use covenant_remote_chain_splitter::msg::InstantiateMsg as SplitterInstantiateMsg; -use covenant_single_party_pol_holder::msg::InstantiateMsg as HolderInstantiateMsg; -use covenant_stride_liquid_staker::msg::InstantiateMsg as LiquidStakerInstantiateMsg; use covenant_utils::split::SplitConfig; use covenant_utils::{instantiate2_helper::get_instantiate2_salt_and_address, DestinationConfig}; use cw2::set_contract_version; +use valence_ibc_forwarder::msg::InstantiateMsg as IbcForwarderInstantiateMsg; +use valence_interchain_router::msg::InstantiateMsg as RouterInstantiateMsg; +use valence_remote_chain_splitter::msg::InstantiateMsg as SplitterInstantiateMsg; +use valence_single_party_pol_holder::msg::InstantiateMsg as HolderInstantiateMsg; +use valence_stride_liquid_staker::msg::InstantiateMsg as LiquidStakerInstantiateMsg; use crate::msg::LiquidPoolerMigrateMsg; use crate::{ @@ -25,7 +25,7 @@ use crate::{ }, }; -const CONTRACT_NAME: &str = "crates.io:covenant-single-party-pol"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub(crate) const CLOCK_SALT: &[u8] = b"clock"; @@ -251,7 +251,7 @@ pub fn instantiate( )?); }; - let clock_instantiate2_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate2_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: msg.clock_tick_max_gas, whitelist: clock_whitelist, } diff --git a/contracts/single-party-pol-covenant/src/msg.rs b/contracts/single-party-pol-covenant/src/msg.rs index 58aab751..f55451a9 100644 --- a/contracts/single-party-pol-covenant/src/msg.rs +++ b/contracts/single-party-pol-covenant/src/msg.rs @@ -2,14 +2,14 @@ use std::collections::BTreeMap; use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Addr, Binary, Decimal, StdResult, Uint128, Uint64, WasmMsg}; -use covenant_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; -use covenant_osmo_liquid_pooler::msg::OsmosisLiquidPoolerConfig; use covenant_utils::{ instantiate2_helper::Instantiate2HelperConfig, CovenantParty, DestinationConfig, InterchainCovenantParty, NativeCovenantParty, PacketForwardMiddlewareConfig, PoolPriceConfig, ReceiverConfig, }; use cw_utils::Expiration; +use valence_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; +use valence_osmo_liquid_pooler::msg::OsmosisLiquidPoolerConfig; pub const DEFAULT_TIMEOUT: u64 = 60 * 60 * 5; // 5 hours @@ -200,14 +200,14 @@ pub enum QueryMsg { pub enum MigrateMsg { MigrateContracts { codes: Option, - clock: Option, - holder: Option, - ls_forwarder: Option, - lp_forwarder: Option, - splitter: Option, + clock: Option, + holder: Option, + ls_forwarder: Option, + lp_forwarder: Option, + splitter: Option, liquid_pooler: Option, - liquid_staker: Option, - router: Option, + liquid_staker: Option, + router: Option, }, UpdateCodeId { data: Option, @@ -216,6 +216,6 @@ pub enum MigrateMsg { #[cw_serde] pub enum LiquidPoolerMigrateMsg { - Osmosis(covenant_osmo_liquid_pooler::msg::MigrateMsg), - Astroport(covenant_astroport_liquid_pooler::msg::MigrateMsg), + Osmosis(valence_osmo_liquid_pooler::msg::MigrateMsg), + Astroport(valence_astroport_liquid_pooler::msg::MigrateMsg), } diff --git a/contracts/single-party-pol-holder/Cargo.toml b/contracts/single-party-pol-holder/Cargo.toml index 2c6d3fa5..7ad725b7 100644 --- a/contracts/single-party-pol-holder/Cargo.toml +++ b/contracts/single-party-pol-holder/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-single-party-pol-holder" +name = "valence-single-party-pol-holder" authors = ["udit "] description = "A holder can hold funds in a covenant" edition = { workspace = true } diff --git a/contracts/single-party-pol-holder/src/contract.rs b/contracts/single-party-pol-holder/src/contract.rs index 94fbbdcc..d9999447 100644 --- a/contracts/single-party-pol-holder/src/contract.rs +++ b/contracts/single-party-pol-holder/src/contract.rs @@ -10,7 +10,7 @@ use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use crate::state::{LOCKUP_PERIOD, POOLER_ADDRESS, WITHDRAWER, WITHDRAW_STATE, WITHDRAW_TO}; -const CONTRACT_NAME: &str = "crates.io:covenant-holder"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/stride-liquid-staker/Cargo.toml b/contracts/stride-liquid-staker/Cargo.toml index f80f0171..2d8cc41f 100644 --- a/contracts/stride-liquid-staker/Cargo.toml +++ b/contracts/stride-liquid-staker/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-stride-liquid-staker" +name = "valence-stride-liquid-staker" authors = ["benskey bekauz@protonmail.com", "Art3mix "] description = "Liquid Staker module for stride covenant" edition = { workspace = true } @@ -18,7 +18,7 @@ library = [] [dependencies] covenant-macros = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } covenant-utils = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } diff --git a/contracts/stride-liquid-staker/examples/schema.rs b/contracts/stride-liquid-staker/examples/schema.rs index 7699f08b..0de5e9db 100644 --- a/contracts/stride-liquid-staker/examples/schema.rs +++ b/contracts/stride-liquid-staker/examples/schema.rs @@ -1,5 +1,5 @@ use cosmwasm_schema::write_api; -use covenant_stride_liquid_staker::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use valence_stride_liquid_staker::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; fn main() { write_api! { diff --git a/contracts/stride-liquid-staker/src/contract.rs b/contracts/stride-liquid-staker/src/contract.rs index ea93102d..5c6f7ba1 100644 --- a/contracts/stride-liquid-staker/src/contract.rs +++ b/contracts/stride-liquid-staker/src/contract.rs @@ -5,7 +5,6 @@ use cosmwasm_std::{ to_json_binary, to_json_string, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult, Uint128, }; -use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::ica::{ get_ica, msg_with_sudo_callback, prepare_sudo_payload, query_ica_registration_fee, sudo_error, sudo_open_ack, sudo_response, sudo_timeout, INTERCHAIN_ACCOUNT_ID, @@ -13,6 +12,7 @@ use covenant_utils::ica::{ use covenant_utils::neutron::{self, get_proto_coin, RemoteChainInfo, SudoPayload}; use cw2::set_contract_version; use neutron_sdk::query::min_ibc_fee::MinIbcFeeResponse; +use valence_clock::helpers::{enqueue_msg, verify_clock}; use crate::helpers::{Autopilot, AutopilotConfig}; use crate::msg::{ContractState, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; @@ -28,7 +28,7 @@ use neutron_sdk::{ NeutronError, NeutronResult, }; -const CONTRACT_NAME: &str = "crates.io:covenant-stride-liquid-staker"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); type QueryDeps<'a> = Deps<'a, NeutronQuery>; diff --git a/contracts/swap-covenant/Cargo.toml b/contracts/swap-covenant/Cargo.toml index e05c57fb..eefb2349 100644 --- a/contracts/swap-covenant/Cargo.toml +++ b/contracts/swap-covenant/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-swap" +name = "valence-covenant-swap" edition = { workspace = true } authors = ["benskey bekauz@protonmail.com"] description = "Swap covenant contract" @@ -36,10 +36,10 @@ serde-json-wasm = { workspace = true } prost = { workspace = true } prost-types = { workspace = true } bech32 = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } -covenant-swap-holder = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } +valence-swap-holder = { workspace = true, features = ["library"] } covenant-utils = { workspace = true } -covenant-native-splitter = { workspace = true, features = ["library"] } -covenant-ibc-forwarder = { workspace = true, features = ["library"] } -covenant-interchain-router = { workspace = true, features = ["library"] } -covenant-native-router = { workspace = true, features = ["library"] } +valence-native-splitter = { workspace = true, features = ["library"] } +valence-ibc-forwarder = { workspace = true, features = ["library"] } +valence-interchain-router = { workspace = true, features = ["library"] } +valence-native-router = { workspace = true, features = ["library"] } diff --git a/contracts/swap-covenant/src/contract.rs b/contracts/swap-covenant/src/contract.rs index e315d950..6df7a80d 100644 --- a/contracts/swap-covenant/src/contract.rs +++ b/contracts/swap-covenant/src/contract.rs @@ -6,12 +6,12 @@ use cosmwasm_std::{ ensure, to_json_binary, to_json_string, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, WasmMsg, }; -use covenant_swap_holder::msg::RefundConfig; use covenant_utils::{ instantiate2_helper::get_instantiate2_salt_and_address, split::remap_splits, CovenantPartiesConfig, CovenantTerms, SwapCovenantTerms, }; use cw2::set_contract_version; +use valence_swap_holder::msg::RefundConfig; use crate::{ error::ContractError, @@ -23,7 +23,7 @@ use crate::{ }, }; -const CONTRACT_NAME: &str = "crates.io:swap-covenant"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub(crate) const CLOCK_SALT: &[u8] = b"clock"; @@ -128,7 +128,7 @@ pub fn instantiate( ) ); - let splitter_instantiate2_msg = covenant_native_splitter::msg::InstantiateMsg { + let splitter_instantiate2_msg = valence_native_splitter::msg::InstantiateMsg { clock_address: clock_instantiate2_config.addr.to_string(), splits: remap_splits( msg.splits.clone(), @@ -157,7 +157,7 @@ pub fn instantiate( format!("{}_interchain_splitter", msg.label), )?; - let holder_instantiate2_msg = covenant_swap_holder::msg::InstantiateMsg { + let holder_instantiate2_msg = valence_swap_holder::msg::InstantiateMsg { lockup_config: msg.lockup_config, parties_config: CovenantPartiesConfig { party_a: msg.party_a_config.to_covenant_party(), @@ -205,7 +205,7 @@ pub fn instantiate( clock_whitelist.push(party_a_forwarder_instantiate2_config.addr.to_string()); // generate its instantiate2 message and add it to the list // of instantiation messages - let instantiate_msg = covenant_ibc_forwarder::msg::InstantiateMsg { + let instantiate_msg = valence_ibc_forwarder::msg::InstantiateMsg { remote_chain_connection_id: config.party_chain_connection_id.to_string(), remote_chain_channel_id: config.party_to_host_chain_channel_id.to_string(), denom: config.remote_chain_denom.to_string(), @@ -246,7 +246,7 @@ pub fn instantiate( clock_whitelist.push(party_b_forwarder_instantiate2_config.addr.to_string()); // generate its instantiate2 message and add it to the list // of instantiation messages - let instantiate_msg = covenant_ibc_forwarder::msg::InstantiateMsg { + let instantiate_msg = valence_ibc_forwarder::msg::InstantiateMsg { remote_chain_connection_id: config.party_chain_connection_id.to_string(), remote_chain_channel_id: config.party_to_host_chain_channel_id.to_string(), denom: config.remote_chain_denom.to_string(), @@ -272,7 +272,7 @@ pub fn instantiate( // include the clock in instantiation flow messages.insert( 0, - covenant_clock::msg::InstantiateMsg { + valence_clock::msg::InstantiateMsg { tick_max_gas: msg.clock_tick_max_gas, whitelist: clock_whitelist, } diff --git a/contracts/swap-covenant/src/msg.rs b/contracts/swap-covenant/src/msg.rs index d935e852..02e5a744 100644 --- a/contracts/swap-covenant/src/msg.rs +++ b/contracts/swap-covenant/src/msg.rs @@ -108,7 +108,7 @@ impl CovenantPartyConfig { ibc_transfer_timeout: party.ibc_transfer_timeout, denom_to_pfm_map: party.denom_to_pfm_map.clone(), }; - let instantiate_msg = covenant_interchain_router::msg::InstantiateMsg { + let instantiate_msg = valence_interchain_router::msg::InstantiateMsg { clock_address: clock_addr.to_string(), destination_config, denoms: covenant_denoms, @@ -116,7 +116,7 @@ impl CovenantPartyConfig { Ok(instantiate_msg.to_instantiate2_msg(&instantiate2_helper, admin, label)?) } CovenantPartyConfig::Native(party) => { - let instantiate_msg = covenant_native_router::msg::InstantiateMsg { + let instantiate_msg = valence_native_router::msg::InstantiateMsg { clock_address: clock_addr.to_string(), receiver_address: party.party_receiver_addr.to_string(), denoms: covenant_denoms, @@ -198,13 +198,13 @@ pub enum QueryMsg { pub enum MigrateMsg { UpdateCovenant { codes: Option, - clock: Option, - holder: Option, - splitter: Option, + clock: Option, + holder: Option, + splitter: Option, party_a_router: Option, party_b_router: Option, - party_a_forwarder: Box>, - party_b_forwarder: Box>, + party_a_forwarder: Box>, + party_b_forwarder: Box>, }, UpdateCodeId { data: Option, @@ -213,8 +213,8 @@ pub enum MigrateMsg { #[cw_serde] pub enum RouterMigrateMsg { - Interchain(covenant_interchain_router::msg::MigrateMsg), - Native(covenant_native_router::msg::MigrateMsg), + Interchain(valence_interchain_router::msg::MigrateMsg), + Native(valence_native_router::msg::MigrateMsg), } #[cw_serde] diff --git a/contracts/swap-holder/Cargo.toml b/contracts/swap-holder/Cargo.toml index 109d7d68..c90fd26f 100644 --- a/contracts/swap-holder/Cargo.toml +++ b/contracts/swap-holder/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-swap-holder" +name = "valence-swap-holder" authors = ["benskey bekauz@protonmail.com"] description = "covenant contract to facilitate a tokenswap" edition = { workspace = true } @@ -21,7 +21,7 @@ cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } cw-utils = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } cw2 = { workspace = true } serde = { workspace = true } thiserror = { workspace = true } diff --git a/contracts/swap-holder/src/contract.rs b/contracts/swap-holder/src/contract.rs index db184213..df25bf14 100644 --- a/contracts/swap-holder/src/contract.rs +++ b/contracts/swap-holder/src/contract.rs @@ -14,10 +14,10 @@ use crate::{ }; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use covenant_clock::helpers::{enqueue_msg, verify_clock}; use cw2::set_contract_version; +use valence_clock::helpers::{enqueue_msg, verify_clock}; -const CONTRACT_NAME: &str = "crates.io:covenant-swap-holder"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/swap-holder/src/msg.rs b/contracts/swap-holder/src/msg.rs index a98b410c..7ad2313d 100644 --- a/contracts/swap-holder/src/msg.rs +++ b/contracts/swap-holder/src/msg.rs @@ -2,12 +2,12 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{ to_json_binary, Addr, Attribute, Binary, DepsMut, StdError, StdResult, WasmMsg, }; -use covenant_clock::helpers::dequeue_msg; use covenant_macros::{clocked, covenant_clock_address, covenant_deposit_address}; use covenant_utils::{ instantiate2_helper::Instantiate2HelperConfig, CovenantPartiesConfig, CovenantTerms, }; use cw_utils::Expiration; +use valence_clock::helpers::dequeue_msg; use crate::state::CONTRACT_STATE; diff --git a/contracts/two-party-pol-covenant/Cargo.toml b/contracts/two-party-pol-covenant/Cargo.toml index ef13cc76..0e204d6b 100644 --- a/contracts/two-party-pol-covenant/Cargo.toml +++ b/contracts/two-party-pol-covenant/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-two-party-pol" +name = "valence-covenant-two-party-pol" edition = { workspace = true } authors = ["benskey bekauz@protonmail.com"] description = "Two Party POL covenant" @@ -36,12 +36,12 @@ serde-json-wasm = { workspace = true } prost = { workspace = true } prost-types = { workspace = true } bech32 = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } covenant-utils = { workspace = true } -covenant-ibc-forwarder = { workspace = true, features = ["library"] } -covenant-interchain-router = { workspace = true, features = ["library"] } -covenant-native-router = { workspace = true, features = ["library"] } -covenant-two-party-pol-holder = { workspace = true, features = ["library"] } -covenant-astroport-liquid-pooler = { workspace = true, features = ["library"] } -covenant-osmo-liquid-pooler = { workspace = true, features = ["library"] } +valence-ibc-forwarder = { workspace = true, features = ["library"] } +valence-interchain-router = { workspace = true, features = ["library"] } +valence-native-router = { workspace = true, features = ["library"] } +valence-two-party-pol-holder = { workspace = true, features = ["library"] } +valence-astroport-liquid-pooler = { workspace = true, features = ["library"] } +valence-osmo-liquid-pooler = { workspace = true, features = ["library"] } astroport = { workspace = true } diff --git a/contracts/two-party-pol-covenant/src/contract.rs b/contracts/two-party-pol-covenant/src/contract.rs index 9d3c6e55..ac0e024c 100644 --- a/contracts/two-party-pol-covenant/src/contract.rs +++ b/contracts/two-party-pol-covenant/src/contract.rs @@ -6,10 +6,10 @@ use cosmwasm_std::{ to_json_binary, Binary, CanonicalAddr, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, WasmMsg, }; -use covenant_ibc_forwarder::msg::InstantiateMsg as IbcForwarderInstantiateMsg; -use covenant_two_party_pol_holder::msg::{RagequitConfig, TwoPartyPolCovenantConfig}; use covenant_utils::{instantiate2_helper::get_instantiate2_salt_and_address, split::remap_splits}; use cw2::set_contract_version; +use valence_ibc_forwarder::msg::InstantiateMsg as IbcForwarderInstantiateMsg; +use valence_two_party_pol_holder::msg::{RagequitConfig, TwoPartyPolCovenantConfig}; use crate::{ error::ContractError, @@ -24,7 +24,7 @@ use crate::{ }, }; -const CONTRACT_NAME: &str = "crates.io:covenant-two-party-pol"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const CLOCK_SALT: &[u8] = b"clock"; @@ -86,7 +86,7 @@ pub fn instantiate( clock_whitelist.push(party_b_router_instantiate2_config.addr.to_string()); clock_whitelist.push(liquid_pooler_instantiate2_config.addr.to_string()); - let holder_instantiate2_msg = covenant_two_party_pol_holder::msg::InstantiateMsg { + let holder_instantiate2_msg = valence_two_party_pol_holder::msg::InstantiateMsg { clock_address: clock_instantiate2_config.addr.to_string(), lockup_config: msg.lockup_config, next_contract: liquid_pooler_instantiate2_config.addr.to_string(), @@ -229,7 +229,7 @@ pub fn instantiate( ); } - let clock_instantiate2_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate2_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: msg.clock_tick_max_gas, whitelist: clock_whitelist, } diff --git a/contracts/two-party-pol-covenant/src/msg.rs b/contracts/two-party-pol-covenant/src/msg.rs index 1302cf6d..e72d3269 100644 --- a/contracts/two-party-pol-covenant/src/msg.rs +++ b/contracts/two-party-pol-covenant/src/msg.rs @@ -2,15 +2,15 @@ use std::collections::{BTreeMap, BTreeSet}; use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{coin, Addr, Binary, Decimal, StdResult, Uint64, WasmMsg}; -use covenant_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; -use covenant_osmo_liquid_pooler::msg::OsmosisLiquidPoolerConfig; -use covenant_two_party_pol_holder::msg::{CovenantType, RagequitConfig, TwoPartyPolCovenantParty}; use covenant_utils::{ instantiate2_helper::Instantiate2HelperConfig, split::SplitConfig, CovenantParty, DestinationConfig, InterchainCovenantParty, NativeCovenantParty, PoolPriceConfig, ReceiverConfig, }; use cw_utils::Expiration; +use valence_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; +use valence_osmo_liquid_pooler::msg::OsmosisLiquidPoolerConfig; +use valence_two_party_pol_holder::msg::{CovenantType, RagequitConfig, TwoPartyPolCovenantParty}; pub const DEFAULT_TIMEOUT: u64 = 60 * 60 * 5; // 5 hours @@ -160,7 +160,7 @@ impl CovenantPartyConfig { ) -> StdResult { match self { CovenantPartyConfig::Interchain(party) => { - let instantiate_msg = covenant_interchain_router::msg::InstantiateMsg { + let instantiate_msg = valence_interchain_router::msg::InstantiateMsg { clock_address: clock_addr.to_string(), destination_config: DestinationConfig { local_to_destination_chain_channel_id: party @@ -175,7 +175,7 @@ impl CovenantPartyConfig { Ok(instantiate_msg.to_instantiate2_msg(&instantiate2_helper, admin_addr, label)?) } CovenantPartyConfig::Native(party) => { - let instantiate_msg = covenant_native_router::msg::InstantiateMsg { + let instantiate_msg = valence_native_router::msg::InstantiateMsg { clock_address: clock_addr.to_string(), receiver_address: party.party_receiver_addr.to_string(), denoms, @@ -275,13 +275,13 @@ pub enum QueryMsg { pub enum MigrateMsg { UpdateCovenant { codes: Option, - clock: Option, - holder: Option, + clock: Option, + holder: Option, liquid_pooler: Option, party_a_router: Option, party_b_router: Option, - party_a_forwarder: Option, - party_b_forwarder: Option, + party_a_forwarder: Option, + party_b_forwarder: Option, }, UpdateCodeId { data: Option, @@ -290,12 +290,12 @@ pub enum MigrateMsg { #[cw_serde] pub enum LiquidPoolerMigrateMsg { - Osmosis(covenant_osmo_liquid_pooler::msg::MigrateMsg), - Astroport(covenant_astroport_liquid_pooler::msg::MigrateMsg), + Osmosis(valence_osmo_liquid_pooler::msg::MigrateMsg), + Astroport(valence_astroport_liquid_pooler::msg::MigrateMsg), } #[cw_serde] pub enum RouterMigrateMsg { - Interchain(covenant_interchain_router::msg::MigrateMsg), - Native(covenant_native_router::msg::MigrateMsg), + Interchain(valence_interchain_router::msg::MigrateMsg), + Native(valence_native_router::msg::MigrateMsg), } diff --git a/contracts/two-party-pol-holder/Cargo.toml b/contracts/two-party-pol-holder/Cargo.toml index a97f47a8..3b608787 100644 --- a/contracts/two-party-pol-holder/Cargo.toml +++ b/contracts/two-party-pol-holder/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "covenant-two-party-pol-holder" +name = "valence-two-party-pol-holder" authors = ["benskey bekauz@protonmail.com"] description = "Two party POL holder module for covenants" edition = { workspace = true } @@ -21,7 +21,7 @@ covenant-macros = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } -covenant-clock = { workspace = true, features = ["library"] } +valence-clock = { workspace = true, features = ["library"] } cw2 = { workspace = true } thiserror = { workspace = true } schemars = { workspace = true } diff --git a/contracts/two-party-pol-holder/src/contract.rs b/contracts/two-party-pol-holder/src/contract.rs index 89c1c8fe..91ab2f28 100644 --- a/contracts/two-party-pol-holder/src/contract.rs +++ b/contracts/two-party-pol-holder/src/contract.rs @@ -9,10 +9,10 @@ use cosmwasm_std::{ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use covenant_clock::helpers::{enqueue_msg, verify_clock}; use covenant_utils::split::SplitConfig; use covenant_utils::withdraw_lp_helper::{generate_withdraw_msg, EMERGENCY_COMMITTEE_ADDR}; use cw2::set_contract_version; +use valence_clock::helpers::{enqueue_msg, verify_clock}; use crate::msg::CovenantType; use crate::state::{WithdrawState, LIQUID_POOLER_ADDRESS, WITHDRAW_STATE}; @@ -28,7 +28,7 @@ use crate::{ }, }; -const CONTRACT_NAME: &str = "crates.io:covenant-two-party-pol-holder"; +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/two-party-pol-holder/src/msg.rs b/contracts/two-party-pol-holder/src/msg.rs index 9b4053d3..d09f066f 100644 --- a/contracts/two-party-pol-holder/src/msg.rs +++ b/contracts/two-party-pol-holder/src/msg.rs @@ -5,13 +5,13 @@ use cosmwasm_std::{ ensure, to_json_binary, Addr, Api, Attribute, Binary, Coin, CosmosMsg, Decimal, DepsMut, StdError, StdResult, WasmMsg, }; -use covenant_clock::helpers::dequeue_msg; use covenant_macros::{ clocked, covenant_clock_address, covenant_deposit_address, covenant_holder_distribute, covenant_holder_emergency_withdraw, covenant_next_contract, }; use covenant_utils::{instantiate2_helper::Instantiate2HelperConfig, split::SplitConfig}; use cw_utils::Expiration; +use valence_clock::helpers::dequeue_msg; use crate::{error::ContractError, state::CONTRACT_STATE}; diff --git a/unit-tests/Cargo.toml b/unit-tests/Cargo.toml index b780dfb4..bb4d53dd 100644 --- a/unit-tests/Cargo.toml +++ b/unit-tests/Cargo.toml @@ -18,22 +18,22 @@ colored = "1.9.4" const_format = "0.2.32" cosmos-sdk-proto = { workspace = true } -covenant-remote-chain-splitter = { workspace = true } -covenant-ibc-forwarder = { workspace = true } -covenant-clock = { workspace = true } -covenant-stride-liquid-staker = { workspace = true } -covenant-native-splitter = { workspace = true } -covenant-swap-holder = { workspace = true } -covenant-swap = { workspace = true } -covenant-interchain-router = { workspace = true } -covenant-two-party-pol-holder = { workspace = true } -covenant-two-party-pol = { workspace = true } -covenant-astroport-liquid-pooler = { workspace = true } -covenant-native-router = { workspace = true } -covenant-outpost-osmo-liquid-pooler = { workspace = true } -covenant-single-party-pol = { workspace = true } -covenant-single-party-pol-holder = { workspace = true } -covenant-osmo-liquid-pooler = { workspace = true } +valence-remote-chain-splitter = { workspace = true } +valence-ibc-forwarder = { workspace = true } +valence-clock = { workspace = true } +valence-stride-liquid-staker = { workspace = true } +valence-native-splitter = { workspace = true } +valence-swap-holder = { workspace = true } +valence-covenant-swap = { workspace = true } +valence-interchain-router = { workspace = true } +valence-two-party-pol-holder = { workspace = true } +valence-covenant-two-party-pol = { workspace = true } +valence-astroport-liquid-pooler = { workspace = true } +valence-native-router = { workspace = true } +valence-outpost-osmo-liquid-pooler = { workspace = true } +valence-covenant-single-party-pol = { workspace = true } +valence-single-party-pol-holder = { workspace = true } +valence-osmo-liquid-pooler = { workspace = true } covenant-utils = { workspace = true } diff --git a/unit-tests/src/setup/base_suite.rs b/unit-tests/src/setup/base_suite.rs index 2c606c1d..ab005ad8 100644 --- a/unit-tests/src/setup/base_suite.rs +++ b/unit-tests/src/setup/base_suite.rs @@ -16,7 +16,7 @@ pub trait BaseSuiteMut { .execute_contract( app.api().addr_make(ADMIN), clock_addr, - &covenant_clock::msg::ExecuteMsg::Tick {}, + &valence_clock::msg::ExecuteMsg::Tick {}, &[], ) .unwrap(); @@ -33,7 +33,7 @@ pub trait BaseSuiteMut { .execute_contract( app.api().addr_make(ADMIN), clock_addr, - &covenant_clock::msg::ExecuteMsg::Tick {}, + &valence_clock::msg::ExecuteMsg::Tick {}, &[], ) .unwrap(); @@ -47,7 +47,7 @@ pub trait BaseSuiteMut { app.execute_contract( clock_addr, contract, - &covenant_clock::msg::ExecuteMsg::Tick {}, + &valence_clock::msg::ExecuteMsg::Tick {}, &[], ) .unwrap() diff --git a/unit-tests/src/setup/contracts.rs b/unit-tests/src/setup/contracts.rs index 34fc1bf5..beed17e0 100644 --- a/unit-tests/src/setup/contracts.rs +++ b/unit-tests/src/setup/contracts.rs @@ -70,8 +70,8 @@ pub fn clock_contract() -> Box> { let exec = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_clock::msg::ExecuteMsg| { - execute_into_neutron(covenant_clock::contract::execute( + msg: valence_clock::msg::ExecuteMsg| { + execute_into_neutron(valence_clock::contract::execute( get_empty_depsmut(deps), env, info, @@ -82,8 +82,8 @@ pub fn clock_contract() -> Box> { let init = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_clock::msg::InstantiateMsg| { - execute_into_neutron(covenant_clock::contract::instantiate( + msg: valence_clock::msg::InstantiateMsg| { + execute_into_neutron(valence_clock::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -91,12 +91,12 @@ pub fn clock_contract() -> Box> { )) }; - let query = |deps: Deps, env: Env, msg: covenant_clock::msg::QueryMsg| { - covenant_clock::contract::query(get_empty_deps(deps), env, msg) + let query = |deps: Deps, env: Env, msg: valence_clock::msg::QueryMsg| { + valence_clock::contract::query(get_empty_deps(deps), env, msg) }; - let migrate = |deps: DepsMut, env: Env, msg: covenant_clock::msg::MigrateMsg| { - execute_into_neutron(covenant_clock::contract::migrate( + let migrate = |deps: DepsMut, env: Env, msg: valence_clock::msg::MigrateMsg| { + execute_into_neutron(valence_clock::contract::migrate( get_empty_depsmut(deps), env, msg, @@ -104,7 +104,7 @@ pub fn clock_contract() -> Box> { }; let reply = |deps: DepsMut, env: Env, reply: Reply| { - execute_into_neutron(covenant_clock::contract::reply( + execute_into_neutron(valence_clock::contract::reply( get_empty_depsmut(deps), env, reply, @@ -119,35 +119,35 @@ pub fn clock_contract() -> Box> { pub fn ibc_forwarder_contract() -> Box> { let contract = ContractWrapper::new( - covenant_ibc_forwarder::contract::execute, - covenant_ibc_forwarder::contract::instantiate, - covenant_ibc_forwarder::contract::query, + valence_ibc_forwarder::contract::execute, + valence_ibc_forwarder::contract::instantiate, + valence_ibc_forwarder::contract::query, ) - .with_reply(covenant_ibc_forwarder::contract::reply) - .with_sudo(covenant_ibc_forwarder::contract::sudo) - .with_migrate(covenant_ibc_forwarder::contract::migrate); + .with_reply(valence_ibc_forwarder::contract::reply) + .with_sudo(valence_ibc_forwarder::contract::sudo) + .with_migrate(valence_ibc_forwarder::contract::migrate); Box::new(contract) } pub fn interchain_router_contract() -> Box> { let contract = ContractWrapper::new( - covenant_interchain_router::contract::execute, - covenant_interchain_router::contract::instantiate, - covenant_interchain_router::contract::query, + valence_interchain_router::contract::execute, + valence_interchain_router::contract::instantiate, + valence_interchain_router::contract::query, ) - .with_migrate(covenant_interchain_router::contract::migrate); + .with_migrate(valence_interchain_router::contract::migrate); Box::new(contract) } pub fn remote_splitter_contract() -> Box> { let contract = ContractWrapper::new( - covenant_remote_chain_splitter::contract::execute, - covenant_remote_chain_splitter::contract::instantiate, - covenant_remote_chain_splitter::contract::query, + valence_remote_chain_splitter::contract::execute, + valence_remote_chain_splitter::contract::instantiate, + valence_remote_chain_splitter::contract::query, ) - .with_reply(covenant_remote_chain_splitter::contract::reply) - .with_sudo(covenant_remote_chain_splitter::contract::sudo) - .with_migrate(covenant_remote_chain_splitter::contract::migrate); + .with_reply(valence_remote_chain_splitter::contract::reply) + .with_sudo(valence_remote_chain_splitter::contract::sudo) + .with_migrate(valence_remote_chain_splitter::contract::migrate); Box::new(contract) } @@ -155,8 +155,8 @@ pub fn osmo_lp_outpost_contract() -> Box> let exec = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_outpost_osmo_liquid_pooler::msg::ExecuteMsg| { - execute_into_neutron(covenant_outpost_osmo_liquid_pooler::contract::execute( + msg: valence_outpost_osmo_liquid_pooler::msg::ExecuteMsg| { + execute_into_neutron(valence_outpost_osmo_liquid_pooler::contract::execute( get_empty_depsmut(deps), env, info, @@ -167,8 +167,8 @@ pub fn osmo_lp_outpost_contract() -> Box> let init = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_outpost_osmo_liquid_pooler::msg::InstantiateMsg| { - execute_into_neutron(covenant_outpost_osmo_liquid_pooler::contract::instantiate( + msg: valence_outpost_osmo_liquid_pooler::msg::InstantiateMsg| { + execute_into_neutron(valence_outpost_osmo_liquid_pooler::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -177,7 +177,7 @@ pub fn osmo_lp_outpost_contract() -> Box> }; let reply = |deps: DepsMut, env: Env, reply: Reply| { - execute_into_neutron(covenant_outpost_osmo_liquid_pooler::contract::reply( + execute_into_neutron(valence_outpost_osmo_liquid_pooler::contract::reply( get_empty_depsmut(deps), env, reply, @@ -186,8 +186,8 @@ pub fn osmo_lp_outpost_contract() -> Box> let query = |deps: Deps, env: Env, - msg: covenant_outpost_osmo_liquid_pooler::msg::QueryMsg| { - covenant_outpost_osmo_liquid_pooler::contract::query(get_empty_deps(deps), env, msg) + msg: valence_outpost_osmo_liquid_pooler::msg::QueryMsg| { + valence_outpost_osmo_liquid_pooler::contract::query(get_empty_deps(deps), env, msg) }; Box::new(ContractWrapper::new(exec, init, query).with_reply(reply)) @@ -197,8 +197,8 @@ pub fn native_router_contract() -> Box> { let exec = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_native_router::msg::ExecuteMsg| { - execute_into_neutron(covenant_native_router::contract::execute( + msg: valence_native_router::msg::ExecuteMsg| { + execute_into_neutron(valence_native_router::contract::execute( get_empty_depsmut(deps), env, info, @@ -209,8 +209,8 @@ pub fn native_router_contract() -> Box> { let init = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_native_router::msg::InstantiateMsg| { - execute_into_neutron(covenant_native_router::contract::instantiate( + msg: valence_native_router::msg::InstantiateMsg| { + execute_into_neutron(valence_native_router::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -218,13 +218,13 @@ pub fn native_router_contract() -> Box> { )) }; - let query = |deps: Deps, env: Env, msg: covenant_native_router::msg::QueryMsg| { - covenant_native_router::contract::query(get_empty_deps(deps), env, msg) + let query = |deps: Deps, env: Env, msg: valence_native_router::msg::QueryMsg| { + valence_native_router::contract::query(get_empty_deps(deps), env, msg) }; let migrate = - |deps: DepsMut, env: Env, msg: covenant_native_router::msg::MigrateMsg| { - execute_into_neutron(covenant_native_router::contract::migrate( + |deps: DepsMut, env: Env, msg: valence_native_router::msg::MigrateMsg| { + execute_into_neutron(valence_native_router::contract::migrate( get_empty_depsmut(deps), env, msg, @@ -239,8 +239,8 @@ pub fn native_splitter_contract() -> Box> let exec = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_native_splitter::msg::ExecuteMsg| { - execute_into_neutron(covenant_native_splitter::contract::execute( + msg: valence_native_splitter::msg::ExecuteMsg| { + execute_into_neutron(valence_native_splitter::contract::execute( get_empty_depsmut(deps), env, info, @@ -251,8 +251,8 @@ pub fn native_splitter_contract() -> Box> let init = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_native_splitter::msg::InstantiateMsg| { - execute_into_neutron(covenant_native_splitter::contract::instantiate( + msg: valence_native_splitter::msg::InstantiateMsg| { + execute_into_neutron(valence_native_splitter::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -261,13 +261,13 @@ pub fn native_splitter_contract() -> Box> }; let query = - |deps: Deps, env: Env, msg: covenant_native_splitter::msg::QueryMsg| { - covenant_native_splitter::contract::query(get_empty_deps(deps), env, msg) + |deps: Deps, env: Env, msg: valence_native_splitter::msg::QueryMsg| { + valence_native_splitter::contract::query(get_empty_deps(deps), env, msg) }; let migrate = - |deps: DepsMut, env: Env, msg: covenant_native_splitter::msg::MigrateMsg| { - execute_into_neutron(covenant_native_splitter::contract::migrate( + |deps: DepsMut, env: Env, msg: valence_native_splitter::msg::MigrateMsg| { + execute_into_neutron(valence_native_splitter::contract::migrate( get_empty_depsmut(deps), env, msg, @@ -290,8 +290,8 @@ pub fn single_party_covenant_contract() -> Box, env: Env, info: MessageInfo, - msg: covenant_single_party_pol::msg::InstantiateMsg| { - execute_into_neutron(covenant_single_party_pol::contract::instantiate( + msg: valence_covenant_single_party_pol::msg::InstantiateMsg| { + execute_into_neutron(valence_covenant_single_party_pol::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -299,19 +299,21 @@ pub fn single_party_covenant_contract() -> Box, env: Env, msg: covenant_single_party_pol::msg::QueryMsg| { - covenant_single_party_pol::contract::query(get_empty_deps(deps), env, msg) - }; + let query = |deps: Deps, + env: Env, + msg: valence_covenant_single_party_pol::msg::QueryMsg| { + valence_covenant_single_party_pol::contract::query(get_empty_deps(deps), env, msg) + }; - let migrate = - |deps: DepsMut, env: Env, msg: covenant_single_party_pol::msg::MigrateMsg| { - execute_into_neutron(covenant_single_party_pol::contract::migrate( - get_empty_depsmut(deps), - env, - msg, - )) - }; + let migrate = |deps: DepsMut, + env: Env, + msg: valence_covenant_single_party_pol::msg::MigrateMsg| { + execute_into_neutron(valence_covenant_single_party_pol::contract::migrate( + get_empty_depsmut(deps), + env, + msg, + )) + }; let contract = ContractWrapper::new(exec, init, query).with_migrate(migrate); Box::new(contract) @@ -321,8 +323,8 @@ pub fn single_party_holder_contract() -> Box, env: Env, info: MessageInfo, - msg: covenant_single_party_pol_holder::msg::ExecuteMsg| { - execute_into_neutron(covenant_single_party_pol_holder::contract::execute( + msg: valence_single_party_pol_holder::msg::ExecuteMsg| { + execute_into_neutron(valence_single_party_pol_holder::contract::execute( get_empty_depsmut(deps), env, info, @@ -333,8 +335,8 @@ pub fn single_party_holder_contract() -> Box, env: Env, info: MessageInfo, - msg: covenant_single_party_pol_holder::msg::InstantiateMsg| { - execute_into_neutron(covenant_single_party_pol_holder::contract::instantiate( + msg: valence_single_party_pol_holder::msg::InstantiateMsg| { + execute_into_neutron(valence_single_party_pol_holder::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -344,14 +346,14 @@ pub fn single_party_holder_contract() -> Box, env: Env, - msg: covenant_single_party_pol_holder::msg::QueryMsg| { - covenant_single_party_pol_holder::contract::query(get_empty_deps(deps), env, msg) + msg: valence_single_party_pol_holder::msg::QueryMsg| { + valence_single_party_pol_holder::contract::query(get_empty_deps(deps), env, msg) }; let migrate = |deps: DepsMut, env: Env, - msg: covenant_single_party_pol_holder::msg::MigrateMsg| { - execute_into_neutron(covenant_single_party_pol_holder::contract::migrate( + msg: valence_single_party_pol_holder::msg::MigrateMsg| { + execute_into_neutron(valence_single_party_pol_holder::contract::migrate( get_empty_depsmut(deps), env, msg, @@ -364,13 +366,13 @@ pub fn single_party_holder_contract() -> Box Box> { let contract = ContractWrapper::new( - covenant_stride_liquid_staker::contract::execute, - covenant_stride_liquid_staker::contract::instantiate, - covenant_stride_liquid_staker::contract::query, + valence_stride_liquid_staker::contract::execute, + valence_stride_liquid_staker::contract::instantiate, + valence_stride_liquid_staker::contract::query, ) - .with_reply(covenant_stride_liquid_staker::contract::reply) - .with_sudo(covenant_stride_liquid_staker::contract::sudo) - .with_migrate(covenant_stride_liquid_staker::contract::migrate); + .with_reply(valence_stride_liquid_staker::contract::reply) + .with_sudo(valence_stride_liquid_staker::contract::sudo) + .with_migrate(valence_stride_liquid_staker::contract::migrate); Box::new(contract) } @@ -386,8 +388,8 @@ pub fn swap_covenant_contract() -> Box> { let init = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_swap::msg::InstantiateMsg| { - execute_into_neutron(covenant_swap::contract::instantiate( + msg: valence_covenant_swap::msg::InstantiateMsg| { + execute_into_neutron(valence_covenant_swap::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -395,17 +397,18 @@ pub fn swap_covenant_contract() -> Box> { )) }; - let query = |deps: Deps, env: Env, msg: covenant_swap::msg::QueryMsg| { - covenant_swap::contract::query(get_empty_deps(deps), env, msg) + let query = |deps: Deps, env: Env, msg: valence_covenant_swap::msg::QueryMsg| { + valence_covenant_swap::contract::query(get_empty_deps(deps), env, msg) }; - let migrate = |deps: DepsMut, env: Env, msg: covenant_swap::msg::MigrateMsg| { - execute_into_neutron(covenant_swap::contract::migrate( - get_empty_depsmut(deps), - env, - msg, - )) - }; + let migrate = + |deps: DepsMut, env: Env, msg: valence_covenant_swap::msg::MigrateMsg| { + execute_into_neutron(valence_covenant_swap::contract::migrate( + get_empty_depsmut(deps), + env, + msg, + )) + }; let contract = ContractWrapper::new(exec, init, query).with_migrate(migrate); Box::new(contract) @@ -415,8 +418,8 @@ pub fn swap_holder_contract() -> Box> { let exec = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_swap_holder::msg::ExecuteMsg| { - execute_into_neutron(covenant_swap_holder::contract::execute( + msg: valence_swap_holder::msg::ExecuteMsg| { + execute_into_neutron(valence_swap_holder::contract::execute( get_empty_depsmut(deps), env, info, @@ -427,8 +430,8 @@ pub fn swap_holder_contract() -> Box> { let init = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_swap_holder::msg::InstantiateMsg| { - execute_into_neutron(covenant_swap_holder::contract::instantiate( + msg: valence_swap_holder::msg::InstantiateMsg| { + execute_into_neutron(valence_swap_holder::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -436,13 +439,13 @@ pub fn swap_holder_contract() -> Box> { )) }; - let query = |deps: Deps, env: Env, msg: covenant_swap_holder::msg::QueryMsg| { - covenant_swap_holder::contract::query(get_empty_deps(deps), env, msg) + let query = |deps: Deps, env: Env, msg: valence_swap_holder::msg::QueryMsg| { + valence_swap_holder::contract::query(get_empty_deps(deps), env, msg) }; let migrate = - |deps: DepsMut, env: Env, msg: covenant_swap_holder::msg::MigrateMsg| { - execute_into_neutron(covenant_swap_holder::contract::migrate( + |deps: DepsMut, env: Env, msg: valence_swap_holder::msg::MigrateMsg| { + execute_into_neutron(valence_swap_holder::contract::migrate( get_empty_depsmut(deps), env, msg, @@ -465,8 +468,8 @@ pub fn two_party_covenant_contract() -> Box, env: Env, info: MessageInfo, - msg: covenant_two_party_pol::msg::InstantiateMsg| { - execute_into_neutron(covenant_two_party_pol::contract::instantiate( + msg: valence_covenant_two_party_pol::msg::InstantiateMsg| { + execute_into_neutron(valence_covenant_two_party_pol::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -474,19 +477,21 @@ pub fn two_party_covenant_contract() -> Box, env: Env, msg: covenant_two_party_pol::msg::QueryMsg| { - covenant_two_party_pol::contract::query(get_empty_deps(deps), env, msg) - }; - - let migrate = - |deps: DepsMut, env: Env, msg: covenant_two_party_pol::msg::MigrateMsg| { - execute_into_neutron(covenant_two_party_pol::contract::migrate( - get_empty_depsmut(deps), - env, - msg, - )) + let query = + |deps: Deps, env: Env, msg: valence_covenant_two_party_pol::msg::QueryMsg| { + valence_covenant_two_party_pol::contract::query(get_empty_deps(deps), env, msg) }; + let migrate = |deps: DepsMut, + env: Env, + msg: valence_covenant_two_party_pol::msg::MigrateMsg| { + execute_into_neutron(valence_covenant_two_party_pol::contract::migrate( + get_empty_depsmut(deps), + env, + msg, + )) + }; + let contract = ContractWrapper::new(exec, init, query).with_migrate(migrate); Box::new(contract) } @@ -495,8 +500,8 @@ pub fn two_party_holder_contract() -> Box let exec = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_two_party_pol_holder::msg::ExecuteMsg| { - execute_into_neutron(covenant_two_party_pol_holder::contract::execute( + msg: valence_two_party_pol_holder::msg::ExecuteMsg| { + execute_into_neutron(valence_two_party_pol_holder::contract::execute( get_empty_depsmut(deps), env, info, @@ -507,8 +512,8 @@ pub fn two_party_holder_contract() -> Box let init = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_two_party_pol_holder::msg::InstantiateMsg| { - execute_into_neutron(covenant_two_party_pol_holder::contract::instantiate( + msg: valence_two_party_pol_holder::msg::InstantiateMsg| { + execute_into_neutron(valence_two_party_pol_holder::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -517,14 +522,14 @@ pub fn two_party_holder_contract() -> Box }; let query = - |deps: Deps, env: Env, msg: covenant_two_party_pol_holder::msg::QueryMsg| { - covenant_two_party_pol_holder::contract::query(get_empty_deps(deps), env, msg) + |deps: Deps, env: Env, msg: valence_two_party_pol_holder::msg::QueryMsg| { + valence_two_party_pol_holder::contract::query(get_empty_deps(deps), env, msg) }; let migrate = |deps: DepsMut, env: Env, - msg: covenant_two_party_pol_holder::msg::MigrateMsg| { - execute_into_neutron(covenant_two_party_pol_holder::contract::migrate( + msg: valence_two_party_pol_holder::msg::MigrateMsg| { + execute_into_neutron(valence_two_party_pol_holder::contract::migrate( get_empty_depsmut(deps), env, msg, @@ -539,8 +544,8 @@ pub fn astroport_pooler_contract() -> Box let exec = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_astroport_liquid_pooler::msg::ExecuteMsg| { - execute_into_neutron(covenant_astroport_liquid_pooler::contract::execute( + msg: valence_astroport_liquid_pooler::msg::ExecuteMsg| { + execute_into_neutron(valence_astroport_liquid_pooler::contract::execute( get_empty_depsmut(deps), env, info, @@ -551,8 +556,8 @@ pub fn astroport_pooler_contract() -> Box let init = |deps: DepsMut, env: Env, info: MessageInfo, - msg: covenant_astroport_liquid_pooler::msg::InstantiateMsg| { - execute_into_neutron(covenant_astroport_liquid_pooler::contract::instantiate( + msg: valence_astroport_liquid_pooler::msg::InstantiateMsg| { + execute_into_neutron(valence_astroport_liquid_pooler::contract::instantiate( get_empty_depsmut(deps), env, info, @@ -562,12 +567,12 @@ pub fn astroport_pooler_contract() -> Box let query = |deps: Deps, env: Env, - msg: covenant_astroport_liquid_pooler::msg::QueryMsg| { - covenant_astroport_liquid_pooler::contract::query(get_empty_deps(deps), env, msg) + msg: valence_astroport_liquid_pooler::msg::QueryMsg| { + valence_astroport_liquid_pooler::contract::query(get_empty_deps(deps), env, msg) }; let reply = |deps: DepsMut, env: Env, reply: Reply| { - execute_into_neutron(covenant_astroport_liquid_pooler::contract::reply( + execute_into_neutron(valence_astroport_liquid_pooler::contract::reply( get_empty_depsmut(deps), env, reply, @@ -576,8 +581,8 @@ pub fn astroport_pooler_contract() -> Box let migrate = |deps: DepsMut, env: Env, - msg: covenant_astroport_liquid_pooler::msg::MigrateMsg| { - execute_into_neutron(covenant_astroport_liquid_pooler::contract::migrate( + msg: valence_astroport_liquid_pooler::msg::MigrateMsg| { + execute_into_neutron(valence_astroport_liquid_pooler::contract::migrate( get_empty_depsmut(deps), env, msg, diff --git a/unit-tests/src/setup/custom_module.rs b/unit-tests/src/setup/custom_module.rs index afcb9667..466b8755 100644 --- a/unit-tests/src/setup/custom_module.rs +++ b/unit-tests/src/setup/custom_module.rs @@ -4,8 +4,6 @@ use cosmwasm_std::{ coin, coins, from_json, to_json_binary, to_json_string, Addr, BalanceResponse, BankMsg, BankQuery, StdError, StdResult, Storage, Uint128, }; -use covenant_ibc_forwarder::helpers::MsgTransfer; -use covenant_stride_liquid_staker::helpers::Autopilot; use cw_multi_test::{ addons::MockApiBech32, error::{bail, AnyError}, @@ -23,6 +21,8 @@ use neutron_sdk::{ sudo::msg::RequestPacket, }; use prost::Message; +use valence_ibc_forwarder::helpers::MsgTransfer; +use valence_stride_liquid_staker::helpers::Autopilot; use super::DENOM_NTRN; diff --git a/unit-tests/src/setup/instantiates/astro_liquid_pooler.rs b/unit-tests/src/setup/instantiates/astro_liquid_pooler.rs index ffca7704..c78c92de 100644 --- a/unit-tests/src/setup/instantiates/astro_liquid_pooler.rs +++ b/unit-tests/src/setup/instantiates/astro_liquid_pooler.rs @@ -6,10 +6,10 @@ use crate::setup::{DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN}; #[derive(Clone)] pub struct AstroLiquidPoolerInstantiate { - pub msg: covenant_astroport_liquid_pooler::msg::InstantiateMsg, + pub msg: valence_astroport_liquid_pooler::msg::InstantiateMsg, } -impl From for covenant_astroport_liquid_pooler::msg::InstantiateMsg { +impl From for valence_astroport_liquid_pooler::msg::InstantiateMsg { fn from(value: AstroLiquidPoolerInstantiate) -> Self { value.msg } @@ -20,14 +20,14 @@ impl AstroLiquidPoolerInstantiate { pool_address: String, clock_address: String, slippage_tolerance: Option, - assets: covenant_astroport_liquid_pooler::msg::AssetData, + assets: valence_astroport_liquid_pooler::msg::AssetData, single_side_lp_limits: SingleSideLpLimits, pool_price_config: PoolPriceConfig, pair_type: PairType, holder_address: String, ) -> Self { Self { - msg: covenant_astroport_liquid_pooler::msg::InstantiateMsg { + msg: valence_astroport_liquid_pooler::msg::InstantiateMsg { pool_address, clock_address, slippage_tolerance, @@ -57,7 +57,7 @@ impl AstroLiquidPoolerInstantiate { pub fn with_assets( &mut self, - assets: covenant_astroport_liquid_pooler::msg::AssetData, + assets: valence_astroport_liquid_pooler::msg::AssetData, ) -> &mut Self { self.msg.assets = assets; self @@ -90,11 +90,11 @@ impl AstroLiquidPoolerInstantiate { impl AstroLiquidPoolerInstantiate { pub fn default(pool_address: String, clock_address: String, holder_address: String) -> Self { Self { - msg: covenant_astroport_liquid_pooler::msg::InstantiateMsg { + msg: valence_astroport_liquid_pooler::msg::InstantiateMsg { pool_address, clock_address, slippage_tolerance: None, - assets: covenant_astroport_liquid_pooler::msg::AssetData { + assets: valence_astroport_liquid_pooler::msg::AssetData { asset_a_denom: DENOM_ATOM_ON_NTRN.to_string(), asset_b_denom: DENOM_LS_ATOM_ON_NTRN.to_string(), }, diff --git a/unit-tests/src/setup/instantiates/clock.rs b/unit-tests/src/setup/instantiates/clock.rs index b62de239..5eeda271 100644 --- a/unit-tests/src/setup/instantiates/clock.rs +++ b/unit-tests/src/setup/instantiates/clock.rs @@ -4,10 +4,10 @@ use crate::setup::suite_builder::SuiteBuilder; #[derive(Clone)] pub struct ClockInstantiate { - pub msg: covenant_clock::msg::InstantiateMsg, + pub msg: valence_clock::msg::InstantiateMsg, } -impl From for covenant_clock::msg::InstantiateMsg { +impl From for valence_clock::msg::InstantiateMsg { fn from(value: ClockInstantiate) -> Self { value.msg } @@ -16,7 +16,7 @@ impl From for covenant_clock::msg::InstantiateMsg { impl ClockInstantiate { pub fn new(tick_max_gas: Option, whitelist: Vec) -> Self { Self { - msg: covenant_clock::msg::InstantiateMsg { + msg: valence_clock::msg::InstantiateMsg { tick_max_gas, whitelist, }, @@ -41,7 +41,7 @@ impl ClockInstantiate { whitelist: Vec, ) -> Self { Self { - msg: covenant_clock::msg::InstantiateMsg { + msg: valence_clock::msg::InstantiateMsg { tick_max_gas, whitelist, }, diff --git a/unit-tests/src/setup/instantiates/ibc_forwarder.rs b/unit-tests/src/setup/instantiates/ibc_forwarder.rs index 887cdd91..2474bf0b 100644 --- a/unit-tests/src/setup/instantiates/ibc_forwarder.rs +++ b/unit-tests/src/setup/instantiates/ibc_forwarder.rs @@ -3,10 +3,10 @@ use cosmwasm_std::{Uint128, Uint64}; use crate::setup::{DENOM_ATOM_ON_NTRN, NTRN_HUB_CHANNEL}; pub struct IbcForwarderInstantiate { - pub msg: covenant_ibc_forwarder::msg::InstantiateMsg, + pub msg: valence_ibc_forwarder::msg::InstantiateMsg, } -impl From for covenant_ibc_forwarder::msg::InstantiateMsg { +impl From for valence_ibc_forwarder::msg::InstantiateMsg { fn from(value: IbcForwarderInstantiate) -> Self { value.msg } @@ -25,7 +25,7 @@ impl IbcForwarderInstantiate { fallback_address: Option, ) -> Self { Self { - msg: covenant_ibc_forwarder::msg::InstantiateMsg { + msg: valence_ibc_forwarder::msg::InstantiateMsg { clock_address, next_contract, remote_chain_connection_id, @@ -88,7 +88,7 @@ impl IbcForwarderInstantiate { impl IbcForwarderInstantiate { pub fn default(clock_address: String, next_contract: String) -> Self { Self { - msg: covenant_ibc_forwarder::msg::InstantiateMsg { + msg: valence_ibc_forwarder::msg::InstantiateMsg { clock_address, next_contract, remote_chain_connection_id: "connection-todo".to_string(), diff --git a/unit-tests/src/setup/instantiates/interchain_router.rs b/unit-tests/src/setup/instantiates/interchain_router.rs index 1f2b4716..cee697fd 100644 --- a/unit-tests/src/setup/instantiates/interchain_router.rs +++ b/unit-tests/src/setup/instantiates/interchain_router.rs @@ -6,10 +6,10 @@ use covenant_utils::DestinationConfig; use crate::setup::{DENOM_ATOM_ON_NTRN, NTRN_HUB_CHANNEL}; pub struct InterchainRouterInstantiate { - pub msg: covenant_interchain_router::msg::InstantiateMsg, + pub msg: valence_interchain_router::msg::InstantiateMsg, } -impl From for covenant_interchain_router::msg::InstantiateMsg { +impl From for valence_interchain_router::msg::InstantiateMsg { fn from(value: InterchainRouterInstantiate) -> Self { value.msg } @@ -22,7 +22,7 @@ impl InterchainRouterInstantiate { denoms: BTreeSet, ) -> Self { Self { - msg: covenant_interchain_router::msg::InstantiateMsg { + msg: valence_interchain_router::msg::InstantiateMsg { clock_address: clock_address.to_string(), destination_config, denoms, diff --git a/unit-tests/src/setup/instantiates/native_router.rs b/unit-tests/src/setup/instantiates/native_router.rs index da9fb69c..ead1371a 100644 --- a/unit-tests/src/setup/instantiates/native_router.rs +++ b/unit-tests/src/setup/instantiates/native_router.rs @@ -5,10 +5,10 @@ use cosmwasm_std::Addr; use crate::setup::DENOM_ATOM_ON_NTRN; pub struct NativeRouterInstantiate { - pub msg: covenant_native_router::msg::InstantiateMsg, + pub msg: valence_native_router::msg::InstantiateMsg, } -impl From for covenant_native_router::msg::InstantiateMsg { +impl From for valence_native_router::msg::InstantiateMsg { fn from(value: NativeRouterInstantiate) -> Self { value.msg } @@ -17,7 +17,7 @@ impl From for covenant_native_router::msg::InstantiateM impl NativeRouterInstantiate { pub fn new(clock_address: Addr, receiver_address: Addr, denoms: BTreeSet) -> Self { Self { - msg: covenant_native_router::msg::InstantiateMsg { + msg: valence_native_router::msg::InstantiateMsg { clock_address: clock_address.to_string(), receiver_address: receiver_address.to_string(), denoms, diff --git a/unit-tests/src/setup/instantiates/native_splitter.rs b/unit-tests/src/setup/instantiates/native_splitter.rs index 796a3de3..0ed5a4e1 100644 --- a/unit-tests/src/setup/instantiates/native_splitter.rs +++ b/unit-tests/src/setup/instantiates/native_splitter.rs @@ -6,10 +6,10 @@ use covenant_utils::split::SplitConfig; use crate::setup::{DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN}; pub struct NativeSplitterInstantiate { - pub msg: covenant_native_splitter::msg::InstantiateMsg, + pub msg: valence_native_splitter::msg::InstantiateMsg, } -impl From for covenant_native_splitter::msg::InstantiateMsg { +impl From for valence_native_splitter::msg::InstantiateMsg { fn from(value: NativeSplitterInstantiate) -> Self { value.msg } @@ -22,7 +22,7 @@ impl NativeSplitterInstantiate { fallback_split: Option, ) -> Self { Self { - msg: covenant_native_splitter::msg::InstantiateMsg { + msg: valence_native_splitter::msg::InstantiateMsg { clock_address, splits, fallback_split, @@ -58,7 +58,7 @@ impl NativeSplitterInstantiate { denom_to_split_config_map.insert(DENOM_LS_ATOM_ON_NTRN.to_string(), split_config.clone()); Self { - msg: covenant_native_splitter::msg::InstantiateMsg { + msg: valence_native_splitter::msg::InstantiateMsg { clock_address, splits: denom_to_split_config_map, fallback_split: Some(split_config), diff --git a/unit-tests/src/setup/instantiates/osmo_lp_outpost.rs b/unit-tests/src/setup/instantiates/osmo_lp_outpost.rs index e4dd9156..8d8adaec 100644 --- a/unit-tests/src/setup/instantiates/osmo_lp_outpost.rs +++ b/unit-tests/src/setup/instantiates/osmo_lp_outpost.rs @@ -1,22 +1,22 @@ -pub struct OsmpLpOutpostInstantiate { - pub msg: covenant_outpost_osmo_liquid_pooler::msg::InstantiateMsg, +pub struct OsmoLpOutpostInstantiate { + pub msg: valence_outpost_osmo_liquid_pooler::msg::InstantiateMsg, } -impl From for covenant_outpost_osmo_liquid_pooler::msg::InstantiateMsg { - fn from(value: OsmpLpOutpostInstantiate) -> Self { +impl From for valence_outpost_osmo_liquid_pooler::msg::InstantiateMsg { + fn from(value: OsmoLpOutpostInstantiate) -> Self { value.msg } } -impl OsmpLpOutpostInstantiate { +impl OsmoLpOutpostInstantiate { pub fn new() -> Self { Self { - msg: covenant_outpost_osmo_liquid_pooler::msg::InstantiateMsg {}, + msg: valence_outpost_osmo_liquid_pooler::msg::InstantiateMsg {}, } } } -impl Default for OsmpLpOutpostInstantiate { +impl Default for OsmoLpOutpostInstantiate { fn default() -> Self { Self::new() } diff --git a/unit-tests/src/setup/instantiates/remote_chain_splitter.rs b/unit-tests/src/setup/instantiates/remote_chain_splitter.rs index da0c05ff..29bc8c3a 100644 --- a/unit-tests/src/setup/instantiates/remote_chain_splitter.rs +++ b/unit-tests/src/setup/instantiates/remote_chain_splitter.rs @@ -6,9 +6,9 @@ use covenant_utils::split::SplitConfig; use crate::setup::{DENOM_ATOM_ON_NTRN, NTRN_HUB_CHANNEL}; pub struct RemoteChainSplitterInstantiate { - pub msg: covenant_remote_chain_splitter::msg::InstantiateMsg, + pub msg: valence_remote_chain_splitter::msg::InstantiateMsg, } -impl From for covenant_remote_chain_splitter::msg::InstantiateMsg { +impl From for valence_remote_chain_splitter::msg::InstantiateMsg { fn from(value: RemoteChainSplitterInstantiate) -> Self { value.msg } @@ -27,7 +27,7 @@ impl RemoteChainSplitterInstantiate { fallback_address: Option, ) -> Self { Self { - msg: covenant_remote_chain_splitter::msg::InstantiateMsg { + msg: valence_remote_chain_splitter::msg::InstantiateMsg { clock_address, remote_chain_connection_id, remote_chain_channel_id, @@ -98,7 +98,7 @@ impl RemoteChainSplitterInstantiate { denom_to_split_config_map.insert(DENOM_ATOM_ON_NTRN.to_string(), split_config.clone()); Self { - msg: covenant_remote_chain_splitter::msg::InstantiateMsg { + msg: valence_remote_chain_splitter::msg::InstantiateMsg { clock_address, remote_chain_connection_id: "connection-0".to_string(), remote_chain_channel_id: NTRN_HUB_CHANNEL.0.to_string(), diff --git a/unit-tests/src/setup/instantiates/single_party_covenant.rs b/unit-tests/src/setup/instantiates/single_party_covenant.rs index aafdefc2..cef8a50f 100644 --- a/unit-tests/src/setup/instantiates/single_party_covenant.rs +++ b/unit-tests/src/setup/instantiates/single_party_covenant.rs @@ -10,10 +10,12 @@ use crate::setup::{ #[derive(Clone)] pub struct SinglePartyCovenantInstantiate { - pub msg: covenant_single_party_pol::msg::InstantiateMsg, + pub msg: valence_covenant_single_party_pol::msg::InstantiateMsg, } -impl From for covenant_single_party_pol::msg::InstantiateMsg { +impl From + for valence_covenant_single_party_pol::msg::InstantiateMsg +{ fn from(value: SinglePartyCovenantInstantiate) -> Self { value.msg } @@ -22,14 +24,14 @@ impl From for covenant_single_party_pol::msg::In impl SinglePartyCovenantInstantiate { pub fn default( builder: &SuiteBuilder, - ls_forwarder_config: covenant_single_party_pol::msg::CovenantPartyConfig, - lp_forwarder_config: covenant_single_party_pol::msg::CovenantPartyConfig, - remote_splitter: covenant_single_party_pol::msg::RemoteChainSplitterConfig, + ls_forwarder_config: valence_covenant_single_party_pol::msg::CovenantPartyConfig, + lp_forwarder_config: valence_covenant_single_party_pol::msg::CovenantPartyConfig, + remote_splitter: valence_covenant_single_party_pol::msg::RemoteChainSplitterConfig, covenant_party: covenant_utils::InterchainCovenantParty, - pooler_config: covenant_single_party_pol::msg::LiquidPoolerConfig, + pooler_config: valence_covenant_single_party_pol::msg::LiquidPoolerConfig, pool_price_config: covenant_utils::PoolPriceConfig, ) -> Self { - let contract_codes = covenant_single_party_pol::msg::CovenantContractCodeIds { + let contract_codes = valence_covenant_single_party_pol::msg::CovenantContractCodeIds { ibc_forwarder_code: builder.ibc_forwarder_code_id, interchain_router_code: builder.interchain_router_code_id, holder_code: builder.single_party_holder_code_id, @@ -41,14 +43,14 @@ impl SinglePartyCovenantInstantiate { Self::new( "single_party_covenant".to_string(), - covenant_single_party_pol::msg::Timeouts { + valence_covenant_single_party_pol::msg::Timeouts { ica_timeout: 1000_u64.into(), ibc_transfer_timeout: 1000_u64.into(), }, contract_codes, None, Expiration::AtHeight(builder.app.block_info().height + 100000), - covenant_single_party_pol::msg::LsInfo { + valence_covenant_single_party_pol::msg::LsInfo { ls_denom: DENOM_LS_ATOM_ON_STRIDE.to_string(), ls_denom_on_neutron: DENOM_LS_ATOM_ON_NTRN.to_string(), ls_chain_to_neutron_channel_id: NTRN_STRIDE_CHANNEL.1.to_string(), @@ -97,8 +99,8 @@ impl SinglePartyCovenantInstantiate { local_to_remote_channel_id: &str, remote_to_local_channel_id: &str, amount: u128, - ) -> covenant_single_party_pol::msg::CovenantPartyConfig { - covenant_single_party_pol::msg::CovenantPartyConfig::Interchain( + ) -> valence_covenant_single_party_pol::msg::CovenantPartyConfig { + valence_covenant_single_party_pol::msg::CovenantPartyConfig::Interchain( SinglePartyCovenantInstantiate::get_covenant_party( remote_recevier, local_recevier, @@ -116,8 +118,8 @@ impl SinglePartyCovenantInstantiate { recevier: &Addr, denom: &str, amount: u128, - ) -> covenant_single_party_pol::msg::CovenantPartyConfig { - covenant_single_party_pol::msg::CovenantPartyConfig::Native( + ) -> valence_covenant_single_party_pol::msg::CovenantPartyConfig { + valence_covenant_single_party_pol::msg::CovenantPartyConfig::Native( covenant_utils::NativeCovenantParty { party_receiver_addr: recevier.to_string(), native_denom: denom.to_string(), @@ -133,8 +135,8 @@ impl SinglePartyCovenantInstantiate { amount: impl Into, ls_share: Decimal, native_share: Decimal, - ) -> covenant_single_party_pol::msg::RemoteChainSplitterConfig { - covenant_single_party_pol::msg::RemoteChainSplitterConfig { + ) -> valence_covenant_single_party_pol::msg::RemoteChainSplitterConfig { + valence_covenant_single_party_pol::msg::RemoteChainSplitterConfig { channel_id: channel_id.into(), connection_id: "conn-1".to_string(), denom: denom.into(), @@ -151,9 +153,9 @@ impl SinglePartyCovenantInstantiate { pool_addr: &Addr, pool_pair_type: astroport::factory::PairType, single_side_lp_limits: covenant_utils::SingleSideLpLimits, - ) -> covenant_single_party_pol::msg::LiquidPoolerConfig { - covenant_single_party_pol::msg::LiquidPoolerConfig::Astroport( - covenant_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig { + ) -> valence_covenant_single_party_pol::msg::LiquidPoolerConfig { + valence_covenant_single_party_pol::msg::LiquidPoolerConfig::Astroport( + valence_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig { pool_pair_type, pool_address: pool_addr.to_string(), asset_a_denom: denom_a.into(), @@ -178,21 +180,21 @@ impl SinglePartyCovenantInstantiate { #[allow(clippy::too_many_arguments)] pub fn new( label: String, - timeouts: covenant_single_party_pol::msg::Timeouts, - contract_codes: covenant_single_party_pol::msg::CovenantContractCodeIds, + timeouts: valence_covenant_single_party_pol::msg::Timeouts, + contract_codes: valence_covenant_single_party_pol::msg::CovenantContractCodeIds, clock_tick_max_gas: Option, lockup_period: Expiration, - ls_info: covenant_single_party_pol::msg::LsInfo, - ls_forwarder_config: covenant_single_party_pol::msg::CovenantPartyConfig, - lp_forwarder_config: covenant_single_party_pol::msg::CovenantPartyConfig, + ls_info: valence_covenant_single_party_pol::msg::LsInfo, + ls_forwarder_config: valence_covenant_single_party_pol::msg::CovenantPartyConfig, + lp_forwarder_config: valence_covenant_single_party_pol::msg::CovenantPartyConfig, pool_price_config: covenant_utils::PoolPriceConfig, - remote_chain_splitter_config: covenant_single_party_pol::msg::RemoteChainSplitterConfig, + remote_chain_splitter_config: valence_covenant_single_party_pol::msg::RemoteChainSplitterConfig, emergency_committee: Option, covenant_party_config: covenant_utils::InterchainCovenantParty, - liquid_pooler_config: covenant_single_party_pol::msg::LiquidPoolerConfig, + liquid_pooler_config: valence_covenant_single_party_pol::msg::LiquidPoolerConfig, ) -> Self { Self { - msg: covenant_single_party_pol::msg::InstantiateMsg { + msg: valence_covenant_single_party_pol::msg::InstantiateMsg { label, timeouts, contract_codes, @@ -221,7 +223,7 @@ impl SinglePartyCovenantInstantiate { ica_timeout: impl Into, ibc_transfer_timeout: impl Into, ) -> &mut Self { - self.msg.timeouts = covenant_single_party_pol::msg::Timeouts { + self.msg.timeouts = valence_covenant_single_party_pol::msg::Timeouts { ica_timeout: ica_timeout.into(), ibc_transfer_timeout: ibc_transfer_timeout.into(), }; @@ -230,7 +232,7 @@ impl SinglePartyCovenantInstantiate { pub fn with_contract_codes( &mut self, - codes: covenant_single_party_pol::msg::CovenantContractCodeIds, + codes: valence_covenant_single_party_pol::msg::CovenantContractCodeIds, ) -> &mut Self { self.msg.contract_codes = codes; self diff --git a/unit-tests/src/setup/instantiates/single_party_holder.rs b/unit-tests/src/setup/instantiates/single_party_holder.rs index 52c9a07b..3bcf1fbf 100644 --- a/unit-tests/src/setup/instantiates/single_party_holder.rs +++ b/unit-tests/src/setup/instantiates/single_party_holder.rs @@ -1,10 +1,10 @@ use cw_utils::Expiration; pub struct SinglePartyHolderInstantiate { - pub msg: covenant_single_party_pol_holder::msg::InstantiateMsg, + pub msg: valence_single_party_pol_holder::msg::InstantiateMsg, } -impl From for covenant_single_party_pol_holder::msg::InstantiateMsg { +impl From for valence_single_party_pol_holder::msg::InstantiateMsg { fn from(value: SinglePartyHolderInstantiate) -> Self { value.msg } @@ -19,7 +19,7 @@ impl SinglePartyHolderInstantiate { lockup_period: Expiration, ) -> Self { Self { - msg: covenant_single_party_pol_holder::msg::InstantiateMsg { + msg: valence_single_party_pol_holder::msg::InstantiateMsg { withdrawer, withdraw_to, emergency_committee_addr, @@ -58,7 +58,7 @@ impl SinglePartyHolderInstantiate { impl SinglePartyHolderInstantiate { pub fn default(pooler_address: String) -> Self { Self { - msg: covenant_single_party_pol_holder::msg::InstantiateMsg { + msg: valence_single_party_pol_holder::msg::InstantiateMsg { withdrawer: pooler_address.to_string(), withdraw_to: pooler_address.to_string(), emergency_committee_addr: Some(pooler_address.to_string()), diff --git a/unit-tests/src/setup/instantiates/swap_covenant.rs b/unit-tests/src/setup/instantiates/swap_covenant.rs index 4ddf4610..1d094c32 100644 --- a/unit-tests/src/setup/instantiates/swap_covenant.rs +++ b/unit-tests/src/setup/instantiates/swap_covenant.rs @@ -7,10 +7,10 @@ use crate::setup::suite_builder::SuiteBuilder; #[derive(Clone)] pub struct SwapCovenantInstantiate { - pub msg: covenant_swap::msg::InstantiateMsg, + pub msg: valence_covenant_swap::msg::InstantiateMsg, } -impl From for covenant_swap::msg::InstantiateMsg { +impl From for valence_covenant_swap::msg::InstantiateMsg { fn from(value: SwapCovenantInstantiate) -> Self { value.msg } @@ -19,11 +19,11 @@ impl From for covenant_swap::msg::InstantiateMsg { impl SwapCovenantInstantiate { pub fn default( builder: &SuiteBuilder, - party_a_config: covenant_swap::msg::CovenantPartyConfig, - party_b_config: covenant_swap::msg::CovenantPartyConfig, + party_a_config: valence_covenant_swap::msg::CovenantPartyConfig, + party_b_config: valence_covenant_swap::msg::CovenantPartyConfig, splits: BTreeMap, ) -> Self { - let contract_codes = covenant_swap::msg::SwapCovenantContractCodeIds { + let contract_codes = valence_covenant_swap::msg::SwapCovenantContractCodeIds { ibc_forwarder_code: builder.ibc_forwarder_code_id, interchain_router_code: builder.interchain_router_code_id, native_router_code: builder.native_router_code_id, @@ -34,7 +34,7 @@ impl SwapCovenantInstantiate { Self::new( "swap_covenant".to_string(), - covenant_swap::msg::Timeouts { + valence_covenant_swap::msg::Timeouts { ica_timeout: 1000_u64.into(), ibc_transfer_timeout: 1000_u64.into(), }, @@ -57,8 +57,8 @@ impl SwapCovenantInstantiate { local_to_remote_channel_id: &str, remote_to_local_channel_id: &str, amount: u128, - ) -> covenant_swap::msg::CovenantPartyConfig { - covenant_swap::msg::CovenantPartyConfig::Interchain( + ) -> valence_covenant_swap::msg::CovenantPartyConfig { + valence_covenant_swap::msg::CovenantPartyConfig::Interchain( covenant_utils::InterchainCovenantParty { party_receiver_addr: remote_recevier.to_string(), party_chain_connection_id: "conn-1".to_string(), @@ -79,13 +79,15 @@ impl SwapCovenantInstantiate { recevier: &Addr, denom: &str, amount: u128, - ) -> covenant_swap::msg::CovenantPartyConfig { - covenant_swap::msg::CovenantPartyConfig::Native(covenant_utils::NativeCovenantParty { - party_receiver_addr: recevier.to_string(), - native_denom: denom.to_string(), - addr: recevier.to_string(), - contribution: coin(amount, denom), - }) + ) -> valence_covenant_swap::msg::CovenantPartyConfig { + valence_covenant_swap::msg::CovenantPartyConfig::Native( + covenant_utils::NativeCovenantParty { + party_receiver_addr: recevier.to_string(), + native_denom: denom.to_string(), + addr: recevier.to_string(), + contribution: coin(amount, denom), + }, + ) } pub fn get_split_custom( @@ -112,18 +114,18 @@ impl SwapCovenantInstantiate { #[allow(clippy::too_many_arguments)] pub fn new( label: String, - timeouts: covenant_swap::msg::Timeouts, - contract_codes: covenant_swap::msg::SwapCovenantContractCodeIds, + timeouts: valence_covenant_swap::msg::Timeouts, + contract_codes: valence_covenant_swap::msg::SwapCovenantContractCodeIds, clock_tick_max_gas: Option, lockup_config: Expiration, - party_a_config: covenant_swap::msg::CovenantPartyConfig, - party_b_config: covenant_swap::msg::CovenantPartyConfig, + party_a_config: valence_covenant_swap::msg::CovenantPartyConfig, + party_b_config: valence_covenant_swap::msg::CovenantPartyConfig, splits: BTreeMap, fallback_split: Option, fallback_address: Option, ) -> Self { Self { - msg: covenant_swap::msg::InstantiateMsg { + msg: valence_covenant_swap::msg::InstantiateMsg { label, timeouts, contract_codes, @@ -149,7 +151,7 @@ impl SwapCovenantInstantiate { ica_timeout: impl Into, ibc_transfer_timeout: impl Into, ) -> &mut Self { - self.msg.timeouts = covenant_swap::msg::Timeouts { + self.msg.timeouts = valence_covenant_swap::msg::Timeouts { ica_timeout: ica_timeout.into(), ibc_transfer_timeout: ibc_transfer_timeout.into(), }; @@ -158,7 +160,7 @@ impl SwapCovenantInstantiate { pub fn with_contract_codes( &mut self, - codes: covenant_swap::msg::SwapCovenantContractCodeIds, + codes: valence_covenant_swap::msg::SwapCovenantContractCodeIds, ) -> &mut Self { self.msg.contract_codes = codes; self @@ -176,7 +178,7 @@ impl SwapCovenantInstantiate { pub fn with_party_a_config( &mut self, - config: covenant_swap::msg::CovenantPartyConfig, + config: valence_covenant_swap::msg::CovenantPartyConfig, ) -> &mut Self { self.msg.party_a_config = config; self @@ -184,7 +186,7 @@ impl SwapCovenantInstantiate { pub fn with_party_b_config( &mut self, - config: covenant_swap::msg::CovenantPartyConfig, + config: valence_covenant_swap::msg::CovenantPartyConfig, ) -> &mut Self { self.msg.party_b_config = config; self diff --git a/unit-tests/src/setup/instantiates/swap_holder.rs b/unit-tests/src/setup/instantiates/swap_holder.rs index 7266d4b4..a7200333 100644 --- a/unit-tests/src/setup/instantiates/swap_holder.rs +++ b/unit-tests/src/setup/instantiates/swap_holder.rs @@ -1,15 +1,15 @@ use cosmwasm_std::{Addr, Uint128}; -use covenant_swap_holder::msg::RefundConfig; use covenant_utils::{CovenantPartiesConfig, CovenantParty, CovenantTerms, ReceiverConfig}; use cw_utils::Expiration; +use valence_swap_holder::msg::RefundConfig; use crate::setup::{DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN}; pub struct SwapHolderInstantiate { - pub msg: covenant_swap_holder::msg::InstantiateMsg, + pub msg: valence_swap_holder::msg::InstantiateMsg, } -impl From for covenant_swap_holder::msg::InstantiateMsg { +impl From for valence_swap_holder::msg::InstantiateMsg { fn from(value: SwapHolderInstantiate) -> Self { value.msg } @@ -25,7 +25,7 @@ impl SwapHolderInstantiate { refund_config: RefundConfig, ) -> Self { Self { - msg: covenant_swap_holder::msg::InstantiateMsg { + msg: valence_swap_holder::msg::InstantiateMsg { clock_address, next_contract, lockup_config, @@ -77,7 +77,7 @@ impl SwapHolderInstantiate { party_b_refund_address: String, ) -> Self { Self { - msg: covenant_swap_holder::msg::InstantiateMsg { + msg: valence_swap_holder::msg::InstantiateMsg { clock_address, next_contract, lockup_config: Expiration::AtHeight(1000000), diff --git a/unit-tests/src/setup/instantiates/two_party_covenant.rs b/unit-tests/src/setup/instantiates/two_party_covenant.rs index bcb64603..0cfe7c91 100644 --- a/unit-tests/src/setup/instantiates/two_party_covenant.rs +++ b/unit-tests/src/setup/instantiates/two_party_covenant.rs @@ -1,21 +1,21 @@ use std::{collections::BTreeMap, str::FromStr}; use cosmwasm_std::{coin, Addr, Decimal, Uint128, Uint64}; -use covenant_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; -use covenant_two_party_pol::msg::{CovenantPartyConfig, Timeouts}; use covenant_utils::{ split::SplitConfig, NativeCovenantParty, PoolPriceConfig, SingleSideLpLimits, }; use cw_utils::Expiration; +use valence_astroport_liquid_pooler::msg::AstroportLiquidPoolerConfig; +use valence_covenant_two_party_pol::msg::{CovenantPartyConfig, Timeouts}; use crate::setup::{suite_builder::SuiteBuilder, DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN}; #[derive(Clone)] pub struct TwoPartyCovenantInstantiate { - pub msg: covenant_two_party_pol::msg::InstantiateMsg, + pub msg: valence_covenant_two_party_pol::msg::InstantiateMsg, } -impl From for covenant_two_party_pol::msg::InstantiateMsg { +impl From for valence_covenant_two_party_pol::msg::InstantiateMsg { fn from(value: TwoPartyCovenantInstantiate) -> Self { value.msg } @@ -29,7 +29,7 @@ impl TwoPartyCovenantInstantiate { pub fn with_contract_codes( &mut self, - contract_codes: covenant_two_party_pol::msg::CovenantContractCodeIds, + contract_codes: valence_covenant_two_party_pol::msg::CovenantContractCodeIds, ) -> &mut Self { self.msg.contract_codes = contract_codes; self @@ -47,7 +47,7 @@ impl TwoPartyCovenantInstantiate { pub fn with_ragequit_config( &mut self, - ragequit_config: Option, + ragequit_config: Option, ) -> &mut Self { self.msg.ragequit_config = ragequit_config; self @@ -60,7 +60,7 @@ impl TwoPartyCovenantInstantiate { pub fn with_party_a_config( &mut self, - party_a_config: covenant_two_party_pol::msg::CovenantPartyConfig, + party_a_config: valence_covenant_two_party_pol::msg::CovenantPartyConfig, ) -> &mut Self { self.msg.party_a_config = party_a_config; self @@ -68,7 +68,7 @@ impl TwoPartyCovenantInstantiate { pub fn with_party_b_config( &mut self, - party_b_config: covenant_two_party_pol::msg::CovenantPartyConfig, + party_b_config: valence_covenant_two_party_pol::msg::CovenantPartyConfig, ) -> &mut Self { self.msg.party_b_config = party_b_config; self @@ -76,7 +76,7 @@ impl TwoPartyCovenantInstantiate { pub fn with_covenant_type( &mut self, - covenant_type: covenant_two_party_pol_holder::msg::CovenantType, + covenant_type: valence_two_party_pol_holder::msg::CovenantType, ) -> &mut Self { self.msg.covenant_type = covenant_type; self @@ -114,7 +114,7 @@ impl TwoPartyCovenantInstantiate { pub fn with_liquid_pooler_config( &mut self, - liquid_pooler_config: covenant_two_party_pol::msg::LiquidPoolerConfig, + liquid_pooler_config: valence_covenant_two_party_pol::msg::LiquidPoolerConfig, ) -> &mut Self { self.msg.liquid_pooler_config = liquid_pooler_config; self @@ -128,7 +128,7 @@ impl TwoPartyCovenantInstantiate { party_b_addr: Addr, pool_address: Addr, ) -> Self { - let contract_codes = covenant_two_party_pol::msg::CovenantContractCodeIds { + let contract_codes = valence_covenant_two_party_pol::msg::CovenantContractCodeIds { ibc_forwarder_code: builder.ibc_forwarder_code_id, interchain_router_code: builder.interchain_router_code_id, holder_code: builder.two_party_holder_code_id, @@ -147,8 +147,8 @@ impl TwoPartyCovenantInstantiate { denom_to_split_config_map.insert(DENOM_LS_ATOM_ON_NTRN.to_string(), split_config.clone()); Self { - msg: covenant_two_party_pol::msg::InstantiateMsg { - label: "covenant_two_party_pol".to_string(), + msg: valence_covenant_two_party_pol::msg::InstantiateMsg { + label: "valence_covenant_two_party_pol".to_string(), timeouts: Timeouts { ica_timeout: Uint64::new(100), ibc_transfer_timeout: Uint64::new(100), @@ -170,7 +170,7 @@ impl TwoPartyCovenantInstantiate { addr: party_b_addr.to_string(), contribution: coin(10_000, DENOM_LS_ATOM_ON_NTRN), }), - covenant_type: covenant_two_party_pol_holder::msg::CovenantType::Share {}, + covenant_type: valence_two_party_pol_holder::msg::CovenantType::Share {}, party_a_share: Decimal::from_str("0.5").unwrap(), party_b_share: Decimal::from_str("0.5").unwrap(), pool_price_config: PoolPriceConfig { @@ -180,18 +180,19 @@ impl TwoPartyCovenantInstantiate { splits: denom_to_split_config_map, fallback_split: None, emergency_committee: None, - liquid_pooler_config: covenant_two_party_pol::msg::LiquidPoolerConfig::Astroport( - AstroportLiquidPoolerConfig { - pool_pair_type: astroport::factory::PairType::Stable {}, - pool_address: pool_address.to_string(), - asset_a_denom: DENOM_ATOM_ON_NTRN.to_string(), - asset_b_denom: DENOM_LS_ATOM_ON_NTRN.to_string(), - single_side_lp_limits: SingleSideLpLimits { - asset_a_limit: Uint128::new(10_000), - asset_b_limit: Uint128::new(10_000), + liquid_pooler_config: + valence_covenant_two_party_pol::msg::LiquidPoolerConfig::Astroport( + AstroportLiquidPoolerConfig { + pool_pair_type: astroport::factory::PairType::Stable {}, + pool_address: pool_address.to_string(), + asset_a_denom: DENOM_ATOM_ON_NTRN.to_string(), + asset_b_denom: DENOM_LS_ATOM_ON_NTRN.to_string(), + single_side_lp_limits: SingleSideLpLimits { + asset_a_limit: Uint128::new(10_000), + asset_b_limit: Uint128::new(10_000), + }, }, - }, - ), + ), fallback_address: None, }, } diff --git a/unit-tests/src/setup/instantiates/two_party_pol_holder.rs b/unit-tests/src/setup/instantiates/two_party_pol_holder.rs index caa79c8c..afb8ed20 100644 --- a/unit-tests/src/setup/instantiates/two_party_pol_holder.rs +++ b/unit-tests/src/setup/instantiates/two_party_pol_holder.rs @@ -8,10 +8,10 @@ use crate::setup::{DENOM_ATOM_ON_NTRN, DENOM_LS_ATOM_ON_NTRN}; #[derive(Clone)] pub struct TwoPartyHolderInstantiate { - pub msg: covenant_two_party_pol_holder::msg::InstantiateMsg, + pub msg: valence_two_party_pol_holder::msg::InstantiateMsg, } -impl From for covenant_two_party_pol_holder::msg::InstantiateMsg { +impl From for valence_two_party_pol_holder::msg::InstantiateMsg { fn from(value: TwoPartyHolderInstantiate) -> Self { value.msg } @@ -23,15 +23,15 @@ impl TwoPartyHolderInstantiate { clock_address: String, next_contract: String, lockup_config: Expiration, - ragequit_config: covenant_two_party_pol_holder::msg::RagequitConfig, + ragequit_config: valence_two_party_pol_holder::msg::RagequitConfig, deposit_deadline: Expiration, - covenant_config: covenant_two_party_pol_holder::msg::TwoPartyPolCovenantConfig, + covenant_config: valence_two_party_pol_holder::msg::TwoPartyPolCovenantConfig, splits: BTreeMap, fallback_split: Option, emergency_committee_addr: Option, ) -> Self { Self { - msg: covenant_two_party_pol_holder::msg::InstantiateMsg { + msg: valence_two_party_pol_holder::msg::InstantiateMsg { clock_address, next_contract, lockup_config, @@ -63,7 +63,7 @@ impl TwoPartyHolderInstantiate { pub fn with_ragequit_config( &mut self, - config: covenant_two_party_pol_holder::msg::RagequitConfig, + config: valence_two_party_pol_holder::msg::RagequitConfig, ) -> &mut Self { self.msg.ragequit_config = config; self @@ -76,7 +76,7 @@ impl TwoPartyHolderInstantiate { pub fn with_covenant_config( &mut self, - config: covenant_two_party_pol_holder::msg::TwoPartyPolCovenantConfig, + config: valence_two_party_pol_holder::msg::TwoPartyPolCovenantConfig, ) -> &mut Self { self.msg.covenant_config = config; self @@ -115,28 +115,28 @@ impl TwoPartyHolderInstantiate { denom_to_split_config_map.insert(DENOM_LS_ATOM_ON_NTRN.to_string(), split_config.clone()); Self { - msg: covenant_two_party_pol_holder::msg::InstantiateMsg { + msg: valence_two_party_pol_holder::msg::InstantiateMsg { clock_address, next_contract, lockup_config: Expiration::AtHeight(200000), - ragequit_config: covenant_two_party_pol_holder::msg::RagequitConfig::Disabled {}, + ragequit_config: valence_two_party_pol_holder::msg::RagequitConfig::Disabled {}, deposit_deadline: Expiration::AtHeight(100000), - covenant_config: covenant_two_party_pol_holder::msg::TwoPartyPolCovenantConfig { - party_a: covenant_two_party_pol_holder::msg::TwoPartyPolCovenantParty { + covenant_config: valence_two_party_pol_holder::msg::TwoPartyPolCovenantConfig { + party_a: valence_two_party_pol_holder::msg::TwoPartyPolCovenantParty { contribution: coin(10_000, DENOM_ATOM_ON_NTRN), host_addr: party_a_addr.to_string(), controller_addr: party_a_addr.to_string(), allocation: Decimal::from_str("0.5").unwrap(), router: party_a_addr.to_string(), }, - party_b: covenant_two_party_pol_holder::msg::TwoPartyPolCovenantParty { + party_b: valence_two_party_pol_holder::msg::TwoPartyPolCovenantParty { contribution: coin(10_000, DENOM_LS_ATOM_ON_NTRN), host_addr: party_b_addr.to_string(), controller_addr: party_b_addr.to_string(), allocation: Decimal::from_str("0.5").unwrap(), router: party_b_addr.to_string(), }, - covenant_type: covenant_two_party_pol_holder::msg::CovenantType::Share {}, + covenant_type: valence_two_party_pol_holder::msg::CovenantType::Share {}, }, splits: denom_to_split_config_map, fallback_split: None, diff --git a/unit-tests/src/test_astroport_liquid_pooler/suite.rs b/unit-tests/src/test_astroport_liquid_pooler/suite.rs index ed448e2a..ea888954 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/suite.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/suite.rs @@ -1,9 +1,9 @@ use astroport::factory::PairType; use cosmwasm_std::{coin, Addr, Coin, Decimal}; -use covenant_astroport_liquid_pooler::msg::{LpConfig, ProvidedLiquidityInfo, QueryMsg}; use covenant_utils::{PoolPriceConfig, SingleSideLpLimits}; use cw_multi_test::{AppResponse, Executor}; use cw_utils::Expiration; +use valence_astroport_liquid_pooler::msg::{LpConfig, ProvidedLiquidityInfo, QueryMsg}; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -38,7 +38,7 @@ impl Default for AstroLiquidPoolerBuilder { SINGLE_PARTY_HOLDER_SALT, ); - let holder_instantiate_msg = covenant_single_party_pol_holder::msg::InstantiateMsg { + let holder_instantiate_msg = valence_single_party_pol_holder::msg::InstantiateMsg { withdrawer: clock_addr.to_string(), withdraw_to: holder_addr.to_string(), emergency_committee_addr: None, @@ -46,7 +46,7 @@ impl Default for AstroLiquidPoolerBuilder { lockup_period: cw_utils::Expiration::AtHeight(123665), }; - let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: None, whitelist: vec![liquid_pooler_addr.to_string()], }; @@ -107,7 +107,7 @@ impl AstroLiquidPoolerBuilder { self } - pub fn with_assets(mut self, assets: covenant_astroport_liquid_pooler::msg::AssetData) -> Self { + pub fn with_assets(mut self, assets: valence_astroport_liquid_pooler::msg::AssetData) -> Self { self.instantiate_msg.with_assets(assets); self } @@ -216,7 +216,7 @@ impl Suite { app.execute_contract( sender.clone(), holder, - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap() @@ -229,7 +229,7 @@ impl Suite { .wrap() .query_wasm_smart( holder.to_string(), - &covenant_single_party_pol_holder::msg::QueryMsg::LockupConfig {}, + &valence_single_party_pol_holder::msg::QueryMsg::LockupConfig {}, ) .unwrap(); let app = self.get_app(); @@ -245,19 +245,19 @@ impl Suite { .wrap() .query_wasm_smart( self.liquid_pooler_addr.clone(), - &covenant_astroport_liquid_pooler::msg::QueryMsg::ProvidedLiquidityInfo {}, + &valence_astroport_liquid_pooler::msg::QueryMsg::ProvidedLiquidityInfo {}, ) .unwrap() } pub(crate) fn query_contract_state( &self, - ) -> covenant_astroport_liquid_pooler::msg::ContractState { + ) -> valence_astroport_liquid_pooler::msg::ContractState { self.get_app() .wrap() .query_wasm_smart( self.liquid_pooler_addr.clone(), - &covenant_astroport_liquid_pooler::msg::QueryMsg::ContractState {}, + &valence_astroport_liquid_pooler::msg::QueryMsg::ContractState {}, ) .unwrap() } @@ -267,7 +267,7 @@ impl Suite { .wrap() .query_wasm_smart( self.liquid_pooler_addr.clone(), - &covenant_astroport_liquid_pooler::msg::QueryMsg::ClockAddress {}, + &valence_astroport_liquid_pooler::msg::QueryMsg::ClockAddress {}, ) .unwrap() } @@ -277,7 +277,7 @@ impl Suite { .wrap() .query_wasm_smart( self.liquid_pooler_addr.clone(), - &covenant_astroport_liquid_pooler::msg::QueryMsg::HolderAddress {}, + &valence_astroport_liquid_pooler::msg::QueryMsg::HolderAddress {}, ) .unwrap() } @@ -287,7 +287,7 @@ impl Suite { .wrap() .query_wasm_smart( self.liquid_pooler_addr.clone(), - &covenant_astroport_liquid_pooler::msg::QueryMsg::LpConfig {}, + &valence_astroport_liquid_pooler::msg::QueryMsg::LpConfig {}, ) .unwrap() } diff --git a/unit-tests/src/test_astroport_liquid_pooler/tests.rs b/unit-tests/src/test_astroport_liquid_pooler/tests.rs index 29fe421d..ad920c15 100644 --- a/unit-tests/src/test_astroport_liquid_pooler/tests.rs +++ b/unit-tests/src/test_astroport_liquid_pooler/tests.rs @@ -1,9 +1,9 @@ use std::str::FromStr; use cosmwasm_std::{coin, coins, Addr, Decimal, Event, Uint128}; -use covenant_astroport_liquid_pooler::msg::{AssetData, ProvidedLiquidityInfo}; use covenant_utils::PoolPriceConfig; use cw_multi_test::Executor; +use valence_astroport_liquid_pooler::msg::{AssetData, ProvidedLiquidityInfo}; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -92,7 +92,7 @@ fn test_withdraw_validates_percentage_range_ceiling() { .execute_contract( holder.clone(), suite.liquid_pooler_addr.clone(), - &covenant_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { + &valence_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { percentage: Some(Decimal::from_str("101.0").unwrap()), }, &[], @@ -122,7 +122,7 @@ fn test_withdraw_validates_percentage_range_floor() { .execute_contract( holder.clone(), suite.liquid_pooler_addr.clone(), - &covenant_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { + &valence_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { percentage: Some(Decimal::from_str("0.0").unwrap()), }, &[], @@ -141,7 +141,7 @@ fn test_withdraw_validates_holder() { .execute_contract( not_the_holder, suite.liquid_pooler_addr.clone(), - &covenant_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { percentage: None }, + &valence_astroport_liquid_pooler::msg::ExecuteMsg::Withdraw { percentage: None }, &[], ) .unwrap(); @@ -216,7 +216,7 @@ fn test_tick_unauthorized() { .execute_contract( unauthorized_sender, suite.liquid_pooler_addr.clone(), - &covenant_clock::msg::ExecuteMsg::Tick {}, + &valence_clock::msg::ExecuteMsg::Tick {}, &[], ) .unwrap(); @@ -801,7 +801,7 @@ fn test_migrate_update_config() { .migrate_contract( Addr::unchecked(ADMIN), liquid_pooler, - &covenant_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { + &valence_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { clock_addr: Some(holder.to_string()), holder_address: Some(clock.to_string()), lp_config: Some(Box::new(lp_config)), @@ -820,6 +820,6 @@ fn test_migrate_update_config() { assert_eq!(clock_address, holder); assert_eq!( contract_state, - covenant_astroport_liquid_pooler::msg::ContractState::Instantiated {} + valence_astroport_liquid_pooler::msg::ContractState::Instantiated {} ); } diff --git a/unit-tests/src/test_ibc_forwarder/suite.rs b/unit-tests/src/test_ibc_forwarder/suite.rs index 6a4850d3..ce78c945 100644 --- a/unit-tests/src/test_ibc_forwarder/suite.rs +++ b/unit-tests/src/test_ibc_forwarder/suite.rs @@ -28,7 +28,7 @@ impl IbcForwarderBuilder { let next_contract_addr = builder.get_contract_addr(builder.ibc_forwarder_code_id, "deposit_forwarder"); - let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: None, whitelist: vec![ ibc_forwarder_addr.to_string(), @@ -125,7 +125,7 @@ impl IbcForwarderBuilder { .wrap() .query_wasm_smart( ibc_forwarder_address.clone(), - &covenant_ibc_forwarder::msg::QueryMsg::ClockAddress {}, + &valence_ibc_forwarder::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -135,7 +135,7 @@ impl IbcForwarderBuilder { .wrap() .query_wasm_smart( ibc_forwarder_address.clone(), - &covenant_ibc_forwarder::msg::QueryMsg::RemoteChainInfo {}, + &valence_ibc_forwarder::msg::QueryMsg::RemoteChainInfo {}, ) .unwrap(); @@ -145,7 +145,7 @@ impl IbcForwarderBuilder { .wrap() .query_wasm_smart( ibc_forwarder_address.clone(), - &covenant_ibc_forwarder::msg::QueryMsg::DepositAddress {}, + &valence_ibc_forwarder::msg::QueryMsg::DepositAddress {}, ) .unwrap(); @@ -179,7 +179,7 @@ impl Suite { .wrap() .query_wasm_smart( self.ibc_forwarder.clone(), - &covenant_ibc_forwarder::msg::QueryMsg::DepositAddress {}, + &valence_ibc_forwarder::msg::QueryMsg::DepositAddress {}, ) .unwrap() } @@ -189,7 +189,7 @@ impl Suite { .wrap() .query_wasm_smart( self.ibc_forwarder.clone(), - &covenant_ibc_forwarder::msg::QueryMsg::RemoteChainInfo {}, + &valence_ibc_forwarder::msg::QueryMsg::RemoteChainInfo {}, ) .unwrap() } @@ -199,17 +199,17 @@ impl Suite { .wrap() .query_wasm_smart( self.ibc_forwarder.clone(), - &covenant_ibc_forwarder::msg::QueryMsg::ClockAddress {}, + &valence_ibc_forwarder::msg::QueryMsg::ClockAddress {}, ) .unwrap() } - pub(crate) fn query_contract_state(&mut self) -> covenant_ibc_forwarder::msg::ContractState { + pub(crate) fn query_contract_state(&mut self) -> valence_ibc_forwarder::msg::ContractState { self.app .wrap() .query_wasm_smart( self.ibc_forwarder.clone(), - &covenant_ibc_forwarder::msg::QueryMsg::ContractState {}, + &valence_ibc_forwarder::msg::QueryMsg::ContractState {}, ) .unwrap() } @@ -217,7 +217,7 @@ impl Suite { pub(crate) fn query_ica_address(&mut self, addr: Addr) -> Addr { self.app .wrap() - .query_wasm_smart(addr, &covenant_ibc_forwarder::msg::QueryMsg::IcaAddress {}) + .query_wasm_smart(addr, &valence_ibc_forwarder::msg::QueryMsg::IcaAddress {}) .unwrap() } @@ -239,7 +239,7 @@ impl Suite { .wrap() .query_wasm_smart( self.ibc_forwarder.clone(), - &covenant_ibc_forwarder::msg::QueryMsg::FallbackAddress {}, + &valence_ibc_forwarder::msg::QueryMsg::FallbackAddress {}, ) .unwrap() } @@ -274,7 +274,7 @@ impl Suite { .execute_contract( self.faucet.clone(), self.ibc_forwarder.clone(), - &covenant_ibc_forwarder::msg::ExecuteMsg::DistributeFallback { coins }, + &valence_ibc_forwarder::msg::ExecuteMsg::DistributeFallback { coins }, &funds, ) .unwrap() diff --git a/unit-tests/src/test_ibc_forwarder/tests.rs b/unit-tests/src/test_ibc_forwarder/tests.rs index 55a76531..048ebf13 100644 --- a/unit-tests/src/test_ibc_forwarder/tests.rs +++ b/unit-tests/src/test_ibc_forwarder/tests.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{coin, coins, Addr, Uint128}; -use covenant_ibc_forwarder::msg::{ContractState, FallbackAddressUpdateConfig}; use cw_multi_test::Executor; +use valence_ibc_forwarder::msg::{ContractState, FallbackAddressUpdateConfig}; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -35,7 +35,7 @@ fn test_tick_validates_clock() { .execute_contract( forwarder_addr.clone(), forwarder_addr.clone(), - &covenant_ibc_forwarder::msg::ExecuteMsg::Tick {}, + &valence_ibc_forwarder::msg::ExecuteMsg::Tick {}, &[], ) .unwrap(); @@ -383,7 +383,7 @@ fn test_migrate_update_config() { .migrate_contract( Addr::unchecked(ADMIN), forwarder_addr.clone(), - &covenant_ibc_forwarder::msg::MigrateMsg::UpdateConfig { + &valence_ibc_forwarder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(next_contract.to_string()), next_contract: Some(clock_addr.to_string()), remote_chain_info: Box::new(Some(remote_chain_info)), @@ -415,7 +415,7 @@ fn test_migrate_update_config_remove_fallback() { .migrate_contract( Addr::unchecked(ADMIN), suite.ibc_forwarder.clone(), - &covenant_ibc_forwarder::msg::MigrateMsg::UpdateConfig { + &valence_ibc_forwarder::msg::MigrateMsg::UpdateConfig { clock_addr: None, next_contract: None, remote_chain_info: Box::new(None), diff --git a/unit-tests/src/test_interchain_router/suite.rs b/unit-tests/src/test_interchain_router/suite.rs index 892d1aa3..d8be180c 100644 --- a/unit-tests/src/test_interchain_router/suite.rs +++ b/unit-tests/src/test_interchain_router/suite.rs @@ -21,7 +21,7 @@ impl Default for InterchainRouterBuilder { let interchain_router_addr = builder.get_contract_addr(builder.interchain_router_code_id, INTERCHAIN_ROUTER_SALT); - let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: None, whitelist: vec![interchain_router_addr.to_string()], }; @@ -76,7 +76,7 @@ impl InterchainRouterBuilder { .wrap() .query_wasm_smart( interchain_router_address.clone(), - &covenant_interchain_router::msg::QueryMsg::ClockAddress {}, + &valence_interchain_router::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -86,7 +86,7 @@ impl InterchainRouterBuilder { .wrap() .query_wasm_smart( interchain_router_address.clone(), - &covenant_interchain_router::msg::QueryMsg::ReceiverConfig {}, + &valence_interchain_router::msg::QueryMsg::ReceiverConfig {}, ) .unwrap(); @@ -96,7 +96,7 @@ impl InterchainRouterBuilder { .wrap() .query_wasm_smart( interchain_router_address.clone(), - &covenant_interchain_router::msg::QueryMsg::TargetDenoms {}, + &valence_interchain_router::msg::QueryMsg::TargetDenoms {}, ) .unwrap(); diff --git a/unit-tests/src/test_native_router/suite.rs b/unit-tests/src/test_native_router/suite.rs index 793bf0c8..663350af 100644 --- a/unit-tests/src/test_native_router/suite.rs +++ b/unit-tests/src/test_native_router/suite.rs @@ -24,7 +24,7 @@ impl Default for NativeRouterBuilder { let native_router_addr = builder.get_contract_addr(builder.native_router_code_id, NATIVE_ROUTER_SALT); - let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: None, whitelist: vec![native_router_addr.to_string()], }; @@ -79,7 +79,7 @@ impl NativeRouterBuilder { .wrap() .query_wasm_smart( native_router_address.clone(), - &covenant_native_router::msg::QueryMsg::ClockAddress {}, + &valence_native_router::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -89,7 +89,7 @@ impl NativeRouterBuilder { .wrap() .query_wasm_smart( native_router_address.clone(), - &covenant_native_router::msg::QueryMsg::ReceiverConfig {}, + &valence_native_router::msg::QueryMsg::ReceiverConfig {}, ) .unwrap(); @@ -99,7 +99,7 @@ impl NativeRouterBuilder { .wrap() .query_wasm_smart( native_router_address.clone(), - &covenant_native_router::msg::QueryMsg::TargetDenoms {}, + &valence_native_router::msg::QueryMsg::TargetDenoms {}, ) .unwrap(); @@ -134,7 +134,7 @@ impl Suite { .wrap() .query_wasm_smart( self.router_addr.clone(), - &covenant_native_router::msg::QueryMsg::ReceiverConfig {}, + &valence_native_router::msg::QueryMsg::ReceiverConfig {}, ) .unwrap() } @@ -144,7 +144,7 @@ impl Suite { .wrap() .query_wasm_smart( self.router_addr.clone(), - &covenant_native_router::msg::QueryMsg::ClockAddress {}, + &valence_native_router::msg::QueryMsg::ClockAddress {}, ) .unwrap() } @@ -154,7 +154,7 @@ impl Suite { .wrap() .query_wasm_smart( self.router_addr.clone(), - &covenant_native_router::msg::QueryMsg::TargetDenoms {}, + &valence_native_router::msg::QueryMsg::TargetDenoms {}, ) .unwrap() } @@ -164,7 +164,7 @@ impl Suite { .execute_contract( self.receiver_addr.clone(), self.router_addr.clone(), - &covenant_native_router::msg::ExecuteMsg::DistributeFallback { denoms }, + &valence_native_router::msg::ExecuteMsg::DistributeFallback { denoms }, &[], ) .unwrap() diff --git a/unit-tests/src/test_native_router/tests.rs b/unit-tests/src/test_native_router/tests.rs index eee8178d..2a72746e 100644 --- a/unit-tests/src/test_native_router/tests.rs +++ b/unit-tests/src/test_native_router/tests.rs @@ -38,7 +38,7 @@ fn test_execute_tick_validates_clock_addr() { .execute_contract( not_the_clock, router, - &covenant_native_router::msg::ExecuteMsg::Tick {}, + &valence_native_router::msg::ExecuteMsg::Tick {}, &[], ) .unwrap(); @@ -151,7 +151,7 @@ fn test_migrate_update_config() { .migrate_contract( Addr::unchecked(ADMIN), router_addr, - &covenant_native_router::msg::MigrateMsg::UpdateConfig { + &valence_native_router::msg::MigrateMsg::UpdateConfig { clock_addr: Some(receiver_addr.to_string()), receiver_address: Some(clock_addr.to_string()), target_denoms: Some(target_denoms.clone().into_iter().collect()), diff --git a/unit-tests/src/test_native_splitter/suite.rs b/unit-tests/src/test_native_splitter/suite.rs index 19e2b2a4..65166192 100644 --- a/unit-tests/src/test_native_splitter/suite.rs +++ b/unit-tests/src/test_native_splitter/suite.rs @@ -24,7 +24,7 @@ impl Default for NativeSplitterBuilder { let native_splitter_addr = builder.get_contract_addr(builder.native_splitter_code_id, NATIVE_SPLITTER_SALT); - let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: None, whitelist: vec![native_splitter_addr.to_string()], }; @@ -82,7 +82,7 @@ impl NativeSplitterBuilder { .wrap() .query_wasm_smart( native_splitter_address.clone(), - &covenant_native_splitter::msg::QueryMsg::ClockAddress {}, + &valence_native_splitter::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -92,7 +92,7 @@ impl NativeSplitterBuilder { .wrap() .query_wasm_smart( native_splitter_address.clone(), - &covenant_native_splitter::msg::QueryMsg::Splits {}, + &valence_native_splitter::msg::QueryMsg::Splits {}, ) .unwrap(); let config_1 = splits[0].clone().1.receivers; @@ -106,7 +106,7 @@ impl NativeSplitterBuilder { .wrap() .query_wasm_smart( native_splitter_address.clone(), - &covenant_native_splitter::msg::QueryMsg::FallbackSplit {}, + &valence_native_splitter::msg::QueryMsg::FallbackSplit {}, ) .unwrap(); @@ -145,7 +145,7 @@ impl Suite { .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_native_splitter::msg::QueryMsg::ClockAddress {}, + &valence_native_splitter::msg::QueryMsg::ClockAddress {}, ) .unwrap() } @@ -155,7 +155,7 @@ impl Suite { .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_native_splitter::msg::QueryMsg::DenomSplit { denom }, + &valence_native_splitter::msg::QueryMsg::DenomSplit { denom }, ) .unwrap() } @@ -166,7 +166,7 @@ impl Suite { .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_native_splitter::msg::QueryMsg::Splits {}, + &valence_native_splitter::msg::QueryMsg::Splits {}, ) .unwrap(); BTreeMap::from_iter(splits) @@ -177,7 +177,7 @@ impl Suite { .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_native_splitter::msg::QueryMsg::FallbackSplit {}, + &valence_native_splitter::msg::QueryMsg::FallbackSplit {}, ) .unwrap() } @@ -187,7 +187,7 @@ impl Suite { .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_native_splitter::msg::QueryMsg::DepositAddress {}, + &valence_native_splitter::msg::QueryMsg::DepositAddress {}, ) .unwrap() } @@ -197,7 +197,7 @@ impl Suite { .execute_contract( self.faucet.clone(), self.splitter.clone(), - &covenant_native_splitter::msg::ExecuteMsg::DistributeFallback { denoms }, + &valence_native_splitter::msg::ExecuteMsg::DistributeFallback { denoms }, &[], ) .unwrap() diff --git a/unit-tests/src/test_native_splitter/tests.rs b/unit-tests/src/test_native_splitter/tests.rs index 82c175ba..0a0e42c2 100644 --- a/unit-tests/src/test_native_splitter/tests.rs +++ b/unit-tests/src/test_native_splitter/tests.rs @@ -95,7 +95,7 @@ fn test_execute_tick_validates_clock() { .execute_contract( suite.faucet, suite.splitter, - &covenant_native_splitter::msg::ExecuteMsg::Tick {}, + &valence_native_splitter::msg::ExecuteMsg::Tick {}, &[], ) .unwrap(); @@ -194,7 +194,7 @@ fn test_migrate_update_config() { .migrate_contract( Addr::unchecked(ADMIN), suite.splitter.clone(), - &covenant_native_splitter::msg::MigrateMsg::UpdateConfig { + &valence_native_splitter::msg::MigrateMsg::UpdateConfig { clock_addr: Some(suite.faucet.to_string()), fallback_split: Some(splits.get(DENOM_LS_ATOM_ON_NTRN).unwrap().clone()), splits: Some(splits.clone()), diff --git a/unit-tests/src/test_osmo_lp_outpost/suite.rs b/unit-tests/src/test_osmo_lp_outpost/suite.rs index 68830ecd..caffac09 100644 --- a/unit-tests/src/test_osmo_lp_outpost/suite.rs +++ b/unit-tests/src/test_osmo_lp_outpost/suite.rs @@ -2,20 +2,20 @@ use cosmwasm_std::{Addr, Coin}; use cw_multi_test::{AppResponse, Executor}; use crate::setup::{ - base_suite::BaseSuiteMut, instantiates::osmo_lp_outpost::OsmpLpOutpostInstantiate, + base_suite::BaseSuiteMut, instantiates::osmo_lp_outpost::OsmoLpOutpostInstantiate, suite_builder::SuiteBuilder, CustomApp, }; pub struct OsmoLpOutpostBuilder { pub builder: SuiteBuilder, - pub instantiate_msg: OsmpLpOutpostInstantiate, + pub instantiate_msg: OsmoLpOutpostInstantiate, } impl Default for OsmoLpOutpostBuilder { fn default() -> Self { Self { builder: SuiteBuilder::new(), - instantiate_msg: OsmpLpOutpostInstantiate::default(), + instantiate_msg: OsmoLpOutpostInstantiate::default(), } } } @@ -52,13 +52,13 @@ impl Suite { &mut self, funds: Vec, sender: Addr, - config: covenant_outpost_osmo_liquid_pooler::msg::OutpostProvideLiquidityConfig, + config: valence_outpost_osmo_liquid_pooler::msg::OutpostProvideLiquidityConfig, ) -> AppResponse { self.app .execute_contract( sender, self.outpost.clone(), - &covenant_outpost_osmo_liquid_pooler::msg::ExecuteMsg::ProvideLiquidity { config }, + &valence_outpost_osmo_liquid_pooler::msg::ExecuteMsg::ProvideLiquidity { config }, &funds, ) .unwrap() @@ -68,13 +68,13 @@ impl Suite { &mut self, funds: Vec, sender: Addr, - config: covenant_outpost_osmo_liquid_pooler::msg::OutpostWithdrawLiquidityConfig, + config: valence_outpost_osmo_liquid_pooler::msg::OutpostWithdrawLiquidityConfig, ) -> AppResponse { self.app .execute_contract( sender, self.outpost.clone(), - &covenant_outpost_osmo_liquid_pooler::msg::ExecuteMsg::WithdrawLiquidity { config }, + &valence_outpost_osmo_liquid_pooler::msg::ExecuteMsg::WithdrawLiquidity { config }, &funds, ) .unwrap() diff --git a/unit-tests/src/test_osmo_lp_outpost/tests.rs b/unit-tests/src/test_osmo_lp_outpost/tests.rs index 98ac30a4..f04bbf21 100644 --- a/unit-tests/src/test_osmo_lp_outpost/tests.rs +++ b/unit-tests/src/test_osmo_lp_outpost/tests.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use cosmwasm_std::{coin, coins, Decimal, Uint128, Uint64}; -use covenant_outpost_osmo_liquid_pooler::msg::{ +use valence_outpost_osmo_liquid_pooler::msg::{ OutpostProvideLiquidityConfig, OutpostWithdrawLiquidityConfig, }; diff --git a/unit-tests/src/test_remote_chain_splitter/suite.rs b/unit-tests/src/test_remote_chain_splitter/suite.rs index 7d4171ae..b4d50266 100644 --- a/unit-tests/src/test_remote_chain_splitter/suite.rs +++ b/unit-tests/src/test_remote_chain_splitter/suite.rs @@ -28,7 +28,7 @@ impl Default for RemoteChainSplitterBuilder { builder.get_contract_addr(builder.ibc_forwarder_code_id, "forwarder_a"); let forwarder_b_addr = builder.get_contract_addr(builder.ibc_forwarder_code_id, "forwarder_b"); - let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: None, whitelist: vec![ remote_chain_splitter_addr.to_string(), @@ -43,7 +43,7 @@ impl Default for RemoteChainSplitterBuilder { &[], ); - let default_forwarder_instantiate_msg = covenant_ibc_forwarder::msg::InstantiateMsg { + let default_forwarder_instantiate_msg = valence_ibc_forwarder::msg::InstantiateMsg { clock_address: clock_addr.to_string(), next_contract: clock_addr.to_string(), remote_chain_connection_id: "connection-0".to_string(), @@ -138,7 +138,7 @@ impl RemoteChainSplitterBuilder { .wrap() .query_wasm_smart( remote_chain_splitter_address.clone(), - &covenant_remote_chain_splitter::msg::QueryMsg::ClockAddress {}, + &valence_remote_chain_splitter::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -148,7 +148,7 @@ impl RemoteChainSplitterBuilder { .wrap() .query_wasm_smart( remote_chain_splitter_address.clone(), - &covenant_remote_chain_splitter::msg::QueryMsg::SplitConfig {}, + &valence_remote_chain_splitter::msg::QueryMsg::SplitConfig {}, ) .unwrap(); let config_1 = split_config[0].clone().1.receivers; @@ -162,7 +162,7 @@ impl RemoteChainSplitterBuilder { .wrap() .query_wasm_smart( remote_chain_splitter_address.clone(), - &covenant_remote_chain_splitter::msg::QueryMsg::TransferAmount {}, + &valence_remote_chain_splitter::msg::QueryMsg::TransferAmount {}, ) .unwrap(); @@ -172,7 +172,7 @@ impl RemoteChainSplitterBuilder { .wrap() .query_wasm_smart( remote_chain_splitter_address.clone(), - &covenant_remote_chain_splitter::msg::QueryMsg::RemoteChainInfo {}, + &valence_remote_chain_splitter::msg::QueryMsg::RemoteChainInfo {}, ) .unwrap(); @@ -214,17 +214,17 @@ impl Suite { .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_remote_chain_splitter::msg::QueryMsg::ClockAddress {}, + &valence_remote_chain_splitter::msg::QueryMsg::ClockAddress {}, ) .unwrap() } - pub fn query_contract_state(&self) -> covenant_remote_chain_splitter::msg::ContractState { + pub fn query_contract_state(&self) -> valence_remote_chain_splitter::msg::ContractState { self.app .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_remote_chain_splitter::msg::QueryMsg::ContractState {}, + &valence_remote_chain_splitter::msg::QueryMsg::ContractState {}, ) .unwrap() } @@ -234,7 +234,7 @@ impl Suite { .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_remote_chain_splitter::msg::QueryMsg::RemoteChainInfo {}, + &valence_remote_chain_splitter::msg::QueryMsg::RemoteChainInfo {}, ) .unwrap() } @@ -245,7 +245,7 @@ impl Suite { .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_remote_chain_splitter::msg::QueryMsg::SplitConfig {}, + &valence_remote_chain_splitter::msg::QueryMsg::SplitConfig {}, ) .unwrap(); BTreeMap::from_iter(split_config) @@ -256,7 +256,7 @@ impl Suite { .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_remote_chain_splitter::msg::QueryMsg::TransferAmount {}, + &valence_remote_chain_splitter::msg::QueryMsg::TransferAmount {}, ) .unwrap() } @@ -266,7 +266,7 @@ impl Suite { .wrap() .query_wasm_smart( addr, - &covenant_remote_chain_splitter::msg::QueryMsg::DepositAddress {}, + &valence_remote_chain_splitter::msg::QueryMsg::DepositAddress {}, ) .unwrap() } @@ -276,7 +276,7 @@ impl Suite { .wrap() .query_wasm_smart( self.splitter.clone(), - &covenant_remote_chain_splitter::msg::QueryMsg::FallbackAddress {}, + &valence_remote_chain_splitter::msg::QueryMsg::FallbackAddress {}, ) .unwrap() } @@ -286,7 +286,7 @@ impl Suite { .execute_contract( self.faucet.clone(), self.splitter.clone(), - &covenant_remote_chain_splitter::msg::ExecuteMsg::DistributeFallback { coins }, + &valence_remote_chain_splitter::msg::ExecuteMsg::DistributeFallback { coins }, &funds, ) .unwrap() @@ -297,7 +297,7 @@ impl Suite { .wrap() .query_wasm_smart( addr, - &covenant_remote_chain_splitter::msg::QueryMsg::IcaAddress {}, + &valence_remote_chain_splitter::msg::QueryMsg::IcaAddress {}, ) .unwrap() } diff --git a/unit-tests/src/test_remote_chain_splitter/tests.rs b/unit-tests/src/test_remote_chain_splitter/tests.rs index e4a74ce0..bacb3f7e 100644 --- a/unit-tests/src/test_remote_chain_splitter/tests.rs +++ b/unit-tests/src/test_remote_chain_splitter/tests.rs @@ -1,9 +1,9 @@ use std::{collections::BTreeMap, str::FromStr}; use cosmwasm_std::{coin, coins, Addr, Decimal, Uint128}; -use covenant_remote_chain_splitter::msg::FallbackAddressUpdateConfig; use covenant_utils::split::SplitConfig; use cw_multi_test::Executor; +use valence_remote_chain_splitter::msg::FallbackAddressUpdateConfig; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -69,7 +69,7 @@ fn test_execute_tick_validates_clock() { .execute_contract( suite.faucet, suite.splitter, - &covenant_remote_chain_splitter::msg::ExecuteMsg::Tick {}, + &valence_remote_chain_splitter::msg::ExecuteMsg::Tick {}, &[], ) .unwrap(); @@ -241,7 +241,7 @@ fn test_migrate_update_config() { .migrate_contract( Addr::unchecked(ADMIN), suite.splitter.clone(), - &covenant_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { + &valence_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { clock_addr: Some(suite.faucet.to_string()), remote_chain_info: Some(remote_chain_info.clone()), splits: Some(split_config.clone()), @@ -276,7 +276,7 @@ fn test_migrate_update_config_disable_fallback() { .migrate_contract( Addr::unchecked(ADMIN), suite.splitter.clone(), - &covenant_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { + &valence_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { clock_addr: None, remote_chain_info: None, splits: None, @@ -315,7 +315,7 @@ fn test_migrate_update_config_validates_splits() { .migrate_contract( Addr::unchecked(ADMIN), suite.splitter.clone(), - &covenant_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { + &valence_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { clock_addr: None, remote_chain_info: None, splits: Some(split_config.clone()), diff --git a/unit-tests/src/test_single_party_covenant/suite.rs b/unit-tests/src/test_single_party_covenant/suite.rs index b6025fd9..713d0bd0 100644 --- a/unit-tests/src/test_single_party_covenant/suite.rs +++ b/unit-tests/src/test_single_party_covenant/suite.rs @@ -1,8 +1,8 @@ use std::{collections::BTreeMap, str::FromStr}; use cosmwasm_std::{coin, Addr, Coin, Decimal, StdResult}; -use covenant_single_party_pol::msg::CovenantContractCodeIds; use cw_multi_test::Executor; +use valence_covenant_single_party_pol::msg::CovenantContractCodeIds; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -74,7 +74,7 @@ impl Suite { .wrap() .query_wasm_smart( covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::ClockAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -83,7 +83,7 @@ impl Suite { .wrap() .query_wasm_smart( covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::HolderAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::HolderAddress {}, ) .unwrap(); @@ -92,7 +92,7 @@ impl Suite { .wrap() .query_wasm_smart::( covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::SplitterAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::SplitterAddress {}, ) .unwrap(); builder.fund_with_ntrn(&splitter_addr, 2_000_000_u128); @@ -102,7 +102,7 @@ impl Suite { .wrap() .query_wasm_smart::( covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, ) .unwrap(); builder.fund_with_ntrn(&router_addr, 2_000_000_u128); @@ -112,7 +112,7 @@ impl Suite { .wrap() .query_wasm_smart::( covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::LiquidStakerAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::LiquidStakerAddress {}, ) .unwrap(); builder.fund_with_ntrn(&lser_addr, 2_000_000_u128); @@ -122,7 +122,7 @@ impl Suite { .wrap() .query_wasm_smart::( covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::IbcForwarderAddress { + &valence_covenant_single_party_pol::msg::QueryMsg::IbcForwarderAddress { ty: "ls".to_string(), }, ) @@ -134,7 +134,7 @@ impl Suite { .wrap() .query_wasm_smart::( covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::LiquidPoolerAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::LiquidPoolerAddress {}, ) .unwrap(); let lp_forwarder_addr = builder @@ -142,7 +142,7 @@ impl Suite { .wrap() .query_wasm_smart::( covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::IbcForwarderAddress { + &valence_covenant_single_party_pol::msg::QueryMsg::IbcForwarderAddress { ty: "lp".to_string(), }, ) @@ -416,7 +416,7 @@ impl Suite { .wrap() .query_wasm_smart::( &addr, - &covenant_remote_chain_splitter::msg::QueryMsg::IcaAddress {}, + &valence_remote_chain_splitter::msg::QueryMsg::IcaAddress {}, ) .is_err() { @@ -427,7 +427,7 @@ impl Suite { .wrap() .query_wasm_smart::( addr, - &covenant_remote_chain_splitter::msg::QueryMsg::IcaAddress {}, + &valence_remote_chain_splitter::msg::QueryMsg::IcaAddress {}, ) .unwrap() } @@ -459,7 +459,7 @@ impl Suite { pub fn query_deposit_addr(&self) -> StdResult { self.app.wrap().query_wasm_smart( self.covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::PartyDepositAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::PartyDepositAddress {}, ) } @@ -468,7 +468,7 @@ impl Suite { .wrap() .query_wasm_smart::( self.covenant_addr.clone(), - &covenant_two_party_pol::msg::QueryMsg::ContractCodes {}, + &valence_covenant_two_party_pol::msg::QueryMsg::ContractCodes {}, ) .unwrap() } diff --git a/unit-tests/src/test_single_party_covenant/test.rs b/unit-tests/src/test_single_party_covenant/test.rs index 01ce9eb6..b07a2599 100644 --- a/unit-tests/src/test_single_party_covenant/test.rs +++ b/unit-tests/src/test_single_party_covenant/test.rs @@ -17,7 +17,7 @@ fn test_covenant() { .execute_contract( suite.admin.clone(), suite.lser_addr.clone(), - &covenant_stride_liquid_staker::msg::ExecuteMsg::Transfer { + &valence_stride_liquid_staker::msg::ExecuteMsg::Transfer { amount: 500_000_000_000_u128.into(), }, &[], @@ -117,7 +117,7 @@ fn test_covenant() { .execute_contract( suite.admin.clone(), suite.lser_addr.clone(), - &covenant_stride_liquid_staker::msg::ExecuteMsg::Transfer { + &valence_stride_liquid_staker::msg::ExecuteMsg::Transfer { amount: 500_000_000_000_u128.into(), }, &[], @@ -170,7 +170,7 @@ fn test_covenant() { .execute_contract( suite.party_local_receiver.clone(), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap_err(); @@ -186,7 +186,7 @@ fn test_covenant() { .execute_contract( suite.party_local_receiver.clone(), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap(); @@ -196,7 +196,7 @@ fn test_covenant() { .wrap() .query_wasm_smart::( suite.covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, ) .unwrap(); @@ -311,7 +311,7 @@ fn test_covenant_with_xyk_pool() { .execute_contract( suite.admin.clone(), suite.lser_addr.clone(), - &covenant_stride_liquid_staker::msg::ExecuteMsg::Transfer { + &valence_stride_liquid_staker::msg::ExecuteMsg::Transfer { amount: 500_000_000_000_u128.into(), }, &[], @@ -364,7 +364,7 @@ fn test_covenant_with_xyk_pool() { .execute_contract( suite.party_local_receiver.clone(), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap_err(); @@ -380,7 +380,7 @@ fn test_covenant_with_xyk_pool() { .execute_contract( suite.party_local_receiver.clone(), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap(); @@ -390,7 +390,7 @@ fn test_covenant_with_xyk_pool() { .wrap() .query_wasm_smart::( suite.covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, ) .unwrap(); @@ -507,7 +507,7 @@ fn test_covenant_with_uneven_pool() { .execute_contract( suite.admin.clone(), suite.lser_addr.clone(), - &covenant_stride_liquid_staker::msg::ExecuteMsg::Transfer { + &valence_stride_liquid_staker::msg::ExecuteMsg::Transfer { amount: 500_000_000_000_u128.into(), }, &[], @@ -559,7 +559,7 @@ fn test_covenant_with_uneven_pool() { .execute_contract( suite.party_local_receiver.clone(), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap_err(); @@ -575,7 +575,7 @@ fn test_covenant_with_uneven_pool() { .execute_contract( suite.party_local_receiver.clone(), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap(); @@ -585,7 +585,7 @@ fn test_covenant_with_uneven_pool() { .wrap() .query_wasm_smart::( suite.covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, ) .unwrap(); @@ -703,7 +703,7 @@ fn test_covenant_with_uneven_pool_stable() { .execute_contract( suite.admin.clone(), suite.lser_addr.clone(), - &covenant_stride_liquid_staker::msg::ExecuteMsg::Transfer { + &valence_stride_liquid_staker::msg::ExecuteMsg::Transfer { amount: 500_000_000_000_u128.into(), }, &[], @@ -764,7 +764,7 @@ fn test_covenant_with_uneven_pool_stable() { .execute_contract( suite.party_local_receiver.clone(), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap_err(); @@ -780,7 +780,7 @@ fn test_covenant_with_uneven_pool_stable() { .execute_contract( suite.party_local_receiver.clone(), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap(); @@ -790,7 +790,7 @@ fn test_covenant_with_uneven_pool_stable() { .wrap() .query_wasm_smart::( suite.covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, ) .unwrap(); @@ -907,7 +907,7 @@ fn test_covenant_with_single_sided() { .execute_contract( suite.admin.clone(), suite.lser_addr.clone(), - &covenant_stride_liquid_staker::msg::ExecuteMsg::Transfer { + &valence_stride_liquid_staker::msg::ExecuteMsg::Transfer { amount: 500_000_000_000_u128.into(), }, &[], @@ -979,7 +979,7 @@ fn test_covenant_with_single_sided() { .execute_contract( suite.party_local_receiver.clone(), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap_err(); @@ -995,7 +995,7 @@ fn test_covenant_with_single_sided() { .execute_contract( suite.party_local_receiver.clone(), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap(); @@ -1005,7 +1005,7 @@ fn test_covenant_with_single_sided() { .wrap() .query_wasm_smart::( suite.covenant_addr.clone(), - &covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, + &valence_covenant_single_party_pol::msg::QueryMsg::InterchainRouterAddress {}, ) .unwrap(); @@ -1043,7 +1043,7 @@ fn test_migrate_update_config_with_codes() { let mut contract_codes = suite.query_contract_codes(); contract_codes.clock_code = 69; - let holder_migrate_msg = covenant_single_party_pol_holder::msg::MigrateMsg::UpdateConfig { + let holder_migrate_msg = valence_single_party_pol_holder::msg::MigrateMsg::UpdateConfig { withdrawer: Some(covenant_addr.to_string()), withdraw_to: None, emergency_committee: None, @@ -1051,7 +1051,7 @@ fn test_migrate_update_config_with_codes() { lockup_period: None, }; - let ibc_forwarder_migrate_msg = covenant_ibc_forwarder::msg::MigrateMsg::UpdateConfig { + let ibc_forwarder_migrate_msg = valence_ibc_forwarder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), next_contract: None, remote_chain_info: Box::new(None), @@ -1060,7 +1060,7 @@ fn test_migrate_update_config_with_codes() { }; let liquid_pooler_migrate_msg = - covenant_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { + valence_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), holder_address: None, lp_config: None, @@ -1073,14 +1073,14 @@ fn test_migrate_update_config_with_codes() { ibc_transfer_timeout: Uint64::one(), ica_timeout: Uint64::one(), }; - let liquid_staker_migrate_msg = covenant_stride_liquid_staker::msg::MigrateMsg::UpdateConfig { + let liquid_staker_migrate_msg = valence_stride_liquid_staker::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), next_contract: Some(covenant_addr.to_string()), remote_chain_info: Some(new_remote_chain_info), }; let remote_chain_splitter_migrate_msg = - covenant_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { + valence_remote_chain_splitter::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), remote_chain_info: None, splits: None, @@ -1092,7 +1092,7 @@ fn test_migrate_update_config_with_codes() { .migrate_contract( Addr::unchecked(ADMIN), covenant_addr, - &covenant_single_party_pol::msg::MigrateMsg::MigrateContracts { + &valence_covenant_single_party_pol::msg::MigrateMsg::MigrateContracts { codes: Some(contract_codes.clone()), clock: None, holder: Some(holder_migrate_msg.clone()), @@ -1100,7 +1100,7 @@ fn test_migrate_update_config_with_codes() { lp_forwarder: Some(ibc_forwarder_migrate_msg.clone()), splitter: Some(remote_chain_splitter_migrate_msg.clone()), liquid_pooler: Some( - covenant_single_party_pol::msg::LiquidPoolerMigrateMsg::Astroport( + valence_covenant_single_party_pol::msg::LiquidPoolerMigrateMsg::Astroport( liquid_pooler_migrate_msg.clone(), ), ), @@ -1162,10 +1162,10 @@ fn test_migrate_update_config_no_codes() { let mut suite = Suite::new_with_stable_pool(); let covenant_addr = suite.covenant_addr.clone(); - let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { + let clock_migrate_msg = valence_clock::msg::MigrateMsg::UpdateTickMaxGas { new_value: Uint64::new(50000), }; - let router_migrate_msg = covenant_interchain_router::msg::MigrateMsg::UpdateConfig { + let router_migrate_msg = valence_interchain_router::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), destination_config: None, target_denoms: None, @@ -1175,7 +1175,7 @@ fn test_migrate_update_config_no_codes() { .migrate_contract( Addr::unchecked(ADMIN), covenant_addr, - &covenant_single_party_pol::msg::MigrateMsg::MigrateContracts { + &valence_covenant_single_party_pol::msg::MigrateMsg::MigrateContracts { codes: None, clock: Some(clock_migrate_msg.clone()), holder: None, diff --git a/unit-tests/src/test_single_party_holder/suite.rs b/unit-tests/src/test_single_party_holder/suite.rs index 9e91556e..5b37a0bc 100644 --- a/unit-tests/src/test_single_party_holder/suite.rs +++ b/unit-tests/src/test_single_party_holder/suite.rs @@ -36,7 +36,7 @@ impl Default for SinglePartyHolderBuilder { builder.get_contract_addr(builder.astro_pooler_code_id, ASTRO_LIQUID_POOLER_SALT); let clock_addr = builder.get_contract_addr(builder.clock_code_id, CLOCK_SALT); - let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: None, whitelist: vec![liquid_pooler_addr.to_string()], }; @@ -47,11 +47,11 @@ impl Default for SinglePartyHolderBuilder { &[], ); - let liquid_pooler_instantiate_msg = covenant_astroport_liquid_pooler::msg::InstantiateMsg { + let liquid_pooler_instantiate_msg = valence_astroport_liquid_pooler::msg::InstantiateMsg { pool_address: pool_addr.to_string(), clock_address: clock_addr.to_string(), slippage_tolerance: None, - assets: covenant_astroport_liquid_pooler::msg::AssetData { + assets: valence_astroport_liquid_pooler::msg::AssetData { asset_a_denom: DENOM_ATOM_ON_NTRN.to_string(), asset_b_denom: DENOM_LS_ATOM_ON_NTRN.to_string(), }, @@ -125,7 +125,7 @@ impl SinglePartyHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_single_party_pol_holder::msg::QueryMsg::PoolerAddress {}, + &valence_single_party_pol_holder::msg::QueryMsg::PoolerAddress {}, ) .unwrap(); @@ -135,7 +135,7 @@ impl SinglePartyHolderBuilder { .wrap() .query_wasm_smart( liquid_pooler_address.to_string(), - &covenant_astroport_liquid_pooler::msg::QueryMsg::ClockAddress {}, + &valence_astroport_liquid_pooler::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -145,7 +145,7 @@ impl SinglePartyHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_single_party_pol_holder::msg::QueryMsg::Withdrawer {}, + &valence_single_party_pol_holder::msg::QueryMsg::Withdrawer {}, ) .unwrap(); @@ -155,7 +155,7 @@ impl SinglePartyHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_single_party_pol_holder::msg::QueryMsg::WithdrawTo {}, + &valence_single_party_pol_holder::msg::QueryMsg::WithdrawTo {}, ) .unwrap(); @@ -194,7 +194,7 @@ impl Suite { .execute_contract( sender, holder, - &covenant_single_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap() @@ -207,7 +207,7 @@ impl Suite { .execute_contract( sender, holder, - &covenant_single_party_pol_holder::msg::ExecuteMsg::Distribute {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::Distribute {}, &funds, ) .unwrap() @@ -220,7 +220,7 @@ impl Suite { .execute_contract( sender, holder, - &covenant_single_party_pol_holder::msg::ExecuteMsg::WithdrawFailed {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::WithdrawFailed {}, &[], ) .unwrap() @@ -233,7 +233,7 @@ impl Suite { .execute_contract( sender, holder, - &covenant_single_party_pol_holder::msg::ExecuteMsg::EmergencyWithdraw {}, + &valence_single_party_pol_holder::msg::ExecuteMsg::EmergencyWithdraw {}, &[], ) .unwrap() @@ -265,7 +265,7 @@ impl Suite { .execute_contract( clock, pooler, - &covenant_astroport_liquid_pooler::msg::ExecuteMsg::Tick {}, + &valence_astroport_liquid_pooler::msg::ExecuteMsg::Tick {}, &[], ) .unwrap() @@ -276,7 +276,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::QueryMsg::Withdrawer {}, + &valence_single_party_pol_holder::msg::QueryMsg::Withdrawer {}, ) .unwrap() } @@ -286,7 +286,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::QueryMsg::WithdrawTo {}, + &valence_single_party_pol_holder::msg::QueryMsg::WithdrawTo {}, ) .unwrap() } @@ -296,7 +296,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::QueryMsg::PoolerAddress {}, + &valence_single_party_pol_holder::msg::QueryMsg::PoolerAddress {}, ) .unwrap() } @@ -306,7 +306,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::QueryMsg::EmergencyCommitteeAddr {}, + &valence_single_party_pol_holder::msg::QueryMsg::EmergencyCommitteeAddr {}, ) .unwrap() } @@ -316,7 +316,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::QueryMsg::LockupConfig {}, + &valence_single_party_pol_holder::msg::QueryMsg::LockupConfig {}, ) .unwrap() } diff --git a/unit-tests/src/test_single_party_holder/tests.rs b/unit-tests/src/test_single_party_holder/tests.rs index bd05d8cc..2474603f 100644 --- a/unit-tests/src/test_single_party_holder/tests.rs +++ b/unit-tests/src/test_single_party_holder/tests.rs @@ -203,7 +203,7 @@ fn test_migrate_update_config_validates_lockup_config() { .migrate_contract( Addr::unchecked(ADMIN), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::MigrateMsg::UpdateConfig { + &valence_single_party_pol_holder::msg::MigrateMsg::UpdateConfig { withdrawer: None, withdraw_to: None, emergency_committee: None, @@ -226,7 +226,7 @@ fn test_migrate_update_config() { .migrate_contract( Addr::unchecked(ADMIN), suite.holder_addr.clone(), - &covenant_single_party_pol_holder::msg::MigrateMsg::UpdateConfig { + &valence_single_party_pol_holder::msg::MigrateMsg::UpdateConfig { withdrawer: Some(clock.to_string()), withdraw_to: Some(clock.to_string()), emergency_committee: Some(clock.to_string()), diff --git a/unit-tests/src/test_swap_covenant/suite.rs b/unit-tests/src/test_swap_covenant/suite.rs index 57cd8976..bd821d56 100644 --- a/unit-tests/src/test_swap_covenant/suite.rs +++ b/unit-tests/src/test_swap_covenant/suite.rs @@ -1,8 +1,8 @@ use std::vec; use cosmwasm_std::{coins, Addr, Coin, Decimal, StdResult}; -use covenant_swap::msg::CovenantContractCodes; use cw_multi_test::Executor; +use valence_covenant_swap::msg::CovenantContractCodes; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -62,7 +62,7 @@ impl Suite { .wrap() .query_wasm_smart( covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::ClockAddress {}, + &valence_covenant_swap::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -71,7 +71,7 @@ impl Suite { .wrap() .query_wasm_smart( covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::HolderAddress {}, + &valence_covenant_swap::msg::QueryMsg::HolderAddress {}, ) .unwrap(); @@ -80,7 +80,7 @@ impl Suite { .wrap() .query_wasm_smart::( covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::InterchainRouterAddress { + &valence_covenant_swap::msg::QueryMsg::InterchainRouterAddress { party: "party_a".to_string(), }, ) @@ -91,7 +91,7 @@ impl Suite { .wrap() .query_wasm_smart::( covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::InterchainRouterAddress { + &valence_covenant_swap::msg::QueryMsg::InterchainRouterAddress { party: "party_b".to_string(), }, ) @@ -102,13 +102,13 @@ impl Suite { .wrap() .query_wasm_smart::( covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::SplitterAddress {}, + &valence_covenant_swap::msg::QueryMsg::SplitterAddress {}, ) .unwrap(); if let Ok(ibc_forwarder) = builder.app.wrap().query_wasm_smart::( covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::IbcForwarderAddress { + &valence_covenant_swap::msg::QueryMsg::IbcForwarderAddress { party: "party_a".to_string(), }, ) { @@ -124,7 +124,7 @@ impl Suite { if let Ok(ibc_forwarder) = builder.app.wrap().query_wasm_smart::( covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::IbcForwarderAddress { + &valence_covenant_swap::msg::QueryMsg::IbcForwarderAddress { party: "party_b".to_string(), }, ) { @@ -141,7 +141,7 @@ impl Suite { // fund routers if let Ok(router) = builder.app.wrap().query_wasm_smart::( covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::InterchainRouterAddress { + &valence_covenant_swap::msg::QueryMsg::InterchainRouterAddress { party: "party_a".to_string(), }, ) { @@ -153,7 +153,7 @@ impl Suite { if let Ok(router) = builder.app.wrap().query_wasm_smart::( covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::InterchainRouterAddress { + &valence_covenant_swap::msg::QueryMsg::InterchainRouterAddress { party: "party_b".to_string(), }, ) { @@ -541,7 +541,7 @@ impl Suite { pub fn query_deposit_addr(&self, party: &str) -> StdResult { self.app.wrap().query_wasm_smart( self.covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::PartyDepositAddress { + &valence_covenant_swap::msg::QueryMsg::PartyDepositAddress { party: party.to_string(), }, ) @@ -552,7 +552,7 @@ impl Suite { .wrap() .query_wasm_smart::( self.covenant_addr.clone(), - &covenant_swap::msg::QueryMsg::ContractCodes {}, + &valence_covenant_swap::msg::QueryMsg::ContractCodes {}, ) .unwrap() } diff --git a/unit-tests/src/test_swap_covenant/test.rs b/unit-tests/src/test_swap_covenant/test.rs index e2cf338e..66bfae44 100644 --- a/unit-tests/src/test_swap_covenant/test.rs +++ b/unit-tests/src/test_swap_covenant/test.rs @@ -239,7 +239,7 @@ fn test_covenant_fallback_split() { .execute_contract( suite.fuacet.clone(), suite.splitter_addr.clone(), - &covenant_native_splitter::msg::ExecuteMsg::DistributeFallback { + &valence_native_splitter::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, &[coin(1000000, DENOM_NTRN)], @@ -252,7 +252,7 @@ fn test_covenant_fallback_split() { .execute_contract( suite.fuacet.clone(), suite.router_a_addr.clone(), - &covenant_native_router::msg::ExecuteMsg::DistributeFallback { + &valence_native_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, &[coin(1000000, DENOM_NTRN)], @@ -264,7 +264,7 @@ fn test_covenant_fallback_split() { .execute_contract( suite.fuacet.clone(), suite.router_b_addr.clone(), - &covenant_native_router::msg::ExecuteMsg::DistributeFallback { + &valence_native_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, &[coin(1000000, DENOM_NTRN)], @@ -333,7 +333,7 @@ fn test_covenant_interchain_fallback_split() { .execute_contract( suite.fuacet.clone(), suite.splitter_addr.clone(), - &covenant_interchain_router::msg::ExecuteMsg::DistributeFallback { + &valence_interchain_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, &[coin(1000000, DENOM_NTRN)], @@ -346,7 +346,7 @@ fn test_covenant_interchain_fallback_split() { .execute_contract( suite.fuacet.clone(), suite.router_a_addr.clone(), - &covenant_interchain_router::msg::ExecuteMsg::DistributeFallback { + &valence_interchain_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, &[coin(100000000, DENOM_NTRN)], @@ -358,7 +358,7 @@ fn test_covenant_interchain_fallback_split() { .execute_contract( suite.fuacet.clone(), suite.router_b_addr.clone(), - &covenant_interchain_router::msg::ExecuteMsg::DistributeFallback { + &valence_interchain_router::msg::ExecuteMsg::DistributeFallback { denoms: vec![DENOM_FALLBACK.to_string()], }, &[coin(100000000, DENOM_NTRN)], @@ -396,7 +396,7 @@ fn test_covenant_interchain_fallback_split() { } #[test] -fn test_covenant_native_refund() { +fn test_valence_native_refund() { let mut suite = Suite::new_with_2_native_configs(); let init_ntrn_router_balance = suite.query_balance(&suite.router_b_addr, DENOM_NTRN); @@ -455,13 +455,13 @@ fn test_migrate_update_with_codes() { let mut contract_codes = suite.query_contract_codes(); contract_codes.clock = 1; - let native_router_migrate_msg = covenant_native_router::msg::MigrateMsg::UpdateConfig { + let native_router_migrate_msg = valence_native_router::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), target_denoms: None, receiver_address: None, }; - let holder_migrate_msg = covenant_swap_holder::msg::MigrateMsg::UpdateConfig { + let holder_migrate_msg = valence_swap_holder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), next_contract: None, lockup_config: None, @@ -470,7 +470,7 @@ fn test_migrate_update_with_codes() { refund_config: None, }; - let splitter_migrate_msg = covenant_native_splitter::msg::MigrateMsg::UpdateConfig { + let splitter_migrate_msg = valence_native_splitter::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), fallback_split: None, splits: None, @@ -481,15 +481,15 @@ fn test_migrate_update_with_codes() { .migrate_contract( Addr::unchecked(ADMIN), Addr::unchecked(covenant_addr), - &covenant_swap::msg::MigrateMsg::UpdateCovenant { + &valence_covenant_swap::msg::MigrateMsg::UpdateCovenant { codes: Some(contract_codes.clone()), clock: None, holder: Some(holder_migrate_msg.clone()), splitter: Some(splitter_migrate_msg.clone()), - party_a_router: Some(covenant_swap::msg::RouterMigrateMsg::Native( + party_a_router: Some(valence_covenant_swap::msg::RouterMigrateMsg::Native( native_router_migrate_msg.clone(), )), - party_b_router: Some(covenant_swap::msg::RouterMigrateMsg::Native( + party_b_router: Some(valence_covenant_swap::msg::RouterMigrateMsg::Native( native_router_migrate_msg.clone(), )), party_a_forwarder: Box::new(None), @@ -536,13 +536,13 @@ fn test_migrate_update_without_codes() { let mut suite = Suite::new_with_2_interchain_configs(); let covenant_addr = suite.covenant_addr.to_string(); - let interchain_router_migrate_msg = covenant_interchain_router::msg::MigrateMsg::UpdateConfig { + let interchain_router_migrate_msg = valence_interchain_router::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), target_denoms: None, destination_config: None, }; - let ibc_forwarder_migrate_msg = covenant_ibc_forwarder::msg::MigrateMsg::UpdateConfig { + let ibc_forwarder_migrate_msg = valence_ibc_forwarder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(covenant_addr.to_string()), next_contract: None, remote_chain_info: Box::new(None), @@ -550,7 +550,7 @@ fn test_migrate_update_without_codes() { fallback_address: None, }; - let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { + let clock_migrate_msg = valence_clock::msg::MigrateMsg::UpdateTickMaxGas { new_value: Uint64::new(50000), }; @@ -559,15 +559,15 @@ fn test_migrate_update_without_codes() { .migrate_contract( Addr::unchecked(ADMIN), Addr::unchecked(covenant_addr), - &covenant_swap::msg::MigrateMsg::UpdateCovenant { + &valence_covenant_swap::msg::MigrateMsg::UpdateCovenant { codes: None, clock: Some(clock_migrate_msg.clone()), holder: None, splitter: None, - party_a_router: Some(covenant_swap::msg::RouterMigrateMsg::Interchain( + party_a_router: Some(valence_covenant_swap::msg::RouterMigrateMsg::Interchain( interchain_router_migrate_msg.clone(), )), - party_b_router: Some(covenant_swap::msg::RouterMigrateMsg::Interchain( + party_b_router: Some(valence_covenant_swap::msg::RouterMigrateMsg::Interchain( interchain_router_migrate_msg.clone(), )), party_a_forwarder: Box::new(Some(ibc_forwarder_migrate_msg.clone())), diff --git a/unit-tests/src/test_swap_holder/suite.rs b/unit-tests/src/test_swap_holder/suite.rs index 41607eb0..01713c2d 100644 --- a/unit-tests/src/test_swap_holder/suite.rs +++ b/unit-tests/src/test_swap_holder/suite.rs @@ -11,9 +11,9 @@ use crate::setup::{ SWAP_HOLDER_SALT, }; use cosmwasm_std::{Addr, Decimal}; -use covenant_swap_holder::msg::RefundConfig; use covenant_utils::{split::SplitConfig, CovenantPartiesConfig, CovenantTerms}; use cw_utils::Expiration; +use valence_swap_holder::msg::RefundConfig; pub struct SwapHolderBuilder { pub builder: SuiteBuilder, @@ -37,7 +37,7 @@ impl Default for SwapHolderBuilder { let party_b_router_addr = builder.get_contract_addr(builder.native_router_code_id, "party_b"); - let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: None, whitelist: vec![ holder_addr.to_string(), @@ -59,7 +59,7 @@ impl Default for SwapHolderBuilder { builder.contract_init2( builder.native_router_code_id, "party_a", - &covenant_native_router::msg::InstantiateMsg { + &valence_native_router::msg::InstantiateMsg { clock_address: clock_addr.to_string(), receiver_address: party_a_controller_addr.to_string(), denoms: denom_set.clone(), @@ -69,7 +69,7 @@ impl Default for SwapHolderBuilder { builder.contract_init2( builder.native_router_code_id, "party_b", - &covenant_native_router::msg::InstantiateMsg { + &valence_native_router::msg::InstantiateMsg { clock_address: clock_addr.to_string(), receiver_address: party_b_controller_addr.to_string(), denoms: denom_set.clone(), @@ -92,7 +92,7 @@ impl Default for SwapHolderBuilder { denom_to_split_config_map.insert(DENOM_ATOM_ON_NTRN.to_string(), split_config.clone()); denom_to_split_config_map.insert(DENOM_LS_ATOM_ON_NTRN.to_string(), split_config.clone()); - let native_splitter_instantiate_msg = covenant_native_splitter::msg::InstantiateMsg { + let native_splitter_instantiate_msg = valence_native_splitter::msg::InstantiateMsg { clock_address: clock_addr.to_string(), splits: denom_to_split_config_map, fallback_split: None, @@ -162,7 +162,7 @@ impl SwapHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_swap_holder::msg::QueryMsg::ClockAddress {}, + &valence_swap_holder::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -172,7 +172,7 @@ impl SwapHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_swap_holder::msg::QueryMsg::LockupConfig {}, + &valence_swap_holder::msg::QueryMsg::LockupConfig {}, ) .unwrap(); @@ -182,7 +182,7 @@ impl SwapHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_swap_holder::msg::QueryMsg::NextContract {}, + &valence_swap_holder::msg::QueryMsg::NextContract {}, ) .unwrap(); @@ -192,7 +192,7 @@ impl SwapHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_swap_holder::msg::QueryMsg::CovenantParties {}, + &valence_swap_holder::msg::QueryMsg::CovenantParties {}, ) .unwrap(); @@ -202,7 +202,7 @@ impl SwapHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_swap_holder::msg::QueryMsg::CovenantTerms {}, + &valence_swap_holder::msg::QueryMsg::CovenantTerms {}, ) .unwrap(); @@ -237,7 +237,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder.clone(), - &covenant_swap_holder::msg::QueryMsg::NextContract {}, + &valence_swap_holder::msg::QueryMsg::NextContract {}, ) .unwrap() } @@ -247,7 +247,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder.clone(), - &covenant_swap_holder::msg::QueryMsg::LockupConfig {}, + &valence_swap_holder::msg::QueryMsg::LockupConfig {}, ) .unwrap() } @@ -257,7 +257,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder.clone(), - &covenant_swap_holder::msg::QueryMsg::CovenantParties {}, + &valence_swap_holder::msg::QueryMsg::CovenantParties {}, ) .unwrap() } @@ -267,7 +267,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder.clone(), - &covenant_swap_holder::msg::QueryMsg::CovenantTerms {}, + &valence_swap_holder::msg::QueryMsg::CovenantTerms {}, ) .unwrap() } @@ -277,17 +277,17 @@ impl Suite { .wrap() .query_wasm_smart( self.holder.clone(), - &covenant_swap_holder::msg::QueryMsg::ClockAddress {}, + &valence_swap_holder::msg::QueryMsg::ClockAddress {}, ) .unwrap() } - pub fn query_contract_state(&self) -> covenant_swap_holder::msg::ContractState { + pub fn query_contract_state(&self) -> valence_swap_holder::msg::ContractState { self.get_app() .wrap() .query_wasm_smart( self.holder.clone(), - &covenant_swap_holder::msg::QueryMsg::ContractState {}, + &valence_swap_holder::msg::QueryMsg::ContractState {}, ) .unwrap() } @@ -297,7 +297,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder.clone(), - &covenant_swap_holder::msg::QueryMsg::DepositAddress {}, + &valence_swap_holder::msg::QueryMsg::DepositAddress {}, ) .unwrap() } @@ -307,7 +307,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder.clone(), - &covenant_swap_holder::msg::QueryMsg::RefundConfig {}, + &valence_swap_holder::msg::QueryMsg::RefundConfig {}, ) .unwrap() } diff --git a/unit-tests/src/test_swap_holder/tests.rs b/unit-tests/src/test_swap_holder/tests.rs index 932e9fd3..91c2d55f 100644 --- a/unit-tests/src/test_swap_holder/tests.rs +++ b/unit-tests/src/test_swap_holder/tests.rs @@ -1,8 +1,8 @@ use cosmwasm_std::{coin, coins, Addr, Event, Uint128}; -use covenant_swap_holder::msg::{ContractState, RefundConfig}; use covenant_utils::{CovenantTerms, SwapCovenantTerms}; use cw_multi_test::Executor; use cw_utils::Expiration; +use valence_swap_holder::msg::{ContractState, RefundConfig}; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -69,7 +69,7 @@ fn test_execute_tick_validates_clock() { .execute_contract( suite.admin, suite.holder.clone(), - &covenant_swap_holder::msg::ExecuteMsg::Tick {}, + &valence_swap_holder::msg::ExecuteMsg::Tick {}, &[], ) .unwrap(); @@ -232,7 +232,7 @@ fn test_migrate_update_config() { .migrate_contract( Addr::unchecked(ADMIN), suite.holder.clone(), - &covenant_swap_holder::msg::MigrateMsg::UpdateConfig { + &valence_swap_holder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(next_contract.to_string()), next_contract: Some(clock_address.to_string()), lockup_config: Some(new_expiration), @@ -274,7 +274,7 @@ fn test_migrate_update_config_validates_lockup_config_expiration() { .migrate_contract( Addr::unchecked(ADMIN), suite.holder.clone(), - &covenant_swap_holder::msg::MigrateMsg::UpdateConfig { + &valence_swap_holder::msg::MigrateMsg::UpdateConfig { clock_addr: None, next_contract: None, lockup_config: Some(Expiration::AtHeight(1)), diff --git a/unit-tests/src/test_two_party_covenant/suite.rs b/unit-tests/src/test_two_party_covenant/suite.rs index 8b6f00e5..dce042b8 100644 --- a/unit-tests/src/test_two_party_covenant/suite.rs +++ b/unit-tests/src/test_two_party_covenant/suite.rs @@ -1,10 +1,10 @@ use std::collections::BTreeMap; use cosmwasm_std::{coin, Addr, Decimal, Uint64}; -use covenant_two_party_pol::msg::{CovenantContractCodes, Timeouts}; use covenant_utils::split::SplitConfig; use cw_multi_test::{AppResponse, Executor}; use cw_utils::Expiration; +use valence_covenant_two_party_pol::msg::{CovenantContractCodes, Timeouts}; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -55,7 +55,7 @@ impl TwoPartyCovenantBuilder { pub fn with_contract_codes( mut self, - contract_codes: covenant_two_party_pol::msg::CovenantContractCodeIds, + contract_codes: valence_covenant_two_party_pol::msg::CovenantContractCodeIds, ) -> Self { self.instantiate_msg.with_contract_codes(contract_codes); self @@ -74,7 +74,7 @@ impl TwoPartyCovenantBuilder { pub fn with_ragequit_config( mut self, - ragequit_config: Option, + ragequit_config: Option, ) -> Self { self.instantiate_msg.with_ragequit_config(ragequit_config); self @@ -87,7 +87,7 @@ impl TwoPartyCovenantBuilder { pub fn with_party_a_config( mut self, - party_a_config: covenant_two_party_pol::msg::CovenantPartyConfig, + party_a_config: valence_covenant_two_party_pol::msg::CovenantPartyConfig, ) -> Self { self.instantiate_msg.with_party_a_config(party_a_config); self @@ -95,7 +95,7 @@ impl TwoPartyCovenantBuilder { pub fn with_party_b_config( mut self, - party_b_config: covenant_two_party_pol::msg::CovenantPartyConfig, + party_b_config: valence_covenant_two_party_pol::msg::CovenantPartyConfig, ) -> Self { self.instantiate_msg.with_party_b_config(party_b_config); self @@ -103,7 +103,7 @@ impl TwoPartyCovenantBuilder { pub fn with_covenant_type( mut self, - covenant_type: covenant_two_party_pol_holder::msg::CovenantType, + covenant_type: valence_two_party_pol_holder::msg::CovenantType, ) -> Self { self.instantiate_msg.with_covenant_type(covenant_type); self @@ -146,7 +146,7 @@ impl TwoPartyCovenantBuilder { pub fn with_liquid_pooler_config( mut self, - liquid_pooler_config: covenant_two_party_pol::msg::LiquidPoolerConfig, + liquid_pooler_config: valence_covenant_two_party_pol::msg::LiquidPoolerConfig, ) -> Self { self.instantiate_msg .with_liquid_pooler_config(liquid_pooler_config); @@ -167,7 +167,7 @@ impl TwoPartyCovenantBuilder { .wrap() .query_wasm_smart( covenant_addr.clone(), - &covenant_two_party_pol::msg::QueryMsg::ClockAddress {}, + &valence_covenant_two_party_pol::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -177,7 +177,7 @@ impl TwoPartyCovenantBuilder { .wrap() .query_wasm_smart( covenant_addr.clone(), - &covenant_two_party_pol::msg::QueryMsg::HolderAddress {}, + &valence_covenant_two_party_pol::msg::QueryMsg::HolderAddress {}, ) .unwrap(); @@ -207,7 +207,7 @@ impl Suite { pub fn migrate_update( &mut self, code: u64, - msg: covenant_two_party_pol::msg::MigrateMsg, + msg: valence_covenant_two_party_pol::msg::MigrateMsg, ) -> AppResponse { self.app .migrate_contract( @@ -224,7 +224,7 @@ impl Suite { .wrap() .query_wasm_smart( self.covenant_addr.clone(), - &covenant_two_party_pol::msg::QueryMsg::ClockAddress {}, + &valence_covenant_two_party_pol::msg::QueryMsg::ClockAddress {}, ) .unwrap() } @@ -234,7 +234,7 @@ impl Suite { .wrap() .query_wasm_smart( self.covenant_addr.clone(), - &covenant_two_party_pol::msg::QueryMsg::HolderAddress {}, + &valence_covenant_two_party_pol::msg::QueryMsg::HolderAddress {}, ) .unwrap() } @@ -244,7 +244,7 @@ impl Suite { .wrap() .query_wasm_smart::( self.covenant_addr.clone(), - &covenant_two_party_pol::msg::QueryMsg::IbcForwarderAddress { + &valence_covenant_two_party_pol::msg::QueryMsg::IbcForwarderAddress { party: party.to_string(), }, ) @@ -256,7 +256,7 @@ impl Suite { .wrap() .query_wasm_smart::( self.covenant_addr.clone(), - &covenant_two_party_pol::msg::QueryMsg::LiquidPoolerAddress {}, + &valence_covenant_two_party_pol::msg::QueryMsg::LiquidPoolerAddress {}, ) .unwrap() } @@ -266,7 +266,7 @@ impl Suite { .wrap() .query_wasm_smart::( self.covenant_addr.clone(), - &covenant_two_party_pol::msg::QueryMsg::InterchainRouterAddress { + &valence_covenant_two_party_pol::msg::QueryMsg::InterchainRouterAddress { party: party.to_string(), }, ) @@ -278,7 +278,7 @@ impl Suite { .wrap() .query_wasm_smart::( self.covenant_addr.clone(), - &covenant_two_party_pol::msg::QueryMsg::ContractCodes {}, + &valence_covenant_two_party_pol::msg::QueryMsg::ContractCodes {}, ) .unwrap() } diff --git a/unit-tests/src/test_two_party_covenant/test.rs b/unit-tests/src/test_two_party_covenant/test.rs index 993deb4f..e6caf258 100644 --- a/unit-tests/src/test_two_party_covenant/test.rs +++ b/unit-tests/src/test_two_party_covenant/test.rs @@ -21,7 +21,7 @@ fn test_instantiate_party_a_interchain() { .get_final_receiver_address(); builder .with_party_a_config( - covenant_two_party_pol::msg::CovenantPartyConfig::Interchain( + valence_covenant_two_party_pol::msg::CovenantPartyConfig::Interchain( covenant_utils::InterchainCovenantParty { party_receiver_addr: party_address.to_string(), party_chain_connection_id: "connection-0".to_string(), @@ -50,7 +50,7 @@ fn test_instantiate_party_b_interchain() { .get_final_receiver_address(); builder .with_party_b_config( - covenant_two_party_pol::msg::CovenantPartyConfig::Interchain( + valence_covenant_two_party_pol::msg::CovenantPartyConfig::Interchain( covenant_utils::InterchainCovenantParty { party_receiver_addr: party_address.to_string(), party_chain_connection_id: "connection-0".to_string(), @@ -92,7 +92,7 @@ fn test_migrate_update_config_party_a_interchain() { .get_final_receiver_address(); let mut suite = builder .with_party_a_config( - covenant_two_party_pol::msg::CovenantPartyConfig::Interchain( + valence_covenant_two_party_pol::msg::CovenantPartyConfig::Interchain( covenant_utils::InterchainCovenantParty { party_receiver_addr: party_address.to_string(), party_chain_connection_id: "connection-0".to_string(), @@ -111,7 +111,7 @@ fn test_migrate_update_config_party_a_interchain() { .build(); let random_address = suite.faucet.clone(); - let holder_migrate_msg = covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + let holder_migrate_msg = valence_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), next_contract: None, emergency_committee: None, @@ -123,33 +123,35 @@ fn test_migrate_update_config_party_a_interchain() { fallback_split: None, }; let astro_liquid_pooler_migrate_msg = - covenant_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { + valence_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), holder_address: None, lp_config: None, }; - let liquid_pooler_migrate_msg = covenant_two_party_pol::msg::LiquidPoolerMigrateMsg::Astroport( - astro_liquid_pooler_migrate_msg.clone(), - ); + let liquid_pooler_migrate_msg = + valence_covenant_two_party_pol::msg::LiquidPoolerMigrateMsg::Astroport( + astro_liquid_pooler_migrate_msg.clone(), + ); let party_a_interchain_router_migrate_msg = - covenant_interchain_router::msg::MigrateMsg::UpdateConfig { + valence_interchain_router::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), destination_config: None, target_denoms: None, }; - let party_a_router_migrate_msg = covenant_two_party_pol::msg::RouterMigrateMsg::Interchain( - party_a_interchain_router_migrate_msg.clone(), - ); - let party_b_native_router_migrate_msg = covenant_native_router::msg::MigrateMsg::UpdateConfig { + let party_a_router_migrate_msg = + valence_covenant_two_party_pol::msg::RouterMigrateMsg::Interchain( + party_a_interchain_router_migrate_msg.clone(), + ); + let party_b_native_router_migrate_msg = valence_native_router::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), receiver_address: None, target_denoms: None, }; - let party_b_router_migrate_msg = covenant_two_party_pol::msg::RouterMigrateMsg::Native( + let party_b_router_migrate_msg = valence_covenant_two_party_pol::msg::RouterMigrateMsg::Native( party_b_native_router_migrate_msg.clone(), ); - let party_a_forwarder_migrate_msg = covenant_ibc_forwarder::msg::MigrateMsg::UpdateConfig { + let party_a_forwarder_migrate_msg = valence_ibc_forwarder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), next_contract: None, remote_chain_info: None.into(), @@ -160,7 +162,7 @@ fn test_migrate_update_config_party_a_interchain() { contract_codes.clock = 1; let resp = suite.migrate_update( 22, - covenant_two_party_pol::msg::MigrateMsg::UpdateCovenant { + valence_covenant_two_party_pol::msg::MigrateMsg::UpdateCovenant { codes: Some(contract_codes.clone()), clock: None, holder: Some(holder_migrate_msg.clone()), @@ -223,7 +225,7 @@ fn test_migrate_update_config_party_a_interchain() { .wrap() .query_wasm_smart( holder_address, - &covenant_two_party_pol_holder::msg::QueryMsg::ClockAddress {}, + &valence_two_party_pol_holder::msg::QueryMsg::ClockAddress {}, ) .unwrap(); assert_eq!(holder_clock_address, random_address); @@ -232,7 +234,7 @@ fn test_migrate_update_config_party_a_interchain() { .wrap() .query_wasm_smart( liquid_pooler_address, - &covenant_astroport_liquid_pooler::msg::QueryMsg::ClockAddress {}, + &valence_astroport_liquid_pooler::msg::QueryMsg::ClockAddress {}, ) .unwrap(); assert_eq!(liquid_pooler_clock_address, random_address); @@ -241,7 +243,7 @@ fn test_migrate_update_config_party_a_interchain() { .wrap() .query_wasm_smart( party_a_router_address, - &covenant_interchain_router::msg::QueryMsg::ClockAddress {}, + &valence_interchain_router::msg::QueryMsg::ClockAddress {}, ) .unwrap(); assert_eq!(party_a_router_clock_address, random_address); @@ -250,7 +252,7 @@ fn test_migrate_update_config_party_a_interchain() { .wrap() .query_wasm_smart( party_b_router_address, - &covenant_native_router::msg::QueryMsg::ClockAddress {}, + &valence_native_router::msg::QueryMsg::ClockAddress {}, ) .unwrap(); assert_eq!(party_b_router_clock_address, random_address); @@ -259,7 +261,7 @@ fn test_migrate_update_config_party_a_interchain() { .wrap() .query_wasm_smart( party_a_forwarder_address, - &covenant_ibc_forwarder::msg::QueryMsg::ClockAddress {}, + &valence_ibc_forwarder::msg::QueryMsg::ClockAddress {}, ) .unwrap(); assert_eq!(party_a_forwarder_clock_address, random_address); @@ -277,7 +279,7 @@ fn test_migrate_update_config_party_b_interchain() { .get_final_receiver_address(); let mut suite = builder .with_party_b_config( - covenant_two_party_pol::msg::CovenantPartyConfig::Interchain( + valence_covenant_two_party_pol::msg::CovenantPartyConfig::Interchain( covenant_utils::InterchainCovenantParty { party_receiver_addr: party_address.to_string(), party_chain_connection_id: "connection-0".to_string(), @@ -296,10 +298,10 @@ fn test_migrate_update_config_party_b_interchain() { .build(); let random_address = suite.faucet.clone(); - let clock_migrate_msg = covenant_clock::msg::MigrateMsg::UpdateTickMaxGas { + let clock_migrate_msg = valence_clock::msg::MigrateMsg::UpdateTickMaxGas { new_value: Uint64::new(500_000), }; - let holder_migrate_msg = covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + let holder_migrate_msg = valence_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), next_contract: None, emergency_committee: None, @@ -311,33 +313,35 @@ fn test_migrate_update_config_party_b_interchain() { fallback_split: None, }; let astro_liquid_pooler_migrate_msg = - covenant_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { + valence_astroport_liquid_pooler::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), holder_address: None, lp_config: None, }; - let liquid_pooler_migrate_msg = covenant_two_party_pol::msg::LiquidPoolerMigrateMsg::Astroport( - astro_liquid_pooler_migrate_msg.clone(), - ); + let liquid_pooler_migrate_msg = + valence_covenant_two_party_pol::msg::LiquidPoolerMigrateMsg::Astroport( + astro_liquid_pooler_migrate_msg.clone(), + ); let party_b_interchain_router_migrate_msg = - covenant_interchain_router::msg::MigrateMsg::UpdateConfig { + valence_interchain_router::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), destination_config: None, target_denoms: None, }; - let party_b_router_migrate_msg = covenant_two_party_pol::msg::RouterMigrateMsg::Interchain( - party_b_interchain_router_migrate_msg.clone(), - ); - let party_a_native_router_migrate_msg = covenant_native_router::msg::MigrateMsg::UpdateConfig { + let party_b_router_migrate_msg = + valence_covenant_two_party_pol::msg::RouterMigrateMsg::Interchain( + party_b_interchain_router_migrate_msg.clone(), + ); + let party_a_native_router_migrate_msg = valence_native_router::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), receiver_address: None, target_denoms: None, }; - let party_a_router_migrate_msg = covenant_two_party_pol::msg::RouterMigrateMsg::Native( + let party_a_router_migrate_msg = valence_covenant_two_party_pol::msg::RouterMigrateMsg::Native( party_a_native_router_migrate_msg.clone(), ); - let party_b_forwarder_migrate_msg = covenant_ibc_forwarder::msg::MigrateMsg::UpdateConfig { + let party_b_forwarder_migrate_msg = valence_ibc_forwarder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(random_address.to_string()), next_contract: None, remote_chain_info: None.into(), @@ -349,7 +353,7 @@ fn test_migrate_update_config_party_b_interchain() { let resp = suite.migrate_update( 22, - covenant_two_party_pol::msg::MigrateMsg::UpdateCovenant { + valence_covenant_two_party_pol::msg::MigrateMsg::UpdateCovenant { codes: Some(contract_codes.clone()), clock: Some(clock_migrate_msg.clone()), holder: Some(holder_migrate_msg.clone()), @@ -414,7 +418,7 @@ fn test_migrate_update_config_party_b_interchain() { let clock_max_gas: Uint64 = app .wrap() - .query_wasm_smart(clock_address, &covenant_clock::msg::QueryMsg::TickMaxGas {}) + .query_wasm_smart(clock_address, &valence_clock::msg::QueryMsg::TickMaxGas {}) .unwrap(); assert_eq!(clock_max_gas, Uint64::new(500_000)); @@ -422,7 +426,7 @@ fn test_migrate_update_config_party_b_interchain() { .wrap() .query_wasm_smart( holder_address, - &covenant_two_party_pol_holder::msg::QueryMsg::ClockAddress {}, + &valence_two_party_pol_holder::msg::QueryMsg::ClockAddress {}, ) .unwrap(); assert_eq!(holder_clock_address, random_address); @@ -431,7 +435,7 @@ fn test_migrate_update_config_party_b_interchain() { .wrap() .query_wasm_smart( liquid_pooler_address, - &covenant_astroport_liquid_pooler::msg::QueryMsg::ClockAddress {}, + &valence_astroport_liquid_pooler::msg::QueryMsg::ClockAddress {}, ) .unwrap(); assert_eq!(liquid_pooler_clock_address, random_address); @@ -440,7 +444,7 @@ fn test_migrate_update_config_party_b_interchain() { .wrap() .query_wasm_smart( party_b_router_address, - &covenant_interchain_router::msg::QueryMsg::ClockAddress {}, + &valence_interchain_router::msg::QueryMsg::ClockAddress {}, ) .unwrap(); assert_eq!(party_b_router_clock_address, random_address); @@ -449,7 +453,7 @@ fn test_migrate_update_config_party_b_interchain() { .wrap() .query_wasm_smart( party_a_router_address, - &covenant_native_router::msg::QueryMsg::ClockAddress {}, + &valence_native_router::msg::QueryMsg::ClockAddress {}, ) .unwrap(); assert_eq!(party_a_router_clock_address, random_address); @@ -458,7 +462,7 @@ fn test_migrate_update_config_party_b_interchain() { .wrap() .query_wasm_smart( party_b_forwarder_address, - &covenant_ibc_forwarder::msg::QueryMsg::ClockAddress {}, + &valence_ibc_forwarder::msg::QueryMsg::ClockAddress {}, ) .unwrap(); assert_eq!(party_b_forwarder_clock_address, random_address); diff --git a/unit-tests/src/test_two_party_pol_holder/suite.rs b/unit-tests/src/test_two_party_pol_holder/suite.rs index 82abca20..da003c0f 100644 --- a/unit-tests/src/test_two_party_pol_holder/suite.rs +++ b/unit-tests/src/test_two_party_pol_holder/suite.rs @@ -2,10 +2,10 @@ use std::collections::BTreeMap; use astroport::factory::PairType; use cosmwasm_std::{coin, Addr, Decimal, Uint128}; -use covenant_two_party_pol_holder::msg::{ContractState, DenomSplits, RagequitConfig}; use covenant_utils::{split::SplitConfig, PoolPriceConfig, SingleSideLpLimits}; use cw_multi_test::{AppResponse, Executor}; use cw_utils::Expiration; +use valence_two_party_pol_holder::msg::{ContractState, DenomSplits, RagequitConfig}; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -37,7 +37,7 @@ impl Default for TwoPartyHolderBuilder { coin(10_000_000_000_000, DENOM_LS_ATOM_ON_NTRN), ); - let clock_instantiate_msg = covenant_clock::msg::InstantiateMsg { + let clock_instantiate_msg = valence_clock::msg::InstantiateMsg { tick_max_gas: None, whitelist: vec![holder_addr.to_string(), liquid_pooler_addr.to_string()], }; @@ -48,11 +48,11 @@ impl Default for TwoPartyHolderBuilder { &[], ); - let liquid_pooler_instantiate_msg = covenant_astroport_liquid_pooler::msg::InstantiateMsg { + let liquid_pooler_instantiate_msg = valence_astroport_liquid_pooler::msg::InstantiateMsg { pool_address: pool_addr.to_string(), clock_address: clock_addr.to_string(), slippage_tolerance: None, - assets: covenant_astroport_liquid_pooler::msg::AssetData { + assets: valence_astroport_liquid_pooler::msg::AssetData { asset_a_denom: DENOM_ATOM_ON_NTRN.to_string(), asset_b_denom: DENOM_LS_ATOM_ON_NTRN.to_string(), }, @@ -111,7 +111,7 @@ impl TwoPartyHolderBuilder { pub fn with_ragequit_config( mut self, - config: covenant_two_party_pol_holder::msg::RagequitConfig, + config: valence_two_party_pol_holder::msg::RagequitConfig, ) -> Self { self.instantiate_msg.with_ragequit_config(config); self @@ -124,7 +124,7 @@ impl TwoPartyHolderBuilder { pub fn with_covenant_config( mut self, - config: covenant_two_party_pol_holder::msg::TwoPartyPolCovenantConfig, + config: valence_two_party_pol_holder::msg::TwoPartyPolCovenantConfig, ) -> Self { self.instantiate_msg.with_covenant_config(config); self @@ -159,7 +159,7 @@ impl TwoPartyHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::ClockAddress {}, + &valence_two_party_pol_holder::msg::QueryMsg::ClockAddress {}, ) .unwrap(); @@ -169,7 +169,7 @@ impl TwoPartyHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::RagequitConfig {}, + &valence_two_party_pol_holder::msg::QueryMsg::RagequitConfig {}, ) .unwrap(); @@ -179,7 +179,7 @@ impl TwoPartyHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::LockupConfig {}, + &valence_two_party_pol_holder::msg::QueryMsg::LockupConfig {}, ) .unwrap(); @@ -189,7 +189,7 @@ impl TwoPartyHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::DepositDeadline {}, + &valence_two_party_pol_holder::msg::QueryMsg::DepositDeadline {}, ) .unwrap(); @@ -199,7 +199,7 @@ impl TwoPartyHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::Config {}, + &valence_two_party_pol_holder::msg::QueryMsg::Config {}, ) .unwrap(); @@ -209,7 +209,7 @@ impl TwoPartyHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::DenomSplits {}, + &valence_two_party_pol_holder::msg::QueryMsg::DenomSplits {}, ) .unwrap(); @@ -219,7 +219,7 @@ impl TwoPartyHolderBuilder { .wrap() .query_wasm_smart( holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::NextContract {}, + &valence_two_party_pol_holder::msg::QueryMsg::NextContract {}, ) .unwrap(); @@ -253,9 +253,9 @@ pub struct Suite { pub clock_addr: Addr, pub next_contract: Addr, pub lockup_config: Expiration, - pub ragequit_config: covenant_two_party_pol_holder::msg::RagequitConfig, + pub ragequit_config: valence_two_party_pol_holder::msg::RagequitConfig, pub deposit_deadline: Expiration, - pub covenant_config: covenant_two_party_pol_holder::msg::TwoPartyPolCovenantConfig, + pub covenant_config: valence_two_party_pol_holder::msg::TwoPartyPolCovenantConfig, pub splits: BTreeMap, pub fallback_split: Option, pub emergency_committee_addr: Option, @@ -285,7 +285,7 @@ impl Suite { .execute_contract( Addr::unchecked(sender), self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::ExecuteMsg::Ragequit {}, + &valence_two_party_pol_holder::msg::ExecuteMsg::Ragequit {}, &[], ) .unwrap() @@ -296,7 +296,7 @@ impl Suite { .execute_contract( Addr::unchecked(sender), self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::ExecuteMsg::Claim {}, + &valence_two_party_pol_holder::msg::ExecuteMsg::Claim {}, &[], ) .unwrap() @@ -307,7 +307,7 @@ impl Suite { .execute_contract( Addr::unchecked(sender), self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::ExecuteMsg::Distribute {}, + &valence_two_party_pol_holder::msg::ExecuteMsg::Distribute {}, &[], ) .unwrap() @@ -318,7 +318,7 @@ impl Suite { .execute_contract( Addr::unchecked(sender), self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::ExecuteMsg::WithdrawFailed {}, + &valence_two_party_pol_holder::msg::ExecuteMsg::WithdrawFailed {}, &[], ) .unwrap() @@ -329,7 +329,7 @@ impl Suite { .execute_contract( Addr::unchecked(sender), self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::ExecuteMsg::EmergencyWithdraw {}, + &valence_two_party_pol_holder::msg::ExecuteMsg::EmergencyWithdraw {}, &[], ) .unwrap() @@ -340,7 +340,7 @@ impl Suite { .execute_contract( Addr::unchecked(sender), self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::ExecuteMsg::DistributeFallbackSplit { denoms }, + &valence_two_party_pol_holder::msg::ExecuteMsg::DistributeFallbackSplit { denoms }, &[], ) .unwrap() @@ -348,12 +348,12 @@ impl Suite { pub fn query_covenant_config( &mut self, - ) -> covenant_two_party_pol_holder::msg::TwoPartyPolCovenantConfig { + ) -> valence_two_party_pol_holder::msg::TwoPartyPolCovenantConfig { self.app .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::Config {}, + &valence_two_party_pol_holder::msg::QueryMsg::Config {}, ) .unwrap() } @@ -363,7 +363,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::ContractState {}, + &valence_two_party_pol_holder::msg::QueryMsg::ContractState {}, ) .unwrap() } @@ -373,7 +373,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::RagequitConfig {}, + &valence_two_party_pol_holder::msg::QueryMsg::RagequitConfig {}, ) .unwrap() } @@ -383,7 +383,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::LockupConfig {}, + &valence_two_party_pol_holder::msg::QueryMsg::LockupConfig {}, ) .unwrap() } @@ -393,7 +393,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::ClockAddress {}, + &valence_two_party_pol_holder::msg::QueryMsg::ClockAddress {}, ) .unwrap() } @@ -403,7 +403,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::NextContract {}, + &valence_two_party_pol_holder::msg::QueryMsg::NextContract {}, ) .unwrap() } @@ -413,7 +413,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::DepositDeadline {}, + &valence_two_party_pol_holder::msg::QueryMsg::DepositDeadline {}, ) .unwrap() } @@ -423,7 +423,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::DenomSplits {}, + &valence_two_party_pol_holder::msg::QueryMsg::DenomSplits {}, ) .unwrap() } @@ -433,7 +433,7 @@ impl Suite { .wrap() .query_wasm_smart( self.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::QueryMsg::EmergencyCommittee {}, + &valence_two_party_pol_holder::msg::QueryMsg::EmergencyCommittee {}, ) .unwrap() } diff --git a/unit-tests/src/test_two_party_pol_holder/tests.rs b/unit-tests/src/test_two_party_pol_holder/tests.rs index 4442e569..9275532c 100644 --- a/unit-tests/src/test_two_party_pol_holder/tests.rs +++ b/unit-tests/src/test_two_party_pol_holder/tests.rs @@ -1,10 +1,10 @@ use std::{collections::BTreeMap, str::FromStr}; use cosmwasm_std::{coin, coins, Addr, Decimal, Event, Timestamp, Uint128}; -use covenant_two_party_pol_holder::msg::{ContractState, RagequitConfig, RagequitTerms}; use covenant_utils::split::SplitConfig; use cw_multi_test::Executor; use cw_utils::Expiration; +use valence_two_party_pol_holder::msg::{ContractState, RagequitConfig, RagequitTerms}; use crate::setup::{ base_suite::{BaseSuite, BaseSuiteMut}, @@ -168,7 +168,7 @@ fn test_instantiate_validates_covenant_config_allocations() { #[should_panic(expected = "Ragequit penalty must be in range of [0.0, 1.0)")] fn test_instantiate_validates_ragequit_config_range() { TwoPartyHolderBuilder::default() - .with_ragequit_config(covenant_two_party_pol_holder::msg::RagequitConfig::Enabled( + .with_ragequit_config(valence_two_party_pol_holder::msg::RagequitConfig::Enabled( RagequitTerms { penalty: Decimal::from_str("1.1").unwrap(), state: None, @@ -181,7 +181,7 @@ fn test_instantiate_validates_ragequit_config_range() { #[should_panic(expected = "Ragequit penalty exceeds party allocation")] fn test_instantiate_validates_ragequit_config_party_allocations() { TwoPartyHolderBuilder::default() - .with_ragequit_config(covenant_two_party_pol_holder::msg::RagequitConfig::Enabled( + .with_ragequit_config(valence_two_party_pol_holder::msg::RagequitConfig::Enabled( RagequitTerms { penalty: Decimal::from_str("0.6").unwrap(), state: None, @@ -244,7 +244,7 @@ fn test_execute_tick_validates_clock() { .execute_contract( suite.faucet.clone(), suite.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::ExecuteMsg::Tick {}, + &valence_two_party_pol_holder::msg::ExecuteMsg::Tick {}, &[], ) .unwrap(); @@ -440,7 +440,7 @@ fn test_execute_tick_expired_noop() { #[test] fn test_execute_tick_ragequit_noop() { let mut suite = TwoPartyHolderBuilder::default() - .with_ragequit_config(covenant_two_party_pol_holder::msg::RagequitConfig::Enabled( + .with_ragequit_config(valence_two_party_pol_holder::msg::RagequitConfig::Enabled( RagequitTerms { penalty: Decimal::from_str("0.05").unwrap(), state: None, @@ -495,7 +495,7 @@ fn test_execute_ragequit_validates_ragequit_config() { #[should_panic(expected = "covenant is not in active state")] fn test_execute_ragequit_validates_active_state() { let mut suite = TwoPartyHolderBuilder::default() - .with_ragequit_config(covenant_two_party_pol_holder::msg::RagequitConfig::Enabled( + .with_ragequit_config(valence_two_party_pol_holder::msg::RagequitConfig::Enabled( RagequitTerms { penalty: Decimal::from_str("0.05").unwrap(), state: None, @@ -515,7 +515,7 @@ fn test_execute_ragequit_validates_withdraw_started() { #[should_panic(expected = "covenant is active but expired; tick to proceed")] fn test_execute_ragequit_validates_lockup_config_expiration() { let mut suite = TwoPartyHolderBuilder::default() - .with_ragequit_config(covenant_two_party_pol_holder::msg::RagequitConfig::Enabled( + .with_ragequit_config(valence_two_party_pol_holder::msg::RagequitConfig::Enabled( RagequitTerms { penalty: Decimal::from_str("0.05").unwrap(), state: None, @@ -542,7 +542,7 @@ fn test_execute_ragequit_validates_lockup_config_expiration() { #[should_panic(expected = "unauthorized")] fn test_execute_ragequit_validates_sender() { let mut suite = TwoPartyHolderBuilder::default() - .with_ragequit_config(covenant_two_party_pol_holder::msg::RagequitConfig::Enabled( + .with_ragequit_config(valence_two_party_pol_holder::msg::RagequitConfig::Enabled( RagequitTerms { penalty: Decimal::from_str("0.05").unwrap(), state: None, @@ -568,7 +568,7 @@ fn test_execute_ragequit_validates_sender() { #[should_panic(expected = "unauthorized")] fn test_execute_claim_unauthorized() { let mut suite = TwoPartyHolderBuilder::default() - .with_ragequit_config(covenant_two_party_pol_holder::msg::RagequitConfig::Enabled( + .with_ragequit_config(valence_two_party_pol_holder::msg::RagequitConfig::Enabled( RagequitTerms { penalty: Decimal::from_str("0.05").unwrap(), state: None, @@ -584,7 +584,7 @@ fn test_execute_claim_unauthorized() { #[should_panic(expected = "Claimer already claimed his share")] fn test_execute_claim_with_null_allocation() { let mut suite = TwoPartyHolderBuilder::default() - .with_ragequit_config(covenant_two_party_pol_holder::msg::RagequitConfig::Enabled( + .with_ragequit_config(valence_two_party_pol_holder::msg::RagequitConfig::Enabled( RagequitTerms { penalty: Decimal::from_str("0.05").unwrap(), state: None, @@ -798,7 +798,7 @@ fn test_migrate_update_config() { .migrate_contract( Addr::unchecked(ADMIN), suite.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + &valence_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { clock_addr: Some(next_contract.to_string()), next_contract: Some(clock.to_string()), emergency_committee: Some(clock.to_string()), @@ -862,7 +862,7 @@ fn test_migrate_update_config_invalid_fallback_split() { .migrate_contract( Addr::unchecked(ADMIN), suite.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + &valence_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { clock_addr: None, next_contract: None, emergency_committee: None, @@ -902,7 +902,7 @@ fn test_migrate_update_config_invalid_explicit_splits() { .migrate_contract( Addr::unchecked(ADMIN), suite.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + &valence_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { clock_addr: None, next_contract: None, emergency_committee: None, @@ -927,7 +927,7 @@ fn test_migrate_update_config_validates_lockup_config_expiration() { .migrate_contract( Addr::unchecked(ADMIN), suite.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + &valence_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { clock_addr: None, next_contract: None, emergency_committee: None, @@ -952,7 +952,7 @@ fn test_migrate_update_config_validates_deposit_deadline_expiration() { .migrate_contract( Addr::unchecked(ADMIN), suite.holder_addr.clone(), - &covenant_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { + &valence_two_party_pol_holder::msg::MigrateMsg::UpdateConfig { clock_addr: None, next_contract: None, emergency_committee: None, From af9a159faab26ce1763454970bfa60ab643a8540 Mon Sep 17 00:00:00 2001 From: bekauz Date: Tue, 16 Apr 2024 22:34:37 +0200 Subject: [PATCH 49/56] osmo liquid pooler option to withdraw party denoms from proxy --- contracts/osmo-liquid-pooler/src/contract.rs | 52 +++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/contracts/osmo-liquid-pooler/src/contract.rs b/contracts/osmo-liquid-pooler/src/contract.rs index faa678c2..3666492c 100644 --- a/contracts/osmo-liquid-pooler/src/contract.rs +++ b/contracts/osmo-liquid-pooler/src/contract.rs @@ -3,8 +3,7 @@ use std::collections::HashMap; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - ensure, to_json_binary, to_json_string, Attribute, Binary, Coin, CosmosMsg, Decimal, Env, - Fraction, IbcTimeout, MessageInfo, Response, StdResult, Uint128, WasmMsg, + ensure, to_json_binary, to_json_string, Addr, Attribute, Binary, Coin, CosmosMsg, Decimal, Env, Fraction, IbcTimeout, MessageInfo, Response, StdResult, Uint128, WasmMsg }; use covenant_utils::{ polytone::get_polytone_execute_msg_binary, withdraw_lp_helper::WithdrawLPMsgs, ForwardMetadata, @@ -124,6 +123,49 @@ pub fn execute( } } +/// this method will attempt to set the contract state to `Distributing`, +/// with any non-lp token denoms available on our remote proxy. +/// doing so will cause upcoming ticks to try to send the withdrawn coins +/// to the holder, completing the withdrawal flow and reverting this contract +/// to active state. +fn withdraw_party_denoms( + deps: ExecuteDeps, + lp_config: LiquidityProvisionConfig, +) -> NeutronResult> { + // if either denom balance is non-zero, collect them + let mut withdraw_coins = vec![]; + if let Some(val) = lp_config.latest_balances.get(&lp_config.party_1_denom_info.osmosis_coin.denom) { + if val.amount > Uint128::zero() { + withdraw_coins.push(val.clone()); + } + } + + if let Some(val) = lp_config.latest_balances.get(&lp_config.party_2_denom_info.osmosis_coin.denom) { + if val.amount > Uint128::zero() { + withdraw_coins.push(val.clone()); + } + } + + // if both balances are zero we error out + ensure!( + !withdraw_coins.is_empty(), + ContractError::OsmosisPoolError("no lp or covenant denoms available to withdraw".to_string()) + .to_neutron_std() + ); + + // otherwise we set the contract state to distributing. + // this will cause incoming ticks to assert whether this contract had received the funds. + // if the funds are not received, the tick will attempt to withdraw them again. + // if all expected coins are received, the contract will submit `Distribute` message to the holder. + CONTRACT_STATE.save(deps.storage, &ContractState::Distributing { coins: withdraw_coins.clone() })?; + + Ok(Response::default() + .add_attribute("method", "withdraw_party_denoms") + .add_attribute("contract_state", "distributing") + .add_attribute("coins", to_json_string(&withdraw_coins)?) + ) +} + fn try_withdraw( deps: ExecuteDeps, env: Env, @@ -143,11 +185,9 @@ fn try_withdraw( let proxy_lp_token_balance = match lp_config.latest_balances.get(&lp_config.lp_token_denom) { Some(val) => { + // if no lp tokens are available, we attempt to withdraw any available denoms if val.amount.is_zero() { - return Err( - ContractError::OsmosisPoolError("proxy holds 0 lp tokens".to_string()) - .to_neutron_std(), - ); + return withdraw_party_denoms(deps, lp_config) } else { val } From f6c73864fb3c9c746fb9c23e1b233d529ec86d54 Mon Sep 17 00:00:00 2001 From: bekauz Date: Tue, 16 Apr 2024 22:35:57 +0200 Subject: [PATCH 50/56] wip: interchaintest adjustments --- .../single-party-pol/single_party_pol_test.go | 18 +++--- interchaintest/swap/tokenswap_test.go | 14 ++--- .../two-party-pol/osmo_lper_test.go | 33 ++++++++--- .../two-party-pol/two_party_osmo_pol_test.go | 58 +++++++++++++++---- .../two_party_pol_native_test.go | 14 ++--- .../two-party-pol/two_party_pol_test.go | 14 ++--- interchaintest/two-party-pol/types.go | 3 +- 7 files changed, 104 insertions(+), 50 deletions(-) diff --git a/interchaintest/single-party-pol/single_party_pol_test.go b/interchaintest/single-party-pol/single_party_pol_test.go index 26503b90..cbb65130 100644 --- a/interchaintest/single-party-pol/single_party_pol_test.go +++ b/interchaintest/single-party-pol/single_party_pol_test.go @@ -481,15 +481,15 @@ func TestSinglePartyPol(t *testing.T) { t.Run("two party pol covenant setup", func(t *testing.T) { // Wasm code that we need to store on Neutron - const covenantContractPath = "wasms/covenant_single_party_pol.wasm" - const clockContractPath = "wasms/covenant_clock.wasm" - const interchainRouterContractPath = "wasms/covenant_interchain_router.wasm" - const nativeRouterContractPath = "wasms/covenant_native_router.wasm" - const ibcForwarderContractPath = "wasms/covenant_ibc_forwarder.wasm" - const holderContractPath = "wasms/covenant_single_party_pol_holder.wasm" - const liquidPoolerPath = "wasms/covenant_astroport_liquid_pooler.wasm" - const remoteChainSplitterPath = "wasms/covenant_remote_chain_splitter.wasm" - const liquidStakerContractPath = "wasms/covenant_stride_liquid_staker.wasm" + const covenantContractPath = "wasms/valence_covenant_single_party_pol.wasm" + const clockContractPath = "wasms/valence_clock.wasm" + const interchainRouterContractPath = "wasms/valence_interchain_router.wasm" + const nativeRouterContractPath = "wasms/valence_native_router.wasm" + const ibcForwarderContractPath = "wasms/valence_ibc_forwarder.wasm" + const holderContractPath = "wasms/valence_single_party_pol_holder.wasm" + const liquidPoolerPath = "wasms/valence_astroport_liquid_pooler.wasm" + const remoteChainSplitterPath = "wasms/valence_remote_chain_splitter.wasm" + const liquidStakerContractPath = "wasms/valence_stride_liquid_staker.wasm" // After storing on Neutron, we will receive a code id // We parse all the subcontracts into uint64 diff --git a/interchaintest/swap/tokenswap_test.go b/interchaintest/swap/tokenswap_test.go index 4f5bf4da..0064a259 100644 --- a/interchaintest/swap/tokenswap_test.go +++ b/interchaintest/swap/tokenswap_test.go @@ -317,13 +317,13 @@ func TestTokenSwap(t *testing.T) { t.Run("tokenswap covenant setup", func(t *testing.T) { // Wasm code that we need to store on Neutron - const covenantContractPath = "wasms/covenant_swap.wasm" - const clockContractPath = "wasms/covenant_clock.wasm" - const interchainRouterContractPath = "wasms/covenant_interchain_router.wasm" - const nativeRouterContractPath = "wasms/covenant_native_router.wasm" - const splitterContractPath = "wasms/covenant_native_splitter.wasm" - const ibcForwarderContractPath = "wasms/covenant_ibc_forwarder.wasm" - const swapHolderContractPath = "wasms/covenant_swap_holder.wasm" + const covenantContractPath = "wasms/valence_covenant_swap.wasm" + const clockContractPath = "wasms/valence_clock.wasm" + const interchainRouterContractPath = "wasms/valence_interchain_router.wasm" + const nativeRouterContractPath = "wasms/valence_native_router.wasm" + const splitterContractPath = "wasms/valence_native_splitter.wasm" + const ibcForwarderContractPath = "wasms/valence_ibc_forwarder.wasm" + const swapHolderContractPath = "wasms/valence_swap_holder.wasm" // After storing on Neutron, we will receive a code id // We parse all the subcontracts into uint64 diff --git a/interchaintest/two-party-pol/osmo_lper_test.go b/interchaintest/two-party-pol/osmo_lper_test.go index 720f0e1e..75f6162a 100644 --- a/interchaintest/two-party-pol/osmo_lper_test.go +++ b/interchaintest/two-party-pol/osmo_lper_test.go @@ -321,13 +321,13 @@ func TestTwoPartyOsmoLP(t *testing.T) { t.Run("two party pol covenant setup", func(t *testing.T) { // Wasm code that we need to store on Neutron - const covenantContractPath = "wasms/covenant_two_party_pol.wasm" - const clockContractPath = "wasms/covenant_clock.wasm" - const routerContractPath = "wasms/covenant_interchain_router.wasm" - const ibcForwarderContractPath = "wasms/covenant_ibc_forwarder.wasm" - const holderContractPath = "wasms/covenant_two_party_pol_holder.wasm" - const liquidPoolerPath = "wasms/covenant_osmo_liquid_pooler.wasm" - const osmoOutpostPath = "wasms/covenant_outpost_osmo_liquid_pooler.wasm" + const covenantContractPath = "wasms/valence_covenant_two_party_pol.wasm" + const clockContractPath = "wasms/valence_clock.wasm" + const routerContractPath = "wasms/valence_interchain_router.wasm" + const ibcForwarderContractPath = "wasms/valence_ibc_forwarder.wasm" + const holderContractPath = "wasms/valence_two_party_pol_holder.wasm" + const liquidPoolerPath = "wasms/valence_osmo_liquid_pooler.wasm" + const osmoOutpostPath = "wasms/valence_outpost_osmo_liquid_pooler.wasm" // After storing on Neutron, we will receive a code id // We parse all the subcontracts into uint64 @@ -544,6 +544,11 @@ func TestTwoPartyOsmoLP(t *testing.T) { Channel: testCtx.OsmoTransferChannelIds[testCtx.Hub.Config().Name], } + duration := Duration{ + Time: new(uint64), + } + *duration.Time = 50 + instantiateMsg := OsmoLiquidPoolerInstantiateMsg{ ClockAddress: neutronUser.Bech32Address(cosmosNeutron.Config().Bech32Prefix), HolderAddress: neutronUser.Bech32Address(cosmosNeutron.Config().Bech32Prefix), @@ -578,7 +583,7 @@ func TestTwoPartyOsmoLP(t *testing.T) { ExpectedSpotPrice: "0.10", AcceptablePriceSpread: "0.04", }, - FundingDurationSeconds: "50", + FundingDuration: duration, SingleSideLpLimits: SingleSideLpLimits{ AssetALimit: "10000", AssetBLimit: "975000004", @@ -671,6 +676,18 @@ func TestTwoPartyOsmoLP(t *testing.T) { } }) + t.Run("perform withdrawal", func(t *testing.T) { + response, err := testCtx.Neutron.ExecuteContract( + testCtx.Ctx, + keyring.BackendTest, + osmoLiquidPoolerAddress, + `{"withdraw":{"percentage":"0.5"}}`, + ) + + println("withdraw response: ", string(response)) + println("withdraw error: ", err) + }) + t.Run("tick until liquidity is provided and proxy receives gamm tokens", func(t *testing.T) { neutronGammDenom := testCtx.GetIbcDenom( testCtx.NeutronTransferChannelIds[cosmosOsmosis.Config().Name], diff --git a/interchaintest/two-party-pol/two_party_osmo_pol_test.go b/interchaintest/two-party-pol/two_party_osmo_pol_test.go index 417ca025..f9bbb899 100644 --- a/interchaintest/two-party-pol/two_party_osmo_pol_test.go +++ b/interchaintest/two-party-pol/two_party_osmo_pol_test.go @@ -291,14 +291,14 @@ func TestTwoPartyOsmoPol(t *testing.T) { t.Run("two party pol covenant setup", func(t *testing.T) { // Wasm code that we need to store on Neutron - const covenantContractPath = "wasms/covenant_two_party_pol.wasm" - const clockContractPath = "wasms/covenant_clock.wasm" - const interchainRouterContractPath = "wasms/covenant_interchain_router.wasm" - const ibcForwarderContractPath = "wasms/covenant_ibc_forwarder.wasm" - const holderContractPath = "wasms/covenant_two_party_pol_holder.wasm" - const liquidPoolerPath = "wasms/covenant_osmo_liquid_pooler.wasm" - const osmoOutpostPath = "wasms/covenant_outpost_osmo_liquid_pooler.wasm" - const nativeRouterContractPath = "wasms/covenant_native_router.wasm" + const covenantContractPath = "wasms/valence_covenant_two_party_pol.wasm" + const clockContractPath = "wasms/valence_clock.wasm" + const interchainRouterContractPath = "wasms/valence_interchain_router.wasm" + const ibcForwarderContractPath = "wasms/valence_ibc_forwarder.wasm" + const holderContractPath = "wasms/valence_two_party_pol_holder.wasm" + const liquidPoolerPath = "wasms/valence_osmo_liquid_pooler.wasm" + const osmoOutpostPath = "wasms/valence_outpost_osmo_liquid_pooler.wasm" + const nativeRouterContractPath = "wasms/valence_native_router.wasm" // After storing on Neutron, we will receive a code id // We parse all the subcontracts into uint64 @@ -646,8 +646,8 @@ func TestTwoPartyOsmoPol(t *testing.T) { PartyBConfig: CovenantPartyConfig{Interchain: &partyBConfig}, DepositDeadline: depositDeadline, CovenantType: "share", - PartyAShare: "50", - PartyBShare: "50", + PartyAShare: "0.5", + PartyBShare: "0.5", PoolPriceConfig: PoolPriceConfig{ ExpectedSpotPrice: "0.1", AcceptablePriceSpread: "0.09", @@ -779,6 +779,44 @@ func TestTwoPartyOsmoPol(t *testing.T) { } }) + t.Run("perform withdrawal", func(t *testing.T) { + response, err := testCtx.Neutron.ExecuteContract( + testCtx.Ctx, + keyring.BackendTest, + holderAddress, + `{"emergency_withdraw":{}}`, + ) + + println("withdraw response: ", string(response)) + println("withdraw error: ", err) + + for { + proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) + proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) + println("proxy atom bal: ", proxyAtomBal) + println("proxy osmo bal: ", proxyOsmoBal) + + lperAtomBal := testCtx.QueryOsmoDenomBalance(neutronAtomIbcDenom, liquidPoolerAddress) + lperOsmoBal := testCtx.QueryOsmoDenomBalance(neutronOsmoIbcDenom, liquidPoolerAddress) + + println("liquid pooler atom bal: ", lperAtomBal) + println("liquid pooler osmo bal: ", lperOsmoBal) + + holderAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, holderAddress) + holderOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, holderAddress) + + println("holder atom bal: ", holderAtomBal) + println("holder osmo bal: ", holderOsmoBal) + + if holderAtomBal != 0 && holderOsmoBal != 0 { + println("withdraw success!") + break + } else { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } + } + }) + t.Run("tick until liquidity is provided and proxy receives gamm tokens", func(t *testing.T) { neutronGammDenom := testCtx.GetIbcDenom( testCtx.NeutronTransferChannelIds[cosmosOsmosis.Config().Name], diff --git a/interchaintest/two-party-pol/two_party_pol_native_test.go b/interchaintest/two-party-pol/two_party_pol_native_test.go index 38d83aa1..17882e23 100644 --- a/interchaintest/two-party-pol/two_party_pol_native_test.go +++ b/interchaintest/two-party-pol/two_party_pol_native_test.go @@ -277,13 +277,13 @@ func TestTwoPartyNativePartyPol(t *testing.T) { t.Run("two party pol covenant setup", func(t *testing.T) { // Wasm code that we need to store on Neutron - const covenantContractPath = "wasms/covenant_two_party_pol.wasm" - const clockContractPath = "wasms/covenant_clock.wasm" - const interchainRouterContractPath = "wasms/covenant_interchain_router.wasm" - const nativeRouterContractPath = "wasms/covenant_native_router.wasm" - const ibcForwarderContractPath = "wasms/covenant_ibc_forwarder.wasm" - const holderContractPath = "wasms/covenant_two_party_pol_holder.wasm" - const liquidPoolerPath = "wasms/covenant_astroport_liquid_pooler.wasm" + const covenantContractPath = "wasms/valence_covenant_two_party_pol.wasm" + const clockContractPath = "wasms/valence_clock.wasm" + const interchainRouterContractPath = "wasms/valence_interchain_router.wasm" + const nativeRouterContractPath = "wasms/valence_native_router.wasm" + const ibcForwarderContractPath = "wasms/valence_ibc_forwarder.wasm" + const holderContractPath = "wasms/valence_two_party_pol_holder.wasm" + const liquidPoolerPath = "wasms/valence_astroport_liquid_pooler.wasm" // After storing on Neutron, we will receive a code id // We parse all the subcontracts into uint64 diff --git a/interchaintest/two-party-pol/two_party_pol_test.go b/interchaintest/two-party-pol/two_party_pol_test.go index e87280a8..a92af99d 100644 --- a/interchaintest/two-party-pol/two_party_pol_test.go +++ b/interchaintest/two-party-pol/two_party_pol_test.go @@ -343,13 +343,13 @@ func TestTwoPartyPol(t *testing.T) { t.Run("two party pol covenant setup", func(t *testing.T) { // Wasm code that we need to store on Neutron - const covenantContractPath = "wasms/covenant_two_party_pol.wasm" - const clockContractPath = "wasms/covenant_clock.wasm" - const interchainRouterContractPath = "wasms/covenant_interchain_router.wasm" - const nativeRouterContractPath = "wasms/covenant_native_router.wasm" - const ibcForwarderContractPath = "wasms/covenant_ibc_forwarder.wasm" - const holderContractPath = "wasms/covenant_two_party_pol_holder.wasm" - const liquidPoolerPath = "wasms/covenant_astroport_liquid_pooler.wasm" + const covenantContractPath = "wasms/valence_covenant_two_party_pol.wasm" + const clockContractPath = "wasms/valence_clock.wasm" + const interchainRouterContractPath = "wasms/valence_interchain_router.wasm" + const nativeRouterContractPath = "wasms/valence_native_router.wasm" + const ibcForwarderContractPath = "wasms/valence_ibc_forwarder.wasm" + const holderContractPath = "wasms/valence_two_party_pol_holder.wasm" + const liquidPoolerPath = "wasms/valence_astroport_liquid_pooler.wasm" // After storing on Neutron, we will receive a code id // We parse all the subcontracts into uint64 diff --git a/interchaintest/two-party-pol/types.go b/interchaintest/two-party-pol/types.go index 12d637c0..21af82c0 100644 --- a/interchaintest/two-party-pol/types.go +++ b/interchaintest/two-party-pol/types.go @@ -496,11 +496,10 @@ type OsmoLiquidPoolerInstantiateMsg struct { OsmoOutpost string `json:"osmo_outpost"` LpTokenDenom string `json:"lp_token_denom"` SlippageTolerance string `json:"slippage_tolerance"` - FundingDurationSeconds string `json:"funding_duration_seconds"` + FundingDuration Duration `json:"funding_duration"` SingleSideLpLimits SingleSideLpLimits `json:"single_side_lp_limits"` PoolPriceConfig PoolPriceConfig `json:"pool_price_config"` } - type PoolPriceConfig struct { ExpectedSpotPrice string `json:"expected_spot_price"` AcceptablePriceSpread string `json:"acceptable_price_spread"` From 1b88a23a128ca8b43488e519eceefc155a67a62b Mon Sep 17 00:00:00 2001 From: bekauz Date: Thu, 18 Apr 2024 21:37:45 +0200 Subject: [PATCH 51/56] osmo liquid pooler handles withdrawals via pending withdraw state --- contracts/osmo-liquid-pooler/src/contract.rs | 165 ++- contracts/osmo-liquid-pooler/src/msg.rs | 16 + .../two-party-pol/two_party_osmo_pol_test.go | 1105 +++++++++++------ interchaintest/utils/connection_helpers.go | 4 +- 4 files changed, 850 insertions(+), 440 deletions(-) diff --git a/contracts/osmo-liquid-pooler/src/contract.rs b/contracts/osmo-liquid-pooler/src/contract.rs index 3666492c..6300602e 100644 --- a/contracts/osmo-liquid-pooler/src/contract.rs +++ b/contracts/osmo-liquid-pooler/src/contract.rs @@ -3,7 +3,8 @@ use std::collections::HashMap; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - ensure, to_json_binary, to_json_string, Addr, Attribute, Binary, Coin, CosmosMsg, Decimal, Env, Fraction, IbcTimeout, MessageInfo, Response, StdResult, Uint128, WasmMsg + ensure, to_json_binary, to_json_string, Attribute, Binary, Coin, CosmosMsg, Decimal, Env, + Fraction, IbcTimeout, MessageInfo, Response, StdError, StdResult, Uint128, WasmMsg, }; use covenant_utils::{ polytone::get_polytone_execute_msg_binary, withdraw_lp_helper::WithdrawLPMsgs, ForwardMetadata, @@ -119,10 +120,50 @@ pub fn execute( match msg { ExecuteMsg::Tick {} => try_tick(deps, env, info), ExecuteMsg::Callback(callback_msg) => try_handle_callback(env, deps, info, callback_msg), - ExecuteMsg::Withdraw { percentage } => try_withdraw(deps, env, info, percentage), + ExecuteMsg::Withdraw { percentage } => try_initiate_withdrawal(deps, info, percentage), } } +/// we initiate the withdrawal phase by setting the contract state to `PendingWithdrawal` +fn try_initiate_withdrawal( + deps: ExecuteDeps, + info: MessageInfo, + percentage: Option, +) -> NeutronResult> { + ensure!( + info.sender == HOLDER_ADDRESS.load(deps.storage)?, + ContractError::NotHolder {}.to_neutron_std() + ); + + let withdraw_share = percentage.unwrap_or(Decimal::one()); + + ensure!( + withdraw_share <= Decimal::one() && withdraw_share > Decimal::zero(), + ContractError::Std(StdError::generic_err(format!( + "withdraw percentage must be in range (0, 1], got {:?}", + withdraw_share + ),)) + .to_neutron_std() + ); + + // we advance the contract state to `PendingWithdrawal` and force latest balances sync + CONTRACT_STATE.save( + deps.storage, + &ContractState::PendingWithdrawal { + share: withdraw_share, + }, + )?; + LIQUIDITY_PROVISIONING_CONFIG.update(deps.storage, |mut lp_config| -> StdResult<_> { + lp_config.reset_latest_proxy_balances(); + Ok(lp_config) + })?; + + Ok(Response::default() + .add_attribute("method", "try_withdraw") + .add_attribute("contract_state", "pending_withdrawal") + .add_attribute("pending_withdrawal", withdraw_share.to_string())) +} + /// this method will attempt to set the contract state to `Distributing`, /// with any non-lp token denoms available on our remote proxy. /// doing so will cause upcoming ticks to try to send the withdrawn coins @@ -130,78 +171,73 @@ pub fn execute( /// to active state. fn withdraw_party_denoms( deps: ExecuteDeps, - lp_config: LiquidityProvisionConfig, + p1_proxy_bal: &Coin, + p2_proxy_bal: &Coin, ) -> NeutronResult> { // if either denom balance is non-zero, collect them - let mut withdraw_coins = vec![]; - if let Some(val) = lp_config.latest_balances.get(&lp_config.party_1_denom_info.osmosis_coin.denom) { - if val.amount > Uint128::zero() { - withdraw_coins.push(val.clone()); - } + let mut withdraw_coins: Vec = Vec::with_capacity(2); + if p1_proxy_bal.amount > Uint128::zero() { + withdraw_coins.push(p1_proxy_bal.clone()); } - - if let Some(val) = lp_config.latest_balances.get(&lp_config.party_2_denom_info.osmosis_coin.denom) { - if val.amount > Uint128::zero() { - withdraw_coins.push(val.clone()); - } + if p2_proxy_bal.amount > Uint128::zero() { + withdraw_coins.push(p2_proxy_bal.clone()); } - // if both balances are zero we error out - ensure!( - !withdraw_coins.is_empty(), - ContractError::OsmosisPoolError("no lp or covenant denoms available to withdraw".to_string()) - .to_neutron_std() - ); - - // otherwise we set the contract state to distributing. - // this will cause incoming ticks to assert whether this contract had received the funds. - // if the funds are not received, the tick will attempt to withdraw them again. - // if all expected coins are received, the contract will submit `Distribute` message to the holder. - CONTRACT_STATE.save(deps.storage, &ContractState::Distributing { coins: withdraw_coins.clone() })?; + if withdraw_coins.is_empty() { + // both both balances are zero, we revert the state to active + // and ping a WithdrawFailed message to the holder. + let withdraw_failed_msg = WasmMsg::Execute { + contract_addr: HOLDER_ADDRESS.load(deps.storage)?.to_string(), + msg: to_json_binary(&WithdrawLPMsgs::WithdrawFailed {})?, + funds: vec![], + }; + CONTRACT_STATE.save(deps.storage, &ContractState::Active)?; + Ok(Response::default() + .add_attribute("method", "withdraw_party_denoms") + .add_attribute("contract_state", "active") + .add_attribute("p1_balance", p1_proxy_bal.to_string()) + .add_attribute("p2_balance", p2_proxy_bal.to_string()) + .add_message(withdraw_failed_msg)) + } else { + // otherwise we set the contract state to distributing. + // this will cause incoming ticks to assert whether this contract had received the funds. + // if the funds are not received, the tick will attempt to withdraw them again. + // if all expected coins are received, the contract will submit `Distribute` message to the holder. + CONTRACT_STATE.save( + deps.storage, + &ContractState::Distributing { + coins: withdraw_coins.clone(), + }, + )?; - Ok(Response::default() - .add_attribute("method", "withdraw_party_denoms") - .add_attribute("contract_state", "distributing") - .add_attribute("coins", to_json_string(&withdraw_coins)?) - ) + Ok(Response::default() + .add_attribute("method", "withdraw_party_denoms") + .add_attribute("contract_state", "distributing") + .add_attribute("p1_balance", p1_proxy_bal.to_string()) + .add_attribute("p2_balance", p2_proxy_bal.to_string()) + .add_attribute("coins", to_json_string(&withdraw_coins)?)) + } } -fn try_withdraw( +pub fn try_withdraw( deps: ExecuteDeps, env: Env, - info: MessageInfo, - percent: Option, + withdraw_share: Decimal, + (party_1_bal, party_2_bal, lp_bal): (&Coin, &Coin, &Coin), + lp_config: LiquidityProvisionConfig, ) -> NeutronResult> { - let percent = percent.unwrap_or(Decimal::one()); let note_address = NOTE_ADDRESS.load(deps.storage)?; let ibc_config = IBC_CONFIG.load(deps.storage)?; - let holder_addr = HOLDER_ADDRESS.load(deps.storage)?; - let lp_config = LIQUIDITY_PROVISIONING_CONFIG.load(deps.storage)?; - ensure!( - info.sender == holder_addr, - ContractError::NotHolder {}.to_neutron_std() - ); - - let proxy_lp_token_balance = match lp_config.latest_balances.get(&lp_config.lp_token_denom) { - Some(val) => { - // if no lp tokens are available, we attempt to withdraw any available denoms - if val.amount.is_zero() { - return withdraw_party_denoms(deps, lp_config) - } else { - val - } - } - None => { - return Err( - ContractError::OsmosisPoolError("no lp token balance".to_string()).to_neutron_std(), - ) - } - }; + // if there are 0 available lp token balances, we attempt to + // withdraw the party denoms directly. + if lp_bal.amount.is_zero() { + return withdraw_party_denoms(deps, party_1_bal, party_2_bal); + } - let lp_redeem_amount = proxy_lp_token_balance + let lp_redeem_amount = lp_bal .amount - .checked_multiply_ratio(percent.numerator(), percent.denominator()) + .checked_multiply_ratio(withdraw_share.numerator(), withdraw_share.denominator()) .map_err(|e| ContractError::CheckedMultiplyError(e).to_neutron_std())?; let exit_pool_message: CosmosMsg = WasmMsg::Execute { @@ -271,6 +307,19 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult try_sync_proxy_balances(deps, env), + ContractState::PendingWithdrawal { share } => { + let lp_config = LIQUIDITY_PROVISIONING_CONFIG.load(deps.storage)?; + match lp_config.get_proxy_balances() { + Some((party_1_bal, party_2_bal, lp_bal)) => try_withdraw( + deps, + env, + share, + (party_1_bal, party_2_bal, lp_bal), + lp_config.clone(), + ), + None => try_sync_proxy_balances(deps, env), + } + } ContractState::Distributing { coins } => try_distribute(deps, env, coins), } } diff --git a/contracts/osmo-liquid-pooler/src/msg.rs b/contracts/osmo-liquid-pooler/src/msg.rs index 47a41e73..afc6a374 100644 --- a/contracts/osmo-liquid-pooler/src/msg.rs +++ b/contracts/osmo-liquid-pooler/src/msg.rs @@ -153,6 +153,10 @@ impl LiquidityProvisionConfig { .get(&self.party_2_denom_info.osmosis_coin.denom) } + pub fn get_lp_token_proxy_balance(&self) -> Option<&Coin> { + self.latest_balances.get(&self.lp_token_denom) + } + pub fn get_osmo_outpost_provide_liquidity_message(&self) -> StdResult { let mut funds = vec![]; if let Some(c) = self.get_party_1_proxy_balance() { @@ -192,6 +196,17 @@ impl LiquidityProvisionConfig { self.latest_balances.remove(&self.lp_token_denom); } + pub fn get_proxy_balances(&self) -> Option<(&Coin, &Coin, &Coin)> { + match ( + self.get_party_1_proxy_balance(), + self.get_party_2_proxy_balance(), + self.get_lp_token_proxy_balance(), + ) { + (Some(p1), Some(p2), Some(lp)) => Some((p1, p2, lp)), + _ => None, + } + } + pub fn proxy_received_party_contributions(&self, p1_coin: &Coin, p2_coin: &Coin) -> bool { let p1_funded = p1_coin.amount >= self.party_1_denom_info.get_osmo_bal(); let p2_funded = p2_coin.amount >= self.party_2_denom_info.get_osmo_bal(); @@ -298,6 +313,7 @@ pub enum ContractState { ProxyFunded { funding_expiration: Expiration }, Active, Distributing { coins: Vec }, + PendingWithdrawal { share: Decimal }, } #[cw_serde] diff --git a/interchaintest/two-party-pol/two_party_osmo_pol_test.go b/interchaintest/two-party-pol/two_party_osmo_pol_test.go index f9bbb899..01f6e00f 100644 --- a/interchaintest/two-party-pol/two_party_osmo_pol_test.go +++ b/interchaintest/two-party-pol/two_party_osmo_pol_test.go @@ -253,6 +253,9 @@ func TestTwoPartyOsmoPol(t *testing.T) { happyCaseHubAccount := ibctest.GetAndFundTestUsers(t, ctx, "default", int64(atomContributionAmount), atom)[0] happyCaseOsmoAccount := ibctest.GetAndFundTestUsers(t, ctx, "default", 5*int64(osmoContributionAmount), osmosis)[0] + sadCaseHubAccount := ibctest.GetAndFundTestUsers(t, ctx, "default", int64(atomContributionAmount), atom)[0] + sadCaseOsmoAccount := ibctest.GetAndFundTestUsers(t, ctx, "default", 5*int64(osmoContributionAmount), osmosis)[0] + osmoPartyNeutronAddr := ibctest.GetAndFundTestUsers(t, ctx, "default", 100000000, neutron)[0] hubPartyNeutronAddr := ibctest.GetAndFundTestUsers(t, ctx, "default", 100000000, neutron)[0] @@ -490,451 +493,793 @@ func TestTwoPartyOsmoPol(t *testing.T) { testCtx.SkipBlocks(10) }) - t.Run("instantiate covenant", func(t *testing.T) { - timeouts := Timeouts{ - IcaTimeout: "100", // sec - IbcTransferTimeout: "100", // sec - } + t.Run("two party POL withdraw pre-lp tokens", func(t *testing.T) { + t.Run("instantiate covenant", func(t *testing.T) { + timeouts := Timeouts{ + IcaTimeout: "100", // sec + IbcTransferTimeout: "100", // sec + } - currentHeight := testCtx.GetNeutronHeight() - depositBlock := Block(currentHeight + 200) - lockupBlock := Block(currentHeight + 210) - lockupConfig := Expiration{ - AtHeight: &lockupBlock, - } - depositDeadline := Expiration{ - AtHeight: &depositBlock, - } + currentHeight := testCtx.GetNeutronHeight() + depositBlock := Block(currentHeight + 200) + lockupBlock := Block(currentHeight + 210) + lockupConfig := Expiration{ + AtHeight: &lockupBlock, + } + depositDeadline := Expiration{ + AtHeight: &depositBlock, + } - hubReceiverAddr := happyCaseHubAccount.Bech32Address(cosmosAtom.Config().Bech32Prefix) - osmoReceiverAddr := happyCaseOsmoAccount.Bech32Address(cosmosOsmosis.Config().Bech32Prefix) + hubReceiverAddr := sadCaseHubAccount.Bech32Address(cosmosAtom.Config().Bech32Prefix) + osmoReceiverAddr := sadCaseOsmoAccount.Bech32Address(cosmosOsmosis.Config().Bech32Prefix) - atomCoin := Coin{ - Denom: cosmosAtom.Config().Denom, - Amount: strconv.FormatUint(atomContributionAmount, 10), - } + atomCoin := Coin{ + Denom: cosmosAtom.Config().Denom, + Amount: strconv.FormatUint(atomContributionAmount, 10), + } - osmoCoin := Coin{ - Denom: cosmosOsmosis.Config().Denom, - Amount: strconv.FormatUint(osmoContributionAmount, 10), - } + osmoCoin := Coin{ + Denom: cosmosOsmosis.Config().Denom, + Amount: strconv.FormatUint(osmoContributionAmount, 10), + } - outwardsPfm := ForwardMetadata{ - Receiver: gaiaUser.Bech32Address(testCtx.Hub.Config().Bech32Prefix), - Port: "transfer", - Channel: testCtx.GaiaTransferChannelIds[testCtx.Osmosis.Config().Name], - } + outwardsPfm := ForwardMetadata{ + Receiver: gaiaUser.Bech32Address(testCtx.Hub.Config().Bech32Prefix), + Port: "transfer", + Channel: testCtx.GaiaTransferChannelIds[testCtx.Osmosis.Config().Name], + } - inwardsPfm := ForwardMetadata{ - Receiver: gaiaUser.Bech32Address(testCtx.Hub.Config().Bech32Prefix), - Port: "transfer", - Channel: testCtx.OsmoTransferChannelIds[testCtx.Hub.Config().Name], - } + inwardsPfm := ForwardMetadata{ + Receiver: gaiaUser.Bech32Address(testCtx.Hub.Config().Bech32Prefix), + Port: "transfer", + Channel: testCtx.OsmoTransferChannelIds[testCtx.Hub.Config().Name], + } - codeIds := ContractCodeIds{ - IbcForwarderCode: ibcForwarderCodeId, - InterchainRouterCode: interchainRouterCodeId, - NativeRouterCode: nativeRouterCodeId, - ClockCode: clockCodeId, - HolderCode: holderCodeId, - LiquidPoolerCode: lperCodeId, - } + codeIds := ContractCodeIds{ + IbcForwarderCode: ibcForwarderCodeId, + InterchainRouterCode: interchainRouterCodeId, + NativeRouterCode: nativeRouterCodeId, + ClockCode: clockCodeId, + HolderCode: holderCodeId, + LiquidPoolerCode: lperCodeId, + } - denomSplits := map[string]SplitConfig{ - neutronAtomIbcDenom: { - Receivers: map[string]string{ - hubReceiverAddr: "0.5", - osmoReceiverAddr: "0.5", + denomSplits := map[string]SplitConfig{ + neutronAtomIbcDenom: { + Receivers: map[string]string{ + hubReceiverAddr: "0.5", + osmoReceiverAddr: "0.5", + }, }, - }, - neutronOsmoIbcDenom: { - Receivers: map[string]string{ - hubReceiverAddr: "0.5", - osmoReceiverAddr: "0.5", + neutronOsmoIbcDenom: { + Receivers: map[string]string{ + hubReceiverAddr: "0.5", + osmoReceiverAddr: "0.5", + }, }, - }, - } - - // for party 1 (hub), we need to route osmosis correctly - neutron->osmosis->hub - party1PfmMap := map[string]PacketForwardMiddlewareConfig{ - neutronOsmoIbcDenom: { - LocalToHopChainChannelId: testCtx.NeutronTransferChannelIds[testCtx.Osmosis.Config().Name], - HopToDestinationChainChannelId: testCtx.OsmoTransferChannelIds[testCtx.Hub.Config().Name], - HopChainReceiverAddress: osmoUser.Bech32Address(cosmosOsmosis.Config().Bech32Prefix), - }, - } + } - partyAConfig := InterchainCovenantParty{ - Addr: hubPartyNeutronAddr.Bech32Address(cosmosNeutron.Config().Bech32Prefix), - NativeDenom: neutronAtomIbcDenom, - RemoteChainDenom: "uatom", - PartyToHostChainChannelId: testCtx.GaiaTransferChannelIds[cosmosNeutron.Config().Name], - HostToPartyChainChannelId: testCtx.NeutronTransferChannelIds[cosmosAtom.Config().Name], - PartyReceiverAddr: hubReceiverAddr, - PartyChainConnectionId: neutronAtomIBCConnId, - IbcTransferTimeout: timeouts.IbcTransferTimeout, - Contribution: atomCoin, - DenomToPfmMap: party1PfmMap, - } - // for party 2 (osmosis), we need to route atom correctly - neutron->hub->osmosis - party2PfmMap := map[string]PacketForwardMiddlewareConfig{ - neutronAtomIbcDenom: { - LocalToHopChainChannelId: testCtx.NeutronTransferChannelIds[testCtx.Hub.Config().Name], - HopToDestinationChainChannelId: testCtx.GaiaTransferChannelIds[testCtx.Osmosis.Config().Name], - HopChainReceiverAddress: gaiaUser.Bech32Address(cosmosAtom.Config().Bech32Prefix), - }, - } - partyBConfig := InterchainCovenantParty{ - Addr: osmoPartyNeutronAddr.Bech32Address(cosmosNeutron.Config().Bech32Prefix), - NativeDenom: neutronOsmoIbcDenom, - RemoteChainDenom: "uosmo", - PartyToHostChainChannelId: testCtx.OsmoTransferChannelIds[cosmosNeutron.Config().Name], - HostToPartyChainChannelId: testCtx.NeutronTransferChannelIds[cosmosOsmosis.Config().Name], - PartyReceiverAddr: osmoReceiverAddr, - PartyChainConnectionId: neutronOsmosisIBCConnId, - IbcTransferTimeout: timeouts.IbcTransferTimeout, - Contribution: osmoCoin, - DenomToPfmMap: party2PfmMap, - } - fundingDuration := Duration{ - Time: new(uint64), - } - *fundingDuration.Time = 300 - - liquidPoolerConfig := LiquidPoolerConfig{ - Osmosis: &OsmosisLiquidPoolerConfig{ - NoteAddress: noteAddress, - PoolId: "1", - OsmoIbcTimeout: "300", - Party1ChainInfo: PartyChainInfo{ - PartyChainToNeutronChannel: testCtx.GaiaTransferChannelIds[testCtx.Neutron.Config().Name], - NeutronToPartyChainChannel: testCtx.NeutronTransferChannelIds[testCtx.Hub.Config().Name], - InwardsPfm: &inwardsPfm, - OutwardsPfm: &outwardsPfm, - IbcTimeout: "300", - }, - Party2ChainInfo: PartyChainInfo{ - NeutronToPartyChainChannel: testCtx.NeutronTransferChannelIds[testCtx.Osmosis.Config().Name], - PartyChainToNeutronChannel: testCtx.OsmoTransferChannelIds[testCtx.Neutron.Config().Name], - IbcTimeout: "300", + // for party 1 (hub), we need to route osmosis correctly - neutron->osmosis->hub + party1PfmMap := map[string]PacketForwardMiddlewareConfig{ + neutronOsmoIbcDenom: { + LocalToHopChainChannelId: testCtx.NeutronTransferChannelIds[testCtx.Osmosis.Config().Name], + HopToDestinationChainChannelId: testCtx.OsmoTransferChannelIds[testCtx.Hub.Config().Name], + HopChainReceiverAddress: osmoUser.Bech32Address(cosmosOsmosis.Config().Bech32Prefix), }, - OsmoToNeutronChannelId: testCtx.OsmoTransferChannelIds[testCtx.Neutron.Config().Name], - Party1DenomInfo: PartyDenomInfo{ - OsmosisCoin: cw.Coin{Denom: osmosisAtomIbcDenom, Amount: strconv.FormatUint(atomContributionAmount, 10)}, - LocalDenom: neutronAtomIbcDenom, + } + + partyAConfig := InterchainCovenantParty{ + Addr: hubPartyNeutronAddr.Bech32Address(cosmosNeutron.Config().Bech32Prefix), + NativeDenom: neutronAtomIbcDenom, + RemoteChainDenom: "uatom", + PartyToHostChainChannelId: testCtx.GaiaTransferChannelIds[cosmosNeutron.Config().Name], + HostToPartyChainChannelId: testCtx.NeutronTransferChannelIds[cosmosAtom.Config().Name], + PartyReceiverAddr: hubReceiverAddr, + PartyChainConnectionId: neutronAtomIBCConnId, + IbcTransferTimeout: timeouts.IbcTransferTimeout, + Contribution: atomCoin, + DenomToPfmMap: party1PfmMap, + } + // for party 2 (osmosis), we need to route atom correctly - neutron->hub->osmosis + party2PfmMap := map[string]PacketForwardMiddlewareConfig{ + neutronAtomIbcDenom: { + LocalToHopChainChannelId: testCtx.NeutronTransferChannelIds[testCtx.Hub.Config().Name], + HopToDestinationChainChannelId: testCtx.GaiaTransferChannelIds[testCtx.Osmosis.Config().Name], + HopChainReceiverAddress: gaiaUser.Bech32Address(cosmosAtom.Config().Bech32Prefix), }, - Party2DenomInfo: PartyDenomInfo{ - OsmosisCoin: cw.Coin{Denom: testCtx.Osmosis.Config().Denom, Amount: strconv.FormatUint(osmoContributionAmount, 10)}, - LocalDenom: neutronOsmoIbcDenom, + } + partyBConfig := InterchainCovenantParty{ + Addr: osmoPartyNeutronAddr.Bech32Address(cosmosNeutron.Config().Bech32Prefix), + NativeDenom: neutronOsmoIbcDenom, + RemoteChainDenom: "uosmo", + PartyToHostChainChannelId: testCtx.OsmoTransferChannelIds[cosmosNeutron.Config().Name], + HostToPartyChainChannelId: testCtx.NeutronTransferChannelIds[cosmosOsmosis.Config().Name], + PartyReceiverAddr: osmoReceiverAddr, + PartyChainConnectionId: neutronOsmosisIBCConnId, + IbcTransferTimeout: timeouts.IbcTransferTimeout, + Contribution: osmoCoin, + DenomToPfmMap: party2PfmMap, + } + fundingDuration := Duration{ + Time: new(uint64), + } + *fundingDuration.Time = 300 + + liquidPoolerConfig := LiquidPoolerConfig{ + Osmosis: &OsmosisLiquidPoolerConfig{ + NoteAddress: noteAddress, + PoolId: "1", + OsmoIbcTimeout: "300", + Party1ChainInfo: PartyChainInfo{ + PartyChainToNeutronChannel: testCtx.GaiaTransferChannelIds[testCtx.Neutron.Config().Name], + NeutronToPartyChainChannel: testCtx.NeutronTransferChannelIds[testCtx.Hub.Config().Name], + InwardsPfm: &inwardsPfm, + OutwardsPfm: &outwardsPfm, + IbcTimeout: "300", + }, + Party2ChainInfo: PartyChainInfo{ + NeutronToPartyChainChannel: testCtx.NeutronTransferChannelIds[testCtx.Osmosis.Config().Name], + PartyChainToNeutronChannel: testCtx.OsmoTransferChannelIds[testCtx.Neutron.Config().Name], + IbcTimeout: "300", + }, + OsmoToNeutronChannelId: testCtx.OsmoTransferChannelIds[testCtx.Neutron.Config().Name], + Party1DenomInfo: PartyDenomInfo{ + OsmosisCoin: cw.Coin{Denom: osmosisAtomIbcDenom, Amount: strconv.FormatUint(atomContributionAmount, 10)}, + LocalDenom: neutronAtomIbcDenom, + }, + Party2DenomInfo: PartyDenomInfo{ + OsmosisCoin: cw.Coin{Denom: testCtx.Osmosis.Config().Denom, Amount: strconv.FormatUint(osmoContributionAmount, 10)}, + LocalDenom: neutronOsmoIbcDenom, + }, + LpTokenDenom: "gamm/pool/1", + OsmoOutpost: osmoOutpost, + FundingDuration: fundingDuration, + SingleSideLpLimits: SingleSideLpLimits{ + AssetALimit: "10000", + AssetBLimit: "975000004", + }, }, - LpTokenDenom: "gamm/pool/1", - OsmoOutpost: osmoOutpost, - FundingDuration: fundingDuration, - SingleSideLpLimits: SingleSideLpLimits{ - AssetALimit: "10000", - AssetBLimit: "975000004", + } + + covenantInstantiateMsg := CovenantInstantiateMsg{ + Label: "covenant-osmo", + Timeouts: timeouts, + ContractCodeIds: codeIds, + LockupConfig: lockupConfig, + PartyAConfig: CovenantPartyConfig{Interchain: &partyAConfig}, + PartyBConfig: CovenantPartyConfig{Interchain: &partyBConfig}, + DepositDeadline: depositDeadline, + CovenantType: "share", + PartyAShare: "0.5", + PartyBShare: "0.5", + PoolPriceConfig: PoolPriceConfig{ + ExpectedSpotPrice: "0.51", + AcceptablePriceSpread: "0.09", }, - }, - } + Splits: denomSplits, + FallbackSplit: nil, + EmergencyCommittee: neutronUser.Bech32Address(cosmosNeutron.Config().Bech32Prefix), + LiquidPoolerConfig: liquidPoolerConfig, + } - covenantInstantiateMsg := CovenantInstantiateMsg{ - Label: "covenant-osmo", - Timeouts: timeouts, - ContractCodeIds: codeIds, - LockupConfig: lockupConfig, - PartyAConfig: CovenantPartyConfig{Interchain: &partyAConfig}, - PartyBConfig: CovenantPartyConfig{Interchain: &partyBConfig}, - DepositDeadline: depositDeadline, - CovenantType: "share", - PartyAShare: "0.5", - PartyBShare: "0.5", - PoolPriceConfig: PoolPriceConfig{ - ExpectedSpotPrice: "0.1", - AcceptablePriceSpread: "0.09", - }, - Splits: denomSplits, - FallbackSplit: nil, - EmergencyCommittee: neutronUser.Bech32Address(cosmosNeutron.Config().Bech32Prefix), - LiquidPoolerConfig: liquidPoolerConfig, - } + covenantAddress = testCtx.ManualInstantiate(covenantRqCodeId, covenantInstantiateMsg, neutronUser, keyring.BackendTest) + println("covenantAddress address: ", covenantAddress) + }) + + t.Run("query covenant contracts", func(t *testing.T) { + clockAddress = testCtx.QueryClockAddress(covenantAddress) + holderAddress = testCtx.QueryHolderAddress(covenantAddress) + liquidPoolerAddress = testCtx.QueryLiquidPoolerAddress(covenantAddress) + partyARouterAddress = testCtx.QueryInterchainRouterAddress(covenantAddress, "party_a") + partyBRouterAddress = testCtx.QueryInterchainRouterAddress(covenantAddress, "party_b") + partyAIbcForwarderAddress = testCtx.QueryIbcForwarderAddress(covenantAddress, "party_a") + partyBIbcForwarderAddress = testCtx.QueryIbcForwarderAddress(covenantAddress, "party_b") + }) + + t.Run("fund contracts with neutron", func(t *testing.T) { + addrs := []string{ + partyAIbcForwarderAddress, + partyBIbcForwarderAddress, + clockAddress, + partyARouterAddress, + partyBRouterAddress, + holderAddress, + liquidPoolerAddress, + } + println("funding addresses with 5000000000untrn") + testCtx.FundChainAddrs(addrs, cosmosNeutron, neutronUser, 5000000000) + }) - covenantAddress = testCtx.ManualInstantiate(covenantCodeId, covenantInstantiateMsg, neutronUser, keyring.BackendTest) - println("covenantAddress address: ", covenantAddress) - }) + t.Run("tick until forwarders create ICA", func(t *testing.T) { + testCtx.SkipBlocks(5) + for { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) - t.Run("query covenant contracts", func(t *testing.T) { - clockAddress = testCtx.QueryClockAddress(covenantAddress) - holderAddress = testCtx.QueryHolderAddress(covenantAddress) - liquidPoolerAddress = testCtx.QueryLiquidPoolerAddress(covenantAddress) - partyARouterAddress = testCtx.QueryInterchainRouterAddress(covenantAddress, "party_a") - partyBRouterAddress = testCtx.QueryInterchainRouterAddress(covenantAddress, "party_b") - partyAIbcForwarderAddress = testCtx.QueryIbcForwarderAddress(covenantAddress, "party_a") - partyBIbcForwarderAddress = testCtx.QueryIbcForwarderAddress(covenantAddress, "party_b") - }) + forwarderAState := testCtx.QueryContractState(partyAIbcForwarderAddress) + forwarderBState := testCtx.QueryContractState(partyBIbcForwarderAddress) - t.Run("fund contracts with neutron", func(t *testing.T) { - addrs := []string{ - partyAIbcForwarderAddress, - partyBIbcForwarderAddress, - clockAddress, - partyARouterAddress, - partyBRouterAddress, - holderAddress, - liquidPoolerAddress, - } - println("funding addresses with 5000000000untrn") - testCtx.FundChainAddrs(addrs, cosmosNeutron, neutronUser, 5000000000) - }) + if forwarderAState == forwarderBState && forwarderBState == "ica_created" { + testCtx.SkipBlocks(3) + partyADepositAddress = testCtx.QueryDepositAddress(covenantAddress, "party_a") + partyBDepositAddress = testCtx.QueryDepositAddress(covenantAddress, "party_b") + break + } + } + }) - t.Run("tick until forwarders create ICA", func(t *testing.T) { - testCtx.SkipBlocks(5) - for { - testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + t.Run("fund the forwarders with sufficient funds", func(t *testing.T) { + testCtx.FundChainAddrs([]string{partyBDepositAddress}, cosmosOsmosis, sadCaseOsmoAccount, int64(osmoContributionAmount)) + testCtx.FundChainAddrs([]string{partyADepositAddress}, cosmosAtom, sadCaseHubAccount, int64(atomContributionAmount)) - forwarderAState := testCtx.QueryContractState(partyAIbcForwarderAddress) - forwarderBState := testCtx.QueryContractState(partyBIbcForwarderAddress) + testCtx.SkipBlocks(5) - if forwarderAState == forwarderBState && forwarderBState == "ica_created" { - testCtx.SkipBlocks(3) - partyADepositAddress = testCtx.QueryDepositAddress(covenantAddress, "party_a") - partyBDepositAddress = testCtx.QueryDepositAddress(covenantAddress, "party_b") - break + osmoBal := testCtx.QueryOsmoDenomBalance(cosmosOsmosis.Config().Denom, partyBDepositAddress) + atomBal := testCtx.QueryHubDenomBalance(nativeAtomDenom, partyADepositAddress) + println("covenant party deposits") + println(partyADepositAddress, " balance: ", atomBal, nativeAtomDenom) + println(partyBDepositAddress, " balance: ", osmoBal, cosmosOsmosis.Config().Denom) + }) + + t.Run("tick until forwarders forward the funds to holder", func(t *testing.T) { + for { + holderOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, holderAddress) + holderAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, holderAddress) + holderState := testCtx.QueryContractState(holderAddress) + + println("holder atom bal: ", holderAtomBal) + println("holder osmo bal: ", holderOsmoBal) + println("holder state: ", holderState) + + if holderAtomBal == atomContributionAmount && holderOsmoBal == osmoContributionAmount { + println("holder received atom & osmo") + break + } else if holderState == "active" { + println("holder is active") + break + } else { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } + } + }) + + t.Run("tick until holder sends funds to LP", func(t *testing.T) { + for { + liquidPoolerAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, liquidPoolerAddress) + liquidPoolerOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, liquidPoolerAddress) + + if liquidPoolerAtomBal == 0 && liquidPoolerOsmoBal != 0 { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } else { + break + } + } + }) + + t.Run("tick until liquid pooler proxy is created", func(t *testing.T) { + for { + lperState := testCtx.QueryContractState(liquidPoolerAddress) + println("osmo liquid pooler state: ", lperState) + if lperState == "proxy_created" { + proxyAddress = testCtx.QueryProxyAddress(liquidPoolerAddress) + println("proxy address: ", proxyAddress) + break + } else { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } + } + }) + + t.Run("tick until proxy is funded", func(t *testing.T) { + for { + proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) + proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) + println("proxy atom bal: ", proxyAtomBal) + println("proxy osmo bal: ", proxyOsmoBal) + if proxyAtomBal != 0 && proxyOsmoBal != 0 { + break + } else { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } + } + }) + + t.Run("perform withdrawal", func(t *testing.T) { + liquidPoolerState := testCtx.QueryContractState(liquidPoolerAddress) + println("liquid pooler state: ", liquidPoolerState) + cmd := []string{"neutrond", "tx", "wasm", "execute", holderAddress, + `{"emergency_withdraw":{}}`, + "--from", neutronUser.GetKeyName(), + "--gas-prices", "0.0untrn", + "--gas-adjustment", `1.5`, + "--output", "json", + "--node", testCtx.Neutron.GetRPCAddress(), + "--home", testCtx.Neutron.HomeDir(), + "--chain-id", testCtx.Neutron.Config().ChainID, + "--gas", "42069420", + "--keyring-backend", keyring.BackendTest, + "-y", } - } - }) - t.Run("fund the forwarders with sufficient funds", func(t *testing.T) { - testCtx.FundChainAddrs([]string{partyBDepositAddress}, cosmosOsmosis, happyCaseOsmoAccount, int64(osmoContributionAmount)) - testCtx.FundChainAddrs([]string{partyADepositAddress}, cosmosAtom, happyCaseHubAccount, int64(atomContributionAmount)) + stdout, stderr, err := testCtx.Neutron.Exec(testCtx.Ctx, cmd, nil) + require.NoError(testCtx.T, err, err) - testCtx.SkipBlocks(5) + println("withdraw stdout: ", string(stdout)) + println("withdraw stderr: ", string(stderr)) - osmoBal := testCtx.QueryOsmoDenomBalance(cosmosOsmosis.Config().Denom, partyBDepositAddress) - atomBal := testCtx.QueryHubDenomBalance(nativeAtomDenom, partyADepositAddress) - println("covenant party deposits") - println(partyADepositAddress, " balance: ", atomBal, nativeAtomDenom) - println(partyBDepositAddress, " balance: ", osmoBal, cosmosOsmosis.Config().Denom) - }) + for { + proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) + proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) + println("proxy atom bal: ", proxyAtomBal) + println("proxy osmo bal: ", proxyOsmoBal) - t.Run("tick until forwarders forward the funds to holder", func(t *testing.T) { - for { - holderOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, holderAddress) - holderAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, holderAddress) - holderState := testCtx.QueryContractState(holderAddress) - - println("holder atom bal: ", holderAtomBal) - println("holder osmo bal: ", holderOsmoBal) - println("holder state: ", holderState) - - if holderAtomBal == atomContributionAmount && holderOsmoBal == osmoContributionAmount { - println("holder received atom & osmo") - break - } else if holderState == "active" { - println("holder is active") - break - } else { - testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) - } - } - }) + lperAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, liquidPoolerAddress) + lperOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, liquidPoolerAddress) - t.Run("tick until holder sends funds to LP", func(t *testing.T) { - for { - liquidPoolerAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, liquidPoolerAddress) - liquidPoolerOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, liquidPoolerAddress) + println("liquid pooler atom bal: ", lperAtomBal) + println("liquid pooler osmo bal: ", lperOsmoBal) - if liquidPoolerAtomBal == 0 && liquidPoolerOsmoBal != 0 { - testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) - } else { - break + p1RouterAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, partyARouterAddress) + p1RouterOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, partyARouterAddress) + + p2RouterAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, partyBRouterAddress) + p2RouterOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, partyBRouterAddress) + println("p1RouterAtomBal: ", p1RouterAtomBal) + println("p1RouterOsmoBal: ", p1RouterOsmoBal) + println("p2RouterAtomBal: ", p2RouterAtomBal) + println("p2RouterOsmoBal: ", p2RouterOsmoBal) + + if p1RouterAtomBal != 0 || p1RouterOsmoBal != 0 || p2RouterAtomBal != 0 || p2RouterOsmoBal != 0 { + println("withdraw success!") + break + } else { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } } - } + }) + + t.Run("tick until parties get their funds", func(t *testing.T) { + for { + hubPartyReceiverAddrAtomBal := testCtx.QueryHubDenomBalance( + "uatom", + sadCaseHubAccount.Bech32Address(cosmosAtom.Config().Bech32Prefix), + ) + hubPartyReceiverAddrOsmoBal := testCtx.QueryHubDenomBalance( + hubOsmoIbcDenom, + sadCaseHubAccount.Bech32Address(cosmosAtom.Config().Bech32Prefix), + ) + osmoPartyReceiverAddrOsmoBal := testCtx.QueryOsmoDenomBalance( + "uosmo", + sadCaseOsmoAccount.Bech32Address(cosmosOsmosis.Config().Bech32Prefix), + ) + osmoPartyReceiverAddrAtomBal := testCtx.QueryOsmoDenomBalance( + osmosisAtomIbcDenom, + sadCaseOsmoAccount.Bech32Address(cosmosOsmosis.Config().Bech32Prefix), + ) + + println("hubPartyReceiverAddrAtomBal", hubPartyReceiverAddrAtomBal) + println("hubPartyReceiverAddrOsmoBal", hubPartyReceiverAddrOsmoBal) + println("osmoPartyReceiverAddrOsmoBal", osmoPartyReceiverAddrOsmoBal) + println("osmoPartyReceiverAddrAtomBal", osmoPartyReceiverAddrAtomBal) + + if osmoPartyReceiverAddrOsmoBal != 0 && osmoPartyReceiverAddrAtomBal != 0 && hubPartyReceiverAddrAtomBal != 0 && hubPartyReceiverAddrOsmoBal != 0 { + println("parties received the funds") + break + } else { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } + } + }) }) - t.Run("tick until liquid pooler proxy is created", func(t *testing.T) { - for { - lperState := testCtx.QueryContractState(liquidPoolerAddress) - println("osmo liquid pooler state: ", lperState) - if lperState == "proxy_created" { - proxyAddress = testCtx.QueryProxyAddress(liquidPoolerAddress) - println("proxy address: ", proxyAddress) - break - } else { - testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + t.Run("two party POL full path", func(t *testing.T) { + t.Run("instantiate covenant", func(t *testing.T) { + timeouts := Timeouts{ + IcaTimeout: "100", // sec + IbcTransferTimeout: "100", // sec } - } - }) - t.Run("tick until proxy is funded", func(t *testing.T) { - for { - proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) - proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) - println("proxy atom bal: ", proxyAtomBal) - println("proxy osmo bal: ", proxyOsmoBal) - if proxyAtomBal != 0 && proxyOsmoBal != 0 { - break - } else { - testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + currentHeight := testCtx.GetNeutronHeight() + depositBlock := Block(currentHeight + 250) + lockupBlock := Block(currentHeight + 300) + lockupConfig := Expiration{ + AtHeight: &lockupBlock, + } + depositDeadline := Expiration{ + AtHeight: &depositBlock, } - } - }) - t.Run("perform withdrawal", func(t *testing.T) { - response, err := testCtx.Neutron.ExecuteContract( - testCtx.Ctx, - keyring.BackendTest, - holderAddress, - `{"emergency_withdraw":{}}`, - ) + hubReceiverAddr := happyCaseHubAccount.Bech32Address(cosmosAtom.Config().Bech32Prefix) + osmoReceiverAddr := happyCaseOsmoAccount.Bech32Address(cosmosOsmosis.Config().Bech32Prefix) - println("withdraw response: ", string(response)) - println("withdraw error: ", err) + atomCoin := Coin{ + Denom: cosmosAtom.Config().Denom, + Amount: strconv.FormatUint(atomContributionAmount, 10), + } - for { - proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) - proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) - println("proxy atom bal: ", proxyAtomBal) - println("proxy osmo bal: ", proxyOsmoBal) + osmoCoin := Coin{ + Denom: cosmosOsmosis.Config().Denom, + Amount: strconv.FormatUint(osmoContributionAmount, 10), + } - lperAtomBal := testCtx.QueryOsmoDenomBalance(neutronAtomIbcDenom, liquidPoolerAddress) - lperOsmoBal := testCtx.QueryOsmoDenomBalance(neutronOsmoIbcDenom, liquidPoolerAddress) + outwardsPfm := ForwardMetadata{ + Receiver: gaiaUser.Bech32Address(testCtx.Hub.Config().Bech32Prefix), + Port: "transfer", + Channel: testCtx.GaiaTransferChannelIds[testCtx.Osmosis.Config().Name], + } - println("liquid pooler atom bal: ", lperAtomBal) - println("liquid pooler osmo bal: ", lperOsmoBal) + inwardsPfm := ForwardMetadata{ + Receiver: gaiaUser.Bech32Address(testCtx.Hub.Config().Bech32Prefix), + Port: "transfer", + Channel: testCtx.OsmoTransferChannelIds[testCtx.Hub.Config().Name], + } - holderAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, holderAddress) - holderOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, holderAddress) + codeIds := ContractCodeIds{ + IbcForwarderCode: ibcForwarderCodeId, + InterchainRouterCode: interchainRouterCodeId, + NativeRouterCode: nativeRouterCodeId, + ClockCode: clockCodeId, + HolderCode: holderCodeId, + LiquidPoolerCode: lperCodeId, + } - println("holder atom bal: ", holderAtomBal) - println("holder osmo bal: ", holderOsmoBal) + denomSplits := map[string]SplitConfig{ + neutronAtomIbcDenom: { + Receivers: map[string]string{ + hubReceiverAddr: "0.5", + osmoReceiverAddr: "0.5", + }, + }, + neutronOsmoIbcDenom: { + Receivers: map[string]string{ + hubReceiverAddr: "0.5", + osmoReceiverAddr: "0.5", + }, + }, + } - if holderAtomBal != 0 && holderOsmoBal != 0 { - println("withdraw success!") - break - } else { - testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + // for party 1 (hub), we need to route osmosis correctly - neutron->osmosis->hub + party1PfmMap := map[string]PacketForwardMiddlewareConfig{ + neutronOsmoIbcDenom: { + LocalToHopChainChannelId: testCtx.NeutronTransferChannelIds[testCtx.Osmosis.Config().Name], + HopToDestinationChainChannelId: testCtx.OsmoTransferChannelIds[testCtx.Hub.Config().Name], + HopChainReceiverAddress: osmoUser.Bech32Address(cosmosOsmosis.Config().Bech32Prefix), + }, } - } - }) - t.Run("tick until liquidity is provided and proxy receives gamm tokens", func(t *testing.T) { - neutronGammDenom := testCtx.GetIbcDenom( - testCtx.NeutronTransferChannelIds[cosmosOsmosis.Config().Name], - "gamm/pool/1", - ) + partyAConfig := InterchainCovenantParty{ + Addr: hubPartyNeutronAddr.Bech32Address(cosmosNeutron.Config().Bech32Prefix), + NativeDenom: neutronAtomIbcDenom, + RemoteChainDenom: "uatom", + PartyToHostChainChannelId: testCtx.GaiaTransferChannelIds[cosmosNeutron.Config().Name], + HostToPartyChainChannelId: testCtx.NeutronTransferChannelIds[cosmosAtom.Config().Name], + PartyReceiverAddr: hubReceiverAddr, + PartyChainConnectionId: neutronAtomIBCConnId, + IbcTransferTimeout: timeouts.IbcTransferTimeout, + Contribution: atomCoin, + DenomToPfmMap: party1PfmMap, + } + // for party 2 (osmosis), we need to route atom correctly - neutron->hub->osmosis + party2PfmMap := map[string]PacketForwardMiddlewareConfig{ + neutronAtomIbcDenom: { + LocalToHopChainChannelId: testCtx.NeutronTransferChannelIds[testCtx.Hub.Config().Name], + HopToDestinationChainChannelId: testCtx.GaiaTransferChannelIds[testCtx.Osmosis.Config().Name], + HopChainReceiverAddress: gaiaUser.Bech32Address(cosmosAtom.Config().Bech32Prefix), + }, + } + partyBConfig := InterchainCovenantParty{ + Addr: osmoPartyNeutronAddr.Bech32Address(cosmosNeutron.Config().Bech32Prefix), + NativeDenom: neutronOsmoIbcDenom, + RemoteChainDenom: "uosmo", + PartyToHostChainChannelId: testCtx.OsmoTransferChannelIds[cosmosNeutron.Config().Name], + HostToPartyChainChannelId: testCtx.NeutronTransferChannelIds[cosmosOsmosis.Config().Name], + PartyReceiverAddr: osmoReceiverAddr, + PartyChainConnectionId: neutronOsmosisIBCConnId, + IbcTransferTimeout: timeouts.IbcTransferTimeout, + Contribution: osmoCoin, + DenomToPfmMap: party2PfmMap, + } + fundingDuration := Duration{ + Time: new(uint64), + } + *fundingDuration.Time = 400 + + liquidPoolerConfig := LiquidPoolerConfig{ + Osmosis: &OsmosisLiquidPoolerConfig{ + NoteAddress: noteAddress, + PoolId: "1", + OsmoIbcTimeout: "300", + Party1ChainInfo: PartyChainInfo{ + PartyChainToNeutronChannel: testCtx.GaiaTransferChannelIds[testCtx.Neutron.Config().Name], + NeutronToPartyChainChannel: testCtx.NeutronTransferChannelIds[testCtx.Hub.Config().Name], + InwardsPfm: &inwardsPfm, + OutwardsPfm: &outwardsPfm, + IbcTimeout: "300", + }, + Party2ChainInfo: PartyChainInfo{ + NeutronToPartyChainChannel: testCtx.NeutronTransferChannelIds[testCtx.Osmosis.Config().Name], + PartyChainToNeutronChannel: testCtx.OsmoTransferChannelIds[testCtx.Neutron.Config().Name], + IbcTimeout: "300", + }, + OsmoToNeutronChannelId: testCtx.OsmoTransferChannelIds[testCtx.Neutron.Config().Name], + Party1DenomInfo: PartyDenomInfo{ + OsmosisCoin: cw.Coin{Denom: osmosisAtomIbcDenom, Amount: strconv.FormatUint(atomContributionAmount, 10)}, + LocalDenom: neutronAtomIbcDenom, + }, + Party2DenomInfo: PartyDenomInfo{ + OsmosisCoin: cw.Coin{Denom: testCtx.Osmosis.Config().Denom, Amount: strconv.FormatUint(osmoContributionAmount, 10)}, + LocalDenom: neutronOsmoIbcDenom, + }, + LpTokenDenom: "gamm/pool/1", + OsmoOutpost: osmoOutpost, + FundingDuration: fundingDuration, + SingleSideLpLimits: SingleSideLpLimits{ + AssetALimit: "10000", + AssetBLimit: "975000004", + }, + }, + } - for { - osmoLiquidPoolerGammBalance := testCtx.QueryNeutronDenomBalance(neutronGammDenom, liquidPoolerAddress) - proxyGammBalance := testCtx.QueryOsmoDenomBalance("gamm/pool/1", proxyAddress) - proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) - proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) - outpostAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, osmoOutpost) - outpostOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, osmoOutpost) - outpostGammBalance := testCtx.QueryOsmoDenomBalance("gamm/pool/1", osmoOutpost) - - println("proxy atom bal: ", proxyAtomBal) - println("proxy osmo bal: ", proxyOsmoBal) - println("outpost atom bal: ", outpostAtomBal) - println("outpost osmo bal: ", outpostOsmoBal) - println("outpost gamm token balance: ", outpostGammBalance) - println("proxy gamm token balance: ", proxyGammBalance) - println("osmo liquid pooler gamm token balance: ", osmoLiquidPoolerGammBalance) - - if proxyGammBalance != 0 && proxyAtomBal == 0 && proxyOsmoBal == 0 { - break - } else { - testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) - testCtx.SkipBlocks(2) + covenantInstantiateMsg := CovenantInstantiateMsg{ + Label: "covenant-osmo", + Timeouts: timeouts, + ContractCodeIds: codeIds, + LockupConfig: lockupConfig, + PartyAConfig: CovenantPartyConfig{Interchain: &partyAConfig}, + PartyBConfig: CovenantPartyConfig{Interchain: &partyBConfig}, + DepositDeadline: depositDeadline, + CovenantType: "share", + PartyAShare: "0.5", + PartyBShare: "0.5", + PoolPriceConfig: PoolPriceConfig{ + ExpectedSpotPrice: "0.1", + AcceptablePriceSpread: "0.09", + }, + Splits: denomSplits, + FallbackSplit: nil, + EmergencyCommittee: neutronUser.Bech32Address(cosmosNeutron.Config().Bech32Prefix), + LiquidPoolerConfig: liquidPoolerConfig, } - } - }) - t.Run("osmo party claims", func(t *testing.T) { - // try to withdraw until lp tokens are gone from proxy - testCtx.SkipBlocks(5) - testCtx.HolderClaim(holderAddress, osmoPartyNeutronAddr, keyring.BackendTest) + covenantAddress = testCtx.ManualInstantiate(covenantCodeId, covenantInstantiateMsg, neutronUser, keyring.BackendTest) + println("covenantAddress address: ", covenantAddress) + }) + + t.Run("query covenant contracts", func(t *testing.T) { + clockAddress = testCtx.QueryClockAddress(covenantAddress) + holderAddress = testCtx.QueryHolderAddress(covenantAddress) + liquidPoolerAddress = testCtx.QueryLiquidPoolerAddress(covenantAddress) + partyARouterAddress = testCtx.QueryInterchainRouterAddress(covenantAddress, "party_a") + partyBRouterAddress = testCtx.QueryInterchainRouterAddress(covenantAddress, "party_b") + partyAIbcForwarderAddress = testCtx.QueryIbcForwarderAddress(covenantAddress, "party_a") + partyBIbcForwarderAddress = testCtx.QueryIbcForwarderAddress(covenantAddress, "party_b") + }) + + t.Run("fund contracts with neutron", func(t *testing.T) { + addrs := []string{ + partyAIbcForwarderAddress, + partyBIbcForwarderAddress, + clockAddress, + partyARouterAddress, + partyBRouterAddress, + holderAddress, + liquidPoolerAddress, + } + println("funding addresses with 5000000000untrn") + testCtx.FundChainAddrs(addrs, cosmosNeutron, neutronUser, 5000000000) + }) - for { + t.Run("tick until forwarders create ICA", func(t *testing.T) { testCtx.SkipBlocks(5) + for { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) - testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) - proxyGammBalance := testCtx.QueryOsmoDenomBalance("gamm/pool/1", proxyAddress) - proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) - proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) - holderOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, holderAddress) - holderAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, holderAddress) - lperAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, liquidPoolerAddress) - lperOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, liquidPoolerAddress) - osmoPartyReceiverAddrOsmoBal := testCtx.QueryOsmoDenomBalance("uosmo", happyCaseOsmoAccount.Bech32Address(cosmosOsmosis.Config().Bech32Prefix)) - osmoPartyReceiverAddrAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, happyCaseOsmoAccount.Bech32Address(cosmosOsmosis.Config().Bech32Prefix)) - - println("holder osmo bal: ", holderOsmoBal) - println("holder atom bal: ", holderAtomBal) + forwarderAState := testCtx.QueryContractState(partyAIbcForwarderAddress) + forwarderBState := testCtx.QueryContractState(partyBIbcForwarderAddress) - println("proxy atom bal: ", proxyAtomBal) - println("proxy osmo bal: ", proxyOsmoBal) - println("proxy gamm token balance: ", proxyGammBalance) + if forwarderAState == forwarderBState && forwarderBState == "ica_created" { + testCtx.SkipBlocks(3) + partyADepositAddress = testCtx.QueryDepositAddress(covenantAddress, "party_a") + partyBDepositAddress = testCtx.QueryDepositAddress(covenantAddress, "party_b") + break + } + } + }) - println("liquid pooler osmo bal: ", lperOsmoBal) - println("liquid pooler atom bal: ", lperAtomBal) + t.Run("fund the forwarders with sufficient funds", func(t *testing.T) { + testCtx.FundChainAddrs([]string{partyBDepositAddress}, cosmosOsmosis, happyCaseOsmoAccount, int64(osmoContributionAmount)) + testCtx.FundChainAddrs([]string{partyADepositAddress}, cosmosAtom, happyCaseHubAccount, int64(atomContributionAmount)) - println("osmoPartyReceiverAddrOsmoBal", osmoPartyReceiverAddrOsmoBal) - println("osmoPartyReceiverAddrAtomBal", osmoPartyReceiverAddrAtomBal) + testCtx.SkipBlocks(5) - if osmoPartyReceiverAddrOsmoBal != 0 && osmoPartyReceiverAddrAtomBal != 0 { - println("claiming party received the funds") - break + osmoBal := testCtx.QueryOsmoDenomBalance(cosmosOsmosis.Config().Denom, partyBDepositAddress) + atomBal := testCtx.QueryHubDenomBalance(nativeAtomDenom, partyADepositAddress) + println("covenant party deposits") + println(partyADepositAddress, " balance: ", atomBal, nativeAtomDenom) + println(partyBDepositAddress, " balance: ", osmoBal, cosmosOsmosis.Config().Denom) + }) + + t.Run("tick until forwarders forward the funds to holder", func(t *testing.T) { + for { + holderOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, holderAddress) + holderAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, holderAddress) + holderState := testCtx.QueryContractState(holderAddress) + + println("holder atom bal: ", holderAtomBal) + println("holder osmo bal: ", holderOsmoBal) + println("holder state: ", holderState) + + if holderAtomBal == atomContributionAmount && holderOsmoBal == osmoContributionAmount { + println("holder received atom & osmo") + break + } else if holderState == "active" { + println("holder is active") + break + } else { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } } - } - }) - - t.Run("tick until we are able to withdraw", func(t *testing.T) { - testCtx.SkipBlocks(10) - tickCount := 0 - for { - testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) - testCtx.SkipBlocks(2) - tickCount = tickCount + 1 - if tickCount == 6 { - break + }) + + t.Run("tick until holder sends funds to LP", func(t *testing.T) { + for { + liquidPoolerAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, liquidPoolerAddress) + liquidPoolerOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, liquidPoolerAddress) + + if liquidPoolerAtomBal == 0 && liquidPoolerOsmoBal != 0 { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } else { + break + } } - } - - testCtx.HolderClaim(holderAddress, hubPartyNeutronAddr, keyring.BackendTest) - testCtx.SkipBlocks(10) + }) + + t.Run("tick until liquid pooler proxy is created", func(t *testing.T) { + for { + lperState := testCtx.QueryContractState(liquidPoolerAddress) + println("osmo liquid pooler state: ", lperState) + if lperState == "proxy_created" { + proxyAddress = testCtx.QueryProxyAddress(liquidPoolerAddress) + println("proxy address: ", proxyAddress) + break + } else { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } + } + }) + + t.Run("tick until proxy is funded", func(t *testing.T) { + for { + proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) + proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) + println("proxy atom bal: ", proxyAtomBal) + println("proxy osmo bal: ", proxyOsmoBal) + if proxyAtomBal != 0 && proxyOsmoBal != 0 { + break + } else { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + } + } + }) + + t.Run("tick until liquidity is provided and proxy receives gamm tokens", func(t *testing.T) { + neutronGammDenom := testCtx.GetIbcDenom( + testCtx.NeutronTransferChannelIds[cosmosOsmosis.Config().Name], + "gamm/pool/1", + ) + + for { + osmoLiquidPoolerGammBalance := testCtx.QueryNeutronDenomBalance(neutronGammDenom, liquidPoolerAddress) + proxyGammBalance := testCtx.QueryOsmoDenomBalance("gamm/pool/1", proxyAddress) + proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) + proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) + outpostAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, osmoOutpost) + outpostOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, osmoOutpost) + outpostGammBalance := testCtx.QueryOsmoDenomBalance("gamm/pool/1", osmoOutpost) + + println("proxy atom bal: ", proxyAtomBal) + println("proxy osmo bal: ", proxyOsmoBal) + println("outpost atom bal: ", outpostAtomBal) + println("outpost osmo bal: ", outpostOsmoBal) + println("outpost gamm token balance: ", outpostGammBalance) + println("proxy gamm token balance: ", proxyGammBalance) + println("osmo liquid pooler gamm token balance: ", osmoLiquidPoolerGammBalance) + + if proxyGammBalance != 0 && proxyAtomBal == 0 && proxyOsmoBal == 0 { + break + } else { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + testCtx.SkipBlocks(2) + } + } + }) - for { - testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + t.Run("osmo party claims", func(t *testing.T) { + // try to withdraw until lp tokens are gone from proxy testCtx.SkipBlocks(5) - proxyGammBalance := testCtx.QueryOsmoDenomBalance("gamm/pool/1", proxyAddress) - proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) - proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) - holderOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, holderAddress) - holderAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, holderAddress) - lperAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, liquidPoolerAddress) - lperOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, liquidPoolerAddress) + testCtx.HolderClaim(holderAddress, osmoPartyNeutronAddr, keyring.BackendTest) - println("holder osmo bal: ", holderOsmoBal) - println("holder atom bal: ", holderAtomBal) + for { + testCtx.SkipBlocks(5) - println("proxy atom bal: ", proxyAtomBal) - println("proxy osmo bal: ", proxyOsmoBal) - println("proxy gamm token balance: ", proxyGammBalance) - - println("liquid pooler osmo bal: ", lperOsmoBal) - println("liquid pooler atom bal: ", lperAtomBal) + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + proxyGammBalance := testCtx.QueryOsmoDenomBalance("gamm/pool/1", proxyAddress) + proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) + proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) + holderOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, holderAddress) + holderAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, holderAddress) + lperAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, liquidPoolerAddress) + lperOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, liquidPoolerAddress) + osmoPartyReceiverAddrOsmoBal := testCtx.QueryOsmoDenomBalance("uosmo", happyCaseOsmoAccount.Bech32Address(cosmosOsmosis.Config().Bech32Prefix)) + osmoPartyReceiverAddrAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, happyCaseOsmoAccount.Bech32Address(cosmosOsmosis.Config().Bech32Prefix)) + + println("holder osmo bal: ", holderOsmoBal) + println("holder atom bal: ", holderAtomBal) + + println("proxy atom bal: ", proxyAtomBal) + println("proxy osmo bal: ", proxyOsmoBal) + println("proxy gamm token balance: ", proxyGammBalance) + + println("liquid pooler osmo bal: ", lperOsmoBal) + println("liquid pooler atom bal: ", lperAtomBal) + + println("osmoPartyReceiverAddrOsmoBal", osmoPartyReceiverAddrOsmoBal) + println("osmoPartyReceiverAddrAtomBal", osmoPartyReceiverAddrAtomBal) + + if osmoPartyReceiverAddrOsmoBal != 0 && osmoPartyReceiverAddrAtomBal != 0 { + println("claiming party received the funds") + break + } + } + }) - hubPartyReceiverAddrAtomBal := testCtx.QueryHubDenomBalance("uatom", happyCaseHubAccount.Bech32Address(cosmosAtom.Config().Bech32Prefix)) - hubPartyReceiverAddrOsmoBal := testCtx.QueryHubDenomBalance(hubOsmoIbcDenom, happyCaseHubAccount.Bech32Address(cosmosAtom.Config().Bech32Prefix)) + t.Run("tick until we are able to withdraw", func(t *testing.T) { + testCtx.SkipBlocks(10) + tickCount := 0 + for { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + testCtx.SkipBlocks(2) + tickCount = tickCount + 1 + if tickCount == 6 { + break + } + } - println("hubPartyReceiverAddrAtomBal", hubPartyReceiverAddrAtomBal) - println("hubPartyReceiverAddrOsmoBal", hubPartyReceiverAddrOsmoBal) + testCtx.HolderClaim(holderAddress, hubPartyNeutronAddr, keyring.BackendTest) + testCtx.SkipBlocks(10) - if hubPartyReceiverAddrAtomBal != 0 && hubPartyReceiverAddrOsmoBal != 0 { - println("claiming party received the funds") - break + for { + testCtx.Tick(clockAddress, keyring.BackendTest, neutronUser.KeyName) + testCtx.SkipBlocks(5) + proxyGammBalance := testCtx.QueryOsmoDenomBalance("gamm/pool/1", proxyAddress) + proxyAtomBal := testCtx.QueryOsmoDenomBalance(osmosisAtomIbcDenom, proxyAddress) + proxyOsmoBal := testCtx.QueryOsmoDenomBalance(testCtx.Osmosis.Config().Denom, proxyAddress) + holderOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, holderAddress) + holderAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, holderAddress) + lperAtomBal := testCtx.QueryNeutronDenomBalance(neutronAtomIbcDenom, liquidPoolerAddress) + lperOsmoBal := testCtx.QueryNeutronDenomBalance(neutronOsmoIbcDenom, liquidPoolerAddress) + + println("holder osmo bal: ", holderOsmoBal) + println("holder atom bal: ", holderAtomBal) + + println("proxy atom bal: ", proxyAtomBal) + println("proxy osmo bal: ", proxyOsmoBal) + println("proxy gamm token balance: ", proxyGammBalance) + + println("liquid pooler osmo bal: ", lperOsmoBal) + println("liquid pooler atom bal: ", lperAtomBal) + + hubPartyReceiverAddrAtomBal := testCtx.QueryHubDenomBalance("uatom", happyCaseHubAccount.Bech32Address(cosmosAtom.Config().Bech32Prefix)) + hubPartyReceiverAddrOsmoBal := testCtx.QueryHubDenomBalance(hubOsmoIbcDenom, happyCaseHubAccount.Bech32Address(cosmosAtom.Config().Bech32Prefix)) + + println("hubPartyReceiverAddrAtomBal", hubPartyReceiverAddrAtomBal) + println("hubPartyReceiverAddrOsmoBal", hubPartyReceiverAddrOsmoBal) + + if hubPartyReceiverAddrAtomBal != 0 && hubPartyReceiverAddrOsmoBal != 0 { + println("claiming party received the funds") + break + } } - } + }) }) }) } diff --git a/interchaintest/utils/connection_helpers.go b/interchaintest/utils/connection_helpers.go index 6aa31f3a..6bc0f6c3 100644 --- a/interchaintest/utils/connection_helpers.go +++ b/interchaintest/utils/connection_helpers.go @@ -895,12 +895,12 @@ func (testCtx *TestContext) ManualInstantiate(codeId uint64, msg any, from *ibc. covInstantiationResp, _, err := testCtx.Neutron.Exec(testCtx.Ctx, cmd, nil) println("covenant instantiation response: ", string(covInstantiationResp)) - testCtx.SkipBlocks(50) + testCtx.SkipBlocks(5) if err != nil { println("manual instantiation failed") } - testCtx.SkipBlocks(10) + testCtx.SkipBlocks(5) queryCmd := []string{"neutrond", "query", "wasm", "list-contract-by-code", codeIdStr, From 20099febe32e261686de765cf7c12e718b72d2ea Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 19 Apr 2024 20:54:48 +0200 Subject: [PATCH 52/56] handling pre and post-proxy funding party denom withdraw cases in osmo liquid pooler --- contracts/osmo-liquid-pooler/src/contract.rs | 126 +++++++++++++++---- contracts/osmo-liquid-pooler/src/msg.rs | 13 +- 2 files changed, 112 insertions(+), 27 deletions(-) diff --git a/contracts/osmo-liquid-pooler/src/contract.rs b/contracts/osmo-liquid-pooler/src/contract.rs index 6300602e..804069bb 100644 --- a/contracts/osmo-liquid-pooler/src/contract.rs +++ b/contracts/osmo-liquid-pooler/src/contract.rs @@ -147,34 +147,89 @@ fn try_initiate_withdrawal( ); // we advance the contract state to `PendingWithdrawal` and force latest balances sync - CONTRACT_STATE.save( - deps.storage, - &ContractState::PendingWithdrawal { + CONTRACT_STATE.update(deps.storage, |contract_state| -> StdResult<_> { + let new_state = ContractState::PendingWithdrawal { share: withdraw_share, - }, - )?; + prev_state: Box::new(contract_state), + }; + Ok(new_state) + })?; LIQUIDITY_PROVISIONING_CONFIG.update(deps.storage, |mut lp_config| -> StdResult<_> { lp_config.reset_latest_proxy_balances(); Ok(lp_config) })?; Ok(Response::default() - .add_attribute("method", "try_withdraw") + .add_attribute("method", "try_initiate_withdrawal") .add_attribute("contract_state", "pending_withdrawal") .add_attribute("pending_withdrawal", withdraw_share.to_string())) } -/// this method will attempt to set the contract state to `Distributing`, -/// with any non-lp token denoms available on our remote proxy. -/// doing so will cause upcoming ticks to try to send the withdrawn coins -/// to the holder, completing the withdrawal flow and reverting this contract -/// to active state. -fn withdraw_party_denoms( +fn try_withdraw_pre_proxy_funding_denoms( + deps: ExecuteDeps, + env: Env, + lp_config: LiquidityProvisionConfig, + prev_state: ContractState, +) -> NeutronResult> { + let mut withdraw_coins: Vec = Vec::with_capacity(2); + let p1_bal = deps.querier.query_balance( + env.contract.address.to_string(), + lp_config.party_1_denom_info.local_denom.to_string(), + )?; + let p2_bal = deps.querier.query_balance( + env.contract.address.to_string(), + lp_config.party_2_denom_info.local_denom.to_string(), + )?; + + if p1_bal.amount > Uint128::zero() { + withdraw_coins.push(p1_bal.clone()); + } + if p2_bal.amount > Uint128::zero() { + withdraw_coins.push(p2_bal.clone()); + } + + if withdraw_coins.is_empty() { + // both both balances are zero, we revert to the previous state + // and ping a WithdrawFailed message to the holder. + let withdraw_failed_msg = WasmMsg::Execute { + contract_addr: HOLDER_ADDRESS.load(deps.storage)?.to_string(), + msg: to_json_binary(&WithdrawLPMsgs::WithdrawFailed {})?, + funds: vec![], + }; + CONTRACT_STATE.save(deps.storage, &prev_state)?; + Ok(Response::default() + .add_attribute("method", "try_withdraw_pre_proxy_funding_denoms") + .add_attribute("contract_state", format!("{:?}", prev_state)) + .add_attribute("p1_balance", p1_bal.to_string()) + .add_attribute("p2_balance", p2_bal.to_string()) + .add_message(withdraw_failed_msg)) + } else { + // otherwise we set the contract state to distributing. + // this will cause incoming ticks to assert whether this contract had received the funds. + // if the funds are not received, the tick will attempt to withdraw them again. + // if all expected coins are received, the contract will submit `Distribute` message to the holder. + CONTRACT_STATE.save( + deps.storage, + &ContractState::Distributing { + coins: withdraw_coins.clone(), + }, + )?; + + Ok(Response::default() + .add_attribute("method", "try_withdraw_pre_proxy_funding_denoms") + .add_attribute("contract_state", "distributing") + .add_attribute("p1_balance", p1_bal.to_string()) + .add_attribute("p2_balance", p2_bal.to_string()) + .add_attribute("coins", to_json_string(&withdraw_coins)?)) + } +} + +fn try_withdraw_post_proxy_funding_denoms( deps: ExecuteDeps, + prev_state: ContractState, p1_proxy_bal: &Coin, p2_proxy_bal: &Coin, ) -> NeutronResult> { - // if either denom balance is non-zero, collect them let mut withdraw_coins: Vec = Vec::with_capacity(2); if p1_proxy_bal.amount > Uint128::zero() { withdraw_coins.push(p1_proxy_bal.clone()); @@ -184,17 +239,21 @@ fn withdraw_party_denoms( } if withdraw_coins.is_empty() { - // both both balances are zero, we revert the state to active + // both both balances are zero, we revert to the previous state // and ping a WithdrawFailed message to the holder. let withdraw_failed_msg = WasmMsg::Execute { contract_addr: HOLDER_ADDRESS.load(deps.storage)?.to_string(), msg: to_json_binary(&WithdrawLPMsgs::WithdrawFailed {})?, funds: vec![], }; - CONTRACT_STATE.save(deps.storage, &ContractState::Active)?; + + // if we are here, we know that proxy holds neither covenant party denom, + // nor the lp token. this means that there is nothing to withdraw and we + // can safely revert the state to the previous one. + CONTRACT_STATE.save(deps.storage, &prev_state)?; Ok(Response::default() - .add_attribute("method", "withdraw_party_denoms") - .add_attribute("contract_state", "active") + .add_attribute("method", "try_withdraw_post_proxy_funding_denoms") + .add_attribute("contract_state", format!("{:?}", prev_state)) .add_attribute("p1_balance", p1_proxy_bal.to_string()) .add_attribute("p2_balance", p2_proxy_bal.to_string()) .add_message(withdraw_failed_msg)) @@ -211,7 +270,7 @@ fn withdraw_party_denoms( )?; Ok(Response::default() - .add_attribute("method", "withdraw_party_denoms") + .add_attribute("method", "try_withdraw_post_proxy_funding_denoms") .add_attribute("contract_state", "distributing") .add_attribute("p1_balance", p1_proxy_bal.to_string()) .add_attribute("p2_balance", p2_proxy_bal.to_string()) @@ -219,22 +278,40 @@ fn withdraw_party_denoms( } } -pub fn try_withdraw( +fn try_withdraw( deps: ExecuteDeps, env: Env, withdraw_share: Decimal, + prev_state: ContractState, (party_1_bal, party_2_bal, lp_bal): (&Coin, &Coin, &Coin), lp_config: LiquidityProvisionConfig, ) -> NeutronResult> { - let note_address = NOTE_ADDRESS.load(deps.storage)?; - let ibc_config = IBC_CONFIG.load(deps.storage)?; - // if there are 0 available lp token balances, we attempt to // withdraw the party denoms directly. if lp_bal.amount.is_zero() { - return withdraw_party_denoms(deps, party_1_bal, party_2_bal); + // if withdrawal was initiated before we delivered funds to the proxy, + // we attempt to refund any party denoms that are held by this contract. + if matches!( + prev_state, + ContractState::Instantiated | ContractState::ProxyCreated + ) { + return try_withdraw_pre_proxy_funding_denoms(deps, env, lp_config, prev_state); + } else { + // otherwise the funds should be held by the proxy, so we + // attempt to withdraw them from the proxy. + return try_withdraw_post_proxy_funding_denoms( + deps, + prev_state, + party_1_bal, + party_2_bal, + ); + } } + // otherwise we proceed with LP redemption flow + let note_address = NOTE_ADDRESS.load(deps.storage)?; + let ibc_config = IBC_CONFIG.load(deps.storage)?; + let lp_redeem_amount = lp_bal .amount .checked_multiply_ratio(withdraw_share.numerator(), withdraw_share.denominator()) @@ -307,13 +384,14 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult try_sync_proxy_balances(deps, env), - ContractState::PendingWithdrawal { share } => { + ContractState::PendingWithdrawal { share, prev_state } => { let lp_config = LIQUIDITY_PROVISIONING_CONFIG.load(deps.storage)?; match lp_config.get_proxy_balances() { Some((party_1_bal, party_2_bal, lp_bal)) => try_withdraw( deps, env, share, + *prev_state, (party_1_bal, party_2_bal, lp_bal), lp_config.clone(), ), diff --git a/contracts/osmo-liquid-pooler/src/msg.rs b/contracts/osmo-liquid-pooler/src/msg.rs index afc6a374..9ad04244 100644 --- a/contracts/osmo-liquid-pooler/src/msg.rs +++ b/contracts/osmo-liquid-pooler/src/msg.rs @@ -310,10 +310,17 @@ pub enum QueryMsg { pub enum ContractState { Instantiated, ProxyCreated, - ProxyFunded { funding_expiration: Expiration }, + ProxyFunded { + funding_expiration: Expiration, + }, Active, - Distributing { coins: Vec }, - PendingWithdrawal { share: Decimal }, + Distributing { + coins: Vec, + }, + PendingWithdrawal { + share: Decimal, + prev_state: Box, + }, } #[cw_serde] From eeac611e435bd6866ec9d0ecbccd836631485c02 Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 19 Apr 2024 22:27:46 +0200 Subject: [PATCH 53/56] revert pre & post-funding proxy withdraw branching --- contracts/osmo-liquid-pooler/src/contract.rs | 124 ++++--------------- contracts/osmo-liquid-pooler/src/msg.rs | 13 +- 2 files changed, 26 insertions(+), 111 deletions(-) diff --git a/contracts/osmo-liquid-pooler/src/contract.rs b/contracts/osmo-liquid-pooler/src/contract.rs index 804069bb..03f72eeb 100644 --- a/contracts/osmo-liquid-pooler/src/contract.rs +++ b/contracts/osmo-liquid-pooler/src/contract.rs @@ -147,13 +147,12 @@ fn try_initiate_withdrawal( ); // we advance the contract state to `PendingWithdrawal` and force latest balances sync - CONTRACT_STATE.update(deps.storage, |contract_state| -> StdResult<_> { - let new_state = ContractState::PendingWithdrawal { + CONTRACT_STATE.save( + deps.storage, + &ContractState::PendingWithdrawal { share: withdraw_share, - prev_state: Box::new(contract_state), - }; - Ok(new_state) - })?; + }, + )?; LIQUIDITY_PROVISIONING_CONFIG.update(deps.storage, |mut lp_config| -> StdResult<_> { lp_config.reset_latest_proxy_balances(); Ok(lp_config) @@ -165,71 +164,17 @@ fn try_initiate_withdrawal( .add_attribute("pending_withdrawal", withdraw_share.to_string())) } -fn try_withdraw_pre_proxy_funding_denoms( - deps: ExecuteDeps, - env: Env, - lp_config: LiquidityProvisionConfig, - prev_state: ContractState, -) -> NeutronResult> { - let mut withdraw_coins: Vec = Vec::with_capacity(2); - let p1_bal = deps.querier.query_balance( - env.contract.address.to_string(), - lp_config.party_1_denom_info.local_denom.to_string(), - )?; - let p2_bal = deps.querier.query_balance( - env.contract.address.to_string(), - lp_config.party_2_denom_info.local_denom.to_string(), - )?; - - if p1_bal.amount > Uint128::zero() { - withdraw_coins.push(p1_bal.clone()); - } - if p2_bal.amount > Uint128::zero() { - withdraw_coins.push(p2_bal.clone()); - } - - if withdraw_coins.is_empty() { - // both both balances are zero, we revert to the previous state - // and ping a WithdrawFailed message to the holder. - let withdraw_failed_msg = WasmMsg::Execute { - contract_addr: HOLDER_ADDRESS.load(deps.storage)?.to_string(), - msg: to_json_binary(&WithdrawLPMsgs::WithdrawFailed {})?, - funds: vec![], - }; - CONTRACT_STATE.save(deps.storage, &prev_state)?; - Ok(Response::default() - .add_attribute("method", "try_withdraw_pre_proxy_funding_denoms") - .add_attribute("contract_state", format!("{:?}", prev_state)) - .add_attribute("p1_balance", p1_bal.to_string()) - .add_attribute("p2_balance", p2_bal.to_string()) - .add_message(withdraw_failed_msg)) - } else { - // otherwise we set the contract state to distributing. - // this will cause incoming ticks to assert whether this contract had received the funds. - // if the funds are not received, the tick will attempt to withdraw them again. - // if all expected coins are received, the contract will submit `Distribute` message to the holder. - CONTRACT_STATE.save( - deps.storage, - &ContractState::Distributing { - coins: withdraw_coins.clone(), - }, - )?; - - Ok(Response::default() - .add_attribute("method", "try_withdraw_pre_proxy_funding_denoms") - .add_attribute("contract_state", "distributing") - .add_attribute("p1_balance", p1_bal.to_string()) - .add_attribute("p2_balance", p2_bal.to_string()) - .add_attribute("coins", to_json_string(&withdraw_coins)?)) - } -} - -fn try_withdraw_post_proxy_funding_denoms( +/// this method will attempt to set the contract state to `Distributing`, +/// with any non-lp token denoms available on our remote proxy. +/// doing so will cause upcoming ticks to try to send the withdrawn coins +/// to the holder, completing the withdrawal flow and reverting this contract +/// to active state. +fn withdraw_party_denoms( deps: ExecuteDeps, - prev_state: ContractState, p1_proxy_bal: &Coin, p2_proxy_bal: &Coin, ) -> NeutronResult> { + // if either denom balance is non-zero, collect them let mut withdraw_coins: Vec = Vec::with_capacity(2); if p1_proxy_bal.amount > Uint128::zero() { withdraw_coins.push(p1_proxy_bal.clone()); @@ -239,21 +184,17 @@ fn try_withdraw_post_proxy_funding_denoms( } if withdraw_coins.is_empty() { - // both both balances are zero, we revert to the previous state + // both both balances are zero, we revert the state to active // and ping a WithdrawFailed message to the holder. let withdraw_failed_msg = WasmMsg::Execute { contract_addr: HOLDER_ADDRESS.load(deps.storage)?.to_string(), msg: to_json_binary(&WithdrawLPMsgs::WithdrawFailed {})?, funds: vec![], }; - - // if we are here, we know that proxy holds neither covenant party denom, - // nor the lp token. this means that there is nothing to withdraw and we - // can safely revert the state to the previous one. - CONTRACT_STATE.save(deps.storage, &prev_state)?; + CONTRACT_STATE.save(deps.storage, &ContractState::Active)?; Ok(Response::default() - .add_attribute("method", "try_withdraw_post_proxy_funding_denoms") - .add_attribute("contract_state", format!("{:?}", prev_state)) + .add_attribute("method", "withdraw_party_denoms") + .add_attribute("contract_state", "active") .add_attribute("p1_balance", p1_proxy_bal.to_string()) .add_attribute("p2_balance", p2_proxy_bal.to_string()) .add_message(withdraw_failed_msg)) @@ -270,7 +211,7 @@ fn try_withdraw_post_proxy_funding_denoms( )?; Ok(Response::default() - .add_attribute("method", "try_withdraw_post_proxy_funding_denoms") + .add_attribute("method", "withdraw_party_denoms") .add_attribute("contract_state", "distributing") .add_attribute("p1_balance", p1_proxy_bal.to_string()) .add_attribute("p2_balance", p2_proxy_bal.to_string()) @@ -278,40 +219,22 @@ fn try_withdraw_post_proxy_funding_denoms( } } -fn try_withdraw( +pub fn try_withdraw( deps: ExecuteDeps, env: Env, withdraw_share: Decimal, - prev_state: ContractState, (party_1_bal, party_2_bal, lp_bal): (&Coin, &Coin, &Coin), lp_config: LiquidityProvisionConfig, ) -> NeutronResult> { + let note_address = NOTE_ADDRESS.load(deps.storage)?; + let ibc_config = IBC_CONFIG.load(deps.storage)?; + // if there are 0 available lp token balances, we attempt to // withdraw the party denoms directly. if lp_bal.amount.is_zero() { - // if withdrawal was initiated before we delivered funds to the proxy, - // we attempt to refund any party denoms that are held by this contract. - if matches!( - prev_state, - ContractState::Instantiated | ContractState::ProxyCreated - ) { - return try_withdraw_pre_proxy_funding_denoms(deps, env, lp_config, prev_state); - } else { - // otherwise the funds should be held by the proxy, so we - // attempt to withdraw them from the proxy. - return try_withdraw_post_proxy_funding_denoms( - deps, - prev_state, - party_1_bal, - party_2_bal, - ); - } + return withdraw_party_denoms(deps, party_1_bal, party_2_bal); } - // otherwise we proceed with LP redemption flow - let note_address = NOTE_ADDRESS.load(deps.storage)?; - let ibc_config = IBC_CONFIG.load(deps.storage)?; - let lp_redeem_amount = lp_bal .amount .checked_multiply_ratio(withdraw_share.numerator(), withdraw_share.denominator()) @@ -384,14 +307,13 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult try_sync_proxy_balances(deps, env), - ContractState::PendingWithdrawal { share, prev_state } => { + ContractState::PendingWithdrawal { share } => { let lp_config = LIQUIDITY_PROVISIONING_CONFIG.load(deps.storage)?; match lp_config.get_proxy_balances() { Some((party_1_bal, party_2_bal, lp_bal)) => try_withdraw( deps, env, share, - *prev_state, (party_1_bal, party_2_bal, lp_bal), lp_config.clone(), ), diff --git a/contracts/osmo-liquid-pooler/src/msg.rs b/contracts/osmo-liquid-pooler/src/msg.rs index 9ad04244..afc6a374 100644 --- a/contracts/osmo-liquid-pooler/src/msg.rs +++ b/contracts/osmo-liquid-pooler/src/msg.rs @@ -310,17 +310,10 @@ pub enum QueryMsg { pub enum ContractState { Instantiated, ProxyCreated, - ProxyFunded { - funding_expiration: Expiration, - }, + ProxyFunded { funding_expiration: Expiration }, Active, - Distributing { - coins: Vec, - }, - PendingWithdrawal { - share: Decimal, - prev_state: Box, - }, + Distributing { coins: Vec }, + PendingWithdrawal { share: Decimal }, } #[cw_serde] From 570122e0c81af0d29d71a5198df56986838bd098 Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 22 Apr 2024 19:16:16 +0200 Subject: [PATCH 54/56] adjust ictests to new instantiate msgs --- .../two_party_pol_native_test.go | 16 +++++++-------- .../two-party-pol/two_party_pol_test.go | 20 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/interchaintest/two-party-pol/two_party_pol_native_test.go b/interchaintest/two-party-pol/two_party_pol_native_test.go index 17882e23..c02ebfdf 100644 --- a/interchaintest/two-party-pol/two_party_pol_native_test.go +++ b/interchaintest/two-party-pol/two_party_pol_native_test.go @@ -545,8 +545,8 @@ func TestTwoPartyNativePartyPol(t *testing.T) { }, RagequitConfig: &ragequitConfig, DepositDeadline: depositDeadline, - PartyAShare: "50", - PartyBShare: "50", + PartyAShare: "0.5", + PartyBShare: "0.5", CovenantType: "share", Splits: denomSplits, FallbackSplit: nil, @@ -872,8 +872,8 @@ func TestTwoPartyNativePartyPol(t *testing.T) { RagequitConfig: &ragequitConfig, DepositDeadline: depositDeadline, CovenantType: "share", - PartyAShare: "50", - PartyBShare: "50", + PartyAShare: "0.5", + PartyBShare: "0.5", PoolPriceConfig: PoolPriceConfig{ ExpectedSpotPrice: "0.1", AcceptablePriceSpread: "0.09", @@ -1149,8 +1149,8 @@ func TestTwoPartyNativePartyPol(t *testing.T) { PartyBConfig: CovenantPartyConfig{Native: &partyBConfig}, RagequitConfig: &ragequitConfig, DepositDeadline: depositDeadline, - PartyAShare: "50", - PartyBShare: "50", + PartyAShare: "0.5", + PartyBShare: "0.5", PoolPriceConfig: PoolPriceConfig{ ExpectedSpotPrice: "0.1", AcceptablePriceSpread: "0.09", @@ -1411,8 +1411,8 @@ func TestTwoPartyNativePartyPol(t *testing.T) { PartyBConfig: CovenantPartyConfig{Native: &partyBConfig}, RagequitConfig: &ragequitConfig, DepositDeadline: depositDeadline, - PartyAShare: "50", - PartyBShare: "50", + PartyAShare: "0.5", + PartyBShare: "0.5", PoolPriceConfig: PoolPriceConfig{ ExpectedSpotPrice: "0.1", AcceptablePriceSpread: "0.09", diff --git a/interchaintest/two-party-pol/two_party_pol_test.go b/interchaintest/two-party-pol/two_party_pol_test.go index a92af99d..c24aae55 100644 --- a/interchaintest/two-party-pol/two_party_pol_test.go +++ b/interchaintest/two-party-pol/two_party_pol_test.go @@ -622,8 +622,8 @@ func TestTwoPartyPol(t *testing.T) { }, RagequitConfig: &ragequitConfig, DepositDeadline: depositDeadline, - PartyAShare: "50", - PartyBShare: "50", + PartyAShare: "0.5", + PartyBShare: "0.5", PoolPriceConfig: PoolPriceConfig{ ExpectedSpotPrice: "0.1", AcceptablePriceSpread: "0.09", @@ -900,8 +900,8 @@ func TestTwoPartyPol(t *testing.T) { PartyBConfig: CovenantPartyConfig{Interchain: &partyBConfig}, RagequitConfig: &ragequitConfig, DepositDeadline: depositDeadline, - PartyAShare: "50", - PartyBShare: "50", + PartyAShare: "0.5", + PartyBShare: "0.5", PoolPriceConfig: PoolPriceConfig{ ExpectedSpotPrice: "0.1", AcceptablePriceSpread: "0.09", @@ -1191,8 +1191,8 @@ func TestTwoPartyPol(t *testing.T) { PartyBConfig: CovenantPartyConfig{Interchain: &partyBConfig}, RagequitConfig: &ragequitConfig, DepositDeadline: depositDeadline, - PartyAShare: "50", - PartyBShare: "50", + PartyAShare: "0.5", + PartyBShare: "0.5", PoolPriceConfig: PoolPriceConfig{ ExpectedSpotPrice: "0.1", AcceptablePriceSpread: "0.09", @@ -1362,8 +1362,8 @@ func TestTwoPartyPol(t *testing.T) { } currentHeight := testCtx.GetNeutronHeight() - depositBlock := Block(currentHeight + 180) - lockupBlock := Block(currentHeight + 180) + depositBlock := Block(currentHeight + 210) + lockupBlock := Block(currentHeight + 230) expirationHeight = lockupBlock lockupConfig := Expiration{ AtHeight: &lockupBlock, @@ -1451,8 +1451,8 @@ func TestTwoPartyPol(t *testing.T) { PartyBConfig: CovenantPartyConfig{Interchain: &partyBConfig}, RagequitConfig: &ragequitConfig, DepositDeadline: depositDeadline, - PartyAShare: "50", - PartyBShare: "50", + PartyAShare: "0.5", + PartyBShare: "0.5", PoolPriceConfig: PoolPriceConfig{ ExpectedSpotPrice: "0.1", AcceptablePriceSpread: "0.09", From d8c60ccee490df6b8a20632086c42e82d43a2ead Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 22 Apr 2024 20:07:34 +0200 Subject: [PATCH 55/56] ci fix --- .github/workflows/interchaintest.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/interchaintest.yml b/.github/workflows/interchaintest.yml index 63d8e086..2c5a6f1b 100644 --- a/.github/workflows/interchaintest.yml +++ b/.github/workflows/interchaintest.yml @@ -129,8 +129,8 @@ jobs: uses: extractions/setup-just@v1 - name: two party POL native & interchain parties - run: mkdir interchaintest/two-party-pol/wasms && cp -R artifacts/*.wasm interchaintest/two-party-pol/wasms && cp -R interchaintest/wasms/astroport/*.wasm interchaintest/two-party-pol/wasms && just local-e2e two-party-pol TestTwoPartyNativePartyPol + run: mkdir -p interchaintest/two-party-pol/wasms && cp -R artifacts/*.wasm interchaintest/two-party-pol/wasms && cp -R interchaintest/wasms/astroport/*.wasm interchaintest/two-party-pol/wasms && just local-e2e two-party-pol TestTwoPartyNativePartyPol - name: two party POL two interchain parties - run: mkdir interchaintest/two-party-pol/wasms && cp -R artifacts/*.wasm interchaintest/two-party-pol/wasms && cp -R interchaintest/wasms/astroport/*.wasm interchaintest/two-party-pol/wasms && just local-e2e two-party-pol TestTwoPartyPol + run: mkdir -p interchaintest/two-party-pol/wasms && cp -R artifacts/*.wasm interchaintest/two-party-pol/wasms && cp -R interchaintest/wasms/astroport/*.wasm interchaintest/two-party-pol/wasms && just local-e2e two-party-pol TestTwoPartyPol From 93635415417160cdb9a801cebb446f0c90236c23 Mon Sep 17 00:00:00 2001 From: bekauz Date: Tue, 23 Apr 2024 16:58:14 +0200 Subject: [PATCH 56/56] extending e2e test execution limit to 60m --- justfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index 62b5b937..64889186 100644 --- a/justfile +++ b/justfile @@ -25,11 +25,11 @@ local-e2e-rebuild TEST PATTERN='.*': optimize cp -R interchaintest/wasms/astroport/*.wasm interchaintest/{{TEST}}/wasms cp -R artifacts/*.wasm interchaintest/{{TEST}}/wasms ls interchaintest/{{TEST}}/wasms - cd interchaintest/{{TEST}} && go clean -testcache && go test -timeout 50m -v -run '{{PATTERN}}' + cd interchaintest/{{TEST}} && go clean -testcache && go test -timeout 60m -v -run '{{PATTERN}}' local-e2e TEST PATTERN='.*': mkdir -p interchaintest/{{TEST}}/wasms cp -R interchaintest/wasms/polytone/*.wasm interchaintest/{{TEST}}/wasms cp -R interchaintest/wasms/astroport/*.wasm interchaintest/{{TEST}}/wasms cp -R artifacts/*.wasm interchaintest/{{TEST}}/wasms - cd interchaintest/{{TEST}} && go clean -testcache && go test -timeout 50m -v -run '{{PATTERN}}' + cd interchaintest/{{TEST}} && go clean -testcache && go test -timeout 60m -v -run '{{PATTERN}}'