Skip to content

Commit

Permalink
Merge pull request #53 from Alien-Worlds/DEMZNE-1088_Simplify-budget-…
Browse files Browse the repository at this point in the history
…claim

Simplify budget claim
  • Loading branch information
angelol authored Oct 4, 2022
2 parents 1e91070 + 84d00de commit c3d6f80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 6 additions & 4 deletions contracts/daccustodian/daccustodian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3400,10 +3400,12 @@ async function expected_budget_transfer_amount(
const nft_with_highest_value = budget_nfts[0];
percentage = nft_with_highest_value.value;
}
const allocation_for_period = (treasury_balance * percentage) / 10000;
const rounded_allocation_for_period = Math.max(allocation_for_period, 10);
const amount_to_transfer = rounded_allocation_for_period - auth_balance;
return Math.max(0, Math.min(treasury_balance, amount_to_transfer));
const allocation = (treasury_balance * percentage) / 10000;
return round_to_decimals(allocation, 4);
}

function round_to_decimals(number, decimals) {
return Math.round(number * Math.pow(10, decimals)) / Math.pow(10, decimals);
}

async function get_balance(
Expand Down
7 changes: 2 additions & 5 deletions contracts/daccustodian/newperiod_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,10 @@ ACTION daccustodian::claimbudget(const name &dac_id) {

// 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.
auto rounded_allocation_for_period = std::max(allocation_for_period, asset{100000, symbol{"TLM", 4}});

// only transfer enough to top up to the rounded_allocation_for_period
auto amount_to_transfer = rounded_allocation_for_period - auth_balance;
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.
amount_to_transfer = std::min(treasury_balance, amount_to_transfer);
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,
Expand Down

0 comments on commit c3d6f80

Please sign in to comment.