Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add initial skeleton for 6900 account support #248

Merged
merged 12 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
build_and_lint_and_test:
name: Lint and Build and Test
runs-on: ubuntu-latest
env:
API_KEY: ${{ secrets.API_KEY }}
steps:
- uses: actions/checkout@v2

Expand Down
58 changes: 52 additions & 6 deletions examples/aa-simple-dapp/src/hooks/useAlchemyProvider.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { chain, gasManagerPolicyId } from "@/config/client";
import { getRpcUrl } from "@/config/rpc";
import {
LightSmartContractAccount,
getDefaultLightAccountFactoryAddress,
MSCA,
MultiOwnerPlugin,
SessionKeyPlugin,
createMultiOwnerMSCA,
encodeFunctionReference,
getDefaultMultiOwnerMSCAFactoryAddress,
installPlugin,
} from "@alchemy/aa-accounts";
import { AlchemyProvider } from "@alchemy/aa-alchemy";
import {
SmartAccountSigner,
getDefaultEntryPointAddress,
} from "@alchemy/aa-core";
import { useCallback, useState } from "react";
import { Address } from "viem";
import { Address, encodeAbiParameters, parseAbiParameters } from "viem";

export enum PluginType {
SESSION_KEY,
}

export const useAlchemyProvider = () => {
const [provider, setProvider] = useState<AlchemyProvider>(
Expand All @@ -24,12 +33,12 @@ export const useAlchemyProvider = () => {
(signer: SmartAccountSigner, account?: Address) => {
const connectedProvider = provider
.connect((provider) => {
return new LightSmartContractAccount({
return createMultiOwnerMSCA({
rpcClient: provider,
owner: signer,
chain,
entryPointAddress: getDefaultEntryPointAddress(chain),
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
factoryAddress: getDefaultMultiOwnerMSCAFactoryAddress(chain),
accountAddress: account,
});
})
Expand All @@ -50,5 +59,42 @@ export const useAlchemyProvider = () => {
return disconnectedProvider;
}, [provider]);

return { provider, connectProviderToAccount, disconnectProviderFromAccount };
const pluginInstall = useCallback(
async (type: PluginType) => {
if (!provider.isConnected<MSCA>()) {
return;
}

switch (type) {
case PluginType.SESSION_KEY:
return installPlugin(provider, {
pluginAddress: SessionKeyPlugin.meta.address[chain.id],
pluginInitData: encodeAbiParameters(
parseAbiParameters("address[]"),
[[]]
),
dependencies: [
encodeFunctionReference(
MultiOwnerPlugin.meta.address[chain.id],
"0x0"
),
encodeFunctionReference(
MultiOwnerPlugin.meta.address[chain.id],
"0x1"
),
],
});
default:
throw new Error("Unexpected plugin type", type);
}
},
[provider]
);

return {
provider,
connectProviderToAccount,
disconnectProviderFromAccount,
pluginInstall,
};
};
5 changes: 4 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
},
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
"dependsOn": ["^build", "generate"],
"outputs": ["{projectRoot}/dist"]
},
"test": {
"dependsOn": ["build"]
},
"generate": {
"outputs": ["{projectRoot}/src/plugins"]
}
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"site"
],
"scripts": {
"generate": "lerna run generate",
"postgenerate": "yarn lint:write",
"build": "lerna run build --ignore=alchemy-daapp --ignore=aa-simple-dapp",
"postbuild": "yarn lint:write",
"build:examples": "lerna run build",
"clean": "lerna run clean",
"test": "lerna run test:run",
Expand Down
5 changes: 5 additions & 0 deletions packages/accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"./package.json": "./package.json"
},
"scripts": {
"generate": "npx wagmi generate",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

learn: have you worked with the wagmi cli? if not / maybe if you remember when you first did, did you just look up a way to generate abis and some stackoverflow pointed you to it?

otherwise, curious how you arrived at this solution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used it before, but then looked at their codebase for how they define plugins so I could write my own

"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm --removeComments && echo > ./dist/esm/package.json '{\"type\":\"module\"}'",
Expand All @@ -40,6 +41,10 @@
},
"devDependencies": {
"@alchemy/aa-core": "^1.2.3",
"@wagmi/cli": "^1.5.2",
"change-case": "^5.1.2",
"dedent": "^1.5.1",
"dotenv": "^16.3.1",
"typescript": "^5.0.4",
"typescript-template": "*",
"vitest": "^0.31.0"
Expand Down
3 changes: 3 additions & 0 deletions packages/accounts/plugindefs/index.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should this folder be plugin-defs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea I think that's a fair change

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { MultiOwnerPluginGenConfig } from "./multi-owner/config.js";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can probably do better here by just reading all the config.js files found within this folder and exporting their contents. we might need to do default exports for the configs though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm but will take break the vscode module navigation ? or you mean reading all config.ts files and export their contents by writing into a new file for exports in out or something

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea the way I was thinking would break module navigation good call... we could make the plugin gen script overwrite this file though that's a good idea

export { SessionKeyPluginGenConfig } from "./session-key/config.js";
export { TokenReceiverPluginGenConfig } from "./token-receiver/config.js";
Loading
Loading