Skip to content

Commit

Permalink
feat: add initial skeleton for 6900 account support
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 authored and avasisht23 committed Nov 27, 2023
1 parent f541859 commit d2cbe18
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
4 changes: 4 additions & 0 deletions packages/accounts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ export type { KernelBaseValidatorParams } from "./kernel-zerodev/validator/base.
//light-account exports
export { LightSmartContractAccount } from "./light-account/account.js";
export { getDefaultLightAccountFactoryAddress } from "./light-account/utils.js";

// msca exports
export { BaseModularSmartContractAccount } from "./msca/base.js";
export type { ModularSmartContractAccountParams } from "./msca/base.js";
74 changes: 74 additions & 0 deletions packages/accounts/src/msca/abis/IStandardExecutor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
export const IStandardExecutorAbi = [
{
inputs: [
{
components: [
{
internalType: "address",
name: "target",
type: "address",
},
{
internalType: "uint256",
name: "value",
type: "uint256",
},
{
internalType: "bytes",
name: "data",
type: "bytes",
},
],
internalType: "struct Execution",
name: "execution",
type: "tuple",
},
],
name: "execute",
outputs: [
{
internalType: "bytes",
name: "",
type: "bytes",
},
],
stateMutability: "payable",
type: "function",
},
{
inputs: [
{
components: [
{
internalType: "address",
name: "target",
type: "address",
},
{
internalType: "uint256",
name: "value",
type: "uint256",
},
{
internalType: "bytes",
name: "data",
type: "bytes",
},
],
internalType: "struct Execution[]",
name: "executions",
type: "tuple[]",
},
],
name: "executeBatch",
outputs: [
{
internalType: "bytes[]",
name: "",
type: "bytes[]",
},
],
stateMutability: "payable",
type: "function",
},
] as const;
237 changes: 237 additions & 0 deletions packages/accounts/src/msca/abis/MultiOwnerMSCAFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
export const MultiOwnerMSCAFactoryAbi = [
{
inputs: [
{
internalType: "address",
name: "owner",
type: "address",
},
{
internalType: "address",
name: "multiOwnerPlugin",
type: "address",
},
{
internalType: "address",
name: "implementation",
type: "address",
},
{
internalType: "bytes32",
name: "manifestHash",
type: "bytes32",
},
{
internalType: "contract IEntryPoint",
name: "entryPoint",
type: "address",
},
],
stateMutability: "nonpayable",
type: "constructor",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "previousOwner",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "newOwner",
type: "address",
},
],
name: "OwnershipTransferred",
type: "event",
},
{
inputs: [],
name: "ENTRYPOINT",
outputs: [
{
internalType: "contract IEntryPoint",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "IMPL",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "MULTI_OWNER_PLUGIN",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "uint32",
name: "unstakeDelay",
type: "uint32",
},
{
internalType: "uint256",
name: "amount",
type: "uint256",
},
],
name: "addStake",
outputs: [],
stateMutability: "payable",
type: "function",
},
{
inputs: [
{
internalType: "uint256",
name: "salt",
type: "uint256",
},
{
internalType: "address[]",
name: "owners",
type: "address[]",
},
],
name: "createAccount",
outputs: [
{
internalType: "address",
name: "addr",
type: "address",
},
],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "uint256",
name: "salt",
type: "uint256",
},
{
internalType: "address[]",
name: "owners",
type: "address[]",
},
],
name: "getAddress",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "owner",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "renounceOwnership",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "newOwner",
type: "address",
},
],
name: "transferOwnership",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "unlockStake",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address payable",
name: "to",
type: "address",
},
{
internalType: "address",
name: "token",
type: "address",
},
{
internalType: "uint256",
name: "amount",
type: "uint256",
},
],
name: "withdraw",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address payable",
name: "to",
type: "address",
},
],
name: "withdrawStake",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
stateMutability: "payable",
type: "receive",
},
] as const;
59 changes: 59 additions & 0 deletions packages/accounts/src/msca/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {
BaseSmartContractAccount,
SignerSchema,
createBaseSmartAccountParamsSchema,
type BatchUserOperationCallData,
type SupportedTransports,
} from "@alchemy/aa-core";
import {
encodeFunctionData,
type Address,
type FallbackTransport,
type Hex,
type Transport,
} from "viem";
import { z } from "zod";
import { IStandardExecutorAbi } from "./abis/IStandardExecutor.js";

export const createModularSmartContractAccountSchema = <
TTransport extends SupportedTransports = Transport
>() =>
createBaseSmartAccountParamsSchema<TTransport>().extend({
owner: SignerSchema,
});

export type ModularSmartContractAccountParams = z.input<
ReturnType<typeof createModularSmartContractAccountSchema>
>;

export abstract class BaseModularSmartContractAccount<
TTransport extends Transport | FallbackTransport = Transport
> extends BaseSmartContractAccount<TTransport> {
async encodeExecute(target: Address, value: bigint, data: Hex): Promise<Hex> {
return encodeFunctionData({
abi: IStandardExecutorAbi,
functionName: "execute",
args: [
{
target,
data,
value,
},
],
});
}

async encodeBatchExecute(txs: BatchUserOperationCallData): Promise<Hex> {
return encodeFunctionData({
abi: IStandardExecutorAbi,
functionName: "executeBatch",
args: [
txs.map((tx) => ({
target: tx.target,
data: tx.data,
value: tx.value ?? 0n,
})),
],
});
}
}

0 comments on commit d2cbe18

Please sign in to comment.