Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Oracle update permissioning #81

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/perennial-oracle/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ contract Oracle is IOracle, Instance {

/// @notice Updates the current oracle provider
/// @param newProvider The new oracle provider
function update(IOracleProvider newProvider) external onlyOwner {
function update(IOracleProvider newProvider) external {
if (msg.sender != address(factory())) revert OracleNotFactoryError();
_updateCurrent(newProvider);
_updateLatest(newProvider.latest());
}
Expand Down
1 change: 1 addition & 0 deletions packages/perennial-oracle/contracts/interfaces/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "@equilibria/root/attribute/interfaces/IInstance.sol";
import "@equilibria/perennial-v2/contracts/interfaces/IOracleProvider.sol";

interface IOracle is IOracleProvider, IInstance {
error OracleNotFactoryError();
error OracleOutOfSyncError();
error OracleOutOfOrderCommitError();

Expand Down
13 changes: 7 additions & 6 deletions packages/perennial-oracle/test/unit/oracle/Oracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('Oracle', () => {

context('updates the oracle w/o sync', async () => {
beforeEach(async () => {
await expect(oracle.connect(owner).update(underlying1.address))
await expect(oracle.connect(oracleFactorySigner).update(underlying1.address))
.to.emit(oracle, 'OracleUpdated')
.withArgs(underlying1.address)
})
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('Oracle', () => {
it('reverts when oracle out of sync', async () => {
const underlying2 = await smock.fake<IOracleProvider>('IOracleProvider')

await expect(oracle.connect(owner).update(underlying2.address)).to.revertedWithCustomError(
await expect(oracle.connect(oracleFactorySigner).update(underlying2.address)).to.revertedWithCustomError(
oracle,
'OracleOutOfSyncError',
)
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('Oracle', () => {
1687230905,
)
await oracle.connect(caller).request(user.address)
await expect(oracle.connect(owner).update(underlying1.address))
await expect(oracle.connect(oracleFactorySigner).update(underlying1.address))
.to.emit(oracle, 'OracleUpdated')
.withArgs(underlying1.address)
})
Expand Down Expand Up @@ -496,9 +496,10 @@ describe('Oracle', () => {
})

it('reverts when not the owner', async () => {
await expect(oracle.connect(user).update(underlying1.address))
.to.revertedWithCustomError(oracle, 'InstanceNotOwnerError')
.withArgs(user.address)
await expect(oracle.connect(user).update(underlying1.address)).to.revertedWithCustomError(
oracle,
'OracleNotFactoryError',
)
})
})

Expand Down