Apply redistribution correction from singlecap to singlenocap contract

This commit is contained in:
lash 2022-02-28 10:42:30 +00:00
parent a04c826ba7
commit 6dc843fb5d
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
12 changed files with 39 additions and 13 deletions

View File

@ -1,4 +1,7 @@
- 0.0.2-pending
- 0.0.9
* Fix wrong redistribution calculation in single nocap
[...]
- 0.0.2
* Move to chainlib-eth
- 0.0.1-unreleased
* Interface for redistributed and non-redistributed, with or without cap

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,3 @@
chainlib-eth~=0.0.15
eth-erc20~=0.1.5
funga-eth~=0.5.1
chainlib-eth~=0.0.27
eth-erc20~=0.1.10
funga-eth~=0.5.6

View File

@ -1,6 +1,6 @@
[metadata]
name = erc20-demurrage-token
version = 0.0.8
version = 0.0.9
description = ERC20 token with redistributed continual demurrage
author = Louis Holbrook
author_email = dev@holbrook.no

View File

@ -107,10 +107,11 @@ class TestBasic(TestDemurrageDefault):
r = self.rpc.do(o)
demurrage_amount = c.parse_demurrage_amount(r)
modifier_base = ((1000000 - self.tax_level) / 1000000) ** 10
logg.warning('mod base {}'.format(modifier_base))
modifier = int(modifier_base * (10 ** 12))
rounding_tolerance_nano = 4000000 # 0.000004% precision
demurrage_amount_truncate = int(demurrage_amount / (10 ** 26)) # equals 12 decimal places
demurrage_amount_truncate = int(demurrage_amount / (10 ** 16)) # equals 38 decimal places - 14 for the modifier magniture - 2 for percent int calc + 6 for token decimals (originally equalled 12 decimal places)
self.assertGreaterEqual(modifier, demurrage_amount_truncate - rounding_tolerance_nano)
self.assertLessEqual(modifier, demurrage_amount_truncate)

View File

@ -311,6 +311,10 @@ contract DemurrageTokenSingleCap {
// Calculate and cache the demurrage value corresponding to the (period of the) time of the method call
function applyDemurrage() public returns (bool) {
return applyDemurrageLimited(0);
}
function applyDemurrageLimited(uint256 _rounds) public returns (bool) {
//uint128 epochPeriodCount;
uint256 periodCount;
uint256 lastDemurrageAmount;
@ -323,6 +327,12 @@ contract DemurrageTokenSingleCap {
return false;
}
lastDemurrageAmount = demurrageAmount;
// safety limit for exponential calculation to ensure that we can always
// execute this code no matter how much time passes.
if (_rounds > 0 && _rounds < periodCount) {
periodCount = _rounds;
}
demurrageAmount = uint128(decayBy(lastDemurrageAmount, periodCount));
//demurragePeriod = epochPeriodCount;
demurrageTimestamp = demurrageTimestamp + (periodCount * 60);

View File

@ -278,7 +278,8 @@ contract DemurrageTokenSingleCap {
function getDistribution(uint256 _supply, uint256 _demurrageAmount) public view returns (uint256) {
uint256 difference;
difference = _supply * (resolutionFactor - _demurrageAmount); //(nanoDivider - ((resolutionFactor - _demurrageAmount) / nanoDivider));
//difference = _supply * (resolutionFactor - _demurrageAmount); //(nanoDivider - ((resolutionFactor - _demurrageAmount) / nanoDivider));
difference = _supply * (resolutionFactor - (_demurrageAmount * 10000000000)); //(nanoDivider - ((resolutionFactor - _demurrageAmount) / nanoDivider));
return difference / resolutionFactor;
}
@ -307,6 +308,10 @@ contract DemurrageTokenSingleCap {
// Calculate and cache the demurrage value corresponding to the (period of the) time of the method call
function applyDemurrage() public returns (bool) {
return applyDemurrageLimited(0);
}
function applyDemurrageLimited(uint256 _rounds) public returns (bool) {
//uint128 epochPeriodCount;
uint256 periodCount;
uint256 lastDemurrageAmount;
@ -319,6 +324,13 @@ contract DemurrageTokenSingleCap {
return false;
}
lastDemurrageAmount = demurrageAmount;
// safety limit for exponential calculation to ensure that we can always
// execute this code no matter how much time passes.
if (_rounds > 0 && _rounds < periodCount) {
periodCount = _rounds;
}
demurrageAmount = uint128(decayBy(lastDemurrageAmount, periodCount));
//demurragePeriod = epochPeriodCount;
demurrageTimestamp = demurrageTimestamp + (periodCount * 60);