@zoralabs/protocol-deployments 0.1.10 → 0.1.12

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
@@ -3,5 +3,6 @@
3
3
  // The can be generated by running `yarn prepack` in the root
4
4
  export * from "./generated/wagmi";
5
5
  export * from "./typedData";
6
+ export * from "./types";
6
7
  export * as contracts1155 from "./generated/1155";
7
8
  export * as mints from "./generated/mints";
package/src/typedData.ts CHANGED
@@ -4,8 +4,29 @@ import {
4
4
  TypedData,
5
5
  TypedDataToPrimitiveTypes,
6
6
  } from "abitype";
7
- import { TypedDataDefinition } from "viem";
8
- import { zoraMints1155Address } from "./generated/wagmi";
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";
9
30
 
10
31
  const premintTypedDataDomain = ({
11
32
  chainId,
@@ -13,7 +34,7 @@ const premintTypedDataDomain = ({
13
34
  creator1155Contract: verifyingContract,
14
35
  }: {
15
36
  chainId: number;
16
- version: "1" | "2";
37
+ version: PremintConfigVersion;
17
38
  creator1155Contract: Address;
18
39
  }): TypedDataDomain => ({
19
40
  chainId,
@@ -47,6 +68,68 @@ const premintV1TypedDataType = {
47
68
  ],
48
69
  } as const satisfies TypedData;
49
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
+
50
133
  /**
51
134
  * Builds a typed data definition for a PremintConfigV1 to be signed
52
135
  * @returns
@@ -58,9 +141,7 @@ export const premintV1TypedDataDefinition = ({
58
141
  }: {
59
142
  chainId: number;
60
143
  creator1155Contract: Address;
61
- message: TypedDataToPrimitiveTypes<
62
- typeof premintV1TypedDataType
63
- >["CreatorAttribution"];
144
+ message: PremintConfigV1;
64
145
  }): TypedDataDefinition<
65
146
  typeof premintV1TypedDataType,
66
147
  "CreatorAttribution"
@@ -69,7 +150,7 @@ export const premintV1TypedDataDefinition = ({
69
150
  primaryType: "CreatorAttribution",
70
151
  domain: premintTypedDataDomain({
71
152
  chainId,
72
- version: "1",
153
+ version: PremintConfigVersion.V1,
73
154
  creator1155Contract,
74
155
  }),
75
156
  message,
@@ -110,9 +191,7 @@ export const premintV2TypedDataDefinition = ({
110
191
  }: {
111
192
  chainId: number;
112
193
  creator1155Contract: Address;
113
- message: TypedDataToPrimitiveTypes<
114
- typeof premintV2TypedDataType
115
- >["CreatorAttribution"];
194
+ message: PremintConfigV2;
116
195
  }): TypedDataDefinition<
117
196
  typeof premintV2TypedDataType,
118
197
  "CreatorAttribution"
@@ -121,12 +200,49 @@ export const premintV2TypedDataDefinition = ({
121
200
  primaryType: "CreatorAttribution",
122
201
  domain: premintTypedDataDomain({
123
202
  chainId,
124
- version: "2",
203
+ version: PremintConfigVersion.V2,
125
204
  creator1155Contract,
126
205
  }),
127
206
  message,
128
207
  });
129
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
+
130
246
  const permitSafeTransferTypedDataType = {
131
247
  PermitSafeTransfer: [
132
248
  { name: "owner", type: "address" },
package/src/types.ts ADDED
@@ -0,0 +1,109 @@
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
+ /** Premint Config */
80
+ premintConfig: PremintConfigForVersion<T>;
81
+ /** PremintConfigVersion of the premint */
82
+ premintConfigVersion: T;
83
+ };
84
+ export type PremintConfigAndVersion =
85
+ | PremintConfigWithVersion<PremintConfigVersion.V1>
86
+ | PremintConfigWithVersion<PremintConfigVersion.V2>
87
+ | PremintConfigWithVersion<PremintConfigVersion.V3>;
88
+
89
+ export type PremintConfig = PremintConfigV1 | PremintConfigV2;
90
+
91
+ export type TokenCreationConfig =
92
+ | TokenCreationConfigV1
93
+ | TokenCreationConfigV2
94
+ | TokenCreationConfigV3;
95
+
96
+ export type PremintConfigForTokenCreationConfig<T extends TokenCreationConfig> =
97
+ T extends TokenCreationConfigV1
98
+ ? PremintConfigV1
99
+ : T extends TokenCreationConfigV2
100
+ ? PremintConfigV2
101
+ : PremintConfigV3;
102
+
103
+ export type TokenConfigForVersion<T extends PremintConfigVersion> =
104
+ PremintConfigForVersion<T>["tokenConfig"];
105
+
106
+ export type TokenConfigWithVersion<T extends PremintConfigVersion> = {
107
+ tokenConfig: TokenConfigForVersion<T>;
108
+ premintConfigVersion: T;
109
+ };