|
| 1 | +/* |
| 2 | + Copyright 2018 Set Labs Inc. |
| 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 | + |
| 17 | +'use strict'; |
| 18 | + |
| 19 | +import Web3 from 'web3'; |
| 20 | + |
| 21 | +import { StrategyContractWrapper } from './StrategyContractWrapper'; |
| 22 | +import { BigNumber, generateTxOpts } from '../../util'; |
| 23 | +import { Address, Tx } from '../../types/common'; |
| 24 | + |
| 25 | +/** |
| 26 | + * @title AssetPairManagerV2Wrapper |
| 27 | + * @author Set Protocol |
| 28 | + * |
| 29 | + * The AssetPairManagerV2Wrapper handles all functions on the AssetPairManagerV2 contract |
| 30 | + * |
| 31 | + */ |
| 32 | +export class AssetPairManagerV2Wrapper { |
| 33 | + protected web3: Web3; |
| 34 | + protected contracts: StrategyContractWrapper; |
| 35 | + |
| 36 | + public constructor(web3: Web3) { |
| 37 | + this.web3 = web3; |
| 38 | + this.contracts = new StrategyContractWrapper(this.web3); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Calls an AssetPairManagerV2's intialPropose function. This function kicks off a propose cycle on the |
| 43 | + * manager by checking that the time and price constraints have been met then logging a timestamp used later in the |
| 44 | + * process to confirm the signal. |
| 45 | + * |
| 46 | + * @param managerAddress Address of the rebalancing manager contract |
| 47 | + * @return The hash of the resulting transaction. |
| 48 | + */ |
| 49 | + public async initialPropose( |
| 50 | + managerAddress: Address, |
| 51 | + txOpts?: Tx, |
| 52 | + ): Promise<string> { |
| 53 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 54 | + const txOptions = await generateTxOpts(this.web3, txOpts); |
| 55 | + |
| 56 | + return await assetPairManagerInstance.initialPropose.sendTransactionAsync(txOptions); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Calls an AssetPairManagerV2's confirmPropose function. This function again checks to make sure that |
| 61 | + * price and time constraints have been satisfied. After that it generates the new allocation proposal and sends the |
| 62 | + * results to the Rebalancing Set Token to kick off the official rebalance. |
| 63 | + * |
| 64 | + * @param managerAddress Address of the rebalancing manager contract |
| 65 | + * @return The hash of the resulting transaction. |
| 66 | + */ |
| 67 | + public async confirmPropose( |
| 68 | + managerAddress: Address, |
| 69 | + txOpts?: Tx, |
| 70 | + ): Promise<string> { |
| 71 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 72 | + const txOptions = await generateTxOpts(this.web3, txOpts); |
| 73 | + |
| 74 | + return await assetPairManagerInstance.confirmPropose.sendTransactionAsync(txOptions); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Update liquidator used by Rebalancing Set. |
| 79 | + * |
| 80 | + * @param managerAddress Address of the rebalancing manager contract |
| 81 | + * @param newLiquidatorAddress Address of new Liquidator |
| 82 | + * @return The hash of the resulting transaction. |
| 83 | + */ |
| 84 | + public async setLiquidator( |
| 85 | + managerAddress: Address, |
| 86 | + newLiquidatorAddress: Address, |
| 87 | + txOpts?: Tx, |
| 88 | + ): Promise<string> { |
| 89 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 90 | + const txOptions = await generateTxOpts(this.web3, txOpts); |
| 91 | + |
| 92 | + return await assetPairManagerInstance.setLiquidator.sendTransactionAsync(newLiquidatorAddress, txOptions); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Update liquidatorData used by Rebalancing Set. |
| 97 | + * |
| 98 | + * @param managerAddress Address of the rebalancing manager contract |
| 99 | + * @param newLiquidatorData New liquidator data in bytes |
| 100 | + * @return The hash of the resulting transaction. |
| 101 | + */ |
| 102 | + public async setLiquidatorData( |
| 103 | + managerAddress: Address, |
| 104 | + newLiquidatorData: string, |
| 105 | + txOpts?: Tx, |
| 106 | + ): Promise<string> { |
| 107 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 108 | + const txOptions = await generateTxOpts(this.web3, txOpts); |
| 109 | + |
| 110 | + return await assetPairManagerInstance.setLiquidatorData.sendTransactionAsync(newLiquidatorData, txOptions); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Update fee recipient on the Set. |
| 115 | + * |
| 116 | + * @param managerAddress Address of the rebalancing manager contract |
| 117 | + * @param newFeeRecipient Address of new fee recipient |
| 118 | + * @return The hash of the resulting transaction. |
| 119 | + */ |
| 120 | + public async setFeeRecipient( |
| 121 | + managerAddress: Address, |
| 122 | + newFeeRecipient: Address, |
| 123 | + txOpts?: Tx, |
| 124 | + ): Promise<string> { |
| 125 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 126 | + const txOptions = await generateTxOpts(this.web3, txOpts); |
| 127 | + |
| 128 | + return await assetPairManagerInstance.setFeeRecipient.sendTransactionAsync(newFeeRecipient, txOptions); |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Calls AssetPairManagerV2's adjustFee function. Allows manager to change performance fees. |
| 133 | + * |
| 134 | + * @param managerAddress Address of the rebalancing manager contract |
| 135 | + * @param newFeeCallData New fee call data |
| 136 | + * @return The hash of the resulting transaction. |
| 137 | + */ |
| 138 | + public async adjustFee( |
| 139 | + managerAddress: Address, |
| 140 | + newFeeCallData: string, |
| 141 | + txOpts?: Tx, |
| 142 | + ): Promise<string> { |
| 143 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 144 | + const txOptions = await generateTxOpts(this.web3, txOpts); |
| 145 | + |
| 146 | + return await assetPairManagerInstance.adjustFee.sendTransactionAsync( |
| 147 | + newFeeCallData, |
| 148 | + txOptions |
| 149 | + ); |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Calls AssetPairManagerV2's adjustFee function. Allows trader to change performance fees. |
| 154 | + * |
| 155 | + * @param managerAddress Address of the rebalancing manager contract |
| 156 | + * @param upgradeHash Hash of upgrade to be removed |
| 157 | + * @return The hash of the resulting transaction. |
| 158 | + */ |
| 159 | + public async removeRegisteredUpgrade( |
| 160 | + managerAddress: Address, |
| 161 | + upgradeHash: string, |
| 162 | + txOpts?: Tx, |
| 163 | + ): Promise<string> { |
| 164 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 165 | + const txOptions = await generateTxOpts(this.web3, txOpts); |
| 166 | + |
| 167 | + return await assetPairManagerInstance.removeRegisteredUpgrade.sendTransactionAsync( |
| 168 | + upgradeHash, |
| 169 | + txOptions |
| 170 | + ); |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * Calls an AssetPairManagerV2's canInitialPropose function. Returns whether initialPropose can be called |
| 175 | + * without reverting. |
| 176 | + * |
| 177 | + * @param managerAddress Address of the rebalancing manager contract |
| 178 | + * @return Boolean indicating whether initialPropose can be successfully called |
| 179 | + */ |
| 180 | + public async canInitialPropose(managerAddress: Address): Promise<boolean> { |
| 181 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 182 | + |
| 183 | + return await assetPairManagerInstance.canInitialPropose.callAsync(); |
| 184 | + } |
| 185 | + |
| 186 | + /** |
| 187 | + * Calls an AssetPairManagerV2's canConfirmPropose function. Returns whether confirmPropose can be called |
| 188 | + * without reverting. |
| 189 | + * |
| 190 | + * @param managerAddress Address of the rebalancing manager contract |
| 191 | + * @return Boolean indicating whether confirmPropose can be successfully called |
| 192 | + */ |
| 193 | + public async canConfirmPropose(managerAddress: Address): Promise<boolean> { |
| 194 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 195 | + |
| 196 | + return await assetPairManagerInstance.canConfirmPropose.callAsync(); |
| 197 | + } |
| 198 | + |
| 199 | + public async core(managerAddress: Address): Promise<Address> { |
| 200 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 201 | + |
| 202 | + return await assetPairManagerInstance.core.callAsync(); |
| 203 | + } |
| 204 | + |
| 205 | + public async allocator(managerAddress: Address): Promise<Address> { |
| 206 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 207 | + |
| 208 | + return await assetPairManagerInstance.allocator.callAsync(); |
| 209 | + } |
| 210 | + |
| 211 | + public async trigger(managerAddress: Address): Promise<Address> { |
| 212 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 213 | + |
| 214 | + return await assetPairManagerInstance.trigger.callAsync(); |
| 215 | + } |
| 216 | + |
| 217 | + public async rebalancingSetToken(managerAddress: Address): Promise<Address> { |
| 218 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 219 | + |
| 220 | + return await assetPairManagerInstance.rebalancingSetToken.callAsync(); |
| 221 | + } |
| 222 | + |
| 223 | + public async baseAssetAllocation(managerAddress: Address): Promise<BigNumber> { |
| 224 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 225 | + |
| 226 | + return await assetPairManagerInstance.baseAssetAllocation.callAsync(); |
| 227 | + } |
| 228 | + |
| 229 | + public async allocationDenominator(managerAddress: Address): Promise<BigNumber> { |
| 230 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 231 | + |
| 232 | + return await assetPairManagerInstance.allocationDenominator.callAsync(); |
| 233 | + } |
| 234 | + |
| 235 | + public async bullishBaseAssetAllocation(managerAddress: Address): Promise<BigNumber> { |
| 236 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 237 | + |
| 238 | + return await assetPairManagerInstance.bullishBaseAssetAllocation.callAsync(); |
| 239 | + } |
| 240 | + |
| 241 | + public async bearishBaseAssetAllocation(managerAddress: Address): Promise<BigNumber> { |
| 242 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 243 | + |
| 244 | + return await assetPairManagerInstance.bearishBaseAssetAllocation.callAsync(); |
| 245 | + } |
| 246 | + |
| 247 | + public async signalConfirmationMinTime(managerAddress: Address): Promise<BigNumber> { |
| 248 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 249 | + |
| 250 | + return await assetPairManagerInstance.signalConfirmationMinTime.callAsync(); |
| 251 | + } |
| 252 | + |
| 253 | + public async signalConfirmationMaxTime(managerAddress: Address): Promise<BigNumber> { |
| 254 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 255 | + |
| 256 | + return await assetPairManagerInstance.signalConfirmationMaxTime.callAsync(); |
| 257 | + } |
| 258 | + |
| 259 | + public async recentInitialProposeTimestamp(managerAddress: Address): Promise<BigNumber> { |
| 260 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 261 | + |
| 262 | + return await assetPairManagerInstance.recentInitialProposeTimestamp.callAsync(); |
| 263 | + } |
| 264 | + |
| 265 | + public async liquidatorData(managerAddress: Address): Promise<string> { |
| 266 | + const assetPairManagerInstance = await this.contracts.loadAssetPairManagerV2ContractAsync(managerAddress); |
| 267 | + |
| 268 | + return await assetPairManagerInstance.liquidatorData.callAsync(); |
| 269 | + } |
| 270 | +} |
0 commit comments