From 808dc27a81218ab205285e463bf53204f914135c Mon Sep 17 00:00:00 2001 From: lubkoll <11710767+lubkoll@users.noreply.github.com> Date: Tue, 27 Aug 2024 00:38:11 +0200 Subject: [PATCH] Remove authz messages (#823) --- .../contracts/cl-vault/schema/cl-vault.json | 73 ----- .../cl-vault/schema/raw/execute.json | 73 ----- .../contracts/cl-vault/src/contract.rs | 12 - .../osmosis/contracts/cl-vault/src/msg.rs | 13 +- .../cl-vault/tests/test-tube/authz.rs | 273 ------------------ .../cl-vault/tests/test-tube/integration.rs | 1 - 6 files changed, 1 insertion(+), 444 deletions(-) delete mode 100644 smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/authz.rs 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 839779b11..31409d9dd 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/schema/cl-vault.json +++ b/smart-contracts/osmosis/contracts/cl-vault/schema/cl-vault.json @@ -377,66 +377,6 @@ } ] }, - "AuthzExtension": { - "description": "Extension messages for Authz. This interface basically reexports certain vault functionality but sets recipient forcibly to None", - "oneOf": [ - { - "type": "object", - "required": [ - "exact_deposit" - ], - "properties": { - "exact_deposit": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "any_deposit" - ], - "properties": { - "any_deposit": { - "type": "object", - "required": [ - "max_slippage" - ], - "properties": { - "max_slippage": { - "$ref": "#/definitions/Decimal" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "redeem" - ], - "properties": { - "redeem": { - "type": "object", - "required": [ - "amount" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, "Decimal": { "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", "type": "string" @@ -457,19 +397,6 @@ }, "additionalProperties": false }, - { - "description": "An interface of certain vault interaction with forced values for authz", - "type": "object", - "required": [ - "authz" - ], - "properties": { - "authz": { - "$ref": "#/definitions/AuthzExtension" - } - }, - "additionalProperties": false - }, { "description": "Rebalance our liquidity range based on an off-chain message given to us by RANGE_ADMIN", "type": "object", 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 99228ac70..cc4f7079e 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/schema/raw/execute.json +++ b/smart-contracts/osmosis/contracts/cl-vault/schema/raw/execute.json @@ -268,66 +268,6 @@ } ] }, - "AuthzExtension": { - "description": "Extension messages for Authz. This interface basically reexports certain vault functionality but sets recipient forcibly to None", - "oneOf": [ - { - "type": "object", - "required": [ - "exact_deposit" - ], - "properties": { - "exact_deposit": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "any_deposit" - ], - "properties": { - "any_deposit": { - "type": "object", - "required": [ - "max_slippage" - ], - "properties": { - "max_slippage": { - "$ref": "#/definitions/Decimal" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "redeem" - ], - "properties": { - "redeem": { - "type": "object", - "required": [ - "amount" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, "Decimal": { "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", "type": "string" @@ -348,19 +288,6 @@ }, "additionalProperties": false }, - { - "description": "An interface of certain vault interaction with forced values for authz", - "type": "object", - "required": [ - "authz" - ], - "properties": { - "authz": { - "$ref": "#/definitions/AuthzExtension" - } - }, - "additionalProperties": false - }, { "description": "Rebalance our liquidity range based on an off-chain message given to us by RANGE_ADMIN", "type": "object", diff --git a/smart-contracts/osmosis/contracts/cl-vault/src/contract.rs b/smart-contracts/osmosis/contracts/cl-vault/src/contract.rs index 2794d764e..67b8d339a 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/contract.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/contract.rs @@ -82,18 +82,6 @@ pub fn execute( crate::msg::ExtensionExecuteMsg::Admin(admin_msg) => { execute_admin(deps, info, admin_msg) } - crate::msg::ExtensionExecuteMsg::Authz(msg) => match msg { - crate::msg::AuthzExtension::ExactDeposit {} => { - execute_exact_deposit(deps, env, info, None) - } - crate::msg::AuthzExtension::AnyDeposit { max_slippage } => { - execute_any_deposit(deps, env, info, None, max_slippage) - } - crate::msg::AuthzExtension::Redeem { amount } => prepend_claim_msg( - &env, - execute_withdraw(deps, &env, info, None, amount.into())?, - ), - }, crate::msg::ExtensionExecuteMsg::Merge(msg) => { execute_merge_position(deps, env, info, msg) } diff --git a/smart-contracts/osmosis/contracts/cl-vault/src/msg.rs b/smart-contracts/osmosis/contracts/cl-vault/src/msg.rs index 1d9dfec45..ce323ccc2 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/msg.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/msg.rs @@ -1,5 +1,5 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Addr, Decimal, Uint128}; +use cosmwasm_std::{Addr, Decimal}; use cw_vault_multi_standard::{VaultStandardExecuteMsg, VaultStandardQueryMsg}; use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute; @@ -15,8 +15,6 @@ use crate::state::{Metadata, VaultConfig}; pub enum ExtensionExecuteMsg { /// Execute Admin operations. Admin(AdminExtensionExecuteMsg), - /// An interface of certain vault interaction with forced values for authz - Authz(AuthzExtension), /// Rebalance our liquidity range based on an off-chain message /// given to us by RANGE_ADMIN ModifyRange(ModifyRangeMsg), @@ -33,15 +31,6 @@ pub enum ExtensionExecuteMsg { }, } -/// Extension messages for Authz. This interface basically reexports certain vault functionality -/// but sets recipient forcibly to None -#[cw_serde] -pub enum AuthzExtension { - ExactDeposit {}, - AnyDeposit { max_slippage: Decimal }, - Redeem { amount: Uint128 }, -} - /// Apollo extension messages define functionality that is part of all apollo /// vaults, but not part of the standard. #[cw_serde] 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 deleted file mode 100644 index 4a6cbfa11..000000000 --- a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/authz.rs +++ /dev/null @@ -1,273 +0,0 @@ -use crate::setup::{ - fixture_default, fixture_dex_router, get_amount_from_denom, DENOM_BASE, DENOM_QUOTE, - PERFORMANCE_FEE_DEFAULT, -}; - -use cl_vault::{ - msg::{ - AuthzExtension, ExecuteMsg, ExtensionExecuteMsg, ExtensionQueryMsg, QueryMsg, - UserBalanceQueryMsg, - }, - query::UserSharesBalanceResponse, -}; -use cosmwasm_std::{assert_approx_eq, Coin, Decimal}; -use osmosis_test_tube::{Account, Module, Wasm}; - -const INITIAL_BALANCE_AMOUNT: u128 = 1_000_000_000_000_000_000_000_000_000_000; - -// check that the authz interface returns the exact same response as -// the regular interface. Thus the actual authz functionality is out of -// scope but contract functionality is in scope here - -#[test] -fn exact_deposit_withdraw_equal() { - let (app, contract_address, ..) = fixture_dex_router(PERFORMANCE_FEE_DEFAULT); - let wasm = Wasm::new(&app); - - let alice = app - .init_account(&[ - Coin::new(INITIAL_BALANCE_AMOUNT, "uosmo"), - Coin::new(INITIAL_BALANCE_AMOUNT, DENOM_BASE), - Coin::new(INITIAL_BALANCE_AMOUNT, DENOM_QUOTE), - ]) - .unwrap(); - - let deposit0 = 1_000_000_000_000_000; - let deposit1 = 1_000_000_000_000_000; - - let deposit_response = wasm - .execute( - contract_address.as_str(), - &ExecuteMsg::ExactDeposit { recipient: None }, - &[ - Coin::new(deposit0, DENOM_BASE), - Coin::new(deposit1, DENOM_QUOTE), - ], - &alice, - ) - .unwrap(); - - let authz_deposit_response = wasm - .execute( - contract_address.as_str(), - &ExecuteMsg::VaultExtension(ExtensionExecuteMsg::Authz( - AuthzExtension::ExactDeposit {}, - )), - &[ - Coin::new(deposit0, DENOM_BASE), - Coin::new(deposit1, DENOM_QUOTE), - ], - &alice, - ) - .unwrap(); - - assert_eq!(deposit_response.data, authz_deposit_response.data); - - assert_eq!( - deposit_response.events.iter().find(|e| e.ty == *"wasm"), - authz_deposit_response - .events - .iter() - .find(|e| e.ty == *"wasm") - ); - - let shares: UserSharesBalanceResponse = wasm - .query( - contract_address.as_str(), - &QueryMsg::VaultExtension(ExtensionQueryMsg::Balances( - UserBalanceQueryMsg::UserSharesBalance { - user: alice.address(), - }, - )), - ) - .unwrap(); - assert!(!shares.balance.is_zero()); - - let to_withdraw = shares.balance.u128() / 2; - - let withdraw_response = wasm - .execute( - contract_address.as_str(), - &ExecuteMsg::Redeem { - recipient: None, - amount: to_withdraw.into(), - }, - &[], - &alice, - ) - .unwrap(); - - let authz_withdraw_response = wasm - .execute( - contract_address.as_str(), - &ExecuteMsg::Redeem { - recipient: None, - amount: to_withdraw.into(), - }, - &[], - &alice, - ) - .unwrap(); - - assert_eq!(withdraw_response.data, authz_withdraw_response.data); - assert_eq!( - withdraw_response.events.iter().find(|e| e.ty == *"wasm"), - authz_withdraw_response - .events - .iter() - .find(|e| e.ty == *"wasm") - ); -} - -#[test] -fn any_deposit_withdraw_equal() { - let (app, contract_address, ..) = fixture_default(PERFORMANCE_FEE_DEFAULT); - let wasm = Wasm::new(&app); - - // Create Alice account - let alice = app - .init_account(&[ - Coin::new(INITIAL_BALANCE_AMOUNT, "uosmo"), - Coin::new(INITIAL_BALANCE_AMOUNT, DENOM_BASE), - ]) - .unwrap(); - - let deposit0 = 1_000_000_000_000_000; - - // Deposit - let deposit_response = wasm - .execute( - contract_address.as_str(), - &ExecuteMsg::AnyDeposit { - amount: deposit0.into(), - asset: DENOM_BASE.to_string(), - recipient: None, - max_slippage: Decimal::bps(900), - }, - &[Coin::new(deposit0, DENOM_BASE)], - &alice, - ) - .unwrap(); - // Deposit via AuthZ - let authz_deposit_response = wasm - .execute( - contract_address.as_str(), - &ExecuteMsg::VaultExtension(ExtensionExecuteMsg::Authz(AuthzExtension::AnyDeposit { - max_slippage: Decimal::bps(900), - })), - &[Coin::new(deposit0, DENOM_BASE)], - &alice, - ) - .unwrap(); - - // Assert deposits are equal - assert_eq!(deposit_response.data, authz_deposit_response.data); - let deposit_event = deposit_response - .events - .iter() - .find(|e| e.ty == *"wasm") - .unwrap(); - let authz_deposit_event = authz_deposit_response - .events - .iter() - .find(|e| e.ty == *"wasm") - .unwrap(); - // Assert events are equal - assert_eq!(deposit_event.ty, authz_deposit_event.ty); - assert_eq!( - deposit_event.attributes.len(), - authz_deposit_event.attributes.len() - ); - // We need to assert approx here as in the any_deposit case, - // depositing involve a swap that changes the pool's condition for the subsequent one. - for (attr1, attr2) in deposit_event - .attributes - .iter() - .zip(&authz_deposit_event.attributes) - { - if attr1.key == "token_in" || attr1.key == "token_out_min_amount" { - assert_approx_eq!( - get_amount_from_denom(&attr1.value), - get_amount_from_denom(&attr2.value), - "0.00001" - ); - } else { - assert_eq!(attr1, attr2); - } - } - - // Check the shares and compute the balance to withdraw - let shares: UserSharesBalanceResponse = wasm - .query( - contract_address.as_str(), - &QueryMsg::VaultExtension(ExtensionQueryMsg::Balances( - UserBalanceQueryMsg::UserSharesBalance { - user: alice.address(), - }, - )), - ) - .unwrap(); - assert!(!shares.balance.is_zero()); - let to_withdraw = shares.balance.u128() / 2; - - // Withdraw - let withdraw_response = wasm - .execute( - contract_address.as_str(), - &ExecuteMsg::Redeem { - recipient: None, - amount: to_withdraw.into(), - }, - &[], - &alice, - ) - .unwrap(); - // Withdraw via AuthZ - let authz_withdraw_response = wasm - .execute( - contract_address.as_str(), - &ExecuteMsg::Redeem { - recipient: None, - amount: to_withdraw.into(), - }, - &[], - &alice, - ) - .unwrap(); - - // Assert withdraws are equal - assert_eq!(withdraw_response.data, authz_withdraw_response.data); - let withdraw_event = withdraw_response - .events - .iter() - .find(|e| e.ty == *"wasm") - .unwrap(); - let authz_withdraw_event = authz_withdraw_response - .events - .iter() - .find(|e| e.ty == *"wasm") - .unwrap(); - // Assert events are equal - assert_eq!(withdraw_event.ty, authz_withdraw_event.ty); - assert_eq!( - withdraw_event.attributes.len(), - authz_withdraw_event.attributes.len() - ); - // We need to assert approx here as in the any_deposit case, - // depositing involve a swap that changes the pool's condition for the subsequent one. - for (attr1, attr2) in withdraw_event - .attributes - .iter() - .zip(&authz_withdraw_event.attributes) - { - if attr1.key == "liquidity_amount" { - assert_approx_eq!( - get_amount_from_denom(&attr1.value), - get_amount_from_denom(&attr2.value), - "0.000000000000000001" - ); - } else { - assert_eq!(attr1, attr2); - } - } -} diff --git a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/integration.rs b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/integration.rs index b2a12506b..4dffde690 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/integration.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/integration.rs @@ -2,7 +2,6 @@ mod setup; mod admin; mod any_deposit; -mod authz; mod autocompound; mod deposit_withdraw; mod initialize;