@defuse-protocol/intents-sdk 0.43.3 → 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 +4 -6
- package/dist/src/lib/route-config.cjs +0 -19
- package/dist/src/lib/route-config.js +0 -19
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region src/constants/withdrawal-timing.ts
|
|
2
|
+
/**
|
|
3
|
+
* Withdrawal timing p99 values (in seconds) by CAIP-2 chain identifier.
|
|
4
|
+
* Used to derive CompletionStats for chain-aware polling.
|
|
5
|
+
*/
|
|
6
|
+
const WITHDRAWAL_P99_BY_CHAIN = {
|
|
7
|
+
"eip155:1": 1852,
|
|
8
|
+
"eip155:56": 36,
|
|
9
|
+
"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": 1387,
|
|
10
|
+
"eip155:8453": 651,
|
|
11
|
+
"tron:27Lqcw": 2358,
|
|
12
|
+
"eip155:42161": 928,
|
|
13
|
+
"bip122:000000000019d6689c085ae165831e93": 3656,
|
|
14
|
+
"eip155:137": 410,
|
|
15
|
+
"xrpl:0": 2276,
|
|
16
|
+
"bip122:00040fe8ec8471911baa1db1266ea15d": 2093,
|
|
17
|
+
"tvm:-239": 53,
|
|
18
|
+
"near:mainnet": 356,
|
|
19
|
+
"bip122:12a765e31ffd4059bada1e25190f6e98": 2385,
|
|
20
|
+
"eip155:143": 22,
|
|
21
|
+
"eip155:43114": 657,
|
|
22
|
+
"stellar:pubnet": 50,
|
|
23
|
+
"eip155:10": 23,
|
|
24
|
+
"bip122:1a91e3dace36e2be3bf030a65679fe82": 1970,
|
|
25
|
+
"sui:mainnet": 752,
|
|
26
|
+
"eip155:80085": 579,
|
|
27
|
+
"eip155:100": 3308,
|
|
28
|
+
"aptos:mainnet": 394,
|
|
29
|
+
"cip34:1-764824073": 807
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Default stats for chains without timing data.
|
|
33
|
+
* Conservative 2-hour timeout with gradual phase transitions.
|
|
34
|
+
*/
|
|
35
|
+
const DEFAULT_WITHDRAWAL_STATS = {
|
|
36
|
+
p50: 6e4,
|
|
37
|
+
p90: 6e5,
|
|
38
|
+
p99: 72e5
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Returns CompletionStats for the given chain.
|
|
42
|
+
* Derives p50/p90 from p99 using reasonable ratios with minimum floors.
|
|
43
|
+
*/
|
|
44
|
+
function getWithdrawalStatsForChain(caip2) {
|
|
45
|
+
const p99Seconds = WITHDRAWAL_P99_BY_CHAIN[caip2];
|
|
46
|
+
if (p99Seconds == null) return DEFAULT_WITHDRAWAL_STATS;
|
|
47
|
+
const p99 = p99Seconds * 1e3;
|
|
48
|
+
return {
|
|
49
|
+
p50: Math.max(5e3, p99 * .15),
|
|
50
|
+
p90: Math.max(3e4, p99 * .5),
|
|
51
|
+
p99
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { getWithdrawalStatsForChain };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_withdrawal_timing = require('../constants/withdrawal-timing.cjs');
|
|
3
|
+
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
4
|
+
|
|
5
|
+
//#region src/core/withdrawal-watcher.ts
|
|
6
|
+
const MAX_CONSECUTIVE_ERRORS = 3;
|
|
7
|
+
async function watchWithdrawal(args) {
|
|
8
|
+
const stats = require_withdrawal_timing.getWithdrawalStatsForChain(args.wid.landingChain);
|
|
9
|
+
let consecutiveErrors = 0;
|
|
10
|
+
try {
|
|
11
|
+
return await (0, _defuse_protocol_internal_utils.poll)(async () => {
|
|
12
|
+
try {
|
|
13
|
+
const status = await args.bridge.describeWithdrawal({
|
|
14
|
+
...args.wid,
|
|
15
|
+
logger: args.logger
|
|
16
|
+
});
|
|
17
|
+
consecutiveErrors = 0;
|
|
18
|
+
if (status.status === "completed") return status.txHash != null ? { hash: status.txHash } : { hash: null };
|
|
19
|
+
if (status.status === "failed") throw new WithdrawalFailedError(status.reason);
|
|
20
|
+
return _defuse_protocol_internal_utils.POLL_PENDING;
|
|
21
|
+
} catch (err) {
|
|
22
|
+
if (err instanceof WithdrawalFailedError) throw err;
|
|
23
|
+
consecutiveErrors++;
|
|
24
|
+
if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) throw new WithdrawalWatchError(err);
|
|
25
|
+
args.logger?.warn(`Transient error (${consecutiveErrors}/${MAX_CONSECUTIVE_ERRORS}): ${err}`);
|
|
26
|
+
return _defuse_protocol_internal_utils.POLL_PENDING;
|
|
27
|
+
}
|
|
28
|
+
}, {
|
|
29
|
+
stats,
|
|
30
|
+
signal: args.signal
|
|
31
|
+
});
|
|
32
|
+
} catch (err) {
|
|
33
|
+
if (err instanceof _defuse_protocol_internal_utils.PollTimeoutError) throw new WithdrawalWatchError(err);
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function createWithdrawalIdentifiers(args) {
|
|
38
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
39
|
+
const results = [];
|
|
40
|
+
for (const w of args.withdrawalParams) {
|
|
41
|
+
const bridge = await findBridgeForWithdrawal(args.bridges, w);
|
|
42
|
+
if (bridge == null) throw new BridgeNotFoundError();
|
|
43
|
+
const currentIndex = indexes.get(bridge.route) ?? 0;
|
|
44
|
+
indexes.set(bridge.route, currentIndex + 1);
|
|
45
|
+
const wid = bridge.createWithdrawalIdentifier({
|
|
46
|
+
withdrawalParams: w,
|
|
47
|
+
index: currentIndex,
|
|
48
|
+
tx: args.intentTx
|
|
49
|
+
});
|
|
50
|
+
results.push({
|
|
51
|
+
bridge,
|
|
52
|
+
wid
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return results;
|
|
56
|
+
}
|
|
57
|
+
async function findBridgeForWithdrawal(bridges, params) {
|
|
58
|
+
for (const bridge of bridges) if (await bridge.supports(params)) return bridge;
|
|
59
|
+
}
|
|
60
|
+
var BridgeNotFoundError = class extends _defuse_protocol_internal_utils.BaseError {
|
|
61
|
+
constructor() {
|
|
62
|
+
super("Bridge adapter not found", { name: "BridgeNotFoundError" });
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var WithdrawalFailedError = class extends _defuse_protocol_internal_utils.BaseError {
|
|
66
|
+
constructor(reason) {
|
|
67
|
+
super(`Withdrawal failed: ${reason}`, { name: "WithdrawalFailedError" });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var WithdrawalWatchError = class extends _defuse_protocol_internal_utils.BaseError {
|
|
71
|
+
constructor(cause) {
|
|
72
|
+
super("Withdrawal watch failed", {
|
|
73
|
+
name: "WithdrawalWatchError",
|
|
74
|
+
cause
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
exports.WithdrawalFailedError = WithdrawalFailedError;
|
|
81
|
+
exports.WithdrawalWatchError = WithdrawalWatchError;
|
|
82
|
+
exports.createWithdrawalIdentifiers = createWithdrawalIdentifiers;
|
|
83
|
+
exports.watchWithdrawal = watchWithdrawal;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseError, ILogger } from "@defuse-protocol/internal-utils";
|
|
2
|
+
|
|
3
|
+
//#region src/core/withdrawal-watcher.d.ts
|
|
4
|
+
|
|
5
|
+
type WithdrawalFailedErrorType = WithdrawalFailedError & {
|
|
6
|
+
name: "WithdrawalFailedError";
|
|
7
|
+
};
|
|
8
|
+
declare class WithdrawalFailedError extends BaseError {
|
|
9
|
+
constructor(reason: string);
|
|
10
|
+
}
|
|
11
|
+
type WithdrawalWatchErrorType = WithdrawalWatchError & {
|
|
12
|
+
name: "WithdrawalWatchError";
|
|
13
|
+
};
|
|
14
|
+
declare class WithdrawalWatchError extends BaseError {
|
|
15
|
+
constructor(cause: unknown);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { WithdrawalFailedError, WithdrawalFailedErrorType, WithdrawalWatchError, WithdrawalWatchErrorType };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseError, ILogger } from "@defuse-protocol/internal-utils";
|
|
2
|
+
|
|
3
|
+
//#region src/core/withdrawal-watcher.d.ts
|
|
4
|
+
|
|
5
|
+
type WithdrawalFailedErrorType = WithdrawalFailedError & {
|
|
6
|
+
name: "WithdrawalFailedError";
|
|
7
|
+
};
|
|
8
|
+
declare class WithdrawalFailedError extends BaseError {
|
|
9
|
+
constructor(reason: string);
|
|
10
|
+
}
|
|
11
|
+
type WithdrawalWatchErrorType = WithdrawalWatchError & {
|
|
12
|
+
name: "WithdrawalWatchError";
|
|
13
|
+
};
|
|
14
|
+
declare class WithdrawalWatchError extends BaseError {
|
|
15
|
+
constructor(cause: unknown);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { WithdrawalFailedError, WithdrawalFailedErrorType, WithdrawalWatchError, WithdrawalWatchErrorType };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getWithdrawalStatsForChain } from "../constants/withdrawal-timing.js";
|
|
2
|
+
import { BaseError, POLL_PENDING, PollTimeoutError, poll } from "@defuse-protocol/internal-utils";
|
|
3
|
+
|
|
4
|
+
//#region src/core/withdrawal-watcher.ts
|
|
5
|
+
const MAX_CONSECUTIVE_ERRORS = 3;
|
|
6
|
+
async function watchWithdrawal(args) {
|
|
7
|
+
const stats = getWithdrawalStatsForChain(args.wid.landingChain);
|
|
8
|
+
let consecutiveErrors = 0;
|
|
9
|
+
try {
|
|
10
|
+
return await poll(async () => {
|
|
11
|
+
try {
|
|
12
|
+
const status = await args.bridge.describeWithdrawal({
|
|
13
|
+
...args.wid,
|
|
14
|
+
logger: args.logger
|
|
15
|
+
});
|
|
16
|
+
consecutiveErrors = 0;
|
|
17
|
+
if (status.status === "completed") return status.txHash != null ? { hash: status.txHash } : { hash: null };
|
|
18
|
+
if (status.status === "failed") throw new WithdrawalFailedError(status.reason);
|
|
19
|
+
return POLL_PENDING;
|
|
20
|
+
} catch (err) {
|
|
21
|
+
if (err instanceof WithdrawalFailedError) throw err;
|
|
22
|
+
consecutiveErrors++;
|
|
23
|
+
if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) throw new WithdrawalWatchError(err);
|
|
24
|
+
args.logger?.warn(`Transient error (${consecutiveErrors}/${MAX_CONSECUTIVE_ERRORS}): ${err}`);
|
|
25
|
+
return POLL_PENDING;
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
stats,
|
|
29
|
+
signal: args.signal
|
|
30
|
+
});
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (err instanceof PollTimeoutError) throw new WithdrawalWatchError(err);
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function createWithdrawalIdentifiers(args) {
|
|
37
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
38
|
+
const results = [];
|
|
39
|
+
for (const w of args.withdrawalParams) {
|
|
40
|
+
const bridge = await findBridgeForWithdrawal(args.bridges, w);
|
|
41
|
+
if (bridge == null) throw new BridgeNotFoundError();
|
|
42
|
+
const currentIndex = indexes.get(bridge.route) ?? 0;
|
|
43
|
+
indexes.set(bridge.route, currentIndex + 1);
|
|
44
|
+
const wid = bridge.createWithdrawalIdentifier({
|
|
45
|
+
withdrawalParams: w,
|
|
46
|
+
index: currentIndex,
|
|
47
|
+
tx: args.intentTx
|
|
48
|
+
});
|
|
49
|
+
results.push({
|
|
50
|
+
bridge,
|
|
51
|
+
wid
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return results;
|
|
55
|
+
}
|
|
56
|
+
async function findBridgeForWithdrawal(bridges, params) {
|
|
57
|
+
for (const bridge of bridges) if (await bridge.supports(params)) return bridge;
|
|
58
|
+
}
|
|
59
|
+
var BridgeNotFoundError = class extends BaseError {
|
|
60
|
+
constructor() {
|
|
61
|
+
super("Bridge adapter not found", { name: "BridgeNotFoundError" });
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var WithdrawalFailedError = class extends BaseError {
|
|
65
|
+
constructor(reason) {
|
|
66
|
+
super(`Withdrawal failed: ${reason}`, { name: "WithdrawalFailedError" });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var WithdrawalWatchError = class extends BaseError {
|
|
70
|
+
constructor(cause) {
|
|
71
|
+
super("Withdrawal watch failed", {
|
|
72
|
+
name: "WithdrawalWatchError",
|
|
73
|
+
cause
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { WithdrawalFailedError, WithdrawalWatchError, createWithdrawalIdentifiers, watchWithdrawal };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _scure_base = require("@scure/base");
|
|
3
3
|
let valibot = require("valibot");
|
|
4
4
|
valibot = require_rolldown_runtime.__toESM(valibot);
|
|
5
5
|
let near_api_js_lib_utils_serialize = require("near-api-js/lib/utils/serialize");
|
|
@@ -65,11 +65,11 @@ let VersionedNonceBuilder;
|
|
|
65
65
|
result.set(VERSIONED_MAGIC_PREFIX, 0);
|
|
66
66
|
result.set([LATEST_VERSION], 4);
|
|
67
67
|
result.set(borshBytes, 5);
|
|
68
|
-
return
|
|
68
|
+
return _scure_base.base64.encode(result);
|
|
69
69
|
}
|
|
70
70
|
_VersionedNonceBuilder.encodeNonce = encodeNonce;
|
|
71
71
|
function decodeNonce(encoded) {
|
|
72
|
-
const bytes =
|
|
72
|
+
const bytes = _scure_base.base64.decode(encoded);
|
|
73
73
|
if (bytes.length !== 32) throw new Error("Nonce too short");
|
|
74
74
|
const prefix = bytes.slice(0, 4);
|
|
75
75
|
const version = bytes[4];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_intent_hash = require('../intent-hash.cjs');
|
|
3
3
|
const require_intent_payload_factory = require('../intent-payload-factory.cjs');
|
|
4
|
-
let
|
|
4
|
+
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
5
5
|
|
|
6
6
|
//#region src/intents/intent-executer-impl/intent-executer.ts
|
|
7
7
|
var IntentExecuter = class {
|
|
@@ -14,7 +14,7 @@ var IntentExecuter = class {
|
|
|
14
14
|
this.onBeforePublishIntent = args.onBeforePublishIntent;
|
|
15
15
|
}
|
|
16
16
|
async signAndSendIntent({ relayParams: relayParamsFactory, salt, signedIntents, ...intentParams }) {
|
|
17
|
-
const verifyingContract =
|
|
17
|
+
const verifyingContract = _defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID;
|
|
18
18
|
let intentPayload = require_intent_payload_factory.defaultIntentPayloadFactory(salt, {
|
|
19
19
|
verifying_contract: verifyingContract,
|
|
20
20
|
...intentParams
|
|
@@ -44,8 +44,11 @@ var IntentExecuter = class {
|
|
|
44
44
|
...relayParams
|
|
45
45
|
}, { logger: this.logger }) };
|
|
46
46
|
}
|
|
47
|
-
async waitForSettlement(ticket) {
|
|
48
|
-
return this.intentRelayer.waitForSettlement(ticket, {
|
|
47
|
+
async waitForSettlement(ticket, ctx) {
|
|
48
|
+
return this.intentRelayer.waitForSettlement(ticket, {
|
|
49
|
+
logger: this.logger,
|
|
50
|
+
signal: ctx?.signal
|
|
51
|
+
});
|
|
49
52
|
}
|
|
50
53
|
};
|
|
51
54
|
async function mergeIntentPayloads(defaultPayload, intentPayloadFactory, salt) {
|
|
@@ -43,8 +43,11 @@ var IntentExecuter = class {
|
|
|
43
43
|
...relayParams
|
|
44
44
|
}, { logger: this.logger }) };
|
|
45
45
|
}
|
|
46
|
-
async waitForSettlement(ticket) {
|
|
47
|
-
return this.intentRelayer.waitForSettlement(ticket, {
|
|
46
|
+
async waitForSettlement(ticket, ctx) {
|
|
47
|
+
return this.intentRelayer.waitForSettlement(ticket, {
|
|
48
|
+
logger: this.logger,
|
|
49
|
+
signal: ctx?.signal
|
|
50
|
+
});
|
|
48
51
|
}
|
|
49
52
|
};
|
|
50
53
|
async function mergeIntentPayloads(defaultPayload, intentPayloadFactory, salt) {
|
|
@@ -6,7 +6,7 @@ const require_raw_ed25519 = require('./intent-hashes/raw-ed25519.cjs');
|
|
|
6
6
|
const require_webauthn = require('./intent-hashes/webauthn.cjs');
|
|
7
7
|
const require_ton_connect = require('./intent-hashes/ton-connect.cjs');
|
|
8
8
|
const require_sep53 = require('./intent-hashes/sep53.cjs');
|
|
9
|
-
let
|
|
9
|
+
let _scure_base = require("@scure/base");
|
|
10
10
|
|
|
11
11
|
//#region src/intents/intent-hash.ts
|
|
12
12
|
/**
|
|
@@ -41,7 +41,7 @@ async function computeIntentHashHashBytes(signed) {
|
|
|
41
41
|
}
|
|
42
42
|
async function computeIntentHash(multiPayload) {
|
|
43
43
|
const hashBytes = await computeIntentHashHashBytes(multiPayload);
|
|
44
|
-
return
|
|
44
|
+
return _scure_base.base58.encode(hashBytes);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _noble_hashes_sha3 = require("@noble/hashes/sha3");
|
|
3
3
|
|
|
4
4
|
//#region src/intents/intent-hashes/erc191.ts
|
|
5
5
|
/**
|
|
@@ -22,7 +22,7 @@ function computeErc191Prehash(payload) {
|
|
|
22
22
|
* @returns 32-byte hash as Uint8Array
|
|
23
23
|
*/
|
|
24
24
|
function computeErc191Hash(payload) {
|
|
25
|
-
return (0,
|
|
25
|
+
return (0, _noble_hashes_sha3.keccak_256)(computeErc191Prehash(payload));
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Compute hash from a signed ERC-191 payload
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_nep413 = require('../../lib/nep413.cjs');
|
|
3
|
-
let
|
|
3
|
+
let _scure_base = require("@scure/base");
|
|
4
4
|
|
|
5
5
|
//#region src/intents/intent-hashes/nep413.ts
|
|
6
6
|
/**
|
|
@@ -14,7 +14,7 @@ async function computeSignedNep413Hash(signed) {
|
|
|
14
14
|
return require_nep413.hashNEP413Message({
|
|
15
15
|
message: payload.message,
|
|
16
16
|
recipient: payload.recipient,
|
|
17
|
-
nonce: Array.from(
|
|
17
|
+
nonce: Array.from(_scure_base.base64.decode(payload.nonce)),
|
|
18
18
|
callback_url: payload.callbackUrl
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
3
3
|
|
|
4
4
|
//#region src/intents/intent-hashes/raw-ed25519.ts
|
|
5
5
|
/**
|
|
@@ -10,7 +10,7 @@ let __noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
|
10
10
|
* @returns 32-byte hash as Uint8Array
|
|
11
11
|
*/
|
|
12
12
|
function computeRawEd25519Hash(payload) {
|
|
13
|
-
return (0,
|
|
13
|
+
return (0, _noble_hashes_sha2.sha256)(new TextEncoder().encode(payload));
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Compute hash from a signed Raw Ed25519 payload
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
3
|
-
let
|
|
2
|
+
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
3
|
+
let _noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
4
4
|
|
|
5
5
|
//#region src/intents/intent-hashes/sep53.ts
|
|
6
6
|
/**
|
|
@@ -10,7 +10,7 @@ let __noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
|
10
10
|
function computeSep53Prehash(payload) {
|
|
11
11
|
const prefix = new TextEncoder().encode("Stellar Signed Message:\n");
|
|
12
12
|
const data = new TextEncoder().encode(payload);
|
|
13
|
-
return
|
|
13
|
+
return _defuse_protocol_internal_utils.utils.concatUint8Arrays([prefix, data]);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Compute the SHA-256 hash of a SEP-53 payload
|
|
@@ -20,7 +20,7 @@ function computeSep53Prehash(payload) {
|
|
|
20
20
|
* @returns 32-byte hash as Uint8Array
|
|
21
21
|
*/
|
|
22
22
|
function computeSep53Hash(payload) {
|
|
23
|
-
return (0,
|
|
23
|
+
return (0, _noble_hashes_sha2.sha256)(computeSep53Prehash(payload));
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Compute hash from a signed SEP-53 payload
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _noble_hashes_sha3 = require("@noble/hashes/sha3");
|
|
3
3
|
|
|
4
4
|
//#region src/intents/intent-hashes/tip191.ts
|
|
5
5
|
/**
|
|
@@ -23,7 +23,7 @@ function computeTip191Prehash(payload) {
|
|
|
23
23
|
* @returns 32-byte hash as Uint8Array
|
|
24
24
|
*/
|
|
25
25
|
function computeTip191Hash(payload) {
|
|
26
|
-
return (0,
|
|
26
|
+
return (0, _noble_hashes_sha3.keccak_256)(computeTip191Prehash(payload));
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Compute hash from a signed TIP-191 payload
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
3
3
|
|
|
4
4
|
//#region src/intents/intent-hashes/ton-connect.ts
|
|
5
5
|
/**
|
|
@@ -84,7 +84,7 @@ function computeTonConnectHash(payload) {
|
|
|
84
84
|
message.set(part, offset);
|
|
85
85
|
offset += part.length;
|
|
86
86
|
}
|
|
87
|
-
return (0,
|
|
87
|
+
return (0, _noble_hashes_sha2.sha256)(message);
|
|
88
88
|
}
|
|
89
89
|
case "binary": throw new Error("Binary payload hashing is not yet supported");
|
|
90
90
|
case "cell": throw new Error("Cell payload hashing is not yet supported.");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
3
3
|
|
|
4
4
|
//#region src/intents/intent-hashes/webauthn.ts
|
|
5
5
|
/**
|
|
@@ -10,7 +10,7 @@ let __noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
|
10
10
|
* @returns 32-byte hash as Uint8Array
|
|
11
11
|
*/
|
|
12
12
|
function computeWebAuthnHash(payload) {
|
|
13
|
-
return (0,
|
|
13
|
+
return (0, _noble_hashes_sha2.sha256)(new TextEncoder().encode(payload));
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Compute hash from a signed WebAuthn payload
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_expirable_nonce = require('./expirable-nonce.cjs');
|
|
3
3
|
const require_intent_payload_factory = require('./intent-payload-factory.cjs');
|
|
4
|
-
let
|
|
4
|
+
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
5
5
|
|
|
6
6
|
//#region src/intents/intent-payload-builder.ts
|
|
7
7
|
/**
|
|
@@ -33,7 +33,7 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
33
33
|
this.intents = [];
|
|
34
34
|
this.env = config.env;
|
|
35
35
|
this.saltManager = config.saltManager;
|
|
36
|
-
this.verifyingContract =
|
|
36
|
+
this.verifyingContract = _defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Set the signer ID (address or account that will sign the intent).
|
|
@@ -44,7 +44,7 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
44
44
|
* @throws Error if signerId is not a valid NEAR account ID
|
|
45
45
|
*/
|
|
46
46
|
setSigner(signerId) {
|
|
47
|
-
if (!
|
|
47
|
+
if (!_defuse_protocol_internal_utils.utils.validateNearAddress(signerId)) throw new Error(`Invalid signer_id: "${signerId}" is not a valid NEAR account ID`);
|
|
48
48
|
this.signerId = signerId;
|
|
49
49
|
return this;
|
|
50
50
|
}
|
|
@@ -122,7 +122,7 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
122
122
|
this.deadline = void 0;
|
|
123
123
|
this.intents = [];
|
|
124
124
|
this.customNonce = void 0;
|
|
125
|
-
this.verifyingContract =
|
|
125
|
+
this.verifyingContract = _defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID;
|
|
126
126
|
return this;
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
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/intents/intent-relayer-impl/intent-relayer-public.ts
|
|
5
5
|
var IntentRelayerPublic = class {
|
|
@@ -14,11 +14,11 @@ var IntentRelayerPublic = class {
|
|
|
14
14
|
}, ctx))[0];
|
|
15
15
|
}
|
|
16
16
|
async publishIntents({ multiPayloads, quoteHashes }, ctx = {}) {
|
|
17
|
-
const result = await
|
|
17
|
+
const result = await _defuse_protocol_internal_utils.solverRelay.publishIntents({
|
|
18
18
|
quote_hashes: quoteHashes,
|
|
19
19
|
signed_datas: multiPayloads
|
|
20
20
|
}, {
|
|
21
|
-
baseURL:
|
|
21
|
+
baseURL: _defuse_protocol_internal_utils.configsByEnvironment[this.env].solverRelayBaseURL,
|
|
22
22
|
logger: ctx.logger,
|
|
23
23
|
solverRelayApiKey: this.solverRelayApiKey
|
|
24
24
|
});
|
|
@@ -27,14 +27,14 @@ var IntentRelayerPublic = class {
|
|
|
27
27
|
}
|
|
28
28
|
async waitForSettlement(ticket, ctx = {}) {
|
|
29
29
|
return { tx: {
|
|
30
|
-
hash: (await
|
|
30
|
+
hash: (await _defuse_protocol_internal_utils.solverRelay.waitForIntentSettlement({
|
|
31
31
|
intentHash: ticket,
|
|
32
|
-
signal:
|
|
33
|
-
baseURL:
|
|
32
|
+
signal: ctx.signal,
|
|
33
|
+
baseURL: _defuse_protocol_internal_utils.configsByEnvironment[this.env].solverRelayBaseURL,
|
|
34
34
|
logger: ctx.logger,
|
|
35
35
|
solverRelayApiKey: this.solverRelayApiKey
|
|
36
36
|
})).txHash,
|
|
37
|
-
accountId:
|
|
37
|
+
accountId: _defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID
|
|
38
38
|
} };
|
|
39
39
|
}
|
|
40
40
|
};
|
|
@@ -28,7 +28,7 @@ var IntentRelayerPublic = class {
|
|
|
28
28
|
return { tx: {
|
|
29
29
|
hash: (await solverRelay.waitForIntentSettlement({
|
|
30
30
|
intentHash: ticket,
|
|
31
|
-
signal:
|
|
31
|
+
signal: ctx.signal,
|
|
32
32
|
baseURL: configsByEnvironment[this.env].solverRelayBaseURL,
|
|
33
33
|
logger: ctx.logger,
|
|
34
34
|
solverRelayApiKey: this.solverRelayApiKey
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_intent_signer_nep413 = require('./intent-signer-nep413.cjs');
|
|
3
|
-
let
|
|
3
|
+
let _scure_base = require("@scure/base");
|
|
4
4
|
|
|
5
5
|
//#region src/intents/intent-signer-impl/intent-signer-near-keypair.ts
|
|
6
6
|
var IntentSignerNearKeypair = class extends require_intent_signer_nep413.IntentSignerNEP413 {
|
|
@@ -10,7 +10,7 @@ var IntentSignerNearKeypair = class extends require_intent_signer_nep413.IntentS
|
|
|
10
10
|
const { publicKey, signature } = signer.sign(nep413Hash);
|
|
11
11
|
return {
|
|
12
12
|
publicKey: publicKey.toString(),
|
|
13
|
-
signature:
|
|
13
|
+
signature: _scure_base.base64.encode(signature)
|
|
14
14
|
};
|
|
15
15
|
},
|
|
16
16
|
accountId
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_nep413 = require('../../lib/nep413.cjs');
|
|
3
|
-
let
|
|
3
|
+
let _scure_base = require("@scure/base");
|
|
4
4
|
|
|
5
5
|
//#region src/intents/intent-signer-impl/intent-signer-nep413.ts
|
|
6
6
|
var IntentSignerNEP413 = class {
|
|
@@ -11,7 +11,7 @@ var IntentSignerNEP413 = class {
|
|
|
11
11
|
async signIntent(intent) {
|
|
12
12
|
const nep413Payload = {
|
|
13
13
|
recipient: intent.verifying_contract,
|
|
14
|
-
nonce: Array.from(
|
|
14
|
+
nonce: Array.from(_scure_base.base64.decode(intent.nonce)),
|
|
15
15
|
message: JSON.stringify({
|
|
16
16
|
deadline: intent.deadline,
|
|
17
17
|
intents: intent.intents,
|
|
@@ -20,7 +20,7 @@ var IntentSignerNEP413 = class {
|
|
|
20
20
|
};
|
|
21
21
|
const nep413Hash = await require_nep413.hashNEP413Message(nep413Payload);
|
|
22
22
|
const { publicKey, signature } = await this.signMessage(nep413Payload, nep413Hash);
|
|
23
|
-
const signatureFormatted = signature.startsWith("ed25519:") ? signature : `ed25519:${
|
|
23
|
+
const signatureFormatted = signature.startsWith("ed25519:") ? signature : `ed25519:${_scure_base.base58.encode(_scure_base.base64.decode(signature))}`;
|
|
24
24
|
return {
|
|
25
25
|
standard: "nep413",
|
|
26
26
|
payload: {
|
|
@@ -1,5 +1,5 @@
|
|
|
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/intents/intent-signer-impl/intent-signer-viem.ts
|
|
5
5
|
var IntentSignerViem = class {
|
|
@@ -8,7 +8,7 @@ var IntentSignerViem = class {
|
|
|
8
8
|
}
|
|
9
9
|
async signIntent(intent) {
|
|
10
10
|
const payload = JSON.stringify({
|
|
11
|
-
signer_id: intent.signer_id ?? this.config.accountId ??
|
|
11
|
+
signer_id: intent.signer_id ?? this.config.accountId ?? _defuse_protocol_internal_utils.utils.authHandleToIntentsUserId({
|
|
12
12
|
identifier: this.config.signer.address,
|
|
13
13
|
method: "evm"
|
|
14
14
|
}),
|
|
@@ -22,7 +22,7 @@ var IntentSignerViem = class {
|
|
|
22
22
|
return {
|
|
23
23
|
standard: "erc191",
|
|
24
24
|
payload,
|
|
25
|
-
signature:
|
|
25
|
+
signature: _defuse_protocol_internal_utils.utils.transformERC191Signature(signature)
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
};
|
|
@@ -29,11 +29,12 @@ interface IIntentRelayer<Ticket, RelayParams = RelayParamsDefault> {
|
|
|
29
29
|
/**
|
|
30
30
|
* Waits for an intent to be settled on-chain.
|
|
31
31
|
* @param ticket - The ticket returned from publishIntent
|
|
32
|
-
* @param ctx - Optional context with logger
|
|
32
|
+
* @param ctx - Optional context with logger and signal
|
|
33
33
|
* @returns Transaction information once settled
|
|
34
34
|
*/
|
|
35
35
|
waitForSettlement(ticket: Ticket, ctx?: {
|
|
36
36
|
logger?: ILogger;
|
|
37
|
+
signal?: AbortSignal;
|
|
37
38
|
}): Promise<{
|
|
38
39
|
tx: NearTxInfo;
|
|
39
40
|
}>;
|
|
@@ -29,11 +29,12 @@ interface IIntentRelayer<Ticket, RelayParams = RelayParamsDefault> {
|
|
|
29
29
|
/**
|
|
30
30
|
* Waits for an intent to be settled on-chain.
|
|
31
31
|
* @param ticket - The ticket returned from publishIntent
|
|
32
|
-
* @param ctx - Optional context with logger
|
|
32
|
+
* @param ctx - Optional context with logger and signal
|
|
33
33
|
* @returns Transaction information once settled
|
|
34
34
|
*/
|
|
35
35
|
waitForSettlement(ticket: Ticket, ctx?: {
|
|
36
36
|
logger?: ILogger;
|
|
37
|
+
signal?: AbortSignal;
|
|
37
38
|
}): Promise<{
|
|
38
39
|
tx: NearTxInfo;
|
|
39
40
|
}>;
|