@defuse-protocol/intents-sdk 0.15.0 → 0.16.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/README.md +10 -1
- package/dist/index.cjs +105 -5
- package/dist/index.d.cts +34 -1
- package/dist/index.d.ts +34 -1
- package/dist/index.js +101 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -154,6 +154,7 @@ Examples:
|
|
|
154
154
|
- `nep141:wrap.near` - Wrapped NEAR (native NEAR)
|
|
155
155
|
- `nep245:v2_1.omni.hot.tg:137_qiStmoQJDQPTebaPjgx5VBxZv6L` - Polygon USDC through Hot
|
|
156
156
|
- `nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near` - Base USDC through PoA
|
|
157
|
+
- `nep141:sol.omdep.near` - SOL bridged through Omni Bridge
|
|
157
158
|
|
|
158
159
|
### Intent Execution
|
|
159
160
|
|
|
@@ -190,7 +191,7 @@ Deposit funds into Near Intents *(Coming Soon)*.
|
|
|
190
191
|
Complete withdrawal functionality from Near Intents to external chains:
|
|
191
192
|
|
|
192
193
|
- **Cross-Chain Transfers**: Withdraw to 20+ supported blockchains
|
|
193
|
-
- **Multi-Bridge Support**: Hot Bridge, PoA Bridge
|
|
194
|
+
- **Multi-Bridge Support**: Hot Bridge, PoA Bridge, Omni Bridge
|
|
194
195
|
- **Batch Processing**: Process multiple withdrawals at a time
|
|
195
196
|
- **Fee Management**: Automatic fee estimation with quote support
|
|
196
197
|
- **Validation**: Built-in validation for withdrawal constraints
|
|
@@ -222,6 +223,7 @@ import {RouteEnum} from '@defuse-protocol/intents-sdk';
|
|
|
222
223
|
|
|
223
224
|
console.log(RouteEnum.HotBridge); // "hot_bridge" - Cross-chain via HOT protocol
|
|
224
225
|
console.log(RouteEnum.PoaBridge); // "poa_bridge" - Cross-chain via PoA bridge
|
|
226
|
+
console.log(RouteEnum.OmniBridge); // "omni_bridge" - Cross-chain via Omni bridge
|
|
225
227
|
console.log(RouteEnum.NearWithdrawal); // "near_withdrawal" - Direct to NEAR blockchain
|
|
226
228
|
console.log(RouteEnum.VirtualChain); // "virtual_chain" - To Aurora Engine chains
|
|
227
229
|
console.log(RouteEnum.InternalTransfer); // "internal_transfer" - Between protocol users
|
|
@@ -237,6 +239,7 @@ import {BridgeNameEnum} from '@defuse-protocol/intents-sdk';
|
|
|
237
239
|
|
|
238
240
|
console.log(BridgeNameEnum.Hot); // "hot" - HOT Labs bridge infrastructure
|
|
239
241
|
console.log(BridgeNameEnum.Poa); // "poa" - Proof-of-Authority bridge by Defuse Labs
|
|
242
|
+
console.log(BridgeNameEnum.Omni); // "omni" - Omni bridge by NEAR
|
|
240
243
|
console.log(BridgeNameEnum.None); // null - No external bridge (NEAR-native or internal)
|
|
241
244
|
```
|
|
242
245
|
|
|
@@ -266,6 +269,12 @@ The SDK automatically detects and supports multiple route types based on asset i
|
|
|
266
269
|
- **Use Case**: Cross-chain transfers for assets bridged through PoA protocol
|
|
267
270
|
- **Route Type**: `poa_bridge`
|
|
268
271
|
|
|
272
|
+
##### Omni Bridge Route
|
|
273
|
+
- **Purpose**: multi-chain asset bridge developed by Near
|
|
274
|
+
- **Supported Assets**: Fungible tokens (NEP-141) supported by omni bridge relayer.
|
|
275
|
+
- **Use Case**: multi-chain transfers for supported list of chains
|
|
276
|
+
- **Route Type**: `omni_bridge`
|
|
277
|
+
|
|
269
278
|
##### Internal Transfer Route
|
|
270
279
|
|
|
271
280
|
- **Purpose**: Transfer between Near Intents users within the protocol
|
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,8 @@ __export(index_exports, {
|
|
|
42
42
|
IntentSettlementError: () => import_internal_utils25.IntentSettlementError,
|
|
43
43
|
IntentsSDK: () => IntentsSDK,
|
|
44
44
|
MinWithdrawalAmountError: () => MinWithdrawalAmountError,
|
|
45
|
+
OmniTransferDestinationChainHashNotFoundError: () => OmniTransferDestinationChainHashNotFoundError,
|
|
46
|
+
OmniTransferNotFoundError: () => OmniTransferNotFoundError,
|
|
45
47
|
PoaWithdrawalInvariantError: () => import_internal_utils22.PoaWithdrawalInvariantError,
|
|
46
48
|
PoaWithdrawalNotFoundError: () => import_internal_utils22.PoaWithdrawalNotFoundError,
|
|
47
49
|
PoaWithdrawalPendingError: () => import_internal_utils22.PoaWithdrawalPendingError,
|
|
@@ -50,6 +52,8 @@ __export(index_exports, {
|
|
|
50
52
|
RouteEnum: () => RouteEnum,
|
|
51
53
|
RpcRequestError: () => import_internal_utils23.RpcRequestError,
|
|
52
54
|
TimeoutError: () => import_internal_utils23.TimeoutError,
|
|
55
|
+
TokenNotFoundInDestinationChainError: () => TokenNotFoundInDestinationChainError,
|
|
56
|
+
TokenNotSupportedByOmniRelayerError: () => TokenNotSupportedByOmniRelayerError,
|
|
53
57
|
TrustlineNotFoundError: () => TrustlineNotFoundError,
|
|
54
58
|
UnsupportedDestinationMemoError: () => UnsupportedDestinationMemoError,
|
|
55
59
|
createDefaultRoute: () => createDefaultRoute,
|
|
@@ -59,6 +63,7 @@ __export(index_exports, {
|
|
|
59
63
|
createIntentSignerViem: () => createIntentSignerViem,
|
|
60
64
|
createInternalTransferRoute: () => createInternalTransferRoute,
|
|
61
65
|
createNearWithdrawalRoute: () => createNearWithdrawalRoute,
|
|
66
|
+
createOmniWithdrawalRoute: () => createOmniWithdrawalRoute,
|
|
62
67
|
createPoaBridgeRoute: () => createPoaBridgeRoute,
|
|
63
68
|
createVirtualChainRoute: () => createVirtualChainRoute
|
|
64
69
|
});
|
|
@@ -751,7 +756,7 @@ var HotBridge = class {
|
|
|
751
756
|
}
|
|
752
757
|
if (typeof status === "string") {
|
|
753
758
|
return {
|
|
754
|
-
hash: "chain" in args.routeConfig ? formatTxHash(status, args.routeConfig.chain) : status
|
|
759
|
+
hash: "chain" in args.routeConfig && args.routeConfig.chain !== void 0 ? formatTxHash(status, args.routeConfig.chain) : status
|
|
755
760
|
};
|
|
756
761
|
}
|
|
757
762
|
throw new HotWithdrawalPendingError(args.tx.hash, args.index);
|
|
@@ -850,6 +855,18 @@ var TokenNotSupportedByOmniRelayerError = class extends import_internal_utils10.
|
|
|
850
855
|
this.token = token;
|
|
851
856
|
}
|
|
852
857
|
};
|
|
858
|
+
var TokenNotFoundInDestinationChainError = class extends import_internal_utils10.BaseError {
|
|
859
|
+
constructor(token, chainKind) {
|
|
860
|
+
super(
|
|
861
|
+
`The token ${token} doesn't exist in destination network ${chainKind}`,
|
|
862
|
+
{
|
|
863
|
+
metaMessages: [`Token: ${token}`, `Destination Chain: ${chainKind}`],
|
|
864
|
+
name: "TokenNotFoundInDestinationChainError"
|
|
865
|
+
}
|
|
866
|
+
);
|
|
867
|
+
this.token = token;
|
|
868
|
+
}
|
|
869
|
+
};
|
|
853
870
|
|
|
854
871
|
// src/bridges/omni-bridge/omni-bridge-constants.ts
|
|
855
872
|
var NEAR_NATIVE_ASSET_ID3 = "nep141:wrap.near";
|
|
@@ -879,6 +896,22 @@ function createWithdrawIntentPrimitive3(params) {
|
|
|
879
896
|
})
|
|
880
897
|
};
|
|
881
898
|
}
|
|
899
|
+
function targetChainSupportedByOmniBridge(network) {
|
|
900
|
+
switch (network) {
|
|
901
|
+
case Chains.Ethereum:
|
|
902
|
+
return true;
|
|
903
|
+
case Chains.Base:
|
|
904
|
+
return true;
|
|
905
|
+
case Chains.Arbitrum:
|
|
906
|
+
return true;
|
|
907
|
+
case Chains.Solana:
|
|
908
|
+
return true;
|
|
909
|
+
case Chains.Bitcoin:
|
|
910
|
+
return true;
|
|
911
|
+
default:
|
|
912
|
+
return false;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
882
915
|
function caip2ToChainKind(network) {
|
|
883
916
|
switch (network) {
|
|
884
917
|
case Chains.Ethereum:
|
|
@@ -922,6 +955,8 @@ var _OmniBridge = class _OmniBridge {
|
|
|
922
955
|
this.storageDepositCache = new import_ttlcache.default({ ttl: 864e5 });
|
|
923
956
|
// TTL cache for supported tokens with 30-second TTL
|
|
924
957
|
this.supportedTokensCache = new import_ttlcache.default({ ttl: 864e5 });
|
|
958
|
+
// 86400000 - 1 day
|
|
959
|
+
this.destinationChainAddressCache = new import_ttlcache.default({ ttl: 864e5 });
|
|
925
960
|
this.env = env;
|
|
926
961
|
this.nearProvider = nearProvider;
|
|
927
962
|
this.omniBridgeAPI = new import_omni_bridge_sdk2.OmniBridgeAPI();
|
|
@@ -931,11 +966,19 @@ var _OmniBridge = class _OmniBridge {
|
|
|
931
966
|
}
|
|
932
967
|
supports(params) {
|
|
933
968
|
try {
|
|
969
|
+
if (this.targetChainSpecified(params.routeConfig)) {
|
|
970
|
+
return targetChainSupportedByOmniBridge(params.routeConfig.chain);
|
|
971
|
+
}
|
|
934
972
|
return this.parseAssetId(params.assetId) !== null;
|
|
935
973
|
} catch {
|
|
936
974
|
return false;
|
|
937
975
|
}
|
|
938
976
|
}
|
|
977
|
+
targetChainSpecified(routeConfig) {
|
|
978
|
+
return Boolean(
|
|
979
|
+
routeConfig?.route && routeConfig.route === RouteEnum.OmniBridge && routeConfig.chain
|
|
980
|
+
);
|
|
981
|
+
}
|
|
939
982
|
parseAssetId(assetId) {
|
|
940
983
|
const parsed = import_internal_utils12.utils.parseDefuseAssetId(assetId);
|
|
941
984
|
if (parsed.standard !== "nep141") return null;
|
|
@@ -947,8 +990,39 @@ var _OmniBridge = class _OmniBridge {
|
|
|
947
990
|
address: parsed.contractId
|
|
948
991
|
});
|
|
949
992
|
}
|
|
950
|
-
|
|
951
|
-
const
|
|
993
|
+
async tokenSupported(assetId, routeConfig) {
|
|
994
|
+
const parsed = import_internal_utils12.utils.parseDefuseAssetId(assetId);
|
|
995
|
+
if (parsed.standard !== "nep141") return null;
|
|
996
|
+
if (this.targetChainSpecified(routeConfig)) {
|
|
997
|
+
const tokenOnDestinationNetwork = await this.getCachedDestinationTokenAddress(
|
|
998
|
+
parsed.contractId,
|
|
999
|
+
routeConfig.chain
|
|
1000
|
+
);
|
|
1001
|
+
if (tokenOnDestinationNetwork === null) {
|
|
1002
|
+
throw new TokenNotFoundInDestinationChainError(
|
|
1003
|
+
assetId,
|
|
1004
|
+
routeConfig.chain
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
return Object.assign(parsed, {
|
|
1008
|
+
blockchain: routeConfig.chain,
|
|
1009
|
+
bridgeName: BridgeNameEnum.Omni,
|
|
1010
|
+
address: parsed.contractId
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
const chain = (0, import_omni_bridge_sdk2.parseOriginChain)(parsed.contractId);
|
|
1014
|
+
if (chain === null) return null;
|
|
1015
|
+
return Object.assign(parsed, {
|
|
1016
|
+
blockchain: chainKindToCaip2(chain),
|
|
1017
|
+
bridgeName: BridgeNameEnum.Omni,
|
|
1018
|
+
address: parsed.contractId
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
async createWithdrawalIntents(args) {
|
|
1022
|
+
const assetInfo = await this.tokenSupported(
|
|
1023
|
+
args.withdrawalParams.assetId,
|
|
1024
|
+
args.withdrawalParams.routeConfig
|
|
1025
|
+
);
|
|
952
1026
|
(0, import_internal_utils12.assert)(
|
|
953
1027
|
assetInfo !== null,
|
|
954
1028
|
`Asset ${args.withdrawalParams.assetId} is not supported`
|
|
@@ -976,7 +1050,7 @@ var _OmniBridge = class _OmniBridge {
|
|
|
976
1050
|
return Promise.resolve(intents);
|
|
977
1051
|
}
|
|
978
1052
|
async validateWithdrawal(args) {
|
|
979
|
-
const assetInfo = this.
|
|
1053
|
+
const assetInfo = await this.tokenSupported(args.assetId, args.routeConfig);
|
|
980
1054
|
(0, import_internal_utils12.assert)(assetInfo !== null, `Asset ${args.assetId} is not supported`);
|
|
981
1055
|
const supportedTokens = await this.getCachedSupportedTokens();
|
|
982
1056
|
if (!supportedTokens[assetInfo.contractId]) {
|
|
@@ -989,7 +1063,10 @@ var _OmniBridge = class _OmniBridge {
|
|
|
989
1063
|
return;
|
|
990
1064
|
}
|
|
991
1065
|
async estimateWithdrawalFee(args) {
|
|
992
|
-
const assetInfo = this.
|
|
1066
|
+
const assetInfo = await this.tokenSupported(
|
|
1067
|
+
args.withdrawalParams.assetId,
|
|
1068
|
+
args.withdrawalParams.routeConfig
|
|
1069
|
+
);
|
|
993
1070
|
(0, import_internal_utils12.assert)(
|
|
994
1071
|
assetInfo !== null,
|
|
995
1072
|
`Asset ${args.withdrawalParams.assetId} is not supported`
|
|
@@ -1110,6 +1187,23 @@ var _OmniBridge = class _OmniBridge {
|
|
|
1110
1187
|
this.supportedTokensCache.set(_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY, data);
|
|
1111
1188
|
return data;
|
|
1112
1189
|
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Gets cached token address on destination chain.
|
|
1192
|
+
* Cache expires after one day using TTL cache.
|
|
1193
|
+
*/
|
|
1194
|
+
async getCachedDestinationTokenAddress(contractId, chain) {
|
|
1195
|
+
const key = `${chain}:${contractId}`;
|
|
1196
|
+
const cached = this.destinationChainAddressCache.get(key);
|
|
1197
|
+
if (cached != null) {
|
|
1198
|
+
return cached;
|
|
1199
|
+
}
|
|
1200
|
+
const tokenOnDestinationNetwork = await (0, import_omni_bridge_sdk2.getBridgedToken)(
|
|
1201
|
+
(0, import_omni_bridge_sdk2.omniAddress)(import_omni_bridge_sdk2.ChainKind.Near, contractId),
|
|
1202
|
+
caip2ToChainKind(chain)
|
|
1203
|
+
);
|
|
1204
|
+
this.destinationChainAddressCache.set(key, tokenOnDestinationNetwork);
|
|
1205
|
+
return tokenOnDestinationNetwork;
|
|
1206
|
+
}
|
|
1113
1207
|
};
|
|
1114
1208
|
// 86400000 - 1 day
|
|
1115
1209
|
_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY = "SUPPORTED_TOKENS_CACHE_KEY";
|
|
@@ -1996,6 +2090,7 @@ var IntentsSDK = class {
|
|
|
1996
2090
|
amount: actualAmount,
|
|
1997
2091
|
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
1998
2092
|
feeEstimation: args.feeEstimation,
|
|
2093
|
+
routeConfig: args.withdrawalParams.routeConfig,
|
|
1999
2094
|
logger: args.logger
|
|
2000
2095
|
});
|
|
2001
2096
|
return bridge.createWithdrawalIntents({
|
|
@@ -2358,6 +2453,8 @@ var import_internal_utils25 = require("@defuse-protocol/internal-utils");
|
|
|
2358
2453
|
IntentSettlementError,
|
|
2359
2454
|
IntentsSDK,
|
|
2360
2455
|
MinWithdrawalAmountError,
|
|
2456
|
+
OmniTransferDestinationChainHashNotFoundError,
|
|
2457
|
+
OmniTransferNotFoundError,
|
|
2361
2458
|
PoaWithdrawalInvariantError,
|
|
2362
2459
|
PoaWithdrawalNotFoundError,
|
|
2363
2460
|
PoaWithdrawalPendingError,
|
|
@@ -2366,6 +2463,8 @@ var import_internal_utils25 = require("@defuse-protocol/internal-utils");
|
|
|
2366
2463
|
RouteEnum,
|
|
2367
2464
|
RpcRequestError,
|
|
2368
2465
|
TimeoutError,
|
|
2466
|
+
TokenNotFoundInDestinationChainError,
|
|
2467
|
+
TokenNotSupportedByOmniRelayerError,
|
|
2369
2468
|
TrustlineNotFoundError,
|
|
2370
2469
|
UnsupportedDestinationMemoError,
|
|
2371
2470
|
createDefaultRoute,
|
|
@@ -2375,6 +2474,7 @@ var import_internal_utils25 = require("@defuse-protocol/internal-utils");
|
|
|
2375
2474
|
createIntentSignerViem,
|
|
2376
2475
|
createInternalTransferRoute,
|
|
2377
2476
|
createNearWithdrawalRoute,
|
|
2477
|
+
createOmniWithdrawalRoute,
|
|
2378
2478
|
createPoaBridgeRoute,
|
|
2379
2479
|
createVirtualChainRoute
|
|
2380
2480
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -229,6 +229,7 @@ type HotBridgeRouteConfig = {
|
|
|
229
229
|
};
|
|
230
230
|
type OmniBridgeRouteConfig = {
|
|
231
231
|
route: RouteEnum["OmniBridge"];
|
|
232
|
+
chain?: Chain;
|
|
232
233
|
};
|
|
233
234
|
type RouteConfig = NearWithdrawalRouteConfig | InternalTransferRouteConfig | VirtualChainRouteConfig | PoaBridgeRouteConfig | HotBridgeRouteConfig | OmniBridgeRouteConfig;
|
|
234
235
|
interface FeeEstimation {
|
|
@@ -252,6 +253,7 @@ interface Bridge {
|
|
|
252
253
|
amount: bigint;
|
|
253
254
|
destinationAddress: string;
|
|
254
255
|
feeEstimation: FeeEstimation;
|
|
256
|
+
routeConfig?: RouteConfig;
|
|
255
257
|
logger?: ILogger;
|
|
256
258
|
}): Promise<void>;
|
|
257
259
|
estimateWithdrawalFee<T extends Pick<WithdrawalParams, "assetId" | "destinationAddress" | "routeConfig">>(args: {
|
|
@@ -425,6 +427,7 @@ declare function createIntentSignerViem(config: IntentSignerViemConfig): IIntent
|
|
|
425
427
|
|
|
426
428
|
declare function createInternalTransferRoute(): InternalTransferRouteConfig;
|
|
427
429
|
declare function createNearWithdrawalRoute(msg?: string): NearWithdrawalRouteConfig;
|
|
430
|
+
declare function createOmniWithdrawalRoute(): OmniBridgeRouteConfig;
|
|
428
431
|
declare function createVirtualChainRoute(auroraEngineContractId: string, proxyTokenContractId: string | null): VirtualChainRouteConfig;
|
|
429
432
|
declare function createPoaBridgeRoute(chain: Chain): PoaBridgeRouteConfig;
|
|
430
433
|
declare function createHotBridgeRoute(chain: Chain): HotBridgeRouteConfig;
|
|
@@ -491,4 +494,34 @@ declare class HotWithdrawalCancelledError extends BaseError {
|
|
|
491
494
|
constructor(txHash: string, index: number);
|
|
492
495
|
}
|
|
493
496
|
|
|
494
|
-
|
|
497
|
+
type OmniTransferNotFoundErrorType = OmniTransferNotFoundError & {
|
|
498
|
+
name: "OmniTransferNotFoundError";
|
|
499
|
+
};
|
|
500
|
+
declare class OmniTransferNotFoundError extends BaseError {
|
|
501
|
+
txHash: string;
|
|
502
|
+
constructor(txHash: string);
|
|
503
|
+
}
|
|
504
|
+
type OmniTransferDestinationChainHashNotFoundErrorType = OmniTransferDestinationChainHashNotFoundError & {
|
|
505
|
+
name: "OmniTransferDestinationChainHashNotFoundError";
|
|
506
|
+
};
|
|
507
|
+
declare class OmniTransferDestinationChainHashNotFoundError extends BaseError {
|
|
508
|
+
txHash: string;
|
|
509
|
+
destinationChain: string | undefined;
|
|
510
|
+
constructor(txHash: string, destinationChain: string | undefined);
|
|
511
|
+
}
|
|
512
|
+
type TokenNotSupportedByOmniRelayerErrorType = TokenNotSupportedByOmniRelayerError & {
|
|
513
|
+
name: "TokenNotSupportedByOmniRelayerError";
|
|
514
|
+
};
|
|
515
|
+
declare class TokenNotSupportedByOmniRelayerError extends BaseError {
|
|
516
|
+
token: string;
|
|
517
|
+
constructor(token: string);
|
|
518
|
+
}
|
|
519
|
+
type TokenNotFoundInDestinationChainErrorType = TokenNotFoundInDestinationChainError & {
|
|
520
|
+
name: "TokenNotFoundInDestinationChainError";
|
|
521
|
+
};
|
|
522
|
+
declare class TokenNotFoundInDestinationChainError extends BaseError {
|
|
523
|
+
token: string;
|
|
524
|
+
constructor(token: string, chainKind: Chain);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
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, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniWithdrawalRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
package/dist/index.d.ts
CHANGED
|
@@ -229,6 +229,7 @@ type HotBridgeRouteConfig = {
|
|
|
229
229
|
};
|
|
230
230
|
type OmniBridgeRouteConfig = {
|
|
231
231
|
route: RouteEnum["OmniBridge"];
|
|
232
|
+
chain?: Chain;
|
|
232
233
|
};
|
|
233
234
|
type RouteConfig = NearWithdrawalRouteConfig | InternalTransferRouteConfig | VirtualChainRouteConfig | PoaBridgeRouteConfig | HotBridgeRouteConfig | OmniBridgeRouteConfig;
|
|
234
235
|
interface FeeEstimation {
|
|
@@ -252,6 +253,7 @@ interface Bridge {
|
|
|
252
253
|
amount: bigint;
|
|
253
254
|
destinationAddress: string;
|
|
254
255
|
feeEstimation: FeeEstimation;
|
|
256
|
+
routeConfig?: RouteConfig;
|
|
255
257
|
logger?: ILogger;
|
|
256
258
|
}): Promise<void>;
|
|
257
259
|
estimateWithdrawalFee<T extends Pick<WithdrawalParams, "assetId" | "destinationAddress" | "routeConfig">>(args: {
|
|
@@ -425,6 +427,7 @@ declare function createIntentSignerViem(config: IntentSignerViemConfig): IIntent
|
|
|
425
427
|
|
|
426
428
|
declare function createInternalTransferRoute(): InternalTransferRouteConfig;
|
|
427
429
|
declare function createNearWithdrawalRoute(msg?: string): NearWithdrawalRouteConfig;
|
|
430
|
+
declare function createOmniWithdrawalRoute(): OmniBridgeRouteConfig;
|
|
428
431
|
declare function createVirtualChainRoute(auroraEngineContractId: string, proxyTokenContractId: string | null): VirtualChainRouteConfig;
|
|
429
432
|
declare function createPoaBridgeRoute(chain: Chain): PoaBridgeRouteConfig;
|
|
430
433
|
declare function createHotBridgeRoute(chain: Chain): HotBridgeRouteConfig;
|
|
@@ -491,4 +494,34 @@ declare class HotWithdrawalCancelledError extends BaseError {
|
|
|
491
494
|
constructor(txHash: string, index: number);
|
|
492
495
|
}
|
|
493
496
|
|
|
494
|
-
|
|
497
|
+
type OmniTransferNotFoundErrorType = OmniTransferNotFoundError & {
|
|
498
|
+
name: "OmniTransferNotFoundError";
|
|
499
|
+
};
|
|
500
|
+
declare class OmniTransferNotFoundError extends BaseError {
|
|
501
|
+
txHash: string;
|
|
502
|
+
constructor(txHash: string);
|
|
503
|
+
}
|
|
504
|
+
type OmniTransferDestinationChainHashNotFoundErrorType = OmniTransferDestinationChainHashNotFoundError & {
|
|
505
|
+
name: "OmniTransferDestinationChainHashNotFoundError";
|
|
506
|
+
};
|
|
507
|
+
declare class OmniTransferDestinationChainHashNotFoundError extends BaseError {
|
|
508
|
+
txHash: string;
|
|
509
|
+
destinationChain: string | undefined;
|
|
510
|
+
constructor(txHash: string, destinationChain: string | undefined);
|
|
511
|
+
}
|
|
512
|
+
type TokenNotSupportedByOmniRelayerErrorType = TokenNotSupportedByOmniRelayerError & {
|
|
513
|
+
name: "TokenNotSupportedByOmniRelayerError";
|
|
514
|
+
};
|
|
515
|
+
declare class TokenNotSupportedByOmniRelayerError extends BaseError {
|
|
516
|
+
token: string;
|
|
517
|
+
constructor(token: string);
|
|
518
|
+
}
|
|
519
|
+
type TokenNotFoundInDestinationChainErrorType = TokenNotFoundInDestinationChainError & {
|
|
520
|
+
name: "TokenNotFoundInDestinationChainError";
|
|
521
|
+
};
|
|
522
|
+
declare class TokenNotFoundInDestinationChainError extends BaseError {
|
|
523
|
+
token: string;
|
|
524
|
+
constructor(token: string, chainKind: Chain);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
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, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniWithdrawalRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
package/dist/index.js
CHANGED
|
@@ -712,7 +712,7 @@ var HotBridge = class {
|
|
|
712
712
|
}
|
|
713
713
|
if (typeof status === "string") {
|
|
714
714
|
return {
|
|
715
|
-
hash: "chain" in args.routeConfig ? formatTxHash(status, args.routeConfig.chain) : status
|
|
715
|
+
hash: "chain" in args.routeConfig && args.routeConfig.chain !== void 0 ? formatTxHash(status, args.routeConfig.chain) : status
|
|
716
716
|
};
|
|
717
717
|
}
|
|
718
718
|
throw new HotWithdrawalPendingError(args.tx.hash, args.index);
|
|
@@ -787,6 +787,7 @@ import { retry as retry2 } from "@lifeomic/attempt";
|
|
|
787
787
|
import {
|
|
788
788
|
ChainKind as ChainKind2,
|
|
789
789
|
OmniBridgeAPI,
|
|
790
|
+
getBridgedToken,
|
|
790
791
|
getChain,
|
|
791
792
|
isEvmChain,
|
|
792
793
|
omniAddress as omniAddress2,
|
|
@@ -826,6 +827,18 @@ var TokenNotSupportedByOmniRelayerError = class extends BaseError3 {
|
|
|
826
827
|
this.token = token;
|
|
827
828
|
}
|
|
828
829
|
};
|
|
830
|
+
var TokenNotFoundInDestinationChainError = class extends BaseError3 {
|
|
831
|
+
constructor(token, chainKind) {
|
|
832
|
+
super(
|
|
833
|
+
`The token ${token} doesn't exist in destination network ${chainKind}`,
|
|
834
|
+
{
|
|
835
|
+
metaMessages: [`Token: ${token}`, `Destination Chain: ${chainKind}`],
|
|
836
|
+
name: "TokenNotFoundInDestinationChainError"
|
|
837
|
+
}
|
|
838
|
+
);
|
|
839
|
+
this.token = token;
|
|
840
|
+
}
|
|
841
|
+
};
|
|
829
842
|
|
|
830
843
|
// src/bridges/omni-bridge/omni-bridge-constants.ts
|
|
831
844
|
var NEAR_NATIVE_ASSET_ID3 = "nep141:wrap.near";
|
|
@@ -855,6 +868,22 @@ function createWithdrawIntentPrimitive3(params) {
|
|
|
855
868
|
})
|
|
856
869
|
};
|
|
857
870
|
}
|
|
871
|
+
function targetChainSupportedByOmniBridge(network) {
|
|
872
|
+
switch (network) {
|
|
873
|
+
case Chains.Ethereum:
|
|
874
|
+
return true;
|
|
875
|
+
case Chains.Base:
|
|
876
|
+
return true;
|
|
877
|
+
case Chains.Arbitrum:
|
|
878
|
+
return true;
|
|
879
|
+
case Chains.Solana:
|
|
880
|
+
return true;
|
|
881
|
+
case Chains.Bitcoin:
|
|
882
|
+
return true;
|
|
883
|
+
default:
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
858
887
|
function caip2ToChainKind(network) {
|
|
859
888
|
switch (network) {
|
|
860
889
|
case Chains.Ethereum:
|
|
@@ -898,6 +927,8 @@ var _OmniBridge = class _OmniBridge {
|
|
|
898
927
|
this.storageDepositCache = new TTLCache({ ttl: 864e5 });
|
|
899
928
|
// TTL cache for supported tokens with 30-second TTL
|
|
900
929
|
this.supportedTokensCache = new TTLCache({ ttl: 864e5 });
|
|
930
|
+
// 86400000 - 1 day
|
|
931
|
+
this.destinationChainAddressCache = new TTLCache({ ttl: 864e5 });
|
|
901
932
|
this.env = env;
|
|
902
933
|
this.nearProvider = nearProvider;
|
|
903
934
|
this.omniBridgeAPI = new OmniBridgeAPI();
|
|
@@ -907,11 +938,19 @@ var _OmniBridge = class _OmniBridge {
|
|
|
907
938
|
}
|
|
908
939
|
supports(params) {
|
|
909
940
|
try {
|
|
941
|
+
if (this.targetChainSpecified(params.routeConfig)) {
|
|
942
|
+
return targetChainSupportedByOmniBridge(params.routeConfig.chain);
|
|
943
|
+
}
|
|
910
944
|
return this.parseAssetId(params.assetId) !== null;
|
|
911
945
|
} catch {
|
|
912
946
|
return false;
|
|
913
947
|
}
|
|
914
948
|
}
|
|
949
|
+
targetChainSpecified(routeConfig) {
|
|
950
|
+
return Boolean(
|
|
951
|
+
routeConfig?.route && routeConfig.route === RouteEnum.OmniBridge && routeConfig.chain
|
|
952
|
+
);
|
|
953
|
+
}
|
|
915
954
|
parseAssetId(assetId) {
|
|
916
955
|
const parsed = utils7.parseDefuseAssetId(assetId);
|
|
917
956
|
if (parsed.standard !== "nep141") return null;
|
|
@@ -923,8 +962,39 @@ var _OmniBridge = class _OmniBridge {
|
|
|
923
962
|
address: parsed.contractId
|
|
924
963
|
});
|
|
925
964
|
}
|
|
926
|
-
|
|
927
|
-
const
|
|
965
|
+
async tokenSupported(assetId, routeConfig) {
|
|
966
|
+
const parsed = utils7.parseDefuseAssetId(assetId);
|
|
967
|
+
if (parsed.standard !== "nep141") return null;
|
|
968
|
+
if (this.targetChainSpecified(routeConfig)) {
|
|
969
|
+
const tokenOnDestinationNetwork = await this.getCachedDestinationTokenAddress(
|
|
970
|
+
parsed.contractId,
|
|
971
|
+
routeConfig.chain
|
|
972
|
+
);
|
|
973
|
+
if (tokenOnDestinationNetwork === null) {
|
|
974
|
+
throw new TokenNotFoundInDestinationChainError(
|
|
975
|
+
assetId,
|
|
976
|
+
routeConfig.chain
|
|
977
|
+
);
|
|
978
|
+
}
|
|
979
|
+
return Object.assign(parsed, {
|
|
980
|
+
blockchain: routeConfig.chain,
|
|
981
|
+
bridgeName: BridgeNameEnum.Omni,
|
|
982
|
+
address: parsed.contractId
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
const chain = parseOriginChain(parsed.contractId);
|
|
986
|
+
if (chain === null) return null;
|
|
987
|
+
return Object.assign(parsed, {
|
|
988
|
+
blockchain: chainKindToCaip2(chain),
|
|
989
|
+
bridgeName: BridgeNameEnum.Omni,
|
|
990
|
+
address: parsed.contractId
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
async createWithdrawalIntents(args) {
|
|
994
|
+
const assetInfo = await this.tokenSupported(
|
|
995
|
+
args.withdrawalParams.assetId,
|
|
996
|
+
args.withdrawalParams.routeConfig
|
|
997
|
+
);
|
|
928
998
|
assert9(
|
|
929
999
|
assetInfo !== null,
|
|
930
1000
|
`Asset ${args.withdrawalParams.assetId} is not supported`
|
|
@@ -952,7 +1022,7 @@ var _OmniBridge = class _OmniBridge {
|
|
|
952
1022
|
return Promise.resolve(intents);
|
|
953
1023
|
}
|
|
954
1024
|
async validateWithdrawal(args) {
|
|
955
|
-
const assetInfo = this.
|
|
1025
|
+
const assetInfo = await this.tokenSupported(args.assetId, args.routeConfig);
|
|
956
1026
|
assert9(assetInfo !== null, `Asset ${args.assetId} is not supported`);
|
|
957
1027
|
const supportedTokens = await this.getCachedSupportedTokens();
|
|
958
1028
|
if (!supportedTokens[assetInfo.contractId]) {
|
|
@@ -965,7 +1035,10 @@ var _OmniBridge = class _OmniBridge {
|
|
|
965
1035
|
return;
|
|
966
1036
|
}
|
|
967
1037
|
async estimateWithdrawalFee(args) {
|
|
968
|
-
const assetInfo = this.
|
|
1038
|
+
const assetInfo = await this.tokenSupported(
|
|
1039
|
+
args.withdrawalParams.assetId,
|
|
1040
|
+
args.withdrawalParams.routeConfig
|
|
1041
|
+
);
|
|
969
1042
|
assert9(
|
|
970
1043
|
assetInfo !== null,
|
|
971
1044
|
`Asset ${args.withdrawalParams.assetId} is not supported`
|
|
@@ -1086,6 +1159,23 @@ var _OmniBridge = class _OmniBridge {
|
|
|
1086
1159
|
this.supportedTokensCache.set(_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY, data);
|
|
1087
1160
|
return data;
|
|
1088
1161
|
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Gets cached token address on destination chain.
|
|
1164
|
+
* Cache expires after one day using TTL cache.
|
|
1165
|
+
*/
|
|
1166
|
+
async getCachedDestinationTokenAddress(contractId, chain) {
|
|
1167
|
+
const key = `${chain}:${contractId}`;
|
|
1168
|
+
const cached = this.destinationChainAddressCache.get(key);
|
|
1169
|
+
if (cached != null) {
|
|
1170
|
+
return cached;
|
|
1171
|
+
}
|
|
1172
|
+
const tokenOnDestinationNetwork = await getBridgedToken(
|
|
1173
|
+
omniAddress2(ChainKind2.Near, contractId),
|
|
1174
|
+
caip2ToChainKind(chain)
|
|
1175
|
+
);
|
|
1176
|
+
this.destinationChainAddressCache.set(key, tokenOnDestinationNetwork);
|
|
1177
|
+
return tokenOnDestinationNetwork;
|
|
1178
|
+
}
|
|
1089
1179
|
};
|
|
1090
1180
|
// 86400000 - 1 day
|
|
1091
1181
|
_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY = "SUPPORTED_TOKENS_CACHE_KEY";
|
|
@@ -1982,6 +2072,7 @@ var IntentsSDK = class {
|
|
|
1982
2072
|
amount: actualAmount,
|
|
1983
2073
|
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
1984
2074
|
feeEstimation: args.feeEstimation,
|
|
2075
|
+
routeConfig: args.withdrawalParams.routeConfig,
|
|
1985
2076
|
logger: args.logger
|
|
1986
2077
|
});
|
|
1987
2078
|
return bridge.createWithdrawalIntents({
|
|
@@ -2359,6 +2450,8 @@ export {
|
|
|
2359
2450
|
IntentSettlementError,
|
|
2360
2451
|
IntentsSDK,
|
|
2361
2452
|
MinWithdrawalAmountError,
|
|
2453
|
+
OmniTransferDestinationChainHashNotFoundError,
|
|
2454
|
+
OmniTransferNotFoundError,
|
|
2362
2455
|
PoaWithdrawalInvariantError,
|
|
2363
2456
|
PoaWithdrawalNotFoundError,
|
|
2364
2457
|
PoaWithdrawalPendingError,
|
|
@@ -2367,6 +2460,8 @@ export {
|
|
|
2367
2460
|
RouteEnum,
|
|
2368
2461
|
RpcRequestError,
|
|
2369
2462
|
TimeoutError,
|
|
2463
|
+
TokenNotFoundInDestinationChainError,
|
|
2464
|
+
TokenNotSupportedByOmniRelayerError,
|
|
2370
2465
|
TrustlineNotFoundError,
|
|
2371
2466
|
UnsupportedDestinationMemoError,
|
|
2372
2467
|
createDefaultRoute,
|
|
@@ -2376,6 +2471,7 @@ export {
|
|
|
2376
2471
|
createIntentSignerViem,
|
|
2377
2472
|
createInternalTransferRoute,
|
|
2378
2473
|
createNearWithdrawalRoute,
|
|
2474
|
+
createOmniWithdrawalRoute,
|
|
2379
2475
|
createPoaBridgeRoute,
|
|
2380
2476
|
createVirtualChainRoute
|
|
2381
2477
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@near-js/accounts": "^2.0.1",
|
|
35
35
|
"@near-js/keystores": "^2.0.1",
|
|
36
36
|
"@defuse-protocol/contract-types": "0.0.3",
|
|
37
|
-
"@defuse-protocol/internal-utils": "0.
|
|
37
|
+
"@defuse-protocol/internal-utils": "0.8.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@biomejs/biome": "1.9.4",
|