mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-11-22 08:16:47 +01:00
Add steps option to demurrage cli
This commit is contained in:
parent
1387451e01
commit
127c67e665
@ -1,3 +1,7 @@
|
|||||||
|
- 0.1.1
|
||||||
|
* Settable demurrage steps for apply demurrage cli tool
|
||||||
|
- 0.1.0
|
||||||
|
* Dependency upgrades
|
||||||
- 0.0.11
|
- 0.0.11
|
||||||
* Apply demurrage cli tool
|
* Apply demurrage cli tool
|
||||||
- 0.0.10
|
- 0.0.10
|
||||||
|
@ -11,6 +11,8 @@ import os
|
|||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import datetime
|
||||||
|
import math
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import confini
|
import confini
|
||||||
@ -25,10 +27,16 @@ from chainlib.eth.gas import (
|
|||||||
RPCGasOracle,
|
RPCGasOracle,
|
||||||
OverrideGasOracle,
|
OverrideGasOracle,
|
||||||
)
|
)
|
||||||
|
from chainlib.eth.block import (
|
||||||
|
block_latest,
|
||||||
|
block_by_number,
|
||||||
|
Block,
|
||||||
|
)
|
||||||
from chainlib.eth.connection import EthHTTPConnection
|
from chainlib.eth.connection import EthHTTPConnection
|
||||||
from chainlib.eth.tx import receipt
|
from chainlib.eth.tx import receipt
|
||||||
from chainlib.eth.constant import ZERO_ADDRESS
|
from chainlib.eth.constant import ZERO_ADDRESS
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
|
from hexathon import to_int as hex_to_int
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
import erc20_demurrage_token
|
import erc20_demurrage_token
|
||||||
@ -47,8 +55,11 @@ config_dir = os.path.join(data_dir, 'config')
|
|||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC
|
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
|
argparser.add_argument('--steps', type=int, default=0, help='Max demurrage steps to apply per round')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, default_fee_limit=DemurrageToken.gas(), base_config_dir=config_dir)
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, default_fee_limit=DemurrageToken.gas(), base_config_dir=config_dir)
|
||||||
|
config.add(args.steps, '_STEPS', False)
|
||||||
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
wallet = chainlib.eth.cli.Wallet()
|
wallet = chainlib.eth.cli.Wallet()
|
||||||
wallet.from_config(config)
|
wallet.from_config(config)
|
||||||
@ -60,30 +71,73 @@ chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
signer = rpc.get_signer()
|
o = block_latest()
|
||||||
signer_address = rpc.get_sender_address()
|
r = conn.do(o)
|
||||||
|
|
||||||
|
block_start_number = None
|
||||||
|
try:
|
||||||
|
block_start_number = hex_to_int(r)
|
||||||
|
except TypeError:
|
||||||
|
block_start_number = int(r)
|
||||||
|
|
||||||
|
o = block_by_number(block_start_number)
|
||||||
|
r = conn.do(o)
|
||||||
|
|
||||||
|
block_start = Block(r)
|
||||||
|
block_start_timestamp = block_start.timestamp
|
||||||
|
block_start_datetime = datetime.datetime.fromtimestamp(block_start_timestamp)
|
||||||
|
|
||||||
gas_oracle = rpc.get_gas_oracle()
|
gas_oracle = rpc.get_gas_oracle()
|
||||||
nonce_oracle = rpc.get_nonce_oracle()
|
c = DemurrageToken(chain_spec, gas_oracle=gas_oracle)
|
||||||
|
o = c.demurrage_timestamp(config.get('_EXEC_ADDRESS'))
|
||||||
|
r = conn.do(o)
|
||||||
|
|
||||||
c = DemurrageToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
demurrage_timestamp = None
|
||||||
(tx_hash_hex, o) = c.apply_demurrage(config.get('_EXEC_ADDRESS'), signer_address)
|
try:
|
||||||
if config.get('_RPC_SEND'):
|
demurrage_timestamp = hex_to_int(r)
|
||||||
conn.do(o)
|
except TypeError:
|
||||||
if config.get('_WAIT'):
|
demurrage_timestamp = int(r)
|
||||||
r = conn.wait(tx_hash_hex)
|
demurrage_datetime = datetime.datetime.fromtimestamp(demurrage_timestamp)
|
||||||
if r['status'] == 0:
|
|
||||||
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
|
||||||
sys.exit(1)
|
|
||||||
# TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
|
|
||||||
address = r['contractAddress']
|
|
||||||
|
|
||||||
print(address)
|
total_seconds = block_start_timestamp - demurrage_timestamp
|
||||||
else:
|
total_steps = total_seconds / 60
|
||||||
|
|
||||||
|
if total_steps < 1.0:
|
||||||
|
logg.error('only {} seconds since last demurrage application, skipping'.format(total_seconds))
|
||||||
|
return
|
||||||
|
|
||||||
|
logg.debug('block start is at {} demurrage is at {} -> {} minutes'.format(
|
||||||
|
block_start_datetime,
|
||||||
|
demurrage_datetime,
|
||||||
|
total_steps,
|
||||||
|
))
|
||||||
|
|
||||||
|
rounds = 1
|
||||||
|
if config.get('_STEPS') > 0:
|
||||||
|
rounds = math.ceil(total_steps / config.get('_STEPS'))
|
||||||
|
|
||||||
|
logg.info('will perform {} rounds of {} steps'.format(rounds, config.get('_STEPS')))
|
||||||
|
|
||||||
|
last_tx_hash = None
|
||||||
|
for i in range(rounds):
|
||||||
|
signer = rpc.get_signer()
|
||||||
|
signer_address = rpc.get_sender_address()
|
||||||
|
|
||||||
|
nonce_oracle = rpc.get_nonce_oracle()
|
||||||
|
|
||||||
|
c = DemurrageToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash_hex, o) = c.apply_demurrage(config.get('_EXEC_ADDRESS'), signer_address, limit=config.get('_STEPS'))
|
||||||
|
if config.get('_RPC_SEND'):
|
||||||
print(tx_hash_hex)
|
print(tx_hash_hex)
|
||||||
|
conn.do(o)
|
||||||
|
if config.get('_WAIT_ALL') or (i == rounds - 1 and config.get('_WAIT')):
|
||||||
|
r = conn.wait(tx_hash_hex)
|
||||||
|
if r['status'] == 0:
|
||||||
|
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print(o)
|
||||||
|
|
||||||
else:
|
|
||||||
print(o)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -380,6 +380,10 @@ class DemurrageToken(ERC20):
|
|||||||
return self.call_noarg('demurrageAmount', contract_address, sender_address=sender_address)
|
return self.call_noarg('demurrageAmount', contract_address, sender_address=sender_address)
|
||||||
|
|
||||||
|
|
||||||
|
def demurrage_timestamp(self, contract_address, sender_address=ZERO_ADDRESS):
|
||||||
|
return self.call_noarg('demurrageTimestamp', contract_address, sender_address=sender_address)
|
||||||
|
|
||||||
|
|
||||||
def supply_cap(self, contract_address, sender_address=ZERO_ADDRESS):
|
def supply_cap(self, contract_address, sender_address=ZERO_ADDRESS):
|
||||||
return self.call_noarg('supplyCap', contract_address, sender_address=sender_address)
|
return self.call_noarg('supplyCap', contract_address, sender_address=sender_address)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = erc20-demurrage-token
|
name = erc20-demurrage-token
|
||||||
version = 0.1.0
|
version = 0.1.1
|
||||||
description = ERC20 token with redistributed continual demurrage
|
description = ERC20 token with redistributed continual demurrage
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
@ -25,12 +25,13 @@ licence_files =
|
|||||||
|
|
||||||
[options]
|
[options]
|
||||||
include_package_data = True
|
include_package_data = True
|
||||||
python_requires = >= 3.6
|
python_requires = >= 3.7
|
||||||
packages =
|
packages =
|
||||||
erc20_demurrage_token
|
erc20_demurrage_token
|
||||||
erc20_demurrage_token.runnable
|
erc20_demurrage_token.runnable
|
||||||
erc20_demurrage_token.data
|
erc20_demurrage_token.data
|
||||||
erc20_demurrage_token.sim
|
erc20_demurrage_token.sim
|
||||||
|
erc20_demurrage_token.unittest
|
||||||
|
|
||||||
[options.package_data]
|
[options.package_data]
|
||||||
* =
|
* =
|
||||||
|
Loading…
Reference in New Issue
Block a user