@defuse-protocol/intents-sdk 0.54.0 → 0.55.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.
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
//#region src/bridges/omni-bridge/omni-bridge-constants.ts
|
|
3
3
|
const NEAR_NATIVE_ASSET_ID = "nep141:wrap.near";
|
|
4
4
|
const OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
|
|
5
|
-
const
|
|
5
|
+
const MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR = 500000000000000000000000n;
|
|
6
6
|
const MIN_GAS_AMOUNT = "37400000000000";
|
|
7
|
+
const INTENTS_STORAGE_BALANCE_CACHE_KEY = "INTENTS_STORAGE_BALANCE";
|
|
7
8
|
|
|
8
9
|
//#endregion
|
|
9
|
-
exports.
|
|
10
|
+
exports.INTENTS_STORAGE_BALANCE_CACHE_KEY = INTENTS_STORAGE_BALANCE_CACHE_KEY;
|
|
10
11
|
exports.MIN_GAS_AMOUNT = MIN_GAS_AMOUNT;
|
|
12
|
+
exports.MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR = MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR;
|
|
11
13
|
exports.NEAR_NATIVE_ASSET_ID = NEAR_NATIVE_ASSET_ID;
|
|
12
14
|
exports.OMNI_BRIDGE_CONTRACT = OMNI_BRIDGE_CONTRACT;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
//#region src/bridges/omni-bridge/omni-bridge-constants.ts
|
|
2
2
|
const NEAR_NATIVE_ASSET_ID = "nep141:wrap.near";
|
|
3
3
|
const OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
|
|
4
|
-
const
|
|
4
|
+
const MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR = 500000000000000000000000n;
|
|
5
5
|
const MIN_GAS_AMOUNT = "37400000000000";
|
|
6
|
+
const INTENTS_STORAGE_BALANCE_CACHE_KEY = "INTENTS_STORAGE_BALANCE";
|
|
6
7
|
|
|
7
8
|
//#endregion
|
|
8
|
-
export {
|
|
9
|
+
export { INTENTS_STORAGE_BALANCE_CACHE_KEY, MIN_GAS_AMOUNT, MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR, NEAR_NATIVE_ASSET_ID, OMNI_BRIDGE_CONTRACT };
|
|
@@ -19,6 +19,10 @@ let _omni_bridge_core = require("@omni-bridge/core");
|
|
|
19
19
|
var OmniBridge = class {
|
|
20
20
|
constructor({ envConfig, nearProvider, solverRelayApiKey, routeMigratedPoaTokensThroughOmniBridge }) {
|
|
21
21
|
this.route = require_route_enum.RouteEnum.OmniBridge;
|
|
22
|
+
this.intentsStorageBalanceCache = new _isaacs_ttlcache.default({
|
|
23
|
+
max: 1,
|
|
24
|
+
ttl: 3e3
|
|
25
|
+
});
|
|
22
26
|
this.storageDepositCache = new lru_cache.LRUCache({
|
|
23
27
|
max: 100,
|
|
24
28
|
ttl: 36e5
|
|
@@ -160,9 +164,8 @@ var OmniBridge = class {
|
|
|
160
164
|
(0, _defuse_protocol_internal_utils.assert)(decimals !== null, `Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
|
|
161
165
|
Ensure the token is supported and the address is correct.`);
|
|
162
166
|
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
|
-
const
|
|
164
|
-
|
|
165
|
-
if (intentsNearStorageBalance <= require_omni_bridge_constants.MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR) throw new require_error.IntentsNearOmniAvailableBalanceTooLowError(intentsNearStorageBalance.toString());
|
|
167
|
+
const intentsStorageBalance = await this.getCachedIntentsStorageBalance();
|
|
168
|
+
if (intentsStorageBalance <= require_omni_bridge_constants.MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR) throw new require_error.IntentsNearOmniAvailableBalanceTooLowError(intentsStorageBalance.toString());
|
|
166
169
|
const utxoChainWithdrawal = require_omni_bridge_utils.isUtxoChain(omniChainKind);
|
|
167
170
|
if (utxoChainWithdrawal === false) {
|
|
168
171
|
const relayerFee = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "relayerFee");
|
|
@@ -304,6 +307,17 @@ var OmniBridge = class {
|
|
|
304
307
|
return tokenDecimals;
|
|
305
308
|
}
|
|
306
309
|
/**
|
|
310
|
+
* Gets cached storage_balance value of intents contract on Omni Bridge contract.
|
|
311
|
+
*/
|
|
312
|
+
async getCachedIntentsStorageBalance() {
|
|
313
|
+
const cached = this.intentsStorageBalanceCache.get(require_omni_bridge_constants.INTENTS_STORAGE_BALANCE_CACHE_KEY);
|
|
314
|
+
if (cached !== void 0) return cached;
|
|
315
|
+
const storageBalance = await require_omni_bridge_utils.getAccountOmniStorageBalance(this.nearProvider, this.envConfig.contractID);
|
|
316
|
+
const intentsStorageBalance = storageBalance === null ? 0n : BigInt(storageBalance.available);
|
|
317
|
+
if (intentsStorageBalance > require_omni_bridge_constants.MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR) this.intentsStorageBalanceCache.set(require_omni_bridge_constants.INTENTS_STORAGE_BALANCE_CACHE_KEY, intentsStorageBalance);
|
|
318
|
+
return intentsStorageBalance;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
307
321
|
* Checks if passed token contract id is an allowlisted PoA token that should be routed via OmniBridge.
|
|
308
322
|
* Always return false when feature flag routeMigratedPoaTokensThroughOmniBridge = false.
|
|
309
323
|
*/
|
|
@@ -5,7 +5,7 @@ import { parseDefuseAssetId } from "../../lib/parse-defuse-asset-id.js";
|
|
|
5
5
|
import { validateAddress } from "../../lib/validateAddress.js";
|
|
6
6
|
import { BridgeNameEnum } from "../../constants/bridge-name-enum.js";
|
|
7
7
|
import { InsufficientUtxoForOmniBridgeWithdrawalError, IntentsNearOmniAvailableBalanceTooLowError, InvalidFeeValueError, OmniWithdrawalApiFeeRequestTimeoutError, TokenNotFoundInDestinationChainError } from "./error.js";
|
|
8
|
-
import {
|
|
8
|
+
import { INTENTS_STORAGE_BALANCE_CACHE_KEY, MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR, NEAR_NATIVE_ASSET_ID, OMNI_BRIDGE_CONTRACT } from "./omni-bridge-constants.js";
|
|
9
9
|
import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "../../constants/poa-tokens-routable-through-omni-bridge.js";
|
|
10
10
|
import { caip2ToChainKind, chainKindToCaip2, createWithdrawIntentsPrimitive, getAccountOmniStorageBalance, getBridgedToken, getTokenDecimals, isUtxoChain, poaContractIdToChainKind, validateOmniToken } from "./omni-bridge-utils.js";
|
|
11
11
|
import { assert, getNearNep141MinStorageBalance, getNearNep141StorageBalance, withTimeout } from "@defuse-protocol/internal-utils";
|
|
@@ -17,6 +17,10 @@ import { BridgeAPI, ChainKind, getChain, getMinimumTransferableAmount, isEvmChai
|
|
|
17
17
|
var OmniBridge = class {
|
|
18
18
|
constructor({ envConfig, nearProvider, solverRelayApiKey, routeMigratedPoaTokensThroughOmniBridge }) {
|
|
19
19
|
this.route = RouteEnum.OmniBridge;
|
|
20
|
+
this.intentsStorageBalanceCache = new TTLCache({
|
|
21
|
+
max: 1,
|
|
22
|
+
ttl: 3e3
|
|
23
|
+
});
|
|
20
24
|
this.storageDepositCache = new LRUCache({
|
|
21
25
|
max: 100,
|
|
22
26
|
ttl: 36e5
|
|
@@ -158,9 +162,8 @@ var OmniBridge = class {
|
|
|
158
162
|
assert(decimals !== null, `Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
|
|
159
163
|
Ensure the token is supported and the address is correct.`);
|
|
160
164
|
if (verifyTransferAmount(args.amount, 0n, decimals.origin_decimals, decimals.decimals) === false) throw new MinWithdrawalAmountError(getMinimumTransferableAmount(decimals.origin_decimals, decimals.decimals), args.amount, args.assetId);
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
if (intentsNearStorageBalance <= MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR) throw new IntentsNearOmniAvailableBalanceTooLowError(intentsNearStorageBalance.toString());
|
|
165
|
+
const intentsStorageBalance = await this.getCachedIntentsStorageBalance();
|
|
166
|
+
if (intentsStorageBalance <= MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR) throw new IntentsNearOmniAvailableBalanceTooLowError(intentsStorageBalance.toString());
|
|
164
167
|
const utxoChainWithdrawal = isUtxoChain(omniChainKind);
|
|
165
168
|
if (utxoChainWithdrawal === false) {
|
|
166
169
|
const relayerFee = getUnderlyingFee(args.feeEstimation, RouteEnum.OmniBridge, "relayerFee");
|
|
@@ -302,6 +305,17 @@ var OmniBridge = class {
|
|
|
302
305
|
return tokenDecimals;
|
|
303
306
|
}
|
|
304
307
|
/**
|
|
308
|
+
* Gets cached storage_balance value of intents contract on Omni Bridge contract.
|
|
309
|
+
*/
|
|
310
|
+
async getCachedIntentsStorageBalance() {
|
|
311
|
+
const cached = this.intentsStorageBalanceCache.get(INTENTS_STORAGE_BALANCE_CACHE_KEY);
|
|
312
|
+
if (cached !== void 0) return cached;
|
|
313
|
+
const storageBalance = await getAccountOmniStorageBalance(this.nearProvider, this.envConfig.contractID);
|
|
314
|
+
const intentsStorageBalance = storageBalance === null ? 0n : BigInt(storageBalance.available);
|
|
315
|
+
if (intentsStorageBalance > MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR) this.intentsStorageBalanceCache.set(INTENTS_STORAGE_BALANCE_CACHE_KEY, intentsStorageBalance);
|
|
316
|
+
return intentsStorageBalance;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
305
319
|
* Checks if passed token contract id is an allowlisted PoA token that should be routed via OmniBridge.
|
|
306
320
|
* Always return false when feature flag routeMigratedPoaTokensThroughOmniBridge = false.
|
|
307
321
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"ripple-address-codec": "^5.0.0",
|
|
46
46
|
"valibot": "^1.0.0",
|
|
47
47
|
"viem": "^2.0.0",
|
|
48
|
-
"@defuse-protocol/internal-utils": "0.28.
|
|
48
|
+
"@defuse-protocol/internal-utils": "0.28.3",
|
|
49
49
|
"@defuse-protocol/contract-types": "0.6.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|