Execute complex DeFi operations seamlessly by building transaction data and sending it with your wallet signer. The SDK handles transaction building, gas estimation, and execution automatically.The
zap
method combines transaction building and execution into a single, streamlined operation. This approach simplifies complex DeFi workflows while maintaining full control over transaction parameters.
Before executing zaps, tokens typically require approval to allow the DZap
contracts to spend them on your behalf. Learn more about gas-optimized
approval mechanisms in the Approval Mechanisms
section.
Zap Execution
Execute a zap using the zap method:Parameters
Thezap
function expects an object with these parameters:
Required Parameters
Parameter | Type | Required | Description |
---|---|---|---|
request | ZapBuildTxnRequest | yes | The zap build request containing operation parameters |
signer | Signer | WalletClient | yes | Ethers signer or viem wallet client for transaction execution |
steps | ZapTransactionStep[] | no | Pre-built transaction steps (if not provided, will build from request) |
ZapBuildTxnRequest Structure
Parameter | Type | Required | Description |
---|---|---|---|
srcChainId | number | yes | Source chain ID |
destChainId | number | yes | Destination chain ID |
account | HexString | yes | User account address |
srcToken | HexString | yes | Source token address |
destToken | HexString | yes | Destination token/protocol address |
amount | string | yes | Amount to zap (in token units) |
recipient | HexString | yes | Address to receive the result |
refundee | HexString | yes | Address to receive refunds |
slippage | number | yes | Slippage tolerance percentage |
permitData | string | no | Pre-signed permit data for gasless approvals |
estimateGas | boolean | no | Whether to estimate gas for the transaction |
positionDetails | ZapRouteRequestPositionDetails | no | Position-specific details for liquidity positions |
poolDetails | ZapRouteRequestPoolDetails | no | Pool-specific details for liquidity pool operations |
allowedBridges | string[] | no | Array of allowed bridge protocols for cross-chain operations |
allowedDexes | string[] | no | Array of allowed DEX protocols for swapping operations |
Additional Type Definitions
Complete Example with Quotes and Approvals
Here’s a full example that gets quotes, handles approvals, and executes a zap:Best Practices
- Always get quotes first to understand the expected outcome and fees
- Validate balances before execution to ensure sufficient funds
- Check allowances and execute approvals/permits if needed
- Implement proper error handling with retry logic for failed zaps
- Use appropriate slippage settings based on market conditions and complexity
- Monitor transaction status for zap completion and position updates
Next Steps
- Monitor Zap Status - Track execution progress and final positions
Always ensure users have sufficient balance for both the zap amount and gas
fees before execution. Zap operations can be complex and may require multiple
transactions.
Use the
buildZapTxn
method first to understand the steps involved before
executing. This helps with user experience and debugging complex zap
operations.