@zoralabs/protocol-sdk 0.5.14 → 0.5.16
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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +15 -0
- package/README.md +42 -2
- package/dist/anvil.d.ts +4 -4
- package/dist/anvil.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/create/1155-create-helper.d.ts +3 -4
- package/dist/create/1155-create-helper.d.ts.map +1 -1
- package/dist/index.cjs +534 -375
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +517 -356
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +14 -6
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +25 -19
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mints/mints-contracts.d.ts +688 -3
- package/dist/mints/mints-contracts.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +111 -1465
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +2 -1
- package/dist/premint/preminter.d.ts.map +1 -1
- package/dist/utils.d.ts +6872 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/constants.ts +36 -0
- package/src/create/1155-create-helper.test.ts +10 -3
- package/src/create/1155-create-helper.ts +8 -7
- package/src/mint/mint-api-client.ts +107 -45
- package/src/mint/mint-client.test.ts +113 -2
- package/src/mint/mint-client.ts +95 -53
- package/src/premint/premint-client.test.ts +16 -10
- package/src/premint/premint-client.ts +566 -374
- package/src/premint/preminter.ts +3 -1
- package/src/utils.ts +25 -0
- package/test-integration/premint-client.test.ts +2 -2
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { decodeEventLog, zeroAddress } from "viem";
|
|
2
2
|
import type {
|
|
3
3
|
Account,
|
|
4
4
|
Address,
|
|
5
5
|
Chain,
|
|
6
6
|
Hex,
|
|
7
|
-
|
|
7
|
+
SimulateContractParameters,
|
|
8
8
|
TransactionReceipt,
|
|
9
|
+
TypedDataDefinition,
|
|
9
10
|
WalletClient,
|
|
10
11
|
} from "viem";
|
|
11
12
|
import { zoraCreator1155PremintExecutorImplABI } from "@zoralabs/protocol-deployments";
|
|
@@ -39,7 +40,12 @@ import { OPEN_EDITION_MINT_SIZE } from "../constants";
|
|
|
39
40
|
import { IHttpClient } from "src/apis/http-api-base";
|
|
40
41
|
import { getApiNetworkConfigForChain } from "src/mint/mint-api-client";
|
|
41
42
|
import { MintCosts } from "src/mint/mint-client";
|
|
42
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
ClientConfig,
|
|
45
|
+
makeSimulateContractParamaters,
|
|
46
|
+
PublicClient,
|
|
47
|
+
setupClient,
|
|
48
|
+
} from "src/utils";
|
|
43
49
|
|
|
44
50
|
type PremintedV2LogType = DecodeEventLogReturnType<
|
|
45
51
|
typeof zoraCreator1155PremintExecutorImplABI,
|
|
@@ -52,12 +58,6 @@ type URLSReturnType = {
|
|
|
52
58
|
zoraManage: null | string;
|
|
53
59
|
};
|
|
54
60
|
|
|
55
|
-
type SignedPremintResponse = {
|
|
56
|
-
urls: URLSReturnType;
|
|
57
|
-
uid: number;
|
|
58
|
-
verifyingContract: Address;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
61
|
export const defaultTokenConfigV1MintArguments = (): Omit<
|
|
62
62
|
TokenCreationConfigV1,
|
|
63
63
|
"fixedPriceMinter" | "tokenURI" | "royaltyRecipient"
|
|
@@ -87,12 +87,12 @@ const makeTokenConfigWithDefaults = <T extends PremintConfigVersion>({
|
|
|
87
87
|
chainId,
|
|
88
88
|
premintConfigVersion,
|
|
89
89
|
tokenCreationConfig,
|
|
90
|
-
|
|
90
|
+
payoutRecipient,
|
|
91
91
|
}: {
|
|
92
92
|
chainId: number;
|
|
93
93
|
premintConfigVersion: T;
|
|
94
94
|
tokenCreationConfig: Partial<TokenConfigForVersion<T>> & { tokenURI: string };
|
|
95
|
-
|
|
95
|
+
payoutRecipient: Address;
|
|
96
96
|
}): TokenConfigForVersion<T> => {
|
|
97
97
|
if (premintConfigVersion === PremintConfigVersion.V3) {
|
|
98
98
|
throw new Error("PremintV3 not supported in SDK");
|
|
@@ -109,14 +109,14 @@ const makeTokenConfigWithDefaults = <T extends PremintConfigVersion>({
|
|
|
109
109
|
return {
|
|
110
110
|
fixedPriceMinter,
|
|
111
111
|
...defaultTokenConfigV1MintArguments(),
|
|
112
|
-
royaltyRecipient:
|
|
112
|
+
royaltyRecipient: payoutRecipient,
|
|
113
113
|
...(tokenCreationConfig as Partial<TokenCreationConfigV1>),
|
|
114
114
|
} as TokenCreationConfigV1;
|
|
115
115
|
} else if (premintConfigVersion === PremintConfigVersion.V2) {
|
|
116
116
|
return {
|
|
117
117
|
fixedPriceMinter,
|
|
118
118
|
...defaultTokenConfigV2MintArguments(),
|
|
119
|
-
payoutRecipient:
|
|
119
|
+
payoutRecipient: payoutRecipient,
|
|
120
120
|
createReferral: zeroAddress,
|
|
121
121
|
...tokenCreationConfig,
|
|
122
122
|
};
|
|
@@ -149,7 +149,6 @@ export function getPremintedLogFromReceipt(
|
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
151
|
* Preminter API to access ZORA Premint functionality.
|
|
152
|
-
* Currently only supports V1 premints.
|
|
153
152
|
*/
|
|
154
153
|
class PremintClient {
|
|
155
154
|
readonly apiClient: PremintAPIClient;
|
|
@@ -158,13 +157,12 @@ class PremintClient {
|
|
|
158
157
|
|
|
159
158
|
constructor(
|
|
160
159
|
chain: Chain,
|
|
161
|
-
publicClient
|
|
162
|
-
httpClient
|
|
160
|
+
publicClient: PublicClient,
|
|
161
|
+
httpClient: IHttpClient,
|
|
163
162
|
) {
|
|
164
163
|
this.chain = chain;
|
|
165
164
|
this.apiClient = new PremintAPIClient(chain.id, httpClient);
|
|
166
|
-
this.publicClient =
|
|
167
|
-
publicClient || createPublicClient({ chain, transport: http() });
|
|
165
|
+
this.publicClient = publicClient;
|
|
168
166
|
}
|
|
169
167
|
|
|
170
168
|
getDataFromPremintReceipt(receipt: TransactionReceipt) {
|
|
@@ -179,219 +177,51 @@ class PremintClient {
|
|
|
179
177
|
}
|
|
180
178
|
|
|
181
179
|
/**
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
* 1. Loads existing premint token
|
|
185
|
-
* 2. Updates with settings passed into function
|
|
186
|
-
* 3. Increments the version field
|
|
187
|
-
* 4. Re-signs the premint
|
|
188
|
-
* 5. Uploads the premint to the ZORA API
|
|
189
|
-
*
|
|
190
|
-
* Updates existing premint
|
|
191
|
-
* @param settings Settings for the new premint
|
|
192
|
-
* @param settings.account Account to sign the premint update from. Taken from walletClient if none passed in.
|
|
193
|
-
* @param settings.collection Collection information for the mint
|
|
194
|
-
* @param settings.walletClient viem wallet client to use to sign
|
|
195
|
-
* @param settings.uid UID
|
|
196
|
-
* @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
|
|
197
|
-
*
|
|
198
|
-
*/
|
|
199
|
-
async updatePremint({
|
|
200
|
-
walletClient,
|
|
201
|
-
uid,
|
|
202
|
-
collection,
|
|
203
|
-
account,
|
|
204
|
-
tokenConfigUpdates,
|
|
205
|
-
}: {
|
|
206
|
-
walletClient: WalletClient;
|
|
207
|
-
uid: number;
|
|
208
|
-
account?: Account | Address;
|
|
209
|
-
collection: Address;
|
|
210
|
-
tokenConfigUpdates: Partial<TokenCreationConfig>;
|
|
211
|
-
}): Promise<SignedPremintResponse> {
|
|
212
|
-
const {
|
|
213
|
-
premintConfig,
|
|
214
|
-
collection: collectionCreationConfig,
|
|
215
|
-
premintConfigVersion,
|
|
216
|
-
} = await this.apiClient.getSignature({
|
|
217
|
-
collectionAddress: collection,
|
|
218
|
-
uid: uid,
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
const updatedPremint = applyUpdateToPremint({
|
|
222
|
-
uid: premintConfig.uid,
|
|
223
|
-
version: premintConfig.version,
|
|
224
|
-
tokenConfig: premintConfig.tokenConfig,
|
|
225
|
-
tokenConfigUpdates: tokenConfigUpdates,
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
return await this.signAndSubmitPremint({
|
|
229
|
-
walletClient,
|
|
230
|
-
account,
|
|
231
|
-
checkSignature: true,
|
|
232
|
-
verifyingContract: collection,
|
|
233
|
-
collection: collectionCreationConfig,
|
|
234
|
-
premintConfig: updatedPremint,
|
|
235
|
-
premintConfigVersion: premintConfigVersion,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Delete premint.
|
|
241
|
-
*
|
|
242
|
-
* 1. Loads current premint from collection address with UID
|
|
243
|
-
* 2. Increments version and marks as deleted
|
|
244
|
-
* 3. Signs new premint version
|
|
245
|
-
* 4. Sends to ZORA Premint API
|
|
246
|
-
*
|
|
247
|
-
* Deletes existing premint
|
|
248
|
-
* @param settings.collection collection address
|
|
249
|
-
* @param settings.uid UID
|
|
250
|
-
* @param settings.walletClient viem wallet client to use to sign
|
|
180
|
+
* Prepares data for updating a premint
|
|
251
181
|
*
|
|
182
|
+
* @param parameters - Parameters for updating the premint {@link UpdatePremintParams}
|
|
183
|
+
* @returns A PremintReturn. {@link PremintReturn}
|
|
252
184
|
*/
|
|
253
|
-
async
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
walletClient: WalletClient;
|
|
260
|
-
uid: number;
|
|
261
|
-
account?: Account | Address;
|
|
262
|
-
collection: Address;
|
|
263
|
-
}) {
|
|
264
|
-
const {
|
|
265
|
-
premintConfig,
|
|
266
|
-
premintConfigVersion,
|
|
267
|
-
collection: collectionCreationConfig,
|
|
268
|
-
} = await this.apiClient.getSignature({
|
|
269
|
-
collectionAddress: collection,
|
|
270
|
-
uid: uid,
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
const deletedPremint = {
|
|
274
|
-
...premintConfig,
|
|
275
|
-
version: premintConfig.version + 1,
|
|
276
|
-
deleted: true,
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
return await this.signAndSubmitPremint({
|
|
280
|
-
walletClient,
|
|
281
|
-
account,
|
|
282
|
-
checkSignature: false,
|
|
283
|
-
verifyingContract: collection,
|
|
284
|
-
collection: collectionCreationConfig,
|
|
285
|
-
premintConfig: deletedPremint,
|
|
286
|
-
premintConfigVersion,
|
|
185
|
+
async updatePremint(args: UpdatePremintParams): Promise<PremintReturn<any>> {
|
|
186
|
+
return await updatePremint({
|
|
187
|
+
...args,
|
|
188
|
+
apiClient: this.apiClient,
|
|
189
|
+
publicClient: this.publicClient,
|
|
190
|
+
chainId: this.chain.id,
|
|
287
191
|
});
|
|
288
192
|
}
|
|
289
193
|
|
|
290
194
|
/**
|
|
291
|
-
*
|
|
195
|
+
* Prepares data for deleting a premint
|
|
292
196
|
*
|
|
293
|
-
* @param
|
|
294
|
-
* @returns
|
|
197
|
+
* @param parameters - Parameters for deleting the premint {@link DeletePremintParams}
|
|
198
|
+
* @returns A PremintReturn. {@link PremintReturn}
|
|
295
199
|
*/
|
|
296
|
-
|
|
297
|
-
params:
|
|
298
|
-
): Promise<
|
|
299
|
-
|
|
200
|
+
async deletePremint(
|
|
201
|
+
params: DeletePremintParams,
|
|
202
|
+
): Promise<PremintReturn<any>> {
|
|
203
|
+
return deletePremint({
|
|
300
204
|
...params,
|
|
301
|
-
chainId: this.chain.id,
|
|
302
205
|
apiClient: this.apiClient,
|
|
303
206
|
publicClient: this.publicClient,
|
|
207
|
+
chainId: this.chain.id,
|
|
304
208
|
});
|
|
305
|
-
|
|
306
|
-
const uid = params.premintConfig.uid;
|
|
307
|
-
|
|
308
|
-
return {
|
|
309
|
-
urls: this.makeUrls({ address: verifyingContract, uid }),
|
|
310
|
-
uid,
|
|
311
|
-
verifyingContract,
|
|
312
|
-
};
|
|
313
209
|
}
|
|
314
210
|
|
|
315
211
|
/**
|
|
316
|
-
*
|
|
212
|
+
* Prepares data for creating a premint
|
|
317
213
|
*
|
|
318
|
-
* @param
|
|
319
|
-
* @
|
|
320
|
-
* @param settings.collection Collection information for the mint
|
|
321
|
-
* @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
|
|
322
|
-
* @param setings.premintConfigVersion Premint config version to use, defaults to V2
|
|
323
|
-
* @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
|
|
324
|
-
* @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
|
|
325
|
-
* @returns premint url, uid, newContractAddress, and premint object
|
|
214
|
+
* @param parameters - Parameters for creating the premint {@link CreatePremintParameters}
|
|
215
|
+
* @returns A PremintReturn. {@link PremintReturn}
|
|
326
216
|
*/
|
|
327
|
-
async createPremint<
|
|
328
|
-
T
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
tokenCreationConfig,
|
|
333
|
-
premintConfigVersion,
|
|
334
|
-
walletClient,
|
|
335
|
-
uid,
|
|
336
|
-
checkSignature = false,
|
|
337
|
-
}: {
|
|
338
|
-
creatorAccount: Address | Account;
|
|
339
|
-
checkSignature?: boolean;
|
|
340
|
-
walletClient: WalletClient;
|
|
341
|
-
collection: ContractCreationConfig;
|
|
342
|
-
tokenCreationConfig: Partial<TokenConfigForVersion<T>> & {
|
|
343
|
-
tokenURI: string;
|
|
344
|
-
};
|
|
345
|
-
premintConfigVersion?: T;
|
|
346
|
-
uid?: number;
|
|
347
|
-
}) {
|
|
348
|
-
const newContractAddress = await getPremintCollectionAddress({
|
|
217
|
+
async createPremint<T extends PremintConfigVersion = PremintConfigVersion.V2>(
|
|
218
|
+
parameters: CreatePremintParameters<T>,
|
|
219
|
+
): Promise<PremintReturn<any>> {
|
|
220
|
+
return createPremint({
|
|
221
|
+
...parameters,
|
|
349
222
|
publicClient: this.publicClient,
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
let uidToUse = uid;
|
|
354
|
-
|
|
355
|
-
if (typeof uidToUse !== "number") {
|
|
356
|
-
uidToUse = await this.apiClient.getNextUID(newContractAddress);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const actualVersion = premintConfigVersion || PremintConfigVersion.V1;
|
|
360
|
-
|
|
361
|
-
if (
|
|
362
|
-
!(await supportsPremintVersion({
|
|
363
|
-
version: actualVersion,
|
|
364
|
-
publicClient: this.publicClient,
|
|
365
|
-
tokenContract: newContractAddress,
|
|
366
|
-
}))
|
|
367
|
-
) {
|
|
368
|
-
throw new Error(
|
|
369
|
-
`Premint version ${actualVersion} not supported by contract`,
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const premintConfig = makeNewPremint({
|
|
374
|
-
tokenConfig: makeTokenConfigWithDefaults({
|
|
375
|
-
// @ts-ignore
|
|
376
|
-
premintConfigVersion: actualVersion,
|
|
377
|
-
tokenCreationConfig,
|
|
378
|
-
creatorAccount:
|
|
379
|
-
typeof creatorAccount === "string"
|
|
380
|
-
? creatorAccount
|
|
381
|
-
: creatorAccount.address,
|
|
382
|
-
chainId: this.chain.id,
|
|
383
|
-
}),
|
|
384
|
-
uid: uidToUse,
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
return await this.signAndSubmitPremint({
|
|
388
|
-
verifyingContract: newContractAddress,
|
|
389
|
-
premintConfig,
|
|
390
|
-
premintConfigVersion: actualVersion,
|
|
391
|
-
checkSignature,
|
|
392
|
-
account: creatorAccount,
|
|
393
|
-
walletClient,
|
|
394
|
-
collection,
|
|
223
|
+
apiClient: this.apiClient,
|
|
224
|
+
chainId: this.chain.id,
|
|
395
225
|
});
|
|
396
226
|
}
|
|
397
227
|
|
|
@@ -494,125 +324,550 @@ class PremintClient {
|
|
|
494
324
|
}
|
|
495
325
|
|
|
496
326
|
/**
|
|
497
|
-
*
|
|
327
|
+
* Prepares the parameters to collect a premint; it brings the contract and token onchain, then collects
|
|
328
|
+
* tokens on that contract for the mint recipient.
|
|
498
329
|
*
|
|
499
|
-
* @param
|
|
500
|
-
* @param settings.account Optional account (if omitted taken from wallet client) for the account executing the premint.
|
|
501
|
-
* @param settings.walletClient WalletClient to send execution from.
|
|
502
|
-
* @param settings.mintArguments User minting arguments.
|
|
503
|
-
* @param settings.mintArguments.quantityToMint Quantity to mint, optional, defaults to 1.
|
|
504
|
-
* @param settings.mintArguments.mintComment Optional mint comment, optional, omits when not included.
|
|
505
|
-
* @param settings.publicClient Optional public client for preflight checks.
|
|
330
|
+
* @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
|
|
506
331
|
* @returns receipt, log, zoraURL
|
|
507
332
|
*/
|
|
508
|
-
async makeMintParameters({
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
minterAccount: Account | Address;
|
|
517
|
-
mintArguments?: {
|
|
518
|
-
quantityToMint: number;
|
|
519
|
-
mintComment?: string;
|
|
520
|
-
mintReferral?: Address;
|
|
521
|
-
platformReferral?: Address;
|
|
522
|
-
mintRecipient?: Address;
|
|
523
|
-
};
|
|
524
|
-
}) {
|
|
525
|
-
if (mintArguments && mintArguments?.quantityToMint < 1) {
|
|
526
|
-
throw new Error("Quantity to mint cannot be below 1");
|
|
527
|
-
}
|
|
333
|
+
async makeMintParameters(parameters: MakeMintParametersArguments) {
|
|
334
|
+
return await makeMintParameters({
|
|
335
|
+
...parameters,
|
|
336
|
+
apiClient: this.apiClient,
|
|
337
|
+
publicClient: this.publicClient,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
528
341
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
342
|
+
export function createPremintClient(clientConfig: ClientConfig) {
|
|
343
|
+
const { chain, httpClient, publicClient } = setupClient(clientConfig);
|
|
344
|
+
return new PremintClient(chain, publicClient, httpClient);
|
|
345
|
+
}
|
|
532
346
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
});
|
|
347
|
+
type ContractCreationConfigWithoutAdditionalAdmins = Omit<
|
|
348
|
+
ContractCreationConfig,
|
|
349
|
+
"additionalAdmins"
|
|
350
|
+
>;
|
|
538
351
|
|
|
539
|
-
|
|
352
|
+
type PremintContext = {
|
|
353
|
+
publicClient: PublicClient;
|
|
354
|
+
apiClient: PremintAPIClient;
|
|
355
|
+
chainId: number;
|
|
356
|
+
};
|
|
540
357
|
|
|
541
|
-
|
|
542
|
-
throw new Error("PremintV3 not supported in premint SDK");
|
|
543
|
-
}
|
|
358
|
+
/** ======= ADMIN ======= */
|
|
544
359
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
360
|
+
export type SignAndSubmitParams = {
|
|
361
|
+
/** The WalletClient used to sign the premint */
|
|
362
|
+
walletClient: WalletClient;
|
|
363
|
+
/** The account that is to sign the premint */
|
|
364
|
+
account: Account | Address;
|
|
365
|
+
/** If the signature should be checked before submitting it to the api */
|
|
366
|
+
checkSignature?: boolean;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
export type SignAndSubmitReturn = {
|
|
370
|
+
/** The signature of the Premint */
|
|
371
|
+
signature: Hex;
|
|
372
|
+
/** The account that signed the Premint */
|
|
373
|
+
signerAccount: Account | Address;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
export type SubmitParams = {
|
|
377
|
+
/** The signature of the Premint */
|
|
378
|
+
signature: Hex;
|
|
379
|
+
/** If the premint signature should be validated before submitting to the API */
|
|
380
|
+
checkSignature?: boolean;
|
|
381
|
+
/** The account that signed the premint */
|
|
382
|
+
signerAccount: Account | Address;
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
type PremintReturn<T extends PremintConfigVersion> = {
|
|
386
|
+
/** The typedDataDefinition of the Premint which is to be signed the creator. */
|
|
387
|
+
typedDataDefinition: TypedDataDefinition;
|
|
388
|
+
/** The deterministic collection address of the Premint */
|
|
389
|
+
collectionAddress: Address;
|
|
390
|
+
/** Signs the Premint, and submits it and the signature to the Zora Premint API */
|
|
391
|
+
signAndSubmit: (params: SignAndSubmitParams) => Promise<SignAndSubmitReturn>;
|
|
392
|
+
/** For the case where the premint is signed externally, takes the signature for the Premint, and submits it and the Premint to the Zora Premint API */
|
|
393
|
+
submit: (params: SubmitParams) => void;
|
|
394
|
+
} & PremintConfigWithVersion<T>;
|
|
395
|
+
|
|
396
|
+
function makePremintReturn<T extends PremintConfigVersion>({
|
|
397
|
+
premintConfig,
|
|
398
|
+
premintConfigVersion,
|
|
399
|
+
collectionAddress,
|
|
400
|
+
collection,
|
|
401
|
+
publicClient,
|
|
402
|
+
apiClient,
|
|
403
|
+
chainId,
|
|
404
|
+
}: PremintConfigWithVersion<T> & {
|
|
405
|
+
collectionAddress: Address;
|
|
406
|
+
collection: ContractCreationConfigWithoutAdditionalAdmins;
|
|
407
|
+
} & PremintContext): PremintReturn<T> {
|
|
408
|
+
const typedDataDefinition = premintTypedDataDefinition({
|
|
409
|
+
verifyingContract: collectionAddress,
|
|
410
|
+
premintConfig,
|
|
411
|
+
premintConfigVersion,
|
|
412
|
+
chainId,
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
const signAndSubmit = async ({
|
|
416
|
+
walletClient,
|
|
417
|
+
account,
|
|
418
|
+
checkSignature,
|
|
419
|
+
}: SignAndSubmitParams): Promise<SignAndSubmitReturn> => {
|
|
420
|
+
const { signature, signerAccount } = await signPremint({
|
|
421
|
+
account,
|
|
422
|
+
walletClient,
|
|
423
|
+
typedDataDefinition,
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
await submit({
|
|
427
|
+
signature,
|
|
428
|
+
checkSignature,
|
|
429
|
+
signerAccount,
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
return {
|
|
433
|
+
signature,
|
|
434
|
+
signerAccount,
|
|
565
435
|
};
|
|
436
|
+
};
|
|
566
437
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
account: minterAccount,
|
|
585
|
-
abi: zoraCreator1155PremintExecutorImplABI,
|
|
586
|
-
functionName: "premintV2",
|
|
587
|
-
value,
|
|
588
|
-
address: getPremintExecutorAddress(),
|
|
589
|
-
args: [
|
|
590
|
-
collection,
|
|
591
|
-
premintConfig,
|
|
592
|
-
signature,
|
|
593
|
-
numberToMint,
|
|
594
|
-
mintArgumentsContract,
|
|
595
|
-
],
|
|
438
|
+
const submit = async ({
|
|
439
|
+
signature,
|
|
440
|
+
checkSignature,
|
|
441
|
+
signerAccount,
|
|
442
|
+
}: {
|
|
443
|
+
signature: Hex;
|
|
444
|
+
checkSignature?: boolean;
|
|
445
|
+
signerAccount: Account | Address;
|
|
446
|
+
}) => {
|
|
447
|
+
if (checkSignature) {
|
|
448
|
+
await validateSignature({
|
|
449
|
+
collection: {
|
|
450
|
+
...collection,
|
|
451
|
+
additionalAdmins: [],
|
|
452
|
+
},
|
|
453
|
+
publicClient,
|
|
454
|
+
signerAccount,
|
|
596
455
|
});
|
|
597
456
|
}
|
|
598
457
|
|
|
599
|
-
|
|
458
|
+
await apiClient.postSignature({
|
|
459
|
+
collection: {
|
|
460
|
+
...collection,
|
|
461
|
+
additionalAdmins: [],
|
|
462
|
+
},
|
|
463
|
+
signature: signature,
|
|
464
|
+
premintConfig,
|
|
465
|
+
premintConfigVersion,
|
|
466
|
+
});
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
return {
|
|
470
|
+
premintConfig,
|
|
471
|
+
premintConfigVersion,
|
|
472
|
+
typedDataDefinition,
|
|
473
|
+
collectionAddress,
|
|
474
|
+
signAndSubmit,
|
|
475
|
+
submit,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
async function signPremint({
|
|
480
|
+
account,
|
|
481
|
+
walletClient,
|
|
482
|
+
typedDataDefinition,
|
|
483
|
+
}: {
|
|
484
|
+
/** The account that is to sign the premint */
|
|
485
|
+
account?: Address | Account;
|
|
486
|
+
/** WalletClient used to sign the premint */
|
|
487
|
+
walletClient: WalletClient;
|
|
488
|
+
/** Data */
|
|
489
|
+
typedDataDefinition: TypedDataDefinition;
|
|
490
|
+
}) {
|
|
491
|
+
if (!account) {
|
|
492
|
+
account = walletClient.account;
|
|
600
493
|
}
|
|
494
|
+
if (!account) {
|
|
495
|
+
throw new Error("No account provided");
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const signature = await walletClient.signTypedData({
|
|
499
|
+
account,
|
|
500
|
+
...typedDataDefinition,
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
return {
|
|
504
|
+
signature,
|
|
505
|
+
signerAccount: account,
|
|
506
|
+
};
|
|
601
507
|
}
|
|
602
508
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
httpClient,
|
|
509
|
+
const validateSignature = async ({
|
|
510
|
+
collection,
|
|
606
511
|
publicClient,
|
|
512
|
+
signerAccount,
|
|
607
513
|
}: {
|
|
608
|
-
|
|
609
|
-
publicClient
|
|
610
|
-
|
|
514
|
+
collection: ContractCreationConfig;
|
|
515
|
+
publicClient: PublicClient;
|
|
516
|
+
signerAccount: Address | Account;
|
|
517
|
+
}) => {
|
|
518
|
+
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
519
|
+
collection,
|
|
520
|
+
publicClient,
|
|
521
|
+
signer:
|
|
522
|
+
typeof signerAccount === "string" ? signerAccount : signerAccount.address,
|
|
523
|
+
collectionAddress: await getPremintCollectionAddress({
|
|
524
|
+
collection,
|
|
525
|
+
publicClient,
|
|
526
|
+
}),
|
|
527
|
+
});
|
|
528
|
+
if (!isAuthorized) {
|
|
529
|
+
throw new Error("Not authorized to create premint");
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
/** CREATE */
|
|
534
|
+
|
|
535
|
+
type CreatePremintParameters<T extends PremintConfigVersion> = {
|
|
536
|
+
/** The account to receive the creator reward if it's a free mint, and the paid mint fee if it's a paid mint */
|
|
537
|
+
payoutRecipient: Address;
|
|
538
|
+
/** Collection information for the mint */
|
|
539
|
+
collection: ContractCreationConfigWithoutAdditionalAdmins;
|
|
540
|
+
/** tokenCreationConfig Token creation settings, optional settings are overridden with sensible defaults */
|
|
541
|
+
tokenCreationConfig: Partial<TokenConfigForVersion<T>> & {
|
|
542
|
+
tokenURI: string;
|
|
543
|
+
};
|
|
544
|
+
/** Premint config version to use, defaults to V2 */
|
|
545
|
+
premintConfigVersion?: T;
|
|
546
|
+
/** uid the UID to use – optional and retrieved as a fresh UID from ZORA by default. */
|
|
547
|
+
uid?: number;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
async function createPremint<T extends PremintConfigVersion>({
|
|
551
|
+
payoutRecipient: creatorAccount,
|
|
552
|
+
collection,
|
|
553
|
+
tokenCreationConfig,
|
|
554
|
+
premintConfigVersion,
|
|
555
|
+
uid,
|
|
556
|
+
publicClient,
|
|
557
|
+
apiClient,
|
|
558
|
+
chainId,
|
|
559
|
+
}: CreatePremintParameters<T> & PremintContext) {
|
|
560
|
+
const {
|
|
561
|
+
premintConfig,
|
|
562
|
+
premintConfigVersion: actualVersion,
|
|
563
|
+
collectionAddress,
|
|
564
|
+
} = await prepareCreatePremintConfig<T>({
|
|
565
|
+
payoutRecipient: creatorAccount,
|
|
566
|
+
collection,
|
|
567
|
+
tokenCreationConfig,
|
|
568
|
+
premintConfigVersion,
|
|
569
|
+
uid,
|
|
570
|
+
publicClient,
|
|
571
|
+
apiClient,
|
|
572
|
+
chainId,
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
return makePremintReturn({
|
|
576
|
+
premintConfig,
|
|
577
|
+
premintConfigVersion: actualVersion,
|
|
578
|
+
collectionAddress,
|
|
579
|
+
collection,
|
|
580
|
+
publicClient,
|
|
581
|
+
apiClient,
|
|
582
|
+
chainId,
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
async function prepareCreatePremintConfig<T extends PremintConfigVersion>({
|
|
587
|
+
payoutRecipient,
|
|
588
|
+
collection,
|
|
589
|
+
tokenCreationConfig,
|
|
590
|
+
premintConfigVersion,
|
|
591
|
+
uid,
|
|
592
|
+
publicClient,
|
|
593
|
+
apiClient,
|
|
594
|
+
chainId,
|
|
595
|
+
}: {
|
|
596
|
+
payoutRecipient: Address | Account;
|
|
597
|
+
collection: Omit<ContractCreationConfig, "additionalAdmins"> & {
|
|
598
|
+
additionalAdmins?: Address[];
|
|
599
|
+
};
|
|
600
|
+
tokenCreationConfig: Partial<TokenConfigForVersion<T>> & {
|
|
601
|
+
tokenURI: string;
|
|
602
|
+
};
|
|
603
|
+
premintConfigVersion?: T;
|
|
604
|
+
uid?: number;
|
|
605
|
+
} & PremintContext) {
|
|
606
|
+
const collectionWithAdditionalAdmins: ContractCreationConfig = {
|
|
607
|
+
...collection,
|
|
608
|
+
additionalAdmins: collection.additionalAdmins || [],
|
|
609
|
+
};
|
|
610
|
+
const newContractAddress = await getPremintCollectionAddress({
|
|
611
|
+
publicClient,
|
|
612
|
+
collection: collectionWithAdditionalAdmins,
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
let uidToUse = uid;
|
|
616
|
+
|
|
617
|
+
if (typeof uidToUse !== "number") {
|
|
618
|
+
uidToUse = await apiClient.getNextUID(newContractAddress);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
const actualVersion = premintConfigVersion || PremintConfigVersion.V1;
|
|
622
|
+
|
|
623
|
+
if (
|
|
624
|
+
!(await supportsPremintVersion({
|
|
625
|
+
version: actualVersion,
|
|
626
|
+
publicClient,
|
|
627
|
+
tokenContract: newContractAddress,
|
|
628
|
+
}))
|
|
629
|
+
) {
|
|
630
|
+
throw new Error(
|
|
631
|
+
`Premint version ${actualVersion} not supported by contract`,
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
const premintConfig = makeNewPremint({
|
|
636
|
+
tokenConfig: makeTokenConfigWithDefaults({
|
|
637
|
+
// @ts-ignore
|
|
638
|
+
premintConfigVersion: actualVersion,
|
|
639
|
+
tokenCreationConfig,
|
|
640
|
+
payoutRecipient:
|
|
641
|
+
typeof payoutRecipient === "string"
|
|
642
|
+
? payoutRecipient
|
|
643
|
+
: payoutRecipient.address,
|
|
644
|
+
chainId,
|
|
645
|
+
}),
|
|
646
|
+
uid: uidToUse,
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
return {
|
|
650
|
+
premintConfig,
|
|
651
|
+
premintConfigVersion: actualVersion,
|
|
652
|
+
collectionAddress: newContractAddress,
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** UPDATE */
|
|
657
|
+
|
|
658
|
+
export type UpdatePremintParams = {
|
|
659
|
+
/** uid of the Premint to update */
|
|
660
|
+
uid: number;
|
|
661
|
+
/** address of the Premint to update */
|
|
662
|
+
collection: Address;
|
|
663
|
+
/** update to apply to the Premint */
|
|
664
|
+
tokenConfigUpdates: Partial<TokenCreationConfig>;
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
async function updatePremint({
|
|
668
|
+
uid,
|
|
669
|
+
collection,
|
|
670
|
+
tokenConfigUpdates,
|
|
671
|
+
apiClient,
|
|
672
|
+
publicClient,
|
|
673
|
+
chainId,
|
|
674
|
+
}: UpdatePremintParams & {
|
|
675
|
+
apiClient: PremintAPIClient;
|
|
676
|
+
publicClient: PublicClient;
|
|
677
|
+
chainId: number;
|
|
611
678
|
}) {
|
|
612
|
-
|
|
679
|
+
const {
|
|
680
|
+
premintConfig,
|
|
681
|
+
collection: collectionCreationConfig,
|
|
682
|
+
premintConfigVersion,
|
|
683
|
+
} = await apiClient.getSignature({
|
|
684
|
+
collectionAddress: collection,
|
|
685
|
+
uid: uid,
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
const updatedPremint = applyUpdateToPremint({
|
|
689
|
+
uid: premintConfig.uid,
|
|
690
|
+
version: premintConfig.version,
|
|
691
|
+
tokenConfig: premintConfig.tokenConfig,
|
|
692
|
+
tokenConfigUpdates: tokenConfigUpdates,
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
return makePremintReturn({
|
|
696
|
+
premintConfig: updatedPremint,
|
|
697
|
+
premintConfigVersion,
|
|
698
|
+
collectionAddress: collection,
|
|
699
|
+
collection: collectionCreationConfig,
|
|
700
|
+
publicClient,
|
|
701
|
+
apiClient,
|
|
702
|
+
chainId,
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/** DELETE */
|
|
707
|
+
|
|
708
|
+
export type DeletePremintParams = {
|
|
709
|
+
/** id of the premint to delete */
|
|
710
|
+
uid: number;
|
|
711
|
+
/** collection address of the Premint to delete */
|
|
712
|
+
collection: Address;
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
async function deletePremint({
|
|
716
|
+
uid,
|
|
717
|
+
collection,
|
|
718
|
+
publicClient,
|
|
719
|
+
apiClient,
|
|
720
|
+
chainId,
|
|
721
|
+
}: DeletePremintParams & {
|
|
722
|
+
apiClient: PremintAPIClient;
|
|
723
|
+
publicClient: PublicClient;
|
|
724
|
+
chainId: number;
|
|
725
|
+
}) {
|
|
726
|
+
const {
|
|
727
|
+
premintConfig,
|
|
728
|
+
premintConfigVersion,
|
|
729
|
+
collection: collectionCreationConfig,
|
|
730
|
+
} = await apiClient.getSignature({
|
|
731
|
+
collectionAddress: collection,
|
|
732
|
+
uid: uid,
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
const deletedPremint = {
|
|
736
|
+
...premintConfig,
|
|
737
|
+
version: premintConfig.version + 1,
|
|
738
|
+
deleted: true,
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
return makePremintReturn({
|
|
742
|
+
premintConfig: deletedPremint,
|
|
743
|
+
premintConfigVersion,
|
|
744
|
+
collectionAddress: collection,
|
|
745
|
+
collection: collectionCreationConfig,
|
|
746
|
+
publicClient,
|
|
747
|
+
apiClient,
|
|
748
|
+
chainId,
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
export type MakeMintParametersArguments = {
|
|
753
|
+
/** uid of the Premint to mint */
|
|
754
|
+
uid: number;
|
|
755
|
+
/** Premint contract address */
|
|
756
|
+
tokenContract: Address;
|
|
757
|
+
/** Account to execute the mint */
|
|
758
|
+
minterAccount: Account | Address;
|
|
759
|
+
/** Minting settings */
|
|
760
|
+
mintArguments?: {
|
|
761
|
+
/** Quantity of tokens to mint */
|
|
762
|
+
quantityToMint: number;
|
|
763
|
+
/** Comment to add to the mint */
|
|
764
|
+
mintComment?: string;
|
|
765
|
+
/** Address to receive the mint referral reward */
|
|
766
|
+
mintReferral?: Address;
|
|
767
|
+
/** Address to receive the minted tokens */
|
|
768
|
+
mintRecipient?: Address;
|
|
769
|
+
};
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
/** ======== MINTING ======== */
|
|
773
|
+
|
|
774
|
+
async function makeMintParameters({
|
|
775
|
+
uid,
|
|
776
|
+
tokenContract,
|
|
777
|
+
minterAccount,
|
|
778
|
+
mintArguments,
|
|
779
|
+
apiClient,
|
|
780
|
+
publicClient,
|
|
781
|
+
}: MakeMintParametersArguments & {
|
|
782
|
+
apiClient: PremintAPIClient;
|
|
783
|
+
publicClient: PublicClient;
|
|
784
|
+
}): Promise<
|
|
785
|
+
SimulateContractParameters<
|
|
786
|
+
typeof zoraCreator1155PremintExecutorImplABI,
|
|
787
|
+
"premintV1" | "premintV2",
|
|
788
|
+
any,
|
|
789
|
+
any,
|
|
790
|
+
any,
|
|
791
|
+
Account | Address
|
|
792
|
+
>
|
|
793
|
+
> {
|
|
794
|
+
if (mintArguments && mintArguments?.quantityToMint < 1) {
|
|
795
|
+
throw new Error("Quantity to mint cannot be below 1");
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if (!minterAccount) {
|
|
799
|
+
throw new Error("Wallet not passed in");
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
const { premintConfig, premintConfigVersion, collection, signature } =
|
|
803
|
+
await apiClient.getSignature({
|
|
804
|
+
collectionAddress: tokenContract,
|
|
805
|
+
uid,
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
|
|
809
|
+
|
|
810
|
+
if (premintConfigVersion === PremintConfigVersion.V3) {
|
|
811
|
+
throw new Error("PremintV3 not supported in premint SDK");
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
const value = (
|
|
815
|
+
await getPremintMintCosts({
|
|
816
|
+
tokenContract,
|
|
817
|
+
quantityToMint: numberToMint,
|
|
818
|
+
publicClient,
|
|
819
|
+
tokenPrice: premintConfig.tokenConfig.pricePerToken,
|
|
820
|
+
})
|
|
821
|
+
).totalCost;
|
|
822
|
+
|
|
823
|
+
const mintArgumentsContract: PremintMintArguments = {
|
|
824
|
+
mintComment: mintArguments?.mintComment || "",
|
|
825
|
+
mintRecipient:
|
|
826
|
+
mintArguments?.mintRecipient ||
|
|
827
|
+
(typeof minterAccount === "string"
|
|
828
|
+
? minterAccount
|
|
829
|
+
: minterAccount.address),
|
|
830
|
+
mintRewardsRecipients: makeMintRewardsRecipient({
|
|
831
|
+
mintReferral: mintArguments?.mintReferral,
|
|
832
|
+
}),
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
if (premintConfigVersion === PremintConfigVersion.V1) {
|
|
836
|
+
return makeSimulateContractParamaters({
|
|
837
|
+
account: minterAccount,
|
|
838
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
839
|
+
functionName: "premintV1",
|
|
840
|
+
value,
|
|
841
|
+
address: getPremintExecutorAddress(),
|
|
842
|
+
args: [
|
|
843
|
+
collection,
|
|
844
|
+
premintConfig,
|
|
845
|
+
signature,
|
|
846
|
+
numberToMint,
|
|
847
|
+
mintArgumentsContract,
|
|
848
|
+
],
|
|
849
|
+
});
|
|
850
|
+
} else if (premintConfigVersion === PremintConfigVersion.V2) {
|
|
851
|
+
return makeSimulateContractParamaters({
|
|
852
|
+
account: minterAccount,
|
|
853
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
854
|
+
functionName: "premintV2",
|
|
855
|
+
value,
|
|
856
|
+
address: getPremintExecutorAddress(),
|
|
857
|
+
args: [
|
|
858
|
+
collection,
|
|
859
|
+
premintConfig,
|
|
860
|
+
signature,
|
|
861
|
+
numberToMint,
|
|
862
|
+
mintArgumentsContract,
|
|
863
|
+
],
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
613
868
|
}
|
|
614
869
|
|
|
615
|
-
function makeUrls({
|
|
870
|
+
export function makeUrls({
|
|
616
871
|
uid,
|
|
617
872
|
address,
|
|
618
873
|
tokenId,
|
|
@@ -647,66 +902,3 @@ function makeUrls({
|
|
|
647
902
|
}:${address}/${zoraTokenPath}`,
|
|
648
903
|
};
|
|
649
904
|
}
|
|
650
|
-
|
|
651
|
-
type SignAndSubmitPremintParams<T extends PremintConfigVersion> = {
|
|
652
|
-
walletClient: WalletClient;
|
|
653
|
-
verifyingContract: Address;
|
|
654
|
-
checkSignature: boolean;
|
|
655
|
-
account?: Address | Account;
|
|
656
|
-
collection: ContractCreationConfig;
|
|
657
|
-
} & PremintConfigWithVersion<T>;
|
|
658
|
-
|
|
659
|
-
async function signAndSubmitPremint<T extends PremintConfigVersion>({
|
|
660
|
-
walletClient,
|
|
661
|
-
verifyingContract,
|
|
662
|
-
account,
|
|
663
|
-
checkSignature,
|
|
664
|
-
collection,
|
|
665
|
-
chainId,
|
|
666
|
-
publicClient,
|
|
667
|
-
apiClient,
|
|
668
|
-
...premintConfigAndVersion
|
|
669
|
-
}: SignAndSubmitPremintParams<T> & {
|
|
670
|
-
chainId: number;
|
|
671
|
-
publicClient: PublicClient;
|
|
672
|
-
apiClient: PremintAPIClient;
|
|
673
|
-
}) {
|
|
674
|
-
if (!account) {
|
|
675
|
-
account = walletClient.account;
|
|
676
|
-
}
|
|
677
|
-
if (!account) {
|
|
678
|
-
throw new Error("No account provided");
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
const signature = await walletClient.signTypedData({
|
|
682
|
-
account,
|
|
683
|
-
...premintTypedDataDefinition({
|
|
684
|
-
verifyingContract,
|
|
685
|
-
...premintConfigAndVersion,
|
|
686
|
-
chainId,
|
|
687
|
-
}),
|
|
688
|
-
});
|
|
689
|
-
|
|
690
|
-
if (checkSignature) {
|
|
691
|
-
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
692
|
-
collection,
|
|
693
|
-
publicClient,
|
|
694
|
-
signer: typeof account === "string" ? account : account.address,
|
|
695
|
-
collectionAddress: await getPremintCollectionAddress({
|
|
696
|
-
collection,
|
|
697
|
-
publicClient,
|
|
698
|
-
}),
|
|
699
|
-
});
|
|
700
|
-
if (!isAuthorized) {
|
|
701
|
-
throw new Error("Not authorized to create premint");
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
const premint = await apiClient.postSignature({
|
|
706
|
-
collection: collection,
|
|
707
|
-
signature: signature,
|
|
708
|
-
...premintConfigAndVersion,
|
|
709
|
-
});
|
|
710
|
-
|
|
711
|
-
return { premint, verifyingContract };
|
|
712
|
-
}
|