Skip to main content

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

Metadata

Release files for BeraChainToolsPro 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BeraChainToolsPro 1.1.3
File Size Uploaded
berachaintoolspro-1.1.3.tar.gz 20.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for BeraChainToolsPro 1.1.3
File Interpreter ABI Platform
BeraChainToolsPro-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 36.5 kB

Release files / berachaintoolspro-1.1.3.tar.gz

Download URL berachaintoolspro-1.1.3.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c0e3d220337ef2233843f369a3abcf520dc44ac0166ecef59433f79bf7e6d039
BLAKE2b-256 checksum
How to use checksums
d3d35f3bb44b919aa5fbf04a593289522ac8d6b062d787ef8f338b60481e1ece
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.2

Release files / BeraChainToolsPro-1.1.3-py3-none-any.whl

Download URL BeraChainToolsPro-1.1.3-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
439240c23f476ecb9ddf42bdf8f5756fa5c947b4c7b2f7f42bebc65d33a12570
BLAKE2b-256 checksum
How to use checksums
c6b5489c9a160b3085b2066f09cf0f3a85245e9f9a3cab299694fceb82c2b016
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page