@zoralabs/protocol-sdk 0.12.2 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,11 +24,7 @@ import {
24
24
  encodePremintConfig,
25
25
  } from "@zoralabs/protocol-deployments";
26
26
 
27
- import {
28
- isValidSignature,
29
- getPremintExecutorAddress,
30
- getPremintMintCosts,
31
- } from "./preminter";
27
+ import { getPremintExecutorAddress, getPremintMintCosts } from "./preminter";
32
28
  import { AnvilViemClientsTest, forkUrls, makeAnvilTest } from "src/anvil";
33
29
  import { privateKeyToAccount } from "viem/accounts";
34
30
 
@@ -177,159 +173,6 @@ const zoraSepoliaAnvilTest = makeAnvilTest({
177
173
  });
178
174
 
179
175
  describe("ZoraCreator1155Preminter", () => {
180
- zoraSepoliaAnvilTest(
181
- "can sign on the forked premint contract",
182
- async ({ viemClients }) => {
183
- const {
184
- fixedPriceMinterAddress,
185
- accounts: { creatorAccount },
186
- } = await setupContracts({ viemClients });
187
- const premintConfig = defaultPremintConfigV1({
188
- fixedPriceMinter: fixedPriceMinterAddress,
189
- creatorAccount,
190
- });
191
- const contractConfig = defaultContractConfig({
192
- contractAdmin: creatorAccount,
193
- });
194
-
195
- const preminterAddress = getPremintExecutorAddress();
196
-
197
- const contractAddress = await viemClients.publicClient.readContract({
198
- abi: preminterAbi,
199
- address: preminterAddress,
200
- functionName: "getContractWithAdditionalAdminsAddress",
201
- args: [contractConfig],
202
- });
203
-
204
- const signedMessage = await viemClients.walletClient.signTypedData({
205
- ...premintTypedDataDefinition({
206
- verifyingContract: contractAddress,
207
- chainId: viemClients.chain.id,
208
- premintConfig,
209
- premintConfigVersion: PremintConfigVersion.V1,
210
- }),
211
- account: creatorAccount,
212
- });
213
-
214
- console.log({
215
- creatorAccount,
216
- signedMessage,
217
- contractConfig,
218
- premintConfig,
219
- contractAddress,
220
- });
221
- },
222
- 20 * 1000,
223
- );
224
- zoraSepoliaAnvilTest(
225
- "can sign and recover a v1 premint config signature",
226
- async ({ viemClients }) => {
227
- const {
228
- fixedPriceMinterAddress,
229
- accounts: { creatorAccount },
230
- } = await setupContracts({ viemClients });
231
-
232
- const premintConfig = defaultPremintConfigV1({
233
- fixedPriceMinter: fixedPriceMinterAddress,
234
- creatorAccount,
235
- });
236
- const contractConfig = defaultContractConfig({
237
- contractAdmin: creatorAccount,
238
- });
239
-
240
- const tokenContract = await viemClients.publicClient.readContract({
241
- abi: preminterAbi,
242
- address: PREMINTER_ADDRESS,
243
- functionName: "getContractWithAdditionalAdminsAddress",
244
- args: [contractConfig],
245
- });
246
-
247
- // sign message containing contract and token creation config and uid
248
- const signedMessage = await viemClients.walletClient.signTypedData({
249
- ...premintTypedDataDefinition({
250
- verifyingContract: tokenContract,
251
- // we need to sign here for the anvil chain, cause thats where it is run on
252
- chainId: viemClients.chain.id,
253
- premintConfig,
254
- premintConfigVersion: PremintConfigVersion.V1,
255
- }),
256
- account: creatorAccount,
257
- });
258
-
259
- // recover and verify address is correct
260
- const { recoveredAddress, isAuthorized } = await isValidSignature({
261
- collection: contractConfig,
262
- collectionAddress: tokenContract,
263
- chainId: viemClients.publicClient.chain!.id,
264
- premintConfig,
265
- premintConfigVersion: PremintConfigVersion.V1,
266
- publicClient: viemClients.publicClient,
267
- signature: signedMessage,
268
- });
269
-
270
- expect(recoveredAddress).to.equal(creatorAccount);
271
- expect(isAuthorized).toBe(true);
272
-
273
- expect(recoveredAddress).to.equal(creatorAccount);
274
- },
275
-
276
- 20 * 1000,
277
- );
278
- zoraSepoliaAnvilTest(
279
- "can sign and recover a v2 premint config signature",
280
- async ({ viemClients }) => {
281
- const {
282
- fixedPriceMinterAddress,
283
- accounts: { creatorAccount },
284
- } = await setupContracts({ viemClients });
285
-
286
- const premintConfig = defaultPremintConfigV2({
287
- creatorAccount,
288
- fixedPriceMinter: fixedPriceMinterAddress,
289
- createReferral: creatorAccount,
290
- });
291
- const contractConfig = defaultContractConfig({
292
- contractAdmin: creatorAccount,
293
- });
294
-
295
- const tokenContract = await viemClients.publicClient.readContract({
296
- abi: preminterAbi,
297
- address: PREMINTER_ADDRESS,
298
- functionName: "getContractWithAdditionalAdminsAddress",
299
- args: [contractConfig],
300
- });
301
-
302
- // sign message containing contract and token creation config and uid
303
- const signedMessage = await viemClients.walletClient.signTypedData({
304
- ...premintTypedDataDefinition({
305
- verifyingContract: tokenContract,
306
- // we need to sign here for the anvil chain, cause thats where it is run on
307
- chainId: viemClients.chain.id,
308
- premintConfig,
309
- premintConfigVersion: PremintConfigVersion.V2,
310
- }),
311
- account: creatorAccount,
312
- });
313
-
314
- // recover and verify address is correct
315
- const { recoveredAddress, isAuthorized } = await isValidSignature({
316
- collection: contractConfig,
317
- collectionAddress: tokenContract,
318
- chainId: viemClients.publicClient.chain!.id,
319
- premintConfig,
320
- premintConfigVersion: PremintConfigVersion.V2,
321
- publicClient: viemClients.publicClient,
322
- signature: signedMessage,
323
- });
324
-
325
- expect(recoveredAddress).to.equal(creatorAccount);
326
- expect(isAuthorized).toBe(true);
327
-
328
- expect(recoveredAddress).to.equal(creatorAccount);
329
- },
330
-
331
- 20 * 1000,
332
- );
333
176
  zoraSepoliaAnvilTest(
334
177
  "can sign and mint multiple tokens",
335
178
  async ({ viemClients }) => {
@@ -1,37 +1,13 @@
1
1
  import { Address } from "abitype";
2
2
  import {
3
3
  zoraCreator1155PremintExecutorImplABI as preminterAbi,
4
- zoraCreator1155ImplABI,
5
4
  zoraCreator1155PremintExecutorImplABI,
6
5
  zoraCreator1155PremintExecutorImplAddress,
7
- zoraCreatorFixedPriceSaleStrategyAddress,
8
- premintTypedDataDefinition,
9
6
  ContractCreationConfig,
10
- PremintConfigForVersion,
11
- } from "@zoralabs/protocol-deployments";
12
- import {
13
- recoverTypedDataAddress,
14
- Hex,
15
- zeroAddress,
16
- hashDomain,
17
- keccak256,
18
- concat,
19
- recoverAddress,
20
- GetEventArgs,
21
- parseEther,
22
- Account,
23
- } from "viem";
24
- import {
25
- PremintConfig,
26
- PremintConfigV1,
27
- PremintConfigV2,
28
- PremintConfigVersion,
29
- PremintConfigWithVersion,
30
- TokenCreationConfig,
31
7
  } from "@zoralabs/protocol-deployments";
8
+ import { zeroAddress, parseEther, Account } from "viem";
32
9
  import { PublicClient } from "src/utils";
33
10
  import {
34
- ContractCreationConfigAndAddress,
35
11
  ContractCreationConfigOrAddress,
36
12
  ContractCreationConfigWithOptionalAdditionalAdmins,
37
13
  } from "./contract-types";
@@ -42,11 +18,6 @@ import { MintCosts } from "src/mint/types";
42
18
  export const getPremintExecutorAddress = () =>
43
19
  zoraCreator1155PremintExecutorImplAddress[999] as Address;
44
20
 
45
- export type IsValidSignatureReturn = {
46
- isAuthorized: boolean;
47
- recoveredAddress?: Address;
48
- };
49
-
50
21
  export async function isAuthorizedToCreatePremint({
51
22
  contractAdmin = zeroAddress,
52
23
  additionalAdmins = [],
@@ -74,203 +45,6 @@ export async function isAuthorizedToCreatePremint({
74
45
  });
75
46
  }
76
47
 
77
- export async function recoverPremintSigner<T extends PremintConfigVersion>({
78
- signature,
79
- ...rest
80
- }: {
81
- signature: Hex;
82
- chainId: number;
83
- verifyingContract: Address;
84
- } & PremintConfigWithVersion<T>): Promise<Address> {
85
- return await recoverTypedDataAddress({
86
- ...premintTypedDataDefinition(rest),
87
- signature,
88
- });
89
- }
90
-
91
- export async function tryRecoverPremintSigner(
92
- params: Parameters<typeof recoverPremintSigner>[0],
93
- ) {
94
- try {
95
- return await recoverPremintSigner(params);
96
- } catch (error) {
97
- console.error(error);
98
- return undefined;
99
- }
100
- }
101
-
102
- /**
103
- * Recovers the address from a typed data signature and then checks if the recovered address is authorized to create a premint
104
- *
105
- * @param params validationProperties
106
- * @param params.typedData typed data definition for premint config
107
- * @param params.signature signature to validate
108
- * @param params.publicClient public rpc read-only client
109
- * @param params.premintConfigContractAdmin the original contractAdmin on the ContractCreationConfig for the premint; this is usually the original creator of the premint
110
- * @param params.tokenContract the address of the 1155 contract
111
- * @returns
112
- */
113
- export async function isValidSignature<T extends PremintConfigVersion>({
114
- signature,
115
- publicClient,
116
- collection,
117
- collectionAddress,
118
- chainId,
119
- ...premintConfigAndVersion
120
- }: {
121
- signature: Hex;
122
- chainId: number;
123
- publicClient: PublicClient;
124
- } & PremintConfigWithVersion<T> &
125
- ContractCreationConfigAndAddress): Promise<IsValidSignatureReturn> {
126
- const recoveredAddress = await tryRecoverPremintSigner({
127
- ...premintConfigAndVersion,
128
- signature,
129
- verifyingContract: collectionAddress,
130
- chainId,
131
- });
132
-
133
- if (!recoverAddress) {
134
- return {
135
- isAuthorized: false,
136
- };
137
- }
138
-
139
- const isAuthorized = await isAuthorizedToCreatePremint({
140
- signer: recoveredAddress!,
141
- additionalAdmins: collection?.additionalAdmins,
142
- contractAdmin: collection?.contractAdmin,
143
- collectionAddress: collectionAddress,
144
- publicClient,
145
- });
146
-
147
- return {
148
- isAuthorized,
149
- recoveredAddress,
150
- };
151
- }
152
-
153
- /**
154
- * Converts a premint config from v1 to v2
155
- *
156
- * @param premintConfig premint config to convert
157
- * @param createReferral address that referred the creator, that will receive create referral rewards for the created token
158
- */
159
- export function migratePremintConfigToV2({
160
- premintConfig,
161
- createReferral = zeroAddress,
162
- }: {
163
- premintConfig: PremintConfigV1;
164
- createReferral: Address;
165
- }): PremintConfigV2 {
166
- return {
167
- ...premintConfig,
168
- tokenConfig: {
169
- tokenURI: premintConfig.tokenConfig.tokenURI,
170
- maxSupply: premintConfig.tokenConfig.maxSupply,
171
- maxTokensPerAddress: premintConfig.tokenConfig.maxTokensPerAddress,
172
- pricePerToken: premintConfig.tokenConfig.pricePerToken,
173
- mintStart: premintConfig.tokenConfig.mintStart,
174
- mintDuration: premintConfig.tokenConfig.mintDuration,
175
- payoutRecipient: premintConfig.tokenConfig.royaltyRecipient,
176
- royaltyBPS: premintConfig.tokenConfig.royaltyBPS,
177
- fixedPriceMinter: premintConfig.tokenConfig.fixedPriceMinter,
178
- createReferral,
179
- },
180
- };
181
- }
182
-
183
- export type CreatorAttributionEventParams = GetEventArgs<
184
- typeof zoraCreator1155ImplABI,
185
- "CreatorAttribution",
186
- { EnableUnion: false }
187
- >;
188
-
189
- /**
190
- * Recovers the address from a CreatorAttribution event emitted from a ZoraCreator1155 contract
191
- * Useful for verifying that the creator of a token is the one who signed a premint for its creation.
192
- *
193
-
194
- * @param creatorAttribution parameters from the CreatorAttribution event
195
- * @param chainId the chain id of the current chain
196
- * @param tokenContract the address of the 1155 contract
197
- * @returns the address of the signer
198
- */
199
- export const recoverCreatorFromCreatorAttribution = async ({
200
- creatorAttribution: { version, domainName, structHash, signature },
201
- chainId,
202
- tokenContract,
203
- }: {
204
- creatorAttribution: CreatorAttributionEventParams;
205
- tokenContract: Address;
206
- chainId: number;
207
- }) => {
208
- // hash the eip712 domain based on the parameters emitted from the event:
209
- const hashedDomain = hashDomain({
210
- domain: {
211
- chainId,
212
- name: domainName,
213
- verifyingContract: tokenContract,
214
- version,
215
- },
216
- types: {
217
- EIP712Domain: [
218
- { name: "name", type: "string" },
219
- { name: "version", type: "string" },
220
- {
221
- name: "chainId",
222
- type: "uint256",
223
- },
224
- {
225
- name: "verifyingContract",
226
- type: "address",
227
- },
228
- ],
229
- },
230
- });
231
-
232
- // re-build the eip-712 typed data hash, consisting of the hashed domain and the structHash emitted from the event:
233
- const parts: Hex[] = ["0x1901", hashedDomain, structHash!];
234
-
235
- const hashedTypedData = keccak256(concat(parts));
236
-
237
- return await recoverAddress({
238
- hash: hashedTypedData,
239
- signature: signature!,
240
- });
241
- };
242
-
243
- export const supportedPremintVersions = async ({
244
- tokenContract,
245
- publicClient,
246
- }: {
247
- tokenContract: Address;
248
- publicClient: PublicClient;
249
- }): Promise<PremintConfigVersion[]> => {
250
- return (await publicClient.readContract({
251
- abi: preminterAbi,
252
- address: getPremintExecutorAddress(),
253
- functionName: "supportedPremintSignatureVersions",
254
- args: [tokenContract],
255
- })) as PremintConfigVersion[];
256
- };
257
- /**
258
- * Checks if the 1155 contract at that address supports the given version of the premint config.
259
- */
260
- export const supportsPremintVersion = async ({
261
- version,
262
- tokenContract,
263
- publicClient,
264
- }: {
265
- version: PremintConfigVersion;
266
- tokenContract: Address;
267
- publicClient: PublicClient;
268
- }): Promise<boolean> => {
269
- return (
270
- await supportedPremintVersions({ tokenContract, publicClient })
271
- ).includes(version);
272
- };
273
-
274
48
  export async function getPremintCollectionAddress({
275
49
  publicClient,
276
50
  contract: collection,
@@ -295,45 +69,6 @@ export async function getPremintCollectionAddress({
295
69
  return collectionAddress;
296
70
  }
297
71
 
298
- export function applyUpdateToPremint({
299
- uid,
300
- version,
301
- tokenConfig,
302
- tokenConfigUpdates,
303
- }: {
304
- tokenConfig: TokenCreationConfig;
305
- tokenConfigUpdates: Partial<TokenCreationConfig>;
306
- } & Pick<PremintConfig, "uid" | "version">): PremintConfig {
307
- const updatedTokenConfig: TokenCreationConfig = {
308
- ...tokenConfig,
309
- ...tokenConfigUpdates,
310
- } as const;
311
-
312
- const result = {
313
- deleted: false,
314
- uid,
315
- version: version + 1,
316
- tokenConfig: updatedTokenConfig,
317
- } as PremintConfig;
318
-
319
- return result;
320
- }
321
-
322
- export function makeNewPremint<T extends PremintConfigVersion>({
323
- tokenConfig,
324
- uid,
325
- }: {
326
- tokenConfig: PremintConfigForVersion<T>["tokenConfig"];
327
- uid: number;
328
- }): PremintConfigForVersion<T> {
329
- return {
330
- deleted: false,
331
- uid,
332
- version: 0,
333
- tokenConfig,
334
- } as PremintConfigForVersion<T>;
335
- }
336
-
337
72
  export async function getPremintMintFee({
338
73
  tokenContract,
339
74
  publicClient,
@@ -380,7 +115,7 @@ export async function getPremintMintCosts({
380
115
  totalCostEth: (mintFee + tokenPrice) * quantityToMintBigInt,
381
116
  };
382
117
  }
383
- export async function getPremintPricePerToken({
118
+ async function getPremintPricePerToken({
384
119
  collection,
385
120
  uid,
386
121
  premintGetter,
@@ -434,12 +169,6 @@ export function makeMintRewardsRecipient({
434
169
  return [mintReferral, platformReferral];
435
170
  }
436
171
 
437
- export function getDefaultFixedPriceMinterAddress(chainId: number): Address {
438
- return zoraCreatorFixedPriceSaleStrategyAddress[
439
- chainId as keyof typeof zoraCreatorFixedPriceSaleStrategyAddress
440
- ]!;
441
- }
442
-
443
172
  export const emptyContractCreationConfig = (): ContractCreationConfig => ({
444
173
  contractAdmin: zeroAddress,
445
174
  contractURI: "",
package/src/sdk.ts CHANGED
@@ -20,8 +20,6 @@ import {
20
20
  import { SecondaryClient } from "./secondary/secondary-client";
21
21
 
22
22
  export type CreatorClient = {
23
- createPremint: PremintClient["createPremint"];
24
- updatePremint: PremintClient["updatePremint"];
25
23
  deletePremint: PremintClient["deletePremint"];
26
24
  create1155: Create1155Client["createNew1155"];
27
25
  create1155OnExistingContract: Create1155Client["createNew1155OnExistingContract"];
@@ -82,8 +80,6 @@ export function createCreatorClient(
82
80
  });
83
81
 
84
82
  return {
85
- createPremint: (p) => premintClient.createPremint(p),
86
- updatePremint: (p) => premintClient.updatePremint(p),
87
83
  deletePremint: (p) => premintClient.deletePremint(p),
88
84
  create1155: (p) => create1155CreatorClient.createNew1155(p),
89
85
  create1155OnExistingContract: (p) =>