@zoralabs/protocol-sdk 0.5.17 → 0.7.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 +19 -0
- package/README.md +1 -416
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/create/1155-create-helper.d.ts +16 -55
- package/dist/create/1155-create-helper.d.ts.map +1 -1
- package/dist/create/contract-setup.d.ts +14 -0
- package/dist/create/contract-setup.d.ts.map +1 -0
- package/dist/create/token-setup.d.ts +27 -0
- package/dist/create/token-setup.d.ts.map +1 -0
- package/dist/create/types.d.ts +45 -0
- package/dist/create/types.d.ts.map +1 -0
- package/dist/index.cjs +1745 -891
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1698 -858
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-client.d.ts +48 -51
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +38 -0
- package/dist/mint/mint-queries.d.ts.map +1 -0
- package/dist/mint/mint-transactions.d.ts +20 -0
- package/dist/mint/mint-transactions.d.ts.map +1 -0
- package/dist/mint/subgraph-mint-getter.d.ts +24 -0
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -0
- package/dist/mint/subgraph-queries.d.ts +55 -0
- package/dist/mint/subgraph-queries.d.ts.map +1 -0
- package/dist/mint/types.d.ts +177 -0
- package/dist/mint/types.d.ts.map +1 -0
- package/dist/mint/utils.d.ts +2 -0
- package/dist/mint/utils.d.ts.map +1 -0
- package/dist/mints/mints-contracts.d.ts +27 -4518
- package/dist/mints/mints-contracts.d.ts.map +1 -1
- package/dist/premint/contract-types.d.ts +4 -4
- package/dist/premint/contract-types.d.ts.map +1 -1
- package/dist/premint/conversions.d.ts +15 -16
- package/dist/premint/conversions.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts +32 -16
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +76 -50
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +20 -8
- package/dist/premint/preminter.d.ts.map +1 -1
- package/dist/sdk.d.ts +45 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +24 -6869
- package/dist/utils.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/constants.ts +0 -36
- package/src/create/1155-create-helper.test.ts +236 -55
- package/src/create/1155-create-helper.ts +141 -309
- package/src/create/contract-setup.ts +88 -0
- package/src/create/token-setup.ts +379 -0
- package/src/create/types.ts +57 -0
- package/src/index.ts +5 -1
- package/src/mint/mint-client.test.ts +116 -78
- package/src/mint/mint-client.ts +130 -234
- package/src/mint/mint-queries.ts +320 -0
- package/src/mint/mint-transactions.ts +253 -0
- package/src/mint/subgraph-mint-getter.ts +247 -0
- package/src/mint/subgraph-queries.ts +170 -0
- package/src/mint/types.ts +239 -0
- package/src/mint/utils.ts +14 -0
- package/src/mints/mints-contracts.test.ts +1 -1
- package/src/mints/mints-contracts.ts +4 -4
- package/src/premint/contract-types.ts +4 -4
- package/src/premint/conversions.ts +38 -4
- package/src/premint/premint-api-client.ts +92 -48
- package/src/premint/premint-client.test.ts +100 -84
- package/src/premint/premint-client.ts +186 -185
- package/src/premint/preminter.test.ts +4 -5
- package/src/premint/preminter.ts +63 -14
- package/src/sdk.ts +101 -0
- package/src/types.ts +18 -0
- package/src/utils.ts +54 -46
- package/test-integration/setup-test-contracts.ts +96 -0
- package/dist/mint/mint-api-client.d.ts +0 -35
- package/dist/mint/mint-api-client.d.ts.map +0 -1
- package/src/mint/mint-api-client.ts +0 -177
- package/test-integration/premint-client.test.ts +0 -148
package/dist/index.js
CHANGED
|
@@ -20,8 +20,243 @@ import {
|
|
|
20
20
|
keccak256,
|
|
21
21
|
concat,
|
|
22
22
|
recoverAddress,
|
|
23
|
-
parseEther
|
|
23
|
+
parseEther as parseEther2
|
|
24
24
|
} from "viem";
|
|
25
|
+
|
|
26
|
+
// src/apis/chain-constants.ts
|
|
27
|
+
import {
|
|
28
|
+
arbitrum,
|
|
29
|
+
base,
|
|
30
|
+
baseSepolia,
|
|
31
|
+
foundry,
|
|
32
|
+
mainnet,
|
|
33
|
+
optimism,
|
|
34
|
+
sepolia,
|
|
35
|
+
zora,
|
|
36
|
+
zoraSepolia
|
|
37
|
+
} from "viem/chains";
|
|
38
|
+
import { parseEther } from "viem";
|
|
39
|
+
|
|
40
|
+
// src/constants.ts
|
|
41
|
+
import { parseAbi } from "viem";
|
|
42
|
+
var ZORA_API_BASE = "https://api.zora.co/";
|
|
43
|
+
var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
|
|
44
|
+
var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
|
|
45
|
+
function getSubgraph(name, version) {
|
|
46
|
+
return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
|
|
47
|
+
}
|
|
48
|
+
var zora721Abi = parseAbi([
|
|
49
|
+
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
50
|
+
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
// src/apis/chain-constants.ts
|
|
54
|
+
var REWARD_PER_TOKEN = parseEther("0.000777");
|
|
55
|
+
var networkConfigByChain = {
|
|
56
|
+
[mainnet.id]: {
|
|
57
|
+
chainId: mainnet.id,
|
|
58
|
+
isTestnet: false,
|
|
59
|
+
zoraCollectPathChainName: "eth",
|
|
60
|
+
zoraBackendChainName: "ETHEREUM-MAINNET",
|
|
61
|
+
subgraphUrl: getSubgraph("zora-create-mainnet", "stable")
|
|
62
|
+
},
|
|
63
|
+
[sepolia.id]: {
|
|
64
|
+
chainId: sepolia.id,
|
|
65
|
+
isTestnet: true,
|
|
66
|
+
zoraCollectPathChainName: "sep",
|
|
67
|
+
zoraBackendChainName: "ETHEREUM-SEPOLIA",
|
|
68
|
+
subgraphUrl: getSubgraph("zora-create-sepolia", "stable")
|
|
69
|
+
},
|
|
70
|
+
[zora.id]: {
|
|
71
|
+
chainId: zora.id,
|
|
72
|
+
isTestnet: false,
|
|
73
|
+
zoraCollectPathChainName: "zora",
|
|
74
|
+
zoraBackendChainName: "ZORA-MAINNET",
|
|
75
|
+
subgraphUrl: getSubgraph("zora-create-zora-mainnet", "stable")
|
|
76
|
+
},
|
|
77
|
+
[zoraSepolia.id]: {
|
|
78
|
+
chainId: zoraSepolia.id,
|
|
79
|
+
isTestnet: true,
|
|
80
|
+
zoraCollectPathChainName: "zsep",
|
|
81
|
+
zoraBackendChainName: "ZORA-SEPOLIA",
|
|
82
|
+
subgraphUrl: getSubgraph("zora-create-zora-sepolia", "stable")
|
|
83
|
+
},
|
|
84
|
+
[optimism.id]: {
|
|
85
|
+
chainId: optimism.id,
|
|
86
|
+
isTestnet: false,
|
|
87
|
+
zoraCollectPathChainName: "oeth",
|
|
88
|
+
zoraBackendChainName: "OPTIMISM-MAINNET",
|
|
89
|
+
subgraphUrl: getSubgraph("zora-create-optimism", "stable")
|
|
90
|
+
},
|
|
91
|
+
[arbitrum.id]: {
|
|
92
|
+
chainId: arbitrum.id,
|
|
93
|
+
isTestnet: true,
|
|
94
|
+
zoraCollectPathChainName: "arb",
|
|
95
|
+
zoraBackendChainName: "ARBITRUM-MAINNET",
|
|
96
|
+
subgraphUrl: getSubgraph("zora-create-arbitrum-one", "stable")
|
|
97
|
+
},
|
|
98
|
+
[base.id]: {
|
|
99
|
+
chainId: base.id,
|
|
100
|
+
isTestnet: false,
|
|
101
|
+
zoraCollectPathChainName: "base",
|
|
102
|
+
zoraBackendChainName: "BASE-MAINNET",
|
|
103
|
+
subgraphUrl: getSubgraph("zora-create-base-mainnet", "stable")
|
|
104
|
+
},
|
|
105
|
+
[baseSepolia.id]: {
|
|
106
|
+
chainId: baseSepolia.id,
|
|
107
|
+
isTestnet: true,
|
|
108
|
+
zoraCollectPathChainName: "bsep",
|
|
109
|
+
zoraBackendChainName: "BASE-SEPOLIA",
|
|
110
|
+
subgraphUrl: getSubgraph("zora-create-base-sepolia", "stable")
|
|
111
|
+
},
|
|
112
|
+
[foundry.id]: {
|
|
113
|
+
chainId: foundry.id,
|
|
114
|
+
isTestnet: true,
|
|
115
|
+
zoraCollectPathChainName: "zgor",
|
|
116
|
+
zoraBackendChainName: "ZORA-GOERLI",
|
|
117
|
+
subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/premint/conversions.ts
|
|
122
|
+
import {
|
|
123
|
+
PremintConfigVersion
|
|
124
|
+
} from "@zoralabs/protocol-deployments";
|
|
125
|
+
var convertCollectionFromApi = (collection) => {
|
|
126
|
+
if (!collection)
|
|
127
|
+
return void 0;
|
|
128
|
+
return {
|
|
129
|
+
additionalAdmins: collection.additionalAdmins || [],
|
|
130
|
+
contractAdmin: collection.contractAdmin,
|
|
131
|
+
contractName: collection.contractName,
|
|
132
|
+
contractURI: collection.contractURI
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
var convertPremintFromApi = (premint) => {
|
|
136
|
+
if (premint.config_version === PremintConfigVersion.V1 || !premint.config_version) {
|
|
137
|
+
const tokenConfig = premint.tokenConfig;
|
|
138
|
+
return {
|
|
139
|
+
premintConfigVersion: PremintConfigVersion.V1,
|
|
140
|
+
premintConfig: {
|
|
141
|
+
deleted: premint.deleted,
|
|
142
|
+
uid: premint.uid,
|
|
143
|
+
version: premint.version,
|
|
144
|
+
tokenConfig: {
|
|
145
|
+
...tokenConfig,
|
|
146
|
+
fixedPriceMinter: tokenConfig.fixedPriceMinter,
|
|
147
|
+
royaltyRecipient: tokenConfig.royaltyRecipient,
|
|
148
|
+
maxSupply: BigInt(tokenConfig.maxSupply),
|
|
149
|
+
pricePerToken: BigInt(tokenConfig.pricePerToken),
|
|
150
|
+
mintStart: BigInt(tokenConfig.mintStart),
|
|
151
|
+
mintDuration: BigInt(tokenConfig.mintDuration),
|
|
152
|
+
maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
} else {
|
|
157
|
+
const tokenConfig = premint.tokenConfig;
|
|
158
|
+
return {
|
|
159
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
160
|
+
premintConfig: {
|
|
161
|
+
deleted: premint.deleted,
|
|
162
|
+
uid: premint.uid,
|
|
163
|
+
version: premint.version,
|
|
164
|
+
tokenConfig: {
|
|
165
|
+
...tokenConfig,
|
|
166
|
+
fixedPriceMinter: tokenConfig.fixedPriceMinter,
|
|
167
|
+
payoutRecipient: tokenConfig.payoutRecipient,
|
|
168
|
+
createReferral: tokenConfig.createReferral,
|
|
169
|
+
maxSupply: BigInt(tokenConfig.maxSupply),
|
|
170
|
+
pricePerToken: BigInt(tokenConfig.pricePerToken),
|
|
171
|
+
mintStart: BigInt(tokenConfig.mintStart),
|
|
172
|
+
mintDuration: BigInt(tokenConfig.mintDuration),
|
|
173
|
+
maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
var convertGetPremintApiResponse = (response) => ({
|
|
180
|
+
collection: convertCollectionFromApi(response.collection),
|
|
181
|
+
collectionAddress: response.collection_address,
|
|
182
|
+
signature: response.signature,
|
|
183
|
+
signer: response.signer,
|
|
184
|
+
premint: convertPremintFromApi(response.premint)
|
|
185
|
+
});
|
|
186
|
+
var convertGetPremintOfCollectionApiResponse = (response) => ({
|
|
187
|
+
collection: convertCollectionFromApi({
|
|
188
|
+
contractAdmin: response.contract_admin,
|
|
189
|
+
contractName: response.contract_name,
|
|
190
|
+
contractURI: response.contract_uri
|
|
191
|
+
}),
|
|
192
|
+
premints: response.premints.map((premint) => ({
|
|
193
|
+
premint: convertPremintFromApi(premint),
|
|
194
|
+
signature: premint.signature
|
|
195
|
+
}))
|
|
196
|
+
});
|
|
197
|
+
var encodePremintV1ForAPI = ({
|
|
198
|
+
tokenConfig,
|
|
199
|
+
...premint
|
|
200
|
+
}) => ({
|
|
201
|
+
...premint,
|
|
202
|
+
config_version: "1",
|
|
203
|
+
tokenConfig: {
|
|
204
|
+
...tokenConfig,
|
|
205
|
+
maxSupply: tokenConfig.maxSupply.toString(),
|
|
206
|
+
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
207
|
+
mintStart: tokenConfig.mintStart.toString(),
|
|
208
|
+
mintDuration: tokenConfig.mintDuration.toString(),
|
|
209
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
var encodePremintV2ForAPI = ({
|
|
213
|
+
tokenConfig,
|
|
214
|
+
...premint
|
|
215
|
+
}) => ({
|
|
216
|
+
...premint,
|
|
217
|
+
config_version: "2",
|
|
218
|
+
tokenConfig: {
|
|
219
|
+
...tokenConfig,
|
|
220
|
+
maxSupply: tokenConfig.maxSupply.toString(),
|
|
221
|
+
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
222
|
+
mintStart: tokenConfig.mintStart.toString(),
|
|
223
|
+
mintDuration: tokenConfig.mintDuration.toString(),
|
|
224
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
var encodePremintForAPI = ({
|
|
228
|
+
premintConfig,
|
|
229
|
+
premintConfigVersion
|
|
230
|
+
}) => {
|
|
231
|
+
if (premintConfigVersion === PremintConfigVersion.V1) {
|
|
232
|
+
return encodePremintV1ForAPI(premintConfig);
|
|
233
|
+
}
|
|
234
|
+
if (premintConfigVersion === PremintConfigVersion.V2) {
|
|
235
|
+
return encodePremintV2ForAPI(premintConfig);
|
|
236
|
+
}
|
|
237
|
+
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
238
|
+
};
|
|
239
|
+
var encodePostSignatureInput = ({
|
|
240
|
+
contract: collection,
|
|
241
|
+
contractAddress: collectionAddress,
|
|
242
|
+
premintConfigVersion,
|
|
243
|
+
premintConfig,
|
|
244
|
+
signature,
|
|
245
|
+
chainId
|
|
246
|
+
}) => ({
|
|
247
|
+
premint: encodePremintForAPI({
|
|
248
|
+
premintConfig,
|
|
249
|
+
premintConfigVersion
|
|
250
|
+
}),
|
|
251
|
+
signature,
|
|
252
|
+
collection,
|
|
253
|
+
collection_address: collectionAddress,
|
|
254
|
+
chain_name: networkConfigByChain[chainId].zoraBackendChainName
|
|
255
|
+
});
|
|
256
|
+
var isPremintConfigV1 = (premintConfigAndVersion) => premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V1;
|
|
257
|
+
var isPremintConfigV2 = (premintConfigAndVersion) => premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2;
|
|
258
|
+
|
|
259
|
+
// src/premint/preminter.ts
|
|
25
260
|
var getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImplAddress[999];
|
|
26
261
|
async function isAuthorizedToCreatePremint({
|
|
27
262
|
contractAdmin = zeroAddress,
|
|
@@ -164,8 +399,8 @@ var supportsPremintVersion = async ({
|
|
|
164
399
|
};
|
|
165
400
|
async function getPremintCollectionAddress({
|
|
166
401
|
publicClient,
|
|
167
|
-
collection,
|
|
168
|
-
collectionAddress
|
|
402
|
+
contract: collection,
|
|
403
|
+
contractAddress: collectionAddress
|
|
169
404
|
}) {
|
|
170
405
|
if (typeof collection !== "undefined") {
|
|
171
406
|
return publicClient.readContract({
|
|
@@ -224,7 +459,7 @@ async function getPremintMintFee({
|
|
|
224
459
|
});
|
|
225
460
|
} catch (e) {
|
|
226
461
|
console.error(e);
|
|
227
|
-
return
|
|
462
|
+
return parseEther2("0.000777");
|
|
228
463
|
}
|
|
229
464
|
}
|
|
230
465
|
async function getPremintMintCosts({
|
|
@@ -234,12 +469,42 @@ async function getPremintMintCosts({
|
|
|
234
469
|
quantityToMint
|
|
235
470
|
}) {
|
|
236
471
|
const mintFee = await getPremintMintFee({ tokenContract, publicClient });
|
|
472
|
+
const quantityToMintBigInt = BigInt(quantityToMint);
|
|
237
473
|
return {
|
|
238
|
-
mintFee: mintFee *
|
|
239
|
-
|
|
240
|
-
|
|
474
|
+
mintFee: mintFee * quantityToMintBigInt,
|
|
475
|
+
totalPurchaseCost: tokenPrice * quantityToMintBigInt,
|
|
476
|
+
totalCostEth: (mintFee + tokenPrice) * quantityToMintBigInt
|
|
241
477
|
};
|
|
242
478
|
}
|
|
479
|
+
async function getPremintPricePerToken({
|
|
480
|
+
collection,
|
|
481
|
+
uid,
|
|
482
|
+
premintGetter
|
|
483
|
+
}) {
|
|
484
|
+
const { premint: premintConfigWithVersion } = await premintGetter.get({
|
|
485
|
+
collectionAddress: collection,
|
|
486
|
+
uid
|
|
487
|
+
});
|
|
488
|
+
if (isPremintConfigV1(premintConfigWithVersion) || isPremintConfigV2(premintConfigWithVersion)) {
|
|
489
|
+
return premintConfigWithVersion.premintConfig.tokenConfig.pricePerToken;
|
|
490
|
+
}
|
|
491
|
+
throw new Error("Premint version not supported to get price");
|
|
492
|
+
}
|
|
493
|
+
async function getPremintMintCostsWithUnknownTokenPrice({
|
|
494
|
+
premintGetter,
|
|
495
|
+
uid,
|
|
496
|
+
...rest
|
|
497
|
+
}) {
|
|
498
|
+
const pricePerToken = await getPremintPricePerToken({
|
|
499
|
+
uid,
|
|
500
|
+
premintGetter,
|
|
501
|
+
collection: rest.tokenContract
|
|
502
|
+
});
|
|
503
|
+
return await getPremintMintCosts({
|
|
504
|
+
...rest,
|
|
505
|
+
tokenPrice: pricePerToken
|
|
506
|
+
});
|
|
507
|
+
}
|
|
243
508
|
function makeMintRewardsRecipient({
|
|
244
509
|
mintReferral = zeroAddress,
|
|
245
510
|
platformReferral = zeroAddress
|
|
@@ -267,12 +532,12 @@ var toContractCreationConfigOrAddress = ({
|
|
|
267
532
|
}) => {
|
|
268
533
|
if (typeof collection !== "undefined") {
|
|
269
534
|
return {
|
|
270
|
-
collection
|
|
535
|
+
contract: collection
|
|
271
536
|
};
|
|
272
537
|
}
|
|
273
538
|
if (typeof collectionAddress !== "undefined") {
|
|
274
539
|
return {
|
|
275
|
-
collectionAddress
|
|
540
|
+
contractAddress: collectionAddress
|
|
276
541
|
};
|
|
277
542
|
}
|
|
278
543
|
throw new Error("Must provide either a collection or a collection address");
|
|
@@ -358,19 +623,39 @@ var httpClient = {
|
|
|
358
623
|
retries
|
|
359
624
|
};
|
|
360
625
|
|
|
361
|
-
// src/
|
|
362
|
-
|
|
363
|
-
var
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
function getSubgraph(name, version) {
|
|
367
|
-
return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
|
|
626
|
+
// src/mint/types.ts
|
|
627
|
+
var isOnChainMint = (mint2) => mint2.mintType !== "premint";
|
|
628
|
+
var is1155Mint = (mint2) => mint2.mintType === "1155";
|
|
629
|
+
function isErc20SaleStrategy(salesConfig) {
|
|
630
|
+
return salesConfig.saleType === "erc20";
|
|
368
631
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
632
|
+
|
|
633
|
+
// src/utils.ts
|
|
634
|
+
var makeContractParameters = (args) => args;
|
|
635
|
+
function mintRecipientOrAccount({
|
|
636
|
+
mintRecipient,
|
|
637
|
+
minterAccount
|
|
638
|
+
}) {
|
|
639
|
+
return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
|
|
640
|
+
}
|
|
641
|
+
async function querySubgraphWithRetries({
|
|
642
|
+
httpClient: httpClient2,
|
|
643
|
+
subgraphUrl,
|
|
644
|
+
query,
|
|
645
|
+
variables
|
|
646
|
+
}) {
|
|
647
|
+
const { retries: retries2, post: post2 } = httpClient2;
|
|
648
|
+
const result = await retries2(async () => {
|
|
649
|
+
return await post2(subgraphUrl, {
|
|
650
|
+
query,
|
|
651
|
+
variables
|
|
652
|
+
});
|
|
653
|
+
});
|
|
654
|
+
return result?.data;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/mint/subgraph-queries.ts
|
|
658
|
+
var NFT_SALE_STRATEGY_FRAGMENT = `
|
|
374
659
|
fragment SaleStrategy on SalesStrategyConfig {
|
|
375
660
|
type
|
|
376
661
|
fixedPrice {
|
|
@@ -388,392 +673,265 @@ fragment SaleStrategy on SalesStrategyConfig {
|
|
|
388
673
|
saleStart
|
|
389
674
|
maxTokensPerAddress
|
|
390
675
|
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
676
|
+
}`;
|
|
677
|
+
var TOKEN_FRAGMENT = `
|
|
678
|
+
fragment Token on ZoraCreateToken {
|
|
679
|
+
creator
|
|
680
|
+
tokenId
|
|
681
|
+
uri
|
|
682
|
+
totalMinted
|
|
683
|
+
maxSupply
|
|
684
|
+
tokenStandard
|
|
685
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
686
|
+
...SaleStrategy
|
|
687
|
+
}
|
|
396
688
|
contract {
|
|
689
|
+
address
|
|
397
690
|
mintFeePerQuantity
|
|
691
|
+
contractVersion
|
|
692
|
+
contractURI
|
|
693
|
+
name
|
|
398
694
|
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
399
695
|
...SaleStrategy
|
|
400
696
|
}
|
|
401
697
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
698
|
+
}`;
|
|
699
|
+
var FRAGMENTS = `
|
|
700
|
+
${NFT_SALE_STRATEGY_FRAGMENT}
|
|
701
|
+
${TOKEN_FRAGMENT}
|
|
702
|
+
`;
|
|
703
|
+
function buildNftTokenSalesQuery({
|
|
704
|
+
tokenId,
|
|
705
|
+
tokenAddress
|
|
706
|
+
}) {
|
|
707
|
+
return {
|
|
708
|
+
query: `
|
|
709
|
+
${FRAGMENTS}
|
|
710
|
+
query ($id: ID!) {
|
|
711
|
+
zoraCreateToken(id: $id) {
|
|
712
|
+
...Token
|
|
405
713
|
}
|
|
406
714
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
zoraBackendChainName: "ETHEREUM-MAINNET",
|
|
429
|
-
subgraphUrl: getSubgraph("zora-create-mainnet", "stable")
|
|
430
|
-
},
|
|
431
|
-
[sepolia.id]: {
|
|
432
|
-
chainId: sepolia.id,
|
|
433
|
-
isTestnet: true,
|
|
434
|
-
zoraCollectPathChainName: "sep",
|
|
435
|
-
zoraBackendChainName: "ETHEREUM-SEPOLIA",
|
|
436
|
-
subgraphUrl: getSubgraph("zora-create-sepolia", "stable")
|
|
437
|
-
},
|
|
438
|
-
[zora.id]: {
|
|
439
|
-
chainId: zora.id,
|
|
440
|
-
isTestnet: false,
|
|
441
|
-
zoraCollectPathChainName: "zora",
|
|
442
|
-
zoraBackendChainName: "ZORA-MAINNET",
|
|
443
|
-
subgraphUrl: getSubgraph("zora-create-zora-mainnet", "stable")
|
|
444
|
-
},
|
|
445
|
-
[zoraSepolia.id]: {
|
|
446
|
-
chainId: zoraSepolia.id,
|
|
447
|
-
isTestnet: true,
|
|
448
|
-
zoraCollectPathChainName: "zsep",
|
|
449
|
-
zoraBackendChainName: "ZORA-SEPOLIA",
|
|
450
|
-
subgraphUrl: getSubgraph("zora-create-zora-sepolia", "stable")
|
|
451
|
-
},
|
|
452
|
-
[optimism.id]: {
|
|
453
|
-
chainId: optimism.id,
|
|
454
|
-
isTestnet: false,
|
|
455
|
-
zoraCollectPathChainName: "oeth",
|
|
456
|
-
zoraBackendChainName: "OPTIMISM-MAINNET",
|
|
457
|
-
subgraphUrl: getSubgraph("zora-create-optimism", "stable")
|
|
458
|
-
},
|
|
459
|
-
[arbitrum.id]: {
|
|
460
|
-
chainId: arbitrum.id,
|
|
461
|
-
isTestnet: true,
|
|
462
|
-
zoraCollectPathChainName: "arb",
|
|
463
|
-
zoraBackendChainName: "ARBITRUM-MAINNET",
|
|
464
|
-
subgraphUrl: getSubgraph("zora-create-arbitrum-one", "stable")
|
|
465
|
-
},
|
|
466
|
-
[base.id]: {
|
|
467
|
-
chainId: base.id,
|
|
468
|
-
isTestnet: false,
|
|
469
|
-
zoraCollectPathChainName: "base",
|
|
470
|
-
zoraBackendChainName: "BASE-MAINNET",
|
|
471
|
-
subgraphUrl: getSubgraph("zora-create-base-mainnet", "stable")
|
|
472
|
-
},
|
|
473
|
-
[baseSepolia.id]: {
|
|
474
|
-
chainId: baseSepolia.id,
|
|
475
|
-
isTestnet: true,
|
|
476
|
-
zoraCollectPathChainName: "bsep",
|
|
477
|
-
zoraBackendChainName: "BASE-SEPOLIA",
|
|
478
|
-
subgraphUrl: getSubgraph("zora-create-base-sepolia", "stable")
|
|
479
|
-
},
|
|
480
|
-
[foundry.id]: {
|
|
481
|
-
chainId: foundry.id,
|
|
482
|
-
isTestnet: true,
|
|
483
|
-
zoraCollectPathChainName: "zgor",
|
|
484
|
-
zoraBackendChainName: "ZORA-GOERLI",
|
|
485
|
-
subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
|
|
715
|
+
`,
|
|
716
|
+
variables: {
|
|
717
|
+
id: tokenId !== void 0 ? (
|
|
718
|
+
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
719
|
+
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
720
|
+
) : `${tokenAddress.toLowerCase()}-0`
|
|
721
|
+
},
|
|
722
|
+
parseResponseData: (responseData) => responseData?.zoraCreateToken
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
function buildContractTokensQuery({
|
|
726
|
+
tokenAddress
|
|
727
|
+
}) {
|
|
728
|
+
return {
|
|
729
|
+
query: `
|
|
730
|
+
${FRAGMENTS}
|
|
731
|
+
query ($contract: Bytes!) {
|
|
732
|
+
zoraCreateTokens(
|
|
733
|
+
where: {address: $contract}
|
|
734
|
+
) {
|
|
735
|
+
...Token
|
|
486
736
|
}
|
|
487
|
-
}
|
|
737
|
+
}
|
|
738
|
+
`,
|
|
739
|
+
variables: {
|
|
740
|
+
contract: tokenAddress.toLowerCase()
|
|
741
|
+
},
|
|
742
|
+
parseResponseData: (responseData) => responseData?.zoraCreateTokens
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
function buildPremintsOfContractQuery({
|
|
746
|
+
tokenAddress
|
|
747
|
+
}) {
|
|
748
|
+
return {
|
|
749
|
+
query: `
|
|
750
|
+
query ($contractAddress: Bytes!) {
|
|
751
|
+
premints(where:{contractAddress:$contractAddress}) {
|
|
752
|
+
uid
|
|
753
|
+
tokenId
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
`,
|
|
757
|
+
variables: {
|
|
758
|
+
contractAddress: tokenAddress.toLowerCase()
|
|
759
|
+
},
|
|
760
|
+
parseResponseData: (responseData) => responseData?.premints
|
|
761
|
+
};
|
|
762
|
+
}
|
|
488
763
|
|
|
489
|
-
// src/mint/mint-
|
|
764
|
+
// src/mint/subgraph-mint-getter.ts
|
|
490
765
|
var getApiNetworkConfigForChain = (chainId) => {
|
|
491
766
|
if (!networkConfigByChain[chainId]) {
|
|
492
767
|
throw new Error(`chain id ${chainId} network not configured `);
|
|
493
768
|
}
|
|
494
769
|
return networkConfigByChain[chainId];
|
|
495
770
|
};
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
this.httpClient = httpClient2 || httpClient;
|
|
499
|
-
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
500
|
-
}
|
|
501
|
-
async getSalesConfigAndTokenInfo({
|
|
502
|
-
tokenAddress,
|
|
503
|
-
tokenId,
|
|
504
|
-
saleType
|
|
505
|
-
}) {
|
|
506
|
-
const { retries: retries2, post: post2 } = this.httpClient;
|
|
507
|
-
return retries2(async () => {
|
|
508
|
-
const response = await post2(this.networkConfig.subgraphUrl, {
|
|
509
|
-
query: NFT_SALE_QUERY,
|
|
510
|
-
variables: {
|
|
511
|
-
id: tokenId !== void 0 ? (
|
|
512
|
-
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
513
|
-
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
514
|
-
) : `${tokenAddress.toLowerCase()}-0`
|
|
515
|
-
}
|
|
516
|
-
});
|
|
517
|
-
const token = response.data?.zoraCreateToken;
|
|
518
|
-
if (!token) {
|
|
519
|
-
throw new Error("Cannot find a token to mint");
|
|
520
|
-
}
|
|
521
|
-
const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
|
|
522
|
-
const saleStrategies = allStrategies.sort(
|
|
523
|
-
(a, b) => BigInt(
|
|
524
|
-
a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd
|
|
525
|
-
) > BigInt(
|
|
526
|
-
b.type === "FIXED_PRICE" ? b.fixedPrice.saleEnd : b.erc20Minter.saleEnd
|
|
527
|
-
) ? 1 : -1
|
|
528
|
-
);
|
|
529
|
-
let targetStrategy;
|
|
530
|
-
if (!saleType) {
|
|
531
|
-
targetStrategy = saleStrategies[0];
|
|
532
|
-
if (!targetStrategy) {
|
|
533
|
-
throw new Error("Cannot find sale strategy");
|
|
534
|
-
}
|
|
535
|
-
} else {
|
|
536
|
-
const mappedSaleType = saleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
|
|
537
|
-
targetStrategy = saleStrategies.find(
|
|
538
|
-
(strategy) => strategy.type === mappedSaleType
|
|
539
|
-
);
|
|
540
|
-
if (!targetStrategy) {
|
|
541
|
-
throw new Error(`Cannot find sale strategy for ${mappedSaleType}`);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
if (targetStrategy.type === "FIXED_PRICE") {
|
|
545
|
-
return {
|
|
546
|
-
salesConfig: {
|
|
547
|
-
saleType: "fixedPrice",
|
|
548
|
-
...targetStrategy.fixedPrice,
|
|
549
|
-
maxTokensPerAddress: BigInt(
|
|
550
|
-
targetStrategy.fixedPrice.maxTokensPerAddress
|
|
551
|
-
),
|
|
552
|
-
pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
|
|
553
|
-
},
|
|
554
|
-
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
if (targetStrategy.type === "ERC_20_MINTER") {
|
|
558
|
-
return {
|
|
559
|
-
salesConfig: {
|
|
560
|
-
saleType: "erc20",
|
|
561
|
-
...targetStrategy.erc20Minter,
|
|
562
|
-
maxTokensPerAddress: BigInt(
|
|
563
|
-
targetStrategy.erc20Minter.maxTokensPerAddress
|
|
564
|
-
),
|
|
565
|
-
pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
|
|
566
|
-
},
|
|
567
|
-
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
throw new Error("Invalid saleType");
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
// src/premint/conversions.ts
|
|
576
|
-
import {
|
|
577
|
-
PremintConfigVersion
|
|
578
|
-
} from "@zoralabs/protocol-deployments";
|
|
579
|
-
var convertCollectionFromApi = (collection) => {
|
|
580
|
-
if (!collection)
|
|
581
|
-
return void 0;
|
|
582
|
-
return {
|
|
583
|
-
additionalAdmins: collection.additionalAdmins || [],
|
|
584
|
-
contractAdmin: collection.contractAdmin,
|
|
585
|
-
contractName: collection.contractName,
|
|
586
|
-
contractURI: collection.contractURI
|
|
587
|
-
};
|
|
588
|
-
};
|
|
589
|
-
var convertPremintFromApi = (premint) => {
|
|
590
|
-
if (premint.config_version === PremintConfigVersion.V1 || !premint.config_version) {
|
|
591
|
-
const tokenConfig = premint.tokenConfig;
|
|
771
|
+
function parseSalesConfig(targetStrategy) {
|
|
772
|
+
if (targetStrategy.type === "FIXED_PRICE")
|
|
592
773
|
return {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
...tokenConfig,
|
|
600
|
-
fixedPriceMinter: tokenConfig.fixedPriceMinter,
|
|
601
|
-
royaltyRecipient: tokenConfig.royaltyRecipient,
|
|
602
|
-
maxSupply: BigInt(tokenConfig.maxSupply),
|
|
603
|
-
pricePerToken: BigInt(tokenConfig.pricePerToken),
|
|
604
|
-
mintStart: BigInt(tokenConfig.mintStart),
|
|
605
|
-
mintDuration: BigInt(tokenConfig.mintDuration),
|
|
606
|
-
maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
|
|
607
|
-
}
|
|
608
|
-
}
|
|
774
|
+
saleType: "fixedPrice",
|
|
775
|
+
...targetStrategy.fixedPrice,
|
|
776
|
+
maxTokensPerAddress: BigInt(
|
|
777
|
+
targetStrategy.fixedPrice.maxTokensPerAddress
|
|
778
|
+
),
|
|
779
|
+
pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
|
|
609
780
|
};
|
|
610
|
-
|
|
611
|
-
const tokenConfig = premint.tokenConfig;
|
|
781
|
+
if (targetStrategy.type === "ERC_20_MINTER") {
|
|
612
782
|
return {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
...tokenConfig,
|
|
620
|
-
fixedPriceMinter: tokenConfig.fixedPriceMinter,
|
|
621
|
-
payoutRecipient: tokenConfig.payoutRecipient,
|
|
622
|
-
createReferral: tokenConfig.createReferral,
|
|
623
|
-
maxSupply: BigInt(tokenConfig.maxSupply),
|
|
624
|
-
pricePerToken: BigInt(tokenConfig.pricePerToken),
|
|
625
|
-
mintStart: BigInt(tokenConfig.mintStart),
|
|
626
|
-
mintDuration: BigInt(tokenConfig.mintDuration),
|
|
627
|
-
maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
|
|
628
|
-
}
|
|
629
|
-
}
|
|
783
|
+
saleType: "erc20",
|
|
784
|
+
...targetStrategy.erc20Minter,
|
|
785
|
+
maxTokensPerAddress: BigInt(
|
|
786
|
+
targetStrategy.erc20Minter.maxTokensPerAddress
|
|
787
|
+
),
|
|
788
|
+
pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
|
|
630
789
|
};
|
|
631
790
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
signature: response.signature
|
|
638
|
-
});
|
|
639
|
-
var encodePremintV1ForAPI = ({
|
|
640
|
-
tokenConfig,
|
|
641
|
-
...premint
|
|
642
|
-
}) => ({
|
|
643
|
-
...premint,
|
|
644
|
-
config_version: "1",
|
|
645
|
-
tokenConfig: {
|
|
646
|
-
...tokenConfig,
|
|
647
|
-
maxSupply: tokenConfig.maxSupply.toString(),
|
|
648
|
-
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
649
|
-
mintStart: tokenConfig.mintStart.toString(),
|
|
650
|
-
mintDuration: tokenConfig.mintDuration.toString(),
|
|
651
|
-
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
652
|
-
}
|
|
653
|
-
});
|
|
654
|
-
var encodePremintV2ForAPI = ({
|
|
655
|
-
tokenConfig,
|
|
656
|
-
...premint
|
|
657
|
-
}) => ({
|
|
658
|
-
...premint,
|
|
659
|
-
config_version: "2",
|
|
660
|
-
tokenConfig: {
|
|
661
|
-
...tokenConfig,
|
|
662
|
-
maxSupply: tokenConfig.maxSupply.toString(),
|
|
663
|
-
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
664
|
-
mintStart: tokenConfig.mintStart.toString(),
|
|
665
|
-
mintDuration: tokenConfig.mintDuration.toString(),
|
|
666
|
-
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
var encodePremintForAPI = ({
|
|
670
|
-
premintConfig,
|
|
671
|
-
premintConfigVersion
|
|
672
|
-
}) => {
|
|
673
|
-
if (premintConfigVersion === PremintConfigVersion.V1) {
|
|
674
|
-
return encodePremintV1ForAPI(premintConfig);
|
|
675
|
-
}
|
|
676
|
-
if (premintConfigVersion === PremintConfigVersion.V2) {
|
|
677
|
-
return encodePremintV2ForAPI(premintConfig);
|
|
678
|
-
}
|
|
679
|
-
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
680
|
-
};
|
|
681
|
-
var encodePostSignatureInput = ({
|
|
682
|
-
collection,
|
|
683
|
-
collectionAddress,
|
|
684
|
-
premintConfigVersion,
|
|
685
|
-
premintConfig,
|
|
686
|
-
signature,
|
|
687
|
-
chainId
|
|
688
|
-
}) => ({
|
|
689
|
-
premint: encodePremintForAPI({
|
|
690
|
-
premintConfig,
|
|
691
|
-
premintConfigVersion
|
|
692
|
-
}),
|
|
693
|
-
signature,
|
|
694
|
-
collection,
|
|
695
|
-
collection_address: collectionAddress,
|
|
696
|
-
chain_name: networkConfigByChain[chainId].zoraBackendChainName
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
// src/premint/premint-api-client.ts
|
|
700
|
-
var postSignature = async ({
|
|
701
|
-
httpClient: { post: post2, retries: retries2 } = httpClient,
|
|
702
|
-
...data
|
|
703
|
-
}) => retries2(
|
|
704
|
-
() => post2(`${ZORA_API_BASE}premint/signature`, data)
|
|
705
|
-
);
|
|
706
|
-
var getNextUID = async ({
|
|
707
|
-
chain_name,
|
|
708
|
-
collection_address,
|
|
709
|
-
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
710
|
-
}) => retries2(
|
|
711
|
-
() => get2(
|
|
712
|
-
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
|
|
713
|
-
)
|
|
714
|
-
);
|
|
715
|
-
var getSignature = async ({
|
|
716
|
-
collection_address,
|
|
717
|
-
uid,
|
|
718
|
-
chain_name,
|
|
719
|
-
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
720
|
-
}) => {
|
|
721
|
-
const result = await retries2(
|
|
722
|
-
() => get2(
|
|
723
|
-
`${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
|
|
724
|
-
)
|
|
791
|
+
throw new Error("Unknown saleType");
|
|
792
|
+
}
|
|
793
|
+
function getSaleEnd(a) {
|
|
794
|
+
return BigInt(
|
|
795
|
+
a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd
|
|
725
796
|
);
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
797
|
+
}
|
|
798
|
+
function getTargetStrategy({
|
|
799
|
+
tokenId,
|
|
800
|
+
preferredSaleType,
|
|
801
|
+
token
|
|
802
|
+
}) {
|
|
803
|
+
const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
|
|
804
|
+
const saleStrategies = allStrategies.sort(
|
|
805
|
+
(a, b) => getSaleEnd(a) > getSaleEnd(b) ? 1 : -1
|
|
806
|
+
);
|
|
807
|
+
let targetStrategy;
|
|
808
|
+
if (!preferredSaleType) {
|
|
809
|
+
targetStrategy = saleStrategies[0];
|
|
810
|
+
if (!targetStrategy) {
|
|
811
|
+
throw new Error("Cannot find sale strategy");
|
|
812
|
+
}
|
|
813
|
+
} else {
|
|
814
|
+
const mappedSaleType = preferredSaleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
|
|
815
|
+
targetStrategy = saleStrategies.find(
|
|
816
|
+
(strategy) => strategy.type === mappedSaleType
|
|
817
|
+
);
|
|
818
|
+
if (!targetStrategy) {
|
|
819
|
+
const targetStrategy2 = saleStrategies.find(
|
|
820
|
+
(strategy) => strategy.type === "FIXED_PRICE" || strategy.type === "ERC_20_MINTER"
|
|
821
|
+
);
|
|
822
|
+
if (!targetStrategy2)
|
|
823
|
+
throw new Error("Cannot find valid sale strategy");
|
|
824
|
+
return targetStrategy2;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return targetStrategy;
|
|
828
|
+
}
|
|
829
|
+
var SubgraphMintGetter = class {
|
|
729
830
|
constructor(chainId, httpClient2) {
|
|
730
|
-
this.
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
const data = encodePostSignatureInput({
|
|
735
|
-
...rest,
|
|
736
|
-
chainId: this.networkConfig.chainId,
|
|
737
|
-
signature
|
|
738
|
-
});
|
|
739
|
-
return postSignature({
|
|
740
|
-
...data,
|
|
741
|
-
httpClient: this.httpClient
|
|
742
|
-
});
|
|
743
|
-
};
|
|
744
|
-
this.getNextUID = async (collectionAddress) => (await getNextUID({
|
|
745
|
-
collection_address: collectionAddress.toLowerCase(),
|
|
746
|
-
chain_name: this.networkConfig.zoraBackendChainName,
|
|
747
|
-
httpClient: this.httpClient
|
|
748
|
-
})).next_uid;
|
|
749
|
-
this.getSignature = async ({
|
|
750
|
-
collectionAddress,
|
|
751
|
-
uid
|
|
831
|
+
this.getMintable = async ({
|
|
832
|
+
tokenAddress,
|
|
833
|
+
tokenId,
|
|
834
|
+
preferredSaleType: saleType
|
|
752
835
|
}) => {
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
836
|
+
const token = await this.querySubgraphWithRetries(
|
|
837
|
+
buildNftTokenSalesQuery({
|
|
838
|
+
tokenId,
|
|
839
|
+
tokenAddress
|
|
840
|
+
})
|
|
841
|
+
);
|
|
842
|
+
if (!token) {
|
|
843
|
+
throw new Error("Cannot find token");
|
|
844
|
+
}
|
|
845
|
+
return parseTokenQueryResult({
|
|
846
|
+
token,
|
|
847
|
+
tokenId,
|
|
848
|
+
preferredSaleType: saleType
|
|
758
849
|
});
|
|
759
|
-
return convertGetPremintApiResponse(response);
|
|
760
850
|
};
|
|
761
851
|
this.httpClient = httpClient2 || httpClient;
|
|
762
852
|
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
763
853
|
}
|
|
854
|
+
async querySubgraphWithRetries({
|
|
855
|
+
query,
|
|
856
|
+
variables,
|
|
857
|
+
parseResponseData
|
|
858
|
+
}) {
|
|
859
|
+
const responseData = await querySubgraphWithRetries({
|
|
860
|
+
httpClient: this.httpClient,
|
|
861
|
+
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
862
|
+
query,
|
|
863
|
+
variables
|
|
864
|
+
});
|
|
865
|
+
return parseResponseData(responseData);
|
|
866
|
+
}
|
|
867
|
+
async getContractMintable({
|
|
868
|
+
tokenAddress,
|
|
869
|
+
preferredSaleType
|
|
870
|
+
}) {
|
|
871
|
+
const tokens = await this.querySubgraphWithRetries(
|
|
872
|
+
buildContractTokensQuery({
|
|
873
|
+
tokenAddress
|
|
874
|
+
})
|
|
875
|
+
);
|
|
876
|
+
if (!tokens)
|
|
877
|
+
return [];
|
|
878
|
+
return tokens.filter((x) => x.tokenId !== "0").map(
|
|
879
|
+
(token) => parseTokenQueryResult({
|
|
880
|
+
token,
|
|
881
|
+
tokenId: token.tokenId,
|
|
882
|
+
preferredSaleType
|
|
883
|
+
})
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
async getContractPremintTokenIds({
|
|
887
|
+
tokenAddress
|
|
888
|
+
}) {
|
|
889
|
+
const premints = await this.querySubgraphWithRetries(
|
|
890
|
+
buildPremintsOfContractQuery({
|
|
891
|
+
tokenAddress
|
|
892
|
+
})
|
|
893
|
+
);
|
|
894
|
+
return premints?.map((premint) => ({
|
|
895
|
+
tokenId: BigInt(premint.tokenId),
|
|
896
|
+
uid: +premint.uid
|
|
897
|
+
})) || [];
|
|
898
|
+
}
|
|
764
899
|
};
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
900
|
+
function parseTokenQueryResult({
|
|
901
|
+
token,
|
|
902
|
+
tokenId,
|
|
903
|
+
preferredSaleType
|
|
904
|
+
}) {
|
|
905
|
+
const targetStrategy = getTargetStrategy({
|
|
906
|
+
tokenId,
|
|
907
|
+
preferredSaleType,
|
|
908
|
+
token
|
|
909
|
+
});
|
|
910
|
+
const tokenInfo = parseTokenInfo(token);
|
|
911
|
+
const salesConfig = parseSalesConfig(targetStrategy);
|
|
912
|
+
if (isErc20SaleStrategy(salesConfig)) {
|
|
913
|
+
tokenInfo.mintFeePerQuantity = 0n;
|
|
914
|
+
}
|
|
915
|
+
return {
|
|
916
|
+
...tokenInfo,
|
|
917
|
+
salesConfig
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
function parseTokenInfo(token) {
|
|
773
921
|
return {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
922
|
+
contract: {
|
|
923
|
+
address: token.contract.address,
|
|
924
|
+
name: token.contract.name,
|
|
925
|
+
URI: token.contract.contractURI
|
|
926
|
+
},
|
|
927
|
+
tokenURI: token.uri,
|
|
928
|
+
tokenId: token.tokenId ? BigInt(token.tokenId) : void 0,
|
|
929
|
+
mintType: token.tokenStandard === "ERC721" ? "721" : "1155",
|
|
930
|
+
creator: token.creator,
|
|
931
|
+
totalMinted: BigInt(token.totalMinted),
|
|
932
|
+
maxSupply: BigInt(token.maxSupply),
|
|
933
|
+
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity),
|
|
934
|
+
contractVersion: token.contract.contractVersion
|
|
777
935
|
};
|
|
778
936
|
}
|
|
779
937
|
|
|
@@ -782,8 +940,7 @@ var defaultTokenConfigV1MintArguments = () => ({
|
|
|
782
940
|
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
783
941
|
maxTokensPerAddress: 0n,
|
|
784
942
|
pricePerToken: 0n,
|
|
785
|
-
mintDuration:
|
|
786
|
-
// 1 week
|
|
943
|
+
mintDuration: 0n,
|
|
787
944
|
mintStart: 0n,
|
|
788
945
|
royaltyMintSchedule: 0,
|
|
789
946
|
royaltyBPS: 1e3
|
|
@@ -824,8 +981,7 @@ var defaultTokenConfigV2MintArguments = () => ({
|
|
|
824
981
|
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
825
982
|
maxTokensPerAddress: 0n,
|
|
826
983
|
pricePerToken: 0n,
|
|
827
|
-
mintDuration:
|
|
828
|
-
// 1 week
|
|
984
|
+
mintDuration: 0n,
|
|
829
985
|
mintStart: 0n,
|
|
830
986
|
royaltyBPS: 1e3
|
|
831
987
|
// 10%,
|
|
@@ -872,20 +1028,17 @@ function getPremintedLogFromReceipt(receipt) {
|
|
|
872
1028
|
}
|
|
873
1029
|
}
|
|
874
1030
|
var PremintClient = class {
|
|
875
|
-
constructor(
|
|
876
|
-
|
|
877
|
-
|
|
1031
|
+
constructor({
|
|
1032
|
+
chainId,
|
|
1033
|
+
publicClient,
|
|
1034
|
+
premintApi
|
|
1035
|
+
}) {
|
|
1036
|
+
this.chainId = chainId;
|
|
1037
|
+
this.apiClient = premintApi;
|
|
878
1038
|
this.publicClient = publicClient;
|
|
879
1039
|
}
|
|
880
|
-
getDataFromPremintReceipt(receipt) {
|
|
881
|
-
|
|
882
|
-
return {
|
|
883
|
-
premintedLog,
|
|
884
|
-
urls: this.makeUrls({
|
|
885
|
-
address: premintedLog?.contractAddress,
|
|
886
|
-
tokenId: premintedLog?.tokenId
|
|
887
|
-
})
|
|
888
|
-
};
|
|
1040
|
+
getDataFromPremintReceipt(receipt, blockExplorerUrl) {
|
|
1041
|
+
return getDataFromPremintReceipt(receipt, this.chainId, blockExplorerUrl);
|
|
889
1042
|
}
|
|
890
1043
|
/**
|
|
891
1044
|
* Prepares data for updating a premint
|
|
@@ -898,7 +1051,7 @@ var PremintClient = class {
|
|
|
898
1051
|
...args,
|
|
899
1052
|
apiClient: this.apiClient,
|
|
900
1053
|
publicClient: this.publicClient,
|
|
901
|
-
chainId: this.
|
|
1054
|
+
chainId: this.chainId
|
|
902
1055
|
});
|
|
903
1056
|
}
|
|
904
1057
|
/**
|
|
@@ -912,7 +1065,7 @@ var PremintClient = class {
|
|
|
912
1065
|
...params,
|
|
913
1066
|
apiClient: this.apiClient,
|
|
914
1067
|
publicClient: this.publicClient,
|
|
915
|
-
chainId: this.
|
|
1068
|
+
chainId: this.chainId
|
|
916
1069
|
});
|
|
917
1070
|
}
|
|
918
1071
|
/**
|
|
@@ -926,7 +1079,7 @@ var PremintClient = class {
|
|
|
926
1079
|
...parameters,
|
|
927
1080
|
publicClient: this.publicClient,
|
|
928
1081
|
apiClient: this.apiClient,
|
|
929
|
-
chainId: this.
|
|
1082
|
+
chainId: this.chainId
|
|
930
1083
|
});
|
|
931
1084
|
}
|
|
932
1085
|
/**
|
|
@@ -936,11 +1089,8 @@ var PremintClient = class {
|
|
|
936
1089
|
* @param uid UID for the desired premint
|
|
937
1090
|
* @returns PremintSignatureGetResponse of premint data from the API
|
|
938
1091
|
*/
|
|
939
|
-
async
|
|
940
|
-
|
|
941
|
-
uid
|
|
942
|
-
}) {
|
|
943
|
-
return await this.apiClient.getSignature({
|
|
1092
|
+
async getPremint({ address, uid }) {
|
|
1093
|
+
return await this.apiClient.get({
|
|
944
1094
|
collectionAddress: address,
|
|
945
1095
|
uid
|
|
946
1096
|
});
|
|
@@ -948,51 +1098,12 @@ var PremintClient = class {
|
|
|
948
1098
|
/**
|
|
949
1099
|
* Gets the deterministic contract address for a premint collection
|
|
950
1100
|
* @param collection Collection to get the address for
|
|
951
|
-
* @returns deterministic contract address
|
|
952
|
-
*/
|
|
953
|
-
async getCollectionAddress(collection) {
|
|
954
|
-
return await getPremintCollectionAddress({
|
|
955
|
-
collection,
|
|
956
|
-
publicClient: this.publicClient
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* Check user signature for v1
|
|
961
|
-
*
|
|
962
|
-
* @param data Signature data from the API
|
|
963
|
-
* @returns isValid = signature is valid or not, recoveredSigner = signer from contract
|
|
964
|
-
*/
|
|
965
|
-
async isValidSignature({
|
|
966
|
-
signature,
|
|
967
|
-
premintConfig,
|
|
968
|
-
premintConfigVersion,
|
|
969
|
-
...collectionAndOrAddress
|
|
970
|
-
}) {
|
|
971
|
-
const collectionAddressToUse = await getPremintCollectionAddress({
|
|
972
|
-
...collectionAndOrAddress,
|
|
973
|
-
publicClient: this.publicClient
|
|
974
|
-
});
|
|
975
|
-
const { isAuthorized, recoveredAddress } = await isValidSignature({
|
|
976
|
-
chainId: this.chain.id,
|
|
977
|
-
signature,
|
|
978
|
-
publicClient: this.publicClient,
|
|
979
|
-
premintConfig,
|
|
980
|
-
premintConfigVersion: premintConfigVersion || PremintConfigVersion2.V1,
|
|
981
|
-
collectionAddress: collectionAddressToUse,
|
|
982
|
-
collection: collectionAndOrAddress.collection
|
|
983
|
-
});
|
|
984
|
-
return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
|
|
985
|
-
}
|
|
986
|
-
makeUrls({
|
|
987
|
-
uid,
|
|
988
|
-
address,
|
|
989
|
-
tokenId
|
|
990
|
-
}) {
|
|
991
|
-
return makeUrls({
|
|
992
|
-
uid,
|
|
993
|
-
address,
|
|
994
|
-
tokenId,
|
|
995
|
-
chain: this.chain
|
|
1101
|
+
* @returns deterministic contract address
|
|
1102
|
+
*/
|
|
1103
|
+
async getCollectionAddress(collection) {
|
|
1104
|
+
return await getPremintCollectionAddress({
|
|
1105
|
+
contract: collection,
|
|
1106
|
+
publicClient: this.publicClient
|
|
996
1107
|
});
|
|
997
1108
|
}
|
|
998
1109
|
async getMintCosts({
|
|
@@ -1014,17 +1125,40 @@ var PremintClient = class {
|
|
|
1014
1125
|
* @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
|
|
1015
1126
|
* @returns receipt, log, zoraURL
|
|
1016
1127
|
*/
|
|
1017
|
-
async makeMintParameters(
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1128
|
+
async makeMintParameters({
|
|
1129
|
+
minterAccount,
|
|
1130
|
+
tokenContract,
|
|
1131
|
+
uid,
|
|
1132
|
+
mintArguments,
|
|
1133
|
+
firstMinter
|
|
1134
|
+
}) {
|
|
1135
|
+
return await collectPremint({
|
|
1136
|
+
uid,
|
|
1137
|
+
tokenContract,
|
|
1138
|
+
minterAccount,
|
|
1139
|
+
quantityToMint: mintArguments?.quantityToMint || 1n,
|
|
1140
|
+
mintComment: mintArguments?.mintComment,
|
|
1141
|
+
mintReferral: mintArguments?.mintReferral,
|
|
1142
|
+
mintRecipient: mintArguments?.mintRecipient,
|
|
1143
|
+
firstMinter,
|
|
1144
|
+
premintGetter: this.apiClient,
|
|
1021
1145
|
publicClient: this.publicClient
|
|
1022
1146
|
});
|
|
1023
1147
|
}
|
|
1024
1148
|
};
|
|
1025
|
-
function
|
|
1026
|
-
const
|
|
1027
|
-
return
|
|
1149
|
+
function getDataFromPremintReceipt(receipt, chainId, blockExplorerUrl) {
|
|
1150
|
+
const premintedLog = getPremintedLogFromReceipt(receipt);
|
|
1151
|
+
return {
|
|
1152
|
+
tokenId: premintedLog?.tokenId,
|
|
1153
|
+
collectionAddres: premintedLog?.contractAddress,
|
|
1154
|
+
premintedLog,
|
|
1155
|
+
urls: makeUrls({
|
|
1156
|
+
address: premintedLog?.contractAddress,
|
|
1157
|
+
tokenId: premintedLog?.tokenId,
|
|
1158
|
+
chainId,
|
|
1159
|
+
blockExplorerUrl
|
|
1160
|
+
})
|
|
1161
|
+
};
|
|
1028
1162
|
}
|
|
1029
1163
|
function makePremintReturn({
|
|
1030
1164
|
premintConfig,
|
|
@@ -1054,7 +1188,7 @@ function makePremintReturn({
|
|
|
1054
1188
|
await submit({
|
|
1055
1189
|
signature,
|
|
1056
1190
|
checkSignature,
|
|
1057
|
-
signerAccount
|
|
1191
|
+
account: signerAccount
|
|
1058
1192
|
});
|
|
1059
1193
|
return {
|
|
1060
1194
|
signature,
|
|
@@ -1064,7 +1198,7 @@ function makePremintReturn({
|
|
|
1064
1198
|
const submit = async ({
|
|
1065
1199
|
signature,
|
|
1066
1200
|
checkSignature,
|
|
1067
|
-
|
|
1201
|
+
account
|
|
1068
1202
|
}) => {
|
|
1069
1203
|
if (checkSignature) {
|
|
1070
1204
|
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
@@ -1072,7 +1206,7 @@ function makePremintReturn({
|
|
|
1072
1206
|
additionalAdmins: collection?.additionalAdmins,
|
|
1073
1207
|
contractAdmin: collection?.contractAdmin,
|
|
1074
1208
|
publicClient,
|
|
1075
|
-
signer:
|
|
1209
|
+
signer: account
|
|
1076
1210
|
});
|
|
1077
1211
|
if (!isAuthorized) {
|
|
1078
1212
|
throw new Error("Not authorized to create premint");
|
|
@@ -1115,7 +1249,7 @@ async function signPremint({
|
|
|
1115
1249
|
};
|
|
1116
1250
|
}
|
|
1117
1251
|
async function createPremint({
|
|
1118
|
-
tokenCreationConfig,
|
|
1252
|
+
token: tokenCreationConfig,
|
|
1119
1253
|
uid,
|
|
1120
1254
|
publicClient,
|
|
1121
1255
|
apiClient,
|
|
@@ -1138,7 +1272,7 @@ async function createPremint({
|
|
|
1138
1272
|
premintConfig,
|
|
1139
1273
|
premintConfigVersion,
|
|
1140
1274
|
collectionAddress: collectionAddressToUse,
|
|
1141
|
-
collection: collectionOrAddress.
|
|
1275
|
+
collection: collectionOrAddress.contract,
|
|
1142
1276
|
publicClient,
|
|
1143
1277
|
apiClient,
|
|
1144
1278
|
chainId
|
|
@@ -1191,10 +1325,9 @@ async function updatePremint({
|
|
|
1191
1325
|
chainId
|
|
1192
1326
|
}) {
|
|
1193
1327
|
const {
|
|
1194
|
-
premintConfig,
|
|
1195
|
-
collection: collectionCreationConfig
|
|
1196
|
-
|
|
1197
|
-
} = await apiClient.getSignature({
|
|
1328
|
+
premint: { premintConfig, premintConfigVersion },
|
|
1329
|
+
collection: collectionCreationConfig
|
|
1330
|
+
} = await apiClient.get({
|
|
1198
1331
|
collectionAddress: collection,
|
|
1199
1332
|
uid
|
|
1200
1333
|
});
|
|
@@ -1222,11 +1355,10 @@ async function deletePremint({
|
|
|
1222
1355
|
chainId
|
|
1223
1356
|
}) {
|
|
1224
1357
|
const {
|
|
1225
|
-
premintConfig,
|
|
1226
|
-
premintConfigVersion,
|
|
1358
|
+
premint: { premintConfig, premintConfigVersion },
|
|
1227
1359
|
collection: collectionCreationConfig,
|
|
1228
1360
|
collectionAddress
|
|
1229
|
-
} = await apiClient.
|
|
1361
|
+
} = await apiClient.get({
|
|
1230
1362
|
collectionAddress: collection,
|
|
1231
1363
|
uid
|
|
1232
1364
|
});
|
|
@@ -1245,52 +1377,72 @@ async function deletePremint({
|
|
|
1245
1377
|
chainId
|
|
1246
1378
|
});
|
|
1247
1379
|
}
|
|
1248
|
-
async function
|
|
1380
|
+
async function collectPremint({
|
|
1249
1381
|
uid,
|
|
1250
1382
|
tokenContract,
|
|
1251
1383
|
minterAccount,
|
|
1252
|
-
|
|
1384
|
+
quantityToMint,
|
|
1385
|
+
mintComment = "",
|
|
1386
|
+
mintReferral,
|
|
1387
|
+
mintRecipient,
|
|
1253
1388
|
firstMinter,
|
|
1254
|
-
|
|
1389
|
+
premintGetter,
|
|
1255
1390
|
publicClient
|
|
1256
1391
|
}) {
|
|
1257
|
-
if (
|
|
1392
|
+
if (typeof quantityToMint !== "undefined" && quantityToMint < 1) {
|
|
1258
1393
|
throw new Error("Quantity to mint cannot be below 1");
|
|
1259
1394
|
}
|
|
1260
|
-
|
|
1261
|
-
throw new Error("Wallet not passed in");
|
|
1262
|
-
}
|
|
1263
|
-
const {
|
|
1264
|
-
premintConfig,
|
|
1265
|
-
premintConfigVersion,
|
|
1266
|
-
collection,
|
|
1267
|
-
collectionAddress,
|
|
1268
|
-
signature
|
|
1269
|
-
} = await apiClient.getSignature({
|
|
1395
|
+
const premint = await premintGetter.get({
|
|
1270
1396
|
collectionAddress: tokenContract,
|
|
1271
1397
|
uid
|
|
1272
1398
|
});
|
|
1273
|
-
const
|
|
1274
|
-
if (premintConfigVersion === PremintConfigVersion2.V3) {
|
|
1275
|
-
throw new Error("PremintV3 not supported in premint SDK");
|
|
1276
|
-
}
|
|
1277
|
-
const value = (await getPremintMintCosts({
|
|
1399
|
+
const mintFee = await getPremintMintFee({
|
|
1278
1400
|
tokenContract,
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1401
|
+
publicClient
|
|
1402
|
+
});
|
|
1403
|
+
return buildPremintMintCall({
|
|
1404
|
+
mintArguments: {
|
|
1405
|
+
minterAccount,
|
|
1406
|
+
quantityToMint,
|
|
1407
|
+
firstMinter,
|
|
1408
|
+
mintComment,
|
|
1409
|
+
mintRecipient,
|
|
1410
|
+
mintReferral
|
|
1411
|
+
},
|
|
1412
|
+
mintFee,
|
|
1413
|
+
premint
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
var buildPremintMintCall = ({
|
|
1417
|
+
mintArguments: {
|
|
1418
|
+
minterAccount,
|
|
1419
|
+
mintComment = "",
|
|
1420
|
+
mintRecipient,
|
|
1421
|
+
mintReferral,
|
|
1422
|
+
firstMinter,
|
|
1423
|
+
quantityToMint
|
|
1424
|
+
},
|
|
1425
|
+
premint: { collection, collectionAddress, premint, signature },
|
|
1426
|
+
mintFee
|
|
1427
|
+
}) => {
|
|
1283
1428
|
const mintArgumentsContract = {
|
|
1284
|
-
mintComment
|
|
1285
|
-
mintRecipient:
|
|
1429
|
+
mintComment,
|
|
1430
|
+
mintRecipient: mintRecipientOrAccount({
|
|
1431
|
+
mintRecipient,
|
|
1432
|
+
minterAccount
|
|
1433
|
+
}),
|
|
1286
1434
|
mintRewardsRecipients: makeMintRewardsRecipient({
|
|
1287
|
-
mintReferral
|
|
1435
|
+
mintReferral
|
|
1288
1436
|
})
|
|
1289
1437
|
};
|
|
1290
1438
|
const collectionOrEmpty = collection ? defaultAdditionalAdmins(collection) : emptyContractCreationConfig();
|
|
1291
1439
|
const collectionAddressToSubmit = collection ? zeroAddress2 : collectionAddress;
|
|
1292
1440
|
const firstMinterToSubmit = firstMinter || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
|
|
1293
|
-
|
|
1441
|
+
if (premint.premintConfigVersion === PremintConfigVersion2.V3) {
|
|
1442
|
+
throw new Error("PremintV3 not supported in premint SDK");
|
|
1443
|
+
}
|
|
1444
|
+
const value = (mintFee + premint.premintConfig.tokenConfig.pricePerToken) * BigInt(quantityToMint);
|
|
1445
|
+
return makeContractParameters({
|
|
1294
1446
|
account: minterAccount,
|
|
1295
1447
|
abi: zoraCreator1155PremintExecutorImplABI2,
|
|
1296
1448
|
functionName: "premint",
|
|
@@ -1299,31 +1451,29 @@ async function makeMintParameters({
|
|
|
1299
1451
|
args: [
|
|
1300
1452
|
collectionOrEmpty,
|
|
1301
1453
|
collectionAddressToSubmit,
|
|
1302
|
-
encodePremintConfig(
|
|
1303
|
-
premintConfig,
|
|
1304
|
-
premintConfigVersion
|
|
1305
|
-
}),
|
|
1454
|
+
encodePremintConfig(premint),
|
|
1306
1455
|
signature,
|
|
1307
|
-
|
|
1456
|
+
BigInt(quantityToMint),
|
|
1308
1457
|
mintArgumentsContract,
|
|
1309
1458
|
firstMinterToSubmit,
|
|
1310
1459
|
zeroAddress2
|
|
1311
1460
|
]
|
|
1312
1461
|
});
|
|
1313
|
-
}
|
|
1462
|
+
};
|
|
1314
1463
|
function makeUrls({
|
|
1315
1464
|
uid,
|
|
1316
1465
|
address,
|
|
1317
1466
|
tokenId,
|
|
1318
|
-
|
|
1467
|
+
chainId,
|
|
1468
|
+
blockExplorerUrl
|
|
1319
1469
|
}) {
|
|
1320
1470
|
if ((!uid || !tokenId) && !address) {
|
|
1321
1471
|
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
1322
1472
|
}
|
|
1323
1473
|
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
1324
|
-
const network = getApiNetworkConfigForChain(
|
|
1474
|
+
const network = getApiNetworkConfigForChain(chainId);
|
|
1325
1475
|
return {
|
|
1326
|
-
explorer: tokenId ? `https://${
|
|
1476
|
+
explorer: tokenId ? `https://${blockExplorerUrl}/token/${address}/instance/${tokenId}` : null,
|
|
1327
1477
|
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`,
|
|
1328
1478
|
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
|
|
1329
1479
|
};
|
|
@@ -1340,18 +1490,487 @@ var PremintConfigVersion3 = ((PremintConfigVersion4) => {
|
|
|
1340
1490
|
return PremintConfigVersion4;
|
|
1341
1491
|
})(PremintConfigVersion3 || {});
|
|
1342
1492
|
|
|
1493
|
+
// src/premint/premint-api-client.ts
|
|
1494
|
+
var postSignature = async ({
|
|
1495
|
+
httpClient: { post: post2, retries: retries2 } = httpClient,
|
|
1496
|
+
...data
|
|
1497
|
+
}) => retries2(
|
|
1498
|
+
() => post2(`${ZORA_API_BASE}premint/signature`, data)
|
|
1499
|
+
);
|
|
1500
|
+
var getNextUID = async ({
|
|
1501
|
+
chainId,
|
|
1502
|
+
collection_address,
|
|
1503
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
1504
|
+
}) => retries2(
|
|
1505
|
+
() => get2(
|
|
1506
|
+
`${ZORA_API_BASE}premint/signature/${getApiNetworkConfigForChain(chainId).zoraBackendChainName}/${collection_address}/next_uid`
|
|
1507
|
+
)
|
|
1508
|
+
);
|
|
1509
|
+
var getSignature = async ({
|
|
1510
|
+
collectionAddress,
|
|
1511
|
+
uid,
|
|
1512
|
+
chainId,
|
|
1513
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
1514
|
+
}) => {
|
|
1515
|
+
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
1516
|
+
const result = await retries2(
|
|
1517
|
+
() => get2(
|
|
1518
|
+
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}/${uid}`
|
|
1519
|
+
)
|
|
1520
|
+
);
|
|
1521
|
+
return convertGetPremintApiResponse(result);
|
|
1522
|
+
};
|
|
1523
|
+
var getOfCollection = async ({
|
|
1524
|
+
collectionAddress,
|
|
1525
|
+
chainId,
|
|
1526
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
1527
|
+
}) => {
|
|
1528
|
+
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
1529
|
+
const result = await retries2(
|
|
1530
|
+
() => get2(
|
|
1531
|
+
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}`
|
|
1532
|
+
)
|
|
1533
|
+
);
|
|
1534
|
+
return convertGetPremintOfCollectionApiResponse(result);
|
|
1535
|
+
};
|
|
1536
|
+
var PremintAPIClient = class {
|
|
1537
|
+
constructor(chainId, httpClient2) {
|
|
1538
|
+
this.postSignature = ({
|
|
1539
|
+
signature,
|
|
1540
|
+
...rest
|
|
1541
|
+
}) => {
|
|
1542
|
+
const data = encodePostSignatureInput({
|
|
1543
|
+
...rest,
|
|
1544
|
+
chainId: this.chainId,
|
|
1545
|
+
signature
|
|
1546
|
+
});
|
|
1547
|
+
return postSignature({
|
|
1548
|
+
...data,
|
|
1549
|
+
httpClient: this.httpClient
|
|
1550
|
+
});
|
|
1551
|
+
};
|
|
1552
|
+
this.getNextUID = async (collectionAddress) => (await getNextUID({
|
|
1553
|
+
collection_address: collectionAddress.toLowerCase(),
|
|
1554
|
+
chainId: this.chainId,
|
|
1555
|
+
httpClient: this.httpClient
|
|
1556
|
+
})).next_uid;
|
|
1557
|
+
this.get = async ({ collectionAddress, uid }) => {
|
|
1558
|
+
return getSignature({
|
|
1559
|
+
collectionAddress,
|
|
1560
|
+
uid,
|
|
1561
|
+
chainId: this.chainId,
|
|
1562
|
+
httpClient: this.httpClient
|
|
1563
|
+
});
|
|
1564
|
+
};
|
|
1565
|
+
this.getOfCollection = async ({
|
|
1566
|
+
collectionAddress
|
|
1567
|
+
}) => {
|
|
1568
|
+
return getOfCollection({
|
|
1569
|
+
collectionAddress,
|
|
1570
|
+
chainId: this.chainId,
|
|
1571
|
+
httpClient: this.httpClient
|
|
1572
|
+
});
|
|
1573
|
+
};
|
|
1574
|
+
this.chainId = chainId;
|
|
1575
|
+
this.httpClient = httpClient2 || httpClient;
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
|
|
1579
|
+
// src/mint/mint-transactions.ts
|
|
1580
|
+
import {
|
|
1581
|
+
encodeAbiParameters,
|
|
1582
|
+
parseAbiParameters,
|
|
1583
|
+
zeroAddress as zeroAddress3
|
|
1584
|
+
} from "viem";
|
|
1585
|
+
import {
|
|
1586
|
+
erc20MinterABI,
|
|
1587
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI2
|
|
1588
|
+
} from "@zoralabs/protocol-deployments";
|
|
1589
|
+
|
|
1590
|
+
// src/mint/utils.ts
|
|
1591
|
+
import * as semver from "semver";
|
|
1592
|
+
var contractSupportsNewMintFunction = (contractVersion) => {
|
|
1593
|
+
if (!contractVersion) {
|
|
1594
|
+
return false;
|
|
1595
|
+
}
|
|
1596
|
+
const semVerContractVersion = semver.coerce(contractVersion)?.raw;
|
|
1597
|
+
if (!semVerContractVersion)
|
|
1598
|
+
return false;
|
|
1599
|
+
return semver.gte(semVerContractVersion, "2.9.0");
|
|
1600
|
+
};
|
|
1601
|
+
|
|
1602
|
+
// src/mint/mint-transactions.ts
|
|
1603
|
+
function makeOnchainMintCall({
|
|
1604
|
+
token,
|
|
1605
|
+
mintParams
|
|
1606
|
+
}) {
|
|
1607
|
+
if (token.mintType === "721") {
|
|
1608
|
+
return makePrepareMint721TokenParams({
|
|
1609
|
+
salesConfigAndTokenInfo: token,
|
|
1610
|
+
tokenContract: token.contract.address,
|
|
1611
|
+
...mintParams
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
return makePrepareMint1155TokenParams({
|
|
1615
|
+
salesConfigAndTokenInfo: token,
|
|
1616
|
+
tokenContract: token.contract.address,
|
|
1617
|
+
tokenId: token.tokenId,
|
|
1618
|
+
...mintParams
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1621
|
+
function makePrepareMint1155TokenParams({
|
|
1622
|
+
tokenContract,
|
|
1623
|
+
tokenId,
|
|
1624
|
+
salesConfigAndTokenInfo,
|
|
1625
|
+
minterAccount,
|
|
1626
|
+
mintComment,
|
|
1627
|
+
mintReferral,
|
|
1628
|
+
mintRecipient,
|
|
1629
|
+
quantityToMint
|
|
1630
|
+
}) {
|
|
1631
|
+
const mintQuantity = BigInt(quantityToMint || 1);
|
|
1632
|
+
const mintTo = mintRecipientOrAccount({ mintRecipient, minterAccount });
|
|
1633
|
+
const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
|
|
1634
|
+
if (saleType === "fixedPrice") {
|
|
1635
|
+
return makeEthMintCall({
|
|
1636
|
+
mintComment,
|
|
1637
|
+
minterAccount,
|
|
1638
|
+
mintQuantity,
|
|
1639
|
+
mintReferral,
|
|
1640
|
+
mintTo,
|
|
1641
|
+
salesConfigAndTokenInfo,
|
|
1642
|
+
tokenContract,
|
|
1643
|
+
tokenId
|
|
1644
|
+
});
|
|
1645
|
+
}
|
|
1646
|
+
if (saleType === "erc20") {
|
|
1647
|
+
return makeContractParameters({
|
|
1648
|
+
abi: erc20MinterABI,
|
|
1649
|
+
functionName: "mint",
|
|
1650
|
+
account: minterAccount,
|
|
1651
|
+
address: salesConfigAndTokenInfo.salesConfig.address,
|
|
1652
|
+
/* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
|
|
1653
|
+
args: [
|
|
1654
|
+
mintTo,
|
|
1655
|
+
mintQuantity,
|
|
1656
|
+
tokenContract,
|
|
1657
|
+
BigInt(tokenId),
|
|
1658
|
+
salesConfigAndTokenInfo.salesConfig.pricePerToken * mintQuantity,
|
|
1659
|
+
salesConfigAndTokenInfo.salesConfig.currency,
|
|
1660
|
+
mintReferral || zeroAddress3,
|
|
1661
|
+
mintComment || ""
|
|
1662
|
+
]
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
throw new Error("Unsupported sale type");
|
|
1666
|
+
}
|
|
1667
|
+
function makePrepareMint721TokenParams({
|
|
1668
|
+
salesConfigAndTokenInfo,
|
|
1669
|
+
minterAccount,
|
|
1670
|
+
tokenContract,
|
|
1671
|
+
mintComment,
|
|
1672
|
+
mintReferral,
|
|
1673
|
+
mintRecipient,
|
|
1674
|
+
quantityToMint
|
|
1675
|
+
}) {
|
|
1676
|
+
const actualQuantityToMint = BigInt(quantityToMint || 1);
|
|
1677
|
+
const mintValue = parseMintCosts({
|
|
1678
|
+
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
1679
|
+
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
1680
|
+
quantityToMint: actualQuantityToMint
|
|
1681
|
+
}).totalCostEth;
|
|
1682
|
+
return makeContractParameters({
|
|
1683
|
+
abi: zora721Abi,
|
|
1684
|
+
address: tokenContract,
|
|
1685
|
+
account: minterAccount,
|
|
1686
|
+
functionName: "mintWithRewards",
|
|
1687
|
+
value: mintValue,
|
|
1688
|
+
args: [
|
|
1689
|
+
mintRecipientOrAccount({ mintRecipient, minterAccount }),
|
|
1690
|
+
actualQuantityToMint,
|
|
1691
|
+
mintComment || "",
|
|
1692
|
+
mintReferral || zeroAddress3
|
|
1693
|
+
]
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
function makeEthMintCall({
|
|
1697
|
+
tokenContract,
|
|
1698
|
+
tokenId,
|
|
1699
|
+
salesConfigAndTokenInfo,
|
|
1700
|
+
minterAccount,
|
|
1701
|
+
mintComment,
|
|
1702
|
+
mintReferral,
|
|
1703
|
+
mintQuantity,
|
|
1704
|
+
mintTo
|
|
1705
|
+
}) {
|
|
1706
|
+
const mintValue = parseMintCosts({
|
|
1707
|
+
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
1708
|
+
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
1709
|
+
quantityToMint: mintQuantity
|
|
1710
|
+
}).totalCostEth;
|
|
1711
|
+
const minterArguments = encodeAbiParameters(
|
|
1712
|
+
parseAbiParameters("address, string"),
|
|
1713
|
+
[mintTo, mintComment || ""]
|
|
1714
|
+
);
|
|
1715
|
+
if (contractSupportsNewMintFunction(salesConfigAndTokenInfo.contractVersion)) {
|
|
1716
|
+
return makeContractParameters({
|
|
1717
|
+
abi: zoraCreator1155ImplABI2,
|
|
1718
|
+
functionName: "mint",
|
|
1719
|
+
account: minterAccount,
|
|
1720
|
+
value: mintValue,
|
|
1721
|
+
address: tokenContract,
|
|
1722
|
+
args: [
|
|
1723
|
+
salesConfigAndTokenInfo.salesConfig.address,
|
|
1724
|
+
BigInt(tokenId),
|
|
1725
|
+
mintQuantity,
|
|
1726
|
+
mintReferral ? [mintReferral] : [],
|
|
1727
|
+
minterArguments
|
|
1728
|
+
]
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
return makeContractParameters({
|
|
1732
|
+
abi: zoraCreator1155ImplABI2,
|
|
1733
|
+
functionName: "mintWithRewards",
|
|
1734
|
+
account: minterAccount,
|
|
1735
|
+
value: mintValue,
|
|
1736
|
+
address: tokenContract,
|
|
1737
|
+
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
1738
|
+
args: [
|
|
1739
|
+
salesConfigAndTokenInfo.salesConfig.address,
|
|
1740
|
+
BigInt(tokenId),
|
|
1741
|
+
mintQuantity,
|
|
1742
|
+
minterArguments,
|
|
1743
|
+
mintReferral || zeroAddress3
|
|
1744
|
+
]
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
function parseMintCosts({
|
|
1748
|
+
salesConfig,
|
|
1749
|
+
mintFeePerQuantity,
|
|
1750
|
+
quantityToMint
|
|
1751
|
+
}) {
|
|
1752
|
+
const mintFeeForTokens = mintFeePerQuantity * quantityToMint;
|
|
1753
|
+
const tokenPurchaseCost = BigInt(salesConfig.pricePerToken) * quantityToMint;
|
|
1754
|
+
const totalPurchaseCostCurrency = isErc20SaleStrategy(salesConfig) ? salesConfig.currency : void 0;
|
|
1755
|
+
const totalPurchaseCostEth = totalPurchaseCostCurrency ? 0n : tokenPurchaseCost;
|
|
1756
|
+
return {
|
|
1757
|
+
mintFee: mintFeeForTokens,
|
|
1758
|
+
totalPurchaseCost: tokenPurchaseCost,
|
|
1759
|
+
totalPurchaseCostCurrency,
|
|
1760
|
+
totalCostEth: mintFeeForTokens + totalPurchaseCostEth
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
// src/mint/mint-queries.ts
|
|
1765
|
+
import { zeroAddress as zeroAddress4 } from "viem";
|
|
1766
|
+
async function getMint({
|
|
1767
|
+
params,
|
|
1768
|
+
mintGetter,
|
|
1769
|
+
premintGetter,
|
|
1770
|
+
publicClient
|
|
1771
|
+
}) {
|
|
1772
|
+
const { tokenContract } = params;
|
|
1773
|
+
if (isOnChainMint(params)) {
|
|
1774
|
+
const tokenId = is1155Mint(params) ? params.tokenId : void 0;
|
|
1775
|
+
const result = await mintGetter.getMintable({
|
|
1776
|
+
tokenId,
|
|
1777
|
+
tokenAddress: tokenContract,
|
|
1778
|
+
preferredSaleType: params.preferredSaleType
|
|
1779
|
+
});
|
|
1780
|
+
return toMintableReturn(result);
|
|
1781
|
+
}
|
|
1782
|
+
const premint = await premintGetter.get({
|
|
1783
|
+
collectionAddress: tokenContract,
|
|
1784
|
+
uid: params.uid
|
|
1785
|
+
});
|
|
1786
|
+
const mintFee = await getPremintMintFee({
|
|
1787
|
+
publicClient,
|
|
1788
|
+
tokenContract
|
|
1789
|
+
});
|
|
1790
|
+
return toPremintMintReturn({ premint, mintFee });
|
|
1791
|
+
}
|
|
1792
|
+
async function getPremintsOfCollectionWithTokenIds({
|
|
1793
|
+
premintGetter,
|
|
1794
|
+
mintGetter,
|
|
1795
|
+
tokenContract
|
|
1796
|
+
}) {
|
|
1797
|
+
const { collection, premints } = await premintGetter.getOfCollection({
|
|
1798
|
+
collectionAddress: tokenContract
|
|
1799
|
+
});
|
|
1800
|
+
const premintUidsAndTokenIds = await mintGetter.getContractPremintTokenIds({
|
|
1801
|
+
tokenAddress: tokenContract
|
|
1802
|
+
});
|
|
1803
|
+
const premintsWithTokenId = premints.map((premint) => ({
|
|
1804
|
+
...premint,
|
|
1805
|
+
tokenId: premintUidsAndTokenIds.find(
|
|
1806
|
+
({ uid }) => uid === premint.premint.premintConfig.uid
|
|
1807
|
+
)?.tokenId
|
|
1808
|
+
}));
|
|
1809
|
+
return {
|
|
1810
|
+
collection,
|
|
1811
|
+
premints: premintsWithTokenId
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
async function getMintsOfContract({
|
|
1815
|
+
params,
|
|
1816
|
+
mintGetter,
|
|
1817
|
+
premintGetter,
|
|
1818
|
+
publicClient
|
|
1819
|
+
}) {
|
|
1820
|
+
const onchainMints = (await mintGetter.getContractMintable({
|
|
1821
|
+
tokenAddress: params.tokenContract
|
|
1822
|
+
})).map(toMintableReturn);
|
|
1823
|
+
const offchainMints = await getPremintsOfContractMintable({
|
|
1824
|
+
mintGetter,
|
|
1825
|
+
premintGetter,
|
|
1826
|
+
publicClient,
|
|
1827
|
+
params: {
|
|
1828
|
+
tokenContract: params.tokenContract
|
|
1829
|
+
}
|
|
1830
|
+
});
|
|
1831
|
+
const tokens = [...onchainMints, ...offchainMints];
|
|
1832
|
+
return {
|
|
1833
|
+
tokens,
|
|
1834
|
+
contract: tokens[0]?.token.contract
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
async function getMintCosts({
|
|
1838
|
+
params,
|
|
1839
|
+
mintGetter,
|
|
1840
|
+
premintGetter,
|
|
1841
|
+
publicClient
|
|
1842
|
+
}) {
|
|
1843
|
+
const { quantityMinted: quantityToMint, collection } = params;
|
|
1844
|
+
if (isOnChainMint(params)) {
|
|
1845
|
+
const tokenId = is1155Mint(params) ? params.tokenId : void 0;
|
|
1846
|
+
const salesConfigAndTokenInfo = await mintGetter.getMintable({
|
|
1847
|
+
tokenId,
|
|
1848
|
+
tokenAddress: collection
|
|
1849
|
+
});
|
|
1850
|
+
return parseMintCosts({
|
|
1851
|
+
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
1852
|
+
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
1853
|
+
quantityToMint: BigInt(quantityToMint)
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
return getPremintMintCostsWithUnknownTokenPrice({
|
|
1857
|
+
premintGetter,
|
|
1858
|
+
publicClient,
|
|
1859
|
+
quantityToMint: BigInt(quantityToMint),
|
|
1860
|
+
uid: params.uid,
|
|
1861
|
+
tokenContract: collection
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
async function getPremintsOfContractMintable({
|
|
1865
|
+
mintGetter,
|
|
1866
|
+
premintGetter,
|
|
1867
|
+
publicClient,
|
|
1868
|
+
params
|
|
1869
|
+
}) {
|
|
1870
|
+
const { premints, collection } = await getPremintsOfCollectionWithTokenIds({
|
|
1871
|
+
mintGetter,
|
|
1872
|
+
premintGetter,
|
|
1873
|
+
tokenContract: params.tokenContract
|
|
1874
|
+
});
|
|
1875
|
+
const offChainPremints = premints.filter(
|
|
1876
|
+
(premint) => (
|
|
1877
|
+
// if premint's uid is not in the list of uids from the subgraph, it is offchain
|
|
1878
|
+
typeof premint.tokenId === "undefined"
|
|
1879
|
+
)
|
|
1880
|
+
);
|
|
1881
|
+
if (offChainPremints.length === 0)
|
|
1882
|
+
return [];
|
|
1883
|
+
const mintFee = await getPremintMintFee({
|
|
1884
|
+
publicClient,
|
|
1885
|
+
tokenContract: params.tokenContract
|
|
1886
|
+
});
|
|
1887
|
+
return offChainPremints.map((premint) => {
|
|
1888
|
+
return toPremintMintReturn({
|
|
1889
|
+
premint: {
|
|
1890
|
+
premint: premint.premint,
|
|
1891
|
+
// todo: fix when api returns signer
|
|
1892
|
+
signer: zeroAddress4,
|
|
1893
|
+
collection,
|
|
1894
|
+
collectionAddress: params.tokenContract,
|
|
1895
|
+
signature: premint.signature
|
|
1896
|
+
},
|
|
1897
|
+
mintFee
|
|
1898
|
+
});
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
function parsePremint({
|
|
1902
|
+
premint,
|
|
1903
|
+
mintFee
|
|
1904
|
+
}) {
|
|
1905
|
+
if (isPremintConfigV1(premint.premint) || isPremintConfigV2(premint.premint)) {
|
|
1906
|
+
return {
|
|
1907
|
+
creator: premint.signer,
|
|
1908
|
+
maxSupply: premint.premint.premintConfig.tokenConfig.maxSupply,
|
|
1909
|
+
mintFeePerQuantity: mintFee,
|
|
1910
|
+
mintType: "premint",
|
|
1911
|
+
uid: premint.premint.premintConfig.uid,
|
|
1912
|
+
contract: {
|
|
1913
|
+
address: premint.collectionAddress,
|
|
1914
|
+
name: premint.collection.contractName,
|
|
1915
|
+
URI: premint.collection.contractURI
|
|
1916
|
+
},
|
|
1917
|
+
tokenURI: premint.premint.premintConfig.tokenConfig.tokenURI,
|
|
1918
|
+
totalMinted: 0n,
|
|
1919
|
+
salesConfig: {
|
|
1920
|
+
duration: premint.premint.premintConfig.tokenConfig.mintDuration,
|
|
1921
|
+
maxTokensPerAddress: premint.premint.premintConfig.tokenConfig.maxTokensPerAddress,
|
|
1922
|
+
pricePerToken: premint.premint.premintConfig.tokenConfig.pricePerToken,
|
|
1923
|
+
saleType: "premint"
|
|
1924
|
+
}
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1927
|
+
throw new Error("Invalid premint config version");
|
|
1928
|
+
}
|
|
1929
|
+
var makeOnchainPrepareMint = (result) => (params) => ({
|
|
1930
|
+
parameters: makeOnchainMintCall({ token: result, mintParams: params }),
|
|
1931
|
+
erc20Approval: getRequiredErc20Approvals(params, result),
|
|
1932
|
+
costs: parseMintCosts({
|
|
1933
|
+
salesConfig: result.salesConfig,
|
|
1934
|
+
quantityToMint: BigInt(params.quantityToMint),
|
|
1935
|
+
mintFeePerQuantity: result.mintFeePerQuantity
|
|
1936
|
+
})
|
|
1937
|
+
});
|
|
1938
|
+
function toMintableReturn(result) {
|
|
1939
|
+
return { token: result, prepareMint: makeOnchainPrepareMint(result) };
|
|
1940
|
+
}
|
|
1941
|
+
var makePremintPrepareMint = (mintable, mintFee, premint) => (params) => ({
|
|
1942
|
+
parameters: buildPremintMintCall({
|
|
1943
|
+
mintArguments: params,
|
|
1944
|
+
mintFee,
|
|
1945
|
+
premint
|
|
1946
|
+
}),
|
|
1947
|
+
costs: parseMintCosts({
|
|
1948
|
+
mintFeePerQuantity: mintFee,
|
|
1949
|
+
quantityToMint: BigInt(params.quantityToMint),
|
|
1950
|
+
salesConfig: mintable.salesConfig
|
|
1951
|
+
})
|
|
1952
|
+
});
|
|
1953
|
+
function toPremintMintReturn({
|
|
1954
|
+
premint,
|
|
1955
|
+
mintFee
|
|
1956
|
+
}) {
|
|
1957
|
+
const mintable = parsePremint({ premint, mintFee });
|
|
1958
|
+
return {
|
|
1959
|
+
token: mintable,
|
|
1960
|
+
prepareMint: makePremintPrepareMint(mintable, mintFee, premint)
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
function getRequiredErc20Approvals(params, result) {
|
|
1964
|
+
if (result.salesConfig.saleType !== "erc20")
|
|
1965
|
+
return void 0;
|
|
1966
|
+
return {
|
|
1967
|
+
quantity: result.salesConfig.pricePerToken * BigInt(params.quantityToMint),
|
|
1968
|
+
approveTo: result.salesConfig.address,
|
|
1969
|
+
erc20: result.salesConfig.currency
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1343
1973
|
// src/mint/mint-client.ts
|
|
1344
|
-
import {
|
|
1345
|
-
encodeAbiParameters,
|
|
1346
|
-
parseAbiParameters,
|
|
1347
|
-
zeroAddress as zeroAddress3
|
|
1348
|
-
} from "viem";
|
|
1349
|
-
import {
|
|
1350
|
-
erc20MinterABI,
|
|
1351
|
-
erc20MinterAddress,
|
|
1352
|
-
zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
|
|
1353
|
-
zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
|
|
1354
|
-
} from "@zoralabs/protocol-deployments";
|
|
1355
1974
|
var MintError = class extends Error {
|
|
1356
1975
|
};
|
|
1357
1976
|
var MintInactiveError = class extends Error {
|
|
@@ -1361,265 +1980,454 @@ var Errors = {
|
|
|
1361
1980
|
MintInactiveError
|
|
1362
1981
|
};
|
|
1363
1982
|
var MintClient = class {
|
|
1364
|
-
constructor(
|
|
1365
|
-
|
|
1983
|
+
constructor({
|
|
1984
|
+
publicClient,
|
|
1985
|
+
premintGetter,
|
|
1986
|
+
mintGetter
|
|
1987
|
+
}) {
|
|
1366
1988
|
this.publicClient = publicClient;
|
|
1989
|
+
this.mintGetter = mintGetter;
|
|
1990
|
+
this.premintGetter = premintGetter;
|
|
1367
1991
|
}
|
|
1368
1992
|
/**
|
|
1369
1993
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
1994
|
+
* Works with premint, onchain 1155, and onchain 721.
|
|
1370
1995
|
*
|
|
1371
|
-
* @param parameters - Parameters for collecting the token {@link
|
|
1372
|
-
* @returns Parameters for simulating/executing the mint transaction
|
|
1996
|
+
* @param parameters - Parameters for collecting the token {@link MakeMintParametersArguments}
|
|
1997
|
+
* @returns Parameters for simulating/executing the mint transaction, any necessary erc20 approval, and costs to mint
|
|
1373
1998
|
*/
|
|
1374
|
-
async
|
|
1375
|
-
return
|
|
1376
|
-
|
|
1377
|
-
|
|
1999
|
+
async mint(parameters) {
|
|
2000
|
+
return mint({
|
|
2001
|
+
parameters,
|
|
2002
|
+
publicClient: this.publicClient,
|
|
2003
|
+
mintGetter: this.mintGetter,
|
|
2004
|
+
premintGetter: this.premintGetter
|
|
2005
|
+
});
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* Gets an 1155, 721, or premint, and returns both information about it, and a function
|
|
2009
|
+
* that can be used to build a mint transaction for a quantity of items to mint.
|
|
2010
|
+
* @param parameters - Token to get {@link GetMintParameters}
|
|
2011
|
+
* @Returns Information about the mint and a function to build a mint transaction {@link MintableReturn}
|
|
2012
|
+
*/
|
|
2013
|
+
async get(parameters) {
|
|
2014
|
+
return getMint({
|
|
2015
|
+
params: parameters,
|
|
2016
|
+
mintGetter: this.mintGetter,
|
|
2017
|
+
premintGetter: this.premintGetter,
|
|
2018
|
+
publicClient: this.publicClient
|
|
2019
|
+
});
|
|
2020
|
+
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Gets onchain and premint tokens of an 1155 contract. For each token returns both information about it, and a function
|
|
2023
|
+
* that can be used to build a mint transaction for a quantity of items to mint.
|
|
2024
|
+
* @param parameters - Contract address to get tokens for {@link GetMintsOfContractParameters}
|
|
2025
|
+
* @Returns Array of tokens, each containing information about the token and a function to build a mint transaction.
|
|
2026
|
+
*/
|
|
2027
|
+
async getOfContract(params) {
|
|
2028
|
+
return getMintsOfContract({
|
|
2029
|
+
params,
|
|
2030
|
+
mintGetter: this.mintGetter,
|
|
2031
|
+
premintGetter: this.premintGetter,
|
|
2032
|
+
publicClient: this.publicClient
|
|
2033
|
+
});
|
|
2034
|
+
}
|
|
2035
|
+
/**
|
|
2036
|
+
* Gets the costs to mint the quantity of tokens specified for a mint.
|
|
2037
|
+
* @param parameters - Parameters for the mint {@link GetMintCostsParameters}
|
|
2038
|
+
* @returns Costs to mint the quantity of tokens specified
|
|
2039
|
+
*/
|
|
2040
|
+
async getMintCosts(parameters) {
|
|
2041
|
+
return getMintCosts({
|
|
2042
|
+
params: parameters,
|
|
2043
|
+
mintGetter: this.mintGetter,
|
|
2044
|
+
premintGetter: this.premintGetter,
|
|
1378
2045
|
publicClient: this.publicClient
|
|
1379
2046
|
});
|
|
1380
2047
|
}
|
|
1381
2048
|
};
|
|
1382
|
-
function
|
|
1383
|
-
|
|
1384
|
-
return new MintClient(chain, publicClient, httpClient2);
|
|
1385
|
-
}
|
|
1386
|
-
async function makePrepareMintTokenParams({
|
|
2049
|
+
async function mint({
|
|
2050
|
+
parameters,
|
|
1387
2051
|
publicClient,
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
tokenAddress,
|
|
1391
|
-
mintArguments,
|
|
1392
|
-
...rest
|
|
2052
|
+
mintGetter,
|
|
2053
|
+
premintGetter
|
|
1393
2054
|
}) {
|
|
1394
|
-
const
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
2055
|
+
const { prepareMint } = await getMint({
|
|
2056
|
+
params: parameters,
|
|
2057
|
+
mintGetter,
|
|
2058
|
+
premintGetter,
|
|
2059
|
+
publicClient
|
|
1398
2060
|
});
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
2061
|
+
return prepareMint({
|
|
2062
|
+
minterAccount: parameters.minterAccount,
|
|
2063
|
+
quantityToMint: parameters.quantityToMint,
|
|
2064
|
+
firstMinter: parameters.firstMinter,
|
|
2065
|
+
mintComment: parameters.mintComment,
|
|
2066
|
+
mintRecipient: parameters.mintRecipient,
|
|
2067
|
+
mintReferral: parameters.mintReferral
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
async function collectOnchain({
|
|
2071
|
+
chainId,
|
|
2072
|
+
mintGetter,
|
|
2073
|
+
...parameters
|
|
2074
|
+
}) {
|
|
2075
|
+
const { tokenContract, preferredSaleType: saleType } = parameters;
|
|
2076
|
+
const tokenId = is1155Mint(parameters) ? parameters.tokenId : void 0;
|
|
2077
|
+
const salesConfigAndTokenInfo = await mintGetter.getMintable({
|
|
1410
2078
|
tokenId,
|
|
1411
|
-
|
|
1412
|
-
|
|
2079
|
+
tokenAddress: tokenContract,
|
|
2080
|
+
preferredSaleType: saleType
|
|
2081
|
+
});
|
|
2082
|
+
return makeOnchainMintCall({
|
|
2083
|
+
mintParams: parameters,
|
|
2084
|
+
token: salesConfigAndTokenInfo
|
|
1413
2085
|
});
|
|
1414
2086
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
2087
|
+
|
|
2088
|
+
// src/create/1155-create-helper.ts
|
|
2089
|
+
import {
|
|
2090
|
+
zoraCreator1155FactoryImplABI as zoraCreator1155FactoryImplABI2,
|
|
2091
|
+
zoraCreator1155FactoryImplAddress as zoraCreator1155FactoryImplAddress2,
|
|
2092
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI5
|
|
2093
|
+
} from "@zoralabs/protocol-deployments";
|
|
2094
|
+
import { decodeEventLog as decodeEventLog2 } from "viem";
|
|
2095
|
+
|
|
2096
|
+
// src/create/contract-setup.ts
|
|
2097
|
+
import {
|
|
2098
|
+
contracts1155,
|
|
2099
|
+
zoraCreator1155FactoryImplABI,
|
|
2100
|
+
zoraCreator1155FactoryImplAddress,
|
|
2101
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI3
|
|
2102
|
+
} from "@zoralabs/protocol-deployments";
|
|
2103
|
+
function new1155ContractVersion(chainId) {
|
|
2104
|
+
const address = contracts1155.addresses[chainId];
|
|
2105
|
+
if (!address) {
|
|
2106
|
+
throw new Error(`No contract address for chainId ${chainId}`);
|
|
2107
|
+
}
|
|
2108
|
+
return address.CONTRACT_1155_IMPL_VERSION;
|
|
2109
|
+
}
|
|
2110
|
+
async function getContractInfo({
|
|
2111
|
+
publicClient,
|
|
2112
|
+
chainId,
|
|
2113
|
+
contract,
|
|
2114
|
+
account
|
|
1420
2115
|
}) {
|
|
1421
|
-
const
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
abi: zora721Abi,
|
|
1427
|
-
address: tokenAddress,
|
|
1428
|
-
account: minterAccount,
|
|
1429
|
-
functionName: "mintWithRewards",
|
|
1430
|
-
value: mintValue,
|
|
2116
|
+
const contractAddress = typeof contract === "string" ? contract : await publicClient.readContract({
|
|
2117
|
+
abi: zoraCreator1155FactoryImplABI,
|
|
2118
|
+
// Since this address is deterministic we can hardcode a chain id safely here.
|
|
2119
|
+
address: zoraCreator1155FactoryImplAddress[chainId],
|
|
2120
|
+
functionName: "deterministicContractAddress",
|
|
1431
2121
|
args: [
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
2122
|
+
account,
|
|
2123
|
+
contract.uri,
|
|
2124
|
+
contract.name,
|
|
2125
|
+
contract.defaultAdmin || account
|
|
1436
2126
|
]
|
|
1437
2127
|
});
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
2128
|
+
let contractVersion;
|
|
2129
|
+
let contractExists;
|
|
2130
|
+
try {
|
|
2131
|
+
contractVersion = await publicClient.readContract({
|
|
2132
|
+
abi: zoraCreator1155ImplABI3,
|
|
2133
|
+
address: contractAddress,
|
|
2134
|
+
functionName: "contractVersion"
|
|
2135
|
+
});
|
|
2136
|
+
contractExists = true;
|
|
2137
|
+
} catch (e) {
|
|
2138
|
+
contractVersion = new1155ContractVersion(chainId);
|
|
2139
|
+
contractExists = false;
|
|
2140
|
+
}
|
|
2141
|
+
const nextTokenId = contractExists ? await publicClient.readContract({
|
|
2142
|
+
address: contractAddress,
|
|
2143
|
+
abi: zoraCreator1155ImplABI3,
|
|
2144
|
+
functionName: "nextTokenId"
|
|
2145
|
+
}) : 1n;
|
|
1445
2146
|
return {
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
2147
|
+
contractExists,
|
|
2148
|
+
contractAddress,
|
|
2149
|
+
contractVersion,
|
|
2150
|
+
nextTokenId
|
|
1449
2151
|
};
|
|
1450
2152
|
}
|
|
1451
|
-
async function makePrepareMint1155TokenParams({
|
|
1452
|
-
tokenId,
|
|
1453
|
-
salesConfigAndTokenInfo,
|
|
1454
|
-
minterAccount,
|
|
1455
|
-
tokenAddress,
|
|
1456
|
-
mintArguments
|
|
1457
|
-
}) {
|
|
1458
|
-
const mintQuantity = BigInt(mintArguments.quantityToMint);
|
|
1459
|
-
const mintValue = getMintCosts({
|
|
1460
|
-
salesConfigAndTokenInfo,
|
|
1461
|
-
quantityToMint: mintQuantity
|
|
1462
|
-
}).totalCost;
|
|
1463
|
-
switch (salesConfigAndTokenInfo.salesConfig.saleType) {
|
|
1464
|
-
case "fixedPrice":
|
|
1465
|
-
const fixedPriceArgs = mintArguments;
|
|
1466
|
-
return makeSimulateContractParamaters({
|
|
1467
|
-
abi: zoraCreator1155ImplABI2,
|
|
1468
|
-
functionName: "mintWithRewards",
|
|
1469
|
-
account: minterAccount,
|
|
1470
|
-
value: mintValue,
|
|
1471
|
-
address: tokenAddress,
|
|
1472
|
-
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
1473
|
-
args: [
|
|
1474
|
-
salesConfigAndTokenInfo.salesConfig.address || zoraCreatorFixedPriceSaleStrategyAddress2[999999999],
|
|
1475
|
-
BigInt(tokenId),
|
|
1476
|
-
mintQuantity,
|
|
1477
|
-
encodeAbiParameters(parseAbiParameters("address, string"), [
|
|
1478
|
-
fixedPriceArgs.mintToAddress,
|
|
1479
|
-
fixedPriceArgs.mintComment || ""
|
|
1480
|
-
]),
|
|
1481
|
-
fixedPriceArgs.mintReferral || zeroAddress3
|
|
1482
|
-
]
|
|
1483
|
-
});
|
|
1484
|
-
case "erc20":
|
|
1485
|
-
const erc20Args = mintArguments;
|
|
1486
|
-
return makeSimulateContractParamaters({
|
|
1487
|
-
abi: erc20MinterABI,
|
|
1488
|
-
functionName: "mint",
|
|
1489
|
-
account: minterAccount,
|
|
1490
|
-
address: salesConfigAndTokenInfo?.salesConfig.address || erc20MinterAddress[999999999],
|
|
1491
|
-
/* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
|
|
1492
|
-
args: [
|
|
1493
|
-
mintArguments.mintToAddress,
|
|
1494
|
-
mintQuantity,
|
|
1495
|
-
tokenAddress,
|
|
1496
|
-
BigInt(tokenId),
|
|
1497
|
-
salesConfigAndTokenInfo.salesConfig.pricePerToken,
|
|
1498
|
-
salesConfigAndTokenInfo.salesConfig.currency,
|
|
1499
|
-
erc20Args.mintReferral || zeroAddress3,
|
|
1500
|
-
erc20Args.mintComment || ""
|
|
1501
|
-
]
|
|
1502
|
-
});
|
|
1503
|
-
default:
|
|
1504
|
-
throw new MintError("Unsupported sale type");
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
2153
|
|
|
1508
|
-
// src/create/
|
|
2154
|
+
// src/create/token-setup.ts
|
|
1509
2155
|
import {
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
zoraCreator1155ImplABI as
|
|
1513
|
-
zoraCreatorFixedPriceSaleStrategyABI
|
|
2156
|
+
erc20MinterABI as erc20MinterABI2,
|
|
2157
|
+
erc20MinterAddress as erc20MinterAddresses,
|
|
2158
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI4,
|
|
2159
|
+
zoraCreatorFixedPriceSaleStrategyABI,
|
|
2160
|
+
zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
|
|
1514
2161
|
} from "@zoralabs/protocol-deployments";
|
|
1515
|
-
import {
|
|
1516
|
-
|
|
1517
|
-
var
|
|
1518
|
-
|
|
1519
|
-
fundsRecipient: zeroAddress4,
|
|
1520
|
-
// Free Mint
|
|
1521
|
-
pricePerToken: 0n,
|
|
1522
|
-
// Sale start time – defaults to beginning of unix time
|
|
1523
|
-
saleStart: 0n,
|
|
1524
|
-
// This is the end of uint64, plenty of time
|
|
1525
|
-
saleEnd: SALE_END_FOREVER,
|
|
1526
|
-
// 0 Here means no limit
|
|
1527
|
-
maxTokensPerAddress: 0n
|
|
2162
|
+
import { encodeFunctionData, zeroAddress as zeroAddress5 } from "viem";
|
|
2163
|
+
import * as semver2 from "semver";
|
|
2164
|
+
var PERMISSION_BITS = {
|
|
2165
|
+
MINTER: 2n ** 2n
|
|
1528
2166
|
};
|
|
1529
|
-
var
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
salesConfig,
|
|
1544
|
-
royaltySettings
|
|
1545
|
-
}) {
|
|
1546
|
-
if (!maxSupply) {
|
|
1547
|
-
maxSupply = OPEN_EDITION_MINT_SIZE;
|
|
1548
|
-
}
|
|
1549
|
-
maxSupply = BigInt(maxSupply);
|
|
1550
|
-
mintToCreatorCount = BigInt(mintToCreatorCount);
|
|
1551
|
-
const salesConfigWithDefaults = {
|
|
1552
|
-
// Set static sales default.
|
|
2167
|
+
var saleSettingsOrDefault = (saleSettings) => {
|
|
2168
|
+
const SALE_END_FOREVER = 18446744073709551615n;
|
|
2169
|
+
const DEFAULT_SALE_SETTINGS = {
|
|
2170
|
+
currency: zeroAddress5,
|
|
2171
|
+
// Free Mint
|
|
2172
|
+
pricePerToken: 0n,
|
|
2173
|
+
// Sale start time – defaults to beginning of unix time
|
|
2174
|
+
saleStart: 0n,
|
|
2175
|
+
// This is the end of uint64, plenty of time
|
|
2176
|
+
saleEnd: SALE_END_FOREVER,
|
|
2177
|
+
// 0 Here means no limit
|
|
2178
|
+
maxTokensPerAddress: 0n
|
|
2179
|
+
};
|
|
2180
|
+
return {
|
|
1553
2181
|
...DEFAULT_SALE_SETTINGS,
|
|
1554
|
-
|
|
1555
|
-
...salesConfig
|
|
2182
|
+
...saleSettings
|
|
1556
2183
|
};
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
createReferral
|
|
1564
|
-
|
|
2184
|
+
};
|
|
2185
|
+
function applyNew1155Defaults(props, ownerAddress) {
|
|
2186
|
+
const { payoutRecipient: fundsRecipient } = props;
|
|
2187
|
+
const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== zeroAddress5 ? fundsRecipient : ownerAddress;
|
|
2188
|
+
return {
|
|
2189
|
+
payoutRecipient: fundsRecipientOrOwner,
|
|
2190
|
+
createReferral: props.createReferral || zeroAddress5,
|
|
2191
|
+
maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
|
|
2192
|
+
royaltyBPS: props.royaltyBPS || 1e3,
|
|
2193
|
+
salesConfig: saleSettingsOrDefault(props.salesConfig),
|
|
2194
|
+
tokenMetadataURI: props.tokenMetadataURI
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
function setupErc20Minter({
|
|
2198
|
+
pricePerToken,
|
|
2199
|
+
chainId,
|
|
2200
|
+
tokenId: nextTokenId,
|
|
2201
|
+
currency,
|
|
2202
|
+
saleStart,
|
|
2203
|
+
saleEnd,
|
|
2204
|
+
maxTokensPerAddress: mintLimit,
|
|
2205
|
+
fundsRecipient
|
|
2206
|
+
}) {
|
|
2207
|
+
const erc20MinterAddress = erc20MinterAddresses[chainId];
|
|
2208
|
+
if (!erc20MinterAddress)
|
|
2209
|
+
throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
|
|
2210
|
+
const erc20MinterApproval = encodeFunctionData({
|
|
2211
|
+
abi: zoraCreator1155ImplABI4,
|
|
2212
|
+
functionName: "addPermission",
|
|
2213
|
+
args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
|
|
2214
|
+
});
|
|
2215
|
+
const saleData = encodeFunctionData({
|
|
2216
|
+
abi: erc20MinterABI2,
|
|
2217
|
+
functionName: "setSale",
|
|
2218
|
+
args: [
|
|
2219
|
+
BigInt(nextTokenId),
|
|
2220
|
+
{
|
|
2221
|
+
saleStart: saleStart || BigInt(0),
|
|
2222
|
+
saleEnd: saleEnd || BigInt(0),
|
|
2223
|
+
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
2224
|
+
pricePerToken,
|
|
2225
|
+
fundsRecipient,
|
|
2226
|
+
currency
|
|
2227
|
+
}
|
|
2228
|
+
]
|
|
2229
|
+
});
|
|
2230
|
+
const callSale = encodeFunctionData({
|
|
2231
|
+
abi: zoraCreator1155ImplABI4,
|
|
2232
|
+
functionName: "callSale",
|
|
2233
|
+
args: [BigInt(nextTokenId), erc20MinterAddress, saleData]
|
|
2234
|
+
});
|
|
2235
|
+
return {
|
|
2236
|
+
minter: erc20MinterAddress,
|
|
2237
|
+
setupActions: [erc20MinterApproval, callSale]
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2240
|
+
function setupFixedPriceMinter({
|
|
2241
|
+
pricePerToken: price,
|
|
2242
|
+
tokenId: nextTokenId,
|
|
2243
|
+
chainId,
|
|
2244
|
+
saleStart,
|
|
2245
|
+
saleEnd,
|
|
2246
|
+
maxTokensPerAddress: mintLimit,
|
|
2247
|
+
fundsRecipient
|
|
2248
|
+
}) {
|
|
2249
|
+
const fixedPriceStrategyAddress = zoraCreatorFixedPriceSaleStrategyAddress2[chainId];
|
|
2250
|
+
const fixedPriceApproval = encodeFunctionData({
|
|
2251
|
+
abi: zoraCreator1155ImplABI4,
|
|
2252
|
+
functionName: "addPermission",
|
|
2253
|
+
args: [
|
|
2254
|
+
BigInt(nextTokenId),
|
|
2255
|
+
fixedPriceStrategyAddress,
|
|
2256
|
+
PERMISSION_BITS.MINTER
|
|
2257
|
+
]
|
|
2258
|
+
});
|
|
2259
|
+
const saleData = encodeFunctionData({
|
|
2260
|
+
abi: zoraCreatorFixedPriceSaleStrategyABI,
|
|
2261
|
+
functionName: "setSale",
|
|
2262
|
+
args: [
|
|
2263
|
+
BigInt(nextTokenId),
|
|
2264
|
+
{
|
|
2265
|
+
pricePerToken: price,
|
|
2266
|
+
saleStart: saleStart || BigInt(0),
|
|
2267
|
+
saleEnd: saleEnd || BigInt(0),
|
|
2268
|
+
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
2269
|
+
fundsRecipient
|
|
2270
|
+
}
|
|
2271
|
+
]
|
|
2272
|
+
});
|
|
2273
|
+
const callSale = encodeFunctionData({
|
|
2274
|
+
abi: zoraCreator1155ImplABI4,
|
|
2275
|
+
functionName: "callSale",
|
|
2276
|
+
args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
|
|
2277
|
+
});
|
|
2278
|
+
return {
|
|
2279
|
+
minter: fixedPriceStrategyAddress,
|
|
2280
|
+
setupActions: [fixedPriceApproval, callSale]
|
|
2281
|
+
};
|
|
2282
|
+
}
|
|
2283
|
+
function setupMinters({ salesConfig, ...rest }) {
|
|
2284
|
+
if (!salesConfig)
|
|
2285
|
+
throw new Error("No sales config for token");
|
|
2286
|
+
const { currency: currencyAddress } = salesConfig;
|
|
2287
|
+
if (currencyAddress === zeroAddress5) {
|
|
2288
|
+
return setupFixedPriceMinter({
|
|
2289
|
+
...salesConfig,
|
|
2290
|
+
...rest
|
|
2291
|
+
});
|
|
2292
|
+
} else {
|
|
2293
|
+
return setupErc20Minter({
|
|
2294
|
+
...salesConfig,
|
|
2295
|
+
...rest
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
function buildSetupNewToken({
|
|
2300
|
+
tokenURI,
|
|
2301
|
+
maxSupply = OPEN_EDITION_MINT_SIZE,
|
|
2302
|
+
createReferral = zeroAddress5,
|
|
2303
|
+
contractVersion
|
|
2304
|
+
}) {
|
|
2305
|
+
if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
|
|
2306
|
+
return encodeFunctionData({
|
|
2307
|
+
abi: zoraCreator1155ImplABI4,
|
|
1565
2308
|
functionName: "setupNewTokenWithCreateReferral",
|
|
1566
|
-
args: [
|
|
1567
|
-
})
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
2309
|
+
args: [tokenURI, BigInt(maxSupply), createReferral]
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
if (createReferral !== zeroAddress5) {
|
|
2313
|
+
throw new Error(
|
|
2314
|
+
"Contract does not support create referral, but one was provided"
|
|
2315
|
+
);
|
|
2316
|
+
}
|
|
2317
|
+
return encodeFunctionData({
|
|
2318
|
+
abi: zoraCreator1155ImplABI4,
|
|
2319
|
+
functionName: "setupNewToken",
|
|
2320
|
+
args: [tokenURI, BigInt(maxSupply)]
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
function setupRoyaltyConfig({
|
|
2324
|
+
royaltyBPS,
|
|
2325
|
+
royaltyRecipient,
|
|
2326
|
+
nextTokenId
|
|
2327
|
+
}) {
|
|
2328
|
+
if (royaltyBPS > 0 && royaltyRecipient != zeroAddress5) {
|
|
2329
|
+
return encodeFunctionData({
|
|
2330
|
+
abi: zoraCreator1155ImplABI4,
|
|
2331
|
+
functionName: "updateRoyaltiesForToken",
|
|
1580
2332
|
args: [
|
|
1581
2333
|
nextTokenId,
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
})
|
|
2334
|
+
{
|
|
2335
|
+
royaltyBPS,
|
|
2336
|
+
royaltyRecipient,
|
|
2337
|
+
royaltyMintSchedule: 0
|
|
2338
|
+
}
|
|
1588
2339
|
]
|
|
1589
|
-
})
|
|
1590
|
-
];
|
|
1591
|
-
if (mintToCreatorCount) {
|
|
1592
|
-
setupActions.push(
|
|
1593
|
-
encodeFunctionData({
|
|
1594
|
-
abi: zoraCreator1155ImplABI3,
|
|
1595
|
-
functionName: "adminMint",
|
|
1596
|
-
args: [account, nextTokenId, mintToCreatorCount, "0x"]
|
|
1597
|
-
})
|
|
1598
|
-
);
|
|
2340
|
+
});
|
|
1599
2341
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
|
|
1610
|
-
royaltyRecipient: royaltySettings?.royaltyRecipient || account
|
|
1611
|
-
}
|
|
1612
|
-
]
|
|
1613
|
-
})
|
|
1614
|
-
);
|
|
2342
|
+
return null;
|
|
2343
|
+
}
|
|
2344
|
+
function makeAdminMintCall({
|
|
2345
|
+
ownerAddress,
|
|
2346
|
+
mintQuantity,
|
|
2347
|
+
nextTokenId
|
|
2348
|
+
}) {
|
|
2349
|
+
if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
|
|
2350
|
+
return null;
|
|
1615
2351
|
}
|
|
1616
|
-
return
|
|
2352
|
+
return encodeFunctionData({
|
|
2353
|
+
abi: zoraCreator1155ImplABI4,
|
|
2354
|
+
functionName: "adminMint",
|
|
2355
|
+
args: [ownerAddress, nextTokenId, BigInt(mintQuantity), zeroAddress5]
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
function constructCreate1155TokenCalls(props) {
|
|
2359
|
+
const {
|
|
2360
|
+
chainId,
|
|
2361
|
+
nextTokenId,
|
|
2362
|
+
mintToCreatorCount,
|
|
2363
|
+
ownerAddress,
|
|
2364
|
+
contractVersion
|
|
2365
|
+
} = props;
|
|
2366
|
+
const new1155TokenPropsWithDefaults = applyNew1155Defaults(
|
|
2367
|
+
props,
|
|
2368
|
+
ownerAddress
|
|
2369
|
+
);
|
|
2370
|
+
const verifyTokenIdExpected = encodeFunctionData({
|
|
2371
|
+
abi: zoraCreator1155ImplABI4,
|
|
2372
|
+
functionName: "assumeLastTokenIdMatches",
|
|
2373
|
+
args: [nextTokenId - 1n]
|
|
2374
|
+
});
|
|
2375
|
+
const setupNewToken = buildSetupNewToken({
|
|
2376
|
+
tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
|
|
2377
|
+
maxSupply: new1155TokenPropsWithDefaults.maxSupply,
|
|
2378
|
+
createReferral: new1155TokenPropsWithDefaults.createReferral,
|
|
2379
|
+
contractVersion
|
|
2380
|
+
});
|
|
2381
|
+
const royaltyConfig = setupRoyaltyConfig({
|
|
2382
|
+
royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
|
|
2383
|
+
royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
|
|
2384
|
+
nextTokenId
|
|
2385
|
+
});
|
|
2386
|
+
const { minter, setupActions: mintersSetup } = setupMinters({
|
|
2387
|
+
tokenId: nextTokenId,
|
|
2388
|
+
chainId,
|
|
2389
|
+
fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
|
|
2390
|
+
salesConfig: new1155TokenPropsWithDefaults.salesConfig
|
|
2391
|
+
});
|
|
2392
|
+
const adminMintCall = makeAdminMintCall({
|
|
2393
|
+
ownerAddress,
|
|
2394
|
+
mintQuantity: mintToCreatorCount,
|
|
2395
|
+
nextTokenId
|
|
2396
|
+
});
|
|
2397
|
+
const setupActions = [
|
|
2398
|
+
verifyTokenIdExpected,
|
|
2399
|
+
setupNewToken,
|
|
2400
|
+
...mintersSetup,
|
|
2401
|
+
royaltyConfig,
|
|
2402
|
+
adminMintCall
|
|
2403
|
+
].filter((item) => item !== null);
|
|
2404
|
+
return {
|
|
2405
|
+
setupActions,
|
|
2406
|
+
minter,
|
|
2407
|
+
newToken: new1155TokenPropsWithDefaults
|
|
2408
|
+
};
|
|
1617
2409
|
}
|
|
2410
|
+
var contractSupportsMintRewards = (contractVersion, contractStandard) => {
|
|
2411
|
+
if (!contractStandard || !contractVersion) {
|
|
2412
|
+
return false;
|
|
2413
|
+
}
|
|
2414
|
+
const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
|
|
2415
|
+
if (!semVerContractVersion)
|
|
2416
|
+
return false;
|
|
2417
|
+
if (contractStandard === "ERC1155") {
|
|
2418
|
+
return semver2.gte(semVerContractVersion, "1.3.5");
|
|
2419
|
+
} else {
|
|
2420
|
+
return semver2.gte(semVerContractVersion, "14.0.0");
|
|
2421
|
+
}
|
|
2422
|
+
};
|
|
2423
|
+
|
|
2424
|
+
// src/create/1155-create-helper.ts
|
|
2425
|
+
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
1618
2426
|
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
1619
2427
|
for (const data of receipt.logs) {
|
|
1620
2428
|
try {
|
|
1621
2429
|
const decodedLog = decodeEventLog2({
|
|
1622
|
-
abi:
|
|
2430
|
+
abi: zoraCreator1155ImplABI5,
|
|
1623
2431
|
eventName: "SetupNewToken",
|
|
1624
2432
|
...data
|
|
1625
2433
|
});
|
|
@@ -1630,132 +2438,116 @@ var getTokenIdFromCreateReceipt = (receipt) => {
|
|
|
1630
2438
|
}
|
|
1631
2439
|
}
|
|
1632
2440
|
};
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
2441
|
+
function makeCreateContractAndTokenCall({
|
|
2442
|
+
contractExists,
|
|
2443
|
+
contractAddress,
|
|
2444
|
+
contract,
|
|
2445
|
+
account,
|
|
2446
|
+
royaltyBPS,
|
|
2447
|
+
tokenSetupActions,
|
|
2448
|
+
fundsRecipient
|
|
2449
|
+
}) {
|
|
2450
|
+
if (!contractAddress && typeof contract === "string") {
|
|
2451
|
+
throw new Error("Invariant: contract cannot be missing and an address");
|
|
2452
|
+
}
|
|
2453
|
+
if (!contractExists) {
|
|
2454
|
+
if (typeof contract === "string") {
|
|
2455
|
+
throw new Error("Invariant: expected contract object");
|
|
2456
|
+
}
|
|
2457
|
+
const accountAddress = typeof account === "string" ? account : account.address;
|
|
2458
|
+
return makeContractParameters({
|
|
2459
|
+
abi: zoraCreator1155FactoryImplABI2,
|
|
2460
|
+
functionName: "createContractDeterministic",
|
|
2461
|
+
account,
|
|
2462
|
+
address: zoraCreator1155FactoryImplAddress2[999],
|
|
1642
2463
|
args: [
|
|
1643
|
-
account,
|
|
1644
2464
|
contract.uri,
|
|
1645
2465
|
contract.name,
|
|
1646
|
-
|
|
2466
|
+
{
|
|
2467
|
+
// deprecated
|
|
2468
|
+
royaltyMintSchedule: 0,
|
|
2469
|
+
royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
|
|
2470
|
+
royaltyRecipient: fundsRecipient || accountAddress
|
|
2471
|
+
},
|
|
2472
|
+
contract.defaultAdmin || accountAddress,
|
|
2473
|
+
tokenSetupActions
|
|
1647
2474
|
]
|
|
1648
2475
|
});
|
|
1649
|
-
try {
|
|
1650
|
-
await publicClient.readContract({
|
|
1651
|
-
abi: zoraCreator1155ImplABI3,
|
|
1652
|
-
address: contractAddress,
|
|
1653
|
-
functionName: "contractVersion"
|
|
1654
|
-
});
|
|
1655
|
-
contractExists = true;
|
|
1656
|
-
} catch (e) {
|
|
1657
|
-
}
|
|
1658
|
-
return { contractAddress, contractExists };
|
|
1659
2476
|
}
|
|
1660
|
-
return {
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
};
|
|
1664
|
-
}
|
|
1665
|
-
function create1155CreatorClient(clientConfig) {
|
|
1666
|
-
const { publicClient } = setupClient(clientConfig);
|
|
1667
|
-
async function createNew1155Token({
|
|
1668
|
-
contract,
|
|
1669
|
-
tokenMetadataURI,
|
|
1670
|
-
mintToCreatorCount = 1,
|
|
1671
|
-
salesConfig = {},
|
|
1672
|
-
maxSupply,
|
|
2477
|
+
return makeContractParameters({
|
|
2478
|
+
abi: zoraCreator1155ImplABI5,
|
|
2479
|
+
functionName: "multicall",
|
|
1673
2480
|
account,
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
2481
|
+
address: contractAddress,
|
|
2482
|
+
args: [tokenSetupActions]
|
|
2483
|
+
});
|
|
2484
|
+
}
|
|
2485
|
+
var Create1155Client = class {
|
|
2486
|
+
constructor({
|
|
2487
|
+
chainId,
|
|
2488
|
+
publicClient
|
|
1677
2489
|
}) {
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
abi: zoraCreator1155ImplABI3,
|
|
1687
|
-
functionName: "nextTokenId",
|
|
1688
|
-
address: contractAddress
|
|
1689
|
-
});
|
|
1690
|
-
}
|
|
1691
|
-
const fixedPriceMinterAddress = await publicClient.readContract({
|
|
1692
|
-
abi: zoraCreator1155FactoryImplABI,
|
|
1693
|
-
address: zoraCreator1155FactoryImplAddress[999],
|
|
1694
|
-
functionName: "fixedPriceMinter"
|
|
1695
|
-
});
|
|
1696
|
-
let tokenSetupActions = create1155TokenSetupArgs({
|
|
1697
|
-
tokenMetadataURI,
|
|
1698
|
-
nextTokenId,
|
|
1699
|
-
salesConfig,
|
|
1700
|
-
maxSupply,
|
|
1701
|
-
fixedPriceMinterAddress,
|
|
1702
|
-
account,
|
|
1703
|
-
mintToCreatorCount,
|
|
1704
|
-
royaltySettings,
|
|
1705
|
-
createReferral
|
|
2490
|
+
this.chainId = chainId;
|
|
2491
|
+
this.publicClient = publicClient;
|
|
2492
|
+
}
|
|
2493
|
+
async createNew1155Token(props) {
|
|
2494
|
+
return createNew1155Token({
|
|
2495
|
+
...props,
|
|
2496
|
+
publicClient: this.publicClient,
|
|
2497
|
+
chainId: this.chainId
|
|
1706
2498
|
});
|
|
1707
|
-
if (getAdditionalSetupActions) {
|
|
1708
|
-
tokenSetupActions = [
|
|
1709
|
-
...getAdditionalSetupActions({ tokenId: nextTokenId, contractAddress }),
|
|
1710
|
-
...tokenSetupActions
|
|
1711
|
-
];
|
|
1712
|
-
}
|
|
1713
|
-
if (!contractAddress && typeof contract === "string") {
|
|
1714
|
-
throw new Error("Invariant: contract cannot be missing and an address");
|
|
1715
|
-
}
|
|
1716
|
-
if (!contractExists && typeof contract !== "string") {
|
|
1717
|
-
const request = makeSimulateContractParamaters({
|
|
1718
|
-
abi: zoraCreator1155FactoryImplABI,
|
|
1719
|
-
functionName: "createContractDeterministic",
|
|
1720
|
-
account,
|
|
1721
|
-
address: zoraCreator1155FactoryImplAddress[999],
|
|
1722
|
-
args: [
|
|
1723
|
-
contract.uri,
|
|
1724
|
-
contract.name,
|
|
1725
|
-
{
|
|
1726
|
-
// deprecated
|
|
1727
|
-
royaltyMintSchedule: 0,
|
|
1728
|
-
royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
|
|
1729
|
-
royaltyRecipient: royaltySettings?.royaltyRecipient || account
|
|
1730
|
-
},
|
|
1731
|
-
contract.defaultAdmin || account,
|
|
1732
|
-
tokenSetupActions
|
|
1733
|
-
]
|
|
1734
|
-
});
|
|
1735
|
-
return {
|
|
1736
|
-
request,
|
|
1737
|
-
tokenSetupActions,
|
|
1738
|
-
contractAddress,
|
|
1739
|
-
contractExists
|
|
1740
|
-
};
|
|
1741
|
-
} else if (contractExists) {
|
|
1742
|
-
const request = makeSimulateContractParamaters({
|
|
1743
|
-
abi: zoraCreator1155ImplABI3,
|
|
1744
|
-
functionName: "multicall",
|
|
1745
|
-
account,
|
|
1746
|
-
address: contractAddress,
|
|
1747
|
-
args: [tokenSetupActions]
|
|
1748
|
-
});
|
|
1749
|
-
return {
|
|
1750
|
-
request,
|
|
1751
|
-
tokenSetupActions,
|
|
1752
|
-
contractAddress,
|
|
1753
|
-
contractExists
|
|
1754
|
-
};
|
|
1755
|
-
}
|
|
1756
|
-
throw new Error("Unsupported contract argument type");
|
|
1757
2499
|
}
|
|
1758
|
-
|
|
2500
|
+
};
|
|
2501
|
+
async function createNew1155Token({
|
|
2502
|
+
contract,
|
|
2503
|
+
account,
|
|
2504
|
+
getAdditionalSetupActions,
|
|
2505
|
+
token: tokenConfig,
|
|
2506
|
+
publicClient,
|
|
2507
|
+
chainId
|
|
2508
|
+
}) {
|
|
2509
|
+
const { contractExists, contractAddress, nextTokenId, contractVersion } = await getContractInfo({
|
|
2510
|
+
publicClient,
|
|
2511
|
+
chainId,
|
|
2512
|
+
contract,
|
|
2513
|
+
account
|
|
2514
|
+
});
|
|
2515
|
+
const {
|
|
2516
|
+
minter,
|
|
2517
|
+
newToken,
|
|
2518
|
+
setupActions: tokenSetupActions
|
|
2519
|
+
} = constructCreate1155TokenCalls({
|
|
2520
|
+
chainId,
|
|
2521
|
+
ownerAddress: account,
|
|
2522
|
+
contractVersion,
|
|
2523
|
+
nextTokenId,
|
|
2524
|
+
...tokenConfig
|
|
2525
|
+
});
|
|
2526
|
+
const setupActions = getAdditionalSetupActions ? [
|
|
2527
|
+
...getAdditionalSetupActions({
|
|
2528
|
+
tokenId: nextTokenId,
|
|
2529
|
+
contractAddress
|
|
2530
|
+
}),
|
|
2531
|
+
...tokenSetupActions
|
|
2532
|
+
] : tokenSetupActions;
|
|
2533
|
+
const request = makeCreateContractAndTokenCall({
|
|
2534
|
+
contractExists,
|
|
2535
|
+
contractAddress,
|
|
2536
|
+
contract,
|
|
2537
|
+
account,
|
|
2538
|
+
tokenSetupActions: setupActions,
|
|
2539
|
+
royaltyBPS: tokenConfig.royaltyBPS,
|
|
2540
|
+
fundsRecipient: tokenConfig.payoutRecipient
|
|
2541
|
+
});
|
|
2542
|
+
return {
|
|
2543
|
+
parameters: request,
|
|
2544
|
+
tokenSetupActions,
|
|
2545
|
+
collectionAddress: contractAddress,
|
|
2546
|
+
contractExists,
|
|
2547
|
+
newTokenId: nextTokenId,
|
|
2548
|
+
newToken,
|
|
2549
|
+
minter
|
|
2550
|
+
};
|
|
1759
2551
|
}
|
|
1760
2552
|
|
|
1761
2553
|
// src/mints/mints-queries.ts
|
|
@@ -1826,7 +2618,7 @@ import {
|
|
|
1826
2618
|
import {
|
|
1827
2619
|
decodeErrorResult,
|
|
1828
2620
|
encodeFunctionData as encodeFunctionData2,
|
|
1829
|
-
zeroAddress as
|
|
2621
|
+
zeroAddress as zeroAddress6
|
|
1830
2622
|
} from "viem";
|
|
1831
2623
|
var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
|
|
1832
2624
|
var mintWithEthParams = ({
|
|
@@ -1835,7 +2627,7 @@ var mintWithEthParams = ({
|
|
|
1835
2627
|
chainId,
|
|
1836
2628
|
pricePerMint,
|
|
1837
2629
|
account
|
|
1838
|
-
}) =>
|
|
2630
|
+
}) => makeContractParameters({
|
|
1839
2631
|
abi: zoraMintsManagerImplConfig.abi,
|
|
1840
2632
|
address: zoraMintsManagerImplConfig.address[chainId],
|
|
1841
2633
|
functionName: "mintWithEth",
|
|
@@ -1891,7 +2683,7 @@ function collectWithMintsParams({
|
|
|
1891
2683
|
minter,
|
|
1892
2684
|
mintArguments
|
|
1893
2685
|
});
|
|
1894
|
-
return
|
|
2686
|
+
return makeContractParameters({
|
|
1895
2687
|
abi: zoraMints1155Config.abi,
|
|
1896
2688
|
address: zoraMints1155Config.address[chainId],
|
|
1897
2689
|
functionName: "transferBatchToManagerAndCall",
|
|
@@ -1982,7 +2774,7 @@ var encodePremintOnManager = ({
|
|
|
1982
2774
|
premintConfig,
|
|
1983
2775
|
premintSignature,
|
|
1984
2776
|
mintArguments,
|
|
1985
|
-
signerContract =
|
|
2777
|
+
signerContract = zeroAddress6
|
|
1986
2778
|
}) => encodeFunctionData2({
|
|
1987
2779
|
abi: zoraMintsManagerImplConfig.abi,
|
|
1988
2780
|
functionName: "collectPremintV2",
|
|
@@ -2037,7 +2829,7 @@ function collectPremintV2WithMintsParams({
|
|
|
2037
2829
|
const call = encodePremintOnManager({
|
|
2038
2830
|
...rest
|
|
2039
2831
|
});
|
|
2040
|
-
return
|
|
2832
|
+
return makeContractParameters({
|
|
2041
2833
|
abi: zoraMints1155Config.abi,
|
|
2042
2834
|
address: zoraMints1155Config.address[chainId],
|
|
2043
2835
|
functionName: "transferBatchToManagerAndCall",
|
|
@@ -2090,23 +2882,66 @@ var unwrapAndForwardEthPermitAndTypedDataDefinition = ({
|
|
|
2090
2882
|
to: mintsEthUnwrapperAndCallerAddress[chainId],
|
|
2091
2883
|
nonce
|
|
2092
2884
|
});
|
|
2885
|
+
|
|
2886
|
+
// src/sdk.ts
|
|
2887
|
+
function createCreatorClient(clientConfig) {
|
|
2888
|
+
const premintClient = new PremintClient({
|
|
2889
|
+
chainId: clientConfig.chainId,
|
|
2890
|
+
publicClient: clientConfig.publicClient,
|
|
2891
|
+
premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
|
|
2892
|
+
});
|
|
2893
|
+
const create1155CreatorClient = new Create1155Client({
|
|
2894
|
+
chainId: clientConfig.chainId,
|
|
2895
|
+
publicClient: clientConfig.publicClient
|
|
2896
|
+
});
|
|
2897
|
+
return {
|
|
2898
|
+
createPremint: (p) => premintClient.createPremint(p),
|
|
2899
|
+
updatePremint: (p) => premintClient.updatePremint(p),
|
|
2900
|
+
deletePremint: (p) => premintClient.deletePremint(p),
|
|
2901
|
+
create1155: (p) => create1155CreatorClient.createNew1155Token(p)
|
|
2902
|
+
};
|
|
2903
|
+
}
|
|
2904
|
+
function createCollectorClient(params) {
|
|
2905
|
+
const premintGetterToUse = params.premintGetter || new PremintAPIClient(params.chainId);
|
|
2906
|
+
const mintGetterToUse = params.mintGetter || new SubgraphMintGetter(params.chainId);
|
|
2907
|
+
const mintClient = new MintClient({
|
|
2908
|
+
publicClient: params.publicClient,
|
|
2909
|
+
premintGetter: premintGetterToUse,
|
|
2910
|
+
mintGetter: mintGetterToUse
|
|
2911
|
+
});
|
|
2912
|
+
return {
|
|
2913
|
+
getPremint: (p) => premintGetterToUse.get({
|
|
2914
|
+
collectionAddress: p.address,
|
|
2915
|
+
uid: p.uid
|
|
2916
|
+
}),
|
|
2917
|
+
getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
|
|
2918
|
+
getToken: (p) => mintClient.get(p),
|
|
2919
|
+
getTokensOfContract: (p) => mintClient.getOfContract(p),
|
|
2920
|
+
mint: (p) => mintClient.mint(p),
|
|
2921
|
+
getMintCosts: (p) => mintClient.getMintCosts(p)
|
|
2922
|
+
};
|
|
2923
|
+
}
|
|
2093
2924
|
export {
|
|
2094
|
-
|
|
2925
|
+
Create1155Client,
|
|
2095
2926
|
Errors,
|
|
2096
|
-
|
|
2927
|
+
MintClient,
|
|
2097
2928
|
PremintAPIClient,
|
|
2929
|
+
PremintClient,
|
|
2098
2930
|
PremintConfigVersion3 as PremintConfigVersion,
|
|
2931
|
+
SubgraphMintGetter,
|
|
2099
2932
|
ZORA_API_BASE,
|
|
2100
2933
|
applyUpdateToPremint,
|
|
2934
|
+
buildPremintMintCall,
|
|
2935
|
+
collectOnchain,
|
|
2936
|
+
collectPremint,
|
|
2101
2937
|
collectPremintV2WithMintsParams,
|
|
2102
2938
|
collectWithMintsParams,
|
|
2103
2939
|
convertCollectionFromApi,
|
|
2104
2940
|
convertGetPremintApiResponse,
|
|
2941
|
+
convertGetPremintOfCollectionApiResponse,
|
|
2105
2942
|
convertPremintFromApi,
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
createMintClient,
|
|
2109
|
-
createPremintClient,
|
|
2943
|
+
createCollectorClient,
|
|
2944
|
+
createCreatorClient,
|
|
2110
2945
|
decodeCallFailedError,
|
|
2111
2946
|
defaultAdditionalAdmins,
|
|
2112
2947
|
defaultTokenConfigV1MintArguments,
|
|
@@ -2116,17 +2951,22 @@ export {
|
|
|
2116
2951
|
encodePostSignatureInput,
|
|
2117
2952
|
encodePremintForAPI,
|
|
2118
2953
|
getApiNetworkConfigForChain,
|
|
2954
|
+
getDataFromPremintReceipt,
|
|
2119
2955
|
getDefaultFixedPriceMinterAddress,
|
|
2120
|
-
getMintCosts,
|
|
2121
2956
|
getMintsAccountBalanceWithPriceQuery,
|
|
2122
2957
|
getMintsEthPrice,
|
|
2123
2958
|
getPremintCollectionAddress,
|
|
2124
2959
|
getPremintExecutorAddress,
|
|
2125
2960
|
getPremintMintCosts,
|
|
2961
|
+
getPremintMintCostsWithUnknownTokenPrice,
|
|
2126
2962
|
getPremintMintFee,
|
|
2963
|
+
getPremintPricePerToken,
|
|
2127
2964
|
getPremintedLogFromReceipt,
|
|
2965
|
+
getSignature,
|
|
2128
2966
|
getTokenIdFromCreateReceipt,
|
|
2129
2967
|
isAuthorizedToCreatePremint,
|
|
2968
|
+
isPremintConfigV1,
|
|
2969
|
+
isPremintConfigV2,
|
|
2130
2970
|
isValidSignature,
|
|
2131
2971
|
makeCallWithEthSafeTransferData,
|
|
2132
2972
|
makeMintRewardsRecipient,
|