Skip to content

Commit

Permalink
chore: cleanup contract references in auth-server and nft-quest
Browse files Browse the repository at this point in the history
  • Loading branch information
itsacoyote committed Dec 10, 2024
1 parent 94087ad commit 75145e7
Show file tree
Hide file tree
Showing 32 changed files with 526 additions and 105 deletions.
23 changes: 1 addition & 22 deletions examples/nft-quest-contracts/deploy/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { formatEther, parseEther } from "ethers";
import fs from "fs";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import path from "path";

import { deployContract, getProvider, getWallet } from "./utils";

export default async function (hre: HardhatRuntimeEnvironment) {
export default async function () {
const provider = getProvider();

const baseTokenURI = "https://nft.zksync.dev/nft/metadata.json";
Expand All @@ -16,24 +13,6 @@ export default async function (hre: HardhatRuntimeEnvironment) {
console.log("NFT CONTRACT: ", await nftContract.getAddress());
console.log("PAYMASTER CONTRACT: ", await paymasterContract.getAddress());

if (hre.network.config.ethNetwork.includes("localhost")) {
// Update the .env.local file with the contract addresses for NFT Quest app
const envFilePath = path.join(__dirname, "../../nft-quest/.env.local");

// Check if the .env.local file exists, if not, create it
if (!fs.existsSync(envFilePath)) {
fs.writeFileSync(envFilePath, "", { encoding: "utf8" });
console.log(`.env.local file has been created at ${envFilePath}`);
}
const nftContractAddress = await nftContract.getAddress();
const paymasterContractAddress = await paymasterContract.getAddress();

const envContent = `NUXT_PUBLIC_CONTRACTS_NFT=${nftContractAddress}\nNUXT_PUBLIC_CONTRACTS_PAYMASTER=${paymasterContractAddress}\n`;

fs.writeFileSync(envFilePath, envContent, { encoding: "utf8" });
console.log(`.env.local file has been updated at ${envFilePath}`);
}

// fund the paymaster contract with enough ETH to pay for transactions
const wallet = getWallet();
await (
Expand Down
10 changes: 3 additions & 7 deletions examples/nft-quest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ pnpm nx deploy contracts
pnpm nx deploy:local nft-quest-contracts
```

The contract addresses for the NFT Quest app will be set in `.env.local`. This
.env file will override the values set in the `runtimeConfig` in
`nuxt.config.ts`.

You may also need to update the contract addresses for the Auth Server in
`/packages/auth-server/stores/client.ts` under the
`contractsByChain[zksyncInMemoryNode.id]`
Contract addresses are defined in the `/packages/auth-server/abi` directory.
For local development using In Memory Node,
edit the contracts' `addressByChain` for `260`.

```sh
# Start the website and Auth Server
Expand Down
2 changes: 2 additions & 0 deletions examples/nft-quest/abi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as Nft from "./nft";
export * as Paymaster from "./paymaster";
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export const ZeekNftQuestAbi = [
export const addressByChain = {
324: "0x",
300: "0x4D533d3B20b50b57268f189F93bFaf8B39c36AB6",
260: "0x111C3E89Ce80e62EE88318C2804920D4c96f92bb",
};

export const Abi = [
{
inputs: [
{
Expand Down
5 changes: 5 additions & 0 deletions examples/nft-quest/abi/paymaster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const addressByChain = {
324: "0x",
300: "0x60eef092977DF2738480a6986e2aCD10236b1FA7",
260: "0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021",
};
7 changes: 5 additions & 2 deletions examples/nft-quest/composables/useMintNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ import { waitForTransactionReceipt, writeContract } from "@wagmi/core";
import type { Address } from "viem";
import { getGeneralPaymasterInput } from "viem/zksync";

import { Nft, Paymaster } from "~/abi";

export const useMintNft = async (_address: MaybeRef<Address>) => {
const address = toRef(_address);

return await useAsyncData("mintZeek", async () => {
const runtimeConfig = useRuntimeConfig();
const { wagmiConfig } = storeToRefs(useConnectorStore());
const chainId = runtimeConfig.public.defaultChainId;

const mintingForAddress = address.value;
const transactionHash = await writeContract(wagmiConfig.value, {
address: runtimeConfig.public.contracts.nft as Address,
address: Nft.addressByChain[chainId],
abi: nftAbi,
functionName: "mint",
args: [mintingForAddress],
paymaster: runtimeConfig.public.contracts.paymaster as Address,
paymaster: Paymaster.addressByChain[chainId],
paymasterInput: getGeneralPaymasterInput({ innerInput: "0x" }),
});

Expand Down
8 changes: 1 addition & 7 deletions examples/nft-quest/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import type { Chain } from "viem";

declare module "nuxt/schema" {
interface PublicRuntimeConfig {
chain: Chain;
contracts: {
nft: `0x${string}`;
paymaster: `0x${string}`;
};
defaultChainId: number;
baseUrl: string;
authServerUrl: string;
explorerUrl: string;
Expand Down
12 changes: 2 additions & 10 deletions examples/nft-quest/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ export default defineNuxtConfig({
$production: {
runtimeConfig: {
public: {
chain: zksyncSepoliaTestnet,
contracts: {
nft: "0x4D533d3B20b50b57268f189F93bFaf8B39c36AB6",
paymaster: "0x60eef092977DF2738480a6986e2aCD10236b1FA7",
},
defaultChainId: zksyncSepoliaTestnet.id,
baseUrl: "https://nft.zksync.dev",
authServerUrl: "https://auth-test.zksync.dev/confirm",
explorerUrl: "https://sepolia.explorer.zksync.io",
Expand Down Expand Up @@ -57,11 +53,7 @@ export default defineNuxtConfig({
},
runtimeConfig: {
public: {
chain: zksyncInMemoryNode,
contracts: {
nft: "0x111C3E89Ce80e62EE88318C2804920D4c96f92bb",
paymaster: "0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021",
},
defaultChainId: zksyncInMemoryNode.id,
baseUrl: "http://localhost:3006",
authServerUrl: "http://localhost:3002/confirm",
explorerUrl: "http://localhost:3010",
Expand Down
13 changes: 7 additions & 6 deletions examples/nft-quest/stores/connector.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { connect, createConfig, type CreateConnectorFn, disconnect, getAccount, http, reconnect, watchAccount } from "@wagmi/core";
import { zksyncInMemoryNode, zksyncLocalNode, zksyncSepoliaTestnet } from "@wagmi/core/chains";
import { type Address, type Hash, parseEther } from "viem";
import { type Address, parseEther } from "viem";
import { callPolicy, zksyncSsoConnector } from "zksync-sso/connector";

import { ZeekNftQuestAbi } from "@/abi/ZeekNFTQuest";
import { Nft } from "~/abi";

export const useConnectorStore = defineStore("connector", () => {
const runtimeConfig = useRuntimeConfig();
Expand All @@ -12,9 +12,10 @@ export const useConnectorStore = defineStore("connector", () => {
zksyncInMemoryNode,
zksyncLocalNode,
] as const;
const chain = supportedChains.filter((x) => x.id == runtimeConfig.public.chain.id)[0];
const chainId = runtimeConfig.public.defaultChainId;
const chain = supportedChains.filter((x) => x.id == chainId)[0];
type SupportedChainId = (typeof supportedChains)[number]["id"];
if (!chain) throw new Error(`Chain with id ${runtimeConfig.public.chain.id} was not found in supported chains list`);
if (!chain) throw new Error(`Chain with id ${chainId} was not found in supported chains list`);

const connector = zksyncSsoConnector({
metadata: {
Expand All @@ -25,8 +26,8 @@ export const useConnectorStore = defineStore("connector", () => {
feeLimit: parseEther("0.001"),
contractCalls: [
callPolicy({
address: runtimeConfig.public.contracts.nft as Hash,
abi: ZeekNftQuestAbi,
address: Nft.addressByChain[chainId],
abi: Nft.Abi,
functionName: "mint",
}),
],
Expand Down
2 changes: 2 additions & 0 deletions packages/auth-server/abi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as NFTQuest from "./nft-quest";
export * as SSO from "./sso";
2 changes: 2 additions & 0 deletions packages/auth-server/abi/nft-quest/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as Nft from "./nft";
export * as Paymaster from "./paymaster";
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export const ZeekNftQuestAbi = [
import type { AddressByChain } from "../types";

export const addressByChain: AddressByChain = {
324: "0x",
300: "0x4D533d3B20b50b57268f189F93bFaf8B39c36AB6",
260: "0x111C3E89Ce80e62EE88318C2804920D4c96f92bb",
};

export const Abi = [
{
inputs: [
{
Expand Down
Loading

0 comments on commit 75145e7

Please sign in to comment.