@gearbox-protocol/sdk 14.11.0-next.2 → 14.11.0-next.4

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.
@@ -44,6 +44,7 @@ __reExport(dev_exports, require("./replaceStorage.js"), module.exports);
44
44
  __reExport(dev_exports, require("./resilientTransport.js"), module.exports);
45
45
  __reExport(dev_exports, require("./transports.js"), module.exports);
46
46
  __reExport(dev_exports, require("./types.js"), module.exports);
47
+ __reExport(dev_exports, require("./verifyTestnet.js"), module.exports);
47
48
  // Annotate the CommonJS export names for ESM import in node:
48
49
  0 && (module.exports = {
49
50
  isRangeError,
@@ -67,5 +68,6 @@ __reExport(dev_exports, require("./types.js"), module.exports);
67
68
  ...require("./replaceStorage.js"),
68
69
  ...require("./resilientTransport.js"),
69
70
  ...require("./transports.js"),
70
- ...require("./types.js")
71
+ ...require("./types.js"),
72
+ ...require("./verifyTestnet.js")
71
73
  });
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var verifyTestnet_exports = {};
20
+ __export(verifyTestnet_exports, {
21
+ ONCHAIN_EXECUTION_ID_ADDRESS: () => ONCHAIN_EXECUTION_ID_ADDRESS,
22
+ iOnchainExecutionIdAbi: () => iOnchainExecutionIdAbi,
23
+ verifyTestnet: () => verifyTestnet
24
+ });
25
+ module.exports = __toCommonJS(verifyTestnet_exports);
26
+ const ONCHAIN_EXECUTION_ID_ADDRESS = "0x34131bc13eaa4ef5f98c2a423f93bc88d6ee01ba";
27
+ const iOnchainExecutionIdAbi = [
28
+ {
29
+ type: "function",
30
+ name: "deployer",
31
+ inputs: [],
32
+ outputs: [
33
+ {
34
+ name: "",
35
+ type: "string",
36
+ internalType: "string"
37
+ }
38
+ ],
39
+ stateMutability: "view"
40
+ },
41
+ {
42
+ type: "function",
43
+ name: "executionId",
44
+ inputs: [],
45
+ outputs: [
46
+ {
47
+ name: "",
48
+ type: "string",
49
+ internalType: "string"
50
+ }
51
+ ],
52
+ stateMutability: "view"
53
+ },
54
+ {
55
+ type: "function",
56
+ name: "forkAlias",
57
+ inputs: [],
58
+ outputs: [
59
+ {
60
+ name: "",
61
+ type: "string",
62
+ internalType: "string"
63
+ }
64
+ ],
65
+ stateMutability: "view"
66
+ },
67
+ {
68
+ type: "function",
69
+ name: "info",
70
+ inputs: [],
71
+ outputs: [
72
+ {
73
+ name: "",
74
+ type: "tuple",
75
+ internalType: "struct ExecutionId.Info",
76
+ components: [
77
+ {
78
+ name: "deployer",
79
+ type: "string",
80
+ internalType: "string"
81
+ },
82
+ {
83
+ name: "executionId",
84
+ type: "string",
85
+ internalType: "string"
86
+ },
87
+ {
88
+ name: "forkAlias",
89
+ type: "string",
90
+ internalType: "string"
91
+ }
92
+ ]
93
+ }
94
+ ],
95
+ stateMutability: "view"
96
+ }
97
+ ];
98
+ async function verifyTestnet(client, expected) {
99
+ try {
100
+ const { deployer, executionId, forkAlias } = await client.readContract({
101
+ abi: iOnchainExecutionIdAbi,
102
+ address: ONCHAIN_EXECUTION_ID_ADDRESS,
103
+ functionName: "info"
104
+ });
105
+ if (deployer !== "anvil-manager") {
106
+ return false;
107
+ }
108
+ if ("executionId" in expected && expected.executionId && expected.executionId !== executionId) {
109
+ return false;
110
+ }
111
+ if ("alias" in expected && expected.alias && expected.alias !== forkAlias) {
112
+ return false;
113
+ }
114
+ return true;
115
+ } catch {
116
+ return false;
117
+ }
118
+ }
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ ONCHAIN_EXECUTION_ID_ADDRESS,
122
+ iOnchainExecutionIdAbi,
123
+ verifyTestnet
124
+ });
@@ -19,6 +19,7 @@ __reExport(prerequisites_exports, require("./AllowancePrerequisite.js"), module.
19
19
  __reExport(prerequisites_exports, require("./BalancePrerequisite.js"), module.exports);
20
20
  __reExport(prerequisites_exports, require("./buildPrerequisites.js"), module.exports);
21
21
  __reExport(prerequisites_exports, require("./Prerequisite.js"), module.exports);
22
+ __reExport(prerequisites_exports, require("./prepareAction.js"), module.exports);
22
23
  __reExport(prerequisites_exports, require("./runPrerequisites.js"), module.exports);
23
24
  __reExport(prerequisites_exports, require("./types.js"), module.exports);
24
25
  // Annotate the CommonJS export names for ESM import in node:
@@ -27,6 +28,7 @@ __reExport(prerequisites_exports, require("./types.js"), module.exports);
27
28
  ...require("./BalancePrerequisite.js"),
28
29
  ...require("./buildPrerequisites.js"),
29
30
  ...require("./Prerequisite.js"),
31
+ ...require("./prepareAction.js"),
30
32
  ...require("./runPrerequisites.js"),
31
33
  ...require("./types.js")
32
34
  });
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var prepareAction_exports = {};
20
+ __export(prepareAction_exports, {
21
+ isActionablePrerequisite: () => isActionablePrerequisite,
22
+ preparePrerequisiteAction: () => preparePrerequisiteAction
23
+ });
24
+ module.exports = __toCommonJS(prepareAction_exports);
25
+ var import_viem = require("viem");
26
+ function preparePrerequisiteAction(result) {
27
+ if (result.kind === "allowance" && result.satisfied === false) {
28
+ const { token, spender, required } = result.detail;
29
+ return {
30
+ kind: "allowance",
31
+ to: token,
32
+ data: (0, import_viem.encodeFunctionData)({
33
+ abi: import_viem.erc20Abi,
34
+ functionName: "approve",
35
+ args: [spender, required]
36
+ })
37
+ };
38
+ }
39
+ return null;
40
+ }
41
+ function isActionablePrerequisite(result) {
42
+ return preparePrerequisiteAction(result) !== null;
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ isActionablePrerequisite,
47
+ preparePrerequisiteAction
48
+ });
@@ -22,6 +22,7 @@ export * from "./replaceStorage.js";
22
22
  export * from "./resilientTransport.js";
23
23
  export * from "./transports.js";
24
24
  export * from "./types.js";
25
+ export * from "./verifyTestnet.js";
25
26
  export {
26
27
  isRangeError,
27
28
  logSplitterTransport
@@ -0,0 +1,98 @@
1
+ const ONCHAIN_EXECUTION_ID_ADDRESS = "0x34131bc13eaa4ef5f98c2a423f93bc88d6ee01ba";
2
+ const iOnchainExecutionIdAbi = [
3
+ {
4
+ type: "function",
5
+ name: "deployer",
6
+ inputs: [],
7
+ outputs: [
8
+ {
9
+ name: "",
10
+ type: "string",
11
+ internalType: "string"
12
+ }
13
+ ],
14
+ stateMutability: "view"
15
+ },
16
+ {
17
+ type: "function",
18
+ name: "executionId",
19
+ inputs: [],
20
+ outputs: [
21
+ {
22
+ name: "",
23
+ type: "string",
24
+ internalType: "string"
25
+ }
26
+ ],
27
+ stateMutability: "view"
28
+ },
29
+ {
30
+ type: "function",
31
+ name: "forkAlias",
32
+ inputs: [],
33
+ outputs: [
34
+ {
35
+ name: "",
36
+ type: "string",
37
+ internalType: "string"
38
+ }
39
+ ],
40
+ stateMutability: "view"
41
+ },
42
+ {
43
+ type: "function",
44
+ name: "info",
45
+ inputs: [],
46
+ outputs: [
47
+ {
48
+ name: "",
49
+ type: "tuple",
50
+ internalType: "struct ExecutionId.Info",
51
+ components: [
52
+ {
53
+ name: "deployer",
54
+ type: "string",
55
+ internalType: "string"
56
+ },
57
+ {
58
+ name: "executionId",
59
+ type: "string",
60
+ internalType: "string"
61
+ },
62
+ {
63
+ name: "forkAlias",
64
+ type: "string",
65
+ internalType: "string"
66
+ }
67
+ ]
68
+ }
69
+ ],
70
+ stateMutability: "view"
71
+ }
72
+ ];
73
+ async function verifyTestnet(client, expected) {
74
+ try {
75
+ const { deployer, executionId, forkAlias } = await client.readContract({
76
+ abi: iOnchainExecutionIdAbi,
77
+ address: ONCHAIN_EXECUTION_ID_ADDRESS,
78
+ functionName: "info"
79
+ });
80
+ if (deployer !== "anvil-manager") {
81
+ return false;
82
+ }
83
+ if ("executionId" in expected && expected.executionId && expected.executionId !== executionId) {
84
+ return false;
85
+ }
86
+ if ("alias" in expected && expected.alias && expected.alias !== forkAlias) {
87
+ return false;
88
+ }
89
+ return true;
90
+ } catch {
91
+ return false;
92
+ }
93
+ }
94
+ export {
95
+ ONCHAIN_EXECUTION_ID_ADDRESS,
96
+ iOnchainExecutionIdAbi,
97
+ verifyTestnet
98
+ };
@@ -2,5 +2,6 @@ export * from "./AllowancePrerequisite.js";
2
2
  export * from "./BalancePrerequisite.js";
3
3
  export * from "./buildPrerequisites.js";
4
4
  export * from "./Prerequisite.js";
5
+ export * from "./prepareAction.js";
5
6
  export * from "./runPrerequisites.js";
6
7
  export * from "./types.js";
@@ -0,0 +1,23 @@
1
+ import { encodeFunctionData, erc20Abi } from "viem";
2
+ function preparePrerequisiteAction(result) {
3
+ if (result.kind === "allowance" && result.satisfied === false) {
4
+ const { token, spender, required } = result.detail;
5
+ return {
6
+ kind: "allowance",
7
+ to: token,
8
+ data: encodeFunctionData({
9
+ abi: erc20Abi,
10
+ functionName: "approve",
11
+ args: [spender, required]
12
+ })
13
+ };
14
+ }
15
+ return null;
16
+ }
17
+ function isActionablePrerequisite(result) {
18
+ return preparePrerequisiteAction(result) !== null;
19
+ }
20
+ export {
21
+ isActionablePrerequisite,
22
+ preparePrerequisiteAction
23
+ };
@@ -19,3 +19,4 @@ export * from "./replaceStorage.js";
19
19
  export * from "./resilientTransport.js";
20
20
  export * from "./transports.js";
21
21
  export * from "./types.js";
22
+ export * from "./verifyTestnet.js";
@@ -0,0 +1,82 @@
1
+ import type { Address, PublicClient } from "viem";
2
+ /**
3
+ * Address is stable, contract deployed via create2
4
+ */
5
+ export declare const ONCHAIN_EXECUTION_ID_ADDRESS: Address;
6
+ /**
7
+ * This contract is deployed on every Gearbox testnet and contains
8
+ * execution id and alias of the testnet
9
+ */
10
+ export declare const iOnchainExecutionIdAbi: readonly [{
11
+ readonly type: "function";
12
+ readonly name: "deployer";
13
+ readonly inputs: readonly [];
14
+ readonly outputs: readonly [{
15
+ readonly name: "";
16
+ readonly type: "string";
17
+ readonly internalType: "string";
18
+ }];
19
+ readonly stateMutability: "view";
20
+ }, {
21
+ readonly type: "function";
22
+ readonly name: "executionId";
23
+ readonly inputs: readonly [];
24
+ readonly outputs: readonly [{
25
+ readonly name: "";
26
+ readonly type: "string";
27
+ readonly internalType: "string";
28
+ }];
29
+ readonly stateMutability: "view";
30
+ }, {
31
+ readonly type: "function";
32
+ readonly name: "forkAlias";
33
+ readonly inputs: readonly [];
34
+ readonly outputs: readonly [{
35
+ readonly name: "";
36
+ readonly type: "string";
37
+ readonly internalType: "string";
38
+ }];
39
+ readonly stateMutability: "view";
40
+ }, {
41
+ readonly type: "function";
42
+ readonly name: "info";
43
+ readonly inputs: readonly [];
44
+ readonly outputs: readonly [{
45
+ readonly name: "";
46
+ readonly type: "tuple";
47
+ readonly internalType: "struct ExecutionId.Info";
48
+ readonly components: readonly [{
49
+ readonly name: "deployer";
50
+ readonly type: "string";
51
+ readonly internalType: "string";
52
+ }, {
53
+ readonly name: "executionId";
54
+ readonly type: "string";
55
+ readonly internalType: "string";
56
+ }, {
57
+ readonly name: "forkAlias";
58
+ readonly type: "string";
59
+ readonly internalType: "string";
60
+ }];
61
+ }];
62
+ readonly stateMutability: "view";
63
+ }];
64
+ export type VerifyTestnetParams = {
65
+ executionId: string;
66
+ } | {
67
+ alias: string;
68
+ } | {
69
+ executionId: string;
70
+ alias: string;
71
+ };
72
+ /**
73
+ * Tries to read the contract that is deployed on every Gearbox testnet
74
+ * and verify that we're on expected testnet.
75
+ *
76
+ * Used to check that wallet is using correct RPC for the testnet.
77
+ *
78
+ * @param client - Public client
79
+ * @param expected - Expected tesnet alias or execution id
80
+ * @returns True if we're on expected testnet
81
+ */
82
+ export declare function verifyTestnet(client: PublicClient, expected: VerifyTestnetParams): Promise<boolean>;
@@ -2,5 +2,6 @@ export * from "./AllowancePrerequisite.js";
2
2
  export * from "./BalancePrerequisite.js";
3
3
  export * from "./buildPrerequisites.js";
4
4
  export * from "./Prerequisite.js";
5
+ export * from "./prepareAction.js";
5
6
  export * from "./runPrerequisites.js";
6
7
  export * from "./types.js";
@@ -0,0 +1,52 @@
1
+ import { type Address, type Hex } from "viem";
2
+ import type { AnyPrerequisiteResult } from "./types.js";
3
+ /**
4
+ * A single transaction that satisfies a sender-actionable prerequisite.
5
+ *
6
+ * The shape is intentionally minimal (`to`/`data`/optional `value`) so it maps
7
+ * directly onto wallet send primitives (e.g. viem `sendTransaction`, wagmi
8
+ * `useSendTransaction`/`useWriteContract`). It is deliberately *not* the heavier
9
+ * {@link import("../../sdk/types/transactions.js").RawTx} used for Safe batches.
10
+ *
11
+ * The `kind` mirrors the prerequisite kind it remediates, so consumers can label
12
+ * the action (e.g. "Approve") without re-deriving it.
13
+ */
14
+ export interface PrerequisiteAction {
15
+ /** Prerequisite kind this action remediates. */
16
+ kind: "allowance";
17
+ /** Contract the transaction is sent to (the ERC-20 token for allowances). */
18
+ to: Address;
19
+ /** Encoded calldata (e.g. `approve(spender, required)`). */
20
+ data: Hex;
21
+ /** Native value to send; omitted (treated as 0) for ERC-20 approvals. */
22
+ value?: bigint;
23
+ }
24
+ /**
25
+ * Builds the transaction that resolves an unsatisfied, sender-actionable
26
+ * prerequisite, or returns `null` when the prerequisite cannot be fixed with a
27
+ * single wallet transaction.
28
+ *
29
+ * Currently only `allowance` is actionable: it returns an ERC-20
30
+ * `approve(spender, required)` for the exact required amount. `balance`
31
+ * shortfalls (the user must acquire/free up funds) and errored reads are not
32
+ * actionable and return `null`. New actionable kinds (permits, native unwrap,
33
+ * approve-reset-to-zero for non-standard tokens, ...) should be encoded here so
34
+ * consumers do not have to special-case them.
35
+ *
36
+ * Operates on the serializable {@link AnyPrerequisiteResult} produced by
37
+ * `verifyPrerequisites` (not on {@link import("./Prerequisite.js").Prerequisite}
38
+ * instances), so it works against cached/persisted results.
39
+ *
40
+ * @param result - A verified prerequisite result.
41
+ * @returns The remediation transaction, or `null` if not auto-actionable.
42
+ */
43
+ export declare function preparePrerequisiteAction(result: AnyPrerequisiteResult): PrerequisiteAction | null;
44
+ /**
45
+ * Whether a prerequisite result represents something the sender can fix with a
46
+ * single wallet transaction (i.e. {@link preparePrerequisiteAction} returns a
47
+ * transaction for it).
48
+ *
49
+ * Useful for UIs that distinguish "approve to continue" (actionable) from hard
50
+ * blocks like an insufficient balance (not actionable).
51
+ */
52
+ export declare function isActionablePrerequisite(result: AnyPrerequisiteResult): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "14.11.0-next.2",
3
+ "version": "14.11.0-next.4",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {