publish.py (6028B)
1 """Deploy sarafu token 2 3 .. moduleauthor:: Louis Holbrook <dev@holbrook.no> 4 .. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 5 6 """ 7 8 # standard imports 9 import sys 10 import os 11 import json 12 import argparse 13 import logging 14 15 # external imports 16 import confini 17 from funga.eth.signer import EIP155Signer 18 from funga.eth.keystore.dict import DictKeystore 19 from chainlib.chain import ChainSpec 20 from chainlib.eth.nonce import ( 21 RPCNonceOracle, 22 OverrideNonceOracle, 23 ) 24 from chainlib.eth.gas import ( 25 RPCGasOracle, 26 OverrideGasOracle, 27 ) 28 from chainlib.eth.connection import EthHTTPConnection 29 from chainlib.eth.tx import receipt 30 from chainlib.eth.constant import ZERO_ADDRESS 31 import chainlib.eth.cli 32 from chainlib.eth.cli.arg import ( 33 Arg, 34 ArgFlag, 35 process_args, 36 ) 37 from chainlib.eth.cli.config import ( 38 Config, 39 process_config, 40 ) 41 from chainlib.eth.cli.log import process_log 42 from chainlib.eth.settings import process_settings 43 from chainlib.eth.address import to_checksum_address 44 from chainlib.settings import ChainSettings 45 46 from dexif import to_fixed 47 48 # local imports 49 import erc20_demurrage_token 50 from erc20_demurrage_token import ( 51 DemurrageToken, 52 DemurrageTokenSettings, 53 ) 54 55 logg = logging.getLogger() 56 57 script_dir = os.path.dirname(__file__) 58 data_dir = os.path.join(script_dir, '..', 'data') 59 60 config_dir = os.path.join(data_dir, 'config') 61 62 63 def process_config_local(config, arg, args, flags): 64 config.add(args.token_name, 'TOKEN_NAME') 65 config.add(args.token_symbol, 'TOKEN_SYMBOL') 66 config.add(args.token_decimals, 'TOKEN_DECIMALS') 67 sink_address = to_checksum_address(args.sink_address) 68 config.add(sink_address, 'TOKEN_SINK_ADDRESS') 69 config.add(args.redistribution_period, 'TOKEN_REDISTRIBUTION_PERIOD') 70 71 v = (1 - (args.demurrage_level / 1000000)) ** (1 / config.get('TOKEN_REDISTRIBUTION_PERIOD')) 72 if v >= 1.0: 73 raise ValueError('demurrage level must be less than 100%') 74 demurrage_level = to_fixed(v) 75 logg.info('v {} demurrage level {}'.format(v, demurrage_level)) 76 config.add(demurrage_level, 'TOKEN_DEMURRAGE_LEVEL') 77 return config 78 79 80 arg_flags = ArgFlag() 81 arg = Arg(arg_flags) 82 flags = arg_flags.STD_WRITE | arg_flags.WALLET 83 84 argparser = chainlib.eth.cli.ArgumentParser(arg_flags) 85 argparser = process_args(argparser, arg, flags) 86 argparser.add_argument('--name', dest='token_name', type=str, help='Token name') 87 argparser.add_argument('--symbol', dest='token_symbol', required=True, type=str, help='Token symbol') 88 argparser.add_argument('--decimals', dest='token_decimals', type=int, help='Token decimals') 89 argparser.add_argument('--sink-address', dest='sink_address', type=str, help='demurrage level,ppm per minute') 90 argparser.add_argument('--redistribution-period', type=int, help='redistribution period, minutes (0 = deactivate)') # default 10080 = week 91 argparser.add_argument('--demurrage-level', dest='demurrage_level', type=int, help='demurrage level, ppm per period') 92 args = argparser.parse_args() 93 94 logg = process_log(args, logg) 95 96 config = Config() 97 config = process_config(config, arg, args, flags) 98 config = process_config_local(config, arg, args, flags) 99 logg.debug('config loaded:\n{}'.format(config)) 100 101 settings = ChainSettings() 102 settings = process_settings(settings, config) 103 logg.debug('settings loaded:\n{}'.format(settings)) 104 105 106 #extra_args = { 107 # 'redistribution_period': 'TOKEN_REDISTRIBUTION_PERIOD', 108 # 'demurrage_level': 'TOKEN_DEMURRAGE_LEVEL', 109 # 'supply_limit': 'TOKEN_SUPPLY_LIMIT', 110 # 'token_name': 'TOKEN_NAME', 111 # 'token_symbol': 'TOKEN_SYMBOL', 112 # 'token_decimals': 'TOKEN_DECIMALS', 113 # 'sink_address': 'TOKEN_SINK_ADDRESS', 114 # 'multi': None, 115 # } 116 #config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=DemurrageToken.gas(), base_config_dir=config_dir) 117 # 118 #if not bool(config.get('TOKEN_NAME')): 119 # logg.info('token name not set, using symbol {} as name'.format(config.get('TOKEN_SYMBOL'))) 120 # config.add(config.get('TOKEN_SYMBOL'), 'TOKEN_NAME', True) 121 # 122 #if config.get('TOKEN_SUPPLY_LIMIT') == None: 123 # config.add(0, 'TOKEN_SUPPLY_LIMIT', True) 124 # 125 #if config.get('TOKEN_REDISTRIBUTION_PERIOD') == None: 126 # config.add(10800, 'TOKEN_REDISTRIBUTION_PERIOD', True) 127 #logg.debug('config loaded:\n{}'.format(config)) 128 # 129 #wallet = chainlib.eth.cli.Wallet() 130 #wallet.from_config(config) 131 # 132 #rpc = chainlib.eth.cli.Rpc(wallet=wallet) 133 #conn = rpc.connect_by_config(config) 134 # 135 #chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC')) 136 137 def main(): 138 conn = settings.get('CONN') 139 c = DemurrageToken( 140 settings.get('CHAIN_SPEC'), 141 signer=settings.get('SIGNER'), 142 gas_oracle=settings.get('FEE_ORACLE'), 143 nonce_oracle=settings.get('NONCE_ORACLE'), 144 ) 145 token_settings = DemurrageTokenSettings() 146 token_settings.name = config.get('TOKEN_NAME') 147 token_settings.symbol = config.get('TOKEN_SYMBOL') 148 token_settings.decimals = int(config.get('TOKEN_DECIMALS')) 149 token_settings.demurrage_level = int(config.get('TOKEN_DEMURRAGE_LEVEL')) 150 token_settings.period_minutes = int(config.get('TOKEN_REDISTRIBUTION_PERIOD')) 151 token_settings.sink_address = config.get('TOKEN_SINK_ADDRESS') 152 153 (tx_hash_hex, o) = c.constructor( 154 settings.get('SENDER_ADDRESS'), 155 token_settings, 156 ) 157 if settings.get('RPC_SEND'): 158 conn.do(o) 159 if config.true('_WAIT'): 160 r = conn.wait(tx_hash_hex) 161 if r['status'] == 0: 162 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you') 163 sys.exit(1) 164 # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase) 165 address = r['contractAddress'] 166 167 print(address) 168 else: 169 print(tx_hash_hex) 170 171 else: 172 print(o) 173 174 175 if __name__ == '__main__': 176 main()