Skip to content
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

refactor: update the test dApp for more .env configs #64

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions examples/alchemy-daapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
1 change: 1 addition & 0 deletions examples/alchemy-daapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 28 additions & 5 deletions examples/alchemy-daapp/src/configs/clientConfigs.ts
Original file line number Diff line number Diff line change
@@ -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}`;
Expand All @@ -13,29 +22,43 @@ export const daappConfigurations: Record<number, DAAppConfiguration> = {
[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,
},
};
11 changes: 10 additions & 1 deletion examples/alchemy-daapp/src/configs/serverConfigs.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -7,6 +14,8 @@ const API_URLs: Record<number, string> = {
[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) {
Expand Down
21 changes: 19 additions & 2 deletions examples/alchemy-daapp/src/env.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

export const env = createEnv({
/**
Expand All @@ -12,14 +12,23 @@ 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(),
},

/**
* Specify your client-side environment variables schema here. This way you can ensure the app
* 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.
Expand All @@ -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,
},
});
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<boolean>,
Expand Down Expand Up @@ -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!
Expand All @@ -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: {
Expand Down
6 changes: 6 additions & 0 deletions examples/contracts/DAAppNFT/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down