Exemplo n.º 1
0
def main(acct=CALLER, claim_threshold=CLAIM_THRESHOLD):
    lp_tripool = Contract("0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490")
    distributor = Contract("0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc")
    proxy = Contract("0xeCb456EA5365865EbAb8a2661B0c503410e9B347")
    btc_burner = Contract("0x00702BbDEaD24C40647f235F15971dB0867F6bdB")
    underlying_burner = Contract("0x874210cF3dC563B98c137927e7C951491A2e9AF3")

    initial_balance = lp_tripool.balanceOf(distributor)

    # get list of active pools
    pool_list = _get_pool_list()

    # withdraw pool fees to pool proxy
    to_claim = []
    for i in range(len(pool_list)):

        # check claimable amount
        claimable = _get_admin_balances(pool_list[i])
        if sum(claimable) >= claim_threshold:
            to_claim.append(pool_list[i])

        if i == len(pool_list) - 1 or len(to_claim) == 20:
            to_claim += [ZERO_ADDRESS] * (20-len(to_claim))
            proxy.withdraw_many(to_claim, {'from': acct, 'gas_price': gas_strategy})
            to_claim = []

    # call burners to convert fee tokens to 3CRV
    burn_start = 0
    to_burn = []
    for i in range(len(COINS)):
        if Contract(COINS[i]).balanceOf(proxy) > 0:
            # no point in burning if we have a zero balance
            to_burn.append(COINS[i])

        to_burn_padded = to_burn + [ZERO_ADDRESS] * (20-len(to_burn))

        # estimate gas to decide when to burn - some of the burners are gas guzzlers
        if i == len(COINS) - 1 or proxy.burn_many.estimate_gas(to_burn_padded, {'from': acct}) > 2000000:
            tx = proxy.burn_many(to_burn_padded, {'from': acct, 'gas_price': gas_strategy})
            to_burn = []
            if not burn_start:
                # record the timestamp of the first tx - need to
                # know how long to wait to finalize synth swaps
                burn_start = tx.timestamp

    # wait on synths to finalize
    time.sleep(max(burn_start + 180 - time.time(), 0))

    # call `execute` on burners
    # for btc burner, this converts sUSD to USDC and sends to the underlying burner
    btc_burner.execute({'from': acct, 'gas_price': gas_strategy})
    # for underlying burner, this deposits USDC/USDT/DAI into 3CRV and sends to the distributor
    underlying_burner.execute({'from': acct, 'gas_price': gas_strategy})

    # finally, call to burn 3CRV - this also triggers a token checkpoint
    proxy.burn(lp_tripool, {'from': acct, 'gas_price': gas_strategy})

    final = lp_tripool.balanceOf(distributor)
    print(f"Success! Total 3CRV fowarded to distributor: {(final-initial_balance)/1e18:.4f}")
def main(acct=CALLER):
    lp_tripool = Contract("0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490")
    distributor = Contract("0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc")
    proxy = Contract("0xeCb456EA5365865EbAb8a2661B0c503410e9B347")
    btc_burner = Contract("0x00702BbDEaD24C40647f235F15971dB0867F6bdB")
    underlying_burner = Contract("0x874210cF3dC563B98c137927e7C951491A2e9AF3")

    initial_balance = lp_tripool.balanceOf(distributor)

    # 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())
    ]

    # withdraw pool fees to pool proxy
    for i in range(0, len(pool_list), 20):
        pools = pool_list[i:i + 20]
        pools += [ZERO_ADDRESS] * (20 - len(pools))
        proxy.withdraw_many(pools, {'from': acct, 'gas_price': gas_strategy})

    # call burners to convert fee tokens to 3CRV
    burn_start = 0
    to_burn = []
    for i in range(len(COINS)):
        to_burn.append(COINS[i])
        to_burn_padded = to_burn + [ZERO_ADDRESS] * (20 - len(to_burn))

        # estimate gas to decide when to burn - some of the burners are gas guzzlers
        if i == len(COINS) - 1 or proxy.burn_many.estimate_gas(
                to_burn_padded, {'from': acct}) > 2000000:
            tx = proxy.burn_many(to_burn_padded, {
                'from': acct,
                'gas_price': gas_strategy
            })
            to_burn = []
            if not burn_start:
                # record the timestamp of the first tx - need to
                # know how long to wait to finalize synth swaps
                burn_start = tx.timestamp

    # wait on synths to finalize
    time.sleep(burn_start + 180 - time.time())

    # call `execute` on burners
    # for btc burner, this converts sUSD to USDC and sends to the underlying burner
    btc_burner.execute({'from': acct, 'gas_price': gas_strategy})
    # for underlying burner, this deposits USDC/USDT/DAI into 3CRV and sends to the distributor
    underlying_burner.execute({'from': acct, 'gas_price': gas_strategy})

    # finally, call to burn 3CRV - this also triggers a token checkpoint
    proxy.burn(lp_tripool, {'from': acct, 'gas_price': gas_strategy})

    final = lp_tripool.balanceOf(distributor)
    print(
        f"Success! Total 3CRV fowarded to distributor: {final-initial_balance/1e18:.4f}"
    )
def main(acct=CALLER, claim_threshold=CLAIM_THRESHOLD):
    lp_tripool = Contract("0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490")
    distributor = Contract("0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc")
    proxy = Contract("0xeCb456EA5365865EbAb8a2661B0c503410e9B347")

    initial_balance = lp_tripool.balanceOf(distributor)

    # get list of active pools
    pool_list = _get_pool_list()

    # withdraw pool fees to pool proxy
    to_claim = []
    for i in range(len(pool_list)):

        # check claimable amount
        sys.stdout.write(
            f"\rQuerying pending fee amounts ({i}/{len(pool_list)})...")
        sys.stdout.flush()
        claimable = _get_admin_balances(pool_list[i])
        if sum(claimable) >= claim_threshold:
            to_claim.append(pool_list[i])

        if i == len(pool_list) - 1 or len(to_claim) == 20:
            to_claim += [ZERO_ADDRESS] * (20 - len(to_claim))
            proxy.withdraw_many(to_claim, {
                'from': acct,
                'gas_price': gas_strategy
            })
            to_claim = []

    # call burners to convert fee tokens to 3CRV
    burn_start = 0
    to_burn = []
    for i in range(len(COINS)):
        # no point in burning if we have a zero balance
        if COINS[i] == ETH_ADDRESS:
            if proxy.balance() > 0:
                to_burn.append(COINS[i])
        elif Contract(COINS[i]).balanceOf(proxy) > 0:
            to_burn.append(COINS[i])

        to_burn_padded = to_burn + [ZERO_ADDRESS] * (20 - len(to_burn))

        # estimate gas to decide when to burn - some of the burners are gas guzzlers
        if i == len(COINS) - 1 or proxy.burn_many.estimate_gas(
                to_burn_padded, {'from': acct}) > 2000000:
            tx = proxy.burn_many(to_burn_padded, {
                'from': acct,
                'gas_price': gas_strategy
            })
            to_burn = []
            if not burn_start:
                # record the timestamp of the first tx - need to
                # know how long to wait to finalize synth swaps
                burn_start = tx.timestamp

    # wait on synths to finalize
    time.sleep(max(burn_start + 180 - time.time(), 0))

    # call `execute` on synth burners that require it
    # converts settled sUSD to USDC and sends to the underlying burner
    susd = Contract("0x57Ab1ec28D129707052df4dF418D58a2D46d5f51")
    exchanger = Contract("0x0bfDc04B38251394542586969E2356d0D731f7DE")
    susd_currency_key = "0x7355534400000000000000000000000000000000000000000000000000000000"
    for burner in SYNTH_BURNERS:
        if susd.balanceOf(burner) > 0:
            settlement_time = exchanger.maxSecsLeftInWaitingPeriod(
                burner, susd_currency_key)
            if settlement_time:
                print("Sleeping until synths have time to settle...")
                time.sleep(settlement_time)
            Contract(burner).execute({'from': acct, 'gas_price': gas_strategy})

    # call `execute` on the underlying burner
    # deposits DAI/USDC/USDT into 3pool and transfers the 3CRV to the fee distributor
    underlying_burner = Contract("0x874210cF3dC563B98c137927e7C951491A2e9AF3")
    underlying_burner.execute({'from': acct, 'gas_price': gas_strategy})

    # finally, call to burn 3CRV - this also triggers a token checkpoint
    proxy.burn(lp_tripool, {'from': acct, 'gas_price': gas_strategy})

    final = lp_tripool.balanceOf(distributor)
    print(
        f"Success! Total 3CRV fowarded to distributor: {(final-initial_balance)/1e18:.4f}"
    )