lampamazaza-new-intents-sdk 0.47.1

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 (179) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1083 -0
  3. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  4. package/dist/index.cjs +124 -0
  5. package/dist/index.d.cts +22 -0
  6. package/dist/index.d.ts +22 -0
  7. package/dist/index.js +19 -0
  8. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.cjs +10 -0
  9. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.js +7 -0
  10. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +44 -0
  11. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.js +42 -0
  12. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +111 -0
  13. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +110 -0
  14. package/dist/src/bridges/direct-bridge/direct-bridge-constants.cjs +8 -0
  15. package/dist/src/bridges/direct-bridge/direct-bridge-constants.js +6 -0
  16. package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +47 -0
  17. package/dist/src/bridges/direct-bridge/direct-bridge-utils.js +44 -0
  18. package/dist/src/bridges/direct-bridge/direct-bridge.cjs +155 -0
  19. package/dist/src/bridges/direct-bridge/direct-bridge.js +154 -0
  20. package/dist/src/bridges/direct-bridge/error.cjs +16 -0
  21. package/dist/src/bridges/direct-bridge/error.d.cts +12 -0
  22. package/dist/src/bridges/direct-bridge/error.d.ts +12 -0
  23. package/dist/src/bridges/direct-bridge/error.js +15 -0
  24. package/dist/src/bridges/hot-bridge/error.cjs +23 -0
  25. package/dist/src/bridges/hot-bridge/error.d.cts +19 -0
  26. package/dist/src/bridges/hot-bridge/error.d.ts +19 -0
  27. package/dist/src/bridges/hot-bridge/error.js +21 -0
  28. package/dist/src/bridges/hot-bridge/hot-bridge-chains.cjs +21 -0
  29. package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.cts +6 -0
  30. package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.ts +6 -0
  31. package/dist/src/bridges/hot-bridge/hot-bridge-chains.js +20 -0
  32. package/dist/src/bridges/hot-bridge/hot-bridge-constants.cjs +11 -0
  33. package/dist/src/bridges/hot-bridge/hot-bridge-constants.js +9 -0
  34. package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +66 -0
  35. package/dist/src/bridges/hot-bridge/hot-bridge-utils.js +61 -0
  36. package/dist/src/bridges/hot-bridge/hot-bridge.cjs +241 -0
  37. package/dist/src/bridges/hot-bridge/hot-bridge.js +239 -0
  38. package/dist/src/bridges/intents-bridge/intents-bridge.cjs +59 -0
  39. package/dist/src/bridges/intents-bridge/intents-bridge.js +59 -0
  40. package/dist/src/bridges/omni-bridge/error.cjs +54 -0
  41. package/dist/src/bridges/omni-bridge/error.d.cts +41 -0
  42. package/dist/src/bridges/omni-bridge/error.d.ts +41 -0
  43. package/dist/src/bridges/omni-bridge/error.js +49 -0
  44. package/dist/src/bridges/omni-bridge/omni-bridge-constants.cjs +12 -0
  45. package/dist/src/bridges/omni-bridge/omni-bridge-constants.js +8 -0
  46. package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +153 -0
  47. package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +143 -0
  48. package/dist/src/bridges/omni-bridge/omni-bridge.cjs +316 -0
  49. package/dist/src/bridges/omni-bridge/omni-bridge.js +314 -0
  50. package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +76 -0
  51. package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +73 -0
  52. package/dist/src/bridges/poa-bridge/poa-bridge.cjs +175 -0
  53. package/dist/src/bridges/poa-bridge/poa-bridge.js +173 -0
  54. package/dist/src/bridges/poa-bridge/poa-constants.cjs +6 -0
  55. package/dist/src/bridges/poa-bridge/poa-constants.js +5 -0
  56. package/dist/src/classes/errors.cjs +87 -0
  57. package/dist/src/classes/errors.d.cts +48 -0
  58. package/dist/src/classes/errors.d.ts +48 -0
  59. package/dist/src/classes/errors.js +81 -0
  60. package/dist/src/constants/bridge-name-enum.cjs +11 -0
  61. package/dist/src/constants/bridge-name-enum.d.cts +11 -0
  62. package/dist/src/constants/bridge-name-enum.d.ts +11 -0
  63. package/dist/src/constants/bridge-name-enum.js +10 -0
  64. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
  65. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
  66. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
  67. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
  68. package/dist/src/constants/public-rpc-urls.cjs +25 -0
  69. package/dist/src/constants/public-rpc-urls.js +24 -0
  70. package/dist/src/constants/route-enum.cjs +13 -0
  71. package/dist/src/constants/route-enum.d.cts +13 -0
  72. package/dist/src/constants/route-enum.d.ts +13 -0
  73. package/dist/src/constants/route-enum.js +12 -0
  74. package/dist/src/constants/withdrawal-timing.cjs +68 -0
  75. package/dist/src/constants/withdrawal-timing.js +68 -0
  76. package/dist/src/core/withdrawal-watcher.cjs +86 -0
  77. package/dist/src/core/withdrawal-watcher.d.cts +18 -0
  78. package/dist/src/core/withdrawal-watcher.d.ts +19 -0
  79. package/dist/src/core/withdrawal-watcher.js +82 -0
  80. package/dist/src/intents/expirable-nonce.cjs +90 -0
  81. package/dist/src/intents/expirable-nonce.d.cts +44 -0
  82. package/dist/src/intents/expirable-nonce.d.ts +45 -0
  83. package/dist/src/intents/expirable-nonce.js +82 -0
  84. package/dist/src/intents/intent-executer-impl/intent-executer.cjs +85 -0
  85. package/dist/src/intents/intent-executer-impl/intent-executer.d.cts +20 -0
  86. package/dist/src/intents/intent-executer-impl/intent-executer.d.ts +24 -0
  87. package/dist/src/intents/intent-executer-impl/intent-executer.js +85 -0
  88. package/dist/src/intents/intent-hash.cjs +48 -0
  89. package/dist/src/intents/intent-hash.d.cts +8 -0
  90. package/dist/src/intents/intent-hash.d.ts +8 -0
  91. package/dist/src/intents/intent-hash.js +47 -0
  92. package/dist/src/intents/intent-hashes/erc191.cjs +38 -0
  93. package/dist/src/intents/intent-hashes/erc191.js +37 -0
  94. package/dist/src/intents/intent-hashes/nep413.cjs +23 -0
  95. package/dist/src/intents/intent-hashes/nep413.js +22 -0
  96. package/dist/src/intents/intent-hashes/raw-ed25519.cjs +26 -0
  97. package/dist/src/intents/intent-hashes/raw-ed25519.js +25 -0
  98. package/dist/src/intents/intent-hashes/sep53.cjs +36 -0
  99. package/dist/src/intents/intent-hashes/sep53.js +35 -0
  100. package/dist/src/intents/intent-hashes/tip191.cjs +39 -0
  101. package/dist/src/intents/intent-hashes/tip191.js +38 -0
  102. package/dist/src/intents/intent-hashes/ton-connect.cjs +105 -0
  103. package/dist/src/intents/intent-hashes/ton-connect.js +104 -0
  104. package/dist/src/intents/intent-hashes/webauthn.cjs +26 -0
  105. package/dist/src/intents/intent-hashes/webauthn.js +25 -0
  106. package/dist/src/intents/intent-payload-builder.cjs +208 -0
  107. package/dist/src/intents/intent-payload-builder.d.cts +161 -0
  108. package/dist/src/intents/intent-payload-builder.d.ts +161 -0
  109. package/dist/src/intents/intent-payload-builder.js +207 -0
  110. package/dist/src/intents/intent-payload-factory.cjs +23 -0
  111. package/dist/src/intents/intent-payload-factory.js +21 -0
  112. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +43 -0
  113. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +42 -0
  114. package/dist/src/intents/intent-signer-impl/factories.cjs +19 -0
  115. package/dist/src/intents/intent-signer-impl/factories.d.cts +11 -0
  116. package/dist/src/intents/intent-signer-impl/factories.d.ts +11 -0
  117. package/dist/src/intents/intent-signer-impl/factories.js +17 -0
  118. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +22 -0
  119. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.cts +15 -0
  120. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts +16 -0
  121. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.js +21 -0
  122. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +37 -0
  123. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.cts +14 -0
  124. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.ts +14 -0
  125. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.js +36 -0
  126. package/dist/src/intents/intent-signer-impl/intent-signer-noop.cjs +8 -0
  127. package/dist/src/intents/intent-signer-impl/intent-signer-noop.js +7 -0
  128. package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +31 -0
  129. package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.cts +17 -0
  130. package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.ts +17 -0
  131. package/dist/src/intents/intent-signer-impl/intent-signer-viem.js +30 -0
  132. package/dist/src/intents/interfaces/intent-executer.d.ts +2 -0
  133. package/dist/src/intents/interfaces/intent-relayer.d.cts +43 -0
  134. package/dist/src/intents/interfaces/intent-relayer.d.ts +43 -0
  135. package/dist/src/intents/interfaces/intent-signer.d.cts +8 -0
  136. package/dist/src/intents/interfaces/intent-signer.d.ts +8 -0
  137. package/dist/src/intents/interfaces/salt-manager.d.cts +9 -0
  138. package/dist/src/intents/interfaces/salt-manager.d.ts +9 -0
  139. package/dist/src/intents/salt-manager.cjs +74 -0
  140. package/dist/src/intents/salt-manager.js +72 -0
  141. package/dist/src/intents/shared-types.d.cts +20 -0
  142. package/dist/src/intents/shared-types.d.ts +20 -0
  143. package/dist/src/lib/array.cjs +11 -0
  144. package/dist/src/lib/array.js +10 -0
  145. package/dist/src/lib/caip2.cjs +50 -0
  146. package/dist/src/lib/caip2.d.cts +38 -0
  147. package/dist/src/lib/caip2.d.ts +38 -0
  148. package/dist/src/lib/caip2.js +48 -0
  149. package/dist/src/lib/configure-rpc-config.cjs +20 -0
  150. package/dist/src/lib/configure-rpc-config.js +18 -0
  151. package/dist/src/lib/estimate-fee.cjs +96 -0
  152. package/dist/src/lib/estimate-fee.js +94 -0
  153. package/dist/src/lib/hex.cjs +11 -0
  154. package/dist/src/lib/hex.js +10 -0
  155. package/dist/src/lib/nep413.cjs +42 -0
  156. package/dist/src/lib/nep413.d.cts +14 -0
  157. package/dist/src/lib/nep413.d.ts +14 -0
  158. package/dist/src/lib/nep413.js +41 -0
  159. package/dist/src/lib/object.cjs +10 -0
  160. package/dist/src/lib/object.js +9 -0
  161. package/dist/src/lib/parse-defuse-asset-id.cjs +15 -0
  162. package/dist/src/lib/parse-defuse-asset-id.js +14 -0
  163. package/dist/src/lib/route-config-factory.cjs +43 -0
  164. package/dist/src/lib/route-config-factory.d.cts +13 -0
  165. package/dist/src/lib/route-config-factory.d.ts +13 -0
  166. package/dist/src/lib/route-config-factory.js +37 -0
  167. package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +17 -0
  168. package/dist/src/lib/tokensUsdPricesHttpClient/apis.js +16 -0
  169. package/dist/src/lib/validateAddress.cjs +271 -0
  170. package/dist/src/lib/validateAddress.d.cts +14 -0
  171. package/dist/src/lib/validateAddress.d.ts +14 -0
  172. package/dist/src/lib/validateAddress.js +270 -0
  173. package/dist/src/sdk.cjs +435 -0
  174. package/dist/src/sdk.d.cts +231 -0
  175. package/dist/src/sdk.d.ts +231 -0
  176. package/dist/src/sdk.js +433 -0
  177. package/dist/src/shared-types.d.cts +378 -0
  178. package/dist/src/shared-types.d.ts +378 -0
  179. package/package.json +62 -0
@@ -0,0 +1,435 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_errors = require('./classes/errors.cjs');
3
+ const require_route_enum = require('./constants/route-enum.cjs');
4
+ const require_caip2 = require('./lib/caip2.cjs');
5
+ const require_aurora_engine_bridge = require('./bridges/aurora-engine-bridge/aurora-engine-bridge.cjs');
6
+ const require_direct_bridge = require('./bridges/direct-bridge/direct-bridge.cjs');
7
+ const require_hot_bridge_chains = require('./bridges/hot-bridge/hot-bridge-chains.cjs');
8
+ const require_hot_bridge = require('./bridges/hot-bridge/hot-bridge.cjs');
9
+ const require_intents_bridge = require('./bridges/intents-bridge/intents-bridge.cjs');
10
+ const require_omni_bridge = require('./bridges/omni-bridge/omni-bridge.cjs');
11
+ const require_poa_bridge = require('./bridges/poa-bridge/poa-bridge.cjs');
12
+ const require_public_rpc_urls = require('./constants/public-rpc-urls.cjs');
13
+ const require_expirable_nonce = require('./intents/expirable-nonce.cjs');
14
+ const require_intent_payload_factory = require('./intents/intent-payload-factory.cjs');
15
+ const require_intent_executer = require('./intents/intent-executer-impl/intent-executer.cjs');
16
+ const require_intent_relayer_public = require('./intents/intent-relayer-impl/intent-relayer-public.cjs');
17
+ const require_intent_signer_noop = require('./intents/intent-signer-impl/intent-signer-noop.cjs');
18
+ const require_array = require('./lib/array.cjs');
19
+ const require_configure_rpc_config = require('./lib/configure-rpc-config.cjs');
20
+ const require_withdrawal_watcher = require('./core/withdrawal-watcher.cjs');
21
+ const require_salt_manager = require('./intents/salt-manager.cjs');
22
+ const require_intent_payload_builder = require('./intents/intent-payload-builder.cjs');
23
+ let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
24
+ let _hot_labs_omni_sdk = require("@hot-labs/omni-sdk");
25
+ let viem = require("viem");
26
+ let valibot = require("valibot");
27
+ valibot = require_rolldown_runtime.__toESM(valibot);
28
+
29
+ //#region src/sdk.ts
30
+ var IntentsSDK = class {
31
+ constructor(args) {
32
+ this.envConfig = (0, lampamazaza_internal_utils.resolveEnvConfig)(args.env);
33
+ this.referral = args.referral;
34
+ this.solverRelayApiKey = args.solverRelayApiKey;
35
+ const nearRpcUrls = args.rpc?.[require_caip2.Chains.Near] ?? lampamazaza_internal_utils.PUBLIC_NEAR_RPC_URLS;
36
+ (0, lampamazaza_internal_utils.assert)(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
37
+ const nearProvider = (0, lampamazaza_internal_utils.nearFailoverRpcProvider)({ urls: nearRpcUrls });
38
+ const stellarRpcUrls = require_configure_rpc_config.configureStellarRpcUrls(require_public_rpc_urls.PUBLIC_STELLAR_RPC_URLS, args.rpc);
39
+ const evmRpcUrls = require_configure_rpc_config.configureEvmRpcUrls(require_public_rpc_urls.PUBLIC_EVM_RPC_URLS, args.rpc, require_hot_bridge_chains.HotBridgeEVMChains);
40
+ /**
41
+ * Order of bridges matters, because the first bridge that supports the `withdrawalParams` will be used.
42
+ * More specific bridges should be placed before more generic ones.
43
+ */
44
+ this.bridges = [
45
+ new require_intents_bridge.IntentsBridge(),
46
+ new require_aurora_engine_bridge.AuroraEngineBridge({
47
+ envConfig: this.envConfig,
48
+ nearProvider,
49
+ solverRelayApiKey: this.solverRelayApiKey
50
+ }),
51
+ new require_poa_bridge.PoaBridge({
52
+ envConfig: this.envConfig,
53
+ routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge
54
+ }),
55
+ new require_hot_bridge.HotBridge({
56
+ envConfig: this.envConfig,
57
+ solverRelayApiKey: this.solverRelayApiKey,
58
+ hotSdk: new _hot_labs_omni_sdk.HotBridge({
59
+ logger: console,
60
+ evmRpc: evmRpcUrls,
61
+ nearRpc: nearRpcUrls,
62
+ stellarRpc: stellarRpcUrls.soroban,
63
+ stellarHorizonRpc: stellarRpcUrls.horizon,
64
+ async executeNearTransaction() {
65
+ throw new Error("not implemented");
66
+ }
67
+ })
68
+ }),
69
+ new require_omni_bridge.OmniBridge({
70
+ envConfig: this.envConfig,
71
+ nearProvider,
72
+ solverRelayApiKey: this.solverRelayApiKey,
73
+ routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge
74
+ }),
75
+ new require_direct_bridge.DirectBridge({
76
+ envConfig: this.envConfig,
77
+ nearProvider,
78
+ solverRelayApiKey: this.solverRelayApiKey
79
+ })
80
+ ];
81
+ this.intentRelayer = new require_intent_relayer_public.IntentRelayerPublic({
82
+ envConfig: this.envConfig,
83
+ solverRelayApiKey: this.solverRelayApiKey
84
+ });
85
+ this.intentSigner = args.intentSigner;
86
+ this.saltManager = new require_salt_manager.SaltManager({
87
+ envConfig: this.envConfig,
88
+ nearProvider
89
+ });
90
+ }
91
+ setIntentSigner(signer) {
92
+ this.intentSigner = signer;
93
+ }
94
+ /**
95
+ * Create a new intent payload builder with environment context.
96
+ * Use this to build custom intent payloads for your API or advanced use cases.
97
+ *
98
+ * @returns A new IntentPayloadBuilder instance configured with the SDK's environment
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * // Build a custom intent payload
103
+ * const payload = await sdk.intentBuilder()
104
+ * .setSigner('0x1234...') // User's EVM address
105
+ * .setDeadline(new Date(Date.now() + 5 * 60 * 1000))
106
+ * .addIntent({
107
+ * intent: 'ft_withdraw',
108
+ * token: 'usdc.omft.near',
109
+ * amount: '1000000',
110
+ * receiver_id: 'user.near'
111
+ * })
112
+ * .build();
113
+ *
114
+ * // Return to user for signing with their preferred method (MetaMask, etc.)
115
+ * return payload;
116
+ * ```
117
+ */
118
+ intentBuilder() {
119
+ return new require_intent_payload_builder.IntentPayloadBuilder({
120
+ envConfig: this.envConfig,
121
+ saltManager: this.saltManager
122
+ });
123
+ }
124
+ /**
125
+ * Invalidate multiple nonces by creating and sending empty signed intents.
126
+ * This prevents previously created but unused intent payloads from being executed.
127
+ *
128
+ * For expirable nonces (versioned nonces with embedded deadlines), the intent's
129
+ * deadline is automatically set to the minimum of:
130
+ * 1. The nonce's embedded deadline (can't exceed this)
131
+ * 2. 1 minute from now (for quick invalidation when possible)
132
+ *
133
+ * @param args.nonces - Array of nonce strings to invalidate (up to 400 nonces per call, but depends on gas consumption)
134
+ * @param args.signer - Optional intent signer to use (defaults to SDK's configured signer)
135
+ * @param args.logger - Optional logger for debugging
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * // Invalidate unused nonces
140
+ * await sdk.invalidateNonces({
141
+ * nonces: ['nonce1', 'nonce2', 'nonce3']
142
+ * });
143
+ * ```
144
+ */
145
+ async invalidateNonces(args) {
146
+ if (args.nonces.length === 0) return;
147
+ const intentSigner = args.signer ?? this.intentSigner;
148
+ (0, lampamazaza_internal_utils.assert)(intentSigner != null, "Intent signer is not provided");
149
+ const signedIntents = await Promise.all(args.nonces.map(async (nonce) => {
150
+ const builder = this.intentBuilder().setNonce(nonce);
151
+ try {
152
+ const decoded = require_expirable_nonce.VersionedNonceBuilder.decodeNonce(nonce);
153
+ if (valibot.is(require_expirable_nonce.saltedNonceSchema, decoded.value)) {
154
+ const nonceDeadlineMs = Number(decoded.value.inner.deadline / 1000000n);
155
+ const nonceDeadline = new Date(nonceDeadlineMs);
156
+ const oneMinuteFromNow = new Date(Date.now() + require_intent_payload_factory.DEFAULT_DEADLINE_MS);
157
+ const deadline = oneMinuteFromNow < nonceDeadline ? oneMinuteFromNow : nonceDeadline;
158
+ builder.setDeadline(deadline);
159
+ } else args.logger?.warn?.("Decoded nonce has unexpected structure, using default deadline");
160
+ } catch {}
161
+ const { signed } = await builder.buildAndSign(intentSigner);
162
+ return signed;
163
+ }));
164
+ await this.intentRelayer.publishIntents({
165
+ multiPayloads: signedIntents,
166
+ quoteHashes: []
167
+ }, { logger: args.logger });
168
+ }
169
+ async createWithdrawalIntents(args) {
170
+ for (const bridge of this.bridges) if (await bridge.supports(args.withdrawalParams)) {
171
+ const actualAmount = args.withdrawalParams.feeInclusive ? args.withdrawalParams.amount - args.feeEstimation.amount : args.withdrawalParams.amount;
172
+ await bridge.validateWithdrawal({
173
+ assetId: args.withdrawalParams.assetId,
174
+ amount: actualAmount,
175
+ destinationAddress: args.withdrawalParams.destinationAddress,
176
+ feeEstimation: args.feeEstimation,
177
+ routeConfig: args.withdrawalParams.routeConfig,
178
+ logger: args.logger
179
+ });
180
+ return bridge.createWithdrawalIntents({
181
+ withdrawalParams: {
182
+ ...args.withdrawalParams,
183
+ amount: actualAmount
184
+ },
185
+ feeEstimation: args.feeEstimation,
186
+ referral: args.referral ?? this.referral
187
+ });
188
+ }
189
+ throw new Error(`Cannot determine bridge for withdrawal = ${(0, viem.stringify)(args.withdrawalParams)}`);
190
+ }
191
+ estimateWithdrawalFee(args) {
192
+ if (!Array.isArray(args.withdrawalParams)) return this._estimateWithdrawalFee({
193
+ ...args,
194
+ withdrawalParams: args.withdrawalParams
195
+ });
196
+ return Promise.all(args.withdrawalParams.map((withdrawalParams) => this._estimateWithdrawalFee({
197
+ ...args,
198
+ withdrawalParams
199
+ })));
200
+ }
201
+ async _estimateWithdrawalFee(args) {
202
+ for (const bridge of this.bridges) if (await bridge.supports(args.withdrawalParams)) {
203
+ const fee = await bridge.estimateWithdrawalFee({
204
+ withdrawalParams: args.withdrawalParams,
205
+ quoteOptions: args.quoteOptions,
206
+ logger: args.logger
207
+ });
208
+ if (args.withdrawalParams.feeInclusive) {
209
+ if (args.withdrawalParams.amount <= fee.amount) throw new require_errors.FeeExceedsAmountError(fee, args.withdrawalParams.amount);
210
+ }
211
+ return fee;
212
+ }
213
+ throw new Error(`Cannot determine bridge for withdrawal = ${(0, viem.stringify)(args.withdrawalParams)}`);
214
+ }
215
+ async waitForWithdrawalCompletion(args) {
216
+ const withdrawalParamsArray = Array.isArray(args.withdrawalParams) ? args.withdrawalParams : [args.withdrawalParams];
217
+ const promises = this.createWithdrawalCompletionPromises({
218
+ withdrawalParams: withdrawalParamsArray,
219
+ intentTx: args.intentTx,
220
+ signal: args.signal,
221
+ logger: args.logger
222
+ });
223
+ const result = await Promise.all(promises);
224
+ if (Array.isArray(args.withdrawalParams)) return result;
225
+ (0, lampamazaza_internal_utils.assert)(result.length === 1, "Unexpected result length");
226
+ return result[0];
227
+ }
228
+ /**
229
+ * Create promises that resolve when each withdrawal completes on the destination chain.
230
+ * Use this for granular control over handling individual withdrawals as they complete,
231
+ * rather than waiting for all to finish.
232
+ *
233
+ * **Important:** Each promise waits until the withdrawal completes, fails, or the
234
+ * chain-specific p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a
235
+ * shorter timeout budget.
236
+ *
237
+ * @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
238
+ * Inspect `error.cause` to determine the reason.
239
+ * @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
240
+ * @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
241
+ *
242
+ * @param params.withdrawalParams - Array of withdrawal parameters
243
+ * @param params.intentTx - The NEAR transaction info from the published intent
244
+ * @param params.signal - Optional AbortSignal for cancellation/timeout
245
+ * @param params.logger - Optional logger for debugging
246
+ * @returns Array of promises, one per withdrawal, that resolve with transaction info
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * const promises = sdk.createWithdrawalCompletionPromises({
251
+ * withdrawalParams: [withdrawal1, withdrawal2],
252
+ * intentTx,
253
+ * signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
254
+ * });
255
+ *
256
+ * // Handle each withdrawal as it completes
257
+ * for (const promise of promises) {
258
+ * promise.then((result) => console.log('Withdrawal completed:', result));
259
+ * }
260
+ * ```
261
+ */
262
+ createWithdrawalCompletionPromises(params) {
263
+ const { withdrawalParams, intentTx, signal, logger } = params;
264
+ const widsPromise = require_withdrawal_watcher.createWithdrawalIdentifiers({
265
+ bridges: this.bridges,
266
+ withdrawalParams,
267
+ intentTx
268
+ });
269
+ const hotChainLastPromise = /* @__PURE__ */ new Map();
270
+ return withdrawalParams.map(async (_, index) => {
271
+ const entry = (await widsPromise)[index];
272
+ (0, lampamazaza_internal_utils.assert)(entry != null, `Missing wid for index ${index}`);
273
+ if (entry.bridge.route === require_route_enum.RouteEnum.HotBridge) {
274
+ const landingChain = entry.wid.landingChain;
275
+ const previousPromise = hotChainLastPromise.get(landingChain);
276
+ const sequentialPromise = (async () => {
277
+ if (previousPromise) await Promise.allSettled([previousPromise]);
278
+ return require_withdrawal_watcher.watchWithdrawal({
279
+ bridge: entry.bridge,
280
+ wid: entry.wid,
281
+ signal,
282
+ logger
283
+ });
284
+ })();
285
+ hotChainLastPromise.set(landingChain, sequentialPromise);
286
+ return sequentialPromise;
287
+ }
288
+ return require_withdrawal_watcher.watchWithdrawal({
289
+ bridge: entry.bridge,
290
+ wid: entry.wid,
291
+ signal,
292
+ logger
293
+ });
294
+ });
295
+ }
296
+ parseAssetId(assetId) {
297
+ for (const bridge of this.bridges) {
298
+ const parsed = bridge.parseAssetId(assetId);
299
+ if (parsed != null) return parsed;
300
+ }
301
+ throw new Error(`Cannot determine bridge for assetId = ${assetId}`);
302
+ }
303
+ async sendSignedIntents(args) {
304
+ return { tickets: await this.intentRelayer.publishIntents({
305
+ multiPayloads: args.multiPayloads,
306
+ quoteHashes: args.quoteHashes ?? []
307
+ }, { logger: args.logger }) };
308
+ }
309
+ async signAndSendIntent(args) {
310
+ const intentSigner = args.signer ?? this.intentSigner;
311
+ (0, lampamazaza_internal_utils.assert)(intentSigner != null, "Intent signer is not provided");
312
+ const intentExecuter = new require_intent_executer.IntentExecuter({
313
+ envConfig: this.envConfig,
314
+ logger: args.logger,
315
+ intentSigner,
316
+ intentRelayer: this.intentRelayer,
317
+ intentPayloadFactory: args.payload,
318
+ onBeforePublishIntent: args.onBeforePublishIntent
319
+ });
320
+ const { ticket } = await this.withSaltRetry(args, async (salt) => intentExecuter.signAndSendIntent({
321
+ intents: args.intents,
322
+ salt,
323
+ relayParams: args.relayParams,
324
+ signedIntents: args.signedIntents
325
+ }));
326
+ return { intentHash: ticket };
327
+ }
328
+ async withSaltRetry(args, fn) {
329
+ try {
330
+ return await fn(await this.saltManager.getCachedSalt());
331
+ } catch (err) {
332
+ if (!(err instanceof lampamazaza_internal_utils.RelayPublishError && err.code === "INVALID_SALT")) throw err;
333
+ args.logger?.warn?.("Salt error detected. Refreshing salt and retrying");
334
+ return fn(await this.saltManager.refresh());
335
+ }
336
+ }
337
+ async signAndSendWithdrawalIntent(args) {
338
+ let withdrawalParamsArray;
339
+ let feeEstimations;
340
+ if (isBatchMode(args)) {
341
+ withdrawalParamsArray = args.withdrawalParams;
342
+ feeEstimations = args.feeEstimation;
343
+ } else {
344
+ withdrawalParamsArray = [args.withdrawalParams];
345
+ feeEstimations = [args.feeEstimation];
346
+ }
347
+ const intentsP = require_array.zip(withdrawalParamsArray, feeEstimations).map(([withdrawalParams, feeEstimation]) => {
348
+ return this.createWithdrawalIntents({
349
+ withdrawalParams,
350
+ feeEstimation,
351
+ referral: args.referral ?? this.referral,
352
+ logger: args.logger
353
+ });
354
+ });
355
+ const intents = (await Promise.all(intentsP)).flat();
356
+ const relayParamsFn = async () => {
357
+ const relayParams = args.intent?.relayParams != null ? await args.intent?.relayParams() : { quoteHashes: void 0 };
358
+ const quoteHashes = relayParams.quoteHashes ?? [];
359
+ for (const fee of feeEstimations) if (fee.quote != null) quoteHashes.push(fee.quote.quote_hash);
360
+ return {
361
+ ...relayParams,
362
+ quoteHashes
363
+ };
364
+ };
365
+ return this.signAndSendIntent({
366
+ intents,
367
+ signer: args.intent?.signer,
368
+ onBeforePublishIntent: args.intent?.onBeforePublishIntent,
369
+ relayParams: relayParamsFn,
370
+ payload: args.intent?.payload,
371
+ logger: args.logger,
372
+ signedIntents: args.intent?.signedIntents
373
+ });
374
+ }
375
+ async waitForIntentSettlement(args) {
376
+ const { tx } = await new require_intent_executer.IntentExecuter({
377
+ envConfig: this.envConfig,
378
+ logger: args.logger,
379
+ intentSigner: require_intent_signer_noop.noopIntentSigner,
380
+ intentRelayer: this.intentRelayer
381
+ }).waitForSettlement(args.intentHash, { signal: args.signal });
382
+ return tx;
383
+ }
384
+ async getIntentStatus({ intentHash, logger }) {
385
+ return lampamazaza_internal_utils.solverRelay.getStatus({ intent_hash: intentHash }, {
386
+ baseURL: this.envConfig.solverRelayBaseURL,
387
+ logger,
388
+ solverRelayApiKey: this.solverRelayApiKey
389
+ });
390
+ }
391
+ async processWithdrawal(args) {
392
+ const withdrawalParams = Array.isArray(args.withdrawalParams) ? args.withdrawalParams : [args.withdrawalParams];
393
+ const feeEstimation = await (() => {
394
+ if (args.feeEstimation != null) return Array.isArray(args.feeEstimation) ? args.feeEstimation : [args.feeEstimation];
395
+ return this.estimateWithdrawalFee({
396
+ withdrawalParams,
397
+ logger: args.logger
398
+ });
399
+ })();
400
+ const { intentHash } = await this.signAndSendWithdrawalIntent({
401
+ withdrawalParams,
402
+ feeEstimation,
403
+ referral: args.referral,
404
+ intent: args.intent,
405
+ logger: args.logger
406
+ });
407
+ const intentTx = await this.waitForIntentSettlement({
408
+ intentHash,
409
+ logger: args.logger
410
+ });
411
+ const destinationTx = await this.waitForWithdrawalCompletion({
412
+ withdrawalParams,
413
+ intentTx,
414
+ logger: args.logger
415
+ });
416
+ if (!Array.isArray(args.withdrawalParams)) return {
417
+ feeEstimation: feeEstimation[0],
418
+ intentHash,
419
+ intentTx,
420
+ destinationTx: destinationTx[0]
421
+ };
422
+ return {
423
+ feeEstimation,
424
+ intentHash,
425
+ intentTx,
426
+ destinationTx
427
+ };
428
+ }
429
+ };
430
+ function isBatchMode(args) {
431
+ return Array.isArray(args.withdrawalParams);
432
+ }
433
+
434
+ //#endregion
435
+ exports.IntentsSDK = IntentsSDK;
@@ -0,0 +1,231 @@
1
+ import { IntentHash, IntentPrimitive, MultiPayload } from "./intents/shared-types.cjs";
2
+ import { IIntentSigner } from "./intents/interfaces/intent-signer.cjs";
3
+ import { BatchWithdrawalResult, Bridge, CreateWithdrawalCompletionPromisesParams, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalParams, WithdrawalResult } from "./shared-types.cjs";
4
+ import { IIntentRelayer } from "./intents/interfaces/intent-relayer.cjs";
5
+ import { ISaltManager } from "./intents/interfaces/salt-manager.cjs";
6
+ import { IntentPayloadBuilder } from "./intents/intent-payload-builder.cjs";
7
+ import { EnvConfig, ILogger, NearIntentsEnv } from "lampamazaza-internal-utils";
8
+
9
+ //#region src/sdk.d.ts
10
+ interface IntentsSDKConfig {
11
+ /**
12
+ * Environment configuration. Can be:
13
+ * - "production" or "stage" to use preset configurations
14
+ * - A custom EnvConfig object for private environments
15
+ *
16
+ * Defaults to "production" if not specified.
17
+ *
18
+ * @example
19
+ * // Use preset
20
+ * new IntentsSDK({ env: "production", referral: "..." });
21
+ *
22
+ * // Use custom config for private environment
23
+ * new IntentsSDK({
24
+ * env: {
25
+ * contractID: "intents.private-shard",
26
+ * poaTokenFactoryContractID: "",
27
+ * poaBridgeBaseURL: "",
28
+ * solverRelayBaseURL: "https://private-relay.example.com",
29
+ * managerConsoleBaseURL: "",
30
+ * nearIntentsBaseURL: "",
31
+ * },
32
+ * referral: "...",
33
+ * });
34
+ */
35
+ env?: NearIntentsEnv | EnvConfig;
36
+ intentSigner?: IIntentSigner;
37
+ rpc?: PartialRPCEndpointMap;
38
+ referral: string;
39
+ solverRelayApiKey?: string;
40
+ features?: {
41
+ /**
42
+ * Route migrated POA tokens (*.omft.near) through Omni Bridge.
43
+ * Enable this to use Omni Bridge for POA tokens that have been migrated to the Omni infrastructure.
44
+ */
45
+ routeMigratedPoaTokensThroughOmniBridge?: boolean;
46
+ };
47
+ }
48
+ declare class IntentsSDK implements IIntentsSDK {
49
+ protected envConfig: EnvConfig;
50
+ protected referral: string;
51
+ protected intentRelayer: IIntentRelayer<IntentHash>;
52
+ protected intentSigner?: IIntentSigner;
53
+ protected bridges: Bridge[];
54
+ protected solverRelayApiKey: string | undefined;
55
+ protected saltManager: ISaltManager;
56
+ constructor(args: IntentsSDKConfig);
57
+ setIntentSigner(signer: IIntentSigner): void;
58
+ /**
59
+ * Create a new intent payload builder with environment context.
60
+ * Use this to build custom intent payloads for your API or advanced use cases.
61
+ *
62
+ * @returns A new IntentPayloadBuilder instance configured with the SDK's environment
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // Build a custom intent payload
67
+ * const payload = await sdk.intentBuilder()
68
+ * .setSigner('0x1234...') // User's EVM address
69
+ * .setDeadline(new Date(Date.now() + 5 * 60 * 1000))
70
+ * .addIntent({
71
+ * intent: 'ft_withdraw',
72
+ * token: 'usdc.omft.near',
73
+ * amount: '1000000',
74
+ * receiver_id: 'user.near'
75
+ * })
76
+ * .build();
77
+ *
78
+ * // Return to user for signing with their preferred method (MetaMask, etc.)
79
+ * return payload;
80
+ * ```
81
+ */
82
+ intentBuilder(): IntentPayloadBuilder;
83
+ /**
84
+ * Invalidate multiple nonces by creating and sending empty signed intents.
85
+ * This prevents previously created but unused intent payloads from being executed.
86
+ *
87
+ * For expirable nonces (versioned nonces with embedded deadlines), the intent's
88
+ * deadline is automatically set to the minimum of:
89
+ * 1. The nonce's embedded deadline (can't exceed this)
90
+ * 2. 1 minute from now (for quick invalidation when possible)
91
+ *
92
+ * @param args.nonces - Array of nonce strings to invalidate (up to 400 nonces per call, but depends on gas consumption)
93
+ * @param args.signer - Optional intent signer to use (defaults to SDK's configured signer)
94
+ * @param args.logger - Optional logger for debugging
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // Invalidate unused nonces
99
+ * await sdk.invalidateNonces({
100
+ * nonces: ['nonce1', 'nonce2', 'nonce3']
101
+ * });
102
+ * ```
103
+ */
104
+ invalidateNonces(args: {
105
+ nonces: string[];
106
+ signer?: IIntentSigner;
107
+ logger?: ILogger;
108
+ }): Promise<void>;
109
+ createWithdrawalIntents(args: {
110
+ withdrawalParams: WithdrawalParams;
111
+ feeEstimation: FeeEstimation;
112
+ referral?: string;
113
+ logger?: ILogger;
114
+ }): Promise<IntentPrimitive[]>;
115
+ estimateWithdrawalFee(args: {
116
+ withdrawalParams: WithdrawalParams;
117
+ quoteOptions?: QuoteOptions;
118
+ logger?: ILogger;
119
+ }): Promise<FeeEstimation>;
120
+ estimateWithdrawalFee(args: {
121
+ withdrawalParams: WithdrawalParams[];
122
+ quoteOptions?: QuoteOptions;
123
+ logger?: ILogger;
124
+ }): Promise<FeeEstimation[]>;
125
+ protected _estimateWithdrawalFee(args: {
126
+ withdrawalParams: WithdrawalParams;
127
+ quoteOptions?: QuoteOptions;
128
+ logger?: ILogger;
129
+ }): Promise<FeeEstimation>;
130
+ /**
131
+ * Wait for withdrawal(s) to complete on the destination chain.
132
+ *
133
+ * **Important:** Waits until the withdrawal completes, fails, or the chain-specific
134
+ * p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a shorter timeout budget.
135
+ *
136
+ * @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
137
+ * Inspect `error.cause` to determine the reason.
138
+ * @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
139
+ * @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
140
+ *
141
+ * @param args.withdrawalParams - Single withdrawal or array of withdrawals
142
+ * @param args.intentTx - The NEAR transaction info from the published intent
143
+ * @param args.signal - Optional AbortSignal for cancellation/timeout
144
+ * @param args.logger - Optional logger for debugging
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // With timeout
149
+ * const result = await sdk.waitForWithdrawalCompletion({
150
+ * withdrawalParams,
151
+ * intentTx,
152
+ * signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
153
+ * });
154
+ * ```
155
+ */
156
+ waitForWithdrawalCompletion(args: {
157
+ withdrawalParams: WithdrawalParams;
158
+ intentTx: NearTxInfo;
159
+ signal?: AbortSignal;
160
+ logger?: ILogger;
161
+ }): Promise<TxInfo | TxNoInfo>;
162
+ waitForWithdrawalCompletion(args: {
163
+ withdrawalParams: WithdrawalParams[];
164
+ intentTx: NearTxInfo;
165
+ signal?: AbortSignal;
166
+ logger?: ILogger;
167
+ }): Promise<Array<TxInfo | TxNoInfo>>;
168
+ /**
169
+ * Create promises that resolve when each withdrawal completes on the destination chain.
170
+ * Use this for granular control over handling individual withdrawals as they complete,
171
+ * rather than waiting for all to finish.
172
+ *
173
+ * **Important:** Each promise waits until the withdrawal completes, fails, or the
174
+ * chain-specific p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a
175
+ * shorter timeout budget.
176
+ *
177
+ * @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
178
+ * Inspect `error.cause` to determine the reason.
179
+ * @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
180
+ * @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
181
+ *
182
+ * @param params.withdrawalParams - Array of withdrawal parameters
183
+ * @param params.intentTx - The NEAR transaction info from the published intent
184
+ * @param params.signal - Optional AbortSignal for cancellation/timeout
185
+ * @param params.logger - Optional logger for debugging
186
+ * @returns Array of promises, one per withdrawal, that resolve with transaction info
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const promises = sdk.createWithdrawalCompletionPromises({
191
+ * withdrawalParams: [withdrawal1, withdrawal2],
192
+ * intentTx,
193
+ * signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
194
+ * });
195
+ *
196
+ * // Handle each withdrawal as it completes
197
+ * for (const promise of promises) {
198
+ * promise.then((result) => console.log('Withdrawal completed:', result));
199
+ * }
200
+ * ```
201
+ */
202
+ createWithdrawalCompletionPromises(params: CreateWithdrawalCompletionPromisesParams): Array<Promise<TxInfo | TxNoInfo>>;
203
+ parseAssetId(assetId: string): ParsedAssetInfo;
204
+ sendSignedIntents(args: {
205
+ multiPayloads: MultiPayload[];
206
+ quoteHashes?: string[];
207
+ logger?: ILogger;
208
+ }): Promise<{
209
+ tickets: IntentHash[];
210
+ }>;
211
+ signAndSendIntent(args: SignAndSendArgs): Promise<IntentPublishResult>;
212
+ private withSaltRetry;
213
+ signAndSendWithdrawalIntent(args: SignAndSendWithdrawalArgs<WithdrawalParams> | SignAndSendWithdrawalArgs<WithdrawalParams[]>): Promise<IntentPublishResult>;
214
+ waitForIntentSettlement(args: {
215
+ intentHash: IntentHash;
216
+ /** AbortSignal for cancellation/timeout. Use AbortSignal.timeout(ms) for timeout. */
217
+ signal?: AbortSignal;
218
+ logger?: ILogger;
219
+ }): Promise<NearTxInfo>;
220
+ getIntentStatus({
221
+ intentHash,
222
+ logger
223
+ }: {
224
+ intentHash: IntentHash;
225
+ logger?: ILogger;
226
+ }): Promise<IntentSettlementStatus>;
227
+ processWithdrawal(args: ProcessWithdrawalArgs<WithdrawalParams>): Promise<WithdrawalResult>;
228
+ processWithdrawal(args: ProcessWithdrawalArgs<WithdrawalParams[]>): Promise<BatchWithdrawalResult>;
229
+ }
230
+ //#endregion
231
+ export { IntentsSDK, IntentsSDKConfig };