Skip to main content

Escrow Contract

The Escrow contract is the core contract that holds depositor liquidity and manages the deposit lifecycle. It handles deposit creation, fund management, and intent locking/unlocking in coordination with the Orchestrator.

Overview

  • Contract: Escrow.sol
  • Inherits: Ownable, Pausable, ReentrancyGuard, IEscrow
  • Purpose: Escrows deposits and manages deposit lifecycle

Key State Variables

IOrchestrator
Address of the orchestrator contract
IPaymentVerifierRegistry
Address of the payment verifier registry contract
uint256
Counter for depositIds
uint256
Amount below which deposits are considered dust and can be closed
uint256
Maximum active intents per deposit (suggested to keep below 100 to prevent deposit withdraw DOS)
uint256
Time period after which an intent expires

Core Functions

Deposit Management

createDeposit

Creates a deposit entry by locking liquidity in the escrow contract.
CreateDepositParams
Struct containing all deposit parameters:
  • token: The ERC20 token to deposit
  • amount: Amount of tokens to deposit
  • intentAmountRange: Min and max intent amounts
  • paymentMethods: List of supported payment methods
  • paymentMethodData: Verification data for each payment method
  • currencies: Supported currencies with min conversion rates
  • delegate: Optional delegate to manage the deposit
  • intentGuardian: Address that can extend intent expiry
  • retainOnEmpty: Whether to keep deposit config when empty
Events Emitted:
  • DepositReceived(depositId, depositor, token, amount, intentAmountRange, delegate, intentGuardian)
  • DepositPaymentMethodAdded(depositId, paymentMethod, payeeDetails, intentGatingService)
  • DepositCurrencyAdded(depositId, paymentMethod, currencyCode, minConversionRate)

addFunds

Adds additional funds to an existing deposit.
uint256
The deposit ID to add funds to
uint256
The amount of tokens to add

removeFunds

Removes funds from an existing deposit. Expired intents are pruned if necessary.
uint256
The deposit ID to remove funds from
uint256
The amount of tokens to remove

withdrawDeposit

Returns all remaining deposits and any outstanding intents that are expired to the depositor.
uint256
DepositId the depositor is attempting to withdraw

Delegate Management

setDelegate

Allows depositor to set a delegate address that can manage a specific deposit.
uint256
The deposit ID
address
The address to set as delegate

removeDelegate

Allows depositor to remove the delegate for a specific deposit.

Deposit Configuration

setCurrencyMinRate

Updates the min conversion rate for a currency for a payment verifier.
uint256
The deposit ID
bytes32
The payment method to update
bytes32
The fiat currency code
uint256
The new min conversion rate (must be greater than 0)

setIntentRange

Updates the intent amount range for a deposit.
uint256
The deposit ID
Range
The new intent amount range (min and max)

setAcceptingIntents

Allows depositor or delegate to set the accepting intents state for a deposit.
uint256
The deposit ID
bool
The new accepting intents state

Orchestrator-Only Functions

lockFunds

ORCHESTRATOR ONLY: Locks funds for an intent with expiry time.
uint256
The deposit ID to lock funds from
bytes32
The intent hash this intent corresponds to
uint256
The amount to lock
Events Emitted:
  • FundsLocked(depositId, intentHash, amount, expiryTime)

unlockFunds

ORCHESTRATOR ONLY: Unlocks funds from a cancelled intent.
uint256
The deposit ID to unlock funds from
bytes32
The intent hash to find and remove the intent for
Events Emitted:
  • FundsUnlocked(depositId, intentHash, amount)

unlockAndTransferFunds

ORCHESTRATOR ONLY: Unlocks and transfers funds from a fulfilled intent.
uint256
The deposit ID to transfer from
bytes32
The intent hash to find and remove the intent for
uint256
The amount to actually transfer (may be less than intent amount)
address
The address to transfer to (orchestrator)
Events Emitted:
  • FundsUnlockedAndTransferred(depositId, intentHash, intentAmount, transferAmount, to)

Intent Guardian Functions

extendIntentExpiry

INTENT GUARDIAN ONLY: Extends the expiry time of an existing intent.
uint256
The deposit ID containing the intent
bytes32
The intent hash to extend expiry for
uint256
The additional time to extend the expiry by
Events Emitted:
  • IntentExpiryExtended(depositId, intentHash, newExpiryTime)

Public Functions

pruneExpiredIntents

ANYONE: Can be called by anyone to clean up expired intents.
uint256
The deposit ID to prune expired intents for

View Functions

getDeposit

Returns the deposit struct for a given deposit ID.
address
Address of the depositor
address
Address of the delegate (if any)
IERC20
The ERC20 token being deposited
Range
Min and max intent amounts
bool
Whether the deposit is accepting new intents
uint256
Available liquidity not locked by intents
uint256
Total amount locked by active intents

getDepositIntentHashes

Returns all active intent hashes for a deposit.

getDepositPaymentMethods

Returns all payment methods configured for a deposit.

getDepositCurrencies

Returns all currencies for a specific payment method on a deposit.

getExpiredIntents

Returns expired intents and the total reclaimable amount.

Events

DepositReceived

Emitted when a new deposit is created.

FundsLocked

Emitted when funds are locked for an intent.

FundsUnlocked

Emitted when funds are unlocked from a cancelled intent.

FundsUnlockedAndTransferred

Emitted when funds are unlocked and transferred for a fulfilled intent.

Constants

uint256
1e18 - Precision unit for calculations
uint256
1e6 - Maximum dust threshold (1 USDC)
uint256
86400 * 5 - Maximum intent expiration period (5 days)

Example Usage

Creating a Deposit

Locking Funds for an Intent