-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
121 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <eosio/asset.hpp> | ||
|
||
namespace eosiosystem { | ||
double compute_bpay_rate(uint64_t tlos_price, eosio::asset total_telos_supply); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <eosio.system/bpay_rate.hpp> | ||
|
||
using eosio::asset; | ||
|
||
namespace eosiosystem { | ||
double compute_bpay_rate(uint64_t tlos_price, asset total_telos_supply) { | ||
const double MULTIPLIER_CONSTANT = 8.34; | ||
const double POWER_OF_CONSTANT = -0.516; | ||
const double ACTIVE_BP_COUNT = 21; | ||
const double STANDBY_BP_COUNT = 21; | ||
|
||
// 100k divided by (30-minutes divided by the Number-of-minutes-in-a-year) | ||
// 100k / 0.00005707762557 | ||
// This was pulled out of the bpay_rate formula | ||
const double _100K_DIVIDED_BY_TIME_PERIOD = 1752000000; | ||
|
||
const double raw_tlos_price = double(tlos_price) / 100; | ||
const double tlos_per_bp = MULTIPLIER_CONSTANT * pow((double) raw_tlos_price, POWER_OF_CONSTANT); | ||
const double tlos_in_30_mins = tlos_per_bp * (ACTIVE_BP_COUNT + 0.5 * STANDBY_BP_COUNT); | ||
|
||
double total_telos_supply_double = double(total_telos_supply.amount) / pow(10.0, total_telos_supply.symbol.precision()); | ||
|
||
const double bp_rate = round( | ||
(_100K_DIVIDED_BY_TIME_PERIOD* tlos_in_30_mins) / | ||
total_telos_supply_double | ||
); | ||
|
||
return bp_rate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project(native_tests) | ||
|
||
find_package(cdt) | ||
|
||
add_native_executable( | ||
bpay_rate_test | ||
bpay_rate_test | ||
${CMAKE_CURRENT_SOURCE_DIR}/bpay_rate_test.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/../contracts/eosio.system/src/bpay_rate.cpp | ||
) | ||
|
||
target_include_directories( bpay_rate_test PUBLIC ${CMAKE_SOURCE_DIR}/../contracts/eosio.system/include ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#undef NDEBUG | ||
#include <cassert> | ||
#include <eosio/print.hpp> | ||
#include <eosio.system/bpay_rate.hpp> | ||
#include <cstdio> | ||
|
||
using eosiosystem::compute_bpay_rate; | ||
|
||
void test_bpay_tests() { | ||
eosio::asset TLOS_TOTAL_SUPPLY = eosio::asset( | ||
4200000000000, | ||
eosio::symbol("TLOS", 4) | ||
); | ||
|
||
assert(compute_bpay_rate(2, TLOS_TOTAL_SUPPLY) == 8250); | ||
assert(compute_bpay_rate(100, TLOS_TOTAL_SUPPLY) == 1096); | ||
assert(compute_bpay_rate(200, TLOS_TOTAL_SUPPLY) == 766); | ||
assert(compute_bpay_rate(500, TLOS_TOTAL_SUPPLY) == 478); | ||
assert(compute_bpay_rate(1000, TLOS_TOTAL_SUPPLY) == 334); | ||
assert(compute_bpay_rate(5000, TLOS_TOTAL_SUPPLY) == 146); | ||
assert(compute_bpay_rate(10000, TLOS_TOTAL_SUPPLY) == 102); | ||
} | ||
|
||
|
||
int main(int argc, char** argv) { | ||
test_bpay_tests(); | ||
return 0; | ||
} |