@zoralabs/protocol-deployments 0.1.9 → 0.1.11

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.
package/src/index.ts CHANGED
@@ -2,5 +2,7 @@
2
2
  // built at build time. They are not checked in to git.
3
3
  // The can be generated by running `yarn prepack` in the root
4
4
  export * from "./generated/wagmi";
5
+ export * from "./typedData";
6
+ export * from "./types";
5
7
  export * as contracts1155 from "./generated/1155";
6
8
  export * as mints from "./generated/mints";
@@ -0,0 +1,342 @@
1
+ import {
2
+ Address,
3
+ TypedDataDomain,
4
+ TypedData,
5
+ TypedDataToPrimitiveTypes,
6
+ } from "abitype";
7
+ import {
8
+ Hex,
9
+ TypedDataDefinition,
10
+ encodeAbiParameters,
11
+ getAbiItem,
12
+ keccak256,
13
+ toHex,
14
+ } from "viem";
15
+ import {
16
+ zoraMints1155Address,
17
+ iPremintDefinitionsABI,
18
+ } from "./generated/wagmi";
19
+ import {
20
+ PremintConfigEncoded,
21
+ PremintConfigV1,
22
+ PremintConfigV2,
23
+ PremintConfigVersion,
24
+ PremintConfigWithVersion,
25
+ TokenConfigWithVersion,
26
+ TokenCreationConfigV1,
27
+ TokenCreationConfigV2,
28
+ TokenCreationConfigV3,
29
+ } from "./types";
30
+
31
+ const premintTypedDataDomain = ({
32
+ chainId,
33
+ version,
34
+ creator1155Contract: verifyingContract,
35
+ }: {
36
+ chainId: number;
37
+ version: PremintConfigVersion;
38
+ creator1155Contract: Address;
39
+ }): TypedDataDomain => ({
40
+ chainId,
41
+ name: "Preminter",
42
+ version,
43
+ verifyingContract,
44
+ });
45
+
46
+ const premintV1TypedDataType = {
47
+ CreatorAttribution: [
48
+ { name: "tokenConfig", type: "TokenCreationConfig" },
49
+ // unique id scoped to the contract and token to create.
50
+ // ensure that a signature can be replaced, as long as the replacement
51
+ // has the same uid, and a newer version.
52
+ { name: "uid", type: "uint32" },
53
+ { name: "version", type: "uint32" },
54
+ // if this update should result in the signature being deleted.
55
+ { name: "deleted", type: "bool" },
56
+ ],
57
+ TokenCreationConfig: [
58
+ { name: "tokenURI", type: "string" },
59
+ { name: "maxSupply", type: "uint256" },
60
+ { name: "maxTokensPerAddress", type: "uint64" },
61
+ { name: "pricePerToken", type: "uint96" },
62
+ { name: "mintStart", type: "uint64" },
63
+ { name: "mintDuration", type: "uint64" },
64
+ { name: "royaltyMintSchedule", type: "uint32" },
65
+ { name: "royaltyBPS", type: "uint32" },
66
+ { name: "royaltyRecipient", type: "address" },
67
+ { name: "fixedPriceMinter", type: "address" },
68
+ ],
69
+ } as const satisfies TypedData;
70
+
71
+ const encodeTokenConfigV1 = (config: TokenCreationConfigV1) => {
72
+ const abiItem = getAbiItem({
73
+ abi: iPremintDefinitionsABI,
74
+ name: "tokenConfigV1Definition",
75
+ });
76
+
77
+ return encodeAbiParameters(abiItem.inputs, [config]);
78
+ };
79
+
80
+ const encodeTokenConfigV2 = (config: TokenCreationConfigV2) => {
81
+ const abiItem = getAbiItem({
82
+ abi: iPremintDefinitionsABI,
83
+ name: "tokenConfigV2Definition",
84
+ });
85
+
86
+ return encodeAbiParameters(abiItem.inputs, [config]);
87
+ };
88
+
89
+ const encodeTokenConfigV3 = (config: TokenCreationConfigV3) => {
90
+ const abiItem = getAbiItem({
91
+ abi: iPremintDefinitionsABI,
92
+ name: "tokenConfigV3Definition",
93
+ });
94
+
95
+ return encodeAbiParameters(abiItem.inputs, [config]);
96
+ };
97
+
98
+ const encodeTokenConfig = <T extends PremintConfigVersion>({
99
+ tokenConfig,
100
+ premintConfigVersion,
101
+ }: TokenConfigWithVersion<T>): Hex => {
102
+ if (premintConfigVersion === PremintConfigVersion.V1) {
103
+ return encodeTokenConfigV1(tokenConfig as TokenCreationConfigV1);
104
+ }
105
+ if (premintConfigVersion === PremintConfigVersion.V2) {
106
+ return encodeTokenConfigV2(tokenConfig as TokenCreationConfigV2);
107
+ }
108
+ if (premintConfigVersion === PremintConfigVersion.V3) {
109
+ return encodeTokenConfigV3(tokenConfig as TokenCreationConfigV3);
110
+ }
111
+
112
+ throw new Error("Invalid PremintConfigVersion: " + premintConfigVersion);
113
+ };
114
+
115
+ export const encodePremintConfig = <T extends PremintConfigVersion>({
116
+ premintConfig,
117
+ premintConfigVersion,
118
+ }: PremintConfigWithVersion<T>): PremintConfigEncoded => {
119
+ const encodedTokenConfig = encodeTokenConfig({
120
+ premintConfigVersion,
121
+ tokenConfig: premintConfig.tokenConfig,
122
+ });
123
+
124
+ return {
125
+ deleted: premintConfig.deleted,
126
+ uid: premintConfig.uid,
127
+ version: premintConfig.version,
128
+ premintConfigVersion: keccak256(toHex(premintConfigVersion)),
129
+ tokenConfig: encodedTokenConfig,
130
+ };
131
+ };
132
+
133
+ /**
134
+ * Builds a typed data definition for a PremintConfigV1 to be signed
135
+ * @returns
136
+ */
137
+ export const premintV1TypedDataDefinition = ({
138
+ chainId,
139
+ creator1155Contract,
140
+ message,
141
+ }: {
142
+ chainId: number;
143
+ creator1155Contract: Address;
144
+ message: PremintConfigV1;
145
+ }): TypedDataDefinition<
146
+ typeof premintV1TypedDataType,
147
+ "CreatorAttribution"
148
+ > => ({
149
+ types: premintV1TypedDataType,
150
+ primaryType: "CreatorAttribution",
151
+ domain: premintTypedDataDomain({
152
+ chainId,
153
+ version: PremintConfigVersion.V1,
154
+ creator1155Contract,
155
+ }),
156
+ message,
157
+ });
158
+
159
+ const premintV2TypedDataType = {
160
+ CreatorAttribution: [
161
+ { name: "tokenConfig", type: "TokenCreationConfig" },
162
+ // unique id scoped to the contract and token to create.
163
+ // ensure that a signature can be replaced, as long as the replacement
164
+ // has the same uid, and a newer version.
165
+ { name: "uid", type: "uint32" },
166
+ { name: "version", type: "uint32" },
167
+ // if this update should result in the signature being deleted.
168
+ { name: "deleted", type: "bool" },
169
+ ],
170
+ TokenCreationConfig: [
171
+ { name: "tokenURI", type: "string" },
172
+ { name: "maxSupply", type: "uint256" },
173
+ { name: "maxTokensPerAddress", type: "uint64" },
174
+ { name: "pricePerToken", type: "uint96" },
175
+ { name: "mintStart", type: "uint64" },
176
+ { name: "mintDuration", type: "uint64" },
177
+ { name: "royaltyBPS", type: "uint32" },
178
+ { name: "payoutRecipient", type: "address" },
179
+ { name: "fixedPriceMinter", type: "address" },
180
+ { name: "createReferral", type: "address" },
181
+ ],
182
+ } as const satisfies TypedData;
183
+
184
+ /**
185
+ * Builds a typed data definition for a PremintConfigV2 to be signed
186
+ */
187
+ export const premintV2TypedDataDefinition = ({
188
+ chainId,
189
+ creator1155Contract,
190
+ message,
191
+ }: {
192
+ chainId: number;
193
+ creator1155Contract: Address;
194
+ message: PremintConfigV2;
195
+ }): TypedDataDefinition<
196
+ typeof premintV2TypedDataType,
197
+ "CreatorAttribution"
198
+ > => ({
199
+ types: premintV2TypedDataType,
200
+ primaryType: "CreatorAttribution",
201
+ domain: premintTypedDataDomain({
202
+ chainId,
203
+ version: PremintConfigVersion.V2,
204
+ creator1155Contract,
205
+ }),
206
+ message,
207
+ });
208
+
209
+ export type PremintTypeDataDefinitionParams<T extends PremintConfigVersion> = {
210
+ verifyingContract: Address;
211
+ chainId: number;
212
+ } & PremintConfigWithVersion<T>;
213
+
214
+ /**
215
+ * Creates a typed data definition for a premint config. Works for all versions of the premint config by specifying the premintConfigVersion.
216
+ *
217
+ * @param params.verifyingContract the address of the 1155 contract
218
+ * @param params.chainId the chain id the premint is signed for
219
+ * @param params.premintConfigVersion the version of the premint config
220
+ * @param params.premintConfig the premint config
221
+ * @returns
222
+ */
223
+ export const premintTypedDataDefinition = <T extends PremintConfigVersion>({
224
+ verifyingContract,
225
+ chainId,
226
+ premintConfigVersion: version,
227
+ premintConfig,
228
+ }: PremintTypeDataDefinitionParams<T>): TypedDataDefinition => {
229
+ if (version === PremintConfigVersion.V1)
230
+ return premintV1TypedDataDefinition({
231
+ chainId,
232
+ creator1155Contract: verifyingContract,
233
+ message: premintConfig as PremintConfigV1,
234
+ });
235
+ if (version === PremintConfigVersion.V2) {
236
+ return premintV2TypedDataDefinition({
237
+ chainId,
238
+ creator1155Contract: verifyingContract,
239
+ message: premintConfig as PremintConfigV2,
240
+ });
241
+ }
242
+
243
+ throw new Error(`Invalid version ${version}`);
244
+ };
245
+
246
+ const permitSafeTransferTypedDataType = {
247
+ PermitSafeTransfer: [
248
+ { name: "owner", type: "address" },
249
+ { name: "to", type: "address" },
250
+ { name: "tokenId", type: "uint256" },
251
+ { name: "quantity", type: "uint256" },
252
+ { name: "safeTransferData", type: "bytes" },
253
+ { name: "nonce", type: "uint256" },
254
+ { name: "deadline", type: "uint256" },
255
+ ],
256
+ } as const;
257
+
258
+ /**
259
+ * Builds a typed data definition for a PermitSafeTransfer on the Mints1155 contract to be signed
260
+ */
261
+ export const mintsSafeTransferTypedDataDefinition = ({
262
+ chainId,
263
+ message,
264
+ }: {
265
+ chainId: keyof typeof zoraMints1155Address;
266
+ message: TypedDataToPrimitiveTypes<
267
+ typeof permitSafeTransferTypedDataType
268
+ >["PermitSafeTransfer"];
269
+ }): TypedDataDefinition<
270
+ typeof permitSafeTransferTypedDataType,
271
+ "PermitSafeTransfer"
272
+ > => ({
273
+ types: permitSafeTransferTypedDataType,
274
+ message,
275
+ primaryType: "PermitSafeTransfer",
276
+ domain: {
277
+ chainId,
278
+ name: "Mints",
279
+ version: "1",
280
+ verifyingContract: zoraMints1155Address[chainId],
281
+ },
282
+ });
283
+
284
+ const permitSafeBatchTransferTypedDataType = {
285
+ Permit: [
286
+ {
287
+ name: "owner",
288
+ type: "address",
289
+ },
290
+ {
291
+ name: "to",
292
+ type: "address",
293
+ },
294
+ {
295
+ name: "tokenIds",
296
+ type: "uint256[]",
297
+ },
298
+ {
299
+ name: "quantities",
300
+ type: "uint256[]",
301
+ },
302
+ {
303
+ name: "safeTransferData",
304
+ type: "bytes",
305
+ },
306
+ {
307
+ name: "nonce",
308
+ type: "uint256",
309
+ },
310
+ {
311
+ name: "deadline",
312
+ type: "uint256",
313
+ },
314
+ ],
315
+ } as const;
316
+
317
+ /**
318
+ * Builds a typed data definition for a PermitSafeTransferBatch on the Mints1155 contract to be signed
319
+ * @returns
320
+ */
321
+ export const mintsSafeTransferBatchTypedDataDefinition = ({
322
+ chainId,
323
+ message,
324
+ }: {
325
+ chainId: keyof typeof zoraMints1155Address;
326
+ message: TypedDataToPrimitiveTypes<
327
+ typeof permitSafeBatchTransferTypedDataType
328
+ >["Permit"];
329
+ }): TypedDataDefinition<
330
+ typeof permitSafeBatchTransferTypedDataType,
331
+ "Permit"
332
+ > => ({
333
+ types: permitSafeBatchTransferTypedDataType,
334
+ message,
335
+ primaryType: "Permit",
336
+ domain: {
337
+ chainId,
338
+ name: "Mints",
339
+ version: "1",
340
+ verifyingContract: zoraMints1155Address[chainId],
341
+ },
342
+ });
package/src/types.ts ADDED
@@ -0,0 +1,107 @@
1
+ import { ExtractAbiFunction, AbiParametersToPrimitiveTypes } from "abitype";
2
+
3
+ import {
4
+ zoraCreator1155PremintExecutorImplABI,
5
+ iPremintDefinitionsABI,
6
+ } from "./generated/wagmi";
7
+
8
+ export enum PremintConfigVersion {
9
+ V1 = "1",
10
+ V2 = "2",
11
+ V3 = "3",
12
+ }
13
+
14
+ export type ContractCreationConfig = AbiParametersToPrimitiveTypes<
15
+ ExtractAbiFunction<
16
+ typeof zoraCreator1155PremintExecutorImplABI,
17
+ "premint"
18
+ >["inputs"]
19
+ >[0];
20
+
21
+ export type TokenCreationConfigV1 = AbiParametersToPrimitiveTypes<
22
+ ExtractAbiFunction<
23
+ typeof iPremintDefinitionsABI,
24
+ "tokenConfigV1Definition"
25
+ >["inputs"]
26
+ >[0];
27
+
28
+ export type TokenCreationConfigV2 = AbiParametersToPrimitiveTypes<
29
+ ExtractAbiFunction<
30
+ typeof iPremintDefinitionsABI,
31
+ "tokenConfigV2Definition"
32
+ >["inputs"]
33
+ >[0];
34
+
35
+ export type TokenCreationConfigV3 = AbiParametersToPrimitiveTypes<
36
+ ExtractAbiFunction<
37
+ typeof iPremintDefinitionsABI,
38
+ "tokenConfigV3Definition"
39
+ >["inputs"]
40
+ >[0];
41
+
42
+ export type PremintConfigEncoded = AbiParametersToPrimitiveTypes<
43
+ ExtractAbiFunction<
44
+ typeof zoraCreator1155PremintExecutorImplABI,
45
+ "premint"
46
+ >["inputs"]
47
+ >[2];
48
+
49
+ type PremintConfigCommon = Pick<
50
+ PremintConfigEncoded,
51
+ "deleted" | "uid" | "version"
52
+ >;
53
+
54
+ export type PremintConfigV1 = PremintConfigCommon & {
55
+ tokenConfig: TokenCreationConfigV1;
56
+ };
57
+ export type PremintConfigV2 = PremintConfigCommon & {
58
+ tokenConfig: TokenCreationConfigV2;
59
+ };
60
+ export type PremintConfigV3 = PremintConfigCommon & {
61
+ tokenConfig: TokenCreationConfigV3;
62
+ };
63
+
64
+ export type PremintMintArguments = AbiParametersToPrimitiveTypes<
65
+ ExtractAbiFunction<
66
+ typeof zoraCreator1155PremintExecutorImplABI,
67
+ "premint"
68
+ >["inputs"]
69
+ >[5];
70
+
71
+ export type PremintConfigForVersion<T extends PremintConfigVersion> =
72
+ T extends PremintConfigVersion.V1
73
+ ? PremintConfigV1
74
+ : T extends PremintConfigVersion.V2
75
+ ? PremintConfigV2
76
+ : PremintConfigV3;
77
+
78
+ export type PremintConfigWithVersion<T extends PremintConfigVersion> = {
79
+ premintConfig: PremintConfigForVersion<T>;
80
+ premintConfigVersion: T;
81
+ };
82
+ export type PremintConfigAndVersion =
83
+ | PremintConfigWithVersion<PremintConfigVersion.V1>
84
+ | PremintConfigWithVersion<PremintConfigVersion.V2>
85
+ | PremintConfigWithVersion<PremintConfigVersion.V3>;
86
+
87
+ export type PremintConfig = PremintConfigV1 | PremintConfigV2;
88
+
89
+ export type TokenCreationConfig =
90
+ | TokenCreationConfigV1
91
+ | TokenCreationConfigV2
92
+ | TokenCreationConfigV3;
93
+
94
+ export type PremintConfigForTokenCreationConfig<T extends TokenCreationConfig> =
95
+ T extends TokenCreationConfigV1
96
+ ? PremintConfigV1
97
+ : T extends TokenCreationConfigV2
98
+ ? PremintConfigV2
99
+ : PremintConfigV3;
100
+
101
+ export type TokenConfigForVersion<T extends PremintConfigVersion> =
102
+ PremintConfigForVersion<T>["tokenConfig"];
103
+
104
+ export type TokenConfigWithVersion<T extends PremintConfigVersion> = {
105
+ tokenConfig: TokenConfigForVersion<T>;
106
+ premintConfigVersion: T;
107
+ };