diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a726cd..b240f79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.8.0 + +* [39d869](https://github.com/terraswap/classic-terraswap/pull/16/commits/39d869e9056d92a3094b1995b032e93fe7068ddb) Do not deduct tax in ibc token + # 2.7.0 * [a189de](https://github.com/terraswap/classic-terraswap/pull/15/commits/a189de88440f5a26e4104aa950fddbcb259a457e) Prevention of share calculation overflow diff --git a/Cargo.lock b/Cargo.lock index ebf4614..d1171bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,6 +13,15 @@ dependencies = [ "version_check", ] +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -93,7 +102,7 @@ dependencies = [ [[package]] name = "classic_terraswap" -version = "2.7.0" +version = "2.8.0" dependencies = [ "classic-bindings", "cosmwasm-schema", @@ -101,6 +110,7 @@ dependencies = [ "cosmwasm-storage", "cw2", "cw20", + "lazy-regex", "protobuf", "schemars", "serde", @@ -514,12 +524,41 @@ dependencies = [ "sha2 0.10.6", ] +[[package]] +name = "lazy-regex" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e723bd417b2df60a0f6a2b6825f297ea04b245d4ba52b5a22cb679bdf58b05fa" +dependencies = [ + "lazy-regex-proc_macros", + "once_cell", + "regex-lite", +] + +[[package]] +name = "lazy-regex-proc_macros" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0a1d9139f0ee2e862e08a9c5d0ba0470f2aa21cd1e1aa1b1562f83116c725f" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn 2.0.18", +] + [[package]] name = "libc" version = "0.2.146" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + [[package]] name = "num-traits" version = "0.2.12" @@ -593,6 +632,41 @@ dependencies = [ "getrandom", ] +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-lite" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b661b2f27137bdbc16f00eda72866a92bb28af1753ffbd56744fb6e2e9cd8e" + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "rfc6979" version = "0.3.1" @@ -802,7 +876,7 @@ dependencies = [ [[package]] name = "terraswap-pair" -version = "0.2.0" +version = "0.3.0" dependencies = [ "classic-bindings", "classic_terraswap", @@ -821,7 +895,7 @@ dependencies = [ [[package]] name = "terraswap-router" -version = "0.1.0" +version = "0.2.0" dependencies = [ "classic-bindings", "classic_terraswap", diff --git a/contracts/terraswap_factory/Cargo.toml b/contracts/terraswap_factory/Cargo.toml index f786cda..e493da0 100644 --- a/contracts/terraswap_factory/Cargo.toml +++ b/contracts/terraswap_factory/Cargo.toml @@ -42,7 +42,7 @@ cw-storage-plus = { version = "1.0.0" } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } protobuf = { version = "2", features = ["with-bytes"] } -classic_terraswap = { path = "../../packages/classic_terraswap", default-features = false, version = "2.7.0"} +classic_terraswap = { path = "../../packages/classic_terraswap", default-features = false, version = "2.8.0"} [dev-dependencies] cosmwasm-schema = { version = "1.0.0"} diff --git a/contracts/terraswap_pair/Cargo.toml b/contracts/terraswap_pair/Cargo.toml index 50bebe8..04e38e7 100644 --- a/contracts/terraswap_pair/Cargo.toml +++ b/contracts/terraswap_pair/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "terraswap-pair" -version = "0.2.0" +version = "0.3.0" authors = ["Terraform Labs, PTE.", "DELIGHT LABS"] edition = "2021" description = "A Terraswap pair contract" @@ -44,7 +44,7 @@ serde = { version = "1.0.103", default-features = false, features = ["derive"] } thiserror = { version = "1.0.20" } protobuf = { version = "2", features = ["with-bytes"] } classic-bindings = { version = "0.1.1" } -classic_terraswap = { path = "../../packages/classic_terraswap", default-features = false, version = "2.7.0"} +classic_terraswap = { path = "../../packages/classic_terraswap", default-features = false, version = "2.8.0"} [dev-dependencies] cosmwasm-schema = { version = "1.0.0" } diff --git a/contracts/terraswap_pair/src/contract.rs b/contracts/terraswap_pair/src/contract.rs index fdc293c..de5794a 100644 --- a/contracts/terraswap_pair/src/contract.rs +++ b/contracts/terraswap_pair/src/contract.rs @@ -868,7 +868,7 @@ pub fn assert_minimum_assets( Ok(()) } -const TARGET_CONTRACT_VERSION: &str = "0.1.1"; +const TARGET_CONTRACT_VERSION: &str = "0.2.0"; #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate( deps: DepsMut, diff --git a/contracts/terraswap_router/Cargo.toml b/contracts/terraswap_router/Cargo.toml index a10f118..88c4852 100644 --- a/contracts/terraswap_router/Cargo.toml +++ b/contracts/terraswap_router/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "terraswap-router" -version = "0.1.0" +version = "0.2.0" authors = ["Terraform Labs, PTE.", "DELIGHT LABS"] edition = "2021" description = "A Terraswap router contract - provides multi-step operations to facilitate single sign operation" @@ -37,7 +37,7 @@ backtraces = ["cosmwasm-std/backtraces"] cw2 = { version = "0.14.0" } cw20 = { version = "0.14.0" } cosmwasm-std = { version = "1.0.0" } -classic_terraswap = { path = "../../packages/classic_terraswap", version = "2.7.0" } +classic_terraswap = { path = "../../packages/classic_terraswap", version = "2.8.0" } classic-bindings = { version = "0.1.1" } cw-storage-plus = { version = "1.0.0"} integer-sqrt = "0.1.5" diff --git a/contracts/terraswap_router/src/contract.rs b/contracts/terraswap_router/src/contract.rs index 555a4d3..ecc7cce 100644 --- a/contracts/terraswap_router/src/contract.rs +++ b/contracts/terraswap_router/src/contract.rs @@ -20,7 +20,7 @@ use classic_terraswap::router::{ ConfigResponse, Cw20HookMsg, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SimulateSwapOperationsResponse, SwapOperation, }; -use classic_terraswap::util::assert_deadline; +use classic_terraswap::util::{assert_deadline, migrate_version}; use cw20::Cw20ReceiveMsg; use std::collections::HashMap; @@ -216,8 +216,7 @@ fn assert_minimum_receive( if swap_amount < minium_receive { return Err(StdError::generic_err(format!( - "assertion failed; minimum receive amount: {}, swap amount: {}", - minium_receive, swap_amount + "assertion failed; minimum receive amount: {minium_receive}, swap amount: {swap_amount}", ))); } @@ -638,8 +637,19 @@ fn test_invalid_operations() { .is_err()); } +const TARGET_CONTRACT_VERSION: &str = "0.1.0"; #[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult { - set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; +pub fn migrate( + deps: DepsMut, + _env: Env, + _msg: MigrateMsg, +) -> StdResult> { + migrate_version( + deps, + TARGET_CONTRACT_VERSION, + CONTRACT_NAME, + CONTRACT_VERSION, + )?; + Ok(Response::default()) } diff --git a/contracts/terraswap_router/src/querier.rs b/contracts/terraswap_router/src/querier.rs index b70885f..7a3fb93 100644 --- a/contracts/terraswap_router/src/querier.rs +++ b/contracts/terraswap_router/src/querier.rs @@ -1,3 +1,4 @@ +use classic_terraswap::asset::IBC_REX; use cosmwasm_std::{Decimal, Decimal256, QuerierWrapper, StdResult, Uint128, Uint256}; use std::ops::Mul; @@ -10,6 +11,10 @@ pub fn compute_tax( amount: Uint128, denom: String, ) -> StdResult { + if IBC_REX.is_match(&denom) { + return Ok(Uint128::zero()); + } + let terra_querier = TerraQuerier::new(querier); let tax_rate: Decimal = (terra_querier.query_tax_rate()?).rate; let tax_cap: Uint128 = (terra_querier.query_tax_cap(denom)?).cap; @@ -27,6 +32,10 @@ pub fn compute_reverse_tax( amount: Uint128, denom: String, ) -> StdResult { + if IBC_REX.is_match(&denom) { + return Ok(Uint128::zero()); + } + let terra_querier = TerraQuerier::new(querier); let tax_rate: Decimal = (terra_querier.query_tax_rate()?).rate; let tax_cap: Uint128 = (terra_querier.query_tax_cap(denom)?).cap; diff --git a/contracts/terraswap_token/Cargo.toml b/contracts/terraswap_token/Cargo.toml index 85b8ba6..d044ec1 100644 --- a/contracts/terraswap_token/Cargo.toml +++ b/contracts/terraswap_token/Cargo.toml @@ -26,7 +26,7 @@ cosmwasm-std = { version = "1.0.0" } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } thiserror = { version = "1.0.20" } -classic_terraswap = { path = "../../packages/classic_terraswap", version = "2.7.0" } +classic_terraswap = { path = "../../packages/classic_terraswap", version = "2.8.0" } [dev-dependencies] # we only need to enable this if we use integration tests diff --git a/packages/classic_terraswap/Cargo.toml b/packages/classic_terraswap/Cargo.toml index 59dd1b1..79e0a8a 100644 --- a/packages/classic_terraswap/Cargo.toml +++ b/packages/classic_terraswap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "classic_terraswap" -version = "2.7.0" +version = "2.8.0" authors = ["Terraform Labs, PTE.", "DELIGHT LABS"] edition = "2021" description = "Common terraswap types" @@ -25,6 +25,7 @@ cosmwasm-std = { version = "1.0.0" } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } protobuf = { version = "2", features = ["with-bytes"] } +lazy-regex = {version = "3.0.2", default-features = false, features = ["lite"]} [dev-dependencies] cosmwasm-schema = { version = "1.0.0" } diff --git a/packages/classic_terraswap/src/asset.rs b/packages/classic_terraswap/src/asset.rs index 9b1721e..fdd3266 100644 --- a/packages/classic_terraswap/src/asset.rs +++ b/packages/classic_terraswap/src/asset.rs @@ -1,3 +1,4 @@ +use lazy_regex::*; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::fmt; @@ -10,6 +11,8 @@ use cosmwasm_std::{ }; use cw20::Cw20ExecuteMsg; +pub static IBC_REX: Lazy = lazy_regex!("^ibc/[A-F0-9]{64}$"); + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct Asset { pub info: AssetInfo, @@ -32,6 +35,10 @@ impl Asset { pub fn compute_tax(&self, querier: &QuerierWrapper) -> StdResult { let amount = self.amount; if let AssetInfo::NativeToken { denom } = &self.info { + if self.info.is_ibc_token() { + return Ok(Uint128::zero()); + } + let terra_querier = TerraQuerier::new(querier); let tax_rate: Decimal = (terra_querier.query_tax_rate()?).rate; let tax_cap: Uint128 = (terra_querier.query_tax_cap(denom.to_string())?).cap; @@ -140,8 +147,8 @@ pub enum AssetInfo { impl fmt::Display for AssetInfo { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - AssetInfo::NativeToken { denom } => write!(f, "{}", denom), - AssetInfo::Token { contract_addr } => write!(f, "{}", contract_addr), + AssetInfo::NativeToken { denom } => write!(f, "{denom}"), + AssetInfo::Token { contract_addr } => write!(f, "{contract_addr}"), } } } @@ -164,6 +171,20 @@ impl AssetInfo { AssetInfo::Token { .. } => false, } } + + pub fn is_ibc_token(&self) -> bool { + match self { + AssetInfo::NativeToken { denom } => { + if IBC_REX.is_match(denom) { + return true; + } + + false + } + AssetInfo::Token { .. } => false, + } + } + pub fn query_pool( &self, querier: &QuerierWrapper, diff --git a/packages/classic_terraswap/src/mock_querier.rs b/packages/classic_terraswap/src/mock_querier.rs index 5733074..2228e5e 100644 --- a/packages/classic_terraswap/src/mock_querier.rs +++ b/packages/classic_terraswap/src/mock_querier.rs @@ -135,7 +135,7 @@ impl Querier for WasmMockQuerier { Ok(v) => v, Err(e) => { return SystemResult::Err(SystemError::InvalidRequest { - error: format!("Parsing query request: {}", e), + error: format!("Parsing query request: {e}"), request: bin_request.into(), }) } @@ -248,9 +248,8 @@ impl WasmMockQuerier { None => { return SystemResult::Err(SystemError::InvalidRequest { error: format!( - "No balance info exists for the contract {}", - contract_addr - ), + "No balance info exists for the contract {contract_addr}" + ), request: msg.as_slice().into(), }) } @@ -279,9 +278,8 @@ impl WasmMockQuerier { None => { return SystemResult::Err(SystemError::InvalidRequest { error: format!( - "No balance info exists for the contract {}", - contract_addr - ), + "No balance info exists for the contract {contract_addr}" + ), request: msg.as_slice().into(), }) } diff --git a/packages/classic_terraswap/src/testing.rs b/packages/classic_terraswap/src/testing.rs index a8c0169..55a90c1 100644 --- a/packages/classic_terraswap/src/testing.rs +++ b/packages/classic_terraswap/src/testing.rs @@ -107,6 +107,12 @@ fn test_asset_info() { let native_token_info: AssetInfo = AssetInfo::NativeToken { denom: "uusd".to_string(), }; + let ibc_token_info: AssetInfo = AssetInfo::NativeToken { + denom: "ibc/7F8A299575858D452509369851605DCD9D4595EB967E805388347FD54852AA62".to_string(), + }; + let invaild_ibc_token_info: AssetInfo = AssetInfo::NativeToken { + denom: "ibc/7".to_string(), + }; assert!(!token_info.equal(&native_token_info)); @@ -120,6 +126,12 @@ fn test_asset_info() { assert!(native_token_info.is_native_token()); assert!(!token_info.is_native_token()); + assert!(ibc_token_info.is_native_token()); + + assert!(ibc_token_info.is_ibc_token()); + assert!(!invaild_ibc_token_info.is_ibc_token()); + assert!(!native_token_info.is_ibc_token()); + assert!(!native_token_info.is_ibc_token()); let mut deps = mock_dependencies(&[Coin { denom: "uusd".to_string(),