Skip to content

Commit

Permalink
Remove Proposal struct because we are only managing one product per e…
Browse files Browse the repository at this point in the history
…xtension
  • Loading branch information
ckoopmann committed Jan 4, 2024
1 parent ac92088 commit cc8a357
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
27 changes: 9 additions & 18 deletions contracts/adapters/OptimisticAuctionRebalanceExtensionV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As

event ProposalDeleted(
bytes32 assertionID,
Proposal indexed proposal
bytes32 indexed proposalHash
);

event IsOpenUpdated(
Expand Down Expand Up @@ -102,16 +102,11 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
bytes32 rulesHash; // IPFS hash of the rules for the product.
}

struct Proposal{
bytes32 proposalHash; // Hash of the proposal.
ISetToken product; // Address of the SetToken to set rules and settings for.
}

/* ============ State Variables ============ */

ProductSettings public productSettings; // Mapping of set token to ProductSettings
mapping(bytes32 => bytes32) public assertionIds; // Maps proposal hashes to assertionIds.
mapping(bytes32 => Proposal) public proposedProduct; // Maps assertionIds to a Proposal.
mapping(bytes32 => bytes32) public assertionIdToProposalHash; // Maps assertionIds to a proposal hash.
bool public isOpen; // Bool indicating whether the extension is open for proposing rebalances.

// Keys for assertion claim data.
Expand Down Expand Up @@ -256,10 +251,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
);

assertionIds[proposalHash] = assertionId;
proposedProduct[assertionId] = Proposal({
proposalHash: proposalHash,
product: setToken
});
assertionIdToProposalHash[assertionId] = proposalHash;

emit RebalanceProposed( setToken, _quoteAsset, _oldComponents, _newComponents, _newComponentsAuctionParams, _oldComponentsAuctionParams, _rebalanceDuration, _positionMultiplier);
emit AssertedClaim(setToken, msg.sender, productSettings.rulesHash, assertionId, claim);
Expand Down Expand Up @@ -355,8 +347,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
* @param _assertionId the identifier of the disputed assertion.
*/
function assertionDisputedCallback(bytes32 _assertionId) external {
Proposal memory proposal = proposedProduct[_assertionId];
require(proposal.product == setToken, "Invalid proposal product");
bytes32 proposalHash = assertionIdToProposalHash[_assertionId];

require(address(productSettings.optimisticParams.optimisticOracleV3) != address(0), "Invalid oracle address");

Expand All @@ -367,11 +358,11 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As

} else {
// If the sender is not the expected Optimistic Oracle V3, check if the expected Oracle has the assertion and if not delete.
require(proposal.proposalHash != bytes32(0), "Invalid proposal hash");
require(proposalHash != bytes32(0), "Invalid proposal hash");
require(productSettings.optimisticParams.optimisticOracleV3.getAssertion(_assertionId).asserter == address(0), "Oracle has assertion");
_deleteProposal(_assertionId);
}
emit ProposalDeleted(_assertionId, proposal);
emit ProposalDeleted(_assertionId, proposalHash);
}

/* ============ Internal Functions ============ */
Expand All @@ -394,9 +385,9 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
/// @dev Internal function that deletes a proposal and associated assertionId.
/// @param assertionId assertionId of the proposal to delete.
function _deleteProposal(bytes32 assertionId) internal {
Proposal memory proposal = proposedProduct[assertionId];
delete assertionIds[proposal.proposalHash];
delete proposedProduct[assertionId];
bytes32 proposalHash = assertionIdToProposalHash[assertionId];
delete assertionIds[proposalHash];
delete assertionIdToProposalHash[assertionId];
}

/// @notice Pulls the higher of the minimum bond or configured bond amount from the sender.
Expand Down
40 changes: 23 additions & 17 deletions test/adapters/optimisticAuctionRebalanceExtensionV1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,18 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
await subject();
});

it("should update proposed products correctly", async () => {
it("should update proposal hash correctly", async () => {
const proposalHashBefore = await auctionRebalanceExtension
.connect(subjectCaller.wallet)
.assertionIdToProposalHash(utils.formatBytes32String("win"));
expect(proposalHashBefore).to.eq(constants.HashZero);

await subject();
const proposal = await auctionRebalanceExtension

const proposalHashAfter = await auctionRebalanceExtension
.connect(subjectCaller.wallet)
.proposedProduct(utils.formatBytes32String("win"));
expect(proposal.product).to.eq(setToken.address);
.assertionIdToProposalHash(utils.formatBytes32String("win"));
expect(proposalHashAfter).to.not.eq(constants.HashZero);
});

it("should pull bond", async () => {
Expand Down Expand Up @@ -788,12 +794,12 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
}
});

describe("assertionDisputedCallback", () => {
describe("#assertionDisputedCallback", () => {
it("should delete the proposal on a disputed callback", async () => {
const proposal = await auctionRebalanceExtension
const proposalHash = await auctionRebalanceExtension
.connect(subjectCaller.wallet)
.proposedProduct(utils.formatBytes32String("win"));
expect(proposal.product).to.eq(setToken.address);
.assertionIdToProposalHash(utils.formatBytes32String("win"));
expect(proposalHash).to.not.eq(constants.HashZero);

await expect(
optimisticOracleV3Mock
Expand All @@ -804,10 +810,10 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
),
).to.not.be.reverted;

const proposalAfter = await auctionRebalanceExtension
const proposalHashAfter = await auctionRebalanceExtension
.connect(subjectCaller.wallet)
.proposedProduct(utils.formatBytes32String("win"));
expect(proposalAfter.product).to.eq(ADDRESS_ZERO);
.assertionIdToProposalHash(utils.formatBytes32String("win"));
expect(proposalHashAfter).to.eq(constants.HashZero);
});

it("should delete the proposal on a disputed callback from currently set oracle", async () => {
Expand All @@ -824,10 +830,10 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
),
);

const proposal = await auctionRebalanceExtension
const proposalHash = await auctionRebalanceExtension
.connect(subjectCaller.wallet)
.proposedProduct(utils.formatBytes32String("win"));
expect(proposal.product).to.eq(setToken.address);
.assertionIdToProposalHash(utils.formatBytes32String("win"));
expect(proposalHash).to.not.eq(constants.HashZero);
await expect(
optimisticOracleV3Mock
.connect(subjectCaller.wallet)
Expand All @@ -837,10 +843,10 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
),
).to.not.be.reverted;

const proposalAfter = await auctionRebalanceExtension
const proposalHashAfter = await auctionRebalanceExtension
.connect(subjectCaller.wallet)
.proposedProduct(utils.formatBytes32String("win"));
expect(proposalAfter.product).to.eq(ADDRESS_ZERO);
.assertionIdToProposalHash(utils.formatBytes32String("win"));
expect(proposalHashAfter).to.eq(constants.HashZero);
});
});

Expand Down

0 comments on commit cc8a357

Please sign in to comment.