PAB is a framework that helps with development and automation of periodic tasks on blockchains.
Project description
PyAutoBlockchain (PAB)
PAB is a framework that helps with development and automation of periodic tasks on blockchains.
With PAB, you quickstart your blockchain development and prototyping. After running pab init to create a new project, you can jump right into developing your own strategies.
With little more configuration, you can connect to any Web3 compatible network using an RPC, load contracts from the network, and use any account you have the Private Key of to authenticate against the network (if you need to make transactions).
PAB allows you to quickly implement Strategies without worring about some Web3 implementation details, like connecting to a blockchain, retrieving contracts and sending transactions.
Check out our documentation here!
Installation
Using pip:
$ pip install PyAutoBlockchain
With PABUI
Install with PABUI extension:
$ pip install PyAutoBlockchain[ui]
And run PABUI from your projects directory:
$ ls
abis/ config.json contracts.json strategies.py tasks.json venv/
$ pabui
Usage
Create project in current directory:
(venv) $ pab init
Run project:
(venv) $ pab run
For a substantially more complete guide, head over to our Official Documentation's Guide section.
Sample Strategy
PAB will load custom strategies at startup from a strategies
module in the current working directory.
This module can be a single strategies.py
file or a strategies
directory with an __init__.py
file.
All subclasses of pab.strategy.BaseStrategy
are loaded as available strategies for tasks, and all must implement
the run()
method.
Here's a basic sample strategy to give you an idea of the Strategy API:
import csv
from datetime import datetime
from pab.strategy import BaseStrategy
class CompoundAndLog(BaseStrategy):
""" Finds pool in `masterchef` for `token`, compounds the given pool for
`self.accounts[account_index]` and logs relevant data into some csv file. """
def __init__(self, *args, filepath: str = "compound.csv", token: str = '', masterchef: str = '', account_index: int = 0):
super().__init__(*args)
self.filepath = filepath
self.account = self.accounts[account_index]
self.token = self.contracts.get(token)
self.masterchef = self.contracts.get(masterchef)
self.pool_id = self.masterchef.functions.getPoolId(self.token.address).call()
if not self.pool_id:
raise Exception(f"Pool not found for {self.token} in {self.masterchef}")
def run(self):
""" Strategy entrypoint. """
balance = self.get_balance()
new_balance = self.compound()
self.write_to_file(balance, new_balance)
self.logger.info(f"Current balance is {balance}")
def compound(self) -> int:
self.transact(self.account, self.masterchef.functions.compound, (self.pool_id, ))
return self.get_balance()
def get_balance(self) -> int:
return self.masterchef.functions.balanceOf(
self.account.address,
self.pool_id
).call()
def write_to_file(self, old_balance: int, new_balance: int):
now = datetime.now().strftime('%Y-%m-%d %I:%M:%S')
diff = new_balance - old_balance
with open(self.filepath, 'a') as fp:
writer = csv.writer(fp)
writer.writerow([now, new_balance, diff])
For more details, read our Official Documentation's Strategies In-Depth section.
Development
Testing
Unit Tests
To run unit tests:
(venv) $ pip install -e requirements-dev.txt
(venv) $ ./tests.sh
Integration tests
The recommended way to run integration-tests is with act.
With act you can run:
$ act -j integration-tests
to run integration from the github actions tests inside a docker container.
The other way is to use local installations of truffle and ganache and run:
$ ./integration-tests.sh
For more information on integration tests see Integration Tests README.
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.5.tar.gz
.
File metadata
- Download URL: PyAutoBlockchain-0.5.tar.gz
- Upload date:
- Size: 28.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d050d6dd0c1decec677dc2f323dd97539e8c4bc8f35192024881a69fcd5b3a71 |
|
MD5 | bb356df19bb759f2fde9a527b2547066 |
|
BLAKE2b-256 | a0a0bbdc09bc483be31b332d0c0e0ec09cf8dc7d559225fe92f1c6bf034d16a8 |
File details
Details for the file PyAutoBlockchain-0.5-py3-none-any.whl
.
File metadata
- Download URL: PyAutoBlockchain-0.5-py3-none-any.whl
- Upload date:
- Size: 32.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f64fed762e2b09de600f1c4ea1d032d37ada007a2229bb65df757387661e790f |
|
MD5 | b90977fbbea6de005e71ea072eb7b668 |
|
BLAKE2b-256 | c11ae8793fd8772d3a7abc84b9d46982fc8ed57b19ece7d9eaf98ed5b218d4a3 |