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_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
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
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
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
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
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]})
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]})