Skip to content

Commit

Permalink
Fix exit fees
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHartnell authored and Jake Hartnell committed Mar 26, 2024
1 parent 4080c01 commit 9c8768e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions contracts/external/cw-abc/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -184,8 +183,6 @@ pub fn execute_sell(deps: DepsMut<TokenFactoryQuery>, _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);

Expand All @@ -204,18 +201,26 @@ pub fn execute_sell(deps: DepsMut<TokenFactoryQuery>, _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<CosmosMsg<TokenFactoryMsg>> =
vec![CosmosMsg::<TokenFactoryMsg>::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(),
}],
})];
Expand Down
4 changes: 2 additions & 2 deletions contracts/external/cw-abc/src/test_tube/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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(),
})
);

Expand Down

0 comments on commit 9c8768e

Please sign in to comment.