Esempio n. 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
Esempio 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
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
    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
Esempio n. 5
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
Esempio n. 6
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]})

    gauges = registry.get_gauges(pool_addr)
    gauge_addr = gauges[0][0]
    gauge_contract = interface.LiquidityGauge(gauge_addr)

    lp_token = MintableForkToken(gauge_contract.lp_token())
    lp_token.approve(gauge_addr, amount, {"from": accounts[0]})
    gauge_contract.deposit(lp_token.balanceOf(accounts[0]), {"from": accounts[0]})
Esempio n. 7
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:
            print(e)
            pass

    print(
        f"Minted and Deposited {trials} @ {nuke_amt:,.2f} = {total_minted / 10 ** coin.decimals():,.2f}"
    )
    return total_minted / 10 ** coin.decimals()