@defuse-protocol/intents-sdk 0.16.1 → 0.16.3

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 (3) hide show
  1. package/dist/index.cjs +108 -453
  2. package/dist/index.js +96 -457
  3. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -30,28 +30,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- AssertionError: () => import_internal_utils24.AssertionError,
34
- BaseError: () => import_internal_utils21.BaseError,
33
+ AssertionError: () => import_internal_utils22.AssertionError,
34
+ BaseError: () => import_internal_utils19.BaseError,
35
35
  BridgeNameEnum: () => BridgeNameEnum,
36
36
  Chains: () => Chains,
37
37
  FeeExceedsAmountError: () => FeeExceedsAmountError,
38
38
  HotWithdrawalCancelledError: () => HotWithdrawalCancelledError,
39
39
  HotWithdrawalNotFoundError: () => HotWithdrawalNotFoundError,
40
40
  HotWithdrawalPendingError: () => HotWithdrawalPendingError,
41
- HttpRequestError: () => import_internal_utils23.HttpRequestError,
42
- IntentSettlementError: () => import_internal_utils25.IntentSettlementError,
41
+ HttpRequestError: () => import_internal_utils21.HttpRequestError,
42
+ IntentSettlementError: () => import_internal_utils23.IntentSettlementError,
43
43
  IntentsSDK: () => IntentsSDK,
44
44
  MinWithdrawalAmountError: () => MinWithdrawalAmountError,
45
45
  OmniTransferDestinationChainHashNotFoundError: () => OmniTransferDestinationChainHashNotFoundError,
46
46
  OmniTransferNotFoundError: () => OmniTransferNotFoundError,
47
- PoaWithdrawalInvariantError: () => import_internal_utils22.PoaWithdrawalInvariantError,
48
- PoaWithdrawalNotFoundError: () => import_internal_utils22.PoaWithdrawalNotFoundError,
49
- PoaWithdrawalPendingError: () => import_internal_utils22.PoaWithdrawalPendingError,
50
- QuoteError: () => import_internal_utils25.QuoteError,
51
- RelayPublishError: () => import_internal_utils25.RelayPublishError,
47
+ PoaWithdrawalInvariantError: () => import_internal_utils20.PoaWithdrawalInvariantError,
48
+ PoaWithdrawalNotFoundError: () => import_internal_utils20.PoaWithdrawalNotFoundError,
49
+ PoaWithdrawalPendingError: () => import_internal_utils20.PoaWithdrawalPendingError,
50
+ QuoteError: () => import_internal_utils23.QuoteError,
51
+ RelayPublishError: () => import_internal_utils23.RelayPublishError,
52
52
  RouteEnum: () => RouteEnum,
53
- RpcRequestError: () => import_internal_utils23.RpcRequestError,
54
- TimeoutError: () => import_internal_utils23.TimeoutError,
53
+ RpcRequestError: () => import_internal_utils21.RpcRequestError,
54
+ TimeoutError: () => import_internal_utils21.TimeoutError,
55
55
  TokenNotFoundInDestinationChainError: () => TokenNotFoundInDestinationChainError,
56
56
  TokenNotSupportedByOmniRelayerError: () => TokenNotSupportedByOmniRelayerError,
57
57
  TrustlineNotFoundError: () => TrustlineNotFoundError,
@@ -70,7 +70,7 @@ __export(index_exports, {
70
70
  module.exports = __toCommonJS(index_exports);
71
71
 
72
72
  // src/sdk.ts
73
- var import_internal_utils19 = require("@defuse-protocol/internal-utils");
73
+ var import_internal_utils16 = require("@defuse-protocol/internal-utils");
74
74
  var import_omni_sdk3 = __toESM(require("@hot-labs/omni-sdk"), 1);
75
75
  var import_viem2 = require("viem");
76
76
 
@@ -816,407 +816,14 @@ var IntentsBridge = class {
816
816
  }
817
817
  };
818
818
 
819
- // src/bridges/omni-bridge/omni-bridge.ts
820
- var import_internal_utils12 = require("@defuse-protocol/internal-utils");
819
+ // src/bridges/poa-bridge/poa-bridge.ts
820
+ var import_internal_utils11 = require("@defuse-protocol/internal-utils");
821
821
  var import_ttlcache = __toESM(require("@isaacs/ttlcache"), 1);
822
- var import_attempt2 = require("@lifeomic/attempt");
823
- var import_omni_bridge_sdk2 = require("omni-bridge-sdk");
824
822
 
825
- // src/bridges/omni-bridge/error.ts
823
+ // src/bridges/poa-bridge/poa-bridge-utils.ts
826
824
  var import_internal_utils10 = require("@defuse-protocol/internal-utils");
827
- var OmniTransferNotFoundError = class extends import_internal_utils10.BaseError {
828
- constructor(txHash) {
829
- super("Omni transfer with given hash is not found in the relayer.", {
830
- metaMessages: [`OriginTxHash: ${txHash}`],
831
- name: "OmniTransferNotFoundError"
832
- });
833
- this.txHash = txHash;
834
- }
835
- };
836
- var OmniTransferDestinationChainHashNotFoundError = class extends import_internal_utils10.BaseError {
837
- constructor(txHash, destinationChain) {
838
- super("Relayer did not return destination chain hash for a transfer.", {
839
- metaMessages: [
840
- `OriginTxHash: ${txHash}`,
841
- `DestinationChain: ${destinationChain}`
842
- ],
843
- name: "OmniTransferDestinationChainHashNotFoundError"
844
- });
845
- this.txHash = txHash;
846
- this.destinationChain = destinationChain;
847
- }
848
- };
849
- var TokenNotSupportedByOmniRelayerError = class extends import_internal_utils10.BaseError {
850
- constructor(token) {
851
- super(`Omni Relayer doesn't accept fee in the transferred token ${token}`, {
852
- metaMessages: [`Token: ${token}`],
853
- name: "TokenNotSupportedByOmniRelayerError"
854
- });
855
- this.token = token;
856
- }
857
- };
858
- var TokenNotFoundInDestinationChainError = class extends import_internal_utils10.BaseError {
859
- constructor(token, chainKind) {
860
- super(
861
- `The token ${token} doesn't exist in destination network ${chainKind}`,
862
- {
863
- metaMessages: [`Token: ${token}`, `Destination Chain: ${chainKind}`],
864
- name: "TokenNotFoundInDestinationChainError"
865
- }
866
- );
867
- this.token = token;
868
- }
869
- };
870
-
871
- // src/bridges/omni-bridge/omni-bridge-constants.ts
872
- var NEAR_NATIVE_ASSET_ID3 = "nep141:wrap.near";
873
- var OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
874
-
875
- // src/bridges/omni-bridge/omni-bridge-utils.ts
876
- var import_internal_utils11 = require("@defuse-protocol/internal-utils");
877
- var import_omni_bridge_sdk = require("omni-bridge-sdk");
878
825
  function createWithdrawIntentPrimitive3(params) {
879
- const { contractId: tokenAccountId, standard } = import_internal_utils11.utils.parseDefuseAssetId(
880
- params.assetId
881
- );
882
- (0, import_internal_utils11.assert)(standard === "nep141", "Only NEP-141 is supported");
883
- return {
884
- intent: "ft_withdraw",
885
- token: tokenAccountId,
886
- receiver_id: OMNI_BRIDGE_CONTRACT,
887
- amount: params.amount.toString(),
888
- storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : null,
889
- msg: JSON.stringify({
890
- recipient: (0, import_omni_bridge_sdk.omniAddress)(
891
- caip2ToChainKind(params.origin),
892
- params.destinationAddress
893
- ),
894
- fee: params.transferredTokenFee.toString(),
895
- native_token_fee: "0"
896
- })
897
- };
898
- }
899
- function targetChainSupportedByOmniBridge(network) {
900
- switch (network) {
901
- case Chains.Ethereum:
902
- return true;
903
- case Chains.Base:
904
- return true;
905
- case Chains.Arbitrum:
906
- return true;
907
- case Chains.Solana:
908
- return true;
909
- case Chains.Bitcoin:
910
- return true;
911
- default:
912
- return false;
913
- }
914
- }
915
- function caip2ToChainKind(network) {
916
- switch (network) {
917
- case Chains.Ethereum:
918
- return import_omni_bridge_sdk.ChainKind.Eth;
919
- case Chains.Base:
920
- return import_omni_bridge_sdk.ChainKind.Base;
921
- case Chains.Arbitrum:
922
- return import_omni_bridge_sdk.ChainKind.Arb;
923
- case Chains.Solana:
924
- return import_omni_bridge_sdk.ChainKind.Sol;
925
- case Chains.Bitcoin:
926
- return import_omni_bridge_sdk.ChainKind.Btc;
927
- default:
928
- throw new Error(`Unsupported Omni network = ${network}`);
929
- }
930
- }
931
- function chainKindToCaip2(network) {
932
- switch (network) {
933
- case import_omni_bridge_sdk.ChainKind.Eth:
934
- return Chains.Ethereum;
935
- case import_omni_bridge_sdk.ChainKind.Base:
936
- return Chains.Base;
937
- case import_omni_bridge_sdk.ChainKind.Arb:
938
- return Chains.Arbitrum;
939
- case import_omni_bridge_sdk.ChainKind.Sol:
940
- return Chains.Solana;
941
- case import_omni_bridge_sdk.ChainKind.Btc:
942
- return Chains.Bitcoin;
943
- default:
944
- throw new Error(`Unsupported Caip2 network = ${network}`);
945
- }
946
- }
947
-
948
- // src/bridges/omni-bridge/omni-bridge.ts
949
- var _OmniBridge = class _OmniBridge {
950
- // 86400000 - 1 day
951
- constructor({
952
- env,
953
- nearProvider
954
- }) {
955
- this.storageDepositCache = new import_ttlcache.default({ ttl: 864e5 });
956
- // TTL cache for supported tokens with 30-second TTL
957
- this.supportedTokensCache = new import_ttlcache.default({ ttl: 864e5 });
958
- // 86400000 - 1 day
959
- this.destinationChainAddressCache = new import_ttlcache.default({ ttl: 864e5 });
960
- this.env = env;
961
- this.nearProvider = nearProvider;
962
- this.omniBridgeAPI = new import_omni_bridge_sdk2.OmniBridgeAPI();
963
- }
964
- is(routeConfig) {
965
- return routeConfig.route === RouteEnum.OmniBridge;
966
- }
967
- supports(params) {
968
- try {
969
- if (this.targetChainSpecified(params.routeConfig)) {
970
- return targetChainSupportedByOmniBridge(params.routeConfig.chain);
971
- }
972
- return this.parseAssetId(params.assetId) !== null;
973
- } catch {
974
- return false;
975
- }
976
- }
977
- targetChainSpecified(routeConfig) {
978
- return Boolean(
979
- routeConfig?.route && routeConfig.route === RouteEnum.OmniBridge && routeConfig.chain
980
- );
981
- }
982
- parseAssetId(assetId) {
983
- const parsed = import_internal_utils12.utils.parseDefuseAssetId(assetId);
984
- if (parsed.standard !== "nep141") return null;
985
- const chain = (0, import_omni_bridge_sdk2.parseOriginChain)(parsed.contractId);
986
- if (chain === null) return null;
987
- return Object.assign(parsed, {
988
- blockchain: chainKindToCaip2(chain),
989
- bridgeName: BridgeNameEnum.Omni,
990
- address: parsed.contractId
991
- });
992
- }
993
- async tokenSupported(assetId, routeConfig) {
994
- const parsed = import_internal_utils12.utils.parseDefuseAssetId(assetId);
995
- if (parsed.standard !== "nep141") return null;
996
- if (this.targetChainSpecified(routeConfig)) {
997
- const tokenOnDestinationNetwork = await this.getCachedDestinationTokenAddress(
998
- parsed.contractId,
999
- routeConfig.chain
1000
- );
1001
- if (tokenOnDestinationNetwork === null) {
1002
- throw new TokenNotFoundInDestinationChainError(
1003
- assetId,
1004
- routeConfig.chain
1005
- );
1006
- }
1007
- return Object.assign(parsed, {
1008
- blockchain: routeConfig.chain,
1009
- bridgeName: BridgeNameEnum.Omni,
1010
- address: parsed.contractId
1011
- });
1012
- }
1013
- const chain = (0, import_omni_bridge_sdk2.parseOriginChain)(parsed.contractId);
1014
- if (chain === null) return null;
1015
- return Object.assign(parsed, {
1016
- blockchain: chainKindToCaip2(chain),
1017
- bridgeName: BridgeNameEnum.Omni,
1018
- address: parsed.contractId
1019
- });
1020
- }
1021
- async createWithdrawalIntents(args) {
1022
- const assetInfo = await this.tokenSupported(
1023
- args.withdrawalParams.assetId,
1024
- args.withdrawalParams.routeConfig
1025
- );
1026
- (0, import_internal_utils12.assert)(
1027
- assetInfo !== null,
1028
- `Asset ${args.withdrawalParams.assetId} is not supported`
1029
- );
1030
- const intents = [];
1031
- if (args.feeEstimation.quote !== null) {
1032
- intents.push({
1033
- intent: "token_diff",
1034
- diff: {
1035
- [args.feeEstimation.quote.defuse_asset_identifier_in]: `-${args.feeEstimation.quote.amount_in}`,
1036
- [args.feeEstimation.quote.defuse_asset_identifier_out]: args.feeEstimation.quote.amount_out
1037
- },
1038
- referral: args.referral
1039
- });
1040
- }
1041
- const intent = createWithdrawIntentPrimitive3({
1042
- assetId: args.withdrawalParams.assetId,
1043
- destinationAddress: args.withdrawalParams.destinationAddress,
1044
- amount: args.withdrawalParams.amount + args.feeEstimation.amount,
1045
- origin: assetInfo.blockchain,
1046
- storageDeposit: args.feeEstimation.quote ? BigInt(args.feeEstimation.quote.amount_out) : 0n,
1047
- transferredTokenFee: args.feeEstimation.amount
1048
- });
1049
- intents.push(intent);
1050
- return Promise.resolve(intents);
1051
- }
1052
- async validateWithdrawal(args) {
1053
- const assetInfo = await this.tokenSupported(args.assetId, args.routeConfig);
1054
- (0, import_internal_utils12.assert)(assetInfo !== null, `Asset ${args.assetId} is not supported`);
1055
- const supportedTokens = await this.getCachedSupportedTokens();
1056
- if (!supportedTokens[assetInfo.contractId]) {
1057
- throw new TokenNotSupportedByOmniRelayerError(args.assetId);
1058
- }
1059
- (0, import_internal_utils12.assert)(
1060
- args.feeEstimation.amount > 0n,
1061
- `Fee must be greater than zero. Current fee is ${args.feeEstimation.amount}.`
1062
- );
1063
- return;
1064
- }
1065
- async estimateWithdrawalFee(args) {
1066
- const assetInfo = await this.tokenSupported(
1067
- args.withdrawalParams.assetId,
1068
- args.withdrawalParams.routeConfig
1069
- );
1070
- (0, import_internal_utils12.assert)(
1071
- assetInfo !== null,
1072
- `Asset ${args.withdrawalParams.assetId} is not supported`
1073
- );
1074
- const fee = await this.omniBridgeAPI.getFee(
1075
- (0, import_omni_bridge_sdk2.omniAddress)(import_omni_bridge_sdk2.ChainKind.Near, import_internal_utils12.configsByEnvironment[this.env].contractID),
1076
- (0, import_omni_bridge_sdk2.omniAddress)(
1077
- caip2ToChainKind(assetInfo.blockchain),
1078
- args.withdrawalParams.destinationAddress
1079
- ),
1080
- (0, import_omni_bridge_sdk2.omniAddress)(import_omni_bridge_sdk2.ChainKind.Near, assetInfo.contractId)
1081
- );
1082
- (0, import_internal_utils12.assert)(
1083
- fee.transferred_token_fee !== null,
1084
- `Asset ${args.withdrawalParams.assetId} is not supported by the relayer`
1085
- );
1086
- const [minStorageBalance, userStorageBalance] = await this.getCachedStorageDepositValue(assetInfo.contractId);
1087
- if (minStorageBalance <= userStorageBalance) {
1088
- return {
1089
- amount: BigInt(fee.transferred_token_fee),
1090
- quote: null
1091
- };
1092
- }
1093
- const feeAmount = minStorageBalance - userStorageBalance;
1094
- const feeQuote = await import_internal_utils12.solverRelay.getQuote({
1095
- quoteParams: {
1096
- defuse_asset_identifier_in: args.withdrawalParams.assetId,
1097
- defuse_asset_identifier_out: NEAR_NATIVE_ASSET_ID3,
1098
- exact_amount_out: feeAmount.toString(),
1099
- wait_ms: args.quoteOptions?.waitMs
1100
- },
1101
- config: {
1102
- baseURL: import_internal_utils12.configsByEnvironment[this.env].solverRelayBaseURL,
1103
- logBalanceSufficient: false,
1104
- logger: args.logger
1105
- }
1106
- });
1107
- return {
1108
- amount: BigInt(fee.transferred_token_fee) + BigInt(feeQuote.amount_in),
1109
- quote: feeQuote
1110
- };
1111
- }
1112
- async waitForWithdrawalCompletion(args) {
1113
- return (0, import_attempt2.retry)(
1114
- async () => {
1115
- if (args.signal?.aborted) {
1116
- throw args.signal.reason;
1117
- }
1118
- const transfer = (await this.omniBridgeAPI.findOmniTransfers({
1119
- transaction_id: args.tx.hash,
1120
- offset: args.index,
1121
- limit: 1
1122
- }))[0];
1123
- if (!transfer) throw new OmniTransferNotFoundError(args.tx.hash);
1124
- const destinationChain = (0, import_omni_bridge_sdk2.getChain)(
1125
- transfer.transfer_message.recipient
1126
- );
1127
- let txHash = null;
1128
- if ((0, import_omni_bridge_sdk2.isEvmChain)(destinationChain)) {
1129
- txHash = transfer.finalised?.EVMLog?.transaction_hash;
1130
- } else if (destinationChain === import_omni_bridge_sdk2.ChainKind.Sol) {
1131
- txHash = transfer.finalised?.Solana?.signature;
1132
- } else {
1133
- return { hash: null };
1134
- }
1135
- if (!txHash)
1136
- throw new OmniTransferDestinationChainHashNotFoundError(
1137
- args.tx.hash,
1138
- import_omni_bridge_sdk2.ChainKind[destinationChain].toLowerCase()
1139
- );
1140
- return { hash: txHash };
1141
- },
1142
- {
1143
- ...args.retryOptions ?? import_internal_utils12.RETRY_CONFIGS.TWO_MINS_GRADUAL,
1144
- handleError: (err, ctx) => {
1145
- if (err instanceof OmniTransferNotFoundError || err === args.signal?.reason) {
1146
- ctx.abort();
1147
- }
1148
- }
1149
- }
1150
- );
1151
- }
1152
- /**
1153
- * Gets storage deposit for a token to avoid frequent RPC calls.
1154
- * Cache expires after one day using TTL cache.
1155
- */
1156
- async getCachedStorageDepositValue(contractId) {
1157
- const cached = this.storageDepositCache.get(contractId);
1158
- if (cached != null) {
1159
- return cached;
1160
- }
1161
- const data = await Promise.all([
1162
- (0, import_internal_utils12.getNearNep141MinStorageBalance)({
1163
- contractId,
1164
- nearProvider: this.nearProvider
1165
- }),
1166
- (0, import_internal_utils12.getNearNep141StorageBalance)({
1167
- contractId,
1168
- accountId: OMNI_BRIDGE_CONTRACT,
1169
- nearProvider: this.nearProvider
1170
- })
1171
- ]);
1172
- this.storageDepositCache.set(contractId, data);
1173
- return data;
1174
- }
1175
- /**
1176
- * Gets cached tokens supported by the omni relayer, tokens not listed there can't be transferred.
1177
- * Cache expires after one day using TTL cache.
1178
- */
1179
- async getCachedSupportedTokens() {
1180
- const cached = this.supportedTokensCache.get(
1181
- _OmniBridge.SUPPORTED_TOKENS_CACHE_KEY
1182
- );
1183
- if (cached != null) {
1184
- return cached;
1185
- }
1186
- const data = await this.omniBridgeAPI.getAllowlistedTokens();
1187
- this.supportedTokensCache.set(_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY, data);
1188
- return data;
1189
- }
1190
- /**
1191
- * Gets cached token address on destination chain.
1192
- * Cache expires after one day using TTL cache.
1193
- */
1194
- async getCachedDestinationTokenAddress(contractId, chain) {
1195
- const key = `${chain}:${contractId}`;
1196
- const cached = this.destinationChainAddressCache.get(key);
1197
- if (cached != null) {
1198
- return cached;
1199
- }
1200
- const tokenOnDestinationNetwork = await (0, import_omni_bridge_sdk2.getBridgedToken)(
1201
- (0, import_omni_bridge_sdk2.omniAddress)(import_omni_bridge_sdk2.ChainKind.Near, contractId),
1202
- caip2ToChainKind(chain)
1203
- );
1204
- this.destinationChainAddressCache.set(key, tokenOnDestinationNetwork);
1205
- return tokenOnDestinationNetwork;
1206
- }
1207
- };
1208
- // 86400000 - 1 day
1209
- _OmniBridge.SUPPORTED_TOKENS_CACHE_KEY = "SUPPORTED_TOKENS_CACHE_KEY";
1210
- var OmniBridge = _OmniBridge;
1211
-
1212
- // src/bridges/poa-bridge/poa-bridge.ts
1213
- var import_internal_utils14 = require("@defuse-protocol/internal-utils");
1214
- var import_ttlcache2 = __toESM(require("@isaacs/ttlcache"), 1);
1215
-
1216
- // src/bridges/poa-bridge/poa-bridge-utils.ts
1217
- var import_internal_utils13 = require("@defuse-protocol/internal-utils");
1218
- function createWithdrawIntentPrimitive4(params) {
1219
- const { contractId: tokenAccountId } = import_internal_utils13.utils.parseDefuseAssetId(
826
+ const { contractId: tokenAccountId } = import_internal_utils10.utils.parseDefuseAssetId(
1220
827
  params.assetId
1221
828
  );
1222
829
  return {
@@ -1291,7 +898,7 @@ function contractIdToCaip2(contractId) {
1291
898
  var PoaBridge = class {
1292
899
  constructor({ env }) {
1293
900
  // TTL cache for supported tokens with 30-second TTL
1294
- this.supportedTokensCache = new import_ttlcache2.default({ ttl: 30 * 1e3 });
901
+ this.supportedTokensCache = new import_ttlcache.default({ ttl: 30 * 1e3 });
1295
902
  this.env = env;
1296
903
  }
1297
904
  is(routeConfig) {
@@ -1309,9 +916,9 @@ var PoaBridge = class {
1309
916
  }
1310
917
  }
1311
918
  parseAssetId(assetId) {
1312
- const parsed = import_internal_utils14.utils.parseDefuseAssetId(assetId);
919
+ const parsed = import_internal_utils11.utils.parseDefuseAssetId(assetId);
1313
920
  if (parsed.contractId.endsWith(
1314
- `.${import_internal_utils14.configsByEnvironment[this.env].poaTokenFactoryContractID}`
921
+ `.${import_internal_utils11.configsByEnvironment[this.env].poaTokenFactoryContractID}`
1315
922
  )) {
1316
923
  return Object.assign(parsed, {
1317
924
  blockchain: contractIdToCaip2(parsed.contractId),
@@ -1323,7 +930,7 @@ var PoaBridge = class {
1323
930
  return null;
1324
931
  }
1325
932
  createWithdrawalIntents(args) {
1326
- const intent = createWithdrawIntentPrimitive4({
933
+ const intent = createWithdrawIntentPrimitive3({
1327
934
  ...args.withdrawalParams,
1328
935
  amount: args.withdrawalParams.amount + args.feeEstimation.amount,
1329
936
  destinationMemo: args.withdrawalParams.destinationMemo
@@ -1338,7 +945,7 @@ var PoaBridge = class {
1338
945
  */
1339
946
  async validateWithdrawal(args) {
1340
947
  const assetInfo = this.parseAssetId(args.assetId);
1341
- (0, import_internal_utils14.assert)(assetInfo != null, "Asset is not supported");
948
+ (0, import_internal_utils11.assert)(assetInfo != null, "Asset is not supported");
1342
949
  const { tokens } = await this.getCachedSupportedTokens(
1343
950
  [toPoaNetwork(assetInfo.blockchain)],
1344
951
  args.logger
@@ -1359,16 +966,16 @@ var PoaBridge = class {
1359
966
  }
1360
967
  async estimateWithdrawalFee(args) {
1361
968
  const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
1362
- (0, import_internal_utils14.assert)(assetInfo != null, "Asset is not supported");
1363
- const estimation = await import_internal_utils14.poaBridge.httpClient.getWithdrawalEstimate(
969
+ (0, import_internal_utils11.assert)(assetInfo != null, "Asset is not supported");
970
+ const estimation = await import_internal_utils11.poaBridge.httpClient.getWithdrawalEstimate(
1364
971
  {
1365
- token: import_internal_utils14.utils.getTokenAccountId(args.withdrawalParams.assetId),
972
+ token: import_internal_utils11.utils.getTokenAccountId(args.withdrawalParams.assetId),
1366
973
  address: args.withdrawalParams.destinationAddress,
1367
974
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
1368
975
  chain: toPoaNetwork(assetInfo.blockchain)
1369
976
  },
1370
977
  {
1371
- baseURL: import_internal_utils14.configsByEnvironment[this.env].poaBridgeBaseURL,
978
+ baseURL: import_internal_utils11.configsByEnvironment[this.env].poaBridgeBaseURL,
1372
979
  logger: args.logger
1373
980
  }
1374
981
  );
@@ -1378,12 +985,12 @@ var PoaBridge = class {
1378
985
  };
1379
986
  }
1380
987
  async waitForWithdrawalCompletion(args) {
1381
- const withdrawalStatus = await import_internal_utils14.poaBridge.waitForWithdrawalCompletion({
988
+ const withdrawalStatus = await import_internal_utils11.poaBridge.waitForWithdrawalCompletion({
1382
989
  txHash: args.tx.hash,
1383
990
  index: args.index,
1384
991
  signal: args.signal ?? new AbortController().signal,
1385
992
  retryOptions: args.retryOptions,
1386
- baseURL: import_internal_utils14.configsByEnvironment[this.env].poaBridgeBaseURL,
993
+ baseURL: import_internal_utils11.configsByEnvironment[this.env].poaBridgeBaseURL,
1387
994
  logger: args.logger
1388
995
  });
1389
996
  return { hash: withdrawalStatus.destinationTxHash };
@@ -1398,10 +1005,10 @@ var PoaBridge = class {
1398
1005
  if (cached != null) {
1399
1006
  return cached;
1400
1007
  }
1401
- const data = await import_internal_utils14.poaBridge.httpClient.getSupportedTokens(
1008
+ const data = await import_internal_utils11.poaBridge.httpClient.getSupportedTokens(
1402
1009
  { chains },
1403
1010
  {
1404
- baseURL: import_internal_utils14.configsByEnvironment[this.env].poaBridgeBaseURL,
1011
+ baseURL: import_internal_utils11.configsByEnvironment[this.env].poaBridgeBaseURL,
1405
1012
  logger
1406
1013
  }
1407
1014
  );
@@ -1423,7 +1030,7 @@ var PUBLIC_STELLAR_RPC_URLS = {
1423
1030
  };
1424
1031
 
1425
1032
  // src/intents/intent-executer-impl/intent-executer.ts
1426
- var import_internal_utils15 = require("@defuse-protocol/internal-utils");
1033
+ var import_internal_utils12 = require("@defuse-protocol/internal-utils");
1427
1034
 
1428
1035
  // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
1429
1036
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
@@ -1804,7 +1411,7 @@ var IntentExecuter = class {
1804
1411
  relayParams: relayParamsFactory,
1805
1412
  ...intentParams
1806
1413
  }) {
1807
- const verifyingContract = import_internal_utils15.configsByEnvironment[this.env].contractID;
1414
+ const verifyingContract = import_internal_utils12.configsByEnvironment[this.env].contractID;
1808
1415
  let intentPayload = defaultIntentPayloadFactory({
1809
1416
  verifying_contract: verifyingContract,
1810
1417
  ...intentParams
@@ -1854,7 +1461,7 @@ async function mergeIntentPayloads(basePayload, intentPayloadFactory) {
1854
1461
  }
1855
1462
 
1856
1463
  // src/intents/intent-relayer-impl/intent-relayer-public.ts
1857
- var import_internal_utils16 = require("@defuse-protocol/internal-utils");
1464
+ var import_internal_utils13 = require("@defuse-protocol/internal-utils");
1858
1465
  var IntentRelayerPublic = class {
1859
1466
  constructor({ env }) {
1860
1467
  this.env = env;
@@ -1876,13 +1483,13 @@ var IntentRelayerPublic = class {
1876
1483
  multiPayloads,
1877
1484
  quoteHashes
1878
1485
  }, ctx = {}) {
1879
- const a = await import_internal_utils16.solverRelay.publishIntents(
1486
+ const a = await import_internal_utils13.solverRelay.publishIntents(
1880
1487
  {
1881
1488
  quote_hashes: quoteHashes,
1882
1489
  signed_datas: multiPayloads
1883
1490
  },
1884
1491
  {
1885
- baseURL: import_internal_utils16.configsByEnvironment[this.env].solverRelayBaseURL,
1492
+ baseURL: import_internal_utils13.configsByEnvironment[this.env].solverRelayBaseURL,
1886
1493
  logger: ctx.logger
1887
1494
  }
1888
1495
  );
@@ -1892,10 +1499,10 @@ var IntentRelayerPublic = class {
1892
1499
  throw a.unwrapErr();
1893
1500
  }
1894
1501
  async waitForSettlement(ticket, ctx = {}) {
1895
- const result = await import_internal_utils16.solverRelay.waitForIntentSettlement({
1502
+ const result = await import_internal_utils13.solverRelay.waitForIntentSettlement({
1896
1503
  intentHash: ticket,
1897
1504
  signal: new AbortController().signal,
1898
- baseURL: import_internal_utils16.configsByEnvironment[this.env].solverRelayBaseURL,
1505
+ baseURL: import_internal_utils13.configsByEnvironment[this.env].solverRelayBaseURL,
1899
1506
  logger: ctx.logger
1900
1507
  });
1901
1508
  return {
@@ -1903,7 +1510,7 @@ var IntentRelayerPublic = class {
1903
1510
  hash: result.txHash,
1904
1511
  // Usually relayer's account id is the verifying contract (`intents.near`),
1905
1512
  // but it is not set in stone and may change in the future.
1906
- accountId: import_internal_utils16.configsByEnvironment[this.env].contractID
1513
+ accountId: import_internal_utils13.configsByEnvironment[this.env].contractID
1907
1514
  }
1908
1515
  };
1909
1516
  }
@@ -1917,14 +1524,14 @@ var noopIntentSigner = {
1917
1524
  };
1918
1525
 
1919
1526
  // src/lib/array.ts
1920
- var import_internal_utils17 = require("@defuse-protocol/internal-utils");
1527
+ var import_internal_utils14 = require("@defuse-protocol/internal-utils");
1921
1528
  function zip(arr1, arr2) {
1922
- (0, import_internal_utils17.assert)(arr1.length === arr2.length, "Arrays must have the same length");
1529
+ (0, import_internal_utils14.assert)(arr1.length === arr2.length, "Arrays must have the same length");
1923
1530
  return arr1.map((v, i) => [v, arr2[i]]);
1924
1531
  }
1925
1532
 
1926
1533
  // src/lib/configure-rpc-config.ts
1927
- var import_internal_utils18 = require("@defuse-protocol/internal-utils");
1534
+ var import_internal_utils15 = require("@defuse-protocol/internal-utils");
1928
1535
 
1929
1536
  // src/lib/object.ts
1930
1537
  function pick(obj, keys) {
@@ -1948,7 +1555,7 @@ function configureEvmRpcUrls(defaultRpcUrls, userRpcUrls, supportedChains) {
1948
1555
  ).map(([caip2, urls]) => [getEIP155ChainId(caip2), urls])
1949
1556
  );
1950
1557
  for (const [chainId, urls] of Object.entries(evmRpcUrls)) {
1951
- (0, import_internal_utils18.assert)(
1558
+ (0, import_internal_utils15.assert)(
1952
1559
  urls.length > 0,
1953
1560
  `EVM RPC URLs for chain ${chainId} are not provided`
1954
1561
  );
@@ -1962,7 +1569,7 @@ function configureStellarRpcUrls(defaultRpcUrls, userRpcUrls) {
1962
1569
  userRpcUrls?.[Chains.Stellar] ?? {}
1963
1570
  );
1964
1571
  for (const [key, value] of Object.entries(stellarRpcUrls)) {
1965
- (0, import_internal_utils18.assert)(value.length > 0, `Stellar RPC URL for ${key} is not provided`);
1572
+ (0, import_internal_utils15.assert)(value.length > 0, `Stellar RPC URL for ${key} is not provided`);
1966
1573
  }
1967
1574
  return stellarRpcUrls;
1968
1575
  }
@@ -2032,9 +1639,9 @@ var IntentsSDK = class {
2032
1639
  constructor(args) {
2033
1640
  this.env = args.env ?? "production";
2034
1641
  this.referral = args.referral;
2035
- const nearRpcUrls = args.rpc?.[Chains.Near] ?? import_internal_utils19.PUBLIC_NEAR_RPC_URLS;
2036
- (0, import_internal_utils19.assert)(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
2037
- const nearProvider = (0, import_internal_utils19.nearFailoverRpcProvider)({ urls: nearRpcUrls });
1642
+ const nearRpcUrls = args.rpc?.[Chains.Near] ?? import_internal_utils16.PUBLIC_NEAR_RPC_URLS;
1643
+ (0, import_internal_utils16.assert)(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
1644
+ const nearProvider = (0, import_internal_utils16.nearFailoverRpcProvider)({ urls: nearRpcUrls });
2038
1645
  const stellarRpcUrls = configureStellarRpcUrls(
2039
1646
  PUBLIC_STELLAR_RPC_URLS,
2040
1647
  args.rpc
@@ -2066,10 +1673,10 @@ var IntentsSDK = class {
2066
1673
  }
2067
1674
  })
2068
1675
  }),
2069
- new OmniBridge({
2070
- env: this.env,
2071
- nearProvider
2072
- }),
1676
+ // new OmniBridge({
1677
+ // env: this.env,
1678
+ // nearProvider,
1679
+ // }),
2073
1680
  new DirectBridge({
2074
1681
  env: this.env,
2075
1682
  nearProvider
@@ -2160,7 +1767,7 @@ var IntentsSDK = class {
2160
1767
  const routeConfig = determineRouteConfig(this, w);
2161
1768
  const route = routeConfig.route;
2162
1769
  const index = indexes.get(route);
2163
- (0, import_internal_utils19.assert)(index != null, "Index is not found for route");
1770
+ (0, import_internal_utils16.assert)(index != null, "Index is not found for route");
2164
1771
  indexes.set(route, index + 1);
2165
1772
  return {
2166
1773
  routeConfig,
@@ -2194,7 +1801,7 @@ var IntentsSDK = class {
2194
1801
  if (Array.isArray(args.withdrawalParams)) {
2195
1802
  return result;
2196
1803
  }
2197
- (0, import_internal_utils19.assert)(result.length === 1, "Unexpected result length");
1804
+ (0, import_internal_utils16.assert)(result.length === 1, "Unexpected result length");
2198
1805
  return result[0];
2199
1806
  }
2200
1807
  parseAssetId(assetId) {
@@ -2208,7 +1815,7 @@ var IntentsSDK = class {
2208
1815
  }
2209
1816
  async signAndSendIntent(args) {
2210
1817
  const intentSigner = args.signer ?? this.intentSigner;
2211
- (0, import_internal_utils19.assert)(intentSigner != null, "Intent signer is not provided");
1818
+ (0, import_internal_utils16.assert)(intentSigner != null, "Intent signer is not provided");
2212
1819
  const intentExecuter = new IntentExecuter({
2213
1820
  env: this.env,
2214
1821
  logger: args.logger,
@@ -2277,12 +1884,12 @@ var IntentsSDK = class {
2277
1884
  intentHash,
2278
1885
  logger
2279
1886
  }) {
2280
- return import_internal_utils19.solverRelay.getStatus(
1887
+ return import_internal_utils16.solverRelay.getStatus(
2281
1888
  {
2282
1889
  intent_hash: intentHash
2283
1890
  },
2284
1891
  {
2285
- baseURL: import_internal_utils19.configsByEnvironment[this.env].solverRelayBaseURL,
1892
+ baseURL: import_internal_utils16.configsByEnvironment[this.env].solverRelayBaseURL,
2286
1893
  logger
2287
1894
  }
2288
1895
  );
@@ -2313,7 +1920,7 @@ var IntentsSDK = class {
2313
1920
  withdrawalParams,
2314
1921
  intentTx,
2315
1922
  logger: args.logger,
2316
- retryOptions: import_internal_utils19.RETRY_CONFIGS.FIVE_MINS_STEADY
1923
+ retryOptions: import_internal_utils16.RETRY_CONFIGS.FIVE_MINS_STEADY
2317
1924
  });
2318
1925
  if (!Array.isArray(args.withdrawalParams)) {
2319
1926
  return {
@@ -2392,14 +1999,14 @@ var IntentSignerNearKeypair = class extends IntentSignerNEP413 {
2392
1999
  };
2393
2000
 
2394
2001
  // src/intents/intent-signer-impl/intent-signer-viem.ts
2395
- var import_internal_utils20 = require("@defuse-protocol/internal-utils");
2002
+ var import_internal_utils17 = require("@defuse-protocol/internal-utils");
2396
2003
  var IntentSignerViem = class {
2397
2004
  constructor(account) {
2398
2005
  this.account = account;
2399
2006
  }
2400
2007
  async signIntent(intent) {
2401
2008
  const payload = JSON.stringify({
2402
- signer_id: intent.signer_id ?? import_internal_utils20.utils.authHandleToIntentsUserId({
2009
+ signer_id: intent.signer_id ?? import_internal_utils17.utils.authHandleToIntentsUserId({
2403
2010
  identifier: this.account.address,
2404
2011
  method: "evm"
2405
2012
  }),
@@ -2417,7 +2024,7 @@ var IntentSignerViem = class {
2417
2024
  return {
2418
2025
  standard: "erc191",
2419
2026
  payload,
2420
- signature: import_internal_utils20.utils.transformERC191Signature(signature)
2027
+ signature: import_internal_utils17.utils.transformERC191Signature(signature)
2421
2028
  };
2422
2029
  }
2423
2030
  };
@@ -2434,11 +2041,59 @@ function createIntentSignerViem(config) {
2434
2041
  }
2435
2042
 
2436
2043
  // index.ts
2044
+ var import_internal_utils19 = require("@defuse-protocol/internal-utils");
2045
+
2046
+ // src/bridges/omni-bridge/error.ts
2047
+ var import_internal_utils18 = require("@defuse-protocol/internal-utils");
2048
+ var OmniTransferNotFoundError = class extends import_internal_utils18.BaseError {
2049
+ constructor(txHash) {
2050
+ super("Omni transfer with given hash is not found in the relayer.", {
2051
+ metaMessages: [`OriginTxHash: ${txHash}`],
2052
+ name: "OmniTransferNotFoundError"
2053
+ });
2054
+ this.txHash = txHash;
2055
+ }
2056
+ };
2057
+ var OmniTransferDestinationChainHashNotFoundError = class extends import_internal_utils18.BaseError {
2058
+ constructor(txHash, destinationChain) {
2059
+ super("Relayer did not return destination chain hash for a transfer.", {
2060
+ metaMessages: [
2061
+ `OriginTxHash: ${txHash}`,
2062
+ `DestinationChain: ${destinationChain}`
2063
+ ],
2064
+ name: "OmniTransferDestinationChainHashNotFoundError"
2065
+ });
2066
+ this.txHash = txHash;
2067
+ this.destinationChain = destinationChain;
2068
+ }
2069
+ };
2070
+ var TokenNotSupportedByOmniRelayerError = class extends import_internal_utils18.BaseError {
2071
+ constructor(token) {
2072
+ super(`Omni Relayer doesn't accept fee in the transferred token ${token}`, {
2073
+ metaMessages: [`Token: ${token}`],
2074
+ name: "TokenNotSupportedByOmniRelayerError"
2075
+ });
2076
+ this.token = token;
2077
+ }
2078
+ };
2079
+ var TokenNotFoundInDestinationChainError = class extends import_internal_utils18.BaseError {
2080
+ constructor(token, chainKind) {
2081
+ super(
2082
+ `The token ${token} doesn't exist in destination network ${chainKind}`,
2083
+ {
2084
+ metaMessages: [`Token: ${token}`, `Destination Chain: ${chainKind}`],
2085
+ name: "TokenNotFoundInDestinationChainError"
2086
+ }
2087
+ );
2088
+ this.token = token;
2089
+ }
2090
+ };
2091
+
2092
+ // index.ts
2093
+ var import_internal_utils20 = require("@defuse-protocol/internal-utils");
2437
2094
  var import_internal_utils21 = require("@defuse-protocol/internal-utils");
2438
2095
  var import_internal_utils22 = require("@defuse-protocol/internal-utils");
2439
2096
  var import_internal_utils23 = require("@defuse-protocol/internal-utils");
2440
- var import_internal_utils24 = require("@defuse-protocol/internal-utils");
2441
- var import_internal_utils25 = require("@defuse-protocol/internal-utils");
2442
2097
  // Annotate the CommonJS export names for ESM import in node:
2443
2098
  0 && (module.exports = {
2444
2099
  AssertionError,