Ejemplo n.º 1
0
def main():
    accounts.from_mnemonic(SEED)
    admin = accounts[0]


    token = ERC20CRV.deploy("Curve DAO Token", "CRV", 18, {'from': admin, 'required_confs': confs})
    voting_escrow = VotingEscrow.deploy(
        token, "Vote-escrowed CRV", "veCRV", "veCRV_1.0.0", {'from': admin, 'required_confs': confs}
    )


    coin_a = ERC20.deploy("Coin A", "USDA", 18, {'from': admin, 'required_confs': confs})
    coin_b = ERC20.deploy("Coin B", "USDB", 18, {'from': admin, 'required_confs': confs})
    coin_a._mint_for_testing(10 ** 9 * 10 ** 18, {'from': admin, 'required_confs': confs})
    coin_b._mint_for_testing(10 ** 9 * 10 ** 18, {'from': admin, 'required_confs': confs})

    lp_token = ERC20LP.deploy("Some pool", "cPool", 18, 0, {'from': admin, 'required_confs': confs})
    pool = CurvePool.deploy([coin_a, coin_b], lp_token, 100, 4 * 10 ** 6, {'from': admin, 'required_confs': confs})
    lp_token.set_minter(pool, {'from': admin, 'required_confs': confs})

    coin_a.approve(pool, "1000000000000000000000", {'from': admin})
    coin_b.approve(pool, "1000000000000000000000", {'from': admin})
    pool.add_liquidity(["100000000000000", "200000000000000"], 0, {'from': admin})

    contract = CurveRewards.deploy(lp_token, coin_a, {'from': accounts[0], 'required_confs': confs})
    contract.setRewardDistribution(accounts[0], {'from': accounts[0], 'required_confs': confs})
    registry = Registry.deploy([ZERO_ADDRESS] * 4, {'from': admin, 'required_confs': confs})

    coin_a.transfer(contract, 100e18, {'from': accounts[0], 'required_confs': confs})

    liquidity_gauge_rewards = LiquidityGaugeReward.deploy(lp_token, '0xbE45e0E4a72aEbF9D08F93E64701964d2CC4cF96', contract, coin_a, {'from': admin, 'required_confs': confs})

    for account in DISTRIBUTION_ADDRESSES:
        coin_a.transfer(account, DISTRIBUTION_AMOUNT, {'from': admin, 'required_confs': confs})
        coin_b.transfer(account, DISTRIBUTION_AMOUNT, {'from': admin, 'required_confs': confs})

    pool.commit_transfer_ownership(ARAGON_AGENT, {'from': admin, 'required_confs': confs})
    pool.apply_transfer_ownership({'from': admin, 'required_confs': confs})
    registry.commit_transfer_ownership(ARAGON_AGENT, {'from': admin, 'required_confs': confs})
    registry.apply_transfer_ownership({'from': admin, 'required_confs': confs})

    gauge_controller = GaugeController.deploy(token, voting_escrow, {'from': admin, 'required_confs': confs})
    minter = Minter.deploy(token, gauge_controller, {'from': admin, 'required_confs': confs})
    liquidity_gauge = LiquidityGauge.deploy(lp_token, minter, {'from': admin, 'required_confs': confs})

    token.set_minter(minter, {'from': admin, 'required_confs': confs})
    gauge_controller.add_type(b'Liquidity', {'from': admin, 'required_confs': confs})
    gauge_controller.change_type_weight(0, 10 ** 18, {'from': admin, 'required_confs': confs})
    gauge_controller.add_gauge(liquidity_gauge, 0, 10 ** 18, {'from': admin, 'required_confs': confs})

    gauge_controller.commit_transfer_ownership(ARAGON_AGENT, {'from': admin, 'required_confs': confs})
    gauge_controller.apply_transfer_ownership({'from': admin, 'required_confs': confs})
    voting_escrow.commit_transfer_ownership(ARAGON_AGENT, {'from': admin, 'required_confs': confs})
    voting_escrow.apply_transfer_ownership({'from': admin, 'required_confs': confs})

    PoolProxy.deploy({'from': admin, 'required_confs': confs})
Ejemplo n.º 2
0
def transfer_ownership(admin, new_admin, gauge_controller, voting_escrow, pool_proxy, erc20crv, confs=1):
    gauge_controller = GaugeController.at(gauge_controller)
    voting_escrow = VotingEscrow.at(voting_escrow)
    pool_proxy = PoolProxy.at(pool_proxy)
    erc20crv = ERC20CRV.at(erc20crv)

    gauge_controller.commit_transfer_ownership(new_admin, {'from': admin, 'required_confs': confs})
    gauge_controller.apply_transfer_ownership({'from': admin, 'required_confs': confs})

    #just a dummy method for compatibility with Aragon, not needed to be transferred to DAO
    #voting_escrow.changeController(new_admin, {'from': admin, 'required_confs': confs})
    voting_escrow.commit_transfer_ownership(new_admin, {'from': admin, 'required_confs': confs})
    voting_escrow.apply_transfer_ownership({'from': admin, 'required_confs': confs})

    pool_proxy.commit_set_admins(
        new_admin, new_admin, new_admin, {'from': admin, 'required_confs': confs}
    )
    pool_proxy.apply_set_admins({'from': admin, 'required_confs': confs})

    erc20crv.set_admin(new_admin, {'from': admin, 'required_confs': confs})
Ejemplo n.º 3
0
def transfer_ownership(admin,
                       new_admin,
                       gauge_controller,
                       voting_escrow,
                       pool_proxy,
                       erc20crv,
                       confs=1):
    gauge_controller = GaugeController.at(gauge_controller)
    voting_escrow = VotingEscrow.at(voting_escrow)
    pool_proxy = PoolProxy.at(pool_proxy)
    erc20crv = ERC20CRV.at(erc20crv)

    gauge_controller.commit_transfer_ownership(new_admin, {
        'from': admin,
        'required_confs': confs
    })
    gauge_controller.apply_transfer_ownership({
        'from': admin,
        'required_confs': confs
    })

    voting_escrow.commit_transfer_ownership(new_admin, {
        'from': admin,
        'required_confs': confs
    })
    voting_escrow.apply_transfer_ownership({
        'from': admin,
        'required_confs': confs
    })

    pool_proxy.commit_set_admins(new_admin, new_admin, new_admin, {
        'from': admin,
        'required_confs': confs
    })
    pool_proxy.apply_set_admins({'from': admin, 'required_confs': confs})

    erc20crv.set_admin(new_admin, {'from': admin, 'required_confs': confs})
Ejemplo n.º 4
0
def deploy_part_two(admin, token, voting_escrow, confs=1, deployments_json=None):
    gauge_controller = GaugeController.deploy(
        token, voting_escrow, {"from": admin, "required_confs": confs}
    )
    for name, weight in GAUGE_TYPES:
        gauge_controller.add_type(name, weight, {"from": admin, "required_confs": confs})

    pool_proxy = PoolProxy.deploy({"from": admin, "required_confs": confs})
    minter = Minter.deploy(token, gauge_controller, {"from": admin, "required_confs": confs})
    token.set_minter(minter, {"from": admin, "required_confs": confs})

    deployments = {
        "ERC20CRV": token.address,
        "VotingEscrow": voting_escrow.address,
        "GaugeController": gauge_controller.address,
        "Minter": minter.address,
        "LiquidityGauge": {},
        "LiquidityGaugeReward": {},
        "PoolProxy": pool_proxy.address,
    }
    for name, (lp_token, weight) in POOL_TOKENS.items():
        gauge = LiquidityGauge.deploy(lp_token, minter, {"from": admin, "required_confs": confs})
        gauge_controller.add_gauge(gauge, 0, weight, {"from": admin, "required_confs": confs})
        deployments["LiquidityGauge"][name] = gauge.address

    for (name, (lp_token, reward_claim, reward_token, weight)) in REWARD_POOL_TOKENS.items():
        gauge = LiquidityGaugeReward.deploy(
            lp_token, minter, reward_claim, reward_token, {"from": admin, "required_confs": confs}
        )
        gauge_controller.add_gauge(gauge, 0, weight, {"from": admin, "required_confs": confs})
        deployments["LiquidityGaugeReward"][name] = gauge.address

    print(f"Deployment complete! Total gas used: {sum(i.gas_used for i in history)}")
    if deployments_json is not None:
        with open(deployments_json, "w") as fp:
            json.dump(deployments, fp)
        print(f"Deployment addresses saved to {deployments_json}")
def test_fee_distribution():

    alice = accounts[0]
    lp_tripool = Contract("0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490")

    # get list of active pools
    provider = Contract("0x0000000022D53366457F9d5E68Ec105046FC4383")
    registry = Contract(provider.get_registry())
    pool_list = [
        Contract(registry.pool_list(i)) for i in range(registry.pool_count())
    ]

    # deploy new pool proxy
    proxy = PoolProxy.deploy(alice, alice, alice, {"from": alice})

    # transfer ownership of all pools to new pool proxy
    for pool in pool_list:
        owner = pool.owner()
        pool.commit_transfer_ownership(proxy, {"from": owner})

    chain.sleep(86400 * 3)

    for pool in pool_list:
        owner = pool.owner()
        pool.apply_transfer_ownership({"from": owner})

    # yes, we are traveling back in time here
    # this is necessary so that SNX oracle data is not considered outdated
    chain.mine(timestamp=history[0].timestamp)

    # deploy the fee distributor
    distributor = FeeDistributor.deploy(
        "0x5f3b5DfEb7B28CDbD7FAba78963EE202a494e2A2",  # VotingEscrow
        chain.time(),
        lp_tripool,
        alice,
        alice,
        {'from': alice})

    # deploy the burners
    underlying_burner = UnderlyingBurner.deploy(distributor, alice, alice,
                                                alice, {'from': alice})
    meta_burner = MetaBurner.deploy(distributor, alice, alice, alice,
                                    {'from': alice})
    usdn_burner = USDNBurner.deploy(proxy, distributor, alice, alice, alice,
                                    {'from': alice})

    btc_burner = BTCBurner.deploy(underlying_burner, alice, alice, alice,
                                  {'from': alice})
    cburner = CBurner.deploy(underlying_burner, alice, alice, alice,
                             {'from': alice})
    yburner = YBurner.deploy(underlying_burner, alice, alice, alice,
                             {'from': alice})

    lp_burner = LPBurner.deploy(alice, alice, alice, {'from': alice})

    # set LP burner to unwrap sbtcCRV -> sBTC and transfer to BTC burner
    lp_burner.set_swap_data("0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3",
                            "0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6",
                            btc_burner)

    # set the burners within pool proxy
    to_set = [(k[-1], x) for k, v in BURNERS.items() for x in v]
    burners = [i[0] for i in to_set] + [ZERO_ADDRESS] * (40 - len(to_set))
    coins = [i[1] for i in to_set] + [ZERO_ADDRESS] * (40 - len(to_set))

    coin_list = [Contract(x) for v in BURNERS.values() for x in v]
    burner_list = [k[-1] for k in BURNERS.keys()]

    proxy.set_many_burners(coins[:20], burners[:20], {'from': alice})
    proxy.set_many_burners(coins[20:], burners[20:], {'from': alice})
    proxy.set_burner(lp_tripool, distributor, {'from': alice})

    # approve USDN burner to donate to USDN pool
    proxy.set_donate_approval("0x0f9cb53Ebe405d49A0bbdBD291A65Ff571bC83e1",
                              usdn_burner, True, {'from': alice})

    # withdraw pool fees to pool proxy
    proxy.withdraw_many(pool_list + [ZERO_ADDRESS] * (20 - len(pool_list)),
                        {'from': alice})

    # individually execute the burners for each coin
    for coin in coin_list + [lp_tripool]:
        proxy.burn(coin, {'from': alice})

    # call to burn sBTC a second time to handle LPBurner -> BTCBurner transfer
    btc_burner.burn("0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6",
                    {'from': alice})

    # sleep prior to execution because synths cannot transfer immediately after a swap
    chain.sleep(300)

    # call execute on burners
    btc_burner.execute({'from': alice})
    underlying_burner.execute({'from': alice})

    # verify zero-balances for all tokens in all contracts
    for coin in coin_list:
        for burner in burner_list:
            assert coin.balanceOf(burner) == 0
        assert coin.balanceOf(proxy) == 0
        assert coin.balanceOf(alice) == 0
        assert coin.balanceOf(distributor) == 0

    # verify zero-balance for 3CRV
    for burner in burner_list:
        assert lp_tripool.balanceOf(burner) == 0
    assert lp_tripool.balanceOf(proxy) == 0
    assert lp_tripool.balanceOf(alice) == 0

    # verify that fee distributor has received 3CRV
    amount = lp_tripool.balanceOf(distributor)
    assert amount > 0
    print(f"Success! Final 3CRV balance in distributor: {amount/1e18:.4f}")
Ejemplo n.º 6
0
def main(deployer=DEPLOYER):
    initial_balance = deployer.balance()
    lp_tripool = Contract("0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490")

    # deploy new pool proxy
    proxy = PoolProxy.deploy(deployer, deployer, deployer, {"from": deployer})

    # sept 17, 2020 - 2 days before admin fee collection begins
    start_time = 1600300800

    # deploy the fee distributor
    distributor = FeeDistributor.deploy(
        "0x5f3b5DfEb7B28CDbD7FAba78963EE202a494e2A2",  # VotingEscrow
        start_time,
        lp_tripool,
        OWNER_ADMIN,
        EMERGENCY_ADMIN,
        {"from": deployer},
    )

    # deploy the burners
    underlying_burner = UnderlyingBurner.deploy(distributor, RECOVERY,
                                                OWNER_ADMIN, EMERGENCY_ADMIN,
                                                {"from": deployer})
    MetaBurner.deploy(distributor, RECOVERY, OWNER_ADMIN, EMERGENCY_ADMIN,
                      {"from": deployer})
    usdn_burner = USDNBurner.deploy(proxy, distributor, RECOVERY, OWNER_ADMIN,
                                    EMERGENCY_ADMIN, {"from": deployer})

    btc_burner = BTCBurner.deploy(underlying_burner, RECOVERY, OWNER_ADMIN,
                                  EMERGENCY_ADMIN, {"from": deployer})
    CBurner.deploy(underlying_burner, RECOVERY, OWNER_ADMIN, EMERGENCY_ADMIN,
                   {"from": deployer})
    YBurner.deploy(underlying_burner, RECOVERY, OWNER_ADMIN, EMERGENCY_ADMIN,
                   {"from": deployer})

    # for LP burner we retain initial ownership to set it up
    lp_burner = LPBurner.deploy(RECOVERY, deployer, EMERGENCY_ADMIN,
                                {"from": deployer})

    # set LP burner to unwrap sbtcCRV -> sBTC and transfer to BTC burner
    lp_burner.set_swap_data(
        "0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3",
        "0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6",
        btc_burner,
        {"from": deployer},
    )

    # this ownership transfer must be accepted by the DAO
    lp_burner.commit_transfer_ownership(OWNER_ADMIN, {"from": deployer})

    # set the burners within pool proxy
    to_set = [(k[-1], x) for k, v in BURNERS.items() for x in v]
    burners = [i[0] for i in to_set] + [ZERO_ADDRESS] * (40 - len(to_set))
    coins = [i[1] for i in to_set] + [ZERO_ADDRESS] * (40 - len(to_set))

    proxy.set_many_burners(coins[:20], burners[:20], {"from": deployer})
    proxy.set_many_burners(coins[20:], burners[20:], {"from": deployer})
    proxy.set_burner(lp_tripool, distributor, {"from": deployer})

    # approve USDN burner to donate to USDN pool
    proxy.set_donate_approval("0x0f9cb53Ebe405d49A0bbdBD291A65Ff571bC83e1",
                              usdn_burner, True, {"from": deployer})

    # set PoolProxy ownership
    proxy.commit_set_admins(OWNER_ADMIN, PARAM_ADMIN, EMERGENCY_ADMIN,
                            {"from": deployer})
    proxy.apply_set_admins({"from": deployer})

    print(
        f"Success! Gas used: {initial_balance - deployer.balance()/1e18:.4f} ETH"
    )