mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-11-22 00:06:46 +01:00
Rehabilitate deploy script
This commit is contained in:
parent
b5421cdd4e
commit
996c0224cf
@ -12,7 +12,8 @@ import json
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
# third-party imports
|
||||
# external imports
|
||||
import confini
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||
from chainlib.chain import ChainSpec
|
||||
@ -29,7 +30,10 @@ from chainlib.eth.tx import receipt
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
|
||||
# local imports
|
||||
from erc20_demurrage_token import DemurrageToken
|
||||
from erc20_demurrage_token import (
|
||||
DemurrageToken,
|
||||
DemurrageTokenSettings,
|
||||
)
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@ -37,7 +41,10 @@ logg = logging.getLogger()
|
||||
script_dir = os.path.dirname(__file__)
|
||||
data_dir = os.path.join(script_dir, '..', 'data')
|
||||
|
||||
default_config_dir = os.environ.get('CONFINI_DIR', '/usr/local/share/sarafu-token')
|
||||
|
||||
argparser = argparse.ArgumentParser()
|
||||
argparser.add_argument('-c', '--config', dest='c', type=str, default=default_config_dir, help='configuration directory')
|
||||
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
|
||||
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
|
||||
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
|
||||
@ -50,11 +57,12 @@ argparser.add_argument('--name', type=str, help='Token name')
|
||||
argparser.add_argument('--decimals', default=6, type=int, help='Token decimals')
|
||||
argparser.add_argument('--gas-price', type=int, dest='gas_price', help='Override gas price')
|
||||
argparser.add_argument('--nonce', type=int, help='Override transaction nonce')
|
||||
argparser.add_argument('--sink-address', default=ZERO_ADDRESS, type=str, help='demurrage level,ppm per minute')
|
||||
argparser.add_argument('--redistribution-period', default=10080, type=int, help='redistribution period, minutes') # default 10080 = week
|
||||
argparser.add_argument('--sink-address', dest='sink_address', default=ZERO_ADDRESS, type=str, help='demurrage level,ppm per minute')
|
||||
argparser.add_argument('--supply-limit', dest='supply_limit', type=int, help='token supply limit (0 = no limit)')
|
||||
argparser.add_argument('--redistribution-period', type=int, help='redistribution period, minutes (0 = deactivate)') # default 10080 = week
|
||||
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
|
||||
argparser.add_argument('symbol', default='SRF', type=str, help='Token symbol')
|
||||
argparser.add_argument('demurrage_level', type=int, help='demurrage level, ppm per minute')
|
||||
argparser.add_argument('--symbol', type=str, help='Token symbol')
|
||||
argparser.add_argument('--demurrage-level', dest='demurrage_level', type=int, help='demurrage level, ppm per minute')
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.vv:
|
||||
@ -65,6 +73,26 @@ elif args.v:
|
||||
block_last = args.w
|
||||
block_all = args.ww
|
||||
|
||||
# process config
|
||||
config = confini.Config(args.c)
|
||||
config.process()
|
||||
args_override = {
|
||||
'TOKEN_REDISTRIBUTION_PERIOD': getattr(args, 'redistribution_period'),
|
||||
'TOKEN_DEMURRAGE_LEVEL': getattr(args, 'demurrage_level'),
|
||||
'TOKEN_SUPPLY_LIMIT': getattr(args, 'supply_limit'),
|
||||
'TOKEN_SYMBOL': getattr(args, 'symbol'),
|
||||
'TOKEN_NAME': getattr(args, 'name'),
|
||||
'TOKEN_DECIMALS': getattr(args, 'decimals'),
|
||||
'TOKEN_SINK_ADDRESS': getattr(args, 'sink_address'),
|
||||
'SESSION_CHAIN_SPEC': getattr(args, 'i'),
|
||||
'ETH_PROVIDER': getattr(args, 'p'),
|
||||
}
|
||||
if config.get('TOKEN_NAME') == None:
|
||||
logg.info('token name not set, using symbol {} as name'.format(config.get('TOKEN_SYMBOL')))
|
||||
config.add(config.get('TOKEN_SYMBOL'), 'TOKEN_NAME', True)
|
||||
config.dict_override(args_override, 'cli args')
|
||||
logg.debug('config loaded:\n{}'.format(config))
|
||||
|
||||
passphrase_env = 'ETH_PASSPHRASE'
|
||||
if args.env_prefix != None:
|
||||
passphrase_env = args.env_prefix + '_' + passphrase_env
|
||||
@ -104,14 +132,19 @@ if token_name == None:
|
||||
|
||||
def main():
|
||||
c = DemurrageToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
||||
settings = DemurrageTokenSettings()
|
||||
settings.name = config.get('TOKEN_NAME')
|
||||
settings.symbol = config.get('TOKEN_SYMBOL')
|
||||
settings.decimals = int(config.get('TOKEN_DECIMALS'))
|
||||
settings.demurrage_level = int(config.get('TOKEN_DEMURRAGE_LEVEL'))
|
||||
settings.period_minutes = int(config.get('TOKEN_REDISTRIBUTION_PERIOD'))
|
||||
settings.sink_address = config.get('TOKEN_SINK_ADDRESS')
|
||||
|
||||
(tx_hash_hex, o) = c.constructor(
|
||||
signer_address,
|
||||
token_name,
|
||||
args.symbol,
|
||||
args.decimals,
|
||||
args.demurrage_level,
|
||||
args.redistribution_period,
|
||||
args.sink_address,
|
||||
settings,
|
||||
redistribute=settings.period_minutes > 0,
|
||||
cap=int(config.get('TOKEN_SUPPLY_LIMIT')),
|
||||
)
|
||||
if dummy:
|
||||
print(tx_hash_hex)
|
||||
|
@ -84,6 +84,7 @@ class DemurrageToken(ERC20):
|
||||
name += 'Cap'
|
||||
else:
|
||||
name += 'Nocap'
|
||||
logg.debug('bytecode name {}'.format(name))
|
||||
return name
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user