-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: XMTP messages contracts are upgradeable and pausable
- Loading branch information
Showing
12 changed files
with
135 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@openzeppelin-contracts-5.1.0/=dependencies/@openzeppelin-contracts-5.1.0/ | ||
forge-std-1.9.4/=dependencies/forge-std-1.9.4/ | ||
@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-5.1.0/ | ||
@openzeppelin-contracts-upgradeable/=dependencies/@openzeppelin-contracts-upgradeable-5.1.0/ | ||
forge-std/=dependencies/forge-std-1.9.4/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.28; | ||
|
||
import "forge-std/src/Script.sol"; | ||
import "src/GroupMessages.sol"; | ||
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
|
||
contract DeployProxiedGroupMessages is Script { | ||
function run() external { | ||
uint256 privateKey = vm.envUint("PRIVATE_KEY"); | ||
vm.startBroadcast(privateKey); | ||
|
||
// Step 1: Deploy the implementation contract | ||
GroupMessages groupMessagesImpl = new GroupMessages(); | ||
|
||
// Step 2: Deploy the proxy contract | ||
ERC1967Proxy proxy = new ERC1967Proxy( | ||
address(groupMessagesImpl), | ||
abi.encodeWithSelector(GroupMessages.initialize.selector) | ||
); | ||
|
||
// Log the deployed contract addresses | ||
console.log("Implementation Address:", address(groupMessagesImpl)); | ||
console.log("Proxy Address:", address(proxy)); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
contracts/script/Deployer.s.sol → contracts/script/DeployerNodeRegistry.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.28; | ||
|
||
contract GroupMessages { | ||
import "@openzeppelin-contracts-upgradeable/access/AccessControlUpgradeable.sol"; | ||
import "@openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import "@openzeppelin-contracts-upgradeable/utils/PausableUpgradeable.sol"; | ||
import "@openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
|
||
/// @title XMTP Group Messages Contract | ||
contract GroupMessages is Initializable, AccessControlUpgradeable, UUPSUpgradeable, PausableUpgradeable { | ||
event MessageSent(bytes32 groupId, bytes message, uint64 sequenceId); | ||
event UpgradeAuthorized(address deployer, address newImplementation); | ||
|
||
uint64 sequenceId; | ||
uint64 private sequenceId; | ||
|
||
function addMessage(bytes32 groupId, bytes memory message) public { | ||
sequenceId++; | ||
/// @notice Initializes the contract with the deployer as admin. | ||
function initialize() public initializer { | ||
__UUPSUpgradeable_init(); | ||
__AccessControl_init(); | ||
__Pausable_init(); | ||
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
} | ||
|
||
/// @notice Pauses the contract. | ||
function pause() public onlyRole(DEFAULT_ADMIN_ROLE) { | ||
_pause(); | ||
} | ||
|
||
/// @notice Unpauses the contract. | ||
function unpause() public onlyRole(DEFAULT_ADMIN_ROLE) { | ||
_unpause(); | ||
} | ||
|
||
/// @notice Adds a message to the group. | ||
/// @param groupId The group ID. | ||
/// @param message The message in bytes. | ||
function addMessage(bytes32 groupId, bytes calldata message) public whenNotPaused { | ||
/// @dev Incrementing the sequence ID is safe here due to the extremely large limit of uint64. | ||
unchecked { | ||
sequenceId++; | ||
} | ||
|
||
emit MessageSent(groupId, message, sequenceId); | ||
} | ||
|
||
/// @dev Authorizes the upgrade of the contract. | ||
/// @param newImplementation The address of the new implementation. | ||
function _authorizeUpgrade(address newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE) { | ||
emit UpgradeAuthorized(msg.sender, newImplementation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.28; | ||
|
||
contract IdentityUpdates { | ||
import "@openzeppelin-contracts-upgradeable/access/AccessControlUpgradeable.sol"; | ||
import "@openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import "@openzeppelin-contracts-upgradeable/utils/PausableUpgradeable.sol"; | ||
import "@openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
|
||
/// @title XMTP Identity Updates Contract | ||
contract IdentityUpdates is Initializable, AccessControlUpgradeable, UUPSUpgradeable, PausableUpgradeable { | ||
event IdentityUpdateCreated(bytes32 inboxId, bytes update, uint64 sequenceId); | ||
event UpgradeAuthorized(address deployer, address newImplementation); | ||
|
||
uint64 sequenceId; | ||
uint64 private sequenceId; | ||
|
||
function addIdentityUpdate(bytes32 inboxId, bytes memory update) public { | ||
sequenceId++; | ||
/// @notice Initializes the contract with the deployer as admin. | ||
function initialize() public initializer { | ||
__UUPSUpgradeable_init(); | ||
__AccessControl_init(); | ||
__Pausable_init(); | ||
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
} | ||
|
||
/// @notice Pauses the contract. | ||
function pause() public onlyRole(DEFAULT_ADMIN_ROLE) { | ||
_pause(); | ||
} | ||
|
||
/// @notice Unpauses the contract. | ||
function unpause() public onlyRole(DEFAULT_ADMIN_ROLE) { | ||
_unpause(); | ||
} | ||
|
||
/// @notice Adds an identity update to an specific inbox ID. | ||
/// @param inboxId The inbox ID. | ||
/// @param update The identity update in bytes. | ||
function addIdentityUpdate(bytes32 inboxId, bytes calldata update) public whenNotPaused { | ||
/// @dev Incrementing the sequence ID is safe here due to the extremely large limit of uint64. | ||
unchecked { | ||
sequenceId++; | ||
} | ||
|
||
emit IdentityUpdateCreated(inboxId, update, sequenceId); | ||
} | ||
|
||
/// @dev Authorizes the upgrade of the contract. | ||
/// @param newImplementation The address of the new implementation. | ||
function _authorizeUpgrade(address newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE) { | ||
emit UpgradeAuthorized(msg.sender, newImplementation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters