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(*, chain: Chain, port: int | None = None)¶
Bases:
ABC
The Backend class handles comms with the local fork network.
- block_to_datetime(block_number: int) datetime ¶
Get the datetime of a block.
This method is very slow, consider batching requests. batch_block_to_datetime is currently under development.
- block_to_timestamp(block_number: int) Timestamp ¶
Get the timestamp of a block.
This method is very slow, consider batching requests. batch_block_to_datetime is currently under development.
- closest_block_lt(datetime_: datetime) int ¶
Get the closest block less than the date given.
- closest_block_to(datetime_: datetime) int ¶
Get the closest block to the date given.
- Raises:
BlockBeforeDeploymentOrInFuture: Block not found for date.
- abstract connect(date_range: tuple[datetime, datetime], backend: str = 'anvil') None ¶
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[Any] | tuple[()] | tuple[Any, ...], call_params: dict[str, Any] | None = None) Any ¶
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[Any] | tuple[()] | tuple[Any, ...], transact_params: dict[str, Any] | None = None) PendingTx ¶
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.
- Raises:
Exception – If the transaction fails.
- contract_transact_with_postprocess(function: ContractFunction, function_params: list[Any] | tuple[()] | tuple[Any, ...], transact_params: dict[str, Any] | None, process_reciept: Callable[[...], Any]) PendingTx ¶
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.
- Raises:
Exception – If the transaction fails.
- deploy_live_contract(protocol: str, name: str, args: list[Any] = [], bytecode: str | None = None) 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.
- Return contract:
the deployed contract
- get_contract(name: str) Contract ¶
Get a web3 contract object.
- Parameters:
name – dojo contract name.
- Raises:
ValueError – If contract is not registered.
- load_state() None ¶
Load the state of the local forked network.
Requires save_state() to have been called first.
- lookup(name_or_address: ChecksumAddress | str) str ¶
Lookup a contract name by address or vice versa.
- Parameters:
name_or_address – contract name or address.
- mine_block(force: bool = True) None ¶
Force the backend to mine a block.
- abstract mint_token(token: str, quantity: int | Decimal) None ¶
Mint tokens for local backend.
- 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.
- rpc_url() str ¶
Get the rpc url for this backend.
- save_state() None ¶
Save the current state of the local forked network.
- set_code(contract_address: HexAddress, code: HexBytes) None ¶
Set the code at the specified address immediately, without mining.
- set_storage(contract_address: HexAddress, storage_address: HexAddress, storage_value: HexStr) None ¶
Set the storage at the specified addresses immediately without mining.
- web3: Web3¶
- web3_contract(address: Address, abi: str) Contract ¶
Get a web3 contract object directly via web3.
- Parameters:
address – deployed contract address.
abi – contract abi ID.
- class dojo.network.ForkedBackend(chain: Chain, port: int | None = None)¶
Bases:
BaseBackend
The ForkedBackend class handles comms with a forked network.
- connect(date_range: tuple[datetime, datetime], backend: str = 'anvil') None ¶
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.
- mint_token(token: str, quantity: int | Decimal) None ¶
Empty function for minting tokens on forked backend.
- class dojo.network.LiveBackend(chain: Chain)¶
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’.
- 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) PendingTx ¶
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.
- disconnect()¶
Disconnect and close the connection to the local network.
- load_state()¶
Calls self.connect() instead.
- mint_token(token: str, quantity: int | Decimal) None ¶
Empty function for minting tokens on live backend.
- save_state()¶
This backend doesn’t support saving state.
- class dojo.network.LocalBackend(*, chain: Chain, port: int | None = None)¶
Bases:
BaseBackend
The LocalBackend class handles comms with a local network.
- connect(date_range: tuple[datetime, datetime], backend: str = 'anvil') None ¶
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.
- 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(rpc_url: str, block_number: int) datetime ¶
Get the datetime of a block.
This method is very slow, consider batching requests. batch_block_to_datetime is currently under development.
You should probably use a method on your Environment instead of this one!
- dojo.network.block_date.block_to_timestamp(rpc_url: str, block_number: int) Timestamp ¶
Get the timestamp of a block.
This method is very slow, consider batching requests. batch_block_to_datetime is currently under development.
You should probably use a method on your Environment instead of this one!