@zoralabs/protocol-sdk 0.5.17 → 0.6.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 (63) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +13 -0
  3. package/README.md +1 -416
  4. package/dist/create/1155-create-helper.d.ts +16 -55
  5. package/dist/create/1155-create-helper.d.ts.map +1 -1
  6. package/dist/create/contract-setup.d.ts +14 -0
  7. package/dist/create/contract-setup.d.ts.map +1 -0
  8. package/dist/create/token-setup.d.ts +27 -0
  9. package/dist/create/token-setup.d.ts.map +1 -0
  10. package/dist/create/types.d.ts +45 -0
  11. package/dist/create/types.d.ts.map +1 -0
  12. package/dist/index.cjs +1273 -857
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +3 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1233 -831
  17. package/dist/index.js.map +1 -1
  18. package/dist/mint/mint-client.d.ts +4083 -43
  19. package/dist/mint/mint-client.d.ts.map +1 -1
  20. package/dist/mint/subgraph-mint-getter.d.ts +17 -0
  21. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -0
  22. package/dist/mint/types.d.ts +79 -0
  23. package/dist/mint/types.d.ts.map +1 -0
  24. package/dist/mints/mints-contracts.d.ts +24 -24
  25. package/dist/premint/contract-types.d.ts +4 -4
  26. package/dist/premint/contract-types.d.ts.map +1 -1
  27. package/dist/premint/conversions.d.ts +3 -1
  28. package/dist/premint/conversions.d.ts.map +1 -1
  29. package/dist/premint/premint-api-client.d.ts +27 -14
  30. package/dist/premint/premint-api-client.d.ts.map +1 -1
  31. package/dist/premint/premint-client.d.ts +62 -46
  32. package/dist/premint/premint-client.d.ts.map +1 -1
  33. package/dist/premint/preminter.d.ts +19 -7
  34. package/dist/premint/preminter.d.ts.map +1 -1
  35. package/dist/sdk.d.ts +43 -0
  36. package/dist/sdk.d.ts.map +1 -0
  37. package/dist/utils.d.ts +17 -6870
  38. package/dist/utils.d.ts.map +1 -1
  39. package/package.json +3 -2
  40. package/src/create/1155-create-helper.test.ts +235 -56
  41. package/src/create/1155-create-helper.ts +141 -309
  42. package/src/create/contract-setup.ts +88 -0
  43. package/src/create/token-setup.ts +379 -0
  44. package/src/create/types.ts +57 -0
  45. package/src/index.ts +5 -1
  46. package/src/mint/mint-client.test.ts +50 -61
  47. package/src/mint/mint-client.ts +321 -157
  48. package/src/mint/{mint-api-client.ts → subgraph-mint-getter.ts} +2 -25
  49. package/src/mint/types.ts +122 -0
  50. package/src/mints/mints-contracts.test.ts +1 -1
  51. package/src/mints/mints-contracts.ts +4 -4
  52. package/src/premint/contract-types.ts +4 -4
  53. package/src/premint/conversions.ts +12 -2
  54. package/src/premint/premint-api-client.ts +55 -43
  55. package/src/premint/premint-client.test.ts +75 -65
  56. package/src/premint/premint-client.ts +126 -153
  57. package/src/premint/preminter.test.ts +4 -5
  58. package/src/premint/preminter.ts +63 -13
  59. package/src/sdk.ts +98 -0
  60. package/src/utils.ts +30 -23
  61. package/test-integration/premint-client.test.ts +8 -8
  62. package/dist/mint/mint-api-client.d.ts +0 -35
  63. package/dist/mint/mint-api-client.d.ts.map +0 -1
@@ -0,0 +1,379 @@
1
+ import {
2
+ erc20MinterABI,
3
+ erc20MinterAddress as erc20MinterAddresses,
4
+ zoraCreator1155ImplABI,
5
+ zoraCreatorFixedPriceSaleStrategyABI,
6
+ zoraCreatorFixedPriceSaleStrategyAddress,
7
+ } from "@zoralabs/protocol-deployments";
8
+ import { Address, encodeFunctionData, zeroAddress, Hex } from "viem";
9
+ import * as semver from "semver";
10
+ import {
11
+ ContractProps,
12
+ CreateNew1155TokenProps,
13
+ New1155Token,
14
+ SalesConfigParamsType,
15
+ } from "./types";
16
+ import { OPEN_EDITION_MINT_SIZE } from "src/constants";
17
+ import { Concrete } from "src/utils";
18
+
19
+ export const PERMISSION_BITS = {
20
+ MINTER: 2n ** 2n,
21
+ };
22
+
23
+ type SetupMintersProps = {
24
+ tokenId: bigint;
25
+ chainId: number;
26
+ fundsRecipient: Address;
27
+ salesConfig: Concrete<SalesConfigParamsType>;
28
+ };
29
+
30
+ // Sales end forever amount (uint64 max)
31
+
32
+ const saleSettingsOrDefault = (
33
+ saleSettings?: SalesConfigParamsType,
34
+ ): Concrete<SalesConfigParamsType> => {
35
+ const SALE_END_FOREVER = 18446744073709551615n;
36
+
37
+ const DEFAULT_SALE_SETTINGS: Concrete<SalesConfigParamsType> = {
38
+ currency: zeroAddress,
39
+ // Free Mint
40
+ pricePerToken: 0n,
41
+ // Sale start time – defaults to beginning of unix time
42
+ saleStart: 0n,
43
+ // This is the end of uint64, plenty of time
44
+ saleEnd: SALE_END_FOREVER,
45
+ // 0 Here means no limit
46
+ maxTokensPerAddress: 0n,
47
+ };
48
+ return {
49
+ ...DEFAULT_SALE_SETTINGS,
50
+ ...saleSettings,
51
+ };
52
+ };
53
+
54
+ function applyNew1155Defaults(
55
+ props: CreateNew1155TokenProps,
56
+ ownerAddress: Address,
57
+ ): New1155Token {
58
+ const { payoutRecipient: fundsRecipient } = props;
59
+ const fundsRecipientOrOwner =
60
+ fundsRecipient && fundsRecipient !== zeroAddress
61
+ ? fundsRecipient
62
+ : ownerAddress;
63
+ return {
64
+ payoutRecipient: fundsRecipientOrOwner,
65
+ createReferral: props.createReferral || zeroAddress,
66
+ maxSupply:
67
+ typeof props.maxSupply === "undefined"
68
+ ? OPEN_EDITION_MINT_SIZE
69
+ : BigInt(props.maxSupply),
70
+ royaltyBPS: props.royaltyBPS || 1000,
71
+ salesConfig: saleSettingsOrDefault(props.salesConfig),
72
+ tokenMetadataURI: props.tokenMetadataURI,
73
+ };
74
+ }
75
+
76
+ type SetupErc20MinterProps = {
77
+ chainId: number;
78
+ tokenId: bigint;
79
+ fundsRecipient: Address;
80
+ } & Concrete<SalesConfigParamsType>;
81
+
82
+ function setupErc20Minter({
83
+ pricePerToken,
84
+ chainId,
85
+ tokenId: nextTokenId,
86
+ currency,
87
+ saleStart,
88
+ saleEnd,
89
+ maxTokensPerAddress: mintLimit,
90
+ fundsRecipient,
91
+ }: SetupErc20MinterProps): {
92
+ minter: Address;
93
+ setupActions: Hex[];
94
+ } {
95
+ const erc20MinterAddress =
96
+ erc20MinterAddresses[chainId as keyof typeof erc20MinterAddresses];
97
+ if (!erc20MinterAddress)
98
+ throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
99
+
100
+ const erc20MinterApproval = encodeFunctionData({
101
+ abi: zoraCreator1155ImplABI,
102
+ functionName: "addPermission",
103
+ args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER],
104
+ });
105
+
106
+ const saleData = encodeFunctionData({
107
+ abi: erc20MinterABI,
108
+ functionName: "setSale",
109
+ args: [
110
+ BigInt(nextTokenId),
111
+ {
112
+ saleStart: saleStart || BigInt(0),
113
+ saleEnd: saleEnd || BigInt(0),
114
+ maxTokensPerAddress: BigInt(mintLimit || 0),
115
+ pricePerToken: pricePerToken,
116
+ fundsRecipient,
117
+ currency: currency,
118
+ },
119
+ ],
120
+ });
121
+
122
+ const callSale = encodeFunctionData({
123
+ abi: zoraCreator1155ImplABI,
124
+ functionName: "callSale",
125
+ args: [BigInt(nextTokenId), erc20MinterAddress, saleData],
126
+ });
127
+
128
+ return {
129
+ minter: erc20MinterAddress,
130
+ setupActions: [erc20MinterApproval, callSale],
131
+ };
132
+ }
133
+
134
+ type SetupFixedPriceMinterProps = {
135
+ fundsRecipient: Address;
136
+ tokenId: bigint;
137
+ chainId: number;
138
+ } & Concrete<Omit<SalesConfigParamsType, "currency">>;
139
+
140
+ function setupFixedPriceMinter({
141
+ pricePerToken: price,
142
+ tokenId: nextTokenId,
143
+ chainId,
144
+ saleStart,
145
+ saleEnd,
146
+ maxTokensPerAddress: mintLimit,
147
+ fundsRecipient,
148
+ }: SetupFixedPriceMinterProps): { minter: Address; setupActions: Hex[] } {
149
+ const fixedPriceStrategyAddress =
150
+ zoraCreatorFixedPriceSaleStrategyAddress[
151
+ chainId as keyof typeof zoraCreatorFixedPriceSaleStrategyAddress
152
+ ];
153
+ const fixedPriceApproval = encodeFunctionData({
154
+ abi: zoraCreator1155ImplABI,
155
+ functionName: "addPermission",
156
+ args: [
157
+ BigInt(nextTokenId),
158
+ fixedPriceStrategyAddress,
159
+ PERMISSION_BITS.MINTER,
160
+ ],
161
+ });
162
+
163
+ const saleData = encodeFunctionData({
164
+ abi: zoraCreatorFixedPriceSaleStrategyABI,
165
+ functionName: "setSale",
166
+ args: [
167
+ BigInt(nextTokenId),
168
+ {
169
+ pricePerToken: price,
170
+ saleStart: saleStart || BigInt(0),
171
+ saleEnd: saleEnd || BigInt(0),
172
+ maxTokensPerAddress: BigInt(mintLimit || 0),
173
+ fundsRecipient,
174
+ },
175
+ ],
176
+ });
177
+
178
+ const callSale = encodeFunctionData({
179
+ abi: zoraCreator1155ImplABI,
180
+ functionName: "callSale",
181
+ args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData],
182
+ });
183
+
184
+ return {
185
+ minter: fixedPriceStrategyAddress,
186
+ setupActions: [fixedPriceApproval, callSale],
187
+ };
188
+ }
189
+
190
+ export function setupMinters({ salesConfig, ...rest }: SetupMintersProps): {
191
+ minter: Address;
192
+ setupActions: Hex[];
193
+ } {
194
+ if (!salesConfig) throw new Error("No sales config for token");
195
+ const { currency: currencyAddress } = salesConfig;
196
+
197
+ if (currencyAddress === zeroAddress) {
198
+ return setupFixedPriceMinter({
199
+ ...salesConfig,
200
+ ...rest,
201
+ });
202
+ } else {
203
+ return setupErc20Minter({
204
+ ...salesConfig,
205
+ ...rest,
206
+ });
207
+ }
208
+ }
209
+
210
+ function buildSetupNewToken({
211
+ tokenURI,
212
+ maxSupply = OPEN_EDITION_MINT_SIZE,
213
+ createReferral = zeroAddress,
214
+ contractVersion,
215
+ }: {
216
+ tokenURI: string;
217
+ maxSupply: bigint;
218
+ createReferral: Address;
219
+ contractVersion?: string;
220
+ }): Hex {
221
+ // If we're adding a new token to an existing contract which doesn't support
222
+ // creator rewards, we won't have the 'setupNewTokenWithCreateReferral' method
223
+ // available, so we need to check for that and use the fallback method instead.
224
+ if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
225
+ return encodeFunctionData({
226
+ abi: zoraCreator1155ImplABI,
227
+ functionName: "setupNewTokenWithCreateReferral",
228
+ args: [tokenURI, BigInt(maxSupply), createReferral],
229
+ });
230
+ }
231
+
232
+ if (createReferral !== zeroAddress) {
233
+ throw new Error(
234
+ "Contract does not support create referral, but one was provided",
235
+ );
236
+ }
237
+ return encodeFunctionData({
238
+ abi: zoraCreator1155ImplABI,
239
+ functionName: "setupNewToken",
240
+ args: [tokenURI, BigInt(maxSupply)],
241
+ });
242
+ }
243
+
244
+ function setupRoyaltyConfig({
245
+ royaltyBPS,
246
+ royaltyRecipient,
247
+ nextTokenId,
248
+ }: {
249
+ royaltyBPS: number;
250
+ royaltyRecipient: Address;
251
+ nextTokenId: bigint;
252
+ }) {
253
+ if (royaltyBPS > 0 && royaltyRecipient != zeroAddress) {
254
+ return encodeFunctionData({
255
+ abi: zoraCreator1155ImplABI,
256
+ functionName: "updateRoyaltiesForToken",
257
+ args: [
258
+ nextTokenId,
259
+ {
260
+ royaltyBPS,
261
+ royaltyRecipient,
262
+ royaltyMintSchedule: 0,
263
+ },
264
+ ],
265
+ });
266
+ }
267
+
268
+ return null;
269
+ }
270
+
271
+ function makeAdminMintCall({
272
+ ownerAddress,
273
+ mintQuantity,
274
+ nextTokenId,
275
+ }: {
276
+ ownerAddress: Address;
277
+ mintQuantity?: number;
278
+ nextTokenId: bigint;
279
+ }) {
280
+ if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
281
+ return null;
282
+ }
283
+
284
+ return encodeFunctionData({
285
+ abi: zoraCreator1155ImplABI,
286
+ functionName: "adminMint",
287
+ args: [ownerAddress, nextTokenId, BigInt(mintQuantity), zeroAddress],
288
+ });
289
+ }
290
+
291
+ export function constructCreate1155TokenCalls(
292
+ props: CreateNew1155TokenProps &
293
+ ContractProps & {
294
+ ownerAddress: Address;
295
+ chainId: number;
296
+ },
297
+ ): {
298
+ setupActions: `0x${string}`[];
299
+ newToken: New1155Token;
300
+ minter: Address;
301
+ } {
302
+ const {
303
+ chainId,
304
+ nextTokenId,
305
+ mintToCreatorCount,
306
+ ownerAddress,
307
+ contractVersion,
308
+ } = props;
309
+
310
+ const new1155TokenPropsWithDefaults = applyNew1155Defaults(
311
+ props,
312
+ ownerAddress,
313
+ );
314
+
315
+ const verifyTokenIdExpected = encodeFunctionData({
316
+ abi: zoraCreator1155ImplABI,
317
+ functionName: "assumeLastTokenIdMatches",
318
+ args: [nextTokenId - 1n],
319
+ });
320
+
321
+ const setupNewToken = buildSetupNewToken({
322
+ tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
323
+ maxSupply: new1155TokenPropsWithDefaults.maxSupply,
324
+ createReferral: new1155TokenPropsWithDefaults.createReferral,
325
+ contractVersion,
326
+ });
327
+
328
+ const royaltyConfig = setupRoyaltyConfig({
329
+ royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
330
+ royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
331
+ nextTokenId,
332
+ });
333
+
334
+ const { minter, setupActions: mintersSetup } = setupMinters({
335
+ tokenId: nextTokenId,
336
+ chainId,
337
+ fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
338
+ salesConfig: new1155TokenPropsWithDefaults.salesConfig,
339
+ });
340
+
341
+ const adminMintCall = makeAdminMintCall({
342
+ ownerAddress,
343
+ mintQuantity: mintToCreatorCount,
344
+ nextTokenId,
345
+ });
346
+
347
+ const setupActions = [
348
+ verifyTokenIdExpected,
349
+ setupNewToken,
350
+ ...mintersSetup,
351
+ royaltyConfig,
352
+ adminMintCall,
353
+ ].filter((item) => item !== null) as `0x${string}`[];
354
+
355
+ return {
356
+ setupActions,
357
+ minter,
358
+ newToken: new1155TokenPropsWithDefaults,
359
+ };
360
+ }
361
+
362
+ export const contractSupportsMintRewards = (
363
+ contractVersion?: string | null,
364
+ contractStandard?: "ERC721" | "ERC1155",
365
+ ) => {
366
+ if (!contractStandard || !contractVersion) {
367
+ return false;
368
+ }
369
+
370
+ // Try force-convert version format to semver format
371
+ const semVerContractVersion = semver.coerce(contractVersion)?.raw;
372
+ if (!semVerContractVersion) return false;
373
+
374
+ if (contractStandard === "ERC1155") {
375
+ return semver.gte(semVerContractVersion, "1.3.5");
376
+ } else {
377
+ return semver.gte(semVerContractVersion, "14.0.0");
378
+ }
379
+ };
@@ -0,0 +1,57 @@
1
+ import { Concrete } from "src/utils";
2
+ import { Address, Hex } from "viem";
3
+
4
+ export type ContractType =
5
+ | {
6
+ name: string;
7
+ uri: string;
8
+ defaultAdmin?: Address;
9
+ }
10
+ | Address;
11
+
12
+ export type SalesConfigParamsType = {
13
+ // defaults to 0
14
+ pricePerToken?: bigint;
15
+ // defaults to 0, in seconds
16
+ saleStart?: bigint;
17
+ // defaults to forever, in seconds
18
+ saleEnd?: bigint;
19
+ // max tokens that can be minted per address
20
+ maxTokensPerAddress?: bigint;
21
+ // if an erc20 mint, the erc20 address. Leave null for eth mints
22
+ currency?: Address;
23
+ };
24
+
25
+ export type CreateNew1155Params = {
26
+ account: Address;
27
+ contract: ContractType;
28
+ getAdditionalSetupActions?: (args: {
29
+ tokenId: bigint;
30
+ contractAddress: Address;
31
+ }) => Hex[];
32
+ token: CreateNew1155TokenProps;
33
+ };
34
+
35
+ export interface CreateNew1155TokenProps {
36
+ maxSupply?: bigint | number;
37
+ tokenMetadataURI: string;
38
+ royaltyBPS?: number;
39
+ salesConfig?: SalesConfigParamsType;
40
+ createReferral?: Address;
41
+ mintToCreatorCount?: number;
42
+ payoutRecipient?: Address;
43
+ }
44
+
45
+ export interface ContractProps {
46
+ nextTokenId: bigint;
47
+ contractVersion: string;
48
+ }
49
+
50
+ export type New1155Token = {
51
+ payoutRecipient: Address;
52
+ createReferral: Address;
53
+ maxSupply: bigint;
54
+ royaltyBPS: number;
55
+ salesConfig: Concrete<SalesConfigParamsType>;
56
+ tokenMetadataURI: string;
57
+ };
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@ export * from "./premint/premint-api-client";
8
8
 
9
9
  export * from "./premint/conversions";
10
10
 
11
- export * from "./mint/mint-api-client";
11
+ export * from "./mint/subgraph-mint-getter";
12
12
 
13
13
  export * from "./mint/mint-client";
14
14
 
@@ -25,3 +25,7 @@ export {
25
25
  type ContractCreationConfigOrAddress,
26
26
  type ContractCreationConfigAndAddress,
27
27
  } from "./premint/contract-types";
28
+
29
+ export * from "./create/types";
30
+
31
+ export * from "./sdk";
@@ -1,12 +1,13 @@
1
1
  import { describe, expect } from "vitest";
2
- import { Address, parseAbi, parseEther } from "viem";
2
+ import { Address, erc20Abi, parseAbi, parseEther } from "viem";
3
3
  import { zora } from "viem/chains";
4
4
  import {
5
5
  zoraCreator1155ImplABI,
6
- erc20MinterAddress,
6
+ erc20MinterAddress as erc20MinterAddresses,
7
7
  } from "@zoralabs/protocol-deployments";
8
- import { createMintClient } from "./mint-client";
9
8
  import { anvilTest, forkUrls, makeAnvilTest } from "src/anvil";
9
+ import { createCollectorClient } from "src/sdk";
10
+ import { requestErc20ApprovalForMint } from "./mint-client";
10
11
 
11
12
  const erc721ABI = parseAbi([
12
13
  "function balanceOf(address owner) public view returns (uint256)",
@@ -25,16 +26,18 @@ describe("mint-helper", () => {
25
26
  const targetContract: Address =
26
27
  "0xa2fea3537915dc6c7c7a97a82d1236041e6feb2e";
27
28
  const targetTokenId = 1n;
28
- const minter = createMintClient({ chain: zora });
29
+ const collectorClient = createCollectorClient({
30
+ chainId: zora.id,
31
+ publicClient,
32
+ });
29
33
 
30
- const params = await minter.makePrepareMintTokenParams({
34
+ const { parameters } = await collectorClient.mint({
31
35
  minterAccount: creatorAccount,
32
36
  tokenId: targetTokenId,
33
- tokenAddress: targetContract,
34
- mintArguments: {
35
- mintToAddress: creatorAccount,
36
- quantityToMint: 1,
37
- },
37
+ tokenContract: targetContract,
38
+ mintType: "1155",
39
+ mintRecipient: creatorAccount,
40
+ quantityToMint: 1,
38
41
  });
39
42
 
40
43
  const oldBalance = await publicClient.readContract({
@@ -44,7 +47,7 @@ describe("mint-helper", () => {
44
47
  args: [creatorAccount, targetTokenId],
45
48
  });
46
49
 
47
- const simulationResult = await publicClient.simulateContract(params);
50
+ const simulationResult = await publicClient.simulateContract(parameters);
48
51
 
49
52
  const hash = await walletClient.writeContract(simulationResult.request);
50
53
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
@@ -64,6 +67,7 @@ describe("mint-helper", () => {
64
67
  makeAnvilTest({
65
68
  forkUrl: forkUrls.zoraMainnet,
66
69
  forkBlockNumber: 6133407,
70
+ anvilChainId: zora.id,
67
71
  })(
68
72
  "mints a new 721 token",
69
73
  async ({ viemClients }) => {
@@ -76,17 +80,17 @@ describe("mint-helper", () => {
76
80
 
77
81
  const targetContract: Address =
78
82
  "0x7aae7e67515A2CbB8585C707Ca6db37BDd3EA839";
79
- const targetTokenId = undefined;
80
- const minter = createMintClient({ chain: zora });
83
+ const collectorClient = createCollectorClient({
84
+ chainId: zora.id,
85
+ publicClient,
86
+ });
81
87
 
82
- const params = await minter.makePrepareMintTokenParams({
83
- tokenId: targetTokenId,
84
- tokenAddress: targetContract,
88
+ const { parameters } = await collectorClient.mint({
89
+ tokenContract: targetContract,
85
90
  minterAccount: creatorAccount,
86
- mintArguments: {
87
- mintToAddress: creatorAccount,
88
- quantityToMint: 1,
89
- },
91
+ mintRecipient: creatorAccount,
92
+ quantityToMint: 1,
93
+ mintType: "721",
90
94
  });
91
95
  const oldBalance = await publicClient.readContract({
92
96
  abi: erc721ABI,
@@ -95,7 +99,7 @@ describe("mint-helper", () => {
95
99
  args: [creatorAccount],
96
100
  });
97
101
 
98
- const simulated = await publicClient.simulateContract(params);
102
+ const simulated = await publicClient.simulateContract(parameters);
99
103
 
100
104
  const hash = await walletClient.writeContract(simulated.request);
101
105
 
@@ -118,16 +122,17 @@ describe("mint-helper", () => {
118
122
  makeAnvilTest({
119
123
  forkUrl: forkUrls.zoraMainnet,
120
124
  forkBlockNumber: 14484183,
125
+ anvilChainId: zora.id,
121
126
  })(
122
127
  "mints an 1155 token with an ERC20 token",
123
128
  async ({ viemClients }) => {
124
- const { testClient, walletClient, publicClient } = viemClients;
129
+ const { testClient, walletClient, publicClient, chain } = viemClients;
125
130
 
126
131
  const targetContract: Address =
127
132
  "0x689bc305456c38656856d12469aed282fbd89fe0";
128
133
  const targetTokenId = 16n;
129
134
 
130
- const minter = createMintClient({ chain: zora });
135
+ const minter = createCollectorClient({ chainId: chain.id, publicClient });
131
136
 
132
137
  const mockCollector = "0xb6b701878a1f80197dF2c209D0BDd292EA73164D";
133
138
  await testClient.impersonateAccount({
@@ -137,12 +142,6 @@ describe("mint-helper", () => {
137
142
  const erc20Currency = "0xa6b280b42cb0b7c4a4f789ec6ccc3a7609a1bc39";
138
143
  const erc20PricePerToken = 1000000000000000000n;
139
144
 
140
- const erc20Abi = parseAbi([
141
- "function balanceOf(address) public view returns (uint256)",
142
- "function approve(address spender, uint256 amount) public returns (bool)",
143
- "function allowance(address owner, address spender) public view returns (uint256)",
144
- ]);
145
-
146
145
  const beforeERC20Balance = await publicClient.readContract({
147
146
  abi: erc20Abi,
148
147
  address: erc20Currency,
@@ -150,35 +149,32 @@ describe("mint-helper", () => {
150
149
  args: [mockCollector],
151
150
  });
152
151
 
153
- const { request } = await publicClient.simulateContract({
154
- account: mockCollector,
155
- address: erc20Currency,
156
- abi: erc20Abi,
157
- functionName: "approve",
158
- args: [erc20MinterAddress[7777777], erc20PricePerToken],
159
- });
152
+ const quantityToMint = 3n;
153
+
154
+ const quantityErc20 = erc20PricePerToken * BigInt(quantityToMint);
155
+
156
+ const { request } = await publicClient.simulateContract(
157
+ requestErc20ApprovalForMint({
158
+ erc20MinterAddress:
159
+ erc20MinterAddresses[chain.id as keyof typeof erc20MinterAddresses],
160
+ tokenAddress: erc20Currency,
161
+ account: mockCollector,
162
+ quantityErc20,
163
+ }),
164
+ );
160
165
  const approveHash = await walletClient.writeContract(request);
161
166
  const approveTxReciept = await publicClient.waitForTransactionReceipt({
162
167
  hash: approveHash,
163
168
  });
164
169
  expect(approveTxReciept).to.not.be.null;
165
170
 
166
- const beforeAllowance = await publicClient.readContract({
167
- abi: erc20Abi,
168
- address: erc20Currency,
169
- functionName: "allowance",
170
- args: [mockCollector, erc20MinterAddress[7777777]],
171
- });
172
- expect(beforeAllowance).to.be.equal(erc20PricePerToken);
173
-
174
- const params = await minter.makePrepareMintTokenParams({
171
+ const { parameters } = await minter.mint({
175
172
  minterAccount: mockCollector,
176
173
  tokenId: targetTokenId,
177
- tokenAddress: targetContract,
178
- mintArguments: {
179
- mintToAddress: mockCollector,
180
- quantityToMint: 1,
181
- },
174
+ tokenContract: targetContract,
175
+ mintRecipient: mockCollector,
176
+ quantityToMint,
177
+ mintType: "1155",
182
178
  });
183
179
 
184
180
  const beforeCollector1155Balance = await publicClient.readContract({
@@ -189,27 +185,20 @@ describe("mint-helper", () => {
189
185
  });
190
186
  expect(beforeCollector1155Balance).to.be.equal(0n);
191
187
 
192
- const simulationResult = await publicClient.simulateContract(params);
188
+ const simulationResult = await publicClient.simulateContract(parameters);
193
189
  const hash = await walletClient.writeContract(simulationResult.request);
194
190
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
195
191
  expect(receipt).to.not.be.null;
196
192
 
197
- const afterAllowance = await publicClient.readContract({
198
- abi: erc20Abi,
199
- address: erc20Currency,
200
- functionName: "allowance",
201
- args: [mockCollector, erc20MinterAddress[7777777]],
202
- });
203
- expect(afterAllowance).to.be.equal(0n);
204
-
205
193
  const afterERC20Balance = await publicClient.readContract({
206
194
  abi: erc20Abi,
207
195
  address: erc20Currency,
208
196
  functionName: "balanceOf",
209
197
  args: [mockCollector],
210
198
  });
199
+
211
200
  expect(beforeERC20Balance - afterERC20Balance).to.be.equal(
212
- erc20PricePerToken,
201
+ erc20PricePerToken * quantityToMint,
213
202
  );
214
203
 
215
204
  const afterCollector1155Balance = await publicClient.readContract({
@@ -218,7 +207,7 @@ describe("mint-helper", () => {
218
207
  functionName: "balanceOf",
219
208
  args: [mockCollector, targetTokenId],
220
209
  });
221
- expect(afterCollector1155Balance).to.be.equal(1n);
210
+ expect(afterCollector1155Balance).to.be.equal(quantityToMint);
222
211
  },
223
212
  12 * 1000,
224
213
  );