@zoralabs/protocol-sdk 0.7.0 → 0.7.2-ALLOWLIST.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/allow-list/allow-list-client.d.ts +25 -0
  3. package/dist/allow-list/allow-list-client.d.ts.map +1 -0
  4. package/dist/allow-list/types.d.ts +14 -0
  5. package/dist/allow-list/types.d.ts.map +1 -0
  6. package/dist/apis/generated/allow-list-api-types.d.ts +288 -0
  7. package/dist/apis/generated/allow-list-api-types.d.ts.map +1 -0
  8. package/dist/apis/http-api-base.d.ts.map +1 -1
  9. package/dist/create/1155-create-helper.d.ts +1 -0
  10. package/dist/create/1155-create-helper.d.ts.map +1 -1
  11. package/dist/create/token-setup.d.ts +3 -4
  12. package/dist/create/token-setup.d.ts.map +1 -1
  13. package/dist/create/types.d.ts +24 -4
  14. package/dist/create/types.d.ts.map +1 -1
  15. package/dist/index.cjs +1388 -54
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.ts +3 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1382 -51
  20. package/dist/index.js.map +1 -1
  21. package/dist/ipfs/arweave.d.ts +3 -0
  22. package/dist/ipfs/arweave.d.ts.map +1 -0
  23. package/dist/ipfs/gateway.d.ts +4 -0
  24. package/dist/ipfs/gateway.d.ts.map +1 -0
  25. package/dist/ipfs/index.d.ts +4 -0
  26. package/dist/ipfs/index.d.ts.map +1 -0
  27. package/dist/ipfs/ipfs.d.ts +5 -0
  28. package/dist/ipfs/ipfs.d.ts.map +1 -0
  29. package/dist/ipfs/mimeTypes.d.ts +25 -0
  30. package/dist/ipfs/mimeTypes.d.ts.map +1 -0
  31. package/dist/ipfs/text-metadata.d.ts +5 -0
  32. package/dist/ipfs/text-metadata.d.ts.map +1 -0
  33. package/dist/ipfs/token-metadata.d.ts +14 -0
  34. package/dist/ipfs/token-metadata.d.ts.map +1 -0
  35. package/dist/ipfs/types.d.ts +49 -0
  36. package/dist/ipfs/types.d.ts.map +1 -0
  37. package/dist/mint/mint-queries.d.ts +3 -1
  38. package/dist/mint/mint-queries.d.ts.map +1 -1
  39. package/dist/mint/mint-transactions.d.ts +5 -3
  40. package/dist/mint/mint-transactions.d.ts.map +1 -1
  41. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  42. package/dist/mint/subgraph-queries.d.ts +27 -13
  43. package/dist/mint/subgraph-queries.d.ts.map +1 -1
  44. package/dist/mint/types.d.ts +22 -11
  45. package/dist/mint/types.d.ts.map +1 -1
  46. package/dist/premint/premint-client.d.ts +2 -1
  47. package/dist/premint/premint-client.d.ts.map +1 -1
  48. package/package.json +3 -1
  49. package/src/allow-list/allow-list-client.ts +102 -0
  50. package/src/allow-list/types.ts +15 -0
  51. package/src/apis/generated/allow-list-api-types.ts +288 -0
  52. package/src/apis/http-api-base.ts +12 -0
  53. package/src/create/1155-create-helper.ts +17 -0
  54. package/src/create/token-setup.ts +116 -19
  55. package/src/create/types.ts +32 -4
  56. package/src/index.ts +6 -0
  57. package/src/ipfs/arweave.ts +5 -0
  58. package/src/ipfs/gateway.ts +48 -0
  59. package/src/ipfs/index.ts +7 -0
  60. package/src/ipfs/ipfs.ts +82 -0
  61. package/src/ipfs/mimeTypes.ts +141 -0
  62. package/src/ipfs/text-metadata.ts +128 -0
  63. package/src/ipfs/token-metadata.ts +99 -0
  64. package/src/ipfs/types.ts +54 -0
  65. package/src/mint/mint-queries.ts +6 -0
  66. package/src/mint/mint-transactions.ts +72 -6
  67. package/src/mint/subgraph-mint-getter.ts +12 -3
  68. package/src/mint/subgraph-queries.ts +39 -17
  69. package/src/mint/types.ts +38 -12
  70. package/src/premint/premint-client.ts +9 -1
  71. package/yarn-error.log +8602 -0
  72. package/.turbo/turbo-build.log +0 -15
  73. package/src/create/1155-create-helper.test.ts +0 -325
  74. package/src/mint/mint-client.test.ts +0 -263
  75. package/src/mints/mints-contracts.test.ts +0 -529
  76. package/src/mints/mints-eth-unwrapper-and-caller.test.ts +0 -467
  77. package/src/mints/mints-queries.test.ts +0 -105
  78. package/src/premint/premint-client.test.ts +0 -290
  79. package/src/premint/preminter.test.ts +0 -866
  80. package/test-integration/setup-test-contracts.ts +0 -96
  81. package/tsconfig.build.json +0 -10
  82. package/tsup.config.ts +0 -12
@@ -5,6 +5,7 @@ import {
5
5
  zeroAddress,
6
6
  Account,
7
7
  SimulateContractParameters,
8
+ Hex,
8
9
  } from "viem";
9
10
  import {
10
11
  erc20MinterABI,
@@ -21,6 +22,7 @@ import { MakeMintParametersArgumentsBase } from "./types";
21
22
 
22
23
  import { contractSupportsNewMintFunction } from "./utils";
23
24
  import { OnchainSalesConfigAndTokenInfo } from "./types";
25
+ import { AllowListEntry } from "src/allow-list/types";
24
26
 
25
27
  export function makeOnchainMintCall({
26
28
  token,
@@ -59,6 +61,7 @@ export function makePrepareMint1155TokenParams({
59
61
  mintReferral,
60
62
  mintRecipient,
61
63
  quantityToMint,
64
+ allowListEntry,
62
65
  }: {
63
66
  salesConfigAndTokenInfo: MintableParameters;
64
67
  tokenId: GenericTokenIdTypes;
@@ -70,6 +73,7 @@ export function makePrepareMint1155TokenParams({
70
73
  | "mintReferral"
71
74
  | "quantityToMint"
72
75
  | "mintRecipient"
76
+ | "allowListEntry"
73
77
  >): SimulateContractParameters<any, any, any, any, any, Address | Account> {
74
78
  const mintQuantity = BigInt(quantityToMint || 1);
75
79
 
@@ -77,7 +81,7 @@ export function makePrepareMint1155TokenParams({
77
81
 
78
82
  const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
79
83
 
80
- if (saleType === "fixedPrice") {
84
+ if (saleType === "fixedPrice" || saleType === "allowlist") {
81
85
  return makeEthMintCall({
82
86
  mintComment,
83
87
  minterAccount,
@@ -87,6 +91,7 @@ export function makePrepareMint1155TokenParams({
87
91
  salesConfigAndTokenInfo,
88
92
  tokenContract,
89
93
  tokenId,
94
+ allowListEntry,
90
95
  });
91
96
  }
92
97
 
@@ -137,6 +142,7 @@ function makePrepareMint721TokenParams({
137
142
  mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
138
143
  salesConfig: salesConfigAndTokenInfo.salesConfig,
139
144
  quantityToMint: actualQuantityToMint,
145
+ allowListEntry: undefined,
140
146
  }).totalCostEth;
141
147
 
142
148
  return makeContractParameters({
@@ -154,6 +160,37 @@ function makePrepareMint721TokenParams({
154
160
  });
155
161
  }
156
162
 
163
+ function makeFixedPriceMinterArguments({
164
+ mintTo,
165
+ mintComment,
166
+ }: {
167
+ mintTo: Address;
168
+ mintComment?: string;
169
+ }) {
170
+ return encodeAbiParameters(parseAbiParameters("address, string"), [
171
+ mintTo,
172
+ mintComment || "",
173
+ ]);
174
+ }
175
+
176
+ function makeAllowListMinterArguments({
177
+ mintTo,
178
+ allowListEntry,
179
+ }: {
180
+ mintTo: Address;
181
+ allowListEntry: AllowListEntry;
182
+ }) {
183
+ return encodeAbiParameters(
184
+ parseAbiParameters("address, uint256, uint256, bytes32[]"),
185
+ [
186
+ mintTo,
187
+ BigInt(allowListEntry.maxCanMint),
188
+ allowListEntry.price,
189
+ allowListEntry.proof,
190
+ ],
191
+ );
192
+ }
193
+
157
194
  function makeEthMintCall({
158
195
  tokenContract,
159
196
  tokenId,
@@ -163,6 +200,7 @@ function makeEthMintCall({
163
200
  mintReferral,
164
201
  mintQuantity,
165
202
  mintTo,
203
+ allowListEntry,
166
204
  }: {
167
205
  minterAccount: Account | Address;
168
206
  tokenContract: Address;
@@ -172,17 +210,26 @@ function makeEthMintCall({
172
210
  mintQuantity: bigint;
173
211
  mintComment?: string;
174
212
  mintReferral?: Address;
213
+ allowListEntry?: AllowListEntry;
175
214
  }): SimulateContractParametersWithAccount {
176
215
  const mintValue = parseMintCosts({
177
216
  mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
178
217
  salesConfig: salesConfigAndTokenInfo.salesConfig,
179
218
  quantityToMint: mintQuantity,
219
+ allowListEntry,
180
220
  }).totalCostEth;
181
221
 
182
- const minterArguments = encodeAbiParameters(
183
- parseAbiParameters("address, string"),
184
- [mintTo, mintComment || ""],
185
- );
222
+ const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
223
+ let minterArguments: Hex;
224
+
225
+ if (saleType === "fixedPrice") {
226
+ minterArguments = makeFixedPriceMinterArguments({ mintTo, mintComment });
227
+ } else if (saleType === "allowlist") {
228
+ if (!allowListEntry) throw new Error("Missing allowListEntry");
229
+ minterArguments = makeAllowListMinterArguments({ mintTo, allowListEntry });
230
+ } else {
231
+ throw new Error("Unsupported sale type");
232
+ }
186
233
 
187
234
  // if based on contract version it has the new mint function,
188
235
  // call the new mint function.
@@ -223,18 +270,37 @@ function makeEthMintCall({
223
270
  });
224
271
  }
225
272
 
273
+ function paidMintCost(
274
+ salesConfig: SaleStrategies,
275
+ allowListEntry?: Pick<AllowListEntry, "price">,
276
+ ) {
277
+ if (
278
+ salesConfig.saleType === "erc20" ||
279
+ salesConfig.saleType === "fixedPrice"
280
+ ) {
281
+ return salesConfig.pricePerToken;
282
+ }
283
+
284
+ if (allowListEntry) return allowListEntry.price;
285
+
286
+ return 0n;
287
+ }
288
+
226
289
  export function parseMintCosts({
227
290
  salesConfig,
228
291
  mintFeePerQuantity,
229
292
  quantityToMint,
293
+ allowListEntry,
230
294
  }: {
231
295
  salesConfig: SaleStrategies;
232
296
  mintFeePerQuantity: bigint;
233
297
  quantityToMint: bigint;
298
+ allowListEntry: Pick<AllowListEntry, "price"> | undefined;
234
299
  }): MintCosts {
235
300
  const mintFeeForTokens = mintFeePerQuantity * quantityToMint;
236
301
 
237
- const tokenPurchaseCost = BigInt(salesConfig.pricePerToken) * quantityToMint;
302
+ const tokenPurchaseCost =
303
+ paidMintCost(salesConfig, allowListEntry) * quantityToMint;
238
304
 
239
305
  const totalPurchaseCostCurrency = isErc20SaleStrategy(salesConfig)
240
306
  ? salesConfig.currency
@@ -53,14 +53,23 @@ function parseSalesConfig(
53
53
  pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken),
54
54
  };
55
55
  }
56
+ if (targetStrategy.type === "PRESALE") {
57
+ return {
58
+ saleType: "allowlist",
59
+ address: targetStrategy.presale.address,
60
+ merkleRoot: targetStrategy.presale.merkleRoot,
61
+ saleStart: targetStrategy.presale.presaleStart,
62
+ saleEnd: targetStrategy.presale.presaleEnd,
63
+ };
64
+ }
56
65
 
57
66
  throw new Error("Unknown saleType");
58
67
  }
59
68
 
60
69
  function getSaleEnd(a: SalesStrategyResult) {
61
- return BigInt(
62
- a.type === "ERC_20_MINTER" ? a.erc20Minter.saleEnd : a.fixedPrice.saleEnd,
63
- );
70
+ if (a.type === "FIXED_PRICE") return BigInt(a.fixedPrice.saleEnd);
71
+ if (a.type === "ERC_20_MINTER") return BigInt(a.erc20Minter.saleEnd);
72
+ return BigInt(a.presale.presaleEnd);
64
73
  }
65
74
 
66
75
  function getTargetStrategy({
@@ -2,26 +2,42 @@ import { GenericTokenIdTypes } from "src/types";
2
2
  import { Address } from "viem";
3
3
 
4
4
  export type FixedPriceSaleStrategyResult = {
5
- address: Address;
6
- pricePerToken: string;
7
- saleEnd: string;
8
- saleStart: string;
9
- maxTokensPerAddress: string;
5
+ type: "FIXED_PRICE";
6
+ fixedPrice: {
7
+ address: Address;
8
+ pricePerToken: string;
9
+ saleEnd: string;
10
+ saleStart: string;
11
+ maxTokensPerAddress: string;
12
+ };
10
13
  };
11
14
 
12
- export type ERC20SaleStrategyResult = FixedPriceSaleStrategyResult & {
13
- currency: Address;
15
+ export type ERC20SaleStrategyResult = {
16
+ type: "ERC_20_MINTER";
17
+ erc20Minter: {
18
+ address: Address;
19
+ pricePerToken: string;
20
+ saleEnd: string;
21
+ saleStart: string;
22
+ maxTokensPerAddress: string;
23
+ currency: Address;
24
+ };
25
+ };
26
+
27
+ export type PresaleSalesStrategyResult = {
28
+ type: "PRESALE";
29
+ presale: {
30
+ address: Address;
31
+ presaleStart: string;
32
+ presaleEnd: string;
33
+ merkleRoot: string;
34
+ };
14
35
  };
15
36
 
16
37
  export type SalesStrategyResult =
17
- | {
18
- type: "FIXED_PRICE";
19
- fixedPrice: FixedPriceSaleStrategyResult;
20
- }
21
- | {
22
- type: "ERC_20_MINTER";
23
- erc20Minter: ERC20SaleStrategyResult;
24
- };
38
+ | FixedPriceSaleStrategyResult
39
+ | ERC20SaleStrategyResult
40
+ | PresaleSalesStrategyResult;
25
41
 
26
42
  export type TokenQueryResult = {
27
43
  tokenId?: string;
@@ -59,6 +75,12 @@ fragment SaleStrategy on SalesStrategyConfig {
59
75
  saleStart
60
76
  maxTokensPerAddress
61
77
  }
78
+ presale {
79
+ address
80
+ presaleStart
81
+ presaleEnd
82
+ merkleRoot
83
+ }
62
84
  }`;
63
85
 
64
86
  const TOKEN_FRAGMENT = `
@@ -69,7 +91,7 @@ fragment Token on ZoraCreateToken {
69
91
  totalMinted
70
92
  maxSupply
71
93
  tokenStandard
72
- salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
94
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE"]}) {
73
95
  ...SaleStrategy
74
96
  }
75
97
  contract {
@@ -78,7 +100,7 @@ fragment Token on ZoraCreateToken {
78
100
  contractVersion
79
101
  contractURI
80
102
  name
81
- salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
103
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE"]}) {
82
104
  ...SaleStrategy
83
105
  }
84
106
  }
package/src/mint/types.ts CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  GenericTokenIdTypes,
4
4
  SimulateContractParametersWithAccount,
5
5
  } from "src/types";
6
+ import { AllowListEntry } from "src/allow-list/types";
6
7
 
7
8
  export type MintParameters<MintType> = {
8
9
  /** Type of the collection to be minted. */
@@ -25,7 +26,7 @@ export type PremintMintParameters = MintParameters<"premint"> & {
25
26
  uid: number;
26
27
  };
27
28
 
28
- export type MintType = "1155" | "721" | "premint";
29
+ export type MintType = "1155" | "721" | "allowlist" | "premint";
29
30
 
30
31
  export type MintTypes =
31
32
  | Erc1155MintParameters
@@ -63,6 +64,8 @@ export type MintParametersBase = {
63
64
  mintRecipient?: Address;
64
65
  /** If this is a premint, the address to get the first minter reward */
65
66
  firstMinter?: Address;
67
+ /** If this is an allow list mint, the info for the allow list entry */
68
+ allowListEntry?: AllowListEntry;
66
69
  };
67
70
 
68
71
  export type MakeMintParametersArgumentsBase = MintParametersBase & {
@@ -99,40 +102,60 @@ export type GetMintCostsParameters = {
99
102
  quantityMinted: number | bigint;
100
103
  } & MintTypes;
101
104
 
102
- export type SaleType = "fixedPrice" | "erc20" | "premint";
105
+ export type SaleType = "fixedPrice" | "erc20" | "allowlist" | "premint";
103
106
 
104
107
  type SaleStrategy<T extends SaleType> = {
105
108
  saleType: T;
109
+ };
110
+
111
+ type PricedSaleStrategy = {
106
112
  pricePerToken: bigint;
107
113
  maxTokensPerAddress: bigint;
108
114
  };
109
115
 
110
- type FixedPriceSaleStrategy = SaleStrategy<"fixedPrice"> & {
111
- address: Address;
116
+ export type StartAndEnd = {
112
117
  saleStart: string;
113
118
  saleEnd: string;
114
119
  };
115
120
 
116
- type ERC20SaleStrategy = SaleStrategy<"erc20"> & {
121
+ type FixedPriceSaleStrategy = SaleStrategy<"fixedPrice"> &
122
+ PricedSaleStrategy &
123
+ StartAndEnd & {
124
+ address: Address;
125
+ };
126
+
127
+ type ERC20SaleStrategy = SaleStrategy<"erc20"> &
128
+ PricedSaleStrategy &
129
+ StartAndEnd & {
130
+ address: Address;
131
+ currency: Address;
132
+ };
133
+
134
+ type AllowListSaleStrategy = SaleStrategy<"allowlist"> & {
117
135
  address: Address;
118
136
  saleStart: string;
119
137
  saleEnd: string;
120
- currency: Address;
138
+ merkleRoot: string;
121
139
  };
122
140
 
123
- type PremintSaleStrategy = SaleStrategy<"premint"> & {
124
- duration: bigint;
125
- };
141
+ type PremintSaleStrategy = SaleStrategy<"premint"> &
142
+ PricedSaleStrategy & {
143
+ duration: bigint;
144
+ };
126
145
 
127
146
  export type SaleStrategies =
128
147
  | FixedPriceSaleStrategy
129
148
  | ERC20SaleStrategy
149
+ | AllowListSaleStrategy
130
150
  | PremintSaleStrategy;
131
151
 
132
- export type OnchainSalesStrategies = FixedPriceSaleStrategy | ERC20SaleStrategy;
152
+ export type OnchainSalesStrategies =
153
+ | FixedPriceSaleStrategy
154
+ | ERC20SaleStrategy
155
+ | AllowListSaleStrategy;
133
156
 
134
157
  export function isErc20SaleStrategy(
135
- salesConfig: FixedPriceSaleStrategy | ERC20SaleStrategy | PremintSaleStrategy,
158
+ salesConfig: SaleStrategies,
136
159
  ): salesConfig is ERC20SaleStrategy {
137
160
  return salesConfig.saleType === "erc20";
138
161
  }
@@ -173,7 +196,10 @@ export type PremintMintable = MintableBase & {
173
196
  };
174
197
 
175
198
  export type OnchainSalesConfigAndTokenInfo = {
176
- salesConfig: FixedPriceSaleStrategy | ERC20SaleStrategy;
199
+ salesConfig:
200
+ | FixedPriceSaleStrategy
201
+ | ERC20SaleStrategy
202
+ | AllowListSaleStrategy;
177
203
  } & OnchainMintable;
178
204
 
179
205
  export type PremintSalesConfigAndTokenInfo = {
@@ -65,7 +65,7 @@ type PremintedV2LogType = DecodeEventLogReturnType<
65
65
  "PremintedV2"
66
66
  >["args"];
67
67
 
68
- type URLSReturnType = {
68
+ export type URLSReturnType = {
69
69
  explorer: null | string;
70
70
  zoraCollect: null | string;
71
71
  zoraManage: null | string;
@@ -433,6 +433,7 @@ type PremintReturn<T extends PremintConfigVersion> = {
433
433
  signAndSubmit: (params: SignAndSubmitParams) => Promise<SignAndSubmitReturn>;
434
434
  /** For the case where the premint is signed externally, takes the signature for the Premint, and submits it and the Premint to the Zora Premint API */
435
435
  submit: (params: SubmitParams) => Promise<void>;
436
+ urls: URLSReturnType;
436
437
  } & PremintConfigWithVersion<T>;
437
438
 
438
439
  function makePremintReturn<T extends PremintConfigVersion>({
@@ -503,6 +504,12 @@ function makePremintReturn<T extends PremintConfigVersion>({
503
504
  });
504
505
  };
505
506
 
507
+ const urls = makeUrls({
508
+ chainId,
509
+ address: collectionAddress,
510
+ uid: premintConfig.uid,
511
+ });
512
+
506
513
  return {
507
514
  premintConfig,
508
515
  premintConfigVersion,
@@ -510,6 +517,7 @@ function makePremintReturn<T extends PremintConfigVersion>({
510
517
  collectionAddress,
511
518
  signAndSubmit,
512
519
  submit,
520
+ urls,
513
521
  };
514
522
  }
515
523