erc20-demurrage-token

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

commit 294ded19f5a99d895c20deeec5f30a13ba724618
parent 2c1b7cbb1efda0e6cb066cb3f1417ce92fd8378a
Author: nolash <dev@holbrook.no>
Date:   Mon, 28 Jun 2021 11:46:05 +0200

Move to chainlib-eth

Diffstat:
Apython/CHANGELOG | 4++++
Mpython/erc20_demurrage_token/sim/sim.py | 2+-
Mpython/erc20_demurrage_token/token.py | 86++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Mpython/requirements.txt | 6+++---
Mpython/setup.cfg | 2+-
Mpython/test_requirements.txt | 1-
Mpython/tests/test_amounts.py | 14+++++++-------
Mpython/tests/test_redistribution_unit.py | 12++++++------
Mpython/tests/test_single.py | 8++++----
9 files changed, 83 insertions(+), 52 deletions(-)

diff --git a/python/CHANGELOG b/python/CHANGELOG @@ -0,0 +1,4 @@ +- 0.0.2-pending + * Move to chainlib-eth +- 0.0.1-unreleased + * Interface for redistributed and non-redistributed, with or without cap diff --git a/python/erc20_demurrage_token/sim/sim.py b/python/erc20_demurrage_token/sim/sim.py @@ -200,7 +200,7 @@ class DemurrageTokenSimulation: else: o = self.caller_contract.balance_of(self.address, holder, sender_address=self.caller_address) r = self.rpc.do(o) - return self.caller_contract.parse_balance_of(r) + return self.caller_contract.parse_balance(r) def __next_block(self): diff --git a/python/erc20_demurrage_token/token.py b/python/erc20_demurrage_token/token.py @@ -14,7 +14,7 @@ from chainlib.eth.contract import ( abi_decode_single, ) from chainlib.eth.constant import ZERO_ADDRESS -from chainlib.jsonrpc import jsonrpc_template +from chainlib.jsonrpc import JSONRPCRequest from eth_erc20 import ERC20 from hexathon import ( add_0x, @@ -146,8 +146,9 @@ class DemurrageToken(ERC20): return tx - def to_base_amount(self, contract_address, value, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def to_base_amount(self, contract_address, value, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('toBaseAmount') @@ -158,11 +159,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def remainder(self, contract_address, parts, whole, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def remainder(self, contract_address, parts, whole, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('remainder') @@ -175,11 +178,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def redistributions(self, contract_address, idx, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def redistributions(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('redistributions') @@ -190,11 +195,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def account_period(self, contract_address, address, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def account_period(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('accountPeriod') @@ -205,11 +212,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def to_redistribution(self, contract_address, participants, demurrage_modifier_ppm, value, period, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def to_redistribution(self, contract_address, participants, demurrage_modifier_ppm, value, period, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('toRedistribution') @@ -226,12 +235,14 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def to_redistribution_period(self, contract_address, redistribution, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def to_redistribution_period(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('toRedistributionPeriod') @@ -242,11 +253,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def to_redistribution_participants(self, contract_address, redistribution, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def to_redistribution_participants(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('toRedistributionParticipants') @@ -257,11 +270,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def to_redistribution_supply(self, contract_address, redistribution, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def to_redistribution_supply(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('toRedistributionSupply') @@ -272,11 +287,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def to_redistribution_demurrage_modifier(self, contract_address, redistribution, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def to_redistribution_demurrage_modifier(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('toRedistributionDemurrageModifier') @@ -287,11 +304,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def base_balance_of(self, contract_address, address, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def base_balance_of(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('baseBalanceOf') @@ -302,6 +321,7 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o @@ -345,8 +365,9 @@ class DemurrageToken(ERC20): return self.call_noarg('supplyCap', contract_address, sender_address=sender_address) - def grow_by(self, contract_address, value, period, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def grow_by(self, contract_address, value, period, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('growBy') @@ -359,11 +380,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def decay_by(self, contract_address, value, period, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def decay_by(self, contract_address, value, period, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('decayBy') @@ -376,11 +399,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def get_distribution(self, contract_address, supply, demurrage_amount, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def get_distribution(self, contract_address, supply, demurrage_amount, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('getDistribution') @@ -393,11 +418,13 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def get_distribution_from_redistribution(self, contract_address, redistribution, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def get_distribution_from_redistribution(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('getDistributionFromRedistribution') @@ -408,6 +435,7 @@ class DemurrageToken(ERC20): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o diff --git a/python/requirements.txt b/python/requirements.txt @@ -1,3 +1,3 @@ -chainlib~=0.0.3rc3 -eth-erc20~=0.0.9a4 -crypto-dev-signer~=0.4.14b3 +chainlib~=0.0.5a1 +eth-erc20~=0.0.10a1 +crypto-dev-signer~=0.4.14b6 diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = erc20-demurrage-token -version = 0.0.1b3 +version = 0.0.2a1 description = ERC20 token with redistributed continual demurrage author = Louis Holbrook author_email = dev@holbrook.no diff --git a/python/test_requirements.txt b/python/test_requirements.txt @@ -1,3 +1,2 @@ -#web3==5.12.2 eth_tester==0.5.0b3 py-evm==0.3.0a20 diff --git a/python/tests/test_amounts.py b/python/tests/test_amounts.py @@ -35,7 +35,7 @@ class TestAmounts(TestDemurrageDefault): o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assertEqual(balance, 817) (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 1000) @@ -43,7 +43,7 @@ class TestAmounts(TestDemurrageDefault): o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assert_within_lower(balance, 1817, 750) self.backend.time_travel(self.start_time + self.period_seconds * 2) @@ -53,7 +53,7 @@ class TestAmounts(TestDemurrageDefault): o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) expected_balance = ((1 - self.tax_level / 1000000) ** 10) * 1000 expected_balance += ((1 - self.tax_level / 1000000) ** 20) * 1000 @@ -73,7 +73,7 @@ class TestAmounts(TestDemurrageDefault): o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assertEqual(balance, 1634) nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc) @@ -83,12 +83,12 @@ class TestAmounts(TestDemurrageDefault): o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assertEqual(balance, 1134) o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assert_within_lower(balance, 500, 2000) @@ -115,7 +115,7 @@ class TestAmounts(TestDemurrageDefault): o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assertEqual(balance, case[1]) diff --git a/python/tests/test_redistribution_unit.py b/python/tests/test_redistribution_unit.py @@ -83,7 +83,7 @@ class TestRedistribution(TestDemurrageUnit): o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assertEqual(balance, expected_balance) @@ -108,7 +108,7 @@ class TestRedistribution(TestDemurrageUnit): for i in range(3): o = c.balance_of(self.address, self.accounts[i+1], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assertEqual(balance, expected_balance) @@ -147,7 +147,7 @@ class TestRedistribution(TestDemurrageUnit): expected_balance = mint_amount - demurrage_amount o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assertEqual(balance, expected_balance) half_demurrage_amount = int((self.tax_level / 1000000) * half_mint_amount) @@ -155,12 +155,12 @@ class TestRedistribution(TestDemurrageUnit): expected_balance = half_mint_amount - half_demurrage_amount o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assertEqual(balance, expected_balance) o = c.balance_of(self.address, self.accounts[3], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assertEqual(balance, expected_balance) o = c.total_supply(self.address, sender_address=self.accounts[0]) @@ -185,7 +185,7 @@ class TestRedistribution(TestDemurrageUnit): o = c.balance_of(self.address, self.sink_address, sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assert_within_lower(balance, expected_balance, 1000) diff --git a/python/tests/test_single.py b/python/tests/test_single.py @@ -67,18 +67,18 @@ class TestRedistributionSingle(TestDemurrageSingle): tax_modifier = (1 - (self.tax_level / 1000000)) ** 10 o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) self.assertEqual(balance, int(mint_amount * tax_modifier)) o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) base_amount = mint_amount - int(mint_amount * 0.1) self.assertEqual(balance, int(base_amount * tax_modifier)) #(base_amount - (base_amount * (self.tax_level / 1000000)))) o = c.balance_of(self.address, self.accounts[3], sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) base_amount = mint_amount - int(mint_amount * 0.2) self.assertEqual(balance, int(base_amount * tax_modifier)) #(base_amount - (base_amount * (self.tax_level / 1000000)))) @@ -88,7 +88,7 @@ class TestRedistributionSingle(TestDemurrageSingle): o = c.balance_of(self.address, self.sink_address, sender_address=self.accounts[0]) r = self.rpc.do(o) - balance = c.parse_balance_of(r) + balance = c.parse_balance(r) expected_balance = new_supply - (new_supply * tax_modifier) self.assert_within_lower(balance, expected_balance, 1)