@zoralabs/protocol-sdk 0.5.14 → 0.5.16

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 (37) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +15 -0
  3. package/README.md +42 -2
  4. package/dist/anvil.d.ts +4 -4
  5. package/dist/anvil.d.ts.map +1 -1
  6. package/dist/constants.d.ts +1 -0
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/create/1155-create-helper.d.ts +3 -4
  9. package/dist/create/1155-create-helper.d.ts.map +1 -1
  10. package/dist/index.cjs +534 -375
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.js +517 -356
  13. package/dist/index.js.map +1 -1
  14. package/dist/mint/mint-api-client.d.ts +14 -6
  15. package/dist/mint/mint-api-client.d.ts.map +1 -1
  16. package/dist/mint/mint-client.d.ts +25 -19
  17. package/dist/mint/mint-client.d.ts.map +1 -1
  18. package/dist/mints/mints-contracts.d.ts +688 -3
  19. package/dist/mints/mints-contracts.d.ts.map +1 -1
  20. package/dist/premint/premint-client.d.ts +111 -1465
  21. package/dist/premint/premint-client.d.ts.map +1 -1
  22. package/dist/premint/preminter.d.ts +2 -1
  23. package/dist/premint/preminter.d.ts.map +1 -1
  24. package/dist/utils.d.ts +6872 -1
  25. package/dist/utils.d.ts.map +1 -1
  26. package/package.json +2 -2
  27. package/src/constants.ts +36 -0
  28. package/src/create/1155-create-helper.test.ts +10 -3
  29. package/src/create/1155-create-helper.ts +8 -7
  30. package/src/mint/mint-api-client.ts +107 -45
  31. package/src/mint/mint-client.test.ts +113 -2
  32. package/src/mint/mint-client.ts +95 -53
  33. package/src/premint/premint-client.test.ts +16 -10
  34. package/src/premint/premint-client.ts +566 -374
  35. package/src/premint/preminter.ts +3 -1
  36. package/src/utils.ts +25 -0
  37. package/test-integration/premint-client.test.ts +2 -2
@@ -1,24 +1,32 @@
1
1
  import {
2
2
  Address,
3
3
  Chain,
4
- PublicClient,
5
- createPublicClient,
6
4
  encodeAbiParameters,
7
5
  parseAbiParameters,
8
6
  zeroAddress,
9
- http,
10
7
  Account,
11
8
  SimulateContractParameters,
12
9
  } from "viem";
13
- import { IHttpClient } from "../apis/http-api-base";
14
- import { MintAPIClient, SalesConfigAndTokenInfo } from "./mint-api-client";
15
10
  import {
11
+ erc20MinterABI,
12
+ erc20MinterAddress,
16
13
  zoraCreator1155ImplABI,
17
14
  zoraCreatorFixedPriceSaleStrategyAddress,
18
15
  } from "@zoralabs/protocol-deployments";
19
- import { GenericTokenIdTypes } from "src/types";
16
+ import { IHttpClient } from "src/apis/http-api-base";
20
17
  import { zora721Abi } from "src/constants";
21
- import { makeSimulateContractParamaters } from "src/utils";
18
+ import { GenericTokenIdTypes } from "src/types";
19
+ import {
20
+ MintAPIClient,
21
+ SalesConfigAndTokenInfo,
22
+ SaleType,
23
+ } from "./mint-api-client";
24
+ import {
25
+ makeSimulateContractParamaters,
26
+ ClientConfig,
27
+ setupClient,
28
+ PublicClient,
29
+ } from "src/utils";
22
30
 
23
31
  class MintError extends Error {}
24
32
  class MintInactiveError extends Error {}
@@ -29,10 +37,26 @@ export const Errors = {
29
37
  };
30
38
 
31
39
  type MintArguments = {
40
+ /** Quantity of tokens to mint */
32
41
  quantityToMint: number;
42
+ /** Comment to add to the mint */
33
43
  mintComment?: string;
44
+ /** Optional address to receive the mint referral reward */
34
45
  mintReferral?: Address;
46
+ /** Address to receive the minted tokens */
35
47
  mintToAddress: Address;
48
+ saleType?: SaleType;
49
+ };
50
+
51
+ type MintTokenParams = {
52
+ /** Account to execute the mint */
53
+ minterAccount: Address | Account;
54
+ /** Contract address of token to mint */
55
+ tokenAddress: Address;
56
+ /** Id of token to mint */
57
+ tokenId?: GenericTokenIdTypes;
58
+ /** Mint settings */
59
+ mintArguments: MintArguments;
36
60
  };
37
61
 
38
62
  class MintClient {
@@ -41,31 +65,22 @@ class MintClient {
41
65
 
42
66
  constructor(
43
67
  chain: Chain,
44
- publicClient?: PublicClient,
45
- httpClient?: IHttpClient,
68
+ publicClient: PublicClient,
69
+ httpClient: IHttpClient,
46
70
  ) {
47
71
  this.apiClient = new MintAPIClient(chain.id, httpClient);
48
- this.publicClient =
49
- publicClient || createPublicClient({ chain, transport: http() });
72
+ this.publicClient = publicClient;
50
73
  }
51
74
 
52
75
  /**
53
76
  * Returns the parameters needed to prepare a transaction mint a token.
54
- * @param param0.minterAccount The account that will mint the token.
55
- * @param param0.mintable The mintable token to mint.
56
- * @param param0.mintArguments The arguments for the mint (mint recipient, comment, mint referral, quantity to mint)
57
- * @returns
77
+ *
78
+ * @param parameters - Parameters for collecting the token {@link MintTokenParams}
79
+ * @returns Parameters for simulating/executing the mint transaction
58
80
  */
59
- async makePrepareMintTokenParams({
60
- ...rest
61
- }: {
62
- minterAccount: Address | Account;
63
- tokenAddress: Address;
64
- tokenId?: GenericTokenIdTypes;
65
- mintArguments: MintArguments;
66
- }) {
81
+ async makePrepareMintTokenParams(parameters: MintTokenParams) {
67
82
  return makePrepareMintTokenParams({
68
- ...rest,
83
+ ...parameters,
69
84
  apiClient: this.apiClient,
70
85
  publicClient: this.publicClient,
71
86
  });
@@ -79,15 +94,8 @@ class MintClient {
79
94
  * @param param0.httpClient Optional http client to override post, get, and retry methods
80
95
  * @returns
81
96
  */
82
- export function createMintClient({
83
- chain,
84
- publicClient,
85
- httpClient,
86
- }: {
87
- chain: Chain;
88
- publicClient?: PublicClient;
89
- httpClient?: IHttpClient;
90
- }) {
97
+ export function createMintClient(clientConfig: ClientConfig) {
98
+ const { chain, publicClient, httpClient } = setupClient(clientConfig);
91
99
  return new MintClient(chain, publicClient, httpClient);
92
100
  }
93
101
 
@@ -98,6 +106,7 @@ async function makePrepareMintTokenParams({
98
106
  apiClient,
99
107
  tokenId,
100
108
  tokenAddress,
109
+ mintArguments,
101
110
  ...rest
102
111
  }: {
103
112
  publicClient: PublicClient;
@@ -112,12 +121,14 @@ async function makePrepareMintTokenParams({
112
121
  const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
113
122
  tokenId,
114
123
  tokenAddress,
124
+ saleType: mintArguments.saleType,
115
125
  });
116
126
 
117
127
  if (tokenId === undefined) {
118
128
  return makePrepareMint721TokenParams({
119
129
  salesConfigAndTokenInfo,
120
130
  tokenAddress,
131
+ mintArguments,
121
132
  ...rest,
122
133
  });
123
134
  }
@@ -126,6 +137,7 @@ async function makePrepareMintTokenParams({
126
137
  salesConfigAndTokenInfo,
127
138
  tokenAddress,
128
139
  tokenId,
140
+ mintArguments,
129
141
  ...rest,
130
142
  });
131
143
  }
@@ -177,7 +189,7 @@ export function getMintCosts({
177
189
  const mintFeeForTokens =
178
190
  salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
179
191
  const tokenPurchaseCost =
180
- BigInt(salesConfigAndTokenInfo.fixedPrice.pricePerToken) * quantityToMint;
192
+ BigInt(salesConfigAndTokenInfo.salesConfig.pricePerToken) * quantityToMint;
181
193
 
182
194
  return {
183
195
  mintFee: mintFeeForTokens,
@@ -206,23 +218,53 @@ async function makePrepareMint1155TokenParams({
206
218
  quantityToMint: mintQuantity,
207
219
  }).totalCost;
208
220
 
209
- return makeSimulateContractParamaters({
210
- abi: zoraCreator1155ImplABI,
211
- functionName: "mintWithRewards",
212
- account: minterAccount,
213
- value: mintValue,
214
- address: tokenAddress,
215
- /* args: minter, tokenId, quantity, minterArguments, mintReferral */
216
- args: [
217
- (salesConfigAndTokenInfo?.fixedPrice.address ||
218
- zoraCreatorFixedPriceSaleStrategyAddress[999]) as Address,
219
- BigInt(tokenId),
220
- mintQuantity,
221
- encodeAbiParameters(parseAbiParameters("address, string"), [
222
- mintArguments.mintToAddress,
223
- mintArguments.mintComment || "",
224
- ]),
225
- mintArguments.mintReferral || zeroAddress,
226
- ],
227
- });
221
+ switch (salesConfigAndTokenInfo.salesConfig.saleType) {
222
+ case "fixedPrice":
223
+ const fixedPriceArgs = mintArguments;
224
+
225
+ return makeSimulateContractParamaters({
226
+ abi: zoraCreator1155ImplABI,
227
+ functionName: "mintWithRewards",
228
+ account: minterAccount,
229
+ value: mintValue,
230
+ address: tokenAddress,
231
+ /* args: minter, tokenId, quantity, minterArguments, mintReferral */
232
+ args: [
233
+ (salesConfigAndTokenInfo.salesConfig.address ||
234
+ zoraCreatorFixedPriceSaleStrategyAddress[999999999]) as Address,
235
+ BigInt(tokenId),
236
+ mintQuantity,
237
+ encodeAbiParameters(parseAbiParameters("address, string"), [
238
+ fixedPriceArgs.mintToAddress,
239
+ fixedPriceArgs.mintComment || "",
240
+ ]),
241
+ fixedPriceArgs.mintReferral || zeroAddress,
242
+ ],
243
+ });
244
+
245
+ case "erc20":
246
+ const erc20Args = mintArguments;
247
+
248
+ return makeSimulateContractParamaters({
249
+ abi: erc20MinterABI,
250
+ functionName: "mint",
251
+ account: minterAccount,
252
+ address: (salesConfigAndTokenInfo?.salesConfig.address ||
253
+ erc20MinterAddress[999999999]) as Address,
254
+ /* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
255
+ args: [
256
+ mintArguments.mintToAddress,
257
+ mintQuantity,
258
+ tokenAddress,
259
+ BigInt(tokenId),
260
+ salesConfigAndTokenInfo.salesConfig.pricePerToken,
261
+ salesConfigAndTokenInfo.salesConfig.currency,
262
+ erc20Args.mintReferral || zeroAddress,
263
+ erc20Args.mintComment || "",
264
+ ],
265
+ });
266
+
267
+ default:
268
+ throw new MintError("Unsupported sale type");
269
+ }
228
270
  }
@@ -29,16 +29,13 @@ describe("ZoraCreator1155Premint - v1 signatures", () => {
29
29
  .fn<Parameters<typeof premintClient.apiClient.postSignature>>()
30
30
  .mockResolvedValue({ ok: true });
31
31
 
32
- await premintClient.createPremint({
33
- walletClient,
34
- creatorAccount: deployerAccount!,
35
- checkSignature: true,
32
+ const { signAndSubmit } = await premintClient.createPremint({
33
+ payoutRecipient: deployerAccount!,
36
34
  collection: {
37
35
  contractAdmin: deployerAccount!,
38
36
  contractName: "Testing Contract",
39
37
  contractURI:
40
38
  "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
41
- additionalAdmins: [],
42
39
  },
43
40
  tokenCreationConfig: {
44
41
  tokenURI:
@@ -46,6 +43,12 @@ describe("ZoraCreator1155Premint - v1 signatures", () => {
46
43
  },
47
44
  });
48
45
 
46
+ await signAndSubmit({
47
+ walletClient,
48
+ checkSignature: true,
49
+ account: deployerAccount!,
50
+ });
51
+
49
52
  const expectedPostSignatureArgs: Parameters<
50
53
  typeof premintClient.apiClient.postSignature
51
54
  >[0] = {
@@ -189,16 +192,13 @@ describe("ZoraCreator1155Premint - v2 signatures", () => {
189
192
  .fn<Parameters<typeof premintClient.apiClient.postSignature>>()
190
193
  .mockResolvedValue({ ok: true });
191
194
 
192
- await premintClient.createPremint({
193
- walletClient,
194
- creatorAccount: creatorAccount!,
195
- checkSignature: true,
195
+ const { signAndSubmit } = await premintClient.createPremint({
196
+ payoutRecipient: creatorAccount!,
196
197
  collection: {
197
198
  contractAdmin: creatorAccount!,
198
199
  contractName: "Testing Contract Premint V2",
199
200
  contractURI:
200
201
  "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
201
- additionalAdmins: [],
202
202
  },
203
203
  premintConfigVersion: PremintConfigVersion.V2,
204
204
  tokenCreationConfig: {
@@ -208,6 +208,12 @@ describe("ZoraCreator1155Premint - v2 signatures", () => {
208
208
  },
209
209
  });
210
210
 
211
+ await signAndSubmit({
212
+ account: creatorAccount!,
213
+ walletClient,
214
+ checkSignature: true,
215
+ });
216
+
211
217
  const expectedPostSignatureArgs: Parameters<
212
218
  typeof premintClient.apiClient.postSignature
213
219
  >[0] = {