-
Notifications
You must be signed in to change notification settings - Fork 629
[SDK] Add ERC6551 Interface #1324
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
7524d7a
wip
ciaranightingale de65f04
merge main
ciaranightingale 98c7018
wip
ciaranightingale 820d4cc
Merge branch 'main' into ciara/tba
ciaranightingale 4755ac0
merge main
ciaranightingale 2580d13
wip
ciaranightingale 279b260
update with clientId & secretKey & requested changes
ciaranightingale c8445b9
Merge branch 'ciara/tba' of https://github.com/thirdweb-dev/js into c…
ciaranightingale af57f47
Merge branch 'main' into ciara/tba
ciaranightingale 2db5249
fix build
ciaranightingale 73a51fa
wip
ciaranightingale 39e22b9
wip
ciaranightingale f34654b
Merge branch 'ciara/tba' of https://github.com/thirdweb-dev/js into c…
ciaranightingale 7477b73
restructure
5ab826b
cleanup
joaquim-verges 909ca2f
Merge branch 'main' into ciara/tba
joaquim-verges 0c9ada2
Merge branch 'main' into ciara/tba
ciaranightingale cf5bb93
working code & fix factoryAddress required
ciaranightingale fdee3f5
Merge branch 'main' into ciara/tba
joaquim-verges 0bdddc0
Merge branch 'main' into ciara/tba
joaquim-verges f11c12a
Merge branch 'main' into ciara/tba
joaquim-verges e93da7f
fix types
joaquim-verges 6b4642a
linting
joaquim-verges 8a07db2
fix build
joaquim-verges a8464f6
Merge branch 'main' into ciara/tba
joaquim-verges 4c8dd1c
require account impl for now
joaquim-verges c9616ed
changeset
joaquim-verges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
working code & fix factoryAddress required
- Loading branch information
commit cf5bb9382a548c196826b23ebafba812de6bcf0e
There are no files selected for viewing
86 changes: 43 additions & 43 deletions
86
packages/wallets/src/evm/connectors/token-bound-smart-wallet/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,54 @@ | ||
| import { TokenBoundSmartWalletConfig } from "./types"; | ||
| import { TokenBoundSmartWalletConfig, TokenBoundSmartWalletConfigInput } from "./types"; | ||
| import { ethers } from "ethers"; | ||
| import { SmartWalletConnector } from "../smart-wallet"; | ||
| import { | ||
| AccountContractInfo, | ||
| FactoryContractInfo, | ||
| AccountContractInfo, | ||
| FactoryContractInfo, | ||
| } from "../smart-wallet/types"; | ||
| import { ERC6551_REGISTRY } from "../smart-wallet/lib/constants"; | ||
| import { SmartWalletConfig } from "../smart-wallet/types"; | ||
|
|
||
| export class TokenBoundSmartWalletConnector extends SmartWalletConnector { | ||
| protected config: TokenBoundSmartWalletConfig; | ||
| protected config: TokenBoundSmartWalletConfig; | ||
|
|
||
| constructor(config: TokenBoundSmartWalletConfig) { | ||
| config.factoryAddress = config.factoryAddress || ERC6551_REGISTRY; | ||
| constructor(input: TokenBoundSmartWalletConfigInput) { | ||
| input.factoryAddress = input.factoryAddress || ERC6551_REGISTRY; | ||
| super(input as TokenBoundSmartWalletConfig); | ||
| this.config = input as TokenBoundSmartWalletConfig; | ||
| } | ||
|
|
||
| super(config); | ||
| this.config = config; | ||
| } | ||
| protected defaultAccountInfo(): AccountContractInfo { | ||
| return { | ||
| execute: async (account, target, value, data) => { | ||
| return account.prepare("executeCall", [target, value, data]); | ||
| }, | ||
| getNonce: async (account) => { | ||
| return account.call("nonce", []); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| protected defaultAccountInfo(): AccountContractInfo { | ||
| return { | ||
| execute: async (account, target, value, data) => { | ||
| return account.prepare("executeCall", [target, value, data]); | ||
| }, | ||
| getNonce: async (account) => { | ||
| return account.call("nonce", []); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| protected defaultFactoryInfo(): FactoryContractInfo { | ||
| return { | ||
| createAccount: async (factory, owner) => { | ||
| return factory.prepare("createAccount", [ | ||
| this.config.accountImplementation, | ||
| this.chainId, | ||
| this.config.tokenContract, | ||
| this.config.tokenId, | ||
| this.config.salt, | ||
| ethers.utils.toUtf8Bytes(""), | ||
| ]); | ||
| }, | ||
| getAccountAddress: async (factory, owner) => { | ||
| return await factory.call("address", [ | ||
| this.config.accountImplementation, | ||
| this.chainId, | ||
| this.config.tokenContract, | ||
| this.config.tokenId, | ||
| this.config.salt, | ||
| ]); | ||
| }, | ||
| }; | ||
| } | ||
| protected defaultFactoryInfo(): FactoryContractInfo { | ||
| return { | ||
| createAccount: async (factory, owner) => { | ||
| return factory.prepare("createAccount", [ | ||
| this.config.accountImplementation, | ||
| this.chainId, | ||
| this.config.tokenContract, | ||
| this.config.tokenId, | ||
| this.config.salt, | ||
| ethers.utils.toUtf8Bytes(""), | ||
| ]); | ||
| }, | ||
| getAccountAddress: async (factory, owner) => { | ||
| return await factory.call("account", [ | ||
| this.config.accountImplementation, | ||
| this.chainId, | ||
| this.config.tokenContract, | ||
| this.config.tokenId, | ||
| this.config.salt, | ||
| ]); | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
29 changes: 25 additions & 4 deletions
29
packages/wallets/src/evm/connectors/token-bound-smart-wallet/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,30 @@ | ||
| import type { BigNumberish } from "ethers"; | ||
| import { WalletConnectReceiverConfig } from "../../../core/types/walletConnect"; | ||
| import type { ChainOrRpcUrl } from "@thirdweb-dev/sdk"; | ||
| import { ContractInfoInput } from "../smart-wallet/types"; | ||
| import { PaymasterAPI } from "@account-abstraction/sdk"; | ||
| import { SmartWalletConfig } from "../smart-wallet/types"; | ||
|
|
||
| export type TokenBoundSmartWalletConfigInput = { | ||
| chain: ChainOrRpcUrl; | ||
| factoryAddress?: string; | ||
| clientId?: string; | ||
| secretKey?: string; | ||
| gasless: boolean; | ||
| bundlerUrl?: string; | ||
| paymasterUrl?: string; | ||
| paymasterAPI?: PaymasterAPI; | ||
| entryPointAddress?: string; | ||
| tokenContract: string; | ||
| tokenId: BigNumberish; | ||
| accountImplementation: string; // TODO provide default implementation published by us | ||
| salt?: BigNumberish; | ||
| } & ContractInfoInput & | ||
| WalletConnectReceiverConfig; | ||
|
|
||
| export type TokenBoundSmartWalletConfig = { | ||
| tokenContract: string; | ||
| tokenId: BigNumberish; | ||
| accountImplementation: string; // TODO provide default implementation published by us | ||
| salt?: BigNumberish; | ||
| tokenContract: string; | ||
| tokenId: BigNumberish; | ||
| accountImplementation: string; // TODO provide default implementation published by us | ||
| salt?: BigNumberish; | ||
| } & SmartWalletConfig; |
56 changes: 28 additions & 28 deletions
56
packages/wallets/src/evm/wallets/token-bound-smart-wallet.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,44 @@ | ||
| import { SmartWallet } from "./smart-wallet"; | ||
| import type { TokenBoundSmartWalletConnector as TokenBoundSmartWalletConnectorType } from "../connectors/token-bound-smart-wallet"; | ||
| import { walletIds } from "../constants/walletIds"; | ||
| import type { TokenBoundSmartWalletConfig } from "../connectors/token-bound-smart-wallet/types"; | ||
| import type { TokenBoundSmartWalletConfigInput, TokenBoundSmartWalletConfig } from "../connectors/token-bound-smart-wallet/types"; | ||
| import { WalletOptions } from "./base"; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| export class TokenBoundSmartWallet extends SmartWallet { | ||
| connector?: TokenBoundSmartWalletConnectorType; | ||
| connector?: TokenBoundSmartWalletConnectorType; | ||
|
|
||
| static meta = { | ||
| name: "Token Bound Smart Wallet", | ||
| iconURL: | ||
| "ipfs://QmeAJVqn17aDNQhjEU3kcWVZCFBrfta8LzaDGkS8Egdiyk/token-bound-smart-wallet.svg", | ||
| }; | ||
| static meta = { | ||
| name: "Token Bound Smart Wallet", | ||
| iconURL: | ||
| "ipfs://QmeAJVqn17aDNQhjEU3kcWVZCFBrfta8LzaDGkS8Egdiyk/token-bound-smart-wallet.svg", | ||
| }; | ||
|
|
||
| static id = walletIds.tokenBoundSmartWallet; | ||
| public get walletName() { | ||
| return "Token Bound Smart Wallet"; | ||
| } | ||
| static id = walletIds.tokenBoundSmartWallet; | ||
| public get walletName() { | ||
| return "Token Bound Smart Wallet"; | ||
| } | ||
|
|
||
| constructor(options: WalletOptions<TokenBoundSmartWalletConfig>) { | ||
| super(options); | ||
| } | ||
| constructor(options: WalletOptions<TokenBoundSmartWalletConfigInput>) { | ||
| super(options as TokenBoundSmartWalletConfig); | ||
| } | ||
|
|
||
| async getConnector(): Promise<TokenBoundSmartWalletConnectorType> { | ||
| if (!this.connector) { | ||
| if (this.enableConnectApp) { | ||
| await this.wcWallet.init(); | ||
| this.setupWalletConnectEventsListeners(); | ||
| } | ||
| async getConnector(): Promise<TokenBoundSmartWalletConnectorType> { | ||
| if (!this.connector) { | ||
| if (this.enableConnectApp) { | ||
| await this.wcWallet.init(); | ||
| this.setupWalletConnectEventsListeners(); | ||
| } | ||
|
|
||
| const { TokenBoundSmartWalletConnector } = await import( | ||
| "../connectors/token-bound-smart-wallet" | ||
| ); | ||
| this.connector = new TokenBoundSmartWalletConnector( | ||
| this.options as TokenBoundSmartWalletConfig, | ||
| ); | ||
| const { TokenBoundSmartWalletConnector } = await import( | ||
| "../connectors/token-bound-smart-wallet" | ||
| ); | ||
| this.connector = new TokenBoundSmartWalletConnector( | ||
| this.options as TokenBoundSmartWalletConfig, | ||
| ); | ||
| } | ||
| return this.connector; | ||
| } | ||
| return this.connector; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dumb question but in the parent SmartWallet class, the calls here are:
executeandgetNonce, just making sure these are different on purposeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah in the official registry, the function signatures are different - they are of this format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you double check that these can be configured back if they so choose
@joaquim-verges could you check this please - my assumption was to use the erc-6551 registry function signatures by default rather than the ones we have - is this the route we are choosing to go? SHould we have a
customoption or something which uses the thirdweb defaults? I just wanted to keep things simple but I'm not sure