import { createLooprSDK } from '@odysseyfi/loopr-sdk'
import { createPublicClient, createWalletClient, custom, http } from 'viem'
import { mainnet } from 'viem/chains'
const loopr = createLooprSDK({ partnerId: 'your-partner-id' })
// 1. Discover strategies (filtered by your partner registration scope).
const strategies = await loopr.strategies.list({ chainId: mainnet.id })
const strategy = strategies[0]
// 2. Quote — `quote.open` is user-agnostic; the strategy supplies chainId,
// strategyId, depositToken, and borrowToken.
const { quote, expiresAt } = await strategy.quote.open({
amount: 1_000_000_000n, // 1000 of strategy.collaterals.asset (e.g. USDC)
leverage: 3,
slippage: 0.01,
})
// 3. Build the unsigned steps. Same shape as the quote, plus build-only
// knobs (`approvalMode`, optional `tokenIn` for zap-ins, etc.).
const { steps } = await strategy.build.open({
owner: '0xYourUserEOA...',
amount: 1_000_000_000n,
leverage: 3,
slippage: 0.01,
approvalMode: 'max',
})
// 4. Execute sequentially with the user's wallet. `waitForReceipt: true`
// requires a public client so the SDK can poll for confirmations.
const wallet = createWalletClient({
account: '0xYourUserEOA...',
chain: mainnet,
transport: custom(window.ethereum),
})
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
})
const results = await loopr.executeAll(wallet, steps, {
publicClient,
waitForReceipt: true,
onStep: result => {
console.log(`step ${result.index} (${result.step.label}): ${result.hash}`)
},
})