Strategy API

For more info see Strategies In-Depth.

pab.strategy.StrategiesDict

TypeAlias for a mapping of strategy_name: strategy_class

pab.strategy.import_strategies(root: Path)

Imports strategies module from root directory.

class pab.strategy.BaseStrategy(blockchain: Blockchain, name: str)

Abstract Base Class for custom strategies.

blockchain: Blockchain

Current blockchain connection.

property accounts: dict[int, LocalAccount]

Returns available accounts in current blockchain. You can access specific accounts with numeric indexes

property contracts: ContractManager

Returns a pab.contract.ContractManager. You can use self.contracts.get(name) to retrieve a contract by name.

abstract run()

Strategy entrypoint. Must be defined by all childs.

transact(account: LocalAccount, func: Callable, args: tuple) TxReceipt

Makes a transaction on the current blockchain.

exception pab.strategy.PABError

Base class for errors while running tasks. Unhandleded PABErrors will prevent further excecutions of a strategy.

exception pab.strategy.RescheduleError

Strategies can raise this exception to tell PAB to reschedule them in known scenarios.

exception pab.strategy.SpecificTimeRescheduleError(message: str, next_at: int | float)

Same as RescheduleError but at a specific time passed as a timestamp.