Skip to main content

BeraChainTools 一个为 BeraChain 生态系统设计的工具集,旨在帮助用户轻松地进行各种交互和操作。

Project description

BeraChainTools

BeraChainTools 一个为 BeraChain 生态系统设计的工具集,旨在帮助用户轻松地进行各种交互和操作。

安装依赖

在开始使用 BeraChainTools 之前,请确保安装了所有必要的依赖。

执行以下命令以安装依赖:

pip install -r requirements.txt

Examples

Example 1 - 领水:

from eth_account import Account
from loguru import logger

from bera_tools import BeraChainTools

account = Account.create()
logger.debug(f'address:{account.address}')
logger.debug(f'key:{account.key.hex()}')
# TODO 填写你的 YesCaptcha client key 或者2Captcha API Key 或者 ez-captcha ClientKey
client_key = '00000000000000'
# 使用yescaptcha solver googlev3
bera = BeraChainTools(private_key=account.key, client_key=client_key,solver_provider='yescaptcha',rpc_url='https://rpc.ankr.com/berachain_testnet')
# 使用2captcha solver googlev3
# bera = BeraChainTools(private_key=account.key, client_key=client_key,solver_provider='2captcha',rpc_url='https://rpc.ankr.com/berachain_testnet')
# 使用ez-captcha solver googlev3
# bera = BeraChainTools(private_key=account.key, client_key=client_key,solver_provider='ez-captcha',rpc_url='https://rpc.ankr.com/berachain_testnet')

# 不使用代理
result = bera.claim_bera()
# 使用代理
# result = bera.claim_bera(proxies={'http':"http://127.0.0.1:8888","https":"http://127.0.0.1:8888"})
logger.debug(result.text)

Example 2 - Bex 交互:

from eth_account import Account
from loguru import logger

from bera_tools import BeraChainTools
from config.address_config import (
    usdc_address, wbear_address, weth_address, bex_approve_liquidity_address,
    usdc_pool_liquidity_address, weth_pool_liquidity_address
)

account = Account.from_key('xxxxxxxxxxxx')
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet')

# bex 使用bera交换usdc
bera_balance = bera.w3.eth.get_balance(account.address)
result = bera.bex_swap(int(bera_balance * 0.2), wbear_address, usdc_address)
logger.debug(result)
# bex 使用usdc交换weth
usdc_balance = bera.usdc_contract.functions.balanceOf(account.address).call()
result = bera.bex_swap(int(usdc_balance * 0.2), usdc_address, weth_address)
logger.debug(result)

# 授权usdc
approve_result = bera.approve_token(bex_approve_liquidity_address, int("0x" + "f" * 64, 16), usdc_address)
logger.debug(approve_result)
# bex 增加 usdc 流动性
usdc_balance = bera.usdc_contract.functions.balanceOf(account.address).call()
result = bera.bex_add_liquidity(int(usdc_balance * 0.5), usdc_pool_liquidity_address, usdc_address)
logger.debug(result)

# 授权weth
approve_result = bera.approve_token(bex_approve_liquidity_address, int("0x" + "f" * 64, 16), weth_address)
logger.debug(approve_result)
# bex 增加 weth 流动性
weth_balance = bera.weth_contract.functions.balanceOf(account.address).call()
result = bera.bex_add_liquidity(int(weth_balance * 0.5), weth_pool_liquidity_address, weth_address)
logger.debug(result)

Example 3 - Honey 交互:

from eth_account import Account
from loguru import logger

from bera_tools import BeraChainTools
from config.address_config import honey_swap_address, usdc_address, honey_address

account = Account.from_key('xxxxxxxxxxxx')
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet')

# 授权usdc
approve_result = bera.approve_token(honey_swap_address, int("0x" + "f" * 64, 16), usdc_address)
logger.debug(approve_result)
# 使用usdc mint honey
usdc_balance = bera.usdc_contract.functions.balanceOf(account.address).call()
result = bera.honey_mint(int(usdc_balance * 0.5))
logger.debug(result)

# 授权honey
approve_result = bera.approve_token(honey_swap_address, int("0x" + "f" * 64, 16), honey_address)
logger.debug(approve_result)
# 赎回 
honey_balance = bera.honey_contract.functions.balanceOf(account.address).call()
result = bera.honey_redeem(int(honey_balance * 0.5))
logger.debug(result)

Example 4 - Bend 交互:

from eth_account import Account
from loguru import logger

from bera_tools import BeraChainTools
from config.address_config import bend_address, weth_address, honey_address, bend_pool_address

account = Account.from_key('xxxxxxxxxxxx')
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet')

# 授权
approve_result = bera.approve_token(bend_address, int("0x" + "f" * 64, 16), weth_address)
logger.debug(approve_result)
# deposit
weth_balance = bera.weth_contract.functions.balanceOf(account.address).call()
result = bera.bend_deposit(int(weth_balance), weth_address)
logger.debug(result)

# borrow
balance = bera.bend_contract.functions.getUserAccountData(account.address).call()[2]
logger.debug(balance)
result = bera.bend_borrow(int(balance * 0.8 * 1e10), honey_address)
logger.debug(result)

# 授权
approve_result = bera.approve_token(bend_address, int("0x" + "f" * 64, 16), honey_address)
logger.debug(approve_result)
# 查询数量 
call_result = bera.bend_borrows_contract.functions.getUserReservesData(bend_pool_address, bera.account.address).call()
repay_amount = call_result[0][0][4]
logger.debug(repay_amount)
# repay
result = bera.bend_repay(int(repay_amount * 0.9), honey_address)
logger.debug(result)

Example 5 - 0xhoneyjar 交互:

from eth_account import Account
from loguru import logger

from bera_tools import BeraChainTools
from config.address_config import ooga_booga_address, honey_address

account = Account.from_key('xxxxxxxxxxxx')
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet')


# https://faucet.0xhoneyjar.xyz/mint
# 授权
approve_result = bera.approve_token(ooga_booga_address, int("0x" + "f" * 64, 16), honey_address)
logger.debug(approve_result)
# 花费4.2 honey mint
result = bera.honey_jar_mint()
logger.debug(result)

Example 6 - 部署合约:

from eth_account import Account
from loguru import logger
from solcx import install_solc

from bera_tools import BeraChainTools
from config.address_config import ooga_booga_address, honey_address

account = Account.from_key('xxxxxxxxxxxx')
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet')

# 安装0.4.18 版本编译器
install_solc('0.4.18')
# 读取sol文件
with open('config/WETH.sol', 'r') as f:
  code = f.read()
# 部署合约
result = bera.deploy_contract(code, '0.4.18')
logger.debug(result)

BeraChain 领水

支持创建地址领水或指定地址领水

bex 交互

支持代币交换和增加流动性

  • 访问链接bex交互
  • 状态:已完成

honey 交互

支持mint和redeem

bend 交互

用于与 BeraChain 的 bend 服务交互。

berps 交互

用于与 BeraChain 的 berps 服务交互。

station 交互

用于与 BeraChain 的 station 服务交互。


galxe 任务

请访问作者 Fooyao

  • Github项目地址galxe

感谢使用 BeraChainTools!如有任何问题或建议,请随时通过 GitHub Issues 提交。

如果您认可和喜欢 BeraChainTools 的功能和使用体验,我非常欢迎您给项目点个 star。您的 star 是对我的工作的认可和支持,也是我不断改进和提升 BeraChainTools 的动力!谢谢您的支持!

更多疑问请扫码添加好友加入交流群

微信图片_20240206233445

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

berachaintoolspro-1.1.3.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

BeraChainToolsPro-1.1.3-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file berachaintoolspro-1.1.3.tar.gz.

File metadata

  • Download URL: berachaintoolspro-1.1.3.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.2

File hashes

Hashes for berachaintoolspro-1.1.3.tar.gz
Algorithm Hash digest
SHA256 c0e3d220337ef2233843f369a3abcf520dc44ac0166ecef59433f79bf7e6d039
MD5 c827de1c89f69b8e805b6e2d21533c64
BLAKE2b-256 d3d35f3bb44b919aa5fbf04a593289522ac8d6b062d787ef8f338b60481e1ece

See more details on using hashes here.

File details

Details for the file BeraChainToolsPro-1.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for BeraChainToolsPro-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 439240c23f476ecb9ddf42bdf8f5756fa5c947b4c7b2f7f42bebc65d33a12570
MD5 92c99145e0b2ef5d3df4624053f38937
BLAKE2b-256 c6b5489c9a160b3085b2066f09cf0f3a85245e9f9a3cab299694fceb82c2b016

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