@defuse-protocol/intents-sdk 0.43.2 → 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.
Files changed (83) hide show
  1. package/README.md +143 -21
  2. package/dist/index.cjs +19 -18
  3. package/dist/index.d.cts +5 -3
  4. package/dist/index.d.ts +5 -3
  5. package/dist/index.js +7 -5
  6. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +5 -5
  7. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +24 -12
  8. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +19 -7
  9. package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +5 -5
  10. package/dist/src/bridges/direct-bridge/direct-bridge.cjs +22 -10
  11. package/dist/src/bridges/direct-bridge/direct-bridge.js +16 -4
  12. package/dist/src/bridges/direct-bridge/error.cjs +2 -2
  13. package/dist/src/bridges/hot-bridge/error.cjs +4 -26
  14. package/dist/src/bridges/hot-bridge/error.d.cts +1 -17
  15. package/dist/src/bridges/hot-bridge/error.d.ts +1 -17
  16. package/dist/src/bridges/hot-bridge/error.js +1 -21
  17. package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +10 -10
  18. package/dist/src/bridges/hot-bridge/hot-bridge.cjs +46 -32
  19. package/dist/src/bridges/hot-bridge/hot-bridge.js +38 -24
  20. package/dist/src/bridges/intents-bridge/intents-bridge.cjs +18 -4
  21. package/dist/src/bridges/intents-bridge/intents-bridge.js +18 -4
  22. package/dist/src/bridges/omni-bridge/error.cjs +6 -27
  23. package/dist/src/bridges/omni-bridge/error.d.cts +1 -16
  24. package/dist/src/bridges/omni-bridge/error.d.ts +1 -16
  25. package/dist/src/bridges/omni-bridge/error.js +1 -20
  26. package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +12 -7
  27. package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +5 -1
  28. package/dist/src/bridges/omni-bridge/omni-bridge.cjs +72 -54
  29. package/dist/src/bridges/omni-bridge/omni-bridge.js +47 -29
  30. package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +2 -2
  31. package/dist/src/bridges/poa-bridge/poa-bridge.cjs +79 -26
  32. package/dist/src/bridges/poa-bridge/poa-bridge.js +66 -13
  33. package/dist/src/classes/errors.cjs +7 -7
  34. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
  35. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
  36. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
  37. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
  38. package/dist/src/constants/withdrawal-timing.cjs +57 -0
  39. package/dist/src/constants/withdrawal-timing.js +56 -0
  40. package/dist/src/core/withdrawal-watcher.cjs +83 -0
  41. package/dist/src/core/withdrawal-watcher.d.cts +18 -0
  42. package/dist/src/core/withdrawal-watcher.d.ts +18 -0
  43. package/dist/src/core/withdrawal-watcher.js +79 -0
  44. package/dist/src/intents/expirable-nonce.cjs +3 -3
  45. package/dist/src/intents/intent-executer-impl/intent-executer.cjs +7 -4
  46. package/dist/src/intents/intent-executer-impl/intent-executer.js +5 -2
  47. package/dist/src/intents/intent-hash.cjs +2 -2
  48. package/dist/src/intents/intent-hashes/erc191.cjs +2 -2
  49. package/dist/src/intents/intent-hashes/nep413.cjs +2 -2
  50. package/dist/src/intents/intent-hashes/raw-ed25519.cjs +2 -2
  51. package/dist/src/intents/intent-hashes/sep53.cjs +4 -4
  52. package/dist/src/intents/intent-hashes/tip191.cjs +2 -2
  53. package/dist/src/intents/intent-hashes/ton-connect.cjs +2 -2
  54. package/dist/src/intents/intent-hashes/webauthn.cjs +2 -2
  55. package/dist/src/intents/intent-payload-builder.cjs +4 -4
  56. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +7 -7
  57. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +1 -1
  58. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +2 -2
  59. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +3 -3
  60. package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +3 -3
  61. package/dist/src/intents/interfaces/intent-relayer.d.cts +2 -1
  62. package/dist/src/intents/interfaces/intent-relayer.d.ts +2 -1
  63. package/dist/src/intents/salt-manager.cjs +5 -5
  64. package/dist/src/lib/array.cjs +2 -2
  65. package/dist/src/lib/caip2.cjs +4 -4
  66. package/dist/src/lib/configure-rpc-config.cjs +3 -3
  67. package/dist/src/lib/estimate-fee.cjs +6 -6
  68. package/dist/src/lib/parse-defuse-asset-id.cjs +2 -2
  69. package/dist/src/lib/route-config-factory.cjs +2 -5
  70. package/dist/src/lib/route-config-factory.d.cts +1 -1
  71. package/dist/src/lib/route-config-factory.d.ts +1 -1
  72. package/dist/src/lib/route-config-factory.js +2 -5
  73. package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +3 -3
  74. package/dist/src/lib/validateAddress.cjs +18 -18
  75. package/dist/src/sdk.cjs +96 -47
  76. package/dist/src/sdk.d.cts +72 -11
  77. package/dist/src/sdk.d.ts +72 -11
  78. package/dist/src/sdk.js +85 -36
  79. package/dist/src/shared-types.d.cts +49 -15
  80. package/dist/src/shared-types.d.ts +49 -15
  81. package/package.json +5 -7
  82. package/dist/src/lib/route-config.cjs +0 -19
  83. package/dist/src/lib/route-config.js +0 -19
@@ -1,27 +1,8 @@
1
1
  const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
- let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
2
+ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
3
3
 
4
4
  //#region src/bridges/omni-bridge/error.ts
5
- var OmniTransferNotFoundError = class extends __defuse_protocol_internal_utils.BaseError {
6
- constructor(txHash) {
7
- super("Omni transfer with given hash is not found in the relayer.", {
8
- metaMessages: [`OriginTxHash: ${txHash}`],
9
- name: "OmniTransferNotFoundError"
10
- });
11
- this.txHash = txHash;
12
- }
13
- };
14
- var OmniTransferDestinationChainHashNotFoundError = class extends __defuse_protocol_internal_utils.BaseError {
15
- constructor(txHash, destinationChain) {
16
- super("Relayer did not return destination chain hash for a transfer.", {
17
- metaMessages: [`OriginTxHash: ${txHash}`, `DestinationChain: ${destinationChain}`],
18
- name: "OmniTransferDestinationChainHashNotFoundError"
19
- });
20
- this.txHash = txHash;
21
- this.destinationChain = destinationChain;
22
- }
23
- };
24
- var TokenNotFoundInDestinationChainError = class extends __defuse_protocol_internal_utils.BaseError {
5
+ var TokenNotFoundInDestinationChainError = class extends _defuse_protocol_internal_utils.BaseError {
25
6
  constructor(token, destinationChain) {
26
7
  super(`The token ${token} doesn't exist in destination chain ${destinationChain}`, {
27
8
  metaMessages: [`Token: ${token}`, `Destination Chain: ${destinationChain}`],
@@ -31,7 +12,7 @@ var TokenNotFoundInDestinationChainError = class extends __defuse_protocol_inter
31
12
  this.destinationChain = destinationChain;
32
13
  }
33
14
  };
34
- var InvalidFeeValueError = class extends __defuse_protocol_internal_utils.BaseError {
15
+ var InvalidFeeValueError = class extends _defuse_protocol_internal_utils.BaseError {
35
16
  constructor(token, value) {
36
17
  super(`Invalid fee value`, {
37
18
  metaMessages: [`Token: ${token}`, `Fee value: ${value}`],
@@ -40,7 +21,7 @@ var InvalidFeeValueError = class extends __defuse_protocol_internal_utils.BaseEr
40
21
  this.token = token;
41
22
  }
42
23
  };
43
- var IntentsNearOmniAvailableBalanceTooLowError = class extends __defuse_protocol_internal_utils.BaseError {
24
+ var IntentsNearOmniAvailableBalanceTooLowError = class extends _defuse_protocol_internal_utils.BaseError {
44
25
  constructor(balance) {
45
26
  super(`Omni storage balance of intents contract is too low to complete this transaction safely.`, {
46
27
  metaMessages: [`Balance: ${balance}`],
@@ -50,12 +31,12 @@ var IntentsNearOmniAvailableBalanceTooLowError = class extends __defuse_protocol
50
31
  this.balance = balance;
51
32
  }
52
33
  };
53
- var OmniWithdrawalApiFeeRequestTimeoutError = class extends __defuse_protocol_internal_utils.BaseError {
34
+ var OmniWithdrawalApiFeeRequestTimeoutError = class extends _defuse_protocol_internal_utils.BaseError {
54
35
  constructor() {
55
36
  super("Omni bridge withdrawal fee request timed out.", { name: "OmniWithdrawalApiFeeRequestTimeoutError" });
56
37
  }
57
38
  };
58
- var InsufficientUtxoForOmniBridgeWithdrawalError = class extends __defuse_protocol_internal_utils.BaseError {
39
+ var InsufficientUtxoForOmniBridgeWithdrawalError = class extends _defuse_protocol_internal_utils.BaseError {
59
40
  constructor(destinationChain) {
60
41
  super("Insufficient utxo for withdrawal to a utxo chain.", {
61
42
  metaMessages: [`Destination Chain: ${destinationChain}`],
@@ -69,7 +50,5 @@ var InsufficientUtxoForOmniBridgeWithdrawalError = class extends __defuse_protoc
69
50
  exports.InsufficientUtxoForOmniBridgeWithdrawalError = InsufficientUtxoForOmniBridgeWithdrawalError;
70
51
  exports.IntentsNearOmniAvailableBalanceTooLowError = IntentsNearOmniAvailableBalanceTooLowError;
71
52
  exports.InvalidFeeValueError = InvalidFeeValueError;
72
- exports.OmniTransferDestinationChainHashNotFoundError = OmniTransferDestinationChainHashNotFoundError;
73
- exports.OmniTransferNotFoundError = OmniTransferNotFoundError;
74
53
  exports.OmniWithdrawalApiFeeRequestTimeoutError = OmniWithdrawalApiFeeRequestTimeoutError;
75
54
  exports.TokenNotFoundInDestinationChainError = TokenNotFoundInDestinationChainError;
@@ -2,21 +2,6 @@ import { Chain } from "../../lib/caip2.cjs";
2
2
  import { BaseError } from "@defuse-protocol/internal-utils";
3
3
 
4
4
  //#region src/bridges/omni-bridge/error.d.ts
5
- type OmniTransferNotFoundErrorType = OmniTransferNotFoundError & {
6
- name: "OmniTransferNotFoundError";
7
- };
8
- declare class OmniTransferNotFoundError extends BaseError {
9
- txHash: string;
10
- constructor(txHash: string);
11
- }
12
- type OmniTransferDestinationChainHashNotFoundErrorType = OmniTransferDestinationChainHashNotFoundError & {
13
- name: "OmniTransferDestinationChainHashNotFoundError";
14
- };
15
- declare class OmniTransferDestinationChainHashNotFoundError extends BaseError {
16
- txHash: string;
17
- destinationChain: string | undefined;
18
- constructor(txHash: string, destinationChain: string | undefined);
19
- }
20
5
  type TokenNotFoundInDestinationChainErrorType = TokenNotFoundInDestinationChainError & {
21
6
  name: "TokenNotFoundInDestinationChainError";
22
7
  };
@@ -53,4 +38,4 @@ declare class InsufficientUtxoForOmniBridgeWithdrawalError extends BaseError {
53
38
  constructor(destinationChain: Chain);
54
39
  }
55
40
  //#endregion
56
- export { InsufficientUtxoForOmniBridgeWithdrawalError, InsufficientUtxoForOmniBridgeWithdrawalErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, InvalidFeeValueError, InvalidFeeValueErrorType, OmniTransferDestinationChainHashNotFoundError, OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, OmniTransferNotFoundErrorType, OmniWithdrawalApiFeeRequestTimeoutError, OmniWithdrawalApiFeeRequestTimeoutErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType };
41
+ export { InsufficientUtxoForOmniBridgeWithdrawalError, InsufficientUtxoForOmniBridgeWithdrawalErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, InvalidFeeValueError, InvalidFeeValueErrorType, OmniWithdrawalApiFeeRequestTimeoutError, OmniWithdrawalApiFeeRequestTimeoutErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType };
@@ -2,21 +2,6 @@ import { Chain } from "../../lib/caip2.js";
2
2
  import { BaseError } from "@defuse-protocol/internal-utils";
3
3
 
4
4
  //#region src/bridges/omni-bridge/error.d.ts
5
- type OmniTransferNotFoundErrorType = OmniTransferNotFoundError & {
6
- name: "OmniTransferNotFoundError";
7
- };
8
- declare class OmniTransferNotFoundError extends BaseError {
9
- txHash: string;
10
- constructor(txHash: string);
11
- }
12
- type OmniTransferDestinationChainHashNotFoundErrorType = OmniTransferDestinationChainHashNotFoundError & {
13
- name: "OmniTransferDestinationChainHashNotFoundError";
14
- };
15
- declare class OmniTransferDestinationChainHashNotFoundError extends BaseError {
16
- txHash: string;
17
- destinationChain: string | undefined;
18
- constructor(txHash: string, destinationChain: string | undefined);
19
- }
20
5
  type TokenNotFoundInDestinationChainErrorType = TokenNotFoundInDestinationChainError & {
21
6
  name: "TokenNotFoundInDestinationChainError";
22
7
  };
@@ -53,4 +38,4 @@ declare class InsufficientUtxoForOmniBridgeWithdrawalError extends BaseError {
53
38
  constructor(destinationChain: Chain);
54
39
  }
55
40
  //#endregion
56
- export { InsufficientUtxoForOmniBridgeWithdrawalError, InsufficientUtxoForOmniBridgeWithdrawalErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, InvalidFeeValueError, InvalidFeeValueErrorType, OmniTransferDestinationChainHashNotFoundError, OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, OmniTransferNotFoundErrorType, OmniWithdrawalApiFeeRequestTimeoutError, OmniWithdrawalApiFeeRequestTimeoutErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType };
41
+ export { InsufficientUtxoForOmniBridgeWithdrawalError, InsufficientUtxoForOmniBridgeWithdrawalErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, InvalidFeeValueError, InvalidFeeValueErrorType, OmniWithdrawalApiFeeRequestTimeoutError, OmniWithdrawalApiFeeRequestTimeoutErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType };
@@ -1,25 +1,6 @@
1
1
  import { BaseError } from "@defuse-protocol/internal-utils";
2
2
 
3
3
  //#region src/bridges/omni-bridge/error.ts
4
- var OmniTransferNotFoundError = class extends BaseError {
5
- constructor(txHash) {
6
- super("Omni transfer with given hash is not found in the relayer.", {
7
- metaMessages: [`OriginTxHash: ${txHash}`],
8
- name: "OmniTransferNotFoundError"
9
- });
10
- this.txHash = txHash;
11
- }
12
- };
13
- var OmniTransferDestinationChainHashNotFoundError = class extends BaseError {
14
- constructor(txHash, destinationChain) {
15
- super("Relayer did not return destination chain hash for a transfer.", {
16
- metaMessages: [`OriginTxHash: ${txHash}`, `DestinationChain: ${destinationChain}`],
17
- name: "OmniTransferDestinationChainHashNotFoundError"
18
- });
19
- this.txHash = txHash;
20
- this.destinationChain = destinationChain;
21
- }
22
- };
23
4
  var TokenNotFoundInDestinationChainError = class extends BaseError {
24
5
  constructor(token, destinationChain) {
25
6
  super(`The token ${token} doesn't exist in destination chain ${destinationChain}`, {
@@ -65,4 +46,4 @@ var InsufficientUtxoForOmniBridgeWithdrawalError = class extends BaseError {
65
46
  };
66
47
 
67
48
  //#endregion
68
- export { InsufficientUtxoForOmniBridgeWithdrawalError, IntentsNearOmniAvailableBalanceTooLowError, InvalidFeeValueError, OmniTransferDestinationChainHashNotFoundError, OmniTransferNotFoundError, OmniWithdrawalApiFeeRequestTimeoutError, TokenNotFoundInDestinationChainError };
49
+ export { InsufficientUtxoForOmniBridgeWithdrawalError, IntentsNearOmniAvailableBalanceTooLowError, InvalidFeeValueError, OmniWithdrawalApiFeeRequestTimeoutError, TokenNotFoundInDestinationChainError };
@@ -1,15 +1,16 @@
1
1
  const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
2
  const require_caip2 = require('../../lib/caip2.cjs');
3
3
  const require_omni_bridge_constants = require('./omni-bridge-constants.cjs');
4
- let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
4
+ const require_poa_tokens_routable_through_omni_bridge = require('../../constants/poa-tokens-routable-through-omni-bridge.cjs');
5
+ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
5
6
  let omni_bridge_sdk = require("omni-bridge-sdk");
6
7
  let valibot = require("valibot");
7
8
  valibot = require_rolldown_runtime.__toESM(valibot);
8
9
 
9
10
  //#region src/bridges/omni-bridge/omni-bridge-utils.ts
10
11
  function createWithdrawIntentsPrimitive(params) {
11
- const { contractId: tokenAccountId, standard } = __defuse_protocol_internal_utils.utils.parseDefuseAssetId(params.assetId);
12
- (0, __defuse_protocol_internal_utils.assert)(standard === "nep141", "Only NEP-141 is supported");
12
+ const { contractId: tokenAccountId, standard } = _defuse_protocol_internal_utils.utils.parseDefuseAssetId(params.assetId);
13
+ (0, _defuse_protocol_internal_utils.assert)(standard === "nep141", "Only NEP-141 is supported");
13
14
  const recipient = (0, omni_bridge_sdk.omniAddress)(params.omniChainKind, params.destinationAddress);
14
15
  let msg = "";
15
16
  const ftWithdrawPayload = {
@@ -18,7 +19,7 @@ function createWithdrawIntentsPrimitive(params) {
18
19
  native_token_fee: params.nativeFee.toString()
19
20
  };
20
21
  if (isUtxoChain(params.omniChainKind)) {
21
- (0, __defuse_protocol_internal_utils.assert)(params.utxoMaxGasFee !== null && params.utxoMaxGasFee > 0n, `Invalid utxo max gas fee: expected > 0, got ${params.utxoMaxGasFee}`);
22
+ (0, _defuse_protocol_internal_utils.assert)(params.utxoMaxGasFee !== null && params.utxoMaxGasFee > 0n, `Invalid utxo max gas fee: expected > 0, got ${params.utxoMaxGasFee}`);
22
23
  msg = JSON.stringify({ MaxGasFee: params.utxoMaxGasFee.toString() });
23
24
  ftWithdrawPayload.msg = msg;
24
25
  }
@@ -72,12 +73,15 @@ const UTXO_CHAINS = [omni_bridge_sdk.ChainKind.Btc];
72
73
  function isUtxoChain(network) {
73
74
  return UTXO_CHAINS.includes(network);
74
75
  }
76
+ function poaContractIdToChainKind(contractId) {
77
+ return require_poa_tokens_routable_through_omni_bridge.POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE[contractId] ?? null;
78
+ }
75
79
  function validateOmniToken(nearAddress) {
76
80
  if (nearAddress.endsWith(".testnet")) return false;
77
81
  return (0, omni_bridge_sdk.isBridgeToken)(nearAddress);
78
82
  }
79
83
  async function getAccountOmniStorageBalance(nearProvider, accountId) {
80
- return __defuse_protocol_internal_utils.utils.queryContract({
84
+ return _defuse_protocol_internal_utils.utils.queryContract({
81
85
  contractId: require_omni_bridge_constants.OMNI_BRIDGE_CONTRACT,
82
86
  methodName: "storage_balance_of",
83
87
  args: { account_id: accountId },
@@ -103,7 +107,7 @@ const OmniAddressSchema = valibot.custom((input) => typeof input === "string" &&
103
107
  * const ethAddress = await getBridgedToken("near:token123", ChainKind.Ethereum)
104
108
  */
105
109
  async function getBridgedToken(nearProvider, tokenAddress, destinationChain) {
106
- return __defuse_protocol_internal_utils.utils.queryContract({
110
+ return _defuse_protocol_internal_utils.utils.queryContract({
107
111
  contractId: require_omni_bridge_constants.OMNI_BRIDGE_CONTRACT,
108
112
  methodName: "get_bridged_token",
109
113
  args: {
@@ -123,7 +127,7 @@ async function getBridgedToken(nearProvider, tokenAddress, destinationChain) {
123
127
  */
124
128
  async function getTokenDecimals(nearProvider, tokenAddress) {
125
129
  if ((0, omni_bridge_sdk.getChain)(tokenAddress) === omni_bridge_sdk.ChainKind.Near) throw new Error("Token decimals cannot be queried using NEAR addresses. Use the token's foreign chain representation (e.g., eth:0x...) to query decimals.");
126
- return __defuse_protocol_internal_utils.utils.queryContract({
130
+ return _defuse_protocol_internal_utils.utils.queryContract({
127
131
  contractId: require_omni_bridge_constants.OMNI_BRIDGE_CONTRACT,
128
132
  methodName: "get_token_decimals",
129
133
  args: { address: tokenAddress },
@@ -144,4 +148,5 @@ exports.getAccountOmniStorageBalance = getAccountOmniStorageBalance;
144
148
  exports.getBridgedToken = getBridgedToken;
145
149
  exports.getTokenDecimals = getTokenDecimals;
146
150
  exports.isUtxoChain = isUtxoChain;
151
+ exports.poaContractIdToChainKind = poaContractIdToChainKind;
147
152
  exports.validateOmniToken = validateOmniToken;
@@ -1,5 +1,6 @@
1
1
  import { Chains } from "../../lib/caip2.js";
2
2
  import { MIN_GAS_AMOUNT, OMNI_BRIDGE_CONTRACT } from "./omni-bridge-constants.js";
3
+ import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "../../constants/poa-tokens-routable-through-omni-bridge.js";
3
4
  import { assert, utils } from "@defuse-protocol/internal-utils";
4
5
  import { ChainKind, calculateStorageAccountId, getChain, isBridgeToken, omniAddress } from "omni-bridge-sdk";
5
6
  import * as v from "valibot";
@@ -70,6 +71,9 @@ const UTXO_CHAINS = [ChainKind.Btc];
70
71
  function isUtxoChain(network) {
71
72
  return UTXO_CHAINS.includes(network);
72
73
  }
74
+ function poaContractIdToChainKind(contractId) {
75
+ return POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE[contractId] ?? null;
76
+ }
73
77
  function validateOmniToken(nearAddress) {
74
78
  if (nearAddress.endsWith(".testnet")) return false;
75
79
  return isBridgeToken(nearAddress);
@@ -135,4 +139,4 @@ async function getTokenDecimals(nearProvider, tokenAddress) {
135
139
  }
136
140
 
137
141
  //#endregion
138
- export { caip2ToChainKind, chainKindToCaip2, createWithdrawIntentsPrimitive, getAccountOmniStorageBalance, getBridgedToken, getTokenDecimals, isUtxoChain, validateOmniToken };
142
+ export { caip2ToChainKind, chainKindToCaip2, createWithdrawIntentsPrimitive, getAccountOmniStorageBalance, getBridgedToken, getTokenDecimals, isUtxoChain, poaContractIdToChainKind, validateOmniToken };
@@ -1,33 +1,35 @@
1
1
  const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ const require_errors = require('../../classes/errors.cjs');
2
3
  const require_route_enum = require('../../constants/route-enum.cjs');
3
4
  const require_estimate_fee = require('../../lib/estimate-fee.cjs');
4
- const require_errors = require('../../classes/errors.cjs');
5
5
  const require_parse_defuse_asset_id = require('../../lib/parse-defuse-asset-id.cjs');
6
6
  const require_validateAddress = require('../../lib/validateAddress.cjs');
7
7
  const require_bridge_name_enum = require('../../constants/bridge-name-enum.cjs');
8
8
  const require_error = require('./error.cjs');
9
9
  const require_omni_bridge_constants = require('./omni-bridge-constants.cjs');
10
+ const require_poa_tokens_routable_through_omni_bridge = require('../../constants/poa-tokens-routable-through-omni-bridge.cjs');
10
11
  const require_omni_bridge_utils = require('./omni-bridge-utils.cjs');
11
- let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
12
+ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
12
13
  let lru_cache = require("lru-cache");
13
- let __lifeomic_attempt = require("@lifeomic/attempt");
14
- let __isaacs_ttlcache = require("@isaacs/ttlcache");
15
- __isaacs_ttlcache = require_rolldown_runtime.__toESM(__isaacs_ttlcache);
14
+ let _isaacs_ttlcache = require("@isaacs/ttlcache");
15
+ _isaacs_ttlcache = require_rolldown_runtime.__toESM(_isaacs_ttlcache);
16
16
  let omni_bridge_sdk = require("omni-bridge-sdk");
17
17
 
18
18
  //#region src/bridges/omni-bridge/omni-bridge.ts
19
19
  var OmniBridge = class {
20
- constructor({ env, nearProvider, solverRelayApiKey }) {
20
+ constructor({ env, nearProvider, solverRelayApiKey, routeMigratedPoaTokensThroughOmniBridge }) {
21
+ this.route = require_route_enum.RouteEnum.OmniBridge;
21
22
  this.storageDepositCache = new lru_cache.LRUCache({
22
23
  max: 100,
23
24
  ttl: 36e5
24
25
  });
25
- this.destinationChainAddressCache = new __isaacs_ttlcache.default({ ttl: 36e5 });
26
- this.tokenDecimalsCache = new __isaacs_ttlcache.default({ ttl: 36e5 });
26
+ this.destinationChainAddressCache = new _isaacs_ttlcache.default({ ttl: 36e5 });
27
+ this.tokenDecimalsCache = new _isaacs_ttlcache.default({ ttl: 36e5 });
27
28
  this.env = env;
28
29
  this.nearProvider = nearProvider;
29
30
  this.omniBridgeAPI = new omni_bridge_sdk.OmniBridgeAPI();
30
31
  this.solverRelayApiKey = solverRelayApiKey;
32
+ this.routeMigratedPoaTokensThroughOmniBridge = routeMigratedPoaTokensThroughOmniBridge ?? false;
31
33
  }
32
34
  is(routeConfig) {
33
35
  return routeConfig.route === require_route_enum.RouteEnum.OmniBridge;
@@ -40,7 +42,8 @@ var OmniBridge = class {
40
42
  const nonValidStandard = parsed.standard !== "nep141";
41
43
  if (nonValidStandard && (omniBridgeSetWithNoChain || targetChainSpecified)) throw new require_errors.UnsupportedAssetIdError(params.assetId, `Only NEP-141 tokens are supported by Omni Bridge.`);
42
44
  if (nonValidStandard) return false;
43
- const nonValidToken = require_omni_bridge_utils.validateOmniToken(parsed.contractId) === false;
45
+ const poaTokenRoutedThroughOmniBridge = this.isPoaTokenRoutedThroughOmniBridge(parsed.contractId);
46
+ const nonValidToken = !poaTokenRoutedThroughOmniBridge && require_omni_bridge_utils.validateOmniToken(parsed.contractId) === false;
44
47
  if (nonValidToken && omniBridgeSetWithNoChain) throw new require_errors.UnsupportedAssetIdError(params.assetId, `Non valid omni contract id ${parsed.contractId}`);
45
48
  if (!targetChainSpecified && nonValidToken) return false;
46
49
  let omniChainKind = null;
@@ -50,7 +53,7 @@ var OmniBridge = class {
50
53
  if (omniChainKind === null) throw new require_errors.UnsupportedAssetIdError(params.assetId, `Chain ${params.routeConfig.chain} is not supported in Omni Bridge.`);
51
54
  caip2Chain = params.routeConfig.chain;
52
55
  } else {
53
- omniChainKind = (0, omni_bridge_sdk.parseOriginChain)(parsed.contractId);
56
+ omniChainKind = poaTokenRoutedThroughOmniBridge ? require_omni_bridge_utils.poaContractIdToChainKind(parsed.contractId) : (0, omni_bridge_sdk.parseOriginChain)(parsed.contractId);
54
57
  if (omniChainKind === null) throw new require_errors.UnsupportedAssetIdError(params.assetId, `Withdrawal of ${parsed.contractId} to its origin chain is not supported in Omni Bridge.`);
55
58
  caip2Chain = require_omni_bridge_utils.chainKindToCaip2(omniChainKind);
56
59
  if (caip2Chain === null) throw new require_errors.UnsupportedAssetIdError(params.assetId, `Withdrawal of ${parsed.contractId} to its origin chain is not supported in Omni Bridge.`);
@@ -64,7 +67,7 @@ var OmniBridge = class {
64
67
  parseAssetId(assetId) {
65
68
  const parsed = require_parse_defuse_asset_id.parseDefuseAssetId(assetId);
66
69
  if (parsed.standard !== "nep141") return null;
67
- const omniChainKind = (0, omni_bridge_sdk.parseOriginChain)(parsed.contractId);
70
+ const omniChainKind = this.isPoaTokenRoutedThroughOmniBridge(parsed.contractId) ? require_omni_bridge_utils.poaContractIdToChainKind(parsed.contractId) : (0, omni_bridge_sdk.parseOriginChain)(parsed.contractId);
68
71
  if (omniChainKind === null) return null;
69
72
  const blockchain = require_omni_bridge_utils.chainKindToCaip2(omniChainKind);
70
73
  if (blockchain === null) return null;
@@ -83,7 +86,7 @@ var OmniBridge = class {
83
86
  omniChainKind = require_omni_bridge_utils.caip2ToChainKind(routeConfig.chain);
84
87
  blockchain = routeConfig.chain;
85
88
  } else {
86
- omniChainKind = (0, omni_bridge_sdk.parseOriginChain)(parsed.contractId);
89
+ omniChainKind = this.isPoaTokenRoutedThroughOmniBridge(parsed.contractId) ? require_omni_bridge_utils.poaContractIdToChainKind(parsed.contractId) : (0, omni_bridge_sdk.parseOriginChain)(parsed.contractId);
87
90
  if (omniChainKind === null) return null;
88
91
  blockchain = require_omni_bridge_utils.chainKindToCaip2(omniChainKind);
89
92
  }
@@ -96,9 +99,9 @@ var OmniBridge = class {
96
99
  }
97
100
  async createWithdrawalIntents(args) {
98
101
  const assetInfo = this.makeAssetInfo(args.withdrawalParams.assetId, args.withdrawalParams.routeConfig);
99
- (0, __defuse_protocol_internal_utils.assert)(assetInfo !== null, `Asset ${args.withdrawalParams.assetId} is not supported by Omni Bridge`);
102
+ (0, _defuse_protocol_internal_utils.assert)(assetInfo !== null, `Asset ${args.withdrawalParams.assetId} is not supported by Omni Bridge`);
100
103
  const omniChainKind = require_omni_bridge_utils.caip2ToChainKind(assetInfo.blockchain);
101
- (0, __defuse_protocol_internal_utils.assert)(omniChainKind !== null, `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`);
104
+ (0, _defuse_protocol_internal_utils.assert)(omniChainKind !== null, `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`);
102
105
  const intents = [];
103
106
  if (args.feeEstimation.quote !== null) intents.push({
104
107
  intent: "token_diff",
@@ -109,7 +112,7 @@ var OmniBridge = class {
109
112
  referral: args.referral
110
113
  });
111
114
  const relayerFee = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "relayerFee");
112
- (0, __defuse_protocol_internal_utils.assert)(relayerFee >= 0n, `Invalid Omni bridge relayer fee: expected >= 0, got ${relayerFee}`);
115
+ (0, _defuse_protocol_internal_utils.assert)(relayerFee >= 0n, `Invalid Omni bridge relayer fee: expected >= 0, got ${relayerFee}`);
113
116
  let amount = args.withdrawalParams.amount;
114
117
  let utxoMaxGasFee = null;
115
118
  /**
@@ -128,8 +131,8 @@ var OmniBridge = class {
128
131
  if (require_omni_bridge_utils.isUtxoChain(omniChainKind)) {
129
132
  utxoMaxGasFee = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "utxoMaxGasFee");
130
133
  const utxoProtocolFee = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "utxoProtocolFee");
131
- (0, __defuse_protocol_internal_utils.assert)(utxoMaxGasFee !== void 0 && utxoMaxGasFee > 0n, `Invalid Omni Bridge utxo max gas fee: expected > 0, got ${utxoMaxGasFee}`);
132
- (0, __defuse_protocol_internal_utils.assert)(utxoProtocolFee !== void 0 && utxoProtocolFee > 0n, `Invalid Omni Bridge utxo protocol fee: expected > 0, got ${utxoProtocolFee}`);
134
+ (0, _defuse_protocol_internal_utils.assert)(utxoMaxGasFee !== void 0 && utxoMaxGasFee > 0n, `Invalid Omni Bridge utxo max gas fee: expected > 0, got ${utxoMaxGasFee}`);
135
+ (0, _defuse_protocol_internal_utils.assert)(utxoProtocolFee !== void 0 && utxoProtocolFee > 0n, `Invalid Omni Bridge utxo protocol fee: expected > 0, got ${utxoProtocolFee}`);
133
136
  amount += utxoMaxGasFee + utxoProtocolFee;
134
137
  }
135
138
  intents.push(...require_omni_bridge_utils.createWithdrawIntentsPrimitive({
@@ -137,7 +140,7 @@ var OmniBridge = class {
137
140
  destinationAddress: args.withdrawalParams.destinationAddress,
138
141
  amount,
139
142
  omniChainKind,
140
- intentsContract: __defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID,
143
+ intentsContract: _defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID,
141
144
  nativeFee: relayerFee,
142
145
  storageDepositAmount: require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "storageDepositFee"),
143
146
  utxoMaxGasFee
@@ -145,48 +148,48 @@ var OmniBridge = class {
145
148
  return Promise.resolve(intents);
146
149
  }
147
150
  async validateWithdrawal(args) {
148
- (0, __defuse_protocol_internal_utils.assert)(args.feeEstimation.amount > 0n, `Invalid Omni Bridge fee: expected > 0, got ${args.feeEstimation.amount}`);
151
+ (0, _defuse_protocol_internal_utils.assert)(args.feeEstimation.amount > 0n, `Invalid Omni Bridge fee: expected > 0, got ${args.feeEstimation.amount}`);
149
152
  const assetInfo = this.makeAssetInfo(args.assetId, args.routeConfig);
150
- (0, __defuse_protocol_internal_utils.assert)(assetInfo !== null, `Asset ${args.assetId} is not supported by Omni Bridge`);
153
+ (0, _defuse_protocol_internal_utils.assert)(assetInfo !== null, `Asset ${args.assetId} is not supported by Omni Bridge`);
151
154
  if (require_validateAddress.validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
152
155
  const omniChainKind = require_omni_bridge_utils.caip2ToChainKind(assetInfo.blockchain);
153
- (0, __defuse_protocol_internal_utils.assert)(omniChainKind !== null, `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`);
156
+ (0, _defuse_protocol_internal_utils.assert)(omniChainKind !== null, `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`);
154
157
  const destTokenAddress = await this.getCachedDestinationTokenAddress(assetInfo.contractId, omniChainKind);
155
158
  if (destTokenAddress === null) throw new require_error.TokenNotFoundInDestinationChainError(args.assetId, assetInfo.blockchain);
156
159
  const decimals = await this.getCachedTokenDecimals(destTokenAddress);
157
- (0, __defuse_protocol_internal_utils.assert)(decimals !== null, `Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
160
+ (0, _defuse_protocol_internal_utils.assert)(decimals !== null, `Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
158
161
  Ensure the token is supported and the address is correct.`);
159
162
  if ((0, omni_bridge_sdk.verifyTransferAmount)(args.amount, 0n, decimals.origin_decimals, decimals.decimals) === false) throw new require_errors.MinWithdrawalAmountError((0, omni_bridge_sdk.getMinimumTransferableAmount)(decimals.origin_decimals, decimals.decimals), args.amount, args.assetId);
160
- const storageBalance = await require_omni_bridge_utils.getAccountOmniStorageBalance(this.nearProvider, __defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID);
163
+ const storageBalance = await require_omni_bridge_utils.getAccountOmniStorageBalance(this.nearProvider, _defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID);
161
164
  const intentsNearStorageBalance = storageBalance === null ? 0n : BigInt(storageBalance.available);
162
165
  if (intentsNearStorageBalance <= require_omni_bridge_constants.MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR) throw new require_error.IntentsNearOmniAvailableBalanceTooLowError(intentsNearStorageBalance.toString());
163
166
  const utxoChainWithdrawal = require_omni_bridge_utils.isUtxoChain(omniChainKind);
164
167
  if (utxoChainWithdrawal === false) {
165
168
  const relayerFee = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "relayerFee");
166
- (0, __defuse_protocol_internal_utils.assert)(require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "relayerFee") > 0n, `Invalid Omni Bridge relayer fee for non UTXO chain withdrawal: expected > 0, got ${relayerFee}`);
169
+ (0, _defuse_protocol_internal_utils.assert)(require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "relayerFee") > 0n, `Invalid Omni Bridge relayer fee for non UTXO chain withdrawal: expected > 0, got ${relayerFee}`);
167
170
  }
168
171
  if (utxoChainWithdrawal) {
169
- const fee = await (0, __defuse_protocol_internal_utils.withTimeout)(() => this.omniBridgeAPI.getFee((0, omni_bridge_sdk.omniAddress)(omni_bridge_sdk.ChainKind.Near, __defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID), (0, omni_bridge_sdk.omniAddress)(omniChainKind, args.destinationAddress), (0, omni_bridge_sdk.omniAddress)(omni_bridge_sdk.ChainKind.Near, assetInfo.contractId), args.amount), {
172
+ const fee = await (0, _defuse_protocol_internal_utils.withTimeout)(() => this.omniBridgeAPI.getFee((0, omni_bridge_sdk.omniAddress)(omni_bridge_sdk.ChainKind.Near, _defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID), (0, omni_bridge_sdk.omniAddress)(omniChainKind, args.destinationAddress), (0, omni_bridge_sdk.omniAddress)(omni_bridge_sdk.ChainKind.Near, assetInfo.contractId), args.amount), {
170
173
  timeout: typeof window !== "undefined" ? 1e4 : 3e3,
171
174
  errorInstance: new require_error.OmniWithdrawalApiFeeRequestTimeoutError()
172
175
  });
173
176
  if (fee.insufficient_utxo) throw new require_error.InsufficientUtxoForOmniBridgeWithdrawalError(assetInfo.blockchain);
174
- (0, __defuse_protocol_internal_utils.assert)(fee.min_amount !== null && fee.min_amount !== void 0 && BigInt(fee.min_amount) > 0n, `Invalid min amount value for a UTXO chain withdrawal: expected > 0, got ${fee.min_amount}`);
177
+ (0, _defuse_protocol_internal_utils.assert)(fee.min_amount !== null && fee.min_amount !== void 0 && BigInt(fee.min_amount) > 0n, `Invalid min amount value for a UTXO chain withdrawal: expected > 0, got ${fee.min_amount}`);
175
178
  const minAmount = BigInt(fee.min_amount);
176
179
  const utxoMaxGasFee = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "utxoMaxGasFee");
177
180
  const utxoProtocolFee = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "utxoProtocolFee");
178
- (0, __defuse_protocol_internal_utils.assert)(utxoMaxGasFee !== void 0 && utxoMaxGasFee > 0n, `Invalid Omni Bridge utxo max gas fee: expected > 0, got ${utxoMaxGasFee}`);
179
- (0, __defuse_protocol_internal_utils.assert)(utxoProtocolFee !== void 0 && utxoProtocolFee > 0n, `Invalid Omni Bridge utxo protocol fee: expected > 0, got ${utxoProtocolFee}`);
181
+ (0, _defuse_protocol_internal_utils.assert)(utxoMaxGasFee !== void 0 && utxoMaxGasFee > 0n, `Invalid Omni Bridge utxo max gas fee: expected > 0, got ${utxoMaxGasFee}`);
182
+ (0, _defuse_protocol_internal_utils.assert)(utxoProtocolFee !== void 0 && utxoProtocolFee > 0n, `Invalid Omni Bridge utxo protocol fee: expected > 0, got ${utxoProtocolFee}`);
180
183
  const actualAmountWithFee = args.amount + utxoMaxGasFee + utxoProtocolFee;
181
184
  if (actualAmountWithFee < minAmount) throw new require_errors.MinWithdrawalAmountError(minAmount, actualAmountWithFee, args.assetId);
182
185
  }
183
186
  }
184
187
  async estimateWithdrawalFee(args) {
185
188
  const assetInfo = this.makeAssetInfo(args.withdrawalParams.assetId, args.withdrawalParams.routeConfig);
186
- (0, __defuse_protocol_internal_utils.assert)(assetInfo !== null, `Asset ${args.withdrawalParams.assetId} is not supported by Omni Bridge`);
189
+ (0, _defuse_protocol_internal_utils.assert)(assetInfo !== null, `Asset ${args.withdrawalParams.assetId} is not supported by Omni Bridge`);
187
190
  const omniChainKind = require_omni_bridge_utils.caip2ToChainKind(assetInfo.blockchain);
188
- (0, __defuse_protocol_internal_utils.assert)(omniChainKind !== null, `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`);
189
- const fee = await (0, __defuse_protocol_internal_utils.withTimeout)(() => this.omniBridgeAPI.getFee((0, omni_bridge_sdk.omniAddress)(omni_bridge_sdk.ChainKind.Near, __defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID), (0, omni_bridge_sdk.omniAddress)(omniChainKind, args.withdrawalParams.destinationAddress), (0, omni_bridge_sdk.omniAddress)(omni_bridge_sdk.ChainKind.Near, assetInfo.contractId), args.withdrawalParams.amount), {
191
+ (0, _defuse_protocol_internal_utils.assert)(omniChainKind !== null, `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`);
192
+ const fee = await (0, _defuse_protocol_internal_utils.withTimeout)(() => this.omniBridgeAPI.getFee((0, omni_bridge_sdk.omniAddress)(omni_bridge_sdk.ChainKind.Near, _defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID), (0, omni_bridge_sdk.omniAddress)(omniChainKind, args.withdrawalParams.destinationAddress), (0, omni_bridge_sdk.omniAddress)(omni_bridge_sdk.ChainKind.Near, assetInfo.contractId), args.withdrawalParams.amount), {
190
193
  timeout: typeof window !== "undefined" ? 1e4 : 3e3,
191
194
  errorInstance: new require_error.OmniWithdrawalApiFeeRequestTimeoutError()
192
195
  });
@@ -222,8 +225,8 @@ var OmniBridge = class {
222
225
  amount += BigInt(quote.amount_in);
223
226
  }
224
227
  if (require_omni_bridge_utils.isUtxoChain(omniChainKind)) {
225
- (0, __defuse_protocol_internal_utils.assert)(fee.gas_fee !== null && fee.gas_fee !== void 0 && fee.gas_fee > 0n, `Invalid Omni Bridge utxo gas fee: expected > 0, got ${fee.gas_fee}`);
226
- (0, __defuse_protocol_internal_utils.assert)(fee.protocol_fee !== null && fee.protocol_fee !== void 0 && fee.protocol_fee > 0n, `Invalid Omni Bridge utxo protocol fee: expected > 0, got ${fee.protocol_fee}`);
228
+ (0, _defuse_protocol_internal_utils.assert)(fee.gas_fee !== null && fee.gas_fee !== void 0 && fee.gas_fee > 0n, `Invalid Omni Bridge utxo gas fee: expected > 0, got ${fee.gas_fee}`);
229
+ (0, _defuse_protocol_internal_utils.assert)(fee.protocol_fee !== null && fee.protocol_fee !== void 0 && fee.protocol_fee > 0n, `Invalid Omni Bridge utxo protocol fee: expected > 0, got ${fee.protocol_fee}`);
227
230
  amount += fee.gas_fee + fee.protocol_fee;
228
231
  underlyingFees.utxoMaxGasFee = fee.gas_fee;
229
232
  underlyingFees.utxoProtocolFee = fee.protocol_fee;
@@ -234,25 +237,33 @@ var OmniBridge = class {
234
237
  underlyingFees: { [require_route_enum.RouteEnum.OmniBridge]: underlyingFees }
235
238
  };
236
239
  }
237
- async waitForWithdrawalCompletion(args) {
238
- return (0, __lifeomic_attempt.retry)(async () => {
239
- if (args.signal?.aborted) throw args.signal.reason;
240
- const transfer = (await this.omniBridgeAPI.getTransfer({ transactionHash: args.tx.hash }))[args.index];
241
- if (transfer == null || transfer.transfer_message == null) throw new require_error.OmniTransferNotFoundError(args.tx.hash);
242
- const destinationChain = (0, omni_bridge_sdk.getChain)(transfer.transfer_message.recipient);
243
- let txHash = null;
244
- if ((0, omni_bridge_sdk.isEvmChain)(destinationChain)) txHash = transfer.finalised?.EVMLog?.transaction_hash;
245
- else if (destinationChain === omni_bridge_sdk.ChainKind.Sol) txHash = transfer.finalised?.Solana?.signature;
246
- else if (destinationChain === omni_bridge_sdk.ChainKind.Btc) txHash = typeof window !== "undefined" ? transfer.utxo_transfer?.btc_pending_id : transfer.finalised?.UtxoLog?.transaction_hash;
247
- else return { hash: null };
248
- if (!txHash) throw new require_error.OmniTransferDestinationChainHashNotFoundError(args.tx.hash, omni_bridge_sdk.ChainKind[destinationChain].toLowerCase());
249
- return { hash: txHash };
250
- }, {
251
- ...args.retryOptions ?? __defuse_protocol_internal_utils.RETRY_CONFIGS.FIVE_MINS_STEADY,
252
- handleError: (err, ctx) => {
253
- if (err === args.signal?.reason) ctx.abort();
254
- }
255
- });
240
+ createWithdrawalIdentifier(args) {
241
+ const assetInfo = this.makeAssetInfo(args.withdrawalParams.assetId, args.withdrawalParams.routeConfig);
242
+ (0, _defuse_protocol_internal_utils.assert)(assetInfo !== null, `Asset ${args.withdrawalParams.assetId} is not supported by Omni Bridge`);
243
+ return {
244
+ landingChain: args.withdrawalParams.routeConfig != null && "chain" in args.withdrawalParams.routeConfig && args.withdrawalParams.routeConfig.chain !== void 0 ? args.withdrawalParams.routeConfig.chain : assetInfo.blockchain,
245
+ index: args.index,
246
+ withdrawalParams: args.withdrawalParams,
247
+ tx: args.tx
248
+ };
249
+ }
250
+ async describeWithdrawal(args) {
251
+ const transfer = (await this.omniBridgeAPI.getTransfer({ transactionHash: args.tx.hash }))[args.index];
252
+ if (transfer == null || transfer.transfer_message == null) return { status: "pending" };
253
+ const destinationChain = (0, omni_bridge_sdk.getChain)(transfer.transfer_message.recipient);
254
+ let txHash = null;
255
+ if ((0, omni_bridge_sdk.isEvmChain)(destinationChain)) txHash = transfer.finalised?.EVMLog?.transaction_hash;
256
+ else if (destinationChain === omni_bridge_sdk.ChainKind.Sol) txHash = transfer.finalised?.Solana?.signature;
257
+ else if (destinationChain === omni_bridge_sdk.ChainKind.Btc) txHash = typeof window !== "undefined" ? transfer.utxo_transfer?.btc_pending_id : transfer.finalised?.UtxoLog?.transaction_hash;
258
+ else return {
259
+ status: "completed",
260
+ txHash: null
261
+ };
262
+ if (!txHash) return { status: "pending" };
263
+ return {
264
+ status: "completed",
265
+ txHash
266
+ };
256
267
  }
257
268
  /**
258
269
  * Gets storage deposit for a token to avoid frequent RPC calls.
@@ -260,10 +271,10 @@ var OmniBridge = class {
260
271
  async getCachedStorageDepositValue(contractId) {
261
272
  const cached = this.storageDepositCache.get(contractId);
262
273
  if (cached !== void 0) return cached;
263
- const result = await Promise.all([(0, __defuse_protocol_internal_utils.getNearNep141MinStorageBalance)({
274
+ const result = await Promise.all([(0, _defuse_protocol_internal_utils.getNearNep141MinStorageBalance)({
264
275
  contractId,
265
276
  nearProvider: this.nearProvider
266
- }), (0, __defuse_protocol_internal_utils.getNearNep141StorageBalance)({
277
+ }), (0, _defuse_protocol_internal_utils.getNearNep141StorageBalance)({
267
278
  contractId,
268
279
  accountId: require_omni_bridge_constants.OMNI_BRIDGE_CONTRACT,
269
280
  nearProvider: this.nearProvider
@@ -292,6 +303,13 @@ var OmniBridge = class {
292
303
  if (tokenDecimals !== null) this.tokenDecimalsCache.set(omniAddress$1, tokenDecimals);
293
304
  return tokenDecimals;
294
305
  }
306
+ /**
307
+ * Checks if passed token contract id is an allowlisted PoA token that should be routed via OmniBridge.
308
+ * Always return false when feature flag routeMigratedPoaTokensThroughOmniBridge = false.
309
+ */
310
+ isPoaTokenRoutedThroughOmniBridge(nearAddress) {
311
+ return this.routeMigratedPoaTokensThroughOmniBridge ? require_poa_tokens_routable_through_omni_bridge.POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE[nearAddress] !== void 0 : false;
312
+ }
295
313
  };
296
314
 
297
315
  //#endregion