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

chore(edits): UMA Extension Edits #157

98 changes: 57 additions & 41 deletions contracts/adapters/OptimisticAuctionRebalanceExtensionV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@ pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";

import { AddressArrayUtils } from "../lib/AddressArrayUtils.sol";

import { AncillaryData } from "../lib/AncillaryData.sol";
import { AssetAllowList } from "../lib/AssetAllowList.sol";
import { AuctionRebalanceExtension } from "./AuctionRebalanceExtension.sol";
import { IAuctionRebalanceModuleV1 } from "../interfaces/IAuctionRebalanceModuleV1.sol";
import { IBaseManager } from "../interfaces/IBaseManager.sol";
import { ISetToken } from "../interfaces/ISetToken.sol";
import {AuctionRebalanceExtension} from "./AuctionRebalanceExtension.sol";
import {AncillaryData } from "../lib/AncillaryData.sol";
import { AssetAllowList } from "../lib/AssetAllowList.sol";
import {OptimisticOracleV3Interface} from "../interfaces/OptimisticOracleV3Interface.sol";
import { OptimisticOracleV3Interface } from "../interfaces/OptimisticOracleV3Interface.sol";

/**
* @title BaseOptimisticAuctionRebalanceExtension
* @title OptimisticAuctionRebalanceExtension
* @author Index Coop
*
* @dev The contract extends `BaseAuctionRebalanceExtension` by adding an optimistic oracle mechanism for validating rules on the proposing and executing of rebalances.
* @dev The contract extends `AuctionRebalanceExtension` by adding an optimistic oracle mechanism for validating rules on the proposing and executing of rebalances.
* It allows setting product-specific parameters for optimistic rebalancing and includes callback functions for resolved or disputed assertions.
* @dev Version 1 is characterised by: Optional Asset Whitelist, No Set Token locking, control over rebalance timing via "isOpen" flag
*/
Expand All @@ -52,6 +51,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
OptimisticRebalanceParams optimisticParams,
bytes32 indexed rulesHash
);

event RebalanceProposed(
ISetToken indexed setToken,
IERC20 indexed quoteAsset,
Expand All @@ -74,7 +74,11 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
event ProposalDeleted(
bytes32 assertionID,
Proposal indexed proposal
);
);

event IsOpenUpdated(
bool indexed isOpen
);

/* ============ Structs ============ */

Expand Down Expand Up @@ -117,12 +121,18 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As

/* ============ Constructor ============ */
/*
* @dev Initializes the BaseOptimisticAuctionRebalanceExtension with the passed parameters.
* @dev Initializes the OptimisticAuctionRebalanceExtension with the passed parameters.
*
* @param _auctionParams AuctionExtensionParams struct containing the baseManager and auctionModule addresses.
*/
constructor(AuctionExtensionParams memory _auctionParams) public AuctionRebalanceExtension(_auctionParams.baseManager, _auctionParams.auctionModule) AssetAllowList(_auctionParams.allowedAssets, _auctionParams.useAssetAllowlist) {

constructor(
AuctionExtensionParams memory _auctionParams
)
public
AuctionRebalanceExtension(_auctionParams.baseManager, _auctionParams.auctionModule)
AssetAllowList(_auctionParams.allowedAssets, _auctionParams.useAssetAllowlist)
{

}

/* ============ Modifier ============ */
Expand All @@ -135,7 +145,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
/* ============ External Functions ============ */

/**
* ONLY OPERATOR: Add new asset(s) that can be traded to, wrapped to, or claimed
* ONLY OPERATOR: Add new asset(s) that can be included as new components in rebalances
*
* @param _assets New asset(s) to add
*/
Expand All @@ -144,7 +154,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
}

/**
* ONLY OPERATOR: Remove asset(s) so that it/they can't be traded to, wrapped to, or claimed
* ONLY OPERATOR: Remove asset(s) so that it/they can't be included as new components in rebalances
*
* @param _assets Asset(s) to remove
*/
Expand All @@ -169,11 +179,9 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
* @param _isOpen Bool indicating whether the extension is open for proposing rebalances.
*/
function updateIsOpen(bool _isOpen) external onlyOperator {
isOpen = _isOpen;
_updateIsOpen(_isOpen);
}



/**
* @dev OPERATOR ONLY: sets product settings for a given set token
* @param _optimisticParams OptimisticRebalanceParams struct containing optimistic rebalance parameters.
Expand All @@ -190,10 +198,13 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
optimisticParams: _optimisticParams,
rulesHash: _rulesHash
});

emit ProductSettingsUpdated(setToken, setToken.manager(), _optimisticParams, _rulesHash);
}

/**
/**
* @dev IF OPEN ONLY: Proposes a rebalance for the SetToken using the Optimistic Oracle V3.
*
* @param _quoteAsset ERC20 token used as the quote asset in auctions.
* @param _oldComponents Addresses of existing components in the SetToken.
* @param _newComponents Addresses of new components to be added.
Expand Down Expand Up @@ -231,7 +242,6 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
require(productSettings.rulesHash != bytes32(""), "Rules not set");
require(address(productSettings.optimisticParams.optimisticOracleV3) != address(0), "Oracle not set");


bytes memory claim = _constructClaim(proposalHash, productSettings.rulesHash);
uint256 totalBond = _pullBond(productSettings.optimisticParams);

Expand All @@ -255,7 +265,6 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As

emit RebalanceProposed( setToken, _quoteAsset, _oldComponents, _newComponents, _newComponentsAuctionParams, _oldComponentsAuctionParams, _rebalanceDuration, _positionMultiplier);
emit AssertedClaim(setToken, msg.sender, productSettings.rulesHash, assertionId, claim);

}

/**
Expand Down Expand Up @@ -332,20 +341,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
);

invokeManager(address(auctionModule), callData);
isOpen = false;
}

// Constructs the claim that will be asserted at the Optimistic Oracle V3.
function _constructClaim(bytes32 proposalHash, bytes32 rulesHash) internal pure returns (bytes memory) {
return
abi.encodePacked(
AncillaryData.appendKeyValueBytes32("", PROPOSAL_HASH_KEY, proposalHash),
",",
RULES_KEY,
":\"",
rulesHash,
"\""
);
_updateIsOpen(false);
}

/**
Expand Down Expand Up @@ -380,6 +376,30 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
emit ProposalDeleted(_assertionId, proposal);
}

/* ============ Internal Functions ============ */

// Constructs the claim that will be asserted at the Optimistic Oracle V3.
function _constructClaim(bytes32 proposalHash, bytes32 rulesHash) internal pure returns (bytes memory) {
return
abi.encodePacked(
AncillaryData.appendKeyValueBytes32("", PROPOSAL_HASH_KEY, proposalHash),
",",
RULES_KEY,
":\"",
rulesHash,
"\""
);
}

/// @notice Delete an existing proposal and associated assertionId.
/// @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];
}

/// @notice Pulls the higher of the minimum bond or configured bond amount from the sender.
/// @dev Internal function to pull the user's bond before asserting a claim.
/// @param optimisticRebalanceParams optimistic rebalance parameters for the product.
Expand All @@ -394,13 +414,9 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
return totalBond;
}

/// @notice Delete an existing proposal and associated assertionId.
/// @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];
function _updateIsOpen(bool _isOpen) internal {
isOpen = _isOpen;
emit IsOpenUpdated(_isOpen);
}

}
16 changes: 6 additions & 10 deletions contracts/lib/AssetAllowList.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 Set Labs Inc.
Copyright 2023 Index Coop

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,17 +20,14 @@ pragma solidity 0.6.10;
import { AddressArrayUtils } from "./AddressArrayUtils.sol";

/**
* @title ModuleBase
* @author Set Protocol
*
* Abstract class that houses common Module-related state and functions.
*
* CHANGELOG:
* - 4/21/21: Delegated modifier logic to internal helpers to reduce contract size
* @title AssetAllowList
* @author Index Coop
*
* Abstract contract that allows inheriting contracts to restrict the assets that can be traded to, wrapped to, or claimed
*/
abstract contract AssetAllowList {
using AddressArrayUtils for address[];

/* ============ Events ============ */

event AllowedAssetAdded(
Expand Down Expand Up @@ -61,7 +58,7 @@ abstract contract AssetAllowList {
modifier onlyAllowedAssets(address[] memory _assets) {
require(
_areAllowedAssets(_assets),
"BaseOptimisticAuctionRebalanceExtension.onlyAllowedAssets: Invalid asset"
"Invalid asset"
);
_;
}
Expand Down Expand Up @@ -148,4 +145,3 @@ abstract contract AssetAllowList {
return true;
}
}

Loading