From e0178d5d7ba5c307774bd9cb7577e9d57fcb557a Mon Sep 17 00:00:00 2001 From: Dan Oved Date: Fri, 17 Nov 2023 14:38:21 -0800 Subject: [PATCH] undo changes to client, will do in future pr --- packages/protocol-sdk/src/anvil.ts | 1 - .../src/premint/premint-client.test.ts | 2 +- .../src/premint/premint-client.ts | 30 ++++---- .../src/premint/preminter.test.ts | 27 +++---- .../protocol-sdk/src/premint/preminter.ts | 70 +------------------ 5 files changed, 32 insertions(+), 98 deletions(-) diff --git a/packages/protocol-sdk/src/anvil.ts b/packages/protocol-sdk/src/anvil.ts index ad0f02f32..69531e944 100644 --- a/packages/protocol-sdk/src/anvil.ts +++ b/packages/protocol-sdk/src/anvil.ts @@ -93,7 +93,6 @@ export const makeAnvilTest = ({ export const forkUrls = { zoraMainnet: "https://rpc.zora.co/", zoraGoerli: "https://testnet.rpc.zora.co", - zoraSepoli: "https://sepolia.rpc.zora.energy", }; export const anvilTest = makeAnvilTest({ diff --git a/packages/protocol-sdk/src/premint/premint-client.test.ts b/packages/protocol-sdk/src/premint/premint-client.test.ts index 24eb4ec33..076ed7af0 100644 --- a/packages/protocol-sdk/src/premint/premint-client.test.ts +++ b/packages/protocol-sdk/src/premint/premint-client.test.ts @@ -68,7 +68,7 @@ describe("ZoraCreator1155Premint", () => { 20 * 1000, ); - anvilTest.skip( + anvilTest( "can validate premint on network", async ({ viemClients: { publicClient } }) => { const premintClient = createPremintClient({ chain: foundry }); diff --git a/packages/protocol-sdk/src/premint/premint-client.ts b/packages/protocol-sdk/src/premint/premint-client.ts index 6009a5cbb..790e58a9e 100644 --- a/packages/protocol-sdk/src/premint/premint-client.ts +++ b/packages/protocol-sdk/src/premint/premint-client.ts @@ -14,11 +14,7 @@ import { zoraCreator1155PremintExecutorImplAddress, zoraCreatorFixedPriceSaleStrategyAddress, } from "@zoralabs/protocol-deployments"; -import { - PremintConfig, - isValidSignatureV1, - preminterTypedDataDefinition, -} from "./preminter"; +import { PremintConfig, preminterTypedDataDefinition } from "./preminter"; import type { PremintSignatureGetResponse, PremintSignatureResponse, @@ -499,20 +495,24 @@ class PremintClient extends ClientBase { publicClient?: PublicClient; }): Promise<{ isValid: boolean; - recoveredSigner: Address | undefined; + contractAddress: Address; + recoveredSigner: Address; }> { publicClient = this.getPublicClient(publicClient); - const { isAuthorized, recoveredAddress } = await isValidSignatureV1({ - contractAddress: data.collection_address as Address, - chainId: this.chain.id, - originalContractAdmin: data.collection.contractAdmin as Address, - premintConfig: convertPremint(data.premint), - publicClient: this.getPublicClient(), - signature: data.signature as Hex, - }); + const [isValid, contractAddress, recoveredSigner] = + await publicClient.readContract({ + abi: zoraCreator1155PremintExecutorImplABI, + address: this.getExecutorAddress(), + functionName: "isValidSignature", + args: [ + convertCollection(data.collection), + convertPremint(data.premint), + data.signature as Hex, + ], + }); - return { isValid: isAuthorized, recoveredSigner: recoveredAddress }; + return { isValid, contractAddress, recoveredSigner }; } protected makeUrls({ diff --git a/packages/protocol-sdk/src/premint/preminter.test.ts b/packages/protocol-sdk/src/premint/preminter.test.ts index 7e395c08c..16368ee4a 100644 --- a/packages/protocol-sdk/src/premint/preminter.test.ts +++ b/packages/protocol-sdk/src/premint/preminter.test.ts @@ -22,11 +22,12 @@ import { PremintConfig, TokenCreationConfig, preminterTypedDataDefinition, - isValidSignatureV1, } from "./preminter"; import { AnvilViemClientsTest, anvilTest, + forkUrls, + makeAnvilTest, } from "src/anvil"; // create token and contract creation config: @@ -144,7 +145,10 @@ describe("ZoraCreator1155Preminter", () => { }, 20 * 1000, ); - anvilTest.skip( + makeAnvilTest({ + forkUrl: forkUrls.zoraGoerli, + forkBlockNumber: 1676105, + })( "can sign and recover a signature", async ({ viemClients }) => { const { @@ -178,18 +182,15 @@ describe("ZoraCreator1155Preminter", () => { account: creatorAccount, }); + const preminterAddress = zoraCreator1155PremintExecutorAddress[999]; // recover and verify address is correct - const { recoveredAddress, isAuthorized } = await isValidSignatureV1({ - contractAddress, - chainId: viemClients.publicClient.chain!.id, - originalContractAdmin: contractConfig.contractAdmin, - premintConfig, - publicClient: viemClients.publicClient, - signature: signedMessage, - }); - - expect(recoveredAddress).to.equal(creatorAccount); - expect(isAuthorized).toBe(true); + const [, , recoveredAddress] = + await viemClients.publicClient.readContract({ + abi: preminterAbi, + address: preminterAddress, + functionName: "isValidSignature", + args: [contractConfig, premintConfig, signedMessage], + }); expect(recoveredAddress).to.equal(creatorAccount); }, diff --git a/packages/protocol-sdk/src/premint/preminter.ts b/packages/protocol-sdk/src/premint/preminter.ts index 1f26b36dc..35e83161d 100644 --- a/packages/protocol-sdk/src/premint/preminter.ts +++ b/packages/protocol-sdk/src/premint/preminter.ts @@ -1,15 +1,7 @@ import { Address } from "abitype"; import { ExtractAbiFunction, AbiParametersToPrimitiveTypes } from "abitype"; -import { - zoraCreator1155PremintExecutorImplABI as preminterAbi, - zoraCreator1155PremintExecutorImplAddress, -} from "@zoralabs/protocol-deployments"; -import { - TypedDataDefinition, - recoverTypedDataAddress, - Hex, - PublicClient, -} from "viem"; +import { zoraCreator1155PremintExecutorImplABI as preminterAbi } from "@zoralabs/protocol-deployments"; +import { TypedDataDefinition } from "viem"; type PremintInputs = ExtractAbiFunction< typeof preminterAbi, @@ -76,63 +68,5 @@ export const preminterTypedDataDefinition = ({ primaryType: "CreatorAttribution", }; - // console.log({ result, deleted }); - return result; }; - -export async function isValidSignatureV1({ - contractAddress, - originalContractAdmin, - premintConfig, - signature, - chainId, - publicClient, -}: { - contractAddress: Address; - originalContractAdmin: Address; - premintConfig: PremintConfig; - signature: Hex; - chainId: number; - publicClient: PublicClient; -}): Promise<{ - isAuthorized: boolean; - recoveredAddress?: Address; -}> { - const typedData = preminterTypedDataDefinition({ - verifyingContract: contractAddress, - premintConfig, - chainId, - }); - - // recover the address from the signature - let recoveredAddress: Address; - - try { - recoveredAddress = await recoverTypedDataAddress({ - ...typedData, - signature, - }); - } catch (error) { - console.error(error); - - return { - isAuthorized: false, - }; - } - - // premint executor is same address on all chains - const premintExecutorAddress = zoraCreator1155PremintExecutorImplAddress[999]; - - const isAuthorized = await publicClient.readContract({ - abi: preminterAbi, - address: premintExecutorAddress, - functionName: "isAuthorizedToCreatePremint", - args: [recoveredAddress, originalContractAdmin, contractAddress], - }); - - return { - isAuthorized, - recoveredAddress, - }; -}