|
| 1 | +/* |
| 2 | + Copyright 2023 Index Coop |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +
|
| 16 | + SPDX-License-Identifier: Apache License, Version 2.0 |
| 17 | +*/ |
| 18 | + |
| 19 | +pragma solidity 0.6.10; |
| 20 | +pragma experimental "ABIEncoderV2"; |
| 21 | + |
| 22 | +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; |
| 23 | +import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; |
| 24 | + |
| 25 | +import { AddressArrayUtils } from "../lib/AddressArrayUtils.sol"; |
| 26 | +import { BaseExtension } from "../lib/BaseExtension.sol"; |
| 27 | +import { IAuctionRebalanceModuleV1 } from "../interfaces/IAuctionRebalanceModuleV1.sol"; |
| 28 | +import { IBaseManager } from "../interfaces/IBaseManager.sol"; |
| 29 | +import { ISetToken } from "../interfaces/ISetToken.sol"; |
| 30 | + |
| 31 | +/** |
| 32 | + * @title AuctionRebalanceExtension |
| 33 | + * @author Index Coop |
| 34 | + * |
| 35 | + * @dev Extension contract for interacting with the AuctionRebalanceModuleV1. This contract acts as a pass-through and functions |
| 36 | + * are only callable by operator. |
| 37 | + */ |
| 38 | +contract AuctionRebalanceExtension is BaseExtension { |
| 39 | + using AddressArrayUtils for address[]; |
| 40 | + using SafeMath for uint256; |
| 41 | + |
| 42 | + /* ============ Structs ============ */ |
| 43 | + |
| 44 | + struct AuctionExecutionParams { |
| 45 | + uint256 targetUnit; // Target quantity of the component in Set, in precise units (10 ** 18). |
| 46 | + string priceAdapterName; // Identifier for the price adapter to be used. |
| 47 | + bytes priceAdapterConfigData; // Encoded data for configuring the chosen price adapter. |
| 48 | + } |
| 49 | + |
| 50 | + /* ============ State Variables ============ */ |
| 51 | + |
| 52 | + ISetToken public setToken; |
| 53 | + IAuctionRebalanceModuleV1 public auctionModule; // AuctionRebalanceModuleV1 |
| 54 | + |
| 55 | + /* ============ Constructor ============ */ |
| 56 | + |
| 57 | + constructor(IBaseManager _manager, IAuctionRebalanceModuleV1 _auctionModule) public BaseExtension(_manager) { |
| 58 | + auctionModule = _auctionModule; |
| 59 | + setToken = manager.setToken(); |
| 60 | + } |
| 61 | + |
| 62 | + /* ============ External Functions ============ */ |
| 63 | + |
| 64 | + /** |
| 65 | + * @dev OPERATOR ONLY: Checks that the old components array matches the current components array and then invokes the |
| 66 | + * AuctionRebalanceModuleV1 startRebalance function. |
| 67 | + * |
| 68 | + * Refer to AuctionRebalanceModuleV1 for function specific restrictions. |
| 69 | + * |
| 70 | + * @param _quoteAsset ERC20 token used as the quote asset in auctions. |
| 71 | + * @param _oldComponents Addresses of existing components in the SetToken. |
| 72 | + * @param _newComponents Addresses of new components to be added. |
| 73 | + * @param _newComponentsAuctionParams AuctionExecutionParams for new components, indexed corresponding to _newComponents. |
| 74 | + * @param _oldComponentsAuctionParams AuctionExecutionParams for existing components, indexed corresponding to |
| 75 | + * the current component positions. Set to 0 for components being removed. |
| 76 | + * @param _shouldLockSetToken Indicates if the rebalance should lock the SetToken. |
| 77 | + * @param _rebalanceDuration Duration of the rebalance in seconds. |
| 78 | + * @param _positionMultiplier Position multiplier at the time target units were calculated. |
| 79 | + */ |
| 80 | + function startRebalance( |
| 81 | + IERC20 _quoteAsset, |
| 82 | + address[] memory _oldComponents, |
| 83 | + address[] memory _newComponents, |
| 84 | + AuctionExecutionParams[] memory _newComponentsAuctionParams, |
| 85 | + AuctionExecutionParams[] memory _oldComponentsAuctionParams, |
| 86 | + bool _shouldLockSetToken, |
| 87 | + uint256 _rebalanceDuration, |
| 88 | + uint256 _positionMultiplier |
| 89 | + ) |
| 90 | + external |
| 91 | + onlyOperator |
| 92 | + { |
| 93 | + address[] memory currentComponents = setToken.getComponents(); |
| 94 | + |
| 95 | + require(currentComponents.length == _oldComponents.length, "Old components length must match the current components length."); |
| 96 | + |
| 97 | + for (uint256 i = 0; i < _oldComponents.length; i++) { |
| 98 | + require(currentComponents[i] == _oldComponents[i], "Input old components array must match the current components array."); |
| 99 | + } |
| 100 | + |
| 101 | + bytes memory callData = abi.encodeWithSelector( |
| 102 | + IAuctionRebalanceModuleV1.startRebalance.selector, |
| 103 | + setToken, |
| 104 | + _quoteAsset, |
| 105 | + _newComponents, |
| 106 | + _newComponentsAuctionParams, |
| 107 | + _oldComponentsAuctionParams, |
| 108 | + _shouldLockSetToken, |
| 109 | + _rebalanceDuration, |
| 110 | + _positionMultiplier |
| 111 | + ); |
| 112 | + |
| 113 | + invokeManager(address(auctionModule), callData); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @dev OPERATOR ONLY: Unlocks SetToken via AuctionRebalanceModuleV1. |
| 118 | + * Refer to AuctionRebalanceModuleV1 for function specific restrictions. |
| 119 | + */ |
| 120 | + function unlock() external onlyOperator { |
| 121 | + bytes memory callData = abi.encodeWithSelector( |
| 122 | + IAuctionRebalanceModuleV1.unlock.selector, |
| 123 | + setToken |
| 124 | + ); |
| 125 | + |
| 126 | + invokeManager(address(auctionModule), callData); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * @dev OPERATOR ONLY: Sets the target raise percentage for all components on AuctionRebalanceModuleV1. |
| 131 | + * Refer to AuctionRebalanceModuleV1 for function specific restrictions. |
| 132 | + * |
| 133 | + * @param _raiseTargetPercentage Amount to raise all component's unit targets by (in precise units) |
| 134 | + */ |
| 135 | + function setRaiseTargetPercentage(uint256 _raiseTargetPercentage) external onlyOperator { |
| 136 | + bytes memory callData = abi.encodeWithSelector( |
| 137 | + IAuctionRebalanceModuleV1.setRaiseTargetPercentage.selector, |
| 138 | + setToken, |
| 139 | + _raiseTargetPercentage |
| 140 | + ); |
| 141 | + |
| 142 | + invokeManager(address(auctionModule), callData); |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * @dev OPERATOR ONLY: Updates the bidding permission status for a list of addresses on AuctionRebalanceModuleV1. |
| 147 | + * Refer to AuctionRebalanceModuleV1 for function specific restrictions. |
| 148 | + * |
| 149 | + * @param _bidders An array of addresses whose bidding permission status is to be toggled. |
| 150 | + * @param _statuses An array of booleans indicating the new bidding permission status for each corresponding address in `_bidders`. |
| 151 | + */ |
| 152 | + function setBidderStatus( |
| 153 | + address[] memory _bidders, |
| 154 | + bool[] memory _statuses |
| 155 | + ) |
| 156 | + external |
| 157 | + onlyOperator |
| 158 | + { |
| 159 | + bytes memory callData = abi.encodeWithSelector( |
| 160 | + IAuctionRebalanceModuleV1.setBidderStatus.selector, |
| 161 | + setToken, |
| 162 | + _bidders, |
| 163 | + _statuses |
| 164 | + ); |
| 165 | + |
| 166 | + invokeManager(address(auctionModule), callData); |
| 167 | + } |
| 168 | + |
| 169 | + /** |
| 170 | + * @dev OPERATOR ONLY: Sets whether anyone can bid on the AuctionRebalanceModuleV1. |
| 171 | + * Refer to AuctionRebalanceModuleV1 for function specific restrictions. |
| 172 | + * |
| 173 | + * @param _status A boolean indicating if anyone can bid. |
| 174 | + */ |
| 175 | + function setAnyoneBid(bool _status) external onlyOperator { |
| 176 | + bytes memory callData = abi.encodeWithSelector( |
| 177 | + IAuctionRebalanceModuleV1.setAnyoneBid.selector, |
| 178 | + setToken, |
| 179 | + _status |
| 180 | + ); |
| 181 | + |
| 182 | + invokeManager(address(auctionModule), callData); |
| 183 | + } |
| 184 | + |
| 185 | + /** |
| 186 | + * @dev OPERATOR ONLY: Initializes the AuctionRebalanceModuleV1. |
| 187 | + * Refer to AuctionRebalanceModuleV1 for function specific restrictions. |
| 188 | + */ |
| 189 | + function initialize() external onlyOperator { |
| 190 | + bytes memory callData = abi.encodeWithSelector( |
| 191 | + IAuctionRebalanceModuleV1.initialize.selector, |
| 192 | + setToken |
| 193 | + ); |
| 194 | + |
| 195 | + invokeManager(address(auctionModule), callData); |
| 196 | + } |
| 197 | +} |
0 commit comments