Skip to main content

Badger utils and shared code

Project description

badger-utils library

This is the library for all badger utils that were moved from badger-system repo.

Build Coverage PYPI
Tests codecov PyPI version

Requirements

To make use of library you would need some interfaces and contracts to be compiled and injected by brownie into your brownie project. List of required interfaces can be found here

You also need some contracts to be compiled as well:

ForceEther, SafeMath, Token, BadgerRegistry

Installing library

pip install badger-utils

To run tests:

$ virtualenv venv
$ source venv/bin/activate
$ make
$ brownie test

Using library

Giving some examples on library usage:

Using coingecko utils

from badger_utils.coingecko_utils import fetch_usd_price
some_erc_token = interface.IERC20(Token)
usd_price = fetch_usd_price(some_erc_token.address)

Using gas_utils module

from badger_utils.gas_utils import GasStrategies

# Class initialization will initialize everything and fetch gas prices
strategies = 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:

export ANYBLOCK_EMAIL=email@gmail.com
export ANYBLOCK_KEY=<YOU ANYBLOCK API KEY>

otherwise def analyze_gas function will always return static data:

DotMap(mode=999999999999999999, median=999999999999999999, std=999999999999999999)

Using network utils

from badger_utils.network_manager import network_manager
network = network_manager.get_active_network()
badger_deploy_file = network_manager.get_active_network_badger_deploy()

Using proxy utils

from badger_utils.proxy_utils import deploy_proxy_admin
from brownie import accounts

contract = deploy_proxy_admin(accounts[0])
assert contract.address is not None

Using distribute from whales realtime with percentage

If you want to use some other Ethplorer key to fetch whales, set env variable: ETHPLORER_API_KEY

export ETHPLORER_API_KEY=<API_KEY>

Otherwise, ethplorer key will be used by default, which is a bit slow

import token  # some deployed token
from brownie import accounts
from badger_utils.token_utils.distribute_from_whales_realtime import distribute_from_whales_realtime_percentage

token.transfer(
    "0x19d099670a21bC0a8211a89B84cEdF59AbB4377F", 100000, {'from': accounts[0]}
)
distribute_from_whales_realtime_percentage(accounts[1], percentage=0.8)

Using distribute from whales realtime with exact amount

import token  # some deployed token
from brownie import accounts
from badger_utils.token_utils.distribute_from_whales_realtime import distribute_from_whales_realtime_exact

token.transfer(
    "0x19d099670a21bC0a8211a89B84cEdF59AbB4377F", 100000, {'from': accounts[0]}
)
distribute_from_whales_realtime_exact(accounts[1], amount=123)

Using token utils

LEGACY. Consider using distribute_from_whales_realtime module

import token  # some deployed token
from brownie import accounts
from badger_utils.token_utils import distribute_from_whales

token.transfer(
    "0x19d099670a21bC0a8211a89B84cEdF59AbB4377F", 100000, {'from': accounts[0]}
)
distribute_from_whales(accounts[1], percentage=0.8)

Using constants

from badger_utils.constants import AddressZero
from badger_utils.constants import TOKEN_LOCKER_ROLE
from badger_utils.constants import ContractSystems

Using tx timer

from badger_utils.tx_timer import tx_timer
from brownie import accounts

tx_timer.prepare_timer(accounts[0], "Harvest")
tx_timer.start_timer(accounts[0], 'Harvest')
tx_timer.end_timer()

Using artifacts

from badger_utils.registry.artifacts import artifacts

timelock_abi = artifacts.open_zeppelin["TokenTimelock"]["abi"]

Using registries

On chain registry

from badger_utils.registry import chain_registries

chain_registries.initialize()
chain_registries.get("badgerTree")

Locally defined registry

NOTE: This is legacy way of working with registries

from brownie import web3
from badger_utils.registry import registry

checksummed = web3.toChecksumAddress(registry.tokens.wbtc)

Using systems

from badger_utils.systems import SushiswapSystem

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

badger-utils-0.2.5.tar.gz (796.4 kB view details)

Uploaded Source

Built Distribution

badger_utils-0.2.5-py2.py3-none-any.whl (837.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file badger-utils-0.2.5.tar.gz.

File metadata

  • Download URL: badger-utils-0.2.5.tar.gz
  • Upload date:
  • Size: 796.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for badger-utils-0.2.5.tar.gz
Algorithm Hash digest
SHA256 bb342f5c72612c43d958cc7b8628362ad332ef45b3ef8c8493ff5cab6bc75e50
MD5 c97bf13c8d6fb3d21166c32aba079220
BLAKE2b-256 8e72c2d794d20fee6fdbcd596595b6e0acb24ff88b508e8df821ee008cf2e0e9

See more details on using hashes here.

File details

Details for the file badger_utils-0.2.5-py2.py3-none-any.whl.

File metadata

  • Download URL: badger_utils-0.2.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 837.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for badger_utils-0.2.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f1b46ab70553600e4efeac5a3609700a144ed0ec4c688432abf65115fbba70ba
MD5 3f4516f7261b533e2e69decc009c62fd
BLAKE2b-256 fcd433c7711f573e3e0e27f932a874a832e06bd01ce6f2fa3244287930ac6520

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page