From 9c8768e30cd9f0df3999ef3070241c1f7dcff26c Mon Sep 17 00:00:00 2001 From: Jake Hartnell Date: Tue, 5 Dec 2023 17:09:04 -0800 Subject: [PATCH] Fix exit fees --- contracts/external/cw-abc/src/commands.rs | 15 ++++++++++----- .../cw-abc/src/test_tube/integration_tests.rs | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/contracts/external/cw-abc/src/commands.rs b/contracts/external/cw-abc/src/commands.rs index a54594f93..fad52f0eb 100644 --- a/contracts/external/cw-abc/src/commands.rs +++ b/contracts/external/cw-abc/src/commands.rs @@ -4,7 +4,6 @@ use cosmwasm_std::{ }; use cw_tokenfactory_issuer::msg::ExecuteMsg as IssuerExecuteMsg; use cw_utils::must_pay; -use rust_decimal::Decimal; use std::collections::HashSet; use std::ops::Deref; use token_bindings::{TokenFactoryMsg, TokenFactoryQuery}; @@ -184,8 +183,6 @@ pub fn execute_sell(deps: DepsMut, _env: Env, info: MessageIn }), ]; - let taxed_amount = calculate_exit_tax(deps.storage, burn_amount)?; - let mut curve_state = CURVE_STATE.load(deps.storage)?; let curve = curve_fn(curve_state.clone().decimals); @@ -204,18 +201,26 @@ pub fn execute_sell(deps: DepsMut, _env: Env, info: MessageIn .checked_sub(new_reserve) .map_err(StdError::overflow)?; + // Calculate the exit tax + let taxed_amount = calculate_exit_tax(deps.storage, released_reserve)?; + // Update the curve state curve_state.reserve = new_reserve; curve_state.funding += taxed_amount; CURVE_STATE.save(deps.storage, &curve_state)?; + // Calculate the amount of tokens to send to the sender + // Subtract the taxed amount from the released amount + let released = released_reserve + .checked_sub(taxed_amount) + .map_err(StdError::overflow)?; + // Now send the tokens to the sender and any fees to the DAO let mut send_msgs: Vec> = vec![CosmosMsg::::Bank(BankMsg::Send { to_address: info.sender.to_string(), amount: vec![Coin { - // TODO Subtract the taxed amount from the released reserve - amount: released_reserve, + amount: released, denom: curve_state.reserve_denom.clone(), }], })]; diff --git a/contracts/external/cw-abc/src/test_tube/integration_tests.rs b/contracts/external/cw-abc/src/test_tube/integration_tests.rs index 231baf92f..6b566af0d 100644 --- a/contracts/external/cw-abc/src/test_tube/integration_tests.rs +++ b/contracts/external/cw-abc/src/test_tube/integration_tests.rs @@ -125,7 +125,7 @@ fn test_happy_path() { CurveInfoResponse { reserve: Uint128::new(890), supply: Uint128::new(8900), - funding: Uint128::new(110), + funding: Uint128::new(101), spot_price: Decimal::percent(10u64), reserve_denom: RESERVE.to_string(), } @@ -159,7 +159,7 @@ fn test_happy_path() { contract_balance.balance, Some(Coin { denom: RESERVE.to_string(), - amount: "880".to_string(), + amount: "890".to_string(), }) );