@defuse-protocol/intents-sdk 0.49.0 → 0.50.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/src/bridges/omni-bridge/omni-bridge-utils.cjs +14 -13
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +2 -1
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +13 -13
- package/dist/src/bridges/omni-bridge/omni-bridge.js +2 -2
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +4 -4
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +1 -1
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +1 -1
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +1 -1
- package/package.json +3 -5
|
@@ -5,13 +5,14 @@ const require_poa_tokens_routable_through_omni_bridge = require('../../constants
|
|
|
5
5
|
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
6
6
|
let valibot = require("valibot");
|
|
7
7
|
valibot = require_rolldown_runtime.__toESM(valibot);
|
|
8
|
-
let
|
|
8
|
+
let _omni_bridge_core = require("@omni-bridge/core");
|
|
9
|
+
let _omni_bridge_near = require("@omni-bridge/near");
|
|
9
10
|
|
|
10
11
|
//#region src/bridges/omni-bridge/omni-bridge-utils.ts
|
|
11
12
|
function createWithdrawIntentsPrimitive(params) {
|
|
12
13
|
const { contractId: tokenAccountId, standard } = _defuse_protocol_internal_utils.utils.parseDefuseAssetId(params.assetId);
|
|
13
14
|
(0, _defuse_protocol_internal_utils.assert)(standard === "nep141", "Only NEP-141 is supported");
|
|
14
|
-
const recipient = (0,
|
|
15
|
+
const recipient = (0, _omni_bridge_core.omniAddress)(params.omniChainKind, params.destinationAddress);
|
|
15
16
|
let msg = "";
|
|
16
17
|
const ftWithdrawPayload = {
|
|
17
18
|
recipient,
|
|
@@ -25,7 +26,7 @@ function createWithdrawIntentsPrimitive(params) {
|
|
|
25
26
|
}
|
|
26
27
|
const intents = [];
|
|
27
28
|
if (params.nativeFee > 0n) intents.push({
|
|
28
|
-
deposit_for_account_id: (0,
|
|
29
|
+
deposit_for_account_id: (0, _omni_bridge_near.calculateStorageAccountId)({
|
|
29
30
|
token: `near:${tokenAccountId}`,
|
|
30
31
|
amount: params.amount,
|
|
31
32
|
recipient,
|
|
@@ -56,12 +57,12 @@ function createWithdrawIntentsPrimitive(params) {
|
|
|
56
57
|
* This serves as a single source of truth for bidirectional chain conversions.
|
|
57
58
|
*/
|
|
58
59
|
const CHAIN_MAPPINGS = [
|
|
59
|
-
[require_caip2.Chains.Ethereum,
|
|
60
|
-
[require_caip2.Chains.Base,
|
|
61
|
-
[require_caip2.Chains.Arbitrum,
|
|
62
|
-
[require_caip2.Chains.Solana,
|
|
63
|
-
[require_caip2.Chains.BNB,
|
|
64
|
-
[require_caip2.Chains.Bitcoin,
|
|
60
|
+
[require_caip2.Chains.Ethereum, _omni_bridge_core.ChainKind.Eth],
|
|
61
|
+
[require_caip2.Chains.Base, _omni_bridge_core.ChainKind.Base],
|
|
62
|
+
[require_caip2.Chains.Arbitrum, _omni_bridge_core.ChainKind.Arb],
|
|
63
|
+
[require_caip2.Chains.Solana, _omni_bridge_core.ChainKind.Sol],
|
|
64
|
+
[require_caip2.Chains.BNB, _omni_bridge_core.ChainKind.Bnb],
|
|
65
|
+
[require_caip2.Chains.Bitcoin, _omni_bridge_core.ChainKind.Btc]
|
|
65
66
|
];
|
|
66
67
|
function caip2ToChainKind(network) {
|
|
67
68
|
return CHAIN_MAPPINGS.find(([chain]) => chain === network)?.[1] ?? null;
|
|
@@ -69,7 +70,7 @@ function caip2ToChainKind(network) {
|
|
|
69
70
|
function chainKindToCaip2(network) {
|
|
70
71
|
return CHAIN_MAPPINGS.find(([_, kind]) => kind === network)?.[0] ?? null;
|
|
71
72
|
}
|
|
72
|
-
const UTXO_CHAINS = [
|
|
73
|
+
const UTXO_CHAINS = [_omni_bridge_core.ChainKind.Btc];
|
|
73
74
|
function isUtxoChain(network) {
|
|
74
75
|
return UTXO_CHAINS.includes(network);
|
|
75
76
|
}
|
|
@@ -78,7 +79,7 @@ function poaContractIdToChainKind(contractId) {
|
|
|
78
79
|
}
|
|
79
80
|
function validateOmniToken(nearAddress) {
|
|
80
81
|
if (nearAddress.endsWith(".testnet")) return false;
|
|
81
|
-
return (0,
|
|
82
|
+
return (0, _omni_bridge_core.isBridgeToken)(nearAddress);
|
|
82
83
|
}
|
|
83
84
|
async function getAccountOmniStorageBalance(nearProvider, accountId) {
|
|
84
85
|
return _defuse_protocol_internal_utils.utils.queryContract({
|
|
@@ -111,7 +112,7 @@ async function getBridgedToken(nearProvider, tokenAddress, destinationChain) {
|
|
|
111
112
|
contractId: require_omni_bridge_constants.OMNI_BRIDGE_CONTRACT,
|
|
112
113
|
methodName: "get_bridged_token",
|
|
113
114
|
args: {
|
|
114
|
-
chain:
|
|
115
|
+
chain: _omni_bridge_core.ChainKind[destinationChain].toString(),
|
|
115
116
|
address: tokenAddress
|
|
116
117
|
},
|
|
117
118
|
finality: "optimistic",
|
|
@@ -126,7 +127,7 @@ async function getBridgedToken(nearProvider, tokenAddress, destinationChain) {
|
|
|
126
127
|
* @returns Promise resolving to the token's decimal information
|
|
127
128
|
*/
|
|
128
129
|
async function getTokenDecimals(nearProvider, tokenAddress) {
|
|
129
|
-
if ((0,
|
|
130
|
+
if ((0, _omni_bridge_core.getChain)(tokenAddress) === _omni_bridge_core.ChainKind.Near) throw new Error("Token decimals cannot be queried using NEAR addresses. Use the token's foreign chain representation (e.g., eth:0x...) to query decimals.");
|
|
130
131
|
return _defuse_protocol_internal_utils.utils.queryContract({
|
|
131
132
|
contractId: require_omni_bridge_constants.OMNI_BRIDGE_CONTRACT,
|
|
132
133
|
methodName: "get_token_decimals",
|
|
@@ -3,7 +3,8 @@ import { MIN_GAS_AMOUNT, OMNI_BRIDGE_CONTRACT } from "./omni-bridge-constants.js
|
|
|
3
3
|
import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "../../constants/poa-tokens-routable-through-omni-bridge.js";
|
|
4
4
|
import { assert, utils } from "@defuse-protocol/internal-utils";
|
|
5
5
|
import * as v from "valibot";
|
|
6
|
-
import { ChainKind,
|
|
6
|
+
import { ChainKind, getChain, isBridgeToken, omniAddress } from "@omni-bridge/core";
|
|
7
|
+
import { calculateStorageAccountId } from "@omni-bridge/near";
|
|
7
8
|
|
|
8
9
|
//#region src/bridges/omni-bridge/omni-bridge-utils.ts
|
|
9
10
|
function createWithdrawIntentsPrimitive(params) {
|
|
@@ -13,7 +13,7 @@ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils")
|
|
|
13
13
|
let lru_cache = require("lru-cache");
|
|
14
14
|
let _isaacs_ttlcache = require("@isaacs/ttlcache");
|
|
15
15
|
_isaacs_ttlcache = require_rolldown_runtime.__toESM(_isaacs_ttlcache);
|
|
16
|
-
let
|
|
16
|
+
let _omni_bridge_core = require("@omni-bridge/core");
|
|
17
17
|
|
|
18
18
|
//#region src/bridges/omni-bridge/omni-bridge.ts
|
|
19
19
|
var OmniBridge = class {
|
|
@@ -27,7 +27,7 @@ var OmniBridge = class {
|
|
|
27
27
|
this.tokenDecimalsCache = new _isaacs_ttlcache.default({ ttl: 36e5 });
|
|
28
28
|
this.envConfig = envConfig;
|
|
29
29
|
this.nearProvider = nearProvider;
|
|
30
|
-
this.omniBridgeAPI = new
|
|
30
|
+
this.omniBridgeAPI = new _omni_bridge_core.BridgeAPI("mainnet");
|
|
31
31
|
this.solverRelayApiKey = solverRelayApiKey;
|
|
32
32
|
this.routeMigratedPoaTokensThroughOmniBridge = routeMigratedPoaTokensThroughOmniBridge ?? false;
|
|
33
33
|
}
|
|
@@ -53,7 +53,7 @@ var OmniBridge = class {
|
|
|
53
53
|
if (omniChainKind === null) throw new require_errors.UnsupportedAssetIdError(params.assetId, `Chain ${params.routeConfig.chain} is not supported in Omni Bridge.`);
|
|
54
54
|
caip2Chain = params.routeConfig.chain;
|
|
55
55
|
} else {
|
|
56
|
-
omniChainKind = poaTokenRoutedThroughOmniBridge ? require_omni_bridge_utils.poaContractIdToChainKind(parsed.contractId) : (0,
|
|
56
|
+
omniChainKind = poaTokenRoutedThroughOmniBridge ? require_omni_bridge_utils.poaContractIdToChainKind(parsed.contractId) : (0, _omni_bridge_core.parseOriginChain)(parsed.contractId);
|
|
57
57
|
if (omniChainKind === null) throw new require_errors.UnsupportedAssetIdError(params.assetId, `Withdrawal of ${parsed.contractId} to its origin chain is not supported in Omni Bridge.`);
|
|
58
58
|
caip2Chain = require_omni_bridge_utils.chainKindToCaip2(omniChainKind);
|
|
59
59
|
if (caip2Chain === null) throw new require_errors.UnsupportedAssetIdError(params.assetId, `Withdrawal of ${parsed.contractId} to its origin chain is not supported in Omni Bridge.`);
|
|
@@ -67,7 +67,7 @@ var OmniBridge = class {
|
|
|
67
67
|
parseAssetId(assetId) {
|
|
68
68
|
const parsed = require_parse_defuse_asset_id.parseDefuseAssetId(assetId);
|
|
69
69
|
if (parsed.standard !== "nep141") return null;
|
|
70
|
-
const omniChainKind = this.isPoaTokenRoutedThroughOmniBridge(parsed.contractId) ? require_omni_bridge_utils.poaContractIdToChainKind(parsed.contractId) : (0,
|
|
70
|
+
const omniChainKind = this.isPoaTokenRoutedThroughOmniBridge(parsed.contractId) ? require_omni_bridge_utils.poaContractIdToChainKind(parsed.contractId) : (0, _omni_bridge_core.parseOriginChain)(parsed.contractId);
|
|
71
71
|
if (omniChainKind === null) return null;
|
|
72
72
|
const blockchain = require_omni_bridge_utils.chainKindToCaip2(omniChainKind);
|
|
73
73
|
if (blockchain === null) return null;
|
|
@@ -86,7 +86,7 @@ var OmniBridge = class {
|
|
|
86
86
|
omniChainKind = require_omni_bridge_utils.caip2ToChainKind(routeConfig.chain);
|
|
87
87
|
blockchain = routeConfig.chain;
|
|
88
88
|
} else {
|
|
89
|
-
omniChainKind = this.isPoaTokenRoutedThroughOmniBridge(parsed.contractId) ? require_omni_bridge_utils.poaContractIdToChainKind(parsed.contractId) : (0,
|
|
89
|
+
omniChainKind = this.isPoaTokenRoutedThroughOmniBridge(parsed.contractId) ? require_omni_bridge_utils.poaContractIdToChainKind(parsed.contractId) : (0, _omni_bridge_core.parseOriginChain)(parsed.contractId);
|
|
90
90
|
if (omniChainKind === null) return null;
|
|
91
91
|
blockchain = require_omni_bridge_utils.chainKindToCaip2(omniChainKind);
|
|
92
92
|
}
|
|
@@ -159,7 +159,7 @@ var OmniBridge = class {
|
|
|
159
159
|
const decimals = await this.getCachedTokenDecimals(destTokenAddress);
|
|
160
160
|
(0, _defuse_protocol_internal_utils.assert)(decimals !== null, `Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
|
|
161
161
|
Ensure the token is supported and the address is correct.`);
|
|
162
|
-
if ((0,
|
|
162
|
+
if ((0, _omni_bridge_core.verifyTransferAmount)(args.amount, 0n, decimals.origin_decimals, decimals.decimals) === false) throw new require_errors.MinWithdrawalAmountError((0, _omni_bridge_core.getMinimumTransferableAmount)(decimals.origin_decimals, decimals.decimals), args.amount, args.assetId);
|
|
163
163
|
const storageBalance = await require_omni_bridge_utils.getAccountOmniStorageBalance(this.nearProvider, this.envConfig.contractID);
|
|
164
164
|
const intentsNearStorageBalance = storageBalance === null ? 0n : BigInt(storageBalance.available);
|
|
165
165
|
if (intentsNearStorageBalance <= require_omni_bridge_constants.MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR) throw new require_error.IntentsNearOmniAvailableBalanceTooLowError(intentsNearStorageBalance.toString());
|
|
@@ -169,7 +169,7 @@ var OmniBridge = class {
|
|
|
169
169
|
(0, _defuse_protocol_internal_utils.assert)(require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "relayerFee") > 0n, `Invalid Omni Bridge relayer fee for non UTXO chain withdrawal: expected > 0, got ${relayerFee}`);
|
|
170
170
|
}
|
|
171
171
|
if (utxoChainWithdrawal) {
|
|
172
|
-
const fee = await (0, _defuse_protocol_internal_utils.withTimeout)(() => this.omniBridgeAPI.getFee((0,
|
|
172
|
+
const fee = await (0, _defuse_protocol_internal_utils.withTimeout)(() => this.omniBridgeAPI.getFee((0, _omni_bridge_core.omniAddress)(_omni_bridge_core.ChainKind.Near, this.envConfig.contractID), (0, _omni_bridge_core.omniAddress)(omniChainKind, args.destinationAddress), (0, _omni_bridge_core.omniAddress)(_omni_bridge_core.ChainKind.Near, assetInfo.contractId), args.amount), {
|
|
173
173
|
timeout: typeof window !== "undefined" ? 1e4 : 3e3,
|
|
174
174
|
errorInstance: new require_error.OmniWithdrawalApiFeeRequestTimeoutError()
|
|
175
175
|
});
|
|
@@ -189,7 +189,7 @@ var OmniBridge = class {
|
|
|
189
189
|
(0, _defuse_protocol_internal_utils.assert)(assetInfo !== null, `Asset ${args.withdrawalParams.assetId} is not supported by Omni Bridge`);
|
|
190
190
|
const omniChainKind = require_omni_bridge_utils.caip2ToChainKind(assetInfo.blockchain);
|
|
191
191
|
(0, _defuse_protocol_internal_utils.assert)(omniChainKind !== null, `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`);
|
|
192
|
-
const fee = await (0, _defuse_protocol_internal_utils.withTimeout)(() => this.omniBridgeAPI.getFee((0,
|
|
192
|
+
const fee = await (0, _defuse_protocol_internal_utils.withTimeout)(() => this.omniBridgeAPI.getFee((0, _omni_bridge_core.omniAddress)(_omni_bridge_core.ChainKind.Near, this.envConfig.contractID), (0, _omni_bridge_core.omniAddress)(omniChainKind, args.withdrawalParams.destinationAddress), (0, _omni_bridge_core.omniAddress)(_omni_bridge_core.ChainKind.Near, assetInfo.contractId), args.withdrawalParams.amount), {
|
|
193
193
|
timeout: typeof window !== "undefined" ? 1e4 : 3e3,
|
|
194
194
|
errorInstance: new require_error.OmniWithdrawalApiFeeRequestTimeoutError()
|
|
195
195
|
});
|
|
@@ -250,11 +250,11 @@ var OmniBridge = class {
|
|
|
250
250
|
async describeWithdrawal(args) {
|
|
251
251
|
const transfer = (await this.omniBridgeAPI.getTransfer({ transactionHash: args.tx.hash }))[args.index];
|
|
252
252
|
if (transfer == null || transfer.transfer_message == null) return { status: "pending" };
|
|
253
|
-
const destinationChain = (0,
|
|
253
|
+
const destinationChain = (0, _omni_bridge_core.getChain)(transfer.transfer_message.recipient);
|
|
254
254
|
let txHash = null;
|
|
255
|
-
if ((0,
|
|
256
|
-
else if (destinationChain ===
|
|
257
|
-
else if (destinationChain ===
|
|
255
|
+
if ((0, _omni_bridge_core.isEvmChain)(destinationChain)) txHash = transfer.finalised?.EVMLog?.transaction_hash;
|
|
256
|
+
else if (destinationChain === _omni_bridge_core.ChainKind.Sol) txHash = transfer.finalised?.Solana?.signature;
|
|
257
|
+
else if (destinationChain === _omni_bridge_core.ChainKind.Btc) txHash = typeof window !== "undefined" ? transfer.utxo_transfer?.btc_pending_id : transfer.finalised?.UtxoLog?.transaction_hash;
|
|
258
258
|
else return {
|
|
259
259
|
status: "completed",
|
|
260
260
|
txHash: null
|
|
@@ -289,7 +289,7 @@ var OmniBridge = class {
|
|
|
289
289
|
const key = `${omniChainKind}:${contractId}`;
|
|
290
290
|
const cached = this.destinationChainAddressCache.get(key);
|
|
291
291
|
if (cached !== void 0) return cached;
|
|
292
|
-
const tokenOnDestinationNetwork = await require_omni_bridge_utils.getBridgedToken(this.nearProvider, (0,
|
|
292
|
+
const tokenOnDestinationNetwork = await require_omni_bridge_utils.getBridgedToken(this.nearProvider, (0, _omni_bridge_core.omniAddress)(_omni_bridge_core.ChainKind.Near, contractId), omniChainKind);
|
|
293
293
|
if (tokenOnDestinationNetwork !== null) this.destinationChainAddressCache.set(key, tokenOnDestinationNetwork);
|
|
294
294
|
return tokenOnDestinationNetwork;
|
|
295
295
|
}
|
|
@@ -11,7 +11,7 @@ import { caip2ToChainKind, chainKindToCaip2, createWithdrawIntentsPrimitive, get
|
|
|
11
11
|
import { assert, getNearNep141MinStorageBalance, getNearNep141StorageBalance, withTimeout } from "@defuse-protocol/internal-utils";
|
|
12
12
|
import { LRUCache } from "lru-cache";
|
|
13
13
|
import TTLCache from "@isaacs/ttlcache";
|
|
14
|
-
import {
|
|
14
|
+
import { BridgeAPI, ChainKind, getChain, getMinimumTransferableAmount, isEvmChain, omniAddress, parseOriginChain, verifyTransferAmount } from "@omni-bridge/core";
|
|
15
15
|
|
|
16
16
|
//#region src/bridges/omni-bridge/omni-bridge.ts
|
|
17
17
|
var OmniBridge = class {
|
|
@@ -25,7 +25,7 @@ var OmniBridge = class {
|
|
|
25
25
|
this.tokenDecimalsCache = new TTLCache({ ttl: 36e5 });
|
|
26
26
|
this.envConfig = envConfig;
|
|
27
27
|
this.nearProvider = nearProvider;
|
|
28
|
-
this.omniBridgeAPI = new
|
|
28
|
+
this.omniBridgeAPI = new BridgeAPI("mainnet");
|
|
29
29
|
this.solverRelayApiKey = solverRelayApiKey;
|
|
30
30
|
this.routeMigratedPoaTokensThroughOmniBridge = routeMigratedPoaTokensThroughOmniBridge ?? false;
|
|
31
31
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _omni_bridge_core = require("@omni-bridge/core");
|
|
3
3
|
|
|
4
4
|
//#region src/constants/poa-tokens-routable-through-omni-bridge.ts
|
|
5
5
|
/**
|
|
@@ -8,9 +8,9 @@ let omni_bridge_sdk = require("omni-bridge-sdk");
|
|
|
8
8
|
* feature flag to enable Omni Bridge routing for these tokens.
|
|
9
9
|
*/
|
|
10
10
|
const POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE = {
|
|
11
|
-
"sol-57d087fd8c460f612f8701f5499ad8b2eec5ab68.omft.near":
|
|
12
|
-
"sol-c58e6539c2f2e097c251f8edf11f9c03e581f8d4.omft.near":
|
|
13
|
-
"sol-b9c68f94ec8fd160137af8cdfe5e61cd68e2afba.omft.near":
|
|
11
|
+
"sol-57d087fd8c460f612f8701f5499ad8b2eec5ab68.omft.near": _omni_bridge_core.ChainKind.Sol,
|
|
12
|
+
"sol-c58e6539c2f2e097c251f8edf11f9c03e581f8d4.omft.near": _omni_bridge_core.ChainKind.Sol,
|
|
13
|
+
"sol-b9c68f94ec8fd160137af8cdfe5e61cd68e2afba.omft.near": _omni_bridge_core.ChainKind.Sol
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -34,16 +34,14 @@
|
|
|
34
34
|
"@hot-labs/omni-sdk": "2.24.7",
|
|
35
35
|
"@isaacs/ttlcache": "^1.0.0",
|
|
36
36
|
"@lifeomic/attempt": "^3.0.0",
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@near-js/keystores": "^2.0.1",
|
|
37
|
+
"@omni-bridge/core": "0.2.3",
|
|
38
|
+
"@omni-bridge/near": "0.2.3",
|
|
40
39
|
"@noble/hashes": "^1.7.1",
|
|
41
40
|
"@scure/base": "^1.0.0",
|
|
42
41
|
"@solana/web3.js": "^1.0.0",
|
|
43
42
|
"borsher": "^4.0.0",
|
|
44
43
|
"lru-cache": "^11",
|
|
45
44
|
"near-api-js": "^4.0.0 || ^5.0.0",
|
|
46
|
-
"omni-bridge-sdk": "0.23.1",
|
|
47
45
|
"ripple-address-codec": "^5.0.0",
|
|
48
46
|
"valibot": "^1.0.0",
|
|
49
47
|
"viem": "^2.0.0",
|