@zoralabs/protocol-deployments 0.3.8 → 0.3.9

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,14 @@ 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,
21
+ callerAndCommenterAddress,
19
22
  } from "./generated/wagmi";
20
23
  import {
21
24
  PremintConfigEncoded,
@@ -27,6 +30,10 @@ import {
27
30
  TokenCreationConfigV1,
28
31
  TokenCreationConfigV2,
29
32
  TokenCreationConfigV3,
33
+ PermitComment,
34
+ PermitSparkComment,
35
+ PermitMintAndComment,
36
+ PermitBuyOnSecondaryAndComment,
30
37
  } from "./types";
31
38
 
32
39
  const premintTypedDataDomain = ({
@@ -413,3 +420,258 @@ export const sponsoredSparksBatchTypedDataDefinition = ({
413
420
  verifyingContract: sponsoredSparksSpenderAddress[chainId],
414
421
  },
415
422
  });
423
+
424
+ const commentIdentifierType = [
425
+ { name: "contractAddress", type: "address" },
426
+ { name: "tokenId", type: "uint256" },
427
+ { name: "commenter", type: "address" },
428
+ { name: "nonce", type: "bytes32" },
429
+ ] as const;
430
+
431
+ const commentsDomain = ({
432
+ signingChainId,
433
+ destinationChainId,
434
+ }: {
435
+ signingChainId: number;
436
+ destinationChainId: keyof typeof commentsAddress;
437
+ }): TypedDataDomain => ({
438
+ chainId: signingChainId,
439
+ name: "Comments",
440
+ version: "1",
441
+ verifyingContract: commentsAddress[destinationChainId]!,
442
+ });
443
+
444
+ /**
445
+ * Generates the typed data definition for a permit comment, for cross-chain commenting.
446
+ *
447
+ * The permit allows a user to sign a comment message on one chain, which can then be
448
+ * submitted by anyone on the destination chain to execute the comment action.
449
+ *
450
+ * The permit includes details such as the comment text, the commenter's address,
451
+ * the comment being replied to, and chain IDs for the source and destination chains.
452
+ *
453
+ * The typed data is generated in a way that makes the signature happen on the source chain
454
+ * but be valid to be executed on the destination chain.
455
+ *
456
+ * @param message - The {@link PermitComment} containing the details of the comment permit.
457
+ * @param signingAccount - (optional) The account that is signing the message, if different thatn the commentor.
458
+ * Only needed if the commentor is a smart wallet; in this case the signing account should be an account
459
+ * that is one of the smart wallet owners.
460
+ * @returns A {@link TypedDataDefinition} object compatible with EIP-712 for structured data hashing and signing,
461
+ * including types, message, primary type, domain, and the signer's account address, which is
462
+ * the commenter's address.
463
+ */
464
+ export const permitCommentTypedDataDefinition = (
465
+ message: PermitComment,
466
+ signingAccount?: Address,
467
+ ): TypedDataDefinition<typeof permitCommentTypedDataType, "PermitComment"> & {
468
+ account: Address;
469
+ } => {
470
+ const permitCommentTypedDataType = {
471
+ PermitComment: [
472
+ { name: "contractAddress", type: "address" },
473
+ { name: "tokenId", type: "uint256" },
474
+ { name: "commenter", type: "address" },
475
+ { name: "replyTo", type: "CommentIdentifier" },
476
+ { name: "text", type: "string" },
477
+ { name: "deadline", type: "uint256" },
478
+ { name: "nonce", type: "bytes32" },
479
+ { name: "commenterSmartWallet", type: "address" },
480
+ { name: "referrer", type: "address" },
481
+ { name: "sourceChainId", type: "uint32" },
482
+ { name: "destinationChainId", type: "uint32" },
483
+ ],
484
+ CommentIdentifier: commentIdentifierType,
485
+ } as const;
486
+ return {
487
+ types: permitCommentTypedDataType,
488
+ message,
489
+ primaryType: "PermitComment",
490
+ domain: commentsDomain({
491
+ signingChainId: message.sourceChainId,
492
+ destinationChainId:
493
+ message.destinationChainId as keyof typeof commentsAddress,
494
+ }),
495
+ account: signingAccount || message.commenter,
496
+ };
497
+ };
498
+
499
+ /**
500
+ * Generates the typed data definition for a permit spark comment, for cross-chain sparking (liking with value) of comments.
501
+ *
502
+ * The permit allows a user to sign a spark comment message on one chain, which can then be
503
+ * submitted by anyone on the destination chain to execute the spark action.
504
+ *
505
+ * The permit includes details such as the comment to be sparked, the sparker's address,
506
+ * the quantity of sparks, and the source and destination chain ids.
507
+ *
508
+ * The typed data is generated in a way that makes the signature happen on the source chain
509
+ * but be valid to be executed on the destination chain.
510
+ *
511
+ * @param message - The {@link PermitSparkComment} containing the details of the spark comment permit.
512
+ * @param signingAccount - (optional) The account that is signing the message, if different than the commenter.
513
+ * Only needed if the commenter is a smart wallet; in this case the signing account should be an account
514
+ * that is one of the smart wallet owners.
515
+ * @returns A {@link TypedDataDefinition} object compatible with EIP-712 for structured data hashing and signing,
516
+ * including types, message, primary type, domain, and the signer's account address, which is
517
+ * the sparker's address.
518
+ */
519
+ export const permitSparkCommentTypedDataDefinition = (
520
+ message: PermitSparkComment,
521
+ signingAccount?: Address,
522
+ ): TypedDataDefinition<
523
+ typeof permitSparkCommentTypedDataType,
524
+ "PermitSparkComment"
525
+ > & { account: Address } => {
526
+ const permitSparkCommentTypedDataType = {
527
+ PermitSparkComment: [
528
+ { name: "comment", type: "CommentIdentifier" },
529
+ { name: "sparker", type: "address" },
530
+ { name: "sparksQuantity", type: "uint256" },
531
+ { name: "deadline", type: "uint256" },
532
+ { name: "nonce", type: "bytes32" },
533
+ { name: "referrer", type: "address" },
534
+ { name: "sourceChainId", type: "uint32" },
535
+ { name: "destinationChainId", type: "uint32" },
536
+ ],
537
+ CommentIdentifier: commentIdentifierType,
538
+ } as const;
539
+
540
+ return {
541
+ types: permitSparkCommentTypedDataType,
542
+ message,
543
+ primaryType: "PermitSparkComment",
544
+ domain: commentsDomain({
545
+ signingChainId: message.sourceChainId,
546
+ destinationChainId:
547
+ message.destinationChainId as keyof typeof commentsAddress,
548
+ }),
549
+ account: signingAccount || message.sparker,
550
+ };
551
+ };
552
+
553
+ // todo: explain
554
+ export const sparkValue = () => parseEther("0.000001");
555
+
556
+ /**
557
+ * Generates the typed data definition for a permit timed sale mint and comment operation.
558
+ *
559
+ * This function creates a structured data object that can be used for EIP-712 signing,
560
+ * allowing users to sign a message on one chain that permits a timed sale mint and comment
561
+ * action to be executed on another chain.
562
+ *
563
+ * @param message - The {@link PermitMintAndComment} containing the details of the permit.
564
+ * @param signingAccount - (optional) The account that is signing the message, if different from the commenter.
565
+ * This is typically used when the commenter is a smart wallet, and the signing account is one of its owners.
566
+ * @returns A {@link TypedDataDefinition} object compatible with EIP-712 for structured data hashing and signing,
567
+ * including types, message, primary type, domain, and the signer's account address.
568
+ */
569
+ export const permitMintAndCommentTypedDataDefinition = (
570
+ message: PermitMintAndComment,
571
+ signingAccount?: Address,
572
+ ): TypedDataDefinition<
573
+ typeof permitTimedSaleMintAndCommentTypedDataType,
574
+ "PermitTimedSaleMintAndComment"
575
+ > & { account: Address } => {
576
+ const permitTimedSaleMintAndCommentTypedDataType = {
577
+ PermitTimedSaleMintAndComment: [
578
+ { name: "commenter", type: "address" },
579
+ { name: "quantity", type: "uint256" },
580
+ { name: "collection", type: "address" },
581
+ { name: "tokenId", type: "uint256" },
582
+ { name: "mintReferral", type: "address" },
583
+ { name: "comment", type: "string" },
584
+ { name: "deadline", type: "uint256" },
585
+ { name: "nonce", type: "bytes32" },
586
+ { name: "sourceChainId", type: "uint32" },
587
+ { name: "destinationChainId", type: "uint32" },
588
+ ],
589
+ } as const;
590
+
591
+ const callerAndCommenterDomain = ({
592
+ signingChainId,
593
+ destinationChainId,
594
+ }: {
595
+ signingChainId: number;
596
+ destinationChainId: keyof typeof callerAndCommenterAddress;
597
+ }) => ({
598
+ name: "CallerAndCommenter",
599
+ version: "1",
600
+ chainId: signingChainId,
601
+ verifyingContract: callerAndCommenterAddress[destinationChainId],
602
+ });
603
+
604
+ return {
605
+ types: permitTimedSaleMintAndCommentTypedDataType,
606
+ message,
607
+ primaryType: "PermitTimedSaleMintAndComment",
608
+ domain: callerAndCommenterDomain({
609
+ signingChainId: message.sourceChainId,
610
+ destinationChainId:
611
+ message.destinationChainId as keyof typeof callerAndCommenterAddress,
612
+ }),
613
+ account: signingAccount || message.commenter,
614
+ };
615
+ };
616
+
617
+ /**
618
+ * Generates the typed data definition for a permit buy on secondary and comment operation.
619
+ *
620
+ * This function creates a structured data object that can be used for EIP-712 signing,
621
+ * allowing users to sign a message on one chain that permits a buy on secondary market and comment
622
+ * action to be executed on another chain.
623
+ *
624
+ * @param message - The {@link PermitBuyOnSecondaryAndComment} containing the details of the permit.
625
+ * @param signingAccount - (optional) The account that is signing the message, if different from the commenter.
626
+ * This is typically used when the commenter is a smart wallet, and the signing account is one of its owners.
627
+ * @returns A {@link TypedDataDefinition} object compatible with EIP-712 for structured data hashing and signing,
628
+ * including types, message, primary type, domain, and the signer's account address.
629
+ */
630
+ export const permitBuyOnSecondaryAndCommentTypedDataDefinition = (
631
+ message: PermitBuyOnSecondaryAndComment,
632
+ signingAccount?: Address,
633
+ ): TypedDataDefinition<
634
+ typeof permitBuyOnSecondaryAndCommentTypedDataType,
635
+ "PermitBuyOnSecondaryAndComment"
636
+ > & { account: Address } => {
637
+ const permitBuyOnSecondaryAndCommentTypedDataType = {
638
+ PermitBuyOnSecondaryAndComment: [
639
+ { name: "commenter", type: "address" },
640
+ { name: "quantity", type: "uint256" },
641
+ { name: "collection", type: "address" },
642
+ { name: "tokenId", type: "uint256" },
643
+ { name: "maxEthToSpend", type: "uint256" },
644
+ { name: "sqrtPriceLimitX96", type: "uint160" },
645
+ { name: "comment", type: "string" },
646
+ { name: "deadline", type: "uint256" },
647
+ { name: "nonce", type: "bytes32" },
648
+ { name: "sourceChainId", type: "uint32" },
649
+ { name: "destinationChainId", type: "uint32" },
650
+ ],
651
+ } as const;
652
+
653
+ const callerAndCommenterDomain = ({
654
+ signingChainId,
655
+ destinationChainId,
656
+ }: {
657
+ signingChainId: number;
658
+ destinationChainId: keyof typeof callerAndCommenterAddress;
659
+ }) => ({
660
+ name: "CallerAndCommenter",
661
+ version: "1",
662
+ chainId: signingChainId,
663
+ verifyingContract: callerAndCommenterAddress[destinationChainId],
664
+ });
665
+
666
+ return {
667
+ types: permitBuyOnSecondaryAndCommentTypedDataType,
668
+ message,
669
+ primaryType: "PermitBuyOnSecondaryAndComment",
670
+ domain: callerAndCommenterDomain({
671
+ signingChainId: message.sourceChainId,
672
+ destinationChainId:
673
+ message.destinationChainId as keyof typeof callerAndCommenterAddress,
674
+ }),
675
+ account: signingAccount || message.commenter,
676
+ };
677
+ };
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, callerAndCommenterABI } from "./generated/wagmi";
11
+
10
12
  export enum PremintConfigVersion {
11
13
  V1 = "1",
12
14
  V2 = "2",
@@ -121,3 +123,69 @@ 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];
166
+
167
+ /**
168
+ * The PermitTimedSaleMintAndComment type represents the data structure for a permit timed sale mint and comment,
169
+ * where a user can sign a message to mint during a timed sale and leave a comment in a single transaction.
170
+ * This can be executed on the destination chain by anyone.
171
+ *
172
+ * The permit includes details such as the minting parameters, comment text, and chain IDs for the source and destination chains.
173
+ */
174
+ export type PermitMintAndComment = AbiParametersToPrimitiveTypes<
175
+ ExtractAbiFunction<
176
+ typeof callerAndCommenterABI,
177
+ "hashPermitTimedSaleMintAndComment"
178
+ >["inputs"]
179
+ >[0];
180
+
181
+ /**
182
+ * The PermitBuyOnSecondaryAndComment type represents the data structure for a permit buy on secondary market and comment,
183
+ * where a user can sign a message to buy on secondary market and leave a comment in a single transaction.
184
+ * This can be executed on the destination chain by anyone.
185
+ */
186
+ export type PermitBuyOnSecondaryAndComment = AbiParametersToPrimitiveTypes<
187
+ ExtractAbiFunction<
188
+ typeof callerAndCommenterABI,
189
+ "hashPermitBuyOnSecondaryAndComment"
190
+ >["inputs"]
191
+ >[0];