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

feat(extension): Add OptimisticAuctionRebalanceExtension #156

Merged
merged 38 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8fc395a
Initialize OptimisticAuctionRebalance module from Global version and …
ckoopmann Dec 7, 2023
7ee621d
Add AssetAllowList to BaseOptimisticRebalanceExtension
ckoopmann Dec 7, 2023
002f8d5
Use extisting AuctionRebalanceExtension
ckoopmann Dec 8, 2023
5314e89
Only allowed assets as new components
ckoopmann Dec 8, 2023
03d7edf
Port tests from global version
ckoopmann Dec 8, 2023
c2cba14
smol fix
ckoopmann Dec 8, 2023
4aa9028
PR Feedback round 2
ckoopmann Dec 12, 2023
7c040e9
PR Feedback round 3
ckoopmann Dec 18, 2023
c3d3902
Simplify constructor tests
ckoopmann Dec 18, 2023
a73d98b
Copy unit tests and run integrated with existing dseth deployment
ckoopmann Dec 15, 2023
05ec545
Test failing with unsupported identifier error
ckoopmann Dec 15, 2023
b093269
All tests passing against uma deployed oracle
ckoopmann Dec 18, 2023
a8d67aa
Set block number individually in test
ckoopmann Dec 18, 2023
bdf2861
Add isOpen boolean gate
ckoopmann Dec 20, 2023
6beb279
Set isOpen to false after starting rebalance
ckoopmann Dec 20, 2023
41a1e71
Add onlyIfOpen modifier to startRebalance function
ckoopmann Dec 20, 2023
ebeeda9
Refactor / extend integration tests
ckoopmann Dec 20, 2023
75b7107
Disable locking set token
ckoopmann Dec 20, 2023
9577f49
Adjust tests
ckoopmann Dec 20, 2023
77b876c
Add V1 suffix
ckoopmann Dec 20, 2023
ba40dae
Remove shouldLockSetToken argument entirely from propose method
ckoopmann Dec 20, 2023
84672e0
Add events for updating the isOpen parameter
ckoopmann Jan 3, 2024
83356e6
chore(edits): UMA Extension Edits (#157)
pblivin0x Jan 4, 2024
dbbfe5d
Merge branch 'ckoopmann/optimistic-auction-rebalance-extension' of gi…
ckoopmann Jan 4, 2024
ced1ad5
Add comment with link to optimistic governor reference implementation…
ckoopmann Jan 4, 2024
57e8ced
Additional tests arround asset allow list
ckoopmann Jan 4, 2024
c4401d9
Additional tests to increase coverage
ckoopmann Jan 4, 2024
ac92088
Declare setToken and auctionModule as immutable
ckoopmann Jan 4, 2024
cc8a357
Remove Proposal struct because we are only managing one product per e…
ckoopmann Jan 4, 2024
a62e71c
Additional tests to trigger require statements in dispute callback
ckoopmann Jan 4, 2024
bc4f074
Fix integration tests
ckoopmann Jan 4, 2024
3562bef
Update contracts/adapters/AuctionRebalanceExtension.sol
pblivin0x Jan 4, 2024
587ee0b
integration test cleanups
pblivin0x Jan 4, 2024
3b481b9
fix buy auction params
pblivin0x Jan 4, 2024
f1fcb69
Update contracts/adapters/OptimisticAuctionRebalanceExtensionV1.sol
pblivin0x Jan 4, 2024
eca86cd
cleanups
pblivin0x Jan 6, 2024
3261fab
Merge branch 'ckoopmann/optimistic-auction-rebalance-extension' of ht…
pblivin0x Jan 6, 2024
8ce942f
Dummy commit to retrigger CI
ckoopmann Jan 8, 2024
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
5 changes: 3 additions & 2 deletions contracts/adapters/AuctionRebalanceExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ contract AuctionRebalanceExtension is BaseExtension {

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

ISetToken public setToken;
IAuctionRebalanceModuleV1 public auctionModule; // AuctionRebalanceModuleV1
ISetToken public immutable setToken;
IAuctionRebalanceModuleV1 public immutable auctionModule; // AuctionRebalanceModuleV1

/* ============ Constructor ============ */

Expand Down Expand Up @@ -88,6 +88,7 @@ contract AuctionRebalanceExtension is BaseExtension {
uint256 _positionMultiplier
)
external
virtual
onlyOperator
{
address[] memory currentComponents = setToken.getComponents();
Expand Down
411 changes: 411 additions & 0 deletions contracts/adapters/OptimisticAuctionRebalanceExtensionV1.sol

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions contracts/interfaces/IIdentifierWhitelist.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

interface IIdentifierWhitelist {
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event SupportedIdentifierAdded(bytes32 indexed identifier);
event SupportedIdentifierRemoved(bytes32 indexed identifier);

function addSupportedIdentifier(bytes32 identifier) external;
function isIdentifierSupported(bytes32 identifier) external view returns (bool);
function owner() external view returns (address);
function removeSupportedIdentifier(bytes32 identifier) external;
function renounceOwnership() external;
function transferOwnership(address newOwner) external;
}
11 changes: 10 additions & 1 deletion contracts/interfaces/OptimisticOracleV3Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ interface OptimisticOracleV3Interface {
uint256 finalFee; // Final fee of the currency.
}

/**
* @notice Disputes an assertion. Depending on how the assertion was configured, this may either escalate to the UMA
* DVM or the configured escalation manager for arbitration.
* @dev The caller must approve this contract to spend at least bond amount of currency for the associated assertion.
* @param assertionId unique identifier for the assertion to dispute.
* @param disputer receives bonds back at settlement.
*/
function disputeAssertion(bytes32 assertionId, address disputer) external;

/**
* @notice Returns the default identifier used by the Optimistic Oracle V3.
* @return The default identifier.
Expand Down Expand Up @@ -167,4 +176,4 @@ interface OptimisticOracleV3Interface {
);

event AdminPropertiesSet(IERC20 defaultCurrency, uint64 defaultLiveness, uint256 burnedBondPercentage);
}
}
147 changes: 147 additions & 0 deletions contracts/lib/AssetAllowList.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
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.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache License, Version 2.0
*/

pragma solidity 0.6.10;
import { AddressArrayUtils } from "./AddressArrayUtils.sol";

/**
* @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(
address indexed _asset
);

event AllowedAssetRemoved(
address indexed _asset
);

event UseAssetAllowlistUpdated(
bool _status
);

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

// Boolean indicating wether to use asset allow list
bool public useAssetAllowlist;

// Mapping keeping track of allowed assets
mapping(address => bool) public assetAllowlist;

// List of allowed assets
address[] internal allowedAssets;

/* ============ Modifiers ============ */

modifier onlyAllowedAssets(address[] memory _assets) {
require(
_areAllowedAssets(_assets),
"Invalid asset"
);
_;
}

/* ============ Constructor ============ */

/**
* Set state variables and map asset pairs to their oracles
*
* @param _allowedAssets Array of allowed assets
* @param _useAssetAllowlist Bool indicating whether to use asset allow list
*/
constructor(address[] memory _allowedAssets, bool _useAssetAllowlist) public {
_addAllowedAssets(_allowedAssets);
_updateUseAssetAllowlist(_useAssetAllowlist);
}

/* ============ External Functions ============ */

function getAllowedAssets() external view returns(address[] memory) {
return allowedAssets;
}

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


/**
* Add new assets that can be traded to, wrapped to, or claimed
*
* @param _assets New asset to add
*/
function _addAllowedAssets(address[] memory _assets) internal {
for (uint256 i = 0; i < _assets.length; i++) {
address asset = _assets[i];

require(!assetAllowlist[asset], "Asset already added");

allowedAssets.push(asset);

assetAllowlist[asset] = true;

emit AllowedAssetAdded(asset);
}
}

/**
* Remove asset(s) so that it/they can't be traded to, wrapped to, or claimed
*
* @param _assets Asset(s) to remove
*/
function _removeAllowedAssets(address[] memory _assets) internal {
for (uint256 i = 0; i < _assets.length; i++) {
address asset = _assets[i];

require(assetAllowlist[asset], "Asset not already added");

allowedAssets.removeStorage(asset);

assetAllowlist[asset] = false;

emit AllowedAssetRemoved(asset);
}
}

/**
* Toggle useAssetAllowlist on and off. When false asset allowlist is ignored
* when true it is enforced.
*
* @param _useAssetAllowlist Bool indicating whether to use asset allow list
*/
function _updateUseAssetAllowlist(bool _useAssetAllowlist) internal {
useAssetAllowlist = _useAssetAllowlist;

emit UseAssetAllowlistUpdated(_useAssetAllowlist);
}

/// @notice Check that all assets in array are allowed to be treated
/// @dev ca be bypassed by setting the useAssetAllowlist to false (default)
function _areAllowedAssets(address[] memory _assets) internal view returns(bool) {
if (!useAssetAllowlist) { return true; }
for (uint256 i = 0; i < _assets.length; i++) {
if (!assetAllowlist[_assets[i]]) { return false; }
}
return true;
}
}
13 changes: 11 additions & 2 deletions contracts/mocks/OptimisticOracleV3Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ interface callbackInterface {
* tradeoffs, enabling the notion of "sovereign security".
*/
contract OptimisticOracleV3Mock is OptimisticOracleV3Interface {
address public asserter;
// Mock implementation of defaultIdentifier
function defaultIdentifier() public view override returns (bytes32) {
return (bytes32("helloWorld"));
}

function setAsserter(address _asserter) public {
asserter = _asserter;
}

// Mock implementation of getAssertion
function getAssertion(bytes32 ) public view override returns (Assertion memory) {
return (Assertion({
Expand All @@ -36,7 +41,7 @@ contract OptimisticOracleV3Mock is OptimisticOracleV3Interface {
assertingCaller: address(0),
escalationManager: address(0)
}),
asserter: address(0),
asserter: asserter,
assertionTime: uint64(0),
settled: false,
currency: IERC20(address(0)),
Expand Down Expand Up @@ -80,6 +85,10 @@ contract OptimisticOracleV3Mock is OptimisticOracleV3Interface {
return (false);
}

function disputeAssertion(bytes32 assertionId, address disputer) external override {
revert("Not implemented");
}

// Mock implementation of getMinimumBond
function getMinimumBond(address ) public view override returns (uint256) {
return (uint256(0));
Expand All @@ -95,4 +104,4 @@ contract OptimisticOracleV3Mock is OptimisticOracleV3Interface {
callbackInterface(target).assertionResolvedCallback(assertionId, truthfully);
}

}
}
Loading