@gibs/bridge-sdk 1.13.0 → 1.17.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 (217) hide show
  1. package/README.md +244 -18
  2. package/abis/package.json +6 -0
  3. package/bridge-limits/package.json +6 -0
  4. package/chain-info/package.json +6 -0
  5. package/chain-names/package.json +6 -0
  6. package/chains/package.json +6 -0
  7. package/claims/package.json +6 -0
  8. package/config/package.json +6 -0
  9. package/consolidated-quote/package.json +6 -0
  10. package/destination-calldata/package.json +6 -0
  11. package/dist/chain-info.d.ts +1 -1
  12. package/dist/chain-info.js +11 -12
  13. package/dist/chains.d.ts +25 -0
  14. package/dist/chains.js +55 -20
  15. package/dist/cjs/abis.d.ts +1 -0
  16. package/dist/cjs/abis.js +19 -0
  17. package/dist/cjs/bridge-limits.d.ts +103 -0
  18. package/dist/cjs/bridge-limits.js +89 -0
  19. package/dist/cjs/chain-info.d.ts +169 -0
  20. package/dist/cjs/chain-info.js +452 -0
  21. package/dist/cjs/chain-names.d.ts +160 -0
  22. package/dist/cjs/chain-names.js +207 -0
  23. package/dist/cjs/chains.d.ts +90 -0
  24. package/dist/cjs/chains.js +357 -0
  25. package/dist/cjs/claims.d.ts +198 -0
  26. package/dist/cjs/claims.js +182 -0
  27. package/dist/cjs/config.d.ts +240 -0
  28. package/dist/cjs/config.js +537 -0
  29. package/dist/cjs/consolidated-quote.d.ts +648 -0
  30. package/dist/cjs/consolidated-quote.js +1048 -0
  31. package/dist/cjs/destination-calldata.d.ts +118 -0
  32. package/dist/cjs/destination-calldata.js +156 -0
  33. package/dist/cjs/ecosystems.d.ts +217 -0
  34. package/dist/cjs/ecosystems.js +298 -0
  35. package/dist/cjs/execution.d.ts +346 -0
  36. package/dist/cjs/execution.js +468 -0
  37. package/dist/cjs/fee-type.d.ts +10 -0
  38. package/dist/cjs/fee-type.js +10 -0
  39. package/dist/cjs/hyperliquid-execution.d.ts +152 -0
  40. package/dist/cjs/hyperliquid-execution.js +175 -0
  41. package/dist/cjs/image-links.d.ts +117 -0
  42. package/dist/cjs/image-links.js +153 -0
  43. package/dist/cjs/index.d.ts +23 -0
  44. package/dist/cjs/index.js +39 -0
  45. package/dist/cjs/lifi-execution-guard.d.ts +210 -0
  46. package/dist/cjs/lifi-execution-guard.js +409 -0
  47. package/dist/cjs/near-intents-conformance.d.ts +85 -0
  48. package/dist/cjs/near-intents-conformance.js +337 -0
  49. package/dist/cjs/near-intents-route.d.ts +47 -0
  50. package/dist/cjs/near-intents-route.js +303 -0
  51. package/dist/cjs/near-intents.d.ts +524 -0
  52. package/dist/cjs/near-intents.js +1071 -0
  53. package/dist/cjs/origin-deposit.d.ts +326 -0
  54. package/dist/cjs/origin-deposit.js +82 -0
  55. package/dist/cjs/package.json +3 -0
  56. package/dist/cjs/pre-quote.d.ts +198 -0
  57. package/dist/cjs/pre-quote.js +180 -0
  58. package/dist/cjs/prices.d.ts +107 -0
  59. package/dist/cjs/prices.js +172 -0
  60. package/dist/cjs/providers.d.ts +238 -0
  61. package/dist/cjs/providers.js +171 -0
  62. package/dist/cjs/quote-fees.d.ts +102 -0
  63. package/dist/cjs/quote-fees.js +201 -0
  64. package/dist/cjs/referral.d.ts +85 -0
  65. package/dist/cjs/referral.js +85 -0
  66. package/dist/cjs/relay-currencies.d.ts +47 -0
  67. package/dist/cjs/relay-currencies.js +95 -0
  68. package/dist/cjs/relay-depository.d.ts +2 -0
  69. package/dist/cjs/relay-depository.js +85 -0
  70. package/dist/cjs/relay-quote.d.ts +301 -0
  71. package/dist/cjs/relay-quote.js +996 -0
  72. package/dist/cjs/route-steps.d.ts +138 -0
  73. package/dist/cjs/route-steps.js +310 -0
  74. package/dist/cjs/routing/amounts.d.ts +80 -0
  75. package/dist/cjs/routing/amounts.js +126 -0
  76. package/dist/cjs/routing/candidate-route.d.ts +43 -0
  77. package/dist/cjs/routing/candidate-route.js +50 -0
  78. package/dist/cjs/routing/candidate.d.ts +237 -0
  79. package/dist/cjs/routing/candidate.js +100 -0
  80. package/dist/cjs/routing/carriers/ask-answer.d.ts +77 -0
  81. package/dist/cjs/routing/carriers/ask-answer.js +2 -0
  82. package/dist/cjs/routing/carriers/omnibridge.d.ts +137 -0
  83. package/dist/cjs/routing/carriers/omnibridge.js +459 -0
  84. package/dist/cjs/routing/carriers/pulsex-paths.d.ts +80 -0
  85. package/dist/cjs/routing/carriers/pulsex-paths.js +97 -0
  86. package/dist/cjs/routing/carriers/pulsex-split.d.ts +175 -0
  87. package/dist/cjs/routing/carriers/pulsex-split.js +193 -0
  88. package/dist/cjs/routing/carriers/pulsex.d.ts +159 -0
  89. package/dist/cjs/routing/carriers/pulsex.js +565 -0
  90. package/dist/cjs/routing/carriers/wrap.d.ts +25 -0
  91. package/dist/cjs/routing/carriers/wrap.js +119 -0
  92. package/dist/cjs/routing/composed-route-quality.d.ts +125 -0
  93. package/dist/cjs/routing/composed-route-quality.js +144 -0
  94. package/dist/cjs/routing/entry-chain-anchor.d.ts +88 -0
  95. package/dist/cjs/routing/entry-chain-anchor.js +59 -0
  96. package/dist/cjs/routing/format.d.ts +31 -0
  97. package/dist/cjs/routing/format.js +64 -0
  98. package/dist/cjs/routing/index.d.ts +38 -0
  99. package/dist/cjs/routing/index.js +134 -0
  100. package/dist/cjs/routing/producers.d.ts +770 -0
  101. package/dist/cjs/routing/producers.js +1617 -0
  102. package/dist/cjs/routing/providers.d.ts +31 -0
  103. package/dist/cjs/routing/providers.js +48 -0
  104. package/dist/cjs/routing/route-data.d.ts +355 -0
  105. package/dist/cjs/routing/route-data.js +2 -0
  106. package/dist/cjs/routing/search/compose.d.ts +168 -0
  107. package/dist/cjs/routing/search/compose.js +104 -0
  108. package/dist/cjs/routing/search/graph.d.ts +668 -0
  109. package/dist/cjs/routing/search/graph.js +461 -0
  110. package/dist/cjs/routing/search/plan-route-data.d.ts +269 -0
  111. package/dist/cjs/routing/search/plan-route-data.js +848 -0
  112. package/dist/cjs/routing/search/score.d.ts +356 -0
  113. package/dist/cjs/routing/search/score.js +445 -0
  114. package/dist/cjs/routing/swap-transactions.d.ts +91 -0
  115. package/dist/cjs/routing/swap-transactions.js +131 -0
  116. package/dist/cjs/routing/usd-value.d.ts +17 -0
  117. package/dist/cjs/routing/usd-value.js +29 -0
  118. package/dist/cjs/settings.d.ts +785 -0
  119. package/dist/cjs/settings.js +1074 -0
  120. package/dist/cjs/ton-connect.d.ts +98 -0
  121. package/dist/cjs/ton-connect.js +206 -0
  122. package/dist/cjs/ton-execution.d.ts +7 -0
  123. package/dist/cjs/ton-execution.js +23 -0
  124. package/dist/cjs/ton.d.ts +37 -0
  125. package/dist/cjs/ton.js +83 -0
  126. package/dist/cjs/tron-execution.d.ts +146 -0
  127. package/dist/cjs/tron-execution.js +248 -0
  128. package/dist/cjs/types.d.ts +51 -0
  129. package/dist/cjs/types.js +2 -0
  130. package/dist/claims.d.ts +198 -0
  131. package/dist/claims.js +140 -0
  132. package/dist/config.d.ts +24 -0
  133. package/dist/config.js +39 -5
  134. package/dist/consolidated-quote.d.ts +109 -15
  135. package/dist/consolidated-quote.js +310 -52
  136. package/dist/execution.d.ts +346 -0
  137. package/dist/execution.js +428 -0
  138. package/dist/hyperliquid-execution.js +2 -3
  139. package/dist/index.d.ts +3 -0
  140. package/dist/index.js +3 -0
  141. package/dist/lifi-execution-guard.d.ts +13 -2
  142. package/dist/lifi-execution-guard.js +4 -0
  143. package/dist/near-intents.js +2 -3
  144. package/dist/pre-quote.d.ts +6 -6
  145. package/dist/pre-quote.js +10 -14
  146. package/dist/providers.d.ts +17 -0
  147. package/dist/providers.js +6 -0
  148. package/dist/referral.d.ts +12 -4
  149. package/dist/referral.js +12 -4
  150. package/dist/relay-depository.d.ts +2 -0
  151. package/dist/relay-depository.js +82 -0
  152. package/dist/relay-quote.js +2 -3
  153. package/dist/routing/candidate.d.ts +3 -3
  154. package/dist/routing/candidate.js +3 -3
  155. package/dist/routing/carriers/ask-answer.d.ts +19 -0
  156. package/dist/routing/carriers/omnibridge.js +23 -21
  157. package/dist/routing/carriers/pulsex-paths.d.ts +80 -0
  158. package/dist/routing/carriers/pulsex-paths.js +92 -0
  159. package/dist/routing/carriers/pulsex-split.d.ts +175 -0
  160. package/dist/routing/carriers/pulsex-split.js +185 -0
  161. package/dist/routing/carriers/pulsex.d.ts +69 -21
  162. package/dist/routing/carriers/pulsex.js +184 -65
  163. package/dist/routing/composed-route-quality.d.ts +28 -6
  164. package/dist/routing/composed-route-quality.js +36 -5
  165. package/dist/routing/entry-chain-anchor.d.ts +1 -1
  166. package/dist/routing/entry-chain-anchor.js +1 -1
  167. package/dist/routing/index.d.ts +7 -3
  168. package/dist/routing/index.js +7 -3
  169. package/dist/routing/producers.js +1 -1
  170. package/dist/routing/providers.d.ts +5 -0
  171. package/dist/routing/providers.js +5 -0
  172. package/dist/routing/search/graph.d.ts +29 -0
  173. package/dist/routing/search/plan-route-data.d.ts +25 -0
  174. package/dist/routing/search/plan-route-data.js +43 -7
  175. package/dist/routing/search/score.d.ts +33 -1
  176. package/dist/routing/search/score.js +41 -6
  177. package/dist/routing/swap-transactions.d.ts +91 -0
  178. package/dist/routing/swap-transactions.js +125 -0
  179. package/dist/settings.d.ts +94 -1
  180. package/dist/settings.js +95 -3
  181. package/dist/ton-connect.d.ts +98 -0
  182. package/dist/ton-connect.js +200 -0
  183. package/dist/ton-execution.d.ts +4 -114
  184. package/dist/ton-execution.js +4 -244
  185. package/dist/ton.d.ts +37 -0
  186. package/dist/ton.js +65 -0
  187. package/docs/examples/example-a-ether-to-pulse.ts +300 -0
  188. package/docs/examples/example-b-token-pulsechain-to-ethereum.ts +270 -0
  189. package/docs/examples/shared.ts +261 -0
  190. package/docs/examples/tsconfig.json +18 -0
  191. package/docs/integration-guide.md +617 -0
  192. package/ecosystems/package.json +6 -0
  193. package/execution/package.json +6 -0
  194. package/fee-type/package.json +6 -0
  195. package/hyperliquid-execution/package.json +6 -0
  196. package/image-links/package.json +6 -0
  197. package/lifi-execution-guard/package.json +6 -0
  198. package/llms.txt +234 -0
  199. package/near-intents/package.json +6 -0
  200. package/near-intents-route/package.json +6 -0
  201. package/origin-deposit/package.json +6 -0
  202. package/package.json +818 -10
  203. package/pre-quote/package.json +6 -0
  204. package/prices/package.json +6 -0
  205. package/providers/package.json +6 -0
  206. package/quote-fees/package.json +6 -0
  207. package/referral/package.json +6 -0
  208. package/relay-currencies/package.json +6 -0
  209. package/relay-quote/package.json +6 -0
  210. package/route-steps/package.json +6 -0
  211. package/routing/package.json +6 -0
  212. package/settings/package.json +6 -0
  213. package/ton/package.json +6 -0
  214. package/ton-connect/package.json +6 -0
  215. package/ton-execution/package.json +6 -0
  216. package/tron-execution/package.json +6 -0
  217. package/types/package.json +6 -0
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseLifiPreQuote = exports.parseRelayPreQuote = exports.buildLifiPreQuoteRequest = exports.buildRelayPreQuoteRequest = exports.lifiRequestHeaders = exports.lifiQuoteUrl = void 0;
4
+ const url_1 = require("@gibs/common/url");
5
+ const consolidated_quote_js_1 = require("./consolidated-quote.js");
6
+ const referral_js_1 = require("./referral.js");
7
+ const relay_quote_js_1 = require("./relay-quote.js");
8
+ /**
9
+ * Plain LI.FI swap quote endpoint (forward-solving), re-exported from
10
+ * `consolidated-quote.js` rather than redeclared here — both modules must
11
+ * agree on the same address, and a second literal would be free to drift from
12
+ * it.
13
+ */
14
+ var consolidated_quote_js_2 = require("./consolidated-quote.js");
15
+ Object.defineProperty(exports, "lifiQuoteUrl", { enumerable: true, get: function () { return consolidated_quote_js_2.lifiQuoteUrl; } });
16
+ Object.defineProperty(exports, "lifiRequestHeaders", { enumerable: true, get: function () { return consolidated_quote_js_2.lifiRequestHeaders; } });
17
+ /**
18
+ * Builds the Relay EXACT_INPUT swap pre-quote body for a fixed input. NO `txs`
19
+ * are attached: Relay solves FORWARD and reports the delivered anchor amount.
20
+ *
21
+ * `recipient` and `refundTo` name TWO DIFFERENT chains and must never be
22
+ * conflated. `refundTo` is always the user's OWN origin-chain address — Relay
23
+ * refunds a failed (or, here, never-run) swap on the origin chain, and an
24
+ * Ethereum fallback address could not receive one there. `recipient` names
25
+ * where the swap lands on the ENTRY chain (`toChainId`), which is always
26
+ * Ethereum Virtual Machine — for an Ethereum origin the user's own address
27
+ * already satisfies that and is the default; for a non-Ethereum origin
28
+ * (Solana base58, Bitcoin bech32, ...) it does NOT, and Relay's `/quote/v2`
29
+ * validates the recipient's FORMAT against `toChainId` even though this
30
+ * pre-quote never executes. Sending the origin account there — as an earlier
31
+ * version of this builder did, reasoning that an unexecuted quote's recipient
32
+ * is "informational" — gets Relay's `400 INVALID_ADDRESS` on every
33
+ * non-Ethereum-origin pre-quote, which starves `fetchBestEntryAnchorPreQuote`
34
+ * of its only capable provider and surfaces as "No route available" for the
35
+ * whole non-Ethereum-origin flow. `request.recipient` (an explicit
36
+ * Ethereum-format address the caller supplies) is therefore REQUIRED for a
37
+ * non-Ethereum origin; without it this returns null.
38
+ *
39
+ * @param request - the provider-agnostic pre-quote request
40
+ * @returns the request body, or null when the input amount is non-positive or
41
+ * a non-Ethereum origin has no explicit Ethereum-format `recipient`
42
+ */
43
+ const buildRelayPreQuoteRequest = (request) => {
44
+ if (request.amount <= 0n) {
45
+ return null;
46
+ }
47
+ const nonEthereumOrigin = (0, consolidated_quote_js_1.isNonEthereumVirtualMachineOrigin)(request);
48
+ // A non-Ethereum origin's own address cannot stand in for an entry-chain
49
+ // recipient; it must be supplied explicitly. An Ethereum origin's own
50
+ // address already IS a valid entry-chain address, so it remains the default.
51
+ const recipient = nonEthereumOrigin ? request.recipient : (request.recipient ?? request.fromAddress);
52
+ if (recipient === undefined) {
53
+ return null;
54
+ }
55
+ return {
56
+ user: request.fromAddress,
57
+ originChainId: request.fromChainId,
58
+ originCurrency: request.fromTokenAddress,
59
+ destinationChainId: request.toChainId,
60
+ destinationCurrency: request.toTokenAddress,
61
+ amount: request.amount.toString(),
62
+ tradeType: 'EXACT_INPUT',
63
+ recipient,
64
+ // Relay always refunds on the ORIGIN chain, so the origin's own address
65
+ // is the correct refund target regardless of ecosystem — unlike
66
+ // `recipient` above, this one is deliberately NOT Ethereum-format for a
67
+ // non-Ethereum origin.
68
+ refundTo: request.fromAddress,
69
+ ...(0, relay_quote_js_1.relayReferrerField)(request),
70
+ ...(request.slippage === undefined
71
+ ? {}
72
+ : { slippageTolerance: (0, relay_quote_js_1.slippageToBasisPoints)(request.slippage) }),
73
+ };
74
+ };
75
+ exports.buildRelayPreQuoteRequest = buildRelayPreQuoteRequest;
76
+ /**
77
+ * Builds the plain LI.FI swap pre-quote as a query string for `GET /v1/quote`.
78
+ * LI.FI's plain `/quote` is forward-solving by construction (`fromAmount` in,
79
+ * `estimate.toAmount` out), so no trade-type flag is needed.
80
+ *
81
+ * Returns null for a non-Ethereum origin (LI.FI cannot bridge across
82
+ * virtual-machine ecosystems) and for a non-positive input amount.
83
+ *
84
+ * @param request - the provider-agnostic pre-quote request
85
+ * @returns the URL query string (without a leading `?`), or null
86
+ */
87
+ const buildLifiPreQuoteRequest = (request) => {
88
+ if (request.amount <= 0n) {
89
+ return null;
90
+ }
91
+ if ((0, consolidated_quote_js_1.isNonEthereumVirtualMachineOrigin)(request)) {
92
+ return null;
93
+ }
94
+ // Left out or `null` OMITS the query parameter (LI.FI's own schema marks it
95
+ // optional); a string is sent as-is. No package default: attribution is the
96
+ // caller's to choose. See `PreQuoteRequest.lifiIntegrator`'s doc.
97
+ const integrator = (0, referral_js_1.resolveAttribution)(request.lifiIntegrator, undefined);
98
+ return (0, url_1.buildQuery)({
99
+ fromChain: request.fromChainId.toString(),
100
+ toChain: request.toChainId.toString(),
101
+ fromToken: request.fromTokenAddress,
102
+ toToken: request.toTokenAddress,
103
+ fromAmount: request.amount.toString(),
104
+ fromAddress: request.fromAddress,
105
+ // Each optional parameter is left out when it is undefined.
106
+ integrator,
107
+ slippage: request.slippage?.toString(),
108
+ });
109
+ };
110
+ exports.buildLifiPreQuoteRequest = buildLifiPreQuoteRequest;
111
+ const asRecord = (value) => {
112
+ if (typeof value !== 'object' || value === null) {
113
+ return null;
114
+ }
115
+ return value;
116
+ };
117
+ /**
118
+ * Parses a decimal-string amount into a bigint.
119
+ *
120
+ * @returns the bigint value, or null when the input is not a parseable amount
121
+ */
122
+ const parseAmount = (value) => {
123
+ if (typeof value !== 'string' || value === '') {
124
+ return null;
125
+ }
126
+ try {
127
+ return BigInt(value);
128
+ }
129
+ catch {
130
+ return null;
131
+ }
132
+ };
133
+ /**
134
+ * Assembles the expected/minimum pair, defaulting the minimum to the expected
135
+ * amount when the provider omits a guaranteed floor. Shared by both parsers so
136
+ * the fallback rule lives in exactly one place.
137
+ *
138
+ * @returns the result, or null when the expected amount is absent
139
+ */
140
+ const toPreQuoteResult = (expected, minimum) => {
141
+ const expectedAmount = parseAmount(expected);
142
+ if (expectedAmount === null) {
143
+ return null;
144
+ }
145
+ const minimumAmount = parseAmount(minimum);
146
+ return {
147
+ expectedAmount,
148
+ minimumAmount: minimumAmount ?? expectedAmount,
149
+ };
150
+ };
151
+ /**
152
+ * Parses a Relay EXACT_INPUT pre-quote response. The delivered anchor figures
153
+ * live under `details.currencyOut`: `amount` (expected) and `minimumAmount`
154
+ * (guaranteed slippage floor). Verified live against `api.relay.link/quote/v2`.
155
+ *
156
+ * @returns the delivered amounts, or null when the payload shape is unexpected
157
+ */
158
+ const parseRelayPreQuote = (payload) => {
159
+ const currencyOut = asRecord(asRecord(asRecord(payload)?.details)?.currencyOut);
160
+ if (!currencyOut) {
161
+ return null;
162
+ }
163
+ return toPreQuoteResult(currencyOut.amount, currencyOut.minimumAmount);
164
+ };
165
+ exports.parseRelayPreQuote = parseRelayPreQuote;
166
+ /**
167
+ * Parses a plain LI.FI `/quote` response. The delivered anchor figures live
168
+ * under `estimate`: `toAmount` (expected) and `toAmountMin` (guaranteed minimum
169
+ * after slippage) — the same estimate shape the route-step normalizer reads.
170
+ *
171
+ * @returns the delivered amounts, or null when the payload shape is unexpected
172
+ */
173
+ const parseLifiPreQuote = (payload) => {
174
+ const estimate = asRecord(asRecord(payload)?.estimate);
175
+ if (!estimate) {
176
+ return null;
177
+ }
178
+ return toPreQuoteResult(estimate.toAmount, estimate.toAmountMin);
179
+ };
180
+ exports.parseLifiPreQuote = parseLifiPreQuote;
@@ -0,0 +1,107 @@
1
+ import { type Hex } from 'viem';
2
+ import type { Token } from './types.js';
3
+ /**
4
+ * PulseChain mainnet numeric chain id (`Chains.PLS` = `0x171`). Tokens on this
5
+ * chain (and its testnet sibling below) are priced on-chain via PulseX rather
6
+ * than from an off-chain price feed.
7
+ */
8
+ export declare const PULSECHAIN_CHAIN_ID: number;
9
+ /**
10
+ * PulseChain V4 testnet numeric chain id (`Chains.V4PLS` = `0x3af`). Shares the
11
+ * PulseX on-chain pricing path with mainnet.
12
+ */
13
+ export declare const PULSECHAIN_TESTNET_CHAIN_ID: number;
14
+ /**
15
+ * Bridged DAI on PulseChain (18 decimals) — the USD anchor stablecoin for
16
+ * on-chain PulseX pricing. One token's `getAmountsOut` ending in this address
17
+ * yields that token's USD price directly (DAI is treated as exactly $1).
18
+ *
19
+ * Kept as an exported constant so the anchor can be swapped without touching the
20
+ * pricing math. Mirrors `DAI_ADDRESS` in `packages/tx-report/src/server/prices.ts`.
21
+ */
22
+ export declare const PULSECHAIN_USD_ANCHOR_ADDRESS: Hex;
23
+ /** Decimals of the {@link PULSECHAIN_USD_ANCHOR_ADDRESS} stablecoin. */
24
+ export declare const PULSECHAIN_USD_ANCHOR_DECIMALS = 18;
25
+ /** Wrapped PLS on PulseChain — the routing intermediary for PulseX paths. */
26
+ export declare const WPLS_ADDRESS: `0x${string}`;
27
+ /** Lowercases an address for case-insensitive map keys and comparisons. */
28
+ export declare const lowercaseAddress: (address: string) => string;
29
+ /**
30
+ * Map key for a foreign (LI.FI-priced) token: `${chainId}-${lowercased address}`.
31
+ * Matches the key the UI builds when assembling the LI.FI price map.
32
+ */
33
+ export declare const lifiPriceKey: (chainId: number, address: string) => string;
34
+ /** True when a chain id is priced on-chain via PulseX (mainnet or V4 testnet). */
35
+ export declare const isPulsechain: (chainId: number) => boolean;
36
+ /**
37
+ * The PulseChain-origin address a bridged token backs out to, when the token's
38
+ * `extensions.bridgeInfo` records a PulseChain counterpart. Bridged tokens are
39
+ * 1:1 with their origin, so the origin's PulseX price is the token's USD value.
40
+ *
41
+ * @param token - the token whose PulseChain-origin link to resolve
42
+ * @returns the PulseChain origin address, or null when the token has no such link
43
+ */
44
+ export declare const pulsechainOriginAddress: (token: Token) => Hex | null;
45
+ /**
46
+ * The set of PulseX swap paths to price one whole unit of `token` into the USD
47
+ * anchor stablecoin. Edge cases collapse to shorter paths:
48
+ *
49
+ * - `token` is the stablecoin itself -> no swap needed (priced as exactly 1).
50
+ * - `token` is WPLS (or the native zero-address) -> `[WPLS, stable]` only.
51
+ * - otherwise -> both `[token, WPLS, stable]` and `[token, stable]`.
52
+ *
53
+ * Returned addresses are always concrete (the native sentinel is rewritten to
54
+ * WPLS) so they can be fed straight into `getAmountsOut`.
55
+ *
56
+ * @param options.token - the token (only its address is read) to build paths for
57
+ * @param options.wpls - the wrapped-native intermediary (defaults to {@link WPLS_ADDRESS})
58
+ * @param options.stable - the USD anchor (defaults to {@link PULSECHAIN_USD_ANCHOR_ADDRESS})
59
+ * @returns `{ paths }` — the candidate paths; empty when the token is the stablecoin
60
+ */
61
+ export declare const pulsexPricePaths: ({ token, wpls, stable, }: {
62
+ token: Pick<Token, "address">;
63
+ wpls?: Hex;
64
+ stable?: Hex;
65
+ }) => {
66
+ paths: Hex[][];
67
+ };
68
+ /**
69
+ * A single `getAmountsOut` outcome: the decoded `bigint[]` on success, or raw
70
+ * `Hex` return data when the (allowFailure) call reverted. Mirrors the
71
+ * `multicallRead` return shape so results can be passed in untransformed.
72
+ */
73
+ export type AmountsOutResult = bigint[] | Hex;
74
+ /**
75
+ * Reduces every `getAmountsOut` result (across all paths and all routers for one
76
+ * token) to a single USD price by taking the MAX final output, then scaling out
77
+ * of the stablecoin's decimals. Failed/empty results are dropped; when none
78
+ * succeed the price is null (no liquidity).
79
+ *
80
+ * @param options.results - the `getAmountsOut` outcomes for the token's paths/routers
81
+ * @param options.stableDecimals - decimals of the anchor (defaults to {@link PULSECHAIN_USD_ANCHOR_DECIMALS})
82
+ * @returns the USD price as a number, or null when no path produced a value
83
+ */
84
+ export declare const computeUsdPriceFromAmountsOut: ({ results, stableDecimals, }: {
85
+ results: readonly AmountsOutResult[];
86
+ stableDecimals?: number;
87
+ }) => number | null;
88
+ /**
89
+ * Resolves a token's USD price using pre-fetched price maps, following the
90
+ * co-designed precedence:
91
+ *
92
+ * 1. PulseChain (mainnet or V4 testnet): the token's own PulseX price.
93
+ * 2. Bridged PulseChain-origin token: the origin's PulseX price (1:1 value).
94
+ * 3. Genuinely foreign token: the LI.FI inline price.
95
+ *
96
+ * The stablecoin anchor itself resolves to exactly 1. All address lookups are
97
+ * case-insensitive (maps are keyed by lowercased address).
98
+ *
99
+ * @param token - the token to price
100
+ * @param options.pulsexPrices - lowercased PulseChain address -> USD price
101
+ * @param options.lifiPrices - `${chainId}-${lowercased address}` -> USD price
102
+ * @returns the USD price as a number, or null when no source can price it
103
+ */
104
+ export declare const resolveTokenPriceUsd: (token: Token, { pulsexPrices, lifiPrices, }: {
105
+ pulsexPrices: Map<string, number>;
106
+ lifiPrices: Map<string, number>;
107
+ }) => number | null;
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveTokenPriceUsd = exports.computeUsdPriceFromAmountsOut = exports.pulsexPricePaths = exports.pulsechainOriginAddress = exports.isPulsechain = exports.lifiPriceKey = exports.lowercaseAddress = exports.WPLS_ADDRESS = exports.PULSECHAIN_USD_ANCHOR_DECIMALS = exports.PULSECHAIN_USD_ANCHOR_ADDRESS = exports.PULSECHAIN_TESTNET_CHAIN_ID = exports.PULSECHAIN_CHAIN_ID = void 0;
4
+ const viem_1 = require("viem");
5
+ const config_js_1 = require("./config.js");
6
+ /**
7
+ * PulseChain mainnet numeric chain id (`Chains.PLS` = `0x171`). Tokens on this
8
+ * chain (and its testnet sibling below) are priced on-chain via PulseX rather
9
+ * than from an off-chain price feed.
10
+ */
11
+ exports.PULSECHAIN_CHAIN_ID = Number(config_js_1.Chains.PLS);
12
+ /**
13
+ * PulseChain V4 testnet numeric chain id (`Chains.V4PLS` = `0x3af`). Shares the
14
+ * PulseX on-chain pricing path with mainnet.
15
+ */
16
+ exports.PULSECHAIN_TESTNET_CHAIN_ID = Number(config_js_1.Chains.V4PLS);
17
+ /**
18
+ * Bridged DAI on PulseChain (18 decimals) — the USD anchor stablecoin for
19
+ * on-chain PulseX pricing. One token's `getAmountsOut` ending in this address
20
+ * yields that token's USD price directly (DAI is treated as exactly $1).
21
+ *
22
+ * Kept as an exported constant so the anchor can be swapped without touching the
23
+ * pricing math. Mirrors `DAI_ADDRESS` in `packages/tx-report/src/server/prices.ts`.
24
+ */
25
+ exports.PULSECHAIN_USD_ANCHOR_ADDRESS = '0xefd766ccb38eaf1dfd701853bfce31359239f305';
26
+ /** Decimals of the {@link PULSECHAIN_USD_ANCHOR_ADDRESS} stablecoin. */
27
+ exports.PULSECHAIN_USD_ANCHOR_DECIMALS = 18;
28
+ /** Wrapped PLS on PulseChain — the routing intermediary for PulseX paths. */
29
+ exports.WPLS_ADDRESS = config_js_1.nativeAssetOut[config_js_1.Chains.PLS];
30
+ /** The native (gas) token sentinel address used across the dapp. */
31
+ const NATIVE_TOKEN_ADDRESS = '0x0000000000000000000000000000000000000000';
32
+ /** Lowercases an address for case-insensitive map keys and comparisons. */
33
+ const lowercaseAddress = (address) => address.toLowerCase();
34
+ exports.lowercaseAddress = lowercaseAddress;
35
+ /** True when two addresses are equal ignoring case (and 0x-checksum casing). */
36
+ const sameAddress = (left, right) => (0, exports.lowercaseAddress)(left) === (0, exports.lowercaseAddress)(right);
37
+ /**
38
+ * Map key for a foreign (LI.FI-priced) token: `${chainId}-${lowercased address}`.
39
+ * Matches the key the UI builds when assembling the LI.FI price map.
40
+ */
41
+ const lifiPriceKey = (chainId, address) => `${chainId}-${(0, exports.lowercaseAddress)(address)}`;
42
+ exports.lifiPriceKey = lifiPriceKey;
43
+ /** True when a chain id is priced on-chain via PulseX (mainnet or V4 testnet). */
44
+ const isPulsechain = (chainId) => chainId === exports.PULSECHAIN_CHAIN_ID || chainId === exports.PULSECHAIN_TESTNET_CHAIN_ID;
45
+ exports.isPulsechain = isPulsechain;
46
+ /**
47
+ * The PulseChain-origin address a bridged token backs out to, when the token's
48
+ * `extensions.bridgeInfo` records a PulseChain counterpart. Bridged tokens are
49
+ * 1:1 with their origin, so the origin's PulseX price is the token's USD value.
50
+ *
51
+ * @param token - the token whose PulseChain-origin link to resolve
52
+ * @returns the PulseChain origin address, or null when the token has no such link
53
+ */
54
+ const pulsechainOriginAddress = (token) => {
55
+ const link = token.extensions?.bridgeInfo?.[exports.PULSECHAIN_CHAIN_ID];
56
+ if (!link) {
57
+ return null;
58
+ }
59
+ return link.tokenAddress;
60
+ };
61
+ exports.pulsechainOriginAddress = pulsechainOriginAddress;
62
+ /**
63
+ * The set of PulseX swap paths to price one whole unit of `token` into the USD
64
+ * anchor stablecoin. Edge cases collapse to shorter paths:
65
+ *
66
+ * - `token` is the stablecoin itself -> no swap needed (priced as exactly 1).
67
+ * - `token` is WPLS (or the native zero-address) -> `[WPLS, stable]` only.
68
+ * - otherwise -> both `[token, WPLS, stable]` and `[token, stable]`.
69
+ *
70
+ * Returned addresses are always concrete (the native sentinel is rewritten to
71
+ * WPLS) so they can be fed straight into `getAmountsOut`.
72
+ *
73
+ * @param options.token - the token (only its address is read) to build paths for
74
+ * @param options.wpls - the wrapped-native intermediary (defaults to {@link WPLS_ADDRESS})
75
+ * @param options.stable - the USD anchor (defaults to {@link PULSECHAIN_USD_ANCHOR_ADDRESS})
76
+ * @returns `{ paths }` — the candidate paths; empty when the token is the stablecoin
77
+ */
78
+ const pulsexPricePaths = ({ token, wpls = exports.WPLS_ADDRESS, stable = exports.PULSECHAIN_USD_ANCHOR_ADDRESS, }) => {
79
+ const address = sameAddress(token.address, NATIVE_TOKEN_ADDRESS) ? wpls : token.address;
80
+ if (sameAddress(address, stable)) {
81
+ return { paths: [] };
82
+ }
83
+ if (sameAddress(address, wpls)) {
84
+ return { paths: [[wpls, stable]] };
85
+ }
86
+ return {
87
+ paths: [
88
+ [address, wpls, stable],
89
+ [address, stable],
90
+ ],
91
+ };
92
+ };
93
+ exports.pulsexPricePaths = pulsexPricePaths;
94
+ /**
95
+ * The final output amount of one `getAmountsOut` result, or null when the call
96
+ * failed (Hex) or returned an empty array. The last element of a `bigint[]`
97
+ * `getAmountsOut` is the output-token amount.
98
+ */
99
+ const finalOutput = (result) => {
100
+ if (typeof result === 'string') {
101
+ return null;
102
+ }
103
+ if (result.length === 0) {
104
+ return null;
105
+ }
106
+ return result[result.length - 1];
107
+ };
108
+ /**
109
+ * Reduces every `getAmountsOut` result (across all paths and all routers for one
110
+ * token) to a single USD price by taking the MAX final output, then scaling out
111
+ * of the stablecoin's decimals. Failed/empty results are dropped; when none
112
+ * succeed the price is null (no liquidity).
113
+ *
114
+ * @param options.results - the `getAmountsOut` outcomes for the token's paths/routers
115
+ * @param options.stableDecimals - decimals of the anchor (defaults to {@link PULSECHAIN_USD_ANCHOR_DECIMALS})
116
+ * @returns the USD price as a number, or null when no path produced a value
117
+ */
118
+ const computeUsdPriceFromAmountsOut = ({ results, stableDecimals = exports.PULSECHAIN_USD_ANCHOR_DECIMALS, }) => {
119
+ const outputs = results.flatMap((result) => {
120
+ const output = finalOutput(result);
121
+ return output === null ? [] : [output];
122
+ });
123
+ if (outputs.length === 0) {
124
+ return null;
125
+ }
126
+ const maxOutput = outputs.reduce((max, current) => (current > max ? current : max), 0n);
127
+ if (maxOutput === 0n) {
128
+ return null;
129
+ }
130
+ return Number((0, viem_1.formatUnits)(maxOutput, stableDecimals));
131
+ };
132
+ exports.computeUsdPriceFromAmountsOut = computeUsdPriceFromAmountsOut;
133
+ /**
134
+ * Resolves a token's USD price using pre-fetched price maps, following the
135
+ * co-designed precedence:
136
+ *
137
+ * 1. PulseChain (mainnet or V4 testnet): the token's own PulseX price.
138
+ * 2. Bridged PulseChain-origin token: the origin's PulseX price (1:1 value).
139
+ * 3. Genuinely foreign token: the LI.FI inline price.
140
+ *
141
+ * The stablecoin anchor itself resolves to exactly 1. All address lookups are
142
+ * case-insensitive (maps are keyed by lowercased address).
143
+ *
144
+ * @param token - the token to price
145
+ * @param options.pulsexPrices - lowercased PulseChain address -> USD price
146
+ * @param options.lifiPrices - `${chainId}-${lowercased address}` -> USD price
147
+ * @returns the USD price as a number, or null when no source can price it
148
+ */
149
+ const resolveTokenPriceUsd = (token, { pulsexPrices, lifiPrices, }) => {
150
+ if ((0, exports.isPulsechain)(token.chainId)) {
151
+ if (sameAddress(token.address, exports.PULSECHAIN_USD_ANCHOR_ADDRESS)) {
152
+ return 1;
153
+ }
154
+ return pulsexPrices.get((0, exports.lowercaseAddress)(token.address)) ?? null;
155
+ }
156
+ const origin = (0, exports.pulsechainOriginAddress)(token);
157
+ if (origin) {
158
+ if (sameAddress(origin, exports.PULSECHAIN_USD_ANCHOR_ADDRESS)) {
159
+ return 1;
160
+ }
161
+ // Prefer the bridged origin's on-chain PulseX price. Fall back to the token's
162
+ // OWN home-chain LI.FI inline price when PulseX cannot price it — a bridged
163
+ // major (e.g. wrapped ether / wrapped binance coin) whose PulseChain pool path
164
+ // returns nothing would otherwise resolve to null despite a well-known market
165
+ // price on its home chain.
166
+ return (pulsexPrices.get((0, exports.lowercaseAddress)(origin)) ??
167
+ lifiPrices.get((0, exports.lifiPriceKey)(token.chainId, token.address)) ??
168
+ null);
169
+ }
170
+ return lifiPrices.get((0, exports.lifiPriceKey)(token.chainId, token.address)) ?? null;
171
+ };
172
+ exports.resolveTokenPriceUsd = resolveTokenPriceUsd;