@zoralabs/protocol-sdk 0.5.14 → 0.5.15
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 +7 -0
- package/README.md +42 -2
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs +138 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +140 -58
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +14 -6
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +3 -2
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +36 -0
- package/src/mint/mint-api-client.ts +107 -45
- package/src/mint/mint-client.test.ts +113 -2
- package/src/mint/mint-client.ts +64 -23
- package/src/premint/preminter.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -26,6 +26,8 @@ async function isAuthorizedToCreatePremint({
|
|
|
26
26
|
publicClient,
|
|
27
27
|
signer
|
|
28
28
|
}) {
|
|
29
|
+
if (collection.additionalAdmins.length > 0)
|
|
30
|
+
throw new Error("additionalAdmins not supported yet.");
|
|
29
31
|
return await publicClient.readContract({
|
|
30
32
|
abi: preminterAbi,
|
|
31
33
|
address: getPremintExecutorAddress(),
|
|
@@ -331,6 +333,41 @@ var zora721Abi = parseAbi([
|
|
|
331
333
|
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
332
334
|
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
|
|
333
335
|
]);
|
|
336
|
+
var NFT_SALE_QUERY = `
|
|
337
|
+
fragment SaleStrategy on SalesStrategyConfig {
|
|
338
|
+
type
|
|
339
|
+
fixedPrice {
|
|
340
|
+
address
|
|
341
|
+
pricePerToken
|
|
342
|
+
saleEnd
|
|
343
|
+
saleStart
|
|
344
|
+
maxTokensPerAddress
|
|
345
|
+
}
|
|
346
|
+
erc20Minter {
|
|
347
|
+
address
|
|
348
|
+
pricePerToken
|
|
349
|
+
currency
|
|
350
|
+
saleEnd
|
|
351
|
+
saleStart
|
|
352
|
+
maxTokensPerAddress
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
query ($id: ID!) {
|
|
357
|
+
zoraCreateToken(id: $id) {
|
|
358
|
+
id
|
|
359
|
+
contract {
|
|
360
|
+
mintFeePerQuantity
|
|
361
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
362
|
+
...SaleStrategy
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
366
|
+
...SaleStrategy
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
`;
|
|
334
371
|
|
|
335
372
|
// src/apis/chain-constants.ts
|
|
336
373
|
import {
|
|
@@ -426,38 +463,13 @@ var MintAPIClient = class {
|
|
|
426
463
|
}
|
|
427
464
|
async getSalesConfigAndTokenInfo({
|
|
428
465
|
tokenAddress,
|
|
429
|
-
tokenId
|
|
466
|
+
tokenId,
|
|
467
|
+
saleType
|
|
430
468
|
}) {
|
|
431
469
|
const { retries: retries2, post: post2 } = this.httpClient;
|
|
432
470
|
return retries2(async () => {
|
|
433
471
|
const response = await post2(this.networkConfig.subgraphUrl, {
|
|
434
|
-
query:
|
|
435
|
-
fragment SaleStrategy on SalesStrategyConfig {
|
|
436
|
-
type
|
|
437
|
-
fixedPrice {
|
|
438
|
-
address
|
|
439
|
-
pricePerToken
|
|
440
|
-
saleEnd
|
|
441
|
-
saleStart
|
|
442
|
-
maxTokensPerAddress
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
query ($id: ID!) {
|
|
447
|
-
zoraCreateToken(id: $id) {
|
|
448
|
-
id
|
|
449
|
-
contract {
|
|
450
|
-
mintFeePerQuantity
|
|
451
|
-
salesStrategies(where: { type: "FIXED_PRICE" }) {
|
|
452
|
-
...SaleStrategy
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
salesStrategies(where: { type: "FIXED_PRICE" }) {
|
|
456
|
-
...SaleStrategy
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
`,
|
|
472
|
+
query: NFT_SALE_QUERY,
|
|
461
473
|
variables: {
|
|
462
474
|
id: tokenId !== void 0 ? (
|
|
463
475
|
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
@@ -469,17 +481,56 @@ var MintAPIClient = class {
|
|
|
469
481
|
if (!token) {
|
|
470
482
|
throw new Error("Cannot find a token to mint");
|
|
471
483
|
}
|
|
472
|
-
const
|
|
473
|
-
const
|
|
474
|
-
(a, b) => BigInt(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
484
|
+
const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
|
|
485
|
+
const saleStrategies = allStrategies.sort(
|
|
486
|
+
(a, b) => BigInt(
|
|
487
|
+
a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd
|
|
488
|
+
) > BigInt(
|
|
489
|
+
b.type === "FIXED_PRICE" ? b.fixedPrice.saleEnd : b.erc20Minter.saleEnd
|
|
490
|
+
) ? 1 : -1
|
|
491
|
+
);
|
|
492
|
+
let targetStrategy;
|
|
493
|
+
if (!saleType) {
|
|
494
|
+
targetStrategy = saleStrategies[0];
|
|
495
|
+
if (!targetStrategy) {
|
|
496
|
+
throw new Error("Cannot find sale strategy");
|
|
497
|
+
}
|
|
498
|
+
} else {
|
|
499
|
+
const mappedSaleType = saleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
|
|
500
|
+
targetStrategy = saleStrategies.find(
|
|
501
|
+
(strategy) => strategy.type === mappedSaleType
|
|
502
|
+
);
|
|
503
|
+
if (!targetStrategy) {
|
|
504
|
+
throw new Error(`Cannot find sale strategy for ${mappedSaleType}`);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (targetStrategy.type === "FIXED_PRICE") {
|
|
508
|
+
return {
|
|
509
|
+
salesConfig: {
|
|
510
|
+
saleType: "fixedPrice",
|
|
511
|
+
...targetStrategy.fixedPrice,
|
|
512
|
+
maxTokensPerAddress: BigInt(
|
|
513
|
+
targetStrategy.fixedPrice.maxTokensPerAddress
|
|
514
|
+
),
|
|
515
|
+
pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
|
|
516
|
+
},
|
|
517
|
+
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
|
|
518
|
+
};
|
|
478
519
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
520
|
+
if (targetStrategy.type === "ERC_20_MINTER") {
|
|
521
|
+
return {
|
|
522
|
+
salesConfig: {
|
|
523
|
+
saleType: "erc20",
|
|
524
|
+
...targetStrategy.erc20Minter,
|
|
525
|
+
maxTokensPerAddress: BigInt(
|
|
526
|
+
targetStrategy.erc20Minter.maxTokensPerAddress
|
|
527
|
+
),
|
|
528
|
+
pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
|
|
529
|
+
},
|
|
530
|
+
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
throw new Error("Invalid saleType");
|
|
483
534
|
});
|
|
484
535
|
}
|
|
485
536
|
};
|
|
@@ -1167,6 +1218,8 @@ import {
|
|
|
1167
1218
|
http as http2
|
|
1168
1219
|
} from "viem";
|
|
1169
1220
|
import {
|
|
1221
|
+
erc20MinterABI,
|
|
1222
|
+
erc20MinterAddress,
|
|
1170
1223
|
zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
|
|
1171
1224
|
zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
|
|
1172
1225
|
} from "@zoralabs/protocol-deployments";
|
|
@@ -1212,16 +1265,19 @@ async function makePrepareMintTokenParams({
|
|
|
1212
1265
|
apiClient,
|
|
1213
1266
|
tokenId,
|
|
1214
1267
|
tokenAddress,
|
|
1268
|
+
mintArguments,
|
|
1215
1269
|
...rest
|
|
1216
1270
|
}) {
|
|
1217
1271
|
const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
|
|
1218
1272
|
tokenId,
|
|
1219
|
-
tokenAddress
|
|
1273
|
+
tokenAddress,
|
|
1274
|
+
saleType: mintArguments.saleType
|
|
1220
1275
|
});
|
|
1221
1276
|
if (tokenId === void 0) {
|
|
1222
1277
|
return makePrepareMint721TokenParams({
|
|
1223
1278
|
salesConfigAndTokenInfo,
|
|
1224
1279
|
tokenAddress,
|
|
1280
|
+
mintArguments,
|
|
1225
1281
|
...rest
|
|
1226
1282
|
});
|
|
1227
1283
|
}
|
|
@@ -1229,6 +1285,7 @@ async function makePrepareMintTokenParams({
|
|
|
1229
1285
|
salesConfigAndTokenInfo,
|
|
1230
1286
|
tokenAddress,
|
|
1231
1287
|
tokenId,
|
|
1288
|
+
mintArguments,
|
|
1232
1289
|
...rest
|
|
1233
1290
|
});
|
|
1234
1291
|
}
|
|
@@ -1261,7 +1318,7 @@ function getMintCosts({
|
|
|
1261
1318
|
quantityToMint
|
|
1262
1319
|
}) {
|
|
1263
1320
|
const mintFeeForTokens = salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
|
|
1264
|
-
const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.
|
|
1321
|
+
const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.salesConfig.pricePerToken) * quantityToMint;
|
|
1265
1322
|
return {
|
|
1266
1323
|
mintFee: mintFeeForTokens,
|
|
1267
1324
|
tokenPurchaseCost,
|
|
@@ -1280,24 +1337,49 @@ async function makePrepareMint1155TokenParams({
|
|
|
1280
1337
|
salesConfigAndTokenInfo,
|
|
1281
1338
|
quantityToMint: mintQuantity
|
|
1282
1339
|
}).totalCost;
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1340
|
+
switch (salesConfigAndTokenInfo.salesConfig.saleType) {
|
|
1341
|
+
case "fixedPrice":
|
|
1342
|
+
const fixedPriceArgs = mintArguments;
|
|
1343
|
+
return makeSimulateContractParamaters({
|
|
1344
|
+
abi: zoraCreator1155ImplABI2,
|
|
1345
|
+
functionName: "mintWithRewards",
|
|
1346
|
+
account: minterAccount,
|
|
1347
|
+
value: mintValue,
|
|
1348
|
+
address: tokenAddress,
|
|
1349
|
+
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
1350
|
+
args: [
|
|
1351
|
+
salesConfigAndTokenInfo.salesConfig.address || zoraCreatorFixedPriceSaleStrategyAddress2[999999999],
|
|
1352
|
+
BigInt(tokenId),
|
|
1353
|
+
mintQuantity,
|
|
1354
|
+
encodeAbiParameters(parseAbiParameters("address, string"), [
|
|
1355
|
+
fixedPriceArgs.mintToAddress,
|
|
1356
|
+
fixedPriceArgs.mintComment || ""
|
|
1357
|
+
]),
|
|
1358
|
+
fixedPriceArgs.mintReferral || zeroAddress3
|
|
1359
|
+
]
|
|
1360
|
+
});
|
|
1361
|
+
case "erc20":
|
|
1362
|
+
const erc20Args = mintArguments;
|
|
1363
|
+
return makeSimulateContractParamaters({
|
|
1364
|
+
abi: erc20MinterABI,
|
|
1365
|
+
functionName: "mint",
|
|
1366
|
+
account: minterAccount,
|
|
1367
|
+
address: salesConfigAndTokenInfo?.salesConfig.address || erc20MinterAddress[999999999],
|
|
1368
|
+
/* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
|
|
1369
|
+
args: [
|
|
1370
|
+
mintArguments.mintToAddress,
|
|
1371
|
+
mintQuantity,
|
|
1372
|
+
tokenAddress,
|
|
1373
|
+
BigInt(tokenId),
|
|
1374
|
+
salesConfigAndTokenInfo.salesConfig.pricePerToken,
|
|
1375
|
+
salesConfigAndTokenInfo.salesConfig.currency,
|
|
1376
|
+
erc20Args.mintReferral || zeroAddress3,
|
|
1377
|
+
erc20Args.mintComment || ""
|
|
1378
|
+
]
|
|
1379
|
+
});
|
|
1380
|
+
default:
|
|
1381
|
+
throw new MintError("Unsupported sale type");
|
|
1382
|
+
}
|
|
1301
1383
|
}
|
|
1302
1384
|
|
|
1303
1385
|
// src/create/1155-create-helper.ts
|