@locker-labs/sdk
Version:
A utility library for enhancing your ERC-4337 experience
839 lines • 32.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SplitPluginAbi = exports.SplitPluginExecutionFunctionAbi = exports.splitPluginActions = exports.SplitPlugin = void 0;
const viem_1 = require("viem");
const core_1 = require("@aa-sdk/core");
const smart_contracts_1 = require("@account-kit/smart-contracts");
const plugin_js_1 = require("../multi-owner/plugin.js");
const addresses = {
8453: "0x2a4f50188850660D2C7D411EdA120CBb5D9A3EE4",
84532: "0x400932DCddAc89bEA6F2C261dA7aC1C427BdBf5b",
11155111: "0x12438c60e855ca58C34b1b2780d208D733D370CF",
};
exports.SplitPlugin = {
meta: {
name: "Split Plugin",
version: "0.0.1",
addresses,
},
getContract: (client, address) => {
if (!client.chain)
throw new core_1.ChainNotFoundError();
return (0, viem_1.getContract)({
address: address || addresses[client.chain.id],
abi: exports.SplitPluginAbi,
client: client,
});
},
};
const splitPluginActions = (client) => ({
createSplit({ args, overrides, context, account = client.account }) {
if (!account) {
throw new core_1.AccountNotFoundError();
}
if (!(0, core_1.isSmartAccountClient)(client)) {
throw new core_1.IncompatibleClientError("SmartAccountClient", "createSplit", client);
}
const uo = (0, viem_1.encodeFunctionData)({
abi: exports.SplitPluginExecutionFunctionAbi,
functionName: "createSplit",
args,
});
return client.sendUserOperation({ uo, overrides, account, context });
},
toggleIsSplitEnabled({ args, overrides, context, account = client.account }) {
if (!account) {
throw new core_1.AccountNotFoundError();
}
if (!(0, core_1.isSmartAccountClient)(client)) {
throw new core_1.IncompatibleClientError("SmartAccountClient", "toggleIsSplitEnabled", client);
}
const uo = (0, viem_1.encodeFunctionData)({
abi: exports.SplitPluginExecutionFunctionAbi,
functionName: "toggleIsSplitEnabled",
args,
});
return client.sendUserOperation({ uo, overrides, account, context });
},
split({ args, overrides, context, account = client.account }) {
if (!account) {
throw new core_1.AccountNotFoundError();
}
if (!(0, core_1.isSmartAccountClient)(client)) {
throw new core_1.IncompatibleClientError("SmartAccountClient", "split", client);
}
const uo = (0, viem_1.encodeFunctionData)({
abi: exports.SplitPluginExecutionFunctionAbi,
functionName: "split",
args,
});
return client.sendUserOperation({ uo, overrides, account, context });
},
updateSplitConfig({ args, overrides, context, account = client.account }) {
if (!account) {
throw new core_1.AccountNotFoundError();
}
if (!(0, core_1.isSmartAccountClient)(client)) {
throw new core_1.IncompatibleClientError("SmartAccountClient", "updateSplitConfig", client);
}
const uo = (0, viem_1.encodeFunctionData)({
abi: exports.SplitPluginExecutionFunctionAbi,
functionName: "updateSplitConfig",
args,
});
return client.sendUserOperation({ uo, overrides, account, context });
},
deleteSplitConfig({ args, overrides, context, account = client.account }) {
if (!account) {
throw new core_1.AccountNotFoundError();
}
if (!(0, core_1.isSmartAccountClient)(client)) {
throw new core_1.IncompatibleClientError("SmartAccountClient", "deleteSplitConfig", client);
}
const uo = (0, viem_1.encodeFunctionData)({
abi: exports.SplitPluginExecutionFunctionAbi,
functionName: "deleteSplitConfig",
args,
});
return client.sendUserOperation({ uo, overrides, account, context });
},
installSplitPlugin({ account = client.account, overrides, context, ...params }) {
if (!account) {
throw new core_1.AccountNotFoundError();
}
if (!(0, core_1.isSmartAccountClient)(client)) {
throw new core_1.IncompatibleClientError("SmartAccountClient", "installSplitPlugin", client);
}
const chain = client.chain;
if (!chain) {
throw new core_1.ChainNotFoundError();
}
const dependencies = params.dependencyOverrides ?? [
(() => {
const pluginAddress = plugin_js_1.MultiOwnerPlugin.meta.addresses[chain.id];
if (!pluginAddress) {
throw new Error("missing MultiOwnerPlugin address for chain " + chain.name);
}
return (0, viem_1.encodePacked)(["address", "uint8"], [pluginAddress, 0x0]);
})(),
(() => {
const pluginAddress = plugin_js_1.MultiOwnerPlugin.meta.addresses[chain.id];
if (!pluginAddress) {
throw new Error("missing MultiOwnerPlugin address for chain " + chain.name);
}
return (0, viem_1.encodePacked)(["address", "uint8"], [pluginAddress, 0x1]);
})(),
];
const pluginAddress = params.pluginAddress ??
exports.SplitPlugin.meta.addresses[chain.id];
if (!pluginAddress) {
throw new Error("missing SplitPlugin address for chain " + chain.name);
}
return (0, smart_contracts_1.installPlugin)(client, {
pluginAddress,
pluginInitData: (0, viem_1.encodeAbiParameters)([
{ type: "address", name: "tokenAddess" },
{ type: "address[]", name: "splitAddresses" },
{ type: "uint256[]", name: "percentages" },
], params.args),
dependencies,
overrides,
account,
context,
});
},
encodeCreateSplit({ args }) {
return (0, viem_1.encodeFunctionData)({
abi: exports.SplitPluginExecutionFunctionAbi,
functionName: "createSplit",
args,
});
},
encodeToggleIsSplitEnabled({ args }) {
return (0, viem_1.encodeFunctionData)({
abi: exports.SplitPluginExecutionFunctionAbi,
functionName: "toggleIsSplitEnabled",
args,
});
},
encodeSplit({ args }) {
return (0, viem_1.encodeFunctionData)({
abi: exports.SplitPluginExecutionFunctionAbi,
functionName: "split",
args,
});
},
encodeUpdateSplitConfig({ args }) {
return (0, viem_1.encodeFunctionData)({
abi: exports.SplitPluginExecutionFunctionAbi,
functionName: "updateSplitConfig",
args,
});
},
encodeDeleteSplitConfig({ args }) {
return (0, viem_1.encodeFunctionData)({
abi: exports.SplitPluginExecutionFunctionAbi,
functionName: "deleteSplitConfig",
args,
});
},
});
exports.splitPluginActions = splitPluginActions;
exports.SplitPluginExecutionFunctionAbi = [
{
type: "function",
name: "createSplit",
inputs: [
{ name: "_tokenAddress", type: "address", internalType: "address" },
{ name: "_splitAddresses", type: "address[]", internalType: "address[]" },
{ name: "_percentages", type: "uint32[]", internalType: "uint32[]" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "toggleIsSplitEnabled",
inputs: [
{ name: "_configIndex", type: "uint256", internalType: "uint256" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "split",
inputs: [
{ name: "_configIndex", type: "uint256", internalType: "uint256" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "updateSplitConfig",
inputs: [
{ name: "_configIndex", type: "uint256", internalType: "uint256" },
{ name: "_splitAddresses", type: "address[]", internalType: "address[]" },
{ name: "_percentages", type: "uint32[]", internalType: "uint32[]" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "deleteSplitConfig",
inputs: [
{ name: "_configIndex", type: "uint256", internalType: "uint256" },
],
outputs: [],
stateMutability: "nonpayable",
},
];
exports.SplitPluginAbi = [
{
type: "function",
name: "AUTHOR",
inputs: [],
outputs: [{ name: "", type: "string", internalType: "string" }],
stateMutability: "view",
},
{
type: "function",
name: "NAME",
inputs: [],
outputs: [{ name: "", type: "string", internalType: "string" }],
stateMutability: "view",
},
{
type: "function",
name: "VERSION",
inputs: [],
outputs: [{ name: "", type: "string", internalType: "string" }],
stateMutability: "view",
},
{
type: "function",
name: "createSplit",
inputs: [
{ name: "_tokenAddress", type: "address", internalType: "address" },
{ name: "_splitAddresses", type: "address[]", internalType: "address[]" },
{ name: "_percentages", type: "uint32[]", internalType: "uint32[]" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "deleteSplitConfig",
inputs: [
{ name: "_configIndex", type: "uint256", internalType: "uint256" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "getSplitConfig",
inputs: [
{ name: "_configIndex", type: "uint256", internalType: "uint256" },
],
outputs: [
{ name: "tokenAddress", type: "address", internalType: "address" },
{ name: "splitAddresses", type: "address[]", internalType: "address[]" },
{ name: "percentages", type: "uint32[]", internalType: "uint32[]" },
{ name: "isSplitEnabled", type: "bool", internalType: "bool" },
],
stateMutability: "view",
},
{
type: "function",
name: "getSplitIndexes",
inputs: [{ name: "_user", type: "address", internalType: "address" }],
outputs: [{ name: "", type: "uint256[]", internalType: "uint256[]" }],
stateMutability: "view",
},
{
type: "function",
name: "isSplitCreator",
inputs: [
{ name: "_configIndex", type: "uint256", internalType: "uint256" },
{ name: "_splitCreator", type: "address", internalType: "address" },
],
outputs: [{ name: "", type: "bool", internalType: "bool" }],
stateMutability: "view",
},
{
type: "function",
name: "onInstall",
inputs: [{ name: "data", type: "bytes", internalType: "bytes" }],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "onUninstall",
inputs: [{ name: "", type: "bytes", internalType: "bytes" }],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "pluginManifest",
inputs: [],
outputs: [
{
name: "manifest",
type: "tuple",
internalType: "struct PluginManifest",
components: [
{ name: "interfaceIds", type: "bytes4[]", internalType: "bytes4[]" },
{
name: "dependencyInterfaceIds",
type: "bytes4[]",
internalType: "bytes4[]",
},
{
name: "executionFunctions",
type: "bytes4[]",
internalType: "bytes4[]",
},
{
name: "permittedExecutionSelectors",
type: "bytes4[]",
internalType: "bytes4[]",
},
{
name: "permitAnyExternalAddress",
type: "bool",
internalType: "bool",
},
{ name: "canSpendNativeToken", type: "bool", internalType: "bool" },
{
name: "permittedExternalCalls",
type: "tuple[]",
internalType: "struct ManifestExternalCallPermission[]",
components: [
{
name: "externalAddress",
type: "address",
internalType: "address",
},
{ name: "permitAnySelector", type: "bool", internalType: "bool" },
{ name: "selectors", type: "bytes4[]", internalType: "bytes4[]" },
],
},
{
name: "userOpValidationFunctions",
type: "tuple[]",
internalType: "struct ManifestAssociatedFunction[]",
components: [
{
name: "executionSelector",
type: "bytes4",
internalType: "bytes4",
},
{
name: "associatedFunction",
type: "tuple",
internalType: "struct ManifestFunction",
components: [
{
name: "functionType",
type: "uint8",
internalType: "enum ManifestAssociatedFunctionType",
},
{ name: "functionId", type: "uint8", internalType: "uint8" },
{
name: "dependencyIndex",
type: "uint256",
internalType: "uint256",
},
],
},
],
},
{
name: "runtimeValidationFunctions",
type: "tuple[]",
internalType: "struct ManifestAssociatedFunction[]",
components: [
{
name: "executionSelector",
type: "bytes4",
internalType: "bytes4",
},
{
name: "associatedFunction",
type: "tuple",
internalType: "struct ManifestFunction",
components: [
{
name: "functionType",
type: "uint8",
internalType: "enum ManifestAssociatedFunctionType",
},
{ name: "functionId", type: "uint8", internalType: "uint8" },
{
name: "dependencyIndex",
type: "uint256",
internalType: "uint256",
},
],
},
],
},
{
name: "preUserOpValidationHooks",
type: "tuple[]",
internalType: "struct ManifestAssociatedFunction[]",
components: [
{
name: "executionSelector",
type: "bytes4",
internalType: "bytes4",
},
{
name: "associatedFunction",
type: "tuple",
internalType: "struct ManifestFunction",
components: [
{
name: "functionType",
type: "uint8",
internalType: "enum ManifestAssociatedFunctionType",
},
{ name: "functionId", type: "uint8", internalType: "uint8" },
{
name: "dependencyIndex",
type: "uint256",
internalType: "uint256",
},
],
},
],
},
{
name: "preRuntimeValidationHooks",
type: "tuple[]",
internalType: "struct ManifestAssociatedFunction[]",
components: [
{
name: "executionSelector",
type: "bytes4",
internalType: "bytes4",
},
{
name: "associatedFunction",
type: "tuple",
internalType: "struct ManifestFunction",
components: [
{
name: "functionType",
type: "uint8",
internalType: "enum ManifestAssociatedFunctionType",
},
{ name: "functionId", type: "uint8", internalType: "uint8" },
{
name: "dependencyIndex",
type: "uint256",
internalType: "uint256",
},
],
},
],
},
{
name: "executionHooks",
type: "tuple[]",
internalType: "struct ManifestExecutionHook[]",
components: [
{
name: "executionSelector",
type: "bytes4",
internalType: "bytes4",
},
{
name: "preExecHook",
type: "tuple",
internalType: "struct ManifestFunction",
components: [
{
name: "functionType",
type: "uint8",
internalType: "enum ManifestAssociatedFunctionType",
},
{ name: "functionId", type: "uint8", internalType: "uint8" },
{
name: "dependencyIndex",
type: "uint256",
internalType: "uint256",
},
],
},
{
name: "postExecHook",
type: "tuple",
internalType: "struct ManifestFunction",
components: [
{
name: "functionType",
type: "uint8",
internalType: "enum ManifestAssociatedFunctionType",
},
{ name: "functionId", type: "uint8", internalType: "uint8" },
{
name: "dependencyIndex",
type: "uint256",
internalType: "uint256",
},
],
},
],
},
],
},
],
stateMutability: "pure",
},
{
type: "function",
name: "pluginMetadata",
inputs: [],
outputs: [
{
name: "",
type: "tuple",
internalType: "struct PluginMetadata",
components: [
{ name: "name", type: "string", internalType: "string" },
{ name: "version", type: "string", internalType: "string" },
{ name: "author", type: "string", internalType: "string" },
{
name: "permissionDescriptors",
type: "tuple[]",
internalType: "struct SelectorPermission[]",
components: [
{
name: "functionSelector",
type: "bytes4",
internalType: "bytes4",
},
{
name: "permissionDescription",
type: "string",
internalType: "string",
},
],
},
],
},
],
stateMutability: "pure",
},
{
type: "function",
name: "postExecutionHook",
inputs: [
{ name: "", type: "uint8", internalType: "uint8" },
{ name: "", type: "bytes", internalType: "bytes" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "preExecutionHook",
inputs: [
{ name: "functionId", type: "uint8", internalType: "uint8" },
{ name: "sender", type: "address", internalType: "address" },
{ name: "value", type: "uint256", internalType: "uint256" },
{ name: "data", type: "bytes", internalType: "bytes" },
],
outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
stateMutability: "nonpayable",
},
{
type: "function",
name: "preRuntimeValidationHook",
inputs: [
{ name: "functionId", type: "uint8", internalType: "uint8" },
{ name: "sender", type: "address", internalType: "address" },
{ name: "value", type: "uint256", internalType: "uint256" },
{ name: "data", type: "bytes", internalType: "bytes" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "preUserOpValidationHook",
inputs: [
{ name: "functionId", type: "uint8", internalType: "uint8" },
{
name: "userOp",
type: "tuple",
internalType: "struct UserOperation",
components: [
{ name: "sender", type: "address", internalType: "address" },
{ name: "nonce", type: "uint256", internalType: "uint256" },
{ name: "initCode", type: "bytes", internalType: "bytes" },
{ name: "callData", type: "bytes", internalType: "bytes" },
{ name: "callGasLimit", type: "uint256", internalType: "uint256" },
{
name: "verificationGasLimit",
type: "uint256",
internalType: "uint256",
},
{
name: "preVerificationGas",
type: "uint256",
internalType: "uint256",
},
{ name: "maxFeePerGas", type: "uint256", internalType: "uint256" },
{
name: "maxPriorityFeePerGas",
type: "uint256",
internalType: "uint256",
},
{ name: "paymasterAndData", type: "bytes", internalType: "bytes" },
{ name: "signature", type: "bytes", internalType: "bytes" },
],
},
{ name: "userOpHash", type: "bytes32", internalType: "bytes32" },
],
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
stateMutability: "nonpayable",
},
{
type: "function",
name: "runtimeValidationFunction",
inputs: [
{ name: "functionId", type: "uint8", internalType: "uint8" },
{ name: "sender", type: "address", internalType: "address" },
{ name: "value", type: "uint256", internalType: "uint256" },
{ name: "data", type: "bytes", internalType: "bytes" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "split",
inputs: [
{ name: "_configIndex", type: "uint256", internalType: "uint256" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "splitConfigCount",
inputs: [],
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
stateMutability: "view",
},
{
type: "function",
name: "splitConfigIndexes",
inputs: [
{ name: "", type: "address", internalType: "address" },
{ name: "", type: "uint256", internalType: "uint256" },
],
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
stateMutability: "view",
},
{
type: "function",
name: "splitConfigs",
inputs: [{ name: "", type: "uint256", internalType: "uint256" }],
outputs: [
{ name: "tokenAddress", type: "address", internalType: "address" },
{ name: "isSplitEnabled", type: "bool", internalType: "bool" },
],
stateMutability: "view",
},
{
type: "function",
name: "supportsInterface",
inputs: [{ name: "interfaceId", type: "bytes4", internalType: "bytes4" }],
outputs: [{ name: "", type: "bool", internalType: "bool" }],
stateMutability: "view",
},
{
type: "function",
name: "toggleIsSplitEnabled",
inputs: [
{ name: "_configIndex", type: "uint256", internalType: "uint256" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "updateSplitConfig",
inputs: [
{ name: "_configIndex", type: "uint256", internalType: "uint256" },
{ name: "_splitAddresses", type: "address[]", internalType: "address[]" },
{ name: "_percentages", type: "uint32[]", internalType: "uint32[]" },
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "userOpValidationFunction",
inputs: [
{ name: "", type: "uint8", internalType: "uint8" },
{
name: "",
type: "tuple",
internalType: "struct UserOperation",
components: [
{ name: "sender", type: "address", internalType: "address" },
{ name: "nonce", type: "uint256", internalType: "uint256" },
{ name: "initCode", type: "bytes", internalType: "bytes" },
{ name: "callData", type: "bytes", internalType: "bytes" },
{ name: "callGasLimit", type: "uint256", internalType: "uint256" },
{
name: "verificationGasLimit",
type: "uint256",
internalType: "uint256",
},
{
name: "preVerificationGas",
type: "uint256",
internalType: "uint256",
},
{ name: "maxFeePerGas", type: "uint256", internalType: "uint256" },
{
name: "maxPriorityFeePerGas",
type: "uint256",
internalType: "uint256",
},
{ name: "paymasterAndData", type: "bytes", internalType: "bytes" },
{ name: "signature", type: "bytes", internalType: "bytes" },
],
},
{ name: "", type: "bytes32", internalType: "bytes32" },
],
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
stateMutability: "pure",
},
{
type: "event",
name: "AutomationSwitched",
inputs: [
{
name: "configIndex",
type: "uint256",
indexed: true,
internalType: "uint256",
},
{
name: "currentState",
type: "bool",
indexed: false,
internalType: "bool",
},
],
anonymous: false,
},
{
type: "event",
name: "SplitConfigCreated",
inputs: [
{ name: "user", type: "address", indexed: true, internalType: "address" },
{
name: "configIndex",
type: "uint256",
indexed: true,
internalType: "uint256",
},
],
anonymous: false,
},
{
type: "event",
name: "SplitConfigDeleted",
inputs: [
{
name: "configIndex",
type: "uint256",
indexed: true,
internalType: "uint256",
},
],
anonymous: false,
},
{
type: "event",
name: "SplitExecuted",
inputs: [
{
name: "configIndex",
type: "uint256",
indexed: true,
internalType: "uint256",
},
],
anonymous: false,
},
{ type: "error", name: "AlreadyInitialized", inputs: [] },
{ type: "error", name: "InvalidAction", inputs: [] },
{
type: "error",
name: "NotContractCaller",
inputs: [{ name: "caller", type: "address", internalType: "address" }],
},
{
type: "error",
name: "NotImplemented",
inputs: [
{ name: "selector", type: "bytes4", internalType: "bytes4" },
{ name: "functionId", type: "uint8", internalType: "uint8" },
],
},
{ type: "error", name: "NotInitialized", inputs: [] },
];
//# sourceMappingURL=plugin.js.map