From 907370f9308208b4769c28bc8f30256b9394989a Mon Sep 17 00:00:00 2001
From: hvthhien <hvthhien@gmail.com>
Date: Wed, 19 Jun 2024 13:42:43 +0700
Subject: [PATCH] handle merging status

---
 contracts/FeralfileArtworkV4.sol   |  4 ++--
 contracts/FeralfileArtworkV4_3.sol | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/contracts/FeralfileArtworkV4.sol b/contracts/FeralfileArtworkV4.sol
index 9915995..cdeb9a0 100644
--- a/contracts/FeralfileArtworkV4.sol
+++ b/contracts/FeralfileArtworkV4.sol
@@ -131,10 +131,10 @@ contract FeralfileExhibitionV4 is
         // initialize max supply map
         for (uint256 i = 0; i < seriesIds_.length; i++) {
             require(
-                _seriesMaxSupplies[i] == 0,
+                _seriesMaxSupplies[seriesIds_[i]] == 0,
                 "FeralfileExhibitionV4: duplicate seriesId"
             );
-            
+
             require(
                 seriesMaxSupplies_[i] > 0,
                 "FeralfileExhibitionV4: zero max supply"
diff --git a/contracts/FeralfileArtworkV4_3.sol b/contracts/FeralfileArtworkV4_3.sol
index 7640602..d651d47 100644
--- a/contracts/FeralfileArtworkV4_3.sol
+++ b/contracts/FeralfileArtworkV4_3.sol
@@ -7,6 +7,7 @@ contract FeralfileExhibitionV4_3 is FeralfileExhibitionV4_1 {
     error InvalidOwner();
     error TokenIsNonMergeable();
     error InvalidLength();
+    error InvalidMergingStatus();
 
     struct MergeArtworkInfo {
         uint256 singleSeriesId;
@@ -15,6 +16,9 @@ contract FeralfileExhibitionV4_3 is FeralfileExhibitionV4_1 {
     }
     MergeArtworkInfo private mergeArtworkInfo;
 
+    // merging
+    bool internal _merging;
+
     constructor(
         string memory name_,
         string memory symbol_,
@@ -47,6 +51,10 @@ contract FeralfileExhibitionV4_3 is FeralfileExhibitionV4_1 {
     /// @notice burns multiples mergeable artworks and mint a new artworks
     /// @param tokenIds - list of tokenIds to be burned
     function mergeArtworks(uint256[] calldata tokenIds) external {
+        if (!_merging) {
+            revert InvalidMergingStatus();
+        }
+
         if (tokenIds.length < 2) {
             revert InvalidLength();
         }
@@ -78,4 +86,22 @@ contract FeralfileExhibitionV4_3 is FeralfileExhibitionV4_1 {
         );
         mergeArtworkInfo.nextTokenId++;
     }
+
+    /// @notice Start token merging
+    function startMerging() external onlyOwner {
+        if (_merging) {
+            revert InvalidMergingStatus();
+        }
+
+        _merging = true;
+    }
+
+    /// @notice Pause token merging
+    function pauseMerging() public onlyOwner {
+        if (!_merging) {
+            revert InvalidMergingStatus();
+        }
+
+        _merging = false;
+    }
 }