Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7524d7a
wip
ciaranightingale Jul 5, 2023
de65f04
merge main
ciaranightingale Jul 5, 2023
98c7018
wip
ciaranightingale Jul 12, 2023
820d4cc
Merge branch 'main' into ciara/tba
ciaranightingale Jul 12, 2023
4755ac0
merge main
ciaranightingale Jul 24, 2023
2580d13
wip
ciaranightingale Jul 24, 2023
279b260
update with clientId & secretKey & requested changes
ciaranightingale Jul 24, 2023
c8445b9
Merge branch 'ciara/tba' of https://github.com/thirdweb-dev/js into c…
ciaranightingale Jul 24, 2023
af57f47
Merge branch 'main' into ciara/tba
ciaranightingale Jul 24, 2023
2db5249
fix build
ciaranightingale Jul 24, 2023
73a51fa
wip
ciaranightingale Jul 26, 2023
39e22b9
wip
ciaranightingale Jul 26, 2023
f34654b
Merge branch 'ciara/tba' of https://github.com/thirdweb-dev/js into c…
ciaranightingale Jul 26, 2023
7477b73
restructure
Jul 26, 2023
5ab826b
cleanup
joaquim-verges Jul 27, 2023
909ca2f
Merge branch 'main' into ciara/tba
joaquim-verges Jul 27, 2023
0c9ada2
Merge branch 'main' into ciara/tba
ciaranightingale Jul 27, 2023
cf5bb93
working code & fix factoryAddress required
ciaranightingale Jul 27, 2023
fdee3f5
Merge branch 'main' into ciara/tba
joaquim-verges Aug 9, 2023
0bdddc0
Merge branch 'main' into ciara/tba
joaquim-verges Aug 9, 2023
f11c12a
Merge branch 'main' into ciara/tba
joaquim-verges Oct 13, 2023
e93da7f
fix types
joaquim-verges Oct 14, 2023
6b4642a
linting
joaquim-verges Oct 14, 2023
8a07db2
fix build
joaquim-verges Oct 14, 2023
a8464f6
Merge branch 'main' into ciara/tba
joaquim-verges Oct 24, 2023
4c8dd1c
require account impl for now
joaquim-verges Oct 24, 2023
c9616ed
changeset
joaquim-verges Oct 24, 2023
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
Prev Previous commit
Next Next commit
fix types
  • Loading branch information
joaquim-verges committed Oct 14, 2023
commit e93da7f23afb2563b59bde6fcc9492bb4240d7f9
33 changes: 4 additions & 29 deletions packages/wallets/src/evm/connectors/smart-wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { EVMWallet } from "../../interfaces";
import { ERC4337EthersSigner } from "./lib/erc4337-signer";
import { BigNumber, ethers, providers } from "ethers";
import {
ChainOrRpcUrl,
getChainProvider,
SignerPermissionsInput,
SignerWithPermissions,
Expand Down Expand Up @@ -45,11 +44,11 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
secretKey: config.secretKey,
}) as providers.BaseProvider;
this.chainId = (await originalProvider.getNetwork()).chainId;
const chainSlug = await this.getChainSlug(config.chain, originalProvider);
const bundlerUrl =
this.config.bundlerUrl || `https://${chainSlug}.bundler.thirdweb.com`;
this.config.bundlerUrl || `https://${this.chainId}.bundler.thirdweb.com`;
const paymasterUrl =
this.config.paymasterUrl || `https://${chainSlug}.bundler.thirdweb.com`;
this.config.paymasterUrl ||
`https://${this.chainId}.bundler.thirdweb.com`;
const entryPointAddress = config.entryPointAddress || ENTRYPOINT_ADDRESS;
const localSigner = await params.personalWallet.getSigner();
const providerConfig: ProviderConfig = {
Expand Down Expand Up @@ -80,6 +79,7 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
providerConfig,
accountApi,
originalProvider,
this.chainId,
);
this.accountApi = accountApi;
}
Expand Down Expand Up @@ -397,29 +397,4 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
},
};
}

private async getChainSlug(
chainOrRpc: ChainOrRpcUrl,
provider: ethers.providers.Provider,
): Promise<string> {
if (typeof chainOrRpc === "object") {
return chainOrRpc.slug;
}
if (typeof chainOrRpc === "number") {
const chain = getChainByChainId(chainOrRpc);
return chain.slug;
}
if (typeof chainOrRpc === "string") {
if (chainOrRpc.startsWith("http") || chainOrRpc.startsWith("ws")) {
// if it's a url, try to get the chain id from the provider
const chainId = (await provider.getNetwork()).chainId;
const chain = getChainByChainId(chainId);
return chain.slug;
}
// otherwise its the network name
return chainOrRpc;
} else {
throw new Error(`Invalid network: ${chainOrRpc}`);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export async function create4337Provider(
config: ProviderConfig,
accountApi: AccountAPI,
originalProvider: providers.BaseProvider,
chainId: number,
): Promise<ERC4337EthersProvider> {
const entryPoint = EntryPoint__factory.connect(
config.entryPointAddress,
originalProvider,
);

const chainId = (await originalProvider.getNetwork()).chainId;
const httpRpcClient = new HttpRpcClient(
config.bundlerUrl,
config.entryPointAddress,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,43 @@
import { TokenBoundSmartWalletConfig, TokenBoundSmartWalletConfigInput } from "./types";
import { TokenBoundSmartWalletConfig } from "./types";
import { ethers } from "ethers";
import { SmartWalletConnector } from "../smart-wallet";
import {
AccountContractInfo,
FactoryContractInfo,
} from "../smart-wallet/types";
import { 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 tbaConfig: TokenBoundSmartWalletConfig;

constructor(input: TokenBoundSmartWalletConfigInput) {
input.factoryAddress = input.factoryAddress || ERC6551_REGISTRY;
super(input as TokenBoundSmartWalletConfig);
this.config = input as TokenBoundSmartWalletConfig;
}
constructor(input: TokenBoundSmartWalletConfig) {
super({
...input,
factoryAddress: ERC6551_REGISTRY,
});
this.tbaConfig = input;
}

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("account", [
this.config.accountImplementation,
this.chainId,
this.config.tokenContract,
this.config.tokenId,
this.config.salt,
]);
},
};
}
protected defaultFactoryInfo(): FactoryContractInfo {
return {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
createAccount: async (factory, owner) => {
return factory.prepare("createAccount", [
this.tbaConfig.accountImplementation,
this.chainId,
this.tbaConfig.tokenContract,
this.tbaConfig.tokenId,
this.tbaConfig.salt,
ethers.utils.toUtf8Bytes(""),
]);
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getAccountAddress: async (factory, owner) => {
return await factory.call("account", [
this.tbaConfig.accountImplementation,
this.chainId,
this.tbaConfig.tokenContract,
this.tbaConfig.tokenId,
this.tbaConfig.salt,
]);
},
};
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
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;
} & SmartWalletConfig;
tokenContract: string;
tokenId: BigNumberish;
accountImplementation?: string;
salt?: BigNumberish;
} & Omit<SmartWalletConfig, "factoryAddress">;
63 changes: 33 additions & 30 deletions packages/wallets/src/evm/wallets/token-bound-smart-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
import { SmartWallet } from "./smart-wallet";
import type { TokenBoundSmartWalletConnector as TokenBoundSmartWalletConnectorType } from "../connectors/token-bound-smart-wallet";
import { walletIds } from "../constants/walletIds";
import type { TokenBoundSmartWalletConfigInput, TokenBoundSmartWalletConfig } from "../connectors/token-bound-smart-wallet/types";
import type { TokenBoundSmartWalletConfig } from "../connectors/token-bound-smart-wallet/types";
import { WalletOptions } from "./base";
import { ERC6551_REGISTRY } from "../connectors/smart-wallet/lib/constants";

/**
*
* A smart wallet controlled by the holder of a particular NFT.
*/
export class TokenBoundSmartWallet extends SmartWallet {
connector?: TokenBoundSmartWalletConnectorType;
tbaConnector?: TokenBoundSmartWalletConnectorType;
tbaOptions: TokenBoundSmartWalletConfig;

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/smart-wallet.svg",
};

static id = walletIds.tokenBoundSmartWallet;
public get walletName() {
return "Token Bound Smart Wallet";
}

constructor(options: WalletOptions<TokenBoundSmartWalletConfigInput>) {
super(options as TokenBoundSmartWalletConfig);
}
static id = walletIds.tokenBoundSmartWallet;
public get walletName() {
return "Token Bound Smart Wallet";
}

async getConnector(): Promise<TokenBoundSmartWalletConnectorType> {
if (!this.connector) {
if (this.enableConnectApp) {
await this.wcWallet.init();
this.setupWalletConnectEventsListeners();
}
constructor(options: WalletOptions<TokenBoundSmartWalletConfig>) {
super({
...options,
factoryAddress: ERC6551_REGISTRY,
});
this.tbaOptions = options;
}

const { TokenBoundSmartWalletConnector } = await import(
"../connectors/token-bound-smart-wallet"
);
this.connector = new TokenBoundSmartWalletConnector(
this.options as TokenBoundSmartWalletConfig,
);
}
return this.connector;
async getConnector(): Promise<TokenBoundSmartWalletConnectorType> {
if (!this.tbaConnector) {
if (this.enableConnectApp) {
await this.wcWallet.init();
this.setupWalletConnectEventsListeners();
}
const { TokenBoundSmartWalletConnector } = await import(
"../connectors/token-bound-smart-wallet"
);
this.tbaConnector = new TokenBoundSmartWalletConnector(this.tbaOptions);
}
return this.tbaConnector;
}
}