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

premint v2 sdk #387

Closed
wants to merge 7 commits into from
Closed
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
19 changes: 19 additions & 0 deletions .changeset/rare-wolves-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"@zoralabs/protocol-sdk": patch
---

### Changes to `preminter`

lower level `preminter.ts` now supports premint v2 by defining v2 typed data defintions.

* `isValidSignature` now takes either v1 or v2 of a premint config, along with the premint config version. and both recovers the signer address and validates if the signer can create a premint on the given contract.
* new function `premintTypedDataDefinition` which takes a premint config version and returns the signable typed data definition for that version
* new function `recoverCreatorFromCreatorAttribution` which recovers the creator address from a `CreatorAttribution` event
* new function `supportsPremintVersion` which checks if a given token contract supports a given premint config version
* new function `tryRecoverPremintSigner` which takes a premint config version and a premint signature, and tries to recover the signer address from the signature. If the signature is invalid, it returns undefined.

### Changes to PremintClient

`PremintClient` creation, updating, and deletion now take both premint config v1 and v2, but currently rejects them until the backend api supports creating v2 premints.

* `isValidSignature` now just takes the data directly as a param, instead of `{data}`
11 changes: 7 additions & 4 deletions packages/protocol-sdk/src/anvil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ async function waitForAnvilInit(anvil: any) {
});
}

export type AnvilTestForkSettings = {
forkUrl: string;
forkBlockNumber: number;
};

export const makeAnvilTest = ({
forkUrl,
forkBlockNumber,
}: {
forkUrl: string;
forkBlockNumber: number;
}) =>
}: AnvilTestForkSettings) =>
test.extend<AnvilViemClientsTest>({
viemClients: async ({ task }, use) => {
console.log("setting up clients for ", task.name);
Expand Down Expand Up @@ -93,6 +95,7 @@ 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
17 changes: 9 additions & 8 deletions packages/protocol-sdk/src/premint/premint-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { foundry } from "viem/chains";
import { describe, expect, vi } from "vitest";
import { createPremintClient } from "./premint-client";
import { anvilTest } from "src/anvil";
import { anvilTest, forkUrls, makeAnvilTest } from "src/anvil";
import { PremintSignatureResponse } from "./premint-api-client";

describe("ZoraCreator1155Premint", () => {
anvilTest(
makeAnvilTest({
forkUrl: forkUrls.zoraGoerli,
forkBlockNumber: 1763437,
})(
"can sign on the forked premint contract",
async ({ viemClients: { walletClient, publicClient } }) => {
const [deployerAccount] = await walletClient.getAddresses();
Expand Down Expand Up @@ -76,7 +80,7 @@ describe("ZoraCreator1155Premint", () => {
publicClient,
});

const premintData = {
const premintData: PremintSignatureResponse = {
collection: {
contractAdmin: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
contractName: "Testing Contract",
Expand All @@ -101,15 +105,12 @@ describe("ZoraCreator1155Premint", () => {
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
},
},
chain_name: "ZORA-TESTNET",
chain_name: "ZORA-GOERLI",
signature:
"0x588d19641de9ba1dade4d2bb5387c8dc96f4a990fef69787534b60caead759e6334975a6be10a796da948cd7d1d4f5580b3f84d49d9fa4e0b41c97759507975a1c",
} as const;

const signatureValid = await premintClient.isValidSignature({
// @ts-ignore: Fix enum type
data: premintData,
});
const signatureValid = await premintClient.isValidSignature(premintData);
expect(signatureValid.isValid).toBe(true);
},
);
Expand Down
Loading
Loading