dojo.network package
Network manages everything related to blockchain forking and connection.
This includes the retrieval of contract objects from the blockchain network. And anything related to brownie
- class dojo.network.BaseBackend(port: int | None = None)
Bases:
ABC
The Backend class handles comms with the local fork network.
- abstract connect(date_range: Tuple[datetime, datetime], backend: str = 'anvil')
Instantiate and connect to the local network.
- Parameters:
date_range – simulation date range.
backend – Type of backend to use. Can be one of [‘hardhat’, ‘anvil’].
- contract_call(function: ContractFunction, function_params: list | tuple, call_params: dict | None = None)
Submit a contract read-only call.
- Parameters:
function – Web3.py contract function to call.
function_params – Parameters to pass to the contract function.
call_params – Call parameters.
- contract_transact(function: ContractFunction, function_params: list | tuple, transact_params: dict | None = None) TxReceipt
Submit a contract write transaction.
- Parameters:
function – Web3.py contract function to call.
function_params – Parameters to pass to the contract function.
transact_params – Transaction parameters.
- deploy_dev_contract(contract_path: str, constructor_args: list = [], compiler_version: str = 'latest') Contract
Deploy a contract from a local source file.
- Parameters:
contract_path – path to the contract .sol source file.
constructor_args – contract constructor arguments.
compiler_version – solidity compiler version to use.
- Return contract:
the deployed contract.
- deploy_live_contract(protocol: str, name: str, args: list = [], method: Literal['standard', 'alternate'] = 'standard') Contract
Deploy an existing live contract to the dojo network.
- Parameters:
protocol – protocol name (e.g. UniswapV3, Tokens etc.).
name – dojo contract name.
args – contract constructor arguments.
method – method to use for contract deployment: - “standard”: use the contract constructor - “alternate”: use the contract creation code
- Return contract:
the deployed contract
- abstract disconnect()
Disconnect and close the connection to the local network.
- get_contract(name: str) Contract
Get a web3 contract object.
- Parameters:
name – dojo contract name.
- Raises:
ValueError – If contract is not registered.
- load_state()
Load the state of the local forked network.
Requires save_state() to have been called first.
- lookup(name_or_address: str) str
Lookup a contract name by address or vice versa.
- Parameters:
name_or_address – contract name or address.
- Raises:
ValueError – If contract is not registered.
- register_contract(name: str, contract: Contract) None
Register a contract that is already deployed at some address.
- Parameters:
name – dojo contract name.
contract – the deployed contract.
- Raises:
ValueError – If contract is already registered.
- save_state()
Save the current state of the local forked network.
- web3_contract(address: str, abi: str) Contract
Get a web3 contract object directly via web3.
- Parameters:
address – deployed contract address.
abi – contract abi ID.
- class dojo.network.ForkedBackend(port: int | None = None)
Bases:
BaseBackend
The ForkedBackend class handles comms with a forked network.
- connect(date_range: Tuple[datetime, datetime], backend: str = 'anvil')
Instantiate and connect to the dojo network.
- Parameters:
date_range – simulation date range.
backend – Type of backend to use. Can be one of ‘hardhat’ or ‘anvil’.
- Raises:
ValueError – if requested backend is not supported.
- disconnect()
Disconnect and close the connection to the local network.
- class dojo.network.LiveBackend
Bases:
BaseBackend
The live backend connects to a live network.
- connect(date_range: Tuple[datetime, datetime], backend: str = 'anvil')
Instantiate and connect to a live network.
- Parameters:
date_range – simulation date range.
backend – Type of backend to use. Can be one of ‘hardhat’.
- disconnect()
Disconnect and close the connection to the local network.
- load_state()
Calls self.connect() instead.
- save_state()
This backend doesn’t support saving state.
- class dojo.network.LocalBackend(port: int | None = None)
Bases:
BaseBackend
The LocalBackend class handles comms with a local network.
- connect(date_range: Tuple[datetime, datetime], backend: str = 'anvil')
Instantiate and connect to the dojo network.
- Parameters:
date_range – simulation date range.
backend – Type of backend to use. Can be one of ‘hardhat’.
- Raises:
ValueError – if requested backend is not supported.
- disconnect()
Disconnect and close the connection to the local network.
- mint_token(token: str, quantity: int | Decimal) None
Mint tokens to the account that deployed the contract.
- Parameters:
token – Name of the token to mint.
quantity – quantity to mint in human or machine readable format.
Submodules
Methods for converting between blocks and dates.
- dojo.network.block_date.block_to_datetime(block_number: int) datetime
Get the datetime of a block.
This method is very slow, use batch_block_to_datetime if getting more than one timestamp.
- dojo.network.block_date.block_to_timestamp(block_number: int) float
Get the timestamp of a block.
This method is very slow, use batch_block_to_datetime if getting more than one timestamp.
- dojo.network.block_date.clean_blocks_files()
Delete all CSV files in the data directory that start with blocks-.
- dojo.network.block_date.closest_block_lt(date: datetime) int
Get the closest block less than the date given.
- dojo.network.block_date.closest_block_to(date: datetime) int
Get the closest block to the date given.