Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ForkUtils

Git Source

Inherits: Credible

Title: ForkUtils

Author: Phylax Systems

Shared fork-aware read and ERC20-delta helpers for assertions and protection suites.

Constants

FORK_VIEW_GAS

Gas forwarded to snapshot-time protocol view calls made through ph.staticcallAt.

uint64 internal constant FORK_VIEW_GAS = 500_000

Functions

_viewFailureMessage

Revert string used when a fork-time static call fails.

Override this when a more specific failure message is useful for a derived contract.

function _viewFailureMessage() internal pure virtual returns (string memory);

_viewAt

Executes a static call against target at a specific snapshot fork.

function _viewAt(address target, bytes memory data, PhEvm.ForkId memory fork)
    internal
    view
    returns (bytes memory resultData);

Parameters

NameTypeDescription
targetaddressThe protocol contract to query.
databytesABI-encoded calldata for the target view.
forkPhEvm.ForkIdThe snapshot fork the read should execute against.

Returns

NameTypeDescription
resultDatabytesRaw return bytes from the static call.

_readUintAt

Convenience wrapper that decodes a snapshot-time static call as uint256.

function _readUintAt(address target, bytes memory data, PhEvm.ForkId memory fork)
    internal
    view
    returns (uint256 value);

_readUint8At

Convenience wrapper that decodes a snapshot-time static call as uint8.

function _readUint8At(address target, bytes memory data, PhEvm.ForkId memory fork)
    internal
    view
    returns (uint8 value);

_readAddressAt

Convenience wrapper that decodes a snapshot-time static call as address.

function _readAddressAt(address target, bytes memory data, PhEvm.ForkId memory fork)
    internal
    view
    returns (address value);

_readBoolAt

Convenience wrapper that decodes a snapshot-time static call as bool.

function _readBoolAt(address target, bytes memory data, PhEvm.ForkId memory fork)
    internal
    view
    returns (bool value);

_readBalanceAt

Convenience wrapper that reads an ERC20-style balanceOf(account) at a snapshot fork.

function _readBalanceAt(address token, address account, PhEvm.ForkId memory fork)
    internal
    view
    returns (uint256 balance);

_reducedErc20BalanceDeltasAt

Returns reduced ERC20 transfer deltas for a token within the selected fork scope.

function _reducedErc20BalanceDeltasAt(address token, PhEvm.ForkId memory fork)
    internal
    view
    returns (PhEvm.Erc20TransferData[] memory deltas);

_transferredValueAt

Returns the total amount of token transferred from from to to in the fork scope.

function _transferredValueAt(address token, address from, address to, PhEvm.ForkId memory fork)
    internal
    view
    returns (uint256 value);

_consumedBetween

Computes the non-negative decrease between two snapshot values.

function _consumedBetween(uint256 beforeValue, uint256 afterValue) internal pure returns (uint256 consumed);