-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a convenience method to make creating an alchemy provider e…
…asier (#206)
- Loading branch information
Showing
31 changed files
with
380 additions
and
159 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { SmartAccountProvider } from "@alchemy/aa-core"; | ||
import { LightSmartContractAccount } from "./account.js"; | ||
import { LightAccountProviderConfigSchema } from "./schema.js"; | ||
import type { LightAccountProviderConfig } from "./types.js"; | ||
import { getDefaultLightAccountFactoryAddress } from "./utils.js"; | ||
|
||
export const createLightAccountProvider = ( | ||
config_: LightAccountProviderConfig | ||
): SmartAccountProvider & { account: LightSmartContractAccount } => { | ||
const config = LightAccountProviderConfigSchema.parse(config_); | ||
|
||
return new SmartAccountProvider({ | ||
rpcProvider: config.rpcProvider, | ||
chain: config.chain, | ||
entryPointAddress: config.entryPointAddress, | ||
opts: config.opts, | ||
}).connect( | ||
(rpcClient) => | ||
new LightSmartContractAccount({ | ||
rpcClient, | ||
initCode: config.initCode, | ||
owner: config.owner, | ||
chain: config.chain, | ||
entryPointAddress: config.entryPointAddress, | ||
factoryAddress: | ||
config.factoryAddress ?? | ||
getDefaultLightAccountFactoryAddress(config.chain), | ||
accountAddress: config.accountAddress, | ||
}) | ||
); | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
SignerSchema, | ||
createSmartAccountProviderConfigSchema, | ||
} from "@alchemy/aa-core"; | ||
import { Address } from "abitype/zod"; | ||
import { isHex } from "viem"; | ||
import { z } from "zod"; | ||
|
||
export const LightAccountFactoryConfigSchema = z.object({ | ||
owner: SignerSchema, | ||
accountAddress: Address.optional().describe( | ||
"Optional override for the account address." | ||
), | ||
initCode: z | ||
.string() | ||
.refine(isHex, "initCode must be a valid hex.") | ||
.optional() | ||
.describe("Optional override for the account init code."), | ||
factoryAddress: Address.optional().describe( | ||
"Optional override for the factory address which deploys the smart account." | ||
), | ||
}); | ||
|
||
export const LightAccountProviderConfigSchema = | ||
createSmartAccountProviderConfigSchema().and(LightAccountFactoryConfigSchema); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { z } from "zod"; | ||
import { LightAccountProviderConfigSchema } from "./schema.js"; | ||
|
||
export type LightAccountProviderConfig = z.input< | ||
typeof LightAccountProviderConfigSchema | ||
>; |
This file contains 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,3 +1,4 @@ | ||
export const API_KEY = process.env.API_KEY!; | ||
export const OWNER_MNEMONIC = process.env.OWNER_MNEMONIC!; | ||
export const PAYMASTER_POLICY_ID = process.env.PAYMASTER_POLICY_ID!; | ||
export const LIGHT_ACCOUNT_OWNER_MNEMONIC = | ||
process.env.LIGHT_ACCOUNT_OWNER_MNEMONIC!; |
This file contains 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
This file contains 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
Oops, something went wrong.