@zoralabs/protocol-sdk 0.5.4-exports.0 → 0.5.4
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 +16 -0
- package/CHANGELOG.md +2 -3
- package/dist/anvil.d.ts +36 -0
- package/dist/anvil.d.ts.map +1 -0
- package/dist/apis/chain-constants.d.ts +13 -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/premint-api-types.d.ts +460 -0
- package/dist/apis/generated/premint-api-types.d.ts.map +1 -0
- package/dist/apis/http-api-base.d.ts +32 -0
- package/dist/apis/http-api-base.d.ts.map +1 -0
- package/dist/constants.d.ts +36 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/create/1155-create-helper.d.ts +62 -0
- package/dist/create/1155-create-helper.d.ts.map +1 -0
- package/dist/index.cjs +1694 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1664 -0
- package/dist/index.js.map +1 -0
- package/dist/mint/mint-api-client.d.ts +27 -0
- package/dist/mint/mint-api-client.d.ts.map +1 -0
- package/dist/mint/mint-client.d.ts +61 -0
- package/dist/mint/mint-client.d.ts.map +1 -0
- package/dist/premint/contract-types.d.ts +125 -0
- package/dist/premint/contract-types.d.ts.map +1 -0
- package/dist/premint/conversions.d.ts +78 -0
- package/dist/premint/conversions.d.ts.map +1 -0
- package/dist/premint/premint-api-client.d.ts +32 -0
- package/dist/premint/premint-api-client.d.ts.map +1 -0
- package/dist/premint/premint-client.d.ts +203 -0
- package/dist/premint/premint-client.d.ts.map +1 -0
- package/dist/premint/preminter.d.ts +121 -0
- package/dist/premint/preminter.d.ts.map +1 -0
- package/dist/preminter.d.ts +36 -0
- package/dist/preminter.d.ts.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,1664 @@
|
|
|
1
|
+
// src/premint/premint-client.ts
|
|
2
|
+
import { createPublicClient, decodeEventLog, http, zeroAddress as zeroAddress2 } from "viem";
|
|
3
|
+
import { zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2 } from "@zoralabs/protocol-deployments";
|
|
4
|
+
|
|
5
|
+
// src/premint/preminter.ts
|
|
6
|
+
import {
|
|
7
|
+
zoraCreator1155PremintExecutorImplABI as preminterAbi,
|
|
8
|
+
zoraCreator1155PremintExecutorImplABI,
|
|
9
|
+
zoraCreator1155PremintExecutorImplAddress,
|
|
10
|
+
zoraCreatorFixedPriceSaleStrategyAddress
|
|
11
|
+
} from "@zoralabs/protocol-deployments";
|
|
12
|
+
import {
|
|
13
|
+
recoverTypedDataAddress,
|
|
14
|
+
zeroAddress,
|
|
15
|
+
hashDomain,
|
|
16
|
+
keccak256,
|
|
17
|
+
concat,
|
|
18
|
+
recoverAddress,
|
|
19
|
+
parseEther
|
|
20
|
+
} from "viem";
|
|
21
|
+
|
|
22
|
+
// src/premint/contract-types.ts
|
|
23
|
+
var v1Types = {
|
|
24
|
+
CreatorAttribution: [
|
|
25
|
+
{ name: "tokenConfig", type: "TokenCreationConfig" },
|
|
26
|
+
// unique id scoped to the contract and token to create.
|
|
27
|
+
// ensure that a signature can be replaced, as long as the replacement
|
|
28
|
+
// has the same uid, and a newer version.
|
|
29
|
+
{ name: "uid", type: "uint32" },
|
|
30
|
+
{ name: "version", type: "uint32" },
|
|
31
|
+
// if this update should result in the signature being deleted.
|
|
32
|
+
{ name: "deleted", type: "bool" }
|
|
33
|
+
],
|
|
34
|
+
TokenCreationConfig: [
|
|
35
|
+
{ name: "tokenURI", type: "string" },
|
|
36
|
+
{ name: "maxSupply", type: "uint256" },
|
|
37
|
+
{ name: "maxTokensPerAddress", type: "uint64" },
|
|
38
|
+
{ name: "pricePerToken", type: "uint96" },
|
|
39
|
+
{ name: "mintStart", type: "uint64" },
|
|
40
|
+
{ name: "mintDuration", type: "uint64" },
|
|
41
|
+
{ name: "royaltyMintSchedule", type: "uint32" },
|
|
42
|
+
{ name: "royaltyBPS", type: "uint32" },
|
|
43
|
+
{ name: "royaltyRecipient", type: "address" },
|
|
44
|
+
{ name: "fixedPriceMinter", type: "address" }
|
|
45
|
+
]
|
|
46
|
+
};
|
|
47
|
+
var v2Types = {
|
|
48
|
+
CreatorAttribution: [
|
|
49
|
+
{ name: "tokenConfig", type: "TokenCreationConfig" },
|
|
50
|
+
// unique id scoped to the contract and token to create.
|
|
51
|
+
// ensure that a signature can be replaced, as long as the replacement
|
|
52
|
+
// has the same uid, and a newer version.
|
|
53
|
+
{ name: "uid", type: "uint32" },
|
|
54
|
+
{ name: "version", type: "uint32" },
|
|
55
|
+
// if this update should result in the signature being deleted.
|
|
56
|
+
{ name: "deleted", type: "bool" }
|
|
57
|
+
],
|
|
58
|
+
TokenCreationConfig: [
|
|
59
|
+
{ name: "tokenURI", type: "string" },
|
|
60
|
+
{ name: "maxSupply", type: "uint256" },
|
|
61
|
+
{ name: "maxTokensPerAddress", type: "uint64" },
|
|
62
|
+
{ name: "pricePerToken", type: "uint96" },
|
|
63
|
+
{ name: "mintStart", type: "uint64" },
|
|
64
|
+
{ name: "mintDuration", type: "uint64" },
|
|
65
|
+
{ name: "royaltyBPS", type: "uint32" },
|
|
66
|
+
{ name: "payoutRecipient", type: "address" },
|
|
67
|
+
{ name: "fixedPriceMinter", type: "address" },
|
|
68
|
+
{ name: "createReferral", type: "address" }
|
|
69
|
+
]
|
|
70
|
+
};
|
|
71
|
+
var PreminterDomain = "Preminter";
|
|
72
|
+
var PremintConfigVersion = /* @__PURE__ */ ((PremintConfigVersion2) => {
|
|
73
|
+
PremintConfigVersion2["V1"] = "1";
|
|
74
|
+
PremintConfigVersion2["V2"] = "2";
|
|
75
|
+
return PremintConfigVersion2;
|
|
76
|
+
})(PremintConfigVersion || {});
|
|
77
|
+
|
|
78
|
+
// src/premint/preminter.ts
|
|
79
|
+
var getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImplAddress[999];
|
|
80
|
+
var premintTypedDataDefinition = ({
|
|
81
|
+
verifyingContract,
|
|
82
|
+
chainId,
|
|
83
|
+
premintConfigVersion: version,
|
|
84
|
+
premintConfig
|
|
85
|
+
}) => {
|
|
86
|
+
const domain = {
|
|
87
|
+
chainId,
|
|
88
|
+
name: PreminterDomain,
|
|
89
|
+
version,
|
|
90
|
+
verifyingContract
|
|
91
|
+
};
|
|
92
|
+
if (version === "1" /* V1 */)
|
|
93
|
+
return {
|
|
94
|
+
domain,
|
|
95
|
+
types: v1Types,
|
|
96
|
+
message: premintConfig,
|
|
97
|
+
primaryType: "CreatorAttribution"
|
|
98
|
+
};
|
|
99
|
+
if (version === "2" /* V2 */) {
|
|
100
|
+
return {
|
|
101
|
+
domain,
|
|
102
|
+
types: v2Types,
|
|
103
|
+
message: premintConfig,
|
|
104
|
+
primaryType: "CreatorAttribution"
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
throw new Error(`Invalid version ${version}`);
|
|
108
|
+
};
|
|
109
|
+
async function isAuthorizedToCreatePremint({
|
|
110
|
+
collection,
|
|
111
|
+
collectionAddress,
|
|
112
|
+
publicClient,
|
|
113
|
+
signer
|
|
114
|
+
}) {
|
|
115
|
+
return await publicClient.readContract({
|
|
116
|
+
abi: preminterAbi,
|
|
117
|
+
address: getPremintExecutorAddress(),
|
|
118
|
+
functionName: "isAuthorizedToCreatePremint",
|
|
119
|
+
args: [signer, collection.contractAdmin, collectionAddress]
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async function recoverPremintSigner({
|
|
123
|
+
signature,
|
|
124
|
+
...rest
|
|
125
|
+
}) {
|
|
126
|
+
const typedData = premintTypedDataDefinition(rest);
|
|
127
|
+
return await recoverTypedDataAddress({
|
|
128
|
+
...typedData,
|
|
129
|
+
signature
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async function tryRecoverPremintSigner(params) {
|
|
133
|
+
try {
|
|
134
|
+
return await recoverPremintSigner(params);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error(error);
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function isValidSignature({
|
|
141
|
+
signature,
|
|
142
|
+
publicClient,
|
|
143
|
+
collection,
|
|
144
|
+
chainId,
|
|
145
|
+
...premintConfigAndVersion
|
|
146
|
+
}) {
|
|
147
|
+
const tokenContract = await getPremintCollectionAddress({
|
|
148
|
+
collection,
|
|
149
|
+
publicClient
|
|
150
|
+
});
|
|
151
|
+
const recoveredAddress = await tryRecoverPremintSigner({
|
|
152
|
+
...premintConfigAndVersion,
|
|
153
|
+
signature,
|
|
154
|
+
verifyingContract: tokenContract,
|
|
155
|
+
chainId
|
|
156
|
+
});
|
|
157
|
+
if (!recoverAddress) {
|
|
158
|
+
return {
|
|
159
|
+
isAuthorized: false
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
163
|
+
signer: recoveredAddress,
|
|
164
|
+
collection,
|
|
165
|
+
collectionAddress: tokenContract,
|
|
166
|
+
publicClient
|
|
167
|
+
});
|
|
168
|
+
return {
|
|
169
|
+
isAuthorized,
|
|
170
|
+
recoveredAddress
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function migratePremintConfigToV2({
|
|
174
|
+
premintConfig,
|
|
175
|
+
createReferral = zeroAddress
|
|
176
|
+
}) {
|
|
177
|
+
return {
|
|
178
|
+
...premintConfig,
|
|
179
|
+
tokenConfig: {
|
|
180
|
+
tokenURI: premintConfig.tokenConfig.tokenURI,
|
|
181
|
+
maxSupply: premintConfig.tokenConfig.maxSupply,
|
|
182
|
+
maxTokensPerAddress: premintConfig.tokenConfig.maxTokensPerAddress,
|
|
183
|
+
pricePerToken: premintConfig.tokenConfig.pricePerToken,
|
|
184
|
+
mintStart: premintConfig.tokenConfig.mintStart,
|
|
185
|
+
mintDuration: premintConfig.tokenConfig.mintDuration,
|
|
186
|
+
payoutRecipient: premintConfig.tokenConfig.royaltyRecipient,
|
|
187
|
+
royaltyBPS: premintConfig.tokenConfig.royaltyBPS,
|
|
188
|
+
fixedPriceMinter: premintConfig.tokenConfig.fixedPriceMinter,
|
|
189
|
+
createReferral
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
var recoverCreatorFromCreatorAttribution = async ({
|
|
194
|
+
creatorAttribution: { version, domainName, structHash, signature },
|
|
195
|
+
chainId,
|
|
196
|
+
tokenContract
|
|
197
|
+
}) => {
|
|
198
|
+
const hashedDomain = hashDomain({
|
|
199
|
+
domain: {
|
|
200
|
+
chainId,
|
|
201
|
+
name: domainName,
|
|
202
|
+
verifyingContract: tokenContract,
|
|
203
|
+
version
|
|
204
|
+
},
|
|
205
|
+
types: {
|
|
206
|
+
EIP712Domain: [
|
|
207
|
+
{ name: "name", type: "string" },
|
|
208
|
+
{ name: "version", type: "string" },
|
|
209
|
+
{
|
|
210
|
+
name: "chainId",
|
|
211
|
+
type: "uint256"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: "verifyingContract",
|
|
215
|
+
type: "address"
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
const parts = ["0x1901", hashedDomain, structHash];
|
|
221
|
+
const hashedTypedData = keccak256(concat(parts));
|
|
222
|
+
return await recoverAddress({
|
|
223
|
+
hash: hashedTypedData,
|
|
224
|
+
signature
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
var supportedPremintVersions = async ({
|
|
228
|
+
tokenContract,
|
|
229
|
+
publicClient
|
|
230
|
+
}) => {
|
|
231
|
+
return await publicClient.readContract({
|
|
232
|
+
abi: preminterAbi,
|
|
233
|
+
address: getPremintExecutorAddress(),
|
|
234
|
+
functionName: "supportedPremintSignatureVersions",
|
|
235
|
+
args: [tokenContract]
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
var supportsPremintVersion = async ({
|
|
239
|
+
version,
|
|
240
|
+
tokenContract,
|
|
241
|
+
publicClient
|
|
242
|
+
}) => {
|
|
243
|
+
return (await supportedPremintVersions({ tokenContract, publicClient })).includes(version);
|
|
244
|
+
};
|
|
245
|
+
async function getPremintCollectionAddress({
|
|
246
|
+
collection,
|
|
247
|
+
publicClient
|
|
248
|
+
}) {
|
|
249
|
+
return publicClient.readContract({
|
|
250
|
+
address: getPremintExecutorAddress(),
|
|
251
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
252
|
+
functionName: "getContractAddress",
|
|
253
|
+
args: [collection]
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
function markPremintDeleted(premintConfig) {
|
|
257
|
+
return {
|
|
258
|
+
...premintConfig,
|
|
259
|
+
version: premintConfig.version + 1,
|
|
260
|
+
deleted: true
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function applyUpdateToPremint({
|
|
264
|
+
uid,
|
|
265
|
+
version,
|
|
266
|
+
tokenConfig,
|
|
267
|
+
tokenConfigUpdates
|
|
268
|
+
}) {
|
|
269
|
+
const updatedTokenConfig = {
|
|
270
|
+
...tokenConfig,
|
|
271
|
+
...tokenConfigUpdates
|
|
272
|
+
};
|
|
273
|
+
const result = {
|
|
274
|
+
deleted: false,
|
|
275
|
+
uid,
|
|
276
|
+
version: version + 1,
|
|
277
|
+
tokenConfig: updatedTokenConfig
|
|
278
|
+
};
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
function makeNewPremint({
|
|
282
|
+
tokenConfig,
|
|
283
|
+
uid
|
|
284
|
+
}) {
|
|
285
|
+
return {
|
|
286
|
+
deleted: false,
|
|
287
|
+
uid,
|
|
288
|
+
version: 0,
|
|
289
|
+
tokenConfig
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
async function getPremintMintFee({
|
|
293
|
+
tokenContract,
|
|
294
|
+
publicClient
|
|
295
|
+
}) {
|
|
296
|
+
try {
|
|
297
|
+
return await publicClient.readContract({
|
|
298
|
+
address: getPremintExecutorAddress(),
|
|
299
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
300
|
+
functionName: "mintFee",
|
|
301
|
+
args: [tokenContract]
|
|
302
|
+
});
|
|
303
|
+
} catch (e) {
|
|
304
|
+
console.error(e);
|
|
305
|
+
return parseEther("0.000777");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async function getPremintMintCosts({
|
|
309
|
+
publicClient,
|
|
310
|
+
tokenContract,
|
|
311
|
+
tokenPrice,
|
|
312
|
+
quantityToMint
|
|
313
|
+
}) {
|
|
314
|
+
const mintFee = await getPremintMintFee({ tokenContract, publicClient });
|
|
315
|
+
return {
|
|
316
|
+
mintFee: mintFee * quantityToMint,
|
|
317
|
+
tokenPurchaseCost: tokenPrice * quantityToMint,
|
|
318
|
+
totalCost: (mintFee + tokenPrice) * quantityToMint
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function makeMintRewardsRecipient({
|
|
322
|
+
mintReferral = zeroAddress,
|
|
323
|
+
platformReferral = zeroAddress
|
|
324
|
+
}) {
|
|
325
|
+
return [mintReferral, platformReferral];
|
|
326
|
+
}
|
|
327
|
+
function getDefaultFixedPriceMinterAddress(chainId) {
|
|
328
|
+
return zoraCreatorFixedPriceSaleStrategyAddress[chainId];
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/apis/http-api-base.ts
|
|
332
|
+
var BadResponseError = class extends Error {
|
|
333
|
+
constructor(message, status, json) {
|
|
334
|
+
super(message);
|
|
335
|
+
this.name = "BadResponseError";
|
|
336
|
+
this.status = status;
|
|
337
|
+
this.json = json;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
async function wait(delayMs) {
|
|
341
|
+
return new Promise((resolve) => {
|
|
342
|
+
setTimeout(resolve, delayMs);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
var get = async (url) => {
|
|
346
|
+
const response = await fetch(url, { method: "GET" });
|
|
347
|
+
if (response.status !== 200) {
|
|
348
|
+
let json;
|
|
349
|
+
try {
|
|
350
|
+
json = await response.json();
|
|
351
|
+
} catch (e) {
|
|
352
|
+
}
|
|
353
|
+
throw new BadResponseError(
|
|
354
|
+
`Invalid response, status ${response.status}`,
|
|
355
|
+
response.status,
|
|
356
|
+
json
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
return await response.json();
|
|
360
|
+
};
|
|
361
|
+
var post = async (url, data) => {
|
|
362
|
+
const response = await fetch(url, {
|
|
363
|
+
method: "POST",
|
|
364
|
+
headers: {
|
|
365
|
+
"content-type": "application/json",
|
|
366
|
+
accept: "application/json"
|
|
367
|
+
},
|
|
368
|
+
body: JSON.stringify(data)
|
|
369
|
+
});
|
|
370
|
+
if (response.status !== 200) {
|
|
371
|
+
let json;
|
|
372
|
+
try {
|
|
373
|
+
json = await response.json();
|
|
374
|
+
} catch (e) {
|
|
375
|
+
}
|
|
376
|
+
throw new BadResponseError(
|
|
377
|
+
`Bad response: ${response.status}`,
|
|
378
|
+
response.status,
|
|
379
|
+
json
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
return await response.json();
|
|
383
|
+
};
|
|
384
|
+
var retries = async (tryFn, maxTries = 3, atTry = 1, linearBackoffMS = 200) => {
|
|
385
|
+
try {
|
|
386
|
+
return await tryFn();
|
|
387
|
+
} catch (err) {
|
|
388
|
+
if (err instanceof BadResponseError) {
|
|
389
|
+
if (err.status >= 500) {
|
|
390
|
+
if (atTry <= maxTries) {
|
|
391
|
+
await wait(atTry * linearBackoffMS);
|
|
392
|
+
return await retries(tryFn, maxTries, atTry + 1);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
throw err;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
var httpClient = {
|
|
400
|
+
get,
|
|
401
|
+
post,
|
|
402
|
+
retries
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
// src/constants.ts
|
|
406
|
+
import { parseAbi } from "viem";
|
|
407
|
+
var ZORA_API_BASE = "https://api.zora.co/";
|
|
408
|
+
var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
|
|
409
|
+
var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
|
|
410
|
+
function getSubgraph(name, version) {
|
|
411
|
+
return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
|
|
412
|
+
}
|
|
413
|
+
var zora721Abi = parseAbi([
|
|
414
|
+
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
415
|
+
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
|
|
416
|
+
]);
|
|
417
|
+
|
|
418
|
+
// src/apis/chain-constants.ts
|
|
419
|
+
import {
|
|
420
|
+
base,
|
|
421
|
+
baseGoerli,
|
|
422
|
+
foundry,
|
|
423
|
+
goerli,
|
|
424
|
+
mainnet,
|
|
425
|
+
optimism,
|
|
426
|
+
optimismGoerli,
|
|
427
|
+
zora,
|
|
428
|
+
zoraSepolia,
|
|
429
|
+
zoraTestnet
|
|
430
|
+
} from "viem/chains";
|
|
431
|
+
import { parseEther as parseEther2 } from "viem";
|
|
432
|
+
var REWARD_PER_TOKEN = parseEther2("0.000777");
|
|
433
|
+
var networkConfigByChain = {
|
|
434
|
+
[mainnet.id]: {
|
|
435
|
+
chainId: mainnet.id,
|
|
436
|
+
isTestnet: false,
|
|
437
|
+
zoraCollectPathChainName: "eth",
|
|
438
|
+
zoraBackendChainName: "ETHEREUM-MAINNET",
|
|
439
|
+
subgraphUrl: getSubgraph("zora-create-mainnet", "stable")
|
|
440
|
+
},
|
|
441
|
+
[goerli.id]: {
|
|
442
|
+
chainId: goerli.id,
|
|
443
|
+
isTestnet: true,
|
|
444
|
+
zoraCollectPathChainName: "gor",
|
|
445
|
+
zoraBackendChainName: "ETHEREUM-GOERLI",
|
|
446
|
+
subgraphUrl: getSubgraph("zora-create-goerli", "stable")
|
|
447
|
+
},
|
|
448
|
+
[zora.id]: {
|
|
449
|
+
chainId: zora.id,
|
|
450
|
+
isTestnet: false,
|
|
451
|
+
zoraCollectPathChainName: "zora",
|
|
452
|
+
zoraBackendChainName: "ZORA-MAINNET",
|
|
453
|
+
subgraphUrl: getSubgraph("zora-create-zora-mainnet", "stable")
|
|
454
|
+
},
|
|
455
|
+
[zoraTestnet.id]: {
|
|
456
|
+
chainId: zoraTestnet.id,
|
|
457
|
+
isTestnet: true,
|
|
458
|
+
zoraCollectPathChainName: "zgor",
|
|
459
|
+
zoraBackendChainName: "ZORA-GOERLI",
|
|
460
|
+
subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
|
|
461
|
+
},
|
|
462
|
+
[zoraSepolia.id]: {
|
|
463
|
+
chainId: zoraSepolia.id,
|
|
464
|
+
isTestnet: true,
|
|
465
|
+
zoraCollectPathChainName: "zsep",
|
|
466
|
+
zoraBackendChainName: "ZORA-SEPOLIA",
|
|
467
|
+
subgraphUrl: getSubgraph("zora-create-zora-sepolia", "stable")
|
|
468
|
+
},
|
|
469
|
+
[optimism.id]: {
|
|
470
|
+
chainId: optimism.id,
|
|
471
|
+
isTestnet: false,
|
|
472
|
+
zoraCollectPathChainName: "oeth",
|
|
473
|
+
zoraBackendChainName: "OPTIMISM-MAINNET",
|
|
474
|
+
subgraphUrl: getSubgraph("zora-create-optimism", "stable")
|
|
475
|
+
},
|
|
476
|
+
[optimismGoerli.id]: {
|
|
477
|
+
chainId: optimismGoerli.id,
|
|
478
|
+
isTestnet: true,
|
|
479
|
+
zoraCollectPathChainName: "ogor",
|
|
480
|
+
zoraBackendChainName: "OPTIMISM-GOERLI",
|
|
481
|
+
subgraphUrl: getSubgraph("zora-create-optimism-goerli", "stable")
|
|
482
|
+
},
|
|
483
|
+
[base.id]: {
|
|
484
|
+
chainId: base.id,
|
|
485
|
+
isTestnet: false,
|
|
486
|
+
zoraCollectPathChainName: "base",
|
|
487
|
+
zoraBackendChainName: "BASE-MAINNET",
|
|
488
|
+
subgraphUrl: getSubgraph("zora-create-base-mainnet", "stable")
|
|
489
|
+
},
|
|
490
|
+
[baseGoerli.id]: {
|
|
491
|
+
chainId: baseGoerli.id,
|
|
492
|
+
isTestnet: true,
|
|
493
|
+
zoraCollectPathChainName: "bgor",
|
|
494
|
+
zoraBackendChainName: "BASE-GOERLI",
|
|
495
|
+
subgraphUrl: getSubgraph("zora-create-base-goerli", "stable")
|
|
496
|
+
},
|
|
497
|
+
[foundry.id]: {
|
|
498
|
+
chainId: foundry.id,
|
|
499
|
+
isTestnet: true,
|
|
500
|
+
zoraCollectPathChainName: "zgor",
|
|
501
|
+
zoraBackendChainName: "ZORA-GOERLI",
|
|
502
|
+
subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
// src/mint/mint-api-client.ts
|
|
507
|
+
var getApiNetworkConfigForChain = (chainId) => {
|
|
508
|
+
if (!networkConfigByChain[chainId]) {
|
|
509
|
+
throw new Error(`chain id ${chainId} network not configured `);
|
|
510
|
+
}
|
|
511
|
+
return networkConfigByChain[chainId];
|
|
512
|
+
};
|
|
513
|
+
var MintAPIClient = class {
|
|
514
|
+
constructor(chainId, httpClient2) {
|
|
515
|
+
this.httpClient = httpClient2 || httpClient;
|
|
516
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
517
|
+
}
|
|
518
|
+
async getSalesConfigAndTokenInfo({
|
|
519
|
+
tokenAddress,
|
|
520
|
+
tokenId
|
|
521
|
+
}) {
|
|
522
|
+
const { retries: retries2, post: post2 } = this.httpClient;
|
|
523
|
+
return retries2(async () => {
|
|
524
|
+
const response = await post2(this.networkConfig.subgraphUrl, {
|
|
525
|
+
query: `
|
|
526
|
+
fragment SaleStrategy on SalesStrategyConfig {
|
|
527
|
+
type
|
|
528
|
+
fixedPrice {
|
|
529
|
+
address
|
|
530
|
+
pricePerToken
|
|
531
|
+
saleEnd
|
|
532
|
+
saleStart
|
|
533
|
+
maxTokensPerAddress
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
query ($id: ID!) {
|
|
538
|
+
zoraCreateToken(id: $id) {
|
|
539
|
+
id
|
|
540
|
+
contract {
|
|
541
|
+
mintFeePerQuantity
|
|
542
|
+
salesStrategies(where: {type: "FIXED_PRICE"}) {
|
|
543
|
+
...SaleStrategy
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
salesStrategies(where: {type: "FIXED_PRICE"}) {
|
|
547
|
+
...SaleStrategy
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
`,
|
|
552
|
+
variables: {
|
|
553
|
+
id: tokenId !== void 0 ? (
|
|
554
|
+
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
555
|
+
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
556
|
+
) : `${tokenAddress.toLowerCase()}-0`
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
const token = response.data?.zoraCreateToken;
|
|
560
|
+
if (!token) {
|
|
561
|
+
throw new Error("Cannot find a token to mint");
|
|
562
|
+
}
|
|
563
|
+
const saleStrategies = tokenId !== void 0 ? token.salesStrategies : token.contract.salesStrategies;
|
|
564
|
+
const fixedPrice = saleStrategies?.sort(
|
|
565
|
+
(a, b) => BigInt(a.fixedPrice.saleEnd) > BigInt(b.fixedPrice.saleEnd) ? 1 : -1
|
|
566
|
+
)?.find(() => true)?.fixedPrice;
|
|
567
|
+
if (!fixedPrice) {
|
|
568
|
+
throw new Error("Cannot find fixed price sale strategy");
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
fixedPrice,
|
|
572
|
+
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
|
|
573
|
+
};
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
// src/premint/conversions.ts
|
|
579
|
+
var convertCollectionFromApi = (collection) => ({
|
|
580
|
+
...collection,
|
|
581
|
+
contractAdmin: collection.contractAdmin
|
|
582
|
+
});
|
|
583
|
+
var convertPremintFromApi = (premint) => {
|
|
584
|
+
if (premint.config_version === "1" /* V1 */ || !premint.config_version) {
|
|
585
|
+
const tokenConfig = premint.tokenConfig;
|
|
586
|
+
return {
|
|
587
|
+
premintConfigVersion: "1" /* V1 */,
|
|
588
|
+
premintConfig: {
|
|
589
|
+
deleted: premint.deleted,
|
|
590
|
+
uid: premint.uid,
|
|
591
|
+
version: premint.version,
|
|
592
|
+
tokenConfig: {
|
|
593
|
+
...tokenConfig,
|
|
594
|
+
fixedPriceMinter: tokenConfig.fixedPriceMinter,
|
|
595
|
+
royaltyRecipient: tokenConfig.royaltyRecipient,
|
|
596
|
+
maxSupply: BigInt(tokenConfig.maxSupply),
|
|
597
|
+
pricePerToken: BigInt(tokenConfig.pricePerToken),
|
|
598
|
+
mintStart: BigInt(tokenConfig.mintStart),
|
|
599
|
+
mintDuration: BigInt(tokenConfig.mintDuration),
|
|
600
|
+
maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
} else {
|
|
605
|
+
const tokenConfig = premint.tokenConfig;
|
|
606
|
+
return {
|
|
607
|
+
premintConfigVersion: "2" /* V2 */,
|
|
608
|
+
premintConfig: {
|
|
609
|
+
deleted: premint.deleted,
|
|
610
|
+
uid: premint.uid,
|
|
611
|
+
version: premint.version,
|
|
612
|
+
tokenConfig: {
|
|
613
|
+
...tokenConfig,
|
|
614
|
+
fixedPriceMinter: tokenConfig.fixedPriceMinter,
|
|
615
|
+
payoutRecipient: tokenConfig.payoutRecipient,
|
|
616
|
+
createReferral: tokenConfig.createReferral,
|
|
617
|
+
maxSupply: BigInt(tokenConfig.maxSupply),
|
|
618
|
+
pricePerToken: BigInt(tokenConfig.pricePerToken),
|
|
619
|
+
mintStart: BigInt(tokenConfig.mintStart),
|
|
620
|
+
mintDuration: BigInt(tokenConfig.mintDuration),
|
|
621
|
+
maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
var convertGetPremintApiResponse = (response) => ({
|
|
628
|
+
...convertPremintFromApi(response.premint),
|
|
629
|
+
collection: convertCollectionFromApi(response.collection),
|
|
630
|
+
signature: response.signature
|
|
631
|
+
});
|
|
632
|
+
var encodePremintV1ForAPI = ({
|
|
633
|
+
tokenConfig,
|
|
634
|
+
...premint
|
|
635
|
+
}) => ({
|
|
636
|
+
...premint,
|
|
637
|
+
config_version: "1",
|
|
638
|
+
tokenConfig: {
|
|
639
|
+
...tokenConfig,
|
|
640
|
+
maxSupply: tokenConfig.maxSupply.toString(),
|
|
641
|
+
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
642
|
+
mintStart: tokenConfig.mintStart.toString(),
|
|
643
|
+
mintDuration: tokenConfig.mintDuration.toString(),
|
|
644
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
var encodePremintV2ForAPI = ({
|
|
648
|
+
tokenConfig,
|
|
649
|
+
...premint
|
|
650
|
+
}) => ({
|
|
651
|
+
...premint,
|
|
652
|
+
config_version: "2",
|
|
653
|
+
tokenConfig: {
|
|
654
|
+
...tokenConfig,
|
|
655
|
+
maxSupply: tokenConfig.maxSupply.toString(),
|
|
656
|
+
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
657
|
+
mintStart: tokenConfig.mintStart.toString(),
|
|
658
|
+
mintDuration: tokenConfig.mintDuration.toString(),
|
|
659
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
var encodePremintForAPI = ({
|
|
663
|
+
premintConfig,
|
|
664
|
+
premintConfigVersion
|
|
665
|
+
}) => {
|
|
666
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
667
|
+
return encodePremintV1ForAPI(premintConfig);
|
|
668
|
+
}
|
|
669
|
+
if (premintConfigVersion === "2" /* V2 */) {
|
|
670
|
+
return encodePremintV2ForAPI(premintConfig);
|
|
671
|
+
}
|
|
672
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
673
|
+
};
|
|
674
|
+
var encodePostSignatureInput = ({
|
|
675
|
+
collection,
|
|
676
|
+
premintConfigVersion,
|
|
677
|
+
premintConfig,
|
|
678
|
+
signature,
|
|
679
|
+
chainId
|
|
680
|
+
}) => ({
|
|
681
|
+
premint: encodePremintForAPI({
|
|
682
|
+
premintConfig,
|
|
683
|
+
premintConfigVersion
|
|
684
|
+
}),
|
|
685
|
+
signature,
|
|
686
|
+
collection,
|
|
687
|
+
chain_name: networkConfigByChain[chainId].zoraBackendChainName
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
// src/premint/premint-api-client.ts
|
|
691
|
+
var postSignature = async ({
|
|
692
|
+
httpClient: { post: post2, retries: retries2 } = httpClient,
|
|
693
|
+
...data
|
|
694
|
+
}) => retries2(
|
|
695
|
+
() => post2(`${ZORA_API_BASE}premint/signature`, data)
|
|
696
|
+
);
|
|
697
|
+
var getNextUID = async ({
|
|
698
|
+
chain_name,
|
|
699
|
+
collection_address,
|
|
700
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
701
|
+
}) => retries2(
|
|
702
|
+
() => get2(
|
|
703
|
+
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
|
|
704
|
+
)
|
|
705
|
+
);
|
|
706
|
+
var getSignature = async ({
|
|
707
|
+
collection_address,
|
|
708
|
+
uid,
|
|
709
|
+
chain_name,
|
|
710
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
711
|
+
}) => {
|
|
712
|
+
const result = await retries2(
|
|
713
|
+
() => get2(
|
|
714
|
+
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
|
|
715
|
+
)
|
|
716
|
+
);
|
|
717
|
+
return result;
|
|
718
|
+
};
|
|
719
|
+
var PremintAPIClient = class {
|
|
720
|
+
constructor(chainId, httpClient2) {
|
|
721
|
+
this.postSignature = async ({
|
|
722
|
+
collection,
|
|
723
|
+
signature,
|
|
724
|
+
...premintConfigAndVersion
|
|
725
|
+
}) => {
|
|
726
|
+
const data = encodePostSignatureInput({
|
|
727
|
+
collection,
|
|
728
|
+
...premintConfigAndVersion,
|
|
729
|
+
chainId: this.networkConfig.chainId,
|
|
730
|
+
signature
|
|
731
|
+
});
|
|
732
|
+
return postSignature({
|
|
733
|
+
...data,
|
|
734
|
+
httpClient: this.httpClient
|
|
735
|
+
});
|
|
736
|
+
};
|
|
737
|
+
this.getNextUID = async (collectionAddress) => (await getNextUID({
|
|
738
|
+
collection_address: collectionAddress.toLowerCase(),
|
|
739
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
740
|
+
httpClient: this.httpClient
|
|
741
|
+
})).next_uid;
|
|
742
|
+
this.getSignature = async ({
|
|
743
|
+
collectionAddress,
|
|
744
|
+
uid
|
|
745
|
+
}) => {
|
|
746
|
+
const response = await getSignature({
|
|
747
|
+
collection_address: collectionAddress.toLowerCase(),
|
|
748
|
+
uid,
|
|
749
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
750
|
+
httpClient: this.httpClient
|
|
751
|
+
});
|
|
752
|
+
return convertGetPremintApiResponse(response);
|
|
753
|
+
};
|
|
754
|
+
this.httpClient = httpClient2 || httpClient;
|
|
755
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
// src/premint/premint-client.ts
|
|
760
|
+
var defaultTokenConfigV1MintArguments = () => ({
|
|
761
|
+
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
762
|
+
maxTokensPerAddress: 0n,
|
|
763
|
+
pricePerToken: 0n,
|
|
764
|
+
mintDuration: BigInt(60 * 60 * 24 * 7),
|
|
765
|
+
// 1 week
|
|
766
|
+
mintStart: 0n,
|
|
767
|
+
royaltyMintSchedule: 0,
|
|
768
|
+
royaltyBPS: 1e3
|
|
769
|
+
// 10%,
|
|
770
|
+
});
|
|
771
|
+
var defaultTokenConfigV2MintArguments = () => ({
|
|
772
|
+
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
773
|
+
maxTokensPerAddress: 0n,
|
|
774
|
+
pricePerToken: 0n,
|
|
775
|
+
mintDuration: BigInt(60 * 60 * 24 * 7),
|
|
776
|
+
// 1 week
|
|
777
|
+
mintStart: 0n,
|
|
778
|
+
royaltyBPS: 1e3
|
|
779
|
+
// 10%,
|
|
780
|
+
});
|
|
781
|
+
var makeTokenConfigWithDefaults = ({
|
|
782
|
+
chainId,
|
|
783
|
+
premintConfigVersion,
|
|
784
|
+
tokenCreationConfig,
|
|
785
|
+
creatorAccount
|
|
786
|
+
}) => {
|
|
787
|
+
const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress(chainId);
|
|
788
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
789
|
+
return {
|
|
790
|
+
fixedPriceMinter,
|
|
791
|
+
...defaultTokenConfigV1MintArguments(),
|
|
792
|
+
royaltyRecipient: creatorAccount,
|
|
793
|
+
...tokenCreationConfig
|
|
794
|
+
};
|
|
795
|
+
} else if (premintConfigVersion === "2" /* V2 */) {
|
|
796
|
+
return {
|
|
797
|
+
fixedPriceMinter,
|
|
798
|
+
...defaultTokenConfigV2MintArguments(),
|
|
799
|
+
payoutRecipient: creatorAccount,
|
|
800
|
+
createReferral: zeroAddress2,
|
|
801
|
+
...tokenCreationConfig
|
|
802
|
+
};
|
|
803
|
+
} else {
|
|
804
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
function getPremintedLogFromReceipt(receipt) {
|
|
808
|
+
for (const data of receipt.logs) {
|
|
809
|
+
try {
|
|
810
|
+
const decodedLog = decodeEventLog({
|
|
811
|
+
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
812
|
+
eventName: "PremintedV2",
|
|
813
|
+
...data
|
|
814
|
+
});
|
|
815
|
+
if (decodedLog.eventName === "PremintedV2") {
|
|
816
|
+
return decodedLog.args;
|
|
817
|
+
}
|
|
818
|
+
} catch (err) {
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
var PremintClient = class {
|
|
823
|
+
constructor(chain, publicClient, httpClient2) {
|
|
824
|
+
this.chain = chain;
|
|
825
|
+
this.apiClient = new PremintAPIClient(chain.id, httpClient2);
|
|
826
|
+
this.publicClient = publicClient || createPublicClient({ chain, transport: http() });
|
|
827
|
+
}
|
|
828
|
+
getDataFromPremintReceipt(receipt) {
|
|
829
|
+
const premintedLog = getPremintedLogFromReceipt(receipt);
|
|
830
|
+
return {
|
|
831
|
+
premintedLog,
|
|
832
|
+
urls: this.makeUrls({
|
|
833
|
+
address: premintedLog?.contractAddress,
|
|
834
|
+
tokenId: premintedLog?.tokenId
|
|
835
|
+
})
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Update existing premint given collection address and UID of existing premint.
|
|
840
|
+
*
|
|
841
|
+
* 1. Loads existing premint token
|
|
842
|
+
* 2. Updates with settings passed into function
|
|
843
|
+
* 3. Increments the version field
|
|
844
|
+
* 4. Re-signs the premint
|
|
845
|
+
* 5. Uploads the premint to the ZORA API
|
|
846
|
+
*
|
|
847
|
+
* Updates existing premint
|
|
848
|
+
* @param settings Settings for the new premint
|
|
849
|
+
* @param settings.account Account to sign the premint update from. Taken from walletClient if none passed in.
|
|
850
|
+
* @param settings.collection Collection information for the mint
|
|
851
|
+
* @param settings.walletClient viem wallet client to use to sign
|
|
852
|
+
* @param settings.uid UID
|
|
853
|
+
* @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
|
|
854
|
+
*
|
|
855
|
+
*/
|
|
856
|
+
async updatePremint({
|
|
857
|
+
walletClient,
|
|
858
|
+
uid,
|
|
859
|
+
collection,
|
|
860
|
+
account,
|
|
861
|
+
tokenConfigUpdates
|
|
862
|
+
}) {
|
|
863
|
+
const {
|
|
864
|
+
premintConfig,
|
|
865
|
+
collection: collectionCreationConfig,
|
|
866
|
+
premintConfigVersion
|
|
867
|
+
} = await this.apiClient.getSignature({
|
|
868
|
+
collectionAddress: collection,
|
|
869
|
+
uid
|
|
870
|
+
});
|
|
871
|
+
const updatedPremint = applyUpdateToPremint({
|
|
872
|
+
uid: premintConfig.uid,
|
|
873
|
+
version: premintConfig.version,
|
|
874
|
+
tokenConfig: premintConfig.tokenConfig,
|
|
875
|
+
tokenConfigUpdates
|
|
876
|
+
});
|
|
877
|
+
return await this.signAndSubmitPremint({
|
|
878
|
+
walletClient,
|
|
879
|
+
account,
|
|
880
|
+
checkSignature: true,
|
|
881
|
+
verifyingContract: collection,
|
|
882
|
+
collection: collectionCreationConfig,
|
|
883
|
+
premintConfig: updatedPremint,
|
|
884
|
+
premintConfigVersion
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Delete premint.
|
|
889
|
+
*
|
|
890
|
+
* 1. Loads current premint from collection address with UID
|
|
891
|
+
* 2. Increments version and marks as deleted
|
|
892
|
+
* 3. Signs new premint version
|
|
893
|
+
* 4. Sends to ZORA Premint API
|
|
894
|
+
*
|
|
895
|
+
* Deletes existing premint
|
|
896
|
+
* @param settings.collection collection address
|
|
897
|
+
* @param settings.uid UID
|
|
898
|
+
* @param settings.walletClient viem wallet client to use to sign
|
|
899
|
+
*
|
|
900
|
+
*/
|
|
901
|
+
async deletePremint({
|
|
902
|
+
walletClient,
|
|
903
|
+
uid,
|
|
904
|
+
account,
|
|
905
|
+
collection
|
|
906
|
+
}) {
|
|
907
|
+
const {
|
|
908
|
+
premintConfig,
|
|
909
|
+
premintConfigVersion,
|
|
910
|
+
collection: collectionCreationConfig
|
|
911
|
+
} = await this.apiClient.getSignature({
|
|
912
|
+
collectionAddress: collection,
|
|
913
|
+
uid
|
|
914
|
+
});
|
|
915
|
+
const deletedPremint = markPremintDeleted(premintConfig);
|
|
916
|
+
return await this.signAndSubmitPremint({
|
|
917
|
+
walletClient,
|
|
918
|
+
account,
|
|
919
|
+
checkSignature: false,
|
|
920
|
+
verifyingContract: collection,
|
|
921
|
+
collection: collectionCreationConfig,
|
|
922
|
+
premintConfig: deletedPremint,
|
|
923
|
+
premintConfigVersion
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Internal function to sign and submit a premint request.
|
|
928
|
+
*
|
|
929
|
+
* @param premintArguments Arguments to premint
|
|
930
|
+
* @returns
|
|
931
|
+
*/
|
|
932
|
+
async signAndSubmitPremint(params) {
|
|
933
|
+
const { verifyingContract } = await signAndSubmitPremint({
|
|
934
|
+
...params,
|
|
935
|
+
chainId: this.chain.id,
|
|
936
|
+
apiClient: this.apiClient,
|
|
937
|
+
publicClient: this.publicClient
|
|
938
|
+
});
|
|
939
|
+
const uid = params.premintConfig.uid;
|
|
940
|
+
return {
|
|
941
|
+
urls: this.makeUrls({ address: verifyingContract, uid }),
|
|
942
|
+
uid,
|
|
943
|
+
verifyingContract
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Create premint
|
|
948
|
+
*
|
|
949
|
+
* @param settings Settings for the new premint
|
|
950
|
+
* @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
|
|
951
|
+
* @param settings.collection Collection information for the mint
|
|
952
|
+
* @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
|
|
953
|
+
* @param setings.premintConfigVersion Premint config version to use, defaults to V2
|
|
954
|
+
* @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
|
|
955
|
+
* @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
|
|
956
|
+
* @returns premint url, uid, newContractAddress, and premint object
|
|
957
|
+
*/
|
|
958
|
+
async createPremint({
|
|
959
|
+
creatorAccount,
|
|
960
|
+
collection,
|
|
961
|
+
tokenCreationConfig,
|
|
962
|
+
premintConfigVersion,
|
|
963
|
+
walletClient,
|
|
964
|
+
uid,
|
|
965
|
+
checkSignature = false
|
|
966
|
+
}) {
|
|
967
|
+
const newContractAddress = await getPremintCollectionAddress({
|
|
968
|
+
publicClient: this.publicClient,
|
|
969
|
+
collection
|
|
970
|
+
});
|
|
971
|
+
let uidToUse = uid;
|
|
972
|
+
if (typeof uidToUse !== "number") {
|
|
973
|
+
uidToUse = await this.apiClient.getNextUID(newContractAddress);
|
|
974
|
+
}
|
|
975
|
+
const actualVersion = premintConfigVersion || "1" /* V1 */;
|
|
976
|
+
if (!await supportsPremintVersion({
|
|
977
|
+
version: actualVersion,
|
|
978
|
+
publicClient: this.publicClient,
|
|
979
|
+
tokenContract: newContractAddress
|
|
980
|
+
})) {
|
|
981
|
+
throw new Error(
|
|
982
|
+
`Premint version ${actualVersion} not supported by contract`
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
const premintConfig = makeNewPremint({
|
|
986
|
+
tokenConfig: makeTokenConfigWithDefaults({
|
|
987
|
+
premintConfigVersion: actualVersion,
|
|
988
|
+
tokenCreationConfig,
|
|
989
|
+
creatorAccount: typeof creatorAccount === "string" ? creatorAccount : creatorAccount.address,
|
|
990
|
+
chainId: this.chain.id
|
|
991
|
+
}),
|
|
992
|
+
uid: uidToUse
|
|
993
|
+
});
|
|
994
|
+
return await this.signAndSubmitPremint({
|
|
995
|
+
verifyingContract: newContractAddress,
|
|
996
|
+
premintConfig,
|
|
997
|
+
premintConfigVersion: actualVersion,
|
|
998
|
+
checkSignature,
|
|
999
|
+
account: creatorAccount,
|
|
1000
|
+
walletClient,
|
|
1001
|
+
collection
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Fetches given premint data from the ZORA API.
|
|
1006
|
+
*
|
|
1007
|
+
* @param address Address for the premint contract
|
|
1008
|
+
* @param uid UID for the desired premint
|
|
1009
|
+
* @returns PremintSignatureGetResponse of premint data from the API
|
|
1010
|
+
*/
|
|
1011
|
+
async getPremintSignature({
|
|
1012
|
+
address,
|
|
1013
|
+
uid
|
|
1014
|
+
}) {
|
|
1015
|
+
return await this.apiClient.getSignature({
|
|
1016
|
+
collectionAddress: address,
|
|
1017
|
+
uid
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Gets the deterministic contract address for a premint collection
|
|
1022
|
+
* @param collection Collection to get the address for
|
|
1023
|
+
* @returns deterministic contract address
|
|
1024
|
+
*/
|
|
1025
|
+
async getCollectionAddress(collection) {
|
|
1026
|
+
return await getPremintCollectionAddress({
|
|
1027
|
+
collection,
|
|
1028
|
+
publicClient: this.publicClient
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Check user signature for v1
|
|
1033
|
+
*
|
|
1034
|
+
* @param data Signature data from the API
|
|
1035
|
+
* @returns isValid = signature is valid or not, recoveredSigner = signer from contract
|
|
1036
|
+
*/
|
|
1037
|
+
async isValidSignature({
|
|
1038
|
+
signature,
|
|
1039
|
+
collection,
|
|
1040
|
+
premintConfig,
|
|
1041
|
+
premintConfigVersion
|
|
1042
|
+
}) {
|
|
1043
|
+
const { isAuthorized, recoveredAddress } = await isValidSignature({
|
|
1044
|
+
chainId: this.chain.id,
|
|
1045
|
+
signature,
|
|
1046
|
+
collection,
|
|
1047
|
+
publicClient: this.publicClient,
|
|
1048
|
+
premintConfig,
|
|
1049
|
+
premintConfigVersion: premintConfigVersion || "1" /* V1 */
|
|
1050
|
+
});
|
|
1051
|
+
return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
|
|
1052
|
+
}
|
|
1053
|
+
makeUrls({
|
|
1054
|
+
uid,
|
|
1055
|
+
address,
|
|
1056
|
+
tokenId
|
|
1057
|
+
}) {
|
|
1058
|
+
return makeUrls({
|
|
1059
|
+
uid,
|
|
1060
|
+
address,
|
|
1061
|
+
tokenId,
|
|
1062
|
+
chain: this.chain
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
async getMintCosts({
|
|
1066
|
+
tokenContract,
|
|
1067
|
+
quantityToMint,
|
|
1068
|
+
pricePerToken
|
|
1069
|
+
}) {
|
|
1070
|
+
return await getPremintMintCosts({
|
|
1071
|
+
publicClient: this.publicClient,
|
|
1072
|
+
quantityToMint,
|
|
1073
|
+
tokenContract,
|
|
1074
|
+
tokenPrice: pricePerToken
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Execute premint on-chain
|
|
1079
|
+
*
|
|
1080
|
+
* @param settings.data Data from the API for the mint
|
|
1081
|
+
* @param settings.account Optional account (if omitted taken from wallet client) for the account executing the premint.
|
|
1082
|
+
* @param settings.walletClient WalletClient to send execution from.
|
|
1083
|
+
* @param settings.mintArguments User minting arguments.
|
|
1084
|
+
* @param settings.mintArguments.quantityToMint Quantity to mint, optional, defaults to 1.
|
|
1085
|
+
* @param settings.mintArguments.mintComment Optional mint comment, optional, omits when not included.
|
|
1086
|
+
* @param settings.publicClient Optional public client for preflight checks.
|
|
1087
|
+
* @returns receipt, log, zoraURL
|
|
1088
|
+
*/
|
|
1089
|
+
async makeMintParameters({
|
|
1090
|
+
uid,
|
|
1091
|
+
tokenContract,
|
|
1092
|
+
minterAccount,
|
|
1093
|
+
mintArguments
|
|
1094
|
+
}) {
|
|
1095
|
+
if (mintArguments && mintArguments?.quantityToMint < 1) {
|
|
1096
|
+
throw new Error("Quantity to mint cannot be below 1");
|
|
1097
|
+
}
|
|
1098
|
+
if (!minterAccount) {
|
|
1099
|
+
throw new Error("Wallet not passed in");
|
|
1100
|
+
}
|
|
1101
|
+
const { premintConfig, premintConfigVersion, collection, signature } = await this.getPremintSignature({
|
|
1102
|
+
address: tokenContract,
|
|
1103
|
+
uid
|
|
1104
|
+
});
|
|
1105
|
+
const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
|
|
1106
|
+
const value = (await getPremintMintCosts({
|
|
1107
|
+
tokenContract,
|
|
1108
|
+
quantityToMint: numberToMint,
|
|
1109
|
+
publicClient: this.publicClient,
|
|
1110
|
+
tokenPrice: premintConfig.tokenConfig.pricePerToken
|
|
1111
|
+
})).totalCost;
|
|
1112
|
+
const mintArgumentsContract = {
|
|
1113
|
+
mintComment: mintArguments?.mintComment || "",
|
|
1114
|
+
mintRecipient: mintArguments?.mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address),
|
|
1115
|
+
mintRewardsRecipients: makeMintRewardsRecipient({
|
|
1116
|
+
mintReferral: mintArguments?.mintReferral,
|
|
1117
|
+
platformReferral: mintArguments?.platformReferral
|
|
1118
|
+
})
|
|
1119
|
+
};
|
|
1120
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
1121
|
+
return {
|
|
1122
|
+
account: minterAccount,
|
|
1123
|
+
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
1124
|
+
functionName: "premintV1",
|
|
1125
|
+
value,
|
|
1126
|
+
address: getPremintExecutorAddress(),
|
|
1127
|
+
args: [
|
|
1128
|
+
collection,
|
|
1129
|
+
premintConfig,
|
|
1130
|
+
signature,
|
|
1131
|
+
numberToMint,
|
|
1132
|
+
mintArgumentsContract
|
|
1133
|
+
]
|
|
1134
|
+
};
|
|
1135
|
+
} else if (premintConfigVersion === "2" /* V2 */) {
|
|
1136
|
+
return {
|
|
1137
|
+
account: minterAccount,
|
|
1138
|
+
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
1139
|
+
functionName: "premintV2",
|
|
1140
|
+
value,
|
|
1141
|
+
address: getPremintExecutorAddress(),
|
|
1142
|
+
args: [
|
|
1143
|
+
collection,
|
|
1144
|
+
premintConfig,
|
|
1145
|
+
signature,
|
|
1146
|
+
numberToMint,
|
|
1147
|
+
mintArgumentsContract
|
|
1148
|
+
]
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
function createPremintClient({
|
|
1155
|
+
chain,
|
|
1156
|
+
httpClient: httpClient2,
|
|
1157
|
+
publicClient
|
|
1158
|
+
}) {
|
|
1159
|
+
return new PremintClient(chain, publicClient, httpClient2);
|
|
1160
|
+
}
|
|
1161
|
+
function makeUrls({
|
|
1162
|
+
uid,
|
|
1163
|
+
address,
|
|
1164
|
+
tokenId,
|
|
1165
|
+
chain
|
|
1166
|
+
}) {
|
|
1167
|
+
if ((!uid || !tokenId) && !address) {
|
|
1168
|
+
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
1169
|
+
}
|
|
1170
|
+
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
1171
|
+
const network = getApiNetworkConfigForChain(chain.id);
|
|
1172
|
+
return {
|
|
1173
|
+
explorer: tokenId ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
|
|
1174
|
+
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`,
|
|
1175
|
+
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
async function signAndSubmitPremint({
|
|
1179
|
+
walletClient,
|
|
1180
|
+
verifyingContract,
|
|
1181
|
+
account,
|
|
1182
|
+
checkSignature,
|
|
1183
|
+
collection,
|
|
1184
|
+
chainId,
|
|
1185
|
+
publicClient,
|
|
1186
|
+
apiClient,
|
|
1187
|
+
...premintConfigAndVersion
|
|
1188
|
+
}) {
|
|
1189
|
+
if (!account) {
|
|
1190
|
+
account = walletClient.account;
|
|
1191
|
+
}
|
|
1192
|
+
if (!account) {
|
|
1193
|
+
throw new Error("No account provided");
|
|
1194
|
+
}
|
|
1195
|
+
const signature = await walletClient.signTypedData({
|
|
1196
|
+
account,
|
|
1197
|
+
...premintTypedDataDefinition({
|
|
1198
|
+
verifyingContract,
|
|
1199
|
+
...premintConfigAndVersion,
|
|
1200
|
+
chainId
|
|
1201
|
+
})
|
|
1202
|
+
});
|
|
1203
|
+
if (checkSignature) {
|
|
1204
|
+
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
1205
|
+
collection,
|
|
1206
|
+
publicClient,
|
|
1207
|
+
signer: typeof account === "string" ? account : account.address,
|
|
1208
|
+
collectionAddress: await getPremintCollectionAddress({
|
|
1209
|
+
collection,
|
|
1210
|
+
publicClient
|
|
1211
|
+
})
|
|
1212
|
+
});
|
|
1213
|
+
if (!isAuthorized) {
|
|
1214
|
+
throw new Error("Not authorized to create premint");
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
const premint = await apiClient.postSignature({
|
|
1218
|
+
collection,
|
|
1219
|
+
signature,
|
|
1220
|
+
...premintConfigAndVersion
|
|
1221
|
+
});
|
|
1222
|
+
return { premint, verifyingContract };
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
// src/mint/mint-client.ts
|
|
1226
|
+
import {
|
|
1227
|
+
createPublicClient as createPublicClient2,
|
|
1228
|
+
encodeAbiParameters,
|
|
1229
|
+
parseAbiParameters,
|
|
1230
|
+
zeroAddress as zeroAddress3,
|
|
1231
|
+
http as http2
|
|
1232
|
+
} from "viem";
|
|
1233
|
+
import {
|
|
1234
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
|
|
1235
|
+
zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
|
|
1236
|
+
} from "@zoralabs/protocol-deployments";
|
|
1237
|
+
var MintError = class extends Error {
|
|
1238
|
+
};
|
|
1239
|
+
var MintInactiveError = class extends Error {
|
|
1240
|
+
};
|
|
1241
|
+
var Errors = {
|
|
1242
|
+
MintError,
|
|
1243
|
+
MintInactiveError
|
|
1244
|
+
};
|
|
1245
|
+
var MintClient = class {
|
|
1246
|
+
constructor(chain, publicClient, httpClient2) {
|
|
1247
|
+
this.apiClient = new MintAPIClient(chain.id, httpClient2);
|
|
1248
|
+
this.publicClient = publicClient || createPublicClient2({ chain, transport: http2() });
|
|
1249
|
+
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Returns the parameters needed to prepare a transaction mint a token.
|
|
1252
|
+
* @param param0.minterAccount The account that will mint the token.
|
|
1253
|
+
* @param param0.mintable The mintable token to mint.
|
|
1254
|
+
* @param param0.mintArguments The arguments for the mint (mint recipient, comment, mint referral, quantity to mint)
|
|
1255
|
+
* @returns
|
|
1256
|
+
*/
|
|
1257
|
+
async makePrepareMintTokenParams({
|
|
1258
|
+
...rest
|
|
1259
|
+
}) {
|
|
1260
|
+
return makePrepareMintTokenParams({
|
|
1261
|
+
...rest,
|
|
1262
|
+
apiClient: this.apiClient,
|
|
1263
|
+
publicClient: this.publicClient
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
function createMintClient({
|
|
1268
|
+
chain,
|
|
1269
|
+
publicClient,
|
|
1270
|
+
httpClient: httpClient2
|
|
1271
|
+
}) {
|
|
1272
|
+
return new MintClient(chain, publicClient, httpClient2);
|
|
1273
|
+
}
|
|
1274
|
+
async function makePrepareMintTokenParams({
|
|
1275
|
+
publicClient,
|
|
1276
|
+
apiClient,
|
|
1277
|
+
tokenId,
|
|
1278
|
+
tokenAddress,
|
|
1279
|
+
...rest
|
|
1280
|
+
}) {
|
|
1281
|
+
const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
|
|
1282
|
+
tokenId,
|
|
1283
|
+
tokenAddress
|
|
1284
|
+
});
|
|
1285
|
+
if (tokenId === void 0) {
|
|
1286
|
+
return makePrepareMint721TokenParams({
|
|
1287
|
+
salesConfigAndTokenInfo,
|
|
1288
|
+
tokenAddress,
|
|
1289
|
+
...rest
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
return makePrepareMint1155TokenParams({
|
|
1293
|
+
salesConfigAndTokenInfo,
|
|
1294
|
+
tokenAddress,
|
|
1295
|
+
tokenId,
|
|
1296
|
+
...rest
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
async function makePrepareMint721TokenParams({
|
|
1300
|
+
tokenAddress,
|
|
1301
|
+
salesConfigAndTokenInfo,
|
|
1302
|
+
minterAccount,
|
|
1303
|
+
mintArguments
|
|
1304
|
+
}) {
|
|
1305
|
+
const mintValue = getMintCosts({
|
|
1306
|
+
salesConfigAndTokenInfo,
|
|
1307
|
+
quantityToMint: BigInt(mintArguments.quantityToMint)
|
|
1308
|
+
}).totalCost;
|
|
1309
|
+
const result = {
|
|
1310
|
+
abi: zora721Abi,
|
|
1311
|
+
address: tokenAddress,
|
|
1312
|
+
account: minterAccount,
|
|
1313
|
+
functionName: "mintWithRewards",
|
|
1314
|
+
value: mintValue,
|
|
1315
|
+
args: [
|
|
1316
|
+
mintArguments.mintToAddress,
|
|
1317
|
+
BigInt(mintArguments.quantityToMint),
|
|
1318
|
+
mintArguments.mintComment || "",
|
|
1319
|
+
mintArguments.mintReferral || zeroAddress3
|
|
1320
|
+
]
|
|
1321
|
+
};
|
|
1322
|
+
return result;
|
|
1323
|
+
}
|
|
1324
|
+
function getMintCosts({
|
|
1325
|
+
salesConfigAndTokenInfo,
|
|
1326
|
+
quantityToMint
|
|
1327
|
+
}) {
|
|
1328
|
+
const mintFeeForTokens = salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
|
|
1329
|
+
const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.fixedPrice.pricePerToken) * quantityToMint;
|
|
1330
|
+
return {
|
|
1331
|
+
mintFee: mintFeeForTokens,
|
|
1332
|
+
tokenPurchaseCost,
|
|
1333
|
+
totalCost: mintFeeForTokens + tokenPurchaseCost
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
async function makePrepareMint1155TokenParams({
|
|
1337
|
+
tokenId,
|
|
1338
|
+
salesConfigAndTokenInfo,
|
|
1339
|
+
minterAccount,
|
|
1340
|
+
tokenAddress,
|
|
1341
|
+
mintArguments
|
|
1342
|
+
}) {
|
|
1343
|
+
const mintQuantity = BigInt(mintArguments.quantityToMint);
|
|
1344
|
+
const mintValue = getMintCosts({
|
|
1345
|
+
salesConfigAndTokenInfo,
|
|
1346
|
+
quantityToMint: mintQuantity
|
|
1347
|
+
}).totalCost;
|
|
1348
|
+
const result = {
|
|
1349
|
+
abi: zoraCreator1155ImplABI2,
|
|
1350
|
+
functionName: "mintWithRewards",
|
|
1351
|
+
account: minterAccount,
|
|
1352
|
+
value: mintValue,
|
|
1353
|
+
address: tokenAddress,
|
|
1354
|
+
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
1355
|
+
args: [
|
|
1356
|
+
salesConfigAndTokenInfo?.fixedPrice.address || zoraCreatorFixedPriceSaleStrategyAddress2[999],
|
|
1357
|
+
BigInt(tokenId),
|
|
1358
|
+
mintQuantity,
|
|
1359
|
+
encodeAbiParameters(parseAbiParameters("address, string"), [
|
|
1360
|
+
mintArguments.mintToAddress,
|
|
1361
|
+
mintArguments.mintComment || ""
|
|
1362
|
+
]),
|
|
1363
|
+
mintArguments.mintReferral || zeroAddress3
|
|
1364
|
+
]
|
|
1365
|
+
};
|
|
1366
|
+
return result;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
// src/create/1155-create-helper.ts
|
|
1370
|
+
import {
|
|
1371
|
+
zoraCreator1155FactoryImplABI,
|
|
1372
|
+
zoraCreator1155FactoryImplAddress,
|
|
1373
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI3,
|
|
1374
|
+
zoraCreatorFixedPriceSaleStrategyABI
|
|
1375
|
+
} from "@zoralabs/protocol-deployments";
|
|
1376
|
+
import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as zeroAddress4 } from "viem";
|
|
1377
|
+
var SALE_END_FOREVER = 18446744073709551615n;
|
|
1378
|
+
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
1379
|
+
var DEFAULT_SALE_SETTINGS = {
|
|
1380
|
+
fundsRecipient: zeroAddress4,
|
|
1381
|
+
// Free Mint
|
|
1382
|
+
pricePerToken: 0n,
|
|
1383
|
+
// Sale start time – defaults to beginning of unix time
|
|
1384
|
+
saleStart: 0n,
|
|
1385
|
+
// This is the end of uint64, plenty of time
|
|
1386
|
+
saleEnd: SALE_END_FOREVER,
|
|
1387
|
+
// 0 Here means no limit
|
|
1388
|
+
maxTokensPerAddress: 0n
|
|
1389
|
+
};
|
|
1390
|
+
var PERMISSION_BIT_MINTER = 4n;
|
|
1391
|
+
function create1155TokenSetupArgs({
|
|
1392
|
+
nextTokenId,
|
|
1393
|
+
// How many NFTs upon initialization to mint to the creator
|
|
1394
|
+
mintToCreatorCount,
|
|
1395
|
+
tokenMetadataURI,
|
|
1396
|
+
// Fixed price minter address – required minter
|
|
1397
|
+
fixedPriceMinterAddress,
|
|
1398
|
+
// Address to use as the create referral, optional.
|
|
1399
|
+
createReferral,
|
|
1400
|
+
// Optional max supply of the token. Default unlimited
|
|
1401
|
+
maxSupply,
|
|
1402
|
+
// wallet sending the transaction
|
|
1403
|
+
account,
|
|
1404
|
+
salesConfig,
|
|
1405
|
+
royaltySettings
|
|
1406
|
+
}) {
|
|
1407
|
+
if (!maxSupply) {
|
|
1408
|
+
maxSupply = OPEN_EDITION_MINT_SIZE;
|
|
1409
|
+
}
|
|
1410
|
+
maxSupply = BigInt(maxSupply);
|
|
1411
|
+
mintToCreatorCount = BigInt(mintToCreatorCount);
|
|
1412
|
+
const salesConfigWithDefaults = {
|
|
1413
|
+
// Set static sales default.
|
|
1414
|
+
...DEFAULT_SALE_SETTINGS,
|
|
1415
|
+
// Override with user settings.
|
|
1416
|
+
...salesConfig
|
|
1417
|
+
};
|
|
1418
|
+
const setupActions = [
|
|
1419
|
+
encodeFunctionData({
|
|
1420
|
+
abi: zoraCreator1155ImplABI3,
|
|
1421
|
+
functionName: "assumeLastTokenIdMatches",
|
|
1422
|
+
args: [nextTokenId - 1n]
|
|
1423
|
+
}),
|
|
1424
|
+
createReferral ? encodeFunctionData({
|
|
1425
|
+
abi: zoraCreator1155ImplABI3,
|
|
1426
|
+
functionName: "setupNewTokenWithCreateReferral",
|
|
1427
|
+
args: [tokenMetadataURI, maxSupply, createReferral]
|
|
1428
|
+
}) : encodeFunctionData({
|
|
1429
|
+
abi: zoraCreator1155ImplABI3,
|
|
1430
|
+
functionName: "setupNewToken",
|
|
1431
|
+
args: [tokenMetadataURI, maxSupply]
|
|
1432
|
+
}),
|
|
1433
|
+
encodeFunctionData({
|
|
1434
|
+
abi: zoraCreator1155ImplABI3,
|
|
1435
|
+
functionName: "addPermission",
|
|
1436
|
+
args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
|
|
1437
|
+
}),
|
|
1438
|
+
encodeFunctionData({
|
|
1439
|
+
abi: zoraCreator1155ImplABI3,
|
|
1440
|
+
functionName: "callSale",
|
|
1441
|
+
args: [
|
|
1442
|
+
nextTokenId,
|
|
1443
|
+
fixedPriceMinterAddress,
|
|
1444
|
+
encodeFunctionData({
|
|
1445
|
+
abi: zoraCreatorFixedPriceSaleStrategyABI,
|
|
1446
|
+
functionName: "setSale",
|
|
1447
|
+
args: [nextTokenId, salesConfigWithDefaults]
|
|
1448
|
+
})
|
|
1449
|
+
]
|
|
1450
|
+
})
|
|
1451
|
+
];
|
|
1452
|
+
if (mintToCreatorCount) {
|
|
1453
|
+
setupActions.push(
|
|
1454
|
+
encodeFunctionData({
|
|
1455
|
+
abi: zoraCreator1155ImplABI3,
|
|
1456
|
+
functionName: "adminMint",
|
|
1457
|
+
args: [account, nextTokenId, mintToCreatorCount, "0x"]
|
|
1458
|
+
})
|
|
1459
|
+
);
|
|
1460
|
+
}
|
|
1461
|
+
if (royaltySettings) {
|
|
1462
|
+
setupActions.push(
|
|
1463
|
+
encodeFunctionData({
|
|
1464
|
+
abi: zoraCreator1155ImplABI3,
|
|
1465
|
+
functionName: "updateRoyaltiesForToken",
|
|
1466
|
+
args: [
|
|
1467
|
+
nextTokenId,
|
|
1468
|
+
{
|
|
1469
|
+
royaltyMintSchedule: 0,
|
|
1470
|
+
royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
|
|
1471
|
+
royaltyRecipient: royaltySettings?.royaltyRecipient || account
|
|
1472
|
+
}
|
|
1473
|
+
]
|
|
1474
|
+
})
|
|
1475
|
+
);
|
|
1476
|
+
}
|
|
1477
|
+
return setupActions;
|
|
1478
|
+
}
|
|
1479
|
+
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
1480
|
+
for (const data of receipt.logs) {
|
|
1481
|
+
try {
|
|
1482
|
+
const decodedLog = decodeEventLog2({
|
|
1483
|
+
abi: zoraCreator1155ImplABI3,
|
|
1484
|
+
eventName: "SetupNewToken",
|
|
1485
|
+
...data
|
|
1486
|
+
});
|
|
1487
|
+
if (decodedLog && decodedLog.eventName === "SetupNewToken") {
|
|
1488
|
+
return decodedLog.args.tokenId;
|
|
1489
|
+
}
|
|
1490
|
+
} catch (err) {
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
async function getContractExists(publicClient, contract, account) {
|
|
1495
|
+
let contractAddress;
|
|
1496
|
+
let contractExists = false;
|
|
1497
|
+
if (typeof contract !== "string") {
|
|
1498
|
+
contractAddress = await publicClient.readContract({
|
|
1499
|
+
abi: zoraCreator1155FactoryImplABI,
|
|
1500
|
+
// Since this address is deterministic we can hardcode a chain id safely here.
|
|
1501
|
+
address: zoraCreator1155FactoryImplAddress[999],
|
|
1502
|
+
functionName: "deterministicContractAddress",
|
|
1503
|
+
args: [
|
|
1504
|
+
account,
|
|
1505
|
+
contract.uri,
|
|
1506
|
+
contract.name,
|
|
1507
|
+
contract.defaultAdmin || account
|
|
1508
|
+
]
|
|
1509
|
+
});
|
|
1510
|
+
try {
|
|
1511
|
+
await publicClient.readContract({
|
|
1512
|
+
abi: zoraCreator1155ImplABI3,
|
|
1513
|
+
address: contractAddress,
|
|
1514
|
+
functionName: "contractVersion"
|
|
1515
|
+
});
|
|
1516
|
+
contractExists = true;
|
|
1517
|
+
} catch (e) {
|
|
1518
|
+
}
|
|
1519
|
+
return { contractAddress, contractExists };
|
|
1520
|
+
}
|
|
1521
|
+
return {
|
|
1522
|
+
contractExists: true,
|
|
1523
|
+
contractAddress: contract
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
function create1155CreatorClient({
|
|
1527
|
+
publicClient
|
|
1528
|
+
}) {
|
|
1529
|
+
async function createNew1155Token({
|
|
1530
|
+
contract,
|
|
1531
|
+
tokenMetadataURI,
|
|
1532
|
+
mintToCreatorCount = 1,
|
|
1533
|
+
salesConfig = {},
|
|
1534
|
+
maxSupply,
|
|
1535
|
+
account,
|
|
1536
|
+
royaltySettings,
|
|
1537
|
+
getAdditionalSetupActions
|
|
1538
|
+
}) {
|
|
1539
|
+
const { contractExists, contractAddress } = await getContractExists(
|
|
1540
|
+
publicClient,
|
|
1541
|
+
contract,
|
|
1542
|
+
account
|
|
1543
|
+
);
|
|
1544
|
+
let nextTokenId = 1n;
|
|
1545
|
+
if (contractExists) {
|
|
1546
|
+
nextTokenId = await publicClient.readContract({
|
|
1547
|
+
abi: zoraCreator1155ImplABI3,
|
|
1548
|
+
functionName: "nextTokenId",
|
|
1549
|
+
address: contractAddress
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
const fixedPriceMinterAddress = await publicClient.readContract({
|
|
1553
|
+
abi: zoraCreator1155FactoryImplABI,
|
|
1554
|
+
address: zoraCreator1155FactoryImplAddress[999],
|
|
1555
|
+
functionName: "fixedPriceMinter"
|
|
1556
|
+
});
|
|
1557
|
+
let tokenSetupActions = create1155TokenSetupArgs({
|
|
1558
|
+
tokenMetadataURI,
|
|
1559
|
+
nextTokenId,
|
|
1560
|
+
salesConfig,
|
|
1561
|
+
maxSupply,
|
|
1562
|
+
fixedPriceMinterAddress,
|
|
1563
|
+
account,
|
|
1564
|
+
mintToCreatorCount,
|
|
1565
|
+
royaltySettings
|
|
1566
|
+
});
|
|
1567
|
+
if (getAdditionalSetupActions) {
|
|
1568
|
+
tokenSetupActions = [
|
|
1569
|
+
...getAdditionalSetupActions({ tokenId: nextTokenId, contractAddress }),
|
|
1570
|
+
...tokenSetupActions
|
|
1571
|
+
];
|
|
1572
|
+
}
|
|
1573
|
+
if (!contractAddress && typeof contract === "string") {
|
|
1574
|
+
throw new Error("Invariant: contract cannot be missing and an address");
|
|
1575
|
+
}
|
|
1576
|
+
if (!contractExists && typeof contract !== "string") {
|
|
1577
|
+
const request = {
|
|
1578
|
+
abi: zoraCreator1155FactoryImplABI,
|
|
1579
|
+
functionName: "createContractDeterministic",
|
|
1580
|
+
account,
|
|
1581
|
+
address: zoraCreator1155FactoryImplAddress[999],
|
|
1582
|
+
args: [
|
|
1583
|
+
contract.uri,
|
|
1584
|
+
contract.name,
|
|
1585
|
+
{
|
|
1586
|
+
// deprecated
|
|
1587
|
+
royaltyMintSchedule: 0,
|
|
1588
|
+
royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
|
|
1589
|
+
royaltyRecipient: royaltySettings?.royaltyRecipient || account
|
|
1590
|
+
},
|
|
1591
|
+
contract.defaultAdmin || account,
|
|
1592
|
+
tokenSetupActions
|
|
1593
|
+
]
|
|
1594
|
+
};
|
|
1595
|
+
return {
|
|
1596
|
+
request,
|
|
1597
|
+
tokenSetupActions,
|
|
1598
|
+
contractAddress,
|
|
1599
|
+
contractExists
|
|
1600
|
+
};
|
|
1601
|
+
} else if (contractExists) {
|
|
1602
|
+
const request = {
|
|
1603
|
+
abi: zoraCreator1155ImplABI3,
|
|
1604
|
+
functionName: "multicall",
|
|
1605
|
+
account,
|
|
1606
|
+
address: contractAddress,
|
|
1607
|
+
args: [tokenSetupActions]
|
|
1608
|
+
};
|
|
1609
|
+
return {
|
|
1610
|
+
request,
|
|
1611
|
+
tokenSetupActions,
|
|
1612
|
+
contractAddress,
|
|
1613
|
+
contractExists
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
throw new Error("Unsupported contract argument type");
|
|
1617
|
+
}
|
|
1618
|
+
return { createNew1155Token };
|
|
1619
|
+
}
|
|
1620
|
+
export {
|
|
1621
|
+
DEFAULT_SALE_SETTINGS,
|
|
1622
|
+
Errors,
|
|
1623
|
+
MintAPIClient,
|
|
1624
|
+
PremintAPIClient,
|
|
1625
|
+
PremintConfigVersion,
|
|
1626
|
+
PreminterDomain,
|
|
1627
|
+
ZORA_API_BASE,
|
|
1628
|
+
applyUpdateToPremint,
|
|
1629
|
+
convertCollectionFromApi,
|
|
1630
|
+
convertGetPremintApiResponse,
|
|
1631
|
+
convertPremintFromApi,
|
|
1632
|
+
create1155CreatorClient,
|
|
1633
|
+
create1155TokenSetupArgs,
|
|
1634
|
+
createMintClient,
|
|
1635
|
+
createPremintClient,
|
|
1636
|
+
defaultTokenConfigV1MintArguments,
|
|
1637
|
+
defaultTokenConfigV2MintArguments,
|
|
1638
|
+
encodePostSignatureInput,
|
|
1639
|
+
encodePremintForAPI,
|
|
1640
|
+
getApiNetworkConfigForChain,
|
|
1641
|
+
getDefaultFixedPriceMinterAddress,
|
|
1642
|
+
getMintCosts,
|
|
1643
|
+
getPremintCollectionAddress,
|
|
1644
|
+
getPremintExecutorAddress,
|
|
1645
|
+
getPremintMintCosts,
|
|
1646
|
+
getPremintMintFee,
|
|
1647
|
+
getPremintedLogFromReceipt,
|
|
1648
|
+
getTokenIdFromCreateReceipt,
|
|
1649
|
+
isAuthorizedToCreatePremint,
|
|
1650
|
+
isValidSignature,
|
|
1651
|
+
makeMintRewardsRecipient,
|
|
1652
|
+
makeNewPremint,
|
|
1653
|
+
markPremintDeleted,
|
|
1654
|
+
migratePremintConfigToV2,
|
|
1655
|
+
premintTypedDataDefinition,
|
|
1656
|
+
recoverCreatorFromCreatorAttribution,
|
|
1657
|
+
recoverPremintSigner,
|
|
1658
|
+
supportedPremintVersions,
|
|
1659
|
+
supportsPremintVersion,
|
|
1660
|
+
tryRecoverPremintSigner,
|
|
1661
|
+
v1Types,
|
|
1662
|
+
v2Types
|
|
1663
|
+
};
|
|
1664
|
+
//# sourceMappingURL=index.js.map
|