Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/GEMxToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ contract GEMxToken is
return address(oracle);
}

function setOracleAddress(address newAddress) external onlyRole(DEFAULT_ADMIN_ROLE) {
oracle = AggregatorV3Interface(newAddress);
}

function getEsuPerToken() external view returns (uint256, uint256) {
return (esuPerTokenValue, esuPerTokenPrecision);
}
Expand Down
1 change: 0 additions & 1 deletion test/mocks/MockV3Aggregator.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity 0.8.20;

import {AggregatorV3Interface} from "@chainlink/contracts/v0.8/shared/interfaces/AggregatorV3Interface.sol";
Expand Down
21 changes: 20 additions & 1 deletion test/unit/GEMxTokenTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ contract GEMxTokenTest is Test {
assertEq(esuPrecision, 100, "Initial EsuPerToken is 0.01");
}

/*##################################################################################*/
/*################################# Oracle Update ##################################*/
/*##################################################################################*/

function testOnlyAdminCanUpdateOracle() public {
address currentOracleAddress = token.getOracleAddress();
MockV3Aggregator newOracle = new MockV3Aggregator(1000);

vm.expectRevert(
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, user, token.DEFAULT_ADMIN_ROLE())
);
vm.prank(user);
token.setOracleAddress(address(newOracle));
assertEq(token.getOracleAddress(), currentOracleAddress);

vm.prank(admin);
token.setOracleAddress(address(newOracle));
assertEq(token.getOracleAddress(), address(newOracle));
}

/*##################################################################################*/
/*###################################### ESU #######################################*/
/*##################################################################################*/
Expand Down Expand Up @@ -132,7 +152,6 @@ contract GEMxTokenTest is Test {
token.setEsuPerToken(9, 10000);

(esu, esuPrecision) = token.getEsuPerToken();

assertEq(esu, 9);
assertEq(esuPrecision, 10000);
}
Expand Down
Loading