Skip to content

Commit

Permalink
undo changes to client, will do in future pr
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Nov 17, 2023
1 parent c44cc61 commit e0178d5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 98 deletions.
1 change: 0 additions & 1 deletion packages/protocol-sdk/src/anvil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-sdk/src/premint/premint-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("ZoraCreator1155Premint", () => {
20 * 1000,
);

anvilTest.skip(
anvilTest(
"can validate premint on network",
async ({ viemClients: { publicClient } }) => {
const premintClient = createPremintClient({ chain: foundry });
Expand Down
30 changes: 15 additions & 15 deletions packages/protocol-sdk/src/premint/premint-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down
27 changes: 14 additions & 13 deletions packages/protocol-sdk/src/premint/preminter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
},
Expand Down
70 changes: 2 additions & 68 deletions packages/protocol-sdk/src/premint/preminter.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
};
}

0 comments on commit e0178d5

Please sign in to comment.