@defuse-protocol/intents-sdk 0.43.2 → 0.44.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/README.md +143 -21
- package/dist/index.cjs +19 -18
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +7 -5
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +5 -5
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +24 -12
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +19 -7
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +5 -5
- package/dist/src/bridges/direct-bridge/direct-bridge.cjs +22 -10
- package/dist/src/bridges/direct-bridge/direct-bridge.js +16 -4
- package/dist/src/bridges/direct-bridge/error.cjs +2 -2
- package/dist/src/bridges/hot-bridge/error.cjs +4 -26
- package/dist/src/bridges/hot-bridge/error.d.cts +1 -17
- package/dist/src/bridges/hot-bridge/error.d.ts +1 -17
- package/dist/src/bridges/hot-bridge/error.js +1 -21
- package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +10 -10
- package/dist/src/bridges/hot-bridge/hot-bridge.cjs +46 -32
- package/dist/src/bridges/hot-bridge/hot-bridge.js +38 -24
- package/dist/src/bridges/intents-bridge/intents-bridge.cjs +18 -4
- package/dist/src/bridges/intents-bridge/intents-bridge.js +18 -4
- package/dist/src/bridges/omni-bridge/error.cjs +6 -27
- package/dist/src/bridges/omni-bridge/error.d.cts +1 -16
- package/dist/src/bridges/omni-bridge/error.d.ts +1 -16
- package/dist/src/bridges/omni-bridge/error.js +1 -20
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +12 -7
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +5 -1
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +72 -54
- package/dist/src/bridges/omni-bridge/omni-bridge.js +47 -29
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +2 -2
- package/dist/src/bridges/poa-bridge/poa-bridge.cjs +79 -26
- package/dist/src/bridges/poa-bridge/poa-bridge.js +66 -13
- package/dist/src/classes/errors.cjs +7 -7
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
- package/dist/src/constants/withdrawal-timing.cjs +57 -0
- package/dist/src/constants/withdrawal-timing.js +56 -0
- package/dist/src/core/withdrawal-watcher.cjs +83 -0
- package/dist/src/core/withdrawal-watcher.d.cts +18 -0
- package/dist/src/core/withdrawal-watcher.d.ts +18 -0
- package/dist/src/core/withdrawal-watcher.js +79 -0
- package/dist/src/intents/expirable-nonce.cjs +3 -3
- package/dist/src/intents/intent-executer-impl/intent-executer.cjs +7 -4
- package/dist/src/intents/intent-executer-impl/intent-executer.js +5 -2
- package/dist/src/intents/intent-hash.cjs +2 -2
- package/dist/src/intents/intent-hashes/erc191.cjs +2 -2
- package/dist/src/intents/intent-hashes/nep413.cjs +2 -2
- package/dist/src/intents/intent-hashes/raw-ed25519.cjs +2 -2
- package/dist/src/intents/intent-hashes/sep53.cjs +4 -4
- package/dist/src/intents/intent-hashes/tip191.cjs +2 -2
- package/dist/src/intents/intent-hashes/ton-connect.cjs +2 -2
- package/dist/src/intents/intent-hashes/webauthn.cjs +2 -2
- package/dist/src/intents/intent-payload-builder.cjs +4 -4
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +7 -7
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +1 -1
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +2 -2
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +3 -3
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +3 -3
- package/dist/src/intents/interfaces/intent-relayer.d.cts +2 -1
- package/dist/src/intents/interfaces/intent-relayer.d.ts +2 -1
- package/dist/src/intents/salt-manager.cjs +5 -5
- package/dist/src/lib/array.cjs +2 -2
- package/dist/src/lib/caip2.cjs +4 -4
- package/dist/src/lib/configure-rpc-config.cjs +3 -3
- package/dist/src/lib/estimate-fee.cjs +6 -6
- package/dist/src/lib/parse-defuse-asset-id.cjs +2 -2
- package/dist/src/lib/route-config-factory.cjs +2 -5
- package/dist/src/lib/route-config-factory.d.cts +1 -1
- package/dist/src/lib/route-config-factory.d.ts +1 -1
- package/dist/src/lib/route-config-factory.js +2 -5
- package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +3 -3
- package/dist/src/lib/validateAddress.cjs +18 -18
- package/dist/src/sdk.cjs +96 -47
- package/dist/src/sdk.d.cts +72 -11
- package/dist/src/sdk.d.ts +72 -11
- package/dist/src/sdk.js +85 -36
- package/dist/src/shared-types.d.cts +49 -15
- package/dist/src/shared-types.d.ts +49 -15
- package/package.json +5 -7
- package/dist/src/lib/route-config.cjs +0 -19
- package/dist/src/lib/route-config.js +0 -19
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_errors = require('../../classes/errors.cjs');
|
|
2
3
|
const require_route_enum = require('../../constants/route-enum.cjs');
|
|
4
|
+
const require_caip2 = require('../../lib/caip2.cjs');
|
|
3
5
|
const require_estimate_fee = require('../../lib/estimate-fee.cjs');
|
|
4
|
-
const require_errors = require('../../classes/errors.cjs');
|
|
5
6
|
const require_parse_defuse_asset_id = require('../../lib/parse-defuse-asset-id.cjs');
|
|
6
|
-
const require_caip2 = require('../../lib/caip2.cjs');
|
|
7
7
|
const require_validateAddress = require('../../lib/validateAddress.cjs');
|
|
8
8
|
const require_bridge_name_enum = require('../../constants/bridge-name-enum.cjs');
|
|
9
9
|
const require_direct_bridge_constants = require('./direct-bridge-constants.cjs');
|
|
10
10
|
const require_direct_bridge_utils = require('./direct-bridge-utils.cjs');
|
|
11
11
|
const require_error = require('./error.cjs');
|
|
12
|
-
let
|
|
12
|
+
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
13
13
|
let lru_cache = require("lru-cache");
|
|
14
14
|
|
|
15
15
|
//#region src/bridges/direct-bridge/direct-bridge.ts
|
|
16
16
|
var DirectBridge = class {
|
|
17
17
|
constructor({ env, nearProvider, solverRelayApiKey }) {
|
|
18
|
+
this.route = require_route_enum.RouteEnum.NearWithdrawal;
|
|
18
19
|
this.storageDepositCache = new lru_cache.LRUCache({
|
|
19
20
|
max: 100,
|
|
20
21
|
ttl: 36e5
|
|
@@ -72,12 +73,12 @@ var DirectBridge = class {
|
|
|
72
73
|
*/
|
|
73
74
|
async validateWithdrawal(args) {
|
|
74
75
|
if (require_validateAddress.validateAddress(args.destinationAddress, require_caip2.Chains.Near) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, require_caip2.Chains.Near);
|
|
75
|
-
if (
|
|
76
|
+
if (_defuse_protocol_internal_utils.utils.isImplicitAccount(args.destinationAddress) === false && await this.getCachedAccountExistenceCheck(args.destinationAddress) === false) throw new require_error.DestinationExplicitNearAccountDoesntExistError(args.destinationAddress);
|
|
76
77
|
}
|
|
77
78
|
async estimateWithdrawalFee(args) {
|
|
78
79
|
require_direct_bridge_utils.withdrawalParamsInvariant(args.withdrawalParams);
|
|
79
|
-
const { contractId: tokenAccountId, standard } =
|
|
80
|
-
(0,
|
|
80
|
+
const { contractId: tokenAccountId, standard } = _defuse_protocol_internal_utils.utils.parseDefuseAssetId(args.withdrawalParams.assetId);
|
|
81
|
+
(0, _defuse_protocol_internal_utils.assert)(standard === "nep141", "Only NEP-141 is supported");
|
|
81
82
|
if (args.withdrawalParams.assetId === require_direct_bridge_constants.NEAR_NATIVE_ASSET_ID && args.withdrawalParams.routeConfig?.msg === void 0) return {
|
|
82
83
|
amount: 0n,
|
|
83
84
|
quote: null,
|
|
@@ -113,10 +114,10 @@ var DirectBridge = class {
|
|
|
113
114
|
const key = `${contractId}${accountId}`;
|
|
114
115
|
const cached = this.storageDepositCache.get(key);
|
|
115
116
|
if (cached !== void 0) return cached;
|
|
116
|
-
const result = await Promise.all([(0,
|
|
117
|
+
const result = await Promise.all([(0, _defuse_protocol_internal_utils.getNearNep141MinStorageBalance)({
|
|
117
118
|
contractId,
|
|
118
119
|
nearProvider: this.nearProvider
|
|
119
|
-
}), (0,
|
|
120
|
+
}), (0, _defuse_protocol_internal_utils.getNearNep141StorageBalance)({
|
|
120
121
|
contractId,
|
|
121
122
|
accountId,
|
|
122
123
|
nearProvider: this.nearProvider
|
|
@@ -134,8 +135,19 @@ var DirectBridge = class {
|
|
|
134
135
|
if (exist) this.accountExistenceCache.set(accountId, exist);
|
|
135
136
|
return exist;
|
|
136
137
|
}
|
|
137
|
-
|
|
138
|
-
return {
|
|
138
|
+
createWithdrawalIdentifier(args) {
|
|
139
|
+
return {
|
|
140
|
+
landingChain: require_caip2.Chains.Near,
|
|
141
|
+
index: args.index,
|
|
142
|
+
withdrawalParams: args.withdrawalParams,
|
|
143
|
+
tx: args.tx
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
async describeWithdrawal(args) {
|
|
147
|
+
return {
|
|
148
|
+
status: "completed",
|
|
149
|
+
txHash: args.tx.hash
|
|
150
|
+
};
|
|
139
151
|
}
|
|
140
152
|
};
|
|
141
153
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { InvalidDestinationAddressForWithdrawalError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
1
2
|
import { RouteEnum } from "../../constants/route-enum.js";
|
|
3
|
+
import { Chains } from "../../lib/caip2.js";
|
|
2
4
|
import { getFeeQuote, getUnderlyingFee } from "../../lib/estimate-fee.js";
|
|
3
|
-
import { InvalidDestinationAddressForWithdrawalError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
4
5
|
import { parseDefuseAssetId } from "../../lib/parse-defuse-asset-id.js";
|
|
5
|
-
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 { NEAR_NATIVE_ASSET_ID } from "./direct-bridge-constants.js";
|
|
@@ -14,6 +14,7 @@ import { LRUCache } from "lru-cache";
|
|
|
14
14
|
//#region src/bridges/direct-bridge/direct-bridge.ts
|
|
15
15
|
var DirectBridge = class {
|
|
16
16
|
constructor({ env, nearProvider, solverRelayApiKey }) {
|
|
17
|
+
this.route = RouteEnum.NearWithdrawal;
|
|
17
18
|
this.storageDepositCache = new LRUCache({
|
|
18
19
|
max: 100,
|
|
19
20
|
ttl: 36e5
|
|
@@ -133,8 +134,19 @@ var DirectBridge = class {
|
|
|
133
134
|
if (exist) this.accountExistenceCache.set(accountId, exist);
|
|
134
135
|
return exist;
|
|
135
136
|
}
|
|
136
|
-
|
|
137
|
-
return {
|
|
137
|
+
createWithdrawalIdentifier(args) {
|
|
138
|
+
return {
|
|
139
|
+
landingChain: Chains.Near,
|
|
140
|
+
index: args.index,
|
|
141
|
+
withdrawalParams: args.withdrawalParams,
|
|
142
|
+
tx: args.tx
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async describeWithdrawal(args) {
|
|
146
|
+
return {
|
|
147
|
+
status: "completed",
|
|
148
|
+
txHash: args.tx.hash
|
|
149
|
+
};
|
|
138
150
|
}
|
|
139
151
|
};
|
|
140
152
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
3
3
|
|
|
4
4
|
//#region src/bridges/direct-bridge/error.ts
|
|
5
|
-
var DestinationExplicitNearAccountDoesntExistError = class extends
|
|
5
|
+
var DestinationExplicitNearAccountDoesntExistError = class extends _defuse_protocol_internal_utils.BaseError {
|
|
6
6
|
constructor(accountId) {
|
|
7
7
|
super("Destination explicit NEAR account doesn't exist.", {
|
|
8
8
|
metaMessages: [`Account Id: ${accountId}`],
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
3
3
|
|
|
4
4
|
//#region src/bridges/hot-bridge/error.ts
|
|
5
|
-
var
|
|
6
|
-
constructor(txHash, index) {
|
|
7
|
-
super("Withdrawal is still pending.", {
|
|
8
|
-
metaMessages: [`TxHash: ${txHash}`, `Index: ${index}`],
|
|
9
|
-
name: "HotWithdrawalPendingError"
|
|
10
|
-
});
|
|
11
|
-
this.txHash = txHash;
|
|
12
|
-
this.index = index;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
var HotWithdrawalNotFoundError = class extends __defuse_protocol_internal_utils.BaseError {
|
|
5
|
+
var HotWithdrawalNotFoundError = class extends _defuse_protocol_internal_utils.BaseError {
|
|
16
6
|
constructor(txHash, index) {
|
|
17
7
|
super("Withdrawal with given index is not found.", {
|
|
18
8
|
metaMessages: [`TxHash: ${txHash}`, `Index: ${index}`],
|
|
@@ -22,17 +12,7 @@ var HotWithdrawalNotFoundError = class extends __defuse_protocol_internal_utils.
|
|
|
22
12
|
this.index = index;
|
|
23
13
|
}
|
|
24
14
|
};
|
|
25
|
-
var
|
|
26
|
-
constructor(txHash, index) {
|
|
27
|
-
super("Gasless withdrawal was canceled.", {
|
|
28
|
-
metaMessages: [`TxHash: ${txHash}`, `Index: ${index}`],
|
|
29
|
-
name: "HotWithdrawalCancelledError"
|
|
30
|
-
});
|
|
31
|
-
this.txHash = txHash;
|
|
32
|
-
this.index = index;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var HotWithdrawalApiFeeRequestTimeoutError = class extends __defuse_protocol_internal_utils.BaseError {
|
|
15
|
+
var HotWithdrawalApiFeeRequestTimeoutError = class extends _defuse_protocol_internal_utils.BaseError {
|
|
36
16
|
constructor() {
|
|
37
17
|
super("Hot bridge withdrawal fee request timed out.", { name: "HotWithdrawalApiFeeRequestTimeoutError" });
|
|
38
18
|
}
|
|
@@ -40,6 +20,4 @@ var HotWithdrawalApiFeeRequestTimeoutError = class extends __defuse_protocol_int
|
|
|
40
20
|
|
|
41
21
|
//#endregion
|
|
42
22
|
exports.HotWithdrawalApiFeeRequestTimeoutError = HotWithdrawalApiFeeRequestTimeoutError;
|
|
43
|
-
exports.
|
|
44
|
-
exports.HotWithdrawalNotFoundError = HotWithdrawalNotFoundError;
|
|
45
|
-
exports.HotWithdrawalPendingError = HotWithdrawalPendingError;
|
|
23
|
+
exports.HotWithdrawalNotFoundError = HotWithdrawalNotFoundError;
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { BaseError } from "@defuse-protocol/internal-utils";
|
|
2
2
|
|
|
3
3
|
//#region src/bridges/hot-bridge/error.d.ts
|
|
4
|
-
type HotWithdrawalPendingErrorType = HotWithdrawalPendingError & {
|
|
5
|
-
name: "HotWithdrawalPendingError";
|
|
6
|
-
};
|
|
7
|
-
declare class HotWithdrawalPendingError extends BaseError {
|
|
8
|
-
txHash: string;
|
|
9
|
-
index: number;
|
|
10
|
-
constructor(txHash: string, index: number);
|
|
11
|
-
}
|
|
12
4
|
type HotWithdrawalNotFoundErrorType = HotWithdrawalNotFoundError & {
|
|
13
5
|
name: "HotWithdrawalNotFoundError";
|
|
14
6
|
};
|
|
@@ -17,14 +9,6 @@ declare class HotWithdrawalNotFoundError extends BaseError {
|
|
|
17
9
|
index: number;
|
|
18
10
|
constructor(txHash: string, index: number);
|
|
19
11
|
}
|
|
20
|
-
type HotWithdrawalCancelledErrorType = HotWithdrawalCancelledError & {
|
|
21
|
-
name: "HotWithdrawalCancelledError";
|
|
22
|
-
};
|
|
23
|
-
declare class HotWithdrawalCancelledError extends BaseError {
|
|
24
|
-
txHash: string;
|
|
25
|
-
index: number;
|
|
26
|
-
constructor(txHash: string, index: number);
|
|
27
|
-
}
|
|
28
12
|
type HotWithdrawalApiFeeRequestTimeoutErrorType = HotWithdrawalApiFeeRequestTimeoutError & {
|
|
29
13
|
name: "HotWithdrawalApiFeeRequestTimeoutError";
|
|
30
14
|
};
|
|
@@ -32,4 +16,4 @@ declare class HotWithdrawalApiFeeRequestTimeoutError extends BaseError {
|
|
|
32
16
|
constructor();
|
|
33
17
|
}
|
|
34
18
|
//#endregion
|
|
35
|
-
export { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalApiFeeRequestTimeoutErrorType,
|
|
19
|
+
export { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType };
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { BaseError } from "@defuse-protocol/internal-utils";
|
|
2
2
|
|
|
3
3
|
//#region src/bridges/hot-bridge/error.d.ts
|
|
4
|
-
type HotWithdrawalPendingErrorType = HotWithdrawalPendingError & {
|
|
5
|
-
name: "HotWithdrawalPendingError";
|
|
6
|
-
};
|
|
7
|
-
declare class HotWithdrawalPendingError extends BaseError {
|
|
8
|
-
txHash: string;
|
|
9
|
-
index: number;
|
|
10
|
-
constructor(txHash: string, index: number);
|
|
11
|
-
}
|
|
12
4
|
type HotWithdrawalNotFoundErrorType = HotWithdrawalNotFoundError & {
|
|
13
5
|
name: "HotWithdrawalNotFoundError";
|
|
14
6
|
};
|
|
@@ -17,14 +9,6 @@ declare class HotWithdrawalNotFoundError extends BaseError {
|
|
|
17
9
|
index: number;
|
|
18
10
|
constructor(txHash: string, index: number);
|
|
19
11
|
}
|
|
20
|
-
type HotWithdrawalCancelledErrorType = HotWithdrawalCancelledError & {
|
|
21
|
-
name: "HotWithdrawalCancelledError";
|
|
22
|
-
};
|
|
23
|
-
declare class HotWithdrawalCancelledError extends BaseError {
|
|
24
|
-
txHash: string;
|
|
25
|
-
index: number;
|
|
26
|
-
constructor(txHash: string, index: number);
|
|
27
|
-
}
|
|
28
12
|
type HotWithdrawalApiFeeRequestTimeoutErrorType = HotWithdrawalApiFeeRequestTimeoutError & {
|
|
29
13
|
name: "HotWithdrawalApiFeeRequestTimeoutError";
|
|
30
14
|
};
|
|
@@ -32,4 +16,4 @@ declare class HotWithdrawalApiFeeRequestTimeoutError extends BaseError {
|
|
|
32
16
|
constructor();
|
|
33
17
|
}
|
|
34
18
|
//#endregion
|
|
35
|
-
export { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalApiFeeRequestTimeoutErrorType,
|
|
19
|
+
export { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType };
|
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import { BaseError } from "@defuse-protocol/internal-utils";
|
|
2
2
|
|
|
3
3
|
//#region src/bridges/hot-bridge/error.ts
|
|
4
|
-
var HotWithdrawalPendingError = class extends BaseError {
|
|
5
|
-
constructor(txHash, index) {
|
|
6
|
-
super("Withdrawal is still pending.", {
|
|
7
|
-
metaMessages: [`TxHash: ${txHash}`, `Index: ${index}`],
|
|
8
|
-
name: "HotWithdrawalPendingError"
|
|
9
|
-
});
|
|
10
|
-
this.txHash = txHash;
|
|
11
|
-
this.index = index;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
4
|
var HotWithdrawalNotFoundError = class extends BaseError {
|
|
15
5
|
constructor(txHash, index) {
|
|
16
6
|
super("Withdrawal with given index is not found.", {
|
|
@@ -21,16 +11,6 @@ var HotWithdrawalNotFoundError = class extends BaseError {
|
|
|
21
11
|
this.index = index;
|
|
22
12
|
}
|
|
23
13
|
};
|
|
24
|
-
var HotWithdrawalCancelledError = class extends BaseError {
|
|
25
|
-
constructor(txHash, index) {
|
|
26
|
-
super("Gasless withdrawal was canceled.", {
|
|
27
|
-
metaMessages: [`TxHash: ${txHash}`, `Index: ${index}`],
|
|
28
|
-
name: "HotWithdrawalCancelledError"
|
|
29
|
-
});
|
|
30
|
-
this.txHash = txHash;
|
|
31
|
-
this.index = index;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
14
|
var HotWithdrawalApiFeeRequestTimeoutError = class extends BaseError {
|
|
35
15
|
constructor() {
|
|
36
16
|
super("Hot bridge withdrawal fee request timed out.", { name: "HotWithdrawalApiFeeRequestTimeoutError" });
|
|
@@ -38,4 +18,4 @@ var HotWithdrawalApiFeeRequestTimeoutError = class extends BaseError {
|
|
|
38
18
|
};
|
|
39
19
|
|
|
40
20
|
//#endregion
|
|
41
|
-
export { HotWithdrawalApiFeeRequestTimeoutError,
|
|
21
|
+
export { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalNotFoundError };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_caip2 = require('../../lib/caip2.cjs');
|
|
3
3
|
const require_hot_bridge_chains = require('./hot-bridge-chains.cjs');
|
|
4
|
-
let
|
|
5
|
-
let
|
|
4
|
+
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
5
|
+
let _hot_labs_omni_sdk = require("@hot-labs/omni-sdk");
|
|
6
6
|
|
|
7
7
|
//#region src/bridges/hot-bridge/hot-bridge-utils.ts
|
|
8
8
|
const MONAD_MAINNET_NETWORK_ID = 143;
|
|
@@ -19,14 +19,14 @@ const nativeTokenMapping = {
|
|
|
19
19
|
[require_caip2.Chains.Adi]: "nep245:v2_1.omni.hot.tg:36900_11111111111111111111"
|
|
20
20
|
};
|
|
21
21
|
const caip2NetworkIdMapping = {
|
|
22
|
-
[require_caip2.Chains.BNB]:
|
|
23
|
-
[require_caip2.Chains.Polygon]:
|
|
22
|
+
[require_caip2.Chains.BNB]: _hot_labs_omni_sdk.Network.Bnb,
|
|
23
|
+
[require_caip2.Chains.Polygon]: _hot_labs_omni_sdk.Network.Polygon,
|
|
24
24
|
[require_caip2.Chains.Monad]: MONAD_MAINNET_NETWORK_ID,
|
|
25
|
-
[require_caip2.Chains.TON]:
|
|
26
|
-
[require_caip2.Chains.Optimism]:
|
|
27
|
-
[require_caip2.Chains.Avalanche]:
|
|
28
|
-
[require_caip2.Chains.Stellar]:
|
|
29
|
-
[require_caip2.Chains.LayerX]:
|
|
25
|
+
[require_caip2.Chains.TON]: _hot_labs_omni_sdk.Network.Ton,
|
|
26
|
+
[require_caip2.Chains.Optimism]: _hot_labs_omni_sdk.Network.Optimism,
|
|
27
|
+
[require_caip2.Chains.Avalanche]: _hot_labs_omni_sdk.Network.Avalanche,
|
|
28
|
+
[require_caip2.Chains.Stellar]: _hot_labs_omni_sdk.Network.Stellar,
|
|
29
|
+
[require_caip2.Chains.LayerX]: _hot_labs_omni_sdk.Network.Xlayer,
|
|
30
30
|
[require_caip2.Chains.Adi]: ADI_NETWORK_ID
|
|
31
31
|
};
|
|
32
32
|
const networkIdCAIP2Mapping = Object.fromEntries(Object.entries(caip2NetworkIdMapping).map(([k, v]) => [v, k]));
|
|
@@ -50,7 +50,7 @@ function formatTxHash(txHash, caip2) {
|
|
|
50
50
|
return txHash;
|
|
51
51
|
}
|
|
52
52
|
function hotBlockchainInvariant(blockchain) {
|
|
53
|
-
(0,
|
|
53
|
+
(0, _defuse_protocol_internal_utils.assert)(require_hot_bridge_chains.HotBridgeChains.includes(blockchain), `${blockchain} is not a valid HOT Bridge blockchain. Supported values: ${require_hot_bridge_chains.HotBridgeChains.join()}`);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
//#endregion
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_errors = require('../../classes/errors.cjs');
|
|
2
3
|
const require_route_enum = require('../../constants/route-enum.cjs');
|
|
4
|
+
const require_caip2 = require('../../lib/caip2.cjs');
|
|
3
5
|
const require_estimate_fee = require('../../lib/estimate-fee.cjs');
|
|
4
|
-
const require_errors = require('../../classes/errors.cjs');
|
|
5
6
|
const require_parse_defuse_asset_id = require('../../lib/parse-defuse-asset-id.cjs');
|
|
6
|
-
const require_caip2 = require('../../lib/caip2.cjs');
|
|
7
7
|
const require_validateAddress = require('../../lib/validateAddress.cjs');
|
|
8
8
|
const require_bridge_name_enum = require('../../constants/bridge-name-enum.cjs');
|
|
9
9
|
const require_error = require('./error.cjs');
|
|
10
10
|
const require_hot_bridge_constants = require('./hot-bridge-constants.cjs');
|
|
11
11
|
const require_hot_bridge_utils = require('./hot-bridge-utils.cjs');
|
|
12
12
|
const require_hex = require('../../lib/hex.cjs');
|
|
13
|
-
let
|
|
14
|
-
let
|
|
15
|
-
let __lifeomic_attempt = require("@lifeomic/attempt");
|
|
13
|
+
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
14
|
+
let _hot_labs_omni_sdk = require("@hot-labs/omni-sdk");
|
|
16
15
|
|
|
17
16
|
//#region src/bridges/hot-bridge/hot-bridge.ts
|
|
18
17
|
var HotBridge = class {
|
|
19
18
|
constructor({ env, hotSdk, solverRelayApiKey }) {
|
|
19
|
+
this.route = require_route_enum.RouteEnum.HotBridge;
|
|
20
20
|
this.env = env;
|
|
21
21
|
this.hotSdk = hotSdk;
|
|
22
22
|
this.solverRelayApiKey = solverRelayApiKey;
|
|
@@ -32,9 +32,9 @@ var HotBridge = class {
|
|
|
32
32
|
}
|
|
33
33
|
parseAssetId(assetId) {
|
|
34
34
|
const parsed = require_parse_defuse_asset_id.parseDefuseAssetId(assetId);
|
|
35
|
-
if (!(parsed.contractId ===
|
|
35
|
+
if (!(parsed.contractId === _hot_labs_omni_sdk.OMNI_HOT_V2)) return null;
|
|
36
36
|
if (parsed.standard !== "nep245") throw new require_errors.UnsupportedAssetIdError(assetId, "Should start with \"nep245:\".");
|
|
37
|
-
const [chainId, address] =
|
|
37
|
+
const [chainId, address] = _hot_labs_omni_sdk.utils.fromOmni(parsed.tokenId).split(":");
|
|
38
38
|
if (chainId == null || address == null) throw new require_errors.UnsupportedAssetIdError(assetId, "Asset has invalid token id format.");
|
|
39
39
|
let blockchain;
|
|
40
40
|
try {
|
|
@@ -49,7 +49,7 @@ var HotBridge = class {
|
|
|
49
49
|
}
|
|
50
50
|
async createWithdrawalIntents(args) {
|
|
51
51
|
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
52
|
-
(0,
|
|
52
|
+
(0, _defuse_protocol_internal_utils.assert)(assetInfo != null, "Asset is not supported");
|
|
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");
|
|
@@ -73,8 +73,8 @@ var HotBridge = class {
|
|
|
73
73
|
amount,
|
|
74
74
|
receiver: args.withdrawalParams.destinationAddress
|
|
75
75
|
});
|
|
76
|
-
(0,
|
|
77
|
-
if (intent.amounts.length === 2) (0,
|
|
76
|
+
(0, _defuse_protocol_internal_utils.assert)(intent.amounts[0] === amount.toString(), "Amount is not correct");
|
|
77
|
+
if (intent.amounts.length === 2) (0, _defuse_protocol_internal_utils.assert)(intent.amounts[1] === feeAmount.toString(), "Amount is not correct");
|
|
78
78
|
const mtWithdrawIntent = intent;
|
|
79
79
|
mtWithdrawIntent.min_gas = require_hot_bridge_constants.MIN_GAS_AMOUNT;
|
|
80
80
|
intents.push(mtWithdrawIntent);
|
|
@@ -87,7 +87,7 @@ var HotBridge = class {
|
|
|
87
87
|
*/
|
|
88
88
|
async validateWithdrawal(args) {
|
|
89
89
|
const assetInfo = this.parseAssetId(args.assetId);
|
|
90
|
-
(0,
|
|
90
|
+
(0, _defuse_protocol_internal_utils.assert)(assetInfo != null, "Asset is not supported");
|
|
91
91
|
require_hot_bridge_utils.hotBlockchainInvariant(assetInfo.blockchain);
|
|
92
92
|
if (require_validateAddress.validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
|
|
93
93
|
if (assetInfo.blockchain === require_caip2.Chains.Stellar) {
|
|
@@ -97,9 +97,9 @@ var HotBridge = class {
|
|
|
97
97
|
}
|
|
98
98
|
async estimateWithdrawalFee(args) {
|
|
99
99
|
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
100
|
-
(0,
|
|
100
|
+
(0, _defuse_protocol_internal_utils.assert)(assetInfo != null, "Asset is not supported");
|
|
101
101
|
require_hot_bridge_utils.hotBlockchainInvariant(assetInfo.blockchain);
|
|
102
|
-
const { gasPrice: feeAmount, blockNumber } = await (0,
|
|
102
|
+
const { gasPrice: feeAmount, blockNumber } = await (0, _defuse_protocol_internal_utils.withTimeout)(() => this.hotSdk.getGaslessWithdrawFee({
|
|
103
103
|
chain: require_hot_bridge_utils.toHotNetworkId(assetInfo.blockchain),
|
|
104
104
|
token: "native" in assetInfo ? "native" : assetInfo.address,
|
|
105
105
|
receiver: args.withdrawalParams.destinationAddress
|
|
@@ -126,28 +126,42 @@ var HotBridge = class {
|
|
|
126
126
|
} }
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
createWithdrawalIdentifier(args) {
|
|
130
|
+
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
131
|
+
(0, _defuse_protocol_internal_utils.assert)(assetInfo != null, "Asset is not supported");
|
|
132
|
+
return {
|
|
133
|
+
landingChain: assetInfo.blockchain,
|
|
134
|
+
index: args.index,
|
|
135
|
+
withdrawalParams: args.withdrawalParams,
|
|
136
|
+
tx: args.tx
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async describeWithdrawal(args) {
|
|
130
140
|
const nonce = (await this.hotSdk.near.parseWithdrawalNonces(args.tx.hash, args.tx.accountId))[args.index];
|
|
131
141
|
if (nonce == null) throw new require_error.HotWithdrawalNotFoundError(args.tx.hash, args.index);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (err instanceof require_error.HotWithdrawalCancelledError || err === args.signal?.reason) ctx.abort();
|
|
142
|
+
const status = await this.hotSdk.getGaslessWithdrawStatus(nonce.toString());
|
|
143
|
+
if (status === require_hot_bridge_constants.HotWithdrawStatus.Canceled) return {
|
|
144
|
+
status: "failed",
|
|
145
|
+
reason: "Withdrawal was cancelled"
|
|
146
|
+
};
|
|
147
|
+
if (status === require_hot_bridge_constants.HotWithdrawStatus.Completed) return {
|
|
148
|
+
status: "completed",
|
|
149
|
+
txHash: null
|
|
150
|
+
};
|
|
151
|
+
if (typeof status === "string") {
|
|
152
|
+
if (!require_hex.default(status)) {
|
|
153
|
+
args.logger?.warn("HOT Bridge incorrect destination tx hash detected", { value: status });
|
|
154
|
+
return {
|
|
155
|
+
status: "completed",
|
|
156
|
+
txHash: null
|
|
157
|
+
};
|
|
149
158
|
}
|
|
150
|
-
|
|
159
|
+
return {
|
|
160
|
+
status: "completed",
|
|
161
|
+
txHash: require_hot_bridge_utils.formatTxHash(status, args.landingChain)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return { status: "pending" };
|
|
151
165
|
}
|
|
152
166
|
};
|
|
153
167
|
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
import { InvalidDestinationAddressForWithdrawalError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError } from "../../classes/errors.js";
|
|
1
2
|
import { RouteEnum } from "../../constants/route-enum.js";
|
|
3
|
+
import { Chains } from "../../lib/caip2.js";
|
|
2
4
|
import { getFeeQuote, getUnderlyingFee } from "../../lib/estimate-fee.js";
|
|
3
|
-
import { InvalidDestinationAddressForWithdrawalError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError } from "../../classes/errors.js";
|
|
4
5
|
import { parseDefuseAssetId } from "../../lib/parse-defuse-asset-id.js";
|
|
5
|
-
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
|
-
import { HotWithdrawalApiFeeRequestTimeoutError,
|
|
8
|
+
import { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalNotFoundError } from "./error.js";
|
|
9
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
|
-
import {
|
|
12
|
+
import { assert, withTimeout } from "@defuse-protocol/internal-utils";
|
|
13
13
|
import { OMNI_HOT_V2, utils as utils$1 } from "@hot-labs/omni-sdk";
|
|
14
|
-
import { retry } from "@lifeomic/attempt";
|
|
15
14
|
|
|
16
15
|
//#region src/bridges/hot-bridge/hot-bridge.ts
|
|
17
16
|
var HotBridge$1 = class {
|
|
18
17
|
constructor({ env, hotSdk, solverRelayApiKey }) {
|
|
18
|
+
this.route = RouteEnum.HotBridge;
|
|
19
19
|
this.env = env;
|
|
20
20
|
this.hotSdk = hotSdk;
|
|
21
21
|
this.solverRelayApiKey = solverRelayApiKey;
|
|
@@ -125,28 +125,42 @@ var HotBridge$1 = class {
|
|
|
125
125
|
} }
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
createWithdrawalIdentifier(args) {
|
|
129
|
+
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
130
|
+
assert(assetInfo != null, "Asset is not supported");
|
|
131
|
+
return {
|
|
132
|
+
landingChain: assetInfo.blockchain,
|
|
133
|
+
index: args.index,
|
|
134
|
+
withdrawalParams: args.withdrawalParams,
|
|
135
|
+
tx: args.tx
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
async describeWithdrawal(args) {
|
|
129
139
|
const nonce = (await this.hotSdk.near.parseWithdrawalNonces(args.tx.hash, args.tx.accountId))[args.index];
|
|
130
140
|
if (nonce == null) throw new HotWithdrawalNotFoundError(args.tx.hash, args.index);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (err instanceof HotWithdrawalCancelledError || err === args.signal?.reason) ctx.abort();
|
|
141
|
+
const status = await this.hotSdk.getGaslessWithdrawStatus(nonce.toString());
|
|
142
|
+
if (status === HotWithdrawStatus.Canceled) return {
|
|
143
|
+
status: "failed",
|
|
144
|
+
reason: "Withdrawal was cancelled"
|
|
145
|
+
};
|
|
146
|
+
if (status === HotWithdrawStatus.Completed) return {
|
|
147
|
+
status: "completed",
|
|
148
|
+
txHash: null
|
|
149
|
+
};
|
|
150
|
+
if (typeof status === "string") {
|
|
151
|
+
if (!isHex(status)) {
|
|
152
|
+
args.logger?.warn("HOT Bridge incorrect destination tx hash detected", { value: status });
|
|
153
|
+
return {
|
|
154
|
+
status: "completed",
|
|
155
|
+
txHash: null
|
|
156
|
+
};
|
|
148
157
|
}
|
|
149
|
-
|
|
158
|
+
return {
|
|
159
|
+
status: "completed",
|
|
160
|
+
txHash: formatTxHash(status, args.landingChain)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return { status: "pending" };
|
|
150
164
|
}
|
|
151
165
|
};
|
|
152
166
|
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
const require_route_enum = require('../../constants/route-enum.cjs');
|
|
2
1
|
const require_errors = require('../../classes/errors.cjs');
|
|
2
|
+
const require_route_enum = require('../../constants/route-enum.cjs');
|
|
3
3
|
const require_caip2 = require('../../lib/caip2.cjs');
|
|
4
4
|
const require_validateAddress = require('../../lib/validateAddress.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/bridges/intents-bridge/intents-bridge.ts
|
|
7
7
|
var IntentsBridge = class {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.route = require_route_enum.RouteEnum.InternalTransfer;
|
|
10
|
+
}
|
|
8
11
|
is(routeConfig) {
|
|
9
|
-
return routeConfig.route ===
|
|
12
|
+
return routeConfig.route === this.route;
|
|
10
13
|
}
|
|
11
14
|
async supports(params) {
|
|
12
15
|
if ("routeConfig" in params && params.routeConfig != null) return this.is(params.routeConfig);
|
|
@@ -36,8 +39,19 @@ var IntentsBridge = class {
|
|
|
36
39
|
underlyingFees: { [require_route_enum.RouteEnum.InternalTransfer]: null }
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
return {
|
|
42
|
+
createWithdrawalIdentifier(args) {
|
|
43
|
+
return {
|
|
44
|
+
landingChain: require_caip2.Chains.Near,
|
|
45
|
+
index: args.index,
|
|
46
|
+
withdrawalParams: args.withdrawalParams,
|
|
47
|
+
tx: args.tx
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async describeWithdrawal(args) {
|
|
51
|
+
return {
|
|
52
|
+
status: "completed",
|
|
53
|
+
txHash: args.tx.hash
|
|
54
|
+
};
|
|
41
55
|
}
|
|
42
56
|
};
|
|
43
57
|
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { RouteEnum } from "../../constants/route-enum.js";
|
|
2
1
|
import { InvalidDestinationAddressForWithdrawalError } from "../../classes/errors.js";
|
|
2
|
+
import { RouteEnum } from "../../constants/route-enum.js";
|
|
3
3
|
import { Chains } from "../../lib/caip2.js";
|
|
4
4
|
import { validateAddress } from "../../lib/validateAddress.js";
|
|
5
5
|
|
|
6
6
|
//#region src/bridges/intents-bridge/intents-bridge.ts
|
|
7
7
|
var IntentsBridge = class {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.route = RouteEnum.InternalTransfer;
|
|
10
|
+
}
|
|
8
11
|
is(routeConfig) {
|
|
9
|
-
return routeConfig.route ===
|
|
12
|
+
return routeConfig.route === this.route;
|
|
10
13
|
}
|
|
11
14
|
async supports(params) {
|
|
12
15
|
if ("routeConfig" in params && params.routeConfig != null) return this.is(params.routeConfig);
|
|
@@ -36,8 +39,19 @@ var IntentsBridge = class {
|
|
|
36
39
|
underlyingFees: { [RouteEnum.InternalTransfer]: null }
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
return {
|
|
42
|
+
createWithdrawalIdentifier(args) {
|
|
43
|
+
return {
|
|
44
|
+
landingChain: Chains.Near,
|
|
45
|
+
index: args.index,
|
|
46
|
+
withdrawalParams: args.withdrawalParams,
|
|
47
|
+
tx: args.tx
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async describeWithdrawal(args) {
|
|
51
|
+
return {
|
|
52
|
+
status: "completed",
|
|
53
|
+
txHash: args.tx.hash
|
|
54
|
+
};
|
|
41
55
|
}
|
|
42
56
|
};
|
|
43
57
|
|