mirror of
git://holbrook.no/erc20-demurrage-token
synced 2026-01-17 10:30:16 +01:00
Compare commits
No commits in common. "1a168d81f94c8fe4bf48afc3de391df73b4a8b30" and "22cd7cf18caa5bc54dfd72aa8b9f46c6e23db9c1" have entirely different histories.
1a168d81f9
...
22cd7cf18c
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,8 +0,0 @@
|
|||||||
build/
|
|
||||||
dist/
|
|
||||||
*.egg-info
|
|
||||||
__pycache__
|
|
||||||
*.pyc
|
|
||||||
gmon.out
|
|
||||||
solidity/*.json
|
|
||||||
solidity/*.bin
|
|
||||||
@ -1,3 +1,2 @@
|
|||||||
chainlib~=0.0.3a1
|
chainlib~=0.0.1a36
|
||||||
eth-erc20~=0.0.9a1
|
crypto-dev-signer~=0.4.14a11
|
||||||
crypto-dev-signer~=0.4.14b3
|
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
from .token import RedistributedDemurrageToken
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,3 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
data_dir = os.path.realpath(os.path.dirname(__file__))
|
|
||||||
@ -1,135 +0,0 @@
|
|||||||
"""Deploy sarafu token
|
|
||||||
|
|
||||||
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
|
||||||
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
# standard imports
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import argparse
|
|
||||||
import logging
|
|
||||||
|
|
||||||
# third-party imports
|
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
|
||||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
|
||||||
from chainlib.chain import ChainSpec
|
|
||||||
from chainlib.eth.nonce import (
|
|
||||||
RPCNonceOracle,
|
|
||||||
OverrideNonceOracle,
|
|
||||||
)
|
|
||||||
from chainlib.eth.gas import (
|
|
||||||
RPCGasOracle,
|
|
||||||
OverrideGasOracle,
|
|
||||||
)
|
|
||||||
from chainlib.eth.connection import EthHTTPConnection
|
|
||||||
from chainlib.eth.tx import receipt
|
|
||||||
from chainlib.eth.constant import ZERO_ADDRESS
|
|
||||||
|
|
||||||
# local imports
|
|
||||||
from sarafu_token import RedistributedDemurrageToken
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
|
||||||
logg = logging.getLogger()
|
|
||||||
|
|
||||||
script_dir = os.path.dirname(__file__)
|
|
||||||
data_dir = os.path.join(script_dir, '..', 'data')
|
|
||||||
|
|
||||||
argparser = argparse.ArgumentParser()
|
|
||||||
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')
|
|
||||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string')
|
|
||||||
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
|
|
||||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
|
||||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
|
||||||
argparser.add_argument('-d', action='store_true', help='Dump RPC calls to terminal and do not send')
|
|
||||||
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('--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')
|
|
||||||
args = argparser.parse_args()
|
|
||||||
|
|
||||||
if args.vv:
|
|
||||||
logg.setLevel(logging.DEBUG)
|
|
||||||
elif args.v:
|
|
||||||
logg.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
block_last = args.w
|
|
||||||
block_all = args.ww
|
|
||||||
|
|
||||||
passphrase_env = 'ETH_PASSPHRASE'
|
|
||||||
if args.env_prefix != None:
|
|
||||||
passphrase_env = args.env_prefix + '_' + passphrase_env
|
|
||||||
passphrase = os.environ.get(passphrase_env)
|
|
||||||
if passphrase == None:
|
|
||||||
logg.warning('no passphrase given')
|
|
||||||
passphrase=''
|
|
||||||
|
|
||||||
signer_address = None
|
|
||||||
keystore = DictKeystore()
|
|
||||||
if args.y != None:
|
|
||||||
logg.debug('loading keystore file {}'.format(args.y))
|
|
||||||
signer_address = keystore.import_keystore_file(args.y, password=passphrase)
|
|
||||||
logg.debug('now have key for signer address {}'.format(signer_address))
|
|
||||||
signer = EIP155Signer(keystore)
|
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(args.i)
|
|
||||||
|
|
||||||
rpc = EthHTTPConnection(args.p)
|
|
||||||
nonce_oracle = None
|
|
||||||
if args.nonce != None:
|
|
||||||
nonce_oracle = OverrideNonceOracle(signer_address, args.nonce)
|
|
||||||
else:
|
|
||||||
nonce_oracle = RPCNonceOracle(signer_address, rpc)
|
|
||||||
|
|
||||||
gas_oracle = None
|
|
||||||
if args.gas_price !=None:
|
|
||||||
gas_oracle = OverrideGasOracle(price=args.gas_price, conn=rpc, code_callback=RedistributedDemurrageToken.gas)
|
|
||||||
else:
|
|
||||||
gas_oracle = RPCGasOracle(rpc, code_callback=RedistributedDemurrageToken.gas)
|
|
||||||
|
|
||||||
dummy = args.d
|
|
||||||
|
|
||||||
token_name = args.name
|
|
||||||
if token_name == None:
|
|
||||||
token_name = args.symbol
|
|
||||||
|
|
||||||
def main():
|
|
||||||
c = RedistributedDemurrageToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
|
||||||
(tx_hash_hex, o) = c.constructor(
|
|
||||||
signer_address,
|
|
||||||
token_name,
|
|
||||||
args.symbol,
|
|
||||||
args.decimals,
|
|
||||||
args.demurrage_level,
|
|
||||||
args.redistribution_period,
|
|
||||||
args.sink_address,
|
|
||||||
)
|
|
||||||
if dummy:
|
|
||||||
print(tx_hash_hex)
|
|
||||||
print(o)
|
|
||||||
else:
|
|
||||||
rpc.do(o)
|
|
||||||
if block_last:
|
|
||||||
r = rpc.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)
|
|
||||||
# TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
|
|
||||||
address = r['contractAddress']
|
|
||||||
|
|
||||||
print(address)
|
|
||||||
else:
|
|
||||||
print(tx_hash_hex)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
# 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,
|
|
||||||
)
|
|
||||||
|
|
||||||
# local imports
|
|
||||||
from sarafu_token.data import data_dir
|
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class RedistributedDemurrageToken(TxFactory):
|
|
||||||
|
|
||||||
__abi = None
|
|
||||||
__bytecode = None
|
|
||||||
|
|
||||||
def constructor(self, sender_address, name, symbol, decimals, demurrage_level, period_minutes, sink_address, tx_format=TxFormat.JSONRPC):
|
|
||||||
code = RedistributedDemurrageToken.bytecode()
|
|
||||||
enc = ABIContractEncoder()
|
|
||||||
enc.string(name)
|
|
||||||
enc.string(symbol)
|
|
||||||
enc.uint256(decimals)
|
|
||||||
enc.uint256(demurrage_level)
|
|
||||||
enc.uint256(period_minutes)
|
|
||||||
enc.address(sink_address)
|
|
||||||
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):
|
|
||||||
return 3500000
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def abi():
|
|
||||||
if RedistributedDemurrageToken.__abi == None:
|
|
||||||
f = open(os.path.join(data_dir, 'RedistributedDemurrageToken.json'), 'r')
|
|
||||||
RedistributedDemurrageToken.__abi = json.load(f)
|
|
||||||
f.close()
|
|
||||||
return RedistributedDemurrageToken.__abi
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def bytecode():
|
|
||||||
if RedistributedDemurrageToken.__bytecode == None:
|
|
||||||
f = open(os.path.join(data_dir, 'RedistributedDemurrageToken.bin'), 'r')
|
|
||||||
RedistributedDemurrageToken.__bytecode = f.read()
|
|
||||||
f.close()
|
|
||||||
return RedistributedDemurrageToken.__bytecode
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = sarafu-token
|
name = sarafu-token
|
||||||
version = 0.0.1a8
|
version = 0.0.1a4
|
||||||
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,11 +25,11 @@ include_package_data = True
|
|||||||
python_requires = >= 3.6
|
python_requires = >= 3.6
|
||||||
packages =
|
packages =
|
||||||
sarafu_token
|
sarafu_token
|
||||||
sarafu_token.runnable
|
sarafu_token.runnable.legacy
|
||||||
install_requires =
|
install_requires =
|
||||||
chainlib~=0.0.3a1
|
chainlib~=0.0.2a1
|
||||||
crypto-dev-signer~=0.4.14b3
|
crypto-dev-signer~=0.4.14a17
|
||||||
|
web3==5.12.2
|
||||||
|
|
||||||
[options.package_data]
|
[options.package_data]
|
||||||
* =
|
* =
|
||||||
@ -38,4 +38,4 @@ install_requires =
|
|||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
sarafu-token-deploy = sarafu_token.runnable.deploy:main
|
sarafu-token-deploy = sarafu_faucet.runnable.legacy.deploy:main
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
web3==5.12.2
|
|
||||||
eth_tester==0.5.0b3
|
eth_tester==0.5.0b3
|
||||||
py-evm==0.3.0a20
|
py-evm==0.3.0a20
|
||||||
|
giftable-erc20-token==0.0.8a1
|
||||||
|
|||||||
@ -35,8 +35,6 @@ contract RedistributedDemurrageToken {
|
|||||||
// Implements EIP172
|
// Implements EIP172
|
||||||
address public owner;
|
address public owner;
|
||||||
|
|
||||||
address newOwner;
|
|
||||||
|
|
||||||
// Implements ERC20
|
// Implements ERC20
|
||||||
string public name;
|
string public name;
|
||||||
|
|
||||||
@ -95,9 +93,6 @@ contract RedistributedDemurrageToken {
|
|||||||
// Temporary event used in development, will be removed on prod
|
// Temporary event used in development, will be removed on prod
|
||||||
event Debug(bytes32 _foo);
|
event Debug(bytes32 _foo);
|
||||||
|
|
||||||
// EIP173
|
|
||||||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
|
|
||||||
|
|
||||||
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _taxLevelMinute, uint256 _periodMinutes, address _defaultSinkAddress) public {
|
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _taxLevelMinute, uint256 _periodMinutes, address _defaultSinkAddress) public {
|
||||||
// ACL setup
|
// ACL setup
|
||||||
owner = msg.sender;
|
owner = msg.sender;
|
||||||
@ -514,7 +509,7 @@ contract RedistributedDemurrageToken {
|
|||||||
return (_value * ppmDivider * 1000000) / demurrageAmount;
|
return (_value * ppmDivider * 1000000) / demurrageAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ERC20, triggers tax and/or redistribution
|
// ERC20, triggers tax and/or redistribution
|
||||||
function approve(address _spender, uint256 _value) public returns (bool) {
|
function approve(address _spender, uint256 _value) public returns (bool) {
|
||||||
uint256 baseValue;
|
uint256 baseValue;
|
||||||
|
|
||||||
@ -527,7 +522,7 @@ contract RedistributedDemurrageToken {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ERC20, triggers tax and/or redistribution
|
// ERC20, triggers tax and/or redistribution
|
||||||
function transfer(address _to, uint256 _value) public returns (bool) {
|
function transfer(address _to, uint256 _value) public returns (bool) {
|
||||||
uint256 baseValue;
|
uint256 baseValue;
|
||||||
bool result;
|
bool result;
|
||||||
@ -542,7 +537,7 @@ contract RedistributedDemurrageToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Implements ERC20, triggers tax and/or redistribution
|
// ERC20, triggers tax and/or redistribution
|
||||||
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
|
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
|
||||||
uint256 baseValue;
|
uint256 baseValue;
|
||||||
bool result;
|
bool result;
|
||||||
@ -571,41 +566,4 @@ contract RedistributedDemurrageToken {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements EIP173
|
|
||||||
function transferOwnership(address _newOwner) public returns (bool) {
|
|
||||||
require(msg.sender == owner);
|
|
||||||
newOwner = _newOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements OwnedAccepter
|
|
||||||
function acceptOwnership() public returns (bool) {
|
|
||||||
address oldOwner;
|
|
||||||
|
|
||||||
require(msg.sender == newOwner);
|
|
||||||
oldOwner = owner;
|
|
||||||
owner = newOwner;
|
|
||||||
newOwner = address(0);
|
|
||||||
emit OwnershipTransferred(oldOwner, owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements EIP165
|
|
||||||
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
|
||||||
if (_sum == 0xc6bb4b70) { // ERC20
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (_sum == 0x449a52f8) { // Minter
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (_sum == 0x01ffc9a7) { // EIP165
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (_sum == 0x9493f8b2) { // EIP173
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (_sum == 0x37a47be4) { // OwnedAccepter
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user