From b95797f7962e3f6bf2176889e099aa985c39854f Mon Sep 17 00:00:00 2001 From: Timidan Date: Tue, 21 Jan 2025 07:57:32 +0100 Subject: [PATCH] add freeze upgrades --- .../facets/ERC1155Facet.sol | 12 +--- .../facets/InstallationAdminFacet.sol | 19 ++---- .../facets/InstallationFacet.sol | 37 ++++------ .../facets/InstallationUpgradeFacet.sol | 23 ++----- .../RealmDiamond/facets/BounceGateFacet.sol | 17 ++--- contracts/RealmDiamond/facets/ERC721Facet.sol | 30 ++------- contracts/RealmDiamond/facets/RealmFacet.sol | 34 ++++------ .../facets/RealmGettersAndSettersFacet.sol | 6 +- contracts/RealmDiamond/facets/VRFFacet.sol | 2 +- .../TileDiamond/facets/ERC1155TileFacet.sol | 12 +--- contracts/TileDiamond/facets/TileFacet.sol | 49 +++++--------- contracts/libraries/AppStorage.sol | 10 +++ .../libraries/AppStorageInstallation.sol | 10 +++ contracts/libraries/AppStorageTile.sol | 10 +++ hardhat.config.ts | 13 +--- .../upgrades/upgrade-addFreezeFn.ts | 67 +++++++++++++++++++ scripts/realm/upgrades/upgrade-addFreezeFn.ts | 67 +++++++++++++++++++ scripts/tile/upgrades/upgrade-addFreezeFn.ts | 57 ++++++++++++++++ scripts/upgrade-batchAddFreezeFn.ts | 13 ++++ 19 files changed, 311 insertions(+), 177 deletions(-) create mode 100644 scripts/installation/upgrades/upgrade-addFreezeFn.ts create mode 100644 scripts/realm/upgrades/upgrade-addFreezeFn.ts create mode 100644 scripts/tile/upgrades/upgrade-addFreezeFn.ts create mode 100644 scripts/upgrade-batchAddFreezeFn.ts diff --git a/contracts/InstallationDiamond/facets/ERC1155Facet.sol b/contracts/InstallationDiamond/facets/ERC1155Facet.sol index 75909451..b3abbd3f 100644 --- a/contracts/InstallationDiamond/facets/ERC1155Facet.sol +++ b/contracts/InstallationDiamond/facets/ERC1155Facet.sol @@ -28,13 +28,7 @@ contract ERC1155Facet is Modifiers { @param _value Transfer amount @param _data Additional data with no specified format, MUST be sent unaltered in call to `onERC1155Received` on `_to` */ - function safeTransferFrom( - address _from, - address _to, - uint256 _id, - uint256 _value, - bytes calldata _data - ) external { + function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external diamondPaused { require(_to != address(0), "ERC1155Facet: Can't transfer to 0 address"); address sender = LibMeta.msgSender(); require(sender == _from || s.operators[_from][sender] || sender == address(this), "ERC1155Facet: Not owner and not approved to transfer"); @@ -67,7 +61,7 @@ contract ERC1155Facet is Modifiers { uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data - ) external { + ) external diamondPaused { require(_to != address(0), "ItemsTransfer: Can't transfer to 0 address"); require(_ids.length == _values.length, "ItemsTransfer: ids not same length as values"); address sender = LibMeta.msgSender(); @@ -83,7 +77,7 @@ contract ERC1155Facet is Modifiers { LibERC1155.onERC1155BatchReceived(sender, _from, _to, _ids, _values, _data); } - function setApprovalForAll(address _operator, bool _approved) external { + function setApprovalForAll(address _operator, bool _approved) external diamondPaused { address sender = LibMeta.msgSender(); require(sender != _operator, "ERC1155Facet: setting approval status for self"); s.operators[sender][_operator] = _approved; diff --git a/contracts/InstallationDiamond/facets/InstallationAdminFacet.sol b/contracts/InstallationDiamond/facets/InstallationAdminFacet.sol index 4b4cf32e..d5978b06 100644 --- a/contracts/InstallationDiamond/facets/InstallationAdminFacet.sol +++ b/contracts/InstallationDiamond/facets/InstallationAdminFacet.sol @@ -106,7 +106,7 @@ contract InstallationAdminFacet is Modifiers { emit AddInstallationType(s.installationTypes.length - 1); emit SetInstallationUnequipType(s.installationTypes.length - 1, _installationTypes[i].unequipType); - if(_installationTypes[i].deprecateTime > 0){ + if (_installationTypes[i].deprecateTime > 0) { s.deprecateTime[s.installationTypes.length - 1] = _installationTypes[i].deprecateTime; emit EditDeprecateTime(s.installationTypes.length - 1, _installationTypes[i].deprecateTime); } @@ -142,11 +142,7 @@ contract InstallationAdminFacet is Modifiers { /// @param _installationIds An array containing the identifiers of the installationTypes to mint /// @param _amounts An array containing the amounts of the installationTypes to mint /// @param _toAddress Address to mint installations - function mintInstallations( - uint16[] calldata _installationIds, - uint16[] calldata _amounts, - address _toAddress - ) external onlyOwner { + function mintInstallations(uint16[] calldata _installationIds, uint16[] calldata _amounts, address _toAddress) external onlyOwner { require(_installationIds.length == _amounts.length, "InstallationFacet: Mismatched arrays"); for (uint256 i = 0; i < _installationIds.length; i++) { uint256 installationId = _installationIds[i]; @@ -232,16 +228,15 @@ contract InstallationAdminFacet is Modifiers { } } - function getUniqueHash( - uint256 _parcelId, - uint16 _x, - uint16 _y, - uint256 _installationId - ) external view returns (uint256) { + function getUniqueHash(uint256 _parcelId, uint16 _x, uint16 _y, uint256 _installationId) external view returns (uint256) { return s.upgradeHashes[keccak256(abi.encodePacked(_parcelId, _x, _y, _installationId))]; } function toggleGameManager(address _newGameManager, bool _active) external onlyOwner { s.gameManager[_newGameManager] = _active; } + + function setDiamondPaused(bool _paused) external onlyOwner { + s.diamondPaused = _paused; + } } diff --git a/contracts/InstallationDiamond/facets/InstallationFacet.sol b/contracts/InstallationDiamond/facets/InstallationFacet.sol index 8edcee6a..5c7f73d0 100644 --- a/contracts/InstallationDiamond/facets/InstallationFacet.sol +++ b/contracts/InstallationDiamond/facets/InstallationFacet.sol @@ -63,11 +63,7 @@ contract InstallationFacet is Modifiers { /// @param _tokenId The ID of the parent token /// @param _id ID of the token /// @return value The balance of the token - function balanceOfToken( - address _tokenContract, - uint256 _tokenId, - uint256 _id - ) public view returns (uint256 value) { + function balanceOfToken(address _tokenContract, uint256 _tokenId, uint256 _id) public view returns (uint256 value) { value = s.nftInstallationBalances[_tokenContract][_tokenId][_id]; } @@ -89,11 +85,10 @@ contract InstallationFacet is Modifiers { /// @param _tokenContract Contract address for the token to query /// @param _tokenId Identifier of the token to query /// @return installationBalancesOfTokenWithTypes_ An array of structs containing details about each installation owned(including installation types) - function installationBalancesOfTokenWithTypes(address _tokenContract, uint256 _tokenId) - external - view - returns (ItemTypeIO[] memory installationBalancesOfTokenWithTypes_) - { + function installationBalancesOfTokenWithTypes( + address _tokenContract, + uint256 _tokenId + ) external view returns (ItemTypeIO[] memory installationBalancesOfTokenWithTypes_) { installationBalancesOfTokenWithTypes_ = LibERC998.itemBalancesOfTokenWithTypes(_tokenContract, _tokenId); } @@ -260,7 +255,7 @@ contract InstallationFacet is Modifiers { // } } - function batchCraftInstallations(BatchCraftInstallationsInput[] calldata _inputs) external { + function batchCraftInstallations(BatchCraftInstallationsInput[] calldata _inputs) external diamondPaused { for (uint256 i = 0; i < _inputs.length; i++) { _batchCraftInstallation(_inputs[i]); } @@ -271,7 +266,7 @@ contract InstallationFacet is Modifiers { /// @dev Puts the installation into a queue /// @param _installationTypes An array containing the identifiers of the installationTypes to craft /// @param _gltr Array of GLTR to spend on each crafting - function craftInstallations(uint16[] calldata _installationTypes, uint40[] calldata _gltr) external { + function craftInstallations(uint16[] calldata _installationTypes, uint40[] calldata _gltr) external diamondPaused { require(_installationTypes.length == _gltr.length, "InstallationFacet: Mismatched arrays"); address[4] memory alchemicaAddresses = RealmDiamond(s.realmDiamond).getAlchemicaAddresses(); @@ -319,7 +314,7 @@ contract InstallationFacet is Modifiers { /// @dev Will throw if the caller is not the queue owner /// @dev Will throw if one of the queues is not ready /// @param _queueIds An array containing the identifiers of queues to claim - function claimInstallations(uint256[] calldata _queueIds) external { + function claimInstallations(uint256[] calldata _queueIds) external diamondPaused { for (uint256 i; i < _queueIds.length; i++) { uint256 queueId = _queueIds[i]; @@ -345,7 +340,7 @@ contract InstallationFacet is Modifiers { /// @dev amount expressed in block numbers /// @param _queueIds An array containing the identifiers of queues to speed up /// @param _amounts An array containing the corresponding amounts of $GLTR tokens to pay for each queue speedup - function reduceCraftTime(uint256[] calldata _queueIds, uint40[] calldata _amounts) external { + function reduceCraftTime(uint256[] calldata _queueIds, uint40[] calldata _amounts) external diamondPaused { require(_queueIds.length == _amounts.length, "InstallationFacet: Mismatched arrays"); for (uint256 i; i < _queueIds.length; i++) { uint256 queueId = _queueIds[i]; @@ -358,7 +353,7 @@ contract InstallationFacet is Modifiers { uint40 blockLeft = queueItem.readyBlock - uint40(block.number); uint40 removeBlocks = _amounts[i] <= blockLeft ? _amounts[i] : blockLeft; - uint256 burnAmount = uint256(removeBlocks) * 10**18; + uint256 burnAmount = uint256(removeBlocks) * 10 ** 18; gltr.burnFrom(msg.sender, burnAmount); queueItem.readyBlock -= removeBlocks; emit CraftTimeReduced(queueId, removeBlocks); @@ -371,11 +366,7 @@ contract InstallationFacet is Modifiers { /// @param _owner Owner of the installation to equip /// @param _realmId The identifier of the parcel to equip the installation to /// @param _installationId Identifier of the installation to equip - function equipInstallation( - address _owner, - uint256 _realmId, - uint256 _installationId - ) external onlyRealmDiamond { + function equipInstallation(address _owner, uint256 _realmId, uint256 _installationId) external onlyRealmDiamond diamondPaused { LibInstallation._equipInstallation(_owner, _realmId, _installationId); } @@ -383,11 +374,7 @@ contract InstallationFacet is Modifiers { /// @dev Will throw if the caller is not the parcel diamond contract /// @param _realmId The identifier of the parcel to unequip the installation from /// @param _installationId Identifier of the installation to unequip - function unequipInstallation( - address _owner, - uint256 _realmId, - uint256 _installationId - ) external onlyRealmDiamond { + function unequipInstallation(address _owner, uint256 _realmId, uint256 _installationId) external onlyRealmDiamond diamondPaused { LibInstallation._unequipInstallation(_owner, _realmId, _installationId); } diff --git a/contracts/InstallationDiamond/facets/InstallationUpgradeFacet.sol b/contracts/InstallationDiamond/facets/InstallationUpgradeFacet.sol index 8b4428a9..892458cb 100644 --- a/contracts/InstallationDiamond/facets/InstallationUpgradeFacet.sol +++ b/contracts/InstallationDiamond/facets/InstallationUpgradeFacet.sol @@ -22,12 +22,7 @@ contract InstallationUpgradeFacet is Modifiers { /// @param _gotchiId The id of the gotchi which is upgrading the installation ///@param _signature API signature ///@param _gltr Amount of GLTR to use, can be 0 - function upgradeInstallation( - UpgradeQueue memory _upgradeQueue, - uint256 _gotchiId, - bytes memory _signature, - uint40 _gltr - ) external { + function upgradeInstallation(UpgradeQueue memory _upgradeQueue, uint256 _gotchiId, bytes memory _signature, uint40 _gltr) external diamondPaused { // Check signature require( LibSignature.isValid( @@ -79,19 +74,14 @@ contract InstallationUpgradeFacet is Modifiers { } /// @notice Allow anyone to finalize any existing queue upgrade - function finalizeUpgrades(uint256[] memory _upgradeIndexes) external { + function finalizeUpgrades(uint256[] memory _upgradeIndexes) external diamondPaused { for (uint256 i; i < _upgradeIndexes.length; i++) { UpgradeQueue storage upgradeQueue = s.upgradeQueue[_upgradeIndexes[i]]; LibInstallation.finalizeUpgrade(upgradeQueue.owner, _upgradeIndexes[i]); } } - function reduceUpgradeTime( - uint256 _upgradeIndex, - uint256 _gotchiId, - uint40 _blocks, - bytes memory _signature - ) external { + function reduceUpgradeTime(uint256 _upgradeIndex, uint256 _gotchiId, uint40 _blocks, bytes memory _signature) external diamondPaused { UpgradeQueue storage queue = s.upgradeQueue[_upgradeIndex]; require( @@ -212,12 +202,7 @@ contract InstallationUpgradeFacet is Modifiers { return s.parcelIdToUpgradeIds[_parcelId].length == 0; } - function parcelInstallationUpgrading( - uint256 _parcelId, - uint256 _installationId, - uint256 _x, - uint256 _y - ) external view returns (bool) { + function parcelInstallationUpgrading(uint256 _parcelId, uint256 _installationId, uint256 _x, uint256 _y) external view returns (bool) { uint256[] memory parcelQueue = s.parcelIdToUpgradeIds[_parcelId]; for (uint256 i; i < parcelQueue.length; i++) { diff --git a/contracts/RealmDiamond/facets/BounceGateFacet.sol b/contracts/RealmDiamond/facets/BounceGateFacet.sol index 2224b50e..7857b214 100644 --- a/contracts/RealmDiamond/facets/BounceGateFacet.sol +++ b/contracts/RealmDiamond/facets/BounceGateFacet.sol @@ -11,28 +11,19 @@ contract BounceGateFacet is Modifiers { uint64 _durationInMinutes, uint256[4] calldata _alchemicaSpent, uint256 _realmId - ) external { + ) external diamondPaused { LibBounceGate._createEvent(_title, _startTime, _durationInMinutes, _alchemicaSpent, _realmId); } - function updateEvent( - uint256 _realmId, - uint256[4] calldata _alchemicaSpent, - uint40 _durationExtensionInMinutes - ) external { + function updateEvent(uint256 _realmId, uint256[4] calldata _alchemicaSpent, uint40 _durationExtensionInMinutes) external diamondPaused { LibBounceGate._updateEvent(_realmId, _alchemicaSpent, _durationExtensionInMinutes); } - function cancelEvent(uint256 _realmId) external { + function cancelEvent(uint256 _realmId) external diamondPaused { LibBounceGate._cancelEvent(_realmId); } - function recreateEvent( - uint256 _realmId, - uint64 _startTime, - uint64 _durationInMinutes, - uint256[4] calldata _alchemicaSpent - ) external { + function recreateEvent(uint256 _realmId, uint64 _startTime, uint64 _durationInMinutes, uint256[4] calldata _alchemicaSpent) external diamondPaused { LibBounceGate._recreateEvent(_realmId, _startTime, _durationInMinutes, _alchemicaSpent); } diff --git a/contracts/RealmDiamond/facets/ERC721Facet.sol b/contracts/RealmDiamond/facets/ERC721Facet.sol index fed877d0..b8642957 100644 --- a/contracts/RealmDiamond/facets/ERC721Facet.sol +++ b/contracts/RealmDiamond/facets/ERC721Facet.sol @@ -78,12 +78,7 @@ contract ERC721Facet is Modifiers { /// @param _to The new owner /// @param _tokenId The NFT to transfer /// @param _data Additional data with no specified format, sent in call to `_to` - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId, - bytes calldata _data - ) public { + function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes calldata _data) public diamondPaused { address sender = LibMeta.msgSender(); LibERC721.transferFrom(sender, _from, _to, _tokenId); LibERC721.checkOnERC721Received(sender, _from, _to, _tokenId, _data); @@ -101,11 +96,7 @@ contract ERC721Facet is Modifiers { /// @param _from The current owner of the NFT /// @param _to The new owner /// @param _tokenId The NFT to transfer - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId - ) external { + function safeTransferFrom(address _from, address _to, uint256 _tokenId) external diamondPaused { address sender = LibMeta.msgSender(); LibERC721.transferFrom(sender, _from, _to, _tokenId); LibERC721.checkOnERC721Received(sender, _from, _to, _tokenId, ""); @@ -126,11 +117,7 @@ contract ERC721Facet is Modifiers { /// @param _from The current owner of the NFT /// @param _to The new owner /// @param _tokenId The NFT to transfer - function transferFrom( - address _from, - address _to, - uint256 _tokenId - ) external { + function transferFrom(address _from, address _to, uint256 _tokenId) external diamondPaused { address sender = LibMeta.msgSender(); LibERC721.transferFrom(sender, _from, _to, _tokenId); @@ -145,7 +132,7 @@ contract ERC721Facet is Modifiers { /// operator of the current owner. /// @param _approved The new approved NFT controller /// @param _tokenId The NFT to approve - function approve(address _approved, uint256 _tokenId) external { + function approve(address _approved, uint256 _tokenId) external diamondPaused { address owner = s.parcels[_tokenId].owner; address sender = LibMeta.msgSender(); require(owner == sender || s.operators[owner][sender], "ERC721: Not owner or operator of token."); @@ -159,7 +146,7 @@ contract ERC721Facet is Modifiers { /// multiple operators per owner. /// @param _operator Address to add to the set of authorized operators /// @param _approved True if the operator is approved, false to revoke approval - function setApprovalForAll(address _operator, bool _approved) external { + function setApprovalForAll(address _operator, bool _approved) external diamondPaused { address sender = LibMeta.msgSender(); s.operators[sender][_operator] = _approved; emit LibEvents.ApprovalForAll(sender, _operator, _approved); @@ -198,12 +185,7 @@ contract ERC721Facet is Modifiers { uint256 alphaBoost; } - function safeBatchTransfer( - address _from, - address _to, - uint256[] calldata _tokenIds, - bytes calldata _data - ) external { + function safeBatchTransfer(address _from, address _to, uint256[] calldata _tokenIds, bytes calldata _data) external diamondPaused { for (uint256 index = 0; index < _tokenIds.length; index++) { safeTransferFrom(_from, _to, _tokenIds[index], _data); } diff --git a/contracts/RealmDiamond/facets/RealmFacet.sol b/contracts/RealmDiamond/facets/RealmFacet.sol index fe52387a..54663a8d 100644 --- a/contracts/RealmDiamond/facets/RealmFacet.sol +++ b/contracts/RealmDiamond/facets/RealmFacet.sol @@ -35,11 +35,7 @@ contract RealmFacet is Modifiers { /// @param _to The address to mint the parcels to /// @param _tokenIds The identifiers of tokens to mint /// @param _metadata An array of structs containing the metadata of each parcel being minted - function mintParcels( - address[] calldata _to, - uint256[] calldata _tokenIds, - MintParcelInput[] memory _metadata - ) external onlyOwner { + function mintParcels(address[] calldata _to, uint256[] calldata _tokenIds, MintParcelInput[] memory _metadata) external onlyOwner { for (uint256 index = 0; index < _tokenIds.length; index++) { require(s.tokenIds.length < LibRealm.MAX_SUPPLY, "RealmFacet: Cannot mint more than 420,069 parcels"); uint256 tokenId = _tokenIds[index]; @@ -74,7 +70,7 @@ contract RealmFacet is Modifiers { uint256 _gotchiId, BatchEquipIO memory _params, bytes[] memory _signatures - ) external gameActive canBuild { + ) external diamondPaused gameActive canBuild { require(_params.ids.length == _params.x.length, "RealmFacet: Wrong length"); require(_params.x.length == _params.y.length, "RealmFacet: Wrong length"); @@ -106,7 +102,7 @@ contract RealmFacet is Modifiers { uint256 _x, uint256 _y, bytes memory _signature - ) public gameActive canBuild { + ) public diamondPaused gameActive canBuild { //2 - Equip Installations LibRealm.verifyAccessRight(_realmId, _gotchiId, 2, LibMeta.msgSender()); require( @@ -153,7 +149,7 @@ contract RealmFacet is Modifiers { uint256 _x, uint256 _y, bytes memory _signature - ) public onlyParcelOwner(_realmId) gameActive canBuild { + ) public diamondPaused onlyParcelOwner(_realmId) gameActive canBuild { require( LibSignature.isValid(keccak256(abi.encodePacked(_realmId, _gotchiId, _installationId, _x, _y)), _signature, s.backendPubKey), "RealmFacet: Invalid signature" @@ -216,7 +212,7 @@ contract RealmFacet is Modifiers { uint256 _y0, uint256 _x1, uint256 _y1 - ) external onlyParcelOwner(_realmId) gameActive canBuild { + ) external diamondPaused onlyParcelOwner(_realmId) gameActive canBuild { //Check if upgrade is in progress InstallationDiamondInterface installation = InstallationDiamondInterface(s.installationsDiamond); @@ -241,7 +237,7 @@ contract RealmFacet is Modifiers { uint256 _x, uint256 _y, bytes memory _signature - ) public gameActive canBuild { + ) public diamondPaused gameActive canBuild { //3 - Equip Tile LibRealm.verifyAccessRight(_realmId, _gotchiId, 3, LibMeta.msgSender()); require( @@ -269,7 +265,7 @@ contract RealmFacet is Modifiers { uint256 _x, uint256 _y, bytes memory _signature - ) public onlyParcelOwner(_realmId) gameActive canBuild { + ) public diamondPaused onlyParcelOwner(_realmId) gameActive canBuild { require( LibSignature.isValid(keccak256(abi.encodePacked(_realmId, _gotchiId, _tileId, _x, _y)), _signature, s.backendPubKey), "RealmFacet: Invalid signature" @@ -295,7 +291,7 @@ contract RealmFacet is Modifiers { uint256 _y0, uint256 _x1, uint256 _y1 - ) external onlyParcelOwner(_realmId) gameActive canBuild { + ) external diamondPaused onlyParcelOwner(_realmId) gameActive canBuild { LibRealm.removeTile(_realmId, _tileId, _x0, _y0); emit UnequipTile(_realmId, _tileId, _x0, _y0); LibRealm.placeTile(_realmId, _tileId, _x1, _y1); @@ -316,7 +312,7 @@ contract RealmFacet is Modifiers { emit InstallationUpgraded(_realmId, _prevInstallationId, _nextInstallationId, _coordinateX, _coordinateY); } - function addUpgradeQueueLength(uint256 _realmId) external onlyInstallationDiamond { + function addUpgradeQueueLength(uint256 _realmId) external diamondPaused onlyInstallationDiamond { s.parcels[_realmId].upgradeQueueLength++; } @@ -324,13 +320,7 @@ contract RealmFacet is Modifiers { s.parcels[_realmId].upgradeQueueLength--; } - function fixGrid( - uint256 _realmId, - uint256 _installationId, - uint256[] memory _x, - uint256[] memory _y, - bool tile - ) external onlyOwner { + function fixGrid(uint256 _realmId, uint256 _installationId, uint256[] memory _x, uint256[] memory _y, bool tile) external onlyOwner { require(_x.length == _y.length, "RealmFacet: _x and _y must be the same length"); Parcel storage parcel = s.parcels[_realmId]; for (uint256 i; i < _x.length; i++) { @@ -350,4 +340,8 @@ contract RealmFacet is Modifiers { function setFreezeBuilding(bool _freezeBuilding) external onlyOwner { s.freezeBuilding = _freezeBuilding; } + + function setDiamondPaused(bool _paused) external onlyOwner { + s.diamondPaused = _paused; + } } diff --git a/contracts/RealmDiamond/facets/RealmGettersAndSettersFacet.sol b/contracts/RealmDiamond/facets/RealmGettersAndSettersFacet.sol index ed5da753..fbb1778d 100644 --- a/contracts/RealmDiamond/facets/RealmGettersAndSettersFacet.sol +++ b/contracts/RealmDiamond/facets/RealmGettersAndSettersFacet.sol @@ -27,7 +27,7 @@ contract RealmGettersAndSettersFacet is Modifiers { uint256[] calldata _realmIds, uint256[] calldata _actionRights, uint256[] calldata _accessRights - ) external gameActive { + ) external diamondPaused gameActive { require(_realmIds.length == _accessRights.length && _realmIds.length == _actionRights.length, "RealmGettersAndSettersFacet: Mismatched arrays"); for (uint256 i; i < _realmIds.length; i++) { require(LibMeta.msgSender() == s.parcels[_realmIds[i]].owner, "RealmGettersAndSettersFacet: Only Parcel owner can call"); @@ -42,7 +42,7 @@ contract RealmGettersAndSettersFacet is Modifiers { uint256[] calldata _actionRights, uint256[] calldata _accessRights, uint32[] calldata _whitelistIds - ) external gameActive { + ) external diamondPaused gameActive { require( _realmIds.length == _actionRights.length && _whitelistIds.length == _actionRights.length && _whitelistIds.length == _actionRights.length, "RealmGettersAndSettersFacet: Mismatched arrays" @@ -68,7 +68,7 @@ contract RealmGettersAndSettersFacet is Modifiers { @dev Used to resync a parcel on the subgraph if metadata is added later @param _tokenIds The parcels to resync */ - function resyncParcel(uint256[] calldata _tokenIds) external onlyOwner { + function resyncParcel(uint256[] calldata _tokenIds) external diamondPaused onlyOwner { for (uint256 index = 0; index < _tokenIds.length; index++) { emit ResyncParcel(_tokenIds[index]); } diff --git a/contracts/RealmDiamond/facets/VRFFacet.sol b/contracts/RealmDiamond/facets/VRFFacet.sol index 86ebef0f..f00b8220 100644 --- a/contracts/RealmDiamond/facets/VRFFacet.sol +++ b/contracts/RealmDiamond/facets/VRFFacet.sol @@ -9,7 +9,7 @@ import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol"; import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol"; contract VRFFacet is Modifiers { - function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external { + function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external diamondPaused { require(LibMeta.msgSender() == s.vrfCoordinator, "Only VRFCoordinator can fulfill"); uint256 tokenId = s.vrfRequestIdToTokenId[requestId]; LibRealm.updateRemainingAlchemica(tokenId, randomWords, s.vrfRequestIdToSurveyingRound[requestId]); diff --git a/contracts/TileDiamond/facets/ERC1155TileFacet.sol b/contracts/TileDiamond/facets/ERC1155TileFacet.sol index 118fd2b1..19662f99 100644 --- a/contracts/TileDiamond/facets/ERC1155TileFacet.sol +++ b/contracts/TileDiamond/facets/ERC1155TileFacet.sol @@ -28,13 +28,7 @@ contract ERC1155TileFacet is Modifiers { @param _value Transfer amount @param _data Additional data with no specified format, MUST be sent unaltered in call to `onERC1155Received` on `_to` */ - function safeTransferFrom( - address _from, - address _to, - uint256 _id, - uint256 _value, - bytes calldata _data - ) external { + function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external diamondPaused { require(_to != address(0), "ERC1155Facet: Can't transfer to 0 address"); address sender = LibMeta.msgSender(); require(sender == _from || s.operators[_from][sender] || sender == address(this), "ERC1155Facet: Not owner and not approved to transfer"); @@ -67,7 +61,7 @@ contract ERC1155TileFacet is Modifiers { uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data - ) external { + ) external diamondPaused { require(_to != address(0), "ItemsTransfer: Can't transfer to 0 address"); require(_ids.length == _values.length, "ItemsTransfer: ids not same length as values"); address sender = LibMeta.msgSender(); @@ -83,7 +77,7 @@ contract ERC1155TileFacet is Modifiers { LibERC1155Tile.onERC1155BatchReceived(sender, _from, _to, _ids, _values, _data); } - function setApprovalForAll(address _operator, bool _approved) external { + function setApprovalForAll(address _operator, bool _approved) external diamondPaused { address sender = LibMeta.msgSender(); require(sender != _operator, "ERC1155Facet: setting approval status for self"); s.operators[sender][_operator] = _approved; diff --git a/contracts/TileDiamond/facets/TileFacet.sol b/contracts/TileDiamond/facets/TileFacet.sol index b05dd004..019c06d4 100644 --- a/contracts/TileDiamond/facets/TileFacet.sol +++ b/contracts/TileDiamond/facets/TileFacet.sol @@ -71,11 +71,7 @@ contract TileFacet is Modifiers { /// @param _tokenId The ID of the parent token /// @param _id ID of the token /// @return value The balance of the token - function balanceOfToken( - address _tokenContract, - uint256 _tokenId, - uint256 _id - ) public view returns (uint256 value) { + function balanceOfToken(address _tokenContract, uint256 _tokenId, uint256 _id) public view returns (uint256 value) { value = s.nftTileBalances[_tokenContract][_tokenId][_id]; } @@ -97,11 +93,10 @@ contract TileFacet is Modifiers { /// @param _tokenContract Contract address for the token to query /// @param _tokenId Identifier of the token to query /// @return tileBalancesOfTokenWithTypes_ An array of structs containing details about each tile owned(including tile types) - function tileBalancesOfTokenWithTypes(address _tokenContract, uint256 _tokenId) - external - view - returns (ItemTypeIO[] memory tileBalancesOfTokenWithTypes_) - { + function tileBalancesOfTokenWithTypes( + address _tokenContract, + uint256 _tokenId + ) external view returns (ItemTypeIO[] memory tileBalancesOfTokenWithTypes_) { tileBalancesOfTokenWithTypes_ = LibERC998Tile.itemBalancesOfTokenWithTypes(_tokenContract, _tokenId); } @@ -110,11 +105,7 @@ contract TileFacet is Modifiers { /// @param _tokenId The identifier of the ERC721 parent token /// @param _ids An array containing the ids of the tileTypes to query /// @return An array containing the corresponding balances of the tile types queried - function tileBalancesOfTokenByIds( - address _tokenContract, - uint256 _tokenId, - uint256[] calldata _ids - ) external view returns (uint256[] memory) { + function tileBalancesOfTokenByIds(address _tokenContract, uint256 _tokenId, uint256[] calldata _ids) external view returns (uint256[] memory) { uint256[] memory balances = new uint256[](_ids.length); for (uint256 i = 0; i < _ids.length; i++) { balances[i] = balanceOfToken(_tokenContract, _tokenId, _ids[i]); @@ -157,7 +148,7 @@ contract TileFacet is Modifiers { /// @notice Allow a user to craft tiles one at a time /// @dev Puts the tile into a queue /// @param _tileTypes An array containing the identifiers of the tileTypes to craft - function craftTiles(uint16[] calldata _tileTypes) external { + function craftTiles(uint16[] calldata _tileTypes) external diamondPaused { address[4] memory alchemicaAddresses = RealmDiamond(s.realmDiamond).getAlchemicaAddresses(); uint256 _tileTypesLength = s.tileTypes.length; @@ -247,7 +238,7 @@ contract TileFacet is Modifiers { } /// @notice Allow a user to craft tiles by batch - function batchCraftTiles(BatchCraftTilesInput[] calldata _inputs) external { + function batchCraftTiles(BatchCraftTilesInput[] calldata _inputs) external diamondPaused { for (uint256 i = 0; i < _inputs.length; i++) { _batchCraftTiles(_inputs[i]); } @@ -257,7 +248,7 @@ contract TileFacet is Modifiers { /// @dev Will throw if the caller is not the queue owner /// @dev Will throw if one of the queues is not ready /// @param _queueIds An array containing the identifiers of queues to claim - function claimTiles(uint256[] calldata _queueIds) external { + function claimTiles(uint256[] calldata _queueIds) external diamondPaused { for (uint256 i; i < _queueIds.length; i++) { uint256 queueId = _queueIds[i]; @@ -280,7 +271,7 @@ contract TileFacet is Modifiers { /// @dev amount expressed in block numbers /// @param _queueIds An array containing the identifiers of queues to speed up /// @param _amounts An array containing the corresponding amounts of $GLTR tokens to pay for each queue speedup - function reduceCraftTime(uint256[] calldata _queueIds, uint40[] calldata _amounts) external { + function reduceCraftTime(uint256[] calldata _queueIds, uint40[] calldata _amounts) external diamondPaused { require(_queueIds.length == _amounts.length, "TileFacet: Mismatched arrays"); for (uint256 i; i < _queueIds.length; i++) { uint256 queueId = _queueIds[i]; @@ -293,7 +284,7 @@ contract TileFacet is Modifiers { uint40 blockLeft = queueItem.readyBlock - uint40(block.number); uint40 removeBlocks = _amounts[i] <= blockLeft ? _amounts[i] : blockLeft; - gltr.burnFrom(msg.sender, removeBlocks * 10**18); + gltr.burnFrom(msg.sender, removeBlocks * 10 ** 18); queueItem.readyBlock -= removeBlocks; emit CraftTimeReduced(queueId, removeBlocks); } @@ -326,11 +317,7 @@ contract TileFacet is Modifiers { /// @param _owner Owner of the tile to equip /// @param _realmId The identifier of the parcel to equip the tile to /// @param _tileId Identifier of the tile to equip - function equipTile( - address _owner, - uint256 _realmId, - uint256 _tileId - ) external onlyRealmDiamond { + function equipTile(address _owner, uint256 _realmId, uint256 _tileId) external onlyRealmDiamond { LibTile._equipTile(_owner, _realmId, _tileId); } @@ -338,11 +325,7 @@ contract TileFacet is Modifiers { /// @dev Will throw if the caller is not the parcel diamond contract /// @param _realmId The identifier of the parcel to unequip the tile from /// @param _tileId Identifier of the tile to unequip - function unequipTile( - address _owner, - uint256 _realmId, - uint256 _tileId - ) external onlyRealmDiamond { + function unequipTile(address _owner, uint256 _realmId, uint256 _tileId) external onlyRealmDiamond { LibTile._unequipTile(_owner, _realmId, _tileId); } @@ -413,7 +396,7 @@ contract TileFacet is Modifiers { ); string memory uri = "https://app.aavegotchi.com/metadata/tile/"; emit LibEvents.URI(LibStrings.strWithUint(uri, i), i); - if(_tileTypes[i].deprecateTime > 0){ + if (_tileTypes[i].deprecateTime > 0) { s.deprecateTime[s.tileTypes.length - 1] = _tileTypes[i].deprecateTime; emit EditDeprecateTime(s.tileTypes.length - 1, _tileTypes[i].deprecateTime); } @@ -437,4 +420,8 @@ contract TileFacet is Modifiers { emit EditTileType(_typeIds[i], _updatedTiles[i]); } } + + function setDiamondPaused(bool _paused) external onlyOwner { + s.diamondPaused = _paused; + } } diff --git a/contracts/libraries/AppStorage.sol b/contracts/libraries/AppStorage.sol index 7e4ef88c..87cdf333 100644 --- a/contracts/libraries/AppStorage.sol +++ b/contracts/libraries/AppStorage.sol @@ -110,6 +110,8 @@ struct AppStorage { mapping(uint256 => BounceGate) bounceGates; // parcelId => action: 0 Alchemical Channeling, 1 Emptying Reservoirs => whitelistIds mapping(uint256 => mapping(uint256 => uint32)) whitelistIds; + //geist cloning switch + bool diamondPaused; } library LibAppStorage { @@ -158,4 +160,12 @@ contract Modifiers { require(!s.freezeBuilding, "AppStorage: Building temporarily disabled"); _; } + + modifier diamondPaused() { + ///we exempt gameManager from the freeze + if (msg.sender != LibDiamond.contractOwner()) { + require(!s.diamondPaused, "AppStorage: Diamond paused"); + } + _; + } } diff --git a/contracts/libraries/AppStorageInstallation.sol b/contracts/libraries/AppStorageInstallation.sol index 0edef64c..46d042be 100644 --- a/contracts/libraries/AppStorageInstallation.sol +++ b/contracts/libraries/AppStorageInstallation.sol @@ -95,6 +95,8 @@ struct InstallationAppStorage { mapping(uint256 => uint256) unequipTypes; // installationType.id => unequipType mapping(uint256 => uint256[]) parcelIdToUpgradeIds; // will not track upgrades before this variable's existence mapping(address => bool) gameManager; + //geist cloning switch + bool diamondPaused; } library LibAppStorageInstallation { @@ -122,4 +124,12 @@ contract Modifiers { require(s.gameManager[msg.sender] == true, "LibDiamond: Must be a gameManager"); _; } + + modifier diamondPaused() { + ///we exempt gameManager from the freeze + if (!s.gameManager[msg.sender]) { + require(!s.diamondPaused, "AppStorage: Diamond paused"); + } + _; + } } diff --git a/contracts/libraries/AppStorageTile.sol b/contracts/libraries/AppStorageTile.sol index b43ae831..d8d732ec 100644 --- a/contracts/libraries/AppStorageTile.sol +++ b/contracts/libraries/AppStorageTile.sol @@ -58,6 +58,8 @@ struct TileAppStorage { mapping(address => mapping(uint256 => uint256)) ownerTileIndexes; // installationId => deprecateTime mapping(uint256 => uint256) deprecateTime; + //in preparation for geist cloning + bool diamondPaused; } library LibAppStorageTile { @@ -80,4 +82,12 @@ contract Modifiers { require(msg.sender == s.realmDiamond, "LibDiamond: Must be realm diamond"); _; } + + modifier diamondPaused() { + ///we exempt gameManager from the freeze + if (msg.sender != LibDiamond.contractOwner()) { + require(!s.diamondPaused, "AppStorage: Diamond paused"); + } + _; + } } diff --git a/hardhat.config.ts b/hardhat.config.ts index e451dc2c..2c5319bd 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -74,8 +74,8 @@ module.exports = { maxPriorityFeePerGas: 1 * GWEI, // timeout: 90000 }, - mumbai: { - url: process.env.MUMBAI_URL, + amoy: { + url: process.env.AMOY_URL, accounts: [process.env.SECRET], blockGasLimit: 20000000, // gasPrice: 1000000000, @@ -91,15 +91,6 @@ module.exports = { }, // gasPrice: 1000000000, }, - kovan: { - url: process.env.KOVAN_URL, - // url: 'https://rpc-mainnet.maticvigil.com/', - accounts: [process.env.SECRET], - // blockGasLimit: 20000000, - blockGasLimit: 12000000, - gasPrice: 100000000000, - // timeout: 90000 - }, }, gasReporter: { diff --git a/scripts/installation/upgrades/upgrade-addFreezeFn.ts b/scripts/installation/upgrades/upgrade-addFreezeFn.ts new file mode 100644 index 00000000..43edd06d --- /dev/null +++ b/scripts/installation/upgrades/upgrade-addFreezeFn.ts @@ -0,0 +1,67 @@ +import { run, ethers } from "hardhat"; +//import { maticTileDiamondAddress } from "../../../constants"; +import { + convertFacetAndSelectorsToString, + DeployUpgradeTaskArgs, + FacetsAndAddSelectors, +} from "../../../tasks/deployUpgrade"; +import { OwnershipFacet } from "../../../typechain-types"; +import { varsForNetwork } from "../../../constants"; + +export async function upgrade() { + const c = await varsForNetwork(ethers); + + const facets: FacetsAndAddSelectors[] = [ + { + facetName: "ERC1155Facet", + addSelectors: [], + removeSelectors: [], + }, + { + facetName: "InstallationAdminFacet", + addSelectors: [`function setDiamondPaused(bool _paused) external`], + removeSelectors: [], + }, + { + facetName: "InstallationFacet", + addSelectors: [], + removeSelectors: [], + }, + { + facetName: "InstallationUpgradeFacet", + addSelectors: [], + removeSelectors: [], + }, + ]; + + const ownership = (await ethers.getContractAt( + "OwnershipFacet", + c.installationDiamond + )) as OwnershipFacet; + + const owner = await ownership.owner(); + console.log("owner:", owner); + + const joined = convertFacetAndSelectorsToString(facets); + + const args: DeployUpgradeTaskArgs = { + diamondAddress: c.installationDiamond, + facetsAndAddSelectors: joined, + useLedger: false, + useMultisig: false, + initAddress: ethers.constants.AddressZero, + initCalldata: "0x", + }; + + await run("deployUpgrade", args); +} + +if (require.main === module) { + upgrade() + .then(() => process.exit(0)) + // .then(() => console.log('upgrade completed') /* process.exit(0) */) + .catch((error) => { + console.error(error); + process.exit(1); + }); +} diff --git a/scripts/realm/upgrades/upgrade-addFreezeFn.ts b/scripts/realm/upgrades/upgrade-addFreezeFn.ts new file mode 100644 index 00000000..408a0d97 --- /dev/null +++ b/scripts/realm/upgrades/upgrade-addFreezeFn.ts @@ -0,0 +1,67 @@ +import { run, ethers } from "hardhat"; +//import { maticTileDiamondAddress } from "../../../constants"; +import { + convertFacetAndSelectorsToString, + DeployUpgradeTaskArgs, + FacetsAndAddSelectors, +} from "../../../tasks/deployUpgrade"; +import { OwnershipFacet } from "../../../typechain-types"; +import { varsForNetwork } from "../../../constants"; + +export async function upgrade() { + const c = await varsForNetwork(ethers); + + const facets: FacetsAndAddSelectors[] = [ + { + facetName: "BounceGateFacet", + addSelectors: [], + removeSelectors: [], + }, + { + facetName: "ERC721Facet", + addSelectors: [], + removeSelectors: [], + }, + { + facetName: "VRFFacet", + addSelectors: [], + removeSelectors: [], + }, + { + facetName: "RealmFacet", + addSelectors: [`function setDiamondPaused(bool _paused) external`], + removeSelectors: [], + }, + ]; + + const ownership = (await ethers.getContractAt( + "OwnershipFacet", + c.realmDiamond + )) as OwnershipFacet; + + const owner = await ownership.owner(); + console.log("owner:", owner); + + const joined = convertFacetAndSelectorsToString(facets); + + const args: DeployUpgradeTaskArgs = { + diamondAddress: c.realmDiamond, + facetsAndAddSelectors: joined, + useLedger: false, + useMultisig: false, + initAddress: ethers.constants.AddressZero, + initCalldata: "0x", + }; + + await run("deployUpgrade", args); +} + +if (require.main === module) { + upgrade() + .then(() => process.exit(0)) + // .then(() => console.log('upgrade completed') /* process.exit(0) */) + .catch((error) => { + console.error(error); + process.exit(1); + }); +} diff --git a/scripts/tile/upgrades/upgrade-addFreezeFn.ts b/scripts/tile/upgrades/upgrade-addFreezeFn.ts new file mode 100644 index 00000000..7ba81532 --- /dev/null +++ b/scripts/tile/upgrades/upgrade-addFreezeFn.ts @@ -0,0 +1,57 @@ +import { run, ethers } from "hardhat"; +//import { maticTileDiamondAddress } from "../../../constants"; +import { + convertFacetAndSelectorsToString, + DeployUpgradeTaskArgs, + FacetsAndAddSelectors, +} from "../../../tasks/deployUpgrade"; +import { OwnershipFacet } from "../../../typechain-types"; +import { varsForNetwork } from "../../../constants"; + +export async function upgrade() { + const c = await varsForNetwork(ethers); + + const facets: FacetsAndAddSelectors[] = [ + { + facetName: "ERC1155TileFacet", + addSelectors: [], + removeSelectors: [], + }, + { + facetName: "TileFacet", + addSelectors: [`function setDiamondPaused(bool _paused) external`], + removeSelectors: [], + }, + ]; + + const ownership = (await ethers.getContractAt( + "OwnershipFacet", + c.tileDiamond + )) as OwnershipFacet; + + const owner = await ownership.owner(); + console.log("owner:", owner); + + const joined = convertFacetAndSelectorsToString(facets); + + const args: DeployUpgradeTaskArgs = { + diamondAddress: c.tileDiamond, + facetsAndAddSelectors: joined, + useLedger: false, + useMultisig: false, + initAddress: ethers.constants.AddressZero, + initCalldata: "0x", + }; + + await run("deployUpgrade", args); +} + +if (require.main === module) { + upgrade() + .then(() => process.exit(0)) + // .then(() => console.log('upgrade completed') /* process.exit(0) */) + .catch((error) => { + console.error(error); + process.exit(1); + }); +} diff --git a/scripts/upgrade-batchAddFreezeFn.ts b/scripts/upgrade-batchAddFreezeFn.ts new file mode 100644 index 00000000..13307acd --- /dev/null +++ b/scripts/upgrade-batchAddFreezeFn.ts @@ -0,0 +1,13 @@ +import { upgrade as realmUpgrade } from "./realm/upgrades/upgrade-addFreezeFn"; +import { upgrade as installationUpgrade } from "./installation/upgrades/upgrade-addFreezeFn"; +import { upgrade as tileUpgrade } from "./tile/upgrades/upgrade-addFreezeFn"; + +async function upgrade() { + await realmUpgrade(); + await installationUpgrade(); + await tileUpgrade(); +} + +if (require.main === module) { + upgrade(); +}