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

Commit

Permalink
Fix price slide
Browse files Browse the repository at this point in the history
  • Loading branch information
alepacheco committed Jul 15, 2018
1 parent 9a9b464 commit 2e35aaa
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/pricing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,11 @@ asset resource_exchange::calcost(asset resources) {
return asset(0);
}
eosio_assert(contract_state.exists(), "No contract state available");
int PURCHASE_STEP = 1; // the lower the more precise but more cpu
auto state = contract_state.get();
int32_t steps = 100;

int64_t purchase = resources.amount;
double_t liquid = state.liquid_funds.amount;
double_t liquid = state.liquid_funds.amount - resources.amount;
double_t total = state.get_total().amount;

int32_t purchase_per_step = purchase / steps;
double_t cost_per_token = 0;
for (int i = 0; i < steps; i++) {
cost_per_token += cost_function(total, liquid, PRICE_TUNE);
liquid -= purchase_per_step;
}
cost_per_token = cost_per_token / steps;
asset price = asset(cost_per_token * purchase);

double_t cost_per_token = cost_function(total, liquid, PRICE_TUNE);
asset price = asset(cost_per_token * resources.amount);
print("price: ", price);
return price;
}
Expand All @@ -43,6 +31,7 @@ double resource_exchange::calcosttoken() {
double total = state.get_total().amount;
eosio_assert(liquid > 0 && total > 0, "No funds to price");
double cost_per_token = cost_function(total, liquid, PRICE_TUNE);
print(cost_per_token);
return cost_per_token;
}

Expand Down

0 comments on commit 2e35aaa

Please sign in to comment.