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(og): L-02 - Emit event on syncing upgraded OOv3 #4487

Merged
merged 4 commits into from
Mar 22, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ contract OptimisticGovernor is OptimisticOracleV3CallbackRecipientInterface, Mod

event SetEscalationManager(address indexed escalationManager);

event OptimisticOracleChanged(address indexed newOptimisticOracleV3);

FinderInterface public immutable finder; // Finder used to discover other UMA ecosystem contracts.

IERC20 public collateral; // Collateral currency used to assert proposed transactions.
Expand Down Expand Up @@ -418,9 +420,11 @@ contract OptimisticGovernor is OptimisticOracleV3CallbackRecipientInterface, Mod

// Caches the address of the Optimistic Oracle V3 from the Finder.
function _sync() internal {
optimisticOracleV3 = OptimisticOracleV3Interface(
finder.getImplementationAddress(OracleInterfaces.OptimisticOracleV3)
);
address newOptimisticOracleV3 = finder.getImplementationAddress(OracleInterfaces.OptimisticOracleV3);
if (newOptimisticOracleV3 != address(optimisticOracleV3)) {
optimisticOracleV3 = OptimisticOracleV3Interface(newOptimisticOracleV3);
emit OptimisticOracleChanged(newOptimisticOracleV3);
}
}

// Checks if the address is a contract.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,28 @@ describe("OptimisticGovernor", () => {
);
});

it("Can reset Escalation Manager to zero address", async function () {
// Deploy Full Policy Escalation Manager and set it as new Escalation Manager.
const newEscalationManager = await FullPolicyEscalationManager.new(optimisticOracleV3.options.address).send({
from: owner,
});
const setEscalationManagerData = optimisticOracleModule.methods
.setEscalationManager(newEscalationManager.options.address)
.encodeABI();
await avatar.methods
.exec(optimisticOracleModule.options.address, "0", setEscalationManagerData)
.send({ from: owner });

// Reset Escalation Manager to zero address.
const resetEscalationManagerData = optimisticOracleModule.methods.setEscalationManager(ZERO_ADDRESS).encodeABI();
await avatar.methods
.exec(optimisticOracleModule.options.address, "0", resetEscalationManagerData)
.send({ from: owner });

// Check that Escalation Manager is set to zero address.
assert.equal(await optimisticOracleModule.methods.escalationManager().call(), ZERO_ADDRESS);
});

it("Cannot process callback from Optimistic Oracle V3 with invalid assertionId", async function () {
// Create assertion directly with Optimistic Oracle V3 and pointing Optimistic Governor as the callback recipient.
await bondToken.methods.approve(optimisticOracleV3.options.address, bond).send({ from: proposer });
Expand Down Expand Up @@ -1267,25 +1289,37 @@ describe("OptimisticGovernor", () => {
);
});

it("Can reset Escalation Manager to zero address", async function () {
// Deploy Full Policy Escalation Manager and set it as new Escalation Manager.
const newEscalationManager = await FullPolicyEscalationManager.new(optimisticOracleV3.options.address).send({
from: owner,
});
const setEscalationManagerData = optimisticOracleModule.methods
.setEscalationManager(newEscalationManager.options.address)
.encodeABI();
await avatar.methods
.exec(optimisticOracleModule.options.address, "0", setEscalationManagerData)
it("Emits event on syncing new Optimistic Oracle V3", async function () {
// Upgrade the Optimistic Oracle V3.
const defaultCurrency = await TestnetERC20.new("Default Currency", "DC", 18).send({ from: owner });
const newOptimisticOracleV3 = await OptimisticOracleV3Test.new(
finder.options.address,
defaultCurrency.options.address,
liveness,
timer.options.address
).send({ from: owner });
await finder.methods
.changeImplementationAddress(utf8ToHex(interfaceName.OptimisticOracleV3), newOptimisticOracleV3.options.address)
.send({ from: owner });

// Reset Escalation Manager to zero address.
const resetEscalationManagerData = optimisticOracleModule.methods.setEscalationManager(ZERO_ADDRESS).encodeABI();
await avatar.methods
.exec(optimisticOracleModule.options.address, "0", resetEscalationManagerData)
// Cache the upgraded Optimistic Oracle V3 and check the event is emitted.
const receipt = await optimisticOracleModule.methods.sync().send({ from: disputer });
await assertEventEmitted(
receipt,
optimisticOracleModule,
"OptimisticOracleChanged",
(event) => event.newOptimisticOracleV3 == newOptimisticOracleV3.options.address
);

// Revert to the original Optimistic Oracle V3 for other tests.
await finder.methods
.changeImplementationAddress(utf8ToHex(interfaceName.OptimisticOracleV3), optimisticOracleV3.options.address)
.send({ from: owner });
});

// Check that Escalation Manager is set to zero address.
assert.equal(await optimisticOracleModule.methods.escalationManager().call(), ZERO_ADDRESS);
it("Does not emit event on syncing the same Optimistic Oracle V3", async function () {
// Sync the Optimistic Oracle V3 and check the event is not emitted.
const receipt = await optimisticOracleModule.methods.sync().send({ from: owner });
assert.equal(Object.keys(receipt.events).length, 0);
});
});