def sushi_router(): yield Contract.from_explorer("0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F")
def crv(gov): # crv token yield Contract("0xD533a949740bb3306d119CC777fa900bA034cd52", owner=gov)
def weth(): token_address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" yield Contract(token_address)
def test_toggle_function_pause(accounts, loanToken, LoanToken, LoanTokenSettingsLowerAdmin, LoanTokenLogicStandard, loanTokenSettings, SUSD, open_margin_trade_position, lend_to_pool): lend_to_pool() functionSignature = "marginTrade(bytes32,uint256,uint256,uint256,address,address,bytes)" # pause the given function localLoanToken = Contract.from_abi("loanToken", address=loanToken.address, abi=LoanToken.abi, owner=accounts[0]) localLoanToken.setTarget(loanTokenSettings.address) localLoanToken = Contract.from_abi("loanToken", address=loanToken.address, abi=LoanTokenSettingsLowerAdmin.abi, owner=accounts[0]) localLoanToken.toggleFunctionPause(functionSignature, True) # make sure the function can't be called anymore localLoanToken = Contract.from_abi("loanToken", address=loanToken.address, abi=LoanToken.abi, owner=accounts[0]) loanTokenLogic = accounts[0].deploy(LoanTokenLogicStandard) localLoanToken.setTarget(loanTokenLogic.address) localLoanToken = Contract.from_abi("loanToken", address=loanToken.address, abi=LoanTokenLogicStandard.abi, owner=accounts[0]) with reverts("unauthorized"): open_margin_trade_position() #check if checkPause returns true assert (localLoanToken.checkPause(functionSignature)) # reactivate the given function localLoanToken = Contract.from_abi("loanToken", address=loanToken.address, abi=LoanToken.abi, owner=accounts[0]) localLoanToken.setTarget(loanTokenSettings.address) localLoanToken = Contract.from_abi("loanToken", address=loanToken.address, abi=LoanTokenSettingsLowerAdmin.abi, owner=accounts[0]) localLoanToken.toggleFunctionPause(functionSignature, False) #make sure the function can be called again localLoanToken = Contract.from_abi("loanToken", address=loanToken.address, abi=LoanToken.abi, owner=accounts[0]) localLoanToken.setTarget(loanTokenLogic.address) localLoanToken = Contract.from_abi("loanToken", address=loanToken.address, abi=LoanTokenLogicStandard.abi, owner=accounts[0]) open_margin_trade_position() #check if checkPause returns false assert (not localLoanToken.checkPause(functionSignature))
def token(gov): # crvLINK token yield Contract("0xcee60cFa923170e4f8204AE08B4fA6A3F5656F3a", owner=gov)
def token(): token_address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" # this should be the address of the ERC-20 used by the strategy/vault (DAI) yield Contract(token_address)
def tricrypto_lp(): return Contract('tricrypto_lp')
print('Usage: {} <address> <path_to_abi_file> [poll_interval]'.format( sys.argv[0])) exit() #read arguments [address, abi_file] = sys.argv[1:3] poll_interval = 5 if (len(sys.argv) > 3): poll_interval = int(sys.argv[3]) # Opening the payCoin contract with open("../blockchain_course_unimi/challenge/teamCST/abi/PayCoin.json" ) as json_file: abi_pc = json.load(json_file) payCoin = Contract.from_abi( 'PayCoin', address="0xa501cA3B72d8D90235BD8ADb2c67aCc062F451FA", abi=abi_pc) # opening the contract to monitor in web3 and brownie format with open(abi_file) as json_file: abi_contract = json.load(json_file) # create the web3 contract object web3Contract = web3.eth.contract(abi=abi_contract, address=address) #create the contract object # create the brownie contract object brownieContract = Contract.from_abi('bContract', address=address, abi=abi_contract) if (brownieContract.address == teamAddresses['teamAA']['exchangeAddress']): lastPrice = brownieContract.lastPrice()[1]
def get_lp(): pd_provider = Contract("0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d") a_provider = Contract(pd_provider.ADDRESSES_PROVIDER()) return Contract(a_provider.getLendingPool())
def dai_vault(): yield Contract('0x19D3364A399d251E894aC732651be8B0E4e85001')
def token(): token_address = "0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e" yield Contract(token_address)
def test_wbtc(HegicKeep3r, deployer, alice, bob): kp3r = Contract.from_explorer("0x1ceb5cb57c4d4e2b2433641b95dd330a33185a44") unlockGasCost = 175_000 unlockValueMultiplier = 10 ethOptions = "0xEfC0eEAdC1132A12c9487d800112693bf49EcfA2" wbtcOptions = "0x3961245DB602eD7c03eECcda33eA3846bD8723BD" helper = "0x93747c4260E64507A213B4016e1d435C9928617f" oracle = "0x73353801921417F465377c8d898c6f4C0270282C" hegicKeep3r = deployer.deploy( HegicKeep3r, kp3r, helper, oracle, ethOptions, wbtcOptions, unlockGasCost, unlockValueMultiplier, ) hegicOptions = Contract.from_explorer(hegicKeep3r.wbtcOptions()) optionIDs = [0, 0, 0] # Buy 3 different ETH call @ 2k for tomorrow tx = hegicOptions.create(24 * 3600, 1e8, 200_000 * 1e8, 2, { "from": bob, "value": bob.balance() }) optionIDs[0] = tx.events["Create"]["id"] tx = hegicOptions.create(24 * 3600, 2 * 1e8, 200_000 * 1e8, 2, { "from": bob, "value": bob.balance() }) optionIDs[1] = tx.events["Create"]["id"] tx = hegicOptions.create(24 * 3600, 10 * 1e8, 200_000 * 1e8, 2, { "from": bob, "value": bob.balance() }) optionIDs[2] = tx.events["Create"]["id"] assert hegicKeep3r.wbtcOptionsUnlockable(optionIDs) == False # TimeTravel two days just to make sure chain.sleep(60 * 60 * 24 * 2) chain.mine(1) # lot's of keep3r boiler plate keeper = accounts.at(kp3r.keeperList(0), force=True) helper = Contract.from_explorer(kp3r.KPRH()) oracle = Contract.from_explorer(helper.UV2SO()) oracleGov = accounts.at(oracle.governance(), force=True) oracle.setMinKeep(0, {"from": oracleGov}) oracle.work({"from": keeper}) # This should happen before kp3r.addJob(hegicKeep3r, {"from": oracleGov}) kp3rWhale = accounts.at("0xf7aa325404f81cf34268657ddf2d046763a8c4ed", force=True) kp3r.approve(kp3r, 2**256 - 1, {"from": kp3rWhale}) kp3r.addCredit(kp3r, hegicKeep3r, Wei("1 ether"), {"from": kp3rWhale}) # Now option should be unlockable! assert hegicKeep3r.wbtcOptionsUnlockable(optionIDs) == True # Only keepers can unlock through the keep3r contract with brownie.reverts(): hegicKeep3r.wbtcUnlockAll(optionIDs, {"from": bob}) t = hegicKeep3r.wbtcUnlockAll(optionIDs, {"from": keeper}) assert t.events["Expire"][0]["id"] == optionIDs[0] assert t.events["Expire"][1]["id"] == optionIDs[1] assert t.events["Expire"][2]["id"] == optionIDs[2] for i in range(3): option = hegicOptions.options(optionIDs[i]) assert option.dict()["state"] == 3
def test_operation(pm, chain): dai_liquidity = accounts.at("0xbebc44782c7db0a1a60cb6fe97d0b483032ff1c7", force=True) # using curve pool (lots of dai) crv3_liquidity = accounts.at("0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490", force=True) # yearn treasury (lots of crv3) crv_liquidity = accounts.at( "0xD533a949740bb3306d119CC777fa900bA034cd52", force=True) # using curve vesting (lots of crv) weth_liquidity = accounts.at("0x2F0b23f53734252Bda2277357e97e1517d6B042A", force=True) # using MKR (lots of weth) rewards = accounts[2] gov = accounts[3] guardian = accounts[4] bob = accounts[5] alice = accounts[6] strategist = accounts[7] tinytim = accounts[8] proxy = accounts[9] # dai approval dai = Contract("0x6b175474e89094c44da98b954eedeac495271d0f", owner=gov) # DAI token dai.approve(dai_liquidity, Wei("1000000 ether"), {"from": dai_liquidity}) dai.transferFrom(dai_liquidity, gov, Wei("300000 ether"), {"from": dai_liquidity}) threePool = Contract("0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7", owner=gov) # crv3 pool address (threePool) #yCRV3 = Contract( # "0x9cA85572E6A3EbF24dEDd195623F188735A5179f", owner=gov #) # crv3 vault (threePool) unirouter = Contract.from_explorer( "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", owner=gov) # UNI router v2 proxy = Contract.from_explorer( "0xc17adf949f524213a540609c386035d7d685b16f", owner=gov) # StrategyProxy gauge = Contract.from_explorer( "0xbFcF63294aD7105dEa65aA58F8AE5BE2D9d0952A", owner=gov) # threePool gauge govProxy = Contract.from_explorer( "0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52", owner=gov) # threePool gauge dai.approve(threePool, Wei("1000000 ether"), {"from": gov}) #crv3 approval crv3 = Contract("0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490", owner=gov) # crv3 token address (threePool token) #depositing DAI to generate crv3 tokens. crv3.approve(crv3_liquidity, Wei("1000000 ether"), {"from": crv3_liquidity}) threePool.add_liquidity([Wei("200000 ether"), 0, 0], 0, {"from": gov}) #crv approval crv = Contract("0xD533a949740bb3306d119CC777fa900bA034cd52", owner=gov) # crv token address (DAO token) crv.approve(crv_liquidity, Wei("1000000 ether"), {"from": crv_liquidity}) crv.transferFrom(crv_liquidity, gov, Wei("10000 ether"), {"from": crv_liquidity}) #weth approval weth = Contract("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", owner=gov) # weth token address weth.approve(weth_liquidity, Wei("1000000 ether"), {"from": weth_liquidity}) weth.transferFrom(weth_liquidity, gov, Wei("10000 ether"), {"from": weth_liquidity}) # config yvCRV3 vault. Vault = pm(config["dependencies"][0]).Vault yCRV3 = Vault.deploy({"from": gov}) yCRV3.initialize(crv3, gov, rewards, "", "") yCRV3.setDepositLimit(Wei("1000000 ether")) strategy = guardian.deploy(Strategy3Poolv2, yCRV3, dai, threePool, crv3, crv, unirouter, weth, proxy, gauge) strategy.setStrategist(strategist) yCRV3.addStrategy(strategy, 10_000, 0, 0, {"from": gov}) #setup for crv3 crv3.approve(gov, Wei("1000000 ether"), {"from": gov}) crv3.transferFrom(gov, bob, Wei("1000 ether"), {"from": gov}) crv3.transferFrom(gov, alice, Wei("4000 ether"), {"from": gov}) crv3.transferFrom(gov, tinytim, Wei("10 ether"), {"from": gov}) crv3.approve(yCRV3, Wei("1000000 ether"), {"from": bob}) crv3.approve(yCRV3, Wei("1000000 ether"), {"from": alice}) crv3.approve(yCRV3, Wei("1000000 ether"), {"from": tinytim}) #setup for dai dai.approve(gov, Wei("1000000 ether"), {"from": gov}) dai.approve(threePool, Wei("1000000 ether"), {"from": gov}) dai.approve(threePool, Wei("1000000 ether"), {"from": strategy}) #setup for crv crv.approve(gov, Wei("1000000 ether"), {"from": gov}) #setup for weth weth.approve(gov, Wei("1000000 ether"), {"from": gov}) proxy.approveStrategy(strategy, {"from": govProxy, "gas limit": 120000000}) # users deposit to vault yCRV3.deposit(Wei("1000 ether"), {"from": bob}) yCRV3.deposit(Wei("4000 ether"), {"from": alice}) yCRV3.deposit(Wei("10 ether"), {"from": tinytim}) chain.mine(1) assert crv3.balanceOf(yCRV3) > 1 assert crv3.balanceOf(alice) == 0 assert yCRV3.balanceOf(alice) > 0 a = yCRV3.pricePerShare() strategy.harvest({"from": gov}) chain.mine(10) assert crv3.balanceOf(strategy) == 0 # there's already crv3 from the existing strategy. It will be counted as profit. b = yCRV3.pricePerShare() assert b > a strategy.setEmergencyExit({"from": gov}) chain.mine(1) assert strategy.emergencyExit() == True strategy.harvest({"from": gov}) chain.mine(1) assert crv3.balanceOf(strategy) == 0 assert crv3.balanceOf(yCRV3) > 0 pass
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}) meta_burner = 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 = CBurner.deploy(underlying_burner, RECOVERY, OWNER_ADMIN, EMERGENCY_ADMIN, {'from': deployer}) yburner = 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")
def vETH(): yield Contract("0x103cc17C2B1586e5Cd9BaD308690bCd0BBe54D5e")
private_key=fss_trading_private_key) local_account_trading = LocalAccount(fss_trading_account.address, fss_trading_account, fss_trading_account.privateKey) ## Admin account fss_admin_private_key = "ede4dd8a3584fd7809a5e0bb299ff8f51983af5b1a9f1f506165b5c1f09e22b1" fss_admin_account = web3.eth.account.from_key( private_key=fss_admin_private_key) local_account_admin = LocalAccount(fss_admin_account.address, fss_admin_account, fss_admin_account.privateKey) with open('./pyscripts/abi/token_exchange.json') as json_file: exchange_abi = json.load(json_file) exchange = Contract.from_abi( 'Exchange', address="0x99d07b3fA4C2046a43e3911AC5a5bC3B0115b110", abi=exchange_abi) print("Charging the prices on the exchange...") prices = pd.read_csv(r'./pyscripts/challenge_scripts/price_history.csv', skiprows=3559, nrows=8759, names=['', 'close']) for j in range(0, 5200, 10): price1 = prices.iloc[j]['close'] price2 = prices.iloc[j + 1]['close'] price3 = prices.iloc[j + 2]['close'] price4 = prices.iloc[j + 3]['close'] price5 = prices.iloc[j + 4]['close'] price6 = prices.iloc[j + 5]['close'] price7 = prices.iloc[j + 6]['close']
def vVSP(): yield Contract("0xbA4cFE5741b357FA371b506e5db0774aBFeCf8Fc")
def KV1O() -> Contract: # SushiswapV1Oracle return Contract.from_explorer("0xf67Ab1c914deE06Ba0F264031885Ea7B276a7cDa")
def tricrypto(): return Contract('tricrypto')
def token(): token_address = "" # this should be the address of the ERC-20 used by the strategy/vault yield Contract(token_address)
def sushi(): return Contract('sushi_router')
def get_name(addr): try: name = Contract(addr)._name return f"{addr} {name}" except ValueError: return str(addr)
def test_operation(accounts, token, vault, strategy, strategist, amount, user, crv3, chain, whale_3crv, gov): chain.snapshot() vault_before = token.balanceOf(vault) strat_before = token.balanceOf(strategy) # Deposit to the vault token.approve(vault.address, amount, {"from": user}) vault.deposit(amount, {"from": user}) assert token.balanceOf(vault.address) == amount + vault_before # Move funds to strat strategy.harvest({"from":strategist}) assert token.balanceOf(strategy.address) == amount + vault_before + strat_before # Done to fix the UniswapV2: K issue pairs = [strategy.ethCrvPair(), strategy.ethYvBoostPair(), strategy.ethUsdcPair()] for pair in pairs: Contract.from_explorer(pair, owner=strategist).sync() # harvest to accrue strategist reward as this is part of our test # to make sure that these yvBOOST shares are separated from the purhcased # amount and not used to withdraw yveCRV from vault strategist_reward_before = vault.balanceOf(strategy) crv3.transfer(strategy, 10e20, {"from": whale_3crv}) strategy.harvest({"from":strategist}) chain.sleep(60*60*6) # sleep to increase pps chain.mine(1) strategist_reward_before = vault.balanceOf(strategy) crv3.transfer(strategy, 10e20, {"from": whale_3crv}) strategy.harvest({"from":strategist}) chain.sleep(60*60*6) # sleep to increase pps chain.mine(1) params = vault.strategies(strategy) total_debt = params.dict()["totalDebt"] assert total_debt == token.balanceOf(strategy) # test strategist reward increase strategist_reward_after = vault.balanceOf(strategy) print("strategist reward before",strategist_reward_before) print("strategist reward after",strategist_reward_after) assert strategist_reward_after > strategist_reward_before # Test mint/buy paths crv3.transfer(strategy, 10e20, {"from": whale_3crv}) chain.snapshot() a = accounts[7] a2 = accounts[8] a3 = accounts[9] a4 = accounts[6] a5 = accounts[5] sushi = Contract("0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F") pathBOOST = [ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", # WETH "0x9d409a0a012cfba9b15f6d4b36ac57a46966ab9a" # yvBOOST ] pathCRV = [ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", # WETH "0xD533a949740bb3306d119CC777fa900bA034cd52" # CRV ] sushi.swapExactETHForTokens(0,pathCRV,a,math.ceil(time.time()+1e6),{'from':a,'value':100e18}) tx1 = strategy.harvest() assert tx1.events['BuyOrMint']['shouldMint'] == False chain.revert() # Make yvBOOST more expensive before = sushi.getAmountsOut(12*1e18, pathBOOST) sushi.swapExactETHForTokens(0,pathBOOST,a,math.ceil(time.time()+1e6),{'from':a,'value':100e18}) sushi.swapExactETHForTokens(0,pathBOOST,a2,math.ceil(time.time()+1e6),{'from':a2,'value':100e18}) sushi.swapExactETHForTokens(0,pathBOOST,a3,math.ceil(time.time()+1e6),{'from':a3,'value':100e18}) sushi.swapExactETHForTokens(0,pathBOOST,a4,math.ceil(time.time()+1e6),{'from':a4,'value':100e18}) sushi.swapExactETHForTokens(0,pathBOOST,a5,math.ceil(time.time()+1e6),{'from':a5,'value':100e18}) after = sushi.getAmountsOut(12*1e18, pathBOOST) assert after < before tx2 = strategy.harvest() print(tx2.events['BuyOrMint']['shouldMint']) assert tx2.events['BuyOrMint']['shouldMint'] == True # withdrawal vault.withdraw({"from": user}) assert token.balanceOf(user) != 0 strategy.setBuffer(40, {"from": gov}) # increase buffer to 4% strategy.restoreApprovals({"from":gov}) # make sure reset approvals works strategy.setProxy("0xA420A63BbEFfbda3B147d0585F1852C358e2C152",{"from":gov}) chain.revert()
def router(): yield Contract("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D")
def dai(gov): # dai yield Contract("0x6B175474E89094C44Da98b954EedeAC495271d0F", owner=gov)
def base_swap(project, charlie, _base_coins, base_pool_token, base_pool_data, is_forked): if base_pool_data is None: return if is_forked: return Contract(base_pool_data["swap_address"]) return _swap(project, charlie, _base_coins, _base_coins, base_pool_token, base_pool_data, None, None, None)
def token(): token_address = "0x6b175474e89094c44da98b954eedeac495271d0f" # this should be the address of the ERC-20 used by the strategy/vault (DAI) yield Contract(token_address)
def aave_lending_pool(AaveLendingPoolMock, pool_data, alice, is_forked): if pool_data['name'] == "aave": if is_forked: return Contract("0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9") else: return AaveLendingPoolMock.deploy({'from': alice})
def test_migration( token, vault, strategy, amount, Strategy, strategist, gov, susd_vault, chain ): chain.snapshot() # Move stale period to 6 days resolver = Contract(strategy.resolver()) settings = Contract( resolver.getAddress(encode_single("bytes32", b"SystemSettings")) ) settings.setRateStalePeriod(24 * 3600 * 6, {"from": settings.owner()}) settings.setDebtSnapshotStaleTime(24 * 3600 * 6, {"from": settings.owner()}) # Deposit to the vault and harvest token.approve(vault, amount, {"from": gov}) vault.deposit(amount, {"from": gov}) strategy.harvest({"from": gov}) assert token.balanceOf(strategy) == amount # sleep for 24h to be able to burn synths chain.sleep(24 * 3600 + 1) chain.mine(1) # migrate to a new strategy new_strategy = strategist.deploy(Strategy, vault, susd_vault) strategy.migrate(new_strategy, {"from": gov}) assert token.balanceOf(new_strategy) == amount chain.revert()
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}" )