2021-05-06 10:35:58 +02:00
|
|
|
"""Deploy sarafu token
|
|
|
|
|
|
|
|
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
|
|
|
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# standard imports
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
|
2021-06-05 14:03:50 +02:00
|
|
|
# external imports
|
|
|
|
import confini
|
2021-05-06 10:35:58 +02:00
|
|
|
from chainlib.eth.connection import EthHTTPConnection
|
|
|
|
from chainlib.eth.tx import receipt
|
|
|
|
from chainlib.eth.constant import ZERO_ADDRESS
|
2021-08-24 21:49:06 +02:00
|
|
|
import chainlib.eth.cli
|
2023-01-11 14:35:24 +01:00
|
|
|
from chainlib.eth.settings import process_settings
|
|
|
|
from chainlib.settings import ChainSettings
|
2023-01-11 14:06:09 +01:00
|
|
|
from chainlib.eth.cli.arg import (
|
|
|
|
Arg,
|
|
|
|
ArgFlag,
|
|
|
|
process_args,
|
|
|
|
)
|
|
|
|
from chainlib.eth.cli.config import (
|
|
|
|
Config,
|
|
|
|
process_config,
|
|
|
|
)
|
2023-01-11 14:35:24 +01:00
|
|
|
from chainlib.eth.cli.log import process_log
|
2021-05-06 10:35:58 +02:00
|
|
|
|
|
|
|
# local imports
|
2021-08-24 21:49:06 +02:00
|
|
|
import erc20_demurrage_token
|
2021-06-05 14:03:50 +02:00
|
|
|
from erc20_demurrage_token import (
|
|
|
|
DemurrageToken,
|
|
|
|
DemurrageTokenSettings,
|
|
|
|
)
|
2021-05-06 10:35:58 +02:00
|
|
|
|
2023-01-11 14:35:24 +01:00
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
|
2023-01-11 14:06:09 +01:00
|
|
|
def process_config_local(config, arg, args, flags):
|
2023-01-11 14:35:24 +01:00
|
|
|
config.add(args.token_name, 'TOKEN_NAME', False)
|
|
|
|
config.add(args.token_symbol, 'TOKEN_SYMBOL', False)
|
|
|
|
config.add(args.token_decimals, 'TOKEN_DECIMALS', False)
|
2023-01-11 14:06:09 +01:00
|
|
|
config.add(args.sink_address, 'TOKEN_SINK_ADDRESS', False)
|
|
|
|
config.add(args.redistribution_period, 'TOKEN_REDISTRIBUTION_PERIOD', False)
|
|
|
|
config.add(args.demurrage_level, 'TOKEN_DEMURRAGE_LEVEL', False)
|
2023-01-11 14:35:24 +01:00
|
|
|
config.add(0, 'TOKEN_SUPPLY_LIMIT', False)
|
|
|
|
return config
|
2021-05-06 10:35:58 +02:00
|
|
|
|
|
|
|
|
2023-01-11 14:06:09 +01:00
|
|
|
arg_flags = ArgFlag()
|
|
|
|
arg = Arg(arg_flags)
|
|
|
|
flags = arg_flags.STD_WRITE | arg_flags.EXEC | arg_flags.WALLET
|
2021-08-24 21:49:06 +02:00
|
|
|
|
2023-01-11 14:06:09 +01:00
|
|
|
argparser = chainlib.eth.cli.ArgumentParser()
|
|
|
|
argparser = process_args(argparser, arg, flags)
|
2021-08-24 21:49:06 +02:00
|
|
|
argparser.add_argument('--name', dest='token_name', type=str, help='Token name')
|
|
|
|
argparser.add_argument('--symbol', dest='token_symbol', required=True, type=str, help='Token symbol')
|
2022-03-14 13:58:45 +01:00
|
|
|
argparser.add_argument('--decimals', dest='token_decimals', type=int, help='Token decimals')
|
|
|
|
argparser.add_argument('--sink-address', dest='sink_address', type=str, help='demurrage level,ppm per minute')
|
2023-01-11 14:06:09 +01:00
|
|
|
#argparser.add_argument('--supply-limit', dest='supply_limit', type=int, help='token supply limit (0 = no limit)')
|
|
|
|
argparser.add_argument('--redistribution-period', dest='redistribution_period', type=int, help='redistribution period, minutes (0 = deactivate)') # default 10080 = week
|
|
|
|
#argparser.add_argument('--multi', action='store_true', help='automatic redistribution')
|
2021-06-05 14:03:50 +02:00
|
|
|
argparser.add_argument('--demurrage-level', dest='demurrage_level', type=int, help='demurrage level, ppm per minute')
|
2021-05-06 10:35:58 +02:00
|
|
|
args = argparser.parse_args()
|
|
|
|
|
2023-01-11 14:06:09 +01:00
|
|
|
logg = process_log(args, logg)
|
2021-06-05 14:03:50 +02:00
|
|
|
|
2023-01-11 14:06:09 +01:00
|
|
|
config = Config()
|
|
|
|
config = process_config(config, arg, args, flags)
|
|
|
|
config = process_config_local(config, arg, args, flags)
|
|
|
|
logg.debug('config loaded:\n{}'.format(config))
|
2021-08-24 21:49:06 +02:00
|
|
|
|
2023-01-11 14:06:09 +01:00
|
|
|
settings = ChainSettings()
|
|
|
|
settings = process_settings(settings, config)
|
|
|
|
logg.debug('settings loaded:\n{}'.format(settings))
|
2021-08-24 21:49:06 +02:00
|
|
|
|
|
|
|
|
2021-05-06 10:35:58 +02:00
|
|
|
def main():
|
2023-01-11 14:35:24 +01:00
|
|
|
chain_spec = settings.get('CHAIN_SPEC')
|
2023-01-11 14:06:09 +01:00
|
|
|
conn = settings.get('CONN')
|
|
|
|
signer = settings.get('SIGNER')
|
|
|
|
signer_address = settings.get('SENDER_ADDRESS')
|
2021-08-24 21:49:06 +02:00
|
|
|
|
2023-01-11 14:06:09 +01:00
|
|
|
gas_oracle = settings.get('FEE_ORACLE')
|
|
|
|
nonce_oracle = settings.get('NONCE_ORACLE')
|
2021-08-24 21:49:06 +02:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
c = DemurrageToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
2023-01-11 14:06:09 +01:00
|
|
|
token_settings = DemurrageTokenSettings()
|
|
|
|
token_settings.name = config.get('TOKEN_NAME')
|
|
|
|
token_settings.symbol = config.get('TOKEN_SYMBOL')
|
|
|
|
token_settings.decimals = int(config.get('TOKEN_DECIMALS'))
|
|
|
|
token_settings.demurrage_level = int(config.get('TOKEN_DEMURRAGE_LEVEL'))
|
|
|
|
token_settings.period_minutes = int(config.get('TOKEN_REDISTRIBUTION_PERIOD'))
|
|
|
|
token_settings.sink_address = config.get('TOKEN_SINK_ADDRESS')
|
2021-06-05 14:03:50 +02:00
|
|
|
|
2021-05-06 10:35:58 +02:00
|
|
|
(tx_hash_hex, o) = c.constructor(
|
|
|
|
signer_address,
|
2023-01-11 14:06:09 +01:00
|
|
|
token_settings,
|
2021-08-24 21:49:06 +02:00
|
|
|
redistribute=config.true('_MULTI'),
|
2021-06-05 14:03:50 +02:00
|
|
|
cap=int(config.get('TOKEN_SUPPLY_LIMIT')),
|
2021-05-06 10:35:58 +02:00
|
|
|
)
|
2023-01-11 14:06:09 +01:00
|
|
|
if settings.get('RPC_SEND'):
|
2021-08-24 21:49:06 +02:00
|
|
|
conn.do(o)
|
2023-01-11 14:06:09 +01:00
|
|
|
if config.true('_WAIT'):
|
2021-08-24 21:49:06 +02:00
|
|
|
r = conn.wait(tx_hash_hex)
|
2021-05-06 10:35:58 +02:00
|
|
|
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)
|
|
|
|
else:
|
|
|
|
print(tx_hash_hex)
|
|
|
|
|
2021-08-24 21:49:06 +02:00
|
|
|
else:
|
|
|
|
print(o)
|
|
|
|
|
2021-05-06 10:35:58 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|