erc20-demurrage-token

ERC20 token with redistributed continual demurrage
Log | Files | Refs | README

commit abe82949ea682357610a87b1de2f6cc90fb3301a
parent a6f53e72789abdf7ed8a5049b4c5deeba4c27acf
Author: nolash <dev@holbrook.no>
Date:   Sun,  4 Jul 2021 14:52:12 +0200

Add slow demurrage calc

Diffstat:
Mpython/erc20_demurrage_token/demurrage.py | 9+++++++++
Mpython/tests/test_demurrage_ext.py | 8+++++++-
2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/python/erc20_demurrage_token/demurrage.py b/python/erc20_demurrage_token/demurrage.py @@ -43,6 +43,15 @@ class DemurrageCalculator: return adjusted_amount + + def amount_since_slow(self, amount, timestamp): + delta = datetime.datetime.utcnow() - datetime.datetime.fromtimestamp(timestamp) + remainder_minutes = math.floor(delta.total_seconds() / 60) + adjusted_amount = amount * ((1 - self.r_min) ** remainder_minutes) + logg.debug('adjusted for {} minutes {} -> {} delta {}'.format(remainder_minutes, amount, adjusted_amount, amount - adjusted_amount)) + + return adjusted_amount + @staticmethod def from_contract(rpc, chain_spec, contract_address, sender_address=ZERO_ADDRESS): diff --git a/python/tests/test_demurrage_ext.py b/python/tests/test_demurrage_ext.py @@ -16,13 +16,19 @@ from tests.base import TestDemurrage class TestEmulate(TestDemurrage): def test_amount_since(self): - d = datetime.datetime.utcnow() - datetime.timedelta(seconds=29, hours=5, minutes=3, days=4) c = DemurrageCalculator(0.00000050105908373373) a = c.amount_since(100, d.timestamp()) self.assert_within_lower(a, 99.69667, 0.1) + def test_amount_since_slow(self): + d = datetime.datetime.utcnow() - datetime.timedelta(seconds=29, hours=5, minutes=3, days=4) + c = DemurrageCalculator(0.00000050105908373373) + a = c.amount_since_slow(100, d.timestamp()) + self.assert_within_lower(a, 99.69667, 0.1) + + def test_from_contract(self): nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)