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
Address of the orchestrator contract
Address of the payment verifier registry contract
Counter for depositIds
Amount below which deposits are considered dust and can be closed
Maximum active intents per deposit (suggested to keep below 100 to prevent deposit withdraw DOS)
Time period after which an intent expires
Core Functions
Deposit Management
createDeposit
Creates a deposit entry by locking liquidity in the escrow contract.Struct containing all deposit parameters:
token: The ERC20 token to depositamount: Amount of tokens to depositintentAmountRange: Min and max intent amountspaymentMethods: List of supported payment methodspaymentMethodData: Verification data for each payment methodcurrencies: Supported currencies with min conversion ratesdelegate: Optional delegate to manage the depositintentGuardian: Address that can extend intent expiryretainOnEmpty: Whether to keep deposit config when empty
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.The deposit ID to add funds to
The amount of tokens to add
removeFunds
Removes funds from an existing deposit. Expired intents are pruned if necessary.The deposit ID to remove funds from
The amount of tokens to remove
withdrawDeposit
Returns all remaining deposits and any outstanding intents that are expired to the depositor.DepositId the depositor is attempting to withdraw
Delegate Management
setDelegate
Allows depositor to set a delegate address that can manage a specific deposit.The deposit ID
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.The deposit ID
The payment method to update
The fiat currency code
The new min conversion rate (must be greater than 0)
setIntentRange
Updates the intent amount range for a deposit.The deposit ID
The new intent amount range (min and max)
setAcceptingIntents
Allows depositor or delegate to set the accepting intents state for a deposit.The deposit ID
The new accepting intents state
Orchestrator-Only Functions
lockFunds
ORCHESTRATOR ONLY: Locks funds for an intent with expiry time.The deposit ID to lock funds from
The intent hash this intent corresponds to
The amount to lock
FundsLocked(depositId, intentHash, amount, expiryTime)
unlockFunds
ORCHESTRATOR ONLY: Unlocks funds from a cancelled intent.The deposit ID to unlock funds from
The intent hash to find and remove the intent for
FundsUnlocked(depositId, intentHash, amount)
unlockAndTransferFunds
ORCHESTRATOR ONLY: Unlocks and transfers funds from a fulfilled intent.The deposit ID to transfer from
The intent hash to find and remove the intent for
The amount to actually transfer (may be less than intent amount)
The address to transfer to (orchestrator)
FundsUnlockedAndTransferred(depositId, intentHash, intentAmount, transferAmount, to)
Intent Guardian Functions
extendIntentExpiry
INTENT GUARDIAN ONLY: Extends the expiry time of an existing intent.The deposit ID containing the intent
The intent hash to extend expiry for
The additional time to extend the expiry by
IntentExpiryExtended(depositId, intentHash, newExpiryTime)
Public Functions
pruneExpiredIntents
ANYONE: Can be called by anyone to clean up expired intents.The deposit ID to prune expired intents for
View Functions
getDeposit
Returns the deposit struct for a given deposit ID.Address of the depositor
Address of the delegate (if any)
The ERC20 token being deposited
Min and max intent amounts
Whether the deposit is accepting new intents
Available liquidity not locked by intents
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
1e18 - Precision unit for calculations1e6 - Maximum dust threshold (1 USDC)86400 * 5 - Maximum intent expiration period (5 days)