@zoralabs/protocol-deployments 0.3.4 → 0.3.5-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.
package/src/typedData.ts CHANGED
@@ -11,11 +11,13 @@ import {
11
11
  getAbiItem,
12
12
  keccak256,
13
13
  toHex,
14
+ parseEther,
14
15
  } from "viem";
15
16
  import {
16
17
  zoraMints1155Address,
17
18
  iPremintDefinitionsABI,
18
19
  sponsoredSparksSpenderAddress,
20
+ commentsAddress,
19
21
  } from "./generated/wagmi";
20
22
  import {
21
23
  PremintConfigEncoded,
@@ -27,6 +29,8 @@ import {
27
29
  TokenCreationConfigV1,
28
30
  TokenCreationConfigV2,
29
31
  TokenCreationConfigV3,
32
+ PermitComment,
33
+ PermitSparkComment,
30
34
  } from "./types";
31
35
 
32
36
  const premintTypedDataDomain = ({
@@ -413,3 +417,123 @@ export const sponsoredSparksBatchTypedDataDefinition = ({
413
417
  verifyingContract: sponsoredSparksSpenderAddress[chainId],
414
418
  },
415
419
  });
420
+
421
+ const commentIdentifierType = [
422
+ { name: "contractAddress", type: "address" },
423
+ { name: "tokenId", type: "uint256" },
424
+ { name: "commenter", type: "address" },
425
+ { name: "nonce", type: "bytes32" },
426
+ ] as const;
427
+
428
+ const permitCommentTypedDataType = {
429
+ PermitComment: [
430
+ { name: "contractAddress", type: "address" },
431
+ { name: "tokenId", type: "uint256" },
432
+ { name: "commenter", type: "address" },
433
+ { name: "replyTo", type: "CommentIdentifier" },
434
+ { name: "text", type: "string" },
435
+ { name: "deadline", type: "uint256" },
436
+ { name: "nonce", type: "bytes32" },
437
+ { name: "referrer", type: "address" },
438
+ { name: "sourceChainId", type: "uint32" },
439
+ { name: "destinationChainId", type: "uint32" },
440
+ ],
441
+ CommentIdentifier: commentIdentifierType,
442
+ } as const;
443
+
444
+ const permitSparkCommentTypedDataType = {
445
+ PermitSparkComment: [
446
+ { name: "comment", type: "CommentIdentifier" },
447
+ { name: "sparker", type: "address" },
448
+ { name: "sparksQuantity", type: "uint64" },
449
+ { name: "deadline", type: "uint256" },
450
+ { name: "nonce", type: "bytes32" },
451
+ { name: "referrer", type: "address" },
452
+ { name: "sourceChainId", type: "uint32" },
453
+ { name: "destinationChainId", type: "uint32" },
454
+ ],
455
+ CommentIdentifier: commentIdentifierType,
456
+ } as const;
457
+
458
+ const commentsDomain = ({
459
+ signingChainId,
460
+ destinationChainId,
461
+ }: {
462
+ signingChainId: number;
463
+ destinationChainId: keyof typeof commentsAddress;
464
+ }): TypedDataDomain => ({
465
+ chainId: signingChainId,
466
+ name: "Comments",
467
+ version: "1",
468
+ verifyingContract: commentsAddress[destinationChainId]!,
469
+ });
470
+
471
+ /**
472
+ * Generates the typed data definition for a permit comment, for cross-chain commenting.
473
+ *
474
+ * The permit allows a user to sign a comment message on one chain, which can then be
475
+ * submitted by anyone on the destination chain to execute the comment action.
476
+ *
477
+ * The permit includes details such as the comment text, the commenter's address,
478
+ * the comment being replied to, and chain IDs for the source and destination chains.
479
+ *
480
+ * The typed data is generated in a way that makes the signature happen on the source chain
481
+ * but be valid to be executed on the destination chain.
482
+ *
483
+ * @param message - The {@link PermitComment} containing the details of the comment permit.
484
+ * @returns A {@link TypedDataDefinition} object compatible with EIP-712 for structured data hashing and signing,
485
+ * including types, message, primary type, domain, and the signer's account address, which is
486
+ * the commenter's address.
487
+ */
488
+ export const permitCommentTypedDataDefinition = (
489
+ message: PermitComment,
490
+ ): TypedDataDefinition<typeof permitCommentTypedDataType, "PermitComment"> & {
491
+ account: Address;
492
+ } => ({
493
+ types: permitCommentTypedDataType,
494
+ message,
495
+ primaryType: "PermitComment",
496
+ domain: commentsDomain({
497
+ signingChainId: message.sourceChainId,
498
+ destinationChainId:
499
+ message.destinationChainId as keyof typeof commentsAddress,
500
+ }),
501
+ account: message.commenter,
502
+ });
503
+
504
+ /**
505
+ * Generates the typed data definition for a permit spark comment, for cross-chain sparking (liking with value) of comments.
506
+ *
507
+ * The permit allows a user to sign a spark comment message on one chain, which can then be
508
+ * submitted by anyone on the destination chain to execute the spark action.
509
+ *
510
+ * The permit includes details such as the comment to be sparked, the sparker's address,
511
+ * the quantity of sparks, and the source and destination chain ids.
512
+ *
513
+ * The typed data is generated in a way that makes the signature happen on the source chain
514
+ * but be valid to be executed on the destination chain.
515
+ *
516
+ * @param message - The {@link PermitSparkComment} containing the details of the spark comment permit.
517
+ * @returns A {@link TypedDataDefinition} object compatible with EIP-712 for structured data hashing and signing,
518
+ * including types, message, primary type, domain, and the signer's account address, which is
519
+ * the sparker's address.
520
+ */
521
+ export const permitSparkCommentTypedDataDefinition = (
522
+ message: PermitSparkComment,
523
+ ): TypedDataDefinition<
524
+ typeof permitSparkCommentTypedDataType,
525
+ "PermitSparkComment"
526
+ > & { account: Address } => ({
527
+ types: permitSparkCommentTypedDataType,
528
+ message,
529
+ primaryType: "PermitSparkComment",
530
+ domain: commentsDomain({
531
+ signingChainId: message.sourceChainId,
532
+ destinationChainId:
533
+ message.destinationChainId as keyof typeof commentsAddress,
534
+ }),
535
+ account: message.sparker,
536
+ });
537
+
538
+ // todo: explain
539
+ export const sparkValue = () => parseEther("0.000001");
package/src/types.ts CHANGED
@@ -7,6 +7,8 @@ import {
7
7
  } from "./generated/wagmi";
8
8
  import { Address } from "viem";
9
9
 
10
+ import { commentsABI } from "./generated/wagmi";
11
+
10
12
  export enum PremintConfigVersion {
11
13
  V1 = "1",
12
14
  V2 = "2",
@@ -121,3 +123,43 @@ export type SponsoredSparksBatch = AbiParametersToPrimitiveTypes<
121
123
  "hashSponsoredMint"
122
124
  >["inputs"]
123
125
  >[0];
126
+
127
+ export type CommentIdentifier = AbiParametersToPrimitiveTypes<
128
+ ExtractAbiFunction<typeof commentsABI, "hashCommentIdentifier">["inputs"]
129
+ >[0];
130
+
131
+ export const emptyCommentIdentifier = (): CommentIdentifier => {
132
+ const zeroAddress = "0x0000000000000000000000000000000000000000";
133
+ const zeroHash =
134
+ "0x0000000000000000000000000000000000000000000000000000000000000000";
135
+ return {
136
+ commenter: zeroAddress,
137
+ contractAddress: zeroAddress,
138
+ tokenId: 0n,
139
+ nonce: zeroHash,
140
+ };
141
+ };
142
+
143
+ /**
144
+ * The PermitComment type represents the data structure for a permit comment,
145
+ * for cross-chain commenting, where a user can sign a comment message on one chain,
146
+ * which can then be submitted by anyone on the destination chain to execute the comment action.
147
+ *
148
+ * The permit includes details such as the comment text, the commenter's address,
149
+ * the comment being replied to, and chain IDs for the source and destination chains.
150
+ */
151
+ export type PermitComment = AbiParametersToPrimitiveTypes<
152
+ ExtractAbiFunction<typeof commentsABI, "hashPermitComment">["inputs"]
153
+ >[0];
154
+
155
+ /**
156
+ * The PermitSparkComment type represents the data structure for a permit spark comment,
157
+ * for cross-chain sparking (liking with value) of comments, where a user can sign a spark comment message on one chain,
158
+ * which can then be submitted by anyone on the destination chain to execute the spark action.
159
+ *
160
+ * The permit includes details such as the comment to be sparked, the sparker's address,
161
+ * the quantity of sparks, and chain IDs for the source and destination chains.
162
+ */
163
+ export type PermitSparkComment = AbiParametersToPrimitiveTypes<
164
+ ExtractAbiFunction<typeof commentsABI, "hashPermitSparkComment">["inputs"]
165
+ >[0];