From 3125bce1ebc50c3ffd4f2cab1dfe95e7ab2b1a07 Mon Sep 17 00:00:00 2001 From: Buckram Date: Thu, 24 Oct 2024 19:05:59 +0300 Subject: [PATCH 1/5] v2 upgrade in progress --- Cargo.toml | 31 +++- bot/Cargo.toml | 8 +- bot/src/bot.rs | 12 +- contracts/carrot-app/Cargo.toml | 32 ++-- contracts/carrot-app/examples/deploy.rs | 2 +- .../examples/install_savings_app.rs | 156 +++++++++--------- contracts/carrot-app/src/contract.rs | 6 +- contracts/carrot-app/src/handlers/execute.rs | 25 ++- .../carrot-app/src/handlers/instantiate.rs | 2 +- contracts/carrot-app/src/handlers/query.rs | 13 +- .../carrot-app/src/handlers/swap_helpers.rs | 28 ++-- contracts/carrot-app/src/helpers.rs | 12 +- contracts/carrot-app/tests/autocompound.rs | 25 +-- contracts/carrot-app/tests/common.rs | 51 ++++-- .../carrot-app/tests/deposit_withdraw.rs | 40 ++--- 15 files changed, 249 insertions(+), 194 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cd7a1bd..3df138a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,12 +4,15 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [workspace.dependencies] -cw-orch = "0.24.0" -abstract-app = { version = "0.23.0" } -abstract-interface = { version = "0.23.0" } -abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", tag = "v0.23.0-dex-adapter" } -abstract-client = { version = "0.23.0" } -cw-asset = { version = "3.0" } +cw-orch = "0.26.0" +abstract-app = { version = "0.24.1-beta.2" } +abstract-adapter = { version = "0.24.1-beta.2" } +abstract-interface = { version = "0.24.1-beta.2" } +abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +abstract-osmosis-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +abstract-client = { version = "0.24.1-beta.2" } +cw-asset = { version = "4.0" } +cw-orch-osmosis-test-tube = { version = "0.4.0" } [profile.release] rpath = false @@ -21,3 +24,19 @@ debug-assertions = false codegen-units = 1 panic = 'abort' incremental = false + +[patch.crates-io] +abstract-app = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +abstract-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +abstract-interface = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +abstract-client = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +abstract-dex-standard = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +abstract-std = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +abstract-sdk = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +abstract-adapter-utils = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +# abstract-osmosis-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +# abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } # Replace to tag tag = "v0.23.0-dex-adapter" } + +cw-orch-osmosis-test-tube = { git = "https://github.com/AbstractSDK/cw-orchestrator.git", branch = "buckram/revive-osmosis-test-tube" } +cw-orch-core = { git = "https://github.com/AbstractSDK/cw-orchestrator.git", branch = "buckram/revive-osmosis-test-tube" } +cw-orch-traits = { git = "https://github.com/AbstractSDK/cw-orchestrator.git", branch = "buckram/revive-osmosis-test-tube" } diff --git a/bot/Cargo.toml b/bot/Cargo.toml index c5d1eb0..4875683 100644 --- a/bot/Cargo.toml +++ b/bot/Cargo.toml @@ -12,13 +12,13 @@ path = "src/bin/local.rs" cw-orch = { workspace = true, features = ["daemon"] } abstract-app = { workspace = true } abstract-client = { workspace = true } -cosmwasm-std = { version = "1.2" } -osmosis-std = { version = "0.21.0" } -cosmos-sdk-proto = { version = "0.20.0" } +cosmwasm-std = { version = "2.0" } +osmosis-std = { version = "0.26.0" } +cosmos-sdk-proto = { version = "0.24.0", features = ["cosmwasm"] } dotenv = "0.15.0" env_logger = "0.11.2" log = "0.4.20" -tonic = "0.10.0" +tonic = "0.12.3" carrot-app = { path = "../contracts/carrot-app", features = ["interface"] } clap = { version = "4", features = ["derive"] } humantime = "2.1.0" diff --git a/bot/src/bot.rs b/bot/src/bot.rs index ba23366..1c78242 100644 --- a/bot/src/bot.rs +++ b/bot/src/bot.rs @@ -43,9 +43,9 @@ use std::{ use tonic::transport::Channel; use abstract_app::{ - abstract_interface::VCQueryFns, + abstract_interface::RegistryQueryFns, objects::module::{ModuleInfo, ModuleStatus}, - std::{ans_host, version_control::ModuleFilter}, + std::{ans_host, registry::ModuleFilter}, }; const LAST_INCOMPATIBLE_VERSION: &str = "0.3.1"; @@ -330,7 +330,7 @@ fn autocompound_instance( } mod utils { - use abstract_app::std::version_control::ModulesListResponse; + use abstract_app::std::registry::ModulesListResponse; use cosmos_sdk_proto::{ cosmos::base::query::v1beta1::{PageRequest, PageResponse}, cosmwasm::wasm::v1::QueryContractsByCodeResponse, @@ -407,8 +407,8 @@ mod utils { .block_on(async { authz_querier ._grants( - granter.to_string(), - authz_grantee.clone(), + &granter, + &Addr::unchecked(authz_grantee), // Get every authorization "".to_owned(), None, @@ -496,7 +496,7 @@ mod utils { }); let mut module_list = ModulesListResponse { modules: vec![] }; loop { - let saving_modules = abstr.version_control().module_list( + let saving_modules = abstr.registry().module_list( Some(ModuleFilter { namespace: Some(module_info.namespace.to_string()), name: Some(module_info.name.clone()), diff --git a/contracts/carrot-app/Cargo.toml b/contracts/carrot-app/Cargo.toml index d4f557d..8c944a9 100644 --- a/contracts/carrot-app/Cargo.toml +++ b/contracts/carrot-app/Cargo.toml @@ -31,40 +31,40 @@ export = [] node-tests = ["interface"] interface = ["export", "dep:cw-orch"] schema = ["abstract-app/schema"] +mock-deployment = ["abstract-app/mock-deployment"] + +[package.metadata.optimizer] +builds = [{ name = "mock", features = ["mock-deployment"] }] [dependencies] -cw-utils = { version = "1.0.3" } -cosmwasm-std = { version = "1.2" } -cosmwasm-schema = { version = "1.2" } -cw-controllers = { version = "1.0.1" } -cw-storage-plus = "1.2.0" +cw-utils = { version = "2.0.0" } +cosmwasm-std = { version = "2.0" } +cosmwasm-schema = { version = "2.0" } +cw-controllers = { version = "2.0.0" } +cw-storage-plus = { version = "2.0.0" } thiserror = { version = "1.0.50" } schemars = "0.8" cw-asset = { workspace = true } -abstract-app = { workspace = true } +abstract-app = { workspace = true, features = ["stargate"] } # Dependencies for interface abstract-dex-adapter = { workspace = true, features = ["osmosis"] } cw-orch = { workspace = true, optional = true } -osmosis-std = { version = "0.25.0" } -prost = { version = "0.12.3" } -# TODO: just to enable "stargate" on abstract-app remove, see ABS-480 -abstract-sdk = { version = "0.23.0", features = ["stargate"] } +osmosis-std = { version = "0.26.0" } +prost = { version = "0.13.1" } [dev-dependencies] abstract-interface = { workspace = true, features = ["daemon"] } -prost = { version = "0.12.3" } -prost-types = { version = "0.12.3" } +prost-types = { version = "0.13.1" } log = { version = "0.4.20" } -carrot-app = { path = ".", features = ["interface"] } +carrot-app = { path = ".", features = ["interface", "mock-deployment"] } abstract-client = { workspace = true } -abstract-app = { workspace = true, features = ["test-utils"] } -speculoos = "0.11.0" +abstract-app = { workspace = true, features = ["test-utils", "stargate"] } semver = "1.0" dotenv = "0.15.0" env_logger = "0.10.0" cw-orch = { workspace = true } -cw-orch-osmosis-test-tube = "0.3.0" +cw-orch-osmosis-test-tube = { workspace = true } clap = { version = "4.3.7", features = ["derive"] } diff --git a/contracts/carrot-app/examples/deploy.rs b/contracts/carrot-app/examples/deploy.rs index 12340fb..fe309df 100644 --- a/contracts/carrot-app/examples/deploy.rs +++ b/contracts/carrot-app/examples/deploy.rs @@ -23,6 +23,6 @@ fn main() -> anyhow::Result<()> { .build()?; publisher.publish_app::>()?; - abstr.version_control().approve_any_abstract_modules()?; + abstr.registry().approve_any_abstract_modules()?; Ok(()) } diff --git a/contracts/carrot-app/examples/install_savings_app.rs b/contracts/carrot-app/examples/install_savings_app.rs index 661783d..92d7bf3 100644 --- a/contracts/carrot-app/examples/install_savings_app.rs +++ b/contracts/carrot-app/examples/install_savings_app.rs @@ -172,7 +172,7 @@ mod utils { module::{ModuleInfo, ModuleVersion}, AccountId, }; - use abstract_app::std::{account_factory, manager::ModuleInstallConfig}; + use abstract_app::std::account::ModuleInstallConfig; use abstract_client::*; use abstract_dex_adapter::DEX_ADAPTER_ID; use abstract_interface::Abstract; @@ -203,7 +203,7 @@ mod utils { app_data: &CarrotAppInitData, ) -> Result, anyhow::Error> { let dex_fee_account = client.account_from(AccountId::local(0))?; - let dex_fee_addr = dex_fee_account.proxy()?.to_string(); + let dex_fee_addr = dex_fee_account.address()?.to_string(); let chain = client.environment().clone(); let authorization_urls = [ @@ -281,48 +281,48 @@ mod utils { ) -> anyhow::Result { let chain = client.environment(); let abstr = Abstract::load_from(chain.clone())?; - let account_factory_addr = abstr.account_factory.addr_str()?; let random_account_id = client.random_account_id()?; - let msg = Any { - type_url: MsgExecuteContract::TYPE_URL.to_owned(), - value: MsgExecuteContract { - sender: chain.sender_addr().to_string(), - contract: account_factory_addr.to_string(), - msg: to_json_vec(&account_factory::ExecuteMsg::CreateAccount { - governance: GovernanceDetails::Monarchy { - monarch: chain.sender_addr().to_string(), - }, - name: "bob".to_owned(), - description: None, - link: None, - base_asset: None, - namespace: None, - install_modules: vec![ - ModuleInstallConfig::new( - ModuleInfo::from_id( - DEX_ADAPTER_ID, - ModuleVersion::Version( - abstract_dex_adapter::contract::CONTRACT_VERSION.to_owned(), - ), - )?, - None, - ), - ModuleInstallConfig::new( - ModuleInfo::from_id( - APP_ID, - ModuleVersion::Version(APP_VERSION.to_owned()), - )?, - Some(to_json_binary(&init_msg)?), - ), - ], - account_id: Some(AccountId::local(random_account_id)), - })?, - funds: vec![], - } - .to_proto_bytes(), - }; - Ok(msg) + todo!(); + // let msg = Any { + // type_url: MsgExecuteContract::TYPE_URL.to_owned(), + // value: MsgExecuteContract { + // sender: chain.sender_addr().to_string(), + // contract: account_factory_addr.to_string(), + // msg: to_json_vec(&account_factory::ExecuteMsg::CreateAccount { + // governance: GovernanceDetails::Monarchy { + // monarch: chain.sender_addr().to_string(), + // }, + // name: "bob".to_owned(), + // description: None, + // link: None, + // base_asset: None, + // namespace: None, + // install_modules: vec![ + // ModuleInstallConfig::new( + // ModuleInfo::from_id( + // DEX_ADAPTER_ID, + // ModuleVersion::Version( + // abstract_dex_adapter::contract::CONTRACT_VERSION.to_owned(), + // ), + // )?, + // None, + // ), + // ModuleInstallConfig::new( + // ModuleInfo::from_id( + // APP_ID, + // ModuleVersion::Version(APP_VERSION.to_owned()), + // )?, + // Some(to_json_binary(&init_msg)?), + // ), + // ], + // account_id: Some(AccountId::local(random_account_id)), + // })?, + // funds: vec![], + // } + // .to_proto_bytes(), + // }; + // Ok(msg) } pub fn create_sub_account_message( @@ -333,41 +333,41 @@ mod utils { let chain = client.environment(); let random_account_id = client.random_account_id()?; - let msg = Any { - type_url: MsgExecuteContract::TYPE_URL.to_owned(), - value: MsgExecuteContract { - sender: chain.sender_addr().to_string(), - contract: account.manager()?.to_string(), - msg: to_json_vec(&abstract_app::std::manager::ExecuteMsg::CreateSubAccount { - name: "deep-adventurous-afternoon".to_owned(), - description: None, - link: None, - base_asset: None, - namespace: None, - install_modules: vec![ - ModuleInstallConfig::new( - ModuleInfo::from_id( - DEX_ADAPTER_ID, - ModuleVersion::Version( - abstract_dex_adapter::contract::CONTRACT_VERSION.to_owned(), - ), - )?, - None, - ), - ModuleInstallConfig::new( - ModuleInfo::from_id( - APP_ID, - ModuleVersion::Version(APP_VERSION.to_owned()), - )?, - Some(to_json_binary(&init_msg)?), - ), - ], - account_id: Some(random_account_id), - })?, - funds: vec![], - } - .to_proto_bytes(), - }; - Ok(msg) + todo!() + // let msg = Any { + // type_url: MsgExecuteContract::TYPE_URL.to_owned(), + // value: MsgExecuteContract { + // sender: chain.sender_addr().to_string(), + // contract: account.address()?.to_string(), + // msg: to_json_vec(&abstract_app::std::account::ExecuteMsg::CreateSubAccount { + // name: Some("deep-adventurous-afternoon".to_owned()), + // description: None, + // link: None, + // namespace: None, + // install_modules: vec![ + // ModuleInstallConfig::new( + // ModuleInfo::from_id( + // DEX_ADAPTER_ID, + // ModuleVersion::Version( + // abstract_dex_adapter::contract::CONTRACT_VERSION.to_owned(), + // ), + // )?, + // None, + // ), + // ModuleInstallConfig::new( + // ModuleInfo::from_id( + // APP_ID, + // ModuleVersion::Version(APP_VERSION.to_owned()), + // )?, + // Some(to_json_binary(&init_msg)?), + // ), + // ], + // account_id: Some(random_account_id), + // })?, + // funds: vec![], + // } + // .to_proto_bytes(), + // }; + // Ok(msg) } } diff --git a/contracts/carrot-app/src/contract.rs b/contracts/carrot-app/src/contract.rs index 8186b1c..763824e 100644 --- a/contracts/carrot-app/src/contract.rs +++ b/contracts/carrot-app/src/contract.rs @@ -58,15 +58,15 @@ impl abstract_app::abstract_interface::Depen fn dependency_install_configs( _configuration: Self::DependenciesConfig, ) -> Result< - Vec, + Vec, abstract_app::abstract_interface::AbstractInterfaceError, > { - let dex_dependency_install_configs: Vec = + let dex_dependency_install_configs: Vec = as abstract_app::abstract_interface::DependencyCreation>::dependency_install_configs( cosmwasm_std::Empty {}, )?; - let adapter_install_config = abstract_app::std::manager::ModuleInstallConfig::new( + let adapter_install_config = abstract_app::std::account::ModuleInstallConfig::new( abstract_app::std::objects::module::ModuleInfo::from_id( abstract_dex_adapter::DEX_ADAPTER_ID, abstract_dex_adapter::contract::CONTRACT_VERSION.into(), diff --git a/contracts/carrot-app/src/handlers/execute.rs b/contracts/carrot-app/src/handlers/execute.rs index 82be0d4..4f92ab3 100644 --- a/contracts/carrot-app/src/handlers/execute.rs +++ b/contracts/carrot-app/src/handlers/execute.rs @@ -47,6 +47,7 @@ pub fn execute_handler( autocompound_rewards_config, } => update_config( deps, + env, app, autocompound_cooldown_seconds, autocompound_rewards_config, @@ -78,6 +79,7 @@ pub fn execute_handler( fn update_config( deps: DepsMut, + env: Env, app: App, autocompound_cooldown_seconds: Option, autocompound_rewards_config: Option, @@ -86,7 +88,7 @@ fn update_config( if let Some(new_rewards_config) = autocompound_rewards_config { // Validate rewards config first - let ans = app.name_service(deps.as_ref()); + let ans = app.name_service(deps.as_ref(), &env); let asset_pairing_resp: Vec = ans .pool_list( Some(abstract_app::std::ans_host::AssetPairingFilter { @@ -128,7 +130,7 @@ fn create_position( app: App, create_position_msg: CreatePositionMessage, ) -> AppResult { - app.admin.assert_admin(deps.as_ref(), &info.sender)?; + app.admin.assert_admin(deps.as_ref(), &env, &info.sender)?; // Check if there is already saved position if CarrotPosition::may_load(deps.as_ref())?.is_some() { return Err(AppError::PositionExists {}); @@ -156,7 +158,7 @@ fn deposit( ) -> AppResult { // Only the admin (manager contracts or account owner) + the smart contract can deposit app.admin - .assert_admin(deps.as_ref(), &info.sender) + .assert_admin(deps.as_ref(), &env, &info.sender) .or(assert_contract(&info, &env))?; let carrot_position = CarrotPosition::load(deps.as_ref())?; @@ -208,7 +210,7 @@ fn withdraw( app: App, ) -> AppResult { // Only the authorized addresses (admin ?) can withdraw - app.admin.assert_admin(deps.as_ref(), &info.sender)?; + app.admin.assert_admin(deps.as_ref(), &env, &info.sender)?; let carrot_position = CarrotPosition::load(deps.as_ref())?; // Get app's user and set up authz. @@ -324,7 +326,7 @@ fn autocompound(deps: DepsMut, env: Env, info: MessageInfo, app: App) -> AppResu .add_message(msg_deposit); // If called by non-admin and reward cooldown has ended, send rewards to the contract caller. - if !app.admin.is_admin(deps.as_ref(), &info.sender)? && compound_status.is_ready() { + if !app.admin.is_admin(deps.as_ref(), &env, &info.sender)? && compound_status.is_ready() { let executor_reward_messages = autocompound_executor_rewards( deps.as_ref(), &env, @@ -525,7 +527,7 @@ pub fn autocompound_executor_rewards( // Get user balance of gas denom let gas_denom = rewards_config .gas_asset - .resolve(&deps.querier, &app.ans_host(deps)?)?; + .resolve(&deps.querier, &app.ans_host(deps, env)?)?; let user_gas_balance = gas_denom.query_balance(&deps.querier, user.clone())?; let mut rewards_messages = vec![]; @@ -533,7 +535,7 @@ pub fn autocompound_executor_rewards( // If not enough gas coins - swap for some amount if user_gas_balance < rewards_config.min_gas_balance { // Get asset entries - let dex = app.ans_dex(deps, OSMOSIS.to_string()); + let dex = app.ans_dex(deps, env, OSMOSIS.to_string()); // Do reverse swap to find approximate amount we need to swap let need_gas_coins = rewards_config.max_gas_balance - user_gas_balance; @@ -543,8 +545,13 @@ pub fn autocompound_executor_rewards( )?; // Get user balance of swap denom - let user_swap_balance = - get_balance(rewards_config.swap_asset.clone(), deps, user.clone(), app)?; + let user_swap_balance = get_balance( + rewards_config.swap_asset.clone(), + deps, + env, + user.clone(), + app, + )?; // Swap as much as available if not enough for max_gas_balance let swap_amount = simulate_swap_response.return_amount.min(user_swap_balance); diff --git a/contracts/carrot-app/src/handlers/instantiate.rs b/contracts/carrot-app/src/handlers/instantiate.rs index de5d3a8..97a96ad 100644 --- a/contracts/carrot-app/src/handlers/instantiate.rs +++ b/contracts/carrot-app/src/handlers/instantiate.rs @@ -32,7 +32,7 @@ pub fn instantiate_handler( .try_into()?; // We query the ANS for useful information on the tokens and pool - let ans = app.name_service(deps.as_ref()); + let ans = app.name_service(deps.as_ref(), &env); // ANS Asset entries to indentify the assets inside Abstract let asset_entries = ans.query(&vec![ AssetInfo::Native(pool.token0.clone()), diff --git a/contracts/carrot-app/src/handlers/query.rs b/contracts/carrot-app/src/handlers/query.rs index ef242e4..cd22655 100644 --- a/contracts/carrot-app/src/handlers/query.rs +++ b/contracts/carrot-app/src/handlers/query.rs @@ -46,7 +46,7 @@ fn query_compound_status(deps: Deps, env: Env, app: &App) -> AppResult AppResult AppResult required_swap_amount @@ -120,6 +120,7 @@ fn query_balance(deps: Deps, _app: &App) -> AppResult { pub fn query_price( deps: Deps, + env: &Env, funds: &[Coin], app: &App, max_spread: Option, @@ -127,7 +128,7 @@ pub fn query_price( belief_price1: Option, ) -> AppResult { let config = CONFIG.load(deps.storage)?; - let ans_host = app.ans_host(deps)?; + let ans_host = app.ans_host(deps, env)?; // We know it's native denom for osmosis pool let token0 = config @@ -154,7 +155,7 @@ pub fn query_price( // We take the biggest amount and simulate a swap for the corresponding asset let price = if amount0 > amount1 { - let simulation_result = app.ans_dex(deps, OSMOSIS.to_string()).simulate_swap( + let simulation_result = app.ans_dex(deps, env, OSMOSIS.to_string()).simulate_swap( AnsAsset::new(config.pool_config.asset0, amount0), config.pool_config.asset1, )?; @@ -168,7 +169,7 @@ pub fn query_price( } price } else { - let simulation_result = app.ans_dex(deps, OSMOSIS.to_string()).simulate_swap( + let simulation_result = app.ans_dex(deps, env, OSMOSIS.to_string()).simulate_swap( AnsAsset::new(config.pool_config.asset1, amount1), config.pool_config.asset0, )?; diff --git a/contracts/carrot-app/src/handlers/swap_helpers.rs b/contracts/carrot-app/src/handlers/swap_helpers.rs index 312e4c5..57c1677 100644 --- a/contracts/carrot-app/src/handlers/swap_helpers.rs +++ b/contracts/carrot-app/src/handlers/swap_helpers.rs @@ -45,7 +45,7 @@ pub(crate) fn swap_msg( } let sender = get_user(deps, app)?; - let dex = app.ans_dex(deps, OSMOSIS.to_string()); + let dex = app.ans_dex(deps, env, OSMOSIS.to_string()); let max_spread = Some(max_spread.unwrap_or(DEFAULT_MAX_SPREAD)); let trigger_swap_msg: GenerateMessagesResponse = dex.generate_swap_messages(offer_asset, ask_asset, max_spread, None, sender.clone())?; @@ -106,7 +106,7 @@ pub(crate) fn tokens_to_swap( let (offer_asset, ask_asset, assets_for_position) = if x0_a1 < x1_a0 { let numerator = x1_a0 - x0_a1; - let denominator = asset0.amount + price * asset1.amount; + let denominator = asset0.amount + asset1.amount.mul_floor(price); let y1 = numerator / denominator; ( @@ -114,7 +114,7 @@ pub(crate) fn tokens_to_swap( config.pool_config.asset0, AssetsForPosition { asset0: Coin { - amount: x0.amount + price * y1, + amount: x0.amount + y1.mul_floor(price), denom: x0.denom, }, asset1: Coin { @@ -125,8 +125,7 @@ pub(crate) fn tokens_to_swap( ) } else { let numerator = x0_a1 - x1_a0; - let denominator = - asset1.amount + Decimal::from_ratio(asset0.amount, 1u128) / price * Uint128::one(); + let denominator = asset1.amount + asset0.amount / Uint128::one().mul_floor(price); let y0 = numerator / denominator; ( @@ -138,7 +137,7 @@ pub(crate) fn tokens_to_swap( denom: x0.denom, }, asset1: Coin { - amount: x1.amount + Decimal::from_ratio(y0, 1u128) / price * Uint128::one(), + amount: x1.amount + y0 / Uint128::one().mul_floor(price), denom: x1.denom, }, }, @@ -160,7 +159,15 @@ pub fn swap_to_enter_position( belief_price0: Option, belief_price1: Option, ) -> AppResult<(Vec, AssetsForPosition)> { - let price = query_price(deps, &funds, app, max_spread, belief_price0, belief_price1)?; + let price = query_price( + deps, + env, + &funds, + app, + max_spread, + belief_price0, + belief_price1, + )?; let (offer_asset, ask_asset, assets_for_position) = tokens_to_swap(deps, funds, asset0, asset1, price)?; @@ -184,6 +191,7 @@ mod tests { let expected = expected.into().u128(); let result = result.u128(); + dbg!(expected, result); if expected < result - 1 || expected > result + 1 { panic!("Results are not close enough") } @@ -320,9 +328,7 @@ mod tests { assert_is_around( swap.amount, 5_000 - - 5_000 * amount1 - / (amount1 - + (Decimal::from_ratio(amount0, 1u128) / price * Uint128::one()).u128()), + - 5_000 * amount1 / (amount1 + (amount0 / Uint128::one().mul_floor(price).u128())), ); assert_eq!(swap.name, AssetEntry::new(TOKEN1)); assert_eq!(ask_asset, AssetEntry::new(TOKEN0)); @@ -348,7 +354,7 @@ mod tests { assert_eq!(ask_asset, AssetEntry::new(TOKEN1)); assert_eq!( 10_000 - swap.amount.u128(), - 4_000 + (Decimal::from_ratio(swap.amount, 1u128) / price * Uint128::one()).u128() + 4_000 + (swap.amount / Uint128::one().mul_floor(price)).u128() ); } } diff --git a/contracts/carrot-app/src/helpers.rs b/contracts/carrot-app/src/helpers.rs index 3a426eb..4338ee7 100644 --- a/contracts/carrot-app/src/helpers.rs +++ b/contracts/carrot-app/src/helpers.rs @@ -1,6 +1,6 @@ use abstract_app::sdk::Resolve; use abstract_app::{objects::AssetEntry, traits::AbstractNameService}; -use cosmwasm_std::{Addr, Deps, MessageInfo, Uint128}; +use cosmwasm_std::{Addr, Deps, Env, MessageInfo, Uint128}; use crate::{ contract::{App, AppResult}, @@ -16,8 +16,14 @@ pub fn get_user(deps: Deps, app: &App) -> AppResult { .map(|admin| deps.api.addr_validate(&admin))??) } -pub fn get_balance(a: AssetEntry, deps: Deps, address: Addr, app: &App) -> AppResult { - let denom = a.resolve(&deps.querier, &app.ans_host(deps)?)?; +pub fn get_balance( + a: AssetEntry, + deps: Deps, + env: &Env, + address: Addr, + app: &App, +) -> AppResult { + let denom = a.resolve(&deps.querier, &app.ans_host(deps, env)?)?; let user_gas_balance = denom.query_balance(&deps.querier, address.clone())?; Ok(user_gas_balance) } diff --git a/contracts/carrot-app/tests/autocompound.rs b/contracts/carrot-app/tests/autocompound.rs index 9a1b8b9..77d58be 100644 --- a/contracts/carrot-app/tests/autocompound.rs +++ b/contracts/carrot-app/tests/autocompound.rs @@ -5,7 +5,7 @@ use crate::common::{ create_position, setup_test_tube, DEX_NAME, GAS_DENOM, LOTS, REWARD_DENOM, USDC, USDC_DENOM, USDT, USDT_DENOM, }; -use abstract_app::abstract_interface::{Abstract, AbstractAccount}; +use abstract_app::abstract_interface::{Abstract, AccountI}; use carrot_app::msg::{ AppExecuteMsgFns, AppQueryMsgFns, AssetsBalanceResponse, CompoundStatus, CompoundStatusResponse, }; @@ -33,7 +33,7 @@ fn check_autocompound() -> anyhow::Result<()> { let mut chain = carrot_app.environment().clone(); chain.add_balance( - chain.sender_addr(), + &chain.sender_addr(), coins(5_000_000, format!("gamm/pool/{pool_id}")), )?; @@ -81,9 +81,9 @@ fn check_autocompound() -> anyhow::Result<()> { let dex: abstract_dex_adapter::interface::DexAdapter<_> = carrot_app.module()?; let abs = Abstract::load_from(chain.clone())?; let account_id = carrot_app.account().id()?; - let account = AbstractAccount::new(&abs, account_id); + let account = AccountI::load_from(&abs, account_id)?; chain.bank_send( - account.proxy.addr_str()?, + account.addr_str()?, vec![ coin(200_000, USDC_DENOM.to_owned()), coin(200_000, USDT_DENOM.to_owned()), @@ -119,12 +119,12 @@ fn check_autocompound() -> anyhow::Result<()> { let balance_before_autocompound: AssetsBalanceResponse = carrot_app.balance()?; let balance_usdc_before_autocompound = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDC_DENOM.to_owned()))? + .balance(&chain.sender_addr(), Some(USDC_DENOM.to_owned()))? .pop() .unwrap(); let balance_usdt_before_autocompound = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDT_DENOM.to_owned()))? + .balance(&chain.sender_addr(), Some(USDT_DENOM.to_owned()))? .pop() .unwrap(); @@ -136,12 +136,12 @@ fn check_autocompound() -> anyhow::Result<()> { let balance_after_autocompound: AssetsBalanceResponse = carrot_app.balance().unwrap(); let balance_usdc_after_autocompound = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDC_DENOM.to_owned()))? + .balance(&chain.sender_addr(), Some(USDC_DENOM.to_owned()))? .pop() .unwrap(); let balance_usdt_after_autocompound = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDT_DENOM.to_owned()))? + .balance(&chain.sender_addr(), Some(USDT_DENOM.to_owned()))? .pop() .unwrap(); @@ -164,7 +164,7 @@ fn stranger_autocompound() -> anyhow::Result<()> { let mut chain = carrot_app.environment().clone(); chain.add_balance( - chain.sender_addr(), + &chain.sender_addr(), coins(5_000_000, format!("gamm/pool/{pool_id}")), )?; let stranger = chain.init_account(coins(LOTS, GAS_DENOM))?; @@ -212,9 +212,9 @@ fn stranger_autocompound() -> anyhow::Result<()> { let dex: abstract_dex_adapter::interface::DexAdapter<_> = carrot_app.module()?; let abs = Abstract::load_from(chain.clone())?; let account_id = carrot_app.account().id()?; - let account = AbstractAccount::new(&abs, account_id); + let account = AccountI::load_from(&abs, account_id)?; chain.bank_send( - account.proxy.addr_str()?, + account.addr_str()?, vec![ coin(200_000, USDC_DENOM.to_owned()), coin(200_000, USDT_DENOM.to_owned()), @@ -277,7 +277,8 @@ fn stranger_autocompound() -> anyhow::Result<()> { assert!(status.spread_rewards.is_empty()); // Check stranger gets rewarded - let stranger_reward_balance = chain.query_balance(stranger.address().as_str(), REWARD_DENOM)?; + let stranger_reward_balance = + chain.query_balance(&Addr::unchecked(stranger.address()), REWARD_DENOM)?; assert_eq!(stranger_reward_balance, Uint128::new(1000)); Ok(()) } diff --git a/contracts/carrot-app/tests/common.rs b/contracts/carrot-app/tests/common.rs index 04c3a55..dc3fd8c 100644 --- a/contracts/carrot-app/tests/common.rs +++ b/contracts/carrot-app/tests/common.rs @@ -1,12 +1,14 @@ use std::iter; +use std::rc::Rc; use abstract_app::objects::module::ModuleInfo; use abstract_app::std::{ - manager::{self, ModuleInstallConfig}, + account::{self, ModuleInstallConfig}, objects::{pool_id::PoolAddressBase, AccountId, AssetEntry, PoolMetadata, PoolType}, }; use abstract_client::{AbstractClient, Application, Environment, Namespace}; use abstract_dex_adapter::DEX_ADAPTER_ID; +use abstract_interface::Abstract; use carrot_app::contract::APP_ID; use carrot_app::msg::{AppInstantiateMsg, CreatePositionMessage}; use carrot_app::state::AutocompoundRewardsConfig; @@ -22,6 +24,7 @@ use cw_orch_osmosis_test_tube::osmosis_test_tube::osmosis_std::types::{ MsgCollectSpreadRewards, PoolRecord, }, }; +use cw_orch_osmosis_test_tube::osmosis_test_tube::Account; use cw_orch_osmosis_test_tube::osmosis_test_tube::{ osmosis_std::types::{ cosmos::{ @@ -99,7 +102,7 @@ pub fn deploy( }, ), ]) - .build()?; + .build(chain.sender().clone())?; // We deploy the carrot_app let publisher = client @@ -145,12 +148,11 @@ pub fn deploy( type_url: MsgExecuteContract::TYPE_URL.to_owned(), value: MsgExecuteContract { sender: chain.sender_addr().to_string(), - contract: publisher.account().manager()?.to_string(), - msg: to_json_vec(&manager::ExecuteMsg::CreateSubAccount { - name: "bob".to_owned(), + contract: publisher.account().address()?.to_string(), + msg: to_json_vec(&account::ExecuteMsg::::CreateSubAccount { + name: Some("bob".to_owned()), description: None, link: None, - base_asset: None, namespace: None, install_modules: vec![ ModuleInstallConfig::new(ModuleInfo::from_id_latest(DEX_ADAPTER_ID)?, None), @@ -186,13 +188,13 @@ pub fn deploy( // We update authorized addresses on the adapter for the app dex_adapter.execute( &abstract_dex_adapter::msg::ExecuteMsg::Base(abstract_app::std::adapter::BaseExecuteMsg { - proxy_address: Some(carrot_app.account().proxy()?.to_string()), + account_address: Some(carrot_app.account().address()?.to_string()), msg: abstract_app::std::adapter::AdapterBaseMsg::UpdateAuthorizedAddresses { to_add: vec![carrot_app.addr_str()?], to_remove: vec![], }, }), - None, + &[], )?; Ok(carrot_app) @@ -216,14 +218,14 @@ pub fn create_position( belief_price1: None, }) .into(), - None, + &[], ) .map_err(Into::into) } pub fn create_pool(mut chain: OsmosisTestTube) -> anyhow::Result<(u64, u64)> { - chain.add_balance(chain.sender_addr(), coins(LOTS, USDC_DENOM))?; - chain.add_balance(chain.sender_addr(), coins(LOTS, USDT_DENOM))?; + chain.add_balance(&chain.sender_addr(), coins(LOTS, USDC_DENOM))?; + chain.add_balance(&chain.sender_addr(), coins(LOTS, USDT_DENOM))?; let asset0 = USDT_DENOM.to_owned(); let asset1 = USDC_DENOM.to_owned(); @@ -249,11 +251,13 @@ pub fn create_pool(mut chain: OsmosisTestTube) -> anyhow::Result<(u64, u64)> { title: "Create concentrated uosmo:usdc pool".to_string(), description: "Create concentrated uosmo:usdc pool, so that we can trade it" .to_string(), + #[allow(deprecated)] pool_records: vec![PoolRecord { denom0: USDT_DENOM.to_owned(), denom1: USDC_DENOM.to_owned(), tick_spacing: TICK_SPACING, spread_factor: Decimal::percent(SPREAD_FACTOR).atomics().to_string(), + exponent_at_price_one: String::default(), }], }, chain.sender_addr().to_string(), @@ -292,15 +296,15 @@ pub fn create_pool(mut chain: OsmosisTestTube) -> anyhow::Result<(u64, u64)> { let gamm = Gamm::new(&*test_tube); let rewards_pool_provider = test_tube.init_account(&[ - Coin::new(1_000_000_000, asset1.clone()), - Coin::new(2_000_000_000, REWARD_DENOM), + Coin::new(1_000_000_000_u128, asset1.clone()), + Coin::new(2_000_000_000_u128, REWARD_DENOM), Coin::new(LOTS, GAS_DENOM), ])?; let gas_pool_response = gamm.create_basic_pool( &[ - Coin::new(1_000_000_000, asset1), - Coin::new(2_000_000_000, REWARD_DENOM), + Coin::new(1_000_000_000_u128, asset1), + Coin::new(2_000_000_000_u128, REWARD_DENOM), ], &rewards_pool_provider, )?; @@ -315,7 +319,18 @@ pub fn setup_test_tube( Application>, )> { let _ = env_logger::builder().is_test(true).try_init(); - let chain = OsmosisTestTube::new(vec![coin(LOTS, GAS_DENOM)]); + let mut chain = OsmosisTestTube::new(vec![]); + + let seed = Abstract::::mock_mnemonic().to_seed(""); + let derive_path = Abstract::::mock_derive_path(None); + let signing_key = cw_orch_osmosis_test_tube::osmosis_test_tube::cosmrs::crypto::secp256k1::SigningKey::derive_from_path(seed, &derive_path.parse().unwrap()).unwrap(); + let signing_account = cw_orch_osmosis_test_tube::osmosis_test_tube::SigningAccount::new( + chain.sender.prefix().to_string(), + signing_key, + chain.sender.fee_setting().clone(), + ); + chain.set_sender(Rc::new(signing_account)); + chain.add_balance(&chain.sender_addr(), coins(LOTS, GAS_DENOM))?; // We create a usdt-usdc pool let (pool_id, gas_pool_id) = create_pool(chain.clone())?; @@ -340,12 +355,12 @@ pub fn setup_test_tube( Ok((pool_id, carrot_app)) } -pub fn give_authorizations_msgs( +pub fn give_authorizations_msgs( client: &AbstractClient, savings_app_addr: impl Into, ) -> Result, anyhow::Error> { let dex_fee_account = client.account_from(AccountId::local(0))?; - let dex_fee_addr = dex_fee_account.proxy()?.to_string(); + let dex_fee_addr = dex_fee_account.address()?.to_string(); let chain = client.environment().clone(); let authorization_urls = [ diff --git a/contracts/carrot-app/tests/deposit_withdraw.rs b/contracts/carrot-app/tests/deposit_withdraw.rs index a7da378..0c636aa 100644 --- a/contracts/carrot-app/tests/deposit_withdraw.rs +++ b/contracts/carrot-app/tests/deposit_withdraw.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use crate::common::{create_position, setup_test_tube, USDC, USDC_DENOM, USDT, USDT_DENOM}; use abstract_app::objects::AssetEntry; -use abstract_interface::{Abstract, AbstractAccount}; +use abstract_interface::{Abstract, AccountI}; use carrot_app::msg::{ AppExecuteMsg, AppExecuteMsgFns, AppQueryMsgFns, AssetsBalanceResponse, CompoundStatus, CreatePositionMessage, PositionResponse, SwapToAsset, @@ -90,12 +90,12 @@ fn withdraw_position() -> anyhow::Result<()> { let balance: AssetsBalanceResponse = carrot_app.balance()?; let balance_usdc_before_withdraw = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDT_DENOM.to_owned()))? + .balance(&chain.sender_addr(), Some(USDT_DENOM.to_owned()))? .pop() .unwrap(); let balance_usdt_before_withdraw = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDC_DENOM.to_owned()))? + .balance(&chain.sender_addr(), Some(USDC_DENOM.to_owned()))? .pop() .unwrap(); @@ -106,12 +106,12 @@ fn withdraw_position() -> anyhow::Result<()> { let balance_usdc_after_half_withdraw = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDT_DENOM.to_owned()))? + .balance(&chain.sender_addr(), Some(USDT_DENOM.to_owned()))? .pop() .unwrap(); let balance_usdt_after_half_withdraw = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDC_DENOM.to_owned()))? + .balance(&chain.sender_addr(), Some(USDC_DENOM.to_owned()))? .pop() .unwrap(); @@ -122,12 +122,12 @@ fn withdraw_position() -> anyhow::Result<()> { carrot_app.withdraw(None, None)?; let balance_usdc_after_full_withdraw = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDT_DENOM.to_owned()))? + .balance(&chain.sender_addr(), Some(USDT_DENOM.to_owned()))? .pop() .unwrap(); let balance_usdt_after_full_withdraw = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDC_DENOM.to_owned()))? + .balance(&chain.sender_addr(), Some(USDC_DENOM.to_owned()))? .pop() .unwrap(); @@ -292,9 +292,9 @@ fn partial_withdraw_position_autoclaims() -> anyhow::Result<()> { let dex: abstract_dex_adapter::interface::DexAdapter<_> = carrot_app.module()?; let abs = Abstract::load_from(chain.clone())?; let account_id = carrot_app.account().id()?; - let account = AbstractAccount::new(&abs, account_id); + let account = AccountI::load_from(&abs, account_id)?; chain.bank_send( - account.proxy.addr_str()?, + account.addr_str()?, vec![ coin(200_000, USDC_DENOM.to_owned()), coin(200_000, USDT_DENOM.to_owned()), @@ -352,9 +352,9 @@ fn manual_partial_withdraw_position_doesnt_autoclaim() -> anyhow::Result<()> { let dex: abstract_dex_adapter::interface::DexAdapter<_> = carrot_app.module()?; let abs = Abstract::load_from(chain.clone())?; let account_id = carrot_app.account().id()?; - let account = AbstractAccount::new(&abs, account_id); + let account = AccountI::load_from(&abs, account_id)?; chain.bank_send( - account.proxy.addr_str()?, + account.addr_str()?, vec![ coin(200_000, USDC_DENOM.to_owned()), coin(200_000, USDT_DENOM.to_owned()), @@ -471,7 +471,7 @@ fn error_on_provided_funds() -> anyhow::Result<()> { belief_price1: None, }) .into(), - Some(&[coin(10, GAS_DENOM)]), + &[coin(10, GAS_DENOM)], ) .expect_err("Should error when funds provided"); Ok(()) @@ -500,10 +500,10 @@ fn withdraw_to_asset() -> anyhow::Result<()> { { let asset0_balance_before = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDT_DENOM.to_owned()))?; + .balance(&chain.sender_addr(), Some(USDT_DENOM.to_owned()))?; let asset1_balance_before = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDC_DENOM.to_owned()))?; + .balance(&chain.sender_addr(), Some(USDC_DENOM.to_owned()))?; carrot_app.withdraw( Some(withdraw_liquidity_amount), @@ -515,10 +515,10 @@ fn withdraw_to_asset() -> anyhow::Result<()> { let asset0_balance_after = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDT_DENOM.to_owned()))?; + .balance(&chain.sender_addr(), Some(USDT_DENOM.to_owned()))?; let asset1_balance_after = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDC_DENOM.to_owned()))?; + .balance(&chain.sender_addr(), Some(USDC_DENOM.to_owned()))?; assert_eq!(asset0_balance_before, asset0_balance_after); assert!( @@ -531,10 +531,10 @@ fn withdraw_to_asset() -> anyhow::Result<()> { { let asset0_balance_before = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDT_DENOM.to_owned()))?; + .balance(&chain.sender_addr(), Some(USDT_DENOM.to_owned()))?; let asset1_balance_before = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDC_DENOM.to_owned()))?; + .balance(&chain.sender_addr(), Some(USDC_DENOM.to_owned()))?; carrot_app.withdraw( Some(withdraw_liquidity_amount), @@ -546,10 +546,10 @@ fn withdraw_to_asset() -> anyhow::Result<()> { let asset0_balance_after = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDT_DENOM.to_owned()))?; + .balance(&chain.sender_addr(), Some(USDT_DENOM.to_owned()))?; let asset1_balance_after = chain .bank_querier() - .balance(chain.sender_addr(), Some(USDC_DENOM.to_owned()))?; + .balance(&chain.sender_addr(), Some(USDC_DENOM.to_owned()))?; assert_eq!(asset1_balance_before, asset1_balance_after); assert!( From 5a993c6ab67fc13a5d9220b18376764688415cc9 Mon Sep 17 00:00:00 2001 From: Buckram Date: Fri, 25 Oct 2024 11:51:05 +0300 Subject: [PATCH 2/5] fix feature for dex-adapter --- contracts/carrot-app/Cargo.toml | 5 ++++- .../carrot-app/src/handlers/swap_helpers.rs | 16 +++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/contracts/carrot-app/Cargo.toml b/contracts/carrot-app/Cargo.toml index 8c944a9..f588198 100644 --- a/contracts/carrot-app/Cargo.toml +++ b/contracts/carrot-app/Cargo.toml @@ -31,7 +31,10 @@ export = [] node-tests = ["interface"] interface = ["export", "dep:cw-orch"] schema = ["abstract-app/schema"] -mock-deployment = ["abstract-app/mock-deployment"] +mock-deployment = [ + "abstract-app/mock-deployment", + "abstract-dex-adapter/mock-deployment", +] [package.metadata.optimizer] builds = [{ name = "mock", features = ["mock-deployment"] }] diff --git a/contracts/carrot-app/src/handlers/swap_helpers.rs b/contracts/carrot-app/src/handlers/swap_helpers.rs index 57c1677..3281cc6 100644 --- a/contracts/carrot-app/src/handlers/swap_helpers.rs +++ b/contracts/carrot-app/src/handlers/swap_helpers.rs @@ -125,7 +125,8 @@ pub(crate) fn tokens_to_swap( ) } else { let numerator = x0_a1 - x1_a0; - let denominator = asset1.amount + asset0.amount / Uint128::one().mul_floor(price); + let denominator = asset1.amount + + Uint128::one().mul_floor(Decimal::from_ratio(asset0.amount, 1u128) / price); let y0 = numerator / denominator; ( @@ -137,7 +138,8 @@ pub(crate) fn tokens_to_swap( denom: x0.denom, }, asset1: Coin { - amount: x1.amount + y0 / Uint128::one().mul_floor(price), + amount: x1.amount + + Uint128::one().mul_floor(Decimal::from_ratio(y0, 1u128) / price), denom: x1.denom, }, }, @@ -191,7 +193,6 @@ mod tests { let expected = expected.into().u128(); let result = result.u128(); - dbg!(expected, result); if expected < result - 1 || expected > result + 1 { panic!("Results are not close enough") } @@ -328,7 +329,10 @@ mod tests { assert_is_around( swap.amount, 5_000 - - 5_000 * amount1 / (amount1 + (amount0 / Uint128::one().mul_floor(price).u128())), + - 5_000 * amount1 + / (amount1 + + (Uint128::one().mul_floor(Decimal::from_ratio(amount0, 1u128) / price)) + .u128()), ); assert_eq!(swap.name, AssetEntry::new(TOKEN1)); assert_eq!(ask_asset, AssetEntry::new(TOKEN0)); @@ -354,7 +358,9 @@ mod tests { assert_eq!(ask_asset, AssetEntry::new(TOKEN1)); assert_eq!( 10_000 - swap.amount.u128(), - 4_000 + (swap.amount / Uint128::one().mul_floor(price)).u128() + 4_000 + + (Uint128::one().mul_floor(Decimal::from_ratio(swap.amount, 1u128) / price)) + .u128() ); } } From 0819466d9646d08f0db8be59b2e33fc7a6c29304 Mon Sep 17 00:00:00 2001 From: Buckram Date: Wed, 30 Oct 2024 13:20:26 +0200 Subject: [PATCH 3/5] replace mock_deployment to wasm editing --- .cargo/config.toml | 4 ++++ Cargo.toml | 24 +++++++++---------- contracts/carrot-app/Cargo.toml | 10 ++------ contracts/carrot-app/examples/deploy.rs | 6 +++-- contracts/carrot-app/tests/common.rs | 15 ++++++++---- .../carrot-app/tests/recreate_position.rs | 4 ++-- 6 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..ccae65c --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,4 @@ +# We set it for tests +# From https://github.com/CosmosContracts/juno/blob/32568dba828ff7783aea8cb5bb4b8b5832888255/docker/test-user.env#L2 +[env] +ABSTRACT_CREATOR = "clip hire initial neck maid actor venue client foam budget lock catalog sweet steak waste crater broccoli pipe steak sister coyote moment obvious choose" diff --git a/Cargo.toml b/Cargo.toml index 3df138a..df8cb4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,8 @@ cw-orch = "0.26.0" abstract-app = { version = "0.24.1-beta.2" } abstract-adapter = { version = "0.24.1-beta.2" } abstract-interface = { version = "0.24.1-beta.2" } -abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } -abstract-osmosis-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } +abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } +abstract-osmosis-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } abstract-client = { version = "0.24.1-beta.2" } cw-asset = { version = "4.0" } cw-orch-osmosis-test-tube = { version = "0.4.0" } @@ -26,16 +26,16 @@ panic = 'abort' incremental = false [patch.crates-io] -abstract-app = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } -abstract-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } -abstract-interface = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } -abstract-client = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } -abstract-dex-standard = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } -abstract-std = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } -abstract-sdk = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } -abstract-adapter-utils = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } -# abstract-osmosis-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } -# abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-tests" } # Replace to tag tag = "v0.23.0-dex-adapter" } +abstract-app = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } +abstract-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } +abstract-interface = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } +abstract-client = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } +abstract-dex-standard = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } +abstract-std = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } +abstract-sdk = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } +abstract-adapter-utils = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } +# abstract-osmosis-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } +# abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } # Replace to tag tag = "v0.23.0-dex-adapter" } cw-orch-osmosis-test-tube = { git = "https://github.com/AbstractSDK/cw-orchestrator.git", branch = "buckram/revive-osmosis-test-tube" } cw-orch-core = { git = "https://github.com/AbstractSDK/cw-orchestrator.git", branch = "buckram/revive-osmosis-test-tube" } diff --git a/contracts/carrot-app/Cargo.toml b/contracts/carrot-app/Cargo.toml index f588198..30ee6ad 100644 --- a/contracts/carrot-app/Cargo.toml +++ b/contracts/carrot-app/Cargo.toml @@ -31,13 +31,6 @@ export = [] node-tests = ["interface"] interface = ["export", "dep:cw-orch"] schema = ["abstract-app/schema"] -mock-deployment = [ - "abstract-app/mock-deployment", - "abstract-dex-adapter/mock-deployment", -] - -[package.metadata.optimizer] -builds = [{ name = "mock", features = ["mock-deployment"] }] [dependencies] cw-utils = { version = "2.0.0" } @@ -59,10 +52,11 @@ prost = { version = "0.13.1" } [dev-dependencies] abstract-interface = { workspace = true, features = ["daemon"] } +bip32 = "0.5.2" prost-types = { version = "0.13.1" } log = { version = "0.4.20" } -carrot-app = { path = ".", features = ["interface", "mock-deployment"] } +carrot-app = { path = ".", features = ["interface"] } abstract-client = { workspace = true } abstract-app = { workspace = true, features = ["test-utils", "stargate"] } semver = "1.0" diff --git a/contracts/carrot-app/examples/deploy.rs b/contracts/carrot-app/examples/deploy.rs index fe309df..e7fb745 100644 --- a/contracts/carrot-app/examples/deploy.rs +++ b/contracts/carrot-app/examples/deploy.rs @@ -19,8 +19,10 @@ fn main() -> anyhow::Result<()> { let abstr = abstract_client::AbstractClient::new(daemon)?; let publisher = abstr - .publisher_builder(Namespace::new(ABSTRACT_NAMESPACE)?) - .build()?; + .fetch_or_build_account(Namespace::new(ABSTRACT_NAMESPACE)?, |builder| { + builder.namespace(Namespace::new(ABSTRACT_NAMESPACE).unwrap()) + })? + .publisher()?; publisher.publish_app::>()?; abstr.registry().approve_any_abstract_modules()?; diff --git a/contracts/carrot-app/tests/common.rs b/contracts/carrot-app/tests/common.rs index dc3fd8c..fe615cc 100644 --- a/contracts/carrot-app/tests/common.rs +++ b/contracts/carrot-app/tests/common.rs @@ -2,6 +2,7 @@ use std::iter; use std::rc::Rc; use abstract_app::objects::module::ModuleInfo; +use abstract_app::objects::namespace::ABSTRACT_NAMESPACE; use abstract_app::std::{ account::{self, ModuleInstallConfig}, objects::{pool_id::PoolAddressBase, AccountId, AssetEntry, PoolMetadata, PoolType}, @@ -106,8 +107,10 @@ pub fn deploy( // We deploy the carrot_app let publisher = client - .publisher_builder(Namespace::new("abstract")?) - .build()?; + .fetch_or_build_account(Namespace::new(ABSTRACT_NAMESPACE)?, |builder| { + builder.namespace(Namespace::new(ABSTRACT_NAMESPACE).unwrap()) + })? + .publisher()?; // The dex adapter let dex_adapter = publisher .publish_adapter::<_, abstract_dex_adapter::interface::DexAdapter>( @@ -312,6 +315,8 @@ pub fn create_pool(mut chain: OsmosisTestTube) -> anyhow::Result<(u64, u64)> { Ok((pool.id, gas_pool_response.data.pool_id)) } +const MOCK_MNEMONIC: &str = "clip hire initial neck maid actor venue client foam budget lock catalog sweet steak waste crater broccoli pipe steak sister coyote moment obvious choose"; + pub fn setup_test_tube( create_position: bool, ) -> anyhow::Result<( @@ -321,8 +326,10 @@ pub fn setup_test_tube( let _ = env_logger::builder().is_test(true).try_init(); let mut chain = OsmosisTestTube::new(vec![]); - let seed = Abstract::::mock_mnemonic().to_seed(""); - let derive_path = Abstract::::mock_derive_path(None); + let seed = bip32::Mnemonic::new(MOCK_MNEMONIC, Default::default()) + .unwrap() + .to_seed(""); + let derive_path = "m/44'/118'/0'/0/0"; let signing_key = cw_orch_osmosis_test_tube::osmosis_test_tube::cosmrs::crypto::secp256k1::SigningKey::derive_from_path(seed, &derive_path.parse().unwrap()).unwrap(); let signing_account = cw_orch_osmosis_test_tube::osmosis_test_tube::SigningAccount::new( chain.sender.prefix().to_string(), diff --git a/contracts/carrot-app/tests/recreate_position.rs b/contracts/carrot-app/tests/recreate_position.rs index d6cd3f4..d2deb97 100644 --- a/contracts/carrot-app/tests/recreate_position.rs +++ b/contracts/carrot-app/tests/recreate_position.rs @@ -192,7 +192,7 @@ fn install_on_sub_account() -> anyhow::Result<()> { .install_app_with_dependencies::>( &init_msg, Empty {}, - )? + ) .build()?; let carrot_app = account.application::>()?; @@ -254,7 +254,7 @@ fn install_on_sub_account_create_position_on_install() -> anyhow::Result<()> { .install_app_with_dependencies::>( &init_msg, Empty {}, - )? + ) .build()?; let carrot_app = account.application::>()?; From 483f5f7ac6fc8760b88b3fb4d82aa27677f8706d Mon Sep 17 00:00:00 2001 From: Buckram Date: Fri, 15 Nov 2024 20:19:19 +0200 Subject: [PATCH 4/5] Update carrot for predictable addresses on abstract --- Cargo.toml | 38 ++-- bot/src/bot.rs | 2 +- contracts/carrot-app/Cargo.toml | 8 +- .../examples/install_savings_app.rs | 189 ++++++++++-------- contracts/carrot-app/src/handlers/execute.rs | 15 +- .../carrot-app/src/handlers/instantiate.rs | 2 +- contracts/carrot-app/src/handlers/query.rs | 6 +- contracts/carrot-app/src/helpers.rs | 12 +- .../carrot-app/src/replies/add_to_position.rs | 4 +- .../carrot-app/src/replies/create_position.rs | 4 +- .../src/replies/withdraw_to_asset.rs | 4 +- contracts/carrot-app/tests/common.rs | 32 +-- 12 files changed, 150 insertions(+), 166 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index df8cb4e..9219524 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,13 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [workspace.dependencies] -cw-orch = "0.26.0" -abstract-app = { version = "0.24.1-beta.2" } -abstract-adapter = { version = "0.24.1-beta.2" } -abstract-interface = { version = "0.24.1-beta.2" } -abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -abstract-osmosis-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -abstract-client = { version = "0.24.1-beta.2" } +cw-orch = { version = "0.27.0" } +abstract-app = { version = "0.24.1" } +abstract-adapter = { version = "0.24.1" } +abstract-interface = { version = "0.24.1" } +abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "main", default-features = false } +abstract-osmosis-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "main" } +abstract-client = { version = "0.24.1" } cw-asset = { version = "4.0" } cw-orch-osmosis-test-tube = { version = "0.4.0" } @@ -26,17 +26,13 @@ panic = 'abort' incremental = false [patch.crates-io] -abstract-app = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -abstract-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -abstract-interface = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -abstract-client = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -abstract-dex-standard = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -abstract-std = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -abstract-sdk = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -abstract-adapter-utils = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -# abstract-osmosis-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } -# abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "buckram/update-osmosis-test-with-modified-wasm" } # Replace to tag tag = "v0.23.0-dex-adapter" } - -cw-orch-osmosis-test-tube = { git = "https://github.com/AbstractSDK/cw-orchestrator.git", branch = "buckram/revive-osmosis-test-tube" } -cw-orch-core = { git = "https://github.com/AbstractSDK/cw-orchestrator.git", branch = "buckram/revive-osmosis-test-tube" } -cw-orch-traits = { git = "https://github.com/AbstractSDK/cw-orchestrator.git", branch = "buckram/revive-osmosis-test-tube" } +abstract-app = { git = "https://github.com/abstractsdk/abstract.git", branch = "artifacts/0.24.x" } +abstract-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "artifacts/0.24.x" } +abstract-interface = { git = "https://github.com/abstractsdk/abstract.git", branch = "artifacts/0.24.x" } +abstract-client = { git = "https://github.com/abstractsdk/abstract.git", branch = "artifacts/0.24.x" } +abstract-dex-standard = { git = "https://github.com/abstractsdk/abstract.git", branch = "artifacts/0.24.x" } +abstract-std = { git = "https://github.com/abstractsdk/abstract.git", branch = "artifacts/0.24.x" } +abstract-sdk = { git = "https://github.com/abstractsdk/abstract.git", branch = "artifacts/0.24.x" } +abstract-adapter-utils = { git = "https://github.com/abstractsdk/abstract.git", branch = "artifacts/0.24.x" } +# abstract-osmosis-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "artifacts/0.24.x" } +# abstract-dex-adapter = { git = "https://github.com/abstractsdk/abstract.git", branch = "artifacts/0.24.x" } # Replace to tag tag = "v0.25.0" } diff --git a/bot/src/bot.rs b/bot/src/bot.rs index 1c78242..12ae333 100644 --- a/bot/src/bot.rs +++ b/bot/src/bot.rs @@ -395,7 +395,7 @@ mod utils { ) -> anyhow::Result { let daemon = abstr.environment(); - let account = abstr.account_from(AccountSource::App(Addr::unchecked(contract_addr)))?; + let account = abstr.fetch_account(AccountSource::App(Addr::unchecked(contract_addr)))?; let granter = account.owner()?; // Check if authz is indeed given diff --git a/contracts/carrot-app/Cargo.toml b/contracts/carrot-app/Cargo.toml index 30ee6ad..e798d95 100644 --- a/contracts/carrot-app/Cargo.toml +++ b/contracts/carrot-app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "carrot-app" -version = "0.5.1" +version = "0.6.0" authors = [ "CyberHoward ", "Adair ", @@ -44,7 +44,8 @@ cw-asset = { workspace = true } abstract-app = { workspace = true, features = ["stargate"] } # Dependencies for interface -abstract-dex-adapter = { workspace = true, features = ["osmosis"] } +abstract-dex-adapter = { workspace = true, features = [ +], default-features = false } cw-orch = { workspace = true, optional = true } osmosis-std = { version = "0.26.0" } @@ -52,7 +53,6 @@ prost = { version = "0.13.1" } [dev-dependencies] abstract-interface = { workspace = true, features = ["daemon"] } -bip32 = "0.5.2" prost-types = { version = "0.13.1" } log = { version = "0.4.20" } @@ -62,6 +62,6 @@ abstract-app = { workspace = true, features = ["test-utils", "stargate"] } semver = "1.0" dotenv = "0.15.0" env_logger = "0.10.0" -cw-orch = { workspace = true } +cw-orch = { workspace = true, features = ["daemon"] } cw-orch-osmosis-test-tube = { workspace = true } clap = { version = "4.3.7", features = ["derive"] } diff --git a/contracts/carrot-app/examples/install_savings_app.rs b/contracts/carrot-app/examples/install_savings_app.rs index 92d7bf3..440344a 100644 --- a/contracts/carrot-app/examples/install_savings_app.rs +++ b/contracts/carrot-app/examples/install_savings_app.rs @@ -6,7 +6,6 @@ use cw_orch::{ anyhow, daemon::{networks::OSMOSIS_1, Daemon, DaemonBuilder}, prelude::Stargate, - tokio::runtime::Runtime, }; use cw_orch_osmosis_test_tube::osmosis_test_tube::osmosis_std::types::cosmos::authz::v1beta1::MsgGrantResponse; use dotenv::dotenv; @@ -34,8 +33,7 @@ fn main() -> anyhow::Result<()> { dotenv().ok(); env_logger::init(); let chain = OSMOSIS_1; - let rt = Runtime::new()?; - let daemon = DaemonBuilder::new(chain).handle(rt.handle()).build()?; + let daemon = DaemonBuilder::new(chain).build()?; let client = AbstractClient::new(daemon.clone())?; let random_account_id = client.random_account_id()?; @@ -78,7 +76,7 @@ fn main() -> anyhow::Result<()> { let create_sub_account_message = utils::create_account_message(&client, init_msg)?; msgs.push(create_sub_account_message); - let _ = daemon.commit_any::(msgs, None)?; + let _ = daemon.commit_any(msgs, None)?; Ok(()) } @@ -168,11 +166,14 @@ mod utils { pub const LOTS: u128 = 100_000_000_000_000; pub const REWARD_ASSET: &str = "osmosis>osmo"; - use abstract_app::objects::{ - module::{ModuleInfo, ModuleVersion}, - AccountId, - }; use abstract_app::std::account::ModuleInstallConfig; + use abstract_app::{ + objects::{ + module::{ModuleInfo, ModuleVersion}, + salt, AccountId, + }, + std::account, + }; use abstract_client::*; use abstract_dex_adapter::DEX_ADAPTER_ID; use abstract_interface::Abstract; @@ -184,7 +185,7 @@ mod utils { authz::v1beta1::{GenericAuthorization, Grant, MsgGrant}, bank::v1beta1::SendAuthorization, }, - cosmwasm::wasm::v1::MsgExecuteContract, + cosmwasm::wasm::v1::{MsgExecuteContract, MsgInstantiateContract2}, osmosis::{ concentratedliquidity::v1beta1::{ MsgAddToPosition, MsgCollectIncentives, MsgCollectSpreadRewards, MsgCreatePosition, @@ -202,7 +203,7 @@ mod utils { savings_app_addr: impl Into, app_data: &CarrotAppInitData, ) -> Result, anyhow::Error> { - let dex_fee_account = client.account_from(AccountId::local(0))?; + let dex_fee_account = client.fetch_account(AccountId::local(0))?; let dex_fee_addr = dex_fee_account.address()?.to_string(); let chain = client.environment().clone(); @@ -282,47 +283,60 @@ mod utils { let chain = client.environment(); let abstr = Abstract::load_from(chain.clone())?; let random_account_id = client.random_account_id()?; - - todo!(); - // let msg = Any { - // type_url: MsgExecuteContract::TYPE_URL.to_owned(), - // value: MsgExecuteContract { - // sender: chain.sender_addr().to_string(), - // contract: account_factory_addr.to_string(), - // msg: to_json_vec(&account_factory::ExecuteMsg::CreateAccount { - // governance: GovernanceDetails::Monarchy { - // monarch: chain.sender_addr().to_string(), - // }, - // name: "bob".to_owned(), - // description: None, - // link: None, - // base_asset: None, - // namespace: None, - // install_modules: vec![ - // ModuleInstallConfig::new( - // ModuleInfo::from_id( - // DEX_ADAPTER_ID, - // ModuleVersion::Version( - // abstract_dex_adapter::contract::CONTRACT_VERSION.to_owned(), - // ), - // )?, - // None, - // ), - // ModuleInstallConfig::new( - // ModuleInfo::from_id( - // APP_ID, - // ModuleVersion::Version(APP_VERSION.to_owned()), - // )?, - // Some(to_json_binary(&init_msg)?), - // ), - // ], - // account_id: Some(AccountId::local(random_account_id)), - // })?, - // funds: vec![], - // } - // .to_proto_bytes(), - // }; - // Ok(msg) + let salt = salt::generate_instantiate_salt(&AccountId::local(random_account_id)); + let code_id = abstr.account_code_id()?; + let creator = chain.sender_addr().to_string(); + + let account_address = chain.wasm_querier().instantiate2_addr( + code_id, + &Addr::unchecked(creator.clone()), + salt.clone(), + )?; + + let msg = Any { + type_url: MsgInstantiateContract2::TYPE_URL.to_owned(), + value: MsgInstantiateContract2 { + sender: creator, + admin: account_address, + code_id, + label: "Abstract Account".to_owned(), + msg: to_json_vec(&account::InstantiateMsg:: { + code_id, + owner: GovernanceDetails::Monarchy { + monarch: chain.sender_addr().to_string(), + }, + name: Some("bob".to_owned()), + description: None, + link: None, + namespace: None, + install_modules: vec![ + ModuleInstallConfig::new( + ModuleInfo::from_id( + DEX_ADAPTER_ID, + ModuleVersion::Version( + abstract_dex_adapter::contract::CONTRACT_VERSION.to_owned(), + ), + )?, + None, + ), + ModuleInstallConfig::new( + ModuleInfo::from_id( + APP_ID, + ModuleVersion::Version(APP_VERSION.to_owned()), + )?, + Some(to_json_binary(&init_msg)?), + ), + ], + account_id: Some(AccountId::local(random_account_id)), + authenticator: None, + })?, + funds: vec![], + salt: salt.to_vec(), + fix_msg: false, + } + .to_proto_bytes(), + }; + Ok(msg) } pub fn create_sub_account_message( @@ -333,41 +347,42 @@ mod utils { let chain = client.environment(); let random_account_id = client.random_account_id()?; - todo!() - // let msg = Any { - // type_url: MsgExecuteContract::TYPE_URL.to_owned(), - // value: MsgExecuteContract { - // sender: chain.sender_addr().to_string(), - // contract: account.address()?.to_string(), - // msg: to_json_vec(&abstract_app::std::account::ExecuteMsg::CreateSubAccount { - // name: Some("deep-adventurous-afternoon".to_owned()), - // description: None, - // link: None, - // namespace: None, - // install_modules: vec![ - // ModuleInstallConfig::new( - // ModuleInfo::from_id( - // DEX_ADAPTER_ID, - // ModuleVersion::Version( - // abstract_dex_adapter::contract::CONTRACT_VERSION.to_owned(), - // ), - // )?, - // None, - // ), - // ModuleInstallConfig::new( - // ModuleInfo::from_id( - // APP_ID, - // ModuleVersion::Version(APP_VERSION.to_owned()), - // )?, - // Some(to_json_binary(&init_msg)?), - // ), - // ], - // account_id: Some(random_account_id), - // })?, - // funds: vec![], - // } - // .to_proto_bytes(), - // }; - // Ok(msg) + let msg = Any { + type_url: MsgExecuteContract::TYPE_URL.to_owned(), + value: MsgExecuteContract { + sender: chain.sender_addr().to_string(), + contract: account.address()?.to_string(), + msg: to_json_vec( + &abstract_app::std::account::ExecuteMsg::::CreateSubAccount { + name: Some("deep-adventurous-afternoon".to_owned()), + description: None, + link: None, + namespace: None, + install_modules: vec![ + ModuleInstallConfig::new( + ModuleInfo::from_id( + DEX_ADAPTER_ID, + ModuleVersion::Version( + abstract_dex_adapter::contract::CONTRACT_VERSION.to_owned(), + ), + )?, + None, + ), + ModuleInstallConfig::new( + ModuleInfo::from_id( + APP_ID, + ModuleVersion::Version(APP_VERSION.to_owned()), + )?, + Some(to_json_binary(&init_msg)?), + ), + ], + account_id: Some(random_account_id), + }, + )?, + funds: vec![], + } + .to_proto_bytes(), + }; + Ok(msg) } } diff --git a/contracts/carrot-app/src/handlers/execute.rs b/contracts/carrot-app/src/handlers/execute.rs index 4f92ab3..8ee3fab 100644 --- a/contracts/carrot-app/src/handlers/execute.rs +++ b/contracts/carrot-app/src/handlers/execute.rs @@ -47,7 +47,6 @@ pub fn execute_handler( autocompound_rewards_config, } => update_config( deps, - env, app, autocompound_cooldown_seconds, autocompound_rewards_config, @@ -79,7 +78,6 @@ pub fn execute_handler( fn update_config( deps: DepsMut, - env: Env, app: App, autocompound_cooldown_seconds: Option, autocompound_rewards_config: Option, @@ -88,7 +86,7 @@ fn update_config( if let Some(new_rewards_config) = autocompound_rewards_config { // Validate rewards config first - let ans = app.name_service(deps.as_ref(), &env); + let ans = app.name_service(deps.as_ref()); let asset_pairing_resp: Vec = ans .pool_list( Some(abstract_app::std::ans_host::AssetPairingFilter { @@ -527,7 +525,7 @@ pub fn autocompound_executor_rewards( // Get user balance of gas denom let gas_denom = rewards_config .gas_asset - .resolve(&deps.querier, &app.ans_host(deps, env)?)?; + .resolve(&deps.querier, &app.ans_host(deps)?)?; let user_gas_balance = gas_denom.query_balance(&deps.querier, user.clone())?; let mut rewards_messages = vec![]; @@ -545,13 +543,8 @@ pub fn autocompound_executor_rewards( )?; // Get user balance of swap denom - let user_swap_balance = get_balance( - rewards_config.swap_asset.clone(), - deps, - env, - user.clone(), - app, - )?; + let user_swap_balance = + get_balance(rewards_config.swap_asset.clone(), deps, user.clone(), app)?; // Swap as much as available if not enough for max_gas_balance let swap_amount = simulate_swap_response.return_amount.min(user_swap_balance); diff --git a/contracts/carrot-app/src/handlers/instantiate.rs b/contracts/carrot-app/src/handlers/instantiate.rs index 97a96ad..de5d3a8 100644 --- a/contracts/carrot-app/src/handlers/instantiate.rs +++ b/contracts/carrot-app/src/handlers/instantiate.rs @@ -32,7 +32,7 @@ pub fn instantiate_handler( .try_into()?; // We query the ANS for useful information on the tokens and pool - let ans = app.name_service(deps.as_ref(), &env); + let ans = app.name_service(deps.as_ref()); // ANS Asset entries to indentify the assets inside Abstract let asset_entries = ans.query(&vec![ AssetInfo::Native(pool.token0.clone()), diff --git a/contracts/carrot-app/src/handlers/query.rs b/contracts/carrot-app/src/handlers/query.rs index cd22655..96d4485 100644 --- a/contracts/carrot-app/src/handlers/query.rs +++ b/contracts/carrot-app/src/handlers/query.rs @@ -46,7 +46,7 @@ fn query_compound_status(deps: Deps, env: Env, app: &App) -> AppResult AppResult required_swap_amount @@ -128,7 +128,7 @@ pub fn query_price( belief_price1: Option, ) -> AppResult { let config = CONFIG.load(deps.storage)?; - let ans_host = app.ans_host(deps, env)?; + let ans_host = app.ans_host(deps)?; // We know it's native denom for osmosis pool let token0 = config diff --git a/contracts/carrot-app/src/helpers.rs b/contracts/carrot-app/src/helpers.rs index 4338ee7..3a426eb 100644 --- a/contracts/carrot-app/src/helpers.rs +++ b/contracts/carrot-app/src/helpers.rs @@ -1,6 +1,6 @@ use abstract_app::sdk::Resolve; use abstract_app::{objects::AssetEntry, traits::AbstractNameService}; -use cosmwasm_std::{Addr, Deps, Env, MessageInfo, Uint128}; +use cosmwasm_std::{Addr, Deps, MessageInfo, Uint128}; use crate::{ contract::{App, AppResult}, @@ -16,14 +16,8 @@ pub fn get_user(deps: Deps, app: &App) -> AppResult { .map(|admin| deps.api.addr_validate(&admin))??) } -pub fn get_balance( - a: AssetEntry, - deps: Deps, - env: &Env, - address: Addr, - app: &App, -) -> AppResult { - let denom = a.resolve(&deps.querier, &app.ans_host(deps, env)?)?; +pub fn get_balance(a: AssetEntry, deps: Deps, address: Addr, app: &App) -> AppResult { + let denom = a.resolve(&deps.querier, &app.ans_host(deps)?)?; let user_gas_balance = denom.query_balance(&deps.querier, address.clone())?; Ok(user_gas_balance) } diff --git a/contracts/carrot-app/src/replies/add_to_position.rs b/contracts/carrot-app/src/replies/add_to_position.rs index 11fa9df..8463f4e 100644 --- a/contracts/carrot-app/src/replies/add_to_position.rs +++ b/contracts/carrot-app/src/replies/add_to_position.rs @@ -9,7 +9,9 @@ use crate::{ }; pub fn add_to_position_reply(deps: DepsMut, env: Env, app: App, reply: Reply) -> AppResult { - let SubMsgResult::Ok(SubMsgResponse { data: Some(b), .. }) = reply.result else { + #[allow(deprecated)] + let SubMsgResult::Ok(SubMsgResponse { data: Some(b), .. }) = reply.result + else { return Err(AppError::Std(StdError::generic_err( "Failed to create position", ))); diff --git a/contracts/carrot-app/src/replies/create_position.rs b/contracts/carrot-app/src/replies/create_position.rs index eeda843..8182ec6 100644 --- a/contracts/carrot-app/src/replies/create_position.rs +++ b/contracts/carrot-app/src/replies/create_position.rs @@ -9,7 +9,9 @@ use crate::{ }; pub fn create_position_reply(deps: DepsMut, env: Env, app: App, reply: Reply) -> AppResult { - let SubMsgResult::Ok(SubMsgResponse { data: Some(b), .. }) = reply.result else { + #[allow(deprecated)] + let SubMsgResult::Ok(SubMsgResponse { data: Some(b), .. }) = reply.result + else { return Err(AppError::Std(StdError::generic_err( "Failed to create position", ))); diff --git a/contracts/carrot-app/src/replies/withdraw_to_asset.rs b/contracts/carrot-app/src/replies/withdraw_to_asset.rs index fa968d2..6c80a57 100644 --- a/contracts/carrot-app/src/replies/withdraw_to_asset.rs +++ b/contracts/carrot-app/src/replies/withdraw_to_asset.rs @@ -10,7 +10,9 @@ use crate::{ }; pub fn withdraw_to_asset_reply(deps: DepsMut, env: Env, app: App, reply: Reply) -> AppResult { - let SubMsgResult::Ok(SubMsgResponse { data: Some(b), .. }) = reply.result else { + #[allow(deprecated)] + let SubMsgResult::Ok(SubMsgResponse { data: Some(b), .. }) = reply.result + else { return Err(AppError::Std(StdError::generic_err( "Failed to withdraw to asset", ))); diff --git a/contracts/carrot-app/tests/common.rs b/contracts/carrot-app/tests/common.rs index fe615cc..1d25f73 100644 --- a/contracts/carrot-app/tests/common.rs +++ b/contracts/carrot-app/tests/common.rs @@ -1,5 +1,4 @@ use std::iter; -use std::rc::Rc; use abstract_app::objects::module::ModuleInfo; use abstract_app::objects::namespace::ABSTRACT_NAMESPACE; @@ -9,7 +8,6 @@ use abstract_app::std::{ }; use abstract_client::{AbstractClient, Application, Environment, Namespace}; use abstract_dex_adapter::DEX_ADAPTER_ID; -use abstract_interface::Abstract; use carrot_app::contract::APP_ID; use carrot_app::msg::{AppInstantiateMsg, CreatePositionMessage}; use carrot_app::state::AutocompoundRewardsConfig; @@ -25,11 +23,10 @@ use cw_orch_osmosis_test_tube::osmosis_test_tube::osmosis_std::types::{ MsgCollectSpreadRewards, PoolRecord, }, }; -use cw_orch_osmosis_test_tube::osmosis_test_tube::Account; use cw_orch_osmosis_test_tube::osmosis_test_tube::{ osmosis_std::types::{ cosmos::{ - authz::v1beta1::{GenericAuthorization, Grant, MsgGrant, MsgGrantResponse}, + authz::v1beta1::{GenericAuthorization, Grant, MsgGrant}, base::v1beta1, }, osmosis::{ @@ -103,7 +100,7 @@ pub fn deploy( }, ), ]) - .build(chain.sender().clone())?; + .build()?; // We deploy the carrot_app let publisher = client @@ -171,7 +168,7 @@ pub fn deploy( .to_proto_bytes(), }; msgs.push(create_sub_account_message); - let _ = chain.commit_any::(msgs, None)?; + let _ = chain.commit_any(msgs, None)?; // Now get Application struct let account = client.account_from(AccountId::local(random_account_id))?; @@ -315,8 +312,6 @@ pub fn create_pool(mut chain: OsmosisTestTube) -> anyhow::Result<(u64, u64)> { Ok((pool.id, gas_pool_response.data.pool_id)) } -const MOCK_MNEMONIC: &str = "clip hire initial neck maid actor venue client foam budget lock catalog sweet steak waste crater broccoli pipe steak sister coyote moment obvious choose"; - pub fn setup_test_tube( create_position: bool, ) -> anyhow::Result<( @@ -324,20 +319,7 @@ pub fn setup_test_tube( Application>, )> { let _ = env_logger::builder().is_test(true).try_init(); - let mut chain = OsmosisTestTube::new(vec![]); - - let seed = bip32::Mnemonic::new(MOCK_MNEMONIC, Default::default()) - .unwrap() - .to_seed(""); - let derive_path = "m/44'/118'/0'/0/0"; - let signing_key = cw_orch_osmosis_test_tube::osmosis_test_tube::cosmrs::crypto::secp256k1::SigningKey::derive_from_path(seed, &derive_path.parse().unwrap()).unwrap(); - let signing_account = cw_orch_osmosis_test_tube::osmosis_test_tube::SigningAccount::new( - chain.sender.prefix().to_string(), - signing_key, - chain.sender.fee_setting().clone(), - ); - chain.set_sender(Rc::new(signing_account)); - chain.add_balance(&chain.sender_addr(), coins(LOTS, GAS_DENOM))?; + let chain = OsmosisTestTube::new(coins(LOTS, GAS_DENOM)); // We create a usdt-usdc pool let (pool_id, gas_pool_id) = create_pool(chain.clone())?; @@ -366,7 +348,7 @@ pub fn give_authorizations_msgs( client: &AbstractClient, savings_app_addr: impl Into, ) -> Result, anyhow::Error> { - let dex_fee_account = client.account_from(AccountId::local(0))?; + let dex_fee_account = client.fetch_account(AccountId::local(0))?; let dex_fee_addr = dex_fee_account.address()?.to_string(); let chain = client.environment().clone(); @@ -439,9 +421,7 @@ pub fn give_authorizations( savings_app_addr: impl Into, ) -> Result<(), anyhow::Error> { let msgs = give_authorizations_msgs(client, savings_app_addr)?; - client - .environment() - .commit_any::(msgs, None)?; + client.environment().commit_any(msgs, None)?; Ok(()) } From ad97f6d5823a77dccc5579c28c02e9cd9bdf030e Mon Sep 17 00:00:00 2001 From: Mykhailo Donchenko <91957742+Buckram123@users.noreply.github.com> Date: Fri, 15 Nov 2024 22:52:33 +0200 Subject: [PATCH 5/5] Delete .cargo/config.toml --- .cargo/config.toml | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index ccae65c..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -# We set it for tests -# From https://github.com/CosmosContracts/juno/blob/32568dba828ff7783aea8cb5bb4b8b5832888255/docker/test-user.env#L2 -[env] -ABSTRACT_CREATOR = "clip hire initial neck maid actor venue client foam budget lock catalog sweet steak waste crater broccoli pipe steak sister coyote moment obvious choose"