@defuse-protocol/intents-sdk 0.17.1 → 0.19.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.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
@@ -1465,6 +1898,7 @@ async function computeIntentHashBytes(multiPayload) {
1465
1898
  multiPayload
1466
1899
  );
1467
1900
  case "erc191":
1901
+ case "tip191":
1468
1902
  return computeErc191Hash(
1469
1903
  multiPayload
1470
1904
  );
@@ -1525,7 +1959,7 @@ var IntentExecuter = class {
1525
1959
  relayParams: relayParamsFactory,
1526
1960
  ...intentParams
1527
1961
  }) {
1528
- const verifyingContract = configsByEnvironment4[this.env].contractID;
1962
+ const verifyingContract = configsByEnvironment5[this.env].contractID;
1529
1963
  let intentPayload = defaultIntentPayloadFactory({
1530
1964
  verifying_contract: verifyingContract,
1531
1965
  ...intentParams
@@ -1576,8 +2010,8 @@ async function mergeIntentPayloads(basePayload, intentPayloadFactory) {
1576
2010
 
1577
2011
  // src/intents/intent-relayer-impl/intent-relayer-public.ts
1578
2012
  import {
1579
- configsByEnvironment as configsByEnvironment5,
1580
- solverRelay as solverRelay2
2013
+ configsByEnvironment as configsByEnvironment6,
2014
+ solverRelay as solverRelay3
1581
2015
  } from "@defuse-protocol/internal-utils";
1582
2016
  var IntentRelayerPublic = class {
1583
2017
  constructor({ env }) {
@@ -1600,13 +2034,13 @@ var IntentRelayerPublic = class {
1600
2034
  multiPayloads,
1601
2035
  quoteHashes
1602
2036
  }, ctx = {}) {
1603
- const a = await solverRelay2.publishIntents(
2037
+ const a = await solverRelay3.publishIntents(
1604
2038
  {
1605
2039
  quote_hashes: quoteHashes,
1606
2040
  signed_datas: multiPayloads
1607
2041
  },
1608
2042
  {
1609
- baseURL: configsByEnvironment5[this.env].solverRelayBaseURL,
2043
+ baseURL: configsByEnvironment6[this.env].solverRelayBaseURL,
1610
2044
  logger: ctx.logger
1611
2045
  }
1612
2046
  );
@@ -1616,10 +2050,10 @@ var IntentRelayerPublic = class {
1616
2050
  throw a.unwrapErr();
1617
2051
  }
1618
2052
  async waitForSettlement(ticket, ctx = {}) {
1619
- const result = await solverRelay2.waitForIntentSettlement({
2053
+ const result = await solverRelay3.waitForIntentSettlement({
1620
2054
  intentHash: ticket,
1621
2055
  signal: new AbortController().signal,
1622
- baseURL: configsByEnvironment5[this.env].solverRelayBaseURL,
2056
+ baseURL: configsByEnvironment6[this.env].solverRelayBaseURL,
1623
2057
  logger: ctx.logger
1624
2058
  });
1625
2059
  return {
@@ -1627,7 +2061,7 @@ var IntentRelayerPublic = class {
1627
2061
  hash: result.txHash,
1628
2062
  // Usually relayer's account id is the verifying contract (`intents.near`),
1629
2063
  // but it is not set in stone and may change in the future.
1630
- accountId: configsByEnvironment5[this.env].contractID
2064
+ accountId: configsByEnvironment6[this.env].contractID
1631
2065
  }
1632
2066
  };
1633
2067
  }
@@ -1641,14 +2075,14 @@ var noopIntentSigner = {
1641
2075
  };
1642
2076
 
1643
2077
  // src/lib/array.ts
1644
- import { assert as assert9 } from "@defuse-protocol/internal-utils";
2078
+ import { assert as assert11 } from "@defuse-protocol/internal-utils";
1645
2079
  function zip(arr1, arr2) {
1646
- assert9(arr1.length === arr2.length, "Arrays must have the same length");
2080
+ assert11(arr1.length === arr2.length, "Arrays must have the same length");
1647
2081
  return arr1.map((v, i) => [v, arr2[i]]);
1648
2082
  }
1649
2083
 
1650
2084
  // src/lib/configure-rpc-config.ts
1651
- import { assert as assert10 } from "@defuse-protocol/internal-utils";
2085
+ import { assert as assert12 } from "@defuse-protocol/internal-utils";
1652
2086
 
1653
2087
  // src/lib/object.ts
1654
2088
  function pick(obj, keys) {
@@ -1672,7 +2106,7 @@ function configureEvmRpcUrls(defaultRpcUrls, userRpcUrls, supportedChains) {
1672
2106
  ).map(([caip2, urls]) => [getEIP155ChainId(caip2), urls])
1673
2107
  );
1674
2108
  for (const [chainId, urls] of Object.entries(evmRpcUrls)) {
1675
- assert10(
2109
+ assert12(
1676
2110
  urls.length > 0,
1677
2111
  `EVM RPC URLs for chain ${chainId} are not provided`
1678
2112
  );
@@ -1686,7 +2120,7 @@ function configureStellarRpcUrls(defaultRpcUrls, userRpcUrls) {
1686
2120
  userRpcUrls?.[Chains.Stellar] ?? {}
1687
2121
  );
1688
2122
  for (const [key, value] of Object.entries(stellarRpcUrls)) {
1689
- 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`);
1690
2124
  }
1691
2125
  return stellarRpcUrls;
1692
2126
  }
@@ -1698,8 +2132,10 @@ function createInternalTransferRoute() {
1698
2132
  function createNearWithdrawalRoute(msg) {
1699
2133
  return { route: RouteEnum.NearWithdrawal, msg };
1700
2134
  }
1701
- function createOmniBridgeRoute() {
1702
- return { route: RouteEnum.OmniBridge };
2135
+ function createOmniBridgeRoute(chain) {
2136
+ const routeConfig = { route: RouteEnum.OmniBridge };
2137
+ if (chain) routeConfig.chain = chain;
2138
+ return routeConfig;
1703
2139
  }
1704
2140
  function createVirtualChainRoute(auroraEngineContractId, proxyTokenContractId) {
1705
2141
  return {
@@ -1736,7 +2172,7 @@ function determineRouteConfig(sdk, withdrawalParams) {
1736
2172
  case BridgeNameEnum.Poa:
1737
2173
  return createPoaBridgeRoute(parseAssetId.blockchain);
1738
2174
  case BridgeNameEnum.Omni:
1739
- return createOmniBridgeRoute();
2175
+ return createOmniBridgeRoute(parseAssetId.blockchain);
1740
2176
  case BridgeNameEnum.None:
1741
2177
  return createNearWithdrawalRoute();
1742
2178
  default:
@@ -1751,7 +2187,7 @@ var IntentsSDK = class {
1751
2187
  this.env = args.env ?? "production";
1752
2188
  this.referral = args.referral;
1753
2189
  const nearRpcUrls = args.rpc?.[Chains.Near] ?? PUBLIC_NEAR_RPC_URLS;
1754
- assert11(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
2190
+ assert13(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
1755
2191
  const nearProvider = nearFailoverRpcProvider({ urls: nearRpcUrls });
1756
2192
  const stellarRpcUrls = configureStellarRpcUrls(
1757
2193
  PUBLIC_STELLAR_RPC_URLS,
@@ -1784,10 +2220,10 @@ var IntentsSDK = class {
1784
2220
  }
1785
2221
  })
1786
2222
  }),
1787
- // new OmniBridge({
1788
- // env: this.env,
1789
- // nearProvider,
1790
- // }),
2223
+ new OmniBridge({
2224
+ env: this.env,
2225
+ nearProvider
2226
+ }),
1791
2227
  new DirectBridge({
1792
2228
  env: this.env,
1793
2229
  nearProvider
@@ -1878,7 +2314,7 @@ var IntentsSDK = class {
1878
2314
  const routeConfig = determineRouteConfig(this, w);
1879
2315
  const route = routeConfig.route;
1880
2316
  const index = indexes.get(route);
1881
- assert11(index != null, "Index is not found for route");
2317
+ assert13(index != null, "Index is not found for route");
1882
2318
  indexes.set(route, index + 1);
1883
2319
  return {
1884
2320
  routeConfig,
@@ -1912,7 +2348,7 @@ var IntentsSDK = class {
1912
2348
  if (Array.isArray(args.withdrawalParams)) {
1913
2349
  return result;
1914
2350
  }
1915
- assert11(result.length === 1, "Unexpected result length");
2351
+ assert13(result.length === 1, "Unexpected result length");
1916
2352
  return result[0];
1917
2353
  }
1918
2354
  parseAssetId(assetId) {
@@ -1926,7 +2362,7 @@ var IntentsSDK = class {
1926
2362
  }
1927
2363
  async signAndSendIntent(args) {
1928
2364
  const intentSigner = args.signer ?? this.intentSigner;
1929
- assert11(intentSigner != null, "Intent signer is not provided");
2365
+ assert13(intentSigner != null, "Intent signer is not provided");
1930
2366
  const intentExecuter = new IntentExecuter({
1931
2367
  env: this.env,
1932
2368
  logger: args.logger,
@@ -1995,12 +2431,12 @@ var IntentsSDK = class {
1995
2431
  intentHash,
1996
2432
  logger
1997
2433
  }) {
1998
- return solverRelay3.getStatus(
2434
+ return solverRelay4.getStatus(
1999
2435
  {
2000
2436
  intent_hash: intentHash
2001
2437
  },
2002
2438
  {
2003
- baseURL: configsByEnvironment6[this.env].solverRelayBaseURL,
2439
+ baseURL: configsByEnvironment7[this.env].solverRelayBaseURL,
2004
2440
  logger
2005
2441
  }
2006
2442
  );
@@ -2031,7 +2467,7 @@ var IntentsSDK = class {
2031
2467
  withdrawalParams,
2032
2468
  intentTx,
2033
2469
  logger: args.logger,
2034
- retryOptions: RETRY_CONFIGS2.FIVE_MINS_STEADY
2470
+ retryOptions: RETRY_CONFIGS3.FIVE_MINS_STEADY
2035
2471
  });
2036
2472
  if (!Array.isArray(args.withdrawalParams)) {
2037
2473
  return {
@@ -2110,14 +2546,14 @@ var IntentSignerNearKeypair = class extends IntentSignerNEP413 {
2110
2546
  };
2111
2547
 
2112
2548
  // src/intents/intent-signer-impl/intent-signer-viem.ts
2113
- import { utils as utils9 } from "@defuse-protocol/internal-utils";
2549
+ import { utils as utils10 } from "@defuse-protocol/internal-utils";
2114
2550
  var IntentSignerViem = class {
2115
2551
  constructor(account) {
2116
2552
  this.account = account;
2117
2553
  }
2118
2554
  async signIntent(intent) {
2119
2555
  const payload = JSON.stringify({
2120
- signer_id: intent.signer_id ?? utils9.authHandleToIntentsUserId({
2556
+ signer_id: intent.signer_id ?? utils10.authHandleToIntentsUserId({
2121
2557
  identifier: this.account.address,
2122
2558
  method: "evm"
2123
2559
  }),
@@ -2135,7 +2571,7 @@ var IntentSignerViem = class {
2135
2571
  return {
2136
2572
  standard: "erc191",
2137
2573
  payload,
2138
- signature: utils9.transformERC191Signature(signature)
2574
+ signature: utils10.transformERC191Signature(signature)
2139
2575
  };
2140
2576
  }
2141
2577
  };
@@ -2155,54 +2591,6 @@ function createIntentSignerViem(config) {
2155
2591
  import {
2156
2592
  BaseError as BaseError4
2157
2593
  } from "@defuse-protocol/internal-utils";
2158
-
2159
- // src/bridges/omni-bridge/error.ts
2160
- import { BaseError as BaseError3 } from "@defuse-protocol/internal-utils";
2161
- var OmniTransferNotFoundError = class extends BaseError3 {
2162
- constructor(txHash) {
2163
- super("Omni transfer with given hash is not found in the relayer.", {
2164
- metaMessages: [`OriginTxHash: ${txHash}`],
2165
- name: "OmniTransferNotFoundError"
2166
- });
2167
- this.txHash = txHash;
2168
- }
2169
- };
2170
- var OmniTransferDestinationChainHashNotFoundError = class extends BaseError3 {
2171
- constructor(txHash, destinationChain) {
2172
- super("Relayer did not return destination chain hash for a transfer.", {
2173
- metaMessages: [
2174
- `OriginTxHash: ${txHash}`,
2175
- `DestinationChain: ${destinationChain}`
2176
- ],
2177
- name: "OmniTransferDestinationChainHashNotFoundError"
2178
- });
2179
- this.txHash = txHash;
2180
- this.destinationChain = destinationChain;
2181
- }
2182
- };
2183
- var TokenNotSupportedByOmniRelayerError = class extends BaseError3 {
2184
- constructor(token) {
2185
- super(`Omni Relayer doesn't accept fee in the transferred token ${token}`, {
2186
- metaMessages: [`Token: ${token}`],
2187
- name: "TokenNotSupportedByOmniRelayerError"
2188
- });
2189
- this.token = token;
2190
- }
2191
- };
2192
- var TokenNotFoundInDestinationChainError = class extends BaseError3 {
2193
- constructor(token, chainKind) {
2194
- super(
2195
- `The token ${token} doesn't exist in destination network ${chainKind}`,
2196
- {
2197
- metaMessages: [`Token: ${token}`, `Destination Chain: ${chainKind}`],
2198
- name: "TokenNotFoundInDestinationChainError"
2199
- }
2200
- );
2201
- this.token = token;
2202
- }
2203
- };
2204
-
2205
- // index.ts
2206
2594
  import {
2207
2595
  PoaWithdrawalInvariantError,
2208
2596
  PoaWithdrawalNotFoundError,