@zoralabs/protocol-sdk 0.3.4 → 0.4.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 +6 -6
- package/CHANGELOG.md +34 -0
- package/README.md +30 -58
- package/dist/anvil.d.ts +4 -2
- package/dist/anvil.d.ts.map +1 -1
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs +819 -518
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +788 -493
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +16 -216
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +7 -227
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/premint/contract-types.d.ts +125 -0
- package/dist/premint/contract-types.d.ts.map +1 -0
- package/dist/premint/premint-api-client.d.ts +14 -7
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +45 -115
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +102 -21
- package/dist/premint/preminter.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/anvil.ts +7 -4
- package/src/constants.ts +7 -0
- package/src/index.ts +2 -0
- package/src/mint/mint-api-client.ts +72 -68
- package/src/mint/mint-client.test.ts +9 -11
- package/src/mint/mint-client.ts +51 -221
- package/src/premint/contract-types.ts +109 -0
- package/src/premint/premint-api-client.ts +162 -22
- package/src/premint/premint-client.test.ts +186 -84
- package/src/premint/premint-client.ts +357 -289
- package/src/premint/preminter.test.ts +209 -130
- package/src/premint/preminter.ts +377 -54
- package/src/types.ts +1 -0
- package/dist/apis/generated/discover-api-types.d.ts +0 -2131
- package/dist/apis/generated/discover-api-types.d.ts.map +0 -1
- package/src/apis/generated/discover-api-types.ts +0 -2180
package/dist/index.cjs
CHANGED
|
@@ -21,79 +21,338 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
DEFAULT_SALE_SETTINGS: () => DEFAULT_SALE_SETTINGS,
|
|
24
|
-
DefaultMintArguments: () => DefaultMintArguments,
|
|
25
24
|
Errors: () => Errors,
|
|
26
25
|
MintAPIClient: () => MintAPIClient,
|
|
27
26
|
PremintAPIClient: () => PremintAPIClient,
|
|
27
|
+
PremintConfigVersion: () => PremintConfigVersion,
|
|
28
|
+
PreminterDomain: () => PreminterDomain,
|
|
28
29
|
ZORA_API_BASE: () => ZORA_API_BASE,
|
|
29
|
-
|
|
30
|
-
convertPremint: () => convertPremint,
|
|
30
|
+
applyUpdateToPremint: () => applyUpdateToPremint,
|
|
31
31
|
create1155CreatorClient: () => create1155CreatorClient,
|
|
32
32
|
create1155TokenSetupArgs: () => create1155TokenSetupArgs,
|
|
33
33
|
createMintClient: () => createMintClient,
|
|
34
34
|
createPremintClient: () => createPremintClient,
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
defaultTokenConfigV1MintArguments: () => defaultTokenConfigV1MintArguments,
|
|
36
|
+
defaultTokenConfigV2MintArguments: () => defaultTokenConfigV2MintArguments,
|
|
37
37
|
getApiNetworkConfigForChain: () => getApiNetworkConfigForChain,
|
|
38
|
+
getMintCosts: () => getMintCosts,
|
|
39
|
+
getPremintCollectionAddress: () => getPremintCollectionAddress,
|
|
40
|
+
getPremintExecutorAddress: () => getPremintExecutorAddress,
|
|
38
41
|
getPremintedLogFromReceipt: () => getPremintedLogFromReceipt,
|
|
39
42
|
getTokenIdFromCreateReceipt: () => getTokenIdFromCreateReceipt,
|
|
40
|
-
|
|
43
|
+
isAuthorizedToCreatePremint: () => isAuthorizedToCreatePremint,
|
|
44
|
+
isValidSignature: () => isValidSignature,
|
|
45
|
+
makeNewPremint: () => makeNewPremint,
|
|
46
|
+
markPremintDeleted: () => markPremintDeleted,
|
|
47
|
+
migratePremintConfigToV2: () => migratePremintConfigToV2,
|
|
48
|
+
premintTypedDataDefinition: () => premintTypedDataDefinition,
|
|
49
|
+
recoverCreatorFromCreatorAttribution: () => recoverCreatorFromCreatorAttribution,
|
|
50
|
+
recoverPremintSigner: () => recoverPremintSigner,
|
|
51
|
+
supportedPremintVersions: () => supportedPremintVersions,
|
|
52
|
+
supportsPremintVersion: () => supportsPremintVersion,
|
|
53
|
+
tryRecoverPremintSigner: () => tryRecoverPremintSigner,
|
|
54
|
+
v1Types: () => v1Types,
|
|
55
|
+
v2Types: () => v2Types
|
|
41
56
|
});
|
|
42
57
|
module.exports = __toCommonJS(src_exports);
|
|
43
58
|
|
|
44
59
|
// src/premint/premint-client.ts
|
|
45
|
-
var
|
|
60
|
+
var import_viem4 = require("viem");
|
|
61
|
+
var import_protocol_deployments2 = require("@zoralabs/protocol-deployments");
|
|
62
|
+
|
|
63
|
+
// src/premint/preminter.ts
|
|
46
64
|
var import_protocol_deployments = require("@zoralabs/protocol-deployments");
|
|
65
|
+
var import_viem = require("viem");
|
|
66
|
+
|
|
67
|
+
// src/premint/contract-types.ts
|
|
68
|
+
var v1Types = {
|
|
69
|
+
CreatorAttribution: [
|
|
70
|
+
{ name: "tokenConfig", type: "TokenCreationConfig" },
|
|
71
|
+
// unique id scoped to the contract and token to create.
|
|
72
|
+
// ensure that a signature can be replaced, as long as the replacement
|
|
73
|
+
// has the same uid, and a newer version.
|
|
74
|
+
{ name: "uid", type: "uint32" },
|
|
75
|
+
{ name: "version", type: "uint32" },
|
|
76
|
+
// if this update should result in the signature being deleted.
|
|
77
|
+
{ name: "deleted", type: "bool" }
|
|
78
|
+
],
|
|
79
|
+
TokenCreationConfig: [
|
|
80
|
+
{ name: "tokenURI", type: "string" },
|
|
81
|
+
{ name: "maxSupply", type: "uint256" },
|
|
82
|
+
{ name: "maxTokensPerAddress", type: "uint64" },
|
|
83
|
+
{ name: "pricePerToken", type: "uint96" },
|
|
84
|
+
{ name: "mintStart", type: "uint64" },
|
|
85
|
+
{ name: "mintDuration", type: "uint64" },
|
|
86
|
+
{ name: "royaltyMintSchedule", type: "uint32" },
|
|
87
|
+
{ name: "royaltyBPS", type: "uint32" },
|
|
88
|
+
{ name: "royaltyRecipient", type: "address" },
|
|
89
|
+
{ name: "fixedPriceMinter", type: "address" }
|
|
90
|
+
]
|
|
91
|
+
};
|
|
92
|
+
var v2Types = {
|
|
93
|
+
CreatorAttribution: [
|
|
94
|
+
{ name: "tokenConfig", type: "TokenCreationConfig" },
|
|
95
|
+
// unique id scoped to the contract and token to create.
|
|
96
|
+
// ensure that a signature can be replaced, as long as the replacement
|
|
97
|
+
// has the same uid, and a newer version.
|
|
98
|
+
{ name: "uid", type: "uint32" },
|
|
99
|
+
{ name: "version", type: "uint32" },
|
|
100
|
+
// if this update should result in the signature being deleted.
|
|
101
|
+
{ name: "deleted", type: "bool" }
|
|
102
|
+
],
|
|
103
|
+
TokenCreationConfig: [
|
|
104
|
+
{ name: "tokenURI", type: "string" },
|
|
105
|
+
{ name: "maxSupply", type: "uint256" },
|
|
106
|
+
{ name: "maxTokensPerAddress", type: "uint64" },
|
|
107
|
+
{ name: "pricePerToken", type: "uint96" },
|
|
108
|
+
{ name: "mintStart", type: "uint64" },
|
|
109
|
+
{ name: "mintDuration", type: "uint64" },
|
|
110
|
+
{ name: "royaltyBPS", type: "uint32" },
|
|
111
|
+
{ name: "payoutRecipient", type: "address" },
|
|
112
|
+
{ name: "fixedPriceMinter", type: "address" },
|
|
113
|
+
{ name: "createReferral", type: "address" }
|
|
114
|
+
]
|
|
115
|
+
};
|
|
116
|
+
var PreminterDomain = "Preminter";
|
|
117
|
+
var PremintConfigVersion = /* @__PURE__ */ ((PremintConfigVersion2) => {
|
|
118
|
+
PremintConfigVersion2["V1"] = "1";
|
|
119
|
+
PremintConfigVersion2["V2"] = "2";
|
|
120
|
+
return PremintConfigVersion2;
|
|
121
|
+
})(PremintConfigVersion || {});
|
|
47
122
|
|
|
48
123
|
// src/premint/preminter.ts
|
|
49
|
-
var
|
|
124
|
+
var getPremintExecutorAddress = () => import_protocol_deployments.zoraCreator1155PremintExecutorImplAddress[999];
|
|
125
|
+
var premintTypedDataDefinition = ({
|
|
50
126
|
verifyingContract,
|
|
51
|
-
|
|
52
|
-
|
|
127
|
+
chainId,
|
|
128
|
+
premintConfigVersion: version,
|
|
129
|
+
premintConfig
|
|
53
130
|
}) => {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// ensure that a signature can be replaced, as long as the replacement
|
|
60
|
-
// has the same uid, and a newer version.
|
|
61
|
-
{ name: "uid", type: "uint32" },
|
|
62
|
-
{ name: "version", type: "uint32" },
|
|
63
|
-
// if this update should result in the signature being deleted.
|
|
64
|
-
{ name: "deleted", type: "bool" }
|
|
65
|
-
],
|
|
66
|
-
TokenCreationConfig: [
|
|
67
|
-
{ name: "tokenURI", type: "string" },
|
|
68
|
-
{ name: "maxSupply", type: "uint256" },
|
|
69
|
-
{ name: "maxTokensPerAddress", type: "uint64" },
|
|
70
|
-
{ name: "pricePerToken", type: "uint96" },
|
|
71
|
-
{ name: "mintStart", type: "uint64" },
|
|
72
|
-
{ name: "mintDuration", type: "uint64" },
|
|
73
|
-
{ name: "royaltyMintSchedule", type: "uint32" },
|
|
74
|
-
{ name: "royaltyBPS", type: "uint32" },
|
|
75
|
-
{ name: "royaltyRecipient", type: "address" },
|
|
76
|
-
{ name: "fixedPriceMinter", type: "address" }
|
|
77
|
-
]
|
|
131
|
+
const domain = {
|
|
132
|
+
chainId,
|
|
133
|
+
name: PreminterDomain,
|
|
134
|
+
version,
|
|
135
|
+
verifyingContract
|
|
78
136
|
};
|
|
79
|
-
|
|
137
|
+
if (version === "1" /* V1 */)
|
|
138
|
+
return {
|
|
139
|
+
domain,
|
|
140
|
+
types: v1Types,
|
|
141
|
+
message: premintConfig,
|
|
142
|
+
primaryType: "CreatorAttribution"
|
|
143
|
+
};
|
|
144
|
+
if (version === "2" /* V2 */) {
|
|
145
|
+
return {
|
|
146
|
+
domain,
|
|
147
|
+
types: v2Types,
|
|
148
|
+
message: premintConfig,
|
|
149
|
+
primaryType: "CreatorAttribution"
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`Invalid version ${version}`);
|
|
153
|
+
};
|
|
154
|
+
async function isAuthorizedToCreatePremint({
|
|
155
|
+
collection,
|
|
156
|
+
collectionAddress,
|
|
157
|
+
publicClient,
|
|
158
|
+
premintConfig,
|
|
159
|
+
premintConfigVersion,
|
|
160
|
+
signature,
|
|
161
|
+
signer
|
|
162
|
+
}) {
|
|
163
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
164
|
+
const [isValidSignature2] = await publicClient.readContract({
|
|
165
|
+
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
166
|
+
address: getPremintExecutorAddress(),
|
|
167
|
+
functionName: "isValidSignature",
|
|
168
|
+
args: [collection, premintConfig, signature]
|
|
169
|
+
});
|
|
170
|
+
return isValidSignature2;
|
|
171
|
+
}
|
|
172
|
+
return await publicClient.readContract({
|
|
173
|
+
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
174
|
+
address: getPremintExecutorAddress(),
|
|
175
|
+
functionName: "isAuthorizedToCreatePremint",
|
|
176
|
+
args: [signer, collection.contractAdmin, collectionAddress]
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async function recoverPremintSigner({
|
|
180
|
+
signature,
|
|
181
|
+
...rest
|
|
182
|
+
}) {
|
|
183
|
+
const typedData = premintTypedDataDefinition(rest);
|
|
184
|
+
return await (0, import_viem.recoverTypedDataAddress)({
|
|
185
|
+
...typedData,
|
|
186
|
+
signature
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
async function tryRecoverPremintSigner(params) {
|
|
190
|
+
try {
|
|
191
|
+
return await recoverPremintSigner(params);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
console.error(error);
|
|
194
|
+
return void 0;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async function isValidSignature({
|
|
198
|
+
signature,
|
|
199
|
+
publicClient,
|
|
200
|
+
collection,
|
|
201
|
+
chainId,
|
|
202
|
+
...premintConfigAndVersion
|
|
203
|
+
}) {
|
|
204
|
+
const tokenContract = await getPremintCollectionAddress({
|
|
205
|
+
collection,
|
|
206
|
+
publicClient
|
|
207
|
+
});
|
|
208
|
+
const recoveredAddress = await tryRecoverPremintSigner({
|
|
209
|
+
...premintConfigAndVersion,
|
|
210
|
+
signature,
|
|
211
|
+
verifyingContract: tokenContract,
|
|
212
|
+
chainId
|
|
213
|
+
});
|
|
214
|
+
if (!import_viem.recoverAddress) {
|
|
215
|
+
return {
|
|
216
|
+
isAuthorized: false
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
220
|
+
signer: recoveredAddress,
|
|
221
|
+
collection,
|
|
222
|
+
collectionAddress: tokenContract,
|
|
223
|
+
publicClient,
|
|
224
|
+
signature,
|
|
225
|
+
...premintConfigAndVersion
|
|
226
|
+
});
|
|
227
|
+
return {
|
|
228
|
+
isAuthorized,
|
|
229
|
+
recoveredAddress
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function migratePremintConfigToV2({
|
|
233
|
+
premintConfig,
|
|
234
|
+
createReferral = import_viem.zeroAddress
|
|
235
|
+
}) {
|
|
236
|
+
return {
|
|
237
|
+
...premintConfig,
|
|
238
|
+
tokenConfig: {
|
|
239
|
+
tokenURI: premintConfig.tokenConfig.tokenURI,
|
|
240
|
+
maxSupply: premintConfig.tokenConfig.maxSupply,
|
|
241
|
+
maxTokensPerAddress: premintConfig.tokenConfig.maxTokensPerAddress,
|
|
242
|
+
pricePerToken: premintConfig.tokenConfig.pricePerToken,
|
|
243
|
+
mintStart: premintConfig.tokenConfig.mintStart,
|
|
244
|
+
mintDuration: premintConfig.tokenConfig.mintDuration,
|
|
245
|
+
payoutRecipient: premintConfig.tokenConfig.royaltyRecipient,
|
|
246
|
+
royaltyBPS: premintConfig.tokenConfig.royaltyBPS,
|
|
247
|
+
fixedPriceMinter: premintConfig.tokenConfig.fixedPriceMinter,
|
|
248
|
+
createReferral
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
var recoverCreatorFromCreatorAttribution = async ({
|
|
253
|
+
creatorAttribution: { version, domainName, structHash, signature },
|
|
254
|
+
chainId,
|
|
255
|
+
tokenContract
|
|
256
|
+
}) => {
|
|
257
|
+
const hashedDomain = (0, import_viem.hashDomain)({
|
|
80
258
|
domain: {
|
|
81
259
|
chainId,
|
|
82
|
-
name:
|
|
83
|
-
|
|
84
|
-
|
|
260
|
+
name: domainName,
|
|
261
|
+
verifyingContract: tokenContract,
|
|
262
|
+
version
|
|
85
263
|
},
|
|
86
|
-
types
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
264
|
+
types: {
|
|
265
|
+
EIP712Domain: [
|
|
266
|
+
{ name: "name", type: "string" },
|
|
267
|
+
{ name: "version", type: "string" },
|
|
268
|
+
{
|
|
269
|
+
name: "chainId",
|
|
270
|
+
type: "uint256"
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: "verifyingContract",
|
|
274
|
+
type: "address"
|
|
275
|
+
}
|
|
276
|
+
]
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
const parts = ["0x1901", hashedDomain, structHash];
|
|
280
|
+
const hashedTypedData = (0, import_viem.keccak256)((0, import_viem.concat)(parts));
|
|
281
|
+
return await (0, import_viem.recoverAddress)({
|
|
282
|
+
hash: hashedTypedData,
|
|
283
|
+
signature
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
var supportedPremintVersions = async ({
|
|
287
|
+
tokenContract,
|
|
288
|
+
publicClient
|
|
289
|
+
}) => {
|
|
290
|
+
try {
|
|
291
|
+
return await publicClient.readContract({
|
|
292
|
+
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
293
|
+
address: getPremintExecutorAddress(),
|
|
294
|
+
functionName: "supportedPremintSignatureVersions",
|
|
295
|
+
args: [tokenContract]
|
|
296
|
+
});
|
|
297
|
+
} catch (e) {
|
|
298
|
+
console.error(e);
|
|
299
|
+
return ["1"];
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
var supportsPremintVersion = async ({
|
|
303
|
+
version,
|
|
304
|
+
tokenContract,
|
|
305
|
+
publicClient
|
|
306
|
+
}) => {
|
|
307
|
+
return (await supportedPremintVersions({ tokenContract, publicClient })).includes(version);
|
|
308
|
+
};
|
|
309
|
+
async function getPremintCollectionAddress({
|
|
310
|
+
collection,
|
|
311
|
+
publicClient
|
|
312
|
+
}) {
|
|
313
|
+
return publicClient.readContract({
|
|
314
|
+
address: getPremintExecutorAddress(),
|
|
315
|
+
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
316
|
+
functionName: "getContractAddress",
|
|
317
|
+
args: [collection]
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
function markPremintDeleted(premintConfig) {
|
|
321
|
+
return {
|
|
322
|
+
...premintConfig,
|
|
323
|
+
version: premintConfig.version + 1,
|
|
324
|
+
deleted: true
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function applyUpdateToPremint({
|
|
328
|
+
uid,
|
|
329
|
+
version,
|
|
330
|
+
tokenConfig,
|
|
331
|
+
tokenConfigUpdates
|
|
332
|
+
}) {
|
|
333
|
+
const updatedTokenConfig = {
|
|
334
|
+
...tokenConfig,
|
|
335
|
+
...tokenConfigUpdates
|
|
336
|
+
};
|
|
337
|
+
const result = {
|
|
338
|
+
deleted: false,
|
|
339
|
+
uid,
|
|
340
|
+
version: version + 1,
|
|
341
|
+
tokenConfig: updatedTokenConfig
|
|
94
342
|
};
|
|
95
343
|
return result;
|
|
96
|
-
}
|
|
344
|
+
}
|
|
345
|
+
function makeNewPremint({
|
|
346
|
+
tokenConfig,
|
|
347
|
+
uid
|
|
348
|
+
}) {
|
|
349
|
+
return {
|
|
350
|
+
deleted: false,
|
|
351
|
+
uid,
|
|
352
|
+
version: 0,
|
|
353
|
+
tokenConfig
|
|
354
|
+
};
|
|
355
|
+
}
|
|
97
356
|
|
|
98
357
|
// src/apis/http-api-base.ts
|
|
99
358
|
var BadResponseError = class extends Error {
|
|
@@ -170,17 +429,22 @@ var httpClient = {
|
|
|
170
429
|
};
|
|
171
430
|
|
|
172
431
|
// src/constants.ts
|
|
432
|
+
var import_viem2 = require("viem");
|
|
173
433
|
var ZORA_API_BASE = "https://api.zora.co/";
|
|
174
434
|
var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
|
|
175
435
|
var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
|
|
176
436
|
function getSubgraph(name, version) {
|
|
177
437
|
return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
|
|
178
438
|
}
|
|
439
|
+
var zora721Abi = (0, import_viem2.parseAbi)([
|
|
440
|
+
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
441
|
+
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
|
|
442
|
+
]);
|
|
179
443
|
|
|
180
444
|
// src/apis/chain-constants.ts
|
|
181
445
|
var import_chains = require("viem/chains");
|
|
182
|
-
var
|
|
183
|
-
var REWARD_PER_TOKEN = (0,
|
|
446
|
+
var import_viem3 = require("viem");
|
|
447
|
+
var REWARD_PER_TOKEN = (0, import_viem3.parseEther)("0.000777");
|
|
184
448
|
var BackendChainNamesLookup = {
|
|
185
449
|
ZORA_MAINNET: "ZORA-MAINNET",
|
|
186
450
|
ZORA_GOERLI: "ZORA-GOERLI",
|
|
@@ -258,9 +522,6 @@ var networkConfigByChain = {
|
|
|
258
522
|
};
|
|
259
523
|
|
|
260
524
|
// src/mint/mint-api-client.ts
|
|
261
|
-
function encodeQueryParameters(params) {
|
|
262
|
-
return new URLSearchParams(params).toString();
|
|
263
|
-
}
|
|
264
525
|
var getApiNetworkConfigForChain = (chainId) => {
|
|
265
526
|
if (!networkConfigByChain[chainId]) {
|
|
266
527
|
throw new Error(`chain id ${chainId} network not configured `);
|
|
@@ -272,59 +533,64 @@ var MintAPIClient = class {
|
|
|
272
533
|
this.httpClient = httpClient2 || httpClient;
|
|
273
534
|
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
274
535
|
}
|
|
275
|
-
async
|
|
276
|
-
|
|
277
|
-
return httpClient2.retries(() => {
|
|
278
|
-
return httpClient2.get(
|
|
279
|
-
`${ZORA_API_BASE}discover/mintables/${path.chain_name}/${path.collection_address}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`
|
|
280
|
-
);
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
async getSalesConfigFixedPrice({
|
|
284
|
-
contractAddress,
|
|
536
|
+
async getSalesConfigAndTokenInfo({
|
|
537
|
+
tokenAddress,
|
|
285
538
|
tokenId
|
|
286
539
|
}) {
|
|
287
540
|
const { retries: retries2, post: post2 } = this.httpClient;
|
|
288
541
|
return retries2(async () => {
|
|
289
542
|
const response = await post2(this.networkConfig.subgraphUrl, {
|
|
290
|
-
query: `
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
543
|
+
query: `
|
|
544
|
+
fragment SaleStrategy on SalesStrategyConfig {
|
|
545
|
+
type
|
|
546
|
+
fixedPrice {
|
|
547
|
+
address
|
|
548
|
+
pricePerToken
|
|
549
|
+
saleEnd
|
|
550
|
+
saleStart
|
|
551
|
+
maxTokensPerAddress
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
query ($id: ID!) {
|
|
556
|
+
zoraCreateToken(id: $id) {
|
|
557
|
+
id
|
|
558
|
+
contract {
|
|
559
|
+
mintFeePerQuantity
|
|
560
|
+
salesStrategies(where: {type: "FIXED_PRICE"}) {
|
|
561
|
+
...SaleStrategy
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
salesStrategies(where: {type: "FIXED_PRICE"}) {
|
|
565
|
+
...SaleStrategy
|
|
301
566
|
}
|
|
302
567
|
}
|
|
303
568
|
}
|
|
304
|
-
|
|
569
|
+
`,
|
|
305
570
|
variables: {
|
|
306
|
-
id:
|
|
571
|
+
id: tokenId !== void 0 ? (
|
|
572
|
+
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
573
|
+
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
574
|
+
) : `${tokenAddress.toLowerCase()}-0`
|
|
307
575
|
}
|
|
308
576
|
});
|
|
309
|
-
const
|
|
577
|
+
const token = response.data?.zoraCreateToken;
|
|
578
|
+
if (!token) {
|
|
579
|
+
throw new Error("Cannot find a token to mint");
|
|
580
|
+
}
|
|
581
|
+
const saleStrategies = tokenId !== void 0 ? token.salesStrategies : token.contract.salesStrategies;
|
|
582
|
+
const fixedPrice = saleStrategies?.sort(
|
|
583
|
+
(a, b) => BigInt(a.fixedPrice.saleEnd) > BigInt(b.fixedPrice.saleEnd) ? 1 : -1
|
|
584
|
+
)?.find(() => true)?.fixedPrice;
|
|
585
|
+
if (!fixedPrice) {
|
|
586
|
+
throw new Error("Cannot find fixed price sale strategy");
|
|
587
|
+
}
|
|
310
588
|
return {
|
|
311
|
-
|
|
312
|
-
|
|
589
|
+
fixedPrice,
|
|
590
|
+
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
|
|
313
591
|
};
|
|
314
592
|
});
|
|
315
593
|
}
|
|
316
|
-
async getMintableForToken({
|
|
317
|
-
tokenContract,
|
|
318
|
-
tokenId
|
|
319
|
-
}) {
|
|
320
|
-
return await this.getMintable(
|
|
321
|
-
{
|
|
322
|
-
chain_name: this.networkConfig.zoraBackendChainName,
|
|
323
|
-
collection_address: tokenContract
|
|
324
|
-
},
|
|
325
|
-
{ token_id: tokenId?.toString() }
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
594
|
};
|
|
329
595
|
|
|
330
596
|
// src/premint/premint-api-client.ts
|
|
@@ -348,39 +614,139 @@ var getSignature = async ({
|
|
|
348
614
|
uid,
|
|
349
615
|
chain_name,
|
|
350
616
|
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
351
|
-
}) =>
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
)
|
|
617
|
+
}) => {
|
|
618
|
+
const result = await retries2(
|
|
619
|
+
() => get2(
|
|
620
|
+
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
|
|
621
|
+
)
|
|
622
|
+
);
|
|
623
|
+
return {
|
|
624
|
+
...result,
|
|
625
|
+
// for now - we stub the backend api to simulate returning v1
|
|
626
|
+
premint_config_version: "1" /* V1 */
|
|
627
|
+
};
|
|
628
|
+
};
|
|
629
|
+
var convertCollection = (collection) => ({
|
|
630
|
+
...collection,
|
|
631
|
+
contractAdmin: collection.contractAdmin
|
|
632
|
+
});
|
|
633
|
+
var convertPremintV1 = (premint) => ({
|
|
634
|
+
...premint,
|
|
635
|
+
tokenConfig: {
|
|
636
|
+
...premint.tokenConfig,
|
|
637
|
+
fixedPriceMinter: premint.tokenConfig.fixedPriceMinter,
|
|
638
|
+
royaltyRecipient: premint.tokenConfig.royaltyRecipient,
|
|
639
|
+
maxSupply: BigInt(premint.tokenConfig.maxSupply),
|
|
640
|
+
pricePerToken: BigInt(premint.tokenConfig.pricePerToken),
|
|
641
|
+
mintStart: BigInt(premint.tokenConfig.mintStart),
|
|
642
|
+
mintDuration: BigInt(premint.tokenConfig.mintDuration),
|
|
643
|
+
maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress)
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
var encodePremintV1ForAPI = ({
|
|
647
|
+
tokenConfig,
|
|
648
|
+
...premint
|
|
649
|
+
}) => ({
|
|
650
|
+
...premint,
|
|
651
|
+
tokenConfig: {
|
|
652
|
+
...tokenConfig,
|
|
653
|
+
maxSupply: tokenConfig.maxSupply.toString(),
|
|
654
|
+
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
655
|
+
mintStart: tokenConfig.mintStart.toString(),
|
|
656
|
+
mintDuration: tokenConfig.mintDuration.toString(),
|
|
657
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
var encodePremintV2ForAPI = ({
|
|
661
|
+
tokenConfig,
|
|
662
|
+
...premint
|
|
663
|
+
}) => ({
|
|
664
|
+
...premint,
|
|
665
|
+
tokenConfig: {
|
|
666
|
+
...tokenConfig,
|
|
667
|
+
maxSupply: tokenConfig.maxSupply.toString(),
|
|
668
|
+
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
669
|
+
mintStart: tokenConfig.mintStart.toString(),
|
|
670
|
+
mintDuration: tokenConfig.mintDuration.toString(),
|
|
671
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
var encodePremintForAPI = ({
|
|
675
|
+
premintConfig,
|
|
676
|
+
premintConfigVersion
|
|
677
|
+
}) => {
|
|
678
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
679
|
+
return encodePremintV1ForAPI(premintConfig);
|
|
680
|
+
}
|
|
681
|
+
if (premintConfigVersion === "2" /* V2 */) {
|
|
682
|
+
return encodePremintV2ForAPI(premintConfig);
|
|
683
|
+
}
|
|
684
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
685
|
+
};
|
|
356
686
|
var PremintAPIClient = class {
|
|
357
687
|
constructor(chainId, httpClient2) {
|
|
358
|
-
this.postSignature = async (
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
688
|
+
this.postSignature = async ({
|
|
689
|
+
collection,
|
|
690
|
+
premintConfigVersion,
|
|
691
|
+
premintConfig,
|
|
692
|
+
signature
|
|
693
|
+
}) => {
|
|
694
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
695
|
+
const data = {
|
|
696
|
+
premint: encodePremintForAPI({
|
|
697
|
+
premintConfig,
|
|
698
|
+
premintConfigVersion
|
|
699
|
+
}),
|
|
700
|
+
signature,
|
|
701
|
+
collection
|
|
702
|
+
};
|
|
703
|
+
return postSignature({
|
|
704
|
+
...data,
|
|
705
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
706
|
+
httpClient: this.httpClient
|
|
707
|
+
});
|
|
708
|
+
} else {
|
|
709
|
+
throw new Error("Unsupported premint config version");
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
this.getNextUID = async (collectionAddress) => (await getNextUID({
|
|
713
|
+
collection_address: collectionAddress.toLowerCase(),
|
|
365
714
|
chain_name: this.networkConfig.zoraBackendChainName,
|
|
366
715
|
httpClient: this.httpClient
|
|
367
|
-
});
|
|
716
|
+
})).next_uid;
|
|
368
717
|
this.getSignature = async ({
|
|
369
|
-
|
|
718
|
+
collectionAddress,
|
|
370
719
|
uid
|
|
371
|
-
}) =>
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
720
|
+
}) => {
|
|
721
|
+
const response = await getSignature({
|
|
722
|
+
collection_address: collectionAddress.toLowerCase(),
|
|
723
|
+
uid,
|
|
724
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
725
|
+
httpClient: this.httpClient
|
|
726
|
+
});
|
|
727
|
+
const premintConfigVersion = response.premint_config_version || "1" /* V1 */;
|
|
728
|
+
let premintConfig;
|
|
729
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
730
|
+
premintConfig = convertPremintV1(response.premint);
|
|
731
|
+
} else {
|
|
732
|
+
throw new Error(
|
|
733
|
+
`Unsupported premint config version: ${premintConfigVersion}`
|
|
734
|
+
);
|
|
735
|
+
}
|
|
736
|
+
return {
|
|
737
|
+
signature: response.signature,
|
|
738
|
+
collection: convertCollection(response.collection),
|
|
739
|
+
premintConfig,
|
|
740
|
+
premintConfigVersion
|
|
741
|
+
};
|
|
742
|
+
};
|
|
377
743
|
this.httpClient = httpClient2 || httpClient;
|
|
378
744
|
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
379
745
|
}
|
|
380
746
|
};
|
|
381
747
|
|
|
382
748
|
// src/premint/premint-client.ts
|
|
383
|
-
var
|
|
749
|
+
var defaultTokenConfigV1MintArguments = () => ({
|
|
384
750
|
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
385
751
|
maxTokensPerAddress: 0n,
|
|
386
752
|
pricePerToken: 0n,
|
|
@@ -390,12 +756,47 @@ var DefaultMintArguments = {
|
|
|
390
756
|
royaltyMintSchedule: 0,
|
|
391
757
|
royaltyBPS: 1e3
|
|
392
758
|
// 10%,
|
|
759
|
+
});
|
|
760
|
+
var defaultTokenConfigV2MintArguments = () => ({
|
|
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
|
+
royaltyBPS: 1e3
|
|
768
|
+
// 10%,
|
|
769
|
+
});
|
|
770
|
+
var makeTokenConfigWithDefaults = ({
|
|
771
|
+
premintConfigVersion,
|
|
772
|
+
tokenCreationConfig,
|
|
773
|
+
creatorAccount
|
|
774
|
+
}) => {
|
|
775
|
+
const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress();
|
|
776
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
777
|
+
return {
|
|
778
|
+
fixedPriceMinter,
|
|
779
|
+
...defaultTokenConfigV1MintArguments(),
|
|
780
|
+
royaltyRecipient: creatorAccount,
|
|
781
|
+
...tokenCreationConfig
|
|
782
|
+
};
|
|
783
|
+
} else if (premintConfigVersion === "2" /* V2 */) {
|
|
784
|
+
return {
|
|
785
|
+
fixedPriceMinter,
|
|
786
|
+
...defaultTokenConfigV2MintArguments(),
|
|
787
|
+
payoutRecipient: creatorAccount,
|
|
788
|
+
createReferral: import_viem4.zeroAddress,
|
|
789
|
+
...tokenCreationConfig
|
|
790
|
+
};
|
|
791
|
+
} else {
|
|
792
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
793
|
+
}
|
|
393
794
|
};
|
|
394
795
|
function getPremintedLogFromReceipt(receipt) {
|
|
395
796
|
for (const data of receipt.logs) {
|
|
396
797
|
try {
|
|
397
|
-
const decodedLog = (0,
|
|
398
|
-
abi:
|
|
798
|
+
const decodedLog = (0, import_viem4.decodeEventLog)({
|
|
799
|
+
abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
|
|
399
800
|
eventName: "Preminted",
|
|
400
801
|
...data
|
|
401
802
|
});
|
|
@@ -406,61 +807,11 @@ function getPremintedLogFromReceipt(receipt) {
|
|
|
406
807
|
}
|
|
407
808
|
}
|
|
408
809
|
}
|
|
409
|
-
var convertPremint = (premint) => ({
|
|
410
|
-
...premint,
|
|
411
|
-
tokenConfig: {
|
|
412
|
-
...premint.tokenConfig,
|
|
413
|
-
fixedPriceMinter: premint.tokenConfig.fixedPriceMinter,
|
|
414
|
-
royaltyRecipient: premint.tokenConfig.royaltyRecipient,
|
|
415
|
-
maxSupply: BigInt(premint.tokenConfig.maxSupply),
|
|
416
|
-
pricePerToken: BigInt(premint.tokenConfig.pricePerToken),
|
|
417
|
-
mintStart: BigInt(premint.tokenConfig.mintStart),
|
|
418
|
-
mintDuration: BigInt(premint.tokenConfig.mintDuration),
|
|
419
|
-
maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress)
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
var convertCollection = (collection) => ({
|
|
423
|
-
...collection,
|
|
424
|
-
contractAdmin: collection.contractAdmin
|
|
425
|
-
});
|
|
426
|
-
var encodePremintForAPI = ({
|
|
427
|
-
tokenConfig,
|
|
428
|
-
...premint
|
|
429
|
-
}) => ({
|
|
430
|
-
...premint,
|
|
431
|
-
tokenConfig: {
|
|
432
|
-
...tokenConfig,
|
|
433
|
-
maxSupply: tokenConfig.maxSupply.toString(),
|
|
434
|
-
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
435
|
-
mintStart: tokenConfig.mintStart.toString(),
|
|
436
|
-
mintDuration: tokenConfig.mintDuration.toString(),
|
|
437
|
-
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
810
|
var PremintClient = class {
|
|
441
811
|
constructor(chain, publicClient, httpClient2) {
|
|
442
812
|
this.chain = chain;
|
|
443
813
|
this.apiClient = new PremintAPIClient(chain.id, httpClient2);
|
|
444
|
-
this.publicClient = publicClient || (0,
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* The premint executor address is deployed to the same address across all chains.
|
|
448
|
-
* Can be overridden as needed by making a parent class.
|
|
449
|
-
*
|
|
450
|
-
* @returns Executor address for premints
|
|
451
|
-
*/
|
|
452
|
-
getExecutorAddress() {
|
|
453
|
-
return import_protocol_deployments.zoraCreator1155PremintExecutorImplAddress[999];
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* The fixed price minter address is the same across all chains for our current
|
|
457
|
-
* deployer strategy.
|
|
458
|
-
* Can be overridden as needed by making a parent class.
|
|
459
|
-
*
|
|
460
|
-
* @returns Fixed price sale strategy
|
|
461
|
-
*/
|
|
462
|
-
getFixedPriceMinterAddress() {
|
|
463
|
-
return import_protocol_deployments.zoraCreatorFixedPriceSaleStrategyAddress[999];
|
|
814
|
+
this.publicClient = publicClient || (0, import_viem4.createPublicClient)({ chain, transport: (0, import_viem4.http)() });
|
|
464
815
|
}
|
|
465
816
|
getDataFromPremintReceipt(receipt) {
|
|
466
817
|
const premintedLog = getPremintedLogFromReceipt(receipt);
|
|
@@ -494,35 +845,31 @@ var PremintClient = class {
|
|
|
494
845
|
walletClient,
|
|
495
846
|
uid,
|
|
496
847
|
collection,
|
|
497
|
-
|
|
498
|
-
|
|
848
|
+
account,
|
|
849
|
+
tokenConfigUpdates
|
|
499
850
|
}) {
|
|
500
|
-
const
|
|
501
|
-
|
|
851
|
+
const {
|
|
852
|
+
premintConfig,
|
|
853
|
+
collection: collectionCreationConfig,
|
|
854
|
+
premintConfigVersion
|
|
855
|
+
} = await this.apiClient.getSignature({
|
|
856
|
+
collectionAddress: collection,
|
|
502
857
|
uid
|
|
503
858
|
});
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
...convertedPremint.tokenConfig,
|
|
511
|
-
...token
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
};
|
|
859
|
+
const updatedPremint = applyUpdateToPremint({
|
|
860
|
+
uid: premintConfig.uid,
|
|
861
|
+
version: premintConfig.version,
|
|
862
|
+
tokenConfig: premintConfig.tokenConfig,
|
|
863
|
+
tokenConfigUpdates
|
|
864
|
+
});
|
|
515
865
|
return await this.signAndSubmitPremint({
|
|
516
866
|
walletClient,
|
|
517
867
|
account,
|
|
518
|
-
checkSignature:
|
|
868
|
+
checkSignature: true,
|
|
519
869
|
verifyingContract: collection,
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
contractAdmin: signerData.collection.contractAdmin
|
|
524
|
-
},
|
|
525
|
-
premintConfig: signerData.premint
|
|
870
|
+
collection: collectionCreationConfig,
|
|
871
|
+
premintConfig: updatedPremint,
|
|
872
|
+
premintConfigVersion
|
|
526
873
|
});
|
|
527
874
|
}
|
|
528
875
|
/**
|
|
@@ -545,26 +892,23 @@ var PremintClient = class {
|
|
|
545
892
|
account,
|
|
546
893
|
collection
|
|
547
894
|
}) {
|
|
548
|
-
const
|
|
549
|
-
|
|
895
|
+
const {
|
|
896
|
+
premintConfig,
|
|
897
|
+
premintConfigVersion,
|
|
898
|
+
collection: collectionCreationConfig
|
|
899
|
+
} = await this.apiClient.getSignature({
|
|
900
|
+
collectionAddress: collection,
|
|
550
901
|
uid
|
|
551
902
|
});
|
|
552
|
-
const
|
|
553
|
-
...signatureResponse,
|
|
554
|
-
collection: convertCollection(signatureResponse.collection),
|
|
555
|
-
premint: {
|
|
556
|
-
...convertPremint(signatureResponse.premint),
|
|
557
|
-
deleted: true
|
|
558
|
-
}
|
|
559
|
-
};
|
|
903
|
+
const deletedPremint = markPremintDeleted(premintConfig);
|
|
560
904
|
return await this.signAndSubmitPremint({
|
|
561
905
|
walletClient,
|
|
562
906
|
account,
|
|
563
907
|
checkSignature: false,
|
|
564
908
|
verifyingContract: collection,
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
909
|
+
collection: collectionCreationConfig,
|
|
910
|
+
premintConfig: deletedPremint,
|
|
911
|
+
premintConfigVersion
|
|
568
912
|
});
|
|
569
913
|
}
|
|
570
914
|
/**
|
|
@@ -573,46 +917,14 @@ var PremintClient = class {
|
|
|
573
917
|
* @param premintArguments Arguments to premint
|
|
574
918
|
* @returns
|
|
575
919
|
*/
|
|
576
|
-
async signAndSubmitPremint({
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
checkSignature,
|
|
583
|
-
collection
|
|
584
|
-
}) {
|
|
585
|
-
if (!account) {
|
|
586
|
-
account = walletClient.account;
|
|
587
|
-
}
|
|
588
|
-
if (!account) {
|
|
589
|
-
throw new Error("No account provided");
|
|
590
|
-
}
|
|
591
|
-
const signature = await walletClient.signTypedData({
|
|
592
|
-
account,
|
|
593
|
-
...preminterTypedDataDefinition({
|
|
594
|
-
verifyingContract,
|
|
595
|
-
premintConfig,
|
|
596
|
-
chainId: this.chain.id
|
|
597
|
-
})
|
|
920
|
+
async signAndSubmitPremint(params) {
|
|
921
|
+
const { premint, verifyingContract } = await signAndSubmitPremint({
|
|
922
|
+
...params,
|
|
923
|
+
chainId: this.chain.id,
|
|
924
|
+
apiClient: this.apiClient,
|
|
925
|
+
publicClient: this.publicClient
|
|
598
926
|
});
|
|
599
|
-
|
|
600
|
-
const [isValidSignature] = await this.publicClient.readContract({
|
|
601
|
-
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
602
|
-
address: this.getExecutorAddress(),
|
|
603
|
-
functionName: "isValidSignature",
|
|
604
|
-
args: [convertCollection(collection), premintConfig, signature]
|
|
605
|
-
});
|
|
606
|
-
if (!isValidSignature) {
|
|
607
|
-
throw new Error("Invalid signature");
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
const apiData = {
|
|
611
|
-
collection,
|
|
612
|
-
premint: encodePremintForAPI(premintConfig),
|
|
613
|
-
signature
|
|
614
|
-
};
|
|
615
|
-
const premint = await this.apiClient.postSignature(apiData);
|
|
927
|
+
const uid = params.premintConfig.uid;
|
|
616
928
|
return {
|
|
617
929
|
urls: this.makeUrls({ address: verifyingContract, uid }),
|
|
618
930
|
uid,
|
|
@@ -626,58 +938,53 @@ var PremintClient = class {
|
|
|
626
938
|
* @param settings Settings for the new premint
|
|
627
939
|
* @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
|
|
628
940
|
* @param settings.collection Collection information for the mint
|
|
629
|
-
* @param settings.
|
|
630
|
-
* @param
|
|
631
|
-
* @param settings.
|
|
632
|
-
* @param settings.executionSettings Execution settings for premint options
|
|
633
|
-
* @param settings.executionSettings.deleted If this UID should be deleted. If omitted, set to false.
|
|
634
|
-
* @param settings.executionSettings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
|
|
941
|
+
* @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
|
|
942
|
+
* @param setings.premintConfigVersion Premint config version to use, defaults to V2
|
|
943
|
+
* @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
|
|
635
944
|
* @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
|
|
636
945
|
* @returns premint url, uid, newContractAddress, and premint object
|
|
637
946
|
*/
|
|
638
947
|
async createPremint({
|
|
639
|
-
|
|
948
|
+
creatorAccount,
|
|
640
949
|
collection,
|
|
641
|
-
|
|
950
|
+
tokenCreationConfig,
|
|
951
|
+
premintConfigVersion,
|
|
642
952
|
walletClient,
|
|
643
|
-
|
|
953
|
+
uid,
|
|
644
954
|
checkSignature = false
|
|
645
955
|
}) {
|
|
646
|
-
const newContractAddress = await
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
functionName: "getContractAddress",
|
|
650
|
-
args: [convertCollection(collection)]
|
|
956
|
+
const newContractAddress = await getPremintCollectionAddress({
|
|
957
|
+
publicClient: this.publicClient,
|
|
958
|
+
collection
|
|
651
959
|
});
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
royaltyRecipient: account,
|
|
656
|
-
...token
|
|
657
|
-
};
|
|
658
|
-
let uid = executionSettings?.uid;
|
|
659
|
-
if (!uid) {
|
|
660
|
-
const uidResponse = await this.apiClient.getNextUID({
|
|
661
|
-
collection_address: newContractAddress.toLowerCase()
|
|
662
|
-
});
|
|
663
|
-
uid = uidResponse.next_uid;
|
|
960
|
+
let uidToUse = uid;
|
|
961
|
+
if (typeof uidToUse !== "number") {
|
|
962
|
+
uidToUse = await this.apiClient.getNextUID(newContractAddress);
|
|
664
963
|
}
|
|
665
|
-
|
|
666
|
-
|
|
964
|
+
const actualVersion = premintConfigVersion || "1" /* V1 */;
|
|
965
|
+
if (!await supportsPremintVersion({
|
|
966
|
+
version: actualVersion,
|
|
967
|
+
publicClient: this.publicClient,
|
|
968
|
+
tokenContract: newContractAddress
|
|
969
|
+
})) {
|
|
970
|
+
throw new Error(
|
|
971
|
+
`Premint version ${actualVersion} not supported by contract`
|
|
972
|
+
);
|
|
667
973
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
974
|
+
const premintConfig = makeNewPremint({
|
|
975
|
+
tokenConfig: makeTokenConfigWithDefaults({
|
|
976
|
+
premintConfigVersion: actualVersion,
|
|
977
|
+
tokenCreationConfig,
|
|
978
|
+
creatorAccount
|
|
979
|
+
}),
|
|
980
|
+
uid: uidToUse
|
|
981
|
+
});
|
|
675
982
|
return await this.signAndSubmitPremint({
|
|
676
|
-
uid,
|
|
677
983
|
verifyingContract: newContractAddress,
|
|
678
984
|
premintConfig,
|
|
985
|
+
premintConfigVersion: actualVersion,
|
|
679
986
|
checkSignature,
|
|
680
|
-
account,
|
|
987
|
+
account: creatorAccount,
|
|
681
988
|
walletClient,
|
|
682
989
|
collection
|
|
683
990
|
});
|
|
@@ -689,51 +996,59 @@ var PremintClient = class {
|
|
|
689
996
|
* @param uid UID for the desired premint
|
|
690
997
|
* @returns PremintSignatureGetResponse of premint data from the API
|
|
691
998
|
*/
|
|
692
|
-
async
|
|
999
|
+
async getPremintSignature({
|
|
693
1000
|
address,
|
|
694
1001
|
uid
|
|
695
1002
|
}) {
|
|
696
1003
|
return await this.apiClient.getSignature({
|
|
697
|
-
|
|
1004
|
+
collectionAddress: address,
|
|
698
1005
|
uid
|
|
699
1006
|
});
|
|
700
1007
|
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Gets the deterministic contract address for a premint collection
|
|
1010
|
+
* @param collection Collection to get the address for
|
|
1011
|
+
* @returns deterministic contract address
|
|
1012
|
+
*/
|
|
1013
|
+
async getCollectionAddress(collection) {
|
|
1014
|
+
return await getPremintCollectionAddress({
|
|
1015
|
+
collection,
|
|
1016
|
+
publicClient: this.publicClient
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
701
1019
|
/**
|
|
702
1020
|
* Check user signature for v1
|
|
703
1021
|
*
|
|
704
1022
|
* @param data Signature data from the API
|
|
705
|
-
* @returns isValid = signature is valid or not,
|
|
1023
|
+
* @returns isValid = signature is valid or not, recoveredSigner = signer from contract
|
|
706
1024
|
*/
|
|
707
1025
|
async isValidSignature({
|
|
708
|
-
|
|
1026
|
+
signature,
|
|
1027
|
+
collection,
|
|
1028
|
+
premintConfig,
|
|
1029
|
+
premintConfigVersion
|
|
709
1030
|
}) {
|
|
710
|
-
const
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
data.signature
|
|
718
|
-
]
|
|
1031
|
+
const { isAuthorized, recoveredAddress } = await isValidSignature({
|
|
1032
|
+
chainId: this.chain.id,
|
|
1033
|
+
signature,
|
|
1034
|
+
collection,
|
|
1035
|
+
publicClient: this.publicClient,
|
|
1036
|
+
premintConfig,
|
|
1037
|
+
premintConfigVersion: premintConfigVersion || "1" /* V1 */
|
|
719
1038
|
});
|
|
720
|
-
return { isValid
|
|
1039
|
+
return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
|
|
721
1040
|
}
|
|
722
1041
|
makeUrls({
|
|
723
1042
|
uid,
|
|
724
1043
|
address,
|
|
725
1044
|
tokenId
|
|
726
1045
|
}) {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
explorer: tokenId ? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
|
|
734
|
-
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
|
|
735
|
-
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
|
|
736
|
-
};
|
|
1046
|
+
return makeUrls({
|
|
1047
|
+
uid,
|
|
1048
|
+
address,
|
|
1049
|
+
tokenId,
|
|
1050
|
+
chain: this.chain
|
|
1051
|
+
});
|
|
737
1052
|
}
|
|
738
1053
|
/**
|
|
739
1054
|
* Execute premint on-chain
|
|
@@ -748,35 +1063,62 @@ var PremintClient = class {
|
|
|
748
1063
|
* @returns receipt, log, zoraURL
|
|
749
1064
|
*/
|
|
750
1065
|
async makeMintParameters({
|
|
751
|
-
|
|
1066
|
+
uid,
|
|
1067
|
+
tokenContract,
|
|
752
1068
|
account,
|
|
753
1069
|
mintArguments
|
|
754
1070
|
}) {
|
|
755
1071
|
if (mintArguments && mintArguments?.quantityToMint < 1) {
|
|
756
1072
|
throw new Error("Quantity to mint cannot be below 1");
|
|
757
1073
|
}
|
|
758
|
-
const targetAddress = this.getExecutorAddress();
|
|
759
|
-
const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
|
|
760
|
-
const args = [
|
|
761
|
-
convertCollection(data.collection),
|
|
762
|
-
convertPremint(data.premint),
|
|
763
|
-
data.signature,
|
|
764
|
-
numberToMint,
|
|
765
|
-
mintArguments?.mintComment || ""
|
|
766
|
-
];
|
|
767
1074
|
if (!account) {
|
|
768
1075
|
throw new Error("Wallet not passed in");
|
|
769
1076
|
}
|
|
1077
|
+
const { premintConfig, premintConfigVersion, collection, signature } = await this.getPremintSignature({
|
|
1078
|
+
address: tokenContract,
|
|
1079
|
+
uid
|
|
1080
|
+
});
|
|
1081
|
+
const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
|
|
770
1082
|
const value = numberToMint * REWARD_PER_TOKEN;
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
1083
|
+
if (premintConfigVersion === "1" /* V1 */) {
|
|
1084
|
+
return {
|
|
1085
|
+
account,
|
|
1086
|
+
abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
|
|
1087
|
+
functionName: "premint",
|
|
1088
|
+
value,
|
|
1089
|
+
address: getPremintExecutorAddress(),
|
|
1090
|
+
args: [
|
|
1091
|
+
collection,
|
|
1092
|
+
premintConfig,
|
|
1093
|
+
signature,
|
|
1094
|
+
numberToMint,
|
|
1095
|
+
mintArguments?.mintComment || ""
|
|
1096
|
+
]
|
|
1097
|
+
};
|
|
1098
|
+
} else if (premintConfigVersion === "2" /* V2 */) {
|
|
1099
|
+
const toPost = premintConfig;
|
|
1100
|
+
const accountAddress = typeof account === "string" ? account : account.address;
|
|
1101
|
+
return {
|
|
1102
|
+
account,
|
|
1103
|
+
abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
|
|
1104
|
+
functionName: "premintV2",
|
|
1105
|
+
value,
|
|
1106
|
+
address: getPremintExecutorAddress(),
|
|
1107
|
+
// args are: ContractCreationConfig calldata contractConfig, PremintConfigV2 calldata premintConfig, bytes calldata signature, uint256 quantityToMint, MintArguments calldata mintArguments
|
|
1108
|
+
args: [
|
|
1109
|
+
collection,
|
|
1110
|
+
toPost,
|
|
1111
|
+
signature,
|
|
1112
|
+
numberToMint,
|
|
1113
|
+
{
|
|
1114
|
+
mintComment: mintArguments?.mintComment || "",
|
|
1115
|
+
mintRecipient: mintArguments?.mintRecipient || accountAddress,
|
|
1116
|
+
mintReferral: mintArguments?.mintReferral || import_viem4.zeroAddress
|
|
1117
|
+
}
|
|
1118
|
+
]
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
780
1122
|
}
|
|
781
1123
|
};
|
|
782
1124
|
function createPremintClient({
|
|
@@ -786,10 +1128,78 @@ function createPremintClient({
|
|
|
786
1128
|
}) {
|
|
787
1129
|
return new PremintClient(chain, publicClient, httpClient2);
|
|
788
1130
|
}
|
|
1131
|
+
function makeUrls({
|
|
1132
|
+
uid,
|
|
1133
|
+
address,
|
|
1134
|
+
tokenId,
|
|
1135
|
+
chain
|
|
1136
|
+
}) {
|
|
1137
|
+
if ((!uid || !tokenId) && !address) {
|
|
1138
|
+
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
1139
|
+
}
|
|
1140
|
+
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
1141
|
+
const network = getApiNetworkConfigForChain(chain.id);
|
|
1142
|
+
return {
|
|
1143
|
+
explorer: tokenId ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
|
|
1144
|
+
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
|
|
1145
|
+
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
async function signAndSubmitPremint({
|
|
1149
|
+
walletClient,
|
|
1150
|
+
verifyingContract,
|
|
1151
|
+
account,
|
|
1152
|
+
checkSignature,
|
|
1153
|
+
collection,
|
|
1154
|
+
chainId,
|
|
1155
|
+
publicClient,
|
|
1156
|
+
apiClient,
|
|
1157
|
+
...premintConfigAndVersion
|
|
1158
|
+
}) {
|
|
1159
|
+
if (!account) {
|
|
1160
|
+
account = walletClient.account;
|
|
1161
|
+
}
|
|
1162
|
+
if (!account) {
|
|
1163
|
+
throw new Error("No account provided");
|
|
1164
|
+
}
|
|
1165
|
+
const signature = await walletClient.signTypedData({
|
|
1166
|
+
account,
|
|
1167
|
+
...premintTypedDataDefinition({
|
|
1168
|
+
verifyingContract,
|
|
1169
|
+
...premintConfigAndVersion,
|
|
1170
|
+
chainId
|
|
1171
|
+
})
|
|
1172
|
+
});
|
|
1173
|
+
if (checkSignature) {
|
|
1174
|
+
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
1175
|
+
collection,
|
|
1176
|
+
signature,
|
|
1177
|
+
publicClient,
|
|
1178
|
+
signer: typeof account === "string" ? account : account.address,
|
|
1179
|
+
collectionAddress: await getPremintCollectionAddress({
|
|
1180
|
+
collection,
|
|
1181
|
+
publicClient
|
|
1182
|
+
}),
|
|
1183
|
+
...premintConfigAndVersion
|
|
1184
|
+
});
|
|
1185
|
+
if (!isAuthorized) {
|
|
1186
|
+
throw new Error("Not authorized to create premint");
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
const premint = await apiClient.postSignature({
|
|
1190
|
+
collection,
|
|
1191
|
+
signature,
|
|
1192
|
+
...premintConfigAndVersion
|
|
1193
|
+
});
|
|
1194
|
+
return { premint, verifyingContract };
|
|
1195
|
+
}
|
|
1196
|
+
function getDefaultFixedPriceMinterAddress() {
|
|
1197
|
+
return import_protocol_deployments2.zoraCreatorFixedPriceSaleStrategyAddress[999];
|
|
1198
|
+
}
|
|
789
1199
|
|
|
790
1200
|
// src/mint/mint-client.ts
|
|
791
|
-
var
|
|
792
|
-
var
|
|
1201
|
+
var import_viem5 = require("viem");
|
|
1202
|
+
var import_protocol_deployments3 = require("@zoralabs/protocol-deployments");
|
|
793
1203
|
var MintError = class extends Error {
|
|
794
1204
|
};
|
|
795
1205
|
var MintInactiveError = class extends Error {
|
|
@@ -798,29 +1208,10 @@ var Errors = {
|
|
|
798
1208
|
MintError,
|
|
799
1209
|
MintInactiveError
|
|
800
1210
|
};
|
|
801
|
-
var zora721Abi = (0, import_viem3.parseAbi)([
|
|
802
|
-
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
803
|
-
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
|
|
804
|
-
]);
|
|
805
1211
|
var MintClient = class {
|
|
806
1212
|
constructor(chain, publicClient, httpClient2) {
|
|
807
1213
|
this.apiClient = new MintAPIClient(chain.id, httpClient2);
|
|
808
|
-
this.publicClient = publicClient || (0,
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* Gets mintable information for a given token
|
|
812
|
-
* @param param0.tokenContract The contract address of the token to mint.
|
|
813
|
-
* @param param0.tokenId The token id to mint.
|
|
814
|
-
* @returns
|
|
815
|
-
*/
|
|
816
|
-
async getMintable({
|
|
817
|
-
tokenContract,
|
|
818
|
-
tokenId
|
|
819
|
-
}) {
|
|
820
|
-
return await this.apiClient.getMintableForToken({
|
|
821
|
-
tokenContract,
|
|
822
|
-
tokenId: tokenId?.toString()
|
|
823
|
-
});
|
|
1214
|
+
this.publicClient = publicClient || (0, import_viem5.createPublicClient)({ chain, transport: (0, import_viem5.http)() });
|
|
824
1215
|
}
|
|
825
1216
|
/**
|
|
826
1217
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
@@ -838,36 +1229,6 @@ var MintClient = class {
|
|
|
838
1229
|
publicClient: this.publicClient
|
|
839
1230
|
});
|
|
840
1231
|
}
|
|
841
|
-
/**
|
|
842
|
-
* Returns the mintFee, sale fee, and total cost of minting x quantities of a token.
|
|
843
|
-
* @param param0.mintable The mintable token to mint.
|
|
844
|
-
* @param param0.quantityToMint The quantity of tokens to mint.
|
|
845
|
-
* @returns
|
|
846
|
-
*/
|
|
847
|
-
async getMintCosts({
|
|
848
|
-
mintable,
|
|
849
|
-
quantityToMint
|
|
850
|
-
}) {
|
|
851
|
-
const mintContextType = validateMintableAndGetContextType(mintable);
|
|
852
|
-
if (mintContextType === "zora_create_1155") {
|
|
853
|
-
return await get1155MintCosts({
|
|
854
|
-
mintable,
|
|
855
|
-
price: BigInt(mintable.cost.native_price.raw),
|
|
856
|
-
publicClient: this.publicClient,
|
|
857
|
-
quantityToMint: BigInt(quantityToMint)
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
if (mintContextType === "zora_create") {
|
|
861
|
-
return await get721MintCosts({
|
|
862
|
-
mintable,
|
|
863
|
-
publicClient: this.publicClient,
|
|
864
|
-
quantityToMint: BigInt(quantityToMint)
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
throw new MintError(
|
|
868
|
-
`Mintable type ${mintContextType} is currently unsupported.`
|
|
869
|
-
);
|
|
870
|
-
}
|
|
871
1232
|
};
|
|
872
1233
|
function createMintClient({
|
|
873
1234
|
chain,
|
|
@@ -876,91 +1237,44 @@ function createMintClient({
|
|
|
876
1237
|
}) {
|
|
877
1238
|
return new MintClient(chain, publicClient, httpClient2);
|
|
878
1239
|
}
|
|
879
|
-
function validateMintableAndGetContextType(mintable) {
|
|
880
|
-
if (!mintable) {
|
|
881
|
-
throw new MintError("No mintable found");
|
|
882
|
-
}
|
|
883
|
-
if (!mintable.is_active) {
|
|
884
|
-
throw new MintInactiveError("Minting token is inactive");
|
|
885
|
-
}
|
|
886
|
-
if (!mintable.mint_context) {
|
|
887
|
-
throw new MintError("No minting context data from zora API");
|
|
888
|
-
}
|
|
889
|
-
if (!["zora_create", "zora_create_1155"].includes(
|
|
890
|
-
mintable.mint_context?.mint_context_type
|
|
891
|
-
)) {
|
|
892
|
-
throw new MintError(
|
|
893
|
-
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`
|
|
894
|
-
);
|
|
895
|
-
}
|
|
896
|
-
return mintable.mint_context.mint_context_type;
|
|
897
|
-
}
|
|
898
1240
|
async function makePrepareMintTokenParams({
|
|
899
1241
|
publicClient,
|
|
900
|
-
mintable,
|
|
901
1242
|
apiClient,
|
|
1243
|
+
tokenId,
|
|
1244
|
+
tokenAddress,
|
|
902
1245
|
...rest
|
|
903
1246
|
}) {
|
|
904
|
-
const
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
publicClient: thisPublicClient,
|
|
910
|
-
mintable,
|
|
911
|
-
mintContextType,
|
|
912
|
-
...rest
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
if (mintContextType === "zora_create") {
|
|
1247
|
+
const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
|
|
1248
|
+
tokenId,
|
|
1249
|
+
tokenAddress
|
|
1250
|
+
});
|
|
1251
|
+
if (tokenId === void 0) {
|
|
916
1252
|
return makePrepareMint721TokenParams({
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
mintContextType,
|
|
1253
|
+
salesConfigAndTokenInfo,
|
|
1254
|
+
tokenAddress,
|
|
920
1255
|
...rest
|
|
921
1256
|
});
|
|
922
1257
|
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
mintable,
|
|
929
|
-
publicClient,
|
|
930
|
-
quantityToMint
|
|
931
|
-
}) {
|
|
932
|
-
const address = mintable.collection.address;
|
|
933
|
-
const [_, mintFee] = await publicClient.readContract({
|
|
934
|
-
abi: zora721Abi,
|
|
935
|
-
address,
|
|
936
|
-
functionName: "zoraFeeForAmount",
|
|
937
|
-
args: [BigInt(quantityToMint)]
|
|
1258
|
+
return makePrepareMint1155TokenParams({
|
|
1259
|
+
salesConfigAndTokenInfo,
|
|
1260
|
+
tokenAddress,
|
|
1261
|
+
tokenId,
|
|
1262
|
+
...rest
|
|
938
1263
|
});
|
|
939
|
-
const tokenPurchaseCost = BigInt(mintable.cost.native_price.raw) * quantityToMint;
|
|
940
|
-
return {
|
|
941
|
-
mintFee,
|
|
942
|
-
tokenPurchaseCost,
|
|
943
|
-
totalCost: mintFee + tokenPurchaseCost
|
|
944
|
-
};
|
|
945
1264
|
}
|
|
946
1265
|
async function makePrepareMint721TokenParams({
|
|
947
|
-
|
|
1266
|
+
tokenAddress,
|
|
1267
|
+
salesConfigAndTokenInfo,
|
|
948
1268
|
minterAccount,
|
|
949
|
-
mintable,
|
|
950
|
-
mintContextType,
|
|
951
1269
|
mintArguments
|
|
952
1270
|
}) {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
}
|
|
956
|
-
const mintValue = (await get721MintCosts({
|
|
957
|
-
mintable,
|
|
958
|
-
publicClient,
|
|
1271
|
+
const mintValue = getMintCosts({
|
|
1272
|
+
salesConfigAndTokenInfo,
|
|
959
1273
|
quantityToMint: BigInt(mintArguments.quantityToMint)
|
|
960
|
-
})
|
|
1274
|
+
}).totalCost;
|
|
961
1275
|
const result = {
|
|
962
1276
|
abi: zora721Abi,
|
|
963
|
-
address:
|
|
1277
|
+
address: tokenAddress,
|
|
964
1278
|
account: minterAccount,
|
|
965
1279
|
functionName: "mintWithRewards",
|
|
966
1280
|
value: mintValue,
|
|
@@ -968,34 +1282,17 @@ async function makePrepareMint721TokenParams({
|
|
|
968
1282
|
mintArguments.mintToAddress,
|
|
969
1283
|
BigInt(mintArguments.quantityToMint),
|
|
970
1284
|
mintArguments.mintComment || "",
|
|
971
|
-
mintArguments.mintReferral ||
|
|
1285
|
+
mintArguments.mintReferral || import_viem5.zeroAddress
|
|
972
1286
|
]
|
|
973
1287
|
};
|
|
974
1288
|
return result;
|
|
975
1289
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
publicClient
|
|
979
|
-
}) {
|
|
980
|
-
return await publicClient.readContract({
|
|
981
|
-
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
982
|
-
functionName: "mintFee",
|
|
983
|
-
address: collectionAddress
|
|
984
|
-
});
|
|
985
|
-
}
|
|
986
|
-
async function get1155MintCosts({
|
|
987
|
-
mintable,
|
|
988
|
-
price,
|
|
989
|
-
publicClient,
|
|
1290
|
+
function getMintCosts({
|
|
1291
|
+
salesConfigAndTokenInfo,
|
|
990
1292
|
quantityToMint
|
|
991
1293
|
}) {
|
|
992
|
-
const
|
|
993
|
-
const
|
|
994
|
-
collectionAddress: address,
|
|
995
|
-
publicClient
|
|
996
|
-
});
|
|
997
|
-
const mintFeeForTokens = mintFee * quantityToMint;
|
|
998
|
-
const tokenPurchaseCost = price * quantityToMint;
|
|
1294
|
+
const mintFeeForTokens = salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
|
|
1295
|
+
const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.fixedPrice.pricePerToken) * quantityToMint;
|
|
999
1296
|
return {
|
|
1000
1297
|
mintFee: mintFeeForTokens,
|
|
1001
1298
|
tokenPurchaseCost,
|
|
@@ -1003,56 +1300,45 @@ async function get1155MintCosts({
|
|
|
1003
1300
|
};
|
|
1004
1301
|
}
|
|
1005
1302
|
async function makePrepareMint1155TokenParams({
|
|
1006
|
-
|
|
1007
|
-
|
|
1303
|
+
tokenId,
|
|
1304
|
+
salesConfigAndTokenInfo,
|
|
1008
1305
|
minterAccount,
|
|
1009
|
-
|
|
1010
|
-
mintContextType,
|
|
1306
|
+
tokenAddress,
|
|
1011
1307
|
mintArguments
|
|
1012
1308
|
}) {
|
|
1013
|
-
if (mintContextType !== "zora_create_1155") {
|
|
1014
|
-
throw new Error("Minted token type must be for 1155");
|
|
1015
|
-
}
|
|
1016
1309
|
const mintQuantity = BigInt(mintArguments.quantityToMint);
|
|
1017
|
-
const
|
|
1018
|
-
|
|
1019
|
-
contractAddress: address,
|
|
1020
|
-
tokenId: BigInt(mintable.token_id)
|
|
1021
|
-
});
|
|
1022
|
-
const mintValue = (await get1155MintCosts({
|
|
1023
|
-
mintable,
|
|
1024
|
-
price: tokenFixedPriceMinter?.pricePerToken || BigInt(mintable.cost.native_price.raw),
|
|
1025
|
-
publicClient,
|
|
1310
|
+
const mintValue = getMintCosts({
|
|
1311
|
+
salesConfigAndTokenInfo,
|
|
1026
1312
|
quantityToMint: mintQuantity
|
|
1027
|
-
})
|
|
1313
|
+
}).totalCost;
|
|
1028
1314
|
const result = {
|
|
1029
|
-
abi:
|
|
1315
|
+
abi: import_protocol_deployments3.zoraCreator1155ImplABI,
|
|
1030
1316
|
functionName: "mintWithRewards",
|
|
1031
1317
|
account: minterAccount,
|
|
1032
1318
|
value: mintValue,
|
|
1033
|
-
address,
|
|
1319
|
+
address: tokenAddress,
|
|
1034
1320
|
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
1035
1321
|
args: [
|
|
1036
|
-
|
|
1037
|
-
BigInt(
|
|
1322
|
+
salesConfigAndTokenInfo?.fixedPrice.address || import_protocol_deployments3.zoraCreatorFixedPriceSaleStrategyAddress[999],
|
|
1323
|
+
BigInt(tokenId),
|
|
1038
1324
|
mintQuantity,
|
|
1039
|
-
(0,
|
|
1325
|
+
(0, import_viem5.encodeAbiParameters)((0, import_viem5.parseAbiParameters)("address, string"), [
|
|
1040
1326
|
mintArguments.mintToAddress,
|
|
1041
1327
|
mintArguments.mintComment || ""
|
|
1042
1328
|
]),
|
|
1043
|
-
mintArguments.mintReferral ||
|
|
1329
|
+
mintArguments.mintReferral || import_viem5.zeroAddress
|
|
1044
1330
|
]
|
|
1045
1331
|
};
|
|
1046
1332
|
return result;
|
|
1047
1333
|
}
|
|
1048
1334
|
|
|
1049
1335
|
// src/create/1155-create-helper.ts
|
|
1050
|
-
var
|
|
1051
|
-
var
|
|
1336
|
+
var import_protocol_deployments4 = require("@zoralabs/protocol-deployments");
|
|
1337
|
+
var import_viem6 = require("viem");
|
|
1052
1338
|
var SALE_END_FOREVER = 18446744073709551615n;
|
|
1053
1339
|
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
1054
1340
|
var DEFAULT_SALE_SETTINGS = {
|
|
1055
|
-
fundsRecipient:
|
|
1341
|
+
fundsRecipient: import_viem6.zeroAddress,
|
|
1056
1342
|
// Free Mint
|
|
1057
1343
|
pricePerToken: 0n,
|
|
1058
1344
|
// Sale start time – defaults to beginning of unix time
|
|
@@ -1091,33 +1377,33 @@ function create1155TokenSetupArgs({
|
|
|
1091
1377
|
...salesConfig
|
|
1092
1378
|
};
|
|
1093
1379
|
const setupActions = [
|
|
1094
|
-
(0,
|
|
1095
|
-
abi:
|
|
1380
|
+
(0, import_viem6.encodeFunctionData)({
|
|
1381
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1096
1382
|
functionName: "assumeLastTokenIdMatches",
|
|
1097
1383
|
args: [nextTokenId - 1n]
|
|
1098
1384
|
}),
|
|
1099
|
-
createReferral ? (0,
|
|
1100
|
-
abi:
|
|
1385
|
+
createReferral ? (0, import_viem6.encodeFunctionData)({
|
|
1386
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1101
1387
|
functionName: "setupNewTokenWithCreateReferral",
|
|
1102
1388
|
args: [tokenMetadataURI, maxSupply, createReferral]
|
|
1103
|
-
}) : (0,
|
|
1104
|
-
abi:
|
|
1389
|
+
}) : (0, import_viem6.encodeFunctionData)({
|
|
1390
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1105
1391
|
functionName: "setupNewToken",
|
|
1106
1392
|
args: [tokenMetadataURI, maxSupply]
|
|
1107
1393
|
}),
|
|
1108
|
-
(0,
|
|
1109
|
-
abi:
|
|
1394
|
+
(0, import_viem6.encodeFunctionData)({
|
|
1395
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1110
1396
|
functionName: "addPermission",
|
|
1111
1397
|
args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
|
|
1112
1398
|
}),
|
|
1113
|
-
(0,
|
|
1114
|
-
abi:
|
|
1399
|
+
(0, import_viem6.encodeFunctionData)({
|
|
1400
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1115
1401
|
functionName: "callSale",
|
|
1116
1402
|
args: [
|
|
1117
1403
|
nextTokenId,
|
|
1118
1404
|
fixedPriceMinterAddress,
|
|
1119
|
-
(0,
|
|
1120
|
-
abi:
|
|
1405
|
+
(0, import_viem6.encodeFunctionData)({
|
|
1406
|
+
abi: import_protocol_deployments4.zoraCreatorFixedPriceSaleStrategyABI,
|
|
1121
1407
|
functionName: "setSale",
|
|
1122
1408
|
args: [nextTokenId, salesConfigWithDefaults]
|
|
1123
1409
|
})
|
|
@@ -1126,8 +1412,8 @@ function create1155TokenSetupArgs({
|
|
|
1126
1412
|
];
|
|
1127
1413
|
if (mintToCreatorCount) {
|
|
1128
1414
|
setupActions.push(
|
|
1129
|
-
(0,
|
|
1130
|
-
abi:
|
|
1415
|
+
(0, import_viem6.encodeFunctionData)({
|
|
1416
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1131
1417
|
functionName: "adminMint",
|
|
1132
1418
|
args: [account, nextTokenId, mintToCreatorCount, "0x"]
|
|
1133
1419
|
})
|
|
@@ -1135,8 +1421,8 @@ function create1155TokenSetupArgs({
|
|
|
1135
1421
|
}
|
|
1136
1422
|
if (royaltySettings) {
|
|
1137
1423
|
setupActions.push(
|
|
1138
|
-
(0,
|
|
1139
|
-
abi:
|
|
1424
|
+
(0, import_viem6.encodeFunctionData)({
|
|
1425
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1140
1426
|
functionName: "updateRoyaltiesForToken",
|
|
1141
1427
|
args: [
|
|
1142
1428
|
nextTokenId,
|
|
@@ -1154,8 +1440,8 @@ function create1155TokenSetupArgs({
|
|
|
1154
1440
|
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
1155
1441
|
for (const data of receipt.logs) {
|
|
1156
1442
|
try {
|
|
1157
|
-
const decodedLog = (0,
|
|
1158
|
-
abi:
|
|
1443
|
+
const decodedLog = (0, import_viem6.decodeEventLog)({
|
|
1444
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1159
1445
|
eventName: "SetupNewToken",
|
|
1160
1446
|
...data
|
|
1161
1447
|
});
|
|
@@ -1171,9 +1457,9 @@ async function getContractExists(publicClient, contract, account) {
|
|
|
1171
1457
|
let contractExists = false;
|
|
1172
1458
|
if (typeof contract !== "string") {
|
|
1173
1459
|
contractAddress = await publicClient.readContract({
|
|
1174
|
-
abi:
|
|
1460
|
+
abi: import_protocol_deployments4.zoraCreator1155FactoryImplABI,
|
|
1175
1461
|
// Since this address is deterministic we can hardcode a chain id safely here.
|
|
1176
|
-
address:
|
|
1462
|
+
address: import_protocol_deployments4.zoraCreator1155FactoryImplAddress[999],
|
|
1177
1463
|
functionName: "deterministicContractAddress",
|
|
1178
1464
|
args: [
|
|
1179
1465
|
account,
|
|
@@ -1184,7 +1470,7 @@ async function getContractExists(publicClient, contract, account) {
|
|
|
1184
1470
|
});
|
|
1185
1471
|
try {
|
|
1186
1472
|
await publicClient.readContract({
|
|
1187
|
-
abi:
|
|
1473
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1188
1474
|
address: contractAddress,
|
|
1189
1475
|
functionName: "contractVersion"
|
|
1190
1476
|
});
|
|
@@ -1219,14 +1505,14 @@ function create1155CreatorClient({
|
|
|
1219
1505
|
let nextTokenId = 1n;
|
|
1220
1506
|
if (contractExists) {
|
|
1221
1507
|
nextTokenId = await publicClient.readContract({
|
|
1222
|
-
abi:
|
|
1508
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1223
1509
|
functionName: "nextTokenId",
|
|
1224
1510
|
address: contractAddress
|
|
1225
1511
|
});
|
|
1226
1512
|
}
|
|
1227
1513
|
const fixedPriceMinterAddress = await publicClient.readContract({
|
|
1228
|
-
abi:
|
|
1229
|
-
address:
|
|
1514
|
+
abi: import_protocol_deployments4.zoraCreator1155FactoryImplABI,
|
|
1515
|
+
address: import_protocol_deployments4.zoraCreator1155FactoryImplAddress[999],
|
|
1230
1516
|
functionName: "fixedPriceMinter"
|
|
1231
1517
|
});
|
|
1232
1518
|
let tokenSetupActions = create1155TokenSetupArgs({
|
|
@@ -1250,10 +1536,10 @@ function create1155CreatorClient({
|
|
|
1250
1536
|
}
|
|
1251
1537
|
if (!contractExists && typeof contract !== "string") {
|
|
1252
1538
|
const request = {
|
|
1253
|
-
abi:
|
|
1539
|
+
abi: import_protocol_deployments4.zoraCreator1155FactoryImplABI,
|
|
1254
1540
|
functionName: "createContractDeterministic",
|
|
1255
1541
|
account,
|
|
1256
|
-
address:
|
|
1542
|
+
address: import_protocol_deployments4.zoraCreator1155FactoryImplAddress[999],
|
|
1257
1543
|
args: [
|
|
1258
1544
|
contract.uri,
|
|
1259
1545
|
contract.name,
|
|
@@ -1275,7 +1561,7 @@ function create1155CreatorClient({
|
|
|
1275
1561
|
};
|
|
1276
1562
|
} else if (contractExists) {
|
|
1277
1563
|
const request = {
|
|
1278
|
-
abi:
|
|
1564
|
+
abi: import_protocol_deployments4.zoraCreator1155ImplABI,
|
|
1279
1565
|
functionName: "multicall",
|
|
1280
1566
|
account,
|
|
1281
1567
|
address: contractAddress,
|
|
@@ -1295,22 +1581,37 @@ function create1155CreatorClient({
|
|
|
1295
1581
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1296
1582
|
0 && (module.exports = {
|
|
1297
1583
|
DEFAULT_SALE_SETTINGS,
|
|
1298
|
-
DefaultMintArguments,
|
|
1299
1584
|
Errors,
|
|
1300
1585
|
MintAPIClient,
|
|
1301
1586
|
PremintAPIClient,
|
|
1587
|
+
PremintConfigVersion,
|
|
1588
|
+
PreminterDomain,
|
|
1302
1589
|
ZORA_API_BASE,
|
|
1303
|
-
|
|
1304
|
-
convertPremint,
|
|
1590
|
+
applyUpdateToPremint,
|
|
1305
1591
|
create1155CreatorClient,
|
|
1306
1592
|
create1155TokenSetupArgs,
|
|
1307
1593
|
createMintClient,
|
|
1308
1594
|
createPremintClient,
|
|
1309
|
-
|
|
1310
|
-
|
|
1595
|
+
defaultTokenConfigV1MintArguments,
|
|
1596
|
+
defaultTokenConfigV2MintArguments,
|
|
1311
1597
|
getApiNetworkConfigForChain,
|
|
1598
|
+
getMintCosts,
|
|
1599
|
+
getPremintCollectionAddress,
|
|
1600
|
+
getPremintExecutorAddress,
|
|
1312
1601
|
getPremintedLogFromReceipt,
|
|
1313
1602
|
getTokenIdFromCreateReceipt,
|
|
1314
|
-
|
|
1603
|
+
isAuthorizedToCreatePremint,
|
|
1604
|
+
isValidSignature,
|
|
1605
|
+
makeNewPremint,
|
|
1606
|
+
markPremintDeleted,
|
|
1607
|
+
migratePremintConfigToV2,
|
|
1608
|
+
premintTypedDataDefinition,
|
|
1609
|
+
recoverCreatorFromCreatorAttribution,
|
|
1610
|
+
recoverPremintSigner,
|
|
1611
|
+
supportedPremintVersions,
|
|
1612
|
+
supportsPremintVersion,
|
|
1613
|
+
tryRecoverPremintSigner,
|
|
1614
|
+
v1Types,
|
|
1615
|
+
v2Types
|
|
1315
1616
|
});
|
|
1316
1617
|
//# sourceMappingURL=index.cjs.map
|