@defuse-protocol/intents-sdk 0.43.3 → 0.44.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.
- package/README.md +143 -21
- package/dist/index.cjs +19 -18
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +7 -5
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +5 -5
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +24 -12
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +19 -7
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +5 -5
- package/dist/src/bridges/direct-bridge/direct-bridge.cjs +22 -10
- package/dist/src/bridges/direct-bridge/direct-bridge.js +16 -4
- package/dist/src/bridges/direct-bridge/error.cjs +2 -2
- package/dist/src/bridges/hot-bridge/error.cjs +4 -26
- package/dist/src/bridges/hot-bridge/error.d.cts +1 -17
- package/dist/src/bridges/hot-bridge/error.d.ts +1 -17
- package/dist/src/bridges/hot-bridge/error.js +1 -21
- package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +10 -10
- package/dist/src/bridges/hot-bridge/hot-bridge.cjs +46 -32
- package/dist/src/bridges/hot-bridge/hot-bridge.js +38 -24
- package/dist/src/bridges/intents-bridge/intents-bridge.cjs +18 -4
- package/dist/src/bridges/intents-bridge/intents-bridge.js +18 -4
- package/dist/src/bridges/omni-bridge/error.cjs +6 -27
- package/dist/src/bridges/omni-bridge/error.d.cts +1 -16
- package/dist/src/bridges/omni-bridge/error.d.ts +1 -16
- package/dist/src/bridges/omni-bridge/error.js +1 -20
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +12 -7
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +5 -1
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +72 -54
- package/dist/src/bridges/omni-bridge/omni-bridge.js +47 -29
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +2 -2
- package/dist/src/bridges/poa-bridge/poa-bridge.cjs +79 -26
- package/dist/src/bridges/poa-bridge/poa-bridge.js +66 -13
- package/dist/src/classes/errors.cjs +7 -7
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
- package/dist/src/constants/withdrawal-timing.cjs +57 -0
- package/dist/src/constants/withdrawal-timing.js +56 -0
- package/dist/src/core/withdrawal-watcher.cjs +83 -0
- package/dist/src/core/withdrawal-watcher.d.cts +18 -0
- package/dist/src/core/withdrawal-watcher.d.ts +18 -0
- package/dist/src/core/withdrawal-watcher.js +79 -0
- package/dist/src/intents/expirable-nonce.cjs +3 -3
- package/dist/src/intents/intent-executer-impl/intent-executer.cjs +7 -4
- package/dist/src/intents/intent-executer-impl/intent-executer.js +5 -2
- package/dist/src/intents/intent-hash.cjs +2 -2
- package/dist/src/intents/intent-hashes/erc191.cjs +2 -2
- package/dist/src/intents/intent-hashes/nep413.cjs +2 -2
- package/dist/src/intents/intent-hashes/raw-ed25519.cjs +2 -2
- package/dist/src/intents/intent-hashes/sep53.cjs +4 -4
- package/dist/src/intents/intent-hashes/tip191.cjs +2 -2
- package/dist/src/intents/intent-hashes/ton-connect.cjs +2 -2
- package/dist/src/intents/intent-hashes/webauthn.cjs +2 -2
- package/dist/src/intents/intent-payload-builder.cjs +4 -4
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +7 -7
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +1 -1
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +2 -2
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +3 -3
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +3 -3
- package/dist/src/intents/interfaces/intent-relayer.d.cts +2 -1
- package/dist/src/intents/interfaces/intent-relayer.d.ts +2 -1
- package/dist/src/intents/salt-manager.cjs +5 -5
- package/dist/src/lib/array.cjs +2 -2
- package/dist/src/lib/caip2.cjs +4 -4
- package/dist/src/lib/configure-rpc-config.cjs +3 -3
- package/dist/src/lib/estimate-fee.cjs +6 -6
- package/dist/src/lib/parse-defuse-asset-id.cjs +2 -2
- package/dist/src/lib/route-config-factory.cjs +2 -5
- package/dist/src/lib/route-config-factory.d.cts +1 -1
- package/dist/src/lib/route-config-factory.d.ts +1 -1
- package/dist/src/lib/route-config-factory.js +2 -5
- package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +3 -3
- package/dist/src/lib/validateAddress.cjs +18 -18
- package/dist/src/sdk.cjs +96 -47
- package/dist/src/sdk.d.cts +72 -11
- package/dist/src/sdk.d.ts +72 -11
- package/dist/src/sdk.js +85 -36
- package/dist/src/shared-types.d.cts +49 -15
- package/dist/src/shared-types.d.ts +49 -15
- package/package.json +4 -6
- package/dist/src/lib/route-config.cjs +0 -19
- package/dist/src/lib/route-config.js +0 -19
package/dist/src/sdk.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IntentHash, IntentPrimitive } from "./intents/shared-types.cjs";
|
|
2
2
|
import { IIntentSigner } from "./intents/interfaces/intent-signer.cjs";
|
|
3
|
-
import { BatchWithdrawalResult, Bridge, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo,
|
|
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
4
|
import { IIntentRelayer } from "./intents/interfaces/intent-relayer.cjs";
|
|
5
5
|
import { ISaltManager } from "./intents/interfaces/salt-manager.cjs";
|
|
6
6
|
import { IntentPayloadBuilder } from "./intents/intent-payload-builder.cjs";
|
|
7
|
-
import { ILogger, NearIntentsEnv
|
|
7
|
+
import { ILogger, NearIntentsEnv } from "@defuse-protocol/internal-utils";
|
|
8
8
|
|
|
9
9
|
//#region src/sdk.d.ts
|
|
10
10
|
interface IntentsSDKConfig {
|
|
@@ -13,6 +13,13 @@ interface IntentsSDKConfig {
|
|
|
13
13
|
rpc?: PartialRPCEndpointMap;
|
|
14
14
|
referral: string;
|
|
15
15
|
solverRelayApiKey?: string;
|
|
16
|
+
features?: {
|
|
17
|
+
/**
|
|
18
|
+
* Route migrated POA tokens (*.omft.near) through Omni Bridge.
|
|
19
|
+
* Enable this to use Omni Bridge for POA tokens that have been migrated to the Omni infrastructure.
|
|
20
|
+
*/
|
|
21
|
+
routeMigratedPoaTokensThroughOmniBridge?: boolean;
|
|
22
|
+
};
|
|
16
23
|
}
|
|
17
24
|
declare class IntentsSDK implements IIntentsSDK {
|
|
18
25
|
protected env: NearIntentsEnv;
|
|
@@ -96,33 +103,87 @@ declare class IntentsSDK implements IIntentsSDK {
|
|
|
96
103
|
quoteOptions?: QuoteOptions;
|
|
97
104
|
logger?: ILogger;
|
|
98
105
|
}): Promise<FeeEstimation>;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Wait for withdrawal(s) to complete on the destination chain.
|
|
108
|
+
*
|
|
109
|
+
* **Important:** Waits until the withdrawal completes, fails, or the chain-specific
|
|
110
|
+
* p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a shorter timeout budget.
|
|
111
|
+
*
|
|
112
|
+
* @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
|
|
113
|
+
* Inspect `error.cause` to determine the reason.
|
|
114
|
+
* @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
|
|
115
|
+
* @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
|
|
116
|
+
*
|
|
117
|
+
* @param args.withdrawalParams - Single withdrawal or array of withdrawals
|
|
118
|
+
* @param args.intentTx - The NEAR transaction info from the published intent
|
|
119
|
+
* @param args.signal - Optional AbortSignal for cancellation/timeout
|
|
120
|
+
* @param args.logger - Optional logger for debugging
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // With timeout
|
|
125
|
+
* const result = await sdk.waitForWithdrawalCompletion({
|
|
126
|
+
* withdrawalParams,
|
|
127
|
+
* intentTx,
|
|
128
|
+
* signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
106
132
|
waitForWithdrawalCompletion(args: {
|
|
107
133
|
withdrawalParams: WithdrawalParams;
|
|
108
134
|
intentTx: NearTxInfo;
|
|
109
135
|
signal?: AbortSignal;
|
|
110
|
-
retryOptions?: RetryOptions;
|
|
111
136
|
logger?: ILogger;
|
|
112
137
|
}): Promise<TxInfo | TxNoInfo>;
|
|
113
138
|
waitForWithdrawalCompletion(args: {
|
|
114
139
|
withdrawalParams: WithdrawalParams[];
|
|
115
140
|
intentTx: NearTxInfo;
|
|
116
141
|
signal?: AbortSignal;
|
|
117
|
-
retryOptions?: RetryOptions;
|
|
118
142
|
logger?: ILogger;
|
|
119
143
|
}): Promise<Array<TxInfo | TxNoInfo>>;
|
|
144
|
+
/**
|
|
145
|
+
* Create promises that resolve when each withdrawal completes on the destination chain.
|
|
146
|
+
* Use this for granular control over handling individual withdrawals as they complete,
|
|
147
|
+
* rather than waiting for all to finish.
|
|
148
|
+
*
|
|
149
|
+
* **Important:** Each promise waits until the withdrawal completes, fails, or the
|
|
150
|
+
* chain-specific p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a
|
|
151
|
+
* shorter timeout budget.
|
|
152
|
+
*
|
|
153
|
+
* @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
|
|
154
|
+
* Inspect `error.cause` to determine the reason.
|
|
155
|
+
* @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
|
|
156
|
+
* @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
|
|
157
|
+
*
|
|
158
|
+
* @param params.withdrawalParams - Array of withdrawal parameters
|
|
159
|
+
* @param params.intentTx - The NEAR transaction info from the published intent
|
|
160
|
+
* @param params.signal - Optional AbortSignal for cancellation/timeout
|
|
161
|
+
* @param params.logger - Optional logger for debugging
|
|
162
|
+
* @returns Array of promises, one per withdrawal, that resolve with transaction info
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const promises = sdk.createWithdrawalCompletionPromises({
|
|
167
|
+
* withdrawalParams: [withdrawal1, withdrawal2],
|
|
168
|
+
* intentTx,
|
|
169
|
+
* signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
|
|
170
|
+
* });
|
|
171
|
+
*
|
|
172
|
+
* // Handle each withdrawal as it completes
|
|
173
|
+
* for (const promise of promises) {
|
|
174
|
+
* promise.then((result) => console.log('Withdrawal completed:', result));
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
createWithdrawalCompletionPromises(params: CreateWithdrawalCompletionPromisesParams): Array<Promise<TxInfo | TxNoInfo>>;
|
|
120
179
|
parseAssetId(assetId: string): ParsedAssetInfo;
|
|
121
180
|
signAndSendIntent(args: SignAndSendArgs): Promise<IntentPublishResult>;
|
|
122
181
|
private withSaltRetry;
|
|
123
182
|
signAndSendWithdrawalIntent(args: SignAndSendWithdrawalArgs<WithdrawalParams> | SignAndSendWithdrawalArgs<WithdrawalParams[]>): Promise<IntentPublishResult>;
|
|
124
183
|
waitForIntentSettlement(args: {
|
|
125
184
|
intentHash: IntentHash;
|
|
185
|
+
/** AbortSignal for cancellation/timeout. Use AbortSignal.timeout(ms) for timeout. */
|
|
186
|
+
signal?: AbortSignal;
|
|
126
187
|
logger?: ILogger;
|
|
127
188
|
}): Promise<NearTxInfo>;
|
|
128
189
|
getIntentStatus({
|
package/dist/src/sdk.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IntentHash, IntentPrimitive } from "./intents/shared-types.js";
|
|
2
2
|
import { IIntentSigner } from "./intents/interfaces/intent-signer.js";
|
|
3
|
-
import { BatchWithdrawalResult, Bridge, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo,
|
|
3
|
+
import { BatchWithdrawalResult, Bridge, CreateWithdrawalCompletionPromisesParams, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalParams, WithdrawalResult } from "./shared-types.js";
|
|
4
4
|
import { IIntentRelayer } from "./intents/interfaces/intent-relayer.js";
|
|
5
5
|
import { ISaltManager } from "./intents/interfaces/salt-manager.js";
|
|
6
6
|
import { IntentPayloadBuilder } from "./intents/intent-payload-builder.js";
|
|
7
|
-
import { ILogger, NearIntentsEnv
|
|
7
|
+
import { ILogger, NearIntentsEnv } from "@defuse-protocol/internal-utils";
|
|
8
8
|
|
|
9
9
|
//#region src/sdk.d.ts
|
|
10
10
|
interface IntentsSDKConfig {
|
|
@@ -13,6 +13,13 @@ interface IntentsSDKConfig {
|
|
|
13
13
|
rpc?: PartialRPCEndpointMap;
|
|
14
14
|
referral: string;
|
|
15
15
|
solverRelayApiKey?: string;
|
|
16
|
+
features?: {
|
|
17
|
+
/**
|
|
18
|
+
* Route migrated POA tokens (*.omft.near) through Omni Bridge.
|
|
19
|
+
* Enable this to use Omni Bridge for POA tokens that have been migrated to the Omni infrastructure.
|
|
20
|
+
*/
|
|
21
|
+
routeMigratedPoaTokensThroughOmniBridge?: boolean;
|
|
22
|
+
};
|
|
16
23
|
}
|
|
17
24
|
declare class IntentsSDK implements IIntentsSDK {
|
|
18
25
|
protected env: NearIntentsEnv;
|
|
@@ -96,33 +103,87 @@ declare class IntentsSDK implements IIntentsSDK {
|
|
|
96
103
|
quoteOptions?: QuoteOptions;
|
|
97
104
|
logger?: ILogger;
|
|
98
105
|
}): Promise<FeeEstimation>;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Wait for withdrawal(s) to complete on the destination chain.
|
|
108
|
+
*
|
|
109
|
+
* **Important:** Waits until the withdrawal completes, fails, or the chain-specific
|
|
110
|
+
* p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a shorter timeout budget.
|
|
111
|
+
*
|
|
112
|
+
* @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
|
|
113
|
+
* Inspect `error.cause` to determine the reason.
|
|
114
|
+
* @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
|
|
115
|
+
* @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
|
|
116
|
+
*
|
|
117
|
+
* @param args.withdrawalParams - Single withdrawal or array of withdrawals
|
|
118
|
+
* @param args.intentTx - The NEAR transaction info from the published intent
|
|
119
|
+
* @param args.signal - Optional AbortSignal for cancellation/timeout
|
|
120
|
+
* @param args.logger - Optional logger for debugging
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // With timeout
|
|
125
|
+
* const result = await sdk.waitForWithdrawalCompletion({
|
|
126
|
+
* withdrawalParams,
|
|
127
|
+
* intentTx,
|
|
128
|
+
* signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
106
132
|
waitForWithdrawalCompletion(args: {
|
|
107
133
|
withdrawalParams: WithdrawalParams;
|
|
108
134
|
intentTx: NearTxInfo;
|
|
109
135
|
signal?: AbortSignal;
|
|
110
|
-
retryOptions?: RetryOptions;
|
|
111
136
|
logger?: ILogger;
|
|
112
137
|
}): Promise<TxInfo | TxNoInfo>;
|
|
113
138
|
waitForWithdrawalCompletion(args: {
|
|
114
139
|
withdrawalParams: WithdrawalParams[];
|
|
115
140
|
intentTx: NearTxInfo;
|
|
116
141
|
signal?: AbortSignal;
|
|
117
|
-
retryOptions?: RetryOptions;
|
|
118
142
|
logger?: ILogger;
|
|
119
143
|
}): Promise<Array<TxInfo | TxNoInfo>>;
|
|
144
|
+
/**
|
|
145
|
+
* Create promises that resolve when each withdrawal completes on the destination chain.
|
|
146
|
+
* Use this for granular control over handling individual withdrawals as they complete,
|
|
147
|
+
* rather than waiting for all to finish.
|
|
148
|
+
*
|
|
149
|
+
* **Important:** Each promise waits until the withdrawal completes, fails, or the
|
|
150
|
+
* chain-specific p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a
|
|
151
|
+
* shorter timeout budget.
|
|
152
|
+
*
|
|
153
|
+
* @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
|
|
154
|
+
* Inspect `error.cause` to determine the reason.
|
|
155
|
+
* @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
|
|
156
|
+
* @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
|
|
157
|
+
*
|
|
158
|
+
* @param params.withdrawalParams - Array of withdrawal parameters
|
|
159
|
+
* @param params.intentTx - The NEAR transaction info from the published intent
|
|
160
|
+
* @param params.signal - Optional AbortSignal for cancellation/timeout
|
|
161
|
+
* @param params.logger - Optional logger for debugging
|
|
162
|
+
* @returns Array of promises, one per withdrawal, that resolve with transaction info
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const promises = sdk.createWithdrawalCompletionPromises({
|
|
167
|
+
* withdrawalParams: [withdrawal1, withdrawal2],
|
|
168
|
+
* intentTx,
|
|
169
|
+
* signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
|
|
170
|
+
* });
|
|
171
|
+
*
|
|
172
|
+
* // Handle each withdrawal as it completes
|
|
173
|
+
* for (const promise of promises) {
|
|
174
|
+
* promise.then((result) => console.log('Withdrawal completed:', result));
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
createWithdrawalCompletionPromises(params: CreateWithdrawalCompletionPromisesParams): Array<Promise<TxInfo | TxNoInfo>>;
|
|
120
179
|
parseAssetId(assetId: string): ParsedAssetInfo;
|
|
121
180
|
signAndSendIntent(args: SignAndSendArgs): Promise<IntentPublishResult>;
|
|
122
181
|
private withSaltRetry;
|
|
123
182
|
signAndSendWithdrawalIntent(args: SignAndSendWithdrawalArgs<WithdrawalParams> | SignAndSendWithdrawalArgs<WithdrawalParams[]>): Promise<IntentPublishResult>;
|
|
124
183
|
waitForIntentSettlement(args: {
|
|
125
184
|
intentHash: IntentHash;
|
|
185
|
+
/** AbortSignal for cancellation/timeout. Use AbortSignal.timeout(ms) for timeout. */
|
|
186
|
+
signal?: AbortSignal;
|
|
126
187
|
logger?: ILogger;
|
|
127
188
|
}): Promise<NearTxInfo>;
|
|
128
189
|
getIntentStatus({
|
package/dist/src/sdk.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FeeExceedsAmountError } from "./classes/errors.js";
|
|
2
|
+
import { RouteEnum } from "./constants/route-enum.js";
|
|
2
3
|
import { Chains } from "./lib/caip2.js";
|
|
3
4
|
import { AuroraEngineBridge } from "./bridges/aurora-engine-bridge/aurora-engine-bridge.js";
|
|
4
5
|
import { DirectBridge } from "./bridges/direct-bridge/direct-bridge.js";
|
|
@@ -15,10 +16,10 @@ import { IntentRelayerPublic } from "./intents/intent-relayer-impl/intent-relaye
|
|
|
15
16
|
import { noopIntentSigner } from "./intents/intent-signer-impl/intent-signer-noop.js";
|
|
16
17
|
import { zip } from "./lib/array.js";
|
|
17
18
|
import { configureEvmRpcUrls, configureStellarRpcUrls } from "./lib/configure-rpc-config.js";
|
|
18
|
-
import {
|
|
19
|
+
import { createWithdrawalIdentifiers, watchWithdrawal } from "./core/withdrawal-watcher.js";
|
|
19
20
|
import { SaltManager } from "./intents/salt-manager.js";
|
|
20
21
|
import { IntentPayloadBuilder } from "./intents/intent-payload-builder.js";
|
|
21
|
-
import { PUBLIC_NEAR_RPC_URLS,
|
|
22
|
+
import { PUBLIC_NEAR_RPC_URLS, RelayPublishError, assert, configsByEnvironment, nearFailoverRpcProvider, solverRelay } from "@defuse-protocol/internal-utils";
|
|
22
23
|
import { HotBridge } from "@hot-labs/omni-sdk";
|
|
23
24
|
import { stringify } from "viem";
|
|
24
25
|
import * as v from "valibot";
|
|
@@ -45,7 +46,10 @@ var IntentsSDK = class {
|
|
|
45
46
|
nearProvider,
|
|
46
47
|
solverRelayApiKey: this.solverRelayApiKey
|
|
47
48
|
}),
|
|
48
|
-
new PoaBridge({
|
|
49
|
+
new PoaBridge({
|
|
50
|
+
env: this.env,
|
|
51
|
+
routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge
|
|
52
|
+
}),
|
|
49
53
|
new HotBridge$1({
|
|
50
54
|
env: this.env,
|
|
51
55
|
solverRelayApiKey: this.solverRelayApiKey,
|
|
@@ -63,7 +67,8 @@ var IntentsSDK = class {
|
|
|
63
67
|
new OmniBridge({
|
|
64
68
|
env: this.env,
|
|
65
69
|
nearProvider,
|
|
66
|
-
solverRelayApiKey: this.solverRelayApiKey
|
|
70
|
+
solverRelayApiKey: this.solverRelayApiKey,
|
|
71
|
+
routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge
|
|
67
72
|
}),
|
|
68
73
|
new DirectBridge({
|
|
69
74
|
env: this.env,
|
|
@@ -205,42 +210,87 @@ var IntentsSDK = class {
|
|
|
205
210
|
}
|
|
206
211
|
throw new Error(`Cannot determine bridge for withdrawal = ${stringify(args.withdrawalParams)}`);
|
|
207
212
|
}
|
|
208
|
-
getWithdrawalsIdentifiers({ withdrawalParams, intentTx }) {
|
|
209
|
-
const indexes = /* @__PURE__ */ new Map();
|
|
210
|
-
return withdrawalParams.map((w) => {
|
|
211
|
-
const routeConfig = determineRouteConfig(this, w);
|
|
212
|
-
const route = routeConfig.route;
|
|
213
|
-
const currentIndex = indexes.get(route) ?? 0;
|
|
214
|
-
indexes.set(route, currentIndex + 1);
|
|
215
|
-
return {
|
|
216
|
-
routeConfig,
|
|
217
|
-
index: currentIndex,
|
|
218
|
-
withdrawalParams: w,
|
|
219
|
-
tx: intentTx
|
|
220
|
-
};
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
213
|
async waitForWithdrawalCompletion(args) {
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
214
|
+
const withdrawalParamsArray = Array.isArray(args.withdrawalParams) ? args.withdrawalParams : [args.withdrawalParams];
|
|
215
|
+
const promises = this.createWithdrawalCompletionPromises({
|
|
216
|
+
withdrawalParams: withdrawalParamsArray,
|
|
217
|
+
intentTx: args.intentTx,
|
|
218
|
+
signal: args.signal,
|
|
219
|
+
logger: args.logger
|
|
227
220
|
});
|
|
228
|
-
const result = await Promise.all(
|
|
229
|
-
for (const bridge of this.bridges) if (bridge.is(wid.routeConfig)) return bridge.waitForWithdrawalCompletion({
|
|
230
|
-
tx: args.intentTx,
|
|
231
|
-
index: wid.index,
|
|
232
|
-
withdrawalParams: wid.withdrawalParams,
|
|
233
|
-
routeConfig: wid.routeConfig,
|
|
234
|
-
signal: args.signal,
|
|
235
|
-
retryOptions: args.retryOptions,
|
|
236
|
-
logger: args.logger
|
|
237
|
-
});
|
|
238
|
-
throw new Error(`Unsupported route = ${stringify(wid.routeConfig)}`);
|
|
239
|
-
}));
|
|
221
|
+
const result = await Promise.all(promises);
|
|
240
222
|
if (Array.isArray(args.withdrawalParams)) return result;
|
|
241
223
|
assert(result.length === 1, "Unexpected result length");
|
|
242
224
|
return result[0];
|
|
243
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Create promises that resolve when each withdrawal completes on the destination chain.
|
|
228
|
+
* Use this for granular control over handling individual withdrawals as they complete,
|
|
229
|
+
* rather than waiting for all to finish.
|
|
230
|
+
*
|
|
231
|
+
* **Important:** Each promise waits until the withdrawal completes, fails, or the
|
|
232
|
+
* chain-specific p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a
|
|
233
|
+
* shorter timeout budget.
|
|
234
|
+
*
|
|
235
|
+
* @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
|
|
236
|
+
* Inspect `error.cause` to determine the reason.
|
|
237
|
+
* @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
|
|
238
|
+
* @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
|
|
239
|
+
*
|
|
240
|
+
* @param params.withdrawalParams - Array of withdrawal parameters
|
|
241
|
+
* @param params.intentTx - The NEAR transaction info from the published intent
|
|
242
|
+
* @param params.signal - Optional AbortSignal for cancellation/timeout
|
|
243
|
+
* @param params.logger - Optional logger for debugging
|
|
244
|
+
* @returns Array of promises, one per withdrawal, that resolve with transaction info
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* const promises = sdk.createWithdrawalCompletionPromises({
|
|
249
|
+
* withdrawalParams: [withdrawal1, withdrawal2],
|
|
250
|
+
* intentTx,
|
|
251
|
+
* signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
|
|
252
|
+
* });
|
|
253
|
+
*
|
|
254
|
+
* // Handle each withdrawal as it completes
|
|
255
|
+
* for (const promise of promises) {
|
|
256
|
+
* promise.then((result) => console.log('Withdrawal completed:', result));
|
|
257
|
+
* }
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
createWithdrawalCompletionPromises(params) {
|
|
261
|
+
const { withdrawalParams, intentTx, signal, logger } = params;
|
|
262
|
+
const widsPromise = createWithdrawalIdentifiers({
|
|
263
|
+
bridges: this.bridges,
|
|
264
|
+
withdrawalParams,
|
|
265
|
+
intentTx
|
|
266
|
+
});
|
|
267
|
+
const hotChainLastPromise = /* @__PURE__ */ new Map();
|
|
268
|
+
return withdrawalParams.map(async (_, index) => {
|
|
269
|
+
const entry = (await widsPromise)[index];
|
|
270
|
+
assert(entry != null, `Missing wid for index ${index}`);
|
|
271
|
+
if (entry.bridge.route === RouteEnum.HotBridge) {
|
|
272
|
+
const landingChain = entry.wid.landingChain;
|
|
273
|
+
const previousPromise = hotChainLastPromise.get(landingChain);
|
|
274
|
+
const sequentialPromise = (async () => {
|
|
275
|
+
if (previousPromise) await Promise.allSettled([previousPromise]);
|
|
276
|
+
return watchWithdrawal({
|
|
277
|
+
bridge: entry.bridge,
|
|
278
|
+
wid: entry.wid,
|
|
279
|
+
signal,
|
|
280
|
+
logger
|
|
281
|
+
});
|
|
282
|
+
})();
|
|
283
|
+
hotChainLastPromise.set(landingChain, sequentialPromise);
|
|
284
|
+
return sequentialPromise;
|
|
285
|
+
}
|
|
286
|
+
return watchWithdrawal({
|
|
287
|
+
bridge: entry.bridge,
|
|
288
|
+
wid: entry.wid,
|
|
289
|
+
signal,
|
|
290
|
+
logger
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
}
|
|
244
294
|
parseAssetId(assetId) {
|
|
245
295
|
for (const bridge of this.bridges) {
|
|
246
296
|
const parsed = bridge.parseAssetId(assetId);
|
|
@@ -320,7 +370,7 @@ var IntentsSDK = class {
|
|
|
320
370
|
logger: args.logger,
|
|
321
371
|
intentSigner: noopIntentSigner,
|
|
322
372
|
intentRelayer: this.intentRelayer
|
|
323
|
-
}).waitForSettlement(args.intentHash);
|
|
373
|
+
}).waitForSettlement(args.intentHash, { signal: args.signal });
|
|
324
374
|
return tx;
|
|
325
375
|
}
|
|
326
376
|
async getIntentStatus({ intentHash, logger }) {
|
|
@@ -353,7 +403,6 @@ var IntentsSDK = class {
|
|
|
353
403
|
const destinationTx = await this.waitForWithdrawalCompletion({
|
|
354
404
|
withdrawalParams,
|
|
355
405
|
intentTx,
|
|
356
|
-
retryOptions: args.retryOptions ?? RETRY_CONFIGS.FIVE_MINS_STEADY,
|
|
357
406
|
logger: args.logger
|
|
358
407
|
});
|
|
359
408
|
if (!Array.isArray(args.withdrawalParams)) return {
|
|
@@ -5,7 +5,7 @@ import { IntentHash, IntentPayloadFactory, IntentPrimitive, IntentRelayParamsFac
|
|
|
5
5
|
import { IIntentSigner } from "./intents/interfaces/intent-signer.cjs";
|
|
6
6
|
import { OnBeforePublishIntentHook } from "./intents/intent-executer-impl/intent-executer.cjs";
|
|
7
7
|
import { Chain, Chains } from "./lib/caip2.cjs";
|
|
8
|
-
import { ILogger,
|
|
8
|
+
import { ILogger, solverRelay } from "@defuse-protocol/internal-utils";
|
|
9
9
|
|
|
10
10
|
//#region src/shared-types.d.ts
|
|
11
11
|
interface IntentPublishResult {
|
|
@@ -106,7 +106,6 @@ type ProcessWithdrawalArgs<T extends WithdrawalParams | WithdrawalParams[]> = {
|
|
|
106
106
|
signedIntents?: SignedIntentsComposition;
|
|
107
107
|
};
|
|
108
108
|
referral?: string;
|
|
109
|
-
retryOptions?: RetryOptions;
|
|
110
109
|
logger?: ILogger;
|
|
111
110
|
};
|
|
112
111
|
interface IIntentsSDK {
|
|
@@ -114,6 +113,8 @@ interface IIntentsSDK {
|
|
|
114
113
|
signAndSendIntent(args: SignAndSendArgs): Promise<IntentPublishResult>;
|
|
115
114
|
waitForIntentSettlement(args: {
|
|
116
115
|
intentHash: IntentHash;
|
|
116
|
+
/** AbortSignal for cancellation/timeout. Use AbortSignal.timeout(ms) for timeout. */
|
|
117
|
+
signal?: AbortSignal;
|
|
117
118
|
logger?: ILogger;
|
|
118
119
|
}): Promise<NearTxInfo>;
|
|
119
120
|
getIntentStatus(args: {
|
|
@@ -140,16 +141,15 @@ interface IIntentsSDK {
|
|
|
140
141
|
withdrawalParams: WithdrawalParams;
|
|
141
142
|
intentTx: NearTxInfo;
|
|
142
143
|
signal?: AbortSignal;
|
|
143
|
-
retryOptions?: RetryOptions;
|
|
144
144
|
logger?: ILogger;
|
|
145
145
|
}): Promise<TxInfo | TxNoInfo>;
|
|
146
146
|
waitForWithdrawalCompletion(args: {
|
|
147
147
|
withdrawalParams: WithdrawalParams[];
|
|
148
148
|
intentTx: NearTxInfo;
|
|
149
149
|
signal?: AbortSignal;
|
|
150
|
-
retryOptions?: RetryOptions;
|
|
151
150
|
logger?: ILogger;
|
|
152
151
|
}): Promise<Array<TxInfo | TxNoInfo>>;
|
|
152
|
+
createWithdrawalCompletionPromises(params: CreateWithdrawalCompletionPromisesParams): Array<Promise<TxInfo | TxNoInfo>>;
|
|
153
153
|
createWithdrawalIntents(args: {
|
|
154
154
|
withdrawalParams: WithdrawalParams;
|
|
155
155
|
feeEstimation: FeeEstimation;
|
|
@@ -176,6 +176,12 @@ interface TxInfo {
|
|
|
176
176
|
interface TxNoInfo {
|
|
177
177
|
hash: null;
|
|
178
178
|
}
|
|
179
|
+
interface CreateWithdrawalCompletionPromisesParams {
|
|
180
|
+
withdrawalParams: WithdrawalParams[];
|
|
181
|
+
intentTx: NearTxInfo;
|
|
182
|
+
signal?: AbortSignal;
|
|
183
|
+
logger?: ILogger;
|
|
184
|
+
}
|
|
179
185
|
interface WithdrawalParams {
|
|
180
186
|
assetId: string;
|
|
181
187
|
amount: bigint;
|
|
@@ -201,7 +207,6 @@ type VirtualChainRouteConfig = {
|
|
|
201
207
|
};
|
|
202
208
|
type PoaBridgeRouteConfig = {
|
|
203
209
|
route: RouteEnum["PoaBridge"];
|
|
204
|
-
chain: Chain;
|
|
205
210
|
};
|
|
206
211
|
type HotBridgeRouteConfig = {
|
|
207
212
|
route: RouteEnum["HotBridge"];
|
|
@@ -266,7 +271,7 @@ interface FeeEstimation {
|
|
|
266
271
|
underlyingFees: UnderlyingFees;
|
|
267
272
|
}
|
|
268
273
|
interface Bridge {
|
|
269
|
-
|
|
274
|
+
readonly route: RouteEnumValues;
|
|
270
275
|
supports(params: Pick<WithdrawalParams, "assetId" | "routeConfig">): Promise<boolean>;
|
|
271
276
|
parseAssetId(assetId: string): ParsedAssetInfo | null;
|
|
272
277
|
/**
|
|
@@ -295,22 +300,51 @@ interface Bridge {
|
|
|
295
300
|
feeEstimation: FeeEstimation;
|
|
296
301
|
referral?: string;
|
|
297
302
|
}): Promise<IntentPrimitive[]>;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Creates a complete withdrawal identifier with all required info.
|
|
305
|
+
* Derives landingChain from withdrawalParams.routeConfig.chain if available, otherwise from assetId.
|
|
306
|
+
*/
|
|
307
|
+
createWithdrawalIdentifier(args: {
|
|
301
308
|
withdrawalParams: WithdrawalParams;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
309
|
+
index: number;
|
|
310
|
+
tx: NearTxInfo;
|
|
311
|
+
}): WithdrawalIdentifier;
|
|
312
|
+
/**
|
|
313
|
+
* One-shot status check for a withdrawal.
|
|
314
|
+
* Returns the current status without polling.
|
|
315
|
+
*/
|
|
316
|
+
describeWithdrawal(args: WithdrawalIdentifier & {
|
|
305
317
|
logger?: ILogger;
|
|
306
|
-
}): Promise<
|
|
318
|
+
}): Promise<WithdrawalStatus>;
|
|
307
319
|
}
|
|
308
320
|
interface WithdrawalIdentifier {
|
|
309
|
-
|
|
321
|
+
/** Actual chain where funds arrive; Near for virtual/internal routes */
|
|
322
|
+
landingChain: Chain;
|
|
323
|
+
/** Per-bridge withdrawal sequence number */
|
|
310
324
|
index: number;
|
|
311
325
|
withdrawalParams: WithdrawalParams;
|
|
312
326
|
tx: NearTxInfo;
|
|
313
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Represents the current state of a withdrawal as returned by bridge adapters.
|
|
330
|
+
*
|
|
331
|
+
* Error handling follows AWS SDK "describe" API patterns:
|
|
332
|
+
* - **Thrown errors**: Infrastructure failures (network, auth, service unavailable).
|
|
333
|
+
* Meaning: "I couldn't check the status."
|
|
334
|
+
* - **`failed` status**: Job-level failure reported by the bridge.
|
|
335
|
+
* Meaning: "I checked, and the withdrawal failed."
|
|
336
|
+
*
|
|
337
|
+
* @see https://docs.aws.amazon.com/AmazonS3/latest/userguide/batch-ops-job-status.html
|
|
338
|
+
*/
|
|
339
|
+
type WithdrawalStatus = {
|
|
340
|
+
status: "pending";
|
|
341
|
+
} | {
|
|
342
|
+
status: "completed";
|
|
343
|
+
txHash: string | null;
|
|
344
|
+
} | {
|
|
345
|
+
status: "failed";
|
|
346
|
+
reason: string;
|
|
347
|
+
};
|
|
314
348
|
type ParsedAssetInfo = ({
|
|
315
349
|
blockchain: Chain;
|
|
316
350
|
bridgeName: BridgeNameEnumValues;
|
|
@@ -334,4 +368,4 @@ type RPCEndpointMap = Record<typeof Chains.Near | HotBridgeEVMChain, string[]> &
|
|
|
334
368
|
type DeepPartial<T> = T extends object ? T extends Array<infer U> ? Array<DeepPartial<U>> : T extends Function ? T : { [P in keyof T]?: DeepPartial<T[P]> } : T;
|
|
335
369
|
type PartialRPCEndpointMap = DeepPartial<RPCEndpointMap>;
|
|
336
370
|
//#endregion
|
|
337
|
-
export { BatchWithdrawalResult, Bridge, FeeEstimation, HotBridgeRouteConfig, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PartialRPCEndpointMap, PoaBridgeRouteConfig, ProcessWithdrawalArgs, QuoteOptions, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult };
|
|
371
|
+
export { BatchWithdrawalResult, Bridge, CreateWithdrawalCompletionPromisesParams, FeeEstimation, HotBridgeRouteConfig, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PartialRPCEndpointMap, PoaBridgeRouteConfig, ProcessWithdrawalArgs, QuoteOptions, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult };
|