@gearbox-protocol/sdk 14.11.0-next.3 → 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.
- package/dist/cjs/preview/prerequisites/index.js +2 -0
- package/dist/cjs/preview/prerequisites/prepareAction.js +48 -0
- package/dist/esm/preview/prerequisites/index.js +1 -0
- package/dist/esm/preview/prerequisites/prepareAction.js +23 -0
- package/dist/types/preview/prerequisites/index.d.ts +1 -0
- package/dist/types/preview/prerequisites/prepareAction.d.ts +52 -0
- package/package.json +1 -1
|
@@ -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
|
+
});
|
|
@@ -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
|
+
};
|
|
@@ -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;
|