terra: fix tax calculation on withdraw_tokens

This commit is contained in:
Evan Gray 2021-12-23 16:20:23 +00:00 committed by Evan Gray
parent 713b834f20
commit 98cb787512
2 changed files with 10 additions and 8 deletions

View File

@ -633,7 +633,7 @@ describe("Integration Tests", () => {
{
deposit_tokens: {},
},
{ ["uluna"]: "1" }
{ uusd: "900000087654321" }
);
const feeEstimate = await lcd.tx.estimateFee(
wallet.key.accAddress,
@ -662,10 +662,10 @@ describe("Integration Tests", () => {
{
initiate_transfer: {
asset: {
amount: "10000",
amount: "5900000087654321",
info: {
native_token: {
denom: "uluna",
denom: "uusd",
},
},
},
@ -696,7 +696,7 @@ describe("Integration Tests", () => {
withdraw_tokens: {
asset: {
native_token: {
denom: "uluna",
denom: "uusd",
},
},
},

View File

@ -295,19 +295,21 @@ fn withdraw_tokens(
let mut messages: Vec<CosmosMsg> = vec![];
if let AssetInfo::NativeToken { denom } = data {
let deposit_key = format!("{}:{}", info.sender, denom);
let mut deposited_amount: u128 = 0;
bridge_deposit(deps.storage).update(
deposit_key.as_bytes(),
|current: Option<Uint128>| match current {
Some(v) => {
messages.push(CosmosMsg::Bank(BankMsg::Send {
to_address: info.sender.to_string(),
amount: vec![coin(v.u128(), &denom)],
}));
deposited_amount = v.u128();
Ok(Uint128::new(0))
}
None => Err(StdError::generic_err("no deposit found to withdraw")),
},
)?;
messages.push(CosmosMsg::Bank(BankMsg::Send {
to_address: info.sender.to_string(),
amount: coins_after_tax(deps, vec![coin(deposited_amount, &denom)])?,
}));
}
Ok(Response::new()