Skip to main content

Scenario

A wallet user holds small balances of USDT, DAI, FRAX and LUSD on Ethereum and wants them as one USDC balance, with one signature. The flow declares one input per stablecoin and swaps each into USDC with its own lifi.swap. All four swaps share one config. sweepTo sends the USDC to the signer in the same transaction.

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 consolidateToUsdc.ts.

Run it

Save the file as consolidate-to-usdc.mts and run it:
The script compiles the flow and prints the result; it sends nothing. To submit, send result.actions in order, as in Build a same-chain flow.

What to check

  • result.outputs['<swap id>.amountOut'] is the USDC from each swap: amount.estimate is the simulated amount and amount.minimum is the swap’s 3% floor. sweepTo makes the signer their owner.
  • result.actions holds an approval for each stablecoin the proxy needs, then execute.
  • A <swap id>.unspentIn output appears only if a swap leaves part of its input unsold. sweepTo returns it too.