@zoralabs/protocol-sdk 0.2.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.
- package/.turbo/turbo-build.log +15 -0
- package/CHANGELOG.md +47 -0
- package/README.md +163 -0
- package/dist/anvil.d.ts +16 -0
- package/dist/anvil.d.ts.map +1 -0
- package/dist/apis/chain-constants.d.ts +21 -0
- package/dist/apis/chain-constants.d.ts.map +1 -0
- package/dist/apis/client-base.d.ts +15 -0
- package/dist/apis/client-base.d.ts.map +1 -0
- package/dist/apis/generated/discover-api-types.d.ts +2131 -0
- package/dist/apis/generated/discover-api-types.d.ts.map +1 -0
- package/dist/apis/generated/premint-api-types.d.ts +356 -0
- package/dist/apis/generated/premint-api-types.d.ts.map +1 -0
- package/dist/apis/http-api-base.d.ts +26 -0
- package/dist/apis/http-api-base.d.ts.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/create/1155-create-helper.d.ts +63 -0
- package/dist/create/1155-create-helper.d.ts.map +1 -0
- package/dist/create/1155-create-helper.test.d.ts +2 -0
- package/dist/create/1155-create-helper.test.d.ts.map +1 -0
- package/dist/index.cjs +1006 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +984 -0
- package/dist/index.js.map +1 -0
- package/dist/mint/mint-api-client.d.ts +20 -0
- package/dist/mint/mint-api-client.d.ts.map +1 -0
- package/dist/mint/mint-client.d.ts +237 -0
- package/dist/mint/mint-client.d.ts.map +1 -0
- package/dist/mint/mint-client.test.d.ts +2 -0
- package/dist/mint/mint-client.test.d.ts.map +1 -0
- package/dist/premint/premint-api-client.d.ts +19 -0
- package/dist/premint/premint-api-client.d.ts.map +1 -0
- package/dist/premint/premint-client.d.ts +320 -0
- package/dist/premint/premint-client.d.ts.map +1 -0
- package/dist/premint/premint-client.test.d.ts +2 -0
- package/dist/premint/premint-client.test.d.ts.map +1 -0
- package/dist/premint/preminter.d.ts +25 -0
- package/dist/premint/preminter.d.ts.map +1 -0
- package/dist/premint/preminter.test.d.ts +2 -0
- package/dist/premint/preminter.test.d.ts.map +1 -0
- package/dist/preminter.d.ts +25 -0
- package/dist/preminter.d.ts.map +1 -0
- package/dist/preminter.test.d.ts +451 -0
- package/dist/preminter.test.d.ts.map +1 -0
- package/package.json +28 -0
- package/src/anvil.ts +84 -0
- package/src/apis/chain-constants.ts +101 -0
- package/src/apis/client-base.ts +29 -0
- package/src/apis/generated/discover-api-types.ts +2138 -0
- package/src/apis/generated/premint-api-types.ts +363 -0
- package/src/apis/http-api-base.ts +93 -0
- package/src/constants.ts +10 -0
- package/src/create/1155-create-helper.test.ts +90 -0
- package/src/create/1155-create-helper.ts +342 -0
- package/src/index.ts +9 -0
- package/src/mint/mint-api-client.ts +52 -0
- package/src/mint/mint-client.test.ts +117 -0
- package/src/mint/mint-client.ts +218 -0
- package/src/premint/premint-api-client.ts +57 -0
- package/src/premint/premint-client.test.ts +196 -0
- package/src/premint/premint-client.ts +619 -0
- package/src/premint/preminter.test.ts +502 -0
- package/src/premint/preminter.ts +72 -0
- package/src/preminter.test.ts +510 -0
- package/src/preminter.ts +72 -0
- package/tsconfig.json +25 -0
- package/tsup.config.js +10 -0
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
import { decodeEventLog } from "viem";
|
|
2
|
+
import type {
|
|
3
|
+
Account,
|
|
4
|
+
Address,
|
|
5
|
+
Chain,
|
|
6
|
+
Hex,
|
|
7
|
+
PublicClient,
|
|
8
|
+
TransactionReceipt,
|
|
9
|
+
WalletClient,
|
|
10
|
+
} from "viem";
|
|
11
|
+
import {
|
|
12
|
+
zoraCreator1155PremintExecutorImplABI,
|
|
13
|
+
zoraCreator1155PremintExecutorImplAddress,
|
|
14
|
+
zoraCreatorFixedPriceSaleStrategyAddress,
|
|
15
|
+
} from "@zoralabs/protocol-deployments";
|
|
16
|
+
import { PremintConfig, preminterTypedDataDefinition } from "./preminter";
|
|
17
|
+
import type {
|
|
18
|
+
PremintSignatureGetResponse,
|
|
19
|
+
PremintSignatureResponse,
|
|
20
|
+
} from "./premint-api-client";
|
|
21
|
+
import { PremintAPIClient } from "./premint-api-client";
|
|
22
|
+
import type { DecodeEventLogReturnType } from "viem";
|
|
23
|
+
import { ClientBase } from "../apis/client-base";
|
|
24
|
+
import { OPEN_EDITION_MINT_SIZE } from "../constants";
|
|
25
|
+
import { REWARD_PER_TOKEN } from "src/apis/chain-constants";
|
|
26
|
+
|
|
27
|
+
type MintArgumentsSettings = {
|
|
28
|
+
tokenURI: string;
|
|
29
|
+
maxSupply?: bigint;
|
|
30
|
+
maxTokensPerAddress?: bigint;
|
|
31
|
+
pricePerToken?: bigint;
|
|
32
|
+
mintStart?: bigint;
|
|
33
|
+
mintDuration?: bigint;
|
|
34
|
+
royaltyMintSchedule?: number;
|
|
35
|
+
royaltyBPS?: number;
|
|
36
|
+
royaltyRecipient?: Address;
|
|
37
|
+
fixedPriceMinter?: Address;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type PremintedLogType = DecodeEventLogReturnType<
|
|
41
|
+
typeof zoraCreator1155PremintExecutorImplABI,
|
|
42
|
+
"Preminted"
|
|
43
|
+
>["args"];
|
|
44
|
+
|
|
45
|
+
type URLSReturnType = {
|
|
46
|
+
explorer: null | string;
|
|
47
|
+
zoraCollect: null | string;
|
|
48
|
+
zoraManage: null | string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type SignedPremintResponse = {
|
|
52
|
+
urls: URLSReturnType;
|
|
53
|
+
uid: number;
|
|
54
|
+
verifyingContract: Address;
|
|
55
|
+
premint: PremintSignatureResponse;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type ExecutedPremintResponse = {
|
|
59
|
+
receipt: TransactionReceipt;
|
|
60
|
+
premintedLog?: PremintedLogType;
|
|
61
|
+
urls: URLSReturnType;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const DefaultMintArguments = {
|
|
65
|
+
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
66
|
+
maxTokensPerAddress: 0n,
|
|
67
|
+
pricePerToken: 0n,
|
|
68
|
+
mintDuration: BigInt(60 * 60 * 24 * 7), // 1 week
|
|
69
|
+
mintStart: 0n,
|
|
70
|
+
royaltyMintSchedule: 0,
|
|
71
|
+
royaltyBPS: 1000, // 10%,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Gets the preminted log from receipt
|
|
76
|
+
*
|
|
77
|
+
* @param receipt Preminted log from receipt
|
|
78
|
+
* @returns Premint event arguments
|
|
79
|
+
*/
|
|
80
|
+
export function getPremintedLogFromReceipt(
|
|
81
|
+
receipt: TransactionReceipt,
|
|
82
|
+
): PremintedLogType | undefined {
|
|
83
|
+
for (const data of receipt.logs) {
|
|
84
|
+
try {
|
|
85
|
+
const decodedLog = decodeEventLog({
|
|
86
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
87
|
+
eventName: "Preminted",
|
|
88
|
+
...data,
|
|
89
|
+
});
|
|
90
|
+
if (decodedLog.eventName === "Preminted") {
|
|
91
|
+
return decodedLog.args;
|
|
92
|
+
}
|
|
93
|
+
} catch (err: any) {}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Convert server to on-chain types for a premint
|
|
99
|
+
*
|
|
100
|
+
* @param premint Premint object from the server to convert to one that's compatible with viem
|
|
101
|
+
* @returns Viem type-compatible premint object
|
|
102
|
+
*/
|
|
103
|
+
export const convertPremint = (
|
|
104
|
+
premint: PremintSignatureGetResponse["premint"],
|
|
105
|
+
) => ({
|
|
106
|
+
...premint,
|
|
107
|
+
tokenConfig: {
|
|
108
|
+
...premint.tokenConfig,
|
|
109
|
+
fixedPriceMinter: premint.tokenConfig.fixedPriceMinter as Address,
|
|
110
|
+
royaltyRecipient: premint.tokenConfig.royaltyRecipient as Address,
|
|
111
|
+
maxSupply: BigInt(premint.tokenConfig.maxSupply),
|
|
112
|
+
pricePerToken: BigInt(premint.tokenConfig.pricePerToken),
|
|
113
|
+
mintStart: BigInt(premint.tokenConfig.mintStart),
|
|
114
|
+
mintDuration: BigInt(premint.tokenConfig.mintDuration),
|
|
115
|
+
maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress),
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
export const convertCollection = (
|
|
120
|
+
collection: PremintSignatureGetResponse["collection"],
|
|
121
|
+
) => ({
|
|
122
|
+
...collection,
|
|
123
|
+
contractAdmin: collection.contractAdmin as Address,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Convert on-chain types for a premint to a server safe type
|
|
128
|
+
*
|
|
129
|
+
* @param premint Premint object from viem to convert to a JSON compatible type.
|
|
130
|
+
* @returns JSON compatible premint
|
|
131
|
+
*/
|
|
132
|
+
export const encodePremintForAPI = ({
|
|
133
|
+
tokenConfig,
|
|
134
|
+
...premint
|
|
135
|
+
}: PremintConfig) => ({
|
|
136
|
+
...premint,
|
|
137
|
+
tokenConfig: {
|
|
138
|
+
...tokenConfig,
|
|
139
|
+
maxSupply: tokenConfig.maxSupply.toString(),
|
|
140
|
+
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
141
|
+
mintStart: tokenConfig.mintStart.toString(),
|
|
142
|
+
mintDuration: tokenConfig.mintDuration.toString(),
|
|
143
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString(),
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Preminter API to access ZORA Premint functionality.
|
|
149
|
+
* Currently only supports V1 premints.
|
|
150
|
+
*/
|
|
151
|
+
export class PremintClient extends ClientBase {
|
|
152
|
+
apiClient: typeof PremintAPIClient;
|
|
153
|
+
|
|
154
|
+
constructor(chain: Chain, apiClient?: typeof PremintAPIClient) {
|
|
155
|
+
super(chain);
|
|
156
|
+
|
|
157
|
+
if (!apiClient) {
|
|
158
|
+
apiClient = PremintAPIClient;
|
|
159
|
+
}
|
|
160
|
+
this.apiClient = apiClient;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The premint executor address is deployed to the same address across all chains.
|
|
165
|
+
* Can be overridden as needed by making a parent class.
|
|
166
|
+
*
|
|
167
|
+
* @returns Executor address for premints
|
|
168
|
+
*/
|
|
169
|
+
getExecutorAddress() {
|
|
170
|
+
return zoraCreator1155PremintExecutorImplAddress[999];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The fixed price minter address is the same across all chains for our current
|
|
175
|
+
* deployer strategy.
|
|
176
|
+
* Can be overridden as needed by making a parent class.
|
|
177
|
+
*
|
|
178
|
+
* @returns Fixed price sale strategy
|
|
179
|
+
*/
|
|
180
|
+
getFixedPriceMinterAddress() {
|
|
181
|
+
return zoraCreatorFixedPriceSaleStrategyAddress[999];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Update existing premint given collection address and UID of existing premint.
|
|
186
|
+
*
|
|
187
|
+
* 1. Loads existing premint token
|
|
188
|
+
* 2. Updates with settings passed into function
|
|
189
|
+
* 3. Increments the version field
|
|
190
|
+
* 4. Re-signs the premint
|
|
191
|
+
* 5. Uploads the premint to the ZORA API
|
|
192
|
+
*
|
|
193
|
+
* Updates existing premint
|
|
194
|
+
* @param settings Settings for the new premint
|
|
195
|
+
* @param settings.account Account to sign the premint update from. Taken from walletClient if none passed in.
|
|
196
|
+
* @param settings.collection Collection information for the mint
|
|
197
|
+
* @param settings.walletClient viem wallet client to use to sign
|
|
198
|
+
* @param settings.uid UID
|
|
199
|
+
* @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
|
|
200
|
+
*
|
|
201
|
+
*/
|
|
202
|
+
async updatePremint({
|
|
203
|
+
walletClient,
|
|
204
|
+
uid,
|
|
205
|
+
collection,
|
|
206
|
+
token,
|
|
207
|
+
account,
|
|
208
|
+
}: {
|
|
209
|
+
walletClient: WalletClient;
|
|
210
|
+
uid: number;
|
|
211
|
+
token: MintArgumentsSettings;
|
|
212
|
+
account?: Account | Address;
|
|
213
|
+
collection: Address;
|
|
214
|
+
}): Promise<SignedPremintResponse> {
|
|
215
|
+
const signatureResponse = await this.apiClient.getSignature({
|
|
216
|
+
chain_name: this.network.zoraBackendChainName,
|
|
217
|
+
collection_address: collection.toLowerCase(),
|
|
218
|
+
uid: uid,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const convertedPremint = convertPremint(signatureResponse.premint);
|
|
222
|
+
const signerData = {
|
|
223
|
+
...signatureResponse,
|
|
224
|
+
premint: {
|
|
225
|
+
...convertedPremint,
|
|
226
|
+
tokenConfig: {
|
|
227
|
+
...convertedPremint.tokenConfig,
|
|
228
|
+
...token,
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
return await this.signAndSubmitPremint({
|
|
234
|
+
walletClient,
|
|
235
|
+
account,
|
|
236
|
+
checkSignature: false,
|
|
237
|
+
verifyingContract: collection,
|
|
238
|
+
publicClient: this.getPublicClient(),
|
|
239
|
+
uid: uid,
|
|
240
|
+
collection: {
|
|
241
|
+
...signerData.collection,
|
|
242
|
+
contractAdmin: signerData.collection.contractAdmin as Address,
|
|
243
|
+
},
|
|
244
|
+
premintConfig: signerData.premint,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Delete premint.
|
|
250
|
+
*
|
|
251
|
+
* 1. Loads current premint from collection address with UID
|
|
252
|
+
* 2. Increments version and marks as deleted
|
|
253
|
+
* 3. Signs new premint version
|
|
254
|
+
* 4. Sends to ZORA Premint API
|
|
255
|
+
*
|
|
256
|
+
* Deletes existing premint
|
|
257
|
+
* @param settings.collection collection address
|
|
258
|
+
* @param settings.uid UID
|
|
259
|
+
* @param settings.walletClient viem wallet client to use to sign
|
|
260
|
+
*
|
|
261
|
+
*/
|
|
262
|
+
async deletePremint({
|
|
263
|
+
walletClient,
|
|
264
|
+
uid,
|
|
265
|
+
account,
|
|
266
|
+
collection,
|
|
267
|
+
publicClient,
|
|
268
|
+
}: {
|
|
269
|
+
walletClient: WalletClient;
|
|
270
|
+
publicClient: PublicClient;
|
|
271
|
+
uid: number;
|
|
272
|
+
account?: Account | Address;
|
|
273
|
+
collection: Address;
|
|
274
|
+
}) {
|
|
275
|
+
const signatureResponse = await this.apiClient.getSignature({
|
|
276
|
+
chain_name: this.network.zoraBackendChainName,
|
|
277
|
+
collection_address: collection.toLowerCase(),
|
|
278
|
+
uid: uid,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
const signerData = {
|
|
282
|
+
...signatureResponse,
|
|
283
|
+
collection: convertCollection(signatureResponse.collection),
|
|
284
|
+
premint: {
|
|
285
|
+
...convertPremint(signatureResponse.premint),
|
|
286
|
+
deleted: true,
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
return await this.signAndSubmitPremint({
|
|
291
|
+
walletClient,
|
|
292
|
+
account,
|
|
293
|
+
checkSignature: false,
|
|
294
|
+
verifyingContract: collection,
|
|
295
|
+
publicClient: this.getPublicClient(publicClient),
|
|
296
|
+
uid: uid,
|
|
297
|
+
collection: signerData.collection,
|
|
298
|
+
premintConfig: signerData.premint,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Internal function to sign and submit a premint request.
|
|
304
|
+
*
|
|
305
|
+
* @param premintArguments Arguments to premint
|
|
306
|
+
* @returns
|
|
307
|
+
*/
|
|
308
|
+
private async signAndSubmitPremint({
|
|
309
|
+
walletClient,
|
|
310
|
+
publicClient,
|
|
311
|
+
verifyingContract,
|
|
312
|
+
premintConfig,
|
|
313
|
+
uid,
|
|
314
|
+
account,
|
|
315
|
+
checkSignature,
|
|
316
|
+
collection,
|
|
317
|
+
}: {
|
|
318
|
+
publicClient: PublicClient;
|
|
319
|
+
uid: number;
|
|
320
|
+
walletClient: WalletClient;
|
|
321
|
+
verifyingContract: Address;
|
|
322
|
+
checkSignature: boolean;
|
|
323
|
+
account?: Address | Account;
|
|
324
|
+
premintConfig: PremintConfig;
|
|
325
|
+
collection: PremintSignatureGetResponse["collection"];
|
|
326
|
+
}) {
|
|
327
|
+
if (!account) {
|
|
328
|
+
account = walletClient.account;
|
|
329
|
+
}
|
|
330
|
+
if (!account) {
|
|
331
|
+
throw new Error("No account provided");
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const signature = await walletClient.signTypedData({
|
|
335
|
+
account,
|
|
336
|
+
...preminterTypedDataDefinition({
|
|
337
|
+
verifyingContract,
|
|
338
|
+
premintConfig,
|
|
339
|
+
chainId: this.chain.id,
|
|
340
|
+
}),
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
if (checkSignature) {
|
|
344
|
+
const [isValidSignature] = await publicClient.readContract({
|
|
345
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
346
|
+
address: this.getExecutorAddress(),
|
|
347
|
+
functionName: "isValidSignature",
|
|
348
|
+
args: [convertCollection(collection), premintConfig, signature],
|
|
349
|
+
});
|
|
350
|
+
if (!isValidSignature) {
|
|
351
|
+
throw new Error("Invalid signature");
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const apiData = {
|
|
356
|
+
collection,
|
|
357
|
+
premint: encodePremintForAPI(premintConfig),
|
|
358
|
+
chain_name: this.network.zoraBackendChainName,
|
|
359
|
+
signature: signature,
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const premint = await this.apiClient.postSignature(apiData);
|
|
363
|
+
|
|
364
|
+
return {
|
|
365
|
+
urls: this.makeUrls({ address: verifyingContract, uid }),
|
|
366
|
+
uid,
|
|
367
|
+
verifyingContract,
|
|
368
|
+
premint,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Create premint
|
|
374
|
+
*
|
|
375
|
+
* @param settings Settings for the new premint
|
|
376
|
+
* @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
|
|
377
|
+
* @param settings.collection Collection information for the mint
|
|
378
|
+
* @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
|
|
379
|
+
* @param settings.publicClient Public client (optional) – instantiated if not passed in with defaults.
|
|
380
|
+
* @param settings.walletClient Required wallet client for signing the premint message.
|
|
381
|
+
* @param settings.executionSettings Execution settings for premint options
|
|
382
|
+
* @param settings.executionSettings.deleted If this UID should be deleted. If omitted, set to false.
|
|
383
|
+
* @param settings.executionSettings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
|
|
384
|
+
* @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
|
|
385
|
+
* @returns premint url, uid, newContractAddress, and premint object
|
|
386
|
+
*/
|
|
387
|
+
async createPremint({
|
|
388
|
+
account,
|
|
389
|
+
collection,
|
|
390
|
+
token,
|
|
391
|
+
publicClient,
|
|
392
|
+
walletClient,
|
|
393
|
+
executionSettings,
|
|
394
|
+
checkSignature = false,
|
|
395
|
+
}: {
|
|
396
|
+
account: Address;
|
|
397
|
+
checkSignature?: boolean;
|
|
398
|
+
walletClient: WalletClient;
|
|
399
|
+
collection: PremintSignatureGetResponse["collection"];
|
|
400
|
+
token: MintArgumentsSettings;
|
|
401
|
+
publicClient?: PublicClient;
|
|
402
|
+
executionSettings?: {
|
|
403
|
+
deleted?: boolean;
|
|
404
|
+
uid?: number;
|
|
405
|
+
};
|
|
406
|
+
}) {
|
|
407
|
+
publicClient = this.getPublicClient(publicClient);
|
|
408
|
+
|
|
409
|
+
const newContractAddress = await publicClient.readContract({
|
|
410
|
+
address: this.getExecutorAddress(),
|
|
411
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
412
|
+
functionName: "getContractAddress",
|
|
413
|
+
args: [convertCollection(collection)],
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
const tokenConfig = {
|
|
417
|
+
...DefaultMintArguments,
|
|
418
|
+
fixedPriceMinter: this.getFixedPriceMinterAddress(),
|
|
419
|
+
royaltyRecipient: account,
|
|
420
|
+
...token,
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
let uid = executionSettings?.uid;
|
|
424
|
+
if (!uid) {
|
|
425
|
+
const uidResponse = await this.apiClient.getNextUID({
|
|
426
|
+
chain_name: this.network.zoraBackendChainName,
|
|
427
|
+
collection_address: newContractAddress.toLowerCase(),
|
|
428
|
+
});
|
|
429
|
+
uid = uidResponse.next_uid;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (!uid) {
|
|
433
|
+
throw new Error("UID is missing but required");
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
let deleted = executionSettings?.deleted || false;
|
|
437
|
+
|
|
438
|
+
const premintConfig = {
|
|
439
|
+
tokenConfig: tokenConfig,
|
|
440
|
+
uid,
|
|
441
|
+
version: 1,
|
|
442
|
+
deleted,
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
return await this.signAndSubmitPremint({
|
|
446
|
+
uid,
|
|
447
|
+
verifyingContract: newContractAddress,
|
|
448
|
+
premintConfig,
|
|
449
|
+
checkSignature,
|
|
450
|
+
account,
|
|
451
|
+
publicClient,
|
|
452
|
+
walletClient,
|
|
453
|
+
collection,
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Fetches given premint data from the ZORA API.
|
|
459
|
+
*
|
|
460
|
+
* @param address Address for the premint contract
|
|
461
|
+
* @param uid UID for the desired premint
|
|
462
|
+
* @returns PremintSignatureGetResponse of premint data from the API
|
|
463
|
+
*/
|
|
464
|
+
async getPremintData({
|
|
465
|
+
address,
|
|
466
|
+
uid,
|
|
467
|
+
}: {
|
|
468
|
+
address: string;
|
|
469
|
+
uid: number;
|
|
470
|
+
}): Promise<PremintSignatureGetResponse> {
|
|
471
|
+
return await this.apiClient.getSignature({
|
|
472
|
+
chain_name: this.network.zoraBackendChainName,
|
|
473
|
+
collection_address: address,
|
|
474
|
+
uid,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Check user signature for v1
|
|
480
|
+
*
|
|
481
|
+
* @param data Signature data from the API
|
|
482
|
+
* @returns isValid = signature is valid or not, contractAddress = assumed contract address, recoveredSigner = signer from contract
|
|
483
|
+
*/
|
|
484
|
+
async isValidSignature({
|
|
485
|
+
data,
|
|
486
|
+
publicClient,
|
|
487
|
+
}: {
|
|
488
|
+
data: PremintSignatureGetResponse;
|
|
489
|
+
publicClient?: PublicClient;
|
|
490
|
+
}): Promise<{
|
|
491
|
+
isValid: boolean;
|
|
492
|
+
contractAddress: Address;
|
|
493
|
+
recoveredSigner: Address;
|
|
494
|
+
}> {
|
|
495
|
+
publicClient = this.getPublicClient(publicClient);
|
|
496
|
+
|
|
497
|
+
const [isValid, contractAddress, recoveredSigner] =
|
|
498
|
+
await publicClient.readContract({
|
|
499
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
500
|
+
address: this.getExecutorAddress(),
|
|
501
|
+
functionName: "isValidSignature",
|
|
502
|
+
args: [
|
|
503
|
+
convertCollection(data.collection),
|
|
504
|
+
convertPremint(data.premint),
|
|
505
|
+
data.signature as Hex,
|
|
506
|
+
],
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
return { isValid, contractAddress, recoveredSigner };
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
protected makeUrls({
|
|
513
|
+
uid,
|
|
514
|
+
address,
|
|
515
|
+
tokenId,
|
|
516
|
+
}: {
|
|
517
|
+
uid?: number;
|
|
518
|
+
tokenId?: bigint;
|
|
519
|
+
address?: Address;
|
|
520
|
+
}): URLSReturnType {
|
|
521
|
+
if ((!uid || !tokenId) && !address) {
|
|
522
|
+
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
526
|
+
|
|
527
|
+
return {
|
|
528
|
+
explorer: tokenId
|
|
529
|
+
? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}`
|
|
530
|
+
: null,
|
|
531
|
+
zoraCollect: `https://${
|
|
532
|
+
this.network.isTestnet ? "testnet." : ""
|
|
533
|
+
}zora.co/collect/${
|
|
534
|
+
this.network.zoraPathChainName
|
|
535
|
+
}:${address}/${zoraTokenPath}`,
|
|
536
|
+
zoraManage: `https://${
|
|
537
|
+
this.network.isTestnet ? "testnet." : ""
|
|
538
|
+
}zora.co/collect/${
|
|
539
|
+
this.network.zoraPathChainName
|
|
540
|
+
}:${address}/${zoraTokenPath}`,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Execute premint on-chain
|
|
546
|
+
*
|
|
547
|
+
* @param settings.data Data from the API for the mint
|
|
548
|
+
* @param settings.account Optional account (if omitted taken from wallet client) for the account executing the premint.
|
|
549
|
+
* @param settings.walletClient WalletClient to send execution from.
|
|
550
|
+
* @param settings.mintArguments User minting arguments.
|
|
551
|
+
* @param settings.mintArguments.quantityToMint Quantity to mint, optional, defaults to 1.
|
|
552
|
+
* @param settings.mintArguments.mintComment Optional mint comment, optional, omits when not included.
|
|
553
|
+
* @param settings.publicClient Optional public client for preflight checks.
|
|
554
|
+
* @returns receipt, log, zoraURL
|
|
555
|
+
*/
|
|
556
|
+
async executePremintWithWallet({
|
|
557
|
+
data,
|
|
558
|
+
account,
|
|
559
|
+
walletClient,
|
|
560
|
+
mintArguments,
|
|
561
|
+
publicClient,
|
|
562
|
+
}: {
|
|
563
|
+
data: PremintSignatureGetResponse;
|
|
564
|
+
walletClient: WalletClient;
|
|
565
|
+
account?: Account | Address;
|
|
566
|
+
mintArguments?: {
|
|
567
|
+
quantityToMint: number;
|
|
568
|
+
mintComment?: string;
|
|
569
|
+
};
|
|
570
|
+
publicClient?: PublicClient;
|
|
571
|
+
}): Promise<ExecutedPremintResponse> {
|
|
572
|
+
publicClient = this.getPublicClient(publicClient);
|
|
573
|
+
|
|
574
|
+
if (mintArguments && mintArguments?.quantityToMint < 1) {
|
|
575
|
+
throw new Error("Quantity to mint cannot be below 1");
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const targetAddress = this.getExecutorAddress();
|
|
579
|
+
const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
|
|
580
|
+
const args = [
|
|
581
|
+
convertCollection(data.collection),
|
|
582
|
+
convertPremint(data.premint),
|
|
583
|
+
data.signature as Hex,
|
|
584
|
+
numberToMint,
|
|
585
|
+
mintArguments?.mintComment || "",
|
|
586
|
+
] as const;
|
|
587
|
+
|
|
588
|
+
if (!account) {
|
|
589
|
+
account = walletClient.account;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (!account) {
|
|
593
|
+
throw new Error("Wallet not passed in");
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const value = numberToMint * REWARD_PER_TOKEN;
|
|
597
|
+
|
|
598
|
+
const { request } = await publicClient.simulateContract({
|
|
599
|
+
account,
|
|
600
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
601
|
+
functionName: "premint",
|
|
602
|
+
value,
|
|
603
|
+
address: targetAddress,
|
|
604
|
+
args,
|
|
605
|
+
});
|
|
606
|
+
const hash = await walletClient.writeContract(request);
|
|
607
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
608
|
+
const premintedLog = getPremintedLogFromReceipt(receipt);
|
|
609
|
+
|
|
610
|
+
return {
|
|
611
|
+
receipt,
|
|
612
|
+
premintedLog,
|
|
613
|
+
urls: this.makeUrls({
|
|
614
|
+
address: premintedLog?.contractAddress,
|
|
615
|
+
tokenId: premintedLog?.tokenId,
|
|
616
|
+
}),
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
}
|