mirror of
git://holbrook.no/erc20-demurrage-token
synced 2026-04-27 18:41:05 +02:00
Create demurrage calc from contract
This commit is contained in:
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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,8 +1,14 @@
|
||||
#
|
||||
# standard imports
|
||||
import logging
|
||||
import datetime
|
||||
import math
|
||||
|
||||
# eternal imports
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
|
||||
# local imports
|
||||
from .token import DemurrageToken
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
@@ -36,3 +42,18 @@ class DemurrageCalculator:
|
||||
logg.debug('adjusted for {} hours {} -> {} delta {}'.format(remainder_minutes, amount, adjusted_amount, adjusted_delta))
|
||||
|
||||
return adjusted_amount
|
||||
|
||||
|
||||
@staticmethod
|
||||
def from_contract(rpc, chain_spec, contract_address, sender_address=ZERO_ADDRESS):
|
||||
c = DemurrageToken(chain_spec)
|
||||
o = c.tax_level(contract_address, sender_address=sender_address)
|
||||
r = rpc.do(o)
|
||||
taxlevel_i = c.parse_tax_level(r)
|
||||
|
||||
o = c.resolution_factor(contract_address, sender_address=sender_address)
|
||||
r = rpc.do(o)
|
||||
divider = c.parse_resolution_factor(r)
|
||||
logg.debug('taxlevel {} f {}'.format(taxlevel_i, divider))
|
||||
taxlevel_f = taxlevel_i / divider
|
||||
return DemurrageCalculator(taxlevel_f)
|
||||
|
||||
@@ -343,7 +343,15 @@ class DemurrageToken(ERC20):
|
||||
tx = self.set_code(tx, data)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
return tx
|
||||
|
||||
|
||||
|
||||
def tax_level(self, contract_address, sender_address=ZERO_ADDRESS):
|
||||
return self.call_noarg('taxLevel', contract_address, sender_address=sender_address)
|
||||
|
||||
|
||||
def resolution_factor(self, contract_address, sender_address=ZERO_ADDRESS):
|
||||
return self.call_noarg('resolutionFactor', contract_address, sender_address=sender_address)
|
||||
|
||||
|
||||
def actual_period(self, contract_address, sender_address=ZERO_ADDRESS):
|
||||
return self.call_noarg('actualPeriod', contract_address, sender_address=sender_address)
|
||||
@@ -507,3 +515,13 @@ class DemurrageToken(ERC20):
|
||||
@classmethod
|
||||
def parse_get_distribution(self, v):
|
||||
return abi_decode_single(ABIContractType.UINT256, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_tax_level(self, v):
|
||||
return abi_decode_single(ABIContractType.UINT256, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_resolution_factor(self, v):
|
||||
return abi_decode_single(ABIContractType.UINT256, v)
|
||||
|
||||
Reference in New Issue
Block a user