Skip to content

Commit

Permalink
feat: add initial skeleton for 6900 account support (#248)
Browse files Browse the repository at this point in the history
* feat: add some plugin generation logic (#262)

* feat: add some plugin generation logic

* chore: add generate commands

* style: apply PR suggestion

Co-authored-by: Dennis Won <denniswon@users.noreply.github.com>

* refactor: create plugin config concept

* feat: add multi-owner-msca impl that leverages the plugin gen (#263)

* feat: add multi-owner-msca impl that leverages the plugin gen

* feat: proposal for msca builder pattern (#264)

* feat: proposal for msca builder pattern

* refactor: rework plugin gen to create read methods for the account

---------

Co-authored-by: Dennis Won <denniswon@users.noreply.github.com>

* chore: lint

* feat: add plugin manager decorator for MSCA (#274)

* feat: add initial skeleton for 6900 account support

* feat: add some plugin generation logic (#262)

* feat: add some plugin generation logic

* chore: add generate commands

* style: apply PR suggestion

Co-authored-by: Dennis Won <denniswon@users.noreply.github.com>

* refactor: create plugin config concept

* feat: add multi-owner-msca impl that leverages the plugin gen (#263)

* feat: add multi-owner-msca impl that leverages the plugin gen

* feat: proposal for msca builder pattern (#264)

* feat: proposal for msca builder pattern

* refactor: rework plugin gen to create read methods for the account

---------

Co-authored-by: Dennis Won <denniswon@users.noreply.github.com>

* chore: update plugin gen

* feat: add plugin manager decorator for MSCA

* feat: add a mechanism for adding provider decorators to accounts (#287)

* feat: add a mechanism for adding provider decorators to accounts

* chore: update lerna and package json to lint generated files

* refactor: rename MSCA to IMSCA

---------

Co-authored-by: Dennis Won <denniswon@users.noreply.github.com>
Co-authored-by: avasisht23 <ajay@alchemy.com>

* fix: missed some plugingen fixes

* refactor: change the names of the plugin decorators and add example usages (#308)

* feat: extend msca account with account loupe decorators (#309)

* refactor: move required by types to aa-core utils types folder

* feat: extend msca account with account loupe decorators

* feat: move extend method on account from msca to base account

* Update packages/core/src/account/types.ts

Co-authored-by: Michael Moldoveanu <michael.moldoveanu@alchemy.com>

* Update packages/core/src/account/types.ts

Co-authored-by: Michael Moldoveanu <michael.moldoveanu@alchemy.com>

* Update packages/core/src/account/types.ts

Co-authored-by: Michael Moldoveanu <michael.moldoveanu@alchemy.com>

* Update packages/accounts/src/msca/account-loupe/decorator.ts

Co-authored-by: Michael Moldoveanu <michael.moldoveanu@alchemy.com>

* fix: fix lint and build

---------

Co-authored-by: Michael Moldoveanu <michael.moldoveanu@alchemy.com>

* fix: update the logic for signing 1271 messages

* feat: msca plugingen to accept multichain address format (#314)

* feat: msca plugingen to accept multichain address format

* Update packages/accounts/scripts/plugingen.ts

Co-authored-by: Michael Moldoveanu <michael.moldoveanu@alchemy.com>

* Update packages/accounts/wagmi.config.ts

Co-authored-by: Michael Moldoveanu <michael.moldoveanu@alchemy.com>

* feat: changed address field in plugingenconfig to addresses

---------

Co-authored-by: Michael Moldoveanu <michael.moldoveanu@alchemy.com>

* feat: msca token receiver plugin with opt out option to exclude default token receiver plugin (#316)

* feat: msca plugingen to accept multichain address format

* feat: msca token receiver plugin with opt out option to exclude default token receiver plugin

* feat: add session key plugin abi and plugingen (#284)

* feat: msca plugingen to accept multichain address format

* feat: msca token receiver plugin with opt out option to exclude default token receiver plugin

* feat: msca token receiver plugin with opt out option to exclude default token receiver plugin

* feat: add session key plugin abi and plugingen

* feat: msca plugin provider decorator to support user op overrides (#342)

* feat: msca plugingen to generate subfolders for each plugin (#350)

---------

Co-authored-by: Dennis Won <denniswon@users.noreply.github.com>
Co-authored-by: avasisht23 <ajay@alchemy.com>
  • Loading branch information
3 people authored Jan 8, 2024
1 parent f6c4e55 commit eb842bf
Show file tree
Hide file tree
Showing 48 changed files with 7,035 additions and 57 deletions.
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",
"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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { MultiOwnerPluginGenConfig } from "./multi-owner/config.js";
export { SessionKeyPluginGenConfig } from "./session-key/config.js";
export { TokenReceiverPluginGenConfig } from "./token-receiver/config.js";
Loading

0 comments on commit eb842bf

Please sign in to comment.