@defuse-protocol/intents-sdk 0.18.0 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  // src/sdk.ts
2
2
  import {
3
- assert as assert11,
3
+ assert as assert13,
4
4
  PUBLIC_NEAR_RPC_URLS,
5
- RETRY_CONFIGS as RETRY_CONFIGS2,
6
- configsByEnvironment as configsByEnvironment6,
5
+ RETRY_CONFIGS as RETRY_CONFIGS3,
6
+ configsByEnvironment as configsByEnvironment7,
7
7
  nearFailoverRpcProvider,
8
- solverRelay as solverRelay3
8
+ solverRelay as solverRelay4
9
9
  } from "@defuse-protocol/internal-utils";
10
10
  import hotOmniSdk from "@hot-labs/omni-sdk";
11
11
  import { stringify } from "viem";
@@ -910,19 +910,452 @@ var IntentsBridge = class {
910
910
  }
911
911
  };
912
912
 
913
- // src/bridges/poa-bridge/poa-bridge.ts
913
+ // src/bridges/omni-bridge/omni-bridge.ts
914
914
  import {
915
- assert as assert8,
915
+ assert as assert9,
916
+ RETRY_CONFIGS as RETRY_CONFIGS2,
916
917
  configsByEnvironment as configsByEnvironment3,
917
- poaBridge,
918
- utils as utils8
918
+ getNearNep141MinStorageBalance as getNearNep141MinStorageBalance3,
919
+ getNearNep141StorageBalance as getNearNep141StorageBalance3,
920
+ solverRelay as solverRelay2
919
921
  } from "@defuse-protocol/internal-utils";
920
922
  import TTLCache from "@isaacs/ttlcache";
923
+ import { retry as retry2 } from "@lifeomic/attempt";
924
+ import {
925
+ ChainKind as ChainKind2,
926
+ OmniBridgeAPI,
927
+ getBridgedToken,
928
+ getChain,
929
+ isEvmChain,
930
+ omniAddress as omniAddress2,
931
+ parseOriginChain
932
+ } from "omni-bridge-sdk";
921
933
 
922
- // src/bridges/poa-bridge/poa-bridge-utils.ts
923
- import { utils as utils7 } from "@defuse-protocol/internal-utils";
934
+ // src/bridges/omni-bridge/error.ts
935
+ import { BaseError as BaseError3 } from "@defuse-protocol/internal-utils";
936
+ var OmniTransferNotFoundError = class extends BaseError3 {
937
+ constructor(txHash) {
938
+ super("Omni transfer with given hash is not found in the relayer.", {
939
+ metaMessages: [`OriginTxHash: ${txHash}`],
940
+ name: "OmniTransferNotFoundError"
941
+ });
942
+ this.txHash = txHash;
943
+ }
944
+ };
945
+ var OmniTransferDestinationChainHashNotFoundError = class extends BaseError3 {
946
+ constructor(txHash, destinationChain) {
947
+ super("Relayer did not return destination chain hash for a transfer.", {
948
+ metaMessages: [
949
+ `OriginTxHash: ${txHash}`,
950
+ `DestinationChain: ${destinationChain}`
951
+ ],
952
+ name: "OmniTransferDestinationChainHashNotFoundError"
953
+ });
954
+ this.txHash = txHash;
955
+ this.destinationChain = destinationChain;
956
+ }
957
+ };
958
+ var TokenNotFoundInDestinationChainError = class extends BaseError3 {
959
+ constructor(token, destinationChain) {
960
+ super(
961
+ `The token ${token} doesn't exist in destination chain ${destinationChain}`,
962
+ {
963
+ metaMessages: [
964
+ `Token: ${token}`,
965
+ `Destination Chain: ${destinationChain}`
966
+ ],
967
+ name: "TokenNotFoundInDestinationChainError"
968
+ }
969
+ );
970
+ this.token = token;
971
+ this.destinationChain = destinationChain;
972
+ }
973
+ };
974
+ var TokenNotSupportedByOmniRelayerError = class extends BaseError3 {
975
+ constructor(token) {
976
+ super(`Omni Relayer doesn't accept fee in the transferred token ${token}`, {
977
+ metaMessages: [`Token: ${token}`],
978
+ name: "TokenNotSupportedByOmniRelayerError"
979
+ });
980
+ this.token = token;
981
+ }
982
+ };
983
+
984
+ // src/bridges/omni-bridge/omni-bridge-constants.ts
985
+ var NEAR_NATIVE_ASSET_ID3 = "nep141:wrap.near";
986
+ var OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
987
+
988
+ // src/bridges/omni-bridge/omni-bridge-utils.ts
989
+ import { assert as assert8, utils as utils7 } from "@defuse-protocol/internal-utils";
990
+ import { ChainKind, omniAddress } from "omni-bridge-sdk";
924
991
  function createWithdrawIntentPrimitive3(params) {
925
- const { contractId: tokenAccountId } = utils7.parseDefuseAssetId(
992
+ const { contractId: tokenAccountId, standard } = utils7.parseDefuseAssetId(
993
+ params.assetId
994
+ );
995
+ assert8(standard === "nep141", "Only NEP-141 is supported");
996
+ return {
997
+ intent: "ft_withdraw",
998
+ token: tokenAccountId,
999
+ receiver_id: OMNI_BRIDGE_CONTRACT,
1000
+ amount: params.amount.toString(),
1001
+ storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : null,
1002
+ msg: JSON.stringify({
1003
+ recipient: omniAddress(params.omniChainKind, params.destinationAddress),
1004
+ fee: params.transferredTokenFee.toString(),
1005
+ native_token_fee: "0"
1006
+ })
1007
+ };
1008
+ }
1009
+ function caip2ToChainKind(network) {
1010
+ switch (network) {
1011
+ case Chains.Ethereum:
1012
+ return ChainKind.Eth;
1013
+ case Chains.Base:
1014
+ return ChainKind.Base;
1015
+ case Chains.Arbitrum:
1016
+ return ChainKind.Arb;
1017
+ case Chains.Solana:
1018
+ return ChainKind.Sol;
1019
+ // case Chains.Bitcoin:
1020
+ // return ChainKind.Btc;
1021
+ default:
1022
+ return null;
1023
+ }
1024
+ }
1025
+ function chainKindToCaip2(network) {
1026
+ switch (network) {
1027
+ case ChainKind.Eth:
1028
+ return Chains.Ethereum;
1029
+ case ChainKind.Base:
1030
+ return Chains.Base;
1031
+ case ChainKind.Arb:
1032
+ return Chains.Arbitrum;
1033
+ case ChainKind.Sol:
1034
+ return Chains.Solana;
1035
+ // case ChainKind.Btc:
1036
+ // return Chains.Bitcoin;
1037
+ default:
1038
+ return null;
1039
+ }
1040
+ }
1041
+ var CHAIN_PATTERNS = {
1042
+ "nbtc.bridge.near": ChainKind.Btc,
1043
+ "eth.bridge.near": ChainKind.Eth,
1044
+ "sol.omdep.near": ChainKind.Sol,
1045
+ "base.omdep.near": ChainKind.Base,
1046
+ "arb.omdep.near": ChainKind.Arb
1047
+ };
1048
+ function validateOmniToken(nearAddress) {
1049
+ return nearAddress in CHAIN_PATTERNS || /\.(omdep\.near|factory\.bridge\.near)$/.test(nearAddress);
1050
+ }
1051
+
1052
+ // src/bridges/omni-bridge/omni-bridge.ts
1053
+ var OmniBridge = class {
1054
+ // 10800000 - 3 hours
1055
+ constructor({
1056
+ env,
1057
+ nearProvider
1058
+ }) {
1059
+ this.storageDepositCache = new TTLCache({ ttl: 108e5 });
1060
+ // 10800000 - 3 hours
1061
+ this.destinationChainAddressCache = new TTLCache({ ttl: 108e5 });
1062
+ this.env = env;
1063
+ this.nearProvider = nearProvider;
1064
+ this.omniBridgeAPI = new OmniBridgeAPI();
1065
+ }
1066
+ is(routeConfig) {
1067
+ return routeConfig.route === RouteEnum.OmniBridge;
1068
+ }
1069
+ async supports(params) {
1070
+ if (params.routeConfig && !this.is(params.routeConfig)) {
1071
+ return false;
1072
+ }
1073
+ const parsed = parseDefuseAssetId(params.assetId);
1074
+ const omniBridgeSetWithNoChain = Boolean(
1075
+ params.routeConfig && params.routeConfig.route === RouteEnum.OmniBridge && params.routeConfig.chain === void 0
1076
+ );
1077
+ const targetChainSpecified = this.targetChainSpecified(params.routeConfig);
1078
+ const nonValidStandard = parsed.standard !== "nep141";
1079
+ if (nonValidStandard && (omniBridgeSetWithNoChain || targetChainSpecified)) {
1080
+ throw new UnsupportedAssetIdError(
1081
+ params.assetId,
1082
+ `Only NEP-141 tokens are supported by Omni Bridge.`
1083
+ );
1084
+ }
1085
+ if (nonValidStandard) return false;
1086
+ const nonValidToken = validateOmniToken(parsed.contractId) === false;
1087
+ if (nonValidToken && omniBridgeSetWithNoChain) {
1088
+ throw new UnsupportedAssetIdError(
1089
+ params.assetId,
1090
+ `Non valid omni contract id ${parsed.contractId}`
1091
+ );
1092
+ }
1093
+ if (!targetChainSpecified && nonValidToken) return false;
1094
+ let omniChainKind = null;
1095
+ let caip2Chain = null;
1096
+ if (this.targetChainSpecified(params.routeConfig)) {
1097
+ omniChainKind = caip2ToChainKind(params.routeConfig.chain);
1098
+ if (omniChainKind === null) {
1099
+ throw new UnsupportedAssetIdError(
1100
+ params.assetId,
1101
+ `Chain ${params.routeConfig.chain} is not supported in Omni Bridge.`
1102
+ );
1103
+ }
1104
+ caip2Chain = params.routeConfig.chain;
1105
+ } else {
1106
+ omniChainKind = parseOriginChain(parsed.contractId);
1107
+ if (omniChainKind === null) {
1108
+ throw new UnsupportedAssetIdError(
1109
+ params.assetId,
1110
+ `Withdrawal of ${parsed.contractId} to its origin chain is not supported in Omni Bridge.`
1111
+ );
1112
+ }
1113
+ caip2Chain = chainKindToCaip2(omniChainKind);
1114
+ if (caip2Chain === null) {
1115
+ throw new UnsupportedAssetIdError(
1116
+ params.assetId,
1117
+ `Withdrawal of ${parsed.contractId} to its origin chain is not supported in Omni Bridge.`
1118
+ );
1119
+ }
1120
+ }
1121
+ const tokenOnDestinationNetwork = await this.getCachedDestinationTokenAddress(
1122
+ parsed.contractId,
1123
+ omniChainKind
1124
+ );
1125
+ if (tokenOnDestinationNetwork === null) {
1126
+ throw new TokenNotFoundInDestinationChainError(
1127
+ params.assetId,
1128
+ caip2Chain
1129
+ );
1130
+ }
1131
+ return true;
1132
+ }
1133
+ targetChainSpecified(routeConfig) {
1134
+ return Boolean(
1135
+ routeConfig?.route && routeConfig.route === RouteEnum.OmniBridge && routeConfig.chain
1136
+ );
1137
+ }
1138
+ parseAssetId(assetId) {
1139
+ const parsed = parseDefuseAssetId(assetId);
1140
+ if (parsed.standard !== "nep141") return null;
1141
+ const omniChainKind = parseOriginChain(parsed.contractId);
1142
+ if (omniChainKind === null) return null;
1143
+ const blockchain = chainKindToCaip2(omniChainKind);
1144
+ if (blockchain === null) return null;
1145
+ return Object.assign(parsed, {
1146
+ blockchain,
1147
+ bridgeName: BridgeNameEnum.Omni,
1148
+ address: parsed.contractId
1149
+ });
1150
+ }
1151
+ makeAssetInfo(assetId, routeConfig) {
1152
+ const parsed = parseDefuseAssetId(assetId);
1153
+ if (parsed.standard !== "nep141") return null;
1154
+ let omniChainKind = null;
1155
+ let blockchain = null;
1156
+ if (this.targetChainSpecified(routeConfig)) {
1157
+ omniChainKind = caip2ToChainKind(routeConfig.chain);
1158
+ blockchain = routeConfig.chain;
1159
+ } else {
1160
+ omniChainKind = parseOriginChain(parsed.contractId);
1161
+ if (omniChainKind === null) return null;
1162
+ blockchain = chainKindToCaip2(omniChainKind);
1163
+ }
1164
+ if (omniChainKind === null || blockchain === null) return null;
1165
+ return Object.assign(parsed, {
1166
+ blockchain,
1167
+ bridgeName: BridgeNameEnum.Omni,
1168
+ address: parsed.contractId
1169
+ });
1170
+ }
1171
+ async createWithdrawalIntents(args) {
1172
+ const assetInfo = this.makeAssetInfo(
1173
+ args.withdrawalParams.assetId,
1174
+ args.withdrawalParams.routeConfig
1175
+ );
1176
+ assert9(
1177
+ assetInfo !== null,
1178
+ `Asset ${args.withdrawalParams.assetId} is not supported by Omni Bridge`
1179
+ );
1180
+ const intents = [];
1181
+ if (args.feeEstimation.quote !== null) {
1182
+ intents.push({
1183
+ intent: "token_diff",
1184
+ diff: {
1185
+ [args.feeEstimation.quote.defuse_asset_identifier_in]: `-${args.feeEstimation.quote.amount_in}`,
1186
+ [args.feeEstimation.quote.defuse_asset_identifier_out]: args.feeEstimation.quote.amount_out
1187
+ },
1188
+ referral: args.referral
1189
+ });
1190
+ }
1191
+ const omniChainKind = caip2ToChainKind(assetInfo.blockchain);
1192
+ assert9(
1193
+ omniChainKind !== null,
1194
+ `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`
1195
+ );
1196
+ const intent = createWithdrawIntentPrimitive3({
1197
+ assetId: args.withdrawalParams.assetId,
1198
+ destinationAddress: args.withdrawalParams.destinationAddress,
1199
+ amount: args.withdrawalParams.amount + args.feeEstimation.amount,
1200
+ omniChainKind,
1201
+ storageDeposit: args.feeEstimation.quote ? BigInt(args.feeEstimation.quote.amount_out) : 0n,
1202
+ transferredTokenFee: args.feeEstimation.amount
1203
+ });
1204
+ intents.push(intent);
1205
+ return Promise.resolve(intents);
1206
+ }
1207
+ async validateWithdrawal(args) {
1208
+ assert9(
1209
+ args.feeEstimation.amount > 0n,
1210
+ `Fee must be greater than zero. Current fee is ${args.feeEstimation.amount}.`
1211
+ );
1212
+ return;
1213
+ }
1214
+ async estimateWithdrawalFee(args) {
1215
+ const assetInfo = this.makeAssetInfo(
1216
+ args.withdrawalParams.assetId,
1217
+ args.withdrawalParams.routeConfig
1218
+ );
1219
+ assert9(
1220
+ assetInfo !== null,
1221
+ `Asset ${args.withdrawalParams.assetId} is not supported by Omni Bridge`
1222
+ );
1223
+ const omniChainKind = caip2ToChainKind(assetInfo.blockchain);
1224
+ assert9(
1225
+ omniChainKind !== null,
1226
+ `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`
1227
+ );
1228
+ const fee = await this.omniBridgeAPI.getFee(
1229
+ omniAddress2(ChainKind2.Near, configsByEnvironment3[this.env].contractID),
1230
+ omniAddress2(omniChainKind, args.withdrawalParams.destinationAddress),
1231
+ omniAddress2(ChainKind2.Near, assetInfo.contractId)
1232
+ );
1233
+ if (fee.transferred_token_fee === null) {
1234
+ throw new TokenNotSupportedByOmniRelayerError(
1235
+ args.withdrawalParams.assetId
1236
+ );
1237
+ }
1238
+ const [minStorageBalance, userStorageBalance] = await this.getCachedStorageDepositValue(assetInfo.contractId);
1239
+ if (minStorageBalance <= userStorageBalance) {
1240
+ return {
1241
+ amount: BigInt(fee.transferred_token_fee),
1242
+ quote: null
1243
+ };
1244
+ }
1245
+ const feeAmount = minStorageBalance - userStorageBalance;
1246
+ const feeQuote = await solverRelay2.getQuote({
1247
+ quoteParams: {
1248
+ defuse_asset_identifier_in: args.withdrawalParams.assetId,
1249
+ defuse_asset_identifier_out: NEAR_NATIVE_ASSET_ID3,
1250
+ exact_amount_out: feeAmount.toString(),
1251
+ wait_ms: args.quoteOptions?.waitMs
1252
+ },
1253
+ config: {
1254
+ baseURL: configsByEnvironment3[this.env].solverRelayBaseURL,
1255
+ logBalanceSufficient: false,
1256
+ logger: args.logger
1257
+ }
1258
+ });
1259
+ return {
1260
+ amount: BigInt(fee.transferred_token_fee) + BigInt(feeQuote.amount_in),
1261
+ quote: feeQuote
1262
+ };
1263
+ }
1264
+ async waitForWithdrawalCompletion(args) {
1265
+ return retry2(
1266
+ async () => {
1267
+ if (args.signal?.aborted) {
1268
+ throw args.signal.reason;
1269
+ }
1270
+ const transfer = (await this.omniBridgeAPI.findOmniTransfers({
1271
+ transaction_id: args.tx.hash,
1272
+ offset: args.index,
1273
+ limit: 1
1274
+ }))[0];
1275
+ if (!transfer) throw new OmniTransferNotFoundError(args.tx.hash);
1276
+ const destinationChain = getChain(
1277
+ transfer.transfer_message.recipient
1278
+ );
1279
+ let txHash = null;
1280
+ if (isEvmChain(destinationChain)) {
1281
+ txHash = transfer.finalised?.EVMLog?.transaction_hash;
1282
+ } else if (destinationChain === ChainKind2.Sol) {
1283
+ txHash = transfer.finalised?.Solana?.signature;
1284
+ } else {
1285
+ return { hash: null };
1286
+ }
1287
+ if (!txHash)
1288
+ throw new OmniTransferDestinationChainHashNotFoundError(
1289
+ args.tx.hash,
1290
+ ChainKind2[destinationChain].toLowerCase()
1291
+ );
1292
+ return { hash: txHash };
1293
+ },
1294
+ {
1295
+ ...args.retryOptions ?? RETRY_CONFIGS2.FIVE_MINS_STEADY,
1296
+ handleError: (err, ctx) => {
1297
+ if (err instanceof OmniTransferNotFoundError || err === args.signal?.reason) {
1298
+ ctx.abort();
1299
+ }
1300
+ }
1301
+ }
1302
+ );
1303
+ }
1304
+ /**
1305
+ * Gets storage deposit for a token to avoid frequent RPC calls.
1306
+ * Cache expires after one day using TTL cache.
1307
+ */
1308
+ async getCachedStorageDepositValue(contractId) {
1309
+ const cached = this.storageDepositCache.get(contractId);
1310
+ if (cached !== void 0) {
1311
+ return cached;
1312
+ }
1313
+ const data = await Promise.all([
1314
+ getNearNep141MinStorageBalance3({
1315
+ contractId,
1316
+ nearProvider: this.nearProvider
1317
+ }),
1318
+ getNearNep141StorageBalance3({
1319
+ contractId,
1320
+ accountId: OMNI_BRIDGE_CONTRACT,
1321
+ nearProvider: this.nearProvider
1322
+ })
1323
+ ]);
1324
+ this.storageDepositCache.set(contractId, data);
1325
+ return data;
1326
+ }
1327
+ /**
1328
+ * Gets cached token address on destination chain.
1329
+ * Cache expires after one day using TTL cache.
1330
+ */
1331
+ async getCachedDestinationTokenAddress(contractId, omniChainKind) {
1332
+ const key = `${omniChainKind}:${contractId}`;
1333
+ const cached = this.destinationChainAddressCache.get(key);
1334
+ if (cached !== void 0) {
1335
+ return cached;
1336
+ }
1337
+ const tokenOnDestinationNetwork = await getBridgedToken(
1338
+ omniAddress2(ChainKind2.Near, contractId),
1339
+ omniChainKind
1340
+ );
1341
+ this.destinationChainAddressCache.set(key, tokenOnDestinationNetwork);
1342
+ return tokenOnDestinationNetwork;
1343
+ }
1344
+ };
1345
+
1346
+ // src/bridges/poa-bridge/poa-bridge.ts
1347
+ import {
1348
+ assert as assert10,
1349
+ configsByEnvironment as configsByEnvironment4,
1350
+ poaBridge,
1351
+ utils as utils9
1352
+ } from "@defuse-protocol/internal-utils";
1353
+ import TTLCache2 from "@isaacs/ttlcache";
1354
+
1355
+ // src/bridges/poa-bridge/poa-bridge-utils.ts
1356
+ import { utils as utils8 } from "@defuse-protocol/internal-utils";
1357
+ function createWithdrawIntentPrimitive4(params) {
1358
+ const { contractId: tokenAccountId } = utils8.parseDefuseAssetId(
926
1359
  params.assetId
927
1360
  );
928
1361
  return {
@@ -997,7 +1430,7 @@ function contractIdToCaip2(contractId) {
997
1430
  var PoaBridge = class {
998
1431
  constructor({ env }) {
999
1432
  // TTL cache for supported tokens with 30-second TTL
1000
- this.supportedTokensCache = new TTLCache({ ttl: 30 * 1e3 });
1433
+ this.supportedTokensCache = new TTLCache2({ ttl: 30 * 1e3 });
1001
1434
  this.env = env;
1002
1435
  }
1003
1436
  is(routeConfig) {
@@ -1020,7 +1453,7 @@ var PoaBridge = class {
1020
1453
  parseAssetId(assetId) {
1021
1454
  const parsed = parseDefuseAssetId(assetId);
1022
1455
  const contractIdSatisfies = parsed.contractId.endsWith(
1023
- `.${configsByEnvironment3[this.env].poaTokenFactoryContractID}`
1456
+ `.${configsByEnvironment4[this.env].poaTokenFactoryContractID}`
1024
1457
  );
1025
1458
  if (!contractIdSatisfies) {
1026
1459
  return null;
@@ -1042,7 +1475,7 @@ var PoaBridge = class {
1042
1475
  });
1043
1476
  }
1044
1477
  createWithdrawalIntents(args) {
1045
- const intent = createWithdrawIntentPrimitive3({
1478
+ const intent = createWithdrawIntentPrimitive4({
1046
1479
  ...args.withdrawalParams,
1047
1480
  amount: args.withdrawalParams.amount + args.feeEstimation.amount,
1048
1481
  destinationMemo: args.withdrawalParams.destinationMemo
@@ -1057,7 +1490,7 @@ var PoaBridge = class {
1057
1490
  */
1058
1491
  async validateWithdrawal(args) {
1059
1492
  const assetInfo = this.parseAssetId(args.assetId);
1060
- assert8(assetInfo != null, "Asset is not supported");
1493
+ assert10(assetInfo != null, "Asset is not supported");
1061
1494
  const { tokens: tokens2 } = await this.getCachedSupportedTokens(
1062
1495
  [toPoaNetwork(assetInfo.blockchain)],
1063
1496
  args.logger
@@ -1078,16 +1511,16 @@ var PoaBridge = class {
1078
1511
  }
1079
1512
  async estimateWithdrawalFee(args) {
1080
1513
  const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
1081
- assert8(assetInfo != null, "Asset is not supported");
1514
+ assert10(assetInfo != null, "Asset is not supported");
1082
1515
  const estimation = await poaBridge.httpClient.getWithdrawalEstimate(
1083
1516
  {
1084
- token: utils8.getTokenAccountId(args.withdrawalParams.assetId),
1517
+ token: utils9.getTokenAccountId(args.withdrawalParams.assetId),
1085
1518
  address: args.withdrawalParams.destinationAddress,
1086
1519
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
1087
1520
  chain: toPoaNetwork(assetInfo.blockchain)
1088
1521
  },
1089
1522
  {
1090
- baseURL: configsByEnvironment3[this.env].poaBridgeBaseURL,
1523
+ baseURL: configsByEnvironment4[this.env].poaBridgeBaseURL,
1091
1524
  logger: args.logger
1092
1525
  }
1093
1526
  );
@@ -1102,7 +1535,7 @@ var PoaBridge = class {
1102
1535
  index: args.index,
1103
1536
  signal: args.signal ?? new AbortController().signal,
1104
1537
  retryOptions: args.retryOptions,
1105
- baseURL: configsByEnvironment3[this.env].poaBridgeBaseURL,
1538
+ baseURL: configsByEnvironment4[this.env].poaBridgeBaseURL,
1106
1539
  logger: args.logger
1107
1540
  });
1108
1541
  return { hash: withdrawalStatus.destinationTxHash };
@@ -1120,7 +1553,7 @@ var PoaBridge = class {
1120
1553
  const data = await poaBridge.httpClient.getSupportedTokens(
1121
1554
  { chains },
1122
1555
  {
1123
- baseURL: configsByEnvironment3[this.env].poaBridgeBaseURL,
1556
+ baseURL: configsByEnvironment4[this.env].poaBridgeBaseURL,
1124
1557
  logger
1125
1558
  }
1126
1559
  );
@@ -1143,7 +1576,7 @@ var PUBLIC_STELLAR_RPC_URLS = {
1143
1576
 
1144
1577
  // src/intents/intent-executer-impl/intent-executer.ts
1145
1578
  import {
1146
- configsByEnvironment as configsByEnvironment4
1579
+ configsByEnvironment as configsByEnvironment5
1147
1580
  } from "@defuse-protocol/internal-utils";
1148
1581
 
1149
1582
  // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
@@ -1526,7 +1959,7 @@ var IntentExecuter = class {
1526
1959
  relayParams: relayParamsFactory,
1527
1960
  ...intentParams
1528
1961
  }) {
1529
- const verifyingContract = configsByEnvironment4[this.env].contractID;
1962
+ const verifyingContract = configsByEnvironment5[this.env].contractID;
1530
1963
  let intentPayload = defaultIntentPayloadFactory({
1531
1964
  verifying_contract: verifyingContract,
1532
1965
  ...intentParams
@@ -1577,8 +2010,8 @@ async function mergeIntentPayloads(basePayload, intentPayloadFactory) {
1577
2010
 
1578
2011
  // src/intents/intent-relayer-impl/intent-relayer-public.ts
1579
2012
  import {
1580
- configsByEnvironment as configsByEnvironment5,
1581
- solverRelay as solverRelay2
2013
+ configsByEnvironment as configsByEnvironment6,
2014
+ solverRelay as solverRelay3
1582
2015
  } from "@defuse-protocol/internal-utils";
1583
2016
  var IntentRelayerPublic = class {
1584
2017
  constructor({ env }) {
@@ -1601,13 +2034,13 @@ var IntentRelayerPublic = class {
1601
2034
  multiPayloads,
1602
2035
  quoteHashes
1603
2036
  }, ctx = {}) {
1604
- const a = await solverRelay2.publishIntents(
2037
+ const a = await solverRelay3.publishIntents(
1605
2038
  {
1606
2039
  quote_hashes: quoteHashes,
1607
2040
  signed_datas: multiPayloads
1608
2041
  },
1609
2042
  {
1610
- baseURL: configsByEnvironment5[this.env].solverRelayBaseURL,
2043
+ baseURL: configsByEnvironment6[this.env].solverRelayBaseURL,
1611
2044
  logger: ctx.logger
1612
2045
  }
1613
2046
  );
@@ -1617,10 +2050,10 @@ var IntentRelayerPublic = class {
1617
2050
  throw a.unwrapErr();
1618
2051
  }
1619
2052
  async waitForSettlement(ticket, ctx = {}) {
1620
- const result = await solverRelay2.waitForIntentSettlement({
2053
+ const result = await solverRelay3.waitForIntentSettlement({
1621
2054
  intentHash: ticket,
1622
2055
  signal: new AbortController().signal,
1623
- baseURL: configsByEnvironment5[this.env].solverRelayBaseURL,
2056
+ baseURL: configsByEnvironment6[this.env].solverRelayBaseURL,
1624
2057
  logger: ctx.logger
1625
2058
  });
1626
2059
  return {
@@ -1628,7 +2061,7 @@ var IntentRelayerPublic = class {
1628
2061
  hash: result.txHash,
1629
2062
  // Usually relayer's account id is the verifying contract (`intents.near`),
1630
2063
  // but it is not set in stone and may change in the future.
1631
- accountId: configsByEnvironment5[this.env].contractID
2064
+ accountId: configsByEnvironment6[this.env].contractID
1632
2065
  }
1633
2066
  };
1634
2067
  }
@@ -1642,14 +2075,14 @@ var noopIntentSigner = {
1642
2075
  };
1643
2076
 
1644
2077
  // src/lib/array.ts
1645
- import { assert as assert9 } from "@defuse-protocol/internal-utils";
2078
+ import { assert as assert11 } from "@defuse-protocol/internal-utils";
1646
2079
  function zip(arr1, arr2) {
1647
- assert9(arr1.length === arr2.length, "Arrays must have the same length");
2080
+ assert11(arr1.length === arr2.length, "Arrays must have the same length");
1648
2081
  return arr1.map((v, i) => [v, arr2[i]]);
1649
2082
  }
1650
2083
 
1651
2084
  // src/lib/configure-rpc-config.ts
1652
- import { assert as assert10 } from "@defuse-protocol/internal-utils";
2085
+ import { assert as assert12 } from "@defuse-protocol/internal-utils";
1653
2086
 
1654
2087
  // src/lib/object.ts
1655
2088
  function pick(obj, keys) {
@@ -1673,7 +2106,7 @@ function configureEvmRpcUrls(defaultRpcUrls, userRpcUrls, supportedChains) {
1673
2106
  ).map(([caip2, urls]) => [getEIP155ChainId(caip2), urls])
1674
2107
  );
1675
2108
  for (const [chainId, urls] of Object.entries(evmRpcUrls)) {
1676
- assert10(
2109
+ assert12(
1677
2110
  urls.length > 0,
1678
2111
  `EVM RPC URLs for chain ${chainId} are not provided`
1679
2112
  );
@@ -1687,7 +2120,7 @@ function configureStellarRpcUrls(defaultRpcUrls, userRpcUrls) {
1687
2120
  userRpcUrls?.[Chains.Stellar] ?? {}
1688
2121
  );
1689
2122
  for (const [key, value] of Object.entries(stellarRpcUrls)) {
1690
- assert10(value.length > 0, `Stellar RPC URL for ${key} is not provided`);
2123
+ assert12(value.length > 0, `Stellar RPC URL for ${key} is not provided`);
1691
2124
  }
1692
2125
  return stellarRpcUrls;
1693
2126
  }
@@ -1699,8 +2132,10 @@ function createInternalTransferRoute() {
1699
2132
  function createNearWithdrawalRoute(msg) {
1700
2133
  return { route: RouteEnum.NearWithdrawal, msg };
1701
2134
  }
1702
- function createOmniBridgeRoute() {
1703
- return { route: RouteEnum.OmniBridge };
2135
+ function createOmniBridgeRoute(chain) {
2136
+ const routeConfig = { route: RouteEnum.OmniBridge };
2137
+ if (chain) routeConfig.chain = chain;
2138
+ return routeConfig;
1704
2139
  }
1705
2140
  function createVirtualChainRoute(auroraEngineContractId, proxyTokenContractId) {
1706
2141
  return {
@@ -1737,7 +2172,7 @@ function determineRouteConfig(sdk, withdrawalParams) {
1737
2172
  case BridgeNameEnum.Poa:
1738
2173
  return createPoaBridgeRoute(parseAssetId.blockchain);
1739
2174
  case BridgeNameEnum.Omni:
1740
- return createOmniBridgeRoute();
2175
+ return createOmniBridgeRoute(parseAssetId.blockchain);
1741
2176
  case BridgeNameEnum.None:
1742
2177
  return createNearWithdrawalRoute();
1743
2178
  default:
@@ -1752,7 +2187,7 @@ var IntentsSDK = class {
1752
2187
  this.env = args.env ?? "production";
1753
2188
  this.referral = args.referral;
1754
2189
  const nearRpcUrls = args.rpc?.[Chains.Near] ?? PUBLIC_NEAR_RPC_URLS;
1755
- assert11(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
2190
+ assert13(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
1756
2191
  const nearProvider = nearFailoverRpcProvider({ urls: nearRpcUrls });
1757
2192
  const stellarRpcUrls = configureStellarRpcUrls(
1758
2193
  PUBLIC_STELLAR_RPC_URLS,
@@ -1785,10 +2220,10 @@ var IntentsSDK = class {
1785
2220
  }
1786
2221
  })
1787
2222
  }),
1788
- // new OmniBridge({
1789
- // env: this.env,
1790
- // nearProvider,
1791
- // }),
2223
+ new OmniBridge({
2224
+ env: this.env,
2225
+ nearProvider
2226
+ }),
1792
2227
  new DirectBridge({
1793
2228
  env: this.env,
1794
2229
  nearProvider
@@ -1879,7 +2314,7 @@ var IntentsSDK = class {
1879
2314
  const routeConfig = determineRouteConfig(this, w);
1880
2315
  const route = routeConfig.route;
1881
2316
  const index = indexes.get(route);
1882
- assert11(index != null, "Index is not found for route");
2317
+ assert13(index != null, "Index is not found for route");
1883
2318
  indexes.set(route, index + 1);
1884
2319
  return {
1885
2320
  routeConfig,
@@ -1913,7 +2348,7 @@ var IntentsSDK = class {
1913
2348
  if (Array.isArray(args.withdrawalParams)) {
1914
2349
  return result;
1915
2350
  }
1916
- assert11(result.length === 1, "Unexpected result length");
2351
+ assert13(result.length === 1, "Unexpected result length");
1917
2352
  return result[0];
1918
2353
  }
1919
2354
  parseAssetId(assetId) {
@@ -1927,7 +2362,7 @@ var IntentsSDK = class {
1927
2362
  }
1928
2363
  async signAndSendIntent(args) {
1929
2364
  const intentSigner = args.signer ?? this.intentSigner;
1930
- assert11(intentSigner != null, "Intent signer is not provided");
2365
+ assert13(intentSigner != null, "Intent signer is not provided");
1931
2366
  const intentExecuter = new IntentExecuter({
1932
2367
  env: this.env,
1933
2368
  logger: args.logger,
@@ -1996,12 +2431,12 @@ var IntentsSDK = class {
1996
2431
  intentHash,
1997
2432
  logger
1998
2433
  }) {
1999
- return solverRelay3.getStatus(
2434
+ return solverRelay4.getStatus(
2000
2435
  {
2001
2436
  intent_hash: intentHash
2002
2437
  },
2003
2438
  {
2004
- baseURL: configsByEnvironment6[this.env].solverRelayBaseURL,
2439
+ baseURL: configsByEnvironment7[this.env].solverRelayBaseURL,
2005
2440
  logger
2006
2441
  }
2007
2442
  );
@@ -2032,7 +2467,7 @@ var IntentsSDK = class {
2032
2467
  withdrawalParams,
2033
2468
  intentTx,
2034
2469
  logger: args.logger,
2035
- retryOptions: RETRY_CONFIGS2.FIVE_MINS_STEADY
2470
+ retryOptions: RETRY_CONFIGS3.FIVE_MINS_STEADY
2036
2471
  });
2037
2472
  if (!Array.isArray(args.withdrawalParams)) {
2038
2473
  return {
@@ -2111,14 +2546,14 @@ var IntentSignerNearKeypair = class extends IntentSignerNEP413 {
2111
2546
  };
2112
2547
 
2113
2548
  // src/intents/intent-signer-impl/intent-signer-viem.ts
2114
- import { utils as utils9 } from "@defuse-protocol/internal-utils";
2549
+ import { utils as utils10 } from "@defuse-protocol/internal-utils";
2115
2550
  var IntentSignerViem = class {
2116
2551
  constructor(account) {
2117
2552
  this.account = account;
2118
2553
  }
2119
2554
  async signIntent(intent) {
2120
2555
  const payload = JSON.stringify({
2121
- signer_id: intent.signer_id ?? utils9.authHandleToIntentsUserId({
2556
+ signer_id: intent.signer_id ?? utils10.authHandleToIntentsUserId({
2122
2557
  identifier: this.account.address,
2123
2558
  method: "evm"
2124
2559
  }),
@@ -2136,7 +2571,7 @@ var IntentSignerViem = class {
2136
2571
  return {
2137
2572
  standard: "erc191",
2138
2573
  payload,
2139
- signature: utils9.transformERC191Signature(signature)
2574
+ signature: utils10.transformERC191Signature(signature)
2140
2575
  };
2141
2576
  }
2142
2577
  };
@@ -2156,54 +2591,6 @@ function createIntentSignerViem(config) {
2156
2591
  import {
2157
2592
  BaseError as BaseError4
2158
2593
  } from "@defuse-protocol/internal-utils";
2159
-
2160
- // src/bridges/omni-bridge/error.ts
2161
- import { BaseError as BaseError3 } from "@defuse-protocol/internal-utils";
2162
- var OmniTransferNotFoundError = class extends BaseError3 {
2163
- constructor(txHash) {
2164
- super("Omni transfer with given hash is not found in the relayer.", {
2165
- metaMessages: [`OriginTxHash: ${txHash}`],
2166
- name: "OmniTransferNotFoundError"
2167
- });
2168
- this.txHash = txHash;
2169
- }
2170
- };
2171
- var OmniTransferDestinationChainHashNotFoundError = class extends BaseError3 {
2172
- constructor(txHash, destinationChain) {
2173
- super("Relayer did not return destination chain hash for a transfer.", {
2174
- metaMessages: [
2175
- `OriginTxHash: ${txHash}`,
2176
- `DestinationChain: ${destinationChain}`
2177
- ],
2178
- name: "OmniTransferDestinationChainHashNotFoundError"
2179
- });
2180
- this.txHash = txHash;
2181
- this.destinationChain = destinationChain;
2182
- }
2183
- };
2184
- var TokenNotSupportedByOmniRelayerError = class extends BaseError3 {
2185
- constructor(token) {
2186
- super(`Omni Relayer doesn't accept fee in the transferred token ${token}`, {
2187
- metaMessages: [`Token: ${token}`],
2188
- name: "TokenNotSupportedByOmniRelayerError"
2189
- });
2190
- this.token = token;
2191
- }
2192
- };
2193
- var TokenNotFoundInDestinationChainError = class extends BaseError3 {
2194
- constructor(token, chainKind) {
2195
- super(
2196
- `The token ${token} doesn't exist in destination network ${chainKind}`,
2197
- {
2198
- metaMessages: [`Token: ${token}`, `Destination Chain: ${chainKind}`],
2199
- name: "TokenNotFoundInDestinationChainError"
2200
- }
2201
- );
2202
- this.token = token;
2203
- }
2204
- };
2205
-
2206
- // index.ts
2207
2594
  import {
2208
2595
  PoaWithdrawalInvariantError,
2209
2596
  PoaWithdrawalNotFoundError,