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

Commit

Permalink
Brian/update protocol viewer (#556)
Browse files Browse the repository at this point in the history
Added batch fetching of fee info from tradingPools. Update contracts to interact with newest version of strategies.
  • Loading branch information
bweick committed Dec 31, 2019
1 parent 32162d5 commit 61dd740
Show file tree
Hide file tree
Showing 6 changed files with 519 additions and 279 deletions.
10 changes: 10 additions & 0 deletions contracts/mocks/supplementary/SocialTradingManagerMock.sol
Expand Up @@ -57,4 +57,14 @@ contract SocialTradingManagerMock {

pools[address(_tradingPool)].currentAllocation = _newAllocation;
}

function updateFee(
address _tradingPool,
uint256 _newFee
)
external
{
pools[_tradingPool].newEntryFee = _newFee;
pools[_tradingPool].feeUpdateTimestamp = block.timestamp;
}
}
40 changes: 40 additions & 0 deletions contracts/viewer/lib/TradingPoolViewer.sol
Expand Up @@ -138,6 +138,46 @@ contract TradingPoolViewer {
return (poolInfo, tradingPoolInfo, collateralSetInfo);
}

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

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

for (uint256 i = 0; i < _poolCount; i++) {
entryFees[i] = _tradingPools[i].entryFee();
}

return entryFees;
}

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

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

for (uint256 i = 0; i < _poolCount; i++) {
rebalanceFees[i] = _tradingPools[i].rebalanceFee();
}

return rebalanceFees;
}

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

function getCollateralSetInfo(
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "set-protocol-contracts",
"version": "1.3.13-beta",
"version": "1.3.14-beta",
"description": "Smart contracts for {Set} Protocol",
"main": "dist/artifacts/index.js",
"typings": "dist/typings/artifacts/index.d.ts",
Expand Down Expand Up @@ -98,7 +98,7 @@
"lint-staged": "^7.2.0",
"module-alias": "^2.1.0",
"openzeppelin-solidity": "^2.2",
"set-protocol-strategies": "^1.1.22",
"set-protocol-strategies": "^1.1.24",
"set-protocol-utils": "^1.0.0-beta.44",
"tiny-promisify": "^1.0.0",
"truffle-flattener": "^1.4.0",
Expand Down
139 changes: 139 additions & 0 deletions test/contracts/viewer/lib/tradingPoolViewer.spec.ts
Expand Up @@ -218,6 +218,9 @@ contract('TradingPoolViewer', accounts => {
let lastRebalanceTimestamp: BigNumber;
let setManager: SocialTradingManagerMockContract;

let newFee: BigNumber;
let feeUpdateTimestamp: BigNumber;

beforeEach(async () => {
currentSetToken = set1;

Expand Down Expand Up @@ -246,6 +249,15 @@ contract('TradingPoolViewer', accounts => {
currentAllocation
);

newFee = ether(.02);
await setManager.updateFee.sendTransactionAsync(
rebalancingSetToken.address,
newFee
);

const block = await web3.eth.getBlock('latest');
feeUpdateTimestamp = new BigNumber(block.timestamp);

subjectTradingPool = rebalancingSetToken.address;
});

Expand All @@ -261,6 +273,8 @@ contract('TradingPoolViewer', accounts => {
expect(poolInfo.trader).to.equal(trader);
expect(poolInfo.allocator).to.equal(allocator);
expect(poolInfo.currentAllocation).to.be.bignumber.equal(currentAllocation);
expect(poolInfo.newEntryFee).to.be.bignumber.equal(newFee);
expect(poolInfo.feeUpdateTimestamp).to.be.bignumber.equal(feeUpdateTimestamp);
});

it('fetches the correct RebalancingSetTokenV2/TradingPool data', async () => {
Expand Down Expand Up @@ -366,6 +380,8 @@ contract('TradingPoolViewer', accounts => {
expect(poolInfo.trader).to.equal(trader);
expect(poolInfo.allocator).to.equal(allocator);
expect(poolInfo.currentAllocation).to.be.bignumber.equal(newAllocation);
expect(poolInfo.newEntryFee).to.be.bignumber.equal(ZERO);
expect(poolInfo.feeUpdateTimestamp).to.be.bignumber.equal(ZERO);
});

it('fetches the correct RebalancingSetTokenV2/TradingPool data', async () => {
Expand Down Expand Up @@ -397,4 +413,127 @@ contract('TradingPoolViewer', accounts => {
expect(collateralSetData.symbol).to.equal('SET');
});
});

describe('#batchFetchTradingPoolEntryFees', async () => {
let subjectTradingPools: Address[];

let rebalancingSetToken2: RebalancingSetTokenV2Contract;
let entryFee1: BigNumber;
let entryFee2: BigNumber;

beforeEach(async () => {
const setManager = await viewerHelper.deploySocialTradingManagerMockAsync();

const failPeriod = ONE_DAY_IN_SECONDS;
const { timestamp } = await web3.eth.getBlock('latest');
const lastRebalanceTimestamp = timestamp;

entryFee1 = ether(.02);
rebalancingSetToken = await rebalancingHelper.createDefaultRebalancingSetTokenV2Async(
coreMock,
rebalancingFactory.address,
setManager.address,
liquidator.address,
feeRecipient,
fixedFeeCalculator.address,
set1.address,
failPeriod,
lastRebalanceTimestamp,
entryFee1
);

entryFee2 = ether(.03);
rebalancingSetToken2 = await rebalancingHelper.createDefaultRebalancingSetTokenV2Async(
coreMock,
rebalancingFactory.address,
setManager.address,
liquidator.address,
feeRecipient,
fixedFeeCalculator.address,
set1.address,
failPeriod,
lastRebalanceTimestamp,
entryFee2
);

subjectTradingPools = [rebalancingSetToken.address, rebalancingSetToken2.address];
});

async function subject(): Promise<any> {
return poolViewer.batchFetchTradingPoolEntryFees.callAsync(
subjectTradingPools
);
}

it('fetches the correct entryFee array', async () => {
const actualEntryFeeArray = await subject();

const expectedEntryFeeArray = [entryFee1, entryFee2];

expect(JSON.stringify(actualEntryFeeArray)).to.equal(JSON.stringify(expectedEntryFeeArray));
});
});

describe('#batchFetchTradingPoolRebalanceFees', async () => {
let subjectTradingPools: Address[];

let rebalancingSetToken2: RebalancingSetTokenV2Contract;
let rebalanceFee1: BigNumber;
let rebalanceFee2: BigNumber;

beforeEach(async () => {
const setManager = await viewerHelper.deploySocialTradingManagerMockAsync();

const failPeriod = ONE_DAY_IN_SECONDS;
const { timestamp } = await web3.eth.getBlock('latest');
const lastRebalanceTimestamp = timestamp;
const entryFee = ether(.02);

rebalanceFee1 = ether(.002);
rebalancingSetToken = await rebalancingHelper.createDefaultRebalancingSetTokenV2Async(
coreMock,
rebalancingFactory.address,
setManager.address,
liquidator.address,
feeRecipient,
fixedFeeCalculator.address,
set1.address,
failPeriod,
lastRebalanceTimestamp,
entryFee,
rebalanceFee1
);

rebalanceFee2 = ether(.003);
rebalancingSetToken2 = await rebalancingHelper.createDefaultRebalancingSetTokenV2Async(
coreMock,
rebalancingFactory.address,
setManager.address,
liquidator.address,
feeRecipient,
fixedFeeCalculator.address,
set1.address,
failPeriod,
lastRebalanceTimestamp,
entryFee,
rebalanceFee2
);

subjectTradingPools = [rebalancingSetToken.address, rebalancingSetToken2.address];
});

async function subject(): Promise<any> {
return poolViewer.batchFetchTradingPoolRebalanceFees.callAsync(
subjectTradingPools
);
}

it('fetches the correct rebalanceFee array', async () => {
const actualEntryRebalanceArray = await subject();

const expectedEntryRebalanceArray = [rebalanceFee1, rebalanceFee2];

expect(JSON.stringify(actualEntryRebalanceArray)).to.equal(JSON.stringify(expectedEntryRebalanceArray));
});
});
});

0 comments on commit 61dd740

Please sign in to comment.