Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.
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
8 changes: 8 additions & 0 deletions contracts/core/tokens/rebalancing-v2/RebalancingStart.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
pragma solidity 0.5.7;
pragma experimental "ABIEncoderV2";

import { ERC20 } from "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import { Math } from "openzeppelin-solidity/contracts/math/Math.sol";
import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";

Expand All @@ -32,6 +33,7 @@ import { RebalancingSetState } from "./RebalancingSetState.sol";
* Implementation of Rebalancing Set Token V2 start rebalance functionality
*/
contract RebalancingStart is
ERC20,
RebalancingSetState
{
using SafeMath for uint256;
Expand Down Expand Up @@ -62,6 +64,12 @@ contract RebalancingStart is
"Interval not elapsed"
);

// Must be a positive supply of the Set
require(
totalSupply() > 0,
"Invalid supply"
);

// New proposed Set must be a valid Set created by Core
require(
core.validSets(address(_nextSet)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ contract('RebalancingSetState', accounts => {

liquidatorMock = await liquidatorHelper.deployLiquidatorMockAsync();
await coreHelper.addAddressToWhiteList(liquidatorMock.address, liquidatorWhitelist);

[ initialSetToken, nextSetToken ] = await rebalancingHelper.createSetTokensAsync(
coreMock,
factory.address,
transferProxy.address,
2
2,
undefined,
managerAccount,
);


manager = managerAccount;
liquidator = liquidatorMock.address;
initialUnitShares = DEFAULT_UNIT_SHARES;
Expand Down Expand Up @@ -181,6 +184,8 @@ contract('RebalancingSetState', accounts => {
entryFee,
]
);

await coreMock.addSet.sendTransactionAsync(rebalancingSetToken.address, txnFrom(deployerAccount));
});

afterEach(async () => {
Expand Down Expand Up @@ -625,16 +630,16 @@ contract('RebalancingSetState', accounts => {

describe('when startRebalance is called from Rebalance State', async () => {
beforeEach(async () => {
const nextSetTokenComponentAddresses = await nextSetToken.getComponents.callAsync();
await coreHelper.addTokensToWhiteList(nextSetTokenComponentAddresses, rebalancingComponentWhiteList);

await rebalancingHelper.transitionToRebalanceV2Async(
coreMock,
rebalancingComponentWhiteList,
rebalancingSetToken,
nextSetToken,
managerAccount
);
const nextSetTokenComponentAddresses = await nextSetToken.getComponents.callAsync();
await coreHelper.addTokensToWhiteList(nextSetTokenComponentAddresses, rebalancingComponentWhiteList);

await rebalancingHelper.transitionToRebalanceV2Async(
coreMock,
rebalancingComponentWhiteList,
rebalancingSetToken,
nextSetToken,
managerAccount
);
});

it('should revert', async () => {
Expand Down
14 changes: 14 additions & 0 deletions test/contracts/core/tokens/rebalancing-v2/rebalancingStart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,20 @@ contract('StartRebalance', accounts => {
});
});

describe('when the rebalancing set supply is 0', async () => {
beforeEach(async () => {
// Redeem all supply
await coreMock.redeem.sendTransactionAsync(
rebalancingSetToken.address,
rebalancingSetQuantityToIssue
);
});

it('should revert', async () => {
await expectRevertError(subject());
});
});

describe('when the rebalance interval has not elapsed', async () => {
beforeEach(async () => {
subjectTimeFastForward = ONE_DAY_IN_SECONDS.sub(10);
Expand Down
10 changes: 8 additions & 2 deletions utils/helpers/rebalancingHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export class RebalancingHelper {
let naturalUnit: BigNumber;
const setTokenArray: SetTokenContract[] = [];

const components = await this._erc20Helper.deployTokensAsync(tokenCount + 1, this._tokenOwnerAddress);
await this._erc20Helper.approveTransfersAsync(components, transferProxy);
const components = await this._erc20Helper.deployTokensAsync(tokenCount + 1, from);
await this._erc20Helper.approveTransfersAsync(components, transferProxy, from);

const indexArray = _.times(tokenCount, Number);
for (const index in indexArray) {
Expand Down Expand Up @@ -189,6 +189,12 @@ export class RebalancingHelper {
naturalUnit,
);

await setToken.approve.sendTransactionAsync(
transferProxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
txnFrom(from)
);

setTokenArray.push(setToken);
}

Expand Down
25 changes: 23 additions & 2 deletions utils/helpers/rebalancingSetV2Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {
ZERO,
} from '../constants';
import { extractNewSetTokenAddressFromLogs } from '../contract_logs/core';

import { getWeb3, getContractInstance } from '../web3Helper';
import { ether } from '@utils/units';
import { getWeb3, getContractInstance, txnFrom } from '../web3Helper';

import { RebalancingHelper } from './rebalancingHelper';

Expand Down Expand Up @@ -172,6 +172,27 @@ export class RebalancingSetV2Helper extends RebalancingHelper {
liquidatorData: string = EMPTY_BYTESTRING,

): Promise<void> {
const currentSupply = await rebalancingSetToken.totalSupply.callAsync();
if (currentSupply.eq(new BigNumber(0))) {
const currentSetMintQuantity = ether(8);
const currentSetToken = await rebalancingSetToken.currentSet.callAsync();

// Issue currentSetToken
await core.issue.sendTransactionAsync(
currentSetToken,
currentSetMintQuantity,
txnFrom(caller)
);

// Use issued currentSetToken to issue rebalancingSetToken
const rebalancingSetQuantityToIssue = ether(7);
await core.issue.sendTransactionAsync(
rebalancingSetToken.address,
rebalancingSetQuantityToIssue,
txnFrom(caller)
);
}

const nextSetTokenComponentAddresses = await nextSetToken.getComponents.callAsync();
await this._coreHelper.addTokensToWhiteList(
nextSetTokenComponentAddresses,
Expand Down