@zoralabs/protocol-sdk 0.3.4 → 0.3.5
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 +22 -0
- package/README.md +7 -26
- 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 +470 -338
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +441 -313
- 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/premint-client.d.ts +63 -17
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +106 -19
- 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/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/premint-client.test.ts +9 -8
- package/src/premint/premint-client.ts +113 -61
- package/src/premint/preminter.test.ts +207 -130
- package/src/premint/preminter.ts +388 -51
- 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,259 @@
|
|
|
1
1
|
// src/premint/premint-client.ts
|
|
2
2
|
import { createPublicClient, decodeEventLog, http } 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
|
+
var v1Types = {
|
|
23
|
+
CreatorAttribution: [
|
|
24
|
+
{ name: "tokenConfig", type: "TokenCreationConfig" },
|
|
25
|
+
// unique id scoped to the contract and token to create.
|
|
26
|
+
// ensure that a signature can be replaced, as long as the replacement
|
|
27
|
+
// has the same uid, and a newer version.
|
|
28
|
+
{ name: "uid", type: "uint32" },
|
|
29
|
+
{ name: "version", type: "uint32" },
|
|
30
|
+
// if this update should result in the signature being deleted.
|
|
31
|
+
{ name: "deleted", type: "bool" }
|
|
32
|
+
],
|
|
33
|
+
TokenCreationConfig: [
|
|
34
|
+
{ name: "tokenURI", type: "string" },
|
|
35
|
+
{ name: "maxSupply", type: "uint256" },
|
|
36
|
+
{ name: "maxTokensPerAddress", type: "uint64" },
|
|
37
|
+
{ name: "pricePerToken", type: "uint96" },
|
|
38
|
+
{ name: "mintStart", type: "uint64" },
|
|
39
|
+
{ name: "mintDuration", type: "uint64" },
|
|
40
|
+
{ name: "royaltyMintSchedule", type: "uint32" },
|
|
41
|
+
{ name: "royaltyBPS", type: "uint32" },
|
|
42
|
+
{ name: "royaltyRecipient", type: "address" },
|
|
43
|
+
{ name: "fixedPriceMinter", type: "address" }
|
|
44
|
+
]
|
|
45
|
+
};
|
|
46
|
+
var v2Types = {
|
|
47
|
+
CreatorAttribution: [
|
|
48
|
+
{ name: "tokenConfig", type: "TokenCreationConfig" },
|
|
49
|
+
// unique id scoped to the contract and token to create.
|
|
50
|
+
// ensure that a signature can be replaced, as long as the replacement
|
|
51
|
+
// has the same uid, and a newer version.
|
|
52
|
+
{ name: "uid", type: "uint32" },
|
|
53
|
+
{ name: "version", type: "uint32" },
|
|
54
|
+
// if this update should result in the signature being deleted.
|
|
55
|
+
{ name: "deleted", type: "bool" }
|
|
56
|
+
],
|
|
57
|
+
TokenCreationConfig: [
|
|
58
|
+
{ name: "tokenURI", type: "string" },
|
|
59
|
+
{ name: "maxSupply", type: "uint256" },
|
|
60
|
+
{ name: "maxTokensPerAddress", type: "uint64" },
|
|
61
|
+
{ name: "pricePerToken", type: "uint96" },
|
|
62
|
+
{ name: "mintStart", type: "uint64" },
|
|
63
|
+
{ name: "mintDuration", type: "uint64" },
|
|
64
|
+
{ name: "royaltyBPS", type: "uint32" },
|
|
65
|
+
{ name: "payoutRecipient", type: "address" },
|
|
66
|
+
{ name: "fixedPriceMinter", type: "address" },
|
|
67
|
+
{ name: "createReferral", type: "address" }
|
|
68
|
+
]
|
|
69
|
+
};
|
|
70
|
+
var PreminterDomain = "Preminter";
|
|
71
|
+
var PremintConfigVersion = {
|
|
72
|
+
V1: "1",
|
|
73
|
+
V2: "2"
|
|
74
|
+
};
|
|
75
|
+
var getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImplAddress[999];
|
|
76
|
+
var premintTypedDataDefinition = ({
|
|
11
77
|
verifyingContract,
|
|
12
|
-
|
|
13
|
-
|
|
78
|
+
chainId,
|
|
79
|
+
premintConfigVersion: version,
|
|
80
|
+
premintConfig
|
|
14
81
|
}) => {
|
|
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
|
-
]
|
|
82
|
+
const domain = {
|
|
83
|
+
chainId,
|
|
84
|
+
name: PreminterDomain,
|
|
85
|
+
version,
|
|
86
|
+
verifyingContract
|
|
39
87
|
};
|
|
40
|
-
|
|
88
|
+
if (version === PremintConfigVersion.V1)
|
|
89
|
+
return {
|
|
90
|
+
domain,
|
|
91
|
+
types: v1Types,
|
|
92
|
+
message: premintConfig,
|
|
93
|
+
primaryType: "CreatorAttribution"
|
|
94
|
+
};
|
|
95
|
+
if (version === PremintConfigVersion.V2) {
|
|
96
|
+
return {
|
|
97
|
+
domain,
|
|
98
|
+
types: v2Types,
|
|
99
|
+
message: premintConfig,
|
|
100
|
+
primaryType: "CreatorAttribution"
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
throw new Error(`Invalid version ${version}`);
|
|
104
|
+
};
|
|
105
|
+
async function isAuthorizedToCreatePremint({
|
|
106
|
+
collection,
|
|
107
|
+
collectionAddress,
|
|
108
|
+
publicClient,
|
|
109
|
+
premintConfig,
|
|
110
|
+
premintConfigVersion,
|
|
111
|
+
signature,
|
|
112
|
+
signer
|
|
113
|
+
}) {
|
|
114
|
+
if (premintConfigVersion === PremintConfigVersion.V1) {
|
|
115
|
+
const [isValidSignature2] = await publicClient.readContract({
|
|
116
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
117
|
+
address: getPremintExecutorAddress(),
|
|
118
|
+
functionName: "isValidSignature",
|
|
119
|
+
args: [collection, premintConfig, signature]
|
|
120
|
+
});
|
|
121
|
+
return isValidSignature2;
|
|
122
|
+
}
|
|
123
|
+
return await publicClient.readContract({
|
|
124
|
+
abi: preminterAbi,
|
|
125
|
+
address: getPremintExecutorAddress(),
|
|
126
|
+
functionName: "isAuthorizedToCreatePremint",
|
|
127
|
+
args: [signer, collection.contractAdmin, collectionAddress]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async function recoverPremintSigner({
|
|
131
|
+
signature,
|
|
132
|
+
...rest
|
|
133
|
+
}) {
|
|
134
|
+
const typedData = premintTypedDataDefinition(rest);
|
|
135
|
+
return await recoverTypedDataAddress({
|
|
136
|
+
...typedData,
|
|
137
|
+
signature
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
async function tryRecoverPremintSigner(params) {
|
|
141
|
+
try {
|
|
142
|
+
return await recoverPremintSigner(params);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error(error);
|
|
145
|
+
return void 0;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function isValidSignature({
|
|
149
|
+
signature,
|
|
150
|
+
publicClient,
|
|
151
|
+
collection,
|
|
152
|
+
chainId,
|
|
153
|
+
...premintConfigAndVersion
|
|
154
|
+
}) {
|
|
155
|
+
const tokenContract = await getPremintCollectionAddress({
|
|
156
|
+
collection,
|
|
157
|
+
publicClient
|
|
158
|
+
});
|
|
159
|
+
const recoveredAddress = await tryRecoverPremintSigner({
|
|
160
|
+
...premintConfigAndVersion,
|
|
161
|
+
signature,
|
|
162
|
+
verifyingContract: tokenContract,
|
|
163
|
+
chainId
|
|
164
|
+
});
|
|
165
|
+
if (!recoverAddress) {
|
|
166
|
+
return {
|
|
167
|
+
isAuthorized: false
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
171
|
+
signer: recoveredAddress,
|
|
172
|
+
collection,
|
|
173
|
+
collectionAddress: tokenContract,
|
|
174
|
+
publicClient,
|
|
175
|
+
signature,
|
|
176
|
+
...premintConfigAndVersion
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
isAuthorized,
|
|
180
|
+
recoveredAddress
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function migratePremintConfigToV2({
|
|
184
|
+
premintConfig,
|
|
185
|
+
createReferral = zeroAddress
|
|
186
|
+
}) {
|
|
187
|
+
return {
|
|
188
|
+
...premintConfig,
|
|
189
|
+
tokenConfig: {
|
|
190
|
+
tokenURI: premintConfig.tokenConfig.tokenURI,
|
|
191
|
+
maxSupply: premintConfig.tokenConfig.maxSupply,
|
|
192
|
+
maxTokensPerAddress: premintConfig.tokenConfig.maxTokensPerAddress,
|
|
193
|
+
pricePerToken: premintConfig.tokenConfig.pricePerToken,
|
|
194
|
+
mintStart: premintConfig.tokenConfig.mintStart,
|
|
195
|
+
mintDuration: premintConfig.tokenConfig.mintDuration,
|
|
196
|
+
payoutRecipient: premintConfig.tokenConfig.royaltyRecipient,
|
|
197
|
+
royaltyBPS: premintConfig.tokenConfig.royaltyBPS,
|
|
198
|
+
fixedPriceMinter: premintConfig.tokenConfig.fixedPriceMinter,
|
|
199
|
+
createReferral
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
var recoverCreatorFromCreatorAttribution = async ({
|
|
204
|
+
creatorAttribution: { version, domainName, structHash, signature },
|
|
205
|
+
chainId,
|
|
206
|
+
tokenContract
|
|
207
|
+
}) => {
|
|
208
|
+
const hashedDomain = hashDomain({
|
|
41
209
|
domain: {
|
|
42
210
|
chainId,
|
|
43
|
-
name:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
types,
|
|
48
|
-
message: {
|
|
49
|
-
tokenConfig,
|
|
50
|
-
uid,
|
|
51
|
-
version,
|
|
52
|
-
deleted
|
|
211
|
+
name: domainName,
|
|
212
|
+
verifyingContract: tokenContract,
|
|
213
|
+
version
|
|
53
214
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
215
|
+
types: {
|
|
216
|
+
EIP712Domain: [
|
|
217
|
+
{ name: "name", type: "string" },
|
|
218
|
+
{ name: "version", type: "string" },
|
|
219
|
+
{
|
|
220
|
+
name: "chainId",
|
|
221
|
+
type: "uint256"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: "verifyingContract",
|
|
225
|
+
type: "address"
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
const parts = ["0x1901", hashedDomain, structHash];
|
|
231
|
+
const hashedTypedData = keccak256(concat(parts));
|
|
232
|
+
return await recoverAddress({
|
|
233
|
+
hash: hashedTypedData,
|
|
234
|
+
signature
|
|
235
|
+
});
|
|
57
236
|
};
|
|
237
|
+
var supportsPremintVersion = async (version, tokenContract, publicClient) => {
|
|
238
|
+
const supportedPremintSignatureVersions = await publicClient.readContract({
|
|
239
|
+
abi: preminterAbi,
|
|
240
|
+
address: getPremintExecutorAddress(),
|
|
241
|
+
functionName: "supportedPremintSignatureVersions",
|
|
242
|
+
args: [tokenContract]
|
|
243
|
+
});
|
|
244
|
+
return supportedPremintSignatureVersions.includes(version);
|
|
245
|
+
};
|
|
246
|
+
async function getPremintCollectionAddress({
|
|
247
|
+
collection,
|
|
248
|
+
publicClient
|
|
249
|
+
}) {
|
|
250
|
+
return publicClient.readContract({
|
|
251
|
+
address: getPremintExecutorAddress(),
|
|
252
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
253
|
+
functionName: "getContractAddress",
|
|
254
|
+
args: [collection]
|
|
255
|
+
});
|
|
256
|
+
}
|
|
58
257
|
|
|
59
258
|
// src/apis/http-api-base.ts
|
|
60
259
|
var BadResponseError = class extends Error {
|
|
@@ -131,12 +330,17 @@ var httpClient = {
|
|
|
131
330
|
};
|
|
132
331
|
|
|
133
332
|
// src/constants.ts
|
|
333
|
+
import { parseAbi } from "viem";
|
|
134
334
|
var ZORA_API_BASE = "https://api.zora.co/";
|
|
135
335
|
var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
|
|
136
336
|
var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
|
|
137
337
|
function getSubgraph(name, version) {
|
|
138
338
|
return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
|
|
139
339
|
}
|
|
340
|
+
var zora721Abi = parseAbi([
|
|
341
|
+
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
342
|
+
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
|
|
343
|
+
]);
|
|
140
344
|
|
|
141
345
|
// src/apis/chain-constants.ts
|
|
142
346
|
import {
|
|
@@ -229,9 +433,6 @@ var networkConfigByChain = {
|
|
|
229
433
|
};
|
|
230
434
|
|
|
231
435
|
// src/mint/mint-api-client.ts
|
|
232
|
-
function encodeQueryParameters(params) {
|
|
233
|
-
return new URLSearchParams(params).toString();
|
|
234
|
-
}
|
|
235
436
|
var getApiNetworkConfigForChain = (chainId) => {
|
|
236
437
|
if (!networkConfigByChain[chainId]) {
|
|
237
438
|
throw new Error(`chain id ${chainId} network not configured `);
|
|
@@ -243,59 +444,64 @@ var MintAPIClient = class {
|
|
|
243
444
|
this.httpClient = httpClient2 || httpClient;
|
|
244
445
|
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
245
446
|
}
|
|
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,
|
|
447
|
+
async getSalesConfigAndTokenInfo({
|
|
448
|
+
tokenAddress,
|
|
256
449
|
tokenId
|
|
257
450
|
}) {
|
|
258
451
|
const { retries: retries2, post: post2 } = this.httpClient;
|
|
259
452
|
return retries2(async () => {
|
|
260
453
|
const response = await post2(this.networkConfig.subgraphUrl, {
|
|
261
|
-
query: `
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
454
|
+
query: `
|
|
455
|
+
fragment SaleStrategy on SalesStrategyConfig {
|
|
456
|
+
type
|
|
457
|
+
fixedPrice {
|
|
458
|
+
address
|
|
459
|
+
pricePerToken
|
|
460
|
+
saleEnd
|
|
461
|
+
saleStart
|
|
462
|
+
maxTokensPerAddress
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
query ($id: ID!) {
|
|
467
|
+
zoraCreateToken(id: $id) {
|
|
468
|
+
id
|
|
469
|
+
contract {
|
|
470
|
+
mintFeePerQuantity
|
|
471
|
+
salesStrategies(where: {type: "FIXED_PRICE"}) {
|
|
472
|
+
...SaleStrategy
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
salesStrategies(where: {type: "FIXED_PRICE"}) {
|
|
476
|
+
...SaleStrategy
|
|
272
477
|
}
|
|
273
478
|
}
|
|
274
479
|
}
|
|
275
|
-
|
|
480
|
+
`,
|
|
276
481
|
variables: {
|
|
277
|
-
id:
|
|
482
|
+
id: tokenId !== void 0 ? (
|
|
483
|
+
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
484
|
+
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
485
|
+
) : `${tokenAddress.toLowerCase()}-0`
|
|
278
486
|
}
|
|
279
487
|
});
|
|
280
|
-
const
|
|
488
|
+
const token = response.data?.zoraCreateToken;
|
|
489
|
+
if (!token) {
|
|
490
|
+
throw new Error("Cannot find a token to mint");
|
|
491
|
+
}
|
|
492
|
+
const saleStrategies = tokenId !== void 0 ? token.salesStrategies : token.contract.salesStrategies;
|
|
493
|
+
const fixedPrice = saleStrategies?.sort(
|
|
494
|
+
(a, b) => BigInt(a.fixedPrice.saleEnd) > BigInt(b.fixedPrice.saleEnd) ? 1 : -1
|
|
495
|
+
)?.find(() => true)?.fixedPrice;
|
|
496
|
+
if (!fixedPrice) {
|
|
497
|
+
throw new Error("Cannot find fixed price sale strategy");
|
|
498
|
+
}
|
|
281
499
|
return {
|
|
282
|
-
|
|
283
|
-
|
|
500
|
+
fixedPrice,
|
|
501
|
+
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
|
|
284
502
|
};
|
|
285
503
|
});
|
|
286
504
|
}
|
|
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
505
|
};
|
|
300
506
|
|
|
301
507
|
// src/premint/premint-api-client.ts
|
|
@@ -366,7 +572,7 @@ function getPremintedLogFromReceipt(receipt) {
|
|
|
366
572
|
for (const data of receipt.logs) {
|
|
367
573
|
try {
|
|
368
574
|
const decodedLog = decodeEventLog({
|
|
369
|
-
abi:
|
|
575
|
+
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
370
576
|
eventName: "Preminted",
|
|
371
577
|
...data
|
|
372
578
|
});
|
|
@@ -377,7 +583,7 @@ function getPremintedLogFromReceipt(receipt) {
|
|
|
377
583
|
}
|
|
378
584
|
}
|
|
379
585
|
}
|
|
380
|
-
var
|
|
586
|
+
var convertPremintV1 = (premint) => ({
|
|
381
587
|
...premint,
|
|
382
588
|
tokenConfig: {
|
|
383
589
|
...premint.tokenConfig,
|
|
@@ -394,7 +600,7 @@ var convertCollection = (collection) => ({
|
|
|
394
600
|
...collection,
|
|
395
601
|
contractAdmin: collection.contractAdmin
|
|
396
602
|
});
|
|
397
|
-
var
|
|
603
|
+
var encodePremintV1ForAPI = ({
|
|
398
604
|
tokenConfig,
|
|
399
605
|
...premint
|
|
400
606
|
}) => ({
|
|
@@ -408,21 +614,38 @@ var encodePremintForAPI = ({
|
|
|
408
614
|
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
409
615
|
}
|
|
410
616
|
});
|
|
617
|
+
var encodePremintV2ForAPI = ({
|
|
618
|
+
tokenConfig,
|
|
619
|
+
...premint
|
|
620
|
+
}) => ({
|
|
621
|
+
...premint,
|
|
622
|
+
tokenConfig: {
|
|
623
|
+
...tokenConfig,
|
|
624
|
+
maxSupply: tokenConfig.maxSupply.toString(),
|
|
625
|
+
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
626
|
+
mintStart: tokenConfig.mintStart.toString(),
|
|
627
|
+
mintDuration: tokenConfig.mintDuration.toString(),
|
|
628
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
var encodePremintForAPI = ({
|
|
632
|
+
premintConfig,
|
|
633
|
+
premintConfigVersion
|
|
634
|
+
}) => {
|
|
635
|
+
if (premintConfigVersion === PremintConfigVersion.V1) {
|
|
636
|
+
return encodePremintV1ForAPI(premintConfig);
|
|
637
|
+
}
|
|
638
|
+
if (premintConfigVersion === PremintConfigVersion.V2) {
|
|
639
|
+
return encodePremintV2ForAPI(premintConfig);
|
|
640
|
+
}
|
|
641
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
642
|
+
};
|
|
411
643
|
var PremintClient = class {
|
|
412
644
|
constructor(chain, publicClient, httpClient2) {
|
|
413
645
|
this.chain = chain;
|
|
414
646
|
this.apiClient = new PremintAPIClient(chain.id, httpClient2);
|
|
415
647
|
this.publicClient = publicClient || createPublicClient({ chain, transport: http() });
|
|
416
648
|
}
|
|
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
649
|
/**
|
|
427
650
|
* The fixed price minter address is the same across all chains for our current
|
|
428
651
|
* deployer strategy.
|
|
@@ -472,7 +695,7 @@ var PremintClient = class {
|
|
|
472
695
|
collection_address: collection.toLowerCase(),
|
|
473
696
|
uid
|
|
474
697
|
});
|
|
475
|
-
const convertedPremint =
|
|
698
|
+
const convertedPremint = convertPremintV1(signatureResponse.premint);
|
|
476
699
|
const signerData = {
|
|
477
700
|
...signatureResponse,
|
|
478
701
|
premint: {
|
|
@@ -493,7 +716,8 @@ var PremintClient = class {
|
|
|
493
716
|
...signerData.collection,
|
|
494
717
|
contractAdmin: signerData.collection.contractAdmin
|
|
495
718
|
},
|
|
496
|
-
premintConfig: signerData.premint
|
|
719
|
+
premintConfig: signerData.premint,
|
|
720
|
+
premintConfigVersion: PremintConfigVersion.V1
|
|
497
721
|
});
|
|
498
722
|
}
|
|
499
723
|
/**
|
|
@@ -524,7 +748,7 @@ var PremintClient = class {
|
|
|
524
748
|
...signatureResponse,
|
|
525
749
|
collection: convertCollection(signatureResponse.collection),
|
|
526
750
|
premint: {
|
|
527
|
-
...
|
|
751
|
+
...convertPremintV1(signatureResponse.premint),
|
|
528
752
|
deleted: true
|
|
529
753
|
}
|
|
530
754
|
};
|
|
@@ -535,7 +759,8 @@ var PremintClient = class {
|
|
|
535
759
|
verifyingContract: collection,
|
|
536
760
|
uid,
|
|
537
761
|
collection: signerData.collection,
|
|
538
|
-
premintConfig: signerData.premint
|
|
762
|
+
premintConfig: signerData.premint,
|
|
763
|
+
premintConfigVersion: PremintConfigVersion.V1
|
|
539
764
|
});
|
|
540
765
|
}
|
|
541
766
|
/**
|
|
@@ -547,11 +772,11 @@ var PremintClient = class {
|
|
|
547
772
|
async signAndSubmitPremint({
|
|
548
773
|
walletClient,
|
|
549
774
|
verifyingContract,
|
|
550
|
-
premintConfig,
|
|
551
775
|
uid,
|
|
552
776
|
account,
|
|
553
777
|
checkSignature,
|
|
554
|
-
collection
|
|
778
|
+
collection,
|
|
779
|
+
...premintConfigAndVersion
|
|
555
780
|
}) {
|
|
556
781
|
if (!account) {
|
|
557
782
|
account = walletClient.account;
|
|
@@ -561,26 +786,32 @@ var PremintClient = class {
|
|
|
561
786
|
}
|
|
562
787
|
const signature = await walletClient.signTypedData({
|
|
563
788
|
account,
|
|
564
|
-
...
|
|
789
|
+
...premintTypedDataDefinition({
|
|
565
790
|
verifyingContract,
|
|
566
|
-
|
|
791
|
+
...premintConfigAndVersion,
|
|
567
792
|
chainId: this.chain.id
|
|
568
793
|
})
|
|
569
794
|
});
|
|
570
795
|
if (checkSignature) {
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
796
|
+
const convertedCollection = convertCollection(collection);
|
|
797
|
+
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
798
|
+
collection: convertCollection(collection),
|
|
799
|
+
signature,
|
|
800
|
+
publicClient: this.publicClient,
|
|
801
|
+
signer: typeof account === "string" ? account : account.address,
|
|
802
|
+
collectionAddress: await this.getCollectionAddress(convertedCollection),
|
|
803
|
+
...premintConfigAndVersion
|
|
576
804
|
});
|
|
577
|
-
if (!
|
|
578
|
-
throw new Error("
|
|
805
|
+
if (!isAuthorized) {
|
|
806
|
+
throw new Error("Not authorized to create premint");
|
|
579
807
|
}
|
|
580
808
|
}
|
|
809
|
+
if (premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2) {
|
|
810
|
+
throw new Error("premint config v2 not supported yet");
|
|
811
|
+
}
|
|
581
812
|
const apiData = {
|
|
582
813
|
collection,
|
|
583
|
-
premint:
|
|
814
|
+
premint: encodePremintV1ForAPI(premintConfigAndVersion.premintConfig),
|
|
584
815
|
signature
|
|
585
816
|
};
|
|
586
817
|
const premint = await this.apiClient.postSignature(apiData);
|
|
@@ -614,11 +845,9 @@ var PremintClient = class {
|
|
|
614
845
|
executionSettings,
|
|
615
846
|
checkSignature = false
|
|
616
847
|
}) {
|
|
617
|
-
const newContractAddress = await
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
functionName: "getContractAddress",
|
|
621
|
-
args: [convertCollection(collection)]
|
|
848
|
+
const newContractAddress = await getPremintCollectionAddress({
|
|
849
|
+
publicClient: this.publicClient,
|
|
850
|
+
collection: convertCollection(collection)
|
|
622
851
|
});
|
|
623
852
|
const tokenConfig = {
|
|
624
853
|
...DefaultMintArguments,
|
|
@@ -647,6 +876,7 @@ var PremintClient = class {
|
|
|
647
876
|
uid,
|
|
648
877
|
verifyingContract: newContractAddress,
|
|
649
878
|
premintConfig,
|
|
879
|
+
premintConfigVersion: PremintConfigVersion.V1,
|
|
650
880
|
checkSignature,
|
|
651
881
|
account,
|
|
652
882
|
walletClient,
|
|
@@ -669,26 +899,37 @@ var PremintClient = class {
|
|
|
669
899
|
uid
|
|
670
900
|
});
|
|
671
901
|
}
|
|
902
|
+
/**
|
|
903
|
+
* Gets the deterministic contract address for a premint collection
|
|
904
|
+
* @param collection Collection to get the address for
|
|
905
|
+
* @returns deterministic contract address
|
|
906
|
+
*/
|
|
907
|
+
async getCollectionAddress(collection) {
|
|
908
|
+
return await getPremintCollectionAddress({
|
|
909
|
+
collection,
|
|
910
|
+
publicClient: this.publicClient
|
|
911
|
+
});
|
|
912
|
+
}
|
|
672
913
|
/**
|
|
673
914
|
* Check user signature for v1
|
|
674
915
|
*
|
|
675
916
|
* @param data Signature data from the API
|
|
676
|
-
* @returns isValid = signature is valid or not,
|
|
917
|
+
* @returns isValid = signature is valid or not, recoveredSigner = signer from contract
|
|
677
918
|
*/
|
|
678
919
|
async isValidSignature({
|
|
679
|
-
|
|
920
|
+
signature,
|
|
921
|
+
premint,
|
|
922
|
+
collection
|
|
680
923
|
}) {
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
data.signature
|
|
689
|
-
]
|
|
924
|
+
const { isAuthorized, recoveredAddress } = await isValidSignature({
|
|
925
|
+
chainId: this.chain.id,
|
|
926
|
+
signature,
|
|
927
|
+
premintConfig: convertPremintV1(premint),
|
|
928
|
+
premintConfigVersion: PremintConfigVersion.V1,
|
|
929
|
+
collection: convertCollection(collection),
|
|
930
|
+
publicClient: this.publicClient
|
|
690
931
|
});
|
|
691
|
-
return { isValid
|
|
932
|
+
return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
|
|
692
933
|
}
|
|
693
934
|
makeUrls({
|
|
694
935
|
uid,
|
|
@@ -726,11 +967,10 @@ var PremintClient = class {
|
|
|
726
967
|
if (mintArguments && mintArguments?.quantityToMint < 1) {
|
|
727
968
|
throw new Error("Quantity to mint cannot be below 1");
|
|
728
969
|
}
|
|
729
|
-
const targetAddress = this.getExecutorAddress();
|
|
730
970
|
const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
|
|
731
971
|
const args = [
|
|
732
972
|
convertCollection(data.collection),
|
|
733
|
-
|
|
973
|
+
convertPremintV1(data.premint),
|
|
734
974
|
data.signature,
|
|
735
975
|
numberToMint,
|
|
736
976
|
mintArguments?.mintComment || ""
|
|
@@ -741,10 +981,10 @@ var PremintClient = class {
|
|
|
741
981
|
const value = numberToMint * REWARD_PER_TOKEN;
|
|
742
982
|
const request = {
|
|
743
983
|
account,
|
|
744
|
-
abi:
|
|
984
|
+
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
745
985
|
functionName: "premint",
|
|
746
986
|
value,
|
|
747
|
-
address:
|
|
987
|
+
address: getPremintExecutorAddress(),
|
|
748
988
|
args
|
|
749
989
|
};
|
|
750
990
|
return request;
|
|
@@ -762,13 +1002,12 @@ function createPremintClient({
|
|
|
762
1002
|
import {
|
|
763
1003
|
createPublicClient as createPublicClient2,
|
|
764
1004
|
encodeAbiParameters,
|
|
765
|
-
parseAbi,
|
|
766
1005
|
parseAbiParameters,
|
|
767
|
-
zeroAddress,
|
|
1006
|
+
zeroAddress as zeroAddress2,
|
|
768
1007
|
http as http2
|
|
769
1008
|
} from "viem";
|
|
770
1009
|
import {
|
|
771
|
-
zoraCreator1155ImplABI,
|
|
1010
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
|
|
772
1011
|
zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
|
|
773
1012
|
} from "@zoralabs/protocol-deployments";
|
|
774
1013
|
var MintError = class extends Error {
|
|
@@ -779,30 +1018,11 @@ var Errors = {
|
|
|
779
1018
|
MintError,
|
|
780
1019
|
MintInactiveError
|
|
781
1020
|
};
|
|
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
1021
|
var MintClient = class {
|
|
787
1022
|
constructor(chain, publicClient, httpClient2) {
|
|
788
1023
|
this.apiClient = new MintAPIClient(chain.id, httpClient2);
|
|
789
1024
|
this.publicClient = publicClient || createPublicClient2({ chain, transport: http2() });
|
|
790
1025
|
}
|
|
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
1026
|
/**
|
|
807
1027
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
808
1028
|
* @param param0.minterAccount The account that will mint the token.
|
|
@@ -819,36 +1039,6 @@ var MintClient = class {
|
|
|
819
1039
|
publicClient: this.publicClient
|
|
820
1040
|
});
|
|
821
1041
|
}
|
|
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
1042
|
};
|
|
853
1043
|
function createMintClient({
|
|
854
1044
|
chain,
|
|
@@ -857,91 +1047,44 @@ function createMintClient({
|
|
|
857
1047
|
}) {
|
|
858
1048
|
return new MintClient(chain, publicClient, httpClient2);
|
|
859
1049
|
}
|
|
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
1050
|
async function makePrepareMintTokenParams({
|
|
880
1051
|
publicClient,
|
|
881
|
-
mintable,
|
|
882
1052
|
apiClient,
|
|
1053
|
+
tokenId,
|
|
1054
|
+
tokenAddress,
|
|
883
1055
|
...rest
|
|
884
1056
|
}) {
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
publicClient: thisPublicClient,
|
|
891
|
-
mintable,
|
|
892
|
-
mintContextType,
|
|
893
|
-
...rest
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
if (mintContextType === "zora_create") {
|
|
1057
|
+
const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
|
|
1058
|
+
tokenId,
|
|
1059
|
+
tokenAddress
|
|
1060
|
+
});
|
|
1061
|
+
if (tokenId === void 0) {
|
|
897
1062
|
return makePrepareMint721TokenParams({
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
mintContextType,
|
|
1063
|
+
salesConfigAndTokenInfo,
|
|
1064
|
+
tokenAddress,
|
|
901
1065
|
...rest
|
|
902
1066
|
});
|
|
903
1067
|
}
|
|
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)]
|
|
1068
|
+
return makePrepareMint1155TokenParams({
|
|
1069
|
+
salesConfigAndTokenInfo,
|
|
1070
|
+
tokenAddress,
|
|
1071
|
+
tokenId,
|
|
1072
|
+
...rest
|
|
919
1073
|
});
|
|
920
|
-
const tokenPurchaseCost = BigInt(mintable.cost.native_price.raw) * quantityToMint;
|
|
921
|
-
return {
|
|
922
|
-
mintFee,
|
|
923
|
-
tokenPurchaseCost,
|
|
924
|
-
totalCost: mintFee + tokenPurchaseCost
|
|
925
|
-
};
|
|
926
1074
|
}
|
|
927
1075
|
async function makePrepareMint721TokenParams({
|
|
928
|
-
|
|
1076
|
+
tokenAddress,
|
|
1077
|
+
salesConfigAndTokenInfo,
|
|
929
1078
|
minterAccount,
|
|
930
|
-
mintable,
|
|
931
|
-
mintContextType,
|
|
932
1079
|
mintArguments
|
|
933
1080
|
}) {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
}
|
|
937
|
-
const mintValue = (await get721MintCosts({
|
|
938
|
-
mintable,
|
|
939
|
-
publicClient,
|
|
1081
|
+
const mintValue = getMintCosts({
|
|
1082
|
+
salesConfigAndTokenInfo,
|
|
940
1083
|
quantityToMint: BigInt(mintArguments.quantityToMint)
|
|
941
|
-
})
|
|
1084
|
+
}).totalCost;
|
|
942
1085
|
const result = {
|
|
943
1086
|
abi: zora721Abi,
|
|
944
|
-
address:
|
|
1087
|
+
address: tokenAddress,
|
|
945
1088
|
account: minterAccount,
|
|
946
1089
|
functionName: "mintWithRewards",
|
|
947
1090
|
value: mintValue,
|
|
@@ -949,34 +1092,17 @@ async function makePrepareMint721TokenParams({
|
|
|
949
1092
|
mintArguments.mintToAddress,
|
|
950
1093
|
BigInt(mintArguments.quantityToMint),
|
|
951
1094
|
mintArguments.mintComment || "",
|
|
952
|
-
mintArguments.mintReferral ||
|
|
1095
|
+
mintArguments.mintReferral || zeroAddress2
|
|
953
1096
|
]
|
|
954
1097
|
};
|
|
955
1098
|
return result;
|
|
956
1099
|
}
|
|
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,
|
|
1100
|
+
function getMintCosts({
|
|
1101
|
+
salesConfigAndTokenInfo,
|
|
971
1102
|
quantityToMint
|
|
972
1103
|
}) {
|
|
973
|
-
const
|
|
974
|
-
const
|
|
975
|
-
collectionAddress: address,
|
|
976
|
-
publicClient
|
|
977
|
-
});
|
|
978
|
-
const mintFeeForTokens = mintFee * quantityToMint;
|
|
979
|
-
const tokenPurchaseCost = price * quantityToMint;
|
|
1104
|
+
const mintFeeForTokens = salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
|
|
1105
|
+
const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.fixedPrice.pricePerToken) * quantityToMint;
|
|
980
1106
|
return {
|
|
981
1107
|
mintFee: mintFeeForTokens,
|
|
982
1108
|
tokenPurchaseCost,
|
|
@@ -984,44 +1110,33 @@ async function get1155MintCosts({
|
|
|
984
1110
|
};
|
|
985
1111
|
}
|
|
986
1112
|
async function makePrepareMint1155TokenParams({
|
|
987
|
-
|
|
988
|
-
|
|
1113
|
+
tokenId,
|
|
1114
|
+
salesConfigAndTokenInfo,
|
|
989
1115
|
minterAccount,
|
|
990
|
-
|
|
991
|
-
mintContextType,
|
|
1116
|
+
tokenAddress,
|
|
992
1117
|
mintArguments
|
|
993
1118
|
}) {
|
|
994
|
-
if (mintContextType !== "zora_create_1155") {
|
|
995
|
-
throw new Error("Minted token type must be for 1155");
|
|
996
|
-
}
|
|
997
1119
|
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,
|
|
1120
|
+
const mintValue = getMintCosts({
|
|
1121
|
+
salesConfigAndTokenInfo,
|
|
1007
1122
|
quantityToMint: mintQuantity
|
|
1008
|
-
})
|
|
1123
|
+
}).totalCost;
|
|
1009
1124
|
const result = {
|
|
1010
|
-
abi:
|
|
1125
|
+
abi: zoraCreator1155ImplABI2,
|
|
1011
1126
|
functionName: "mintWithRewards",
|
|
1012
1127
|
account: minterAccount,
|
|
1013
1128
|
value: mintValue,
|
|
1014
|
-
address,
|
|
1129
|
+
address: tokenAddress,
|
|
1015
1130
|
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
1016
1131
|
args: [
|
|
1017
|
-
|
|
1018
|
-
BigInt(
|
|
1132
|
+
salesConfigAndTokenInfo?.fixedPrice.address || zoraCreatorFixedPriceSaleStrategyAddress2[999],
|
|
1133
|
+
BigInt(tokenId),
|
|
1019
1134
|
mintQuantity,
|
|
1020
1135
|
encodeAbiParameters(parseAbiParameters("address, string"), [
|
|
1021
1136
|
mintArguments.mintToAddress,
|
|
1022
1137
|
mintArguments.mintComment || ""
|
|
1023
1138
|
]),
|
|
1024
|
-
mintArguments.mintReferral ||
|
|
1139
|
+
mintArguments.mintReferral || zeroAddress2
|
|
1025
1140
|
]
|
|
1026
1141
|
};
|
|
1027
1142
|
return result;
|
|
@@ -1031,14 +1146,14 @@ async function makePrepareMint1155TokenParams({
|
|
|
1031
1146
|
import {
|
|
1032
1147
|
zoraCreator1155FactoryImplABI,
|
|
1033
1148
|
zoraCreator1155FactoryImplAddress,
|
|
1034
|
-
zoraCreator1155ImplABI as
|
|
1149
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI3,
|
|
1035
1150
|
zoraCreatorFixedPriceSaleStrategyABI
|
|
1036
1151
|
} from "@zoralabs/protocol-deployments";
|
|
1037
|
-
import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as
|
|
1152
|
+
import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as zeroAddress3 } from "viem";
|
|
1038
1153
|
var SALE_END_FOREVER = 18446744073709551615n;
|
|
1039
1154
|
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
1040
1155
|
var DEFAULT_SALE_SETTINGS = {
|
|
1041
|
-
fundsRecipient:
|
|
1156
|
+
fundsRecipient: zeroAddress3,
|
|
1042
1157
|
// Free Mint
|
|
1043
1158
|
pricePerToken: 0n,
|
|
1044
1159
|
// Sale start time – defaults to beginning of unix time
|
|
@@ -1078,26 +1193,26 @@ function create1155TokenSetupArgs({
|
|
|
1078
1193
|
};
|
|
1079
1194
|
const setupActions = [
|
|
1080
1195
|
encodeFunctionData({
|
|
1081
|
-
abi:
|
|
1196
|
+
abi: zoraCreator1155ImplABI3,
|
|
1082
1197
|
functionName: "assumeLastTokenIdMatches",
|
|
1083
1198
|
args: [nextTokenId - 1n]
|
|
1084
1199
|
}),
|
|
1085
1200
|
createReferral ? encodeFunctionData({
|
|
1086
|
-
abi:
|
|
1201
|
+
abi: zoraCreator1155ImplABI3,
|
|
1087
1202
|
functionName: "setupNewTokenWithCreateReferral",
|
|
1088
1203
|
args: [tokenMetadataURI, maxSupply, createReferral]
|
|
1089
1204
|
}) : encodeFunctionData({
|
|
1090
|
-
abi:
|
|
1205
|
+
abi: zoraCreator1155ImplABI3,
|
|
1091
1206
|
functionName: "setupNewToken",
|
|
1092
1207
|
args: [tokenMetadataURI, maxSupply]
|
|
1093
1208
|
}),
|
|
1094
1209
|
encodeFunctionData({
|
|
1095
|
-
abi:
|
|
1210
|
+
abi: zoraCreator1155ImplABI3,
|
|
1096
1211
|
functionName: "addPermission",
|
|
1097
1212
|
args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
|
|
1098
1213
|
}),
|
|
1099
1214
|
encodeFunctionData({
|
|
1100
|
-
abi:
|
|
1215
|
+
abi: zoraCreator1155ImplABI3,
|
|
1101
1216
|
functionName: "callSale",
|
|
1102
1217
|
args: [
|
|
1103
1218
|
nextTokenId,
|
|
@@ -1113,7 +1228,7 @@ function create1155TokenSetupArgs({
|
|
|
1113
1228
|
if (mintToCreatorCount) {
|
|
1114
1229
|
setupActions.push(
|
|
1115
1230
|
encodeFunctionData({
|
|
1116
|
-
abi:
|
|
1231
|
+
abi: zoraCreator1155ImplABI3,
|
|
1117
1232
|
functionName: "adminMint",
|
|
1118
1233
|
args: [account, nextTokenId, mintToCreatorCount, "0x"]
|
|
1119
1234
|
})
|
|
@@ -1122,7 +1237,7 @@ function create1155TokenSetupArgs({
|
|
|
1122
1237
|
if (royaltySettings) {
|
|
1123
1238
|
setupActions.push(
|
|
1124
1239
|
encodeFunctionData({
|
|
1125
|
-
abi:
|
|
1240
|
+
abi: zoraCreator1155ImplABI3,
|
|
1126
1241
|
functionName: "updateRoyaltiesForToken",
|
|
1127
1242
|
args: [
|
|
1128
1243
|
nextTokenId,
|
|
@@ -1141,7 +1256,7 @@ var getTokenIdFromCreateReceipt = (receipt) => {
|
|
|
1141
1256
|
for (const data of receipt.logs) {
|
|
1142
1257
|
try {
|
|
1143
1258
|
const decodedLog = decodeEventLog2({
|
|
1144
|
-
abi:
|
|
1259
|
+
abi: zoraCreator1155ImplABI3,
|
|
1145
1260
|
eventName: "SetupNewToken",
|
|
1146
1261
|
...data
|
|
1147
1262
|
});
|
|
@@ -1170,7 +1285,7 @@ async function getContractExists(publicClient, contract, account) {
|
|
|
1170
1285
|
});
|
|
1171
1286
|
try {
|
|
1172
1287
|
await publicClient.readContract({
|
|
1173
|
-
abi:
|
|
1288
|
+
abi: zoraCreator1155ImplABI3,
|
|
1174
1289
|
address: contractAddress,
|
|
1175
1290
|
functionName: "contractVersion"
|
|
1176
1291
|
});
|
|
@@ -1205,7 +1320,7 @@ function create1155CreatorClient({
|
|
|
1205
1320
|
let nextTokenId = 1n;
|
|
1206
1321
|
if (contractExists) {
|
|
1207
1322
|
nextTokenId = await publicClient.readContract({
|
|
1208
|
-
abi:
|
|
1323
|
+
abi: zoraCreator1155ImplABI3,
|
|
1209
1324
|
functionName: "nextTokenId",
|
|
1210
1325
|
address: contractAddress
|
|
1211
1326
|
});
|
|
@@ -1261,7 +1376,7 @@ function create1155CreatorClient({
|
|
|
1261
1376
|
};
|
|
1262
1377
|
} else if (contractExists) {
|
|
1263
1378
|
const request = {
|
|
1264
|
-
abi:
|
|
1379
|
+
abi: zoraCreator1155ImplABI3,
|
|
1265
1380
|
functionName: "multicall",
|
|
1266
1381
|
account,
|
|
1267
1382
|
address: contractAddress,
|
|
@@ -1284,18 +1399,31 @@ export {
|
|
|
1284
1399
|
Errors,
|
|
1285
1400
|
MintAPIClient,
|
|
1286
1401
|
PremintAPIClient,
|
|
1402
|
+
PremintConfigVersion,
|
|
1403
|
+
PreminterDomain,
|
|
1287
1404
|
ZORA_API_BASE,
|
|
1288
1405
|
convertCollection,
|
|
1289
|
-
|
|
1406
|
+
convertPremintV1,
|
|
1290
1407
|
create1155CreatorClient,
|
|
1291
1408
|
create1155TokenSetupArgs,
|
|
1292
1409
|
createMintClient,
|
|
1293
1410
|
createPremintClient,
|
|
1294
1411
|
encodePremintForAPI,
|
|
1295
|
-
|
|
1412
|
+
encodePremintV1ForAPI,
|
|
1413
|
+
encodePremintV2ForAPI,
|
|
1296
1414
|
getApiNetworkConfigForChain,
|
|
1415
|
+
getMintCosts,
|
|
1416
|
+
getPremintCollectionAddress,
|
|
1417
|
+
getPremintExecutorAddress,
|
|
1297
1418
|
getPremintedLogFromReceipt,
|
|
1298
1419
|
getTokenIdFromCreateReceipt,
|
|
1299
|
-
|
|
1420
|
+
isAuthorizedToCreatePremint,
|
|
1421
|
+
isValidSignature,
|
|
1422
|
+
migratePremintConfigToV2,
|
|
1423
|
+
premintTypedDataDefinition,
|
|
1424
|
+
recoverCreatorFromCreatorAttribution,
|
|
1425
|
+
recoverPremintSigner,
|
|
1426
|
+
supportsPremintVersion,
|
|
1427
|
+
tryRecoverPremintSigner
|
|
1300
1428
|
};
|
|
1301
1429
|
//# sourceMappingURL=index.js.map
|