@zoralabs/protocol-sdk 0.4.3 → 0.5.1

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.
Files changed (39) hide show
  1. package/.turbo/turbo-build.log +15 -14
  2. package/CHANGELOG.md +28 -1
  3. package/README.md +1 -1
  4. package/dist/anvil.d.ts +6 -2
  5. package/dist/anvil.d.ts.map +1 -1
  6. package/dist/apis/chain-constants.d.ts +4 -12
  7. package/dist/apis/chain-constants.d.ts.map +1 -1
  8. package/dist/index.cjs +55 -66
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.js +58 -71
  11. package/dist/index.js.map +1 -1
  12. package/dist/premint/conversions.d.ts +1 -1
  13. package/dist/premint/conversions.d.ts.map +1 -1
  14. package/dist/premint/premint-client.d.ts +4 -4
  15. package/dist/premint/premint-client.d.ts.map +1 -1
  16. package/dist/premint/preminter.d.ts +3 -3
  17. package/dist/premint/preminter.d.ts.map +1 -1
  18. package/package.json +10 -8
  19. package/src/anvil.ts +10 -3
  20. package/src/apis/chain-constants.ts +31 -32
  21. package/src/mint/mint-client.test.ts +1 -1
  22. package/src/premint/conversions.ts +12 -6
  23. package/src/premint/premint-client.test.ts +14 -64
  24. package/src/premint/premint-client.ts +25 -27
  25. package/src/premint/preminter.test.ts +1 -1
  26. package/src/premint/preminter.ts +9 -23
  27. package/test-integration/premint-client.test.ts +146 -0
  28. package/tsconfig.build.json +10 -0
  29. package/tsconfig.json +1 -1
  30. package/tsup.config.js +2 -1
  31. package/.turbo/turbo-lint.log +0 -5
  32. package/dist/create/1155-create-helper.test.d.ts +0 -2
  33. package/dist/create/1155-create-helper.test.d.ts.map +0 -1
  34. package/dist/mint/mint-client.test.d.ts +0 -2
  35. package/dist/mint/mint-client.test.d.ts.map +0 -1
  36. package/dist/premint/premint-client.test.d.ts +0 -2
  37. package/dist/premint/premint-client.test.d.ts.map +0 -1
  38. package/dist/premint/preminter.test.d.ts +0 -2
  39. package/dist/premint/preminter.test.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,15 +1,13 @@
1
1
  // src/premint/premint-client.ts
2
2
  import { createPublicClient, decodeEventLog, http, zeroAddress as zeroAddress2 } from "viem";
3
- import {
4
- zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2,
5
- zoraCreatorFixedPriceSaleStrategyAddress
6
- } from "@zoralabs/protocol-deployments";
3
+ import { zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2 } from "@zoralabs/protocol-deployments";
7
4
 
8
5
  // src/premint/preminter.ts
9
6
  import {
10
7
  zoraCreator1155PremintExecutorImplABI as preminterAbi,
11
8
  zoraCreator1155PremintExecutorImplABI,
12
- zoraCreator1155PremintExecutorImplAddress
9
+ zoraCreator1155PremintExecutorImplAddress,
10
+ zoraCreatorFixedPriceSaleStrategyAddress
13
11
  } from "@zoralabs/protocol-deployments";
14
12
  import {
15
13
  recoverTypedDataAddress,
@@ -112,20 +110,8 @@ async function isAuthorizedToCreatePremint({
112
110
  collection,
113
111
  collectionAddress,
114
112
  publicClient,
115
- premintConfig,
116
- premintConfigVersion,
117
- signature,
118
113
  signer
119
114
  }) {
120
- if (premintConfigVersion === "1" /* V1 */) {
121
- const [isValidSignature2] = await publicClient.readContract({
122
- abi: zoraCreator1155PremintExecutorImplABI,
123
- address: getPremintExecutorAddress(),
124
- functionName: "isValidSignature",
125
- args: [collection, premintConfig, signature]
126
- });
127
- return isValidSignature2;
128
- }
129
115
  return await publicClient.readContract({
130
116
  abi: preminterAbi,
131
117
  address: getPremintExecutorAddress(),
@@ -177,9 +163,7 @@ async function isValidSignature({
177
163
  signer: recoveredAddress,
178
164
  collection,
179
165
  collectionAddress: tokenContract,
180
- publicClient,
181
- signature,
182
- ...premintConfigAndVersion
166
+ publicClient
183
167
  });
184
168
  return {
185
169
  isAuthorized,
@@ -340,6 +324,9 @@ function makeMintRewardsRecipient({
340
324
  }) {
341
325
  return [mintReferral, platformReferral];
342
326
  }
327
+ function getDefaultFixedPriceMinterAddress(chainId) {
328
+ return zoraCreatorFixedPriceSaleStrategyAddress[chainId];
329
+ }
343
330
 
344
331
  // src/apis/http-api-base.ts
345
332
  var BadResponseError = class extends Error {
@@ -438,82 +425,80 @@ import {
438
425
  optimism,
439
426
  optimismGoerli,
440
427
  zora,
428
+ zoraSepolia,
441
429
  zoraTestnet
442
430
  } from "viem/chains";
443
431
  import { parseEther as parseEther2 } from "viem";
444
432
  var REWARD_PER_TOKEN = parseEther2("0.000777");
445
- var BackendChainNamesLookup = {
446
- ZORA_MAINNET: "ZORA-MAINNET",
447
- ZORA_GOERLI: "ZORA-GOERLI",
448
- OPTIMISM_MAINNET: "OPTIMISM-MAINNET",
449
- OPTIMISM_GOERLI: "OPTIMISM-GOERLI",
450
- ETHEREUM_MAINNET: "ETHEREUM-MAINNET",
451
- ETHEREUM_GOERLI: "ETHEREUM-GOERLI",
452
- BASE_MAINNET: "BASE-MAINNET",
453
- BASE_GOERLI: "BASE-GOERLI"
454
- };
455
433
  var networkConfigByChain = {
456
434
  [mainnet.id]: {
457
435
  chainId: mainnet.id,
458
436
  isTestnet: false,
459
- zoraPathChainName: "eth",
460
- zoraBackendChainName: BackendChainNamesLookup.ETHEREUM_MAINNET,
437
+ zoraCollectPathChainName: "eth",
438
+ zoraBackendChainName: "ETHEREUM-MAINNET",
461
439
  subgraphUrl: getSubgraph("zora-create-mainnet", "stable")
462
440
  },
463
441
  [goerli.id]: {
464
442
  chainId: goerli.id,
465
443
  isTestnet: true,
466
- zoraPathChainName: "gor",
467
- zoraBackendChainName: BackendChainNamesLookup.ETHEREUM_GOERLI,
444
+ zoraCollectPathChainName: "gor",
445
+ zoraBackendChainName: "ETHEREUM-GOERLI",
468
446
  subgraphUrl: getSubgraph("zora-create-goerli", "stable")
469
447
  },
470
448
  [zora.id]: {
471
449
  chainId: zora.id,
472
450
  isTestnet: false,
473
- zoraPathChainName: "zora",
474
- zoraBackendChainName: BackendChainNamesLookup.ZORA_MAINNET,
451
+ zoraCollectPathChainName: "zora",
452
+ zoraBackendChainName: "ZORA-MAINNET",
475
453
  subgraphUrl: getSubgraph("zora-create-zora-mainnet", "stable")
476
454
  },
477
455
  [zoraTestnet.id]: {
478
- chainId: zora.id,
456
+ chainId: zoraTestnet.id,
479
457
  isTestnet: true,
480
- zoraPathChainName: "zgor",
481
- zoraBackendChainName: BackendChainNamesLookup.ZORA_GOERLI,
458
+ zoraCollectPathChainName: "zgor",
459
+ zoraBackendChainName: "ZORA-GOERLI",
482
460
  subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
483
461
  },
462
+ [zoraSepolia.id]: {
463
+ chainId: zoraSepolia.id,
464
+ isTestnet: true,
465
+ zoraCollectPathChainName: "zsep",
466
+ zoraBackendChainName: "ZORA-SEPOLIA",
467
+ subgraphUrl: getSubgraph("zora-create-zora-sepolia", "stable")
468
+ },
484
469
  [optimism.id]: {
485
470
  chainId: optimism.id,
486
471
  isTestnet: false,
487
- zoraPathChainName: "opt",
488
- zoraBackendChainName: BackendChainNamesLookup.OPTIMISM_MAINNET,
472
+ zoraCollectPathChainName: "opt",
473
+ zoraBackendChainName: "OPTIMISM-MAINNET",
489
474
  subgraphUrl: getSubgraph("zora-create-optimism", "stable")
490
475
  },
491
476
  [optimismGoerli.id]: {
492
477
  chainId: optimismGoerli.id,
493
478
  isTestnet: true,
494
- zoraPathChainName: "ogor",
495
- zoraBackendChainName: BackendChainNamesLookup.OPTIMISM_GOERLI,
479
+ zoraCollectPathChainName: "ogor",
480
+ zoraBackendChainName: "OPTIMISM-GOERLI",
496
481
  subgraphUrl: getSubgraph("zora-create-optimism-goerli", "stable")
497
482
  },
498
483
  [base.id]: {
499
484
  chainId: base.id,
500
485
  isTestnet: false,
501
- zoraPathChainName: "base",
502
- zoraBackendChainName: BackendChainNamesLookup.BASE_MAINNET,
486
+ zoraCollectPathChainName: "base",
487
+ zoraBackendChainName: "BASE-MAINNET",
503
488
  subgraphUrl: getSubgraph("zora-create-base-mainnet", "stable")
504
489
  },
505
490
  [baseGoerli.id]: {
506
491
  chainId: baseGoerli.id,
507
492
  isTestnet: true,
508
- zoraPathChainName: "bgor",
509
- zoraBackendChainName: BackendChainNamesLookup.BASE_GOERLI,
493
+ zoraCollectPathChainName: "bgor",
494
+ zoraBackendChainName: "BASE-GOERLI",
510
495
  subgraphUrl: getSubgraph("zora-create-base-goerli", "stable")
511
496
  },
512
497
  [foundry.id]: {
513
498
  chainId: foundry.id,
514
499
  isTestnet: true,
515
- zoraPathChainName: "zgor",
516
- zoraBackendChainName: BackendChainNamesLookup.ZORA_GOERLI,
500
+ zoraCollectPathChainName: "zgor",
501
+ zoraBackendChainName: "ZORA-GOERLI",
517
502
  subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
518
503
  }
519
504
  };
@@ -601,7 +586,9 @@ var convertPremintFromApi = (premint) => {
601
586
  return {
602
587
  premintConfigVersion: "1" /* V1 */,
603
588
  premintConfig: {
604
- ...premint,
589
+ deleted: premint.deleted,
590
+ uid: premint.uid,
591
+ version: premint.version,
605
592
  tokenConfig: {
606
593
  ...tokenConfig,
607
594
  fixedPriceMinter: tokenConfig.fixedPriceMinter,
@@ -619,7 +606,9 @@ var convertPremintFromApi = (premint) => {
619
606
  return {
620
607
  premintConfigVersion: "2" /* V2 */,
621
608
  premintConfig: {
622
- ...premint,
609
+ deleted: premint.deleted,
610
+ uid: premint.uid,
611
+ version: premint.version,
623
612
  tokenConfig: {
624
613
  ...tokenConfig,
625
614
  fixedPriceMinter: tokenConfig.fixedPriceMinter,
@@ -645,6 +634,7 @@ var encodePremintV1ForAPI = ({
645
634
  ...premint
646
635
  }) => ({
647
636
  ...premint,
637
+ config_version: "1",
648
638
  tokenConfig: {
649
639
  ...tokenConfig,
650
640
  maxSupply: tokenConfig.maxSupply.toString(),
@@ -659,6 +649,7 @@ var encodePremintV2ForAPI = ({
659
649
  ...premint
660
650
  }) => ({
661
651
  ...premint,
652
+ config_version: "2",
662
653
  tokenConfig: {
663
654
  ...tokenConfig,
664
655
  maxSupply: tokenConfig.maxSupply.toString(),
@@ -788,11 +779,12 @@ var defaultTokenConfigV2MintArguments = () => ({
788
779
  // 10%,
789
780
  });
790
781
  var makeTokenConfigWithDefaults = ({
782
+ chainId,
791
783
  premintConfigVersion,
792
784
  tokenCreationConfig,
793
785
  creatorAccount
794
786
  }) => {
795
- const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress();
787
+ const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress(chainId);
796
788
  if (premintConfigVersion === "1" /* V1 */) {
797
789
  return {
798
790
  fixedPriceMinter,
@@ -994,7 +986,8 @@ var PremintClient = class {
994
986
  tokenConfig: makeTokenConfigWithDefaults({
995
987
  premintConfigVersion: actualVersion,
996
988
  tokenCreationConfig,
997
- creatorAccount
989
+ creatorAccount,
990
+ chainId: this.chain.id
998
991
  }),
999
992
  uid: uidToUse
1000
993
  });
@@ -1072,13 +1065,13 @@ var PremintClient = class {
1072
1065
  async getMintCosts({
1073
1066
  tokenContract,
1074
1067
  quantityToMint,
1075
- tokenCreationConfig
1068
+ pricePerToken
1076
1069
  }) {
1077
1070
  return await getPremintMintCosts({
1078
1071
  publicClient: this.publicClient,
1079
1072
  quantityToMint,
1080
1073
  tokenContract,
1081
- tokenPrice: tokenCreationConfig.pricePerToken
1074
+ tokenPrice: pricePerToken
1082
1075
  });
1083
1076
  }
1084
1077
  /**
@@ -1096,13 +1089,13 @@ var PremintClient = class {
1096
1089
  async makeMintParameters({
1097
1090
  uid,
1098
1091
  tokenContract,
1099
- account,
1092
+ minterAccount,
1100
1093
  mintArguments
1101
1094
  }) {
1102
1095
  if (mintArguments && mintArguments?.quantityToMint < 1) {
1103
1096
  throw new Error("Quantity to mint cannot be below 1");
1104
1097
  }
1105
- if (!account) {
1098
+ if (!minterAccount) {
1106
1099
  throw new Error("Wallet not passed in");
1107
1100
  }
1108
1101
  const { premintConfig, premintConfigVersion, collection, signature } = await this.getPremintSignature({
@@ -1118,7 +1111,7 @@ var PremintClient = class {
1118
1111
  })).totalCost;
1119
1112
  const mintArgumentsContract = {
1120
1113
  mintComment: mintArguments?.mintComment || "",
1121
- mintRecipient: mintArguments?.mintRecipient || (typeof account === "string" ? account : account.address),
1114
+ mintRecipient: mintArguments?.mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address),
1122
1115
  mintRewardsRecipients: makeMintRewardsRecipient({
1123
1116
  mintReferral: mintArguments?.mintReferral,
1124
1117
  platformReferral: mintArguments?.platformReferral
@@ -1126,7 +1119,7 @@ var PremintClient = class {
1126
1119
  };
1127
1120
  if (premintConfigVersion === "1" /* V1 */) {
1128
1121
  return {
1129
- account,
1122
+ account: minterAccount,
1130
1123
  abi: zoraCreator1155PremintExecutorImplABI2,
1131
1124
  functionName: "premintV1",
1132
1125
  value,
@@ -1140,17 +1133,15 @@ var PremintClient = class {
1140
1133
  ]
1141
1134
  };
1142
1135
  } else if (premintConfigVersion === "2" /* V2 */) {
1143
- const toPost = premintConfig;
1144
1136
  return {
1145
- account,
1137
+ account: minterAccount,
1146
1138
  abi: zoraCreator1155PremintExecutorImplABI2,
1147
1139
  functionName: "premintV2",
1148
1140
  value,
1149
1141
  address: getPremintExecutorAddress(),
1150
- // args are: ContractCreationConfig calldata contractConfig, PremintConfigV2 calldata premintConfig, bytes calldata signature, uint256 quantityToMint, MintArguments calldata mintArguments
1151
1142
  args: [
1152
1143
  collection,
1153
- toPost,
1144
+ premintConfig,
1154
1145
  signature,
1155
1146
  numberToMint,
1156
1147
  mintArgumentsContract
@@ -1180,8 +1171,8 @@ function makeUrls({
1180
1171
  const network = getApiNetworkConfigForChain(chain.id);
1181
1172
  return {
1182
1173
  explorer: tokenId ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
1183
- zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`,
1184
- zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraPathChainName}:${address}/${zoraTokenPath}`
1174
+ zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`,
1175
+ zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
1185
1176
  };
1186
1177
  }
1187
1178
  async function signAndSubmitPremint({
@@ -1212,14 +1203,12 @@ async function signAndSubmitPremint({
1212
1203
  if (checkSignature) {
1213
1204
  const isAuthorized = await isAuthorizedToCreatePremint({
1214
1205
  collection,
1215
- signature,
1216
1206
  publicClient,
1217
1207
  signer: typeof account === "string" ? account : account.address,
1218
1208
  collectionAddress: await getPremintCollectionAddress({
1219
1209
  collection,
1220
1210
  publicClient
1221
- }),
1222
- ...premintConfigAndVersion
1211
+ })
1223
1212
  });
1224
1213
  if (!isAuthorized) {
1225
1214
  throw new Error("Not authorized to create premint");
@@ -1232,9 +1221,6 @@ async function signAndSubmitPremint({
1232
1221
  });
1233
1222
  return { premint, verifyingContract };
1234
1223
  }
1235
- function getDefaultFixedPriceMinterAddress() {
1236
- return zoraCreatorFixedPriceSaleStrategyAddress[999];
1237
- }
1238
1224
 
1239
1225
  // src/mint/mint-client.ts
1240
1226
  import {
@@ -1652,6 +1638,7 @@ export {
1652
1638
  encodePostSignatureInput,
1653
1639
  encodePremintForAPI,
1654
1640
  getApiNetworkConfigForChain,
1641
+ getDefaultFixedPriceMinterAddress,
1655
1642
  getMintCosts,
1656
1643
  getPremintCollectionAddress,
1657
1644
  getPremintExecutorAddress,