erc20-demurrage-token

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

commit c31649fed248f2e210c05b76f41cd587d9d8deab
parent cf1e716b5a68234714426742235a157e0c489fe4
Author: lash <dev@holbrook.no>
Date:   Tue, 14 Feb 2023 07:23:59 +0000

Implement chainlib gen

Diffstat:
Mpython/erc20_demurrage_token/__init__.py | 3+++
Apython/erc20_demurrage_token/data/.chainlib | 0
Mpython/erc20_demurrage_token/token.py | 54+++++++++++++++++++++++++++++++++++++++++-------------
Mpython/requirements.txt | 2+-
Apython/tests/test_mint.py | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 96 insertions(+), 14 deletions(-)

diff --git a/python/erc20_demurrage_token/__init__.py b/python/erc20_demurrage_token/__init__.py @@ -3,3 +3,6 @@ from .token import ( DemurrageTokenSettings, DemurrageRedistribution, ) +from .token import create +from .token import bytecode +from .token import args diff --git a/python/erc20_demurrage_token/data/.chainlib b/python/erc20_demurrage_token/data/.chainlib diff --git a/python/erc20_demurrage_token/token.py b/python/erc20_demurrage_token/token.py @@ -78,28 +78,34 @@ class DemurrageToken(ERC20, SealedContract, ExpiryContract): __abi = {} __bytecode = {} - def constructor(self, sender_address, settings, tx_format=TxFormat.JSONRPC): - code = DemurrageToken.bytecode() - enc = ABIContractEncoder() - enc.string(settings.name) - enc.string(settings.symbol) - enc.uint256(settings.decimals) - enc.uint256(settings.demurrage_level) - enc.uint256(settings.period_minutes) - enc.address(settings.sink_address) - code += enc.get() + def constructor(self, sender_address, settings, tx_format=TxFormat.JSONRPC, version=None): + code = self.cargs(settings.name, settings.symbol, settings.decimals, settings.demurrage_level, settings.period_minutes, settings.sink_address, version=version) tx = self.template(sender_address, None, use_nonce=True) tx = self.set_code(tx, code) return self.finalize(tx, tx_format) @staticmethod + def cargs(name, symbol, decimals, demurrage_level, period_minutes, sink_address, version=None): + code = DemurrageToken.bytecode() + enc = ABIContractEncoder() + enc.string(name) + enc.string(symbol) + enc.uint256(decimals) + enc.uint256(demurrage_level) + enc.uint256(period_minutes) + enc.address(sink_address) + code += enc.get() + return code + + + @staticmethod def gas(code=None): - return 4000000 + return 6000000 @staticmethod - def abi(multi=True): + def abi(): name = 'DemurrageTokenSingleNocap' if DemurrageToken.__abi.get(name) == None: f = open(os.path.join(data_dir, name + '.json'), 'r') @@ -109,7 +115,7 @@ class DemurrageToken(ERC20, SealedContract, ExpiryContract): @staticmethod - def bytecode(multi=True): + def bytecode(version=None): name = 'DemurrageTokenSingleNocap' if DemurrageToken.__bytecode.get(name) == None: f = open(os.path.join(data_dir, name + '.bin'), 'r') @@ -665,3 +671,25 @@ class DemurrageToken(ERC20, SealedContract, ExpiryContract): def parse_total_burned(self, v): return abi_decode_single(ABIContractType.UINT256, v) + +def bytecode(**kwargs): + return DemurrageToken.bytecode(version=kwargs.get('version')) + + +def create(**kwargs): + return DemurrageToken.cargs( + kwargs['name'], + kwargs['symbol'], + kwargs['decimals'], + kwargs['demurragelevel'], + kwargs['redistributionperiod'], + kwargs['sinkaddress'], + version=kwargs.get('version')) + + +def args(v): + if v == 'create': + return (['name', 'symbol', 'decimals', 'demurragelevel', 'redistributionperiod', 'sinkaddress'], ['version'],) + elif v == 'default' or v == 'bytecode': + return ([], ['version'],) + raise ValueError('unknown command: ' + v) diff --git a/python/requirements.txt b/python/requirements.txt @@ -1,4 +1,4 @@ chainlib-eth~=0.4.11 eth-erc20~=0.5.0 funga-eth~=0.6.0 -dexif~=0.0.1 +dexif~=0.0.2 diff --git a/python/tests/test_mint.py b/python/tests/test_mint.py @@ -0,0 +1,51 @@ +# standard imports +import os +import unittest +import json +import logging + +# external imports +from chainlib.eth.constant import ZERO_ADDRESS +from chainlib.eth.nonce import RPCNonceOracle +from chainlib.eth.tx import receipt +from chainlib.eth.block import block_latest +from chainlib.eth.block import block_by_number + +# local imports +from erc20_demurrage_token import DemurrageToken + +# test imports +from erc20_demurrage_token.unittest import TestDemurrageDefault + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + +testdir = os.path.dirname(__file__) + +class TestAmounts(TestDemurrageDefault): + + def test_mint(self): + o = block_latest() + r = self.rpc.do(o) + o = block_by_number(r) + r = self.rpc.do(o) + tb = r['timestamp'] + self.backend.time_travel(self.start_time + 800) + o = block_latest() + r = self.rpc.do(o) + o = block_by_number(r) + r = self.rpc.do(o) + ta = r['timestamp'] + logg.info('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>< {} {} {}'.format(tb, ta, ta-tb)) + + nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) + c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 1000) + r = self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + +if __name__ == '__main__': + unittest.main()