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.
- package/LICENSE +21 -0
- package/README.md +1083 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/index.cjs +124 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +19 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.cjs +10 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.js +7 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +44 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.js +42 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +111 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +110 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-constants.cjs +8 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-constants.js +6 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +47 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.js +44 -0
- package/dist/src/bridges/direct-bridge/direct-bridge.cjs +155 -0
- package/dist/src/bridges/direct-bridge/direct-bridge.js +154 -0
- package/dist/src/bridges/direct-bridge/error.cjs +16 -0
- package/dist/src/bridges/direct-bridge/error.d.cts +12 -0
- package/dist/src/bridges/direct-bridge/error.d.ts +12 -0
- package/dist/src/bridges/direct-bridge/error.js +15 -0
- package/dist/src/bridges/hot-bridge/error.cjs +23 -0
- package/dist/src/bridges/hot-bridge/error.d.cts +19 -0
- package/dist/src/bridges/hot-bridge/error.d.ts +19 -0
- package/dist/src/bridges/hot-bridge/error.js +21 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.cjs +21 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.cts +6 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.ts +6 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.js +20 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-constants.cjs +11 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-constants.js +9 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +66 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-utils.js +61 -0
- package/dist/src/bridges/hot-bridge/hot-bridge.cjs +241 -0
- package/dist/src/bridges/hot-bridge/hot-bridge.js +239 -0
- package/dist/src/bridges/intents-bridge/intents-bridge.cjs +59 -0
- package/dist/src/bridges/intents-bridge/intents-bridge.js +59 -0
- package/dist/src/bridges/omni-bridge/error.cjs +54 -0
- package/dist/src/bridges/omni-bridge/error.d.cts +41 -0
- package/dist/src/bridges/omni-bridge/error.d.ts +41 -0
- package/dist/src/bridges/omni-bridge/error.js +49 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.cjs +12 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.js +8 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +153 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +143 -0
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +316 -0
- package/dist/src/bridges/omni-bridge/omni-bridge.js +314 -0
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +76 -0
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +73 -0
- package/dist/src/bridges/poa-bridge/poa-bridge.cjs +175 -0
- package/dist/src/bridges/poa-bridge/poa-bridge.js +173 -0
- package/dist/src/bridges/poa-bridge/poa-constants.cjs +6 -0
- package/dist/src/bridges/poa-bridge/poa-constants.js +5 -0
- package/dist/src/classes/errors.cjs +87 -0
- package/dist/src/classes/errors.d.cts +48 -0
- package/dist/src/classes/errors.d.ts +48 -0
- package/dist/src/classes/errors.js +81 -0
- package/dist/src/constants/bridge-name-enum.cjs +11 -0
- package/dist/src/constants/bridge-name-enum.d.cts +11 -0
- package/dist/src/constants/bridge-name-enum.d.ts +11 -0
- package/dist/src/constants/bridge-name-enum.js +10 -0
- 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/public-rpc-urls.cjs +25 -0
- package/dist/src/constants/public-rpc-urls.js +24 -0
- package/dist/src/constants/route-enum.cjs +13 -0
- package/dist/src/constants/route-enum.d.cts +13 -0
- package/dist/src/constants/route-enum.d.ts +13 -0
- package/dist/src/constants/route-enum.js +12 -0
- package/dist/src/constants/withdrawal-timing.cjs +68 -0
- package/dist/src/constants/withdrawal-timing.js +68 -0
- package/dist/src/core/withdrawal-watcher.cjs +86 -0
- package/dist/src/core/withdrawal-watcher.d.cts +18 -0
- package/dist/src/core/withdrawal-watcher.d.ts +19 -0
- package/dist/src/core/withdrawal-watcher.js +82 -0
- package/dist/src/intents/expirable-nonce.cjs +90 -0
- package/dist/src/intents/expirable-nonce.d.cts +44 -0
- package/dist/src/intents/expirable-nonce.d.ts +45 -0
- package/dist/src/intents/expirable-nonce.js +82 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.cjs +85 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.d.cts +20 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.d.ts +24 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.js +85 -0
- package/dist/src/intents/intent-hash.cjs +48 -0
- package/dist/src/intents/intent-hash.d.cts +8 -0
- package/dist/src/intents/intent-hash.d.ts +8 -0
- package/dist/src/intents/intent-hash.js +47 -0
- package/dist/src/intents/intent-hashes/erc191.cjs +38 -0
- package/dist/src/intents/intent-hashes/erc191.js +37 -0
- package/dist/src/intents/intent-hashes/nep413.cjs +23 -0
- package/dist/src/intents/intent-hashes/nep413.js +22 -0
- package/dist/src/intents/intent-hashes/raw-ed25519.cjs +26 -0
- package/dist/src/intents/intent-hashes/raw-ed25519.js +25 -0
- package/dist/src/intents/intent-hashes/sep53.cjs +36 -0
- package/dist/src/intents/intent-hashes/sep53.js +35 -0
- package/dist/src/intents/intent-hashes/tip191.cjs +39 -0
- package/dist/src/intents/intent-hashes/tip191.js +38 -0
- package/dist/src/intents/intent-hashes/ton-connect.cjs +105 -0
- package/dist/src/intents/intent-hashes/ton-connect.js +104 -0
- package/dist/src/intents/intent-hashes/webauthn.cjs +26 -0
- package/dist/src/intents/intent-hashes/webauthn.js +25 -0
- package/dist/src/intents/intent-payload-builder.cjs +208 -0
- package/dist/src/intents/intent-payload-builder.d.cts +161 -0
- package/dist/src/intents/intent-payload-builder.d.ts +161 -0
- package/dist/src/intents/intent-payload-builder.js +207 -0
- package/dist/src/intents/intent-payload-factory.cjs +23 -0
- package/dist/src/intents/intent-payload-factory.js +21 -0
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +43 -0
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +42 -0
- package/dist/src/intents/intent-signer-impl/factories.cjs +19 -0
- package/dist/src/intents/intent-signer-impl/factories.d.cts +11 -0
- package/dist/src/intents/intent-signer-impl/factories.d.ts +11 -0
- package/dist/src/intents/intent-signer-impl/factories.js +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +22 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.cts +15 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts +16 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.js +21 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +37 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.cts +14 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.ts +14 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.js +36 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-noop.cjs +8 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-noop.js +7 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +31 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.cts +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.ts +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.js +30 -0
- package/dist/src/intents/interfaces/intent-executer.d.ts +2 -0
- package/dist/src/intents/interfaces/intent-relayer.d.cts +43 -0
- package/dist/src/intents/interfaces/intent-relayer.d.ts +43 -0
- package/dist/src/intents/interfaces/intent-signer.d.cts +8 -0
- package/dist/src/intents/interfaces/intent-signer.d.ts +8 -0
- package/dist/src/intents/interfaces/salt-manager.d.cts +9 -0
- package/dist/src/intents/interfaces/salt-manager.d.ts +9 -0
- package/dist/src/intents/salt-manager.cjs +74 -0
- package/dist/src/intents/salt-manager.js +72 -0
- package/dist/src/intents/shared-types.d.cts +20 -0
- package/dist/src/intents/shared-types.d.ts +20 -0
- package/dist/src/lib/array.cjs +11 -0
- package/dist/src/lib/array.js +10 -0
- package/dist/src/lib/caip2.cjs +50 -0
- package/dist/src/lib/caip2.d.cts +38 -0
- package/dist/src/lib/caip2.d.ts +38 -0
- package/dist/src/lib/caip2.js +48 -0
- package/dist/src/lib/configure-rpc-config.cjs +20 -0
- package/dist/src/lib/configure-rpc-config.js +18 -0
- package/dist/src/lib/estimate-fee.cjs +96 -0
- package/dist/src/lib/estimate-fee.js +94 -0
- package/dist/src/lib/hex.cjs +11 -0
- package/dist/src/lib/hex.js +10 -0
- package/dist/src/lib/nep413.cjs +42 -0
- package/dist/src/lib/nep413.d.cts +14 -0
- package/dist/src/lib/nep413.d.ts +14 -0
- package/dist/src/lib/nep413.js +41 -0
- package/dist/src/lib/object.cjs +10 -0
- package/dist/src/lib/object.js +9 -0
- package/dist/src/lib/parse-defuse-asset-id.cjs +15 -0
- package/dist/src/lib/parse-defuse-asset-id.js +14 -0
- package/dist/src/lib/route-config-factory.cjs +43 -0
- package/dist/src/lib/route-config-factory.d.cts +13 -0
- package/dist/src/lib/route-config-factory.d.ts +13 -0
- package/dist/src/lib/route-config-factory.js +37 -0
- package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +17 -0
- package/dist/src/lib/tokensUsdPricesHttpClient/apis.js +16 -0
- package/dist/src/lib/validateAddress.cjs +271 -0
- package/dist/src/lib/validateAddress.d.cts +14 -0
- package/dist/src/lib/validateAddress.d.ts +14 -0
- package/dist/src/lib/validateAddress.js +270 -0
- package/dist/src/sdk.cjs +435 -0
- package/dist/src/sdk.d.cts +231 -0
- package/dist/src/sdk.d.ts +231 -0
- package/dist/src/sdk.js +433 -0
- package/dist/src/shared-types.d.cts +378 -0
- package/dist/src/shared-types.d.ts +378 -0
- package/package.json +62 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { IntentHash, IntentPrimitive, MultiPayload } from "./intents/shared-types.js";
|
|
2
|
+
import { IIntentSigner } from "./intents/interfaces/intent-signer.js";
|
|
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
|
+
import { IIntentRelayer } from "./intents/interfaces/intent-relayer.js";
|
|
5
|
+
import { ISaltManager } from "./intents/interfaces/salt-manager.js";
|
|
6
|
+
import { IntentPayloadBuilder } from "./intents/intent-payload-builder.js";
|
|
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 };
|
package/dist/src/sdk.js
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { FeeExceedsAmountError } from "./classes/errors.js";
|
|
2
|
+
import { RouteEnum } from "./constants/route-enum.js";
|
|
3
|
+
import { Chains } from "./lib/caip2.js";
|
|
4
|
+
import { AuroraEngineBridge } from "./bridges/aurora-engine-bridge/aurora-engine-bridge.js";
|
|
5
|
+
import { DirectBridge } from "./bridges/direct-bridge/direct-bridge.js";
|
|
6
|
+
import { HotBridgeEVMChains } from "./bridges/hot-bridge/hot-bridge-chains.js";
|
|
7
|
+
import { HotBridge as HotBridge$1 } from "./bridges/hot-bridge/hot-bridge.js";
|
|
8
|
+
import { IntentsBridge } from "./bridges/intents-bridge/intents-bridge.js";
|
|
9
|
+
import { OmniBridge } from "./bridges/omni-bridge/omni-bridge.js";
|
|
10
|
+
import { PoaBridge } from "./bridges/poa-bridge/poa-bridge.js";
|
|
11
|
+
import { PUBLIC_EVM_RPC_URLS, PUBLIC_STELLAR_RPC_URLS } from "./constants/public-rpc-urls.js";
|
|
12
|
+
import { VersionedNonceBuilder, saltedNonceSchema } from "./intents/expirable-nonce.js";
|
|
13
|
+
import { DEFAULT_DEADLINE_MS } from "./intents/intent-payload-factory.js";
|
|
14
|
+
import { IntentExecuter } from "./intents/intent-executer-impl/intent-executer.js";
|
|
15
|
+
import { IntentRelayerPublic } from "./intents/intent-relayer-impl/intent-relayer-public.js";
|
|
16
|
+
import { noopIntentSigner } from "./intents/intent-signer-impl/intent-signer-noop.js";
|
|
17
|
+
import { zip } from "./lib/array.js";
|
|
18
|
+
import { configureEvmRpcUrls, configureStellarRpcUrls } from "./lib/configure-rpc-config.js";
|
|
19
|
+
import { createWithdrawalIdentifiers, watchWithdrawal } from "./core/withdrawal-watcher.js";
|
|
20
|
+
import { SaltManager } from "./intents/salt-manager.js";
|
|
21
|
+
import { IntentPayloadBuilder } from "./intents/intent-payload-builder.js";
|
|
22
|
+
import { PUBLIC_NEAR_RPC_URLS, RelayPublishError, assert, nearFailoverRpcProvider, resolveEnvConfig, solverRelay } from "lampamazaza-internal-utils";
|
|
23
|
+
import { HotBridge } from "@hot-labs/omni-sdk";
|
|
24
|
+
import { stringify } from "viem";
|
|
25
|
+
import * as v from "valibot";
|
|
26
|
+
|
|
27
|
+
//#region src/sdk.ts
|
|
28
|
+
var IntentsSDK = class {
|
|
29
|
+
constructor(args) {
|
|
30
|
+
this.envConfig = resolveEnvConfig(args.env);
|
|
31
|
+
this.referral = args.referral;
|
|
32
|
+
this.solverRelayApiKey = args.solverRelayApiKey;
|
|
33
|
+
const nearRpcUrls = args.rpc?.[Chains.Near] ?? PUBLIC_NEAR_RPC_URLS;
|
|
34
|
+
assert(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
|
|
35
|
+
const nearProvider = nearFailoverRpcProvider({ urls: nearRpcUrls });
|
|
36
|
+
const stellarRpcUrls = configureStellarRpcUrls(PUBLIC_STELLAR_RPC_URLS, args.rpc);
|
|
37
|
+
const evmRpcUrls = configureEvmRpcUrls(PUBLIC_EVM_RPC_URLS, args.rpc, HotBridgeEVMChains);
|
|
38
|
+
/**
|
|
39
|
+
* Order of bridges matters, because the first bridge that supports the `withdrawalParams` will be used.
|
|
40
|
+
* More specific bridges should be placed before more generic ones.
|
|
41
|
+
*/
|
|
42
|
+
this.bridges = [
|
|
43
|
+
new IntentsBridge(),
|
|
44
|
+
new AuroraEngineBridge({
|
|
45
|
+
envConfig: this.envConfig,
|
|
46
|
+
nearProvider,
|
|
47
|
+
solverRelayApiKey: this.solverRelayApiKey
|
|
48
|
+
}),
|
|
49
|
+
new PoaBridge({
|
|
50
|
+
envConfig: this.envConfig,
|
|
51
|
+
routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge
|
|
52
|
+
}),
|
|
53
|
+
new HotBridge$1({
|
|
54
|
+
envConfig: this.envConfig,
|
|
55
|
+
solverRelayApiKey: this.solverRelayApiKey,
|
|
56
|
+
hotSdk: new HotBridge({
|
|
57
|
+
logger: console,
|
|
58
|
+
evmRpc: evmRpcUrls,
|
|
59
|
+
nearRpc: nearRpcUrls,
|
|
60
|
+
stellarRpc: stellarRpcUrls.soroban,
|
|
61
|
+
stellarHorizonRpc: stellarRpcUrls.horizon,
|
|
62
|
+
async executeNearTransaction() {
|
|
63
|
+
throw new Error("not implemented");
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}),
|
|
67
|
+
new OmniBridge({
|
|
68
|
+
envConfig: this.envConfig,
|
|
69
|
+
nearProvider,
|
|
70
|
+
solverRelayApiKey: this.solverRelayApiKey,
|
|
71
|
+
routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge
|
|
72
|
+
}),
|
|
73
|
+
new DirectBridge({
|
|
74
|
+
envConfig: this.envConfig,
|
|
75
|
+
nearProvider,
|
|
76
|
+
solverRelayApiKey: this.solverRelayApiKey
|
|
77
|
+
})
|
|
78
|
+
];
|
|
79
|
+
this.intentRelayer = new IntentRelayerPublic({
|
|
80
|
+
envConfig: this.envConfig,
|
|
81
|
+
solverRelayApiKey: this.solverRelayApiKey
|
|
82
|
+
});
|
|
83
|
+
this.intentSigner = args.intentSigner;
|
|
84
|
+
this.saltManager = new SaltManager({
|
|
85
|
+
envConfig: this.envConfig,
|
|
86
|
+
nearProvider
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
setIntentSigner(signer) {
|
|
90
|
+
this.intentSigner = signer;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create a new intent payload builder with environment context.
|
|
94
|
+
* Use this to build custom intent payloads for your API or advanced use cases.
|
|
95
|
+
*
|
|
96
|
+
* @returns A new IntentPayloadBuilder instance configured with the SDK's environment
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Build a custom intent payload
|
|
101
|
+
* const payload = await sdk.intentBuilder()
|
|
102
|
+
* .setSigner('0x1234...') // User's EVM address
|
|
103
|
+
* .setDeadline(new Date(Date.now() + 5 * 60 * 1000))
|
|
104
|
+
* .addIntent({
|
|
105
|
+
* intent: 'ft_withdraw',
|
|
106
|
+
* token: 'usdc.omft.near',
|
|
107
|
+
* amount: '1000000',
|
|
108
|
+
* receiver_id: 'user.near'
|
|
109
|
+
* })
|
|
110
|
+
* .build();
|
|
111
|
+
*
|
|
112
|
+
* // Return to user for signing with their preferred method (MetaMask, etc.)
|
|
113
|
+
* return payload;
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
intentBuilder() {
|
|
117
|
+
return new IntentPayloadBuilder({
|
|
118
|
+
envConfig: this.envConfig,
|
|
119
|
+
saltManager: this.saltManager
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Invalidate multiple nonces by creating and sending empty signed intents.
|
|
124
|
+
* This prevents previously created but unused intent payloads from being executed.
|
|
125
|
+
*
|
|
126
|
+
* For expirable nonces (versioned nonces with embedded deadlines), the intent's
|
|
127
|
+
* deadline is automatically set to the minimum of:
|
|
128
|
+
* 1. The nonce's embedded deadline (can't exceed this)
|
|
129
|
+
* 2. 1 minute from now (for quick invalidation when possible)
|
|
130
|
+
*
|
|
131
|
+
* @param args.nonces - Array of nonce strings to invalidate (up to 400 nonces per call, but depends on gas consumption)
|
|
132
|
+
* @param args.signer - Optional intent signer to use (defaults to SDK's configured signer)
|
|
133
|
+
* @param args.logger - Optional logger for debugging
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* // Invalidate unused nonces
|
|
138
|
+
* await sdk.invalidateNonces({
|
|
139
|
+
* nonces: ['nonce1', 'nonce2', 'nonce3']
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
async invalidateNonces(args) {
|
|
144
|
+
if (args.nonces.length === 0) return;
|
|
145
|
+
const intentSigner = args.signer ?? this.intentSigner;
|
|
146
|
+
assert(intentSigner != null, "Intent signer is not provided");
|
|
147
|
+
const signedIntents = await Promise.all(args.nonces.map(async (nonce) => {
|
|
148
|
+
const builder = this.intentBuilder().setNonce(nonce);
|
|
149
|
+
try {
|
|
150
|
+
const decoded = VersionedNonceBuilder.decodeNonce(nonce);
|
|
151
|
+
if (v.is(saltedNonceSchema, decoded.value)) {
|
|
152
|
+
const nonceDeadlineMs = Number(decoded.value.inner.deadline / 1000000n);
|
|
153
|
+
const nonceDeadline = new Date(nonceDeadlineMs);
|
|
154
|
+
const oneMinuteFromNow = new Date(Date.now() + DEFAULT_DEADLINE_MS);
|
|
155
|
+
const deadline = oneMinuteFromNow < nonceDeadline ? oneMinuteFromNow : nonceDeadline;
|
|
156
|
+
builder.setDeadline(deadline);
|
|
157
|
+
} else args.logger?.warn?.("Decoded nonce has unexpected structure, using default deadline");
|
|
158
|
+
} catch {}
|
|
159
|
+
const { signed } = await builder.buildAndSign(intentSigner);
|
|
160
|
+
return signed;
|
|
161
|
+
}));
|
|
162
|
+
await this.intentRelayer.publishIntents({
|
|
163
|
+
multiPayloads: signedIntents,
|
|
164
|
+
quoteHashes: []
|
|
165
|
+
}, { logger: args.logger });
|
|
166
|
+
}
|
|
167
|
+
async createWithdrawalIntents(args) {
|
|
168
|
+
for (const bridge of this.bridges) if (await bridge.supports(args.withdrawalParams)) {
|
|
169
|
+
const actualAmount = args.withdrawalParams.feeInclusive ? args.withdrawalParams.amount - args.feeEstimation.amount : args.withdrawalParams.amount;
|
|
170
|
+
await bridge.validateWithdrawal({
|
|
171
|
+
assetId: args.withdrawalParams.assetId,
|
|
172
|
+
amount: actualAmount,
|
|
173
|
+
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
174
|
+
feeEstimation: args.feeEstimation,
|
|
175
|
+
routeConfig: args.withdrawalParams.routeConfig,
|
|
176
|
+
logger: args.logger
|
|
177
|
+
});
|
|
178
|
+
return bridge.createWithdrawalIntents({
|
|
179
|
+
withdrawalParams: {
|
|
180
|
+
...args.withdrawalParams,
|
|
181
|
+
amount: actualAmount
|
|
182
|
+
},
|
|
183
|
+
feeEstimation: args.feeEstimation,
|
|
184
|
+
referral: args.referral ?? this.referral
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
throw new Error(`Cannot determine bridge for withdrawal = ${stringify(args.withdrawalParams)}`);
|
|
188
|
+
}
|
|
189
|
+
estimateWithdrawalFee(args) {
|
|
190
|
+
if (!Array.isArray(args.withdrawalParams)) return this._estimateWithdrawalFee({
|
|
191
|
+
...args,
|
|
192
|
+
withdrawalParams: args.withdrawalParams
|
|
193
|
+
});
|
|
194
|
+
return Promise.all(args.withdrawalParams.map((withdrawalParams) => this._estimateWithdrawalFee({
|
|
195
|
+
...args,
|
|
196
|
+
withdrawalParams
|
|
197
|
+
})));
|
|
198
|
+
}
|
|
199
|
+
async _estimateWithdrawalFee(args) {
|
|
200
|
+
for (const bridge of this.bridges) if (await bridge.supports(args.withdrawalParams)) {
|
|
201
|
+
const fee = await bridge.estimateWithdrawalFee({
|
|
202
|
+
withdrawalParams: args.withdrawalParams,
|
|
203
|
+
quoteOptions: args.quoteOptions,
|
|
204
|
+
logger: args.logger
|
|
205
|
+
});
|
|
206
|
+
if (args.withdrawalParams.feeInclusive) {
|
|
207
|
+
if (args.withdrawalParams.amount <= fee.amount) throw new FeeExceedsAmountError(fee, args.withdrawalParams.amount);
|
|
208
|
+
}
|
|
209
|
+
return fee;
|
|
210
|
+
}
|
|
211
|
+
throw new Error(`Cannot determine bridge for withdrawal = ${stringify(args.withdrawalParams)}`);
|
|
212
|
+
}
|
|
213
|
+
async waitForWithdrawalCompletion(args) {
|
|
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
|
|
220
|
+
});
|
|
221
|
+
const result = await Promise.all(promises);
|
|
222
|
+
if (Array.isArray(args.withdrawalParams)) return result;
|
|
223
|
+
assert(result.length === 1, "Unexpected result length");
|
|
224
|
+
return result[0];
|
|
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
|
+
}
|
|
294
|
+
parseAssetId(assetId) {
|
|
295
|
+
for (const bridge of this.bridges) {
|
|
296
|
+
const parsed = bridge.parseAssetId(assetId);
|
|
297
|
+
if (parsed != null) return parsed;
|
|
298
|
+
}
|
|
299
|
+
throw new Error(`Cannot determine bridge for assetId = ${assetId}`);
|
|
300
|
+
}
|
|
301
|
+
async sendSignedIntents(args) {
|
|
302
|
+
return { tickets: await this.intentRelayer.publishIntents({
|
|
303
|
+
multiPayloads: args.multiPayloads,
|
|
304
|
+
quoteHashes: args.quoteHashes ?? []
|
|
305
|
+
}, { logger: args.logger }) };
|
|
306
|
+
}
|
|
307
|
+
async signAndSendIntent(args) {
|
|
308
|
+
const intentSigner = args.signer ?? this.intentSigner;
|
|
309
|
+
assert(intentSigner != null, "Intent signer is not provided");
|
|
310
|
+
const intentExecuter = new IntentExecuter({
|
|
311
|
+
envConfig: this.envConfig,
|
|
312
|
+
logger: args.logger,
|
|
313
|
+
intentSigner,
|
|
314
|
+
intentRelayer: this.intentRelayer,
|
|
315
|
+
intentPayloadFactory: args.payload,
|
|
316
|
+
onBeforePublishIntent: args.onBeforePublishIntent
|
|
317
|
+
});
|
|
318
|
+
const { ticket } = await this.withSaltRetry(args, async (salt) => intentExecuter.signAndSendIntent({
|
|
319
|
+
intents: args.intents,
|
|
320
|
+
salt,
|
|
321
|
+
relayParams: args.relayParams,
|
|
322
|
+
signedIntents: args.signedIntents
|
|
323
|
+
}));
|
|
324
|
+
return { intentHash: ticket };
|
|
325
|
+
}
|
|
326
|
+
async withSaltRetry(args, fn) {
|
|
327
|
+
try {
|
|
328
|
+
return await fn(await this.saltManager.getCachedSalt());
|
|
329
|
+
} catch (err) {
|
|
330
|
+
if (!(err instanceof RelayPublishError && err.code === "INVALID_SALT")) throw err;
|
|
331
|
+
args.logger?.warn?.("Salt error detected. Refreshing salt and retrying");
|
|
332
|
+
return fn(await this.saltManager.refresh());
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async signAndSendWithdrawalIntent(args) {
|
|
336
|
+
let withdrawalParamsArray;
|
|
337
|
+
let feeEstimations;
|
|
338
|
+
if (isBatchMode(args)) {
|
|
339
|
+
withdrawalParamsArray = args.withdrawalParams;
|
|
340
|
+
feeEstimations = args.feeEstimation;
|
|
341
|
+
} else {
|
|
342
|
+
withdrawalParamsArray = [args.withdrawalParams];
|
|
343
|
+
feeEstimations = [args.feeEstimation];
|
|
344
|
+
}
|
|
345
|
+
const intentsP = zip(withdrawalParamsArray, feeEstimations).map(([withdrawalParams, feeEstimation]) => {
|
|
346
|
+
return this.createWithdrawalIntents({
|
|
347
|
+
withdrawalParams,
|
|
348
|
+
feeEstimation,
|
|
349
|
+
referral: args.referral ?? this.referral,
|
|
350
|
+
logger: args.logger
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
const intents = (await Promise.all(intentsP)).flat();
|
|
354
|
+
const relayParamsFn = async () => {
|
|
355
|
+
const relayParams = args.intent?.relayParams != null ? await args.intent?.relayParams() : { quoteHashes: void 0 };
|
|
356
|
+
const quoteHashes = relayParams.quoteHashes ?? [];
|
|
357
|
+
for (const fee of feeEstimations) if (fee.quote != null) quoteHashes.push(fee.quote.quote_hash);
|
|
358
|
+
return {
|
|
359
|
+
...relayParams,
|
|
360
|
+
quoteHashes
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
return this.signAndSendIntent({
|
|
364
|
+
intents,
|
|
365
|
+
signer: args.intent?.signer,
|
|
366
|
+
onBeforePublishIntent: args.intent?.onBeforePublishIntent,
|
|
367
|
+
relayParams: relayParamsFn,
|
|
368
|
+
payload: args.intent?.payload,
|
|
369
|
+
logger: args.logger,
|
|
370
|
+
signedIntents: args.intent?.signedIntents
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
async waitForIntentSettlement(args) {
|
|
374
|
+
const { tx } = await new IntentExecuter({
|
|
375
|
+
envConfig: this.envConfig,
|
|
376
|
+
logger: args.logger,
|
|
377
|
+
intentSigner: noopIntentSigner,
|
|
378
|
+
intentRelayer: this.intentRelayer
|
|
379
|
+
}).waitForSettlement(args.intentHash, { signal: args.signal });
|
|
380
|
+
return tx;
|
|
381
|
+
}
|
|
382
|
+
async getIntentStatus({ intentHash, logger }) {
|
|
383
|
+
return solverRelay.getStatus({ intent_hash: intentHash }, {
|
|
384
|
+
baseURL: this.envConfig.solverRelayBaseURL,
|
|
385
|
+
logger,
|
|
386
|
+
solverRelayApiKey: this.solverRelayApiKey
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
async processWithdrawal(args) {
|
|
390
|
+
const withdrawalParams = Array.isArray(args.withdrawalParams) ? args.withdrawalParams : [args.withdrawalParams];
|
|
391
|
+
const feeEstimation = await (() => {
|
|
392
|
+
if (args.feeEstimation != null) return Array.isArray(args.feeEstimation) ? args.feeEstimation : [args.feeEstimation];
|
|
393
|
+
return this.estimateWithdrawalFee({
|
|
394
|
+
withdrawalParams,
|
|
395
|
+
logger: args.logger
|
|
396
|
+
});
|
|
397
|
+
})();
|
|
398
|
+
const { intentHash } = await this.signAndSendWithdrawalIntent({
|
|
399
|
+
withdrawalParams,
|
|
400
|
+
feeEstimation,
|
|
401
|
+
referral: args.referral,
|
|
402
|
+
intent: args.intent,
|
|
403
|
+
logger: args.logger
|
|
404
|
+
});
|
|
405
|
+
const intentTx = await this.waitForIntentSettlement({
|
|
406
|
+
intentHash,
|
|
407
|
+
logger: args.logger
|
|
408
|
+
});
|
|
409
|
+
const destinationTx = await this.waitForWithdrawalCompletion({
|
|
410
|
+
withdrawalParams,
|
|
411
|
+
intentTx,
|
|
412
|
+
logger: args.logger
|
|
413
|
+
});
|
|
414
|
+
if (!Array.isArray(args.withdrawalParams)) return {
|
|
415
|
+
feeEstimation: feeEstimation[0],
|
|
416
|
+
intentHash,
|
|
417
|
+
intentTx,
|
|
418
|
+
destinationTx: destinationTx[0]
|
|
419
|
+
};
|
|
420
|
+
return {
|
|
421
|
+
feeEstimation,
|
|
422
|
+
intentHash,
|
|
423
|
+
intentTx,
|
|
424
|
+
destinationTx
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
function isBatchMode(args) {
|
|
429
|
+
return Array.isArray(args.withdrawalParams);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
//#endregion
|
|
433
|
+
export { IntentsSDK };
|