Skip to content

Commit 241e2f0

Browse files
committed
add more flexibility for control
1 parent b95fba9 commit 241e2f0

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
lines changed

solidity/contracts/Gravity.sol

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ contract Gravity is ReentrancyGuard, AccessControl, Pausable, Ownable {
8585
using SafeERC20 for IERC20;
8686

8787
bytes32 public constant RELAYER = keccak256("RELAYER");
88-
bytes32 public constant RELAYER_ADMIN = keccak256("RELAYER_ADMIN");
88+
bytes32 public constant CONTROL = keccak256("CONTROL");
89+
bytes32 public constant ADMIN = keccak256("ADMIN");
8990

9091
// These are updated often
9192
bytes32 public state_lastValsetCheckpoint;
@@ -128,6 +129,11 @@ contract Gravity is ReentrancyGuard, AccessControl, Pausable, Ownable {
128129
_;
129130
}
130131

132+
modifier checkControl() {
133+
_checkRole(CONTROL, msg.sender);
134+
_;
135+
}
136+
131137
// TransactionBatchExecutedEvent and SendToCosmosEvent both include the field _eventNonce.
132138
// This is incremented every time one of these events is emitted. It is checked by the
133139
// Cosmos module to ensure that all events are received in order, and that none are lost.
@@ -686,7 +692,7 @@ contract Gravity is ReentrancyGuard, AccessControl, Pausable, Ownable {
686692
string calldata _name,
687693
string calldata _symbol,
688694
uint8 _decimals
689-
) external {
695+
) external whenNotPaused checkWhiteList {
690696
// Deploy an ERC20 with entire supply granted to Gravity.sol
691697
CosmosERC20 erc20 = new CosmosERC20(address(this), _name, _symbol, _decimals);
692698

@@ -709,15 +715,15 @@ contract Gravity is ReentrancyGuard, AccessControl, Pausable, Ownable {
709715
* Only owner
710716
* pause will deactivate contract functionalities
711717
*/
712-
function pause() public onlyOwner {
718+
function pause() public checkControl {
713719
_pause();
714720
}
715721

716722
/**
717723
* Only owner
718724
* unpause will re activate contract functionalities
719725
*/
720-
function unpause() public onlyOwner {
726+
function unpause() public checkControl {
721727
_unpause();
722728
}
723729

@@ -765,16 +771,16 @@ contract Gravity is ReentrancyGuard, AccessControl, Pausable, Ownable {
765771

766772
function setAnyoneCanRelay (
767773
bool _anyoneCanRelay
768-
) public onlyRole(RELAYER_ADMIN) {
774+
) public onlyRole(ADMIN) {
769775
anyoneCanRelay = _anyoneCanRelay;
770776
emit AnyoneCanRelay(anyoneCanRelay);
771777
}
772778

773-
function transferRelayerAdmin (
779+
function transferAdmin (
774780
address _newAdmin
775-
) public onlyRole(RELAYER_ADMIN) {
776-
grantRole(RELAYER_ADMIN, _newAdmin);
777-
revokeRole(RELAYER_ADMIN, msg.sender);
781+
) public onlyRole(ADMIN) {
782+
grantRole(ADMIN, _newAdmin);
783+
revokeRole(ADMIN, msg.sender);
778784
}
779785

780786
constructor(
@@ -785,7 +791,7 @@ contract Gravity is ReentrancyGuard, AccessControl, Pausable, Ownable {
785791
// The validator set
786792
address[] memory _validators,
787793
uint256[] memory _powers,
788-
address relayerAdmin
794+
address _admin
789795
) {
790796
// CHECKS
791797

@@ -824,9 +830,10 @@ contract Gravity is ReentrancyGuard, AccessControl, Pausable, Ownable {
824830

825831
// ACL
826832

827-
_setupRole(RELAYER_ADMIN, relayerAdmin);
828-
_setRoleAdmin(RELAYER, RELAYER_ADMIN);
829-
_setRoleAdmin(RELAYER_ADMIN, RELAYER_ADMIN);
833+
_setupRole(ADMIN, _admin);
834+
_setRoleAdmin(RELAYER, ADMIN);
835+
_setRoleAdmin(CONTROL, ADMIN);
836+
_setRoleAdmin(ADMIN, ADMIN);
830837

831838
// LOGS
832839

solidity/test/pause.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const { expect } = chai;
1717

1818
async function runTest(opts: {
1919
isRelayer?: boolean;
20-
isOwner?: boolean;
20+
isControl?: boolean;
2121
pause?: boolean;
2222
unpause?: boolean;
2323
}) {
@@ -37,8 +37,11 @@ async function runTest(opts: {
3737
checkpoint: deployCheckpoint
3838
} = await deployContracts(gravityId, validators, powers, powerThreshold);
3939

40-
if (opts.isOwner) {
41-
await gravity.transferOwnership(signers[1].address);
40+
if (opts.isControl) {
41+
await gravity.grantRole(
42+
await gravity.CONTROL(),
43+
signers[1].address,
44+
);
4245
}
4346

4447
if (opts.pause) {
@@ -51,21 +54,21 @@ async function runTest(opts: {
5154
}
5255

5356
describe("pause tests", function () {
54-
it("non-owner cannot call pause()", async function () {
57+
it("non control admin cannot call pause()", async function () {
5558
await expect(runTest({
5659
pause: true
57-
})).to.be.revertedWith("Ownable: caller is not the owner");
60+
})).to.be.revertedWith("AccessControl: account 0xead9c93b79ae7c1591b1fb5323bd777e86e150d4 is missing role 0xbdded29a54e6a5d6169bedea55373b06f57e35d7b0f67ac187565b435e2cc943");
5861
});
5962

60-
it("non-owner cannot call unpause()", async function () {
63+
it("non control admin call unpause()", async function () {
6164
await expect(runTest({
6265
unpause: true
63-
})).to.be.revertedWith("Ownable: caller is not the owner");
66+
})).to.be.revertedWith("AccessControl: account 0xead9c93b79ae7c1591b1fb5323bd777e86e150d4 is missing role 0xbdded29a54e6a5d6169bedea55373b06f57e35d7b0f67ac187565b435e2cc943");
6467
});
6568

66-
it("owner can call pause() and unpause()", async function () {
69+
it("control admin can call pause() and unpause()", async function () {
6770
await runTest({
68-
isOwner: true,
71+
isControl: true,
6972
pause: true,
7073
unpause: true,
7174
});

solidity/test/transferRelayerAdmin.ts.bak renamed to solidity/test/transferRelayerAdmin.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { expect } = chai;
1616

1717

1818
async function runTest(opts: {
19-
isRelayerAdmin?: boolean;
19+
isAdmin?: boolean;
2020
}) {
2121

2222

@@ -35,22 +35,22 @@ async function runTest(opts: {
3535
} = await deployContracts(gravityId, validators, powers, powerThreshold);
3636

3737

38-
if (!opts.isRelayerAdmin) {
39-
await gravity.connect(signers[1]).transferRelayerAdmin(signers[1].address);
38+
if (!opts.isAdmin) {
39+
await gravity.connect(signers[1]).transferAdmin(signers[1].address);
4040
}
4141

4242
}
4343

4444
describe("transferRelayerAdmin tests", function () {
45-
it("Only relayerAdmin can call transferRelayerAdmin", async function () {
45+
it("non admin cannot call transferAdmin", async function () {
4646
await expect(runTest({
47-
isRelayerAdmin: false
48-
})).to.be.revertedWith("Ownable: caller is not the owner");
47+
isAdmin: false
48+
})).to.be.revertedWith("AccessControl: account 0xead9c93b79ae7c1591b1fb5323bd777e86e150d4 is missing role 0xdf8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec42");
4949
});
5050

51-
it("old relayAdmin have no role after transferred", async function () {
51+
it("admin can call transferAdmin", async function () {
5252
await expect(runTest({
53-
isRelayerAdmin: true
54-
})).to.be.revertedWith("Ownable: caller is not the owner");
53+
isAdmin: true
54+
}))
5555
});
5656
});

0 commit comments

Comments
 (0)