amogus-sdk-intents-sdk 0.72.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 (182) hide show
  1. package/README.md +1087 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/index.cjs +139 -0
  4. package/dist/index.d.cts +25 -0
  5. package/dist/index.d.ts +25 -0
  6. package/dist/index.js +20 -0
  7. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.cjs +10 -0
  8. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.js +7 -0
  9. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +44 -0
  10. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.js +42 -0
  11. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +111 -0
  12. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +110 -0
  13. package/dist/src/bridges/direct-bridge/direct-bridge-constants.cjs +8 -0
  14. package/dist/src/bridges/direct-bridge/direct-bridge-constants.js +6 -0
  15. package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +47 -0
  16. package/dist/src/bridges/direct-bridge/direct-bridge-utils.js +44 -0
  17. package/dist/src/bridges/direct-bridge/direct-bridge.cjs +155 -0
  18. package/dist/src/bridges/direct-bridge/direct-bridge.js +154 -0
  19. package/dist/src/bridges/direct-bridge/error.cjs +16 -0
  20. package/dist/src/bridges/direct-bridge/error.d.cts +12 -0
  21. package/dist/src/bridges/direct-bridge/error.d.ts +12 -0
  22. package/dist/src/bridges/direct-bridge/error.js +15 -0
  23. package/dist/src/bridges/hot-bridge/error.cjs +23 -0
  24. package/dist/src/bridges/hot-bridge/error.d.cts +19 -0
  25. package/dist/src/bridges/hot-bridge/error.d.ts +19 -0
  26. package/dist/src/bridges/hot-bridge/error.js +21 -0
  27. package/dist/src/bridges/hot-bridge/hot-bridge-chains.cjs +21 -0
  28. package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.cts +6 -0
  29. package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.ts +6 -0
  30. package/dist/src/bridges/hot-bridge/hot-bridge-chains.js +20 -0
  31. package/dist/src/bridges/hot-bridge/hot-bridge-constants.cjs +11 -0
  32. package/dist/src/bridges/hot-bridge/hot-bridge-constants.js +9 -0
  33. package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +66 -0
  34. package/dist/src/bridges/hot-bridge/hot-bridge-utils.js +61 -0
  35. package/dist/src/bridges/hot-bridge/hot-bridge.cjs +313 -0
  36. package/dist/src/bridges/hot-bridge/hot-bridge.js +311 -0
  37. package/dist/src/bridges/intents-bridge/intents-bridge.cjs +60 -0
  38. package/dist/src/bridges/intents-bridge/intents-bridge.js +60 -0
  39. package/dist/src/bridges/omni-bridge/error.cjs +54 -0
  40. package/dist/src/bridges/omni-bridge/error.d.cts +41 -0
  41. package/dist/src/bridges/omni-bridge/error.d.ts +41 -0
  42. package/dist/src/bridges/omni-bridge/error.js +49 -0
  43. package/dist/src/bridges/omni-bridge/omni-bridge-constants.cjs +16 -0
  44. package/dist/src/bridges/omni-bridge/omni-bridge-constants.js +10 -0
  45. package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +156 -0
  46. package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +146 -0
  47. package/dist/src/bridges/omni-bridge/omni-bridge.cjs +342 -0
  48. package/dist/src/bridges/omni-bridge/omni-bridge.js +340 -0
  49. package/dist/src/bridges/poa-bridge/errors.cjs +28 -0
  50. package/dist/src/bridges/poa-bridge/errors.d.cts +19 -0
  51. package/dist/src/bridges/poa-bridge/errors.d.ts +19 -0
  52. package/dist/src/bridges/poa-bridge/errors.js +26 -0
  53. package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +84 -0
  54. package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +81 -0
  55. package/dist/src/bridges/poa-bridge/poa-bridge.cjs +201 -0
  56. package/dist/src/bridges/poa-bridge/poa-bridge.js +199 -0
  57. package/dist/src/bridges/poa-bridge/poa-constants.cjs +6 -0
  58. package/dist/src/bridges/poa-bridge/poa-constants.js +5 -0
  59. package/dist/src/classes/errors.cjs +87 -0
  60. package/dist/src/classes/errors.d.cts +48 -0
  61. package/dist/src/classes/errors.d.ts +48 -0
  62. package/dist/src/classes/errors.js +81 -0
  63. package/dist/src/constants/bridge-name-enum.cjs +11 -0
  64. package/dist/src/constants/bridge-name-enum.d.cts +11 -0
  65. package/dist/src/constants/bridge-name-enum.d.ts +11 -0
  66. package/dist/src/constants/bridge-name-enum.js +10 -0
  67. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +26 -0
  68. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
  69. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
  70. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +25 -0
  71. package/dist/src/constants/public-rpc-urls.cjs +27 -0
  72. package/dist/src/constants/public-rpc-urls.js +25 -0
  73. package/dist/src/constants/route-enum.cjs +13 -0
  74. package/dist/src/constants/route-enum.d.cts +13 -0
  75. package/dist/src/constants/route-enum.d.ts +13 -0
  76. package/dist/src/constants/route-enum.js +12 -0
  77. package/dist/src/constants/withdrawal-timing.cjs +68 -0
  78. package/dist/src/constants/withdrawal-timing.js +68 -0
  79. package/dist/src/core/withdrawal-watcher.cjs +86 -0
  80. package/dist/src/core/withdrawal-watcher.d.cts +18 -0
  81. package/dist/src/core/withdrawal-watcher.d.ts +19 -0
  82. package/dist/src/core/withdrawal-watcher.js +82 -0
  83. package/dist/src/intents/expirable-nonce.cjs +98 -0
  84. package/dist/src/intents/expirable-nonce.d.cts +53 -0
  85. package/dist/src/intents/expirable-nonce.d.ts +55 -0
  86. package/dist/src/intents/expirable-nonce.js +90 -0
  87. package/dist/src/intents/intent-executer-impl/intent-executer.cjs +85 -0
  88. package/dist/src/intents/intent-executer-impl/intent-executer.d.cts +20 -0
  89. package/dist/src/intents/intent-executer-impl/intent-executer.d.ts +24 -0
  90. package/dist/src/intents/intent-executer-impl/intent-executer.js +85 -0
  91. package/dist/src/intents/intent-hash.cjs +48 -0
  92. package/dist/src/intents/intent-hash.d.cts +8 -0
  93. package/dist/src/intents/intent-hash.d.ts +8 -0
  94. package/dist/src/intents/intent-hash.js +47 -0
  95. package/dist/src/intents/intent-hashes/erc191.cjs +38 -0
  96. package/dist/src/intents/intent-hashes/erc191.js +37 -0
  97. package/dist/src/intents/intent-hashes/nep413.cjs +23 -0
  98. package/dist/src/intents/intent-hashes/nep413.js +22 -0
  99. package/dist/src/intents/intent-hashes/raw-ed25519.cjs +26 -0
  100. package/dist/src/intents/intent-hashes/raw-ed25519.js +25 -0
  101. package/dist/src/intents/intent-hashes/sep53.cjs +36 -0
  102. package/dist/src/intents/intent-hashes/sep53.js +35 -0
  103. package/dist/src/intents/intent-hashes/tip191.cjs +39 -0
  104. package/dist/src/intents/intent-hashes/tip191.js +38 -0
  105. package/dist/src/intents/intent-hashes/ton-connect.cjs +85 -0
  106. package/dist/src/intents/intent-hashes/ton-connect.js +84 -0
  107. package/dist/src/intents/intent-hashes/webauthn.cjs +26 -0
  108. package/dist/src/intents/intent-hashes/webauthn.js +25 -0
  109. package/dist/src/intents/intent-payload-builder.cjs +230 -0
  110. package/dist/src/intents/intent-payload-builder.d.cts +180 -0
  111. package/dist/src/intents/intent-payload-builder.d.ts +180 -0
  112. package/dist/src/intents/intent-payload-builder.js +229 -0
  113. package/dist/src/intents/intent-payload-factory.cjs +22 -0
  114. package/dist/src/intents/intent-payload-factory.js +21 -0
  115. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +43 -0
  116. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +42 -0
  117. package/dist/src/intents/intent-signer-impl/factories.cjs +19 -0
  118. package/dist/src/intents/intent-signer-impl/factories.d.cts +10 -0
  119. package/dist/src/intents/intent-signer-impl/factories.d.ts +10 -0
  120. package/dist/src/intents/intent-signer-impl/factories.js +17 -0
  121. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +22 -0
  122. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.cts +23 -0
  123. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts +23 -0
  124. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.js +21 -0
  125. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +44 -0
  126. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.cts +30 -0
  127. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.ts +30 -0
  128. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.js +43 -0
  129. package/dist/src/intents/intent-signer-impl/intent-signer-noop.cjs +8 -0
  130. package/dist/src/intents/intent-signer-impl/intent-signer-noop.js +7 -0
  131. package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +35 -0
  132. package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.cts +29 -0
  133. package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.ts +29 -0
  134. package/dist/src/intents/intent-signer-impl/intent-signer-viem.js +34 -0
  135. package/dist/src/intents/interfaces/intent-executer.d.ts +2 -0
  136. package/dist/src/intents/interfaces/intent-relayer.d.cts +43 -0
  137. package/dist/src/intents/interfaces/intent-relayer.d.ts +43 -0
  138. package/dist/src/intents/interfaces/intent-signer.d.cts +8 -0
  139. package/dist/src/intents/interfaces/intent-signer.d.ts +8 -0
  140. package/dist/src/intents/interfaces/salt-manager.d.cts +9 -0
  141. package/dist/src/intents/interfaces/salt-manager.d.ts +9 -0
  142. package/dist/src/intents/salt-manager.cjs +94 -0
  143. package/dist/src/intents/salt-manager.js +91 -0
  144. package/dist/src/intents/shared-types.d.cts +20 -0
  145. package/dist/src/intents/shared-types.d.ts +20 -0
  146. package/dist/src/lib/array.cjs +11 -0
  147. package/dist/src/lib/array.js +10 -0
  148. package/dist/src/lib/caip2.cjs +56 -0
  149. package/dist/src/lib/caip2.d.cts +44 -0
  150. package/dist/src/lib/caip2.d.ts +44 -0
  151. package/dist/src/lib/caip2.js +54 -0
  152. package/dist/src/lib/configure-rpc-config.cjs +49 -0
  153. package/dist/src/lib/configure-rpc-config.js +46 -0
  154. package/dist/src/lib/estimate-fee.cjs +96 -0
  155. package/dist/src/lib/estimate-fee.js +94 -0
  156. package/dist/src/lib/hex.cjs +11 -0
  157. package/dist/src/lib/hex.js +10 -0
  158. package/dist/src/lib/nep413.cjs +42 -0
  159. package/dist/src/lib/nep413.d.cts +14 -0
  160. package/dist/src/lib/nep413.d.ts +14 -0
  161. package/dist/src/lib/nep413.js +41 -0
  162. package/dist/src/lib/parse-defuse-asset-id.cjs +15 -0
  163. package/dist/src/lib/parse-defuse-asset-id.js +14 -0
  164. package/dist/src/lib/route-config-factory.cjs +43 -0
  165. package/dist/src/lib/route-config-factory.d.cts +13 -0
  166. package/dist/src/lib/route-config-factory.d.ts +13 -0
  167. package/dist/src/lib/route-config-factory.js +37 -0
  168. package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +17 -0
  169. package/dist/src/lib/tokensUsdPricesHttpClient/apis.js +16 -0
  170. package/dist/src/lib/ton-address.cjs +74 -0
  171. package/dist/src/lib/ton-address.js +69 -0
  172. package/dist/src/lib/validateAddress.cjs +513 -0
  173. package/dist/src/lib/validateAddress.d.cts +14 -0
  174. package/dist/src/lib/validateAddress.d.ts +14 -0
  175. package/dist/src/lib/validateAddress.js +512 -0
  176. package/dist/src/sdk.cjs +456 -0
  177. package/dist/src/sdk.d.cts +234 -0
  178. package/dist/src/sdk.d.ts +234 -0
  179. package/dist/src/sdk.js +454 -0
  180. package/dist/src/shared-types.d.cts +403 -0
  181. package/dist/src/shared-types.d.ts +403 -0
  182. package/package.json +67 -0
package/README.md ADDED
@@ -0,0 +1,1087 @@
1
+ # amogus-sdk-intents-sdk
2
+
3
+ A comprehensive SDK for Near Intents protocol. This SDK provides tools for intent execution, deposits, withdrawals, and
4
+ interacting with various bridge implementations across multiple blockchains.
5
+
6
+ ## Table of Contents
7
+
8
+ - [Installation](#installation)
9
+ - [Features](#features)
10
+ - [Quick Start](#quick-start)
11
+ - [Core Functionalities](#core-functionalities)
12
+ - [Core Concepts](#core-concepts)
13
+ - [Intent Execution](#intent-execution)
14
+ - [Deposits](#deposits)
15
+ - [Withdrawals](#withdrawals)
16
+ - [Routes and Bridges](#routes-and-bridges)
17
+ - [Route Types](#route-types)
18
+ - [Fee Estimation](#fee-estimation)
19
+ - [Advanced Usage](#advanced-usage)
20
+ - [Custom RPC URLs](#custom-rpc-urls)
21
+ - [Feature Flags](#feature-flags)
22
+ - [Other Intent Signers](#other-intent-signers)
23
+ - [Intent Payload Builder](#intent-payload-builder)
24
+ - [Intent Publishing Hooks](#intent-publishing-hooks)
25
+ - [Batch Withdrawals](#batch-withdrawals)
26
+ - [Waiting for Batch Completion](#waiting-for-batch-completion)
27
+ - [Intent Management](#intent-management)
28
+ - [Nonce Invalidation](#nonce-invalidation)
29
+ - [Configure Withdrawal Routes](#configure-withdrawal-routes)
30
+ - [Asset Information Parsing](#asset-information-parsing)
31
+ - [Waiting for Completion](#waiting-for-completion)
32
+ - [Error Handling](#error-handling)
33
+ - [Atomic Multi-Intent Publishing](#atomic-multi-intent-publishing)
34
+ - [Supported Networks](#supported-networks)
35
+ - [Development](#development)
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ npm install amogus-sdk-intents-sdk --save-exact
41
+ ```
42
+
43
+ ## Features
44
+
45
+ | Feature | Status | Description |
46
+ |------------------|:------:|------------------------------------------------------------------------|
47
+ | Intent Execution | ✅ | Sign, submit, and track intent execution on Near Intents |
48
+ | Deposits | ❌ | Deposit funds to Near Intents (use bridge interfaces directly) |
49
+ | Withdrawals | ✅ | Complete withdrawal functionality from Near Intents to external chains |
50
+
51
+ ## Quick Start
52
+
53
+ ### Basic Setup
54
+
55
+ First, initialize the SDK with your referral code and intent signer:
56
+
57
+ ```typescript
58
+ import {IntentsSDK, createIntentSignerNearKeyPair} from 'amogus-sdk-intents-sdk';
59
+ import {KeyPair} from 'near-api-js';
60
+
61
+ // Initialize the SDK
62
+ const sdk = new IntentsSDK({
63
+ referral: 'your-referral-code', // Only referral is required
64
+ intentSigner: createIntentSignerNearKeyPair({
65
+ signer: KeyPair.fromString('your-private-key'),
66
+ accountId: 'your-account.near'
67
+ })
68
+ });
69
+ ```
70
+
71
+ ### Most Common Use Case: Withdrawals
72
+
73
+ For most users, the primary use case is withdrawing funds from Near Intents to external chains. Use the high-level
74
+ `processWithdrawal` method:
75
+
76
+ ```typescript
77
+ // Complete end-to-end withdrawal (recommended)
78
+ const result = await sdk.processWithdrawal({
79
+ withdrawalParams: {
80
+ assetId: 'nep141:usdt.tether-token.near', // USDT token on NEAR
81
+ amount: 1000000n, // 1 USDT (in smallest units - 6 decimals)
82
+ destinationAddress: '0x742d35Cc6634C0532925a3b8D84B2021F90a51A3', // Ethereum address
83
+ feeInclusive: false, // Amount excludes withdrawal fees
84
+ }
85
+ });
86
+
87
+ console.log('Intent hash:', result.intentHash);
88
+ console.log('Destination transaction:', result.destinationTx);
89
+ ```
90
+
91
+ ### Advanced Use Case: Custom Intents
92
+
93
+ For advanced users who need custom intent logic beyond withdrawals, use the lower-level `signAndSendIntent` method:
94
+
95
+ ```typescript
96
+ // Custom intent execution (advanced)
97
+ const result = await sdk.signAndSendIntent({
98
+ intents: [
99
+ {
100
+ intent: "transfer", // Custom intent type
101
+ receiver_id: "recipient.near",
102
+ tokens: {"usdt.tether-token.near": "1000000"}, // 1 USDT
103
+ },
104
+ ],
105
+ });
106
+
107
+ console.log('Intent hash:', result.intentHash);
108
+ ```
109
+
110
+ > **💡 Tip**: Use `processWithdrawal` for withdrawals and `signAndSendIntent` for custom intent logic. The withdrawal
111
+ > method handles fee estimation, validation, and completion tracking automatically.
112
+
113
+ ## Core Functionalities
114
+
115
+ ### Core Concepts
116
+
117
+ #### Intent
118
+
119
+ TBD
120
+
121
+ #### Intent Signers
122
+
123
+ Intent signers are required to authenticate and sign both regular and withdrawal intents. The SDK supports
124
+ multiple signing methods:
125
+
126
+ | Singing Standard | Methods | Description |
127
+ |------------------|:------------------------------------------------------------------:|----------------------------------------------------------|
128
+ | nep413 | `createIntentSignerNEP413()`<br/>`createIntentSignerNearKeyPair()` | Almost all NEAR wallets support this standard |
129
+ | erc191 | `createIntentSignerViem()` | Only Viem library supported, Ethers.js signer is coming |
130
+ | raw_ed25519 | ❌ | Available on the protocol level, but not included to SDK |
131
+ | webauthn | ❌ | Available on the protocol level, but not included to SDK |
132
+ | ton_connect | ❌ | Available on the protocol level, but not included to SDK |
133
+
134
+ You must set an intent signer before processing withdrawals:
135
+
136
+ ```typescript
137
+ // Example: Set up a NEAR KeyPair signer
138
+ const signer = createIntentSignerNearKeyPair({
139
+ signer: KeyPair.fromString('your-private-key'),
140
+ accountId: 'your-account.near'
141
+ });
142
+ sdk.setIntentSigner(signer);
143
+ ```
144
+
145
+ See the [Intent Signers](#intent-signers-1) section below for detailed implementation examples.
146
+
147
+ #### Asset Identifiers
148
+
149
+ The SDK uses standardized asset identifiers in the format:
150
+
151
+ - `nep141:contract.near` - NEP-141 tokens
152
+ - `nep245:contract.near:tokenId` - NEP-245 multi-tokens
153
+
154
+ Asset Identifier uniquely determines the corresponding withdrawal route and destination chain.
155
+
156
+ Examples:
157
+
158
+ - `nep141:usdt.tether-token.near` - USDT on NEAR
159
+ - `nep141:wrap.near` - Wrapped NEAR (native NEAR)
160
+ - `nep245:v2_1.omni.hot.tg:137_qiStmoQJDQPTebaPjgx5VBxZv6L` - Polygon USDC through Hot
161
+ - `nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near` - Base USDC through PoA
162
+ - `nep141:eth.bridge.near` - ETH bridged through Omni Bridge
163
+
164
+ ### Intent Execution
165
+
166
+ The primary functionality of the SDK - execute custom intents on Near Intents:
167
+
168
+ - **Sign Intents**: Create and sign intent payloads with various signer types
169
+ - **Submit Intents**: Publish intents to the Near Intents relayer network
170
+ - **Track Status**: Monitor intent settlement and execution status
171
+ - **Batch Intents**: Execute multiple intents in a single transaction
172
+ - **Custom Logic**: Support for any intent type supported by the protocol
173
+
174
+ ```typescript
175
+ // Generic intent execution
176
+ const {intentHash} = await sdk.signAndSendIntent({
177
+ intents: [/* array of intent primitives */],
178
+ onBeforePublishIntent: async (data) => {
179
+ console.log('About to publish intent:', data.intentHash);
180
+ }
181
+ });
182
+
183
+ // Monitor settlement
184
+ const intentTx = await sdk.waitForIntentSettlement({intentHash});
185
+ ```
186
+
187
+ ### Deposits
188
+
189
+ Deposit funds into Near Intents *(Coming Soon)*.
190
+
191
+ > **Note**: Deposit functionality is not yet implemented in this SDK. Currently, use bridge interfaces directly for
192
+ > deposit operations.
193
+
194
+ ### Withdrawals
195
+
196
+ Complete withdrawal functionality from Near Intents to external chains:
197
+
198
+ - **Cross-Chain Transfers**: Withdraw to 20+ supported blockchains
199
+ - **Multi-Bridge Support**: Hot Bridge, PoA Bridge, Omni Bridge
200
+ - **Batch Processing**: Process multiple withdrawals at a time
201
+ - **Fee Management**: Automatic fee estimation with quote support
202
+ - **Validation**: Built-in validation for withdrawal constraints
203
+ - **Status Tracking**: End-to-end monitoring from intent to destination
204
+
205
+ ```typescript
206
+ // Complete withdrawal process
207
+ const result = await sdk.processWithdrawal({
208
+ withdrawalParams: {
209
+ assetId: 'nep141:usdt.tether-token.near',
210
+ amount: 1000000n,
211
+ destinationAddress: '0x742d35Cc6634C0532925a3b8D84B2021F90a51A3',
212
+ feeInclusive: false
213
+ }
214
+ });
215
+ ```
216
+
217
+ #### Routes and Bridges
218
+
219
+ The SDK uses two key concepts to organize withdrawal operations:
220
+
221
+ ##### Routes
222
+
223
+ Routes define the **path** a withdrawal takes - the specific mechanism and destination for transferring assets. Each
224
+ route represents a different withdrawal flow:
225
+
226
+ ```typescript
227
+ import {RouteEnum} from 'amogus-sdk-intents-sdk';
228
+
229
+ console.log(RouteEnum.HotBridge); // "hot_bridge" - Cross-chain via HOT protocol
230
+ console.log(RouteEnum.PoaBridge); // "poa_bridge" - Cross-chain via PoA bridge
231
+ console.log(RouteEnum.OmniBridge); // "omni_bridge" - Cross-chain via Omni bridge
232
+ console.log(RouteEnum.NearWithdrawal); // "near_withdrawal" - Direct to NEAR blockchain
233
+ console.log(RouteEnum.VirtualChain); // "virtual_chain" - To Aurora Engine chains
234
+ console.log(RouteEnum.InternalTransfer); // "internal_transfer" - Between protocol users
235
+ ```
236
+
237
+ ##### Bridge Names
238
+
239
+ Bridge names identify the **underlying bridge infrastructure** that handles the cross-chain transfer. This determines
240
+ which external protocol processes the withdrawal:
241
+
242
+ ```typescript
243
+ import {BridgeNameEnum} from 'amogus-sdk-intents-sdk';
244
+
245
+ console.log(BridgeNameEnum.Hot); // "hot" - HOT Labs bridge infrastructure
246
+ console.log(BridgeNameEnum.Poa); // "poa" - Proof-of-Authority bridge by Defuse Labs
247
+ console.log(BridgeNameEnum.Omni); // "omni" - Omni bridge by NEAR
248
+ console.log(BridgeNameEnum.None); // null - No external bridge (NEAR-native or internal)
249
+ ```
250
+
251
+ **Key Difference**:
252
+
253
+ - **Route** = "How and where" the withdrawal goes (the path)
254
+ - **Bridge Name** = "Who operates" the underlying infrastructure (the bridge provider)
255
+
256
+ For example, both `hot_bridge` and `poa_bridge` routes perform cross-chain transfers, but use different bridge
257
+ infrastructures (`hot` vs `poa`) with different fee structures and supported networks.
258
+
259
+ #### Route Types
260
+
261
+ The SDK automatically detects and supports multiple route types based on asset identifiers:
262
+
263
+ ##### Hot Bridge Route
264
+
265
+ - **Purpose**: Cross-chain transfers via HOT Labs infrastructure
266
+ - **Supported Assets**: Multi-tokens (NEP-245) from Hot protocol (contract `v2_1.omni.hot.tg`)
267
+ - **Use Case**: Cross-chain transfers for assets bridged through Hot protocol
268
+ - **Route Type**: `hot_bridge`
269
+
270
+ ##### PoA Bridge Route
271
+
272
+ - **Purpose**: Proof-of-Authority bridge transfers operated by Defuse Labs
273
+ - **Supported Assets**: Fungible tokens (NEP-141) ending with `.omft.near`
274
+ - **Use Case**: Cross-chain transfers for assets bridged through PoA protocol
275
+ - **Route Type**: `poa_bridge`
276
+
277
+ ##### Omni Bridge Route
278
+ - **Purpose**: multi-chain asset bridge developed by Near
279
+ - **Supported Assets**: Fungible tokens (NEP-141) supported by omni bridge relayer.
280
+ - **Use Case**: multi-chain transfers for supported list of chains
281
+ - **Route Type**: `omni_bridge`
282
+
283
+ ##### Internal Transfer Route
284
+
285
+ - **Purpose**: Transfer between Near Intents users within the protocol
286
+ - **Supported Assets**: All NEP-141 and NEP-245 tokens
287
+ - **Use Case**: User A having funds in the protocol wants to transfer to User B
288
+ - **Route Type**: `internal_transfer`
289
+
290
+ ##### Near Withdrawal Route
291
+
292
+ - **Purpose**: Transfers within the NEAR blockchain
293
+ - **Supported Assets**: NEP-141 tokens on NEAR, including native NEAR (wrap.near)
294
+ - **Use Case**: Same-chain transfers on NEAR
295
+ - **Route Type**: `near_withdrawal`
296
+
297
+ ##### Virtual Chain Route
298
+
299
+ - **Purpose**: Transfers to Aurora Engine-powered chains (aka Virtual chains)
300
+ - **Supported Assets**: NEP-141 tokens with Aurora Engine integration
301
+ - **Use Case**: Near Intents to Aurora ecosystem transfers
302
+ - **Route Type**: `virtual_chain`
303
+ - **Note**: Requires explicit `routeConfig` with `auroraEngineContractId`
304
+
305
+ #### Fee Estimation
306
+
307
+ The SDK now supports both single and batch fee estimation:
308
+
309
+ ```typescript
310
+ // Single withdrawal fee estimation
311
+ const feeEstimation = await sdk.estimateWithdrawalFee({
312
+ withdrawalParams: {
313
+ assetId: 'nep141:usdt.tether-token.near',
314
+ amount: 1000000n,
315
+ destinationAddress: '0x742d35Cc6634C0532925a3b8D84B2021F90a51A3',
316
+ feeInclusive: false
317
+ }
318
+ });
319
+
320
+ console.log('Fee amount:', feeEstimation.amount);
321
+
322
+ // Batch fee estimation
323
+ const batchFees = await sdk.estimateWithdrawalFee({
324
+ withdrawalParams: [
325
+ {
326
+ assetId: 'nep141:usdt.tether-token.near',
327
+ amount: 1000000n,
328
+ destinationAddress: '0x742d35Cc...',
329
+ feeInclusive: false
330
+ },
331
+ {
332
+ assetId: 'nep245:v2_1.omni.hot.tg:137_qiStmoQJDQPTebaPjgx5VBxZv6L',
333
+ amount: 500000n,
334
+ destinationAddress: '0x742d35Cc...',
335
+ feeInclusive: false
336
+ }
337
+ ]
338
+ });
339
+
340
+ console.log('Batch fees:', batchFees); // Array of FeeEstimation objects
341
+ ```
342
+
343
+ > **Note:** `estimateWithdrawalFee` also runs `validateWithdrawal` internally. If the withdrawal parameters are invalid (e.g. invalid destination address, amount below minimum, insufficient UTXOs), the bridge's `validateWithdrawal` will throw and the error will propagate from `estimateWithdrawalFee`.
344
+
345
+ > **Note:** When `amount` is `0n` and `feeInclusive` is `false`, minimum amount validation is skipped. This is useful when the exact withdrawal amount is not yet known and you only need a fee estimate.
346
+
347
+ ## Advanced Usage
348
+
349
+ ### Custom RPC URLs
350
+
351
+ Set NEAR and EVM chains RPC URLs in the constructor:
352
+
353
+ ```typescript
354
+ import {Chains} from 'amogus-sdk-intents-sdk'
355
+
356
+ const sdk = new IntentsSDK({
357
+ ...,
358
+ rpc: {
359
+ [Chains.Near]: ['https://rpc.mainnet.near.org'],
360
+ [Chains.Polygon]: ['https://polygon-rpc.com'],
361
+ [Chains.BNB]: ['https://bsc-dataseed.binance.org'],
362
+ }
363
+ });
364
+ ```
365
+
366
+ ### Feature Flags
367
+
368
+ Configure optional SDK features through the `features` configuration:
369
+
370
+ #### Migrated PoA Token Routing
371
+
372
+ Will route migrated PoA tokens (ending with `*.omft.near`) through Omni Bridge instead of the legacy PoA Bridge, unless explicitly set to route them through PoA bridge with routeConfig. Enable this when working with POA tokens that have been migrated to the Omni infrastructure:
373
+
374
+ ```typescript
375
+ const sdk = new IntentsSDK({
376
+ referral: 'your-referral-code',
377
+ features: {
378
+ routeMigratedPoaTokensThroughOmniBridge: true
379
+ }
380
+ });
381
+
382
+ // With this flag enabled, tokens like 'nep141:sol-c58e6539c2f2e097c251f8edf11f9c03e581f8d4.omft.near' will route through Omni Bridge
383
+ const result = await sdk.processWithdrawal({
384
+ withdrawalParams: {
385
+ assetId: 'nep141:sol-c58e6539c2f2e097c251f8edf11f9c03e581f8d4.omft.near', // Migrated PoA token
386
+ amount: 1000000n,
387
+ destinationAddress: '39hqXivfCPUSqmXAaX3eo4JcA5bGFXhhs26dmg585DGb',
388
+ feeInclusive: false
389
+ }
390
+ });
391
+ ```
392
+
393
+ **When to enable:**
394
+ - Working with PoA tokens that have been migrated to Omni Bridge
395
+ - Explicitly want to route `*.omft.near` tokens through the Omni Bridge
396
+ - Default behavior (when disabled) routes these tokens through the PoA Bridge
397
+
398
+ **Allowlisted Tokens:**
399
+
400
+ Not all PoA tokens can be routed through Omni Bridge. The SDK exports `POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE` constant containing the tokens that support this routing:
401
+
402
+ ```typescript
403
+ import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from 'amogus-sdk-intents-sdk';
404
+
405
+ console.log(POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE);
406
+ // { 'sol-...omft.near': ChainKind.Sol, ... }
407
+ ```
408
+
409
+ The keys are token contract IDs and values are their `ChainKind`. Only tokens in this map will be routed through Omni Bridge when the feature flag is enabled. Other `*.omft.near` tokens will continue using the PoA Bridge.
410
+
411
+ ### Other Intent Signers
412
+
413
+ The SDK supports multiple intent signing methods using factory functions:
414
+
415
+ #### NEAR KeyPair Signer
416
+
417
+ ```typescript
418
+ import {createIntentSignerNearKeyPair, IntentsSDK} from 'amogus-sdk-intents-sdk';
419
+ import {KeyPair} from 'near-api-js';
420
+
421
+ const keyPair = KeyPair.fromString('your-private-key');
422
+ const signer = createIntentSignerNearKeyPair({
423
+ signer: keyPair,
424
+ accountId: 'your-account.near'
425
+ });
426
+ ```
427
+
428
+ #### NEP-413 Signer
429
+
430
+ ```typescript
431
+ import {createIntentSignerNEP413} from 'amogus-sdk-intents-sdk';
432
+
433
+ const signer = createIntentSignerNEP413({
434
+ signMessage: async (nep413Payload, nep413Hash) => {
435
+ // Implement your custom signing logic here
436
+ return {
437
+ publicKey: 'ed25519:YourPublicKey',
438
+ signature: 'base64-encoded-signature'
439
+ };
440
+ },
441
+ accountId: 'your-account.near'
442
+ });
443
+ ```
444
+
445
+ #### EVM/Viem Signer
446
+
447
+ ```typescript
448
+ import {createIntentSignerViem} from 'amogus-sdk-intents-sdk';
449
+ import {privateKeyToAccount} from 'viem/accounts';
450
+
451
+ const account = privateKeyToAccount('0x...');
452
+ const signer = createIntentSignerViem({ signer: account });
453
+
454
+ // Set the signer at runtime
455
+ sdk.setIntentSigner(signer);
456
+ ```
457
+
458
+ ### Intent Payload Builder
459
+
460
+ For API builders who need to generate intent payloads based on user metadata (e.g., generating payloads server-side for users to sign with MetaMask), the SDK provides a fluent `IntentPayloadBuilder`:
461
+
462
+ ```typescript
463
+ // Build an intent payload for your users
464
+ const payload = await sdk.intentBuilder()
465
+ .setSigner('0x742d35cc6634c0532925a3b8d84b2021f90a51a3') // User's EVM address
466
+ .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes
467
+ .addIntent({
468
+ intent: "transfer",
469
+ tokens: { "token.near": "100" },
470
+ receiver_id: "receiver.near",
471
+ })
472
+ .build();
473
+ ```
474
+
475
+ ### Versioned Nonce Builder
476
+
477
+ By default, the nonce is generated during the intent construction process, but it is possible to generate and pass the nonce within the builder independently. All of the nonces have specific [requirements](https://github.com/near/intents/tree/main/defuse#nonces) for the structure reflecting their validity.
478
+
479
+ ```typescript
480
+ import {VersionedNonceBuilder} from 'amogus-sdk-intents-sdk';
481
+
482
+ // Fetch current salt from the verifier contract
483
+ const salt_hex = await nearRPC.viewFunction({
484
+ contractId: "intents.near",
485
+ methodName: "current_salt",
486
+ });
487
+
488
+ // Example: 5-minute deadline, but actual deadline should not be greater than intent's deadline
489
+ const deadline = new Date(Date.now() + 5 * 60 * 1000)
490
+
491
+ // Create ready to use versioned nonce from salt and deadline
492
+ const versionedNonce = VersionedNonceBuilder.encodeNonce(
493
+ Uint8Array.from(Buffer.from(salt_hex, "hex")),
494
+ deadline
495
+ );
496
+
497
+ // Create intent builder with specified nonce
498
+ const builder = await sdk.intentBuilder().setNonce(versionedNonce);
499
+ ```
500
+
501
+
502
+ ### Intent Publishing Hooks
503
+
504
+ Use the `onBeforePublishIntent` hook to intercept and process intent data before it's published to the relayer. This is
505
+ useful for persistence, logging, analytics, or custom processing:
506
+
507
+ ```typescript
508
+ import {type OnBeforePublishIntentHook} from 'amogus-sdk-intents-sdk';
509
+
510
+ // Define your hook function
511
+ const onBeforePublishIntent: OnBeforePublishIntentHook = async (intentData) => {
512
+ // Save to database for tracking
513
+ await saveIntentToDatabase({
514
+ hash: intentData.intentHash,
515
+ payload: intentData.intentPayload,
516
+ timestamp: new Date(),
517
+ });
518
+
519
+ // Send analytics
520
+ analytics.track('intent_about_to_publish', {
521
+ intentHash: intentData.intentHash,
522
+ intentType: intentData.intentPayload.intents[0]?.intent,
523
+ });
524
+ };
525
+
526
+ // Use the hook with the functional API
527
+ const result = await sdk.processWithdrawal({
528
+ withdrawalParams: { /* ... */},
529
+ intent: {
530
+ onBeforePublishIntent, // Add the hook here
531
+ }
532
+ });
533
+
534
+ // Or with granular control
535
+ const {intentHash} = await sdk.signAndSendWithdrawalIntent({
536
+ withdrawalParams: { /* ... */},
537
+ feeEstimation: fee,
538
+ intent: {
539
+ onBeforePublishIntent, // Add the hook here
540
+ }
541
+ });
542
+
543
+ // Or with generic intent publishing
544
+ const {intentHash} = await sdk.signAndSendIntent({
545
+ intents: [/* ... */],
546
+ onBeforePublishIntent, // Add the hook here
547
+ });
548
+ ```
549
+
550
+ **Hook Parameters:**
551
+
552
+ - `intentHash` - The computed hash of the intent payload
553
+ - `intentPayload` - The unsigned intent payload
554
+ - `multiPayload` - The signed multi-payload containing signature and metadata
555
+ - `relayParams` - Additional parameters passed to the relayer (quote hashes)
556
+
557
+ **Important Notes:**
558
+
559
+ - The hook is called synchronously before publishing the intent
560
+ - If the hook throws an error, the withdrawal will fail
561
+ - The hook can be async and return a Promise
562
+
563
+ ### Batch Withdrawals
564
+
565
+ Process multiple withdrawals in a single intent:
566
+
567
+ ```typescript
568
+ const withdrawalParams = [
569
+ {
570
+ assetId: 'nep141:usdt.tether-token.near',
571
+ amount: 1000000n,
572
+ destinationAddress: '0x742d35Cc...',
573
+ feeInclusive: false
574
+ },
575
+ {
576
+ assetId: 'nep245:v2_1.omni.hot.tg:137_qiStmoQJDQPTebaPjgx5VBxZv6L',
577
+ amount: 100000n,
578
+ destinationAddress: '0x742d35Cc...',
579
+ feeInclusive: false
580
+ }
581
+ ]
582
+
583
+ // Method 1: Complete end-to-end batch processing
584
+ const batchResult = await sdk.processWithdrawal({
585
+ withdrawalParams,
586
+ // feeEstimation is optional - will be estimated automatically if not provided
587
+ });
588
+
589
+ console.log('Batch intent hash:', batchResult.intentHash);
590
+ console.log('Destination transactions:', batchResult.destinationTx); // Array of results
591
+
592
+ // Method 2: Step-by-step batch processing for granular control
593
+ const feeEstimation = await sdk.estimateWithdrawalFee({
594
+ withdrawalParams
595
+ });
596
+
597
+ const {intentHash} = await sdk.signAndSendWithdrawalIntent({
598
+ withdrawalParams,
599
+ feeEstimation
600
+ });
601
+
602
+ const intentTx = await sdk.waitForIntentSettlement({intentHash});
603
+
604
+ // See "Waiting for Batch Completion" below for completion options
605
+ ```
606
+
607
+ #### Waiting for Batch Completion
608
+
609
+ After the intent settles on NEAR, you need to wait for withdrawals to complete on destination chains. Two approaches are available:
610
+
611
+ **Option A: Wait for All (`waitForWithdrawalCompletion`)**
612
+
613
+ Waits for all withdrawals to complete before returning. Simple, but blocks on the slowest withdrawal.
614
+
615
+ > **Note:** Waits until completion or chain-specific p99 timeout (throws `PollTimeoutError`). Use `AbortSignal.timeout()` to set a shorter timeout.
616
+
617
+ ```typescript
618
+ const destinationTxs = await sdk.waitForWithdrawalCompletion({
619
+ withdrawalParams,
620
+ intentTx,
621
+ signal: AbortSignal.timeout(10 * 60 * 1000), // 10 minute timeout
622
+ });
623
+
624
+ console.log('All destination transactions:', destinationTxs);
625
+ ```
626
+
627
+ **Option B: Independent Promises (`createWithdrawalCompletionPromises`)**
628
+
629
+ For scenarios where fast withdrawals (Solana ~2s) shouldn't wait for slow ones (Bitcoin ~1hr), use `createWithdrawalCompletionPromises` to get promises that resolve independently:
630
+
631
+ ```typescript
632
+ // Get array of promises - one per withdrawal
633
+ const promises = sdk.createWithdrawalCompletionPromises({
634
+ withdrawalParams,
635
+ intentTx
636
+ });
637
+
638
+ // Fire and forget - handle each independently
639
+ promises[0].then(tx => saveUsdc(tx)).catch(err => logError(0, err));
640
+ promises[1].then(tx => saveBtc(tx)).catch(err => logError(1, err));
641
+
642
+ // Or await a specific withdrawal (fast chain first)
643
+ const usdcTx = await promises[0];
644
+ await notifyUser('USDC received', usdcTx.hash);
645
+
646
+ // Or process as they complete with backpressure
647
+ const pending = new Map(promises.map((p, i) => [i, p]));
648
+ while (pending.size > 0) {
649
+ const { index, tx } = await Promise.race(
650
+ [...pending.entries()].map(async ([i, p]) => ({ index: i, tx: await p }))
651
+ );
652
+ pending.delete(index);
653
+ await saveSuccess(index, tx); // Backpressure maintained
654
+ }
655
+
656
+ // Or wait for all with independent error handling
657
+ const results = await Promise.allSettled(promises);
658
+ for (const [i, result] of results.entries()) {
659
+ if (result.status === 'fulfilled') {
660
+ await saveSuccess(i, result.value);
661
+ } else {
662
+ await saveFailure(i, result.reason);
663
+ }
664
+ }
665
+ ```
666
+
667
+ **With timeout control:**
668
+
669
+ ```typescript
670
+ const promises = sdk.createWithdrawalCompletionPromises({
671
+ withdrawalParams,
672
+ intentTx,
673
+ signal: AbortSignal.timeout(30_000) // 30 second timeout
674
+ });
675
+ ```
676
+
677
+ **Key benefits:**
678
+ - Fast withdrawals (Solana ~2s) aren't blocked by slow ones (Bitcoin ~1hr)
679
+ - One failure doesn't affect other withdrawals
680
+ - Recovery-friendly: recreate promises from saved `{ withdrawalParams, intentTx }`
681
+ - Index correspondence: `promises[i]` corresponds to `withdrawalParams[i]`
682
+
683
+ > **Note:** Both methods wait until completion or chain-specific p99 timeout (throws `PollTimeoutError`). Use `AbortSignal.timeout()` for a shorter timeout.
684
+
685
+ ### Intent Management
686
+
687
+ The SDK provides direct access to intent operations for advanced use cases:
688
+
689
+ ```typescript
690
+ // Generic intent signing and publishing
691
+ const {intentHash} = await sdk.signAndSendIntent({
692
+ intents: [/* array of intent primitives */],
693
+ signer: customIntentSigner, // optional - uses SDK default if not provided
694
+ onBeforePublishIntent: async (data) => {
695
+ // Custom logic before publishing
696
+ console.log('About to publish intent:', data.intentHash);
697
+ }
698
+ });
699
+
700
+ // Wait for intent settlement
701
+ const intentTx = await sdk.waitForIntentSettlement({
702
+ intentHash
703
+ });
704
+
705
+ // or manual status check
706
+
707
+ // Check intent status at any time
708
+ const status = await sdk.getIntentStatus({
709
+ intentHash: intentHash
710
+ });
711
+
712
+ console.log('Intent status:', status.status); // "PENDING" | "TX_BROADCASTED" | "SETTLED" | "NOT_FOUND_OR_NOT_VALID"
713
+
714
+ if (status.status === 'SETTLED') {
715
+ console.log('Settlement transaction:', status.txHash);
716
+ }
717
+ ```
718
+
719
+ **Intent Status Values:**
720
+
721
+ - `PENDING` - Intent published but not yet processed
722
+ - `TX_BROADCASTED` - Intent being processed, transaction broadcasted
723
+ - `SETTLED` - Intent successfully completed
724
+ - `NOT_FOUND_OR_NOT_VALID` - Intent not found or invalid, it isn't executed onchain
725
+
726
+ ### Nonce Invalidation
727
+
728
+ Invalidate nonces to prevent execution of previously created intent payloads. Primarily used by **solvers** to revoke quotes due to price volatility, liquidity changes, or risk management.
729
+
730
+ ```typescript
731
+ await sdk.invalidateNonces({
732
+ nonces: ['VigoxLwmUGf35MGLVBG9Fh5cCtJw3D68pSKFcqGCkHU='],
733
+ signer: customIntentSigner, // optional - uses SDK default if not provided
734
+ });
735
+ ```
736
+
737
+ ### Configure Withdrawal Routes
738
+
739
+ **Recommended**: Use factory functions to create route configurations. The SDK provides factory functions for type-safe
740
+ and convenient route configuration creation:
741
+
742
+ ```typescript
743
+ import {
744
+ createVirtualChainRoute,
745
+ createNearWithdrawalRoute,
746
+ createInternalTransferRoute
747
+ } from 'amogus-sdk-intents-sdk';
748
+
749
+ // Create virtual chain route configuration (recommended)
750
+ const virtualChainRoute = createVirtualChainRoute(
751
+ '0x4e45415f.c.aurora', // Aurora Engine contract ID
752
+ null // Proxy token contract ID (optional)
753
+ );
754
+
755
+ // Create near withdrawal route with custom message
756
+ const nearWithdrawalRoute = createNearWithdrawalRoute(
757
+ 'Custom withdrawal message' // Optional message
758
+ );
759
+
760
+ // Create internal transfer route
761
+ const internalTransferRoute = createInternalTransferRoute();
762
+
763
+ // Use the factory-created route configuration in withdrawal
764
+ const result = await sdk.processWithdrawal({
765
+ withdrawalParams: {
766
+ assetId: 'nep141:a35923162c49cf95e6bf26623385eb431ad920d3.factory.bridge.near',
767
+ amount: BigInt('1000000'),
768
+ destinationAddress: '0x742d35Cc6634C0532925a3b8D84B2021F90a51A3',
769
+ feeInclusive: false,
770
+ routeConfig: virtualChainRoute // Recommended: Use factory function
771
+ }
772
+ });
773
+ ```
774
+
775
+ ### Asset Information Parsing
776
+
777
+ Get detailed information about supported assets:
778
+
779
+ ```typescript
780
+ try {
781
+ const assetInfo = sdk.parseAssetId('nep141:usdt.tether-token.near');
782
+ console.log('Bridge name:', assetInfo.bridgeName);
783
+ console.log('Blockchain:', assetInfo.blockchain);
784
+ console.log('Contract ID:', assetInfo.contractId);
785
+ console.log('Standard:', assetInfo.standard);
786
+ } catch (error) {
787
+ console.log('Asset not supported');
788
+ }
789
+ ```
790
+
791
+ ### Waiting for Completion
792
+
793
+ Monitor withdrawal completion:
794
+
795
+ ```typescript
796
+ // Method 1: Using the orchestrated approach (automatic monitoring)
797
+ const result = await sdk.processWithdrawal({
798
+ withdrawalParams: {
799
+ assetId: 'nep141:usdt.tether-token.near',
800
+ amount: 1000000n,
801
+ destinationAddress: '0x742d35Cc...',
802
+ feeInclusive: false
803
+ }
804
+ });
805
+
806
+ console.log('Intent settled:', result.intentTx.hash);
807
+ console.log('Withdrawal completed:', result.destinationTx);
808
+
809
+ // Method 2: Step-by-step monitoring for granular control
810
+ const feeEstimation = await sdk.estimateWithdrawalFee({
811
+ withdrawalParams: {
812
+ assetId: 'nep141:usdt.tether-token.near',
813
+ amount: 1000000n,
814
+ destinationAddress: '0x742d35Cc...',
815
+ feeInclusive: false
816
+ }
817
+ });
818
+
819
+ const {intentHash} = await sdk.signAndSendWithdrawalIntent({
820
+ withdrawalParams: {
821
+ assetId: 'nep141:usdt.tether-token.near',
822
+ amount: 1000000n,
823
+ destinationAddress: '0x742d35Cc...',
824
+ feeInclusive: false
825
+ },
826
+ feeEstimation
827
+ });
828
+
829
+ // Monitor intent settlement
830
+ const intentTx = await sdk.waitForIntentSettlement({intentHash});
831
+ console.log('Intent settled:', intentTx.hash);
832
+
833
+ // Wait for withdrawal completion on destination chain
834
+ // Note: Has chain-specific p99 timeout - use signal for a shorter timeout
835
+ const completionResult = await sdk.waitForWithdrawalCompletion({
836
+ withdrawalParams: {
837
+ assetId: 'nep141:usdt.tether-token.near',
838
+ amount: 1000000n,
839
+ destinationAddress: '0x742d35Cc...',
840
+ feeInclusive: false
841
+ },
842
+ intentTx,
843
+ signal: AbortSignal.timeout(10 * 60 * 1000), // 10 minute timeout
844
+ });
845
+
846
+ if ('hash' in completionResult) {
847
+ console.log('Withdrawal completed with hash:', completionResult.hash);
848
+ } else {
849
+ console.log('Withdrawal completion not trackable for this bridge');
850
+ }
851
+ ```
852
+
853
+ ### Error Handling
854
+
855
+ ```typescript
856
+ import {FeeExceedsAmountError, MinWithdrawalAmountError} from 'amogus-sdk-intents-sdk';
857
+
858
+ try {
859
+ const result = await sdk.processWithdrawal({
860
+ withdrawalParams: {
861
+ assetId: 'nep141:usdt.tether-token.near',
862
+ amount: BigInt('100'), // Very small amount
863
+ destinationAddress: '0x742d35Cc...',
864
+ feeInclusive: true // Fee must be less than amount
865
+ }
866
+ });
867
+ } catch (error) {
868
+ if (error instanceof FeeExceedsAmountError) {
869
+ console.log('Fee exceeds withdrawal amount');
870
+ console.log('Required fee:', error.feeEstimation.amount);
871
+ console.log('Withdrawal amount:', error.amount);
872
+ } else if (error instanceof MinWithdrawalAmountError) {
873
+ console.log('Amount below minimum withdrawal limit');
874
+ console.log('Minimum required:', error.minAmount);
875
+ console.log('Requested amount:', error.requestedAmount);
876
+ console.log('Asset:', error.assetId);
877
+ }
878
+ }
879
+
880
+ // Error handling with granular control
881
+ try {
882
+ const feeEstimation = await sdk.estimateWithdrawalFee({
883
+ withdrawalParams: {
884
+ assetId: 'nep141:usdt.tether-token.near',
885
+ amount: 100n,
886
+ destinationAddress: '0x742d35Cc...',
887
+ feeInclusive: true
888
+ }
889
+ });
890
+
891
+ // Continue with other operations...
892
+ } catch (error) {
893
+ // Handle specific errors at each step
894
+ console.error('Fee estimation failed:', error);
895
+ }
896
+ ```
897
+
898
+ #### PoA Bridge Minimum Withdrawal Amount Validation
899
+
900
+ PoA bridge has minimum withdrawal amount requirements that vary per token and blockchain. The SDK automatically
901
+ validates this for all withdrawals.
902
+
903
+ ```typescript
904
+ // Validation happens automatically during withdrawal processing:
905
+ try {
906
+ const result = await sdk.processWithdrawal({
907
+ withdrawalParams: {
908
+ assetId: 'nep141:zec.omft.near', // Zcash token
909
+ amount: BigInt('50000000'), // 0.5 ZEC (in smallest units)
910
+ destinationAddress: 'your-zcash-address',
911
+ feeInclusive: false
912
+ }
913
+ });
914
+ } catch (error) {
915
+ if (error instanceof MinWithdrawalAmountError) {
916
+ console.log(`Minimum withdrawal for ${error.assetId}: ${error.minAmount}`);
917
+ console.log(`Requested amount: ${error.requestedAmount}`);
918
+ // For Zcash: minimum is typically 1.0 ZEC (100000000 in smallest units)
919
+ // Plus 0.2 ZEC fee, so user needs at least 1.2 ZEC to withdraw 1.0 ZEC
920
+ }
921
+ }
922
+ ```
923
+
924
+ Note: Other routes (Near Withdrawal, Virtual Chain, Internal Transfer) don't have minimum withdrawal restrictions, so
925
+ validation passes through for those routes.
926
+
927
+ #### Hot Bridge Stellar Trustline Validation
928
+
929
+ Hot Bridge validates that destination addresses have the required trustlines when withdrawing to Stellar blockchain.
930
+ This prevents failed transactions due to missing trustlines.
931
+
932
+ ```typescript
933
+ import {TrustlineNotFoundError} from 'amogus-sdk-intents-sdk';
934
+
935
+ // Validation happens automatically during withdrawal processing:
936
+ try {
937
+ const result = await sdk.processWithdrawal({
938
+ withdrawalParams: {
939
+ assetId: 'nep245:v2_1.omni.hot.tg:stellar_1_USD_GBDMM6LG7YX7YGF6JFAEWX3KFUSBXGAEPZ2IHDLWH:1100', // Stellar USD token
940
+ amount: BigInt('1000000'), // 1 USD (in smallest units)
941
+ destinationAddress: 'GCKFBEIYTKP6RYVDYGMVVMJ6J6XKCRZL74JPWTFGD2NQNMPBQC2LGTVZ', // Stellar address
942
+ feeInclusive: false
943
+ }
944
+ });
945
+ } catch (error) {
946
+ if (error instanceof TrustlineNotFoundError) {
947
+ console.log(`Trustline not found for token: ${error.assetId}`);
948
+ console.log(`Destination address: ${error.destinationAddress}`);
949
+ console.log('The destination address must have a trustline for this token before withdrawal');
950
+ // User needs to create a trustline for the token on Stellar before withdrawing
951
+ }
952
+ }
953
+ ```
954
+
955
+ **What is a trustline?**
956
+ On Stellar, accounts must explicitly create "trustlines" to hold non-native assets. Before receiving any token (except
957
+ XLM), the destination address must:
958
+
959
+ 1. Create a trustline for that specific token
960
+ 2. Have sufficient XLM balance to maintain the trustline
961
+
962
+ **Why this validation matters:**
963
+
964
+ - Prevents failed withdrawals due to missing trustlines
965
+ - Saves gas fees and reduces user frustration
966
+ - Provides clear error messages for troubleshooting
967
+
968
+ Note: This validation only applies to Stellar destinations via Hot Bridge. Other blockchains and routes don't require
969
+ trustline validation.
970
+
971
+ #### Omni Bridge Withdrawal Validation
972
+
973
+ SDK verifies that the token exists on the destination chain.
974
+
975
+ ```typescript
976
+ import { TokenNotFoundInDestinationChainError } from 'amogus-sdk-intents-sdk';
977
+
978
+ try {
979
+ const result = await sdk.processWithdrawal({
980
+ withdrawalParams: {
981
+ assetId: 'nep141:aaaaaa20d9e0e2461697782ef11675f668207961.factory.bridge.near', // Aurora token
982
+ amount: 70000000000000000000n, // 70 Aurora (in smallest units)
983
+ destinationAddress: '0x741b0b0F27c4b4047ecFCcDf4690F749C6Cfd66c',
984
+ feeInclusive: false
985
+ }
986
+ });
987
+ } catch (error) {
988
+ if (error instanceof TokenNotFoundInDestinationChainError) {
989
+ console.log(`Token ${error.token} was not found on ${error.destinationChain}.`);
990
+ }
991
+ }
992
+ ```
993
+
994
+ ### Atomic Multi-Intent Publishing
995
+
996
+ Include pre-signed intents (from other users or prior operations) to be published atomically with your new intent.
997
+ Useful for multi-user coordination and batch operations.
998
+
999
+ ```typescript
1000
+ import type { MultiPayload } from 'amogus-sdk-intents-sdk';
1001
+
1002
+ // Include pre-signed intents before/after your new intent
1003
+ await sdk.signAndSendIntent({
1004
+ intents: [{ intent: "transfer", receiver_id: "alice.near", tokens: {...} }],
1005
+ signedIntents: {
1006
+ before: [preSigned1], // Execute before new intent
1007
+ after: [preSigned2] // Execute after new intent
1008
+ }
1009
+ });
1010
+
1011
+ // Also works with withdrawals
1012
+ await sdk.processWithdrawal({
1013
+ withdrawalParams: {...},
1014
+ intent: {
1015
+ signedIntents: {
1016
+ before: [preSigned1],
1017
+ after: [preSigned2]
1018
+ }
1019
+ }
1020
+ });
1021
+ ```
1022
+
1023
+ **Key Points:**
1024
+ - All intents execute atomically in order: `before` → new intent → `after`
1025
+ - Returned `intentHash` is for your newly created intent, not the included ones
1026
+
1027
+ ## Supported Networks
1028
+
1029
+ For a list of supported chains, see
1030
+ the [Chain Support page](https://docs.near-intents.org/near-intents/chain-address-support) in the Near Intents
1031
+ documentation.
1032
+
1033
+ ## Development
1034
+
1035
+ ### Prerequisites
1036
+
1037
+ - [Node.js](https://nodejs.org/) (v20 or later)
1038
+ - [pnpm](https://pnpm.io/) for package management
1039
+
1040
+ ### Setup
1041
+
1042
+ ```bash
1043
+ # Install dependencies (from the monorepo root)
1044
+ pnpm install
1045
+ ```
1046
+
1047
+ ### Build
1048
+
1049
+ ```bash
1050
+ # Build the package
1051
+ pnpm run build
1052
+
1053
+ # Build in watch mode
1054
+ pnpm run dev
1055
+ ```
1056
+
1057
+ ### Test
1058
+
1059
+ ```bash
1060
+ # Run tests
1061
+ pnpm run test
1062
+
1063
+ # Run tests in watch mode
1064
+ pnpm run test:watch
1065
+ ```
1066
+
1067
+ ### Lint and Format
1068
+
1069
+ ```bash
1070
+ # Check code style
1071
+ pnpm run lint
1072
+
1073
+ # Format code
1074
+ pnpm run format
1075
+ ```
1076
+
1077
+ ## Version History
1078
+
1079
+ See [CHANGELOG.md](./CHANGELOG.md) for detailed version history and migration guides.
1080
+
1081
+ ## Contributing
1082
+
1083
+ This package is part of Near Intents SDK monorepo. Please refer to the main repository's contributing guidelines.
1084
+
1085
+ ## License
1086
+
1087
+ MIT License © 2025 NEAR Foundation