def test_eth_to_usd(Settler, alice, swap, sUSD, sETH, curve_susd, curve_seth,
                    usd_idx):
    final = MintableForkToken(curve_susd.coins(usd_idx))

    tx = swap.swap_into_synth(ETH_ADDRESS, sUSD, alice.balance(), 0, {
        "from": alice,
        "value": alice.balance()
    })
    token_id = tx.events["Transfer"][-1]["token_id"]

    chain.mine(timedelta=600)
    amount = swap.token_info(token_id)["underlying_balance"]
    swap.swap_from_synth(token_id, final, amount, 0, {"from": alice})

    settler = Settler.at(hex(token_id))
    for coin in (sETH, sUSD):
        assert coin.balanceOf(swap) == 0
        assert coin.balanceOf(settler) == 0
        assert coin.balanceOf(alice) == 0

    assert swap.balance() == 0
    assert settler.balance() == 0
    assert alice.balance() == 0

    assert final.balanceOf(swap) == 0
    assert final.balanceOf(settler) == 0
    assert final.balanceOf(alice) > 0

    assert swap.balanceOf(alice) == 0
Exemplo n.º 2
0
def test_eth_to_btc(Settler, alice, swap, sBTC, sETH, curve_sbtc, curve_seth,
                    btc_idx):
    final = MintableForkToken(curve_sbtc.coins(btc_idx))

    tx = swap.swap_into_synth(ETH_ADDRESS, sBTC, alice.balance(), 0, {
        'from': alice,
        'value': alice.balance()
    })
    token_id = tx.events['Transfer'][-1]['token_id']

    chain.mine(timedelta=600)
    amount = swap.token_info(token_id)['underlying_balance']
    swap.swap_from_synth(token_id, final, amount, 0, {'from': alice})

    settler = Settler.at(hex(token_id))
    for coin in (sETH, sBTC):
        assert coin.balanceOf(swap) == 0
        assert coin.balanceOf(settler) == 0
        assert coin.balanceOf(alice) == 0

    assert swap.balance() == 0
    assert settler.balance() == 0
    assert alice.balance() == 0

    assert final.balanceOf(swap) == 0
    assert final.balanceOf(settler) == 0
    assert final.balanceOf(alice) > 0

    assert swap.balanceOf(alice) == 0
Exemplo n.º 3
0
def test_btc_swaps(alice, bob, swap_btc, factory, coin):
    # add liquidity
    wrapped_coins = [coin, MintableForkToken(swap_btc.coins(1))]
    underlying_coins = [coin] + [
        MintableForkToken(i)
        for i in factory.get_underlying_coins(swap_btc)[1:4]
    ]

    amounts = [100 * 10**i.decimals() for i in wrapped_coins]
    for coin, amount in zip(wrapped_coins, amounts):
        coin._mint_for_testing(alice, amount)
        coin.approve(swap_btc, 2**256 - 1, {'from': alice})

    swap_btc.add_liquidity(amounts, 0, {'from': alice})
    chain.sleep(3600)

    # perform swaps between each coin
    for send, recv in itertools.permutations(range(2), 2):
        amount = 10**wrapped_coins[send].decimals()

        wrapped_coins[send]._mint_for_testing(bob, amount, {'from': bob})
        wrapped_coins[send].approve(swap_btc, amount, {'from': bob})

        swap_btc.exchange(send, recv, amount, 0, {'from': bob})
        chain.sleep(3600)

    # perform swaps between each underlying coin

    for send, recv in itertools.permutations(range(4), 2):
        amount = 10**underlying_coins[send].decimals()

        underlying_coins[send]._mint_for_testing(bob, amount, {'from': bob})
        underlying_coins[send].approve(swap_btc, amount, {'from': bob})

        swap_btc.exchange_underlying(send, recv, amount, 0, {'from': bob})
        chain.sleep(3600)

    # remove liquidity balanced
    swap_btc.remove_liquidity(10**18, [0, 0], {'from': alice})
    chain.sleep(3600)

    # remove liquidity imbalanced
    for idx in range(2):
        amounts = [10**wrapped_coins[i].decimals() for i in range(2)]
        amounts[idx] = 0
        swap_btc.remove_liquidity_imbalance(amounts, 2**256 - 1,
                                            {'from': alice})
        chain.sleep(3600)

    for idx in range(2):
        swap_btc.remove_liquidity_one_coin(10**wrapped_coins[idx].decimals(),
                                           idx, 0, {'from': alice})
        chain.sleep(3600)

    before_withdraw = wrapped_coins[1].balanceOf(
        "0xaa42C0CD9645A58dfeB699cCAeFBD30f19B1ff81")
    swap_btc.withdraw_admin_fees({'from': alice})
    assert wrapped_coins[1].balanceOf(
        "0xaa42C0CD9645A58dfeB699cCAeFBD30f19B1ff81") > before_withdraw
def test_ethplorer_error(alice, invalid_ethplorer_key):
    brownie_tokens.forked._token_holders.clear()
    ethplorer_error = {"code": 1, "message": "Invalid API key"}

    token = MintableForkToken(token_address_default)
    with pytest.raises(BrownieTokensError,
                       match=f"Ethplorer returned error: {ethplorer_error}."):
        token._mint_for_testing(alice, 10**6)
Exemplo n.º 5
0
def underlying_coins(coin, is_rebase, rebase_coin):
    BASE_COINS = [
        "0x6B175474E89094C44Da98b954EedeAC495271d0F",  # DAI
        "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",  # USDC
        "0xdAC17F958D2ee523a2206206994597C13D831ec7",  # USDT
    ]
    if is_rebase:
        yield [rebase_coin] + [MintableForkToken(i) for i in BASE_COINS]
    else:
        yield [coin] + [MintableForkToken(i) for i in BASE_COINS]
    def _mint(self, acct, token, amount):
        token = MintableForkToken(token)
        amount = int(amount * 10**token.decimals())
        if not token.allowance(acct, self.swap):
            token.approve(self.swap, 2**256 - 1, {"from": acct})
        balance = token.balanceOf(acct)
        if balance < amount:
            token._mint_for_testing(acct, amount - balance)

        return amount
Exemplo n.º 7
0
def test_btc_to_eth(Settler, alice, bob, swap, sBTC, sETH, curve_sbtc,
                    curve_seth, btc_idx):
    initial = MintableForkToken(curve_sbtc.coins(btc_idx))

    amount = 5 * 10**initial.decimals()
    initial._mint_for_testing(alice, amount)
    initial.approve(swap, 2**256 - 1, {'from': alice})
    alice.transfer(bob, alice.balance())

    tx = swap.swap_into_synth(initial, sETH, amount, 0, {'from': alice})
    token_id = tx.events['Transfer'][-1]['token_id']

    chain.mine(timedelta=600)
    amount = swap.token_info(token_id)['underlying_balance']
    swap.swap_from_synth(token_id, ETH_ADDRESS, amount, 0, {'from': alice})

    settler = Settler.at(hex(token_id))
    for coin in (initial, sETH, sBTC):
        assert coin.balanceOf(swap) == 0
        assert coin.balanceOf(settler) == 0
        assert coin.balanceOf(alice) == 0

    assert swap.balance() == 0
    assert settler.balance() == 0
    assert alice.balance() > 0

    assert swap.balanceOf(alice) == 0
def test_usd_to_eth(Settler, alice, bob, swap, sUSD, sETH, curve_susd,
                    curve_seth, usd_idx):
    initial = MintableForkToken(curve_susd.coins(usd_idx))

    amount = 100_000 * 10**initial.decimals()
    initial._mint_for_testing(alice, amount)
    initial.approve(swap, 2**256 - 1, {"from": alice})
    alice.transfer(bob, alice.balance())

    tx = swap.swap_into_synth(initial, sETH, amount, 0, {"from": alice})
    token_id = tx.events["Transfer"][-1]["token_id"]

    chain.mine(timedelta=600)
    amount = swap.token_info(token_id)["underlying_balance"]
    swap.swap_from_synth(token_id, ETH_ADDRESS, amount, 0, {"from": alice})

    settler = Settler.at(hex(token_id))
    for coin in (initial, sETH, sUSD):
        assert coin.balanceOf(swap) == 0
        assert coin.balanceOf(settler) == 0
        assert coin.balanceOf(alice) == 0

    assert swap.balance() == 0
    assert settler.balance() == 0
    assert alice.balance() > 0

    assert swap.balanceOf(alice) == 0
Exemplo n.º 9
0
def run_arb(amt):
    tri = Contract("tricrypto")
    coins = []
    for c in range(3):
        coins.append(MintableForkToken(tri.coins(c)))

    fqamt = amt * 10 ** coins[0].decimals()
    coins[0]._mint_for_testing(accounts[0], fqamt)
    ape_strat_2(coins, 0, 2, accounts[0])
Exemplo n.º 10
0
def tripool_funded(registry, alice, tripool):
    dai_addr = registry.get_coins(tripool)[0]
    dai = MintableForkToken(dai_addr)
    amount = 100000 * 10 ** dai.decimals()
    dai.approve(tripool, amount, {"from": alice})
    dai._mint_for_testing(alice, amount)

    amounts = [amount, 0, 0]
    tripool.add_liquidity(amounts, 0, {"from": alice})
    return tripool
Exemplo n.º 11
0
def base_pool():
    pool = Contract("0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7")

    # ensure the base pool is balanced so our tests are deterministic
    max_balance = max([pool.balances(0), pool.balances(1) * 10**12, pool.balances(2) * 10**12])
    ideal_balances = [max_balance, max_balance // 10**12, max_balance // 10**12]
    for i, amount in enumerate(ideal_balances):
        balance = pool.balances(i)
        if balance < amount:
            MintableForkToken(pool.coins(i))._mint_for_testing(pool, amount - balance)
    pool.donate_admin_fees({'from': pool.owner()})

    yield pool
Exemplo n.º 12
0
def test_zap_gas(DepositZapBTC, alice, bob, swap_btc, factory, coin):
    zap = DepositZapBTC.deploy({'from': alice})
    underlying_coins = [coin] + [
        MintableForkToken(i)
        for i in factory.get_underlying_coins(swap_btc)[1:4]
    ]
    amounts = [100 * 10**i.decimals() for i in underlying_coins]
    for coin, amount in zip(underlying_coins, amounts):
        coin._mint_for_testing(alice, amount)
        coin.approve(zap, 2**256 - 1, {'from': alice})

    # add liquidity balanced
    zap.add_liquidity(swap_btc, [i // 2 for i in amounts], 0, {'from': alice})
    chain.sleep(3600)

    # add liquidity imbalanced
    for idx in range(4):
        amounts = [10**i.decimals() for i in underlying_coins]
        amounts[idx] = 0
        zap.add_liquidity(swap_btc, amounts, 0, {'from': alice})
        chain.sleep(3600)

    # remove liquidity balanced
    swap_btc.approve(zap, 2**256 - 1, {'from': alice})
    zap.remove_liquidity(swap_btc, 10**18, [0, 0, 0, 0], {'from': alice})
    chain.sleep(3600)

    amounts = [10**i.decimals() for i in underlying_coins]
    zap.remove_liquidity_imbalance(swap_btc, amounts,
                                   swap_btc.balanceOf(alice), {'from': alice})
    chain.sleep(3600)

    # remove liquidity imbalanced
    for idx in range(4):
        amounts = [10**i.decimals() for i in underlying_coins]
        amounts[idx] = 0
        zap.remove_liquidity_imbalance(swap_btc, amounts,
                                       swap_btc.balanceOf(alice),
                                       {'from': alice})
        chain.sleep(3600)

    for idx in range(4):
        zap.remove_liquidity_one_coin(swap_btc,
                                      10**underlying_coins[idx].decimals(),
                                      idx, 0, {'from': alice})
        chain.sleep(3600)
Exemplo n.º 13
0
def add_tripool_liquidity():
    dai_addr = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
    usdc_addr = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"

    amount = 100_000 * 10**18
    dai = MintableForkToken(dai_addr)
    dai._mint_for_testing(whale, amount)

    pool_addr = registry.find_pool_for_coins(dai_addr, usdc_addr)
    pool = Contract(pool_addr)

    dai.approve(pool_addr, amount, {'from': whale})
    pool.add_liquidity([amount, 0, 0], 0, {'from': whale})
    return pool
Exemplo n.º 14
0
def check_arb(initial_val=40000):
    ninja = accounts[0]
    tri = Contract("tricrypto")
    coins = []
    for c in range(3):
        coins.append(MintableForkToken(tri.coins(c)))

    amount = initial_val * 10 ** coins[0].decimals()
    c1 = 0
    c2 = 2

    coins[c1]._mint_for_testing(ninja, amount)

    chain.snapshot()

    # One Direction
    _val = ape_strat_1(coins, c1, c2, ninja)
    print(f"Difference: {_val - initial_val:,.2f}")
    chain.revert()

    _val = ape_strat_2(coins, c1, c2, ninja)
    print(f"Difference: {_val - initial_val:,.2f}")
    chain.revert()
Exemplo n.º 15
0
def main():
    dai_addr = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
    usdc_addr = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
    registry_addr = "0x7D86446dDb609eD0F5f8684AcF30380a356b2B4c"

    amount = 100_000 * 10 ** 18
    dai = MintableForkToken(dai_addr)
    dai._mint_for_testing(accounts[0], amount)

    registry = Contract(registry_addr)
    pool_addr = registry.find_pool_for_coins(
            dai_addr, usdc_addr)
    pool = Contract(pool_addr)

    dai.approve(pool_addr, amount, 
            {'from': accounts[0]})
    pool.add_liquidity(
            [amount, 0, 0], 0, 
            {'from': accounts[0]})
Exemplo n.º 16
0
def WBTC():
    yield MintableForkToken("0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599")
Exemplo n.º 17
0
def dai(alice):
    dai = MintableForkToken("dai")
    dai._mint_for_testing(alice, 5_000 * 10**dai.decimals())
    return dai
Exemplo n.º 18
0
def sUSD():
    yield MintableForkToken("0x57ab1ec28d129707052df4df418d58a2d46d5f51")
Exemplo n.º 19
0
def test_usd_to_btc(Settler, alice, swap, sUSD, sBTC, curve_susd, curve_sbtc,
                    usd_idx, btc_idx):
    initial = MintableForkToken(curve_susd.coins(usd_idx))
    final = MintableForkToken(curve_sbtc.coins(btc_idx))

    amount = 1_000_000 * 10**initial.decimals()
    initial._mint_for_testing(alice, amount)
    initial.approve(swap, 2**256 - 1, {"from": alice})

    tx = swap.swap_into_synth(initial, sBTC, amount, 0, {"from": alice})
    token_id = tx.events["Transfer"][-1]["token_id"]

    chain.mine(timedelta=600)
    amount = swap.token_info(token_id)["underlying_balance"]
    swap.swap_from_synth(token_id, final, amount, 0, {"from": alice})

    settler = Settler.at(hex(token_id))
    for coin in (initial, sBTC, sUSD):
        assert coin.balanceOf(swap) == 0
        assert coin.balanceOf(settler) == 0
        assert coin.balanceOf(alice) == 0

    assert final.balanceOf(swap) == 0
    assert final.balanceOf(settler) == 0
    assert final.balanceOf(alice) > 0

    assert swap.balanceOf(alice) == 0
Exemplo n.º 20
0
def sBTC():
    yield MintableForkToken("0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6")
def ERC20(address: str) -> MintableForkToken:
    return MintableForkToken(address)
Exemplo n.º 22
0
def sETH():
    yield MintableForkToken("0x5e74C9036fb86BD7eCdcb084a0673EFc32eA31cb")
Exemplo n.º 23
0
def test_skip_list(alice):
    token = MintableForkToken(token_address_default)
    # Fetch top holders
    token._mint_for_testing(alice, Wei(0))

    holders = [_token_holders[token.address][i] for i in [0, 1, 10]]
    initial_balances = [token.balanceOf(holder) for holder in holders]

    # Should remove addresses from current lists
    # ZERO_ADDRESS to check address that is not in _token_holders
    skip_holders(*holders, ZERO_ADDRESS)
    token._mint_for_testing(alice, 10**6)
    for holder, initial_balance in zip(holders, initial_balances):
        assert token.balanceOf(holder) == initial_balance

    # Should not include addresses that were set to skip before
    _token_holders.clear()
    token._mint_for_testing(alice, 10**6)
    for holder, initial_balance in zip(holders, initial_balances):
        assert token.balanceOf(holder) == initial_balance
Exemplo n.º 24
0
def weth():
    return MintableForkToken('weth')
Exemplo n.º 25
0
def tether():
    return MintableForkToken('tether')
Exemplo n.º 26
0
def base_lp_token():
    yield MintableForkToken("0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490")
Exemplo n.º 27
0
from brownie import *
from brownie_tokens import MintableForkToken

tri = Contract("tricrypto")
tri_lp = Contract("tricrypto_lp")
tri_rewards = Contract("tricrypto_rewards")
test_addr = accounts[0]

coin_id = 0
coin = MintableForkToken(tri.coins(coin_id))

# Rapidly deposit to Curve TriCrypto to test effect on price
def main():
    print("\n==Beginning==\n")
    current_state()

    nuke()
    print("\n==After Nuke==\n")
    current_state()

    reverse_nuke()
    print("\n==Reverse the Nuke==\n")
    current_state()
    portfolio_state(accounts[0])


# Current state of TriCrypto
def current_state():
    balances = []
    total_balance = 0
    print("Current state of TriCrypto")
Exemplo n.º 28
0
def usdc(alice, dai):
    usdc = MintableForkToken("usdc")
    dai.approve(Contract("3pool"), dai.balanceOf(alice), {"from": alice})
    Contract("3pool").exchange(0, 1, dai.balanceOf(alice), 0, {"from": alice})
    return usdc
Exemplo n.º 29
0
def ERC20(address: str) -> MintableForkToken:
    return MintableForkToken(Contract.from_explorer(address))
Exemplo n.º 30
0
def print_money(addr, amount, alias):
    coin = MintableForkToken(alias)
    coin._mint_for_testing(addr, amount * 10**coin.decimals())
    return coin