@defuse-protocol/intents-sdk 0.46.0 → 0.47.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.
@@ -12,14 +12,46 @@ const require_hot_bridge_utils = require('./hot-bridge-utils.cjs');
12
12
  const require_hex = require('../../lib/hex.cjs');
13
13
  let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
14
14
  let _hot_labs_omni_sdk = require("@hot-labs/omni-sdk");
15
+ let lru_cache = require("lru-cache");
16
+ let valibot = require("valibot");
17
+ valibot = require_rolldown_runtime.__toESM(valibot);
15
18
 
16
19
  //#region src/bridges/hot-bridge/hot-bridge.ts
17
- var HotBridge = class {
20
+ const HotApiWithdrawalSchema = valibot.object({
21
+ hash: valibot.nullable(valibot.string()),
22
+ nonce: valibot.string(),
23
+ near_trx: valibot.string(),
24
+ verified_withdraw: valibot.boolean(),
25
+ chain_id: valibot.number()
26
+ });
27
+ const HotApiWithdrawalResponseSchema = valibot.object({
28
+ hash: valibot.nullable(valibot.string()),
29
+ nonce: valibot.string(),
30
+ near_trx: valibot.string(),
31
+ withdrawals: valibot.array(HotApiWithdrawalSchema)
32
+ });
33
+ var HotBridge = class HotBridge {
34
+ static {
35
+ this.API_FALLBACK_TIMEOUT_MS = 5e3;
36
+ }
37
+ static {
38
+ this.NEAR_RPC_TIMEOUT_MS = 1e4;
39
+ }
18
40
  constructor({ envConfig, hotSdk, solverRelayApiKey }) {
19
41
  this.route = require_route_enum.RouteEnum.HotBridge;
20
42
  this.envConfig = envConfig;
21
43
  this.hotSdk = hotSdk;
22
44
  this.solverRelayApiKey = solverRelayApiKey;
45
+ this.noncesCache = new lru_cache.LRUCache({
46
+ max: 50,
47
+ ttl: 3600 * 1e3,
48
+ fetchMethod: async (_key, _staleValue, { context: tx }) => {
49
+ return (0, _defuse_protocol_internal_utils.withTimeout)(() => this.hotSdk.near.parseWithdrawalNonces(tx.hash, tx.accountId), { timeout: HotBridge.NEAR_RPC_TIMEOUT_MS });
50
+ }
51
+ });
52
+ }
53
+ getNoncesCacheKey(tx) {
54
+ return `${tx.hash}:${tx.accountId}`;
23
55
  }
24
56
  is(routeConfig) {
25
57
  return routeConfig.route === require_route_enum.RouteEnum.HotBridge;
@@ -141,7 +173,10 @@ var HotBridge = class {
141
173
  };
142
174
  }
143
175
  async describeWithdrawal(args) {
144
- const nonce = (await this.hotSdk.near.parseWithdrawalNonces(args.tx.hash, args.tx.accountId))[args.index];
176
+ const cacheKey = this.getNoncesCacheKey(args.tx);
177
+ const nonces = await this.noncesCache.fetch(cacheKey, { context: args.tx });
178
+ if (nonces == null) throw new require_error.HotWithdrawalNotFoundError(args.tx.hash, args.index);
179
+ const nonce = nonces[args.index];
145
180
  if (nonce == null) throw new require_error.HotWithdrawalNotFoundError(args.tx.hash, args.index);
146
181
  const status = await this.hotSdk.getGaslessWithdrawStatus(nonce.toString());
147
182
  if (status === require_hot_bridge_constants.HotWithdrawStatus.Canceled) return {
@@ -165,8 +200,41 @@ var HotBridge = class {
165
200
  txHash: require_hot_bridge_utils.formatTxHash(status, args.landingChain)
166
201
  };
167
202
  }
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
+ };
168
208
  return { status: "pending" };
169
209
  }
210
+ async fetchWithdrawalHashFromApi(nearTxHash, nonce, logger) {
211
+ try {
212
+ 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();
213
+ const parseResult = valibot.safeParse(HotApiWithdrawalResponseSchema, data);
214
+ if (!parseResult.success) {
215
+ logger?.debug("HOT API response parse failed", { issues: parseResult.issues });
216
+ return null;
217
+ }
218
+ const withdrawal = parseResult.output.withdrawals.find((w) => w.nonce === nonce.toString());
219
+ if (withdrawal?.hash) {
220
+ const hash = withdrawal.hash.replace(/^0x/, "");
221
+ if (require_hex.default(hash)) {
222
+ logger?.info("HOT withdrawal hash found via API fallback", {
223
+ nearTxHash,
224
+ nonce: nonce.toString()
225
+ });
226
+ return hash;
227
+ }
228
+ }
229
+ return null;
230
+ } catch (error) {
231
+ logger?.debug("HOT API fallback failed", {
232
+ error,
233
+ nearTxHash
234
+ });
235
+ return null;
236
+ }
237
+ }
170
238
  };
171
239
 
172
240
  //#endregion
@@ -11,14 +11,45 @@ import { formatTxHash, getFeeAssetIdForChain, hotBlockchainInvariant, hotNetwork
11
11
  import isHex from "../../lib/hex.js";
12
12
  import { assert, withTimeout } from "@defuse-protocol/internal-utils";
13
13
  import { OMNI_HOT_V2, utils as utils$1 } from "@hot-labs/omni-sdk";
14
+ import { LRUCache } from "lru-cache";
15
+ import * as v from "valibot";
14
16
 
15
17
  //#region src/bridges/hot-bridge/hot-bridge.ts
16
- var HotBridge$1 = class {
18
+ const HotApiWithdrawalSchema = v.object({
19
+ hash: v.nullable(v.string()),
20
+ nonce: v.string(),
21
+ near_trx: v.string(),
22
+ verified_withdraw: v.boolean(),
23
+ chain_id: v.number()
24
+ });
25
+ const HotApiWithdrawalResponseSchema = v.object({
26
+ hash: v.nullable(v.string()),
27
+ nonce: v.string(),
28
+ near_trx: v.string(),
29
+ withdrawals: v.array(HotApiWithdrawalSchema)
30
+ });
31
+ var HotBridge$1 = class HotBridge$1 {
32
+ static {
33
+ this.API_FALLBACK_TIMEOUT_MS = 5e3;
34
+ }
35
+ static {
36
+ this.NEAR_RPC_TIMEOUT_MS = 1e4;
37
+ }
17
38
  constructor({ envConfig, hotSdk, solverRelayApiKey }) {
18
39
  this.route = RouteEnum.HotBridge;
19
40
  this.envConfig = envConfig;
20
41
  this.hotSdk = hotSdk;
21
42
  this.solverRelayApiKey = solverRelayApiKey;
43
+ this.noncesCache = new LRUCache({
44
+ max: 50,
45
+ ttl: 3600 * 1e3,
46
+ fetchMethod: async (_key, _staleValue, { context: tx }) => {
47
+ return withTimeout(() => this.hotSdk.near.parseWithdrawalNonces(tx.hash, tx.accountId), { timeout: HotBridge$1.NEAR_RPC_TIMEOUT_MS });
48
+ }
49
+ });
50
+ }
51
+ getNoncesCacheKey(tx) {
52
+ return `${tx.hash}:${tx.accountId}`;
22
53
  }
23
54
  is(routeConfig) {
24
55
  return routeConfig.route === RouteEnum.HotBridge;
@@ -140,7 +171,10 @@ var HotBridge$1 = class {
140
171
  };
141
172
  }
142
173
  async describeWithdrawal(args) {
143
- const nonce = (await this.hotSdk.near.parseWithdrawalNonces(args.tx.hash, args.tx.accountId))[args.index];
174
+ const cacheKey = this.getNoncesCacheKey(args.tx);
175
+ const nonces = await this.noncesCache.fetch(cacheKey, { context: args.tx });
176
+ if (nonces == null) throw new HotWithdrawalNotFoundError(args.tx.hash, args.index);
177
+ const nonce = nonces[args.index];
144
178
  if (nonce == null) throw new HotWithdrawalNotFoundError(args.tx.hash, args.index);
145
179
  const status = await this.hotSdk.getGaslessWithdrawStatus(nonce.toString());
146
180
  if (status === HotWithdrawStatus.Canceled) return {
@@ -164,8 +198,41 @@ var HotBridge$1 = class {
164
198
  txHash: formatTxHash(status, args.landingChain)
165
199
  };
166
200
  }
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
+ };
167
206
  return { status: "pending" };
168
207
  }
208
+ async fetchWithdrawalHashFromApi(nearTxHash, nonce, logger) {
209
+ try {
210
+ 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();
211
+ const parseResult = v.safeParse(HotApiWithdrawalResponseSchema, data);
212
+ if (!parseResult.success) {
213
+ logger?.debug("HOT API response parse failed", { issues: parseResult.issues });
214
+ return null;
215
+ }
216
+ const withdrawal = parseResult.output.withdrawals.find((w) => w.nonce === nonce.toString());
217
+ if (withdrawal?.hash) {
218
+ const hash = withdrawal.hash.replace(/^0x/, "");
219
+ if (isHex(hash)) {
220
+ logger?.info("HOT withdrawal hash found via API fallback", {
221
+ nearTxHash,
222
+ nonce: nonce.toString()
223
+ });
224
+ return hash;
225
+ }
226
+ }
227
+ return null;
228
+ } catch (error) {
229
+ logger?.debug("HOT API fallback failed", {
230
+ error,
231
+ nearTxHash
232
+ });
233
+ return null;
234
+ }
235
+ }
169
236
  };
170
237
 
171
238
  //#endregion
@@ -3,9 +3,9 @@ const require_caip2 = require('../../lib/caip2.cjs');
3
3
  const require_omni_bridge_constants = require('./omni-bridge-constants.cjs');
4
4
  const require_poa_tokens_routable_through_omni_bridge = require('../../constants/poa-tokens-routable-through-omni-bridge.cjs');
5
5
  let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
6
- let omni_bridge_sdk = require("omni-bridge-sdk");
7
6
  let valibot = require("valibot");
8
7
  valibot = require_rolldown_runtime.__toESM(valibot);
8
+ let omni_bridge_sdk = require("omni-bridge-sdk");
9
9
 
10
10
  //#region src/bridges/omni-bridge/omni-bridge-utils.ts
11
11
  function createWithdrawIntentsPrimitive(params) {
@@ -2,8 +2,8 @@ import { Chains } from "../../lib/caip2.js";
2
2
  import { MIN_GAS_AMOUNT, OMNI_BRIDGE_CONTRACT } from "./omni-bridge-constants.js";
3
3
  import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "../../constants/poa-tokens-routable-through-omni-bridge.js";
4
4
  import { assert, utils } from "@defuse-protocol/internal-utils";
5
- import { ChainKind, calculateStorageAccountId, getChain, isBridgeToken, omniAddress } from "omni-bridge-sdk";
6
5
  import * as v from "valibot";
6
+ import { ChainKind, calculateStorageAccountId, getChain, isBridgeToken, omniAddress } from "omni-bridge-sdk";
7
7
 
8
8
  //#region src/bridges/omni-bridge/omni-bridge-utils.ts
9
9
  function createWithdrawIntentsPrimitive(params) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defuse-protocol/intents-sdk",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {
@@ -31,7 +31,7 @@
31
31
  "typescript": "^5"
32
32
  },
33
33
  "dependencies": {
34
- "@hot-labs/omni-sdk": "2.24.3",
34
+ "@hot-labs/omni-sdk": "2.24.7",
35
35
  "@isaacs/ttlcache": "^1.0.0",
36
36
  "@lifeomic/attempt": "^3.0.0",
37
37
  "@near-js/accounts": "^2.0.1",
@@ -47,8 +47,8 @@
47
47
  "ripple-address-codec": "^5.0.0",
48
48
  "valibot": "^1.0.0",
49
49
  "viem": "^2.0.0",
50
- "@defuse-protocol/contract-types": "0.4.4",
51
- "@defuse-protocol/internal-utils": "0.24.0"
50
+ "@defuse-protocol/contract-types": "0.5.0",
51
+ "@defuse-protocol/internal-utils": "0.24.2"
52
52
  },
53
53
  "devDependencies": {
54
54
  "tsdown": "0.19.0"