2021-06-04 09:05:08 +02:00
|
|
|
|
# standard imports
|
|
|
|
|
import os
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
# external imports
|
|
|
|
|
from chainlib.eth.tx import (
|
|
|
|
|
TxFactory,
|
|
|
|
|
TxFormat,
|
|
|
|
|
)
|
|
|
|
|
from chainlib.hash import keccak256_string_to_hex
|
|
|
|
|
from chainlib.eth.contract import (
|
|
|
|
|
ABIContractEncoder,
|
|
|
|
|
ABIContractType,
|
|
|
|
|
abi_decode_single,
|
|
|
|
|
)
|
|
|
|
|
from chainlib.eth.constant import ZERO_ADDRESS
|
2021-06-28 11:46:05 +02:00
|
|
|
|
from chainlib.jsonrpc import JSONRPCRequest
|
2021-06-04 09:05:08 +02:00
|
|
|
|
from eth_erc20 import ERC20
|
|
|
|
|
from hexathon import (
|
|
|
|
|
add_0x,
|
|
|
|
|
strip_0x,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# local imports
|
|
|
|
|
from erc20_demurrage_token.data import data_dir
|
|
|
|
|
|
|
|
|
|
logg = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DemurrageTokenSettings:
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.name = None
|
|
|
|
|
self.symbol = None
|
|
|
|
|
self.decimals = None
|
|
|
|
|
self.demurrage_level = None
|
|
|
|
|
self.period_minutes = None
|
|
|
|
|
self.sink_address = None
|
|
|
|
|
|
|
|
|
|
|
2022-05-30 09:53:22 +02:00
|
|
|
|
def __str__(self):
|
|
|
|
|
return 'name {} demurrage level {} period minutes {} sink address {}'.format(
|
|
|
|
|
self.name,
|
|
|
|
|
self.demurrage_level,
|
|
|
|
|
self.period_minutes,
|
|
|
|
|
self.sink_address,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
|
class DemurrageToken(ERC20):
|
|
|
|
|
|
2021-06-05 07:50:59 +02:00
|
|
|
|
__abi = {}
|
|
|
|
|
__bytecode = {}
|
2021-06-05 08:45:37 +02:00
|
|
|
|
valid_modes = [
|
|
|
|
|
'MultiNocap',
|
|
|
|
|
'SingleNocap',
|
|
|
|
|
'MultiCap',
|
2021-06-05 11:58:35 +02:00
|
|
|
|
'SingleCap',
|
2021-06-05 08:45:37 +02:00
|
|
|
|
]
|
2021-06-04 09:05:08 +02:00
|
|
|
|
|
|
|
|
|
def constructor(self, sender_address, settings, redistribute=True, cap=0, tx_format=TxFormat.JSONRPC):
|
2021-06-05 07:50:59 +02:00
|
|
|
|
if int(cap) < 0:
|
|
|
|
|
raise ValueError('cap must be 0 or positive integer')
|
|
|
|
|
code = DemurrageToken.bytecode(multi=redistribute, cap=cap>0)
|
2021-06-04 09:05:08 +02:00
|
|
|
|
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)
|
2021-06-05 11:58:35 +02:00
|
|
|
|
if cap > 0:
|
|
|
|
|
enc.uint256(cap)
|
2021-06-04 09:05:08 +02:00
|
|
|
|
code += enc.get()
|
|
|
|
|
tx = self.template(sender_address, None, use_nonce=True)
|
|
|
|
|
tx = self.set_code(tx, code)
|
|
|
|
|
return self.finalize(tx, tx_format)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def gas(code=None):
|
2021-06-09 14:54:43 +02:00
|
|
|
|
return 4000000
|
2021-06-04 09:05:08 +02:00
|
|
|
|
|
2021-06-05 07:50:59 +02:00
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def __to_contract_name(multi, cap):
|
|
|
|
|
name = 'DemurrageToken'
|
|
|
|
|
if multi:
|
|
|
|
|
name += 'Multi'
|
|
|
|
|
else:
|
|
|
|
|
name += 'Single'
|
|
|
|
|
if cap:
|
|
|
|
|
name += 'Cap'
|
|
|
|
|
else:
|
|
|
|
|
name += 'Nocap'
|
2021-06-05 14:03:50 +02:00
|
|
|
|
logg.debug('bytecode name {}'.format(name))
|
2021-06-05 07:50:59 +02:00
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
|
@staticmethod
|
2021-06-05 07:50:59 +02:00
|
|
|
|
def abi(multi=True, cap=False):
|
|
|
|
|
name = DemurrageToken.__to_contract_name(multi, cap)
|
|
|
|
|
if DemurrageToken.__abi.get(name) == None:
|
|
|
|
|
f = open(os.path.join(data_dir, name + '.json'), 'r')
|
|
|
|
|
DemurrageToken.__abi[name] = json.load(f)
|
2021-06-04 09:05:08 +02:00
|
|
|
|
f.close()
|
2021-06-05 07:50:59 +02:00
|
|
|
|
return DemurrageToken.__abi[name]
|
2021-06-04 09:05:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
2021-06-05 07:50:59 +02:00
|
|
|
|
def bytecode(multi=True, cap=False):
|
|
|
|
|
name = DemurrageToken.__to_contract_name(multi, cap)
|
|
|
|
|
if DemurrageToken.__bytecode.get(name) == None:
|
|
|
|
|
f = open(os.path.join(data_dir, name + '.bin'), 'r')
|
|
|
|
|
DemurrageToken.__bytecode[name] = f.read()
|
2021-06-04 09:05:08 +02:00
|
|
|
|
f.close()
|
2021-06-05 07:50:59 +02:00
|
|
|
|
return DemurrageToken.__bytecode[name]
|
2021-06-04 09:05:08 +02:00
|
|
|
|
|
|
|
|
|
|
2023-01-05 14:36:40 +01:00
|
|
|
|
def increase_allowance(self, contract_address, sender_address, address, value, tx_format=TxFormat.JSONRPC):
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('increaseAllowance')
|
|
|
|
|
enc.typ(ABIContractType.ADDRESS)
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.address(address)
|
|
|
|
|
enc.uint256(value)
|
|
|
|
|
data = enc.get()
|
|
|
|
|
tx = self.template(sender_address, contract_address, use_nonce=True)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
tx = self.finalize(tx, tx_format)
|
|
|
|
|
return tx
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def decrease_allowance(self, contract_address, sender_address, address, value, tx_format=TxFormat.JSONRPC):
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('decreaseAllowance')
|
|
|
|
|
enc.typ(ABIContractType.ADDRESS)
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.address(address)
|
|
|
|
|
enc.uint256(value)
|
|
|
|
|
data = enc.get()
|
|
|
|
|
tx = self.template(sender_address, contract_address, use_nonce=True)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
tx = self.finalize(tx, tx_format)
|
|
|
|
|
return tx
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
|
def add_minter(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('addMinter')
|
|
|
|
|
enc.typ(ABIContractType.ADDRESS)
|
|
|
|
|
enc.address(address)
|
|
|
|
|
data = enc.get()
|
|
|
|
|
tx = self.template(sender_address, contract_address, use_nonce=True)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
tx = self.finalize(tx, tx_format)
|
|
|
|
|
return tx
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 09:24:05 +02:00
|
|
|
|
def remove_minter(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('removeMinter')
|
|
|
|
|
enc.typ(ABIContractType.ADDRESS)
|
|
|
|
|
enc.address(address)
|
|
|
|
|
data = enc.get()
|
|
|
|
|
tx = self.template(sender_address, contract_address, use_nonce=True)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
tx = self.finalize(tx, tx_format)
|
|
|
|
|
return tx
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
|
def mint_to(self, contract_address, sender_address, address, value, tx_format=TxFormat.JSONRPC):
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('mintTo')
|
|
|
|
|
enc.typ(ABIContractType.ADDRESS)
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.address(address)
|
|
|
|
|
enc.uint256(value)
|
|
|
|
|
data = enc.get()
|
|
|
|
|
tx = self.template(sender_address, contract_address, use_nonce=True)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
tx = self.finalize(tx, tx_format)
|
|
|
|
|
return tx
|
|
|
|
|
|
|
|
|
|
|
2022-12-05 19:17:58 +01:00
|
|
|
|
def burn(self, contract_address, sender_address, value, tx_format=TxFormat.JSONRPC):
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('burn')
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.uint256(value)
|
|
|
|
|
data = enc.get()
|
|
|
|
|
tx = self.template(sender_address, contract_address, use_nonce=True)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
tx = self.finalize(tx, tx_format)
|
|
|
|
|
return tx
|
|
|
|
|
|
|
|
|
|
|
2022-12-05 19:25:04 +01:00
|
|
|
|
def total_burned(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('totalBurned')
|
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
|
|
|
|
o = j.finalize(o)
|
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def to_base_amount(self, contract_address, value, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-04 09:29:52 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('toBaseAmount')
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.uint256(value)
|
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-04 09:29:52 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def remainder(self, contract_address, parts, whole, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-04 11:48:17 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('remainder')
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.uint256(parts)
|
|
|
|
|
enc.uint256(whole)
|
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-04 11:48:17 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def redistributions(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-04 13:14:26 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('redistributions')
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.uint256(idx)
|
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-04 13:14:26 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def account_period(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-04 15:08:03 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('accountPeriod')
|
|
|
|
|
enc.typ(ABIContractType.ADDRESS)
|
|
|
|
|
enc.address(address)
|
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-04 15:08:03 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
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()
|
2021-06-08 11:16:56 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('toRedistribution')
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.uint256(participants)
|
|
|
|
|
enc.uint256(demurrage_modifier_ppm)
|
|
|
|
|
enc.uint256(value)
|
|
|
|
|
enc.uint256(period)
|
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-08 11:16:56 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def to_redistribution_period(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-04 13:14:26 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('toRedistributionPeriod')
|
2023-02-08 09:26:15 +01:00
|
|
|
|
v = strip_0x(redistribution)
|
|
|
|
|
enc.typ_literal('(uint32,uint72,uint104)')
|
|
|
|
|
enc.bytes32(v[:64])
|
|
|
|
|
enc.bytes32(v[64:128])
|
|
|
|
|
enc.bytes32(v[128:192])
|
2021-06-04 13:14:26 +02:00
|
|
|
|
data = add_0x(enc.get())
|
2021-06-06 05:57:39 +02:00
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-06 05:57:39 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2023-02-08 09:26:15 +01:00
|
|
|
|
# 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')
|
|
|
|
|
# v = strip_0x(redistribution)
|
|
|
|
|
# enc.typ_literal('(uint32,uint72,uint104)')
|
|
|
|
|
# #enc.typ(ABIContractType.BYTES32)
|
|
|
|
|
# enc.bytes32(v[:64])
|
|
|
|
|
# enc.bytes32(v[64:128])
|
|
|
|
|
# enc.bytes32(v[128:192])
|
|
|
|
|
# data = add_0x(enc.get())
|
|
|
|
|
# tx = self.template(sender_address, contract_address)
|
|
|
|
|
# tx = self.set_code(tx, data)
|
|
|
|
|
# o['params'].append(self.normalize(tx))
|
|
|
|
|
# o['params'].append('latest')
|
|
|
|
|
# o = j.finalize(o)
|
|
|
|
|
# return o
|
|
|
|
|
#
|
2021-06-06 09:34:18 +02:00
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def to_redistribution_supply(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-06 09:34:18 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('toRedistributionSupply')
|
2023-02-08 09:26:15 +01:00
|
|
|
|
v = strip_0x(redistribution)
|
|
|
|
|
enc.typ_literal('(uint32,uint72,uint104)')
|
|
|
|
|
enc.bytes32(v[:64])
|
|
|
|
|
enc.bytes32(v[64:128])
|
|
|
|
|
enc.bytes32(v[128:192])
|
2021-06-06 09:34:18 +02:00
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-06 09:34:18 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def to_redistribution_demurrage_modifier(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-06 09:34:18 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('toRedistributionDemurrageModifier')
|
2023-02-08 09:26:15 +01:00
|
|
|
|
v = strip_0x(redistribution)
|
|
|
|
|
enc.typ_literal('(uint32,uint72,uint104)')
|
|
|
|
|
enc.bytes32(v[:64])
|
|
|
|
|
enc.bytes32(v[64:128])
|
|
|
|
|
enc.bytes32(v[128:192])
|
2021-06-06 09:34:18 +02:00
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-06 09:34:18 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def base_balance_of(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-06 05:57:39 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('baseBalanceOf')
|
|
|
|
|
enc.typ(ABIContractType.ADDRESS)
|
|
|
|
|
enc.address(address)
|
|
|
|
|
data = add_0x(enc.get())
|
2021-06-04 13:14:26 +02:00
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-04 13:14:26 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2022-03-02 10:01:50 +01:00
|
|
|
|
def apply_demurrage(self, contract_address, sender_address, limit=0, tx_format=TxFormat.JSONRPC):
|
|
|
|
|
if limit == 0:
|
|
|
|
|
return self.transact_noarg('applyDemurrage', contract_address, sender_address)
|
|
|
|
|
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('applyDemurrageLimited')
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.uint256(limit)
|
|
|
|
|
data = enc.get()
|
|
|
|
|
tx = self.template(sender_address, contract_address, use_nonce=True)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
tx = self.finalize(tx, tx_format)
|
|
|
|
|
return tx
|
2021-06-04 09:05:08 +02:00
|
|
|
|
|
|
|
|
|
|
2021-06-04 13:14:26 +02:00
|
|
|
|
def change_period(self, contract_address, sender_address):
|
|
|
|
|
return self.transact_noarg('changePeriod', contract_address, sender_address)
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
def apply_redistribution_on_account(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('applyRedistributionOnAccount')
|
|
|
|
|
enc.typ(ABIContractType.ADDRESS)
|
|
|
|
|
enc.address(address)
|
|
|
|
|
data = enc.get()
|
|
|
|
|
tx = self.template(sender_address, contract_address, use_nonce=True)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
tx = self.finalize(tx, tx_format)
|
|
|
|
|
return tx
|
2021-07-04 12:10:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
|
def actual_period(self, contract_address, sender_address=ZERO_ADDRESS):
|
|
|
|
|
return self.call_noarg('actualPeriod', contract_address, sender_address=sender_address)
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 14:03:07 +02:00
|
|
|
|
def period_start(self, contract_address, sender_address=ZERO_ADDRESS):
|
2021-06-04 15:59:42 +02:00
|
|
|
|
return self.call_noarg('periodStart', contract_address, sender_address=sender_address)
|
2021-06-04 14:03:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def period_duration(self, contract_address, sender_address=ZERO_ADDRESS):
|
2021-06-04 15:59:42 +02:00
|
|
|
|
return self.call_noarg('periodDuration', contract_address, sender_address=sender_address)
|
2021-06-04 14:03:07 +02:00
|
|
|
|
|
|
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
|
def demurrage_amount(self, contract_address, sender_address=ZERO_ADDRESS):
|
|
|
|
|
return self.call_noarg('demurrageAmount', contract_address, sender_address=sender_address)
|
|
|
|
|
|
|
|
|
|
|
2022-05-30 09:53:22 +02:00
|
|
|
|
def demurrage_timestamp(self, contract_address, sender_address=ZERO_ADDRESS):
|
|
|
|
|
return self.call_noarg('demurrageTimestamp', contract_address, sender_address=sender_address)
|
|
|
|
|
|
|
|
|
|
|
2021-06-05 11:58:35 +02:00
|
|
|
|
def supply_cap(self, contract_address, sender_address=ZERO_ADDRESS):
|
|
|
|
|
return self.call_noarg('supplyCap', contract_address, sender_address=sender_address)
|
|
|
|
|
|
|
|
|
|
|
2023-02-08 09:26:15 +01:00
|
|
|
|
# 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')
|
|
|
|
|
# enc.typ(ABIContractType.UINT256)
|
|
|
|
|
# enc.typ(ABIContractType.UINT256)
|
|
|
|
|
# enc.uint256(value)
|
|
|
|
|
# enc.uint256(period)
|
|
|
|
|
# data = add_0x(enc.get())
|
|
|
|
|
# tx = self.template(sender_address, contract_address)
|
|
|
|
|
# tx = self.set_code(tx, data)
|
|
|
|
|
# o['params'].append(self.normalize(tx))
|
|
|
|
|
# o['params'].append('latest')
|
|
|
|
|
# o = j.finalize(o)
|
|
|
|
|
# return o
|
|
|
|
|
#
|
2021-06-08 07:38:10 +02:00
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def decay_by(self, contract_address, value, period, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-08 07:38:10 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('decayBy')
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.uint256(value)
|
|
|
|
|
enc.uint256(period)
|
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-08 07:38:10 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def get_distribution(self, contract_address, supply, demurrage_amount, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-08 09:45:24 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('getDistribution')
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.typ(ABIContractType.UINT256)
|
|
|
|
|
enc.uint256(supply)
|
|
|
|
|
enc.uint256(demurrage_amount)
|
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-08 09:45:24 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
2021-06-28 11:46:05 +02:00
|
|
|
|
def get_distribution_from_redistribution(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
|
|
|
j = JSONRPCRequest(id_generator)
|
|
|
|
|
o = j.template()
|
2021-06-08 11:16:56 +02:00
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
|
enc = ABIContractEncoder()
|
|
|
|
|
enc.method('getDistributionFromRedistribution')
|
2023-02-08 09:26:15 +01:00
|
|
|
|
v = strip_0x(redistribution)
|
|
|
|
|
enc.typ_literal('(uint32,uint72,uint104)')
|
|
|
|
|
enc.bytes32(v[:64])
|
|
|
|
|
enc.bytes32(v[64:128])
|
|
|
|
|
enc.bytes32(v[128:192])
|
2021-06-08 11:16:56 +02:00
|
|
|
|
data = add_0x(enc.get())
|
|
|
|
|
tx = self.template(sender_address, contract_address)
|
|
|
|
|
tx = self.set_code(tx, data)
|
|
|
|
|
o['params'].append(self.normalize(tx))
|
|
|
|
|
o['params'].append('latest')
|
2021-06-28 11:46:05 +02:00
|
|
|
|
o = j.finalize(o)
|
2021-06-08 11:16:56 +02:00
|
|
|
|
return o
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
@classmethod
|
2021-06-04 09:05:08 +02:00
|
|
|
|
def parse_actual_period(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
@classmethod
|
2021-06-04 14:03:07 +02:00
|
|
|
|
def parse_period_start(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
@classmethod
|
2021-06-04 14:03:07 +02:00
|
|
|
|
def parse_period_duration(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
@classmethod
|
2021-06-04 09:05:08 +02:00
|
|
|
|
def parse_demurrage_amount(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
2021-06-04 09:29:52 +02:00
|
|
|
|
|
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
@classmethod
|
2021-06-04 11:48:17 +02:00
|
|
|
|
def parse_remainder(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
@classmethod
|
2021-06-04 09:29:52 +02:00
|
|
|
|
def parse_to_base_amount(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
|
|
|
|
|
2021-06-04 13:14:26 +02:00
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
@classmethod
|
2021-06-04 13:14:26 +02:00
|
|
|
|
def parse_redistributions(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.BYTES32, v)
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
@classmethod
|
|
|
|
|
def parse_account_period(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.ADDRESS, v)
|
2021-06-04 13:14:26 +02:00
|
|
|
|
|
2021-06-04 09:29:52 +02:00
|
|
|
|
|
2021-06-04 15:08:03 +02:00
|
|
|
|
@classmethod
|
|
|
|
|
def parse_to_redistribution_period(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
2021-06-05 11:58:35 +02:00
|
|
|
|
|
|
|
|
|
|
2021-06-06 09:34:18 +02:00
|
|
|
|
@classmethod
|
|
|
|
|
def parse_to_redistribution_item(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
|
|
|
|
|
|
|
|
|
|
2021-06-05 11:58:35 +02:00
|
|
|
|
@classmethod
|
|
|
|
|
def parse_supply_cap(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
2021-06-08 07:38:10 +02:00
|
|
|
|
|
2022-12-05 19:25:04 +01:00
|
|
|
|
|
2021-06-08 07:38:10 +02:00
|
|
|
|
@classmethod
|
|
|
|
|
def parse_grow_by(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def parse_decay_by(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
2021-06-08 09:45:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def parse_get_distribution(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|
2021-07-04 12:10:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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)
|
2022-12-05 19:25:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def parse_total_burned(self, v):
|
|
|
|
|
return abi_decode_single(ABIContractType.UINT256, v)
|