4. Plan the transactions
planCandidateExecution in @gibs/bridge-sdk/execution turns a served route into an ordered list of PlannedTx, one entry per transaction:
What the plan guarantees:
- Approvals are exact. The plan approves only the amount a transaction spends. It skips an approval that the current allowance covers. It resets a short, non-zero allowance to zero first.
- Spenders are checked. The plan approves only these spenders: the omnibridge mediator and the PulseX router from the package configuration, the LI.FI Diamond (with the LI.FI execution guard), and the Relay depository (
relayDepositoryByChainId). The plan refuses a quote that names any other spender or deposit target. - Only live quotes are signed. An aggregator section needs the live quote asked for your wallet, in
sections[i].aggregator. The route's own display quote is never signed. Without a live quote, the plan refuses withlive-quote-required. - Deposits match the request amount. The LI.FI guard checks the decoded swap amount. Relay must call
depositNativeordepositErc20with the requested token, value and amount. NEAR Intents must pay exactly the requested amount to the quote's own deposit address. The plan refuses a quote that disagrees with the request, withamount-mismatchorrecipient-mismatch. - Delivery is your explicit choice. Each crossing takes
delivery: { shouldDeliver: false }or{ shouldDeliver: true, fee }. There is no default.
Plan one section at a time
A route with two sections has a crossing, and then something on the far chain. The second section must spend what actually arrived, not what the search predicted. So plan each section when it is about to run:
- Pass
firstSectionIndex. Thensections[0]plans that section. Refusal indices and delivery indices stay absolute. - Plan section 1 after section 0's crossing arrived, with the amount that arrived. Every check above still applies to the later section.
A fresh swap floor
A PulseX section takes swap.quotedAmountOut, a fresh quote of its output. The slippage floor then comes from this quote, not from the search-time figure. readPulseXSectionQuote({ hop, amountIn, client }) reads it along the exact path the swap signs, on the hop's own router. Pass a fresh swap.deadline too.
The live quote
fetchLiveSectionQuote in @gibs/quotes/search builds the request from the section itself, and asks the section's own provider. It returns { quote, request }, which is exactly sections[i].aggregator.
- It handles three shapes: a direct last section, a section that another section follows (it lands in your own wallet), and a section that fuses with an omnibridge entry.
- For the fused shape, it reads the token mapping through your
clientForChain. It shrinks the entry amount when the cost of the entry call would make the spend exceedamountIn. It asks at most three times. It never returns a quote that spends more thanamountIn. - It takes your
fetch,keys(lifiApiKey,relayApiKey,nearIntentsApiKey, each sent only as its own header),attribution,lifiApiOriginandsignal.
fetchLiveQuote is the lower-level call: one provider, and one ConsolidatedQuoteRequest you built yourself. Both calls send through the same wire guard as the search. No request that names PulseChain, and no request that carries a key outside a header, ever leaves.