Multi-Token Flash
Borrow multiple different tokens in a single atomic transaction. Essential for cross-token arbitrage strategies.
Transaction Pattern
Multi-token flash uses a nested sandwich โ borrows are stacked, then repaid in reverse order:
text
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Single Atomic Transaction โ
โ โ
โ IX 1: begin_flash(SOL, 1000) โ
โ IX 2: begin_flash(USDC, 50000) โ
โ โ
โ IX 3: your_arb_ix(SOL โ DEX_A) โ
โ IX 4: your_arb_ix(USDC โ DEX_B) โ
โ โ
โ IX 5: end_flash(USDC) โ
โ IX 6: end_flash(SOL) โ
โ โ
โ All or nothing โ atomic execution โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Code Examples
const sig = await flash.borrowMulti({
loans: [
{ token: 'SOL', amount: 1000 },
{ token: 'USDC', amount: 50000 },
],
onFunds: async (ixs) => {
ixs.push(arbSolIx);
ixs.push(arbUsdcIx);
return ixs;
},
});
PDA Isolation
Each token gets its own PDA โ ["flash", payer, token_mint]. This prevents cross-token collisions and allows independent routing for each borrow.
Limits
| Constraint | Value | Reason |
|---|
| Max tokens per TX | 4 | Transaction size limit (1232 bytes) |
| Each token independently routed | โ
| Each uses its own source/fallback |
| Partial repay | โ All or nothing | Atomicity guarantee |
๐ก Tip
Keep multi-token borrows to 2-3 tokens max. Each borrow adds ~200 bytes and ~5,000 CU to the transaction.