@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.
@@ -7,9 +7,9 @@ $ tsup
7
7
  CLI Cleaning output folder
8
8
  CJS Build start
9
9
  ESM Build start
10
- CJS dist/index.cjs 58.27 KB
11
- CJS dist/index.cjs.map 116.71 KB
12
- CJS ⚡️ Build success in 115ms
13
- ESM dist/index.js 52.91 KB
14
- ESM dist/index.js.map 116.68 KB
15
- ESM ⚡️ Build success in 117ms
10
+ CJS dist/index.cjs 60.89 KB
11
+ CJS dist/index.cjs.map 121.87 KB
12
+ CJS ⚡️ Build success in 106ms
13
+ ESM dist/index.js 55.50 KB
14
+ ESM dist/index.js.map 121.86 KB
15
+ ESM ⚡️ Build success in 125ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @zoralabs/protocol-sdk
2
2
 
3
+ ## 0.5.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 888168b8: Fix protocol-sdk to point to `isAuthorizedToCreatePremint`
8
+ - 344f452b: Add support for ERC-20 minting on 1155s using ERC20 minters within the function `makePrepareMintTokenParams`.
9
+
3
10
  ## 0.5.14
4
11
 
5
12
  ### Patch Changes
package/README.md CHANGED
@@ -9,7 +9,6 @@ Protocol SDK allows developers to create tokens using the Zora Protocol and mint
9
9
  - `npm install viem`
10
10
  - `npm install `
11
11
 
12
-
13
12
  ## Examples
14
13
 
15
14
  - [Creating a mint from an on-chain contract](#creating-a-mint-from-an-on-chain-contract)
@@ -83,6 +82,44 @@ async function mintNFT({
83
82
  }
84
83
  ```
85
84
 
85
+ ### Minting an NFT with an ERC20 minter
86
+
87
+ If an 1155 token is set to be an ERC20 mint, use the `makePrepareMintTokenParams` the same way as for
88
+ eth based mints. The underlying function should handle preparing arguments for the ERC20 mint.
89
+
90
+ ```ts
91
+ import type { PublicClient } from "viem";
92
+
93
+ async function mint1155TokenWithERC20Currency(
94
+ publicClient: PublicClient,
95
+ minterAddress: Address,
96
+ ) {
97
+ const mintClient = createMintClient({ chain: zora });
98
+ const exampleCurrency = "0xb6b701878a1f80197dF2c209D0BDd292EA73164D";
99
+ // nft collection address
100
+ const targetContract = "0x689bc305456c38656856d12469aed282fbd89fe0";
101
+ const tokenId = 17;
102
+ // the NFT token price in WEI value
103
+ const erc20PricePerToken = 2000000000000000000;
104
+
105
+ const tokenParams = await mintClient.makePrepareMintTokenParams({
106
+ minterAccount: minterAddress,
107
+ tokenId: tokenId,
108
+ tokenAddress: targetContract,
109
+ mintArguments: {
110
+ mintToAddress: minterAddress,
111
+ quantityToMint: 1,
112
+ },
113
+ });
114
+
115
+ const simulationResult = await publicClient.simulateContract(params);
116
+ const hash = await walletClient.writeContract(simulationResult.request);
117
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
118
+
119
+ return receipt;
120
+ }
121
+ ```
122
+
86
123
  #### Using wagmi
87
124
 
88
125
  ```tsx
@@ -260,7 +297,10 @@ async function createForFree({
260
297
  checkSignature: true,
261
298
  // collection info of collection to create
262
299
  collection: {
263
- contractAdmin: typeof creatorAccount === "string" ? creatorAccount : creatorAccount.address,
300
+ contractAdmin:
301
+ typeof creatorAccount === "string"
302
+ ? creatorAccount
303
+ : creatorAccount.address,
264
304
  contractName: "Testing Contract",
265
305
  contractURI:
266
306
  "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
@@ -33,4 +33,5 @@ export declare const zora721Abi: readonly [{
33
33
  readonly type: "uint256";
34
34
  }];
35
35
  }];
36
+ export declare const NFT_SALE_QUERY = "\nfragment SaleStrategy on SalesStrategyConfig {\n type\n fixedPrice {\n address\n pricePerToken\n saleEnd\n saleStart\n maxTokensPerAddress\n }\n erc20Minter {\n address\n pricePerToken\n currency\n saleEnd\n saleStart\n maxTokensPerAddress\n }\n}\n\nquery ($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n contract {\n mintFeePerQuantity\n salesStrategies(where: {type_in: [\"FIXED_PRICE\", \"ERC_20_MINTER\"]}) {\n ...SaleStrategy\n }\n }\n salesStrategies(where: {type_in: [\"FIXED_PRICE\", \"ERC_20_MINTER\"]}) {\n ...SaleStrategy\n }\n }\n}\n";
36
37
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,yBAAyB,CAAC;AACpD,eAAO,MAAM,sBAAsB,QAAiC,CAAC;AAMrE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGZ,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,yBAAyB,CAAC;AACpD,eAAO,MAAM,sBAAsB,QAAiC,CAAC;AAMrE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGZ,CAAC;AAEZ,eAAO,MAAM,cAAc,0nBAkC1B,CAAC"}
package/dist/index.cjs CHANGED
@@ -89,6 +89,8 @@ async function isAuthorizedToCreatePremint({
89
89
  publicClient,
90
90
  signer
91
91
  }) {
92
+ if (collection.additionalAdmins.length > 0)
93
+ throw new Error("additionalAdmins not supported yet.");
92
94
  return await publicClient.readContract({
93
95
  abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
94
96
  address: getPremintExecutorAddress(),
@@ -391,6 +393,41 @@ var zora721Abi = (0, import_viem2.parseAbi)([
391
393
  "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
392
394
  "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
393
395
  ]);
396
+ var NFT_SALE_QUERY = `
397
+ fragment SaleStrategy on SalesStrategyConfig {
398
+ type
399
+ fixedPrice {
400
+ address
401
+ pricePerToken
402
+ saleEnd
403
+ saleStart
404
+ maxTokensPerAddress
405
+ }
406
+ erc20Minter {
407
+ address
408
+ pricePerToken
409
+ currency
410
+ saleEnd
411
+ saleStart
412
+ maxTokensPerAddress
413
+ }
414
+ }
415
+
416
+ query ($id: ID!) {
417
+ zoraCreateToken(id: $id) {
418
+ id
419
+ contract {
420
+ mintFeePerQuantity
421
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
422
+ ...SaleStrategy
423
+ }
424
+ }
425
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
426
+ ...SaleStrategy
427
+ }
428
+ }
429
+ }
430
+ `;
394
431
 
395
432
  // src/apis/chain-constants.ts
396
433
  var import_chains = require("viem/chains");
@@ -476,38 +513,13 @@ var MintAPIClient = class {
476
513
  }
477
514
  async getSalesConfigAndTokenInfo({
478
515
  tokenAddress,
479
- tokenId
516
+ tokenId,
517
+ saleType
480
518
  }) {
481
519
  const { retries: retries2, post: post2 } = this.httpClient;
482
520
  return retries2(async () => {
483
521
  const response = await post2(this.networkConfig.subgraphUrl, {
484
- query: `
485
- fragment SaleStrategy on SalesStrategyConfig {
486
- type
487
- fixedPrice {
488
- address
489
- pricePerToken
490
- saleEnd
491
- saleStart
492
- maxTokensPerAddress
493
- }
494
- }
495
-
496
- query ($id: ID!) {
497
- zoraCreateToken(id: $id) {
498
- id
499
- contract {
500
- mintFeePerQuantity
501
- salesStrategies(where: { type: "FIXED_PRICE" }) {
502
- ...SaleStrategy
503
- }
504
- }
505
- salesStrategies(where: { type: "FIXED_PRICE" }) {
506
- ...SaleStrategy
507
- }
508
- }
509
- }
510
- `,
522
+ query: NFT_SALE_QUERY,
511
523
  variables: {
512
524
  id: tokenId !== void 0 ? (
513
525
  // Generic Token ID types all stringify down to the base numeric equivalent.
@@ -519,17 +531,56 @@ var MintAPIClient = class {
519
531
  if (!token) {
520
532
  throw new Error("Cannot find a token to mint");
521
533
  }
522
- const saleStrategies = tokenId !== void 0 ? token.salesStrategies : token.contract.salesStrategies;
523
- const fixedPrice = saleStrategies?.sort(
524
- (a, b) => BigInt(a.fixedPrice.saleEnd) > BigInt(b.fixedPrice.saleEnd) ? 1 : -1
525
- )?.find(() => true)?.fixedPrice;
526
- if (!fixedPrice) {
527
- throw new Error("Cannot find fixed price sale strategy");
534
+ const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
535
+ const saleStrategies = allStrategies.sort(
536
+ (a, b) => BigInt(
537
+ a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd
538
+ ) > BigInt(
539
+ b.type === "FIXED_PRICE" ? b.fixedPrice.saleEnd : b.erc20Minter.saleEnd
540
+ ) ? 1 : -1
541
+ );
542
+ let targetStrategy;
543
+ if (!saleType) {
544
+ targetStrategy = saleStrategies[0];
545
+ if (!targetStrategy) {
546
+ throw new Error("Cannot find sale strategy");
547
+ }
548
+ } else {
549
+ const mappedSaleType = saleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
550
+ targetStrategy = saleStrategies.find(
551
+ (strategy) => strategy.type === mappedSaleType
552
+ );
553
+ if (!targetStrategy) {
554
+ throw new Error(`Cannot find sale strategy for ${mappedSaleType}`);
555
+ }
556
+ }
557
+ if (targetStrategy.type === "FIXED_PRICE") {
558
+ return {
559
+ salesConfig: {
560
+ saleType: "fixedPrice",
561
+ ...targetStrategy.fixedPrice,
562
+ maxTokensPerAddress: BigInt(
563
+ targetStrategy.fixedPrice.maxTokensPerAddress
564
+ ),
565
+ pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
566
+ },
567
+ mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
568
+ };
528
569
  }
529
- return {
530
- fixedPrice,
531
- mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
532
- };
570
+ if (targetStrategy.type === "ERC_20_MINTER") {
571
+ return {
572
+ salesConfig: {
573
+ saleType: "erc20",
574
+ ...targetStrategy.erc20Minter,
575
+ maxTokensPerAddress: BigInt(
576
+ targetStrategy.erc20Minter.maxTokensPerAddress
577
+ ),
578
+ pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
579
+ },
580
+ mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
581
+ };
582
+ }
583
+ throw new Error("Invalid saleType");
533
584
  });
534
585
  }
535
586
  };
@@ -1251,16 +1302,19 @@ async function makePrepareMintTokenParams({
1251
1302
  apiClient,
1252
1303
  tokenId,
1253
1304
  tokenAddress,
1305
+ mintArguments,
1254
1306
  ...rest
1255
1307
  }) {
1256
1308
  const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
1257
1309
  tokenId,
1258
- tokenAddress
1310
+ tokenAddress,
1311
+ saleType: mintArguments.saleType
1259
1312
  });
1260
1313
  if (tokenId === void 0) {
1261
1314
  return makePrepareMint721TokenParams({
1262
1315
  salesConfigAndTokenInfo,
1263
1316
  tokenAddress,
1317
+ mintArguments,
1264
1318
  ...rest
1265
1319
  });
1266
1320
  }
@@ -1268,6 +1322,7 @@ async function makePrepareMintTokenParams({
1268
1322
  salesConfigAndTokenInfo,
1269
1323
  tokenAddress,
1270
1324
  tokenId,
1325
+ mintArguments,
1271
1326
  ...rest
1272
1327
  });
1273
1328
  }
@@ -1300,7 +1355,7 @@ function getMintCosts({
1300
1355
  quantityToMint
1301
1356
  }) {
1302
1357
  const mintFeeForTokens = salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
1303
- const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.fixedPrice.pricePerToken) * quantityToMint;
1358
+ const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.salesConfig.pricePerToken) * quantityToMint;
1304
1359
  return {
1305
1360
  mintFee: mintFeeForTokens,
1306
1361
  tokenPurchaseCost,
@@ -1319,24 +1374,49 @@ async function makePrepareMint1155TokenParams({
1319
1374
  salesConfigAndTokenInfo,
1320
1375
  quantityToMint: mintQuantity
1321
1376
  }).totalCost;
1322
- return makeSimulateContractParamaters({
1323
- abi: import_protocol_deployments6.zoraCreator1155ImplABI,
1324
- functionName: "mintWithRewards",
1325
- account: minterAccount,
1326
- value: mintValue,
1327
- address: tokenAddress,
1328
- /* args: minter, tokenId, quantity, minterArguments, mintReferral */
1329
- args: [
1330
- salesConfigAndTokenInfo?.fixedPrice.address || import_protocol_deployments6.zoraCreatorFixedPriceSaleStrategyAddress[999],
1331
- BigInt(tokenId),
1332
- mintQuantity,
1333
- (0, import_viem5.encodeAbiParameters)((0, import_viem5.parseAbiParameters)("address, string"), [
1334
- mintArguments.mintToAddress,
1335
- mintArguments.mintComment || ""
1336
- ]),
1337
- mintArguments.mintReferral || import_viem5.zeroAddress
1338
- ]
1339
- });
1377
+ switch (salesConfigAndTokenInfo.salesConfig.saleType) {
1378
+ case "fixedPrice":
1379
+ const fixedPriceArgs = mintArguments;
1380
+ return makeSimulateContractParamaters({
1381
+ abi: import_protocol_deployments6.zoraCreator1155ImplABI,
1382
+ functionName: "mintWithRewards",
1383
+ account: minterAccount,
1384
+ value: mintValue,
1385
+ address: tokenAddress,
1386
+ /* args: minter, tokenId, quantity, minterArguments, mintReferral */
1387
+ args: [
1388
+ salesConfigAndTokenInfo.salesConfig.address || import_protocol_deployments6.zoraCreatorFixedPriceSaleStrategyAddress[999999999],
1389
+ BigInt(tokenId),
1390
+ mintQuantity,
1391
+ (0, import_viem5.encodeAbiParameters)((0, import_viem5.parseAbiParameters)("address, string"), [
1392
+ fixedPriceArgs.mintToAddress,
1393
+ fixedPriceArgs.mintComment || ""
1394
+ ]),
1395
+ fixedPriceArgs.mintReferral || import_viem5.zeroAddress
1396
+ ]
1397
+ });
1398
+ case "erc20":
1399
+ const erc20Args = mintArguments;
1400
+ return makeSimulateContractParamaters({
1401
+ abi: import_protocol_deployments6.erc20MinterABI,
1402
+ functionName: "mint",
1403
+ account: minterAccount,
1404
+ address: salesConfigAndTokenInfo?.salesConfig.address || import_protocol_deployments6.erc20MinterAddress[999999999],
1405
+ /* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
1406
+ args: [
1407
+ mintArguments.mintToAddress,
1408
+ mintQuantity,
1409
+ tokenAddress,
1410
+ BigInt(tokenId),
1411
+ salesConfigAndTokenInfo.salesConfig.pricePerToken,
1412
+ salesConfigAndTokenInfo.salesConfig.currency,
1413
+ erc20Args.mintReferral || import_viem5.zeroAddress,
1414
+ erc20Args.mintComment || ""
1415
+ ]
1416
+ });
1417
+ default:
1418
+ throw new MintError("Unsupported sale type");
1419
+ }
1340
1420
  }
1341
1421
 
1342
1422
  // src/create/1155-create-helper.ts