Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit 3f9b508

Browse files
committed
WIP asset pair v2
1 parent 0b73632 commit 3f9b508

File tree

8 files changed

+1152
-4
lines changed

8 files changed

+1152
-4
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
"lodash": "^4.17.4",
6868
"lodash.compact": "^3.0.1",
6969
"moment": "^2.22.2",
70-
"set-protocol-contracts": "1.4.5-beta",
70+
"set-protocol-contracts": "1.4.9-beta",
7171
"set-protocol-oracles": "^1.0.16",
72-
"set-protocol-strategies": "^1.1.37",
72+
"set-protocol-strategies": "^1.1.39",
7373
"set-protocol-viewers": "^1.0.11",
7474
"set-protocol-utils": "^1.1.2",
7575
"timekeeper": "^2.1.2",

src/wrappers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export { WhitelistWrapper } from './set_protocol/WhitelistWrapper';
4242
export { VaultWrapper } from './set_protocol/VaultWrapper';
4343

4444
export { AssetPairManagerWrapper } from './strategies/AssetPairManagerWrapper';
45+
export { AssetPairManagerV2Wrapper } from './strategies/AssetPairManagerV2Wrapper';
4546
export { BTCDAIRebalancingManagerWrapper } from './strategies/BTCDAIRebalancingManagerWrapper';
4647
export { BTCETHRebalancingManagerWrapper } from './strategies/BTCETHRebalancingManagerWrapper';
4748
export { ETHDAIRebalancingManagerWrapper } from './strategies/ETHDAIRebalancingManagerWrapper';
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
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+
}

src/wrappers/strategies/StrategyContractWrapper.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828

2929
import {
3030
AssetPairManagerContract,
31+
AssetPairManagerV2Contract,
3132
BaseContract as StrategyBaseContract,
3233
BTCDaiRebalancingManagerContract,
3334
BTCETHRebalancingManagerContract,
@@ -316,6 +317,32 @@ export class StrategyContractWrapper {
316317
}
317318
}
318319

320+
/**
321+
* Load a AssetPairManagerV2 contract
322+
*
323+
* @param assetPairManagerV2 Address of the AssetPairManagerV2 contract
324+
* @param transactionOptions Options sent into the contract deployed method
325+
* @return The AssetPairManagerV2 Contract
326+
*/
327+
public async loadAssetPairManagerV2ContractAsync(
328+
assetPairManagerV2: Address,
329+
transactionOptions: object = {},
330+
): Promise<AssetPairManagerV2Contract> {
331+
const cacheKey = `assetPairManagerV2_${assetPairManagerV2}`;
332+
333+
if (cacheKey in this.cache) {
334+
return this.cache[cacheKey] as AssetPairManagerV2Contract;
335+
} else {
336+
const assetPairManagerV2Contract = await AssetPairManagerV2Contract.at(
337+
assetPairManagerV2,
338+
this.web3,
339+
transactionOptions,
340+
);
341+
this.cache[cacheKey] = assetPairManagerV2Contract;
342+
return assetPairManagerV2Contract;
343+
}
344+
}
345+
319346
/**
320347
* Load a SocialTradingManager contract
321348
*

test/helpers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export {
8787

8888
export {
8989
deployAssetPairManagerAsync,
90+
deployAssetPairManagerV2Async,
9091
deployBinaryAllocatorAsync,
9192
deployBtcDaiManagerContractAsync,
9293
deployBtcEthManagerContractAsync,

test/helpers/strategyHelpers.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Address, Bytes } from 'set-protocol-utils';
44
import {
55
AssetPairManager,
66
AssetPairManagerContract,
7+
AssetPairManagerV2,
8+
AssetPairManagerV2Contract,
79
BinaryAllocator,
810
BinaryAllocatorContract,
911
BTCDaiRebalancingManager,
@@ -258,6 +260,38 @@ export const deployAssetPairManagerAsync = async(
258260
);
259261
};
260262

263+
export const deployAssetPairManagerV2Async = async(
264+
web3: Web3,
265+
coreInstance: Address,
266+
allocatorInstance: Address,
267+
triggerInstance: Address,
268+
useBullishAssetAllocation: boolean,
269+
allocationPrecision: BigNumber,
270+
bullishBaseAssetAllocation: BigNumber,
271+
signalConfirmationMinTime: BigNumber,
272+
signalConfirmationMaxTime: BigNumber,
273+
liquidatorData: Bytes,
274+
): Promise<AssetPairManagerV2Contract> => {
275+
const truffleAssetPairManager = setDefaultTruffleContract(web3, AssetPairManagerV2);
276+
277+
// Deploy MACO Strategy Manager V2
278+
const deployedAssetPairManagerInstance = await truffleAssetPairManager.new(
279+
coreInstance,
280+
allocatorInstance,
281+
triggerInstance,
282+
useBullishAssetAllocation,
283+
allocationPrecision,
284+
bullishBaseAssetAllocation,
285+
[signalConfirmationMinTime, signalConfirmationMaxTime],
286+
liquidatorData,
287+
);
288+
return await AssetPairManagerV2Contract.at(
289+
deployedAssetPairManagerInstance.address,
290+
web3,
291+
TX_DEFAULTS,
292+
);
293+
};
294+
261295
export const deploySocialTradingManagerAsync = async(
262296
web3: Web3,
263297
core: Address,
@@ -406,7 +440,7 @@ export const deployRSITrendingTriggerAsync = async(
406440
};
407441

408442
export const initializeManagerAsync = async(
409-
macoManager: MACOStrategyManagerContract | MACOStrategyManagerV2Contract | AssetPairManagerContract,
443+
macoManager: MACOStrategyManagerContract | MACOStrategyManagerV2Contract | AssetPairManagerContract | AssetPairManagerV2Contract,
410444
rebalancingSetTokenAddress: Address,
411445
): Promise<void> => {
412446
await macoManager.initialize.sendTransactionAsync(rebalancingSetTokenAddress);

0 commit comments

Comments
 (0)