Add slow demurrage calc
This commit is contained in:
parent
a6f53e7278
commit
abe82949ea
@ -43,6 +43,15 @@ class DemurrageCalculator:
|
|||||||
|
|
||||||
return adjusted_amount
|
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
|
@staticmethod
|
||||||
def from_contract(rpc, chain_spec, contract_address, sender_address=ZERO_ADDRESS):
|
def from_contract(rpc, chain_spec, contract_address, sender_address=ZERO_ADDRESS):
|
||||||
|
@ -16,13 +16,19 @@ from tests.base import TestDemurrage
|
|||||||
class TestEmulate(TestDemurrage):
|
class TestEmulate(TestDemurrage):
|
||||||
|
|
||||||
def test_amount_since(self):
|
def test_amount_since(self):
|
||||||
|
|
||||||
d = datetime.datetime.utcnow() - datetime.timedelta(seconds=29, hours=5, minutes=3, days=4)
|
d = datetime.datetime.utcnow() - datetime.timedelta(seconds=29, hours=5, minutes=3, days=4)
|
||||||
c = DemurrageCalculator(0.00000050105908373373)
|
c = DemurrageCalculator(0.00000050105908373373)
|
||||||
a = c.amount_since(100, d.timestamp())
|
a = c.amount_since(100, d.timestamp())
|
||||||
self.assert_within_lower(a, 99.69667, 0.1)
|
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):
|
def test_from_contract(self):
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
Reference in New Issue
Block a user