def withdraw_asset_on_ethereum(burn_tx_id: str = MATIC_BURN_TX_ID, sender=MSG_SENDER): print("Building Calldata") calldata = build_calldata(burn_tx_id) fp = f"withdraw-calldata-{datetime.now().isoformat()}.txt" with open(fp, "w") as f: f.write(calldata.hex()) root_chain_mgr_proxy_addr = ADDRS[ network.show_active()]["RootChainManagerProxy"] abi = get_loaded_projects()[0].interface.RootChainManager.abi root_chain_mgr = Contract.from_abi("RootChainManager", root_chain_mgr_proxy_addr, abi) print("Calling Exit Function on Root Chain Manager") root_chain_mgr.exit(calldata, { "from": sender, "gas_price": GasNowScalingStrategy("fast") }) # transfer USDC out of the root receiver usdc = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" root_receiver = RootForwarder.at( "0x4473243A61b5193670D1324872368d015081822f") root_receiver.transfer(usdc, { "from": sender, "gas_price": GasNowScalingStrategy("fast") })
def main(): deployer = accounts.load("deployer") balance = deployer.balance() gas_strategy = GasNowScalingStrategy() vault = deployer.deploy( AlphaVault, POOL, PROTOCOL_FEE, MAX_TOTAL_SUPPLY, publish_source=True, gas_price=gas_strategy, ) strategy = deployer.deploy( PassiveStrategy, vault, BASE_THRESHOLD, LIMIT_THRESHOLD, PERIOD, MIN_TICK_MOVE, MAX_TWAP_DEVIATION, TWAP_DURATION, KEEPER, publish_source=True, gas_price=gas_strategy, ) vault.setStrategy(strategy, {"from": deployer, "gas_price": gas_strategy}) print(f"Gas used: {(balance - deployer.balance()) / 1e18:.4f} ETH") print(f"Vault address: {vault.address}")
def main(): deployer = accounts.load("deployer") balance = deployer.balance() gas_strategy = GasNowScalingStrategy() feeds = deployer.deploy(ChainlinkFeedsRegistry, publish_source=True, gas_price=gas_strategy) feeds.addEthFeed( "BTC", "0x2431452A0010a43878bF198e170F6319Af6d27F4", {"gas_price": gas_strategy}, ) feeds.addUsdFeed( "ETH", "0x8A753747A1Fa494EC906cE90E9f37563A8AF630e", {"gas_price": gas_strategy}, ) feeds.addUsdFeed( "LINK", "0xd8bD0a1cB028a31AA859A21A3758685a95dE4623", {"gas_price": gas_strategy}, ) feeds.addUsdFeed( "SNX", "0xE96C4407597CD507002dF88ff6E0008AB41266Ee", {"gas_price": gas_strategy}, ) cubeTokenImpl = deployer.deploy(CubeToken, publish_source=True, gas_price=gas_strategy) cubeTokenImpl.initialize(ZERO_ADDRESS, "", False, {"gas_price": gas_strategy}) pool = deployer.deploy(CubePool, feeds, cubeTokenImpl, publish_source=True, gas_price=gas_strategy) time.sleep(15) pool.setProtocolFee(2000, {"gas_price": gas_strategy}) # 20% pool.setMaxPoolBalance(100e18, {"gas_price": gas_strategy}) # 100 eth pool.addCubeToken("BTC", LONG, 150, 100, 0, {"gas_price": gas_strategy}) pool.addCubeToken("BTC", SHORT, 150, 100, 0, {"gas_price": gas_strategy}) pool.addCubeToken("ETH", LONG, 150, 100, 0, {"gas_price": gas_strategy}) pool.addCubeToken("ETH", SHORT, 150, 100, 0, {"gas_price": gas_strategy}) pool.addCubeToken("LINK", LONG, 300, 100, 0, {"gas_price": gas_strategy}) pool.addCubeToken("LINK", SHORT, 300, 100, 0, {"gas_price": gas_strategy}) pool.addCubeToken("SNX", LONG, 300, 100, 0, {"gas_price": gas_strategy}) pool.addCubeToken("SNX", SHORT, 300, 100, 0, {"gas_price": gas_strategy}) print(f"Pool address: {pool.address}") print( f"Gas used in deployment: {(balance - deployer.balance()) / 1e18:.4f} ETH" )
def cli( ctx, etherscan_token, gas_speed, gas_max_speed, gas_increment, gas_block_duration, network, ): ctx.ensure_object(dict) # put this into the environment so that brownie sees it os.environ["ETHERSCAN_TOKEN"] = etherscan_token # setup the project and network the same way brownie's run helper does brownie_project = project.load(get_project_root()) brownie_project.load_config() if network != "none": brownie_network.connect(network) logger.info( f"{brownie_project._name} is the active {network} project.") if network in ["mainnet", "mainnet-fork"]: # TODO: write my own strategy gas_strategy = GasNowScalingStrategy( initial_speed=gas_speed, max_speed=gas_max_speed, increment=gas_increment, block_duration=gas_block_duration, ) gas_price(gas_strategy) logger.info(f"Default gas strategy: {gas_strategy}") elif network in ["bsc", "bsc-fork"]: gas_strategy = "10 gwei" gas_price(gas_strategy) logger.info(f"Default gas price: {gas_strategy}") elif network in ["matic", "matic-fork"]: gas_strategy = "1 gwei" gas_price(gas_strategy) logger.info(f"Default gas price: {gas_strategy}") else: logger.warning( "No default gas price or gas strategy has been set!") else: logger.warning( f"{brownie_project._name} is the active project. It is not conencted to any networks" ) # pass the project on to the other functions ctx.obj["brownie_project"] = brownie_project
def main(): keeper = getAccount(os.environ["KEEPER_ACCOUNT"], os.environ["KEEPER_PW"]) # keeper = accounts.load(input("Brownie account: ")) gas_strategy = GasNowScalingStrategy() balance = keeper.balance() pool = CubePool.at(POOL) pool.updateAll(MAX_STALE_TIME, {"from": keeper, "gas_price": gas_strategy}) print(f"Gas used: {(balance - keeper.balance()) / 1e18:.4f} ETH") print(f"New balance: {keeper.balance() / 1e18:.4f} ETH")
def main(): deployer = accounts.load("deployer") balance = deployer.balance() gas_strategy = GasNowScalingStrategy() multicall = deployer.deploy(CubePoolMulticall, publish_source=True, gas_price=gas_strategy) print(f"Multicall address: {multicall.address}") print( f"Gas used in deployment: {(balance - deployer.balance()) / 1e18:.4f} ETH" )
def main(): deployer = accounts.load("deployer") UniswapV3Core = project.load("Uniswap/[email protected]") gas_strategy = GasNowScalingStrategy() balance = keeper.balance() pool = UniswapV3Core.interface.IUniswapV3Pool(POOL) pool.increaseObservationCardinalityNext( CARDINALITY, {"from": deployer, "gas_price": gas_strategy} ) print(f"Gas used: {(balance - keeper.balance()) / 1e18:.4f} ETH") print(f"New balance: {keeper.balance() / 1e18:.4f} ETH")
def main(): deployer = accounts.load("deployer") balance = deployer.balance() gas_strategy = GasNowScalingStrategy() feeds = deployer.deploy( ChainlinkFeedsRegistry, publish_source=True, gas_price=gas_strategy ) time.sleep(5) for symbol, feed in USD_FEEDS.items(): feeds.addUsdFeed(symbol, feed, {"gas_price": gas_strategy}) for symbol, feed in ETH_FEEDS.items(): feeds.addEthFeed(symbol, feed, {"gas_price": gas_strategy}) print(f"Feeds address: {feeds.address}") print(f"Gas used in deployment: {(balance - deployer.balance()) / 1e18:.4f} ETH")
def brownie_connect(): # this allows later click commands to set the default. there might be a better way network = ctx.obj["brownie_network"] or ctx.obj.get("default_brownie_network") # setup the project and network the same way brownie's run helper does brownie_project = project.load(get_project_root(), "ArgobytesBrownieProject") brownie_project.load_config() ctx.obj["brownie_project"] = brownie_project if network == "none" or network is None: logger.warning(f"{brownie_project._name} is the active project. Not connected to any networks") else: brownie_network.connect(network) logger.info(f"{brownie_project._name} is the active {network} project.") if flashbot_account: print(f"Using {flashbot_account} for signing flashbot bundles.") flashbot(web3, flashbot_account) if network in ["mainnet", "mainnet-fork"]: # TODO: write my own strategy gas_strategy = GasNowScalingStrategy( initial_speed=gas_speed, max_speed=gas_max_speed, increment=gas_increment, block_duration=gas_block_duration, ) gas_price(gas_strategy) logger.info(f"Default gas strategy: {gas_strategy}") elif network in ["bsc-main", "bsc-main-fork"]: gas_strategy = "5010000000" # 5.01 gwei gas_price(gas_strategy) logger.info(f"Default gas price: {gas_strategy}") elif network in ["polygon", "polygon-fork"]: gas_strategy = "1010000000" # "1.01 gwei" gas_price(gas_strategy) logger.info(f"Default gas price: {gas_strategy}") else: logger.warning("No default gas price or gas strategy has been set!")
def main(): deployer = accounts.load("deployer") balance = deployer.balance() gas_strategy = GasNowScalingStrategy() cubeTokenImpl = deployer.deploy(CubeToken, publish_source=True, gas_price=gas_strategy) cubeTokenImpl.initialize(ZERO_ADDRESS, "", False, {"gas_price": gas_strategy}) pool = deployer.deploy( CubePool, FEEDS_CONTRACT, cubeTokenImpl, publish_source=True, gas_price=gas_strategy, ) time.sleep(5) pool.setProtocolFee(2000, {"gas_price": gas_strategy}) # 20% pool.setMaxPoolBalance(100e18, {"gas_price": gas_strategy}) # 100 eth # 1.5% fee for symbol in SYMBOLS_150: pool.addCubeToken(symbol, LONG, 150, 0, {"gas_price": gas_strategy}) pool.addCubeToken(symbol, SHORT, 150, 0, {"gas_price": gas_strategy}) # 3% fee for symbol in SYMBOLS_300: pool.addCubeToken(symbol, LONG, 300, 0, {"gas_price": gas_strategy}) pool.addCubeToken(symbol, SHORT, 300, 0, {"gas_price": gas_strategy}) print(f"Pool address: {pool.address}") print( f"Gas used in deployment: {(balance - deployer.balance()) / 1e18:.4f} ETH" )
def main(): deployer = accounts.load("deployer") UniswapV3Core = project.load("Uniswap/[email protected]") gas_strategy = GasNowScalingStrategy() vault = AlphaVault.at(VAULT_ADDRESS) old = PassiveStrategy.at(vault.strategy()) print(f"Old strategy address: {old.address}") strategy = deployer.deploy( PassiveStrategy, vault, BASE_THRESHOLD, LIMIT_THRESHOLD, PERIOD, MIN_TICK_MOVE, MAX_TWAP_DEVIATION, TWAP_DURATION, KEEPER, publish_source=True, gas_price=gas_strategy, ) print(f"Strategy address: {strategy.address}") assert old.vault() == strategy.vault() == VAULT_ADDRESS assert old.baseThreshold() == strategy.baseThreshold() == BASE_THRESHOLD assert old.limitThreshold() == strategy.limitThreshold() == LIMIT_THRESHOLD assert old.period() == strategy.period() == PERIOD assert old.minTickMove() == strategy.minTickMove() == MIN_TICK_MOVE assert old.maxTwapDeviation() == strategy.maxTwapDeviation( ) == MAX_TWAP_DEVIATION assert old.twapDuration() == strategy.twapDuration() == TWAP_DURATION assert old.keeper() == strategy.keeper() == KEEPER vault.setStrategy(strategy, {"from": deployer, "gas_price": gas_strategy})
from brownie import accounts, network, interface, Vault, Token from brownie.network.gas.strategies import GasNowScalingStrategy from decimal import Decimal from eth_utils import is_checksum_address import requests from time import sleep GAS_BUFFER = 1.2 gas_strategy = GasNowScalingStrategy() def get_address(msg: str) -> str: while True: addr = input(msg) if is_checksum_address(addr): return addr print(f"I'm sorry, but '{addr}' is not a checksummed address") def main(): print(f"You are using the '{network.show_active()}' network") bot = accounts.load("bot") print(f"You are using: 'bot' [{bot.address}]") # TODO: Allow adding/removing strategies during operation strategies = [interface.StrategyAPI(get_address("Strategy to farm: "))] while input("Add another strategy? (y/[N]): ").lower() == "y": strategies.append(interface.StrategyAPI(get_address("Strategy to farm: "))) vault = Vault.at(strategies[0].vault())
badger.connect_badger_tree(badger_deploy["badgerTree"]) badger.connect_rewards_escrow(badger_deploy["rewardsEscrow"]) badger.connect_honeypot_meme(badger_deploy["honeypotMeme"]) badger.connect_community_pool(badger_deploy["communityPool"]) badger.connect_dao_badger_timelock(badger_deploy["daoBadgerTimelock"]) # Connect Sett badger.connect_sett_system(badger_deploy["sett_system"], badger_deploy["geysers"]) digg = connect_digg(badger_deploy_file) badger.add_existing_digg(digg) return badger default_gas_strategy = GasNowScalingStrategy() class BadgerSystem: def __init__( self, config, deployer, keeper, guardian, deploy=True, load_deployer=False, load_keeper=False, load_guardian=False, ): self.config = config
from brownie import accounts, interface from brownie import AlphaStaking, TransparentUpgradeableProxyImpl, ProxyAdminImpl from brownie.network.gas.strategies import GasNowScalingStrategy gas_strategy = GasNowScalingStrategy( initial_speed="slow", max_speed="fast", increment=1.085, block_duration=20) def main(): deployer = accounts.at('0xB593d82d53e2c187dc49673709a6E9f806cdC835', force=True) # deployer = accounts.load('gh') alpha = interface.IAny('0xa1faa113cbE53436Df28FF0aEe54275c13B40975') proxy_admin = ProxyAdminImpl.at('0x090eCE252cEc5998Db765073D07fac77b8e60CB2') staking_impl = AlphaStaking.deploy({'from': deployer, 'gas_price': gas_strategy}) staking = TransparentUpgradeableProxyImpl.deploy( staking_impl, proxy_admin, staking_impl.initialize.encode_input(alpha, deployer), {'from': deployer, 'gas_price': gas_strategy}) staking = interface.IAny(staking) # approve staking contract stake_amt = 10 * 10**18 alpha.approve(staking, stake_amt, {'from': deployer, 'gas_price': gas_strategy}) # stake 10 ALPHA staking.stake(stake_amt, {'from': deployer, 'gas_price': gas_strategy})
"0xdAC17F958D2ee523a2206206994597C13D831ec7", # USDT "0x8e870d67f660d95d5be530380d0ec0bd388289e1", # PAX "0x57ab1ec28d129707052df4df418d58a2d46d5f51", # sUSD ] # for synth burners, executing converts sUSD to USDC and forwards to # underlying burner. this has to happen in a separate transaction due # to the three minute settlement time. SYNTH_BURNERS = [ "0x00702BbDEaD24C40647f235F15971dB0867F6bdB", # BtcBurner "0xD782EbD4bAbd95c2D8255112eFc6DD865c849394", # EthBurner "0x3a16b6001201577CC67bDD8aAE5A105bbB035882", # EuroBurner ] _rate_cache = {} gas_strategy = GasNowScalingStrategy(initial_speed="slow", max_speed="fast") def _get_pool_list(): sys.stdout.write("Getting list of pools from registry...") sys.stdout.flush() provider = Contract("0x0000000022D53366457F9d5E68Ec105046FC4383") registry = Contract(provider.get_registry()) pool_count = registry.pool_count() pool_list = {} for i in range(pool_count): sys.stdout.write( f"\rGetting list of pools from registry ({i+1}/{pool_count})...") sys.stdout.flush()
from brownie.network.gas.strategies import GasNowScalingStrategy # address of the StakingRewards contract REWARDS_CONTRACT_ADDRESS = "0x" # address that owns `StakingRewards` OWNER = accounts.add() # address that is permitted to fund the contract REWARD_ADMIN = OWNER # amount to add as a reward REWARDS_AMOUNT = 0 # duration of the rewards period, in seconds - we recommend keeping this as 30 days REWARDS_DURATION = 30 * 86400 gas_strategy = GasNowScalingStrategy("standard", "fast") def main(): rewards = StakingRewards.at(REWARDS_CONTRACT_ADDRESS) token = Contract(rewards.rewardsToken()) # sanity check on the reward amount if REWARDS_AMOUNT < 10**token.decimals(): raise ValueError( "Reward amount is less than 1 token - are you sure this is correct?" ) # ensure the reward admin has sufficient balance of the reward token if token.balanceOf(REWARD_ADMIN) < REWARDS_AMOUNT: raise ValueError(
def main(): deployer = accounts.load("deployer") UniswapV3Core = project.load("Uniswap/[email protected]") gas_strategy = GasNowScalingStrategy() eth = deployer.deploy(MockToken, "ETH", "ETH", 18) usdc = deployer.deploy(MockToken, "USDC", "USDC", 6) eth.mint(deployer, 100 * 1e18, {"from": deployer, "gas_price": gas_strategy}) usdc.mint(deployer, 100000 * 1e6, {"from": deployer, "gas_price": gas_strategy}) factory = UniswapV3Core.interface.IUniswapV3Factory(FACTORY) factory.createPool(eth, usdc, 3000, {"from": deployer, "gas_price": gas_strategy}) time.sleep(15) pool = UniswapV3Core.interface.IUniswapV3Pool(factory.getPool(eth, usdc, 3000)) inverse = pool.token0() == usdc price = 1e18 / 2000e6 if inverse else 2000e6 / 1e18 # Set ETH/USDC price to 2000 pool.initialize( floor(sqrt(price) * (1 << 96)), {"from": deployer, "gas_price": gas_strategy} ) # Increase cardinality so TWAP works pool.increaseObservationCardinalityNext( 100, {"from": deployer, "gas_price": gas_strategy} ) router = deployer.deploy(TestRouter) MockToken.at(eth).approve( router, 1 << 255, {"from": deployer, "gas_price": gas_strategy} ) MockToken.at(usdc).approve( router, 1 << 255, {"from": deployer, "gas_price": gas_strategy} ) time.sleep(15) max_tick = 887272 // 60 * 60 router.mint( pool, -max_tick, max_tick, 1e14, {"from": deployer, "gas_price": gas_strategy} ) vault = deployer.deploy( AlphaVault, pool, PROTOCOL_FEE, MAX_TOTAL_SUPPLY, publish_source=True, gas_price=gas_strategy, ) strategy = deployer.deploy( PassiveStrategy, vault, BASE_THRESHOLD, LIMIT_THRESHOLD, PERIOD, MIN_TICK_MOVE, MAX_TWAP_DEVIATION, TWAP_DURATION, deployer, publish_source=True, gas_price=gas_strategy, ) vault.setStrategy(strategy, {"from": deployer, "gas_price": gas_strategy}) print(f"Vault address: {vault.address}") print(f"Strategy address: {strategy.address}") print(f"Router address: {router.address}")
def _tx_params(): return { 'from': DEPLOYER, 'required_confs': REQUIRED_CONFIRMATIONS, 'gas_price': GasNowScalingStrategy("standard", "fast"), }
"0x5bc25f649fc4e26069ddf4cf4010f9f706c23831", # DUSD # USDN burner "0x674C6Ad92Fd080e4004b2312b45f796a192D27a0", # USDN # underlying burner # called last, as other burners forward to it "0x6B175474E89094C44Da98b954EedeAC495271d0F", # DAI "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", # USDC "0xdAC17F958D2ee523a2206206994597C13D831ec7", # USDT "0x8e870d67f660d95d5be530380d0ec0bd388289e1", # PAX "0x57ab1ec28d129707052df4df418d58a2d46d5f51", # sUSD ] _rate_cache = {} gas_strategy = GasNowScalingStrategy(initial_speed="standard", max_speed="fast") def _fetch_rate(address): # fetch teh current rate for a coin from coingecko address = str(address).lower() if address not in _rate_cache: _rate_cache[address] = requests.get( "https://api.coingecko.com/api/v3/simple/token_price/ethereum", params={ 'contract_addresses': address, 'vs_currencies': "usd" }).json()[address]['usd'] return _rate_cache[address]
from brownie import ( DepositZapBTC, DepositZapUSD, Factory, MetaImplementationBTC, MetaImplementationUSD, OwnerProxy, accounts ) from brownie.network.gas.strategies import GasNowScalingStrategy # modify me prior to deployment on mainnet! DEPLOYER = accounts.at("0x7EeAC6CDdbd1D0B8aF061742D41877D7F707289a", force=True) gas_price = GasNowScalingStrategy("slow", "fast") OWNER_ADMIN = "0x40907540d8a6C65c637785e8f8B742ae6b0b9968" PARAM_ADMIN = "0x4EEb3bA4f221cA16ed4A0cC7254E2E32DF948c5f" EMERGENCY_ADMIN = "0x00669DF67E4827FCc0E48A1838a8d5AB79281909" BASE_3POOL = "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7" BASE_SBTC = "0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714" def main(deployer=DEPLOYER): factory = Factory.deploy({'from': deployer}) implementation_usd = MetaImplementationUSD.deploy({'from': deployer, 'gas_price': gas_price}) factory.add_base_pool(BASE_3POOL, implementation_usd, {'from': deployer, 'gas_price': gas_price})
def _tx_params(): return { "from": DEPLOYER, "required_confs": REQUIRED_CONFIRMATIONS, "gas_price": GasNowScalingStrategy("standard", "fast"), }
def main(): # Acocunts load_accounts() gas_strategy = GasNowScalingStrategy("fast", increment=1.2) gas_price(gas_strategy) # MONA Token access_control = deploy_access_control() mona_token = get_mona_token() # Get Contracts genesis_staking = get_genesis_staking() parent_staking = get_parent_staking() lp_staking = get_lp_staking() rewards = get_rewards() # # Set Tokens Claimable genesis_staking.setTokensClaimable(False, {'from':accounts[0]}) parent_staking.setTokensClaimable(False, {'from':accounts[0]}) lp_staking.setTokensClaimable(False, {'from':accounts[0]}) # Accounting snapshot last_rewards = rewards.lastRewardTime({'from':accounts[0]}) print("Last Rewards: ", str(last_rewards)) genesis_paid = rewards.genesisRewardsPaid({'from':accounts[0]}) parent_paid = rewards.parentRewardsPaid({'from':accounts[0]}) lp_paid = rewards.lpRewardsPaid({'from':accounts[0]}) print("Rewards Paid: G:", str(genesis_paid), " P:", str(parent_paid), " L:",str(lp_paid)) week_points0 = rewards.weeklyWeightPoints(0, {'from':accounts[0]}) print("Weekly Points0:", str(week_points0)) week_points1 = rewards.weeklyWeightPoints(1, {'from':accounts[0]}) print("Weekly Points1:", str(week_points1)) # # Rewards Contract new_rewards = deploy_new_rewards(mona_token,genesis_staking,parent_staking,lp_staking, access_control,REWARDS_START_TIME, last_rewards, genesis_paid, parent_paid, lp_paid) # Set weekly rewards set_bonus(genesis_staking, new_rewards) set_rewards(new_rewards) print("rewards per second for week[0] =",new_rewards.weeklyRewardsPerSecond(0)* 7*24*60*60 /TENPOW18) print("rewards per second for week[8]=",new_rewards.weeklyRewardsPerSecond(8)* 7*24*60*60/TENPOW18) new_rewards.setInitialPoints(0, week_points0[0], week_points0[1], week_points0[2],{'from': accounts[0]}) new_rewards.setInitialPoints(1, week_points1[0], week_points1[1], week_points1[2],{'from': accounts[0]}) # Add Minter permissions access_control.addMinterRole(new_rewards, {'from': accounts[0]}) # Set Rewards contract on staking pooks genesis_staking.setRewardsContract(new_rewards,{'from': accounts[0]}) parent_staking.setRewardsContract(new_rewards,{'from': accounts[0]}) lp_staking.setRewardsContract(new_rewards,{'from': accounts[0]}) # Set Tokens Claimable genesis_staking.setTokensClaimable(True, {'from':accounts[0]}) parent_staking.setTokensClaimable(True, {'from':accounts[0]}) lp_staking.setTokensClaimable(True, {'from':accounts[0]}) # Refresh the updated time to check it works new_rewards.updateRewards({'from': accounts[0]})