Overview
The Vault contract is an escrow contract for managing cross-chain reward payments. It implements a lifecycle-based vault that can be funded, withdrawn from, or refunded. Contract Location:contracts/vault/Vault.sol
Implements: IVault
Vault contracts are created deterministically using CREATE2 by the IntentSource contract. Each intent gets its own dedicated vault for holding rewards.
State Variables
portal
Constructor
Vault()
The constructor automatically sets msg.sender as the portal, ensuring only the deploying contract can manage vault operations.
State-Changing Functions
fundFor
The reward structure containing token addresses, amounts, and native value
Address that will provide the funding
Optional permit contract for gasless token approvals
True if the vault was fully funded, false otherwise
This function is payable to accept native tokens (ETH). It first attempts to use the permit contract for gasless approvals, then falls back to standard ERC20 transfers if needed.
withdraw
The reward structure defining what to withdraw
Address that will receive the withdrawn rewards
The function withdraws the minimum of the reward amount and the vault’s actual balance for each token. This allows partial withdrawals if the vault is not fully funded.
refund
The reward structure containing token information
Address to receive the refunded rewards
Unlike withdraw, this function refunds the entire balance of each token and all native currency in the vault, not just the reward amounts.
recover
Address to receive the recovered tokens
Address of the token to recover (must not be a reward token)
This function is used to recover tokens that were sent to the vault by mistake. The token must not be among the reward tokens, and the vault must have a non-zero balance of the token.
Errors
NotPortalCaller
NativeTransferFailed
ZeroRecoverTokenBalance
Access Control
All state-changing functions use theonlyPortal modifier, which ensures that only the portal contract can:
- Fund the vault
- Withdraw rewards to claimants
- Refund rewards to creators
- Recover mistakenly sent tokens