コード例 #1
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
コード例 #2
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
コード例 #3
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
コード例 #4
0
    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
コード例 #5
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
コード例 #6
0
ファイル: tri_nuke.py プロジェクト: curvefi/brownie-tutorial
# Current state of a user portfolio
def portfolio_state(test_addr):
    print("\nPortfolio State")
    for i in range(3):
        _coin = Contract(tri.coins(i))
        _bal = _coin.balanceOf(test_addr) / 10 ** _coin.decimals()
        if i - 1 >= 0:
            price = tri.price_oracle(i - 1) / 10 ** 18
        else:
            price = 1
        print(f"{_coin.symbol()}: {_bal:,.2f} @ {price:.2f} = {_bal * price:,.2f}  ")


# Deposit Tether into TriPool to artificial pump other asset prices
def nuke(nuke_amt=1_000_000, trials=200):
    coin_amt = nuke_amt * 10 ** coin.decimals()
    tri_lp = Contract("tricrypto_lp")

    total_minted = 0
    for j in range(trials):
        try:
            coin._mint_for_testing(test_addr, coin_amt)
            _bal = coin.balanceOf(test_addr)
            safe_approve(coin, tri, _bal, test_addr)
            arr = [0, 0, 0]
            arr[coin_id] = _bal
            actual = tri.add_liquidity(arr, 0, {"from": test_addr})

            total_minted += _bal

        except Exception as e:
コード例 #7
0
def print_money(addr, amount, alias):
    coin = MintableForkToken(alias)
    coin._mint_for_testing(addr, amount * 10**coin.decimals())
    return coin
コード例 #8
0
ファイル: conftest.py プロジェクト: curvefi/brownie-tutorial
def dai(alice):
    dai = MintableForkToken("dai")
    dai._mint_for_testing(alice, 5_000 * 10**dai.decimals())
    return dai