Example #1
0
def main():

    # set up the accounts
    accounts.add(os.environ['METAMASK_SECRET_KEY'])
    accounts.default = accounts[1]

    # misc shit
    print(network.show_active())
    network.gas_limit(10000000)

    # intialize web3 providers
    web3_l1 = Web3(Web3.HTTPProvider(os.environ['PROVIDER_KOVAN']))
    web3_l2 = Web3(Web3.HTTPProvider('https://kovan.optimism.io'))

    assert web3_l1.isConnected()
    assert web3_l2.isConnected()

    # debug some accounts shit
    # print(web3_l1.eth.Eth.accounts)

    # need the ABI and bytecode for each of the following contracts:
    #   ERC20.sol -- token
    #   L2DepositedERC20.sol -- gateway
    # all are accessible via the brownie contract objects
    
    # deploy the L1 token
    tx_hash = web3_l2.eth.contract(
        abi=ERC20.abi, 
        bytecode=ERC20.bytecode).constructor(69000,'ELMO').transact(
            {'from': str(accounts.default)}
        )
    addr_token_l1 = web3_l1.eth.get_transaction_receipt(tx_hash)['contractAddress']

    print('Done!')
Example #2
0
def main():
    account = None
    if network.show_active() in ["mainnet-fork"]:
        account = accounts.at(myWalletAddress, force=True)
    elif network.show_active() in ["mainnet"]:
        account = accounts.load("maindev")

    # Set the gas price
    network.gas_price("120 gwei")
    network.gas_limit("auto")

    # Deploy/Get contract
    #bountyHunter = BountyHunter.deploy({"from":account})
    bountyHunter = BountyHunter.at(BOUNTY_HUNTER_ADDRESS)

    print("My wallet eth amount before claim: " + str(account.balance()))

    print("Claiming bounty...")
    bountyHunter.claimBounty({"from": account, "value": ETH_TO_SELL})

    print("Amount of Eth required: " + str(ETH_TO_SELL - bountyHunter.balance()))

    # print("The amount of Eth needed to buy back UNI tokens: " + str(200000000000000000 - bountyHunter.balance()))
    print("My wallet eth amount after claim: " + str(account.balance()))
    uniToken = interface.ERC20(UNI_TOKEN_ADDRESS)
    print("My wallet uni amount after claim: " + str(uniToken.balanceOf(myWalletAddress)))
def main():

    print(network.show_active())
    network.gas_limit(10000000)

    accounts.add(os.environ['METAMASK_SECRET_KEY'])
    accounts.default = accounts[1]
    ERC20.deploy(69000, 'ELMO', {'from': accounts.default})
Example #4
0
def main():
    privateKey = 'private key'
    factoryAddr = '0x44226Fc17074A4F019FAA6412E85eff3e01b8368'  # factory addr on kovan
    poolAddr = 'pool addr'
    acc = accounts.add(privateKey)
    network.gas_limit(10000000)  # Not work without it on kovan
    network.gas_price(Wei('1 gwei'))  # Not work without it on kovan

    factory = Factory(acc, factoryAddr)
    pool = factory.loadPool(poolAddr)

    print('Pool Address', pool.getAddress())
    print('isPool', pool.getAddress(), factory.isPool(pool.getAddress()))
    print('isPool', '0xb12DC0644f505028388Da4A919eD72d422175dA8',
          factory.isPool('0xb12DC0644f505028388Da4A919eD72d422175dA8'))
    print('Pool manager fee', factory.getManagerFee(pool.getAddress()))
    print('Dao fee', factory.getDaoFee())
    print('Dao address', factory.getDaoAddress())
    print('Exit fee', factory.getExitFee())
    print('Maximum manager fee', factory.getMaximumManagerFee())
    print('Exit fee cooldown', factory.getExitFeeCooldown())
    print('Max assets', factory.getMaximumAssetCount())
    print('Total pools', factory.getPoolCount())

    # Pool test
    print('Is pool private', pool.isPrivate())
    print('Creator', pool.getCreator())
    print('Creation time', pool.getCreationTime())
    print('Factory address', pool.getFactory())
    print('Assets', pool.getAssets())
    print('Token price at last fee mint', pool.getTokenPriceAtLastFeeMint())
    print('Manager', pool.getManager())
    print('Manager name', pool.getManagerName())
    print('Pool members', pool.getMembers())
    print('Pool member count', pool.getMemberCount())

    sUSD = pool.getAsset('sUSD')
    balance = sUSD.balanceOf(factory.signer)
    print('sUSD balance', balance)

    sUSD.contract.approve(pool.getAddress(), '1000000000000000000',
                          {'from': acc})
    pool.deposit('1000000000000000000')
    print('Pool Value', pool.getPoolValue())

    pool.exchange('sUSD', '500000000000000000', 'sETH')

    print('Pool Value', pool.getPoolValue())
    print('sUSD value', pool.assetValue('sUSD'))
    print('sETH value', pool.assetValue('sETH'))

    print('Summary', pool.getSummary())
    print('Composition', pool.getComposition())
    print('Waiting periods', pool.getWaitingPeriods())
    print('Suspended assets', pool.getSuspendedAssets())
Example #5
0
def run_test(filename, network, idx):
    network.reset()
    if type(CONFIG['test']['gas_limit']) is int:
        network.gas_limit(CONFIG['test']['gas_limit'])
    
    module = importlib.import_module(filename.replace(os.sep, '.'))
    test_names = [
        i for i in dir(module) if i not in dir(sys.modules['brownie']) and
        i[0] != "_" and callable(getattr(module, i))
    ]
    code = Path(CONFIG['folders']['project']).joinpath("{}.py".format(filename)).open().read()
    test_names = re.findall('(?<=\ndef)[\s]{1,}[^(]*(?=\([^)]*\)[\s]*:)', code)
    test_names = [i.strip() for i in test_names if i.strip()[0] != "_"]
    duplicates = set([i for i in test_names if test_names.count(i) > 1])
    if duplicates:
        raise ValueError(
            "tests/{}.py contains multiple tests of the same name: {}".format(
                filename, ", ".join(duplicates)
            )
        )
    traceback_info = []
    test_history = set()
    if not test_names:
        print("\n{0[error]}WARNING{0}: No test functions in {0[module]}{1}.py{0}".format(color, filename))
        return [], []

    print("\nRunning {0[module]}{1}.py{0} - {2} test{3}".format(
            color, filename, len(test_names)-1, "s" if len(test_names) != 2 else ""
    ))
    if 'setup' in test_names:
        test_names.remove('setup')
        traceback_info += _run_test(module, 'setup', 0, len(test_names))
        if traceback_info:
            return history.copy(), traceback_info
    network.rpc.snapshot()
    for c, t in enumerate(test_names[idx], start=idx.start + 1):
        network.rpc.revert()
        traceback_info += _run_test(module, t, c, len(test_names))
        if sys.argv[1] != "coverage":
            continue
        # need to retrieve stack trace before reverting the EVM
        for i in history:
            i.trace
        test_history.update(history.copy())
    return history, traceback_info
def main():
    privateKey = 'private key'
    factoryAddr = '0x44226Fc17074A4F019FAA6412E85eff3e01b8368'  # factory addr on kovan

    acc = accounts.add(privateKey)

    factory = Factory(acc, factoryAddr)

    network.gas_limit(10000000)  # Not work without it on kovan
    network.gas_price(Wei('1 gwei'))  # Not work without it on kovan

    privatePool = False
    managerName = 'Test'
    poolName = 'Test'
    assets = ['sETH', 'sBTC']

    managerFeeNumerator = 100
    secho('create pool...', fg="green")

    pool = factory.createPool(privatePool, managerName, poolName, assets,
                              managerFeeNumerator)
    secho(f'pool {pool.address} created', fg="green")

    comp = pool.getComposition()
    secho(f'composition: {comp}', fg="yellow")

    sUSD = pool.getAsset('sUSD')
    secho('approve sUSD...', fg="green")
    tx = sUSD.contract.approve(pool.address, Wei('100000000000000 ether'),
                               {'from': acc})
    tx.wait(1)

    secho('deposit sUSD...', fg="green")
    tx = pool.deposit(Wei('5 ether'))
    tx.wait(1)

    secho('exchange synths...', fg="green")
    tx = pool.exchange('sUSD', Wei('5 ether'), 'sETH')
    tx.wait(1)

    comp = pool.getComposition()
    secho(f'composition: {comp}', fg="yellow")
Example #7
0
def test_gas_limit_raises_not_connected():
    with pytest.raises(ConnectionError):
        network.gas_limit()
    with pytest.raises(ConnectionError):
        network.gas_limit('auto')
    with pytest.raises(ConnectionError):
        network.gas_limit(100000)
Example #8
0
def test_gas_limit_raises():
    with pytest.raises(ValueError):
        network.gas_limit(2000)
    with pytest.raises(TypeError):
        network.gas_limit("potato")
Example #9
0
def test_gas_limit_auto():
    network.gas_limit('auto')
    assert not config['active_network']['gas_limit']
    network.gas_limit(False)
    assert not config['active_network']['gas_limit']
Example #10
0
def test_gas_limit_manual():
    network.connect('ropsten')
    network.gas_limit(21000)
    assert config['active_network']['gas_limit'] == 21000
    network.gas_limit(100000)
    assert config['active_network']['gas_limit'] == 100000
Example #11
0
import os
os.system(
    'brownie networks add Ethereum maticv3 chainid=15001 host=https://testnetv3.matic.network'
)
from brownie import Contract, network, web3
from brownie.network import accounts
from . import abi
import json

ETH_WALLET_KEY = os.environ['ETH_WALLET_KEY']
CONTRACT_ADDRESS = os.environ['CONTRACT_ADDRESS']

abi = abi.abi
abi = json.loads(abi)
network.connect('maticv3')
network.gas_limit(0)
accounts.add(ETH_WALLET_KEY)
my_contract = Contract("TakeMeTo",
                       CONTRACT_ADDRESS,
                       abi=abi,
                       owner=accounts[0])


def get_total(category=0):
    return my_contract.gettotal(category, {'from': accounts[0]})


def submit_url(category: int, url: str, title: str, submitter: str):
    my_contract.submitUrl(category, url, title, submitter,
                          {'from': accounts[0]})