@defuse-protocol/intents-sdk 0.15.0 → 0.16.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.
package/dist/index.cjs CHANGED
@@ -751,7 +751,7 @@ var HotBridge = class {
751
751
  }
752
752
  if (typeof status === "string") {
753
753
  return {
754
- hash: "chain" in args.routeConfig ? formatTxHash(status, args.routeConfig.chain) : status
754
+ hash: "chain" in args.routeConfig && args.routeConfig.chain !== void 0 ? formatTxHash(status, args.routeConfig.chain) : status
755
755
  };
756
756
  }
757
757
  throw new HotWithdrawalPendingError(args.tx.hash, args.index);
@@ -850,6 +850,18 @@ var TokenNotSupportedByOmniRelayerError = class extends import_internal_utils10.
850
850
  this.token = token;
851
851
  }
852
852
  };
853
+ var TokenNotFoundInDestinationChainError = class extends import_internal_utils10.BaseError {
854
+ constructor(token, chainKind) {
855
+ super(
856
+ `The token ${token} doesn't exist in destination network ${chainKind}`,
857
+ {
858
+ metaMessages: [`Token: ${token}`, `Destination Chain: ${chainKind}`],
859
+ name: "TokenNotFoundInDestinationChainError"
860
+ }
861
+ );
862
+ this.token = token;
863
+ }
864
+ };
853
865
 
854
866
  // src/bridges/omni-bridge/omni-bridge-constants.ts
855
867
  var NEAR_NATIVE_ASSET_ID3 = "nep141:wrap.near";
@@ -879,6 +891,22 @@ function createWithdrawIntentPrimitive3(params) {
879
891
  })
880
892
  };
881
893
  }
894
+ function targetChainSupportedByOmniBridge(network) {
895
+ switch (network) {
896
+ case Chains.Ethereum:
897
+ return true;
898
+ case Chains.Base:
899
+ return true;
900
+ case Chains.Arbitrum:
901
+ return true;
902
+ case Chains.Solana:
903
+ return true;
904
+ case Chains.Bitcoin:
905
+ return true;
906
+ default:
907
+ return false;
908
+ }
909
+ }
882
910
  function caip2ToChainKind(network) {
883
911
  switch (network) {
884
912
  case Chains.Ethereum:
@@ -922,6 +950,8 @@ var _OmniBridge = class _OmniBridge {
922
950
  this.storageDepositCache = new import_ttlcache.default({ ttl: 864e5 });
923
951
  // TTL cache for supported tokens with 30-second TTL
924
952
  this.supportedTokensCache = new import_ttlcache.default({ ttl: 864e5 });
953
+ // 86400000 - 1 day
954
+ this.destinationChainAddressCache = new import_ttlcache.default({ ttl: 864e5 });
925
955
  this.env = env;
926
956
  this.nearProvider = nearProvider;
927
957
  this.omniBridgeAPI = new import_omni_bridge_sdk2.OmniBridgeAPI();
@@ -931,11 +961,19 @@ var _OmniBridge = class _OmniBridge {
931
961
  }
932
962
  supports(params) {
933
963
  try {
964
+ if (this.targetChainSpecified(params.routeConfig)) {
965
+ return targetChainSupportedByOmniBridge(params.routeConfig.chain);
966
+ }
934
967
  return this.parseAssetId(params.assetId) !== null;
935
968
  } catch {
936
969
  return false;
937
970
  }
938
971
  }
972
+ targetChainSpecified(routeConfig) {
973
+ return Boolean(
974
+ routeConfig?.route && routeConfig.route === RouteEnum.OmniBridge && routeConfig.chain
975
+ );
976
+ }
939
977
  parseAssetId(assetId) {
940
978
  const parsed = import_internal_utils12.utils.parseDefuseAssetId(assetId);
941
979
  if (parsed.standard !== "nep141") return null;
@@ -947,8 +985,39 @@ var _OmniBridge = class _OmniBridge {
947
985
  address: parsed.contractId
948
986
  });
949
987
  }
950
- createWithdrawalIntents(args) {
951
- const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
988
+ async tokenSupported(assetId, routeConfig) {
989
+ const parsed = import_internal_utils12.utils.parseDefuseAssetId(assetId);
990
+ if (parsed.standard !== "nep141") return null;
991
+ if (this.targetChainSpecified(routeConfig)) {
992
+ const tokenOnDestinationNetwork = await this.getCachedDestinationTokenAddress(
993
+ parsed.contractId,
994
+ routeConfig.chain
995
+ );
996
+ if (tokenOnDestinationNetwork === null) {
997
+ throw new TokenNotFoundInDestinationChainError(
998
+ assetId,
999
+ routeConfig.chain
1000
+ );
1001
+ }
1002
+ return Object.assign(parsed, {
1003
+ blockchain: routeConfig.chain,
1004
+ bridgeName: BridgeNameEnum.Omni,
1005
+ address: parsed.contractId
1006
+ });
1007
+ }
1008
+ const chain = (0, import_omni_bridge_sdk2.parseOriginChain)(parsed.contractId);
1009
+ if (chain === null) return null;
1010
+ return Object.assign(parsed, {
1011
+ blockchain: chainKindToCaip2(chain),
1012
+ bridgeName: BridgeNameEnum.Omni,
1013
+ address: parsed.contractId
1014
+ });
1015
+ }
1016
+ async createWithdrawalIntents(args) {
1017
+ const assetInfo = await this.tokenSupported(
1018
+ args.withdrawalParams.assetId,
1019
+ args.withdrawalParams.routeConfig
1020
+ );
952
1021
  (0, import_internal_utils12.assert)(
953
1022
  assetInfo !== null,
954
1023
  `Asset ${args.withdrawalParams.assetId} is not supported`
@@ -976,7 +1045,7 @@ var _OmniBridge = class _OmniBridge {
976
1045
  return Promise.resolve(intents);
977
1046
  }
978
1047
  async validateWithdrawal(args) {
979
- const assetInfo = this.parseAssetId(args.assetId);
1048
+ const assetInfo = await this.tokenSupported(args.assetId, args.routeConfig);
980
1049
  (0, import_internal_utils12.assert)(assetInfo !== null, `Asset ${args.assetId} is not supported`);
981
1050
  const supportedTokens = await this.getCachedSupportedTokens();
982
1051
  if (!supportedTokens[assetInfo.contractId]) {
@@ -989,7 +1058,10 @@ var _OmniBridge = class _OmniBridge {
989
1058
  return;
990
1059
  }
991
1060
  async estimateWithdrawalFee(args) {
992
- const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
1061
+ const assetInfo = await this.tokenSupported(
1062
+ args.withdrawalParams.assetId,
1063
+ args.withdrawalParams.routeConfig
1064
+ );
993
1065
  (0, import_internal_utils12.assert)(
994
1066
  assetInfo !== null,
995
1067
  `Asset ${args.withdrawalParams.assetId} is not supported`
@@ -1110,6 +1182,23 @@ var _OmniBridge = class _OmniBridge {
1110
1182
  this.supportedTokensCache.set(_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY, data);
1111
1183
  return data;
1112
1184
  }
1185
+ /**
1186
+ * Gets cached token address on destination chain.
1187
+ * Cache expires after one day using TTL cache.
1188
+ */
1189
+ async getCachedDestinationTokenAddress(contractId, chain) {
1190
+ const key = `${chain}:${contractId}`;
1191
+ const cached = this.destinationChainAddressCache.get(key);
1192
+ if (cached != null) {
1193
+ return cached;
1194
+ }
1195
+ const tokenOnDestinationNetwork = await (0, import_omni_bridge_sdk2.getBridgedToken)(
1196
+ (0, import_omni_bridge_sdk2.omniAddress)(import_omni_bridge_sdk2.ChainKind.Near, contractId),
1197
+ caip2ToChainKind(chain)
1198
+ );
1199
+ this.destinationChainAddressCache.set(key, tokenOnDestinationNetwork);
1200
+ return tokenOnDestinationNetwork;
1201
+ }
1113
1202
  };
1114
1203
  // 86400000 - 1 day
1115
1204
  _OmniBridge.SUPPORTED_TOKENS_CACHE_KEY = "SUPPORTED_TOKENS_CACHE_KEY";
@@ -1996,6 +2085,7 @@ var IntentsSDK = class {
1996
2085
  amount: actualAmount,
1997
2086
  destinationAddress: args.withdrawalParams.destinationAddress,
1998
2087
  feeEstimation: args.feeEstimation,
2088
+ routeConfig: args.withdrawalParams.routeConfig,
1999
2089
  logger: args.logger
2000
2090
  });
2001
2091
  return bridge.createWithdrawalIntents({
package/dist/index.d.cts CHANGED
@@ -229,6 +229,7 @@ type HotBridgeRouteConfig = {
229
229
  };
230
230
  type OmniBridgeRouteConfig = {
231
231
  route: RouteEnum["OmniBridge"];
232
+ chain?: Chain;
232
233
  };
233
234
  type RouteConfig = NearWithdrawalRouteConfig | InternalTransferRouteConfig | VirtualChainRouteConfig | PoaBridgeRouteConfig | HotBridgeRouteConfig | OmniBridgeRouteConfig;
234
235
  interface FeeEstimation {
@@ -252,6 +253,7 @@ interface Bridge {
252
253
  amount: bigint;
253
254
  destinationAddress: string;
254
255
  feeEstimation: FeeEstimation;
256
+ routeConfig?: RouteConfig;
255
257
  logger?: ILogger;
256
258
  }): Promise<void>;
257
259
  estimateWithdrawalFee<T extends Pick<WithdrawalParams, "assetId" | "destinationAddress" | "routeConfig">>(args: {
package/dist/index.d.ts CHANGED
@@ -229,6 +229,7 @@ type HotBridgeRouteConfig = {
229
229
  };
230
230
  type OmniBridgeRouteConfig = {
231
231
  route: RouteEnum["OmniBridge"];
232
+ chain?: Chain;
232
233
  };
233
234
  type RouteConfig = NearWithdrawalRouteConfig | InternalTransferRouteConfig | VirtualChainRouteConfig | PoaBridgeRouteConfig | HotBridgeRouteConfig | OmniBridgeRouteConfig;
234
235
  interface FeeEstimation {
@@ -252,6 +253,7 @@ interface Bridge {
252
253
  amount: bigint;
253
254
  destinationAddress: string;
254
255
  feeEstimation: FeeEstimation;
256
+ routeConfig?: RouteConfig;
255
257
  logger?: ILogger;
256
258
  }): Promise<void>;
257
259
  estimateWithdrawalFee<T extends Pick<WithdrawalParams, "assetId" | "destinationAddress" | "routeConfig">>(args: {
package/dist/index.js CHANGED
@@ -712,7 +712,7 @@ var HotBridge = class {
712
712
  }
713
713
  if (typeof status === "string") {
714
714
  return {
715
- hash: "chain" in args.routeConfig ? formatTxHash(status, args.routeConfig.chain) : status
715
+ hash: "chain" in args.routeConfig && args.routeConfig.chain !== void 0 ? formatTxHash(status, args.routeConfig.chain) : status
716
716
  };
717
717
  }
718
718
  throw new HotWithdrawalPendingError(args.tx.hash, args.index);
@@ -787,6 +787,7 @@ import { retry as retry2 } from "@lifeomic/attempt";
787
787
  import {
788
788
  ChainKind as ChainKind2,
789
789
  OmniBridgeAPI,
790
+ getBridgedToken,
790
791
  getChain,
791
792
  isEvmChain,
792
793
  omniAddress as omniAddress2,
@@ -826,6 +827,18 @@ var TokenNotSupportedByOmniRelayerError = class extends BaseError3 {
826
827
  this.token = token;
827
828
  }
828
829
  };
830
+ var TokenNotFoundInDestinationChainError = class extends BaseError3 {
831
+ constructor(token, chainKind) {
832
+ super(
833
+ `The token ${token} doesn't exist in destination network ${chainKind}`,
834
+ {
835
+ metaMessages: [`Token: ${token}`, `Destination Chain: ${chainKind}`],
836
+ name: "TokenNotFoundInDestinationChainError"
837
+ }
838
+ );
839
+ this.token = token;
840
+ }
841
+ };
829
842
 
830
843
  // src/bridges/omni-bridge/omni-bridge-constants.ts
831
844
  var NEAR_NATIVE_ASSET_ID3 = "nep141:wrap.near";
@@ -855,6 +868,22 @@ function createWithdrawIntentPrimitive3(params) {
855
868
  })
856
869
  };
857
870
  }
871
+ function targetChainSupportedByOmniBridge(network) {
872
+ switch (network) {
873
+ case Chains.Ethereum:
874
+ return true;
875
+ case Chains.Base:
876
+ return true;
877
+ case Chains.Arbitrum:
878
+ return true;
879
+ case Chains.Solana:
880
+ return true;
881
+ case Chains.Bitcoin:
882
+ return true;
883
+ default:
884
+ return false;
885
+ }
886
+ }
858
887
  function caip2ToChainKind(network) {
859
888
  switch (network) {
860
889
  case Chains.Ethereum:
@@ -898,6 +927,8 @@ var _OmniBridge = class _OmniBridge {
898
927
  this.storageDepositCache = new TTLCache({ ttl: 864e5 });
899
928
  // TTL cache for supported tokens with 30-second TTL
900
929
  this.supportedTokensCache = new TTLCache({ ttl: 864e5 });
930
+ // 86400000 - 1 day
931
+ this.destinationChainAddressCache = new TTLCache({ ttl: 864e5 });
901
932
  this.env = env;
902
933
  this.nearProvider = nearProvider;
903
934
  this.omniBridgeAPI = new OmniBridgeAPI();
@@ -907,11 +938,19 @@ var _OmniBridge = class _OmniBridge {
907
938
  }
908
939
  supports(params) {
909
940
  try {
941
+ if (this.targetChainSpecified(params.routeConfig)) {
942
+ return targetChainSupportedByOmniBridge(params.routeConfig.chain);
943
+ }
910
944
  return this.parseAssetId(params.assetId) !== null;
911
945
  } catch {
912
946
  return false;
913
947
  }
914
948
  }
949
+ targetChainSpecified(routeConfig) {
950
+ return Boolean(
951
+ routeConfig?.route && routeConfig.route === RouteEnum.OmniBridge && routeConfig.chain
952
+ );
953
+ }
915
954
  parseAssetId(assetId) {
916
955
  const parsed = utils7.parseDefuseAssetId(assetId);
917
956
  if (parsed.standard !== "nep141") return null;
@@ -923,8 +962,39 @@ var _OmniBridge = class _OmniBridge {
923
962
  address: parsed.contractId
924
963
  });
925
964
  }
926
- createWithdrawalIntents(args) {
927
- const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
965
+ async tokenSupported(assetId, routeConfig) {
966
+ const parsed = utils7.parseDefuseAssetId(assetId);
967
+ if (parsed.standard !== "nep141") return null;
968
+ if (this.targetChainSpecified(routeConfig)) {
969
+ const tokenOnDestinationNetwork = await this.getCachedDestinationTokenAddress(
970
+ parsed.contractId,
971
+ routeConfig.chain
972
+ );
973
+ if (tokenOnDestinationNetwork === null) {
974
+ throw new TokenNotFoundInDestinationChainError(
975
+ assetId,
976
+ routeConfig.chain
977
+ );
978
+ }
979
+ return Object.assign(parsed, {
980
+ blockchain: routeConfig.chain,
981
+ bridgeName: BridgeNameEnum.Omni,
982
+ address: parsed.contractId
983
+ });
984
+ }
985
+ const chain = 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 createWithdrawalIntents(args) {
994
+ const assetInfo = await this.tokenSupported(
995
+ args.withdrawalParams.assetId,
996
+ args.withdrawalParams.routeConfig
997
+ );
928
998
  assert9(
929
999
  assetInfo !== null,
930
1000
  `Asset ${args.withdrawalParams.assetId} is not supported`
@@ -952,7 +1022,7 @@ var _OmniBridge = class _OmniBridge {
952
1022
  return Promise.resolve(intents);
953
1023
  }
954
1024
  async validateWithdrawal(args) {
955
- const assetInfo = this.parseAssetId(args.assetId);
1025
+ const assetInfo = await this.tokenSupported(args.assetId, args.routeConfig);
956
1026
  assert9(assetInfo !== null, `Asset ${args.assetId} is not supported`);
957
1027
  const supportedTokens = await this.getCachedSupportedTokens();
958
1028
  if (!supportedTokens[assetInfo.contractId]) {
@@ -965,7 +1035,10 @@ var _OmniBridge = class _OmniBridge {
965
1035
  return;
966
1036
  }
967
1037
  async estimateWithdrawalFee(args) {
968
- const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
1038
+ const assetInfo = await this.tokenSupported(
1039
+ args.withdrawalParams.assetId,
1040
+ args.withdrawalParams.routeConfig
1041
+ );
969
1042
  assert9(
970
1043
  assetInfo !== null,
971
1044
  `Asset ${args.withdrawalParams.assetId} is not supported`
@@ -1086,6 +1159,23 @@ var _OmniBridge = class _OmniBridge {
1086
1159
  this.supportedTokensCache.set(_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY, data);
1087
1160
  return data;
1088
1161
  }
1162
+ /**
1163
+ * Gets cached token address on destination chain.
1164
+ * Cache expires after one day using TTL cache.
1165
+ */
1166
+ async getCachedDestinationTokenAddress(contractId, chain) {
1167
+ const key = `${chain}:${contractId}`;
1168
+ const cached = this.destinationChainAddressCache.get(key);
1169
+ if (cached != null) {
1170
+ return cached;
1171
+ }
1172
+ const tokenOnDestinationNetwork = await getBridgedToken(
1173
+ omniAddress2(ChainKind2.Near, contractId),
1174
+ caip2ToChainKind(chain)
1175
+ );
1176
+ this.destinationChainAddressCache.set(key, tokenOnDestinationNetwork);
1177
+ return tokenOnDestinationNetwork;
1178
+ }
1089
1179
  };
1090
1180
  // 86400000 - 1 day
1091
1181
  _OmniBridge.SUPPORTED_TOKENS_CACHE_KEY = "SUPPORTED_TOKENS_CACHE_KEY";
@@ -1982,6 +2072,7 @@ var IntentsSDK = class {
1982
2072
  amount: actualAmount,
1983
2073
  destinationAddress: args.withdrawalParams.destinationAddress,
1984
2074
  feeEstimation: args.feeEstimation,
2075
+ routeConfig: args.withdrawalParams.routeConfig,
1985
2076
  logger: args.logger
1986
2077
  });
1987
2078
  return bridge.createWithdrawalIntents({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defuse-protocol/intents-sdk",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,