@defuse-protocol/intents-sdk 0.52.0 → 0.53.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.
|
@@ -183,30 +183,81 @@ var HotBridge = class HotBridge {
|
|
|
183
183
|
status: "failed",
|
|
184
184
|
reason: "Withdrawal was cancelled"
|
|
185
185
|
};
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
186
|
+
if (args.landingChain.startsWith("eip155:")) try {
|
|
187
|
+
args.logger?.info(`Using bridge indexer to retrieve HOT withdrawal hash with nearTxHash=${args.tx.hash} nonce=${nonce.toString()}`);
|
|
188
|
+
const bridgeIndexerHash = await this.fetchWithdrawalHashBridgeIndexer(args.tx.hash, nonce.toString(), args.logger);
|
|
189
|
+
if (bridgeIndexerHash !== null) {
|
|
190
|
+
args.logger?.info(`Bridge indexer returned withdrawHash=${bridgeIndexerHash} for nearTxHash=${args.tx.hash} nonce=${nonce.toString()}`);
|
|
191
|
+
return {
|
|
192
|
+
status: "completed",
|
|
193
|
+
txHash: bridgeIndexerHash
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
args.logger?.error("Bridge indexer failed unexpectedly, trying HOT API fallback", {
|
|
198
|
+
nearTxHash: args.tx.hash,
|
|
199
|
+
nonce: nonce.toString(),
|
|
200
|
+
error
|
|
201
|
+
});
|
|
202
|
+
const apiHash = await this.fetchWithdrawalHashFromApi(args.tx.hash, nonce, args.logger);
|
|
203
|
+
if (apiHash != null) {
|
|
204
|
+
args.logger?.info(`Hot Api returned withdrawHash=${apiHash} for nearTxHash=${args.tx.hash} nonce=${nonce.toString()}`);
|
|
193
205
|
return {
|
|
194
206
|
status: "completed",
|
|
195
|
-
txHash:
|
|
207
|
+
txHash: require_hot_bridge_utils.formatTxHash(apiHash, args.landingChain)
|
|
196
208
|
};
|
|
197
209
|
}
|
|
198
|
-
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
if (status === require_hot_bridge_constants.HotWithdrawStatus.Completed) return {
|
|
199
213
|
status: "completed",
|
|
200
|
-
txHash:
|
|
214
|
+
txHash: null
|
|
215
|
+
};
|
|
216
|
+
if (typeof status === "string") {
|
|
217
|
+
if (!require_hex.default(status)) {
|
|
218
|
+
args.logger?.warn("HOT Bridge incorrect destination tx hash detected", { value: status });
|
|
219
|
+
return {
|
|
220
|
+
status: "completed",
|
|
221
|
+
txHash: null
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
status: "completed",
|
|
226
|
+
txHash: require_hot_bridge_utils.formatTxHash(status, args.landingChain)
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const apiHash = await this.fetchWithdrawalHashFromApi(args.tx.hash, nonce, args.logger);
|
|
230
|
+
if (apiHash != null) return {
|
|
231
|
+
status: "completed",
|
|
232
|
+
txHash: require_hot_bridge_utils.formatTxHash(apiHash, args.landingChain)
|
|
201
233
|
};
|
|
202
234
|
}
|
|
203
|
-
const apiHash = await this.fetchWithdrawalHashFromApi(args.tx.hash, nonce, args.logger);
|
|
204
|
-
if (apiHash != null) return {
|
|
205
|
-
status: "completed",
|
|
206
|
-
txHash: require_hot_bridge_utils.formatTxHash(apiHash, args.landingChain)
|
|
207
|
-
};
|
|
208
235
|
return { status: "pending" };
|
|
209
236
|
}
|
|
237
|
+
async fetchWithdrawalHashBridgeIndexer(nearTxHash, nonce, logger) {
|
|
238
|
+
const { withdrawals } = await _defuse_protocol_internal_utils.bridgeIndexer.httpClient.withdrawalsByNearTxHash(nearTxHash, {
|
|
239
|
+
timeout: typeof window !== "undefined" ? 1e4 : 3e3,
|
|
240
|
+
logger
|
|
241
|
+
});
|
|
242
|
+
const withdrawal = withdrawals.find((withdrawal$1) => {
|
|
243
|
+
return withdrawal$1.nonce === nonce;
|
|
244
|
+
});
|
|
245
|
+
if (withdrawal === void 0) {
|
|
246
|
+
logger?.info("HOT Bridge indexer withdrawal hash not found", {
|
|
247
|
+
nearTxHash,
|
|
248
|
+
nonce: nonce.toString()
|
|
249
|
+
});
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
if (withdrawal.hash === null || withdrawal.hash === "") {
|
|
253
|
+
logger?.info(`HOT Bridge returned invalid hash, expected a non empty string, got ${withdrawal.hash}`, {
|
|
254
|
+
nearTxHash,
|
|
255
|
+
nonce: nonce.toString()
|
|
256
|
+
});
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
return withdrawal.hash;
|
|
260
|
+
}
|
|
210
261
|
async fetchWithdrawalHashFromApi(nearTxHash, nonce, logger) {
|
|
211
262
|
try {
|
|
212
263
|
const data = await (await (0, _defuse_protocol_internal_utils.withTimeout)(() => this.hotSdk.api.requestApi(`/api/v1/evm/bridge_withdrawal_hash?near_trx=${nearTxHash}`, { method: "GET" }), { timeout: HotBridge.API_FALLBACK_TIMEOUT_MS })).json();
|
|
@@ -9,7 +9,7 @@ import { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalNotFoundError } fr
|
|
|
9
9
|
import { HotWithdrawStatus, MIN_GAS_AMOUNT } from "./hot-bridge-constants.js";
|
|
10
10
|
import { formatTxHash, getFeeAssetIdForChain, hotBlockchainInvariant, hotNetworkIdToCAIP2, toHotNetworkId } from "./hot-bridge-utils.js";
|
|
11
11
|
import isHex from "../../lib/hex.js";
|
|
12
|
-
import { assert, withTimeout } from "@defuse-protocol/internal-utils";
|
|
12
|
+
import { assert, bridgeIndexer, withTimeout } from "@defuse-protocol/internal-utils";
|
|
13
13
|
import { OMNI_HOT_V2, utils as utils$1 } from "@hot-labs/omni-sdk";
|
|
14
14
|
import { LRUCache } from "lru-cache";
|
|
15
15
|
import * as v from "valibot";
|
|
@@ -181,30 +181,81 @@ var HotBridge$1 = class HotBridge$1 {
|
|
|
181
181
|
status: "failed",
|
|
182
182
|
reason: "Withdrawal was cancelled"
|
|
183
183
|
};
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
184
|
+
if (args.landingChain.startsWith("eip155:")) try {
|
|
185
|
+
args.logger?.info(`Using bridge indexer to retrieve HOT withdrawal hash with nearTxHash=${args.tx.hash} nonce=${nonce.toString()}`);
|
|
186
|
+
const bridgeIndexerHash = await this.fetchWithdrawalHashBridgeIndexer(args.tx.hash, nonce.toString(), args.logger);
|
|
187
|
+
if (bridgeIndexerHash !== null) {
|
|
188
|
+
args.logger?.info(`Bridge indexer returned withdrawHash=${bridgeIndexerHash} for nearTxHash=${args.tx.hash} nonce=${nonce.toString()}`);
|
|
189
|
+
return {
|
|
190
|
+
status: "completed",
|
|
191
|
+
txHash: bridgeIndexerHash
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
args.logger?.error("Bridge indexer failed unexpectedly, trying HOT API fallback", {
|
|
196
|
+
nearTxHash: args.tx.hash,
|
|
197
|
+
nonce: nonce.toString(),
|
|
198
|
+
error
|
|
199
|
+
});
|
|
200
|
+
const apiHash = await this.fetchWithdrawalHashFromApi(args.tx.hash, nonce, args.logger);
|
|
201
|
+
if (apiHash != null) {
|
|
202
|
+
args.logger?.info(`Hot Api returned withdrawHash=${apiHash} for nearTxHash=${args.tx.hash} nonce=${nonce.toString()}`);
|
|
191
203
|
return {
|
|
192
204
|
status: "completed",
|
|
193
|
-
txHash:
|
|
205
|
+
txHash: formatTxHash(apiHash, args.landingChain)
|
|
194
206
|
};
|
|
195
207
|
}
|
|
196
|
-
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
if (status === HotWithdrawStatus.Completed) return {
|
|
197
211
|
status: "completed",
|
|
198
|
-
txHash:
|
|
212
|
+
txHash: null
|
|
213
|
+
};
|
|
214
|
+
if (typeof status === "string") {
|
|
215
|
+
if (!isHex(status)) {
|
|
216
|
+
args.logger?.warn("HOT Bridge incorrect destination tx hash detected", { value: status });
|
|
217
|
+
return {
|
|
218
|
+
status: "completed",
|
|
219
|
+
txHash: null
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
status: "completed",
|
|
224
|
+
txHash: formatTxHash(status, args.landingChain)
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const apiHash = await this.fetchWithdrawalHashFromApi(args.tx.hash, nonce, args.logger);
|
|
228
|
+
if (apiHash != null) return {
|
|
229
|
+
status: "completed",
|
|
230
|
+
txHash: formatTxHash(apiHash, args.landingChain)
|
|
199
231
|
};
|
|
200
232
|
}
|
|
201
|
-
const apiHash = await this.fetchWithdrawalHashFromApi(args.tx.hash, nonce, args.logger);
|
|
202
|
-
if (apiHash != null) return {
|
|
203
|
-
status: "completed",
|
|
204
|
-
txHash: formatTxHash(apiHash, args.landingChain)
|
|
205
|
-
};
|
|
206
233
|
return { status: "pending" };
|
|
207
234
|
}
|
|
235
|
+
async fetchWithdrawalHashBridgeIndexer(nearTxHash, nonce, logger) {
|
|
236
|
+
const { withdrawals } = await bridgeIndexer.httpClient.withdrawalsByNearTxHash(nearTxHash, {
|
|
237
|
+
timeout: typeof window !== "undefined" ? 1e4 : 3e3,
|
|
238
|
+
logger
|
|
239
|
+
});
|
|
240
|
+
const withdrawal = withdrawals.find((withdrawal$1) => {
|
|
241
|
+
return withdrawal$1.nonce === nonce;
|
|
242
|
+
});
|
|
243
|
+
if (withdrawal === void 0) {
|
|
244
|
+
logger?.info("HOT Bridge indexer withdrawal hash not found", {
|
|
245
|
+
nearTxHash,
|
|
246
|
+
nonce: nonce.toString()
|
|
247
|
+
});
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
if (withdrawal.hash === null || withdrawal.hash === "") {
|
|
251
|
+
logger?.info(`HOT Bridge returned invalid hash, expected a non empty string, got ${withdrawal.hash}`, {
|
|
252
|
+
nearTxHash,
|
|
253
|
+
nonce: nonce.toString()
|
|
254
|
+
});
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
return withdrawal.hash;
|
|
258
|
+
}
|
|
208
259
|
async fetchWithdrawalHashFromApi(nearTxHash, nonce, logger) {
|
|
209
260
|
try {
|
|
210
261
|
const data = await (await withTimeout(() => this.hotSdk.api.requestApi(`/api/v1/evm/bridge_withdrawal_hash?near_trx=${nearTxHash}`, { method: "GET" }), { timeout: HotBridge$1.API_FALLBACK_TIMEOUT_MS })).json();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"ripple-address-codec": "^5.0.0",
|
|
46
46
|
"valibot": "^1.0.0",
|
|
47
47
|
"viem": "^2.0.0",
|
|
48
|
-
"@defuse-protocol/contract-types": "0.6.
|
|
49
|
-
"@defuse-protocol/internal-utils": "0.
|
|
48
|
+
"@defuse-protocol/contract-types": "0.6.1",
|
|
49
|
+
"@defuse-protocol/internal-utils": "0.28.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"tsdown": "0.19.0"
|