Auto-routed multi-source execution โ splits across protocols for maximum capacity and reliability.
What is executeSmart?
When you call execute() or executeLocal(), VAEA picks one protocol. But what if Marginfi has 50K SOL and Kamino has 80K SOL, and you need 100K? executeSmart() automatically evaluates capacity across all sources and routes your request optimally.
typescript
// Standard โ fails if single source < 100K
await flash.execute({ token: 'SOL', amount: 100_000 }); // โ INSUFFICIENT_LIQUIDITY
// Smart โ auto-splits across protocols
await flash.executeSmart({ token: 'SOL', amount: 100_000 }); // โ splits 50K Marginfi + 50K Kamino
How It Works
text
executeSmart({ token: 'SOL', amount: 100_000 })
โ
1. Query /v1/capacity โ get available amounts per source
โ Marginfi: 50,000 SOL
โ Kamino: 80,000 SOL
โ Jupiter Lend: 35,000 SOL
โ
2. Route optimizer:
โ Need: 100,000 SOL
โ Plan: 50K from Marginfi (cheapest) + 50K from Kamino
โ
3. Build nested sandwich:
begin_flash(SOL, 50K, marginfi)
begin_flash(SOL, 50K, kamino)
[your instructions]
end_flash(SOL, kamino)
end_flash(SOL, marginfi)
โ
4. Single atomic TX โ all or nothing
Code Examples
const sig = await flash.executeSmart({
token: 'SOL',
amount: 100_000,
onFunds: async (ixs) => {
ixs.push(myLargeArbInstruction);
return ixs;
},
}, {
maxSources: 3, // max protocols to split across
priorityMicroLamports: 5000,
});
console.log('Executed:', sig);
executeSmart() vs execute()
execute()
executeSmart()
Sources
1 protocol
1-3 protocols
Max capacity
Single pool limit
Aggregate across all pools
TX size
Smaller
Larger (nested sandwich)
CU cost
~25K
~25K per source
Use case
Standard borrows
Large borrows, max capacity
๐ก Tip
Use executeSmart() when your borrow amount might exceed the capacity of a single lending protocol. For standard amounts, execute() is simpler and uses less CU.