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