PAB is a framework for developing and running custom tasks in crypto blockchains.
Project description
PyAutoBlockchain (PAB)
PAB is a framework that helps with development and automation of periodic tasks on blockchains.
For a more in-depth guide see GUIDE.md, the example at examples or a more complex implementation at PolyCompounder.
Installation
Using pip:
$ pip install PyAutoBlockchain
Usage
(venv) $ pab create-keyfile [-o keyfile] # Create keyfile
(venv) $ pab edit-config # Edit config file
(venv) $ pab list-strategies -v # List available strategies and parameters
(venv) $ pab run # Run tasks
Configuration
Configure wallet and RPC
Create project config and keyfile:
(venv) $ pab edit-config
(venv) $ pab create-keyfile
A basic config file without alerts enabled might look like:
{
"blockchain": "POLYGON",
"chainId": 137,
"endpoint": "https://mainnet.infura.io/v3/your_key",
"myAddress": "0xyour_address"
}
You can get a free RPC endpoint for most known blockchains (e.g. Infura or MaticVigil).
Adding extra contracts
To use contracts in the strategies you first need to add the abi file to abis
and
modify the contracts.json
file to load it.
For example, given the contract for MYTOKEN
at 0x12345
create the abifile at abis/mytoken.abi
and add
to contracts.json
the following:
{
"MYTOKEN": {
"address": "0x12345",
"abifile": "mytoken.abi"
}
}
Setting up tasks
You can add tasks to execute at tasks.json
.
For example, the following example defines 1 task to execute, using the strategy BaseStrategy
and the contracts BNB
, WBTC
, PAIR
, MASTERCHEF
and ROUTER
.
[
{
"strategy": "BaseStrategy",
"name": "BNB-WBTC",
"repeat_every": {
"days": 1
},
"params": {
"swap_path": ["BNB", "WBTC"],
"pair": "PAIR",
"masterchef": "MASTERCHEF",
"router": "ROUTER",
"pool_id": 11
}
}
]
Tasks are defined as dictionaries with:
strategy
: Class name of strategy (must be subclass ofpab.strategy.BaseStrategy
, seepab list-strategies
)name
: Name, just for logging.params
: Dictionary with strategy parameters. (seepab list-strategies -v
)repeat_every
: Optional. Dictionary with periodicity of the process, same arguments asdatetime.timedelta
.
Run pab list-strategies -v
to see available strategies and parameters.
Creating custom strategies
pab
will load custom strategies at startup from a strategies
module in the current working directory.
Custom strategies must be childs of pab.strategy.BaseStrategy
.
For more info on creating strategies see GUIDE.md and PolyCompounder for a different example.
Email alerts
You can setup email alerts for when something goes wrong.
Add the following to your config.json
:
{
"emails": {
"enabled": true,
"host": "smtp.host.com",
"port": 465,
"address": "email@host.com",
"password": "password",
"recipient": "me@host.com"
}
}
Transaction settings
Transaction options are available in config.json
:
{
"transactions": {
"timeout": 200,
"gasPrice": {
"number": "1.1",
"unit": "gwei"
},
"gas": {
"useEstimate": false,
"exact": 200000
}
}
}
Developing
For details see ARCHITECTURE.md
Running tests
Using pytest:
(venv) $ pip install -e requirements-dev.txt
(venv) $ ./tests.sh
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file PyAutoBlockchain-0.3.4.tar.gz
.
File metadata
- Download URL: PyAutoBlockchain-0.3.4.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff63701f6ccaa0cdd3774b77abe1ae4d29c87068b222bdab75456bb4f44fbf4a |
|
MD5 | 72ebfab6d0ea9f80cb827d0ab6c683bb |
|
BLAKE2b-256 | 94cca23f080e4ef297ecfb447c5cba2d96ae778c73d1726b5cc63b2f79d23187 |
File details
Details for the file PyAutoBlockchain-0.3.4-py3-none-any.whl
.
File metadata
- Download URL: PyAutoBlockchain-0.3.4-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6886c9f603c00a38da3709b27a62fba0fa7fd1653edd01d806a732e2a82cb12e |
|
MD5 | 6acfe36f809f09e8a2ecdaca27593cdd |
|
BLAKE2b-256 | fbc765ba9e53a08553a834b49b7eb72c50015b6a889f03dbe68853a8a24460b0 |