def main(): swap = swap_system.connect_swap(badger_config.prod_json) bridge = bridge_system.connect_bridge(badger_config.prod_json) bridge.add_existing_swap(swap) swap.configure_strategies_grant_swapper_role(bridge.adapter.address) confirm_deploy(bridge) console.print("[green]deployed bridge adapter at {}[/green]".format( bridge.adapter.address)) console.print("[green]deployed swap router at {}[/green]".format( bridge.swap.router.address)) bridge_system.print_to_file(bridge, "deploy-bridge.json") swap_system.print_to_file(bridge.swap, "deploy-swap.json")
def test_bridge_vault(vault): badger = connect_badger(badger_config.prod_json) bridge = connect_bridge(badger, badger_config.prod_json) swap = connect_swap(badger_config.prod_json) bridge.add_existing_swap(swap) _deploy_bridge_mocks(badger, bridge) slippage = 0.03 amount = 1 * 10**8 v = vault["address"] # TODO: Can interleave these mints/burns. for accIdx in range(10, 12): account = accounts[accIdx] for i in range(0, 2): balanceBefore = interface.IERC20(v).balanceOf(account) bridge.adapter.mint( vault["inToken"], slippage * 10**4, account.address, v, amount, # Darknode args hash/sig optional since gateway is mocked. "", "", {"from": account}, ) balance = interface.IERC20(v).balanceOf(account) assert balance > balanceBefore interface.IERC20(v).approve( bridge.adapter.address, balance, {"from": account}, ) # Approve mock gateway for transfer of underlying token for "mock" burns. # NB: In the real world, burns don't require approvals as it's just # an internal update the the user's token balance. interface.IERC20(registry.tokens.renbtc).approve( bridge.mocks.BTC.gateway, balance, {"from": bridge.adapter}) bridge.adapter.burn( vault["outToken"], v, slippage * 10**4, account.address, balance, {"from": account}, ) assert interface.IERC20(v).balanceOf(account) == 0
def main(): badger = connect_badger(badger_config.prod_json) bridge = connect_bridge(badger, badger_config.prod_json) swap = connect_swap(badger_config.prod_json) upgrade_bridge(badger, bridge) console.print("[orange]Queued bridge adapter update[/orange]") upgrade_swap_strategy(badger, swap.strategies.curve, CurveSwapStrategy) console.print("[orange]Queued swap strategy update[/orange]") bridge.deploy_curve_token_wrapper() configure_bridge(badger, bridge) console.print("[orange]Configured bridge to use new curve token wrapper[/orange]")
def test_bridge_basic_swap_fail(): renbtc = registry.tokens.renbtc wbtc = registry.tokens.wbtc badger = connect_badger(badger_config.prod_json) bridge = connect_bridge(badger, badger_config.prod_json) swap = connect_swap(badger_config.prod_json) bridge.add_existing_swap(swap) _upgrade_bridge(badger, bridge) _deploy_bridge_mocks(badger, bridge) # NB: If true, fails during router opimizeSwap() call, otherwise the underlying strategy fails. for router_fail in [True, False]: _deploy_swap_mocks(badger, bridge, swap, router_fail=router_fail) # .1% slippage slippage = 0.001 amount = 1 * 10**8 for accIdx in range(10, 12): account = accounts[accIdx] for i in range(0, 2): balanceBefore = interface.IERC20(renbtc).balanceOf(account) # Test mints bridge.adapter.mint( wbtc, slippage * 10**4, account.address, AddressZero, # No vault. amount, # Darknode args hash/sig optional since gateway is mocked. "", "", {"from": account}, ) assert interface.IERC20(renbtc).balanceOf( account) > balanceBefore # NB: User should not receive any wbtc but rather renbtc as part # of the fallback mechanism. assert interface.IERC20(wbtc).balanceOf(account) == 0
def test_bridge_vault(vault): badger = connect_badger(badger_config.prod_json) bridge = connect_bridge(badger, badger_config.prod_json) swap = connect_swap(badger_config.prod_json) _upgrade_bridge(badger, bridge) _upgrade_swap(badger, swap) _deploy_bridge_mocks(badger, bridge) slippage = 0.03 amount = 1 * 10**8 v = vault["address"] if v == AddressZero: v = MockVault.deploy(vault["id"], vault["symbol"], vault["token"], { "from": badger.deployer }).address # Must approve mock vaults to mint/burn to/from. bridge.adapter.setVaultApproval( v, True, {"from": badger.devMultisig}, ) else: badger.sett_system.vaults[vault["id"]].approveContractAccess( bridge.adapter, {"from": badger.devMultisig}, ) # TODO: Can interleave these mints/burns. for accIdx in range(10, 12): account = accounts[accIdx] for i in range(0, 2): balanceBefore = interface.IERC20(v).balanceOf(account) bridge.adapter.mint( vault["inToken"], slippage * 10**4, account.address, v, amount, # Darknode args hash/sig optional since gateway is mocked. "", "", {"from": account}, ) balance = interface.IERC20(v).balanceOf(account) assert balance > balanceBefore interface.IERC20(v).approve( bridge.adapter.address, balance, {"from": account}, ) # Approve mock gateway for transfer of underlying token for "mock" burns. # NB: In the real world, burns don't require approvals as it's just # an internal update the the user's token balance. interface.IERC20(registry.tokens.renbtc).approve( bridge.mocks.BTC.gateway, balance, {"from": bridge.adapter}) bridge.adapter.burn( vault["outToken"], v, slippage * 10**4, account.address, balance, {"from": account}, ) assert interface.IERC20(v).balanceOf(account) == 0
def test_bridge_basic(): renbtc = registry.tokens.renbtc wbtc = registry.tokens.wbtc badger = connect_badger(badger_config.prod_json) bridge = connect_bridge(badger, badger_config.prod_json) swap = connect_swap(badger_config.prod_json) _upgrade_bridge(badger, bridge) _upgrade_swap(badger, swap) _deploy_bridge_mocks(badger, bridge) router = swap.router # 3% slippage slippage = 0.03 amount = 1 * 10**8 # Test estimating slippage from a random account for wbtc <-> renbtc swaps. _assert_swap_slippage( router, renbtc, wbtc, amount, slippage, ) _assert_swap_slippage( router, wbtc, renbtc, amount, slippage, ) for accIdx in range(10, 12): account = accounts[accIdx] for i in range(0, 2): balanceBefore = interface.IERC20(wbtc).balanceOf(account) # Test mints bridge.adapter.mint( wbtc, slippage * 10**4, account.address, AddressZero, # No vault. amount, # Darknode args hash/sig optional since gateway is mocked. "", "", {"from": account}, ) assert interface.IERC20(wbtc).balanceOf(account) > balanceBefore # Test burns balance = interface.IERC20(wbtc).balanceOf(account) interface.IERC20(wbtc).approve(bridge.adapter, balance, {"from": account}) # Approve mock gateway for transfer of underlying token for "mock" burns. # NB: In the real world, burns don't require approvals as it's # just an internal update the the user's token balance. interface.IERC20(renbtc).approve( bridge.mocks.BTC.gateway, balance, {"from": bridge.adapter}, ) bridge.adapter.burn( wbtc, AddressZero, # No vault. slippage * 10**4, account.address, balance, {"from": account}, ) assert interface.IERC20(wbtc).balanceOf(account) == 0