const WETH = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
const aWETH = '0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8';
const USDC = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';
const aaveV3Pool = '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2';
const quoteResponse = await fetch('https://api.biconomy.io/v1/quote', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': process.env.API_KEY
},
body: JSON.stringify({
mode: 'smart-account',
ownerAddress: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
composeFlows: [
// Step 1: Deposit initial WETH to Aave
{
type: '/instructions/intent-simple',
data: {
srcToken: WETH,
dstToken: aWETH,
srcChainId: 1,
dstChainId: 1,
amount: '1000000000000000000', // 1 WETH
slippage: 0.001
}
},
// Step 2: Borrow USDC against collateral
{
type: '/instructions/build',
data: {
functionSignature: 'function borrow(address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf)',
args: [
USDC,
'1000000000', // 1000 USDC
2, // Variable rate
0, // No referral
'0xd8da6bf26964af9d7eed9e03e53415d37aa96045'
],
to: aaveV3Pool,
chainId: 1
}
},
// Step 3: Swap borrowed USDC to WETH
{
type: '/instructions/intent-simple',
data: {
srcToken: USDC,
dstToken: WETH,
srcChainId: 1,
dstChainId: 1,
amount: '1000000000', // 1000 USDC
slippage: 0.01
}
},
// Step 4: Deposit swapped WETH back to Aave
{
type: '/instructions/build',
data: {
functionSignature: 'function approve(address spender, uint256 amount)',
args: [
aaveV3Pool,
{
type: 'runtimeErc20Balance',
tokenAddress: WETH
}
],
to: WETH,
chainId: 1
}
},
{
type: '/instructions/intent-simple',
data: {
srcToken: WETH,
dstToken: aWETH,
srcChainId: 1,
dstChainId: 1,
amount: {
type: 'runtimeErc20Balance',
tokenAddress: WETH
},
slippage: 0.001
}
}
]
})
});