The debug instructions are Foundry-only helpers that print swap state to the console during local testing. They are not part of the production SwapVM opcode set and are not intended for production programs. Each one depends on forge-std/console.sol and produces no output outside a Foundry test environment.
Debug instructions are Foundry-only. Do not include them in production strategy programs or on deployed routers.
Source: src/instructions/Debug.sol
Injecting debug opcodes
Solidity
123
function _injectDebugOpcodes(
function(Context memory, bytes calldata) internal[] memory opcodes
) internal pure returns (function(Context memory, bytes calldata) internal[] memory)
Registers all five debug instructions into opcode slots 0 to 4 of the provided opcodes array. Call it during router initialization to enable the debug instructions in tests.
Instructions
All debug instructions take no args (0 bytes) and are pure or view only.
_printSwapRegisters
Solidity
1
function _printSwapRegisters(Context memory ctx, bytes calldata /* args */) internal pure
Logs ctx.swap: balanceIn, balanceOut, amountIn, amountOut.
_printSwapQuery
Solidity
1
function _printSwapQuery(Context memory ctx, bytes calldata /* args */) internal pure
Logs ctx.query: orderHash, taker, maker, tokenIn, tokenOut, isExactIn.
_printContext
Solidity
1
function _printContext(Context memory ctx, bytes calldata /* args */) internal pure
Logs ctx.vm: nextPC and takerArgs (as hex string).
_printGasLeft
Solidity
1
function _printGasLeft(Context memory /* ctx */, bytes calldata /* args */) internal view
Logs gasleft().
_printFreeMemoryPointer
Solidity
1
function _printFreeMemoryPointer(Context memory /* ctx */, bytes calldata /* args */) internal pure
Logs the free memory pointer (mload(0x40)).
Related
- SwapVM: overview of the instruction execution model.