Package: badger-utils
badger-utils libraryThis is the library for all badger utils that were moved frombadger-systemrepo.BuildCoveragePYPIRequirementsTo make use of library you would need some interfaces and contracts to becompiledand injected by brownie into your brownie project.
List of required interfaces can be foundhereYou also need some contracts to be compiled as well:ForceEther, SafeMath, Token, BadgerRegistryInstalling librarypip install badger-utilsTo run tests:$ virtualenv venv
$ source venv/bin/activate
$ make
$ brownie testUsing libraryCoingecko UtilsGas utils moduleNetwork utilsProxy utilsDistribute from whales realtimeDistribute from whales realtime with exact amountToken utilsConstantsTx timerArtifactsLocal registryOn chain registrySystemsGiving some examples on library usage:Using coingecko utilsfrombadger_utils.coingecko_utilsimportfetch_usd_pricesome_erc_token=interface.IERC20(Token)usd_price=fetch_usd_price(some_erc_token.address)Using gas_utils modulefrombadger_utils.gas_utilsimportGasStrategies# Class initialization will initialize everything and fetch gas pricesstrategies=GasStrategies()price=strategies.optimal_price()# check gas cost:strategies.gas_cost(gas_estimate=21000)# Set default strategy:strategies.set_default_for_active_chain()NOTE:If you want to use Anyblock historical data in gas analysis, consider adding auth keys
from anyblock account:exportANYBLOCK_EMAIL=email@gmail.comexportANYBLOCK_KEY=<YOUANYBLOCKAPIKEY>otherwisedef analyze_gasfunction will always return static data:DotMap(mode=999999999999999999,median=999999999999999999,std=999999999999999999)Using network utilsfrombadger_utils.network_managerimportnetwork_managernetwork=network_manager.get_active_network()badger_deploy_file=network_manager.get_active_network_badger_deploy()Using proxy utilsfrombadger_utils.proxy_utilsimportdeploy_proxy_adminfrombrownieimportaccountscontract=deploy_proxy_admin(accounts[0])assertcontract.addressisnotNoneUsing distribute from whales realtime with percentageIf you want to use some other Ethplorer key to fetch whales, set env variable: ETHPLORER_API_KEYexportETHPLORER_API_KEY=<API_KEY>Otherwise, ethplorer key will be used by default, which is a bit slowimporttoken# some deployed tokenfrombrownieimportaccountsfrombadger_utils.token_utils.distribute_from_whales_realtimeimportdistribute_from_whales_realtime_percentagetoken.transfer("0x19d099670a21bC0a8211a89B84cEdF59AbB4377F",100000,{'from':accounts[0]})distribute_from_whales_realtime_percentage(accounts[1],percentage=0.8)Using distribute from whales realtime with exact amountimporttoken# some deployed tokenfrombrownieimportaccountsfrombadger_utils.token_utils.distribute_from_whales_realtimeimportdistribute_from_whales_realtime_exacttoken.transfer("0x19d099670a21bC0a8211a89B84cEdF59AbB4377F",100000,{'from':accounts[0]})distribute_from_whales_realtime_exact(accounts[1],amount=123)Using token utilsLEGACY. Consider usingdistribute_from_whales_realtimemoduleimporttoken# some deployed tokenfrombrownieimportaccountsfrombadger_utils.token_utilsimportdistribute_from_whalestoken.transfer("0x19d099670a21bC0a8211a89B84cEdF59AbB4377F",100000,{'from':accounts[0]})distribute_from_whales(accounts[1],percentage=0.8)Using constantsfrombadger_utils.constantsimportAddressZerofrombadger_utils.constantsimportTOKEN_LOCKER_ROLEfrombadger_utils.constantsimportContractSystemsUsing tx timerfrombadger_utils.tx_timerimporttx_timerfrombrownieimportaccountstx_timer.prepare_timer(accounts[0],"Harvest")tx_timer.start_timer(accounts[0],'Harvest')tx_timer.end_timer()Using artifactsfrombadger_utils.registry.artifactsimportartifactstimelock_abi=artifacts.open_zeppelin["TokenTimelock"]["abi"]Using registriesOn chain registryfrombadger_utils.registryimportchain_registrieschain_registries.initialize()chain_registries.get("badgerTree")Locally defined registryNOTE:This is legacy way of working with registriesfrombrownieimportweb3frombadger_utils.registryimportregistrychecksummed=web3.toChecksumAddress(registry.tokens.wbtc)Using systemsfrombadger_utils.systemsimportSushiswapSystem