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