예제 #1
0
def main():
    deployer = accounts.at('0xB593d82d53e2c187dc49673709a6E9f806cdC835',
                           force=True)
    # deployer = accounts.load('gh')

    # deploy safeboxes
    safebox_eth = SafeBoxETH.deploy(
        '0x41c84c0e2EE0b740Cf0d31F63f3B6F627DC6b393',
        'Interest Bearing Ether v2', 'ibETHv2', {'from': deployer})
    safebox_dai = SafeBox.deploy('0x8e595470Ed749b85C6F7669de83EAe304C2ec68F',
                                 'Interest Bearing Dai Stablecoin v2',
                                 'ibDAIv2', {'from': deployer})
    safebox_usdt = SafeBox.deploy('0x48759F220ED983dB51fA7A8C0D2AAb8f3ce4166a',
                                  'Interest Bearing Tether USD v2', 'ibUSDTv2',
                                  {'from': deployer})
    safebox_usdc = SafeBox.deploy('0x76Eb2FE28b36B3ee97F3Adae0C69606eeDB2A37c',
                                  'Interest Bearing USD Coin v2', 'ibUSDCv2',
                                  {'from': deployer})
    safebox_yfi = SafeBox.deploy('0xFa3472f7319477c9bFEcdD66E4B948569E7621b9',
                                 'Interest Bearing yearn.finance v2',
                                 'ibYFIv2', {'from': deployer})

    # add banks
    usdt = interface.IERC20Ex('0xdAC17F958D2ee523a2206206994597C13D831ec7')
    usdc = interface.IERC20Ex('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48')
    yfi = interface.IERC20Ex('0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e')

    cyusdt = '0x48759F220ED983dB51fA7A8C0D2AAb8f3ce4166a'
    cyusdc = '0x76Eb2FE28b36B3ee97F3Adae0C69606eeDB2A37c'
    cyyfi = '0xFa3472f7319477c9bFEcdD66E4B948569E7621b9'

    bank = HomoraBank.at('0x5f5Cd91070960D13ee549C9CC47e7a4Cd00457bb')
    bank.addBank(usdt, cyusdt, {'from': deployer})
    bank.addBank(usdc, cyusdc, {'from': deployer})
def get_safebox(token):
    if token == Tokens.weth:
        return SafeBoxETH.at('0xeEa3311250FE4c3268F8E684f7C87A82fF183Ec1')
    elif token == Tokens.dai:
        return SafeBox.at('0xee8389d235E092b2945fE363e97CDBeD121A0439')
    elif token == Tokens.usdt:
        return SafeBox.at('0x020eDC614187F9937A1EfEeE007656C6356Fb13A')
    elif token == Tokens.usdc:
        return SafeBox.at('0x08bd64BFC832F1C2B3e07e634934453bA7Fa2db2')
    elif token == Tokens.yfi:
        return SafeBox.at('0x3614644AE157280b5C1d17AE686C153a204aaf3b')
    elif token == Tokens.dpi:
        return SafeBox.at('0x9E6aCA6B13a0Bc3364D035fF6D97ff4dB319F88A')
    elif token == Tokens.snx:
        return SafeBox.at('0x9446614037a839730A92E28a7ec870344B7B8F09')
    elif token == Tokens.susd:
        return SafeBox.at('0x3E1F2Feb27738609a22aa8B192a1a9138c445aa0')
    else:
        raise Exception(f'safebox not supported for token {token}')
예제 #3
0
def main():
    safebox_eth = SafeBoxETH.at('0xeEa3311250FE4c3268F8E684f7C87A82fF183Ec1')
    safebox_usdt = SafeBox.at('0x020eDC614187F9937A1EfEeE007656C6356Fb13A')
    safebox_usdc = SafeBox.at('0x08bd64BFC832F1C2B3e07e634934453bA7Fa2db2')
    safebox_dai = SafeBox.at('0xee8389d235E092b2945fE363e97CDBeD121A0439')

    cy_eth = interface.IAny(safebox_eth.cToken())
    cy_usdt = interface.IAny(safebox_usdt.cToken())
    cy_usdc = interface.IAny(safebox_usdc.cToken())
    cy_dai = interface.IAny(safebox_dai.cToken())

    print('eth',
          safebox_eth.totalSupply() * cy_eth.exchangeRateStored() / 1e36)
    print('usdt',
          safebox_usdt.totalSupply() * cy_usdt.exchangeRateStored() / 1e24)
    print('usdc',
          safebox_usdc.totalSupply() * cy_usdc.exchangeRateStored() / 1e24)
    print('dai',
          safebox_dai.totalSupply() * cy_dai.exchangeRateStored() / 1e36)
예제 #4
0
def main():
    deployer = accounts.at('0xB593d82d53e2c187dc49673709a6E9f806cdC835',
                           force=True)
    # deployer = accounts.load('gh')

    # deploy safeboxes
    safebox_eth = SafeBoxETH.deploy(
        '0x41c84c0e2EE0b740Cf0d31F63f3B6F627DC6b393',
        'Interest Bearing Ether v2', 'ibETHv2', {'from': deployer})
    safebox_dai = SafeBox.deploy('0x8e595470Ed749b85C6F7669de83EAe304C2ec68F',
                                 'Interest Bearing Dai Stablecoin v2',
                                 'ibDAIv2', {'from': deployer})
    safebox_usdt = SafeBox.deploy('0x48759F220ED983dB51fA7A8C0D2AAb8f3ce4166a',
                                  'Interest Bearing Tether USD v2', 'ibUSDTv2',
                                  {'from': deployer})
    safebox_usdc = SafeBox.deploy('0x76Eb2FE28b36B3ee97F3Adae0C69606eeDB2A37c',
                                  'Interest Bearing USD Coin v2', 'ibUSDCv2',
                                  {'from': deployer})
    safebox_yfi = SafeBox.deploy('0xFa3472f7319477c9bFEcdD66E4B948569E7621b9',
                                 'Interest Bearing yearn.finance v2',
                                 'ibYFIv2', {'from': deployer})
def main():
    admin = accounts[0]
    alice = accounts[1]
    bob = accounts[2]

    weth = interface.IERC20Ex('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')
    cyweth = interface.IERC20Ex('0x41c84c0e2ee0b740cf0d31f63f3b6f627dc6b393')

    homora = HomoraBank.deploy({'from': admin})

    safebox = SafeBoxETH.deploy(cyweth, 'ibETHv2', 'ibETHv2', {'from': admin})

    # set up funds to alice
    mint_tokens(weth, alice)
    mint_tokens(weth, bob)

    weth.approve(cyweth, 2**256-1, {'from': bob})

    #################################################################
    # check decimals

    assert safebox.decimals() == cyweth.decimals(), 'incorrect decimals'

    #################################################################
    # deposit
    print('====================================')
    print('Case 1. deposit')

    prevETHAlice = alice.balance()
    prevWETHBob = weth.balanceOf(bob)
    prevIBETHAlice = safebox.balanceOf(alice)
    prevcyWETHBob = cyweth.balanceOf(bob)

    alice_amt = 10**18
    bob_amt = 10**18
    safebox.deposit({'from': alice, 'value': alice_amt})
    chain.mine(20)
    cyweth.mint(bob_amt, {'from': bob})

    curETHAlice = alice.balance()
    curWETHBob = weth.balanceOf(bob)
    curIBETHAlice = safebox.balanceOf(alice)
    curcyWETHBob = cyweth.balanceOf(bob)

    print('∆ eth alice', curETHAlice - prevETHAlice)
    print('∆ weth bob', curWETHBob - prevWETHBob)
    print('∆ ibETH bal alice', curIBETHAlice - prevIBETHAlice)
    print('∆ cyWETH bal bob', curcyWETHBob - prevcyWETHBob)
    print('calculated ibETH alice', alice_amt * 10**18 // cyweth.exchangeRateStored())
    print('calculated ibETH bob', bob_amt * 10**18 // cyweth.exchangeRateStored())

    assert curETHAlice - prevETHAlice == -alice_amt, 'incorrect alice amount'
    assert curWETHBob - prevWETHBob == -bob_amt, 'incorrect bob amount'
    assert almostEqual(curIBETHAlice - prevIBETHAlice, curcyWETHBob - prevcyWETHBob)

    chain.mine(200)

    #################################################################
    # alice withdraws 1/3 & 2/3. bob withdraws all.
    print('====================================')
    print('Case 2. withdraw')

    alice_withdraw_1 = safebox.balanceOf(alice) // 3
    alice_withdraw_2 = safebox.balanceOf(alice) - alice_withdraw_1
    bob_withdraw = cyweth.balanceOf(bob) // 3

    prevETHAlice = alice.balance()
    prevWETHBob = weth.balanceOf(bob)
    prevIBETHAlice = safebox.balanceOf(alice)
    prevcyWETHBob = cyweth.balanceOf(bob)

    safebox.withdraw(alice_withdraw_1, {'from': alice})
    chain.mine(20)
    cyweth.redeem(bob_withdraw, {'from': bob})

    curETHAlice = alice.balance()
    curWETHBob = weth.balanceOf(bob)
    curIBETHAlice = safebox.balanceOf(alice)
    curcyWETHBob = cyweth.balanceOf(bob)

    print('∆ eth alice', curETHAlice - prevETHAlice)
    print('∆ weth bob', curWETHBob - prevWETHBob)
    print('∆ ibETH bal alice', curIBETHAlice - prevIBETHAlice)
    print('∆ cyWETH bal bob', curcyWETHBob - prevcyWETHBob)

    assert almostEqual(curETHAlice - prevETHAlice, alice_amt //
                       3), 'incorrect alice withdraw eth amount'
    assert almostEqual(curWETHBob - prevWETHBob, bob_amt // 3), 'incorrect bob withdraw eth amount'
    assert almostEqual(curIBETHAlice - prevIBETHAlice, curcyWETHBob -
                       prevcyWETHBob), 'incorrect withdraw amount'

    chain.mine(20)

    prevETHAlice = alice.balance()
    prevIBETHAlice = safebox.balanceOf(alice)

    safebox.withdraw(alice_withdraw_2, {'from': alice})

    curETHAlice = alice.balance()
    curIBETHAlice = safebox.balanceOf(alice)

    print('∆ eth alice', curETHAlice - prevETHAlice)
    print('∆ ibETH bal alice', curIBETHAlice - prevIBETHAlice)

    assert almostEqual(curETHAlice - prevETHAlice, alice_amt * 2 //
                       3), 'incorrect second withdraw'
def main():
    admin = accounts[0]
    alice = accounts[1]

    alpha = interface.IERC20Ex('0xa1faa113cbe53436df28ff0aee54275c13b40975')
    ibethv2 = SafeBoxETH.at('0xeEa3311250FE4c3268F8E684f7C87A82fF183Ec1')

    mint_tokens(alpha, alice)
    mint_tokens(alpha, admin)

    ibethv2.deposit({'from': alice, 'value': '100000 ether'})
    ibethv2.deposit({'from': admin, 'value': '100000 ether'})

    pair = interface.IUniswapV2Pair(
        '0xf79a07cd3488BBaFB86dF1bAd09a6168D935c017')
    # sushi router
    router = interface.IUniswapV2Router02(
        '0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f')

    ibethv2_router = IbETHRouterV2.deploy(alpha, ibethv2, router,
                                          {'from': admin})

    alpha.approve(ibethv2_router, 2**256 - 1, {'from': alice})
    ibethv2.approve(ibethv2_router, 2**256 - 1, {'from': alice})
    pair.approve(ibethv2_router, 2**256 - 1, {'from': alice})

    #######################################################################
    # setup liquidity first time

    init_alpha_amt = 1000 * 10**alpha.decimals()
    init_ibethv2_amt = 1 * 10**ibethv2.decimals()

    ibethv2.transfer(pair, init_ibethv2_amt, {'from': admin})
    alpha.transfer(pair, init_alpha_amt, {'from': admin})

    pair.mint(admin, {'from': admin})

    prevIbethv2Bal = ibethv2.balanceOf(admin)
    ibethv2.deposit({'from': admin, 'value': '1 ether'})
    curIbethv2Bal = ibethv2.balanceOf(admin)
    ibethv2_eth_rate = 10**18 / (curIbethv2Bal - prevIbethv2Bal)
    print('conversion rate', ibethv2_eth_rate)
    print('init ibethv2 amt', init_ibethv2_amt * ibethv2_eth_rate)
    print('deposited', 10**18, 'ether')
    print('received', curIbethv2Bal - prevIbethv2Bal, 'ibethv2')

    ########################################################################
    # check state vars
    print('=======================================')
    print('Case. check state vars')

    assert ibethv2_router.alpha() == alpha
    assert ibethv2_router.ibETHv2() == ibethv2
    assert ibethv2_router.lpToken() == pair
    assert ibethv2_router.router() == router

    #######################################################################
    # test swap exact ETH to ALPHA
    print('===========================================')
    print('Case. test swap exact eth to alpha')

    eth_amt = 10**12

    prevETHBal = alice.balance()
    prevAlphaBal = alpha.balanceOf(alice)

    ibethv2_router.swapExactETHToAlpha(0, alice, 2**256 - 1, {
        'from': alice,
        'value': eth_amt,
        'gas_price': 0
    })

    curETHBal = alice.balance()
    curAlphaBal = alpha.balanceOf(alice)

    print('∆ alpha', curAlphaBal - prevAlphaBal)
    print(
        'calc alpha',
        eth_amt * (init_alpha_amt / init_ibethv2_amt) / ibethv2_eth_rate *
        0.997)

    assert curETHBal - prevETHBal == -eth_amt, 'incorrect ETH amount'
    assert almostEqual(
        curAlphaBal - prevAlphaBal,
        eth_amt * (init_alpha_amt / init_ibethv2_amt) / ibethv2_eth_rate *
        0.997), 'incorrect alpha amount'

    #######################################################################
    # test swap exact ALPHA to ETH
    print('=========================================')
    print('Case. swap exact alpha to eth')

    alpha_amt = 10**18

    prevETHBal = alice.balance()
    prevAlphaBal = alpha.balanceOf(alice)

    ibethv2_router.swapExactAlphaToETH(alpha_amt, 0, alice, 2**256 - 1, {
        'from': alice,
        'gas_price': 0
    })

    curETHBal = alice.balance()
    curAlphaBal = alpha.balanceOf(alice)

    print('∆ eth', curETHBal - prevETHBal)
    print(
        'calc eth', alpha_amt / (init_alpha_amt / init_ibethv2_amt) *
        ibethv2_eth_rate * 0.997)

    assert almostEqual(
        curETHBal - prevETHBal,
        alpha_amt / (init_alpha_amt / init_ibethv2_amt) * ibethv2_eth_rate *
        0.997), 'incorrect ETH amount'
    assert almostEqual(curAlphaBal - prevAlphaBal,
                       -alpha_amt), 'incorrect alpha amount'

    #######################################################################
    # test add liquidity eth alpha optimal
    print('=========================================')
    print('Case. test add liquidity eth alpha optimal')

    alpha_amt = 100000 * 10**18
    eth_amt = 1000 * 10**18

    prevETHBal = alice.balance()
    prevAlphaBal = alpha.balanceOf(alice)
    prevLPBal = pair.balanceOf(alice)

    prevLPSupply = pair.totalSupply()
    r0, r1, _ = pair.getReserves()

    ibethv2_router.addLiquidityETHAlphaOptimal(alpha_amt, 0, alice, 2**256 - 1,
                                               {
                                                   'from': alice,
                                                   'value': eth_amt,
                                                   'gas_price': 0
                                               })

    curETHBal = alice.balance()
    curAlphaBal = alpha.balanceOf(alice)
    curLPBal = pair.balanceOf(alice)

    new_r0, new_r1, _ = pair.getReserves()

    expected_lp = (sqrt((new_r0 * new_r1) / (r0 * r1)) - 1) * prevLPSupply

    print('prev total lp supply', prevLPSupply)
    print('prev reserves', r0, r1)
    print('cur reserves', new_r0, new_r1)
    print('∆ lp', curLPBal - prevLPBal)
    print('calc lp', expected_lp)

    assert almostEqual(new_r0, r0 + alpha_amt), 'incorrect r0 new amt'
    assert almostEqual(new_r1,
                       r1 + eth_amt / ibethv2_eth_rate), 'incorrect r1 new amt'

    assert curETHBal - prevETHBal == -eth_amt, 'incorrect ETH add'
    assert curAlphaBal - prevAlphaBal == -alpha_amt, 'incorrect Alpha add'
    assert almostEqual(curLPBal - prevLPBal,
                       expected_lp), 'incorrect LP received'

    # ###########################################################################
    # # test add liquidity ibethv2 alpha optimal
    print('=========================================')
    print('Case. test add liquidity ibethv2 alpha optimal')

    alpha_amt = 1000000 * 10**18
    ibethv2_amt = 1000 * 10**5

    prevETHBal = alice.balance()
    prevIbethv2Bal = ibethv2.balanceOf(alice)
    prevAlphaBal = alpha.balanceOf(alice)
    prevLPBal = pair.balanceOf(alice)

    prevLPSupply = pair.totalSupply()
    r0, r1, _ = pair.getReserves()

    ibethv2_router.addLiquidityIbETHv2AlphaOptimal(ibethv2_amt, alpha_amt, 0,
                                                   alice, 2**256 - 1, {
                                                       'from': alice,
                                                       'gas_price': 0
                                                   })

    curETHBal = alice.balance()
    curAlphaBal = alpha.balanceOf(alice)
    curIbethv2Bal = ibethv2.balanceOf(alice)
    curLPBal = pair.balanceOf(alice)

    new_r0, new_r1, _ = pair.getReserves()
    expected_lp = (sqrt((new_r0 * new_r1) / (r0 * r1)) - 1) * prevLPSupply

    print('prev total lp supply', prevLPSupply)
    print('prev reserves', r0, r1)
    print('cur reserves', new_r0, new_r1)
    print('∆ lp', curLPBal - prevLPBal)
    print('calc lp', expected_lp)

    assert almostEqual(new_r0, r0 + alpha_amt), 'incorrect r0 new amt'
    assert almostEqual(new_r1, r1 + ibethv2_amt), 'incorrect r1 new amt'

    assert curIbethv2Bal - prevIbethv2Bal == -ibethv2_amt, 'incorrect ibethv2 add'
    assert curAlphaBal - prevAlphaBal == -alpha_amt, 'incorrect Alpha add'
    assert almostEqual(curLPBal - prevLPBal,
                       expected_lp), 'incorrect LP received'

    ###############################################################################
    # test remove liquidity eth alpha
    print('===========================================')
    print('Case. test remove liquidity eth alpha')

    lp_amt = pair.balanceOf(alice) // 3

    prevETHBal = alice.balance()
    prevIbethv2Bal = ibethv2.balanceOf(alice)
    prevAlphaBal = alpha.balanceOf(alice)
    prevLPBal = pair.balanceOf(alice)

    prevLPSupply = pair.totalSupply()

    r0, r1, _ = pair.getReserves()  # token0 = alpha

    ibethv2_router.removeLiquidityETHAlpha(lp_amt, 0, 0, alice, 2**256 - 1,
                                           {'from': alice})

    curETHBal = alice.balance()
    curAlphaBal = alpha.balanceOf(alice)
    curIbethv2Bal = ibethv2.balanceOf(alice)
    curLPBal = pair.balanceOf(alice)

    print('∆ alpha', curAlphaBal - prevAlphaBal)
    print('∆ ibethv2', curIbethv2Bal - prevIbethv2Bal)

    assert curLPBal - prevLPBal == -lp_amt, 'incorrect LP withdraw'
    assert almostEqual(curAlphaBal - prevAlphaBal, lp_amt / prevLPSupply *
                       r0), 'incorrect alpha withdraw amount'
    assert almostEqual(curETHBal - prevETHBal, lp_amt / prevLPSupply * r1 *
                       ibethv2_eth_rate), 'incorrect eth withraw amount'

    ##################################################################################
    # test remove liquidity alpha only
    print('===============================================')
    print('Case. test remove liquidity alpha only')

    lp_amt = pair.balanceOf(alice) // 10**3

    prevETHBal = alice.balance()
    prevIbethv2Bal = ibethv2.balanceOf(alice)
    prevAlphaBal = alpha.balanceOf(alice)
    prevLPBal = pair.balanceOf(alice)

    prevLPSupply = pair.totalSupply()

    r0, r1, _ = pair.getReserves()  # token0 = alpha

    ibethv2_router.removeLiquidityAlphaOnly(lp_amt, 0, alice, 2**256 - 1,
                                            {'from': alice})

    curETHBal = alice.balance()
    curAlphaBal = alpha.balanceOf(alice)
    curIbethv2Bal = ibethv2.balanceOf(alice)
    curLPBal = pair.balanceOf(alice)

    assert curLPBal - prevLPBal == -lp_amt, 'incorrect LP withdraw'
    assert almostEqual(curAlphaBal - prevAlphaBal, lp_amt / prevLPSupply * r0 *
                       2), 'incorrect alpha withdraw amount'