Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions contracts/mocks/TrendingManagerMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2020 Set Labs Inc.

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.
*/

pragma solidity 0.5.7;
pragma experimental "ABIEncoderV2";


/**
* @title TrendingManagerMock
* @author Set Protocol
*
* Mock for TrendingManagerMock to test viewer.
*/
contract TrendingManagerMock {
uint256 public lastCrossoverConfirmationTimestamp;
uint256 public recentInitialProposeTimestamp;

constructor(
uint256 _crossoverTimestamp
)
public
{
lastCrossoverConfirmationTimestamp = _crossoverTimestamp;
recentInitialProposeTimestamp = _crossoverTimestamp;
}
}
4 changes: 3 additions & 1 deletion contracts/viewer/ProtocolViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pragma solidity 0.5.7;
pragma experimental "ABIEncoderV2";

import { ERC20Viewer } from "./lib/ERC20Viewer.sol";
import { ManagerViewer } from "./lib/ManagerViewer.sol";
import { RebalancingSetTokenViewer } from "./lib/RebalancingSetTokenViewer.sol";
import { TradingPoolViewer } from "./lib/TradingPoolViewer.sol";
import { CTokenViewer } from "./lib/CTokenViewer.sol";
Expand All @@ -36,5 +37,6 @@ contract ProtocolViewer is
ERC20Viewer,
RebalancingSetTokenViewer,
TradingPoolViewer,
CTokenViewer
CTokenViewer,
ManagerViewer
{}
76 changes: 76 additions & 0 deletions contracts/viewer/lib/ManagerViewer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright 2020 Set Labs Inc.

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.
*/

pragma solidity 0.5.7;
pragma experimental "ABIEncoderV2";

import { IAssetPairManager } from "set-protocol-strategies/contracts/managers/interfaces/IAssetPairManager.sol";
import { IMACOStrategyManagerV2 } from "set-protocol-strategies/contracts/managers/interfaces/IMACOStrategyManagerV2.sol";


/**
* @title ManagerViewer
* @author Set Protocol
*
* Interfaces for fetching multiple managers state in a single read
*/
contract ManagerViewer {

function batchFetchMACOV2CrossoverTimestamp(
IMACOStrategyManagerV2[] calldata _managers
)
external
view
returns (uint256[] memory)
{
// Cache length of addresses to fetch owner for
uint256 _managerCount = _managers.length;

// Instantiate output array in memory
uint256[] memory timestamps = new uint256[](_managerCount);

for (uint256 i = 0; i < _managerCount; i++) {
IMACOStrategyManagerV2 manager = _managers[i];

timestamps[i] = manager.lastCrossoverConfirmationTimestamp();
}

return timestamps;
}

function batchFetchAssetPairCrossoverTimestamp(
IAssetPairManager[] calldata _managers
)
external
view
returns (uint256[] memory)
{
// Cache length of addresses to fetch owner for
uint256 _managerCount = _managers.length;

// Instantiate output array in memory
uint256[] memory timestamps = new uint256[](_managerCount);

for (uint256 i = 0; i < _managerCount; i++) {
IAssetPairManager manager = _managers[i];

timestamps[i] = manager.recentInitialProposeTimestamp();
}

return timestamps;
}

}
176 changes: 160 additions & 16 deletions contracts/viewer/lib/TradingPoolViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ import { ERC20Detailed } from "openzeppelin-solidity/contracts/token/ERC20/ERC20
import { ISocialTradingManager } from "set-protocol-strategies/contracts/managers/interfaces/ISocialTradingManager.sol";
import { SocialTradingLibrary } from "set-protocol-strategies/contracts/managers/lib/SocialTradingLibrary.sol";

import { IFeeCalculator } from "set-protocol-contracts/contracts/core/interfaces/IFeeCalculator.sol";
import { ILiquidator } from "set-protocol-contracts/contracts/core/interfaces/ILiquidator.sol";
import { IPerformanceFeeCalculator } from "set-protocol-contracts/contracts/core/interfaces/IPerformanceFeeCalculator.sol";
import { IRebalancingSetTokenV2 } from "set-protocol-contracts/contracts/core/interfaces/IRebalancingSetTokenV2.sol";
import { RebalancingLibrary } from "set-protocol-contracts/contracts/core/lib/RebalancingLibrary.sol";
import { IRebalancingSetTokenV3 } from "set-protocol-contracts/contracts/core/interfaces/IRebalancingSetTokenV3.sol";
import { ISetToken } from "set-protocol-contracts/contracts/core/interfaces/ISetToken.sol";
import { PerformanceFeeLibrary } from "set-protocol-contracts/contracts/core/fee-calculators/lib/PerformanceFeeLibrary.sol";
import { RebalancingLibrary } from "set-protocol-contracts/contracts/core/lib/RebalancingLibrary.sol";


/**
Expand Down Expand Up @@ -80,30 +84,55 @@ contract TradingPoolViewer {
view
returns (SocialTradingLibrary.PoolInfo memory, TradingPoolCreateInfo memory, CollateralSetInfo memory)
{
TradingPoolCreateInfo memory tradingPoolInfo = TradingPoolCreateInfo({
manager: _tradingPool.manager(),
feeRecipient: _tradingPool.feeRecipient(),
currentSet: _tradingPool.currentSet(),
unitShares: _tradingPool.unitShares(),
naturalUnit: _tradingPool.naturalUnit(),
rebalanceInterval: _tradingPool.rebalanceInterval(),
entryFee: _tradingPool.entryFee(),
rebalanceFee: _tradingPool.rebalanceFee(),
lastRebalanceTimestamp: _tradingPool.lastRebalanceTimestamp(),
rebalanceState: _tradingPool.rebalanceState(),
name: _tradingPool.name(),
symbol: _tradingPool.symbol()
});
TradingPoolCreateInfo memory tradingPoolInfo = getTradingPoolInfo(
address(_tradingPool)
);

SocialTradingLibrary.PoolInfo memory poolInfo = ISocialTradingManager(tradingPoolInfo.manager).pools(
address(_tradingPool)
);

CollateralSetInfo memory collateralSetInfo = getCollateralSetInfo(tradingPoolInfo.currentSet);
CollateralSetInfo memory collateralSetInfo = getCollateralSetInfo(
tradingPoolInfo.currentSet
);

return (poolInfo, tradingPoolInfo, collateralSetInfo);
}

function fetchNewTradingPoolV2Details(
IRebalancingSetTokenV3 _tradingPool
)
external
view
returns (
SocialTradingLibrary.PoolInfo memory,
TradingPoolCreateInfo memory,
PerformanceFeeLibrary.FeeState memory,
CollateralSetInfo memory,
address
)
{
TradingPoolCreateInfo memory tradingPoolInfo = getTradingPoolInfo(
address(_tradingPool)
);

SocialTradingLibrary.PoolInfo memory poolInfo = ISocialTradingManager(tradingPoolInfo.manager).pools(
address(_tradingPool)
);

PerformanceFeeLibrary.FeeState memory performanceFeeInfo = getPerformanceFeeState(
address(_tradingPool)
);

CollateralSetInfo memory collateralSetInfo = getCollateralSetInfo(
tradingPoolInfo.currentSet
);

address performanceFeeCalculatorAddress = address(_tradingPool.rebalanceFeeCalculator());

return (poolInfo, tradingPoolInfo, performanceFeeInfo, collateralSetInfo, performanceFeeCalculatorAddress);
}

function fetchTradingPoolRebalanceDetails(
IRebalancingSetTokenV2 _tradingPool
)
Expand Down Expand Up @@ -138,6 +167,30 @@ contract TradingPoolViewer {
return (poolInfo, tradingPoolInfo, collateralSetInfo);
}

function batchFetchTradingPoolOperator(
IRebalancingSetTokenV2[] calldata _tradingPools
)
external
view
returns (address[] memory)
{
// Cache length of addresses to fetch owner for
uint256 _poolCount = _tradingPools.length;

// Instantiate output array in memory
address[] memory operators = new address[](_poolCount);

for (uint256 i = 0; i < _poolCount; i++) {
IRebalancingSetTokenV2 tradingPool = _tradingPools[i];

operators[i] = ISocialTradingManager(tradingPool.manager()).pools(
address(tradingPool)
).trader;
}

return operators;
}

function batchFetchTradingPoolEntryFees(
IRebalancingSetTokenV2[] calldata _tradingPools
)
Expand Down Expand Up @@ -178,6 +231,59 @@ contract TradingPoolViewer {
return rebalanceFees;
}

function batchFetchTradingPoolAccumulation(
IRebalancingSetTokenV3[] calldata _tradingPools
)
external
view
returns (uint256[] memory, uint256[] memory)
{
// Cache length of addresses to fetch rebalanceFees for
uint256 _poolCount = _tradingPools.length;

// Instantiate streaming fees output array in memory
uint256[] memory streamingFees = new uint256[](_poolCount);

// Instantiate profit fees output array in memory
uint256[] memory profitFees = new uint256[](_poolCount);

for (uint256 i = 0; i < _poolCount; i++) {
address rebalanceFeeCalculatorAddress = address(_tradingPools[i].rebalanceFeeCalculator());

(
streamingFees[i],
profitFees[i]
) = IPerformanceFeeCalculator(rebalanceFeeCalculatorAddress).getCalculatedFees(
address(_tradingPools[i])
);
}

return (streamingFees, profitFees);
}


function batchFetchTradingPoolFeeState(
IRebalancingSetTokenV3[] calldata _tradingPools
)
external
view
returns (PerformanceFeeLibrary.FeeState[] memory)
{
// Cache length of addresses to fetch rebalanceFees for
uint256 _poolCount = _tradingPools.length;

// Instantiate output array in memory
PerformanceFeeLibrary.FeeState[] memory feeStates = new PerformanceFeeLibrary.FeeState[](_poolCount);

for (uint256 i = 0; i < _poolCount; i++) {
feeStates[i] = getPerformanceFeeState(
address(_tradingPools[i])
);
}

return feeStates;
}

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

function getCollateralSetInfo(
Expand All @@ -195,4 +301,42 @@ contract TradingPoolViewer {
symbol: ERC20Detailed(address(_collateralSet)).symbol()
});
}

function getTradingPoolInfo(
address _tradingPool
)
internal
view
returns (TradingPoolCreateInfo memory)
{
IRebalancingSetTokenV2 rebalancingSetTokenV2Instance = IRebalancingSetTokenV2(_tradingPool);

return TradingPoolCreateInfo({
manager: rebalancingSetTokenV2Instance.manager(),
feeRecipient: rebalancingSetTokenV2Instance.feeRecipient(),
currentSet: rebalancingSetTokenV2Instance.currentSet(),
unitShares: rebalancingSetTokenV2Instance.unitShares(),
naturalUnit: rebalancingSetTokenV2Instance.naturalUnit(),
rebalanceInterval: rebalancingSetTokenV2Instance.rebalanceInterval(),
entryFee: rebalancingSetTokenV2Instance.entryFee(),
rebalanceFee: rebalancingSetTokenV2Instance.rebalanceFee(),
lastRebalanceTimestamp: rebalancingSetTokenV2Instance.lastRebalanceTimestamp(),
rebalanceState: rebalancingSetTokenV2Instance.rebalanceState(),
name: rebalancingSetTokenV2Instance.name(),
symbol: rebalancingSetTokenV2Instance.symbol()
});
}

function getPerformanceFeeState(
address _tradingPool
)
internal
view
returns (PerformanceFeeLibrary.FeeState memory)
{
IRebalancingSetTokenV3 rebalancingSetTokenV3Instance = IRebalancingSetTokenV3(_tradingPool);

address rebalanceFeeCalculatorAddress = address(rebalancingSetTokenV3Instance.rebalanceFeeCalculator());
return IPerformanceFeeCalculator(rebalanceFeeCalculatorAddress).feeState(_tradingPool);
}
}
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test": "test"
},
"scripts": {
"chain": "yarn clean-chain && ganache-cli --db blockchain --networkId 50 --accounts 20 -l 19000000 -e 10000000000 -m 'concert load couple harbor equip island argue ramp clarify fence smart topic'",
"chain": "yarn clean-chain && ganache-cli --db blockchain --networkId 50 --accounts 20 -l 20000000 -e 10000000000 -m 'concert load couple harbor equip island argue ramp clarify fence smart topic'",
"clean": "rm -rf build; rm -rf transpiled; rm -rf types/generated",
"clean-chain": "rm -rf blockchain && cp -r snapshots/0x-Kyber-Compound blockchain",
"compile": "./node_modules/.bin/truffle compile --all",
Expand Down Expand Up @@ -78,7 +78,7 @@
"set-abi-gen": "1.1.0-beta.1",
"solc": "^0.5.4",
"solidity-coverage": "^0.6.3",
"truffle": "^5.0.37",
"truffle": "^5.1.12",
"@truffle/contract": "^4.0.2",
"tslint": "^5.8.0",
"tslint-no-unused-expression-chai": "0.0.3",
Expand All @@ -98,8 +98,8 @@
"lint-staged": "^7.2.0",
"module-alias": "^2.1.0",
"openzeppelin-solidity": "^2.2",
"set-protocol-contracts": "^1.3.34-beta",
"set-protocol-strategies": "^1.1.26",
"set-protocol-contracts": "^1.3.48-beta",
"set-protocol-strategies": "1.1.29",
"set-protocol-oracles": "^1.0.5",
"set-protocol-utils": "^1.0.0-beta.45",
"tiny-promisify": "^1.0.0",
Expand All @@ -108,7 +108,8 @@
"ts-node": "^8.0.2",
"tslint-eslint-rules": "^5.3.1",
"web3": "1.0.0-beta.36",
"web3-utils": "1.0.0-beta.36"
"web3-utils": "1.0.0-beta.36",
"zos-lib": "^2.4.2"
},
"husky": {
"hooks": {
Expand Down
Loading