@defuse-protocol/intents-sdk 0.20.0 → 0.22.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/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/index.cjs +92 -13
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +96 -15
- package/package.json +6 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 NEAR Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
IntentSettlementError: () => import_internal_utils28.IntentSettlementError,
|
|
43
43
|
IntentsSDK: () => IntentsSDK,
|
|
44
44
|
MinWithdrawalAmountError: () => MinWithdrawalAmountError,
|
|
45
|
+
OmniTokenNormalisationCheckError: () => OmniTokenNormalisationCheckError,
|
|
45
46
|
OmniTransferDestinationChainHashNotFoundError: () => OmniTransferDestinationChainHashNotFoundError,
|
|
46
47
|
OmniTransferNotFoundError: () => OmniTransferNotFoundError,
|
|
47
48
|
PoaWithdrawalInvariantError: () => import_internal_utils25.PoaWithdrawalInvariantError,
|
|
@@ -1013,6 +1014,26 @@ var TokenNotSupportedByOmniRelayerError = class extends import_internal_utils13.
|
|
|
1013
1014
|
this.token = token;
|
|
1014
1015
|
}
|
|
1015
1016
|
};
|
|
1017
|
+
var OmniTokenNormalisationCheckError = class extends import_internal_utils13.BaseError {
|
|
1018
|
+
constructor(tokenIn, destinationToken, minAmount, fee) {
|
|
1019
|
+
super(
|
|
1020
|
+
`Transfer amount sent to relayer is too small - would result in 0 after decimal normalisation. Minimum transferable amount if feeInclusive=false is >= ${minAmount}. Minimum transferable amount if feeInclusive=true is >= ${minAmount + fee}.`,
|
|
1021
|
+
{
|
|
1022
|
+
metaMessages: [
|
|
1023
|
+
`TokenIn: ${tokenIn}`,
|
|
1024
|
+
`DestinationToken: ${destinationToken}`,
|
|
1025
|
+
`MinAmount: ${minAmount}`,
|
|
1026
|
+
`fee: ${fee}`
|
|
1027
|
+
],
|
|
1028
|
+
name: "OmniTokenNormalisationCheckError"
|
|
1029
|
+
}
|
|
1030
|
+
);
|
|
1031
|
+
this.tokenIn = tokenIn;
|
|
1032
|
+
this.destinationToken = destinationToken;
|
|
1033
|
+
this.minAmount = minAmount;
|
|
1034
|
+
this.fee = fee;
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1016
1037
|
|
|
1017
1038
|
// src/bridges/omni-bridge/omni-bridge-constants.ts
|
|
1018
1039
|
var NEAR_NATIVE_ASSET_ID3 = "nep141:wrap.near";
|
|
@@ -1071,15 +1092,9 @@ function chainKindToCaip2(network) {
|
|
|
1071
1092
|
return null;
|
|
1072
1093
|
}
|
|
1073
1094
|
}
|
|
1074
|
-
var CHAIN_PATTERNS = {
|
|
1075
|
-
"nbtc.bridge.near": import_omni_bridge_sdk.ChainKind.Btc,
|
|
1076
|
-
"eth.bridge.near": import_omni_bridge_sdk.ChainKind.Eth,
|
|
1077
|
-
"sol.omdep.near": import_omni_bridge_sdk.ChainKind.Sol,
|
|
1078
|
-
"base.omdep.near": import_omni_bridge_sdk.ChainKind.Base,
|
|
1079
|
-
"arb.omdep.near": import_omni_bridge_sdk.ChainKind.Arb
|
|
1080
|
-
};
|
|
1081
1095
|
function validateOmniToken(nearAddress) {
|
|
1082
|
-
|
|
1096
|
+
if (nearAddress.endsWith(".testnet")) return false;
|
|
1097
|
+
return (0, import_omni_bridge_sdk.isBridgeToken)(nearAddress);
|
|
1083
1098
|
}
|
|
1084
1099
|
|
|
1085
1100
|
// src/bridges/omni-bridge/omni-bridge.ts
|
|
@@ -1092,6 +1107,10 @@ var OmniBridge = class {
|
|
|
1092
1107
|
this.storageDepositCache = new import_ttlcache.default({ ttl: 108e5 });
|
|
1093
1108
|
// 10800000 - 3 hours
|
|
1094
1109
|
this.destinationChainAddressCache = new import_ttlcache.default({ ttl: 108e5 });
|
|
1110
|
+
// 10800000 - 3 hours
|
|
1111
|
+
this.tokenDecimalsCache = new import_ttlcache.default({
|
|
1112
|
+
ttl: 108e5
|
|
1113
|
+
});
|
|
1095
1114
|
this.env = env;
|
|
1096
1115
|
this.nearProvider = nearProvider;
|
|
1097
1116
|
this.omniBridgeAPI = new import_omni_bridge_sdk2.OmniBridgeAPI();
|
|
@@ -1242,6 +1261,51 @@ var OmniBridge = class {
|
|
|
1242
1261
|
args.feeEstimation.amount > 0n,
|
|
1243
1262
|
`Fee must be greater than zero. Current fee is ${args.feeEstimation.amount}.`
|
|
1244
1263
|
);
|
|
1264
|
+
const assetInfo = this.makeAssetInfo(args.assetId, args.routeConfig);
|
|
1265
|
+
(0, import_internal_utils15.assert)(
|
|
1266
|
+
assetInfo !== null,
|
|
1267
|
+
`Asset ${args.assetId} is not supported by Omni Bridge`
|
|
1268
|
+
);
|
|
1269
|
+
const omniChainKind = caip2ToChainKind(assetInfo.blockchain);
|
|
1270
|
+
(0, import_internal_utils15.assert)(
|
|
1271
|
+
omniChainKind !== null,
|
|
1272
|
+
`Chain ${assetInfo.blockchain} is not supported by Omni Bridge`
|
|
1273
|
+
);
|
|
1274
|
+
const destTokenAddress = await this.getCachedDestinationTokenAddress(
|
|
1275
|
+
assetInfo.contractId,
|
|
1276
|
+
omniChainKind
|
|
1277
|
+
);
|
|
1278
|
+
if (destTokenAddress === null) {
|
|
1279
|
+
throw new TokenNotFoundInDestinationChainError(
|
|
1280
|
+
args.assetId,
|
|
1281
|
+
assetInfo.blockchain
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
const decimals = await this.getCachedTokenDecimals(destTokenAddress);
|
|
1285
|
+
(0, import_internal_utils15.assert)(
|
|
1286
|
+
decimals !== null,
|
|
1287
|
+
`Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
|
|
1288
|
+
Ensure the token is supported and the address is correct.`
|
|
1289
|
+
);
|
|
1290
|
+
const normalisationCheckSucceeded = (0, import_omni_bridge_sdk2.verifyTransferAmount)(
|
|
1291
|
+
// args.amount is without fee, we need to pass an amount being sent to relayer so we add fee here
|
|
1292
|
+
args.amount + args.feeEstimation.amount,
|
|
1293
|
+
args.feeEstimation.amount,
|
|
1294
|
+
decimals.origin_decimals,
|
|
1295
|
+
decimals.decimals
|
|
1296
|
+
);
|
|
1297
|
+
if (normalisationCheckSucceeded === false) {
|
|
1298
|
+
const minAmount = (0, import_omni_bridge_sdk2.getMinimumTransferableAmount)(
|
|
1299
|
+
decimals.origin_decimals,
|
|
1300
|
+
decimals.decimals
|
|
1301
|
+
);
|
|
1302
|
+
throw new OmniTokenNormalisationCheckError(
|
|
1303
|
+
args.assetId,
|
|
1304
|
+
destTokenAddress,
|
|
1305
|
+
minAmount,
|
|
1306
|
+
args.feeEstimation.amount
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1245
1309
|
return;
|
|
1246
1310
|
}
|
|
1247
1311
|
async estimateWithdrawalFee(args) {
|
|
@@ -1305,7 +1369,8 @@ var OmniBridge = class {
|
|
|
1305
1369
|
offset: args.index,
|
|
1306
1370
|
limit: 1
|
|
1307
1371
|
}))[0];
|
|
1308
|
-
if (
|
|
1372
|
+
if (transfer == null || transfer.transfer_message == null)
|
|
1373
|
+
throw new OmniTransferNotFoundError(args.tx.hash);
|
|
1309
1374
|
const destinationChain = (0, import_omni_bridge_sdk2.getChain)(
|
|
1310
1375
|
transfer.transfer_message.recipient
|
|
1311
1376
|
);
|
|
@@ -1336,7 +1401,6 @@ var OmniBridge = class {
|
|
|
1336
1401
|
}
|
|
1337
1402
|
/**
|
|
1338
1403
|
* Gets storage deposit for a token to avoid frequent RPC calls.
|
|
1339
|
-
* Cache expires after one day using TTL cache.
|
|
1340
1404
|
*/
|
|
1341
1405
|
async getCachedStorageDepositValue(contractId) {
|
|
1342
1406
|
const cached = this.storageDepositCache.get(contractId);
|
|
@@ -1359,7 +1423,6 @@ var OmniBridge = class {
|
|
|
1359
1423
|
}
|
|
1360
1424
|
/**
|
|
1361
1425
|
* Gets cached token address on destination chain.
|
|
1362
|
-
* Cache expires after one day using TTL cache.
|
|
1363
1426
|
*/
|
|
1364
1427
|
async getCachedDestinationTokenAddress(contractId, omniChainKind) {
|
|
1365
1428
|
const key = `${omniChainKind}:${contractId}`;
|
|
@@ -1374,6 +1437,21 @@ var OmniBridge = class {
|
|
|
1374
1437
|
this.destinationChainAddressCache.set(key, tokenOnDestinationNetwork);
|
|
1375
1438
|
return tokenOnDestinationNetwork;
|
|
1376
1439
|
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Gets cached token decimals on destination chain and on near.
|
|
1442
|
+
*/
|
|
1443
|
+
async getCachedTokenDecimals(omniAddress3) {
|
|
1444
|
+
const cached = this.tokenDecimalsCache.get(omniAddress3);
|
|
1445
|
+
if (cached !== void 0) {
|
|
1446
|
+
return cached;
|
|
1447
|
+
}
|
|
1448
|
+
const tokenDecimals = await (0, import_omni_bridge_sdk2.getTokenDecimals)(
|
|
1449
|
+
OMNI_BRIDGE_CONTRACT,
|
|
1450
|
+
omniAddress3
|
|
1451
|
+
);
|
|
1452
|
+
this.tokenDecimalsCache.set(omniAddress3, tokenDecimals);
|
|
1453
|
+
return tokenDecimals;
|
|
1454
|
+
}
|
|
1377
1455
|
};
|
|
1378
1456
|
|
|
1379
1457
|
// src/bridges/poa-bridge/poa-bridge.ts
|
|
@@ -2489,8 +2567,8 @@ var IntentsSDK = class {
|
|
|
2489
2567
|
const destinationTx = await this.waitForWithdrawalCompletion({
|
|
2490
2568
|
withdrawalParams,
|
|
2491
2569
|
intentTx,
|
|
2492
|
-
|
|
2493
|
-
|
|
2570
|
+
retryOptions: args.retryOptions ?? import_internal_utils22.RETRY_CONFIGS.FIVE_MINS_STEADY,
|
|
2571
|
+
logger: args.logger
|
|
2494
2572
|
});
|
|
2495
2573
|
if (!Array.isArray(args.withdrawalParams)) {
|
|
2496
2574
|
return {
|
|
@@ -2630,6 +2708,7 @@ var import_internal_utils28 = require("@defuse-protocol/internal-utils");
|
|
|
2630
2708
|
IntentSettlementError,
|
|
2631
2709
|
IntentsSDK,
|
|
2632
2710
|
MinWithdrawalAmountError,
|
|
2711
|
+
OmniTokenNormalisationCheckError,
|
|
2633
2712
|
OmniTransferDestinationChainHashNotFoundError,
|
|
2634
2713
|
OmniTransferNotFoundError,
|
|
2635
2714
|
PoaWithdrawalInvariantError,
|
package/dist/index.d.cts
CHANGED
|
@@ -134,6 +134,7 @@ type ProcessWithdrawalArgs<T extends WithdrawalParams | WithdrawalParams[]> = {
|
|
|
134
134
|
onBeforePublishIntent?: OnBeforePublishIntentHook;
|
|
135
135
|
};
|
|
136
136
|
referral?: string;
|
|
137
|
+
retryOptions?: RetryOptions;
|
|
137
138
|
logger?: ILogger;
|
|
138
139
|
};
|
|
139
140
|
interface IIntentsSDK {
|
|
@@ -531,5 +532,15 @@ declare class TokenNotSupportedByOmniRelayerError extends BaseError {
|
|
|
531
532
|
token: string;
|
|
532
533
|
constructor(token: string);
|
|
533
534
|
}
|
|
535
|
+
type OmniTokenNormalisationCheckErrorType = OmniTokenNormalisationCheckError & {
|
|
536
|
+
name: "OmniTokenNormalisationCheckError";
|
|
537
|
+
};
|
|
538
|
+
declare class OmniTokenNormalisationCheckError extends BaseError {
|
|
539
|
+
tokenIn: string;
|
|
540
|
+
destinationToken: string;
|
|
541
|
+
minAmount: bigint;
|
|
542
|
+
fee: bigint;
|
|
543
|
+
constructor(tokenIn: string, destinationToken: string, minAmount: bigint, fee: bigint);
|
|
544
|
+
}
|
|
534
545
|
|
|
535
|
-
export { type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, type IIntentSigner, type IntentPayload, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, type IntentSettlementStatus, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, type ProcessWithdrawalArgs, type RouteConfig, RouteEnum, type RouteEnumValues, type SignAndSendWithdrawalArgs, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TokenNotSupportedByOmniRelayerError, type TokenNotSupportedByOmniRelayerErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
|
546
|
+
export { type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, type IIntentSigner, type IntentPayload, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, type IntentSettlementStatus, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTokenNormalisationCheckError, type OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, type ProcessWithdrawalArgs, type RouteConfig, RouteEnum, type RouteEnumValues, type SignAndSendWithdrawalArgs, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TokenNotSupportedByOmniRelayerError, type TokenNotSupportedByOmniRelayerErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
package/dist/index.d.ts
CHANGED
|
@@ -134,6 +134,7 @@ type ProcessWithdrawalArgs<T extends WithdrawalParams | WithdrawalParams[]> = {
|
|
|
134
134
|
onBeforePublishIntent?: OnBeforePublishIntentHook;
|
|
135
135
|
};
|
|
136
136
|
referral?: string;
|
|
137
|
+
retryOptions?: RetryOptions;
|
|
137
138
|
logger?: ILogger;
|
|
138
139
|
};
|
|
139
140
|
interface IIntentsSDK {
|
|
@@ -531,5 +532,15 @@ declare class TokenNotSupportedByOmniRelayerError extends BaseError {
|
|
|
531
532
|
token: string;
|
|
532
533
|
constructor(token: string);
|
|
533
534
|
}
|
|
535
|
+
type OmniTokenNormalisationCheckErrorType = OmniTokenNormalisationCheckError & {
|
|
536
|
+
name: "OmniTokenNormalisationCheckError";
|
|
537
|
+
};
|
|
538
|
+
declare class OmniTokenNormalisationCheckError extends BaseError {
|
|
539
|
+
tokenIn: string;
|
|
540
|
+
destinationToken: string;
|
|
541
|
+
minAmount: bigint;
|
|
542
|
+
fee: bigint;
|
|
543
|
+
constructor(tokenIn: string, destinationToken: string, minAmount: bigint, fee: bigint);
|
|
544
|
+
}
|
|
534
545
|
|
|
535
|
-
export { type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, type IIntentSigner, type IntentPayload, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, type IntentSettlementStatus, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, type ProcessWithdrawalArgs, type RouteConfig, RouteEnum, type RouteEnumValues, type SignAndSendWithdrawalArgs, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TokenNotSupportedByOmniRelayerError, type TokenNotSupportedByOmniRelayerErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
|
546
|
+
export { type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, type IIntentSigner, type IntentPayload, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, type IntentSettlementStatus, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTokenNormalisationCheckError, type OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, type ProcessWithdrawalArgs, type RouteConfig, RouteEnum, type RouteEnumValues, type SignAndSendWithdrawalArgs, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TokenNotSupportedByOmniRelayerError, type TokenNotSupportedByOmniRelayerErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
package/dist/index.js
CHANGED
|
@@ -926,9 +926,12 @@ import {
|
|
|
926
926
|
OmniBridgeAPI,
|
|
927
927
|
getBridgedToken,
|
|
928
928
|
getChain,
|
|
929
|
+
getMinimumTransferableAmount,
|
|
930
|
+
getTokenDecimals,
|
|
929
931
|
isEvmChain,
|
|
930
932
|
omniAddress as omniAddress2,
|
|
931
|
-
parseOriginChain
|
|
933
|
+
parseOriginChain,
|
|
934
|
+
verifyTransferAmount
|
|
932
935
|
} from "omni-bridge-sdk";
|
|
933
936
|
|
|
934
937
|
// src/bridges/omni-bridge/error.ts
|
|
@@ -980,6 +983,26 @@ var TokenNotSupportedByOmniRelayerError = class extends BaseError3 {
|
|
|
980
983
|
this.token = token;
|
|
981
984
|
}
|
|
982
985
|
};
|
|
986
|
+
var OmniTokenNormalisationCheckError = class extends BaseError3 {
|
|
987
|
+
constructor(tokenIn, destinationToken, minAmount, fee) {
|
|
988
|
+
super(
|
|
989
|
+
`Transfer amount sent to relayer is too small - would result in 0 after decimal normalisation. Minimum transferable amount if feeInclusive=false is >= ${minAmount}. Minimum transferable amount if feeInclusive=true is >= ${minAmount + fee}.`,
|
|
990
|
+
{
|
|
991
|
+
metaMessages: [
|
|
992
|
+
`TokenIn: ${tokenIn}`,
|
|
993
|
+
`DestinationToken: ${destinationToken}`,
|
|
994
|
+
`MinAmount: ${minAmount}`,
|
|
995
|
+
`fee: ${fee}`
|
|
996
|
+
],
|
|
997
|
+
name: "OmniTokenNormalisationCheckError"
|
|
998
|
+
}
|
|
999
|
+
);
|
|
1000
|
+
this.tokenIn = tokenIn;
|
|
1001
|
+
this.destinationToken = destinationToken;
|
|
1002
|
+
this.minAmount = minAmount;
|
|
1003
|
+
this.fee = fee;
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
983
1006
|
|
|
984
1007
|
// src/bridges/omni-bridge/omni-bridge-constants.ts
|
|
985
1008
|
var NEAR_NATIVE_ASSET_ID3 = "nep141:wrap.near";
|
|
@@ -987,7 +1010,7 @@ var OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
|
|
|
987
1010
|
|
|
988
1011
|
// src/bridges/omni-bridge/omni-bridge-utils.ts
|
|
989
1012
|
import { assert as assert8, utils as utils7 } from "@defuse-protocol/internal-utils";
|
|
990
|
-
import { ChainKind, omniAddress } from "omni-bridge-sdk";
|
|
1013
|
+
import { ChainKind, omniAddress, isBridgeToken } from "omni-bridge-sdk";
|
|
991
1014
|
function createWithdrawIntentPrimitive3(params) {
|
|
992
1015
|
const { contractId: tokenAccountId, standard } = utils7.parseDefuseAssetId(
|
|
993
1016
|
params.assetId
|
|
@@ -1038,15 +1061,9 @@ function chainKindToCaip2(network) {
|
|
|
1038
1061
|
return null;
|
|
1039
1062
|
}
|
|
1040
1063
|
}
|
|
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
1064
|
function validateOmniToken(nearAddress) {
|
|
1049
|
-
|
|
1065
|
+
if (nearAddress.endsWith(".testnet")) return false;
|
|
1066
|
+
return isBridgeToken(nearAddress);
|
|
1050
1067
|
}
|
|
1051
1068
|
|
|
1052
1069
|
// src/bridges/omni-bridge/omni-bridge.ts
|
|
@@ -1059,6 +1076,10 @@ var OmniBridge = class {
|
|
|
1059
1076
|
this.storageDepositCache = new TTLCache({ ttl: 108e5 });
|
|
1060
1077
|
// 10800000 - 3 hours
|
|
1061
1078
|
this.destinationChainAddressCache = new TTLCache({ ttl: 108e5 });
|
|
1079
|
+
// 10800000 - 3 hours
|
|
1080
|
+
this.tokenDecimalsCache = new TTLCache({
|
|
1081
|
+
ttl: 108e5
|
|
1082
|
+
});
|
|
1062
1083
|
this.env = env;
|
|
1063
1084
|
this.nearProvider = nearProvider;
|
|
1064
1085
|
this.omniBridgeAPI = new OmniBridgeAPI();
|
|
@@ -1209,6 +1230,51 @@ var OmniBridge = class {
|
|
|
1209
1230
|
args.feeEstimation.amount > 0n,
|
|
1210
1231
|
`Fee must be greater than zero. Current fee is ${args.feeEstimation.amount}.`
|
|
1211
1232
|
);
|
|
1233
|
+
const assetInfo = this.makeAssetInfo(args.assetId, args.routeConfig);
|
|
1234
|
+
assert9(
|
|
1235
|
+
assetInfo !== null,
|
|
1236
|
+
`Asset ${args.assetId} is not supported by Omni Bridge`
|
|
1237
|
+
);
|
|
1238
|
+
const omniChainKind = caip2ToChainKind(assetInfo.blockchain);
|
|
1239
|
+
assert9(
|
|
1240
|
+
omniChainKind !== null,
|
|
1241
|
+
`Chain ${assetInfo.blockchain} is not supported by Omni Bridge`
|
|
1242
|
+
);
|
|
1243
|
+
const destTokenAddress = await this.getCachedDestinationTokenAddress(
|
|
1244
|
+
assetInfo.contractId,
|
|
1245
|
+
omniChainKind
|
|
1246
|
+
);
|
|
1247
|
+
if (destTokenAddress === null) {
|
|
1248
|
+
throw new TokenNotFoundInDestinationChainError(
|
|
1249
|
+
args.assetId,
|
|
1250
|
+
assetInfo.blockchain
|
|
1251
|
+
);
|
|
1252
|
+
}
|
|
1253
|
+
const decimals = await this.getCachedTokenDecimals(destTokenAddress);
|
|
1254
|
+
assert9(
|
|
1255
|
+
decimals !== null,
|
|
1256
|
+
`Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
|
|
1257
|
+
Ensure the token is supported and the address is correct.`
|
|
1258
|
+
);
|
|
1259
|
+
const normalisationCheckSucceeded = verifyTransferAmount(
|
|
1260
|
+
// args.amount is without fee, we need to pass an amount being sent to relayer so we add fee here
|
|
1261
|
+
args.amount + args.feeEstimation.amount,
|
|
1262
|
+
args.feeEstimation.amount,
|
|
1263
|
+
decimals.origin_decimals,
|
|
1264
|
+
decimals.decimals
|
|
1265
|
+
);
|
|
1266
|
+
if (normalisationCheckSucceeded === false) {
|
|
1267
|
+
const minAmount = getMinimumTransferableAmount(
|
|
1268
|
+
decimals.origin_decimals,
|
|
1269
|
+
decimals.decimals
|
|
1270
|
+
);
|
|
1271
|
+
throw new OmniTokenNormalisationCheckError(
|
|
1272
|
+
args.assetId,
|
|
1273
|
+
destTokenAddress,
|
|
1274
|
+
minAmount,
|
|
1275
|
+
args.feeEstimation.amount
|
|
1276
|
+
);
|
|
1277
|
+
}
|
|
1212
1278
|
return;
|
|
1213
1279
|
}
|
|
1214
1280
|
async estimateWithdrawalFee(args) {
|
|
@@ -1272,7 +1338,8 @@ var OmniBridge = class {
|
|
|
1272
1338
|
offset: args.index,
|
|
1273
1339
|
limit: 1
|
|
1274
1340
|
}))[0];
|
|
1275
|
-
if (
|
|
1341
|
+
if (transfer == null || transfer.transfer_message == null)
|
|
1342
|
+
throw new OmniTransferNotFoundError(args.tx.hash);
|
|
1276
1343
|
const destinationChain = getChain(
|
|
1277
1344
|
transfer.transfer_message.recipient
|
|
1278
1345
|
);
|
|
@@ -1303,7 +1370,6 @@ var OmniBridge = class {
|
|
|
1303
1370
|
}
|
|
1304
1371
|
/**
|
|
1305
1372
|
* Gets storage deposit for a token to avoid frequent RPC calls.
|
|
1306
|
-
* Cache expires after one day using TTL cache.
|
|
1307
1373
|
*/
|
|
1308
1374
|
async getCachedStorageDepositValue(contractId) {
|
|
1309
1375
|
const cached = this.storageDepositCache.get(contractId);
|
|
@@ -1326,7 +1392,6 @@ var OmniBridge = class {
|
|
|
1326
1392
|
}
|
|
1327
1393
|
/**
|
|
1328
1394
|
* Gets cached token address on destination chain.
|
|
1329
|
-
* Cache expires after one day using TTL cache.
|
|
1330
1395
|
*/
|
|
1331
1396
|
async getCachedDestinationTokenAddress(contractId, omniChainKind) {
|
|
1332
1397
|
const key = `${omniChainKind}:${contractId}`;
|
|
@@ -1341,6 +1406,21 @@ var OmniBridge = class {
|
|
|
1341
1406
|
this.destinationChainAddressCache.set(key, tokenOnDestinationNetwork);
|
|
1342
1407
|
return tokenOnDestinationNetwork;
|
|
1343
1408
|
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Gets cached token decimals on destination chain and on near.
|
|
1411
|
+
*/
|
|
1412
|
+
async getCachedTokenDecimals(omniAddress3) {
|
|
1413
|
+
const cached = this.tokenDecimalsCache.get(omniAddress3);
|
|
1414
|
+
if (cached !== void 0) {
|
|
1415
|
+
return cached;
|
|
1416
|
+
}
|
|
1417
|
+
const tokenDecimals = await getTokenDecimals(
|
|
1418
|
+
OMNI_BRIDGE_CONTRACT,
|
|
1419
|
+
omniAddress3
|
|
1420
|
+
);
|
|
1421
|
+
this.tokenDecimalsCache.set(omniAddress3, tokenDecimals);
|
|
1422
|
+
return tokenDecimals;
|
|
1423
|
+
}
|
|
1344
1424
|
};
|
|
1345
1425
|
|
|
1346
1426
|
// src/bridges/poa-bridge/poa-bridge.ts
|
|
@@ -2466,8 +2546,8 @@ var IntentsSDK = class {
|
|
|
2466
2546
|
const destinationTx = await this.waitForWithdrawalCompletion({
|
|
2467
2547
|
withdrawalParams,
|
|
2468
2548
|
intentTx,
|
|
2469
|
-
|
|
2470
|
-
|
|
2549
|
+
retryOptions: args.retryOptions ?? RETRY_CONFIGS3.FIVE_MINS_STEADY,
|
|
2550
|
+
logger: args.logger
|
|
2471
2551
|
});
|
|
2472
2552
|
if (!Array.isArray(args.withdrawalParams)) {
|
|
2473
2553
|
return {
|
|
@@ -2622,6 +2702,7 @@ export {
|
|
|
2622
2702
|
IntentSettlementError,
|
|
2623
2703
|
IntentsSDK,
|
|
2624
2704
|
MinWithdrawalAmountError,
|
|
2705
|
+
OmniTokenNormalisationCheckError,
|
|
2625
2706
|
OmniTransferDestinationChainHashNotFoundError,
|
|
2626
2707
|
OmniTransferNotFoundError,
|
|
2627
2708
|
PoaWithdrawalInvariantError,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"@hot-labs/omni-sdk": "2.20.2",
|
|
26
26
|
"@isaacs/ttlcache": "^1.0.0",
|
|
27
27
|
"@lifeomic/attempt": "^3.0.0",
|
|
28
|
+
"@near-js/accounts": "^2.0.1",
|
|
29
|
+
"@near-js/client": "^2.0.1",
|
|
30
|
+
"@near-js/keystores": "^2.0.1",
|
|
28
31
|
"@scure/base": "^1.0.0",
|
|
29
32
|
"borsher": "^4.0.0",
|
|
30
33
|
"near-api-js": "^4.0.0 || ^5.0.0",
|
|
34
|
+
"omni-bridge-sdk": "0.17.5",
|
|
31
35
|
"viem": "^2.0.0",
|
|
32
|
-
"omni-bridge-sdk": "0.13.1",
|
|
33
|
-
"@near-js/client": "^2.0.1",
|
|
34
|
-
"@near-js/accounts": "^2.0.1",
|
|
35
|
-
"@near-js/keystores": "^2.0.1",
|
|
36
36
|
"@defuse-protocol/contract-types": "0.1.0",
|
|
37
|
-
"@defuse-protocol/internal-utils": "0.
|
|
37
|
+
"@defuse-protocol/internal-utils": "0.11.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"tsup": "^8.5.0",
|