Skip to content

Commit

Permalink
fix: item 5 - return_dust only tickets are below a hard-coded thresho…
Browse files Browse the repository at this point in the history
…ld (2)
  • Loading branch information
PFC-developer committed Sep 22, 2024
1 parent 8cfe54c commit caa5449
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
23 changes: 18 additions & 5 deletions contracts/treasurechest-contract/src/executions.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::{ops::Mul, str::FromStr};
use std::collections::HashMap;
use std::ops::Sub;

const DEFAULT_SIZE:u32 = 20;
const MIN_TICKETS:u128 = 2;

use cosmwasm_std::{
Addr, BankMsg, Coin, CosmosMsg, DepsMut, Env, Event, MessageInfo, Order, Response, StdResult,
Uint128,
};

use cosmwasm_std::{Addr, BalanceResponse, BankMsg, BankQuery, Coin, CosmosMsg, DepsMut, Env, Event, MessageInfo, Order, Response, StdResult, Uint128};
use cosmwasm_std::QueryRequest::Bank;
use treasurechest::{errors::ContractError, tf::tokenfactory::TokenFactoryType};

use crate::state::{CONFIG, TOTAL_REWARDS};
Expand Down Expand Up @@ -83,6 +82,20 @@ pub fn change_token_factory(
pub fn return_dust(deps: DepsMut, env: Env, sender: Addr, limit: Option<u32>) -> Result<Response, ContractError> {
cw_ownable::assert_owner(deps.storage, &sender)?;
let config = CONFIG.load(deps.storage)?;

let denom_total = deps.querier.query::<BalanceResponse>(&Bank(BankQuery::Supply {denom: config.denom.clone()}))?;
if config.burn_it {
if denom_total .amount.amount.u128()> MIN_TICKETS {
return Err(ContractError::TicketsOutstanding(denom_total.amount.amount.u128(),MIN_TICKETS))
}
} else {
let ticket_balance = deps.querier.query_balance(env.contract.address.clone(),config.denom.clone())?;
let outstanding = denom_total.amount.amount.sub(ticket_balance.amount);
if outstanding.u128() > MIN_TICKETS {
return Err(ContractError::TicketsOutstanding(outstanding.u128(),MIN_TICKETS))
}
}

let balances = deps
.querier
.query_all_balances(env.contract.address)?
Expand Down
3 changes: 3 additions & 0 deletions packages/treasurechest/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub enum ContractError {
#[error("invalid token factory type {0}")]
TokenFactoryTypeInvalid(String),

#[error("Too many outstanding redemption tokens {0} - min = {1}")]
TicketsOutstanding(u128,u128),

#[error("Unauthorized")]
Unauthorized {},

Expand Down

0 comments on commit caa5449

Please sign in to comment.