@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
@@ -3,15 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeRelaySteps = exports.normalizeLifiSteps = void 0;
4
4
  const chain_names_js_1 = require("./chain-names.js");
5
5
  const isHexString = (value) => typeof value === 'string' && value.startsWith('0x');
6
- /**
7
- * Sums the `amountUSD` field across a LI.FI cost array (`feeCosts` or
8
- * `gasCosts`), tolerating missing/malformed entries by skipping them. LI.FI
9
- * reports each cost's dollar value as a numeric string; entries without a finite
10
- * `amountUSD` contribute nothing rather than poisoning the sum with `NaN`.
11
- *
12
- * @param costs - a raw `feeCosts`/`gasCosts` value from a step estimate
13
- * @returns the total United States dollar cost; zero when none are present
14
- */
15
6
  const sumUsdCosts = (costs) => {
16
7
  if (!Array.isArray(costs)) {
17
8
  return 0;
@@ -28,13 +19,6 @@ const asRecord = (value) => {
28
19
  }
29
20
  return value;
30
21
  };
31
- /**
32
- * Maps a LI.FI step type string to the normalized `RouteStepKind`.
33
- *
34
- * LI.FI reports `"cross"` for bridge legs and `"swap"` for same-chain
35
- * exchanges. `"wrap"` and `"unwrap"` map directly. Unknown types fall back to
36
- * `"send"` rather than failing the whole normalization.
37
- */
38
22
  const lifiTypeToKind = (type) => {
39
23
  if (type === 'cross')
40
24
  return 'bridge';
@@ -46,12 +30,6 @@ const lifiTypeToKind = (type) => {
46
30
  return 'unwrap';
47
31
  return 'send';
48
32
  };
49
- /**
50
- * Builds a human-readable label for a LI.FI step.
51
- *
52
- * Labels are fully spelled out (no acronyms) so they can be displayed
53
- * directly in the UI without any post-processing.
54
- */
55
33
  const buildLifiLabel = (kind, toChainId, toolName) => {
56
34
  if (kind === 'bridge')
57
35
  return `Bridge to ${(0, chain_names_js_1.chainDisplayName)(toChainId)}`;
@@ -63,15 +41,6 @@ const buildLifiLabel = (kind, toChainId, toolName) => {
63
41
  return `Unwrap to native on ${(0, chain_names_js_1.chainDisplayName)(toChainId)}`;
64
42
  return `Transfer on ${(0, chain_names_js_1.chainDisplayName)(toChainId)}`;
65
43
  };
66
- /**
67
- * Normalizes a LI.FI `includedSteps` array into the provider-agnostic
68
- * `RouteStep[]` shape. Steps with missing or non-hex token addresses are
69
- * silently dropped rather than causing the whole normalization to fail.
70
- *
71
- * @param steps - the raw `includedSteps` value from a LI.FI quote response,
72
- * or `undefined` when the field was absent (trimmed responses)
73
- * @returns ordered list of normalized steps; empty when no usable legs are present
74
- */
75
44
  const normalizeLifiSteps = (steps) => {
76
45
  if (!Array.isArray(steps) || steps.length === 0) {
77
46
  return [];
@@ -92,12 +61,6 @@ const normalizeLifiSteps = (steps) => {
92
61
  if (fromChainId === null || toChainId === null) {
93
62
  continue;
94
63
  }
95
- // A step that changes chains IS a bridge, whatever the provider called its
96
- // type. LI.FI labels most cross-chain legs `"cross"`, but some (e.g. an Across
97
- // leg, or a `"protocol"`/`"lifi"`-typed leg) would otherwise fall through to
98
- // the generic `"send"` kind and read as "Transfer on Ethereum" — misleading,
99
- // since the funds are actually being BRIDGED there. Deciding from the chains
100
- // rather than the type string keeps the label honest.
101
64
  const typeKind = lifiTypeToKind(type);
102
65
  const kind = typeKind === 'send' && fromChainId !== toChainId ? 'bridge' : typeKind;
103
66
  const fromTokenRecord = asRecord(action.fromToken);
@@ -117,10 +80,6 @@ const normalizeLifiSteps = (steps) => {
117
80
  : typeof step.tool === 'string'
118
81
  ? step.tool
119
82
  : 'unknown';
120
- // The per-step tool's logo, when the provider supplies one. This is the best
121
- // source for a real service-provider image on the consuming interface (for
122
- // example the Uniswap or Stargate logo for the leg the aggregator routes
123
- // through). Null when absent, so the interface falls back to an initials tile.
124
83
  const providerLogoUri = typeof toolDetails?.logoURI === 'string' ? toolDetails.logoURI : null;
125
84
  const label = buildLifiLabel(kind, toChainId, toolName);
126
85
  const estimate = asRecord(step.estimate);
@@ -138,15 +97,10 @@ const normalizeLifiSteps = (steps) => {
138
97
  const router = isHexString(integrationData?.callToAddress)
139
98
  ? integrationData.callToAddress
140
99
  : null;
141
- // Per-step cost = protocol fees + gas, both reported in United States dollars.
142
- // Null when the provider reported neither, so the UI omits the hop's fee.
143
100
  const protocolFeeUsd = sumUsdCosts(estimate?.feeCosts);
144
101
  const gasCostUsd = sumUsdCosts(estimate?.gasCosts);
145
102
  const stepCostUsd = protocolFeeUsd + gasCostUsd;
146
103
  const feeUsd = stepCostUsd > 0 ? stepCostUsd : null;
147
- // Gas alone, for route ranking (which charges gas on top of the paid-versus-
148
- // delivered spread and must not double-count the protocol fees already baked
149
- // into the quote's `fromAmount`). Null when no gas was reported.
150
104
  const gasUsd = gasCostUsd > 0 ? gasCostUsd : null;
151
105
  result.push({
152
106
  kind,
@@ -169,12 +123,6 @@ const normalizeLifiSteps = (steps) => {
169
123
  return result;
170
124
  };
171
125
  exports.normalizeLifiSteps = normalizeLifiSteps;
172
- /**
173
- * Parses one `{ currency, amount }` entry from Relay's `details.route`.
174
- *
175
- * @param value - a raw `inputCurrency`/`outputCurrency` value
176
- * @returns the endpoint, or null when the chain id or address is unusable
177
- */
178
126
  const relayRouteEndpoint = (value) => {
179
127
  const entry = asRecord(value);
180
128
  const currency = asRecord(entry?.currency);
@@ -183,8 +131,6 @@ const relayRouteEndpoint = (value) => {
183
131
  }
184
132
  const chainId = typeof currency.chainId === 'number' ? currency.chainId : null;
185
133
  const address = typeof currency.address === 'string' ? currency.address : null;
186
- // Without a chain and an identifier there is no leg to describe. Both are
187
- // always present in Relay's verified shape; bail rather than invent one.
188
134
  if (chainId === null || address === null) {
189
135
  return null;
190
136
  }
@@ -206,46 +152,12 @@ const relayRouteEndpoint = (value) => {
206
152
  amount,
207
153
  };
208
154
  };
209
- /**
210
- * Reads a `{ amountUsd }` entry from Relay's `fees` object as a number.
211
- * Relay reports dollar values as numeric strings; anything non-finite
212
- * contributes nothing rather than poisoning the sum with `NaN`.
213
- */
214
155
  const relayFeeUsd = (fees, key) => {
215
156
  const fee = asRecord(fees?.[key]);
216
157
  const amountUsd = typeof fee?.amountUsd === 'string' ? Number(fee.amountUsd) : Number.NaN;
217
158
  return Number.isFinite(amountUsd) ? amountUsd : 0;
218
159
  };
219
- /** True when two endpoints are the same currency on the same chain. */
220
160
  const isSameEndpoint = (left, right) => left.chainId === right.chainId && left.address === right.address;
221
- /**
222
- * Normalizes a Relay quote into the provider-agnostic `RouteStep[]` shape.
223
- *
224
- * Relay's `steps` array holds only OPERATIONAL steps (`approve` and `deposit`) —
225
- * what the user signs, not where the funds go. The route itself lives in
226
- * `details.route`, which describes the journey as an origin leg and a
227
- * destination leg, each with an input and an output currency. Reading those four
228
- * endpoints in order and emitting a step between each consecutive pair recovers
229
- * the real path, so a Bitcoin origin renders as "Bitcoin → United States Dollar
230
- * Coin on Ethereum" rather than as nothing at all.
231
- *
232
- * Consecutive endpoints that name the same currency on the same chain are
233
- * collapsed, because Relay repeats an endpoint when a leg performs no
234
- * conversion. A step's kind follows from its chains: crossing chains is a
235
- * `bridge`, staying put is a `swap`. Relay reports no wrap/unwrap distinction,
236
- * so none is invented.
237
- *
238
- * Costs are route-level in Relay's response, not per leg, so they are attached
239
- * to the FIRST step — the one the user actually signs and pays at. `gasUsd`
240
- * carries `fees.gas` alone (the origin transaction's gas, paid on top in the
241
- * network's native token), while `feeUsd` adds the relayer and application fees
242
- * on top of it, matching how the LI.FI normalizer splits the two. The relayer
243
- * fee's `relayerGas`/`relayerService` components are deliberately NOT summed:
244
- * they add up to `relayer` exactly, so counting them would double the fee.
245
- *
246
- * @param quote - a raw Relay quote response body
247
- * @returns ordered list of normalized steps; empty when no route is present
248
- */
249
161
  const normalizeRelaySteps = (quote) => {
250
162
  const details = asRecord(asRecord(quote)?.details);
251
163
  const route = asRecord(details?.route);
@@ -260,15 +172,12 @@ const normalizeRelaySteps = (quote) => {
260
172
  relayRouteEndpoint(destination?.inputCurrency),
261
173
  relayRouteEndpoint(destination?.outputCurrency),
262
174
  ].filter((endpoint) => endpoint !== null);
263
- // Collapse repeats so a leg that converts nothing does not become a step.
264
175
  const path = endpoints.filter((endpoint, index) => index === 0 || !isSameEndpoint(endpoint, endpoints[index - 1]));
265
176
  if (path.length < 2) {
266
177
  return [];
267
178
  }
268
179
  const fees = asRecord(asRecord(quote)?.fees);
269
180
  const gasUsd = relayFeeUsd(fees, 'gas');
270
- // `relayer` is the full relayer charge; its `relayerGas` and `relayerService`
271
- // components sum to it exactly, so only the total is counted here.
272
181
  const totalUsd = gasUsd + relayFeeUsd(fees, 'relayer') + relayFeeUsd(fees, 'app');
273
182
  const result = [];
274
183
  for (let index = 1; index < path.length; index += 1) {
@@ -287,20 +196,11 @@ const normalizeRelaySteps = (quote) => {
287
196
  toToken: to.address,
288
197
  fromTokenSymbol: from.symbol,
289
198
  toTokenSymbol: to.symbol,
290
- // Relay's currency metadata carries the TOKEN's own image, which is the only
291
- // one available for a non-Ethereum endpoint (Bitcoin, Solana, Tron, The Open
292
- // Network) — the image service cannot key those by a hex address.
293
199
  fromTokenLogoUri: from.logoUri,
294
200
  toTokenLogoUri: to.logoUri,
295
- // Relay's `router` field on a route leg names the service ("relay"), not a
296
- // contract address, so there is no router address to surface for the leg.
297
201
  router: null,
298
- // Relay supplies a logo for the currency, not for a per-leg tool, so the
299
- // consuming interface falls back to the provider tile. Deliberately null
300
- // rather than passing a token image off as a service-provider image.
301
202
  providerLogoUri: null,
302
203
  estimatedOut: to.amount,
303
- // Route-level costs land on the signed step; later legs run inside it.
304
204
  feeUsd: isFirstStep && totalUsd > 0 ? totalUsd : null,
305
205
  gasUsd: isFirstStep && gasUsd > 0 ? gasUsd : null,
306
206
  });
@@ -3,35 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.valueEquivalentAmount = exports.restateInDecimals = exports.netDeliveredAmount = void 0;
4
4
  const viem_1 = require("viem");
5
5
  const settings_js_1 = require("../settings.js");
6
- /**
7
- * The amount that actually LANDS on PulseChain for an aggregator candidate, net
8
- * of the omnibridge crossing fee.
9
- *
10
- * The aggregator delivers `entryChainAmount` (the consolidated request's
11
- * `toAmount`) onto the omnibridge entry chain, and the omnibridge entry call
12
- * relays exactly that — but the omnibridge takes its foreign→home crossing fee on
13
- * the way to PulseChain, so the user receives LESS than `entryChainAmount`. This
14
- * nets that crossing fee out using the SDK's OWN fee primitives ({@link bridgeCost}
15
- * and {@link amountAfterBridgeFee}) — the identical math the direct engine applies
16
- * — so the displayed received amount is honest rather than overstated.
17
- *
18
- * The multiplexed (aggregator) swap fees are NOT subtracted here: the aggregator
19
- * already quotes the source-chain `fromAmount` it needs to GUARANTEE
20
- * `entryChainAmount` arrives, so those fees are already reflected in `fromAmount`.
21
- * Only the omnibridge crossing fee remains to net out, which is this function's
22
- * sole job.
23
- *
24
- * @param entryChainAmount - the amount arriving on the entry chain (request `toAmount`)
25
- * @param omnibridgeFeePerEther - the omnibridge foreign→home fee rate (per 1e18), or null
26
- * @returns the net amount delivered on PulseChain; equals `entryChainAmount` when the fee is unknown
27
- */
28
6
  const netDeliveredAmount = (entryChainAmount, omnibridgeFeePerEther) => {
29
- // Defensive: the omnibridge percentage math runs ONLY when both operands are
30
- // true bigints. A non-bigint fee (a value rehydrated from storage as a string,
31
- // the project's documented BigInt-serialization gotcha) would throw inside
32
- // `bridgeCost`'s mixed-type multiplication, so fall back to the un-netted
33
- // entry-chain amount rather than crash the render. The `typeof` guards intentionally
34
- // outlive the static `bigint` types because the runtime value can violate them.
35
7
  if (typeof entryChainAmount !== 'bigint' || typeof omnibridgeFeePerEther !== 'bigint') {
36
8
  return entryChainAmount;
37
9
  }
@@ -40,25 +12,6 @@ const netDeliveredAmount = (entryChainAmount, omnibridgeFeePerEther) => {
40
12
  return net ?? entryChainAmount;
41
13
  };
42
14
  exports.netDeliveredAmount = netDeliveredAmount;
43
- /**
44
- * Restates an amount in a different token's decimals, preserving the QUANTITY.
45
- *
46
- * This is the honest degraded answer when {@link valueEquivalentAmount} cannot
47
- * price a conversion. Losing the price must not also lose the decimals: the two
48
- * omnibridge anchors hold the same asset bridged two ways, and the only
49
- * difference between them is where the decimal point sits. Returning an
50
- * unadjusted amount across that gap is wrong by a factor of 10^12, which is the
51
- * exact error the value conversion exists to prevent.
52
- *
53
- * Scaling DOWN truncates, and must — a six-decimal token cannot hold the twelve
54
- * extra digits an eighteen-decimal one carries. The lost remainder is smaller
55
- * than one base unit of the target.
56
- *
57
- * @param params.amount - the amount, in `fromDecimals` base units
58
- * @param params.fromDecimals - the decimals the amount is currently expressed in
59
- * @param params.toDecimals - the decimals to restate it in
60
- * @returns the same quantity, in `toDecimals` base units
61
- */
62
15
  const restateInDecimals = ({ amount, fromDecimals, toDecimals, }) => {
63
16
  if (fromDecimals === toDecimals)
64
17
  return amount;
@@ -67,47 +20,11 @@ const restateInDecimals = ({ amount, fromDecimals, toDecimals, }) => {
67
20
  return amount / 10n ** BigInt(fromDecimals - toDecimals);
68
21
  };
69
22
  exports.restateInDecimals = restateInDecimals;
70
- /**
71
- * Converts `amount` of a source token into the base-unit amount of a TARGET token
72
- * carrying the SAME United States dollar value:
73
- *
74
- * valueUsd = amount / 10^fromDecimals × fromPrice
75
- * targetAmount = valueUsd / toPrice × 10^toDecimals
76
- *
77
- * This is what lets the two omnibridge entry points be quoted for the SAME VALUE
78
- * even when their anchor tokens differ in decimals — a PulseChain-bridged
79
- * stablecoin is 6 decimals when bridged from Ethereum but 18 from Binance Smart
80
- * Chain. Feeding one raw integer to both targeted quantities ~10^12 apart, so the
81
- * routes were not comparable and the higher-decimal entry won on a bigger NUMBER
82
- * rather than more value. Targeting equal value in each anchor's own decimals
83
- * restores a fair, decimals-correct comparison.
84
- *
85
- * Returns null when either price is missing or non-positive, the scaled value is
86
- * not finite, or the target cannot be parsed — the caller then has no
87
- * value-equivalent target and must fall back rather than quote a bogus amount.
88
- *
89
- * @param params.amount - the source amount, in `fromDecimals` base units
90
- * @param params.fromDecimals - the source token's decimals
91
- * @param params.fromPrice - the source token's per-token United States dollar price, or null
92
- * @param params.toDecimals - the target token's decimals
93
- * @param params.toPrice - the target token's per-token United States dollar price, or null
94
- * @returns the value-equivalent amount in the target token's base units, or null
95
- */
96
23
  const valueEquivalentAmount = ({ amount, fromDecimals, fromPrice, toDecimals, toPrice, }) => {
97
24
  if (fromPrice === null || toPrice === null)
98
25
  return null;
99
26
  if (!(fromPrice > 0) || !(toPrice > 0))
100
27
  return null;
101
- // Equal prices make this a pure change of decimals, and integer rescaling is
102
- // EXACT where the double round trip is not. `39.3` is not representable as a
103
- // double, so `toFixed(18)` writes 39.299999999999997158 and the conversion
104
- // comes back 2842 base units short of the 39.3 that went in. At the same
105
- // decimals it lands one unit out (0.008802 returns as 8802000000000001).
106
- //
107
- // Both are negligible in value and neither is a reason to convert at all: with
108
- // one price on both sides there is no value question to answer, only a decimal
109
- // point to move. Moving it in integers keeps the same input producing the same
110
- // target.
111
28
  if (fromPrice === toPrice)
112
29
  return (0, exports.restateInDecimals)({ amount, fromDecimals, toDecimals });
113
30
  const valueUsd = Number((0, viem_1.formatUnits)(amount, fromDecimals)) * fromPrice;
@@ -4,85 +4,12 @@ exports.routeSignatureCountForAccount = exports.routeSignatureCount = exports.bu
4
4
  const near_intents_route_js_1 = require("../near-intents-route.js");
5
5
  const execution_js_1 = require("../execution.js");
6
6
  const producers_js_1 = require("./producers.js");
7
- /**
8
- * One door in front of the two base route builders.
9
- *
10
- * WHY THIS EXISTS. A candidate is drawn by one of two builders and the choice
11
- * is not the caller's to make by hand. {@link buildCandidateRouteData} draws a
12
- * candidate as ONE signature, because the aggregator's executor performs the
13
- * omnibridge entry call on arrival. {@link buildNearIntentsTwoStepRouteData}
14
- * draws it as TWO, because the aggregator that carried it cannot execute
15
- * anything on the chain it delivers to, so the reader signs the crossing
16
- * themselves.
17
- *
18
- * Every composer that builds on top of a candidate — the PulseX conversion
19
- * route is the first — has to pick between them, and picking wrong is not a
20
- * cosmetic error. A two-signature candidate run through the one-signature
21
- * builder produces a route that claims the crossing happens inside the
22
- * transaction the reader already signed. It does not. The reader would select
23
- * that route, sign once, and be left holding the anchor token on the entry
24
- * chain with the interface reporting the journey finished.
25
- *
26
- * `candidate.deferredCrossing` is the fact that decides it, and it is the same
27
- * field {@link buildNearIntentsTwoStepRouteData} refuses to build without. So
28
- * the two agree by construction rather than by two callers remembering the
29
- * same rule.
30
- *
31
- * @param candidate - the priced route candidate
32
- * @returns the raw route data, or null when the candidate names a deferred
33
- * crossing but no omnibridge provider to perform it
34
- */
35
7
  const buildRouteDataForCandidate = (candidate) => candidate.deferredCrossing
36
8
  ? (0, near_intents_route_js_1.buildNearIntentsTwoStepRouteData)(candidate)
37
9
  : (0, producers_js_1.buildCandidateRouteData)(candidate);
38
10
  exports.buildRouteDataForCandidate = buildRouteDataForCandidate;
39
- /**
40
- * How many wallet signatures a raw route asks the reader for.
41
- *
42
- * Counts the sections, because one section is one signature — that is what a
43
- * section means. Named rather than left as `sections.length` at each call
44
- * site, so a surface that warns about a long journey and a surface that ranks
45
- * routes cannot come to different counts.
46
- *
47
- * THIS COUNT LEAVES OUT APPROVALS. A token that is not the chain's native coin
48
- * needs an `approve` transaction before its first section when the allowance
49
- * is too small, and that approval is a signature too. Raw route data does not
50
- * say who the spender is or what the account has approved already, so this
51
- * function cannot count it. Use {@link routeSignatureCountForAccount} for the
52
- * number the wallet will really ask for.
53
- *
54
- * @param route - the raw route data
55
- * @returns the number of signatures, one per section, with no approvals
56
- */
57
11
  const routeSignatureCount = (route) => route.sections.length;
58
12
  exports.routeSignatureCount = routeSignatureCount;
59
- /**
60
- * How many wallet signatures a route asks one account for, approvals included.
61
- *
62
- * {@link routeSignatureCount} counts sections only, so a USDC route reads "1"
63
- * and then asks for two prompts: approve, then send. This function plans the
64
- * sections with {@link planCandidateExecution} and counts what that plan
65
- * contains, so it uses the same allowance rule and the same spender the
66
- * execution planner uses. A native input needs no approval. An allowance that
67
- * already covers the amount needs none. A smaller, non-zero allowance counts
68
- * the reset and the new approval, the two transactions the planner emits. The
69
- * spender is whatever the planner picks: the omnibridge mediator, a swap
70
- * venue's router (including routers passed in `swapVenues`), or the
71
- * aggregator's approval address.
72
- *
73
- * Pass every section of the route to count the whole route. Pass fewer to
74
- * count only the window you plan now; each section is counted against the
75
- * allowance on chain today, so a later section that spends a token an earlier
76
- * section delivers is counted as if the approval is still needed.
77
- *
78
- * An aggregator section needs its `aggregator` inputs, a quote and the request
79
- * it answered, exactly as {@link planCandidateExecution} does. Without them
80
- * this function throws, because the approval spender comes from that quote.
81
- *
82
- * @param inputs - the same inputs {@link planCandidateExecution} takes
83
- * @returns the signatures, approvals, and their total
84
- * @throws when a section cannot be planned; the message names the section and the reason
85
- */
86
13
  const routeSignatureCountForAccount = async (inputs) => {
87
14
  const plan = await (0, execution_js_1.planCandidateExecution)(inputs);
88
15
  if (plan.kind === 'refused') {
@@ -4,39 +4,6 @@ exports.buildDirectCrossingCandidate = void 0;
4
4
  const viem_1 = require("viem");
5
5
  const amounts_js_1 = require("./amounts.js");
6
6
  const providers_js_1 = require("./providers.js");
7
- /**
8
- * Synthesizes a {@link RouteCandidate} for the SAME-CHAIN direct-omnibridge
9
- * conversion case: when the origin chain IS one of the omnibridge entry chains
10
- * (Ethereum chain 1 or Binance Smart Chain chain 56), there is no aggregator leg
11
- * to quote — the user bridges directly from that chain to PulseChain. The
12
- * same-chain skip in {@link useAggregatorRouteCandidate} is correct (nothing to
13
- * quote), but it left the conversion path empty. This helper fills that gap by
14
- * synthesizing a zero-step candidate. The user interface no longer calls this:
15
- * the route engine serves a conversion now. The export stays as published
16
- * interface until a separate decision removes it.
17
- *
18
- * The synthetic quote carries zero steps (no aggregator hops), a zero execution
19
- * duration (the direct crossing needs no quote wait), and a null transaction
20
- * request — this candidate is DISPLAY and RANKING only. The candidate's
21
- * `deliveredAmount` is net of the omnibridge crossing fee, identical to the math
22
- * {@link useAggregatorRouteCandidate} applies.
23
- *
24
- * This is a PURE exported helper (no hooks, no side effects) so it is
25
- * unit-testable in isolation and can be called from two `useMemo` blocks in
26
- * Bridge.tsx without duplicating the object literal.
27
- *
28
- * EXECUTION: when the route built from this candidate is selected, the
29
- * consolidated (aggregator) execute path is deliberately NOT used — there is no
30
- * aggregator leg for it to sign. `executesViaConsolidated`
31
- * (`packages/ui/src/lib/state/bridgeExecution.ts`) recognizes the candidate's
32
- * `entryChainId === originChainId` and routes the selection through the direct
33
- * omnibridge sender instead, which builds its transaction from the live
34
- * `useBridgeSettings` cascade rather than from this synthetic quote.
35
- *
36
- * @param inputs - the entry chain, origin/destination tokens, amount, and fee rate
37
- * @returns the synthesized RouteCandidate, or throws when the entry chain is not
38
- * a valid omnibridge entry point (caller must guard on `omnibridgeProviderForEntryChain`)
39
- */
40
7
  const buildDirectCrossingCandidate = ({ entryChainId, originChainId, originToken, destinationToken, amountIn, originUsdPrice, destinationUsdPrice, omnibridgeFeePerEther, }) => {
41
8
  const provider = (0, providers_js_1.omnibridgeProviderForEntryChain)(entryChainId);
42
9
  if (provider === null) {
@@ -52,13 +19,6 @@ const buildDirectCrossingCandidate = ({ entryChainId, originChainId, originToken
52
19
  : null;
53
20
  const quoteId = `direct-omnibridge-${entryChainId}-${originChainId}`;
54
21
  const syntheticQuote = {
55
- // The synthetic quote wraps the omnibridge provider slug. ConsolidatedQuote's
56
- // `provider` field is typed for the aggregator providers ('lifi' | 'relay'),
57
- // but the functions that read it (`resolveProviderDisplayName`,
58
- // `resolveProviderLogoUri`) accept any string at runtime. The cast is safe here
59
- // because no aggregator-specific code path runs on a zero-step candidate —
60
- // this synthetic quote is never itself signed; see the module doc comment
61
- // above for where execution actually happens for the route built from it.
62
22
  provider: provider,
63
23
  quoteId,
64
24
  tool: provider,
@@ -68,9 +28,6 @@ const buildDirectCrossingCandidate = ({ entryChainId, originChainId, originToken
68
28
  approvalAddress: null,
69
29
  executionDurationSeconds: 0,
70
30
  steps: [],
71
- // A direct crossing carries no aggregator, so there is no carrier fee to
72
- // report. The omnibridge's own crossing fee is `omnibridgeFeeAmount`
73
- // beside it, which the route surfaces separately.
74
31
  fees: [],
75
32
  originDeposit: {
76
33
  ecosystem: 'evm',
@@ -91,9 +48,6 @@ const buildDirectCrossingCandidate = ({ entryChainId, originChainId, originToken
91
48
  deliveredAmount: delivered,
92
49
  omnibridgeFeeAmount,
93
50
  destinationUsdPrice,
94
- // A same-chain crossing has no aggregator leg to solve backward, so it spends
95
- // exactly what was typed — requested and spent are the same figure by
96
- // construction, and the route reports nothing unspent.
97
51
  requestedAmount: amountIn,
98
52
  };
99
53
  };
@@ -3,40 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.carrierStepKind = exports.carrierProviderKey = exports.WRAP_CARRIER_ID = void 0;
4
4
  const config_js_1 = require("../config.js");
5
5
  const providers_js_1 = require("../providers.js");
6
- /**
7
- * The carrier id of the native-coin wrap and unwrap step
8
- * (`routing/carriers/wrap.ts`).
9
- */
10
6
  exports.WRAP_CARRIER_ID = 'wrap';
11
- /**
12
- * Every engine carrier id that IS a provider, mapped to its {@link ProviderKey}.
13
- * The omnibridge crossings carry the provider value itself; the aggregators
14
- * carry their registry id; the PulseChain exchange carries its own literal.
15
- */
16
7
  const providerKeyByCarrierId = new Map([
17
8
  ...Object.values(config_js_1.Providers).map((provider) => [provider, provider]),
18
9
  ...providers_js_1.providerRegistry.map((descriptor) => [descriptor.id, descriptor.id]),
19
10
  ['PulseX', 'PulseX'],
20
11
  ]);
21
- /**
22
- * The one place an engine carrier id becomes a {@link ProviderKey}.
23
- *
24
- * AN ENGINE CARRIER ID IS NOT A PROVIDER KEY. The engine is a plug-in host: a
25
- * carrier id is any string, and one of them, `'wrap'`, names a step that no
26
- * provider performs. Handing a raw id to the logo, glyph, or name tables drew a
27
- * blank mark and logged an error. Route data resolves the key here, once, and
28
- * every display site reads the resolved key.
29
- *
30
- * @param carrierId - the `carrier` of a planned hop's edge
31
- * @returns the provider key, or null when no registered provider carries that id
32
- */
33
12
  const carrierProviderKey = (carrierId) => providerKeyByCarrierId.get(carrierId) ?? null;
34
13
  exports.carrierProviderKey = carrierProviderKey;
35
- /**
36
- * The kind of provider-less step a carrier id performs.
37
- *
38
- * @param carrierId - the `carrier` of a planned hop's edge
39
- * @returns the step kind, or null when the carrier is a provider or unknown
40
- */
41
14
  const carrierStepKind = (carrierId) => carrierId === exports.WRAP_CARRIER_ID ? 'wrap' : null;
42
15
  exports.carrierStepKind = carrierStepKind;