Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: do not deduct tax in ibc token #16

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
80 changes: 77 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/terraswap_factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
4 changes: 2 additions & 2 deletions contracts/terraswap_pair/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion contracts/terraswap_pair/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TerraQuery>,
Expand Down
4 changes: 2 additions & 2 deletions contracts/terraswap_router/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down
20 changes: 15 additions & 5 deletions contracts/terraswap_router/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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}",
)));
}

Expand Down Expand Up @@ -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<Response> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
pub fn migrate(
deps: DepsMut<TerraQuery>,
_env: Env,
_msg: MigrateMsg,
) -> StdResult<Response<TerraMsg>> {
migrate_version(
deps,
TARGET_CONTRACT_VERSION,
CONTRACT_NAME,
CONTRACT_VERSION,
)?;

Ok(Response::default())
}
9 changes: 9 additions & 0 deletions contracts/terraswap_router/src/querier.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use classic_terraswap::asset::IBC_REX;
use cosmwasm_std::{Decimal, Decimal256, QuerierWrapper, StdResult, Uint128, Uint256};
use std::ops::Mul;

Expand All @@ -10,6 +11,10 @@ pub fn compute_tax(
amount: Uint128,
denom: String,
) -> StdResult<Uint128> {
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;
Expand All @@ -27,6 +32,10 @@ pub fn compute_reverse_tax(
amount: Uint128,
denom: String,
) -> StdResult<Uint128> {
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;
Expand Down
2 changes: 1 addition & 1 deletion contracts/terraswap_token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/classic_terraswap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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" }
Expand Down
25 changes: 23 additions & 2 deletions packages/classic_terraswap/src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use lazy_regex::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt;
Expand All @@ -10,6 +11,8 @@ use cosmwasm_std::{
};
use cw20::Cw20ExecuteMsg;

pub static IBC_REX: Lazy<Regex> = lazy_regex!("^ibc/[A-F0-9]{64}$");

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct Asset {
pub info: AssetInfo,
Expand All @@ -32,6 +35,10 @@ impl Asset {
pub fn compute_tax(&self, querier: &QuerierWrapper<TerraQuery>) -> StdResult<Uint128> {
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;
Expand Down Expand Up @@ -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}"),
}
}
}
Expand All @@ -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<TerraQuery>,
Expand Down
12 changes: 5 additions & 7 deletions packages/classic_terraswap/src/mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}
Expand Down Expand Up @@ -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(),
})
}
Expand Down Expand Up @@ -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(),
})
}
Expand Down
Loading
Loading