Skip to main content
@eco-incorp/sauce/actions lowers routing intents into Sauce programs and carries the AMM and bridge action primitives.
This page covers actions/dist/megas-swap.d.ts.
Generated from the type declarations shipped in @eco-incorp/sauce 0.99.4. Each entry shows the package authors’ JSDoc and declaration for this SDK version. For runtime compatibility and deployed addresses, see architecture and deployments.

megasSwapToSauce

Function · actions/dist/megas-swap.d.ts

megasSwapToSauceSource

Function · actions/dist/megas-swap.d.ts Emit the SauceScript for a greedy split-routing across candidates. Declared functions: quote_i(amount) One per candidate; invokes the protocol quoter with a runtime amount. quote_any(idx, amount) if/else dispatch to the matching quote_i. swap_any(idx, amount) Same dispatch, but executing the swap. main() The three passes below. Main algorithm (all three passes are real for loops - the per-candidate state lives in transient storage keyed by i):
  1. Init: for i in 0..N-1 { marg[i] = quote_any(i, bucket); } used[i] and total[i] default to 0 (TLOAD of untouched keys).
  2. Greedy: for iter in 0..n-1 { for i in 0..N-1 argmax → (bestMarg, bestIdx); used[bestIdx] += 1; total[bestIdx] += marg[bestIdx]; // cached, no call marg[bestIdx] = quote_any(bestIdx, (used[bestIdx]+1)*bucket)
    • total[bestIdx]; }
  3. Execute: for i in 0..N-1 if (used[i] > 0) swap_any(i, used[i]*bucket);
SIZE, CHANGED: the retired compiler kept every main-level pass a fixed-size loop, so the program was O(N). The Rust compiler’s constant folder UNROLLS a loop whose bound it knows, and N/n are compile-time constants here, so the emitted main is O(N + n·N) instructions. Behaviour is identical; only the byte count grows. Reach for a runtime bound if that ever matters. Requirements:
  • n >= 1. n=1 reduces to “pick the single best pool at full size”.
  • Every candidate’s quote must expose toSauceDynamic (fixed amount offset).
  • Swap builders must accept a runtime amountIn expression; UniswapV4 does not and will embed a stale compile-time amount.

megasUsdcUsdtSwapToSauce

Function · actions/dist/megas-swap.d.ts Pre-configured greedy split router for USDC → USDT on Ethereum mainnet. Candidates (all pre-populated, caller never picks addresses or pool IDs):
  • UniswapV3 at 1 bps (pool 0x38…)
  • UniswapV3 at 5 bps (pool 0x7858…)
  • Curve stableswap 3pool (DAI/USDC/USDT, indices 1→2)
  • Uniswap V2 router via [USDC, USDT] pair
The returned bytecode is self-contained and can be fed straight into Sauce.cook(bytes[]): it approves all 3 spenders for amountIn, runs the split-swap loop for n buckets, and sends the USDT output to recipient. Candidates whose pools are thin (UniV3 5 bps, shallow UniV2 pair) are still included - the greedy algorithm handles them by never routing buckets that direction. That costs N + n extra quoter CALLs worth of gas; drop them manually if you want to save. Balancer V2 is NOT a candidate: its only quote is queryBatchSwap, which mutates state and reverts to return, so it cannot be called on-chain at all.

MegasSwapOpts

Interface · actions/dist/megas-swap.d.ts