@zoralabs/protocol-sdk 0.11.3-COMMENTS.0 → 0.11.3-COMMENTS.1

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,5 +1,5 @@
1
1
 
2
- > @zoralabs/protocol-sdk@0.11.3-COMMENTS.0 build /home/runner/work/zora-protocol-private/zora-protocol-private/packages/protocol-sdk
2
+ > @zoralabs/protocol-sdk@0.11.3-COMMENTS.1 build /home/runner/work/zora-protocol-private/zora-protocol-private/packages/protocol-sdk
3
3
  > pnpm tsup
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -12,7 +12,7 @@ CJS Build start
12
12
  ESM Build start
13
13
  ESM dist/index.js 217.84 KB
14
14
  ESM dist/index.js.map 452.19 KB
15
- ESM ⚡️ Build success in 323ms
15
+ ESM ⚡️ Build success in 294ms
16
16
  CJS dist/index.cjs 224.10 KB
17
17
  CJS dist/index.cjs.map 454.19 KB
18
- CJS ⚡️ Build success in 328ms
18
+ CJS ⚡️ Build success in 352ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @zoralabs/protocol-sdk
2
2
 
3
+ ## 0.11.3-COMMENTS.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a8b21987]
8
+ - @zoralabs/protocol-deployments@0.3.5-COMMENTS.1
9
+
3
10
  ## 0.11.3-COMMENTS.0
4
11
 
5
12
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"1155-create-helper.test.d.ts","sourceRoot":"","sources":["../../src/create/1155-create-helper.test.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,oBAAoB,uEACqC,CAAC;AACvE,eAAO,MAAM,uBAAuB,+BAA+B,CAAC"}
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"}
@@ -1,5 +1,6 @@
1
1
  import { zoraCreator1155FactoryImplAddress } from "@zoralabs/protocol-deployments";
2
2
  import { Address, Hex, PublicClient } from "viem";
3
+ import { NewContractParams } from "./create/types";
3
4
  export declare const waitForSuccess: (hash: Hex, publicClient: PublicClient) => Promise<void>;
4
5
  export declare const getFixedPricedMinter: ({ publicClient, chainId, }: {
5
6
  publicClient: PublicClient;
@@ -8,4 +9,5 @@ export declare const getFixedPricedMinter: ({ publicClient, chainId, }: {
8
9
  export declare const fixedPriceMinterMinterArguments: ({ mintRecipient, }: {
9
10
  mintRecipient: Address;
10
11
  }) => `0x${string}`;
12
+ export declare function randomNewContract(): NewContractParams;
11
13
  //# sourceMappingURL=test-utils.d.ts.map
@@ -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;AAGd,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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoralabs/protocol-sdk",
3
- "version": "0.11.3-COMMENTS.0",
3
+ "version": "0.11.3-COMMENTS.1",
4
4
  "repository": "https://github.com/ourzora/zora-protocol",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "abitype": "^1.0.2",
20
- "@zoralabs/protocol-deployments": "^0.3.5-COMMENTS.0"
20
+ "@zoralabs/protocol-deployments": "^0.3.5-COMMENTS.1"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "viem": "^2.13.2"
@@ -0,0 +1,223 @@
1
+ import { describe, expect } from "vitest";
2
+ import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
3
+ import { base, zoraSepolia } from "viem/chains";
4
+ import {
5
+ commentsABI,
6
+ commentsAddress,
7
+ emptyCommentIdentifier,
8
+ PermitComment,
9
+ PermitSparkComment,
10
+ sparkValue,
11
+ CommentIdentifier,
12
+ permitSparkCommentTypedDataDefinition,
13
+ } from "@zoralabs/protocol-deployments";
14
+ import {
15
+ Address,
16
+ keccak256,
17
+ toBytes,
18
+ zeroAddress,
19
+ parseEther,
20
+ TransactionReceipt,
21
+ parseEventLogs,
22
+ } from "viem";
23
+ import { createCreatorClient } from "src/sdk";
24
+ import { randomNewContract, waitForSuccess } from "src/test-utils";
25
+ import { demoTokenMetadataURI } from "src/create/1155-create-helper.test";
26
+ import { permitCommentTypedDataDefinition } from "@zoralabs/protocol-deployments";
27
+
28
+ const getCommentIdentifierFromReceipt = (
29
+ receipt: TransactionReceipt,
30
+ ): CommentIdentifier => {
31
+ const logs = parseEventLogs({
32
+ abi: commentsABI,
33
+ logs: receipt.logs,
34
+ eventName: "Commented",
35
+ });
36
+
37
+ if (logs.length === 0) {
38
+ throw new Error("No Commented event found in receipt");
39
+ }
40
+
41
+ return logs[0]!.args.comment;
42
+ };
43
+
44
+ // todo: move this to protocol-deployments
45
+ describe("comments", () => {
46
+ makeAnvilTest({
47
+ forkUrl: forkUrls.zoraSepolia,
48
+ forkBlockNumber: 14918747,
49
+ anvilChainId: zoraSepolia.id,
50
+ })(
51
+ "can sign and execute a cross-chain comment, and sign and execute a cross-chain spark comment",
52
+ async ({
53
+ viemClients: { publicClient, walletClient, chain, testClient },
54
+ }) => {
55
+ // Get the chain ID and set up addresses for different roles
56
+ const chainId = chain.id;
57
+ const [
58
+ collectorAddress,
59
+ creatorAddress,
60
+ executorAddress,
61
+ sparkerAddress,
62
+ ] = (await walletClient.getAddresses()!) as [
63
+ Address,
64
+ Address,
65
+ Address,
66
+ Address,
67
+ ];
68
+
69
+ // Create a creator client for interacting with the protocol
70
+ const creatorClient = createCreatorClient({
71
+ chainId,
72
+ publicClient,
73
+ });
74
+
75
+ // Step 1: Create a new 1155 contract and token
76
+ const { contractAddress, newTokenId, parameters, prepareMint } =
77
+ await creatorClient.create1155({
78
+ contract: randomNewContract(),
79
+ token: {
80
+ tokenMetadataURI: demoTokenMetadataURI,
81
+ },
82
+ account: creatorAddress,
83
+ });
84
+
85
+ // Deploy the new contract
86
+ const { request } = await publicClient.simulateContract(parameters);
87
+ await writeContractWithRetries({
88
+ request,
89
+ walletClient,
90
+ publicClient,
91
+ });
92
+
93
+ // Prepare to mint a token
94
+ const { parameters: collectParameters } = await prepareMint({
95
+ quantityToMint: 1n,
96
+ minterAccount: collectorAddress,
97
+ });
98
+
99
+ // Step 2: Mint an 1155 token on the new contract
100
+ const { request: mintRequest } =
101
+ await publicClient.simulateContract(collectParameters);
102
+ await writeContractWithRetries({
103
+ request: mintRequest,
104
+ walletClient,
105
+ publicClient,
106
+ });
107
+
108
+ // Set up cross-chain comment parameters
109
+ 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;
114
+
115
+ // Step 3: Prepare a cross-chain comment
116
+ const permitComment: PermitComment = {
117
+ sourceChainId,
118
+ contractAddress,
119
+ destinationChainId: chainId,
120
+ tokenId: newTokenId,
121
+ commenter: collectorAddress,
122
+ text: "hello world",
123
+ deadline: thirtySecondsFromNow,
124
+ nonce: randomNonce(),
125
+ referrer: zeroAddress,
126
+ replyTo: emptyCommentIdentifier(),
127
+ };
128
+
129
+ // Generate typed data for signing
130
+ const typedData = permitCommentTypedDataDefinition(permitComment);
131
+
132
+ const commentsAddressForChainId =
133
+ commentsAddress[chainId as keyof typeof commentsAddress];
134
+
135
+ // Verify the typed data is correctly set up
136
+ expect(typedData.domain!.chainId).toEqual(sourceChainId);
137
+ expect(typedData.account).toEqual(collectorAddress);
138
+ expect(typedData.domain!.verifyingContract).toEqual(
139
+ commentsAddressForChainId,
140
+ );
141
+
142
+ // Ensure the commenter has enough balance for the spark value
143
+ await testClient.setBalance({
144
+ address: collectorAddress,
145
+ value: sparkValue(),
146
+ });
147
+
148
+ // Step 4: Sign the cross-chain comment
149
+ const signature = await walletClient.signTypedData(typedData);
150
+
151
+ // Ensure the executor has enough balance to execute the transaction
152
+ await testClient.setBalance({
153
+ address: executorAddress,
154
+ value: parseEther("1"),
155
+ });
156
+
157
+ // Step 5: Simulate and execute the cross-chain comment
158
+ const { request: commentRequest } = await publicClient.simulateContract({
159
+ abi: commentsABI,
160
+ address: commentsAddressForChainId,
161
+ functionName: "permitComment",
162
+ args: [permitComment, signature],
163
+ account: executorAddress,
164
+ value: sparkValue(),
165
+ });
166
+
167
+ const commentHash = await walletClient.writeContract(commentRequest);
168
+ const receipt = await publicClient.waitForTransactionReceipt({
169
+ hash: commentHash,
170
+ });
171
+
172
+ if (receipt.status !== "success") {
173
+ expect(receipt.status).toBe("success");
174
+ }
175
+
176
+ // Extract the comment identifier from the transaction receipt
177
+ const commentIdentifier = getCommentIdentifierFromReceipt(receipt);
178
+
179
+ // Step 6: Prepare a spark (like) for the comment
180
+ const sparkComment: PermitSparkComment = {
181
+ sparksQuantity: 3n,
182
+ sparker: sparkerAddress,
183
+ deadline: thirtySecondsFromNow,
184
+ nonce: randomNonce(),
185
+ referrer: zeroAddress,
186
+ sourceChainId,
187
+ destinationChainId: chainId,
188
+ comment: commentIdentifier,
189
+ };
190
+
191
+ const sparkTypedData =
192
+ permitSparkCommentTypedDataDefinition(sparkComment);
193
+
194
+ // Step 7: Sign the spark comment
195
+ const sparkSignature = await walletClient.signTypedData(sparkTypedData);
196
+
197
+ // Step 8: Simulate and execute the spark comment
198
+ const { request: sparkRequest } = await publicClient.simulateContract({
199
+ abi: commentsABI,
200
+ address: commentsAddressForChainId,
201
+ functionName: "permitSparkComment",
202
+ args: [sparkComment, sparkSignature],
203
+ account: executorAddress,
204
+ value: sparkValue() * sparkComment.sparksQuantity,
205
+ });
206
+
207
+ const sparkHash = await walletClient.writeContract(sparkRequest);
208
+
209
+ await waitForSuccess(sparkHash, publicClient);
210
+
211
+ // Step 9: Verify the spark count
212
+ const sparkCount = await publicClient.readContract({
213
+ abi: commentsABI,
214
+ address: commentsAddressForChainId,
215
+ functionName: "commentSparksQuantity",
216
+ args: [commentIdentifier],
217
+ });
218
+
219
+ expect(sparkCount).toEqual(sparkComment.sparksQuantity);
220
+ },
221
+ 20_000,
222
+ );
223
+ });
@@ -5,6 +5,7 @@ import {
5
5
  } from "./1155-create-helper";
6
6
  import { createCreatorClient } from "src/sdk";
7
7
  import {
8
+ zoraCreator1155FactoryImplAddress,
8
9
  zoraCreator1155ImplABI,
9
10
  zoraTimedSaleStrategyABI,
10
11
  zoraTimedSaleStrategyAddress,
@@ -16,12 +17,12 @@ import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
16
17
  import { zora } from "viem/chains";
17
18
  import { AllowList } from "src/allow-list/types";
18
19
  import { createAllowList } from "src/allow-list/allow-list-client";
19
- import { NewContractParams } from "./types";
20
20
  import { SubgraphContractGetter } from "./contract-getter";
21
21
  import {
22
22
  DEFAULT_MINIMUM_MARKET_ETH,
23
23
  DEFAULT_MARKET_COUNTDOWN,
24
24
  } from "./minter-defaults";
25
+ import { randomNewContract } from "src/test-utils";
25
26
 
26
27
  export const demoTokenMetadataURI =
27
28
  "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u";
@@ -56,13 +57,6 @@ const minterIsMinterOnToken = async ({
56
57
  });
57
58
  };
58
59
 
59
- function randomNewContract(): NewContractParams {
60
- return {
61
- name: `testContract-${Math.round(Math.random() * 1_000_000)}`,
62
- uri: demoContractMetadataURI,
63
- };
64
- }
65
-
66
60
  describe("create-helper", () => {
67
61
  anvilTest(
68
62
  "when no sales config is provided, it creates a new 1155 contract and token using the timed sale strategy",
@@ -101,7 +95,11 @@ describe("create-helper", () => {
101
95
  publicClient,
102
96
  });
103
97
  expect(receipt).not.toBeNull();
104
- expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
98
+ expect(receipt.to).to.equal(
99
+ zoraCreator1155FactoryImplAddress[
100
+ chain.id as keyof typeof zoraCreator1155FactoryImplAddress
101
+ ],
102
+ );
105
103
  expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n);
106
104
  expect(getContractAddressFromReceipt(receipt)).to.be.equal(
107
105
  contractAddress,
@@ -299,7 +297,11 @@ describe("create-helper", () => {
299
297
  walletClient,
300
298
  publicClient,
301
299
  });
302
- expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
300
+ expect(receipt.to).to.equal(
301
+ zoraCreator1155FactoryImplAddress[
302
+ chain.id as keyof typeof zoraCreator1155FactoryImplAddress
303
+ ],
304
+ );
303
305
  expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(newTokenId);
304
306
 
305
307
  expect(
package/src/test-utils.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  encodeAbiParameters,
10
10
  parseAbiParameters,
11
11
  } from "viem";
12
+ import { NewContractParams } from "./create/types";
12
13
  import { expect } from "vitest";
13
14
 
14
15
  export const waitForSuccess = async (hash: Hex, publicClient: PublicClient) => {
@@ -37,3 +38,12 @@ export const fixedPriceMinterMinterArguments = ({
37
38
  }: {
38
39
  mintRecipient: Address;
39
40
  }) => encodeAbiParameters(parseAbiParameters("address"), [mintRecipient]);
41
+
42
+ const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
43
+
44
+ export function randomNewContract(): NewContractParams {
45
+ return {
46
+ name: `testContract-${Math.round(Math.random() * 1_000_000)}`,
47
+ uri: demoContractMetadataURI,
48
+ };
49
+ }