@zoralabs/protocol-sdk 0.7.3-SPARKS.0 → 0.7.3

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.
@@ -1,6 +1,6 @@
1
1
  import { Address, Hex, PublicClient, WalletClient } from "viem";
2
2
  import { PermitSafeTransferBatch } from "./mints-contracts";
3
- import { sparksEthUnwrapperAndCallerAddress } from "@zoralabs/protocol-deployments";
3
+ import { mintsEthUnwrapperAndCallerAddress } from "@zoralabs/protocol-deployments";
4
4
  export declare const getRelayCall: ({ tx, depositingAccount, originChainId, toChainId, }: {
5
5
  tx: {
6
6
  to: Address;
@@ -23,7 +23,7 @@ export declare const getRelayCall: ({ tx, depositingAccount, originChainId, toCh
23
23
  relayFee: bigint;
24
24
  }>;
25
25
  export declare const makeAndSignSponsoredRelayCall: ({ originChainId, toChainId, tx, executingAccount, walletClient, }: {
26
- originChainId: keyof typeof sparksEthUnwrapperAndCallerAddress;
26
+ originChainId: keyof typeof mintsEthUnwrapperAndCallerAddress;
27
27
  toChainId: number;
28
28
  tx: {
29
29
  to: Address;
@@ -43,7 +43,7 @@ export declare const validateSponsoredRelayCall: ({ safeTransferData, additional
43
43
  additionalValueToSend: bigint;
44
44
  deadline: bigint;
45
45
  executingAccount: Address;
46
- chainId: keyof typeof sparksEthUnwrapperAndCallerAddress;
46
+ chainId: keyof typeof mintsEthUnwrapperAndCallerAddress;
47
47
  signature: Hex;
48
48
  }) => Promise<void>;
49
49
  export declare const validateAndExecuteSponsoredRelayCall: ({ permit, permitSignature, additionalValueToSend, deadline, chainId, executingAccount, sponsoredCallSignature, walletClient, publicClient, }: {
@@ -52,7 +52,7 @@ export declare const validateAndExecuteSponsoredRelayCall: ({ permit, permitSign
52
52
  additionalValueToSend: bigint;
53
53
  deadline: bigint;
54
54
  executingAccount: Address;
55
- chainId: keyof typeof sparksEthUnwrapperAndCallerAddress;
55
+ chainId: keyof typeof mintsEthUnwrapperAndCallerAddress;
56
56
  sponsoredCallSignature: Hex;
57
57
  publicClient: PublicClient;
58
58
  walletClient: WalletClient;
@@ -1 +1 @@
1
- {"version":3,"file":"mints-relay-example.d.ts","sourceRoot":"","sources":["../../src/mints/mints-relay-example.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,YAAY,EAGZ,YAAY,EAEb,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAEL,kCAAkC,EACnC,MAAM,gCAAgC,CAAC;AAuBxC,eAAO,MAAM,YAAY;QAMnB;QACF,EAAE,EAAE,OAAO,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,GAAG,CAAC;KACX;uBACkB,OAAO;mBACX,MAAM;eACV,MAAM;;;;;;;;;;;;EAyClB,CAAC;AAKF,eAAO,MAAM,6BAA6B;mBAQzB,MAAM,yCAAyC;eAEnD,MAAM;QAEb;QACF,EAAE,EAAE,OAAO,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,GAAG,CAAC;KACX;sBACiB,OAAO;kBACX,YAAY;;;;;;EA2C3B,CAAC;AAIF,eAAO,MAAM,0BAA0B;sBASnB,GAAG;2BACE,MAAM;cACnB,MAAM;sBACE,OAAO;aAChB,MAAM,yCAAyC;eAC7C,GAAG;mBAiBf,CAAC;AAIF,eAAO,MAAM,oCAAoC;YAYvC,uBAAuB;qBACd,GAAG;2BAEG,MAAM;cAEnB,MAAM;sBAEE,OAAO;aAChB,MAAM,yCAAyC;4BAEhC,GAAG;kBACb,YAAY;kBACZ,YAAY;mBAyC3B,CAAC"}
1
+ {"version":3,"file":"mints-relay-example.d.ts","sourceRoot":"","sources":["../../src/mints/mints-relay-example.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,YAAY,EAGZ,YAAY,EAEb,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAEL,iCAAiC,EAClC,MAAM,gCAAgC,CAAC;AAiCxC,eAAO,MAAM,YAAY;QAMnB;QACF,EAAE,EAAE,OAAO,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,GAAG,CAAC;KACX;uBACkB,OAAO;mBACX,MAAM;eACV,MAAM;;;;;;;;;;;;EAyClB,CAAC;AAKF,eAAO,MAAM,6BAA6B;mBAQzB,MAAM,wCAAwC;eAElD,MAAM;QAEb;QACF,EAAE,EAAE,OAAO,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,GAAG,CAAC;KACX;sBACiB,OAAO;kBACX,YAAY;;;;;;EA2C3B,CAAC;AAIF,eAAO,MAAM,0BAA0B;sBASnB,GAAG;2BACE,MAAM;cACnB,MAAM;sBACE,OAAO;aAChB,MAAM,wCAAwC;eAC5C,GAAG;mBAiBf,CAAC;AAIF,eAAO,MAAM,oCAAoC;YAYvC,uBAAuB;qBACd,GAAG;2BAEG,MAAM;cAEnB,MAAM;sBAEE,OAAO;aAChB,MAAM,wCAAwC;4BAE/B,GAAG;kBACb,YAAY;kBACZ,YAAY;mBAyC3B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoralabs/protocol-sdk",
3
- "version": "0.7.3-SPARKS.0",
3
+ "version": "0.7.3",
4
4
  "repository": "https://github.com/ourzora/zora-protocol",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,28 +16,32 @@
16
16
  }
17
17
  },
18
18
  "scripts": {
19
- "build": "tsup",
19
+ "build": "yarn run tsup",
20
20
  "prepack": "yarn build",
21
21
  "test:js": "vitest src",
22
22
  "test:integration": "vitest test-integration",
23
23
  "generate-types": "echo 'npx is used here because this is a rare operation' && npx openapi-typescript https://api.zora.co/premint/openapi.json -o src/apis/generated/premint-api-types.ts",
24
- "prettier": "prettier --write 'src/**/*.ts' 'test-integration/**/*.ts'",
24
+ "prettier:write": "prettier --write 'src/**/*.ts' 'test-integration/**/*.ts'",
25
25
  "lint": "prettier --check 'src/**/*.ts' 'test-integration/**/*.ts'"
26
26
  },
27
27
  "dependencies": {
28
- "@zoralabs/protocol-deployments": "0.2.0-SPARKS.0",
28
+ "@zoralabs/protocol-deployments": "*",
29
+ "abitype": "^1.0.2",
29
30
  "semver": "^7.6.2"
30
31
  },
31
32
  "peerDependencies": {
32
- "viem": "^2.11.1"
33
+ "viem": "^2.13.2"
33
34
  },
34
35
  "devDependencies": {
36
+ "@types/node": "^20.13.0",
35
37
  "@fleekhq/fleek-storage-js": "^1.0.24",
36
38
  "@lavamoat/preinstall-always-fail": "2.0.0",
37
39
  "@reservoir0x/relay-sdk": "^0.3.8",
38
40
  "@reservoir0x/reservoir-sdk": "^2.0.11",
39
- "abitype": "^1.0.2",
40
41
  "graphql-prettier": "^1.0.6",
42
+ "tsup": "^7.2.0",
43
+ "prettier": "^3.0.3",
44
+ "prettier-plugin-solidity": "^1.1.3",
41
45
  "typescript": "^5.2.2",
42
46
  "vite": "^4.5.0",
43
47
  "vitest": "^0.34.6",
@@ -0,0 +1,325 @@
1
+ import { describe, expect } from "vitest";
2
+ import { getTokenIdFromCreateReceipt } from "./1155-create-helper";
3
+ import { anvilTest } from "src/anvil";
4
+ import { createCreatorClient } from "src/sdk";
5
+ import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
6
+ import { waitForSuccess } from "src/test-utils";
7
+ import { parseEther } from "viem";
8
+ import {
9
+ MintableParameters,
10
+ makePrepareMint1155TokenParams,
11
+ } from "src/mint/mint-transactions";
12
+
13
+ const demoTokenMetadataURI = "ipfs://DUMMY/token.json";
14
+ const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
15
+
16
+ describe("create-helper", () => {
17
+ anvilTest(
18
+ "creates a new 1155 contract and token",
19
+ async ({ viemClients: { publicClient, walletClient, chain } }) => {
20
+ const addresses = await walletClient.getAddresses();
21
+ const creatorAddress = addresses[0]!;
22
+
23
+ const creatorClient = createCreatorClient({
24
+ chainId: chain.id,
25
+ publicClient: publicClient,
26
+ });
27
+ const { parameters: request } = await creatorClient.create1155({
28
+ contract: {
29
+ name: "testContract",
30
+ uri: demoContractMetadataURI,
31
+ },
32
+ token: {
33
+ tokenMetadataURI: demoTokenMetadataURI,
34
+ mintToCreatorCount: 1,
35
+ },
36
+ account: creatorAddress,
37
+ });
38
+ const { request: simulationResponse } =
39
+ await publicClient.simulateContract(request);
40
+ const hash = await walletClient.writeContract(simulationResponse);
41
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
42
+ expect(receipt).not.toBeNull();
43
+ expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
44
+ expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n);
45
+ },
46
+ 20 * 1000,
47
+ );
48
+ anvilTest(
49
+ "creates a new contract, then can create a new token on this existing contract",
50
+ async ({ viemClients: { publicClient, walletClient, chain } }) => {
51
+ const addresses = await walletClient.getAddresses();
52
+ const creatorAccount = addresses[0]!;
53
+
54
+ const creatorClient = createCreatorClient({
55
+ chainId: chain.id,
56
+ publicClient: publicClient,
57
+ });
58
+
59
+ const {
60
+ parameters: request,
61
+ collectionAddress: contractAddress,
62
+ contractExists,
63
+ } = await creatorClient.create1155({
64
+ contract: {
65
+ name: "testContract2",
66
+ uri: demoContractMetadataURI,
67
+ },
68
+ token: {
69
+ tokenMetadataURI: demoTokenMetadataURI,
70
+ mintToCreatorCount: 3,
71
+ },
72
+ account: creatorAccount,
73
+ });
74
+ expect(contractAddress).to.be.equal(
75
+ "0xb1A8928dF830C21eD682949Aa8A83C1C215194d3",
76
+ );
77
+ expect(contractExists).to.be.false;
78
+ const { request: simulateResponse } =
79
+ await publicClient.simulateContract(request);
80
+ const hash = await walletClient.writeContract(simulateResponse);
81
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
82
+ const firstTokenId = getTokenIdFromCreateReceipt(receipt);
83
+ expect(firstTokenId).to.be.equal(1n);
84
+ expect(receipt).not.toBeNull();
85
+
86
+ // creator should have mint to creator count balance
87
+ expect(
88
+ await publicClient.readContract({
89
+ address: contractAddress,
90
+ abi: zoraCreator1155ImplABI,
91
+ functionName: "balanceOf",
92
+ args: [creatorAccount, firstTokenId!],
93
+ }),
94
+ ).toBe(3n);
95
+
96
+ const newTokenOnExistingContract = await creatorClient.create1155({
97
+ contract: {
98
+ name: "testContract2",
99
+ uri: demoContractMetadataURI,
100
+ },
101
+ token: {
102
+ tokenMetadataURI: demoTokenMetadataURI,
103
+ mintToCreatorCount: 2,
104
+ },
105
+ account: creatorAccount,
106
+ });
107
+ expect(newTokenOnExistingContract.collectionAddress).to.be.equal(
108
+ "0xb1A8928dF830C21eD682949Aa8A83C1C215194d3",
109
+ );
110
+ expect(newTokenOnExistingContract.contractExists).to.be.true;
111
+ const { request: simulateRequest } = await publicClient.simulateContract(
112
+ newTokenOnExistingContract.parameters,
113
+ );
114
+ const newHash = await walletClient.writeContract(simulateRequest);
115
+ const newReceipt = await publicClient.waitForTransactionReceipt({
116
+ hash: newHash,
117
+ });
118
+ const tokenId = getTokenIdFromCreateReceipt(newReceipt);
119
+ expect(tokenId).to.be.equal(2n);
120
+ expect(newReceipt).not.toBeNull();
121
+ },
122
+ 20 * 1000,
123
+ );
124
+ anvilTest(
125
+ "creates a new token with a create referral address",
126
+ async ({ viemClients: { publicClient, walletClient, chain } }) => {
127
+ const addresses = await walletClient.getAddresses();
128
+ const creatorAddress = addresses[0]!;
129
+ const createReferral = addresses[1]!;
130
+
131
+ const creatorClient = createCreatorClient({
132
+ chainId: chain.id,
133
+ publicClient: publicClient,
134
+ });
135
+ const { parameters: request } = await creatorClient.create1155({
136
+ contract: {
137
+ name: "testContract",
138
+ uri: demoContractMetadataURI,
139
+ },
140
+ token: {
141
+ tokenMetadataURI: demoTokenMetadataURI,
142
+ createReferral,
143
+ },
144
+ account: creatorAddress,
145
+ });
146
+ const { request: simulationResponse } =
147
+ await publicClient.simulateContract(request);
148
+ const hash = await walletClient.writeContract(simulationResponse);
149
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
150
+ expect(receipt).not.toBeNull();
151
+ expect(receipt.to).to.equal("0xa72724cc3dcef210141a1b84c61824074151dc99");
152
+ expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(2n);
153
+
154
+ expect(
155
+ await publicClient.readContract({
156
+ abi: zoraCreator1155ImplABI,
157
+ address: "0xa72724cc3dcef210141a1b84c61824074151dc99",
158
+ functionName: "createReferrals",
159
+ args: [2n],
160
+ }),
161
+ ).to.be.equal(createReferral);
162
+ },
163
+ 20 * 1000,
164
+ );
165
+
166
+ anvilTest(
167
+ "creates a new 1155 free mint that can be minted",
168
+ async ({
169
+ viemClients: { testClient, publicClient, walletClient, chain },
170
+ }) => {
171
+ const addresses = await walletClient.getAddresses();
172
+ const creatorAddress = addresses[0]!;
173
+
174
+ const creatorClient = createCreatorClient({
175
+ chainId: chain.id,
176
+ publicClient: publicClient,
177
+ });
178
+ const {
179
+ parameters: request,
180
+ collectionAddress,
181
+ newTokenId,
182
+ newToken,
183
+ minter,
184
+ } = await creatorClient.create1155({
185
+ contract: {
186
+ name: "testContract",
187
+ uri: demoContractMetadataURI,
188
+ },
189
+ token: {
190
+ tokenMetadataURI: demoTokenMetadataURI,
191
+ },
192
+ account: creatorAddress,
193
+ });
194
+ const { request: createSimulation } =
195
+ await publicClient.simulateContract(request);
196
+ await waitForSuccess(
197
+ await walletClient.writeContract(createSimulation),
198
+ publicClient,
199
+ );
200
+
201
+ const salesConfigAndTokenInfo: MintableParameters = {
202
+ mintFeePerQuantity: parseEther("0.000777"),
203
+ contractVersion: "2.8.0",
204
+ salesConfig: {
205
+ saleType: "fixedPrice",
206
+ address: minter,
207
+ pricePerToken: newToken.salesConfig.pricePerToken,
208
+ // these dont matter
209
+ maxTokensPerAddress: 0n,
210
+ saleEnd: "",
211
+ saleStart: "",
212
+ },
213
+ };
214
+
215
+ const quantityToMint = 5n;
216
+
217
+ // now try to mint a free mint
218
+ const minterAddress = addresses[1]!;
219
+
220
+ await testClient.setBalance({
221
+ address: minterAddress,
222
+ value: parseEther("10"),
223
+ });
224
+
225
+ const mintParams = makePrepareMint1155TokenParams({
226
+ tokenContract: collectionAddress,
227
+ minterAccount: minterAddress,
228
+ tokenId: newTokenId,
229
+ salesConfigAndTokenInfo,
230
+ quantityToMint,
231
+ });
232
+
233
+ const { request: collectSimulation } =
234
+ await publicClient.simulateContract(mintParams);
235
+ await waitForSuccess(
236
+ await walletClient.writeContract(collectSimulation),
237
+ publicClient,
238
+ );
239
+ },
240
+ 20 * 1000,
241
+ );
242
+
243
+ anvilTest(
244
+ "creates a new 1155 paid mint that can be minted",
245
+ async ({
246
+ viemClients: { testClient, publicClient, walletClient, chain },
247
+ }) => {
248
+ const addresses = await walletClient.getAddresses();
249
+ const creatorAddress = addresses[0]!;
250
+
251
+ const creatorClient = createCreatorClient({
252
+ chainId: chain.id,
253
+ publicClient: publicClient,
254
+ });
255
+
256
+ const pricePerToken = parseEther("0.01");
257
+
258
+ const {
259
+ parameters: request,
260
+ collectionAddress,
261
+ newTokenId,
262
+ newToken,
263
+ minter,
264
+ } = await creatorClient.create1155({
265
+ contract: {
266
+ name: "testContract",
267
+ uri: demoContractMetadataURI,
268
+ },
269
+ token: {
270
+ tokenMetadataURI: demoTokenMetadataURI,
271
+ salesConfig: {
272
+ pricePerToken,
273
+ },
274
+ },
275
+ account: creatorAddress,
276
+ });
277
+ const { request: createSimulation } =
278
+ await publicClient.simulateContract(request);
279
+ await waitForSuccess(
280
+ await walletClient.writeContract(createSimulation),
281
+ publicClient,
282
+ );
283
+
284
+ const salesConfigAndTokenInfo: MintableParameters = {
285
+ mintFeePerQuantity: parseEther("0.000777"),
286
+ contractVersion: "2.8.0",
287
+ salesConfig: {
288
+ saleType: "fixedPrice",
289
+ address: minter,
290
+ pricePerToken: newToken.salesConfig.pricePerToken,
291
+ // these dont matter
292
+ maxTokensPerAddress: 0n,
293
+ saleEnd: "",
294
+ saleStart: "",
295
+ },
296
+ };
297
+
298
+ const quantityToMint = 5n;
299
+
300
+ // now try to mint a free mint
301
+ const minterAddress = addresses[1]!;
302
+
303
+ await testClient.setBalance({
304
+ address: minterAddress,
305
+ value: parseEther("10"),
306
+ });
307
+
308
+ const mintParams = makePrepareMint1155TokenParams({
309
+ tokenContract: collectionAddress,
310
+ minterAccount: minterAddress,
311
+ tokenId: newTokenId,
312
+ salesConfigAndTokenInfo,
313
+ quantityToMint,
314
+ });
315
+
316
+ const { request: collectSimulation } =
317
+ await publicClient.simulateContract(mintParams);
318
+ await waitForSuccess(
319
+ await walletClient.writeContract(collectSimulation),
320
+ publicClient,
321
+ );
322
+ },
323
+ 20 * 1000,
324
+ );
325
+ });
@@ -0,0 +1,263 @@
1
+ import { describe, expect } from "vitest";
2
+ import { Address, erc20Abi, parseAbi, parseEther } from "viem";
3
+ import { zora, zoraSepolia } from "viem/chains";
4
+ import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
5
+ import { forkUrls, makeAnvilTest } from "src/anvil";
6
+ import { createCollectorClient } from "src/sdk";
7
+
8
+ const erc721ABI = parseAbi([
9
+ "function balanceOf(address owner) public view returns (uint256)",
10
+ ] as const);
11
+
12
+ describe("mint-helper", () => {
13
+ makeAnvilTest({
14
+ forkBlockNumber: 16028671,
15
+ forkUrl: forkUrls.zoraMainnet,
16
+ anvilChainId: zora.id,
17
+ })(
18
+ "mints a new 1155 token",
19
+ async ({ viemClients }) => {
20
+ const { testClient, walletClient, publicClient } = viemClients;
21
+ const creatorAccount = (await walletClient.getAddresses())[0]!;
22
+ await testClient.setBalance({
23
+ address: creatorAccount,
24
+ value: parseEther("2000"),
25
+ });
26
+ const targetContract: Address =
27
+ "0xa2fea3537915dc6c7c7a97a82d1236041e6feb2e";
28
+ const targetTokenId = 1n;
29
+ const collectorClient = createCollectorClient({
30
+ chainId: zora.id,
31
+ publicClient,
32
+ });
33
+
34
+ const { token: mintable, prepareMint } = await collectorClient.getToken({
35
+ tokenContract: targetContract,
36
+ mintType: "1155",
37
+ tokenId: targetTokenId,
38
+ });
39
+
40
+ mintable.maxSupply;
41
+ mintable.totalMinted;
42
+ mintable.tokenURI;
43
+ mintable;
44
+
45
+ const { parameters, costs } = prepareMint({
46
+ minterAccount: creatorAccount,
47
+ quantityToMint: 1,
48
+ });
49
+
50
+ expect(costs.totalCostEth).toBe(1n * parseEther("0.000777"));
51
+
52
+ const oldBalance = await publicClient.readContract({
53
+ abi: zoraCreator1155ImplABI,
54
+ address: targetContract,
55
+ functionName: "balanceOf",
56
+ args: [creatorAccount, targetTokenId],
57
+ });
58
+
59
+ const simulationResult = await publicClient.simulateContract(parameters);
60
+
61
+ const hash = await walletClient.writeContract(simulationResult.request);
62
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
63
+ const newBalance = await publicClient.readContract({
64
+ abi: zoraCreator1155ImplABI,
65
+ address: targetContract,
66
+ functionName: "balanceOf",
67
+ args: [creatorAccount, targetTokenId],
68
+ });
69
+ expect(receipt).to.not.be.null;
70
+ expect(oldBalance).to.be.equal(0n);
71
+ expect(newBalance).to.be.equal(1n);
72
+ },
73
+ 12 * 1000,
74
+ );
75
+
76
+ makeAnvilTest({
77
+ forkUrl: forkUrls.zoraMainnet,
78
+ forkBlockNumber: 6133407,
79
+ anvilChainId: zora.id,
80
+ })(
81
+ "mints a new 721 token",
82
+ async ({ viemClients }) => {
83
+ const { testClient, walletClient, publicClient } = viemClients;
84
+ const creatorAccount = (await walletClient.getAddresses())[0]!;
85
+ await testClient.setBalance({
86
+ address: creatorAccount,
87
+ value: parseEther("2000"),
88
+ });
89
+
90
+ const targetContract: Address =
91
+ "0x7aae7e67515A2CbB8585C707Ca6db37BDd3EA839";
92
+ const collectorClient = createCollectorClient({
93
+ chainId: zora.id,
94
+ publicClient,
95
+ });
96
+
97
+ const { prepareMint } = await collectorClient.getToken({
98
+ tokenContract: targetContract,
99
+ mintType: "721",
100
+ });
101
+
102
+ const quantityToMint = 3n;
103
+
104
+ const { parameters, costs } = prepareMint({
105
+ minterAccount: creatorAccount,
106
+ mintRecipient: creatorAccount,
107
+ quantityToMint,
108
+ });
109
+
110
+ expect(costs.totalPurchaseCost).toBe(quantityToMint * parseEther(".08"));
111
+ expect(costs.totalCostEth).toBe(
112
+ quantityToMint * (parseEther("0.08") + parseEther("0.000777")),
113
+ );
114
+
115
+ const oldBalance = await publicClient.readContract({
116
+ abi: erc721ABI,
117
+ address: targetContract,
118
+ functionName: "balanceOf",
119
+ args: [creatorAccount],
120
+ });
121
+
122
+ const simulated = await publicClient.simulateContract(parameters);
123
+
124
+ const hash = await walletClient.writeContract(simulated.request);
125
+
126
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
127
+ expect(receipt).not.to.be.null;
128
+
129
+ const newBalance = await publicClient.readContract({
130
+ abi: erc721ABI,
131
+ address: targetContract,
132
+ functionName: "balanceOf",
133
+ args: [creatorAccount],
134
+ });
135
+
136
+ expect(oldBalance).to.be.equal(0n);
137
+ expect(newBalance).to.be.equal(quantityToMint);
138
+ },
139
+ 12 * 1000,
140
+ );
141
+
142
+ makeAnvilTest({
143
+ forkUrl: forkUrls.zoraMainnet,
144
+ forkBlockNumber: 14484183,
145
+ anvilChainId: zora.id,
146
+ })(
147
+ "mints an 1155 token with an ERC20 token",
148
+ async ({ viemClients }) => {
149
+ const { testClient, walletClient, publicClient, chain } = viemClients;
150
+
151
+ const targetContract: Address =
152
+ "0x689bc305456c38656856d12469aed282fbd89fe0";
153
+ const targetTokenId = 16n;
154
+
155
+ const minter = createCollectorClient({ chainId: chain.id, publicClient });
156
+
157
+ const mockCollector = "0xb6b701878a1f80197dF2c209D0BDd292EA73164D";
158
+ await testClient.impersonateAccount({
159
+ address: mockCollector,
160
+ });
161
+
162
+ const { prepareMint } = await minter.getToken({
163
+ mintType: "1155",
164
+ tokenContract: targetContract,
165
+ tokenId: targetTokenId,
166
+ });
167
+
168
+ const quantityToMint = 1n;
169
+
170
+ const { parameters, erc20Approval, costs } = prepareMint({
171
+ minterAccount: mockCollector,
172
+ quantityToMint,
173
+ });
174
+
175
+ expect(erc20Approval).toBeDefined();
176
+ expect(costs.totalCostEth).toBe(0n);
177
+ expect(costs.totalPurchaseCost).toBe(
178
+ quantityToMint * 1000000000000000000n,
179
+ );
180
+ expect(costs.totalPurchaseCostCurrency).toBe(
181
+ "0xa6b280b42cb0b7c4a4f789ec6ccc3a7609a1bc39",
182
+ );
183
+
184
+ const beforeERC20Balance = await publicClient.readContract({
185
+ abi: erc20Abi,
186
+ address: erc20Approval!.erc20,
187
+ functionName: "balanceOf",
188
+ args: [mockCollector],
189
+ });
190
+
191
+ // execute the erc20 approval
192
+ const { request: erc20Request } = await publicClient.simulateContract({
193
+ abi: erc20Abi,
194
+ address: erc20Approval!.erc20,
195
+ functionName: "approve",
196
+ args: [erc20Approval!.approveTo, erc20Approval!.quantity],
197
+ account: mockCollector,
198
+ });
199
+
200
+ const approveHash = await walletClient.writeContract(erc20Request);
201
+ await publicClient.waitForTransactionReceipt({
202
+ hash: approveHash,
203
+ });
204
+
205
+ const beforeCollector1155Balance = await publicClient.readContract({
206
+ abi: zoraCreator1155ImplABI,
207
+ address: targetContract,
208
+ functionName: "balanceOf",
209
+ args: [mockCollector, targetTokenId],
210
+ });
211
+ expect(beforeCollector1155Balance).to.be.equal(0n);
212
+
213
+ // execute the mint
214
+ const simulationResult = await publicClient.simulateContract(parameters);
215
+ const hash = await walletClient.writeContract(simulationResult.request);
216
+ await publicClient.waitForTransactionReceipt({ hash });
217
+
218
+ const afterERC20Balance = await publicClient.readContract({
219
+ abi: erc20Abi,
220
+ address: erc20Approval!.erc20,
221
+ functionName: "balanceOf",
222
+ args: [mockCollector],
223
+ });
224
+
225
+ expect(beforeERC20Balance - afterERC20Balance).to.be.equal(
226
+ erc20Approval!.quantity,
227
+ );
228
+
229
+ const afterCollector1155Balance = await publicClient.readContract({
230
+ abi: zoraCreator1155ImplABI,
231
+ address: targetContract,
232
+ functionName: "balanceOf",
233
+ args: [mockCollector, targetTokenId],
234
+ });
235
+ expect(afterCollector1155Balance).to.be.equal(quantityToMint);
236
+ },
237
+ 12 * 1000,
238
+ );
239
+
240
+ makeAnvilTest({
241
+ forkUrl: forkUrls.zoraSepolia,
242
+ forkBlockNumber: 10294670,
243
+ anvilChainId: zoraSepolia.id,
244
+ })(
245
+ "gets onchain and premint mintables",
246
+ async ({ viemClients }) => {
247
+ const { publicClient, chain } = viemClients;
248
+
249
+ const targetContract: Address =
250
+ "0xa33e4228843092bb0f2fcbb2eb237bcefc1046b3";
251
+
252
+ const minter = createCollectorClient({ chainId: chain.id, publicClient });
253
+
254
+ const { tokens: mintables, contract } = await minter.getTokensOfContract({
255
+ tokenContract: targetContract,
256
+ });
257
+
258
+ expect(mintables.length).toBe(4);
259
+ expect(contract).toBeDefined();
260
+ },
261
+ 12 * 1000,
262
+ );
263
+ });