import { createComposeSdk, guards, materialisers, resources } from '@lifi/composer-sdk';
// Ethereum mainnet
const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
const UNISWAP_V2_ROUTER = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D';
const UNISWAP_V2_FACTORY = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';
const USDC_WETH_PAIR = '0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc';
const sdk = createComposeSdk({
baseUrl: 'https://composer.li.quest',
apiKey: process.env.LIFI_API_KEY!,
});
const builder = sdk.flow(1, {
name: 'uniswap-v2-add-liquidity',
inputs: {
usdcIn: resources.erc20(USDC, 1),
wethIn: resources.erc20(WETH, 1),
},
});
builder.uniswapV2.addLiquidity('add-liquidity', {
bind: { tokenA: builder.inputs.usdcIn, tokenB: builder.inputs.wethIn },
config: {
router: UNISWAP_V2_ROUTER,
factory: UNISWAP_V2_FACTORY,
pair: USDC_WETH_PAIR,
},
guards: [
// Revert unless the pool price read before the deposit is within ±0.5%
// of the simulated price, in either direction.
guards.band({ port: 'poolPrice', bps: 50 }),
// Revert unless the deposit mints at least 99.5% of the simulated LP amount.
guards.slippage({ port: 'liquidity', bps: 50 }),
],
});
await builder.compile({
signer: '0xYourSignerAddress',
inputs: {
usdcIn: materialisers.directDeposit({ amount: '1000000000' }), // 1,000 USDC
wethIn: materialisers.directDeposit({ amount: '250000000000000000' }), // 0.25 WETH
},
sweepTo: builder.context.sender,
// The LP token has no price, so the default price-impact check would read
// the deposit as a total loss. 0 skips it; the two guards are the protection.
maxPriceImpactBps: 0,
});