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
94 changes: 86 additions & 8 deletions contracts/viewer/lib/TradingPoolViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ILiquidator } from "set-protocol-contracts/contracts/core/interfaces/IL
import { IPerformanceFeeCalculator } from "set-protocol-contracts/contracts/core/interfaces/IPerformanceFeeCalculator.sol";
import { IRebalancingSetTokenV2 } from "set-protocol-contracts/contracts/core/interfaces/IRebalancingSetTokenV2.sol";
import { IRebalancingSetTokenV3 } from "set-protocol-contracts/contracts/core/interfaces/IRebalancingSetTokenV3.sol";
import { ITWAPAuctionGetters } from "set-protocol-contracts/contracts/core/interfaces/ITWAPAuctionGetters.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 @@ -69,12 +70,31 @@ contract TradingPoolViewer {
ILiquidator liquidator;
}

struct TradingPoolTWAPRebalanceInfo {
uint256 rebalanceStartTime;
uint256 timeToPivot;
uint256 startPrice;
uint256 endPrice;
uint256 startingCurrentSets;
uint256 remainingCurrentSets;
uint256 minimumBid;
RebalancingLibrary.State rebalanceState;
ISetToken nextSet;
ILiquidator liquidator;
uint256 orderSize;
uint256 orderRemaining;
uint256 totalSetsRemaining;
uint256 chunkSize;
uint256 chunkAuctionPeriod;
uint256 lastChunkAuctionEnd;
}

struct CollateralSetInfo {
address[] components;
uint256[] units;
uint256 naturalUnit;
string name;
string symbol;
string symbol;
}

function fetchNewTradingPoolDetails(
Expand Down Expand Up @@ -148,7 +168,7 @@ contract TradingPoolViewer {
timeToPivot: auctionParams[1],
startPrice: auctionParams[2],
endPrice: auctionParams[3],
startingCurrentSets: _tradingPool.startingCurrentSetAmount(),
startingCurrentSets: _tradingPool.startingCurrentSetAmount(),
remainingCurrentSets: biddingParams[1],
minimumBid: biddingParams[0],
rebalanceState: _tradingPool.rebalanceState(),
Expand All @@ -167,6 +187,64 @@ contract TradingPoolViewer {
return (poolInfo, tradingPoolInfo, collateralSetInfo);
}

function fetchRBSetTWAPRebalanceDetails(
IRebalancingSetTokenV2 _rebalancingSetToken
)
public
view
returns (TradingPoolTWAPRebalanceInfo memory, CollateralSetInfo memory)
{
uint256[] memory auctionParams = _rebalancingSetToken.getAuctionPriceParameters();
uint256[] memory biddingParams = _rebalancingSetToken.getBiddingParameters();
ILiquidator liquidator = _rebalancingSetToken.liquidator();

ITWAPAuctionGetters twapStateGetters = ITWAPAuctionGetters(address(liquidator));

TradingPoolTWAPRebalanceInfo memory tradingPoolInfo = TradingPoolTWAPRebalanceInfo({
rebalanceStartTime: auctionParams[0],
timeToPivot: auctionParams[1],
startPrice: auctionParams[2],
endPrice: auctionParams[3],
startingCurrentSets: _rebalancingSetToken.startingCurrentSetAmount(),
remainingCurrentSets: biddingParams[1],
minimumBid: biddingParams[0],
rebalanceState: _rebalancingSetToken.rebalanceState(),
nextSet: _rebalancingSetToken.nextSet(),
liquidator: liquidator,
orderSize: twapStateGetters.getOrderSize(address(_rebalancingSetToken)),
orderRemaining: twapStateGetters.getOrderRemaining(address(_rebalancingSetToken)),
totalSetsRemaining: twapStateGetters.getTotalSetsRemaining(address(_rebalancingSetToken)),
chunkSize: twapStateGetters.getChunkSize(address(_rebalancingSetToken)),
chunkAuctionPeriod: twapStateGetters.getChunkAuctionPeriod(address(_rebalancingSetToken)),
lastChunkAuctionEnd: twapStateGetters.getLastChunkAuctionEnd(address(_rebalancingSetToken))
});

CollateralSetInfo memory collateralSetInfo = getCollateralSetInfo(_rebalancingSetToken.nextSet());

return (tradingPoolInfo, collateralSetInfo);
}

function fetchTradingPoolTWAPRebalanceDetails(
IRebalancingSetTokenV2 _tradingPool
)
external
view
returns (SocialTradingLibrary.PoolInfo memory, TradingPoolTWAPRebalanceInfo memory, CollateralSetInfo memory)
{
(
TradingPoolTWAPRebalanceInfo memory tradingPoolInfo,
CollateralSetInfo memory collateralSetInfo
) = fetchRBSetTWAPRebalanceDetails(_tradingPool);

address manager = _tradingPool.manager();

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

return (poolInfo, tradingPoolInfo, collateralSetInfo);
}

function batchFetchTradingPoolOperator(
IRebalancingSetTokenV2[] calldata _tradingPools
)
Expand All @@ -176,7 +254,7 @@ contract TradingPoolViewer {
{
// Cache length of addresses to fetch owner for
uint256 _poolCount = _tradingPools.length;

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

Expand All @@ -200,7 +278,7 @@ contract TradingPoolViewer {
{
// Cache length of addresses to fetch entryFees for
uint256 _poolCount = _tradingPools.length;

// Instantiate output array in memory
uint256[] memory entryFees = new uint256[](_poolCount);

Expand All @@ -220,7 +298,7 @@ contract TradingPoolViewer {
{
// Cache length of addresses to fetch rebalanceFees for
uint256 _poolCount = _tradingPools.length;

// Instantiate output array in memory
uint256[] memory rebalanceFees = new uint256[](_poolCount);

Expand All @@ -240,7 +318,7 @@ contract TradingPoolViewer {
{
// 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);

Expand All @@ -249,7 +327,7 @@ contract TradingPoolViewer {

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

(
streamingFees[i],
profitFees[i]
Expand All @@ -271,7 +349,7 @@ contract TradingPoolViewer {
{
// 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);

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "set-protocol-viewers",
"version": "1.0.11",
"version": "1.0.12",
"main": "dist/artifacts/index.js",
"typings": "dist/typings/artifacts/index.d.ts",
"files": [
Expand Down Expand Up @@ -100,7 +100,7 @@
"minify-all": "^1.2.2",
"module-alias": "^2.1.0",
"openzeppelin-solidity": "^2.2",
"set-protocol-contracts": "^1.4.5-beta",
"set-protocol-contracts": "^1.4.9-beta",
"set-protocol-strategies": "^1.1.37",
"set-protocol-oracles": "^1.0.16",
"set-protocol-utils": "^1.1.2",
Expand Down
Loading