@defuse-protocol/intents-sdk 0.43.0 → 0.43.2
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/aurora-engine-bridge/aurora-engine-bridge-constants.cjs +4 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.js +3 -1
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +5 -2
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.js +5 -2
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +1 -1
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +1 -1
- package/dist/src/bridges/direct-bridge/direct-bridge-constants.cjs +2 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-constants.js +2 -1
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +3 -1
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.js +4 -2
- package/dist/src/bridges/direct-bridge/direct-bridge.cjs +2 -1
- package/dist/src/bridges/direct-bridge/direct-bridge.js +2 -1
- package/dist/src/bridges/hot-bridge/hot-bridge-constants.cjs +3 -1
- package/dist/src/bridges/hot-bridge/hot-bridge-constants.js +2 -1
- package/dist/src/bridges/hot-bridge/hot-bridge.cjs +11 -5
- package/dist/src/bridges/hot-bridge/hot-bridge.js +12 -6
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.cjs +2 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.js +2 -1
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +2 -1
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +3 -2
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +2 -2
- package/dist/src/bridges/omni-bridge/omni-bridge.js +2 -2
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +3 -1
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +3 -1
- package/dist/src/bridges/poa-bridge/poa-bridge.cjs +1 -1
- package/dist/src/bridges/poa-bridge/poa-bridge.js +1 -1
- package/dist/src/bridges/poa-bridge/poa-constants.cjs +6 -0
- package/dist/src/bridges/poa-bridge/poa-constants.js +5 -0
- package/dist/src/sdk.cjs +6 -7
- package/dist/src/sdk.js +6 -7
- package/dist/src/shared-types.d.cts +4 -0
- package/dist/src/shared-types.d.ts +4 -0
- package/package.json +3 -3
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.ts
|
|
3
3
|
const NEAR_NATIVE_ASSET_ID = "nep141:wrap.near";
|
|
4
|
+
const MIN_GAS_AMOUNT = "38500000000000";
|
|
5
|
+
const MIN_GAS_AMOUNT_NON_STANDARD_DECIMALS = "100000000000000";
|
|
4
6
|
|
|
5
7
|
//#endregion
|
|
8
|
+
exports.MIN_GAS_AMOUNT = MIN_GAS_AMOUNT;
|
|
9
|
+
exports.MIN_GAS_AMOUNT_NON_STANDARD_DECIMALS = MIN_GAS_AMOUNT_NON_STANDARD_DECIMALS;
|
|
6
10
|
exports.NEAR_NATIVE_ASSET_ID = NEAR_NATIVE_ASSET_ID;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
//#region src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.ts
|
|
2
2
|
const NEAR_NATIVE_ASSET_ID = "nep141:wrap.near";
|
|
3
|
+
const MIN_GAS_AMOUNT = "38500000000000";
|
|
4
|
+
const MIN_GAS_AMOUNT_NON_STANDARD_DECIMALS = "100000000000000";
|
|
3
5
|
|
|
4
6
|
//#endregion
|
|
5
|
-
export { NEAR_NATIVE_ASSET_ID };
|
|
7
|
+
export { MIN_GAS_AMOUNT, MIN_GAS_AMOUNT_NON_STANDARD_DECIMALS, NEAR_NATIVE_ASSET_ID };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_route_enum = require('../../constants/route-enum.cjs');
|
|
3
|
+
const require_aurora_engine_bridge_constants = require('./aurora-engine-bridge-constants.cjs');
|
|
3
4
|
let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
4
5
|
let viem = require("viem");
|
|
5
6
|
|
|
@@ -13,7 +14,8 @@ function createWithdrawIntentPrimitive(params) {
|
|
|
13
14
|
receiver_id: params.auroraEngineContractId,
|
|
14
15
|
amount: params.amount.toString(),
|
|
15
16
|
msg: makeAuroraEngineDepositMsg(params.destinationAddress),
|
|
16
|
-
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0
|
|
17
|
+
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0,
|
|
18
|
+
min_gas: require_aurora_engine_bridge_constants.MIN_GAS_AMOUNT
|
|
17
19
|
};
|
|
18
20
|
return {
|
|
19
21
|
intent: "ft_withdraw",
|
|
@@ -21,7 +23,8 @@ function createWithdrawIntentPrimitive(params) {
|
|
|
21
23
|
receiver_id: params.proxyTokenContractId,
|
|
22
24
|
amount: params.amount.toString(),
|
|
23
25
|
msg: `${params.auroraEngineContractId}:${makeAuroraEngineDepositMsg(params.destinationAddress)}`,
|
|
24
|
-
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0
|
|
26
|
+
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0,
|
|
27
|
+
min_gas: require_aurora_engine_bridge_constants.MIN_GAS_AMOUNT_NON_STANDARD_DECIMALS
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RouteEnum } from "../../constants/route-enum.js";
|
|
2
|
+
import { MIN_GAS_AMOUNT, MIN_GAS_AMOUNT_NON_STANDARD_DECIMALS } from "./aurora-engine-bridge-constants.js";
|
|
2
3
|
import { assert, utils } from "@defuse-protocol/internal-utils";
|
|
3
4
|
import { getAddress } from "viem";
|
|
4
5
|
|
|
@@ -12,7 +13,8 @@ function createWithdrawIntentPrimitive(params) {
|
|
|
12
13
|
receiver_id: params.auroraEngineContractId,
|
|
13
14
|
amount: params.amount.toString(),
|
|
14
15
|
msg: makeAuroraEngineDepositMsg(params.destinationAddress),
|
|
15
|
-
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0
|
|
16
|
+
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0,
|
|
17
|
+
min_gas: MIN_GAS_AMOUNT
|
|
16
18
|
};
|
|
17
19
|
return {
|
|
18
20
|
intent: "ft_withdraw",
|
|
@@ -20,7 +22,8 @@ function createWithdrawIntentPrimitive(params) {
|
|
|
20
22
|
receiver_id: params.proxyTokenContractId,
|
|
21
23
|
amount: params.amount.toString(),
|
|
22
24
|
msg: `${params.auroraEngineContractId}:${makeAuroraEngineDepositMsg(params.destinationAddress)}`,
|
|
23
|
-
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0
|
|
25
|
+
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0,
|
|
26
|
+
min_gas: MIN_GAS_AMOUNT_NON_STANDARD_DECIMALS
|
|
24
27
|
};
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
@@ -90,7 +90,7 @@ var AuroraEngineBridge = class {
|
|
|
90
90
|
underlyingFees: { [require_route_enum.RouteEnum.VirtualChain]: { storageDepositFee: feeAmount } }
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
async waitForWithdrawalCompletion(
|
|
93
|
+
async waitForWithdrawalCompletion() {
|
|
94
94
|
return { hash: null };
|
|
95
95
|
}
|
|
96
96
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/bridges/direct-bridge/direct-bridge-constants.ts
|
|
3
3
|
const NEAR_NATIVE_ASSET_ID = "nep141:wrap.near";
|
|
4
|
+
const MIN_GAS_AMOUNT = "17050000000000";
|
|
4
5
|
|
|
5
6
|
//#endregion
|
|
7
|
+
exports.MIN_GAS_AMOUNT = MIN_GAS_AMOUNT;
|
|
6
8
|
exports.NEAR_NATIVE_ASSET_ID = NEAR_NATIVE_ASSET_ID;
|
|
@@ -13,13 +13,15 @@ function createWithdrawIntentPrimitive(params) {
|
|
|
13
13
|
};
|
|
14
14
|
const { contractId: tokenAccountId, standard } = __defuse_protocol_internal_utils.utils.parseDefuseAssetId(params.assetId);
|
|
15
15
|
(0, __defuse_protocol_internal_utils.assert)(standard === "nep141", "Only NEP-141 is supported");
|
|
16
|
+
if (params.msg !== void 0) params.logger?.warn("min_gas is not set for direct-bridge withdrawal with msg, gas consumption is unpredictable");
|
|
16
17
|
return {
|
|
17
18
|
intent: "ft_withdraw",
|
|
18
19
|
token: tokenAccountId,
|
|
19
20
|
receiver_id: params.destinationAddress,
|
|
20
21
|
amount: params.amount.toString(),
|
|
21
22
|
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0,
|
|
22
|
-
msg: params.msg
|
|
23
|
+
msg: params.msg,
|
|
24
|
+
min_gas: params.msg == null ? require_direct_bridge_constants.MIN_GAS_AMOUNT : void 0
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
27
|
function withdrawalParamsInvariant(params) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RouteEnum } from "../../constants/route-enum.js";
|
|
2
|
-
import { NEAR_NATIVE_ASSET_ID } from "./direct-bridge-constants.js";
|
|
2
|
+
import { MIN_GAS_AMOUNT, NEAR_NATIVE_ASSET_ID } from "./direct-bridge-constants.js";
|
|
3
3
|
import { assert, unwrapNearFailoverRpcProvider, utils } from "@defuse-protocol/internal-utils";
|
|
4
4
|
import { providers } from "near-api-js";
|
|
5
5
|
|
|
@@ -12,13 +12,15 @@ function createWithdrawIntentPrimitive(params) {
|
|
|
12
12
|
};
|
|
13
13
|
const { contractId: tokenAccountId, standard } = utils.parseDefuseAssetId(params.assetId);
|
|
14
14
|
assert(standard === "nep141", "Only NEP-141 is supported");
|
|
15
|
+
if (params.msg !== void 0) params.logger?.warn("min_gas is not set for direct-bridge withdrawal with msg, gas consumption is unpredictable");
|
|
15
16
|
return {
|
|
16
17
|
intent: "ft_withdraw",
|
|
17
18
|
token: tokenAccountId,
|
|
18
19
|
receiver_id: params.destinationAddress,
|
|
19
20
|
amount: params.amount.toString(),
|
|
20
21
|
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0,
|
|
21
|
-
msg: params.msg
|
|
22
|
+
msg: params.msg,
|
|
23
|
+
min_gas: params.msg == null ? MIN_GAS_AMOUNT : void 0
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
26
|
function withdrawalParamsInvariant(params) {
|
|
@@ -61,7 +61,8 @@ var DirectBridge = class {
|
|
|
61
61
|
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
62
62
|
amount: args.withdrawalParams.amount,
|
|
63
63
|
storageDeposit: require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.NearWithdrawal, "storageDepositFee"),
|
|
64
|
-
msg: args.withdrawalParams.routeConfig?.msg
|
|
64
|
+
msg: args.withdrawalParams.routeConfig?.msg,
|
|
65
|
+
logger: args.logger
|
|
65
66
|
});
|
|
66
67
|
intents.push(intent);
|
|
67
68
|
return Promise.resolve(intents);
|
|
@@ -60,7 +60,8 @@ var DirectBridge = class {
|
|
|
60
60
|
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
61
61
|
amount: args.withdrawalParams.amount,
|
|
62
62
|
storageDeposit: getUnderlyingFee(args.feeEstimation, RouteEnum.NearWithdrawal, "storageDepositFee"),
|
|
63
|
-
msg: args.withdrawalParams.routeConfig?.msg
|
|
63
|
+
msg: args.withdrawalParams.routeConfig?.msg,
|
|
64
|
+
logger: args.logger
|
|
64
65
|
});
|
|
65
66
|
intents.push(intent);
|
|
66
67
|
return Promise.resolve(intents);
|
|
@@ -4,6 +4,8 @@ const HotWithdrawStatus = {
|
|
|
4
4
|
Completed: "COMPLETED",
|
|
5
5
|
Canceled: "CANCELED"
|
|
6
6
|
};
|
|
7
|
+
const MIN_GAS_AMOUNT = "91300000000000";
|
|
7
8
|
|
|
8
9
|
//#endregion
|
|
9
|
-
exports.HotWithdrawStatus = HotWithdrawStatus;
|
|
10
|
+
exports.HotWithdrawStatus = HotWithdrawStatus;
|
|
11
|
+
exports.MIN_GAS_AMOUNT = MIN_GAS_AMOUNT;
|
|
@@ -53,6 +53,7 @@ var HotBridge = class {
|
|
|
53
53
|
if (args.withdrawalParams.destinationMemo != null && args.withdrawalParams.destinationMemo !== "") throw new require_errors.UnsupportedDestinationMemoError(assetInfo.blockchain, args.withdrawalParams.assetId);
|
|
54
54
|
const intents = [];
|
|
55
55
|
const feeAmount = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.HotBridge, "relayerFee");
|
|
56
|
+
const blockNumber = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.HotBridge, "blockNumber");
|
|
56
57
|
if (args.feeEstimation.quote !== null) intents.push({
|
|
57
58
|
intent: "token_diff",
|
|
58
59
|
diff: {
|
|
@@ -66,15 +67,17 @@ var HotBridge = class {
|
|
|
66
67
|
const intent = await this.hotSdk.buildGaslessWithdrawIntent({
|
|
67
68
|
feeToken: "native",
|
|
68
69
|
feeAmount,
|
|
70
|
+
blockNumber,
|
|
69
71
|
chain: require_hot_bridge_utils.toHotNetworkId(assetInfo.blockchain),
|
|
70
72
|
token: isNative ? "native" : assetInfo.address,
|
|
71
73
|
amount,
|
|
72
|
-
receiver: args.withdrawalParams.destinationAddress
|
|
73
|
-
intentAccount: ""
|
|
74
|
+
receiver: args.withdrawalParams.destinationAddress
|
|
74
75
|
});
|
|
75
76
|
(0, __defuse_protocol_internal_utils.assert)(intent.amounts[0] === amount.toString(), "Amount is not correct");
|
|
76
77
|
if (intent.amounts.length === 2) (0, __defuse_protocol_internal_utils.assert)(intent.amounts[1] === feeAmount.toString(), "Amount is not correct");
|
|
77
|
-
|
|
78
|
+
const mtWithdrawIntent = intent;
|
|
79
|
+
mtWithdrawIntent.min_gas = require_hot_bridge_constants.MIN_GAS_AMOUNT;
|
|
80
|
+
intents.push(mtWithdrawIntent);
|
|
78
81
|
return intents;
|
|
79
82
|
}
|
|
80
83
|
/**
|
|
@@ -96,7 +99,7 @@ var HotBridge = class {
|
|
|
96
99
|
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
97
100
|
(0, __defuse_protocol_internal_utils.assert)(assetInfo != null, "Asset is not supported");
|
|
98
101
|
require_hot_bridge_utils.hotBlockchainInvariant(assetInfo.blockchain);
|
|
99
|
-
const { gasPrice: feeAmount } = await (0, __defuse_protocol_internal_utils.withTimeout)(() => this.hotSdk.getGaslessWithdrawFee({
|
|
102
|
+
const { gasPrice: feeAmount, blockNumber } = await (0, __defuse_protocol_internal_utils.withTimeout)(() => this.hotSdk.getGaslessWithdrawFee({
|
|
100
103
|
chain: require_hot_bridge_utils.toHotNetworkId(assetInfo.blockchain),
|
|
101
104
|
token: "native" in assetInfo ? "native" : assetInfo.address,
|
|
102
105
|
receiver: args.withdrawalParams.destinationAddress
|
|
@@ -117,7 +120,10 @@ var HotBridge = class {
|
|
|
117
120
|
return {
|
|
118
121
|
amount: feeQuote ? BigInt(feeQuote.amount_in) : feeAmount,
|
|
119
122
|
quote: feeQuote,
|
|
120
|
-
underlyingFees: { [require_route_enum.RouteEnum.HotBridge]: {
|
|
123
|
+
underlyingFees: { [require_route_enum.RouteEnum.HotBridge]: {
|
|
124
|
+
relayerFee: feeAmount,
|
|
125
|
+
blockNumber
|
|
126
|
+
} }
|
|
121
127
|
};
|
|
122
128
|
}
|
|
123
129
|
async waitForWithdrawalCompletion(args) {
|
|
@@ -6,7 +6,7 @@ import { Chains } from "../../lib/caip2.js";
|
|
|
6
6
|
import { validateAddress } from "../../lib/validateAddress.js";
|
|
7
7
|
import { BridgeNameEnum } from "../../constants/bridge-name-enum.js";
|
|
8
8
|
import { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalCancelledError, HotWithdrawalNotFoundError, HotWithdrawalPendingError } from "./error.js";
|
|
9
|
-
import { HotWithdrawStatus } from "./hot-bridge-constants.js";
|
|
9
|
+
import { HotWithdrawStatus, MIN_GAS_AMOUNT } from "./hot-bridge-constants.js";
|
|
10
10
|
import { formatTxHash, getFeeAssetIdForChain, hotBlockchainInvariant, hotNetworkIdToCAIP2, toHotNetworkId } from "./hot-bridge-utils.js";
|
|
11
11
|
import isHex from "../../lib/hex.js";
|
|
12
12
|
import { RETRY_CONFIGS, assert, withTimeout } from "@defuse-protocol/internal-utils";
|
|
@@ -52,6 +52,7 @@ var HotBridge$1 = class {
|
|
|
52
52
|
if (args.withdrawalParams.destinationMemo != null && args.withdrawalParams.destinationMemo !== "") throw new UnsupportedDestinationMemoError(assetInfo.blockchain, args.withdrawalParams.assetId);
|
|
53
53
|
const intents = [];
|
|
54
54
|
const feeAmount = getUnderlyingFee(args.feeEstimation, RouteEnum.HotBridge, "relayerFee");
|
|
55
|
+
const blockNumber = getUnderlyingFee(args.feeEstimation, RouteEnum.HotBridge, "blockNumber");
|
|
55
56
|
if (args.feeEstimation.quote !== null) intents.push({
|
|
56
57
|
intent: "token_diff",
|
|
57
58
|
diff: {
|
|
@@ -65,15 +66,17 @@ var HotBridge$1 = class {
|
|
|
65
66
|
const intent = await this.hotSdk.buildGaslessWithdrawIntent({
|
|
66
67
|
feeToken: "native",
|
|
67
68
|
feeAmount,
|
|
69
|
+
blockNumber,
|
|
68
70
|
chain: toHotNetworkId(assetInfo.blockchain),
|
|
69
71
|
token: isNative ? "native" : assetInfo.address,
|
|
70
72
|
amount,
|
|
71
|
-
receiver: args.withdrawalParams.destinationAddress
|
|
72
|
-
intentAccount: ""
|
|
73
|
+
receiver: args.withdrawalParams.destinationAddress
|
|
73
74
|
});
|
|
74
75
|
assert(intent.amounts[0] === amount.toString(), "Amount is not correct");
|
|
75
76
|
if (intent.amounts.length === 2) assert(intent.amounts[1] === feeAmount.toString(), "Amount is not correct");
|
|
76
|
-
|
|
77
|
+
const mtWithdrawIntent = intent;
|
|
78
|
+
mtWithdrawIntent.min_gas = MIN_GAS_AMOUNT;
|
|
79
|
+
intents.push(mtWithdrawIntent);
|
|
77
80
|
return intents;
|
|
78
81
|
}
|
|
79
82
|
/**
|
|
@@ -95,7 +98,7 @@ var HotBridge$1 = class {
|
|
|
95
98
|
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
96
99
|
assert(assetInfo != null, "Asset is not supported");
|
|
97
100
|
hotBlockchainInvariant(assetInfo.blockchain);
|
|
98
|
-
const { gasPrice: feeAmount } = await withTimeout(() => this.hotSdk.getGaslessWithdrawFee({
|
|
101
|
+
const { gasPrice: feeAmount, blockNumber } = await withTimeout(() => this.hotSdk.getGaslessWithdrawFee({
|
|
99
102
|
chain: toHotNetworkId(assetInfo.blockchain),
|
|
100
103
|
token: "native" in assetInfo ? "native" : assetInfo.address,
|
|
101
104
|
receiver: args.withdrawalParams.destinationAddress
|
|
@@ -116,7 +119,10 @@ var HotBridge$1 = class {
|
|
|
116
119
|
return {
|
|
117
120
|
amount: feeQuote ? BigInt(feeQuote.amount_in) : feeAmount,
|
|
118
121
|
quote: feeQuote,
|
|
119
|
-
underlyingFees: { [RouteEnum.HotBridge]: {
|
|
122
|
+
underlyingFees: { [RouteEnum.HotBridge]: {
|
|
123
|
+
relayerFee: feeAmount,
|
|
124
|
+
blockNumber
|
|
125
|
+
} }
|
|
120
126
|
};
|
|
121
127
|
}
|
|
122
128
|
async waitForWithdrawalCompletion(args) {
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
const NEAR_NATIVE_ASSET_ID = "nep141:wrap.near";
|
|
4
4
|
const OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
|
|
5
5
|
const MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR = 500000000000000000000000n;
|
|
6
|
+
const MIN_GAS_AMOUNT = "37400000000000";
|
|
6
7
|
|
|
7
8
|
//#endregion
|
|
8
9
|
exports.MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR = MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR;
|
|
10
|
+
exports.MIN_GAS_AMOUNT = MIN_GAS_AMOUNT;
|
|
9
11
|
exports.NEAR_NATIVE_ASSET_ID = NEAR_NATIVE_ASSET_ID;
|
|
10
12
|
exports.OMNI_BRIDGE_CONTRACT = OMNI_BRIDGE_CONTRACT;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const NEAR_NATIVE_ASSET_ID = "nep141:wrap.near";
|
|
3
3
|
const OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
|
|
4
4
|
const MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR = 500000000000000000000000n;
|
|
5
|
+
const MIN_GAS_AMOUNT = "37400000000000";
|
|
5
6
|
|
|
6
7
|
//#endregion
|
|
7
|
-
export { MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR, NEAR_NATIVE_ASSET_ID, OMNI_BRIDGE_CONTRACT };
|
|
8
|
+
export { MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR, MIN_GAS_AMOUNT, NEAR_NATIVE_ASSET_ID, OMNI_BRIDGE_CONTRACT };
|
|
@@ -45,7 +45,8 @@ function createWithdrawIntentsPrimitive(params) {
|
|
|
45
45
|
receiver_id: require_omni_bridge_constants.OMNI_BRIDGE_CONTRACT,
|
|
46
46
|
amount: params.amount.toString(),
|
|
47
47
|
storage_deposit: params.storageDepositAmount > 0n ? params.storageDepositAmount.toString() : void 0,
|
|
48
|
-
msg: JSON.stringify(ftWithdrawPayload)
|
|
48
|
+
msg: JSON.stringify(ftWithdrawPayload),
|
|
49
|
+
min_gas: require_omni_bridge_constants.MIN_GAS_AMOUNT
|
|
49
50
|
});
|
|
50
51
|
return intents;
|
|
51
52
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Chains } from "../../lib/caip2.js";
|
|
2
|
-
import { OMNI_BRIDGE_CONTRACT } from "./omni-bridge-constants.js";
|
|
2
|
+
import { MIN_GAS_AMOUNT, OMNI_BRIDGE_CONTRACT } from "./omni-bridge-constants.js";
|
|
3
3
|
import { assert, utils } from "@defuse-protocol/internal-utils";
|
|
4
4
|
import { ChainKind, calculateStorageAccountId, getChain, isBridgeToken, omniAddress } from "omni-bridge-sdk";
|
|
5
5
|
import * as v from "valibot";
|
|
@@ -43,7 +43,8 @@ function createWithdrawIntentsPrimitive(params) {
|
|
|
43
43
|
receiver_id: OMNI_BRIDGE_CONTRACT,
|
|
44
44
|
amount: params.amount.toString(),
|
|
45
45
|
storage_deposit: params.storageDepositAmount > 0n ? params.storageDepositAmount.toString() : void 0,
|
|
46
|
-
msg: JSON.stringify(ftWithdrawPayload)
|
|
46
|
+
msg: JSON.stringify(ftWithdrawPayload),
|
|
47
|
+
min_gas: MIN_GAS_AMOUNT
|
|
47
48
|
});
|
|
48
49
|
return intents;
|
|
49
50
|
}
|
|
@@ -145,7 +145,7 @@ var OmniBridge = class {
|
|
|
145
145
|
return Promise.resolve(intents);
|
|
146
146
|
}
|
|
147
147
|
async validateWithdrawal(args) {
|
|
148
|
-
(0, __defuse_protocol_internal_utils.assert)(args.feeEstimation.amount > 0n, `
|
|
148
|
+
(0, __defuse_protocol_internal_utils.assert)(args.feeEstimation.amount > 0n, `Invalid Omni Bridge fee: expected > 0, got ${args.feeEstimation.amount}`);
|
|
149
149
|
const assetInfo = this.makeAssetInfo(args.assetId, args.routeConfig);
|
|
150
150
|
(0, __defuse_protocol_internal_utils.assert)(assetInfo !== null, `Asset ${args.assetId} is not supported by Omni Bridge`);
|
|
151
151
|
if (require_validateAddress.validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
|
|
@@ -156,7 +156,7 @@ var OmniBridge = class {
|
|
|
156
156
|
const decimals = await this.getCachedTokenDecimals(destTokenAddress);
|
|
157
157
|
(0, __defuse_protocol_internal_utils.assert)(decimals !== null, `Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
|
|
158
158
|
Ensure the token is supported and the address is correct.`);
|
|
159
|
-
if ((0, omni_bridge_sdk.verifyTransferAmount)(args.amount
|
|
159
|
+
if ((0, omni_bridge_sdk.verifyTransferAmount)(args.amount, 0n, decimals.origin_decimals, decimals.decimals) === false) throw new require_errors.MinWithdrawalAmountError((0, omni_bridge_sdk.getMinimumTransferableAmount)(decimals.origin_decimals, decimals.decimals), args.amount, args.assetId);
|
|
160
160
|
const storageBalance = await require_omni_bridge_utils.getAccountOmniStorageBalance(this.nearProvider, __defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID);
|
|
161
161
|
const intentsNearStorageBalance = storageBalance === null ? 0n : BigInt(storageBalance.available);
|
|
162
162
|
if (intentsNearStorageBalance <= require_omni_bridge_constants.MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR) throw new require_error.IntentsNearOmniAvailableBalanceTooLowError(intentsNearStorageBalance.toString());
|
|
@@ -143,7 +143,7 @@ var OmniBridge = class {
|
|
|
143
143
|
return Promise.resolve(intents);
|
|
144
144
|
}
|
|
145
145
|
async validateWithdrawal(args) {
|
|
146
|
-
assert(args.feeEstimation.amount > 0n, `
|
|
146
|
+
assert(args.feeEstimation.amount > 0n, `Invalid Omni Bridge fee: expected > 0, got ${args.feeEstimation.amount}`);
|
|
147
147
|
const assetInfo = this.makeAssetInfo(args.assetId, args.routeConfig);
|
|
148
148
|
assert(assetInfo !== null, `Asset ${args.assetId} is not supported by Omni Bridge`);
|
|
149
149
|
if (validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
|
|
@@ -154,7 +154,7 @@ var OmniBridge = class {
|
|
|
154
154
|
const decimals = await this.getCachedTokenDecimals(destTokenAddress);
|
|
155
155
|
assert(decimals !== null, `Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
|
|
156
156
|
Ensure the token is supported and the address is correct.`);
|
|
157
|
-
if (verifyTransferAmount(args.amount
|
|
157
|
+
if (verifyTransferAmount(args.amount, 0n, decimals.origin_decimals, decimals.decimals) === false) throw new MinWithdrawalAmountError(getMinimumTransferableAmount(decimals.origin_decimals, decimals.decimals), args.amount, args.assetId);
|
|
158
158
|
const storageBalance = await getAccountOmniStorageBalance(this.nearProvider, configsByEnvironment[this.env].contractID);
|
|
159
159
|
const intentsNearStorageBalance = storageBalance === null ? 0n : BigInt(storageBalance.available);
|
|
160
160
|
if (intentsNearStorageBalance <= MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR) throw new IntentsNearOmniAvailableBalanceTooLowError(intentsNearStorageBalance.toString());
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_caip2 = require('../../lib/caip2.cjs');
|
|
3
|
+
const require_poa_constants = require('./poa-constants.cjs');
|
|
3
4
|
let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
4
5
|
|
|
5
6
|
//#region src/bridges/poa-bridge/poa-bridge-utils.ts
|
|
@@ -13,7 +14,8 @@ function createWithdrawIntentPrimitive(params) {
|
|
|
13
14
|
memo: createWithdrawMemo({
|
|
14
15
|
receiverAddress: params.destinationAddress,
|
|
15
16
|
xrpMemo: params.destinationMemo
|
|
16
|
-
})
|
|
17
|
+
}),
|
|
18
|
+
min_gas: require_poa_constants.MIN_GAS_AMOUNT
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
21
|
function createWithdrawMemo({ receiverAddress, xrpMemo }) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Chains } from "../../lib/caip2.js";
|
|
2
|
+
import { MIN_GAS_AMOUNT } from "./poa-constants.js";
|
|
2
3
|
import { utils } from "@defuse-protocol/internal-utils";
|
|
3
4
|
|
|
4
5
|
//#region src/bridges/poa-bridge/poa-bridge-utils.ts
|
|
@@ -12,7 +13,8 @@ function createWithdrawIntentPrimitive(params) {
|
|
|
12
13
|
memo: createWithdrawMemo({
|
|
13
14
|
receiverAddress: params.destinationAddress,
|
|
14
15
|
xrpMemo: params.destinationMemo
|
|
15
|
-
})
|
|
16
|
+
}),
|
|
17
|
+
min_gas: MIN_GAS_AMOUNT
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
function createWithdrawMemo({ receiverAddress, xrpMemo }) {
|
|
@@ -89,7 +89,7 @@ var PoaBridge = class {
|
|
|
89
89
|
async waitForWithdrawalCompletion(args) {
|
|
90
90
|
return { hash: (await __defuse_protocol_internal_utils.poaBridge.waitForWithdrawalCompletion({
|
|
91
91
|
txHash: args.tx.hash,
|
|
92
|
-
|
|
92
|
+
withdrawalCriteria: { assetId: args.withdrawalParams.assetId },
|
|
93
93
|
signal: args.signal ?? new AbortController().signal,
|
|
94
94
|
retryOptions: args.retryOptions,
|
|
95
95
|
baseURL: __defuse_protocol_internal_utils.configsByEnvironment[this.env].poaBridgeBaseURL,
|
|
@@ -87,7 +87,7 @@ var PoaBridge = class {
|
|
|
87
87
|
async waitForWithdrawalCompletion(args) {
|
|
88
88
|
return { hash: (await poaBridge.waitForWithdrawalCompletion({
|
|
89
89
|
txHash: args.tx.hash,
|
|
90
|
-
|
|
90
|
+
withdrawalCriteria: { assetId: args.withdrawalParams.assetId },
|
|
91
91
|
signal: args.signal ?? new AbortController().signal,
|
|
92
92
|
retryOptions: args.retryOptions,
|
|
93
93
|
baseURL: configsByEnvironment[this.env].poaBridgeBaseURL,
|
package/dist/src/sdk.cjs
CHANGED
|
@@ -208,18 +208,16 @@ var IntentsSDK = class {
|
|
|
208
208
|
throw new Error(`Cannot determine bridge for withdrawal = ${(0, viem.stringify)(args.withdrawalParams)}`);
|
|
209
209
|
}
|
|
210
210
|
getWithdrawalsIdentifiers({ withdrawalParams, intentTx }) {
|
|
211
|
-
const indexes = new Map(
|
|
212
|
-
return require_route_config.determineRouteConfig(this, w).route;
|
|
213
|
-
}), Array(withdrawalParams.length).fill(0)));
|
|
211
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
214
212
|
return withdrawalParams.map((w) => {
|
|
215
213
|
const routeConfig = require_route_config.determineRouteConfig(this, w);
|
|
216
214
|
const route = routeConfig.route;
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
indexes.set(route, index + 1);
|
|
215
|
+
const currentIndex = indexes.get(route) ?? 0;
|
|
216
|
+
indexes.set(route, currentIndex + 1);
|
|
220
217
|
return {
|
|
221
218
|
routeConfig,
|
|
222
|
-
index,
|
|
219
|
+
index: currentIndex,
|
|
220
|
+
withdrawalParams: w,
|
|
223
221
|
tx: intentTx
|
|
224
222
|
};
|
|
225
223
|
});
|
|
@@ -233,6 +231,7 @@ var IntentsSDK = class {
|
|
|
233
231
|
for (const bridge of this.bridges) if (bridge.is(wid.routeConfig)) return bridge.waitForWithdrawalCompletion({
|
|
234
232
|
tx: args.intentTx,
|
|
235
233
|
index: wid.index,
|
|
234
|
+
withdrawalParams: wid.withdrawalParams,
|
|
236
235
|
routeConfig: wid.routeConfig,
|
|
237
236
|
signal: args.signal,
|
|
238
237
|
retryOptions: args.retryOptions,
|
package/dist/src/sdk.js
CHANGED
|
@@ -206,18 +206,16 @@ var IntentsSDK = class {
|
|
|
206
206
|
throw new Error(`Cannot determine bridge for withdrawal = ${stringify(args.withdrawalParams)}`);
|
|
207
207
|
}
|
|
208
208
|
getWithdrawalsIdentifiers({ withdrawalParams, intentTx }) {
|
|
209
|
-
const indexes = new Map(
|
|
210
|
-
return determineRouteConfig(this, w).route;
|
|
211
|
-
}), Array(withdrawalParams.length).fill(0)));
|
|
209
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
212
210
|
return withdrawalParams.map((w) => {
|
|
213
211
|
const routeConfig = determineRouteConfig(this, w);
|
|
214
212
|
const route = routeConfig.route;
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
indexes.set(route, index + 1);
|
|
213
|
+
const currentIndex = indexes.get(route) ?? 0;
|
|
214
|
+
indexes.set(route, currentIndex + 1);
|
|
218
215
|
return {
|
|
219
216
|
routeConfig,
|
|
220
|
-
index,
|
|
217
|
+
index: currentIndex,
|
|
218
|
+
withdrawalParams: w,
|
|
221
219
|
tx: intentTx
|
|
222
220
|
};
|
|
223
221
|
});
|
|
@@ -231,6 +229,7 @@ var IntentsSDK = class {
|
|
|
231
229
|
for (const bridge of this.bridges) if (bridge.is(wid.routeConfig)) return bridge.waitForWithdrawalCompletion({
|
|
232
230
|
tx: args.intentTx,
|
|
233
231
|
index: wid.index,
|
|
232
|
+
withdrawalParams: wid.withdrawalParams,
|
|
234
233
|
routeConfig: wid.routeConfig,
|
|
235
234
|
signal: args.signal,
|
|
236
235
|
retryOptions: args.retryOptions,
|
|
@@ -219,6 +219,8 @@ interface RouteFeeStructures {
|
|
|
219
219
|
[RouteEnum.HotBridge]: {
|
|
220
220
|
/** Relayer fee for processing the withdrawal on destination chain, taken in base token of destination chain. */
|
|
221
221
|
relayerFee: bigint;
|
|
222
|
+
/** Block number at the time of fee estimation, required for building gasless withdraw intent. */
|
|
223
|
+
blockNumber: bigint;
|
|
222
224
|
};
|
|
223
225
|
[RouteEnum.PoaBridge]: {
|
|
224
226
|
/** Relayer fee for POA bridge transfers, taken in transferred token. */
|
|
@@ -296,6 +298,7 @@ interface Bridge {
|
|
|
296
298
|
waitForWithdrawalCompletion(args: {
|
|
297
299
|
tx: NearTxInfo;
|
|
298
300
|
index: number;
|
|
301
|
+
withdrawalParams: WithdrawalParams;
|
|
299
302
|
routeConfig: RouteConfig;
|
|
300
303
|
signal?: AbortSignal;
|
|
301
304
|
retryOptions?: RetryOptions;
|
|
@@ -305,6 +308,7 @@ interface Bridge {
|
|
|
305
308
|
interface WithdrawalIdentifier {
|
|
306
309
|
routeConfig: RouteConfig;
|
|
307
310
|
index: number;
|
|
311
|
+
withdrawalParams: WithdrawalParams;
|
|
308
312
|
tx: NearTxInfo;
|
|
309
313
|
}
|
|
310
314
|
type ParsedAssetInfo = ({
|
|
@@ -219,6 +219,8 @@ interface RouteFeeStructures {
|
|
|
219
219
|
[RouteEnum.HotBridge]: {
|
|
220
220
|
/** Relayer fee for processing the withdrawal on destination chain, taken in base token of destination chain. */
|
|
221
221
|
relayerFee: bigint;
|
|
222
|
+
/** Block number at the time of fee estimation, required for building gasless withdraw intent. */
|
|
223
|
+
blockNumber: bigint;
|
|
222
224
|
};
|
|
223
225
|
[RouteEnum.PoaBridge]: {
|
|
224
226
|
/** Relayer fee for POA bridge transfers, taken in transferred token. */
|
|
@@ -296,6 +298,7 @@ interface Bridge {
|
|
|
296
298
|
waitForWithdrawalCompletion(args: {
|
|
297
299
|
tx: NearTxInfo;
|
|
298
300
|
index: number;
|
|
301
|
+
withdrawalParams: WithdrawalParams;
|
|
299
302
|
routeConfig: RouteConfig;
|
|
300
303
|
signal?: AbortSignal;
|
|
301
304
|
retryOptions?: RetryOptions;
|
|
@@ -305,6 +308,7 @@ interface Bridge {
|
|
|
305
308
|
interface WithdrawalIdentifier {
|
|
306
309
|
routeConfig: RouteConfig;
|
|
307
310
|
index: number;
|
|
311
|
+
withdrawalParams: WithdrawalParams;
|
|
308
312
|
tx: NearTxInfo;
|
|
309
313
|
}
|
|
310
314
|
type ParsedAssetInfo = ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.43.
|
|
3
|
+
"version": "0.43.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typescript": "^5"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@hot-labs/omni-sdk": "2.
|
|
34
|
+
"@hot-labs/omni-sdk": "2.24.0",
|
|
35
35
|
"@isaacs/ttlcache": "^1.0.0",
|
|
36
36
|
"@lifeomic/attempt": "^3.0.0",
|
|
37
37
|
"@near-js/accounts": "^2.0.1",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"valibot": "^1.0.0",
|
|
49
49
|
"viem": "^2.0.0",
|
|
50
50
|
"@defuse-protocol/contract-types": "0.4.3",
|
|
51
|
-
"@defuse-protocol/internal-utils": "0.21.
|
|
51
|
+
"@defuse-protocol/internal-utils": "0.21.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"tsdown": "0.15.5",
|