From 35b188d0433ad9243cb9ee8f1d3ef476f0ffb03d Mon Sep 17 00:00:00 2001 From: Arjun Rao <2940142+arjun-io@users.noreply.github.com> Date: Fri, 25 Aug 2023 16:01:48 -0400 Subject: [PATCH] [Fix] Oracle update permissioning --- packages/perennial-oracle/contracts/Oracle.sol | 3 ++- packages/perennial-oracle/contracts/interfaces/IOracle.sol | 1 + packages/perennial-oracle/test/unit/oracle/Oracle.test.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/perennial-oracle/contracts/Oracle.sol b/packages/perennial-oracle/contracts/Oracle.sol index f811522c9..654fd5914 100644 --- a/packages/perennial-oracle/contracts/Oracle.sol +++ b/packages/perennial-oracle/contracts/Oracle.sol @@ -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()); } diff --git a/packages/perennial-oracle/contracts/interfaces/IOracle.sol b/packages/perennial-oracle/contracts/interfaces/IOracle.sol index 68af5fea7..1ce877b61 100644 --- a/packages/perennial-oracle/contracts/interfaces/IOracle.sol +++ b/packages/perennial-oracle/contracts/interfaces/IOracle.sol @@ -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(); diff --git a/packages/perennial-oracle/test/unit/oracle/Oracle.test.ts b/packages/perennial-oracle/test/unit/oracle/Oracle.test.ts index b92abc7ce..aa083a7ca 100644 --- a/packages/perennial-oracle/test/unit/oracle/Oracle.test.ts +++ b/packages/perennial-oracle/test/unit/oracle/Oracle.test.ts @@ -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) })