Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Commit

Permalink
Fixing 3 days delay
Browse files Browse the repository at this point in the history
  • Loading branch information
alepacheco committed Jul 6, 2018
1 parent 0dd00b1 commit 5257791
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void resource_exchange::deposit(currency::transfer tx) {
* be unstaked and accesible on 3 days
**/
void resource_exchange::withdraw(account_name to, asset quantity) {
// TODO cancel buy tx if cant pay for it
eosio_assert(quantity.is_valid(), "invalid quantity");
eosio_assert(quantity.amount > 0, "must withdraw positive quantity");
auto state = contract_state.get();
Expand Down
10 changes: 1 addition & 9 deletions src/pricing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,12 @@ double resource_exchange::calcosttoken() {
}

void resource_exchange::payreward(account_name user, asset fee_collected) {
const double FEE_SHARE = 1;
auto state = contract_state.get();
double fees = fee_collected.amount * FEE_SHARE;
double fees_devs = fee_collected.amount - fees;
double reward_per_token = fees / state.get_total().amount;
double reward_per_token = fee_collected.amount / state.get_total().amount;
auto acnt = accounts.find(user);
double reward = acnt->balance.amount * reward_per_token;
accounts.modify(acnt, 0,
[&](auto& account) { account.balance += asset(reward); });

if (fees_devs > 0) {
// pay devs
// remove from liquid
}
}

asset resource_exchange::billaccount(account_name owner,
Expand Down
5 changes: 4 additions & 1 deletion src/resource_exchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ void resource_exchange::docycle() {
fees_collected += billaccount(acnt->owner, cost_per_token);
matchbandwidth(acnt->owner);
}
asset fees_devs = fees_collected * 0.1;
for (auto acnt = accounts.begin(); acnt != accounts.end(); ++acnt) {
payreward(acnt->owner, fees_collected);
payreward(acnt->owner, fees_collected - fees_devs);
}
unstakeunknown();

// TODO paydevs
state_cycle();

print("Total fees: ", fees_collected, " ");
Expand Down

0 comments on commit 5257791

Please sign in to comment.