Skip to main content

Intent Hooks

Hooks add custom logic to intents on OrchestratorV3:

  • Pre-intent hooks run during signalIntent, before funds lock. They can only revert, for example to require a signature.
  • Post-intent hooks run when an intent settles. They receive the released tokens and route them, for example to bridge, split or swap.

The depositor or delegate sets a deposit's pre-intent hook. The taker chooses a post-intent hook when signaling. Neither needs a governance allowlist. OrchestratorV3 also runs a governance-selected lifecycle hook, IntentLifecycleHookV1, for whitelist and stake-backed admission; it is separate from both.

Historical reference: O3 retired 2026-11-05

OrchestratorV3 was retired on 2026-11-05. OrchestratorV4 is current. Once O3 is removed from OrchestratorRegistry, Escrow rejects its signal and fulfillment calls. Historical O3 intents, payments and events remain readable. OrchestratorV4 has no pre- or post-intent hooks. The examples below document retired O3 behavior and must not be used as a current integration path.

info

For the protocol-level specification, see Pre-Intent Hooks and Post-Intent Hooks.


Post-Intent Hooks​

Interface​

Post-intent hooks implement IPostIntentHookV2. The orchestrator passes a HookExecutionContext:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

interface IPostIntentHookV2 {
struct HookIntentContext {
address owner;
address to;
address escrow;
uint256 depositId;
uint256 amount;
uint256 timestamp;
bytes32 paymentMethod;
bytes32 fiatCurrency;
uint256 conversionRate;
bytes32 payeeId;
bytes signalHookData; // from SignalIntentParams.data
}

struct HookExecutionContext {
bytes32 intentHash;
address token; // deposit token
uint256 executableAmount;// amount after all fees
HookIntentContext intent;
}

function execute(
HookExecutionContext calldata _ctx,
bytes calldata _fulfillHookData
) external;
}

Source: contracts/interfaces/IPostIntentHookV2.sol

How it works​

When an intent settles, OrchestratorV3:

  1. Deducts the protocol, referral and manager fees from the released amount. The rest is executableAmount.
  2. Approves your hook to pull exactly executableAmount of the deposit token.
  3. Calls hook.execute(ctx, fulfillHookData).
  4. Checks that the hook pulled exactly executableAmount and sent nothing back, then resets the allowance to zero.

If any step fails, the whole settlement reverts. The hook also runs when the depositor releases funds manually with releaseFundsToPayer, with empty fulfillHookData.

Minimal template​

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IPostIntentHookV2 } from "zkp2p-contracts/contracts/interfaces/IPostIntentHookV2.sol";

contract MyHook is IPostIntentHookV2 {
using SafeERC20 for IERC20;

address public immutable orchestrator;

constructor(address _orchestrator) {
orchestrator = _orchestrator;
}

function execute(
HookExecutionContext calldata ctx,
bytes calldata /* fulfillHookData */
) external override {
require(msg.sender == orchestrator, "only orchestrator");
IERC20(ctx.token).safeTransferFrom(msg.sender, ctx.intent.to, ctx.executableAmount);
}
}

Passing data to hooks​

  • At signal time: SignalIntentParams.data is stored with the intent and arrives as ctx.intent.signalHookData. Use it for static configuration, such as a target address, split ratio or destination chain.
  • At fulfill time: FulfillIntentParams.postIntentHookData arrives as _fulfillHookData. Use it for dynamic inputs, such as a bridge quote, memo or flags. It is empty on manual release.

Example: 95/5 split​

// builder: an immutable fee recipient set in the constructor
function execute(HookExecutionContext calldata ctx, bytes calldata) external override {
require(msg.sender == orchestrator, "only orchestrator");
uint256 fee = ctx.executableAmount * 5 / 100;
IERC20(ctx.token).safeTransferFrom(msg.sender, ctx.intent.to, ctx.executableAmount - fee);
IERC20(ctx.token).safeTransferFrom(msg.sender, builder, fee);
}

Example: pull, then act​

function execute(HookExecutionContext calldata ctx, bytes calldata) external override {
require(msg.sender == orchestrator, "only orchestrator");
IERC20(ctx.token).safeTransferFrom(msg.sender, address(this), ctx.executableAmount);
// The hook now holds the tokens: approve a router, bridge, swap,
// and forward the result to ctx.intent.to.
}

What reverts​

  • Pulling any amount other than executableAmount
  • Sending tokens to the orchestrator during execution
  • Any revert inside the hook

Deploy and use​

  1. Deploy your hook with the OrchestratorV3 address (0x014025fDE093f8701d86e9f38e2C3a9b779cb5c7).
  2. Signal an intent on OrchestratorV3 with your hook and its signal-time data:
import { encodeAbiParameters } from "viem";

const ORCHESTRATOR_V3 = "0x014025fDE093f8701d86e9f38e2C3a9b779cb5c7";

const signalTxHash = await client.signalIntent({
depositId,
amount,
toAddress,
processorName,
payeeDetails,
fiatCurrencyCode,
conversionRate, // 18 decimals
postIntentHook: myHookAddress,
data: encodeAbiParameters([{ type: "address" }], [targetAddress]),
orchestratorAddress: ORCHESTRATOR_V3,
});
  1. Fulfill with the hook's fulfill-time data:
await client.fulfillIntent({
intentHash,
proof,
postIntentHookData: encodeAbiParameters([{ type: "string" }], [memo]),
});

See the Client Reference for the full signalIntent() and fulfillIntent() parameters.


Pre-Intent Hooks​

Interface​

Pre-intent hooks implement IPreIntentHook. They run during signalIntent before any state changes and can only revert to reject:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import { IReferralFee } from "./IReferralFee.sol";

interface IPreIntentHook {
struct PreIntentContext {
address taker;
address escrow;
uint256 depositId;
uint256 amount;
address to;
bytes32 paymentMethod;
bytes32 fiatCurrency;
uint256 conversionRate;
IReferralFee.ReferralFee[] referralFees;
bytes preIntentHookData; // from SignalIntentParams.preIntentHookData
}

function validateSignalIntent(PreIntentContext calldata _ctx) external;
}

Source: contracts/interfaces/IPreIntentHook.sol

How it works​

Each deposit has one pre-intent hook slot on OrchestratorV3. The hook runs during signalIntent; if it reverts, the intent is rejected.

Built-in implementation​

HookAddress (Base)Purpose
SignatureGatingPreIntentHook0x62D410a3d6FC766dd2192be2a67a5fc79c5c2e1FRequires an EIP-191 signature from a signer you configure

The depositor or delegate sets the signer with setDepositSigner(escrow, depositId, signer) on the hook. The taker passes the ABI-encoded signature and expiration as preIntentHookData. See Pre-Intent Hooks for the signed message.

Setup​

The depositor or delegate sets the deposit's hook:

const ORCHESTRATOR_V3 = "0x014025fDE093f8701d86e9f38e2C3a9b779cb5c7";

await client.setDepositPreIntentHook({
depositId,
preIntentHook: hookAddress, // the zero address removes the hook
orchestratorAddress: ORCHESTRATOR_V3,
});

Deposit whitelists are a separate mechanism; see Deposit access policy.

Writing a custom pre-intent hook​

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import { IPreIntentHook } from "zkp2p-contracts/contracts/interfaces/IPreIntentHook.sol";

contract MyGatingHook is IPreIntentHook {
function validateSignalIntent(PreIntentContext calldata ctx) external override {
// Only allow intents of at least 100 USDC (6 decimals).
require(ctx.amount >= 100e6, "amount too low");

// Only allow Venmo.
require(ctx.paymentMethod == keccak256("venmo"), "method not allowed");

// Returning without reverting approves the intent.
}
}

Deploy it and set it on your deposit. No governance approval is needed.


Tips​

  • Keep hooks short and deterministic. A revert undoes the whole transaction.
  • Use SafeERC20 for token transfers.
  • Store the orchestrator address as immutable and check msg.sender against it.
  • Read the token from ctx.token; you don't need to query the escrow.

Addresses​

ContractAddress (Base)Basescan
OrchestratorV30x014025fDE093f8701d86e9f38e2C3a9b779cb5c7View
EscrowV20x777777779d229cdF3110e9de47943791c26300EfView
SignatureGatingPreIntentHook0x62D410a3d6FC766dd2192be2a67a5fc79c5c2e1FView
IntentLifecycleHookV10x5Dd6C675a7406fE8C9f0D93394a36fd6e8c50031View

See V3 Deployments for every contract address.