def pre_deploy_setup(self, deploy=True): """ Deploy DIGG System and Dynamic oracle for testing. """ if not deploy: digg = connect_digg(digg_config.prod_json) self.digg = digg self._deploy_dynamic_oracle(self.digg.devMultisig) # digg.constantOracle.updateAndPush({"from": digg.devMultisig}) # Sleep long enough that the report is valid. chain.sleep(digg_config.cpiOracleParams.reportDelaySec) return deployer = self.deployer devProxyAdminAddress = web3.toChecksumAddress( "0x20dce41acca85e8222d6861aa6d23b6c941777bf") daoProxyAdminAddress = web3.toChecksumAddress( "0x11a9d034b1bbfbbdcac9cb3b86ca7d5df05140f2") self.digg = deploy_digg_minimal(deployer, devProxyAdminAddress, daoProxyAdminAddress, owner=deployer) self.badger.deploy_logic("DiggRewardsFaucet", DiggRewardsFaucet) self._deploy_dynamic_oracle(self.deployer)
def test_curve_lp_price_oracle_historical(name): if name in ['linkusd']: pytest.xfail('no active market') token = web3.toChecksumAddress(pooldata[name]['lp_token_address']) swap = web3.toChecksumAddress(pooldata[name]['swap_address']) deploy = contract_creation_block(swap) # sample 10 blocks over the pool lifetime blocks = [ int(block) for block in np.linspace(deploy + 10000, chain.height, 10) ] prices = [] for block in blocks: try: prices.append(curve.curve.get_price(token, block)) except (PriceError, TypeError): prices.append(None) virtual_prices = [ contract(swap).get_virtual_price(block_identifier=block) / 1e18 for block in blocks ] print( tabulate(list(zip(blocks, prices, virtual_prices)), headers=['block', 'price', 'vp']))
def __init__(self): self.contract_registry = registry.pancake self.factory = interface.IUniswapV2Factory( web3.toChecksumAddress(self.contract_registry.factoryV2)) self.router = interface.IUniswapRouterV2( web3.toChecksumAddress(self.contract_registry.routerV2)) self.chef = interface.ISushiChef(self.contract_registry.masterChef)
def __init__(self): self.contract_registry = registry.sushiswap self.factory = interface.IUniswapV2Factory( web3.toChecksumAddress(self.contract_registry.factory)) self.router = interface.IUniswapRouterV2( web3.toChecksumAddress(self.contract_registry.router)) self.chef = interface.ISushiChef(self.contract_registry.sushiChef) self.bar = interface.IxSushi(self.contract_registry.xsushiToken)
def address_to_id(token_address): checksummed = web3.toChecksumAddress(token_address) if checksummed == web3.toChecksumAddress(registry.tokens.wbtc): return "wrapped-bitcoin" if checksummed == web3.toChecksumAddress(registry.tokens.badger): return "badger-dao" if checksummed == web3.toChecksumAddress(registry.tokens.digg): return "digg" else: assert False
def getContracts(): global Contracts, abis, addresses try: abis = pickle.load(open("abis.pickle", "rb")) addresses = pickle.load(open("addresses.pickle", "rb")) Contracts = pickle.load(open("Contracts.pickle", "rb")) change = False for key, value in ercAddresses.items(): if key in Contracts.keys(): print(key, addresses[key]) else: change = True address = web3.toChecksumAddress(value) addresses[key] = address if key in ['WBTC', 'WETH', 'LINK']: abi = json.loads( getABI( web3.toChecksumAddress( implementationAddresses[key]))['result']) abis[key] = abi Contracts[key] = Contract.from_abi(key, address, abi) else: abi = json.loads(getABI(address)['result']) abis[key] = abi Contracts[key] = Contract.from_abi(key, address, abi) if change == True: pickle.dump(abis, open("abis.pickle", "wb")) pickle.dump(addresses, open("addresses.pickle", "wb")) pickle.dump(Contracts, open("Contracts.pickle", "wb")) except (OSError, IOError) as e: for key, value in ercAddresses.items(): address = web3.toChecksumAddress(value) addresses[key] = address if key in ['WBTC', 'WETH', 'LINK']: abi = json.loads( getABI(web3.toChecksumAddress( implementationAddresses[key]))['result']) abis[key] = abi Contracts[key] = Contract.from_abi(key, address, abi) else: abi = json.loads(getABI(address)['result']) abis[key] = abi Contracts[key] = Contract.from_abi(key, address, abi) pickle.dump(abis, open("abis.pickle", "wb")) pickle.dump(addresses, open("addresses.pickle", "wb")) pickle.dump(Contracts, open("Contracts.pickle", "wb"))
def connect_bridge(badger, badger_deploy_file): bridge_deploy = {} console.print( "[grey]Connecting to Existing 🦡 Bridge System at {}...[/grey]". format(badger_deploy_file)) with open(badger_deploy_file) as f: badger_deploy = json.load(f) """ Connect to existing bridge deployment """ bridge_deploy = badger_deploy["bridge_system"] abi = artifacts.open_zeppelin["ProxyAdmin"]["abi"] bridge = BridgeSystem( badger.deployer, Contract.from_abi( "ProxyAdmin", web3.toChecksumAddress(badger_deploy["devProxyAdmin"]), abi, ), bridge_config, ) bridge.connect_logic(bridge_deploy["logic"]) bridge.connect_adapter(bridge_deploy["adapter"]) bridge.connect_curve_token_wrapper(bridge_deploy["curveTokenWrapper"]) return bridge
def deploy_adapter(self, registry, router, deployer): config = self.config # deployer = self.deployer devProxyAdmin = self.devProxyAdmin logic = self.logic self.adapter = deploy_proxy( "BadgerBridgeAdapter", BadgerBridgeAdapter.abi, logic.BadgerBridgeAdapter.address, web3.toChecksumAddress(devProxyAdmin.address), logic.BadgerBridgeAdapter.initialize.encode_input( config.governance, config.rewards, registry, router, config.wbtc, [ config.mintFeeBps, config.burnFeeBps, config.percentageFeeRewardsBps, config.percentageFeeGovernanceBps, ], ), deployer, )
def test_curve_total_value(name, curve_tvl_api): if name in ['linkusd']: pytest.xfail('no active market') pool = web3.toChecksumAddress(pooldata[name]['swap_address']) tvl = curve.curve.get_tvl(pool) print(name, tvl) assert tvl
def launcher_pool_liquidity(PoolLiquidity, launcher): template_id = 1 tx = launcher.createLiquidityLauncher(template_id, {"from": accounts[0]}) assert "LiquidityLauncherCreated" in tx.events pool_liquidity = PoolLiquidity.at( web3.toChecksumAddress(tx.events['LiquidityLauncherCreated']['addr'])) return pool_liquidity
def main(): # uncomment to rescan the blockchain, it takes about ~30mins because it has to retrieve tx data for each mint event # new_renbtc_minters_data = get_renbtc_mint() # with open('./snapshot/renbtcMinters_NEW.json', 'w') as fp: # json.dump(new_renbtc_minters_data, fp) # prescanned data with open('./snapshot/renbtcMinters_NEW.json', 'r') as fp: new_renbtc_minters_data = json.load(fp) with open('./snapshot/renbtcMinters.json', 'r') as fp: old_renbtc_minters_data = json.load(fp) with open('./snapshot/final.json', 'r') as fp: final = json.load(fp) # converting all addresses to ChecksumAddress just incase old_renbtc_minters_addresses = set([web3.toChecksumAddress(address) for address in set(old_renbtc_minters_data.keys())]) new_renbtc_minters_addresses = set([web3.toChecksumAddress(address) for address in set(new_renbtc_minters_data.keys())]) final_snapshot_addresses = set([web3.toChecksumAddress(address) for address in set(final.keys())]) in_new_but_not_in_old = new_renbtc_minters_addresses - old_renbtc_minters_addresses renbtc_minters_notin_final = new_renbtc_minters_addresses - final_snapshot_addresses # double check the subtraction logic above missing = Counter() for address in new_renbtc_minters_addresses: if address not in old_renbtc_minters_addresses: missing['oldminters'] += 1 if address not in final_snapshot_addresses: missing['finalsnapshot'] += 1 assert missing['oldminters'] == len(in_new_but_not_in_old) assert missing['finalsnapshot'] == len(renbtc_minters_notin_final) print(f"Number of renbtc minters not credited for minting: {len(in_new_but_not_in_old)}") print(f"Number of minters that are not included in final.json: {len(renbtc_minters_notin_final)}")
def deploy_router(self): admin = self.admin devProxyAdmin = self.devProxyAdmin self.router = deploy_proxy( "SwapStrategyRouter", SwapStrategyRouter.abi, self.logic.SwapStrategyRouter.address, web3.toChecksumAddress(devProxyAdmin.address), self.logic.SwapStrategyRouter.initialize.encode_input( admin.address, ), self.deployer, )
def get_boi_holders(): holders = Counter() contract = web3.eth.contract(web3.toChecksumAddress(boi), abi=erc721ABI) for start in trange(boiStart, 13392532, 1000): end = min(start + 999, 13392532) logs = contract.events.Transfer().getLogs(fromBlock=start, toBlock=end) for log in logs: holders[log['args']['from']] -= 1 holders[log['args']['to']] += 1 filteredMints = valfilter(bool, dict(holders.most_common())) print(len(filteredMints)) return filteredMints
def deploy_curve_swap_strategy(self): config = self.config admin = self.admin devProxyAdmin = self.devProxyAdmin self.strategies.curve = deploy_proxy( "CurveSwapStrategy", CurveSwapStrategy.abi, self.logic.CurveSwapStrategy.address, web3.toChecksumAddress(devProxyAdmin.address), self.logic.CurveSwapStrategy.initialize.encode_input( admin.address, config.strategies.curve.registry, ), self.deployer, )
def erc1820_registry(ERC1820Registry): # ERC1820Registry contract deployment # See https://github.com/ethereum/EIPs/issues/1820 for more details raw_transaction = '0xf90a388085174876e800830c35008080b909e5608060405234801561001057600080fd5b506109c5806100206000396000f3fe608060405234801561001057600080fd5b50600436106100a5576000357c010000000000000000000000000000000000000000000000000000000090048063a41e7d5111610078578063a41e7d51146101d4578063aabbb8ca1461020a578063b705676514610236578063f712f3e814610280576100a5565b806329965a1d146100aa5780633d584063146100e25780635df8122f1461012457806365ba36c114610152575b600080fd5b6100e0600480360360608110156100c057600080fd5b50600160a060020a038135811691602081013591604090910135166102b6565b005b610108600480360360208110156100f857600080fd5b5035600160a060020a0316610570565b60408051600160a060020a039092168252519081900360200190f35b6100e06004803603604081101561013a57600080fd5b50600160a060020a03813581169160200135166105bc565b6101c26004803603602081101561016857600080fd5b81019060208101813564010000000081111561018357600080fd5b82018360208201111561019557600080fd5b803590602001918460018302840111640100000000831117156101b757600080fd5b5090925090506106b3565b60408051918252519081900360200190f35b6100e0600480360360408110156101ea57600080fd5b508035600160a060020a03169060200135600160e060020a0319166106ee565b6101086004803603604081101561022057600080fd5b50600160a060020a038135169060200135610778565b61026c6004803603604081101561024c57600080fd5b508035600160a060020a03169060200135600160e060020a0319166107ef565b604080519115158252519081900360200190f35b61026c6004803603604081101561029657600080fd5b508035600160a060020a03169060200135600160e060020a0319166108aa565b6000600160a060020a038416156102cd57836102cf565b335b9050336102db82610570565b600160a060020a031614610339576040805160e560020a62461bcd02815260206004820152600f60248201527f4e6f7420746865206d616e616765720000000000000000000000000000000000604482015290519081900360640190fd5b6103428361092a565b15610397576040805160e560020a62461bcd02815260206004820152601a60248201527f4d757374206e6f7420626520616e204552433136352068617368000000000000604482015290519081900360640190fd5b600160a060020a038216158015906103b85750600160a060020a0382163314155b156104ff5760405160200180807f455243313832305f4143434550545f4d4147494300000000000000000000000081525060140190506040516020818303038152906040528051906020012082600160a060020a031663249cb3fa85846040518363ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004018083815260200182600160a060020a0316600160a060020a031681526020019250505060206040518083038186803b15801561047e57600080fd5b505afa158015610492573d6000803e3d6000fd5b505050506040513d60208110156104a857600080fd5b5051146104ff576040805160e560020a62461bcd02815260206004820181905260248201527f446f6573206e6f7420696d706c656d656e742074686520696e74657266616365604482015290519081900360640190fd5b600160a060020a03818116600081815260208181526040808320888452909152808220805473ffffffffffffffffffffffffffffffffffffffff19169487169485179055518692917f93baa6efbd2244243bfee6ce4cfdd1d04fc4c0e9a786abd3a41313bd352db15391a450505050565b600160a060020a03818116600090815260016020526040812054909116151561059a5750806105b7565b50600160a060020a03808216600090815260016020526040902054165b919050565b336105c683610570565b600160a060020a031614610624576040805160e560020a62461bcd02815260206004820152600f60248201527f4e6f7420746865206d616e616765720000000000000000000000000000000000604482015290519081900360640190fd5b81600160a060020a031681600160a060020a0316146106435780610646565b60005b600160a060020a03838116600081815260016020526040808220805473ffffffffffffffffffffffffffffffffffffffff19169585169590951790945592519184169290917f605c2dbf762e5f7d60a546d42e7205dcb1b011ebc62a61736a57c9089d3a43509190a35050565b600082826040516020018083838082843780830192505050925050506040516020818303038152906040528051906020012090505b92915050565b6106f882826107ef565b610703576000610705565b815b600160a060020a03928316600081815260208181526040808320600160e060020a031996909616808452958252808320805473ffffffffffffffffffffffffffffffffffffffff19169590971694909417909555908152600284528181209281529190925220805460ff19166001179055565b600080600160a060020a038416156107905783610792565b335b905061079d8361092a565b156107c357826107ad82826108aa565b6107b85760006107ba565b815b925050506106e8565b600160a060020a0390811660009081526020818152604080832086845290915290205416905092915050565b6000808061081d857f01ffc9a70000000000000000000000000000000000000000000000000000000061094c565b909250905081158061082d575080155b1561083d576000925050506106e8565b61084f85600160e060020a031961094c565b909250905081158061086057508015155b15610870576000925050506106e8565b61087a858561094c565b909250905060018214801561088f5750806001145b1561089f576001925050506106e8565b506000949350505050565b600160a060020a0382166000908152600260209081526040808320600160e060020a03198516845290915281205460ff1615156108f2576108eb83836107ef565b90506106e8565b50600160a060020a03808316600081815260208181526040808320600160e060020a0319871684529091529020549091161492915050565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff161590565b6040517f01ffc9a7000000000000000000000000000000000000000000000000000000008082526004820183905260009182919060208160248189617530fa90519096909550935050505056fea165627a7a72305820377f4a2d4301ede9949f163f319021a6e9c687c292a5e2b2c4734c126b524e6c00291ba01820182018201820182018201820182018201820182018201820182018201820a01820182018201820182018201820182018201820182018201820182018201820' abi = [{"constant":False,"inputs":[{"name":"_addr","type":"address"},{"name":"_interfaceHash","type":"bytes32"},{"name":"_implementer","type":"address"}],"name":"setInterfaceImplementer","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[{"name":"_addr","type":"address"}],"name":"getManager","outputs":[{"name":"","type":"address"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":False,"inputs":[{"name":"_addr","type":"address"},{"name":"_newManager","type":"address"}],"name":"setManager","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[{"name":"_interfaceName","type":"string"}],"name":"interfaceHash","outputs":[{"name":"","type":"bytes32"}],"payable":False,"stateMutability":"pure","type":"function"},{"constant":False,"inputs":[{"name":"_contract","type":"address"},{"name":"_interfaceId","type":"bytes4"}],"name":"updateERC165Cache","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[{"name":"_addr","type":"address"},{"name":"_interfaceHash","type":"bytes32"}],"name":"getInterfaceImplementer","outputs":[{"name":"","type":"address"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[{"name":"_contract","type":"address"},{"name":"_interfaceId","type":"bytes4"}],"name":"implementsERC165InterfaceNoCache","outputs":[{"name":"","type":"bool"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[{"name":"_contract","type":"address"},{"name":"_interfaceId","type":"bytes4"}],"name":"implementsERC165Interface","outputs":[{"name":"","type":"bool"}],"payable":False,"stateMutability":"view","type":"function"},{"anonymous":False,"inputs":[{"indexed":True,"name":"addr","type":"address"},{"indexed":True,"name":"interfaceHash","type":"bytes32"},{"indexed":True,"name":"implementer","type":"address"}],"name":"InterfaceImplementerSet","type":"event"},{"anonymous":False,"inputs":[{"indexed":True,"name":"addr","type":"address"},{"indexed":True,"name":"newManager","type":"address"}],"name":"ManagerChanged","type":"event"}] deployment_address = web3.toChecksumAddress('0xa990077c3205cbDf861e17Fa532eeB069cE9fF96') funding_amount = Wei("1 ether") # Send ether to the registry deployment account web3.eth.sendTransaction({ 'from': accounts[0].address, 'to': deployment_address, 'value': funding_amount }) # Deploy ERC1820Registry contract tx_hash = web3.eth.sendRawTransaction(raw_transaction) # Print brownie-style TransactionReceipt TransactionReceipt(tx_hash, deployment_address, name='ERC1820Registry.constructor') return Contract('ERC1820Registry','0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24', abi)
def connect_swap(badger_deploy_file): swap_deploy = {} console.print( "[grey]Connecting to Existing Swap 🦡 System at {}...[/grey]".format( badger_deploy_file)) with open(badger_deploy_file) as f: badger_deploy = json.load(f) """ Connect to existing swap deployment """ swap_deploy = badger_deploy["swap_system"] abi = artifacts.open_zeppelin["ProxyAdmin"]["abi"] swap = SwapSystem( badger_deploy["deployer"], Contract.from_abi( "ProxyAdmin", web3.toChecksumAddress(badger_deploy["devProxyAdmin"]), abi, ), swap_config, ) swap.connect_logic(swap_deploy["logic"]) # arguments: (attr name, address) strategies = swap_deploy["strategies"] connectable = [ ( "curve", "CurveSwapStrategy", strategies["curve"], ), ] for args in connectable: swap.connect_strategy(*args) swap.connect_router(swap_deploy["router"]) return swap
def calc_tree_rewards(badger, startBlock, endBlock, nextCycle): # sharesPerFragment = badger.digg.logic.UFragments._sharesPerFragment() # _, _2, ibbtc_balances = fetch_wallet_balances(sharesPerFragment, endBlock) treeDists = fetch_tree_distributions(startBlock, endBlock) console.log( "Calculating rewards for {} harvests between {} and {}".format( len(treeDists), startBlock, endBlock ) ) rewards = RewardsList(nextCycle, badger.badgerTree) rewardsData = {} for dist in treeDists: blockNumber = dist["blockNumber"] strategy = dist["id"].split("-")[0] token = dist["token"]["address"] symbol = dist["token"]["symbol"] amountToDistribute = int(dist["amount"]) console.log("Processing harvest...") console.log("Token:{}".format(symbol)) console.log("Amount:{} \n".format(amountToDistribute / 1e18)) if symbol not in rewardsData: rewardsData[symbol] = 0 rewardsData[symbol] += amountToDistribute / 1e18 settName = badger.getSettFromStrategy(strategy) balances = calculate_sett_balances(badger, settName, int(blockNumber)) totalBalance = sum([u.balance for u in balances]) rewardsUnit = amountToDistribute / totalBalance rewardsLog.add_total_token_dist( settName, web3.toChecksumAddress(token), amountToDistribute / 1e18 ) # totalIbbtcBalance = sum(ibbtc_balances.values()) for user in balances: userReward = rewardsUnit * user.balance # if user.address in [a.lower() for a in PEAK_ADDRESSES]: # ibbtcRewardsUnit = userReward / totalIbbtcBalance # console.log( # "Distributing {} {} to {} ibbtc holders from {}".format( # userReward / 1e18, symbol, len(ibbtc_balances), settName # ) # ) # # Redistribute peak addresses rewards to ibbtc users # for addr, balance in ibbtc_balances.items(): # rewards.increase_user_rewards( # web3.toChecksumAddress(addr), # token, # int(ibbtcRewardsUnit * balance), # ) # else: rewards.increase_user_rewards( web3.toChecksumAddress(user.address), web3.toChecksumAddress(token), int(userReward), ) console.log(rewardsData) return rewards
badger_total_supply = Wei("21000000 ether") multisig_config = DotMap( address="0xB65cef03b9B89f99517643226d76e286ee999e77", owners=[ "0xe24b6bF43d4624B2E146D3F871e19b7ECb811208", "0x211b82242076792A07C7554A5B968F0DE4414938", "0xe7bab002A39f9672a1bD0E949d3128eeBd883575", "0x59c68A651a1f49C26145666E9D5647B1472912A9", "0x15b8Fe651C268cfb5b519cC7E98bd45C162313C2", ], ) dao_config = DotMap( initialOwner=web3.toChecksumAddress( "0xDA25ee226E534d868f0Dd8a459536b03fEE9079b"), token="0x3472a5a71965499acd81997a54bba8d852c6e53d", kernel="0x33D53383314190B0B885D1b6913B5a50E2D3A639", agent="0x8de82c4c968663a0284b01069dde6ef231d0ef9b", ) globalStartTime = 1607014800 badger_config = DotMap( prod_json="deploy-final.json", test_mode=False, startMultiplier=1, endMultiplier=3, multisig=multisig_config, dao=dao_config, globalStartTime=globalStartTime,
def curve_tvl_api(): data = requests.get('https://api.curve.fi/api/getTVL').json() return { web3.toChecksumAddress(pool['pool_address']): pool['balance'] for pool in data['data']['allPools'] }
def test_get_balances_fallback(name): registry_deploy = 12195750 pool = web3.toChecksumAddress(pooldata[name]['swap_address']) if curve.curve.get_factory(pool): pytest.skip('not applicable to metapools') print(name, curve.curve.get_balances(pool, block=registry_deploy))
def main(): getContracts() # get native balances getBalances() # convert to checksum address getAddresses() # quote for 1 asset in usd # amountIn = 1 * 10 ** 18 # use WXDAI as common market measure (assume WXDAI = $1) quote = 'WXDAI' # wxdai_abi = json.loads(getABI(contracts['WXDAI'])['result']) # print(wxdai_abi) # wxdai_contract = Contract.from_abi("WXDAI", contracts['WXDAI'], wxdai_abi) wxdai_contract = Contracts["WXDAI"] # wxdai_contract = web3.eth.contract( # address=contracts['WXDAI'], abi=wxdai_abi) for key, value in balances.items(): asset = key if asset != 'WXDAI' and asset != 'XDAI' and asset != 'UNI-V2': print(asset) path = [] path.append(contracts[asset]) path.append(contracts[quote]) # quote for 1 asset in usd amountIn = 1 * 10**decimals[key] amounts = honeyswap_join.functions.getAmountsOut(amountIn, path).call() # print(amounts) amountOut = amounts[-1] print(convertToNormal(amountOut, decimals[asset])) prices[asset] = convertToNormal(amountOut, decimals[asset]) prices['XDAI'] = 1.0 prices['WXDAI'] = 1.0 # prices['UNI-V2'] = shareVal pprint.pprint(prices) total = 0 for key, value in balances.items(): if key != 'UNI-V2': asset = key balancesusd[asset] = value * prices[asset] total = total + balancesusd[asset] pprint.pprint(balancesusd) print(total) # get difference diffs = {} for key, value in portfolio.items(): adjshare = total * value currshare = balancesusd[key] diff = adjshare - currshare diffs[key] = diff diffs = dict(sorted(diffs.items(), key=lambda x: x[1])) print('Adjustments ') pprint.pprint(diffs) # WXDAI as base # fill first if diffs['XDAI'] < -4.0: # swap xDai for wxDai dummydiff = 0 - diffs['XDAI'] if dummydiff > 4.0: amountWei = backtoWack(dummydiff, 18) print(amountWei) tx_hash = wxdai_contract.deposit({ "from": acct, "value": amountWei }) for key, value in diffs.items(): if key != 'XDAI' and key != 'WXDAI' and key != 'UNI-V2': if value < -4.0: asset_contract = Contracts[key] pathAddresses = [] pathAddresses.append(contracts[key]) pathAddresses.append(contracts[quote]) toAdrress = web3.toChecksumAddress(accAddress) amountOut = 0 - value amountOutWei = backtoWack(amountOut, 18) amountInMax = amountOut / prices[key] # slippage 1 % amountInMax = amountInMax + amountInMax * 0.02 amountInMaxWei = backtoWack(amountInMax, 18) # 2 hour deadline deadline = int(time.time() + 60 * 60 * 2) print(key, amountOutWei, amountInMaxWei, pathAddresses, toAdrress, deadline) if key == 'HNY': asset_contract.approve(honeyswap_contract, 0, {"from": acct}) asset_contract.approve(honeyswap_contract, amountInMaxWei, {"from": acct}) Honeyswap_Contract.swapTokensForExactTokens( amountOutWei, amountInMaxWei, pathAddresses, toAdrress, deadline, { "from": acct, "gas_limit": 12487780, "gas_price": 1000000000 }) for key, value in diffs.items(): if key != 'XDAI' and key != 'WXDAI' and key != 'UNI-V2': if value > 4.0: pathAddresses = [] pathAddresses.append(contracts[quote]) pathAddresses.append(contracts[key]) toAdrress = web3.toChecksumAddress(accAddress) amountOutMin = value / prices[key] # slippage 1 % amountOutMin = amountOutMin - amountOutMin * 0.02 amountOutMinWei = backtoWack(amountOutMin, 18) amountIn = value amountInWei = backtoWack(amountIn, 18) # 2 hour deadline deadline = int(time.time() + 60 * 60 * 2) print(key, amountInWei, amountOutMinWei, pathAddresses, toAdrress, deadline) wxdai_contract.approve(honeyswap_contract, amountInWei, {"from": acct}) Honeyswap_Contract.swapExactTokensForTokens( amountInWei, amountOutMinWei, pathAddresses, toAdrress, deadline, { "from": acct, "gas_limit": 12487780, "gas_price": 1000000000 }) if diffs['XDAI'] > 4.0: # swap wxDai for xDai amountWei = backtoWack(diffs['XDAI'], 18) print(amountWei) tx_hash = wxdai_contract.withdraw(amountWei, {"from": acct}) print(tx_hash)
def getAddresses(): global contracts for key, value in ercAddresses.items(): contracts[key] = web3.toChecksumAddress(value)
def getAddresses(): global contracts for key, value in ercAddresses.items(): contracts[key] = web3.toChecksumAddress(value) # honeyswapFactory_contract = web3.toChecksumAddress(UniswapV2Factory) # print(honeyswapFactory_contract) # # load our contract # honeyswapFactory_join = web3.eth.contract( # address=honeyswapFactory_contract, abi=UniswapV2Factoryabi) # contract_response = honeyswapFactory_join.functions.allPairsLength().call() # print(contract_response) honeyswap_contract = web3.toChecksumAddress(UniswapV2Router02) # load our contract honeyswap_join = web3.eth.contract(address=honeyswap_contract, abi=UniswapV2Router02abi) Honeyswap_Contract = Contract.from_abi("Honeyswap", honeyswap_contract, UniswapV2Router02abi) # # find liquidity share value # UNIV2 = "0x4505b262dc053998c10685dc5f9098af8ae5c8ad" # univ2_contract = web3.toChecksumAddress(UNIV2) # # load our contract # univ2_join = web3.eth.contract( # address=univ2_contract, abi=UniswapV2Pairabi) # # ress = convertToNormal(univ2_join.functions.kLast().call(), 18) # ress2 = univ2_join.functions.getReserves().call() # # print(ress)
import sys acct = accounts.load("arbAccount") one_inch_split_abi = json.load(open("scripts/abi/IOneSplitMulti_old.json", "r")) # 20 ether in wei loan = "20000000000000000000" arbMargin = 2.0 altarbMargin = 2.2 parts = 10 AAVE_LENDING_POOL_ADDRESS_PROVIDER = "0x24a42fD28C976A61Df5D00D0599C34c4f90748c8" OneSplitAddress = "0x50FDA034C0Ce7a8f7EFDAebDA7Aa7cA21CC1267e" one_inch_split_contract = web3.toChecksumAddress( OneSplitAddress) # 1 inch split contract # load our contract one_inch_join = web3.eth.contract(address=one_inch_split_contract, abi=one_inch_split_abi) markets = {} blacklist = [] blacklist.append("CHAI-ETH") blacklist.append("CHAI-USDT") blacklist.append("CHAI-DAI") blacklist.append("CHAI-USDC") ercAddresses = {} contracts = {} priceOfETH = {}