@gibs/bridge-sdk 1.13.1 → 1.18.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 (228) hide show
  1. package/README.md +295 -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 +255 -0
  28. package/dist/cjs/config.js +569 -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 +359 -0
  36. package/dist/cjs/execution.js +495 -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 +24 -0
  44. package/dist/cjs/index.js +40 -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 +117 -0
  59. package/dist/cjs/prices.js +224 -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/carrier-provider-key.d.ts +31 -0
  81. package/dist/cjs/routing/carrier-provider-key.js +42 -0
  82. package/dist/cjs/routing/carriers/ask-answer.d.ts +77 -0
  83. package/dist/cjs/routing/carriers/ask-answer.js +2 -0
  84. package/dist/cjs/routing/carriers/omnibridge.d.ts +137 -0
  85. package/dist/cjs/routing/carriers/omnibridge.js +459 -0
  86. package/dist/cjs/routing/carriers/pulsex-paths.d.ts +80 -0
  87. package/dist/cjs/routing/carriers/pulsex-paths.js +97 -0
  88. package/dist/cjs/routing/carriers/pulsex-split.d.ts +175 -0
  89. package/dist/cjs/routing/carriers/pulsex-split.js +193 -0
  90. package/dist/cjs/routing/carriers/pulsex.d.ts +184 -0
  91. package/dist/cjs/routing/carriers/pulsex.js +615 -0
  92. package/dist/cjs/routing/carriers/wrap.d.ts +25 -0
  93. package/dist/cjs/routing/carriers/wrap.js +119 -0
  94. package/dist/cjs/routing/composed-route-quality.d.ts +125 -0
  95. package/dist/cjs/routing/composed-route-quality.js +144 -0
  96. package/dist/cjs/routing/entry-chain-anchor.d.ts +88 -0
  97. package/dist/cjs/routing/entry-chain-anchor.js +59 -0
  98. package/dist/cjs/routing/format.d.ts +31 -0
  99. package/dist/cjs/routing/format.js +64 -0
  100. package/dist/cjs/routing/index.d.ts +42 -0
  101. package/dist/cjs/routing/index.js +142 -0
  102. package/dist/cjs/routing/producers.d.ts +770 -0
  103. package/dist/cjs/routing/producers.js +1617 -0
  104. package/dist/cjs/routing/providers.d.ts +31 -0
  105. package/dist/cjs/routing/providers.js +48 -0
  106. package/dist/cjs/routing/route-data.d.ts +397 -0
  107. package/dist/cjs/routing/route-data.js +2 -0
  108. package/dist/cjs/routing/search/compose.d.ts +168 -0
  109. package/dist/cjs/routing/search/compose.js +104 -0
  110. package/dist/cjs/routing/search/graph.d.ts +668 -0
  111. package/dist/cjs/routing/search/graph.js +461 -0
  112. package/dist/cjs/routing/search/plan-route-data.d.ts +285 -0
  113. package/dist/cjs/routing/search/plan-route-data.js +871 -0
  114. package/dist/cjs/routing/search/score.d.ts +356 -0
  115. package/dist/cjs/routing/search/score.js +445 -0
  116. package/dist/cjs/routing/swap-transactions.d.ts +95 -0
  117. package/dist/cjs/routing/swap-transactions.js +133 -0
  118. package/dist/cjs/routing/usd-value.d.ts +17 -0
  119. package/dist/cjs/routing/usd-value.js +29 -0
  120. package/dist/cjs/settings.d.ts +785 -0
  121. package/dist/cjs/settings.js +1074 -0
  122. package/dist/cjs/swap-venues.d.ts +43 -0
  123. package/dist/cjs/swap-venues.js +29 -0
  124. package/dist/cjs/ton-connect.d.ts +98 -0
  125. package/dist/cjs/ton-connect.js +206 -0
  126. package/dist/cjs/ton-execution.d.ts +7 -0
  127. package/dist/cjs/ton-execution.js +23 -0
  128. package/dist/cjs/ton.d.ts +37 -0
  129. package/dist/cjs/ton.js +83 -0
  130. package/dist/cjs/tron-execution.d.ts +146 -0
  131. package/dist/cjs/tron-execution.js +248 -0
  132. package/dist/cjs/types.d.ts +51 -0
  133. package/dist/cjs/types.js +2 -0
  134. package/dist/claims.d.ts +198 -0
  135. package/dist/claims.js +140 -0
  136. package/dist/config.d.ts +42 -3
  137. package/dist/config.js +87 -21
  138. package/dist/consolidated-quote.d.ts +109 -15
  139. package/dist/consolidated-quote.js +310 -52
  140. package/dist/execution.d.ts +359 -0
  141. package/dist/execution.js +455 -0
  142. package/dist/hyperliquid-execution.js +2 -3
  143. package/dist/index.d.ts +4 -0
  144. package/dist/index.js +4 -0
  145. package/dist/lifi-execution-guard.d.ts +13 -2
  146. package/dist/lifi-execution-guard.js +4 -0
  147. package/dist/near-intents.js +2 -3
  148. package/dist/pre-quote.d.ts +6 -6
  149. package/dist/pre-quote.js +10 -14
  150. package/dist/prices.d.ts +10 -0
  151. package/dist/prices.js +52 -1
  152. package/dist/providers.d.ts +17 -0
  153. package/dist/providers.js +6 -0
  154. package/dist/referral.d.ts +12 -4
  155. package/dist/referral.js +12 -4
  156. package/dist/relay-depository.d.ts +2 -0
  157. package/dist/relay-depository.js +82 -0
  158. package/dist/relay-quote.js +2 -3
  159. package/dist/routing/candidate.d.ts +3 -3
  160. package/dist/routing/candidate.js +3 -3
  161. package/dist/routing/carrier-provider-key.d.ts +31 -0
  162. package/dist/routing/carrier-provider-key.js +37 -0
  163. package/dist/routing/carriers/ask-answer.d.ts +17 -0
  164. package/dist/routing/carriers/omnibridge.js +23 -21
  165. package/dist/routing/carriers/pulsex-paths.d.ts +80 -0
  166. package/dist/routing/carriers/pulsex-paths.js +92 -0
  167. package/dist/routing/carriers/pulsex-split.d.ts +175 -0
  168. package/dist/routing/carriers/pulsex-split.js +185 -0
  169. package/dist/routing/carriers/pulsex.d.ts +81 -46
  170. package/dist/routing/carriers/pulsex.js +267 -148
  171. package/dist/routing/composed-route-quality.d.ts +28 -6
  172. package/dist/routing/composed-route-quality.js +36 -5
  173. package/dist/routing/entry-chain-anchor.d.ts +1 -1
  174. package/dist/routing/entry-chain-anchor.js +1 -1
  175. package/dist/routing/index.d.ts +11 -3
  176. package/dist/routing/index.js +8 -2
  177. package/dist/routing/producers.js +1 -1
  178. package/dist/routing/providers.d.ts +5 -0
  179. package/dist/routing/providers.js +5 -0
  180. package/dist/routing/route-data.d.ts +47 -5
  181. package/dist/routing/search/graph.d.ts +15 -0
  182. package/dist/routing/search/plan-route-data.d.ts +42 -1
  183. package/dist/routing/search/plan-route-data.js +68 -9
  184. package/dist/routing/search/score.d.ts +3 -0
  185. package/dist/routing/search/score.js +11 -3
  186. package/dist/routing/swap-transactions.d.ts +95 -0
  187. package/dist/routing/swap-transactions.js +127 -0
  188. package/dist/settings.d.ts +94 -1
  189. package/dist/settings.js +95 -3
  190. package/dist/swap-venues.d.ts +43 -0
  191. package/dist/swap-venues.js +24 -0
  192. package/dist/ton-connect.d.ts +98 -0
  193. package/dist/ton-connect.js +200 -0
  194. package/dist/ton-execution.d.ts +4 -114
  195. package/dist/ton-execution.js +4 -244
  196. package/dist/ton.d.ts +37 -0
  197. package/dist/ton.js +65 -0
  198. package/docs/examples/example-a-ether-to-pulse.ts +300 -0
  199. package/docs/examples/example-b-token-pulsechain-to-ethereum.ts +270 -0
  200. package/docs/examples/shared.ts +261 -0
  201. package/docs/examples/tsconfig.json +18 -0
  202. package/docs/integration-guide.md +617 -0
  203. package/ecosystems/package.json +6 -0
  204. package/execution/package.json +6 -0
  205. package/fee-type/package.json +6 -0
  206. package/hyperliquid-execution/package.json +6 -0
  207. package/image-links/package.json +6 -0
  208. package/lifi-execution-guard/package.json +6 -0
  209. package/llms.txt +75 -10
  210. package/near-intents/package.json +6 -0
  211. package/near-intents-route/package.json +6 -0
  212. package/origin-deposit/package.json +6 -0
  213. package/package.json +817 -10
  214. package/pre-quote/package.json +6 -0
  215. package/prices/package.json +6 -0
  216. package/providers/package.json +6 -0
  217. package/quote-fees/package.json +6 -0
  218. package/referral/package.json +6 -0
  219. package/relay-currencies/package.json +6 -0
  220. package/relay-quote/package.json +6 -0
  221. package/route-steps/package.json +6 -0
  222. package/routing/package.json +6 -0
  223. package/settings/package.json +6 -0
  224. package/ton/package.json +6 -0
  225. package/ton-connect/package.json +6 -0
  226. package/ton-execution/package.json +6 -0
  227. package/tron-execution/package.json +6 -0
  228. package/types/package.json +6 -0
@@ -0,0 +1,198 @@
1
+ import { type Hex } from 'viem';
2
+ import type { PlannedTx } from './execution.js';
3
+ /**
4
+ * MANUAL CLAIMS. A home-to-foreign crossing (PulseChain to Ethereum, for
5
+ * example) ends with a release on the destination chain. When nobody delivers
6
+ * it, the reader claims it by hand: they send the validators' signatures and
7
+ * the encoded message to the destination bridge. This module builds that
8
+ * transaction from the bridge indexer's `UserRequest` record.
9
+ *
10
+ * THE INDEXER ASSUMPTION. The indexer collects the signatures in
11
+ * `handleSignedFor` (`packages/indexer/src/index.ts`, the handler for
12
+ * `HomeAMB:SignedForUserRequest` and `HomeAMB:SignedForAffirmation`). It does
13
+ * not read the signature from the event. It decodes the TRANSACTION's own
14
+ * input as `submitSignature(bytes signature, bytes message)`. That works only
15
+ * when a validator sends `submitSignature` straight to the home bridge from
16
+ * its own account.
17
+ *
18
+ * When a validator signs some other way (through a multisig wallet, a proxy,
19
+ * a batching contract, or any call whose top-level input is not
20
+ * `submitSignature`), the decode fails and the handler drops that signature.
21
+ * It still counts it: `confirmedSignatures` goes up by one, but `signatures`
22
+ * stays one short. `finishedSigning` does NOT stay false. The separate
23
+ * `HomeAMB:CollectedSignatures` event sets it to true regardless. So the
24
+ * record says "signed" while it holds too few signatures, and a claim built
25
+ * from it reverts on the destination bridge, which checks the count against
26
+ * its required-signature threshold. {@link buildClaimTransaction} refuses
27
+ * that record with `signatures-incomplete` rather than build a claim that
28
+ * cannot succeed.
29
+ */
30
+ /** A signature split into the three parts the destination bridge reads, each as hex without a `0x` prefix. */
31
+ export type SignatureParts = {
32
+ readonly v: string;
33
+ readonly r: string;
34
+ readonly s: string;
35
+ };
36
+ /**
37
+ * Splits one 65-byte validator signature into its `v`, `r` and `s` parts.
38
+ *
39
+ * @param rawSignature - the signature as the indexer stores it, with or without a `0x` prefix
40
+ * @returns the three parts, hex without prefixes
41
+ */
42
+ export declare const signatureToVRS: (rawSignature: string) => SignatureParts;
43
+ /**
44
+ * Packs signatures in the layout the bridge's `executeSignatures` reads: one
45
+ * count byte, then every `v`, then every `r`, then every `s`.
46
+ *
47
+ * @param signatures - the split signatures, in the order the validators signed
48
+ * @returns the packed signatures as one hex string
49
+ */
50
+ export declare const packSignatures: (signatures: readonly SignatureParts[]) => Hex;
51
+ /**
52
+ * The calldata for a release that pays no delivery tip: a direct call to the
53
+ * destination bridge.
54
+ *
55
+ * @param options.encodedData - the bridge message, `UserRequest.encodedData`
56
+ * @param options.encodedSignatures - the output of {@link packSignatures}
57
+ * @returns the calldata for `safeExecuteSignaturesWithAutoGasLimit`
58
+ */
59
+ export declare const encodeReleaseWithoutTipData: ({ encodedData, encodedSignatures, }: {
60
+ encodedData: Hex;
61
+ encodedSignatures: Hex;
62
+ }) => Hex;
63
+ /**
64
+ * The calldata for a release sent through the pathway's destination output
65
+ * router, the path a fee-director (delivery) request uses.
66
+ *
67
+ * @param options.validator - the pathway's validator contract
68
+ * @param options.encodedData - the bridge message, `UserRequest.encodedData`
69
+ * @param options.encodedSignatures - the output of {@link packSignatures}
70
+ * @returns the calldata for the router's `safeExecuteSignaturesWithAutoGasLimit`
71
+ */
72
+ export declare const encodeReleaseToRouterData: ({ validator, encodedData, encodedSignatures, }: {
73
+ validator: Hex;
74
+ encodedData: Hex;
75
+ encodedSignatures: Hex;
76
+ }) => Hex;
77
+ /**
78
+ * Where a claim is sent.
79
+ *
80
+ * - `direct` sends it to the destination bridge and pays no delivery tip.
81
+ * - `router` sends it through the pathway's destination output router, which
82
+ * pays the tip a fee-director request carries. Read both addresses from the
83
+ * pathway (`pathway(bridgeKey)`'s `destinationRouter` and `validator`).
84
+ */
85
+ export type ClaimRoute = {
86
+ readonly kind: 'direct';
87
+ } | {
88
+ readonly kind: 'router';
89
+ readonly destinationRouter: Hex;
90
+ readonly validator: Hex;
91
+ };
92
+ /**
93
+ * The one place a claim's target and calldata come from. The interface's
94
+ * release hook and {@link buildClaimTransaction} both call it.
95
+ *
96
+ * @param options.encodedData - the bridge message
97
+ * @param options.signatures - the raw validator signatures, in signing order
98
+ * @param options.destinationAmbAddress - the destination bridge, used by the `direct` route
99
+ * @param options.via - which contract receives the claim
100
+ * @returns the target contract and the calldata
101
+ */
102
+ export declare const claimCall: ({ encodedData, signatures, destinationAmbAddress, via, }: {
103
+ readonly encodedData: Hex;
104
+ readonly signatures: readonly string[];
105
+ readonly destinationAmbAddress: Hex;
106
+ readonly via: ClaimRoute;
107
+ }) => {
108
+ readonly to: Hex;
109
+ readonly data: Hex;
110
+ };
111
+ /**
112
+ * The bridge indexer's `UserRequest` fields a claim reads. The names match the
113
+ * indexer's GraphQL type, so a caller passes the record it fetched as it is.
114
+ * The indexer sends its big-integer scalars as decimal strings, so the counts
115
+ * and the chain id accept a string as well.
116
+ */
117
+ export type ClaimableUserRequest = {
118
+ /** `'signature'` for a home-to-foreign request. Only those are claimed by hand. */
119
+ readonly type: string;
120
+ readonly encodedData: string;
121
+ /** The JSON list of raw validator signatures, or null on a request type that collects none. */
122
+ readonly signatures?: unknown;
123
+ /** How many `SignedFor` events the indexer counted for this request. */
124
+ readonly confirmedSignatures: bigint | number | string;
125
+ /**
126
+ * The bridge's required-signature threshold in force for this request, as
127
+ * the indexer links it. When absent, the builder demands every counted
128
+ * signature, which is stricter than the bridge.
129
+ */
130
+ readonly requiredSignatures?: {
131
+ readonly value: bigint | number | string;
132
+ } | null;
133
+ readonly destinationAmbAddress: string;
134
+ readonly destinationChainId: bigint | number | string;
135
+ /** True once the indexer saw `CollectedSignatures` (or the delivery itself). */
136
+ readonly finishedSigning: boolean;
137
+ /** True once the release executed on the destination chain. */
138
+ readonly delivered: boolean;
139
+ };
140
+ /**
141
+ * Why a request cannot be claimed. Each case names a different action for the
142
+ * reader:
143
+ *
144
+ * - `wrong-type` — not a signature request. An affirmation request is
145
+ * executed by the validators themselves; there is nothing to claim.
146
+ * - `already-delivered` — the release already executed. A claim would revert.
147
+ * - `not-signed-yet` — the validators have not finished signing. Wait.
148
+ * - `signatures-incomplete` — the indexer stored fewer signatures than the
149
+ * bridge needs (the threshold, or every counted signature when the request
150
+ * carries no threshold). See this module's note on the `submitSignature`
151
+ * assumption. Waiting does not fix this one.
152
+ * - `malformed-request` — a field is not the shape the indexer documents.
153
+ */
154
+ export type ClaimRefusal = {
155
+ readonly reason: 'wrong-type';
156
+ readonly type: string;
157
+ } | {
158
+ readonly reason: 'already-delivered';
159
+ } | {
160
+ readonly reason: 'not-signed-yet';
161
+ } | {
162
+ readonly reason: 'signatures-incomplete';
163
+ readonly stored: number;
164
+ readonly needed: number;
165
+ } | {
166
+ readonly reason: 'malformed-request';
167
+ readonly field: string;
168
+ };
169
+ /** A claim transaction, or the typed reason none can be built. */
170
+ export type ClaimPlan = {
171
+ readonly kind: 'claim';
172
+ readonly transaction: PlannedTx;
173
+ } | {
174
+ readonly kind: 'refused';
175
+ readonly refusal: ClaimRefusal;
176
+ };
177
+ /**
178
+ * Builds the manual-claim transaction for one bridge request, or refuses with
179
+ * a typed reason.
180
+ *
181
+ * The checks run in this order: request type, delivery, signing, then the
182
+ * stored signature count. A delivered request is refused before the signing
183
+ * check, because delivery also sets `finishedSigning`.
184
+ *
185
+ * ASSUMPTION: the signatures are only complete when every validator sent
186
+ * `submitSignature` directly to the home bridge. The indexer drops a
187
+ * signature sent any other way; see this module's head note. This builder
188
+ * catches the drop by comparing the stored list with the required-signature
189
+ * threshold, or with `confirmedSignatures` when the record carries no threshold.
190
+ *
191
+ * @param options.request - the indexer's `UserRequest` record
192
+ * @param options.via - the claim target; see {@link ClaimRoute}
193
+ * @returns a `claim` plan whose transaction runs on the destination chain, or a refusal
194
+ */
195
+ export declare const buildClaimTransaction: ({ request, via, }: {
196
+ readonly request: ClaimableUserRequest;
197
+ readonly via: ClaimRoute;
198
+ }) => ClaimPlan;
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.buildClaimTransaction = exports.claimCall = exports.encodeReleaseToRouterData = exports.encodeReleaseWithoutTipData = exports.packSignatures = exports.signatureToVRS = void 0;
37
+ const viem_1 = require("viem");
38
+ const abis = __importStar(require("./abis.js"));
39
+ const strip0x = (input) => input.replace(/^0x/, '');
40
+ /**
41
+ * Splits one 65-byte validator signature into its `v`, `r` and `s` parts.
42
+ *
43
+ * @param rawSignature - the signature as the indexer stores it, with or without a `0x` prefix
44
+ * @returns the three parts, hex without prefixes
45
+ */
46
+ const signatureToVRS = (rawSignature) => {
47
+ const signature = strip0x(rawSignature);
48
+ const word = 32;
49
+ const word2 = word * 2;
50
+ const word4 = word2 * 2;
51
+ const r = signature.slice(0, word2);
52
+ const s = signature.slice(word2, word4);
53
+ const v = signature.slice(word4);
54
+ return { v, r, s };
55
+ };
56
+ exports.signatureToVRS = signatureToVRS;
57
+ /**
58
+ * Packs signatures in the layout the bridge's `executeSignatures` reads: one
59
+ * count byte, then every `v`, then every `r`, then every `s`.
60
+ *
61
+ * @param signatures - the split signatures, in the order the validators signed
62
+ * @returns the packed signatures as one hex string
63
+ */
64
+ const packSignatures = (signatures) => {
65
+ const length = strip0x((0, viem_1.numberToHex)(signatures.length));
66
+ const countByte = length.length === 1 ? `0${length}` : length;
67
+ const v = signatures.map((signature) => signature.v).join('');
68
+ const r = signatures.map((signature) => signature.r).join('');
69
+ const s = signatures.map((signature) => signature.s).join('');
70
+ return `0x${countByte}${v}${r}${s}`;
71
+ };
72
+ exports.packSignatures = packSignatures;
73
+ /**
74
+ * The calldata for a release that pays no delivery tip: a direct call to the
75
+ * destination bridge.
76
+ *
77
+ * @param options.encodedData - the bridge message, `UserRequest.encodedData`
78
+ * @param options.encodedSignatures - the output of {@link packSignatures}
79
+ * @returns the calldata for `safeExecuteSignaturesWithAutoGasLimit`
80
+ */
81
+ const encodeReleaseWithoutTipData = ({ encodedData, encodedSignatures, }) => (0, viem_1.encodeFunctionData)({
82
+ abi: abis.relayTokensDirect,
83
+ functionName: 'safeExecuteSignaturesWithAutoGasLimit',
84
+ args: [encodedData, encodedSignatures],
85
+ });
86
+ exports.encodeReleaseWithoutTipData = encodeReleaseWithoutTipData;
87
+ /**
88
+ * The calldata for a release sent through the pathway's destination output
89
+ * router, the path a fee-director (delivery) request uses.
90
+ *
91
+ * @param options.validator - the pathway's validator contract
92
+ * @param options.encodedData - the bridge message, `UserRequest.encodedData`
93
+ * @param options.encodedSignatures - the output of {@link packSignatures}
94
+ * @returns the calldata for the router's `safeExecuteSignaturesWithAutoGasLimit`
95
+ */
96
+ const encodeReleaseToRouterData = ({ validator, encodedData, encodedSignatures, }) => (0, viem_1.encodeFunctionData)({
97
+ abi: abis.outputRouter,
98
+ functionName: 'safeExecuteSignaturesWithAutoGasLimit',
99
+ args: [validator, encodedData, encodedSignatures],
100
+ });
101
+ exports.encodeReleaseToRouterData = encodeReleaseToRouterData;
102
+ /**
103
+ * The one place a claim's target and calldata come from. The interface's
104
+ * release hook and {@link buildClaimTransaction} both call it.
105
+ *
106
+ * @param options.encodedData - the bridge message
107
+ * @param options.signatures - the raw validator signatures, in signing order
108
+ * @param options.destinationAmbAddress - the destination bridge, used by the `direct` route
109
+ * @param options.via - which contract receives the claim
110
+ * @returns the target contract and the calldata
111
+ */
112
+ const claimCall = ({ encodedData, signatures, destinationAmbAddress, via, }) => {
113
+ const encodedSignatures = (0, exports.packSignatures)(signatures.map(exports.signatureToVRS));
114
+ if (via.kind === 'router') {
115
+ return {
116
+ to: via.destinationRouter,
117
+ data: (0, exports.encodeReleaseToRouterData)({ validator: via.validator, encodedData, encodedSignatures }),
118
+ };
119
+ }
120
+ return { to: destinationAmbAddress, data: (0, exports.encodeReleaseWithoutTipData)({ encodedData, encodedSignatures }) };
121
+ };
122
+ exports.claimCall = claimCall;
123
+ const isSignatureList = (value) => Array.isArray(value) && value.every((entry) => typeof entry === 'string' && (0, viem_1.isHex)(entry));
124
+ const refused = (refusal) => ({ kind: 'refused', refusal });
125
+ /**
126
+ * Builds the manual-claim transaction for one bridge request, or refuses with
127
+ * a typed reason.
128
+ *
129
+ * The checks run in this order: request type, delivery, signing, then the
130
+ * stored signature count. A delivered request is refused before the signing
131
+ * check, because delivery also sets `finishedSigning`.
132
+ *
133
+ * ASSUMPTION: the signatures are only complete when every validator sent
134
+ * `submitSignature` directly to the home bridge. The indexer drops a
135
+ * signature sent any other way; see this module's head note. This builder
136
+ * catches the drop by comparing the stored list with the required-signature
137
+ * threshold, or with `confirmedSignatures` when the record carries no threshold.
138
+ *
139
+ * @param options.request - the indexer's `UserRequest` record
140
+ * @param options.via - the claim target; see {@link ClaimRoute}
141
+ * @returns a `claim` plan whose transaction runs on the destination chain, or a refusal
142
+ */
143
+ const buildClaimTransaction = ({ request, via, }) => {
144
+ if (request.type !== 'signature')
145
+ return refused({ reason: 'wrong-type', type: request.type });
146
+ if (request.delivered)
147
+ return refused({ reason: 'already-delivered' });
148
+ if (!request.finishedSigning)
149
+ return refused({ reason: 'not-signed-yet' });
150
+ if (!isSignatureList(request.signatures))
151
+ return refused({ reason: 'malformed-request', field: 'signatures' });
152
+ if (!(0, viem_1.isHex)(request.encodedData))
153
+ return refused({ reason: 'malformed-request', field: 'encodedData' });
154
+ if (!(0, viem_1.isHex)(request.destinationAmbAddress)) {
155
+ return refused({ reason: 'malformed-request', field: 'destinationAmbAddress' });
156
+ }
157
+ const needed = Number(request.requiredSignatures?.value ?? request.confirmedSignatures);
158
+ const stored = request.signatures.length;
159
+ if (stored < needed)
160
+ return refused({ reason: 'signatures-incomplete', stored, needed });
161
+ const { to, data } = (0, exports.claimCall)({
162
+ encodedData: request.encodedData,
163
+ signatures: request.signatures,
164
+ destinationAmbAddress: request.destinationAmbAddress,
165
+ via,
166
+ });
167
+ return {
168
+ kind: 'claim',
169
+ transaction: {
170
+ chainId: Number(request.destinationChainId),
171
+ kind: 'claim',
172
+ to,
173
+ data,
174
+ value: 0n,
175
+ // The calldata itself asks the bridge to pick its own gas limit
176
+ // (`safeExecuteSignaturesWithAutoGasLimit`); the wallet estimates the rest.
177
+ gasLimit: null,
178
+ waitForReceipt: false,
179
+ },
180
+ };
181
+ };
182
+ exports.buildClaimTransaction = buildClaimTransaction;
@@ -0,0 +1,255 @@
1
+ import { type Hex } from 'viem';
2
+ import type { SwapVenues } from './swap-venues.js';
3
+ import type { BridgeKey, Token, TokenOut } from './types.js';
4
+ /**
5
+ * Add here your chain id as hex, be sure to add your chain in the chainsMetadata object too
6
+ */
7
+ export declare enum Chains {
8
+ PLS = "0x171",
9
+ ETH = "0x1",
10
+ BNB = "0x38",
11
+ SEP = "0xaa36a7",
12
+ V4PLS = "0x3af"
13
+ }
14
+ /** The key of a chain - human readable for query params */
15
+ export type ChainKey = keyof typeof Chains;
16
+ /** A map of chain ids to chain keys */
17
+ export declare const chainIdToKey: Map<Chains, "PLS" | "ETH" | "BNB" | "SEP" | "V4PLS">;
18
+ /**
19
+ * Converts a chain id to a chain key
20
+ * @param chainId - the chain id
21
+ * @returns the chain key
22
+ */
23
+ export declare const toChain: (chainId: number | string) => Chains;
24
+ /**
25
+ * Converts a chain id to a chain key
26
+ * @param chainId - the chain id
27
+ * @returns the chain key
28
+ */
29
+ export declare const toChainKey: (chainId: number | string) => "PLS" | "ETH" | "BNB" | "SEP" | "V4PLS" | undefined;
30
+ export declare const Providers: {
31
+ readonly PULSECHAIN: "pulsechain";
32
+ readonly TOKENSEX: "tokensex";
33
+ };
34
+ export type Provider = (typeof Providers)[keyof typeof Providers];
35
+ /** A map of chains to native asset out addresses */
36
+ export declare const nativeAssetOut: Record<Chains, Hex>;
37
+ /**
38
+ * Four PulseChain mainnet tokens that no other constant in this package
39
+ * names. The PulseX carrier routes swaps through them
40
+ * (`routing/carriers/pulsex-paths.ts`), and the interface builds its
41
+ * PulseChain hub nodes from the two stablecoins.
42
+ *
43
+ * Each address was already in the repository before it moved here: USDC and
44
+ * USDT from the interface's `HUB_STABLECOIN_ADDRESSES`
45
+ * (`packages/ui/src/lib/state/useRouteSearch.ts`), PLSX and HEX from
46
+ * `scripts/route-parity-corpus.ts`. Each one was read on chain again on
47
+ * 2026-10-06 (`symbol()`, `decimals()`): PLSX 18, HEX 8, USDC 6, USDT 6.
48
+ * `getAddress` checksums them at load, so a mistyped character fails the
49
+ * build rather than silently matching nothing.
50
+ */
51
+ export declare const pulsechainTokenAddresses: Readonly<{
52
+ /** PulseX, the exchange's own token. */
53
+ PLSX: `0x${string}`;
54
+ /** HEX. */
55
+ HEX: `0x${string}`;
56
+ /** USD Coin, bridged from Ethereum. */
57
+ USDC: `0x${string}`;
58
+ /** Tether USD, bridged from Ethereum. */
59
+ USDT: `0x${string}`;
60
+ }>;
61
+ /** A map of chains to deprecated native asset out addresses */
62
+ export declare const deprecatedNativeAssetOut: Partial<Record<Chains, Set<Hex>>>;
63
+ /**
64
+ * The swap venues the package ships with: PulseX V1 then V2 on PulseChain.
65
+ * Frozen. A caller who wants other routers passes its own
66
+ * {@link SwapVenues} (see `resolveSwapVenues`); this table is never mutated.
67
+ *
68
+ * Each factory is the router's own `router.factory()` read on chain — see
69
+ * {@link uniV2Factories}'s doc. The fee is 29 basis points for both
70
+ * deployments (measured, same doc).
71
+ */
72
+ export declare const defaultSwapVenues: SwapVenues;
73
+ /**
74
+ * A map of chains to uni v2 router addresses. Frozen. PulseChain's entries
75
+ * derive from {@link defaultSwapVenues}, so the two cannot drift. Kept for
76
+ * compatibility; to swap on other routers pass `swapVenues` instead.
77
+ */
78
+ export declare const uniV2Routers: Readonly<Record<Chains, readonly Hex[]>>;
79
+ /**
80
+ * Each {@link uniV2Routers} entry's OWN factory address, same index, same
81
+ * chain — `router.factory()` read live from `one.valve.city` on 2026-09-24.
82
+ * Only PulseChain mainnet is filled: PulseX carries funds nowhere else
83
+ * (`routing/carriers/pulsex.ts`'s own `pulseXCarries`), so no other chain's
84
+ * factory has ever been needed or verified.
85
+ *
86
+ * MEASURED, NOT ASSUMED (owner Rule 13). Reading each factory's `getPair`
87
+ * and the resulting pool's `getReserves`, then recomputing `getAmountsOut`
88
+ * from the standard constant-product formula, showed the SAME fee ratio for
89
+ * both — `9971/10000` (0.29%) — to the base unit, on both a one-hop and a
90
+ * two-hop path. "V1 and V2 differ" was the assumption going in; measurement
91
+ * said otherwise, so `routing/carriers/pulsex.ts`'s `exact` uses one shared
92
+ * fee constant rather than two.
93
+ *
94
+ * `0x1715a3E4A142d8b698131108995174F37aEBA10D` (the V1 factory, index 0) is
95
+ * NOT a copy-paste of the omnibridge's Ethereum mediator address from
96
+ * `pathways` above — it is the same string on a DIFFERENT chain (PulseChain,
97
+ * not Ethereum), confirmed by reading it fresh from `one.valve.city/…/evm/369`.
98
+ * Two unrelated contracts landing on the same address on two different
99
+ * chains is possible (a shared deployer at a matching nonce, or a CREATE2
100
+ * salt collision) and worth this note so a future reader does not assume a
101
+ * transcription error and "fix" it back to something wrong.
102
+ */
103
+ export declare const uniV2Factories: Readonly<Record<Chains, readonly Hex[]>>;
104
+ /** A map of chains to native token symbols */
105
+ export declare const nativeTokenSymbol: Record<Chains, string>;
106
+ /** A map of chains to native token names */
107
+ export declare const nativeTokenName: Record<Chains, string>;
108
+ /** The pathway of a bridge */
109
+ export type Pathway = {
110
+ from: Hex;
111
+ to: Hex;
112
+ destinationRouter: Hex | null;
113
+ nativeRouter: Hex;
114
+ validator: Hex;
115
+ usesExtraParam: boolean;
116
+ feeManager: 'from' | 'to';
117
+ toHome: boolean;
118
+ requiresDelivery: boolean;
119
+ bridgedNativeAssetOut: Hex;
120
+ settingOverrides?: Record<Hex, Partial<Pathway>>;
121
+ };
122
+ /** A map of providers to pathways */
123
+ export type DeepPathwayConfig = Record<Provider, Partial<Record<Chains, Partial<Record<Chains, Pathway>>>>>;
124
+ export declare const pathways: DeepPathwayConfig;
125
+ export declare const testnetPathways: DeepPathwayConfig;
126
+ /** Returns the valid bridge keys for the given is prod */
127
+ export declare const validBridgeKeys: (isProd: boolean) => BridgeKey[];
128
+ /**
129
+ * Whether a chain belongs to the testnet pathway map rather than the mainnet one.
130
+ * @param chain - the chain to classify
131
+ * @returns true for Sepolia and PulseChain testnet V4
132
+ */
133
+ export declare const isTestnetChain: (chain: Chains) => boolean;
134
+ /**
135
+ * Infers the bridge key from the current key, provider, from chain, and to chain.
136
+ *
137
+ * A chain the provider does not serve falls back to the provider's first chain,
138
+ * so a provider switch lands on a real pathway. That fallback never crosses
139
+ * between the testnet and mainnet maps: when testnets are off and a requested
140
+ * chain is a testnet chain, this returns null rather than a mainnet key for a
141
+ * testnet pair.
142
+ *
143
+ * @param options.currentKey - the current bridge key
144
+ * @param options.provider - the provider
145
+ * @param options.fromChain - the from chain (defaults to the current key's)
146
+ * @param options.toChain - the to chain (defaults to the current key's)
147
+ * @param options.isProd - true leaves testnet pathways out (default false: both maps)
148
+ * @returns the inferred bridge key, or null when no pathway can honour the request
149
+ */
150
+ export declare const inferBridgeKey: ({ currentKey, provider, fromChain, toChain, isProd, }: {
151
+ currentKey: BridgeKey;
152
+ provider: Provider;
153
+ fromChain?: Chains;
154
+ toChain?: Chains;
155
+ isProd?: boolean;
156
+ }) => BridgeKey | null;
157
+ /**
158
+ * Returns the pathway for the given bridge key, is prod, and asset in address
159
+ * @param bridgeKey - the bridge key
160
+ * @param isProd - whether to use the production pathway
161
+ * @param assetInAddress - the asset in address
162
+ * @returns the pathway
163
+ */
164
+ /**
165
+ * The pathway group for one provider on one chain, honouring the testnet map.
166
+ *
167
+ * Exists because {@link pathway} already knew that testnet pathways live in a
168
+ * SECOND map and are only in play off production, while other callers reached
169
+ * straight into `pathways` and therefore could not see a testnet route at all.
170
+ * That is the sort of knowledge that has to live in one place: duplicated, one
171
+ * copy silently lags the other, and the symptom is a thrown "no pathway found"
172
+ * on a route the rest of the application considers perfectly valid.
173
+ *
174
+ * @param provider - the bridge provider
175
+ * @param chain - the chain being bridged FROM
176
+ * @param isProd - whether this is a production build; testnets are off when true
177
+ * @returns the group keyed by destination chain, or undefined when unknown
178
+ */
179
+ export declare const pathwayGroup: (provider: Provider, chain: Chains, isProd: boolean) => Partial<Record<Chains, Pathway>> | undefined;
180
+ export declare const pathway: (bridgeKey: BridgeKey | null, isProd: boolean, assetInAddress?: string | Hex | null | undefined) => Pathway | undefined;
181
+ /**
182
+ * Returns the default asset in for the given bridge key and is prod
183
+ * @param bridgeKey - the bridge key
184
+ * @param isProd - whether to use the production pathway
185
+ * @returns the default asset in
186
+ */
187
+ export declare const defaultAssetIn: ($bridgeKey: BridgeKey | null, isProd: boolean) => `0x${string}` | null | undefined;
188
+ /** Which pathway maps a lookup reads. */
189
+ export type PathwayLookupOptions = {
190
+ /**
191
+ * true reads the mainnet map alone; false (the default) also reads the
192
+ * testnet map, which is what every caller did before this option existed.
193
+ */
194
+ isProd?: boolean;
195
+ };
196
+ /**
197
+ * Returns whether the given asset is the native asset for the given bridge key.
198
+ *
199
+ * Never throws. A token whose address is not known yet (a {@link TokenOut} for a
200
+ * not-yet-bridged token), an address that is not a valid address, and a bridge
201
+ * key with no pathway each answer false.
202
+ *
203
+ * @param asset - the asset
204
+ * @param bridgeKey - the bridge key
205
+ * @param options - which pathway maps to read; see {@link PathwayLookupOptions}
206
+ * @returns whether the given asset is the native asset for the given bridge key
207
+ */
208
+ export declare const isNative: (asset: Token | TokenOut | null, bridgeKey: BridgeKey | null, options?: PathwayLookupOptions) => boolean;
209
+ /**
210
+ * Returns whether the given asset is unwrappable for the given bridge key.
211
+ *
212
+ * Never throws: a missing or malformed address and a bridge key with no
213
+ * pathway each answer false.
214
+ *
215
+ * @param bridgeKey - the bridge key
216
+ * @param assetIn - the asset in
217
+ * @param options - which pathway maps to read; see {@link PathwayLookupOptions}
218
+ * @returns whether the given asset is unwrappable for the given bridge key
219
+ */
220
+ export declare const isUnwrappable: (bridgeKey: BridgeKey | null, assetIn: {
221
+ address: string | null;
222
+ } | null, options?: PathwayLookupOptions) => boolean;
223
+ /**
224
+ * Returns whether the given asset can be unwrapped for the given bridge key
225
+ * @param bridgeKey - the bridge key
226
+ * @param assetIn - the asset in
227
+ * @param options - which pathway maps to read; see {@link PathwayLookupOptions}
228
+ * @returns boolean
229
+ */
230
+ export declare const canChangeUnwrap: (bridgeKey: BridgeKey, assetIn: Token | null, options?: PathwayLookupOptions) => boolean;
231
+ export declare const chains: {
232
+ readonly ethereum: 1;
233
+ readonly bsc: 56;
234
+ readonly pulsechain: 369;
235
+ readonly pulsechainV4: 943;
236
+ readonly sepolia: 11155111;
237
+ };
238
+ export declare const chainIds: (1 | 56 | 369 | 943 | 11155111)[];
239
+ /** Start blocks aligned with when bridge validators began operating — canonical reference for all ponder indexers in this monorepo. */
240
+ export declare const startBlocks: Record<keyof typeof chains, number>;
241
+ export type ChainId = (typeof chainIds)[number];
242
+ export type Side = 'home' | 'foreign';
243
+ export type MinimalKey = `${ChainId}-${Hex}`;
244
+ export type PathwayInfo = {
245
+ pair: string;
246
+ key: string;
247
+ home: Hex;
248
+ foreign: Hex;
249
+ };
250
+ export type ProviderHomeChainEntry = Partial<Record<ChainId, PathwayInfo[]>>;
251
+ export type ProviderEntries = Partial<Record<ChainId, ProviderHomeChainEntry>>;
252
+ export type BridgeConfig = Record<Provider, ProviderEntries>;
253
+ export declare const bridgeConfigs: BridgeConfig;
254
+ export declare const HOME_TO_FOREIGN_FEE: `0x${string}`;
255
+ export declare const FOREIGN_TO_HOME_FEE: `0x${string}`;