Skip to content

Commit

Permalink
algo change
Browse files Browse the repository at this point in the history
  • Loading branch information
angelol committed Oct 4, 2022
1 parent 9997f80 commit 84d00de
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions contracts/daccustodian/newperiod_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,16 @@ ACTION daccustodian::claimbudget(const name &dac_id) {
// percentage value is scaled by 100, so to calculate percent we need to divide by (100 * 100 == 10000)
const auto allocation_for_period = treasury_balance * budget_percentage / 10000;

if (allocation_for_period.amount > 0) {
// if the calculated allocation_for_period is very small round it up to 10 TLM or the full treasury balance to avoid
// dust transactions for low percentage/balances in treasury.
const auto rounded_allocation_for_period = std::max(allocation_for_period, asset{100000, symbol{"TLM", 4}});

// Because this has been rounded up, ensure we don't attempt to transfer more than the treasury balance.
const auto amount_to_transfer = std::min(treasury_balance, rounded_allocation_for_period);

if (amount_to_transfer.amount > 0) {
action(permission_level{treasury_account, "xfer"_n}, TLM_TOKEN_CONTRACT, "transfer"_n,
make_tuple(treasury_account, recipient, allocation_for_period, "period budget"s))
make_tuple(treasury_account, recipient, amount_to_transfer, "period budget"s))
.send();
}

Expand Down

0 comments on commit 84d00de

Please sign in to comment.