From 877e26e6db890687302404d1482e769c1bc7db4d Mon Sep 17 00:00:00 2001 From: Lars Lubkoll <11710767+lubkoll@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:18:34 +0000 Subject: [PATCH] Use dex-router in test-tube tests --- .../contracts/cl-vault/schema/cl-vault.json | 24 ++++++++++-- .../cl-vault/schema/raw/execute.json | 8 +++- .../cl-vault/schema/raw/instantiate.json | 8 +++- .../cl-vault/schema/raw/migrate.json | 8 +++- .../cl-vault/tests/test-tube/any_deposit.rs | 8 ++-- .../cl-vault/tests/test-tube/authz.rs | 7 ++-- .../cl-vault/tests/test-tube/autocompound.rs | 14 ++----- .../cl-vault/tests/test-tube/initialize.rs | 7 ++-- .../cl-vault/tests/test-tube/range.rs | 38 ++++++++++--------- .../cl-vault/tests/test-tube/setup.rs | 28 +++++++++++--- 10 files changed, 100 insertions(+), 50 deletions(-) diff --git a/smart-contracts/osmosis/contracts/cl-vault/schema/cl-vault.json b/smart-contracts/osmosis/contracts/cl-vault/schema/cl-vault.json index baf3f2f48..839779b11 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/schema/cl-vault.json +++ b/smart-contracts/osmosis/contracts/cl-vault/schema/cl-vault.json @@ -78,7 +78,8 @@ "performance_fee", "swap_admin", "swap_max_slippage", - "treasury" + "treasury", + "twap_window_seconds" ], "properties": { "dex_router": { @@ -95,6 +96,11 @@ }, "treasury": { "$ref": "#/definitions/Addr" + }, + "twap_window_seconds": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false @@ -727,7 +733,8 @@ "performance_fee", "swap_admin", "swap_max_slippage", - "treasury" + "treasury", + "twap_window_seconds" ], "properties": { "dex_router": { @@ -744,6 +751,11 @@ }, "treasury": { "$ref": "#/definitions/Addr" + }, + "twap_window_seconds": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false @@ -1122,11 +1134,17 @@ "title": "MigrateMsg", "type": "object", "required": [ - "swap_admin" + "swap_admin", + "twap_window_seconds" ], "properties": { "swap_admin": { "$ref": "#/definitions/Addr" + }, + "twap_window_seconds": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false, diff --git a/smart-contracts/osmosis/contracts/cl-vault/schema/raw/execute.json b/smart-contracts/osmosis/contracts/cl-vault/schema/raw/execute.json index e060365a3..99228ac70 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/schema/raw/execute.json +++ b/smart-contracts/osmosis/contracts/cl-vault/schema/raw/execute.json @@ -624,7 +624,8 @@ "performance_fee", "swap_admin", "swap_max_slippage", - "treasury" + "treasury", + "twap_window_seconds" ], "properties": { "dex_router": { @@ -641,6 +642,11 @@ }, "treasury": { "$ref": "#/definitions/Addr" + }, + "twap_window_seconds": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false diff --git a/smart-contracts/osmosis/contracts/cl-vault/schema/raw/instantiate.json b/smart-contracts/osmosis/contracts/cl-vault/schema/raw/instantiate.json index a9fa051e6..36c9ca99d 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/schema/raw/instantiate.json +++ b/smart-contracts/osmosis/contracts/cl-vault/schema/raw/instantiate.json @@ -74,7 +74,8 @@ "performance_fee", "swap_admin", "swap_max_slippage", - "treasury" + "treasury", + "twap_window_seconds" ], "properties": { "dex_router": { @@ -91,6 +92,11 @@ }, "treasury": { "$ref": "#/definitions/Addr" + }, + "twap_window_seconds": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false diff --git a/smart-contracts/osmosis/contracts/cl-vault/schema/raw/migrate.json b/smart-contracts/osmosis/contracts/cl-vault/schema/raw/migrate.json index 718f06c36..b5ea62fd9 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/schema/raw/migrate.json +++ b/smart-contracts/osmosis/contracts/cl-vault/schema/raw/migrate.json @@ -3,11 +3,17 @@ "title": "MigrateMsg", "type": "object", "required": [ - "swap_admin" + "swap_admin", + "twap_window_seconds" ], "properties": { "swap_admin": { "$ref": "#/definitions/Addr" + }, + "twap_window_seconds": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false, diff --git a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/any_deposit.rs b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/any_deposit.rs index cfcd8a56a..d72d4f76f 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/any_deposit.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/any_deposit.rs @@ -1,6 +1,6 @@ use crate::setup::{ - fixture_dex_router, ACCOUNTS_INIT_BALANCE, ACCOUNTS_NUM, DENOM_BASE, DENOM_QUOTE, - MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT, + fixture_default, fixture_dex_router, ACCOUNTS_INIT_BALANCE, ACCOUNTS_NUM, DENOM_BASE, + DENOM_QUOTE, MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT, }; use cl_vault::msg::ExecuteMsg; @@ -25,8 +25,8 @@ fn test_any_deposit() { ]; for (amount_base, amount_quote) in test_cases { - let (app, contract_address, _dex_router_addr, vault_pool_id, _pools_ids, admin, _) = - fixture_dex_router(PERFORMANCE_FEE_DEFAULT); + let (app, contract_address, vault_pool_id, admin, ..) = + fixture_default(PERFORMANCE_FEE_DEFAULT); do_and_verify_any_deposit( app, diff --git a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/authz.rs b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/authz.rs index 16e45d422..4a6cbfa11 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/authz.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/authz.rs @@ -1,5 +1,6 @@ use crate::setup::{ - fixture_default, get_amount_from_denom, DENOM_BASE, DENOM_QUOTE, PERFORMANCE_FEE_DEFAULT, + fixture_default, fixture_dex_router, get_amount_from_denom, DENOM_BASE, DENOM_QUOTE, + PERFORMANCE_FEE_DEFAULT, }; use cl_vault::{ @@ -20,7 +21,7 @@ const INITIAL_BALANCE_AMOUNT: u128 = 1_000_000_000_000_000_000_000_000_000_000; #[test] fn exact_deposit_withdraw_equal() { - let (app, contract_address, _cl_pool_id, _admin, _) = fixture_default(PERFORMANCE_FEE_DEFAULT); + let (app, contract_address, ..) = fixture_dex_router(PERFORMANCE_FEE_DEFAULT); let wasm = Wasm::new(&app); let alice = app @@ -120,7 +121,7 @@ fn exact_deposit_withdraw_equal() { #[test] fn any_deposit_withdraw_equal() { - let (app, contract_address, _cl_pool_id, _admin, _) = fixture_default(PERFORMANCE_FEE_DEFAULT); + let (app, contract_address, ..) = fixture_default(PERFORMANCE_FEE_DEFAULT); let wasm = Wasm::new(&app); // Create Alice account diff --git a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/autocompound.rs b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/autocompound.rs index 3362ae309..02c9a2121 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/autocompound.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/autocompound.rs @@ -292,16 +292,10 @@ fn test_autocompound_with_rewards_swap_non_vault_funds() { token_in_denom: DENOM_REWARD.to_string(), pool_id_base: swap_pools_ids[1], pool_id_quote: swap_pools_ids[2], - forced_swap_route_base: Some(vec![ - SwapAmountInRoute { - pool_id: swap_pools_ids[2], - token_out_denom: DENOM_QUOTE.to_string(), - }, - SwapAmountInRoute { - pool_id: swap_pools_ids[1], - token_out_denom: DENOM_BASE.to_string(), - }, - ]), + forced_swap_route_base: Some(vec![SwapAmountInRoute { + pool_id: swap_pools_ids[1], + token_out_denom: DENOM_BASE.to_string(), + }]), forced_swap_route_quote: Some(vec![SwapAmountInRoute { pool_id: swap_pools_ids[2], token_out_denom: DENOM_QUOTE.to_string(), diff --git a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/initialize.rs b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/initialize.rs index a7ce84c66..b38d8c988 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/initialize.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/initialize.rs @@ -1,5 +1,5 @@ use crate::setup::{ - fixture_default, DENOM_BASE, DENOM_QUOTE, MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT, + fixture_dex_router, DENOM_BASE, DENOM_QUOTE, MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT, }; use cl_vault::{ @@ -25,8 +25,9 @@ use osmosis_test_tube::{ use std::str::FromStr; #[test] -fn fixture_default_works() { - let (app, contract_address, cl_pool_id, admin, _) = fixture_default(PERFORMANCE_FEE_DEFAULT); +fn fixture_dex_router_works() { + let (app, contract_address, _dex_router, cl_pool_id, _pools, admin, ..) = + fixture_dex_router(PERFORMANCE_FEE_DEFAULT); let wasm = Wasm::new(&app); let cl = ConcentratedLiquidity::new(&app); let tf = TokenFactory::new(&app); diff --git a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/range.rs b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/range.rs index e5e3f7aac..d3b572e66 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/range.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/range.rs @@ -1,6 +1,6 @@ use crate::setup::{ - fixture_default, fixture_dex_router, init_test_contract, ADMIN_BALANCE_AMOUNT, DENOM_BASE, - DENOM_QUOTE, MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT, + fixture_dex_router, init_test_contract, ADMIN_BALANCE_AMOUNT, DENOM_BASE, DENOM_QUOTE, + MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT, }; use cosmwasm_std::{coin, Coin, Decimal, Uint128}; @@ -32,7 +32,8 @@ const SWAP_SUCCESS_QUOTE_BALANCE_OFFSET: usize = 4; #[test] fn move_range_works() { - let (app, contract_address, _cl_pool_id, admin, _) = fixture_default(PERFORMANCE_FEE_DEFAULT); + let (app, contract_address, _dex_router, _cl_pool_id, _pools, admin, ..) = + fixture_dex_router(PERFORMANCE_FEE_DEFAULT); let wasm = Wasm::new(&app); let _before_position: PositionResponse = wasm @@ -88,7 +89,7 @@ fn move_range_works() { ); assert_eq!( event.attributes[pos + SWAP_SUCCESS_QUOTE_BALANCE_OFFSET].value, - "1201279ubtc" + "1221399ubtc" ); } } @@ -113,13 +114,13 @@ fn move_range_works() { .unwrap(); let pos_base: Coin = pos.asset0.unwrap().try_into().unwrap(); let pos_quote: Coin = pos.asset1.unwrap().try_into().unwrap(); - assert_eq!(pos_base, coin(762164u128, DENOM_BASE)); - assert_eq!(pos_quote, coin(1201279u128, DENOM_QUOTE)); + assert_eq!(pos_base, coin(774929u128, DENOM_BASE)); + assert_eq!(pos_quote, coin(1221399u128, DENOM_QUOTE)); } #[test] fn move_range_cw_dex_works() { - let (app, contract_address, _dex_router_addr, _vault_pool_id, _swap_pools_ids, admin, _) = + let (app, contract_address, _dex_router_addr, _vault_pool_id, _swap_pools_ids, admin, ..) = fixture_dex_router(PERFORMANCE_FEE_DEFAULT); let wasm = Wasm::new(&app); @@ -171,7 +172,7 @@ fn move_range_cw_dex_works() { if let Some(pos) = pos { assert_eq!( event.attributes[pos + SWAP_SUCCESS_BASE_BALANCE_OFFSET].value, - "1899998uatom" + "1989999uatom" ); assert_eq!( event.attributes[pos + SWAP_SUCCESS_QUOTE_BALANCE_OFFSET].value, @@ -200,13 +201,13 @@ fn move_range_cw_dex_works() { .unwrap(); let pos_base: Coin = pos.asset0.unwrap().try_into().unwrap(); let pos_quote: Coin = pos.asset1.unwrap().try_into().unwrap(); - assert_eq!(pos_base, coin(1899998u128, DENOM_BASE)); + assert_eq!(pos_base, coin(1989999u128, DENOM_BASE)); assert_eq!(pos_quote, coin(0u128, DENOM_QUOTE)); } #[test] fn move_range_cw_dex_works_forced_swap_route() { - let (app, contract_address, _dex_router_addr, vault_pool_id, _swap_pools_ids, admin, _) = + let (app, contract_address, _dex_router_addr, vault_pool_id, _swap_pools_ids, admin, ..) = fixture_dex_router(PERFORMANCE_FEE_DEFAULT); let wasm = Wasm::new(&app); @@ -266,7 +267,7 @@ fn move_range_cw_dex_works_forced_swap_route() { if let Some(pos) = pos { assert_eq!( event.attributes[pos + SWAP_SUCCESS_BASE_BALANCE_OFFSET].value, - "1899998uatom" + "1989999uatom" ); assert_eq!( event.attributes[pos + SWAP_SUCCESS_QUOTE_BALANCE_OFFSET].value, @@ -294,13 +295,14 @@ fn move_range_cw_dex_works_forced_swap_route() { .unwrap(); let pos_base: Coin = pos.asset0.unwrap().try_into().unwrap(); let pos_quote: Coin = pos.asset1.unwrap().try_into().unwrap(); - assert_eq!(pos_base, coin(1899998u128, DENOM_BASE)); + assert_eq!(pos_base, coin(1989999u128, DENOM_BASE)); assert_eq!(pos_quote, coin(0u128, DENOM_QUOTE)); } #[test] fn move_range_single_side_works() { - let (app, contract_address, _cl_pool_id, admin, _) = fixture_default(PERFORMANCE_FEE_DEFAULT); + let (app, contract_address, _dex_router_addr, _vault_pool_id, _swap_pools_ids, admin, ..) = + fixture_dex_router(PERFORMANCE_FEE_DEFAULT); let wasm = Wasm::new(&app); let response = wasm @@ -343,7 +345,7 @@ fn move_range_single_side_works() { if let Some(pos) = pos { assert_eq!( event.attributes[pos + SWAP_SUCCESS_BASE_BALANCE_OFFSET].value, - "1899998uatom" + "1989999uatom" ); assert_eq!( event.attributes[pos + SWAP_SUCCESS_QUOTE_BALANCE_OFFSET].value, @@ -377,11 +379,11 @@ fn move_range_single_side_works() { if let Some(pos) = pos { assert_eq!( event.attributes[pos + DO_SWAP_DEPOSIT_TOKEN_IN_OFFSET].value, - "1899997uatom" + "1989998uatom" ); assert_eq!( event.attributes[pos + DO_SWAP_DEPOSIT_MIN_OUT_OFFSET].value, - "1709997" + "1790998" ); } @@ -396,7 +398,7 @@ fn move_range_single_side_works() { ); assert_eq!( event.attributes[pos + SWAP_SUCCESS_QUOTE_BALANCE_OFFSET].value, - "1709997ubtc" + "1970100ubtc" ); } } @@ -422,7 +424,7 @@ fn move_range_single_side_works() { let pos_base: Coin = pos.asset0.unwrap().try_into().unwrap(); let pos_quote: Coin = pos.asset1.unwrap().try_into().unwrap(); assert_eq!(pos_base, coin(0u128, DENOM_BASE)); - assert_eq!(pos_quote, coin(1709997u128, DENOM_QUOTE)); + assert_eq!(pos_quote, coin(1970100u128, DENOM_QUOTE)); } /* diff --git a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/setup.rs b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/setup.rs index 2117832b9..129ba21f0 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/setup.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/setup.rs @@ -1,6 +1,10 @@ #![allow(dead_code)] -use cl_vault::{helpers::generic::sort_tokens, msg::InstantiateMsg, state::VaultConfig}; +use cl_vault::{ + helpers::generic::sort_tokens, + msg::{AdminExtensionExecuteMsg, ExtensionExecuteMsg, InstantiateMsg}, + state::VaultConfig, +}; use cosmwasm_std::{coin, Addr, Attribute, Coin, Decimal, Uint128}; use dex_router_osmosis::msg::{ExecuteMsg as DexExecuteMsg, InstantiateMsg as DexInstantiate}; use osmosis_std::types::{ @@ -416,7 +420,7 @@ fn init_test_contract_with_dex_router_and_swap_pools( &DexInstantiate {}, Some(admin.address().as_str()), Some("dex-router"), - sort_tokens(vec![]).as_ref(), + &[], &admin, ) .unwrap(); @@ -424,7 +428,7 @@ fn init_test_contract_with_dex_router_and_swap_pools( // Here we pass only the 3x swap LP pools, not the Vault CL pool id 1 set_dex_router_paths( &app, - contract_dex_router.data.address.to_string(), + &contract_dex_router.data.address, &lp_pools, &pools_coins, &admin, @@ -463,6 +467,18 @@ fn init_test_contract_with_dex_router_and_swap_pools( ) .unwrap(); + wasm.execute( + &contract_cl.data.address, + &cw_vault_multi_standard::VaultStandardExecuteMsg::VaultExtension( + ExtensionExecuteMsg::Admin(AdminExtensionExecuteMsg::UpdateDexRouter { + address: Some(contract_dex_router.data.address.clone()), + }), + ), + &[], + &admin, + ) + .unwrap(); + ( app, Addr::unchecked(contract_cl.data.address), @@ -476,7 +492,7 @@ fn init_test_contract_with_dex_router_and_swap_pools( fn set_dex_router_paths( app: &OsmosisTestApp, - dex_router: String, + dex_router: &str, pools: &[u64], pools_coins: &[Vec], admin: &SigningAccount, @@ -487,14 +503,14 @@ fn set_dex_router_paths( // Set Dex Router contract paths for (index, pool_id) in pools.iter().enumerate() { wasm.execute( - &dex_router, + dex_router, &DexExecuteMsg::SetPath { offer_denom: pools_coins[index][0].denom.to_string(), ask_denom: pools_coins[index][1].denom.to_string(), path: vec![*pool_id], bidirectional: true, }, - vec![].as_ref(), + &[], admin, ) .unwrap();