@zoralabs/protocol-sdk 0.11.3-COMMENTS.1 → 0.11.3-COMMENTS.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.
@@ -27,8 +27,8 @@ export declare const preminterTypedDataDefinition: ({ verifyingContract, premint
27
27
  domain?: {
28
28
  chainId?: number | undefined;
29
29
  name?: string | undefined;
30
- salt?: import("abitype").ResolvedRegister["bytesType"]["outputs"] | undefined;
31
- verifyingContract?: Address | undefined;
30
+ salt?: import("viem").ResolvedRegister["bytesType"]["outputs"] | undefined;
31
+ verifyingContract?: import("viem").Address | undefined;
32
32
  version?: string | undefined;
33
33
  } | undefined;
34
34
  message: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"preminter.d.ts","sourceRoot":"","sources":["../src/preminter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EACL,qCAAqC,IAAI,YAAY,EAEtD,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAGL,GAAG,EACH,YAAY,EACb,MAAM,MAAM,CAAC;AAEd,KAAK,aAAa,GAAG,kBAAkB,CACrC,OAAO,YAAY,EACnB,WAAW,CACZ,CAAC,QAAQ,CAAC,CAAC;AAEZ,KAAK,sBAAsB,GAAG,6BAA6B,CAAC,aAAa,CAAC,CAAC;AAE3E,MAAM,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;AAC/D,MAAM,MAAM,aAAa,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;AACtD,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAI/D,eAAO,MAAM,4BAA4B,mDAItC;IACD,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB;;;;;;;;;;;;;;;;eAsGsqE,+CAA8B;;;;;CAzDpsE,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,EACvC,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,OAAO,EACP,YAAY,GACb,EAAE;IACD,eAAe,EAAE,OAAO,CAAC;IACzB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,OAAO,CAAC;IACV,YAAY,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC,CAqCD"}
1
+ {"version":3,"file":"preminter.d.ts","sourceRoot":"","sources":["../src/preminter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EACL,qCAAqC,IAAI,YAAY,EAEtD,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAGL,GAAG,EACH,YAAY,EACb,MAAM,MAAM,CAAC;AAEd,KAAK,aAAa,GAAG,kBAAkB,CACrC,OAAO,YAAY,EACnB,WAAW,CACZ,CAAC,QAAQ,CAAC,CAAC;AAEZ,KAAK,sBAAsB,GAAG,6BAA6B,CAAC,aAAa,CAAC,CAAC;AAE3E,MAAM,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;AAC/D,MAAM,MAAM,aAAa,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;AACtD,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAI/D,eAAO,MAAM,4BAA4B,mDAItC;IACD,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB;;;;;;;;;;;;;;;;eAsGgoE,4CAA8B;;;;;CAzD9pE,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,EACvC,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,OAAO,EACP,YAAY,GACb,EAAE;IACD,eAAe,EAAE,OAAO,CAAC;IACzB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,OAAO,CAAC;IACV,YAAY,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC,CAqCD"}
@@ -1,7 +1,7 @@
1
1
  import { zoraCreator1155FactoryImplAddress } from "@zoralabs/protocol-deployments";
2
2
  import { Address, Hex, PublicClient } from "viem";
3
3
  import { NewContractParams } from "./create/types";
4
- export declare const waitForSuccess: (hash: Hex, publicClient: PublicClient) => Promise<void>;
4
+ export declare const waitForSuccess: (hash: Hex, publicClient: PublicClient) => Promise<import("viem").TransactionReceipt>;
5
5
  export declare const getFixedPricedMinter: ({ publicClient, chainId, }: {
6
6
  publicClient: PublicClient;
7
7
  chainId: keyof typeof zoraCreator1155FactoryImplAddress;
@@ -1 +1 @@
1
- {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iCAAiC,EAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,EACP,GAAG,EACH,YAAY,EAGb,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,eAAO,MAAM,cAAc,SAAgB,GAAG,gBAAgB,YAAY,kBAMzE,CAAC;AAEF,eAAO,MAAM,oBAAoB,+BAG9B;IACD,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,OAAO,iCAAiC,CAAC;CACzD,2BAKG,CAAC;AAEL,eAAO,MAAM,+BAA+B,uBAEzC;IACD,aAAa,EAAE,OAAO,CAAC;CACxB,kBAAwE,CAAC;AAI1E,wBAAgB,iBAAiB,IAAI,iBAAiB,CAKrD"}
1
+ {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iCAAiC,EAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,EACP,GAAG,EACH,YAAY,EAGb,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,eAAO,MAAM,cAAc,SAAgB,GAAG,gBAAgB,YAAY,+CAQzE,CAAC;AAEF,eAAO,MAAM,oBAAoB,+BAG9B;IACD,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,OAAO,iCAAiC,CAAC;CACzD,2BAKG,CAAC;AAEL,eAAO,MAAM,+BAA+B,uBAEzC;IACD,aAAa,EAAE,OAAO,CAAC;CACxB,kBAAwE,CAAC;AAI1E,wBAAgB,iBAAiB,IAAI,iBAAiB,CAKrD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoralabs/protocol-sdk",
3
- "version": "0.11.3-COMMENTS.1",
3
+ "version": "0.11.3-COMMENTS.3",
4
4
  "repository": "https://github.com/ourzora/zora-protocol",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,10 +17,10 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "abitype": "^1.0.2",
20
- "@zoralabs/protocol-deployments": "^0.3.5-COMMENTS.1"
20
+ "@zoralabs/protocol-deployments": "^0.3.5-COMMENTS.3"
21
21
  },
22
22
  "peerDependencies": {
23
- "viem": "^2.13.2"
23
+ "viem": "^2.21.21"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@lavamoat/preinstall-always-fail": "2.0.0",
@@ -1,6 +1,6 @@
1
1
  import { describe, expect } from "vitest";
2
2
  import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
3
- import { base, zoraSepolia } from "viem/chains";
3
+ import { base, zora, zoraSepolia } from "viem/chains";
4
4
  import {
5
5
  commentsABI,
6
6
  commentsAddress,
@@ -10,6 +10,11 @@ import {
10
10
  sparkValue,
11
11
  CommentIdentifier,
12
12
  permitSparkCommentTypedDataDefinition,
13
+ permitTimedSaleMintAndCommentTypedDataDefinition,
14
+ PermitTimedSaleMintAndComment,
15
+ callerAndCommenterAddress as callerAndCommenterAddresses,
16
+ callerAndCommenterABI,
17
+ zoraCreator1155ImplABI,
13
18
  } from "@zoralabs/protocol-deployments";
14
19
  import {
15
20
  Address,
@@ -19,11 +24,12 @@ import {
19
24
  parseEther,
20
25
  TransactionReceipt,
21
26
  parseEventLogs,
27
+ hashTypedData,
22
28
  } from "viem";
23
29
  import { createCreatorClient } from "src/sdk";
24
30
  import { randomNewContract, waitForSuccess } from "src/test-utils";
25
- import { demoTokenMetadataURI } from "src/create/1155-create-helper.test";
26
31
  import { permitCommentTypedDataDefinition } from "@zoralabs/protocol-deployments";
32
+ import { demoTokenMetadataURI } from "src/fixtures/contract-setup";
27
33
 
28
34
  const getCommentIdentifierFromReceipt = (
29
35
  receipt: TransactionReceipt,
@@ -38,15 +44,17 @@ const getCommentIdentifierFromReceipt = (
38
44
  throw new Error("No Commented event found in receipt");
39
45
  }
40
46
 
41
- return logs[0]!.args.comment;
47
+ return logs[0]!.args.commentIdentifier;
42
48
  };
43
-
49
+ const randomNonce = () => keccak256(toBytes(Math.round(Math.random() * 1000)));
50
+ const thirtySecondsFromNow =
51
+ BigInt(Math.round(new Date().getTime() / 1000)) + 30n;
44
52
  // todo: move this to protocol-deployments
45
53
  describe("comments", () => {
46
54
  makeAnvilTest({
47
- forkUrl: forkUrls.zoraSepolia,
48
- forkBlockNumber: 14918747,
49
- anvilChainId: zoraSepolia.id,
55
+ forkUrl: forkUrls.zoraMainnet,
56
+ forkBlockNumber: 21297211,
57
+ anvilChainId: zora.id,
50
58
  })(
51
59
  "can sign and execute a cross-chain comment, and sign and execute a cross-chain spark comment",
52
60
  async ({
@@ -107,10 +115,9 @@ describe("comments", () => {
107
115
 
108
116
  // Set up cross-chain comment parameters
109
117
  const sourceChainId = base.id; // The chain ID where the comment originates
110
- const randomNonce = () =>
111
- keccak256(toBytes(Math.round(Math.random() * 1000)));
112
- const thirtySecondsFromNow =
113
- BigInt(Math.round(new Date().getTime() / 1000)) + 30n;
118
+
119
+ const commentsAddressForChainId =
120
+ commentsAddress[chainId as keyof typeof commentsAddress];
114
121
 
115
122
  // Step 3: Prepare a cross-chain comment
116
123
  const permitComment: PermitComment = {
@@ -123,21 +130,30 @@ describe("comments", () => {
123
130
  deadline: thirtySecondsFromNow,
124
131
  nonce: randomNonce(),
125
132
  referrer: zeroAddress,
133
+ commenterSmartWallet: zeroAddress,
126
134
  replyTo: emptyCommentIdentifier(),
127
135
  };
128
136
 
129
137
  // Generate typed data for signing
130
138
  const typedData = permitCommentTypedDataDefinition(permitComment);
131
139
 
132
- const commentsAddressForChainId =
133
- commentsAddress[chainId as keyof typeof commentsAddress];
134
-
135
- // Verify the typed data is correctly set up
136
140
  expect(typedData.domain!.chainId).toEqual(sourceChainId);
137
141
  expect(typedData.account).toEqual(collectorAddress);
138
142
  expect(typedData.domain!.verifyingContract).toEqual(
139
143
  commentsAddressForChainId,
140
144
  );
145
+ expect(typedData.domain!.verifyingContract).toEqual(
146
+ commentsAddressForChainId,
147
+ );
148
+
149
+ const hashed = await publicClient.readContract({
150
+ abi: commentsABI,
151
+ address: commentsAddressForChainId,
152
+ functionName: "hashPermitComment",
153
+ args: [permitComment],
154
+ });
155
+
156
+ expect(hashed).toEqual(hashTypedData(typedData));
141
157
 
142
158
  // Ensure the commenter has enough balance for the spark value
143
159
  await testClient.setBalance({
@@ -169,9 +185,7 @@ describe("comments", () => {
169
185
  hash: commentHash,
170
186
  });
171
187
 
172
- if (receipt.status !== "success") {
173
- expect(receipt.status).toBe("success");
174
- }
188
+ expect(receipt.status).toBe("success");
175
189
 
176
190
  // Extract the comment identifier from the transaction receipt
177
191
  const commentIdentifier = getCommentIdentifierFromReceipt(receipt);
@@ -218,6 +232,112 @@ describe("comments", () => {
218
232
 
219
233
  expect(sparkCount).toEqual(sparkComment.sparksQuantity);
220
234
  },
221
- 20_000,
235
+ 40_000,
236
+ );
237
+ makeAnvilTest({
238
+ forkUrl: forkUrls.zoraMainnet,
239
+ forkBlockNumber: 21297211,
240
+ anvilChainId: zora.id,
241
+ })(
242
+ "can sign and execute a cross-chain timed sale mint and comment",
243
+ async ({
244
+ viemClients: { publicClient, walletClient, chain, testClient },
245
+ }) => {
246
+ // Get the chain ID and set up addresses for different roles
247
+ const chainId = chain.id;
248
+ const [commenterAddress, executorAddress] =
249
+ (await walletClient.getAddresses()!) as [Address, Address, Address];
250
+
251
+ // Create a creator client for interacting with the protocol
252
+ const creatorClient = createCreatorClient({
253
+ chainId,
254
+ publicClient,
255
+ });
256
+
257
+ // Step 1: Create a new 1155 contract and token
258
+ const { contractAddress, newTokenId, parameters } =
259
+ await creatorClient.create1155({
260
+ contract: randomNewContract(),
261
+ token: {
262
+ tokenMetadataURI: demoTokenMetadataURI,
263
+ },
264
+ account: commenterAddress,
265
+ });
266
+
267
+ // Deploy the new contract
268
+ const { request } = await publicClient.simulateContract(parameters);
269
+ await writeContractWithRetries({
270
+ request,
271
+ walletClient,
272
+ publicClient,
273
+ });
274
+
275
+ // Step 2: Prepare the permit data for timed sale mint and comment
276
+ const thirtySecondsFromNow = BigInt(Math.floor(Date.now() / 1000) + 30);
277
+ const quantity = 3n;
278
+ const mintReferral = zeroAddress;
279
+ const comment = "This is a test comment for timed sale mint";
280
+
281
+ const permitTimedSaleMintAndComment: PermitTimedSaleMintAndComment = {
282
+ commenter: commenterAddress,
283
+ quantity,
284
+ collection: contractAddress,
285
+ tokenId: newTokenId,
286
+ mintReferral,
287
+ comment,
288
+ deadline: thirtySecondsFromNow,
289
+ nonce: randomNonce(),
290
+ sourceChainId: chainId,
291
+ destinationChainId: chainId,
292
+ };
293
+
294
+ // Step 3: Generate the typed data for signing
295
+ const typedData = permitTimedSaleMintAndCommentTypedDataDefinition(
296
+ permitTimedSaleMintAndComment,
297
+ );
298
+
299
+ // Step 4: Sign the typed data
300
+ const signature = await walletClient.signTypedData(typedData);
301
+
302
+ await testClient.setBalance({
303
+ address: executorAddress,
304
+ value: parseEther("1"),
305
+ });
306
+
307
+ // Step 5: Simulate and execute the permitTimedSaleMintAndComment function
308
+ const callerAndCommenterAddress =
309
+ callerAndCommenterAddresses[
310
+ chainId as keyof typeof callerAndCommenterAddresses
311
+ ];
312
+ const { request: permitRequest } = await publicClient.simulateContract({
313
+ abi: callerAndCommenterABI,
314
+ address: callerAndCommenterAddress,
315
+ functionName: "permitTimedSaleMintAndComment",
316
+ args: [permitTimedSaleMintAndComment, signature],
317
+ account: executorAddress,
318
+ value: quantity * parseEther("0.000111"),
319
+ });
320
+
321
+ const receipt = await writeContractWithRetries({
322
+ publicClient,
323
+ walletClient,
324
+ request: permitRequest,
325
+ });
326
+
327
+ // Step 6: Verify the comment was created
328
+ const commentIdentifier = getCommentIdentifierFromReceipt(receipt);
329
+ expect(commentIdentifier).toBeDefined();
330
+
331
+ // Step 7: Verify the token was minted
332
+ const balance = await publicClient.readContract({
333
+ abi: zoraCreator1155ImplABI,
334
+ address: contractAddress,
335
+ functionName: "balanceOf",
336
+ args: [commenterAddress, newTokenId],
337
+ });
338
+
339
+ expect(balance).toEqual(quantity);
340
+ },
341
+ 40_000, // Increased timeout to 30 seconds
222
342
  );
223
343
  });
@@ -5,7 +5,6 @@ import {
5
5
  } from "./1155-create-helper";
6
6
  import { createCreatorClient } from "src/sdk";
7
7
  import {
8
- zoraCreator1155FactoryImplAddress,
9
8
  zoraCreator1155ImplABI,
10
9
  zoraTimedSaleStrategyABI,
11
10
  zoraTimedSaleStrategyAddress,
@@ -23,10 +22,7 @@ import {
23
22
  DEFAULT_MARKET_COUNTDOWN,
24
23
  } from "./minter-defaults";
25
24
  import { randomNewContract } from "src/test-utils";
26
-
27
- export const demoTokenMetadataURI =
28
- "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u";
29
- export const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
25
+ import { demoTokenMetadataURI } from "src/fixtures/contract-setup";
30
26
 
31
27
  const anvilTest = makeAnvilTest({
32
28
  forkUrl: forkUrls.zoraMainnet,
@@ -95,10 +91,8 @@ describe("create-helper", () => {
95
91
  publicClient,
96
92
  });
97
93
  expect(receipt).not.toBeNull();
98
- expect(receipt.to).to.equal(
99
- zoraCreator1155FactoryImplAddress[
100
- chain.id as keyof typeof zoraCreator1155FactoryImplAddress
101
- ],
94
+ expect(receipt.to?.toLowerCase()).to.equal(
95
+ "0x777777c338d93e2c7adf08d102d45ca7cc4ed021".toLowerCase(),
102
96
  );
103
97
  expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n);
104
98
  expect(getContractAddressFromReceipt(receipt)).to.be.equal(
@@ -297,10 +291,9 @@ describe("create-helper", () => {
297
291
  walletClient,
298
292
  publicClient,
299
293
  });
300
- expect(receipt.to).to.equal(
301
- zoraCreator1155FactoryImplAddress[
302
- chain.id as keyof typeof zoraCreator1155FactoryImplAddress
303
- ],
294
+
295
+ expect(receipt.to?.toLowerCase()).to.equal(
296
+ "0x777777c338d93e2c7adf08d102d45ca7cc4ed021".toLowerCase(),
304
297
  );
305
298
  expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(newTokenId);
306
299
 
@@ -219,7 +219,7 @@ async function createNew1155ContractAndToken({
219
219
  });
220
220
 
221
221
  const contractAddress = await getDeterministicContractAddress({
222
- account,
222
+ account: typeof account === "string" ? account : account.address,
223
223
  publicClient,
224
224
  setupActions: tokenSetupActions,
225
225
  chainId,
@@ -327,7 +327,7 @@ function prepareSetupActions({
327
327
  setupActions: tokenSetupActions,
328
328
  } = constructCreate1155TokenCalls({
329
329
  chainId: chainId,
330
- ownerAddress: account,
330
+ ownerAddress: typeof account === "string" ? account : account.address,
331
331
  contractVersion,
332
332
  nextTokenId,
333
333
  ...token,
@@ -9,10 +9,9 @@ import {
9
9
  ConcreteSalesConfig,
10
10
  TimedSaleParamsType,
11
11
  } from "./types";
12
-
13
- // 200 mints worth of eth
14
- export const DEFAULT_MINIMUM_MARKET_ETH = 2220000000000000n;
15
-
12
+ import { parseEther } from "viem";
13
+ // 1111 mints worth of market reward eth - 0.0000111 eth * 1,111 = 0.0123321 eth
14
+ export const DEFAULT_MINIMUM_MARKET_ETH = parseEther("0.0123321");
16
15
  // 24 hour countdown
17
16
  export const DEFAULT_MARKET_COUNTDOWN = BigInt(24 * 60 * 60);
18
17
 
@@ -63,7 +63,7 @@ export type SalesConfigParamsType =
63
63
  | TimedSaleParamsType;
64
64
 
65
65
  export type CreateNew1155ParamsBase = {
66
- account: Address;
66
+ account: Address | Account;
67
67
  getAdditionalSetupActions?: (args: { tokenId: bigint }) => Hex[];
68
68
  token: CreateNew1155TokenProps;
69
69
  };
@@ -1,13 +1,13 @@
1
1
  import { Address, Chain, PublicClient, WalletClient } from "viem";
2
2
  import { simulateAndWriteContractWithRetries } from "src/anvil";
3
3
  import { createCreatorClient } from "src/sdk";
4
- import {
5
- demoContractMetadataURI,
6
- demoTokenMetadataURI,
7
- } from "src/create/1155-create-helper.test";
8
4
  import { SubgraphMintGetter } from "src/mint/subgraph-mint-getter";
9
5
  import { SubgraphRewardsGetter } from "../rewards/subgraph-rewards-getter";
10
6
 
7
+ export const demoTokenMetadataURI =
8
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u";
9
+ export const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
10
+
11
11
  export async function setupContractAndToken({
12
12
  chain,
13
13
  publicClient,
@@ -0,0 +1,69 @@
1
+ import { Address, Account, PublicClient, TestClient, WalletClient } from "viem";
2
+ import { CollectorClient } from "../sdk";
3
+ import { simulateAndWriteContractWithRetries } from "../anvil";
4
+ import { makeContractParameters } from "../utils";
5
+ import {
6
+ zoraTimedSaleStrategyABI,
7
+ zoraTimedSaleStrategyAddress,
8
+ } from "@zoralabs/protocol-deployments";
9
+
10
+ export async function advanceToSaleAndAndLaunchMarket({
11
+ contractAddress,
12
+ tokenId,
13
+ testClient,
14
+ publicClient,
15
+ walletClient,
16
+ collectorClient,
17
+ chainId,
18
+ account,
19
+ }: {
20
+ contractAddress: Address;
21
+ tokenId: bigint;
22
+ testClient: TestClient;
23
+ publicClient: PublicClient;
24
+ walletClient: WalletClient;
25
+ collectorClient: CollectorClient;
26
+ chainId: number;
27
+ account: Address | Account;
28
+ }) {
29
+ const saleInfo = await collectorClient.getSecondaryInfo({
30
+ contract: contractAddress,
31
+ tokenId,
32
+ });
33
+
34
+ if (!saleInfo) {
35
+ throw new Error("Sale not set");
36
+ }
37
+
38
+ if (!saleInfo.saleEnd) {
39
+ throw new Error("Sale end not set");
40
+ }
41
+
42
+ const saleEnd = saleInfo.saleEnd;
43
+
44
+ // advance to end of sale
45
+ await testClient.setNextBlockTimestamp({
46
+ timestamp: saleEnd,
47
+ });
48
+
49
+ await testClient.mine({
50
+ blocks: 1,
51
+ });
52
+
53
+ // advance to end of sale
54
+ // launch the market
55
+ await simulateAndWriteContractWithRetries({
56
+ parameters: makeContractParameters({
57
+ abi: zoraTimedSaleStrategyABI,
58
+ functionName: "launchMarket",
59
+ args: [contractAddress, tokenId],
60
+ address:
61
+ zoraTimedSaleStrategyAddress[
62
+ chainId as keyof typeof zoraTimedSaleStrategyAddress
63
+ ],
64
+ account: account,
65
+ }),
66
+ publicClient,
67
+ walletClient,
68
+ });
69
+ }
@@ -180,7 +180,7 @@ function getTargetStrategy({
180
180
  );
181
181
 
182
182
  const stillValidSalesStrategies = parsedStrategies.filter(
183
- (strategy) => strategy.saleActive,
183
+ (strategy) => strategy.saleActive || strategy.secondaryMarketActive,
184
184
  );
185
185
 
186
186
  const saleStrategies = stillValidSalesStrategies.sort((a, b) =>
@@ -18,7 +18,7 @@ import {
18
18
  import { makeContractParameters } from "src/utils";
19
19
  import { mockRewardsQueryResults } from "src/fixtures/rewards-query-results";
20
20
  import { setupContractAndToken } from "src/fixtures/contract-setup";
21
- import { advanceToSaleAndAndLaunchMarket } from "src/secondary/secondary-client.test";
21
+ import { advanceToSaleAndAndLaunchMarket } from "src/fixtures/secondary";
22
22
 
23
23
  describe("rewardsClient", () => {
24
24
  makeAnvilTest({
@@ -146,7 +146,7 @@ describe("rewardsClient", () => {
146
146
  value: parseEther("100"),
147
147
  });
148
148
 
149
- const quantityToMint = 10_000n;
149
+ const quantityToMint = 1111n;
150
150
 
151
151
  mintGetter.subgraphQuerier.query = vi
152
152
  .fn<ISubgraphQuerier["query"]>()
@@ -1,12 +1,5 @@
1
1
  import { describe, expect, vi } from "vitest";
2
- import {
3
- Address,
4
- parseEther,
5
- PublicClient,
6
- TestClient,
7
- WalletClient,
8
- Account,
9
- } from "viem";
2
+ import { parseEther } from "viem";
10
3
  import { zoraSepolia } from "viem/chains";
11
4
  import {
12
5
  forkUrls,
@@ -14,69 +7,13 @@ import {
14
7
  simulateAndWriteContractWithRetries,
15
8
  } from "src/anvil";
16
9
  import { createCollectorClient } from "src/sdk";
17
- import {
18
- zoraCreator1155ImplABI,
19
- zoraTimedSaleStrategyABI,
20
- zoraTimedSaleStrategyAddress,
21
- } from "@zoralabs/protocol-deployments";
22
- import { makeContractParameters } from "src/utils";
10
+ import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
23
11
  import { setupContractAndToken } from "src/fixtures/contract-setup";
24
- import { CollectorClient } from "src/sdk";
25
12
  import { ERROR_SECONDARY_NOT_STARTED } from "./secondary-client";
26
13
  import { ISubgraphQuerier } from "src/apis/subgraph-querier";
27
14
  import { mockTimedSaleStrategyTokenQueryResult } from "src/fixtures/mint-query-results";
28
15
  import { new1155ContractVersion } from "src/create/contract-setup";
29
-
30
- export async function advanceToSaleAndAndLaunchMarket({
31
- contractAddress,
32
- tokenId,
33
- testClient,
34
- publicClient,
35
- walletClient,
36
- collectorClient,
37
- chainId,
38
- account,
39
- }: {
40
- contractAddress: Address;
41
- tokenId: bigint;
42
- testClient: TestClient;
43
- publicClient: PublicClient;
44
- walletClient: WalletClient;
45
- collectorClient: CollectorClient;
46
- chainId: number;
47
- account: Address | Account;
48
- }) {
49
- const saleEnd = (await collectorClient.getSecondaryInfo({
50
- contract: contractAddress,
51
- tokenId,
52
- }))!.saleEnd!;
53
-
54
- // advance to end of sale
55
- await testClient.setNextBlockTimestamp({
56
- timestamp: saleEnd,
57
- });
58
-
59
- await testClient.mine({
60
- blocks: 1,
61
- });
62
-
63
- // advance to end of sale
64
- // launch the market
65
- await simulateAndWriteContractWithRetries({
66
- parameters: makeContractParameters({
67
- abi: zoraTimedSaleStrategyABI,
68
- functionName: "launchMarket",
69
- args: [contractAddress, tokenId],
70
- address:
71
- zoraTimedSaleStrategyAddress[
72
- chainId as keyof typeof zoraTimedSaleStrategyAddress
73
- ],
74
- account: account,
75
- }),
76
- publicClient,
77
- walletClient,
78
- });
79
- }
16
+ import { advanceToSaleAndAndLaunchMarket } from "src/fixtures/secondary";
80
17
 
81
18
  describe("secondary", () => {
82
19
  makeAnvilTest({
@@ -152,8 +89,6 @@ describe("secondary", () => {
152
89
  value: parseEther("100"),
153
90
  });
154
91
 
155
- const quantityToMint = 100_000n;
156
-
157
92
  mintGetter.subgraphQuerier.query = vi
158
93
  .fn<ISubgraphQuerier["query"]>()
159
94
  .mockResolvedValue({
@@ -174,10 +109,13 @@ describe("secondary", () => {
174
109
  mintGetter,
175
110
  });
176
111
 
112
+ // mint 1 less than expected minimum market.
113
+ // make sure that there is no sale end
177
114
  const { parameters: collectParameters } = await collectorClient.mint({
178
115
  minterAccount: collectorAccount,
179
116
  mintType: "1155",
180
- quantityToMint,
117
+ // mint 1 less than expected minimum market.
118
+ quantityToMint: 1111n - 1n,
181
119
  tokenId: newTokenId,
182
120
  tokenContract: contractAddress,
183
121
  });
@@ -188,6 +126,37 @@ describe("secondary", () => {
188
126
  publicClient,
189
127
  });
190
128
 
129
+ // make sure that there is no sale end
130
+ let saleEnd = (await collectorClient.getSecondaryInfo({
131
+ contract: contractAddress,
132
+ tokenId: newTokenId,
133
+ }))!.saleEnd;
134
+
135
+ expect(saleEnd).toBeUndefined();
136
+
137
+ // mint 1 more - this should cause the countdown to start
138
+ const { parameters: collectMoreParameters } = await collectorClient.mint({
139
+ minterAccount: collectorAccount,
140
+ mintType: "1155",
141
+ quantityToMint: 1n,
142
+ tokenId: newTokenId,
143
+ tokenContract: contractAddress,
144
+ });
145
+
146
+ await simulateAndWriteContractWithRetries({
147
+ parameters: collectMoreParameters,
148
+ walletClient,
149
+ publicClient,
150
+ });
151
+
152
+ // now there should be a sale end
153
+ saleEnd = (await collectorClient.getSecondaryInfo({
154
+ contract: contractAddress,
155
+ tokenId: newTokenId,
156
+ }))!.saleEnd;
157
+
158
+ expect(saleEnd).toBeDefined();
159
+
191
160
  await advanceToSaleAndAndLaunchMarket({
192
161
  contractAddress,
193
162
  tokenId: newTokenId,
@@ -276,7 +245,7 @@ describe("secondary", () => {
276
245
  args: [collectorAccount, newTokenId],
277
246
  });
278
247
 
279
- expect(balance).toBe(quantityToMint + quantityToBuy - quantityToSell);
248
+ expect(balance).toBe(1111n + quantityToBuy - quantityToSell);
280
249
  },
281
250
  30_000,
282
251
  );
package/src/test-utils.ts CHANGED
@@ -18,6 +18,8 @@ export const waitForSuccess = async (hash: Hex, publicClient: PublicClient) => {
18
18
  });
19
19
 
20
20
  expect(receipt.status).toBe("success");
21
+
22
+ return receipt;
21
23
  };
22
24
 
23
25
  export const getFixedPricedMinter = async ({
@@ -1,3 +0,0 @@
1
- export declare const demoTokenMetadataURI = "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u";
2
- export declare const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
3
- //# sourceMappingURL=1155-create-helper.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"1155-create-helper.test.d.ts","sourceRoot":"","sources":["../../src/create/1155-create-helper.test.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,oBAAoB,uEACqC,CAAC;AACvE,eAAO,MAAM,uBAAuB,+BAA+B,CAAC"}