Skip to main content

Scenario

A user swaps 1 WETH to USDC and deposits the USDC into Aave as aEthUSDC, in one transaction on Ethereum. The Flow binds the lifi.swap output handle straight into the lifi.zap input, and a slippage guard floors the deposit.

Full example

Install the SDK with npm install @lifi/composer-sdk @lifi/compose-spec and set LIFI_API_KEY; see Before you start. Adapted from swapAndZap.ts.

Run it

Save the file as swap-and-deposit.mts and run node swap-and-deposit.mts. The script compiles the flow; it sends nothing.

What to check

  • result.outputs['zap.amountOut'] is the aEthUSDC the signer receives (role: 'terminal', swept to the sender). amount.estimate is the simulated amount; amount.minimum is the 1% guard floor (basis: 'guard').
  • result.outputs['swap.amountOut'] has role: 'consumed' and consumedBy: 'zap'. Its amount.minimum is the swap’s own 3% floor (basis: 'op'), so the swap needs no guard.
  • result.actions holds the WETH approval, then execute.