@gibs/bridge-sdk 1.19.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/abis.js +0 -2
  2. package/dist/bridge-limits.js +0 -38
  3. package/dist/chain-info.js +0 -116
  4. package/dist/chain-names.js +0 -151
  5. package/dist/chains.js +0 -198
  6. package/dist/cjs/abis.js +0 -2
  7. package/dist/cjs/bridge-limits.js +0 -38
  8. package/dist/cjs/chain-info.js +0 -116
  9. package/dist/cjs/chain-names.js +0 -151
  10. package/dist/cjs/chains.js +0 -198
  11. package/dist/cjs/claims.js +0 -60
  12. package/dist/cjs/config.js +1 -208
  13. package/dist/cjs/consolidated-quote.js +0 -465
  14. package/dist/cjs/destination-calldata.js +0 -71
  15. package/dist/cjs/ecosystems.js +0 -183
  16. package/dist/cjs/execution.js +0 -92
  17. package/dist/cjs/fee-type.js +0 -1
  18. package/dist/cjs/hyperliquid-execution.js +0 -98
  19. package/dist/cjs/image-links.js +0 -108
  20. package/dist/cjs/lifi-execution-guard.js +65 -172
  21. package/dist/cjs/near-intents-conformance.js +0 -110
  22. package/dist/cjs/near-intents-route.js +0 -149
  23. package/dist/cjs/near-intents.js +0 -562
  24. package/dist/cjs/origin-deposit.js +0 -56
  25. package/dist/cjs/pre-quote.js +0 -80
  26. package/dist/cjs/prices.js +0 -113
  27. package/dist/cjs/providers.js +0 -83
  28. package/dist/cjs/quote-fees.js +0 -80
  29. package/dist/cjs/referral.js +0 -75
  30. package/dist/cjs/relay-currencies.js +0 -31
  31. package/dist/cjs/relay-depository.js +52 -77
  32. package/dist/cjs/relay-quote.js +0 -394
  33. package/dist/cjs/route-steps.js +0 -100
  34. package/dist/cjs/routing/amounts.js +0 -83
  35. package/dist/cjs/routing/candidate-route.js +0 -73
  36. package/dist/cjs/routing/candidate.js +0 -46
  37. package/dist/cjs/routing/carrier-provider-key.js +0 -27
  38. package/dist/cjs/routing/carriers/omnibridge.js +0 -120
  39. package/dist/cjs/routing/carriers/pulsex-paths.js +0 -57
  40. package/dist/cjs/routing/carriers/pulsex-split.js +0 -92
  41. package/dist/cjs/routing/carriers/pulsex.js +0 -279
  42. package/dist/cjs/routing/carriers/wrap.js +0 -57
  43. package/dist/cjs/routing/composed-route-quality.js +0 -95
  44. package/dist/cjs/routing/entry-chain-anchor.js +0 -27
  45. package/dist/cjs/routing/format.js +0 -50
  46. package/dist/cjs/routing/index.js +0 -28
  47. package/dist/cjs/routing/producers.js +0 -854
  48. package/dist/cjs/routing/providers.js +0 -27
  49. package/dist/cjs/routing/search/compose.js +0 -56
  50. package/dist/cjs/routing/search/graph.js +0 -364
  51. package/dist/cjs/routing/search/plan-route-data.js +0 -508
  52. package/dist/cjs/routing/search/score.js +0 -344
  53. package/dist/cjs/routing/swap-transactions.js +0 -74
  54. package/dist/cjs/routing/usd-value.js +0 -12
  55. package/dist/cjs/settings.js +1 -456
  56. package/dist/cjs/swap-venues.js +0 -17
  57. package/dist/cjs/ton-connect.js +0 -82
  58. package/dist/cjs/ton-execution.js +0 -6
  59. package/dist/cjs/ton.js +0 -42
  60. package/dist/cjs/tron-execution.js +0 -145
  61. package/dist/claims.js +0 -60
  62. package/dist/config.js +1 -211
  63. package/dist/consolidated-quote.js +0 -465
  64. package/dist/destination-calldata.js +0 -71
  65. package/dist/ecosystems.js +0 -183
  66. package/dist/execution.js +0 -92
  67. package/dist/fee-type.js +0 -2
  68. package/dist/hyperliquid-execution.js +0 -98
  69. package/dist/image-links.js +0 -108
  70. package/dist/lifi-execution-guard.js +65 -172
  71. package/dist/near-intents-conformance.js +0 -110
  72. package/dist/near-intents-route.js +0 -149
  73. package/dist/near-intents.js +0 -562
  74. package/dist/origin-deposit.js +0 -56
  75. package/dist/pre-quote.js +0 -80
  76. package/dist/prices.js +0 -113
  77. package/dist/providers.js +0 -83
  78. package/dist/quote-fees.js +0 -80
  79. package/dist/referral.js +0 -75
  80. package/dist/relay-currencies.js +0 -31
  81. package/dist/relay-depository.js +52 -77
  82. package/dist/relay-quote.js +0 -394
  83. package/dist/route-steps.js +0 -100
  84. package/dist/routing/amounts.js +0 -83
  85. package/dist/routing/candidate-route.js +0 -73
  86. package/dist/routing/candidate.js +0 -46
  87. package/dist/routing/carrier-provider-key.js +0 -27
  88. package/dist/routing/carriers/omnibridge.js +0 -120
  89. package/dist/routing/carriers/pulsex-paths.js +0 -57
  90. package/dist/routing/carriers/pulsex-split.js +0 -92
  91. package/dist/routing/carriers/pulsex.js +0 -279
  92. package/dist/routing/carriers/wrap.js +0 -57
  93. package/dist/routing/composed-route-quality.js +0 -95
  94. package/dist/routing/entry-chain-anchor.js +0 -27
  95. package/dist/routing/format.js +0 -50
  96. package/dist/routing/index.js +0 -28
  97. package/dist/routing/producers.js +0 -854
  98. package/dist/routing/providers.js +0 -27
  99. package/dist/routing/search/compose.js +0 -56
  100. package/dist/routing/search/graph.js +0 -364
  101. package/dist/routing/search/plan-route-data.js +0 -508
  102. package/dist/routing/search/score.js +0 -344
  103. package/dist/routing/swap-transactions.js +0 -74
  104. package/dist/routing/usd-value.js +0 -12
  105. package/dist/settings.js +1 -456
  106. package/dist/swap-venues.js +0 -17
  107. package/dist/ton-connect.js +0 -82
  108. package/dist/ton-execution.js +0 -6
  109. package/dist/ton.js +0 -42
  110. package/dist/tron-execution.js +0 -145
  111. package/package.json +3 -3
@@ -41,78 +41,10 @@ const carrier_provider_key_js_1 = require("../carrier-provider-key.js");
41
41
  const near_intents_route_js_1 = require("../../near-intents-route.js");
42
42
  const producers_js_1 = require("../producers.js");
43
43
  const graph_js_1 = require("./graph.js");
44
- /**
45
- * PHASE 1 — turns a priced {@link RoutePlan} into the SAME `RouteData` /
46
- * `RouteCandidate` / `RouteScoreInputs` shapes today's four hand-written
47
- * producers emit: {@link buildNearIntentsTwoStepRouteData} (`../../near-intents-route.js`),
48
- * {@link buildConversionRouteData}, {@link buildOutboundRouteData} and
49
- * {@link buildDirectCrossingCandidate} (paired with `buildCandidateRouteData`)
50
- * — all in `../producers.js` and `../candidate.js`. See the route-search
51
- * design's section 6, "what it absorbs," and this module's own tests
52
- * (`plan-route-data.test.ts`) for the parity checks against each of the four.
53
- *
54
- * WHAT THIS MODULE DOES NOT DO: PRICE A PLAN. Every existing builder prices
55
- * a section from carrier-specific knowledge this module has no access to — a
56
- * bridge's own fee-manager rate (`crossingCost` in `../producers.js`), a
57
- * PulseX swap's estimate (`buildPulseXSwapEstimateData`), or an aggregator's
58
- * own paid/delivered spread (`candidatePaidUsd` / `candidateDeliveredUsd`,
59
- * both reused here rather than restated). A `RoutePlan` (`./graph.js`) names
60
- * the STRUCTURE of a path and a base-unit delivered amount per hop; it
61
- * carries no United States dollar figure at all. So every dollar figure this
62
- * module places on a `RouteData` — a section's fee, a section's landing
63
- * value, the route's total cost — is a CALLER-SUPPLIED input
64
- * ({@link PlanSectionPricing}), never a formula computed here. This mirrors
65
- * `RouteScoreInputs`' own doc in `score.ts`: "the caller is responsible for
66
- * turning a priced RoutePlan into these fields."
67
- *
68
- * WHAT THIS MODULE DOES DO: compose the STRUCTURE — which section a hop
69
- * belongs to, whether that section is deferred, what it is labelled, what
70
- * its hops are titled, and what its token flow is — directly from the
71
- * plan's graph shape, using exactly the same conventions today's four
72
- * builders use. Where those four builders DISAGREE with each other (and two
73
- * of them genuinely do — see `hopIsAutomatic` below), this module picks ONE
74
- * rule and documents which existing convention it follows and which it
75
- * knowingly departs from, per this project's "surface conflicts, don't
76
- * average them" rule. Every departure is named in this module's tests.
77
- */
78
- // ---------------------------------------------------------------------------
79
- // Carrier classification
80
- // ---------------------------------------------------------------------------
81
- /**
82
- * Whether `carrier` is an omnibridge crossing (`'pulsechain'` or
83
- * `'tokensex'`) — a genuine type predicate, not a plain boolean, so every
84
- * call site narrows `carrier` from the wide {@link HopCarrier} union down to
85
- * {@link Provider}. `providerDisplayName` (`../producers.js`) is total only
86
- * over `Provider`'s two keys and falls back to the generic string
87
- * "Omnibridge" for anything else; a plain-boolean guard left the call sites
88
- * below typed as `HopCarrier` and accepting a bare `string`, which is the
89
- * SAME shape of fault that let a NEAR Intents leg display as "Omnibridge"
90
- * (see `plan-route-data.test.ts`'s now-fixed "documented divergence" case).
91
- * Narrowing here makes that class of mistake fail to compile instead of
92
- * silently mis-naming a hop.
93
- */
94
44
  const isBridgeCarrier = (carrier) => carrier === 'pulsechain' || carrier === 'tokensex';
95
- /** Whether `carrier` is a consolidated-route aggregator (LI.FI, Relay, NEAR Intents). */
96
45
  const isAggregatorCarrier = (carrier) => carrier === 'lifi' || carrier === 'relay' || carrier === 'near-intents';
97
- /** Whether a hop lands on PulseChain — the signal every label/title rule below keys on. */
98
46
  const hopLandsOnPulsechain = (hop) => hop.edge.to.chainId === producers_js_1.pulsechainChainId;
99
- /** Whether `hopIndex` is the plan's LAST hop overall — a completing leg, not a starting one. */
100
47
  const isFinalHopOfPlan = (hopIndex, plan) => hopIndex === plan.hops.length - 1;
101
- /**
102
- * Resolves a node's display token and asserts its `decimals` agree with the
103
- * NODE's own `decimals` — the field `graph.ts` added specifically so a hop
104
- * touching two independently-resolved mentions of the same token can be
105
- * checked against each other without a second lookup (see `AssetNode`'s own
106
- * doc). A name is a hypothesis, not evidence: `resolveToken` is a caller
107
- * hook this module does not control, and trusting its `decimals` blind would
108
- * silently misplace a decimal point in a real amount exactly the way
109
- * `compose.ts`'s `decimals-mismatch` refusal exists to prevent one hop
110
- * downstream. The NODE's decimals wins as the returned, asserted value.
111
- *
112
- * @param node - the graph node to resolve
113
- * @param resolveToken - resolves the node to its full display token
114
- * @returns the resolved token and the node's own, asserted decimals
115
- */
116
48
  const resolveNodeWithAssertedDecimals = (node, resolveToken) => {
117
49
  const token = resolveToken(node);
118
50
  if (token.decimals !== node.decimals) {
@@ -121,19 +53,6 @@ const resolveNodeWithAssertedDecimals = (node, resolveToken) => {
121
53
  }
122
54
  return { token, decimals: node.decimals };
123
55
  };
124
- /**
125
- * Builds the raw `RouteTokenRef` for one graph node, resolving its logo the
126
- * same way every existing builder's own token-node helper does
127
- * (`tokenNode` in `../../near-intents-route.js`, the inline node literals in
128
- * `buildCandidateRouteData`): the token's own image first, the chain badge
129
- * from `imageLinks.networkOrPseudo` second — which is what makes a
130
- * pay-by-hand origin's invented chain id resolve to a real badge instead of
131
- * a 404ing numeric lookup.
132
- *
133
- * @param node - the graph node to render
134
- * @param resolveToken - resolves the node to its full display token
135
- * @returns the raw token reference
136
- */
137
56
  const toRouteTokenRef = (node, resolveToken) => {
138
57
  const { token, decimals } = resolveNodeWithAssertedDecimals(node, resolveToken);
139
58
  return {
@@ -141,34 +60,10 @@ const toRouteTokenRef = (node, resolveToken) => {
141
60
  address: token.address,
142
61
  chainId: node.chainId,
143
62
  decimals,
144
- // NOT `image`, which checksums the address as an Ethereum one and throws
145
- // for anything else. A plan can start on a pay-by-hand chain (Zcash's
146
- // native sentinel is `t1Hsc…`), and that throw blanked the whole bridge
147
- // form the moment such a route was served. A token's own logo still wins;
148
- // an address no picture can be asked for draws its chain's mark.
149
63
  logoUri: token.logoURI ? token.logoURI : imageLinks.tokenImageOrChainFallback(token),
150
64
  chainLogoUri: imageLinks.networkOrPseudo(node.chainId),
151
65
  };
152
66
  };
153
- /**
154
- * The distinct stops a signature group's hops walk: the origin, then every
155
- * node a hop lands on, collapsing a hop that lands back on the node the
156
- * flow already holds — generalizing `deriveTokenFlow` in `../producers.js`
157
- * from RAW ADDRESS-STRING comparison (`isSameTokenRef`) to
158
- * {@link assetNodeKey}, which is already the collision-free, casing-normalized
159
- * identity every other part of the graph model uses.
160
- *
161
- * THIS IS WHERE THE RECENTLY-FIXED BUG STAYS FIXED. `deriveTokenFlow` used to
162
- * leave a route showing only its origin when a candidate itemized no hops at
163
- * all — see `../producers.js`'s own note on the defect. A `RoutePlan` always
164
- * carries at least one hop for a real crossing, and this walk always ends on
165
- * that hop's `to` node, so the flow can never stop short of the plan's own
166
- * declared destination for its group.
167
- *
168
- * @param hops - one signature group's hops, first to last
169
- * @param resolveToken - resolves a graph node to its full display token
170
- * @returns the group's token flow, origin first
171
- */
172
67
  const buildGroupTokenFlow = (hops, resolveToken) => {
173
68
  const originNode = hops[0].edge.from;
174
69
  const nodeFlow = hops.reduce((flow, hop) => {
@@ -180,51 +75,9 @@ const buildGroupTokenFlow = (hops, resolveToken) => {
180
75
  }, [originNode]);
181
76
  return nodeFlow.map((node) => toRouteTokenRef(node, resolveToken));
182
77
  };
183
- // ---------------------------------------------------------------------------
184
- // Section-level labelling
185
- // ---------------------------------------------------------------------------
186
- /**
187
- * A signature group's own hop-index list, resolved to its hops.
188
- *
189
- * @param group - one entry of `plan.signatures` — hop indices into `plan.hops`
190
- * @param plan - the plan those indices are drawn from
191
- * @returns the group's hops, first to last
192
- */
193
78
  const groupHops = (group, plan) => group.map((hopIndex) => plan.hops[hopIndex]);
194
- /**
195
- * Whether every hop of a group is carried by PulseX — the standalone-swap
196
- * shape `buildPulseXSwapSectionData` draws, labelled "Swap on PulseX"
197
- * regardless of the group's position in the plan.
198
- */
199
79
  const isPulseXOnlyGroup = (hops) => hops.every((hop) => hop.edge.carrier === 'PulseX');
200
- /** Whether a group's LAST hop is the omnibridge crossing — the fact that decides "Bridge to X". */
201
80
  const groupEndsWithBridgeHop = (hops) => isBridgeCarrier(hops[hops.length - 1].edge.carrier);
202
- /**
203
- * A signature section's label, generalizing the four distinct conventions
204
- * found across today's producers into one rule:
205
- *
206
- * - **"Swap on PulseX"** — every hop in the group is carried by PulseX.
207
- * Matches `buildPulseXSwapSectionData`'s hard-coded label.
208
- * - **"Bridge to {X}"** — the WHOLE plan is one signature (matches
209
- * `buildCandidateRouteData`, which always uses this label for its one
210
- * section, omnibridge leg or not), OR the group's last hop IS the
211
- * omnibridge crossing (matches `buildNearIntentsTwoStepRouteData`'s
212
- * second section AND `buildOutboundRouteData`'s first section).
213
- * - **"Complete at {X}"** — the group is the plan's LAST signature and does
214
- * NOT end on a bridge hop. Matches `buildOutboundRouteData`'s second
215
- * section, in BOTH its shapes (the entry-chain swap and the onward
216
- * aggregator hop) — the section label names where the journey finishes
217
- * regardless of which service carries the last leg.
218
- * - **"Swap on {X}"** — a group of the "Send to" shape whose first hop starts
219
- * on the chain its last hop ends on: nothing is sent anywhere.
220
- * - **"Send to {X}"** — every other case: a non-final, non-bridge-ending
221
- * group. Matches `buildNearIntentsTwoStepRouteData`'s first section.
222
- *
223
- * @param group - the group's hop indices
224
- * @param groupIndex - the group's position in `plan.signatures`
225
- * @param plan - the plan the group belongs to
226
- * @returns the section's label
227
- */
228
81
  const sectionLabel = (group, groupIndex, plan) => {
229
82
  const hops = groupHops(group, plan);
230
83
  if (isPulseXOnlyGroup(hops))
@@ -240,29 +93,6 @@ const sectionLabel = (group, groupIndex, plan) => {
240
93
  }
241
94
  return (0, near_intents_route_js_1.sendOrSwapLabel)(hops[0].edge.from.chainId, destinationChainId);
242
95
  };
243
- // ---------------------------------------------------------------------------
244
- // Hop-level rendering
245
- // ---------------------------------------------------------------------------
246
- /**
247
- * A hop's display provider name.
248
- *
249
- * A bridge carrier resolves through {@link providerDisplayName} (the same
250
- * "PulseChain Bridge" / "Tokens Express Bridge" table every builder reads).
251
- * PulseX is named directly. An aggregator carrier resolves through the
252
- * PROVIDER REGISTRY's own label (`providerById(id).label`) — DELIBERATELY,
253
- * not through `providerDisplayName`, because that function's table only
254
- * ever held the two omnibridge providers. `buildNearIntentsTwoStepRouteData`
255
- * calls `providerDisplayName(candidate.quote.provider)` for its aggregator
256
- * hop today, and `'near-intents'` is not a key in that table, so it silently
257
- * falls back to the generic string `'Omnibridge'` — naming NEAR Intents
258
- * after the bridge it is not. That reads as an unintentional defect in the
259
- * existing code, not a convention worth reproducing; this function returns
260
- * `'NEAR Intents'` instead. See this module's test file and the report back
261
- * to the owner for the specific call-out.
262
- *
263
- * @param carrier - the hop's carrier
264
- * @returns the display name for that carrier
265
- */
266
96
  const hopProviderName = (carrier) => {
267
97
  if (isBridgeCarrier(carrier))
268
98
  return (0, producers_js_1.providerDisplayName)(carrier);
@@ -270,39 +100,8 @@ const hopProviderName = (carrier) => {
270
100
  return 'PulseX';
271
101
  if ((0, carrier_provider_key_js_1.carrierStepKind)(carrier) === 'wrap')
272
102
  return 'Wrap';
273
- // TOTAL OVER EVERY CARRIER. The engine plans hops for carriers the provider
274
- // registry does not hold (a local wrap, a host's own plug-in). Casting such
275
- // an id to a provider id and asking the throwing lookup crashed the whole
276
- // bridge form the first time a plan began with a wrap. A carrier with no
277
- // registered label is named by its own id.
278
103
  return (0, providers_js_1.findProviderById)(carrier)?.label ?? carrier;
279
104
  };
280
- /**
281
- * A hop's title, generalizing the title conventions of every existing
282
- * builder:
283
- *
284
- * - a bridge hop landing on PulseChain → `"Bridge to PulseChain"` (matches
285
- * `buildCandidateRouteData`'s omnibridge hop and
286
- * `buildNearIntentsTwoStepRouteData`'s crossing hop);
287
- * - a bridge hop landing elsewhere (leaving PulseChain) →
288
- * `providerDisplayName(carrier)`, e.g. `"PulseChain Bridge"` (matches
289
- * `buildOutboundRouteData`'s bridge hop exactly);
290
- * - a PulseX hop → `"Swap to {toSymbol}"` (matches `buildPulseXSwapSectionData`);
291
- * - an aggregator hop that is the plan's FINAL hop (nothing follows it,
292
- * so this signature is the one that COMPLETES the journey) →
293
- * `"Bridge to {toChainName}"` (matches `buildOutboundRouteData`'s onward
294
- * hop, which names the chain it finishes on even though an aggregator,
295
- * not the omnibridge, carries it);
296
- * - any other aggregator hop (something follows it) → `"Send to {toChainName}"`,
297
- * or `"Swap on {chainName}"` when the hop starts and ends on one chain
298
- * (matches `buildNearIntentsTwoStepRouteData`'s aggregator hop).
299
- *
300
- * @param hop - the hop to title
301
- * @param hopIndex - the hop's index into `plan.hops`
302
- * @param plan - the plan the hop belongs to
303
- * @param resolveToken - resolves a graph node to its full display token
304
- * @returns the hop's title
305
- */
306
105
  const hopTitle = (hop, hopIndex, plan, resolveToken) => {
307
106
  const carrier = hop.edge.carrier;
308
107
  if (isBridgeCarrier(carrier)) {
@@ -318,28 +117,6 @@ const hopTitle = (hop, hopIndex, plan, resolveToken) => {
318
117
  }
319
118
  return (0, near_intents_route_js_1.sendOrSwapLabel)(hop.edge.from.chainId, hop.edge.to.chainId);
320
119
  };
321
- /**
322
- * A hop's conversion subtitle.
323
- *
324
- * The source data has two conventions for this string: the candidate-based
325
- * builders (`buildCandidateRouteData`'s omnibridge hop,
326
- * `buildNearIntentsTwoStepRouteData`'s both hops) write an ARROW-ONLY clause
327
- * (`"→ USDC"`), leaving the origin side implicit; the settings-based
328
- * builders (`buildOutboundRouteData`, `buildPulseXSwapSectionData`) write
329
- * the FULL two-sided clause (`"PLS → USDC"`). Both are correct prose for
330
- * their own hop; this function reproduces BOTH conventions rather than
331
- * picking one, keyed on the exact same signal {@link hopTitle} already uses
332
- * to distinguish a starting/intermediate leg from a completing one: arrow-only
333
- * for a bridge hop landing on PulseChain or an aggregator hop that is NOT the
334
- * plan's final hop (there is more journey to draw, so the origin side is
335
- * already on screen from the previous hop); full two-sided otherwise.
336
- *
337
- * @param hop - the hop to describe
338
- * @param hopIndex - the hop's index into `plan.hops`
339
- * @param plan - the plan the hop belongs to
340
- * @param resolveToken - resolves a graph node to its full display token
341
- * @returns the hop's conversion subtitle
342
- */
343
120
  const hopConversion = (hop, hopIndex, plan, resolveToken) => {
344
121
  const carrier = hop.edge.carrier;
345
122
  const toSymbol = resolveToken(hop.edge.to).symbol;
@@ -350,51 +127,10 @@ const hopConversion = (hop, hopIndex, plan, resolveToken) => {
350
127
  const fromSymbol = resolveToken(hop.edge.from).symbol;
351
128
  return `${fromSymbol} → ${toSymbol}`;
352
129
  };
353
- /**
354
- * Whether a hop runs AUTOMATICALLY inside a signature a PRECEDING hop
355
- * already signed — true exactly when the hop is not the first hop of its
356
- * own signature group, per `RouteHopData.automatic`'s own doc ("runs
357
- * automatically inside the SECTION's single signature").
358
- *
359
- * THIS MATCHES THREE OF THE FOUR TARGET SHAPES EXACTLY —
360
- * `buildCandidateRouteData` (an aggregator hop with index > 0 inside its
361
- * section, and the omnibridge hop only when an aggregator hop preceded it),
362
- * `buildNearIntentsTwoStepRouteData` (both of its hops are their own
363
- * section's first and only hop, so both are `false`), and
364
- * `buildPulseXSwapSectionData` (its one hop is always `false`, hard-coded
365
- * for the same reason).
366
- *
367
- * IT DOES NOT MATCH `buildOutboundRouteData`'s BRIDGE HOP, which hard-codes
368
- * `true` even though it is that section's own first and only hop — a SECOND,
369
- * DIFFERENT reading of "automatic" that describes the omnibridge's own
370
- * far-side auto-completion (no reader signature needed to FINISH the
371
- * crossing once signed) rather than whether the hop itself needed no
372
- * signature to START. `buildDirectRouteData` (a separate, non-plan family
373
- * this module does not otherwise touch) hard-codes the same reading. This
374
- * function follows the field's own documented meaning and the majority
375
- * convention (three of four builders) rather than that reading — see this
376
- * module's test file for the specific, deliberate divergence this produces
377
- * against `buildOutboundRouteData`'s bridge hop.
378
- *
379
- * @param hopIndex - the hop's index into `plan.hops`
380
- * @param plan - the plan the hop belongs to
381
- * @returns whether the hop is automatic
382
- */
383
130
  const hopIsAutomatic = (hopIndex, plan) => {
384
131
  const group = plan.signatures.find((candidateGroup) => candidateGroup.includes(hopIndex));
385
132
  return group !== undefined && group[0] !== hopIndex;
386
133
  };
387
- /**
388
- * Builds the raw `RouteHopData` for one planned hop.
389
- *
390
- * @param hop - the hop to render
391
- * @param hopIndex - the hop's index into `plan.hops`
392
- * @param plan - the plan the hop belongs to
393
- * @param resolveToken - resolves a graph node to its full display token
394
- * @param feeUsdValue - the hop's own share of its section's cost, or null
395
- * @param gas - the hop's gas split, or null when the producer states none
396
- * @returns the raw hop data
397
- */
398
134
  const toRouteHopData = (hop, hopIndex, plan, resolveToken, feeUsdValue, gas) => ({
399
135
  providerName: hopProviderName(hop.edge.carrier),
400
136
  providerKey: (0, carrier_provider_key_js_1.carrierProviderKey)(hop.edge.carrier),
@@ -403,23 +139,10 @@ const toRouteHopData = (hop, hopIndex, plan, resolveToken, feeUsdValue, gas) =>
403
139
  conversion: hopConversion(hop, hopIndex, plan, resolveToken),
404
140
  fromToken: toRouteTokenRef(hop.edge.from, resolveToken),
405
141
  toToken: toRouteTokenRef(hop.edge.to, resolveToken),
406
- // The per-hop dollar figure is a caller-supplied input (see this module's
407
- // head doc); the caller passes it in, never derived here.
408
142
  feeUsdValue,
409
143
  ...(gas === null ? {} : gas),
410
144
  automatic: hopIsAutomatic(hopIndex, plan),
411
145
  });
412
- /**
413
- * The per-hop shares a section's pricing names, checked against the group
414
- * they describe.
415
- *
416
- * @param pricing - the section's caller-supplied pricing
417
- * @param group - the signature group's hop indices
418
- * @param groupIndex - the group's index, for the error message
419
- * @returns one share per hop, null where none was given
420
- * @throws when the caller passed a share list of the wrong length — a share
421
- * matched to the wrong hop is a figure on the wrong leg
422
- */
423
146
  const groupHopFeeUsdValues = (pricing, group, groupIndex) => {
424
147
  const shares = pricing.hopFeeUsdValues;
425
148
  if (shares === undefined)
@@ -429,54 +152,14 @@ const groupHopFeeUsdValues = (pricing, group, groupIndex) => {
429
152
  }
430
153
  return shares;
431
154
  };
432
- // ---------------------------------------------------------------------------
433
- // Route-level derivations — candidate.ts's promised derivation, made real
434
- // ---------------------------------------------------------------------------
435
- /**
436
- * The plan's omnibridge provider, or null when the plan crosses no bridge
437
- * hop at all — exactly the derivation `RouteCandidate.plan`'s own TSDoc
438
- * (`../candidate.ts`) promises: "that same hop's `carrier`... the `to` node's
439
- * `chainId` of the plan's LAST hop whose carrier is `'pulsechain'` or
440
- * `'tokensex'`." Reading the LAST such hop, not the first, matters for a
441
- * plan with two bridge crossings (an outbound leg out of PulseChain followed
442
- * later by a separate inbound one) — not a shape any of today's four
443
- * builders draws, but one the general search can.
444
- *
445
- * @param plan - the plan to derive from
446
- * @returns the omnibridge provider, or null
447
- */
448
155
  const deriveOmnibridgeProviderFromPlan = (plan) => {
449
156
  const bridgeHop = [...plan.hops].reverse().find((hop) => isBridgeCarrier(hop.edge.carrier));
450
157
  if (bridgeHop === undefined)
451
158
  return null;
452
- // `Array.prototype.find`'s own predicate narrowing does not flow back out
453
- // of the callback into the found element's type — only `isBridgeCarrier`
454
- // called again, directly on the plain `carrier` binding, narrows it here.
455
- // Re-declaring the return type as the real `Provider | null` (rather than
456
- // the wide `string | null` this used to widen to) is what surfaces a
457
- // mismatch at the source the moment a caller narrows further downstream,
458
- // instead of a silent `string` riding all the way to `providerDisplayName`.
459
159
  const { carrier } = bridgeHop.edge;
460
160
  return isBridgeCarrier(carrier) ? carrier : null;
461
161
  };
462
162
  exports.deriveOmnibridgeProviderFromPlan = deriveOmnibridgeProviderFromPlan;
463
- /**
464
- * The plan's entry chain id — the chain the plan's FIRST hop lands on, when
465
- * that hop is carried by an aggregator (LI.FI, Relay or NEAR Intents); null
466
- * when the plan's first hop IS the omnibridge itself (a direct, same-chain
467
- * crossing — `buildDirectCrossingCandidate`'s shape) or is a PulseX swap.
468
- *
469
- * MATCHES `RouteCandidate.entryChainId`'S EXISTING MEANING throughout the
470
- * candidate-based builders — "the chain the omnibridge leg starts on" — for
471
- * every candidate that carries one, including a candidate whose aggregator
472
- * reaches its OWN destination with no further bridge hop at all (today's
473
- * `makeCandidate` test fixtures set `entryChainId` to the destination chain
474
- * in exactly that case, because it is still where the aggregator's own leg
475
- * lands).
476
- *
477
- * @param plan - the plan to derive from
478
- * @returns the entry chain id, or null for a direct crossing or a swap-only plan
479
- */
480
163
  const deriveEntryChainIdFromPlan = (plan) => {
481
164
  const firstHop = plan.hops[0];
482
165
  if (!firstHop)
@@ -484,45 +167,11 @@ const deriveEntryChainIdFromPlan = (plan) => {
484
167
  return isAggregatorCarrier(firstHop.edge.carrier) ? firstHop.edge.to.chainId : null;
485
168
  };
486
169
  exports.deriveEntryChainIdFromPlan = deriveEntryChainIdFromPlan;
487
- /**
488
- * The decimal chain ids every INTERMEDIATE hop of the plan passes through,
489
- * origin and destination excluded — `RouteData.viaChainIds`'s own contract.
490
- * Undefined (never an empty array) when the plan has nothing to report, per
491
- * that field's own "ABSENT... on any route with no intermediate chain" doc.
492
- *
493
- * @param plan - the plan to derive from
494
- * @returns the via chain ids in hop order, or undefined
495
- */
496
170
  const deriveViaChainIdsFromPlan = (plan) => {
497
171
  const intermediateChainIds = plan.hops.slice(0, -1).map((hop) => hop.edge.to.chainId);
498
172
  return intermediateChainIds.length > 0 ? intermediateChainIds : undefined;
499
173
  };
500
174
  exports.deriveViaChainIdsFromPlan = deriveViaChainIdsFromPlan;
501
- /**
502
- * The plan's `RouteKind`, per the route-search design's section 1: `'direct'`
503
- * when signature 1 IS the omnibridge crossing itself (no aggregator prefix —
504
- * `buildDirectCrossingCandidate`'s shape, and `buildOutboundRouteData`'s
505
- * shape), `'conversion'` when the LAST hop is a PulseX swap
506
- * (`buildConversionRouteData`'s shape), `'aggregated'` otherwise (an
507
- * aggregator carries signature 1, fused with a bridge hop or not —
508
- * `buildNearIntentsTwoStepRouteData`'s shape, and the general
509
- * aggregator-fused shape).
510
- *
511
- * DIVERGES FROM TODAY'S LITERAL OUTPUT FOR ONE CASE, DELIBERATELY: a
512
- * same-chain candidate built by `buildDirectCrossingCandidate` and rendered
513
- * through `buildCandidateRouteData` today always comes back `kind:
514
- * 'aggregated'`, because that builder hard-codes `'aggregated'`
515
- * unconditionally — an artifact of `RouteCandidate.entryChainId` being
516
- * non-nullable, so `buildCandidateRouteData` always assumes an
517
- * aggregator-entry shape even for a candidate with no aggregator leg at all.
518
- * This function instead answers `'direct'` for that exact plan, matching how
519
- * `buildDirectRouteData` (the OTHER, non-candidate 'direct' family) already
520
- * represents the identical real-world same-chain crossing. See this
521
- * module's test file for the specific case.
522
- *
523
- * @param plan - the plan to derive from
524
- * @returns the route's kind
525
- */
526
175
  const derivePlanKind = (plan) => {
527
176
  const lastHop = plan.hops[plan.hops.length - 1];
528
177
  if (lastHop && lastHop.edge.carrier === 'PulseX')
@@ -533,24 +182,6 @@ const derivePlanKind = (plan) => {
533
182
  return 'aggregated';
534
183
  };
535
184
  exports.derivePlanKind = derivePlanKind;
536
- /**
537
- * Narrows a plan's {@link HopCarrier} (a plain string, since `HopEdge.carrier`
538
- * moved off the closed `ProviderKey` union) down to `RouteData.headlineProviderKey`'s
539
- * own closed {@link ProviderKey} type, for the display/logo lookup tables that
540
- * type exists to protect (`resolveProviderLogoUri` / `resolveProviderDisplayName`
541
- * — see `ProviderKey`'s own doc in `../../providers.js`).
542
- *
543
- * A GIBS PLAN NEVER CARRIES ANYTHING ELSE. Every carrier a `RoutePlan` this
544
- * module renders can name is one gibs itself registered — the three built-in
545
- * aggregators, the omnibridge, PulseX, or a wrap step, which
546
- * {@link deriveHeadlineProviderKeyFromPlan} skips (`routing/carriers/`,
547
- * `packages/ui/src/lib/state/useRouteSearch.ts`) — so this throws rather than
548
- * guessing when it sees anything else: a plan naming an unrecognized carrier
549
- * is a bug in whatever built it, not a display gap to paper over silently.
550
- *
551
- * @param carrier - the plan's headline carrier
552
- * @returns the same value, typed as `ProviderKey`
553
- */
554
185
  const toHeadlineProviderKey = (carrier) => {
555
186
  if (isBridgeCarrier(carrier))
556
187
  return carrier;
@@ -560,49 +191,9 @@ const toHeadlineProviderKey = (carrier) => {
560
191
  return carrier;
561
192
  throw new Error(`toHeadlineProviderKey: unrecognized carrier "${carrier}"`);
562
193
  };
563
- /**
564
- * The plan's headline provider — the omnibridge crossing it out when it
565
- * crosses one, or whichever carrier performs signature 1 when it does not.
566
- * Matches every existing builder's own headline choice: the omnibridge when
567
- * present (`buildCandidateRouteData`, `buildNearIntentsTwoStepRouteData`,
568
- * `buildOutboundRouteData`), the aggregator's own key as the fallback
569
- * (`buildCandidateRouteData`'s no-omnibridge branch).
570
- *
571
- * @param plan - the plan to derive from
572
- * @returns the headline provider key
573
- */
574
194
  const deriveHeadlineProviderKeyFromPlan = (plan) => toHeadlineProviderKey((0, exports.deriveOmnibridgeProviderFromPlan)(plan) ?? firstHeadlineCarrier(plan));
575
195
  exports.deriveHeadlineProviderKeyFromPlan = deriveHeadlineProviderKeyFromPlan;
576
- /**
577
- * The carrier of the first hop that can headline a route. A `wrap` hop
578
- * (native coin to its wrapped token, or back) is a step inside a route, never
579
- * the route itself, so it is skipped. A plan made only of wraps headlines as
580
- * PulseX, the same key the same-chain swap builder gives that route
581
- * (`buildSameChainSwapRouteData`).
582
- *
583
- * @param plan - the plan to read
584
- * @returns the carrier to headline
585
- */
586
196
  const firstHeadlineCarrier = (plan) => plan.hops.find((hop) => hop.edge.carrier !== carrier_provider_key_js_1.WRAP_CARRIER_ID)?.edge.carrier ?? 'PulseX';
587
- /**
588
- * The anchor a two-signature plan leaves the reader holding between its
589
- * first and second groups — `RouteCandidate.plan`'s own TSDoc: "the anchor
590
- * the reader is left holding between signatures... taken from the first hop
591
- * of the second group." Reuses `describeDeferredCrossing`
592
- * (`../../near-intents-route.js`) rather than re-validating the same
593
- * "positive amount, resolved token" rule a second time.
594
- *
595
- * Null when the plan has only one signature group (there is no deferred
596
- * crossing to describe) or the plan is malformed (a signature group naming
597
- * hop indices the plan does not have).
598
- *
599
- * @param plan - the plan to derive from
600
- * @param resolveToken - resolves a graph node to its full display token
601
- * @param anchorUsdValue - the anchor's own carrier's valuation of the
602
- * landing, exactly as `DeferredCrossing.anchorUsdValue` expects — supplied
603
- * by the caller, since a plan carries no United States dollar figures.
604
- * @returns the deferred crossing, or null
605
- */
606
197
  const deriveDeferredCrossingFromPlan = (plan, resolveToken, anchorUsdValue) => {
607
198
  const secondGroup = plan.signatures[1];
608
199
  const firstGroup = plan.signatures[0];
@@ -623,26 +214,7 @@ const deriveDeferredCrossingFromPlan = (plan, resolveToken, anchorUsdValue) => {
623
214
  });
624
215
  };
625
216
  exports.deriveDeferredCrossingFromPlan = deriveDeferredCrossingFromPlan;
626
- /**
627
- * Whether `hop`'s own figure carries no value at all — an `EstimateBasis`
628
- * (`graph.ts`) of `'unpriced'`: a bare decimal rescale with nothing behind
629
- * it (see that type's own doc). {@link sectionLandingAmount} is what a
630
- * `true` result means for the section's (and the route's) headline figure:
631
- * it is left OUT of `amount` entirely, never shown at all.
632
- */
633
217
  const hopOutcomeIsUnpriced = (hop) => hop.outcome.kind === 'estimate' && hop.outcome.basis === 'unpriced';
634
- /**
635
- * What `hop` reports for `RouteLandingData.estimateBasis` /
636
- * `RouteOutputData.estimateBasis` (`../route-data.ts`): the hop's own
637
- * `EstimateBasis` string when it is a composed/probed figure, `null` for a
638
- * bound quote — and `null` for `'unpriced'` too, per that field's own doc
639
- * ("'unpriced' never reaches here"), since {@link sectionLandingAmount}
640
- * already leaves an unpriced hop's `amount` out entirely rather than
641
- * labelling it.
642
- *
643
- * @param hop - the hop to read
644
- * @returns the estimate basis to report, or null
645
- */
646
218
  const hopEstimateBasis = (hop) => {
647
219
  if (hop.outcome.kind !== 'estimate')
648
220
  return null;
@@ -650,17 +222,6 @@ const hopEstimateBasis = (hop) => {
650
222
  return null;
651
223
  return hop.outcome.basis;
652
224
  };
653
- /**
654
- * A section's landing amount: the caller's explicit override when given
655
- * ({@link PlanSectionPricing.landingAmountOverride}'s own doc), else `null`
656
- * when the section's last hop is `'unpriced'` (see {@link hopOutcomeIsUnpriced}
657
- * — a figure with no value behind it is never shown, marked or not), else
658
- * the hop's own composed delivered amount.
659
- *
660
- * @param pricing - the section's caller-supplied pricing
661
- * @param lastHop - the section's last hop
662
- * @returns the amount to land the section on, or null
663
- */
664
225
  const sectionLandingAmount = (pricing, lastHop) => {
665
226
  if ('landingAmountOverride' in pricing)
666
227
  return pricing.landingAmountOverride ?? null;
@@ -668,26 +229,6 @@ const sectionLandingAmount = (pricing, lastHop) => {
668
229
  return null;
669
230
  return lastHop.outcome.deliveredAmount;
670
231
  };
671
- /**
672
- * Turns a priced {@link RoutePlan} into a raw {@link RouteData} — one section
673
- * per signature group, `deferred` on every group after the first, each
674
- * section's hops and token flow drawn structurally from the plan, and the
675
- * dollar figures overlaid from `inputs.sections`. See this module's head doc
676
- * for why the dollar figures are caller-supplied rather than derived here.
677
- *
678
- * NEVER SHOWS AN UNPRICED HEADLINE FIGURE, AND MARKS EVERY OTHER ESTIMATE AS
679
- * ONE — PHASE 3. A section (and the route's own `output`) whose last hop is
680
- * grounded on `EstimateBasis` `'unpriced'` lands on `amount: null`, whatever
681
- * the caller's own pricing says, per {@link sectionLandingAmount}'s own doc.
682
- * Every OTHER estimate (`'probe-rate'`, `'priced-conversion'`) still shows
683
- * its figure, with `estimateBasis` set to that basis so a reader is never
684
- * shown a composed/probed number as if it were a confirmed quote — see
685
- * `RouteOutputData.estimateBasis`'s own doc (`../route-data.ts`) for the
686
- * full rule this reads off {@link hopEstimateBasis}.
687
- *
688
- * @param inputs - the plan, a token resolver, an id, and per-section pricing
689
- * @returns the raw route data
690
- */
691
232
  const buildRouteDataFromPlan = (inputs) => {
692
233
  const { plan, resolveToken, routeId, sections, totalCostUsdValue, netValueUsd, etaMinutes } = inputs;
693
234
  if (plan.hops.length === 0) {
@@ -759,26 +300,12 @@ const buildRouteDataFromPlan = (inputs) => {
759
300
  }),
760
301
  netValueUsd,
761
302
  etaMinutes,
762
- // The single legacy `viaChainId` a not-yet-migrated consumer may still
763
- // read (`RouteOption`, `journeyPlan.ts`'s current `pathKeyFor` — see the
764
- // route-search design's section 1) — the first intermediate chain, when
765
- // there is one. `buildOutboundRouteData` sets this to the chain its one
766
- // bridge hop lands on, which is exactly this plan's first via chain.
767
303
  viaChainId: (0, exports.deriveViaChainIdsFromPlan)(plan)?.[0],
768
304
  pathKey: plan.pathKey,
769
305
  viaChainIds: (0, exports.deriveViaChainIdsFromPlan)(plan),
770
306
  };
771
307
  };
772
308
  exports.buildRouteDataFromPlan = buildRouteDataFromPlan;
773
- /**
774
- * Turns a priced {@link RoutePlan} into a {@link RouteCandidate}, filling
775
- * `plan` and deriving `deferredCrossing`, `entryChainId` and
776
- * `omnibridgeProvider` from it exactly as `RouteCandidate.plan`'s own TSDoc
777
- * (`../candidate.ts`) promises.
778
- *
779
- * @param inputs - the plan, a token resolver, an id, and the caller's pricing
780
- * @returns the route candidate
781
- */
782
309
  const buildRouteCandidateFromPlan = (inputs) => {
783
310
  const { plan, resolveToken, id, inputAmount, paidUsdValue, lastHopDeliveredUsdValue, destinationUsdPrice, omnibridgeFeeAmount = 0n, anchorUsdValue = null, requestedAmount, fees = [], executionDurationSeconds = 0, } = inputs;
784
311
  const firstHop = plan.hops[0];
@@ -806,23 +333,6 @@ const buildRouteCandidateFromPlan = (inputs) => {
806
333
  executionDurationSeconds,
807
334
  steps: [],
808
335
  fees: [...fees],
809
- // A PRICED-BUT-NOT-RESERVED deposit (`UnreservedDeposit`,
810
- // `../../origin-deposit.js`) — the variant that EXISTS for exactly this
811
- // case: "a route on display... priced with a dry quote, which carries
812
- // figures and no address" (that type's own doc). This candidate exists
813
- // for scoring and for `RouteData`/`RouteCandidate` shape assembly, never
814
- // for a real signature, so it has nothing to reserve.
815
- //
816
- // THIS IS NOT A STAND-IN FOR THE ORIGIN'S REAL ECOSYSTEM. An earlier
817
- // version of this line hard-coded `{ ecosystem: 'evm', ... }`
818
- // unconditionally, which is wrong for any non-Ethereum-Virtual-Machine
819
- // origin a general-search plan can now represent (a Zcash or Solana
820
- // first hop, for example) — a deposit's ecosystem must come from the
821
- // chain, never asserted past it. `UnreservedDeposit` sidesteps the
822
- // question honestly instead of answering it wrongly: it is
823
- // discriminated by `kind`, not by `ecosystem`, and carries no
824
- // ecosystem-specific fields at all, so there is no wrong shape to pick
825
- // regardless of which ecosystem `firstHop.edge.from` names.
826
336
  originDeposit: { kind: 'unreserved', chainId: firstHop.edge.from.chainId },
827
337
  };
828
338
  return {
@@ -841,20 +351,6 @@ const buildRouteCandidateFromPlan = (inputs) => {
841
351
  };
842
352
  };
843
353
  exports.buildRouteCandidateFromPlan = buildRouteCandidateFromPlan;
844
- /**
845
- * Turns a priced {@link RoutePlan} into {@link RouteScoreInputs} — reusing
846
- * `candidateDeliveredUsd`, `candidatePaidUsd` and `candidateOutsideFeesUsd`
847
- * (`../producers.js`) against the SAME candidate
848
- * {@link buildRouteCandidateFromPlan} builds, exactly as `RouteScoreInputs`'
849
- * own doc in `score.ts` asks: "generalized to the plan's LAST hop and FIRST
850
- * hop respectively... import and reuse them; do not write a second
851
- * valuation."
852
- *
853
- * @param valuation - the plan, a token resolver, an id, and the caller's pricing
854
- * @param gaslessIntermediateChainCount - intermediate chains the connected
855
- * account holds no gas on — supplied by the caller, never computed here
856
- * @returns the plan's score inputs
857
- */
858
354
  const buildRouteScoreInputsFromPlan = (valuation, gaslessIntermediateChainCount) => {
859
355
  const candidate = (0, exports.buildRouteCandidateFromPlan)(valuation);
860
356
  return {
@@ -864,10 +360,6 @@ const buildRouteScoreInputsFromPlan = (valuation, gaslessIntermediateChainCount)
864
360
  legClaimedDurationsSeconds: valuation.legClaimedDurationsSeconds,
865
361
  readerActionCount: valuation.plan.signatures.length,
866
362
  gaslessIntermediateChainCount,
867
- // PHASE 3 — read directly off the plan's own hops, never re-derived: see
868
- // `planComposedBasis`'s own doc (`graph.ts`) for why this always agrees
869
- // with `planIsRankable`, and `RouteScoreInputs.basis`'s own doc for what
870
- // `scoreRoutePlan` does with it.
871
363
  basis: (0, graph_js_1.planComposedBasis)(valuation.plan.hops),
872
364
  };
873
365
  };