diff --git a/examples/alchemy-daapp/README.md b/examples/alchemy-daapp/README.md index c033ff5153..490872f42a 100644 --- a/examples/alchemy-daapp/README.md +++ b/examples/alchemy-daapp/README.md @@ -63,12 +63,12 @@ You can replace the default values with your contract addresses and policy ids a ## Contributing We welcome contributions to the examples/alchemy-daapp repo! If you would like to contribute, please follow these steps: +**This repository follows an MIT license** + 1. Clone the repository 2. Create a new branch for your changes 3. Make your changes and commit them -4. Push your changes to the repository -5. Submit a pull request to the examples/aa-SDK repo +4. Push your changes to your forked repository +5. Submit a pull request to the examples/aa-sdk repo Please ensure that your code follows our coding standards and that you have added appropriate tests for your changes. We appreciate your contributions and look forward to working with you. - -**This repository follows an MIT license** diff --git a/examples/alchemy-daapp/package.json b/examples/alchemy-daapp/package.json index 312f6906bb..28b002d34a 100644 --- a/examples/alchemy-daapp/package.json +++ b/examples/alchemy-daapp/package.json @@ -9,6 +9,7 @@ "lint": "next lint" }, "dependencies": { + "@alchemy/aa-alchemy": "^0.1.0-alpha.17", "@alchemy/aa-core": "file:../../packages/core", "@chakra-ui/react": "^2.6.1", "@emotion/react": "^11.11.0", diff --git a/examples/alchemy-daapp/src/configs/clientConfigs.ts b/examples/alchemy-daapp/src/configs/clientConfigs.ts index 5f84f4f6d1..2b3cb77a53 100644 --- a/examples/alchemy-daapp/src/configs/clientConfigs.ts +++ b/examples/alchemy-daapp/src/configs/clientConfigs.ts @@ -1,4 +1,13 @@ -import { Chain, polygon, polygonMumbai, sepolia, arbitrum } from "viem/chains"; +import { + Chain, + arbitrum, + optimism, + optimismGoerli, + polygon, + polygonMumbai, + sepolia, +} from "viem/chains"; +import { env } from "~/env.mjs"; export interface DAAppConfiguration { nftContractAddress: `0x${string}`; @@ -13,29 +22,43 @@ export const daappConfigurations: Record = { [polygon.id]: { nftContractAddress: "0xb7b9424ef3d1b9086b7e53276c4aad68a1dd971c", simpleAccountFactoryAddress: "0x15Ba39375ee2Ab563E8873C8390be6f2E2F50232", - gasManagerPolicyId: "b888d426-485d-4a0e-be81-7c94ced3d4b1", + gasManagerPolicyId: env.NEXT_PUBLIC_POLYGON_POLICY_ID, rpcUrl: `/api/rpc/proxy?chainId=${polygon.id}`, chain: polygon, }, [polygonMumbai.id]: { nftContractAddress: "0x5679b0de84bba361d31b2e7152ab20f0f8565245", simpleAccountFactoryAddress: "0x9406Cc6185a346906296840746125a0E44976454", - gasManagerPolicyId: "469689aa-4fdd-43bd-a721-697f7d5e2c5d", + gasManagerPolicyId: env.NEXT_PUBLIC_MUMBAI_POLICY_ID, rpcUrl: `/api/rpc/proxy?chainId=${polygonMumbai.id}`, chain: polygonMumbai, }, [sepolia.id]: { nftContractAddress: "0x5679b0de84bba361d31b2e7152ab20f0f8565245", simpleAccountFactoryAddress: "0xc8c5736988F4Ea76B9f620dc678c23d5cBf3C83c", - gasManagerPolicyId: "97ca8953-1692-40ff-9cb8-202accb1416c", + gasManagerPolicyId: env.NEXT_PUBLIC_SEPOLIA_POLICY_ID, rpcUrl: `/api/rpc/proxy?chainId=${sepolia.id}`, chain: sepolia, }, [arbitrum.id]: { nftContractAddress: "0xb7b9424ef3d1b9086b7e53276c4aad68a1dd971c", simpleAccountFactoryAddress: "0x15Ba39375ee2Ab563E8873C8390be6f2E2F50232", - gasManagerPolicyId: "04a10add-f2d6-4f53-93ef-50feec3d7309", + gasManagerPolicyId: env.NEXT_PUBLIC_ARB_POLICY_ID, rpcUrl: `/api/rpc/proxy?chainId=${arbitrum.id}`, chain: arbitrum, }, + [optimism.id]: { + nftContractAddress: "0x835629117Abb8cfe20a2e8717C691905A4725b7c", + simpleAccountFactoryAddress: "0x15Ba39375ee2Ab563E8873C8390be6f2E2F50232", + gasManagerPolicyId: env.NEXT_PUBLIC_OPT_POLICY_ID, + rpcUrl: `/api/rpc/proxy?chainId=${optimism.id}`, + chain: optimism, + }, + [optimismGoerli.id]: { + nftContractAddress: "0x835629117Abb8cfe20a2e8717C691905A4725b7c", + simpleAccountFactoryAddress: "0x9406cc6185a346906296840746125a0e44976454", + gasManagerPolicyId: env.NEXT_PUBLIC_OPT_GOERLI_POLICY_ID, + rpcUrl: `/api/rpc/proxy?chainId=${optimismGoerli.id}`, + chain: optimismGoerli, + }, }; diff --git a/examples/alchemy-daapp/src/configs/serverConfigs.ts b/examples/alchemy-daapp/src/configs/serverConfigs.ts index b0d8114f31..33405dda6f 100644 --- a/examples/alchemy-daapp/src/configs/serverConfigs.ts +++ b/examples/alchemy-daapp/src/configs/serverConfigs.ts @@ -1,4 +1,11 @@ -import { arbitrum, polygon, polygonMumbai, sepolia } from "viem/chains"; +import { + arbitrum, + optimism, + optimismGoerli, + polygon, + polygonMumbai, + sepolia, +} from "viem/chains"; import { env } from "~/env.mjs"; // TODO: Replace with your own api urls per chain. @@ -7,6 +14,8 @@ const API_URLs: Record = { [sepolia.id]: env.SEPOLIA_ALCHEMY_API_URL, [polygon.id]: env.POLYGON_ALCHEMY_API_URL, [arbitrum.id]: env.ARB_ALCHEMY_API_URL, + [optimism.id]: env.OPT_ALCHEMY_API_URL, + [optimismGoerli.id]: env.OPT_GOERLI_ALCHEMY_API_URL, }; export function getApiUrl(chainId: number | string) { diff --git a/examples/alchemy-daapp/src/env.mjs b/examples/alchemy-daapp/src/env.mjs index 6f866f4af3..fd23d42284 100644 --- a/examples/alchemy-daapp/src/env.mjs +++ b/examples/alchemy-daapp/src/env.mjs @@ -1,5 +1,5 @@ -import { z } from "zod"; import { createEnv } from "@t3-oss/env-nextjs"; +import { z } from "zod"; export const env = createEnv({ /** @@ -12,6 +12,8 @@ export const env = createEnv({ SEPOLIA_ALCHEMY_API_URL: z.string().url(), POLYGON_ALCHEMY_API_URL: z.string().url(), ARB_ALCHEMY_API_URL: z.string().url(), + OPT_ALCHEMY_API_URL: z.string().url(), + OPT_GOERLI_ALCHEMY_API_URL: z.string().url(), }, /** @@ -19,7 +21,14 @@ export const env = createEnv({ * isn't built with invalid env vars. To expose them to the client, prefix them with * `NEXT_PUBLIC_`. */ - client: {}, + client: { + NEXT_PUBLIC_OPT_GOERLI_POLICY_ID: z.string(), + NEXT_PUBLIC_OPT_POLICY_ID: z.string(), + NEXT_PUBLIC_ARB_POLICY_ID: z.string(), + NEXT_PUBLIC_POLYGON_POLICY_ID: z.string(), + NEXT_PUBLIC_SEPOLIA_POLICY_ID: z.string(), + NEXT_PUBLIC_MUMBAI_POLICY_ID: z.string(), + }, /** * You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g. @@ -31,5 +40,13 @@ export const env = createEnv({ ARB_ALCHEMY_API_URL: process.env.ARB_ALCHEMY_API_URL, MUMBAI_ALCHEMY_API_URL: process.env.MUMBAI_ALCHEMY_API_URL, SEPOLIA_ALCHEMY_API_URL: process.env.SEPOLIA_ALCHEMY_API_URL, + OPT_ALCHEMY_API_URL: process.env.OPT_ALCHEMY_API_URL, + OPT_GOERLI_ALCHEMY_API_URL: process.env.OPT_GOERLI_ALCHEMY_API_URL, + NEXT_PUBLIC_OPT_GOERLI_POLICY_ID: process.env.NEXT_PUBLIC_OPT_GOERLI_POLICY_ID, + NEXT_PUBLIC_OPT_POLICY_ID: process.env.NEXT_PUBLIC_OPT_POLICY_ID, + NEXT_PUBLIC_ARB_POLICY_ID: process.env.NEXT_PUBLIC_ARB_POLICY_ID, + NEXT_PUBLIC_POLYGON_POLICY_ID: process.env.NEXT_PUBLIC_POLYGON_POLICY_ID, + NEXT_PUBLIC_SEPOLIA_POLICY_ID: process.env.NEXT_PUBLIC_SEPOLIA_POLICY_ID, + NEXT_PUBLIC_MUMBAI_POLICY_ID: process.env.NEXT_PUBLIC_MUMBAI_POLICY_ID, }, }); diff --git a/examples/alchemy-daapp/src/surfaces/onboarding/OnboardingController.ts b/examples/alchemy-daapp/src/surfaces/onboarding/OnboardingController.ts index e3abdfc8a8..705531aad8 100644 --- a/examples/alchemy-daapp/src/surfaces/onboarding/OnboardingController.ts +++ b/examples/alchemy-daapp/src/surfaces/onboarding/OnboardingController.ts @@ -1,13 +1,14 @@ -import { useCallback, useEffect, useMemo, useState } from "react"; -import { encodeFunctionData } from "viem"; +import { withAlchemyGasManager } from "@alchemy/aa-alchemy"; import { - createPublicErc4337Client, SimpleSmartContractAccount, - type SimpleSmartAccountOwner, SmartAccountProvider, - alchemyPaymasterAndDataMiddleware, + createPublicErc4337Client, + type SimpleSmartAccountOwner } from "@alchemy/aa-core"; +import { useCallback, useEffect, useMemo, useState } from "react"; +import { encodeFunctionData } from "viem"; import { useAccount, useNetwork } from "wagmi"; +import { localSmartContractStore } from "~/clients/localStorage"; import { NFTContractABI } from "../../clients/nftContract"; import { DAAppConfiguration, @@ -21,7 +22,18 @@ import { initialStep, metaForStepIdentifier, } from "./OnboardingDataModels"; -import { localSmartContractStore } from "~/clients/localStorage"; + +export enum GasFeeStrategy { + DEFAULT = "DEFAULT", + FIXED = "FIXED", + BASE_FEE_PERCENTAGE = "BASE_FEE_PERCENTAGE", + PRIORITY_FEE_PERCENTAGE = "PRIORITY_FEE_PERCENTAGE", +} + +export interface GasFeeMode { + strategy: GasFeeStrategy; + value: bigint; +} async function pollForLambdaForComplete( lambda: () => Promise, @@ -97,7 +109,7 @@ const onboardingStepHandlers: Record< throw new Error("No entrypoint address was found"); } const entryPointAddress = context.entrypointAddress; - const baseSigner = new SmartAccountProvider( + let baseSigner = new SmartAccountProvider( appConfig.rpcUrl, context.entrypointAddress!, context.chain! @@ -113,15 +125,16 @@ const onboardingStepHandlers: Record< rpcClient: provider, }); }); + + const smartAccountAddress = await baseSigner.getAddress(); if (context.useGasManager) { - const smartAccountSigner = await baseSigner.withPaymasterMiddleware( - alchemyPaymasterAndDataMiddleware({ - provider: baseSigner.rpcClient, - policyId: appConfig.gasManagerPolicyId, - entryPoint: entryPointAddress, - }) - ); + const smartAccountSigner = withAlchemyGasManager(baseSigner, { + provider: baseSigner.rpcClient, + policyId: appConfig.gasManagerPolicyId, + entryPoint: entryPointAddress, + }); + return { nextStep: OnboardingStepIdentifier.MINT_NFT, addedContext: { diff --git a/examples/contracts/DAAppNFT/migrations.md b/examples/contracts/DAAppNFT/migrations.md index 8977bdbde9..1d7fc89979 100644 --- a/examples/contracts/DAAppNFT/migrations.md +++ b/examples/contracts/DAAppNFT/migrations.md @@ -25,3 +25,9 @@ Transaction hash: 0xdc73899cf183cf852605c7a7473c0b110554155d5f4cc03452c11a4ce0d4 Deployer: 0x15a411507e901f26965f0ebcd3155834b058a6b2 Deployed to: 0xb7b9424ef3d1b9086b7e53276c4aad68a1dd971c Transaction hash: 0x4ca9a016935f5634d009e4580ea0dc9c4b3edf0d8 + +# Opt Mainnet + +Deployer: 0xD8Ea779b8FFC1096CA422D40588C4c0641709890 +Deployed to: 0x835629117Abb8cfe20a2e8717C691905A4725b7c +Transaction hash: 0x9f33c06fb1016da9922927cbd9ff2eca2bf239d8779b17079c05f3f5fd3ae828 diff --git a/yarn.lock b/yarn.lock index ea96086390..e357098253 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8,7 +8,7 @@ integrity sha512-iowxq3U30sghZotgl4s/oJRci6WPBfNO5YYgk2cIOMCHr3LeGPcsZjCEr+33Q4N+oV3OABDAtA+pyvWjbvBifQ== "@alchemy/aa-core@file:packages/core": - version "0.1.0-alpha.14" + version "0.1.0-alpha.17" dependencies: abitype "^0.8.3"