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
299 changes: 217 additions & 82 deletions contracts/core/RebalancingSetToken.sol

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions contracts/core/interfaces/ICore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,30 @@ pragma solidity 0.4.24;
* various extensions and is a light weight way to interact with the contract.
*/
interface ICore {
/**
* Return transferProxy address.
*
* @return address transferProxy address
*/
function transferProxy()
public
view
returns(address);

/**
* Return vault address.
*
* @return address vault address
*/
function vault()
public
view
returns(address);

/*
* Get natural unit of Set
* Returns if valid set
*
* @return uint256 Natural unit of Set
* @return bool Returns true if Set created through Core and isn't disabled
*/
function validSets(address)
external
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"lint-sol": "solium -d contracts/",
"lint": "yarn run lint-sol && yarn run lint-ts",
"clean-chain": "rm -rf blockchain && cp -r snapshots/0x-Kyber blockchain",
"chain": "yarn clean-chain && ganache-cli --db blockchain --networkId 50 --accounts 20 -l 12000000 -e 10000000000 -m 'concert load couple harbor equip island argue ramp clarify fence smart topic'",
"coverage-setup": "cp -r transpiled/artifacts/ts/* artifacts/ts/. && cp -r transpiled/test/* test/. && cp -r transpiled/types/* types/. && cp -r transpiled/utils/* utils/.",
"chain": "yarn clean-chain && ganache-cli --db blockchain --networkId 50 --accounts 20 -l 16000000 -e 10000000000 -m 'concert load couple harbor equip island argue ramp clarify fence smart topic'",
"coverage-setup": "yarn transpile && cp -r transpiled/artifacts/ts/* artifacts/ts/. && cp -r transpiled/test/* test/. && cp -r transpiled/types/* types/. && cp -r transpiled/utils/* utils/.",
"coverage-cleanup": "find artifacts/ts -name \\*.js* -type f -delete && find test -name \\*.js* -type f -delete && find types -name \\*.js* -type f -delete && find utils -name \\*.js* -type f -delete",
"coverage": "yarn coverage-setup && ./node_modules/.bin/solidity-coverage && yarn coverage-cleanup",
"setup": "yarn clean && yarn compile && yarn generate-typings && yarn deploy:development",
Expand Down Expand Up @@ -65,7 +65,7 @@
"ethereumjs-abi": "^0.6.4",
"ethereumjs-util": "^5.1.2",
"ethjs-abi": "^0.2.1",
"ganache-cli": "^6.1.7",
"ganache-cli": "^6.1.2",
"import-sort-cli": "^4.2.0",
"import-sort-parser-babylon": "^4.2.0",
"import-sort-style-eslint": "^4.2.0",
Expand Down
59 changes: 22 additions & 37 deletions test/core/extensions/coreIssuance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,29 +366,21 @@ contract('CoreIssuance', accounts => {
let initialShareRatio: BigNumber;
let rebalancingNaturalUnit: BigNumber;

const naturalUnit: BigNumber = ether(2);
let components: StandardTokenMockContract[] = [];
let componentUnits: BigNumber[];
let setToken: SetTokenContract;
let rebalancingToken: RebalancingSetTokenContract;
let rebalancingSetToken: RebalancingSetTokenContract;

beforeEach(async () => {
components = await erc20Wrapper.deployTokensAsync(2, ownerAccount);
await erc20Wrapper.approveTransfersAsync(components, transferProxy.address);

const componentAddresses = _.map(components, token => token.address);
componentUnits = _.map(components, () => ether(4)); // Multiple of naturalUnit
setToken = await coreWrapper.createSetTokenAsync(
const setTokens = await rebalancingTokenWrapper.createSetTokensAsync(
core,
setTokenFactory.address,
componentAddresses,
componentUnits,
naturalUnit,
transferProxy.address,
1
);
setToken = setTokens[0];

rebalancingNaturalUnit = DEFAULT_REBALANCING_NATURAL_UNIT;
initialShareRatio = DEFAULT_UNIT_SHARES;
rebalancingToken = await rebalancingTokenWrapper.createDefaultRebalancingSetTokenAsync(
rebalancingSetToken = await rebalancingTokenWrapper.createDefaultRebalancingSetTokenAsync(
core,
rebalancingTokenFactory.address,
managerAccount,
Expand All @@ -403,7 +395,7 @@ contract('CoreIssuance', accounts => {

subjectCaller = ownerAccount;
subjectQuantityToIssue = ether(1);
subjectSetToIssue = rebalancingToken.address;
subjectSetToIssue = rebalancingSetToken.address;
});

async function subject(): Promise<string> {
Expand Down Expand Up @@ -432,7 +424,7 @@ contract('CoreIssuance', accounts => {
const expectedLogs: Log[] = _.map([setToken], (component, idx) => {
return IssuanceComponentDeposited(
core.address,
rebalancingToken.address,
rebalancingSetToken.address,
setToken.address,
subjectQuantityToIssue.mul(initialShareRatio).div(rebalancingNaturalUnit),
);
Expand All @@ -442,14 +434,14 @@ contract('CoreIssuance', accounts => {
});

it('updates the balances of the components in the vault to belong to the set token', async () => {
const existingBalance = await vault.balances.callAsync(setToken.address, rebalancingToken.address);
const existingBalance = await vault.balances.callAsync(setToken.address, rebalancingSetToken.address);

await subject();

const expectedNewBalance = existingBalance.add(
subjectQuantityToIssue.div(rebalancingNaturalUnit).mul(initialShareRatio)
);
const newBalance = await vault.balances.callAsync(setToken.address, rebalancingToken.address);
const newBalance = await vault.balances.callAsync(setToken.address, rebalancingSetToken.address);
expect(newBalance).to.be.bignumber.eql(expectedNewBalance);
});

Expand All @@ -463,11 +455,11 @@ contract('CoreIssuance', accounts => {
});

it('mints the correct quantity of the set for the user', async () => {
const existingBalance = await rebalancingToken.balanceOf.callAsync(ownerAccount);
const existingBalance = await rebalancingSetToken.balanceOf.callAsync(ownerAccount);

await subject();

await assertTokenBalanceAsync(rebalancingToken, existingBalance.add(subjectQuantityToIssue), ownerAccount);
await assertTokenBalanceAsync(rebalancingSetToken, existingBalance.add(subjectQuantityToIssue), ownerAccount);
});

describe('when the set was not created through core', async () => {
Expand Down Expand Up @@ -496,7 +488,6 @@ contract('CoreIssuance', accounts => {

describe('when the required set component quantity is in the vault for the user', async () => {
let alreadyDepositedQuantity: BigNumber;
const componentUnit: BigNumber = new BigNumber(1);

beforeEach(async () => {
alreadyDepositedQuantity = vanillaQuantityToIssue;
Expand All @@ -505,6 +496,7 @@ contract('CoreIssuance', accounts => {

it('updates the vault balance of the component for the user by the correct amount', async () => {
const existingVaultBalance = await vault.balances.callAsync(setToken.address, ownerAccount);
const componentUnit = await rebalancingSetToken.unitShares.callAsync();

await subject();

Expand All @@ -515,11 +507,11 @@ contract('CoreIssuance', accounts => {
});

it('mints the correct quantity of the set for the user', async () => {
const existingBalance = await rebalancingToken.balanceOf.callAsync(ownerAccount);
const existingBalance = await rebalancingSetToken.balanceOf.callAsync(ownerAccount);

await subject();

await assertTokenBalanceAsync(rebalancingToken, existingBalance.add(subjectQuantityToIssue), ownerAccount);
await assertTokenBalanceAsync(rebalancingSetToken, existingBalance.add(subjectQuantityToIssue), ownerAccount);
});
});

Expand Down Expand Up @@ -558,11 +550,11 @@ contract('CoreIssuance', accounts => {
});

it('mints the correct quantity of the set for the user', async () => {
const existingBalance = await rebalancingToken.balanceOf.callAsync(ownerAccount);
const existingBalance = await rebalancingSetToken.balanceOf.callAsync(ownerAccount);

await subject();

await assertTokenBalanceAsync(rebalancingToken, existingBalance.add(subjectQuantityToIssue), ownerAccount);
await assertTokenBalanceAsync(rebalancingSetToken, existingBalance.add(subjectQuantityToIssue), ownerAccount);
});
});
});
Expand Down Expand Up @@ -707,25 +699,18 @@ contract('CoreIssuance', accounts => {
let rebalancingQuantityToIssue: BigNumber;
let rebalancingTokenToIssue: Address;

const naturalUnit: BigNumber = ether(2);
let components: StandardTokenMockContract[] = [];
let componentUnits: BigNumber[];
let setToken: SetTokenContract;
let rebalancingToken: RebalancingSetTokenContract;

beforeEach(async () => {
components = await erc20Wrapper.deployTokensAsync(2, ownerAccount);
await erc20Wrapper.approveTransfersAsync(components, transferProxy.address);

const componentAddresses = _.map(components, token => token.address);
componentUnits = _.map(components, () => ether(4)); // Multiple of naturalUnit
setToken = await coreWrapper.createSetTokenAsync(
const setTokens = await rebalancingTokenWrapper.createSetTokensAsync(
core,
setTokenFactory.address,
componentAddresses,
componentUnits,
naturalUnit,
transferProxy.address,
1
);
setToken = setTokens[0];


rebalancingNaturalUnit = DEFAULT_REBALANCING_NATURAL_UNIT;
initialShareRatio = DEFAULT_UNIT_SHARES;
Expand Down
24 changes: 12 additions & 12 deletions test/core/extensions/coreIssuanceOrder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,23 +264,23 @@ contract('CoreIssuanceOrder', accounts => {
});

it('transfers the remaining maker tokens to the taker', async () => {
const existingBalance = await makerToken.balanceOf.callAsync(issuanceOrderTaker);
await assertTokenBalanceAsync(makerToken, ZERO, issuanceOrderTaker);
const existingBalance = await makerToken.balanceOf.callAsync(subjectCaller);
await assertTokenBalanceAsync(makerToken, ZERO, subjectCaller);

await subject();

const netMakerToTaker = order.makerTokenAmount.sub(zeroExOrder.fillAmount);
const expectedNewBalance = existingBalance.plus(netMakerToTaker);
await assertTokenBalanceAsync(makerToken, expectedNewBalance, issuanceOrderTaker);
await assertTokenBalanceAsync(makerToken, expectedNewBalance, subjectCaller);
});

it('transfers the fees to the relayer', async () => {
await assertTokenBalanceAsync(relayerToken, ZERO, order.relayerAddress);
await assertTokenBalanceAsync(relayerToken, ZERO, relayerAccount);

await subject();

const expectedNewBalance = order.makerRelayerFee.add(order.takerRelayerFee);
await assertTokenBalanceAsync(relayerToken, expectedNewBalance, order.relayerAddress);
const expectedNewBalance = ether(3);
await assertTokenBalanceAsync(relayerToken, expectedNewBalance, relayerAccount);
});

it('mints the correct quantity of the set for the maker', async () => {
Expand Down Expand Up @@ -341,25 +341,25 @@ contract('CoreIssuanceOrder', accounts => {
await assertTokenBalanceAsync(makerToken, expectedNewBalance, issuanceOrderMaker);
});

it('transfers the partial maker token amount to the taker', async () => {
const existingBalance = await makerToken.balanceOf.callAsync(issuanceOrderTaker);
await assertTokenBalanceAsync(makerToken, ZERO, issuanceOrderTaker);
it('transfers the remaining maker tokens to the taker', async () => {
const existingBalance = await makerToken.balanceOf.callAsync(subjectCaller);
await assertTokenBalanceAsync(makerToken, ZERO, subjectCaller);

await subject();

const makerTokenAmountAvailableForThisOrder = order.makerTokenAmount.div(2);
const netMakerToTaker = makerTokenAmountAvailableForThisOrder.mul(subjectQuantityToFill).div(ether(4));
const expectedNewBalance = existingBalance.plus(netMakerToTaker);
await assertTokenBalanceAsync(makerToken, expectedNewBalance, issuanceOrderTaker);
await assertTokenBalanceAsync(makerToken, expectedNewBalance, subjectCaller);
});

it('transfers the partial fees to the relayer', async () => {
await assertTokenBalanceAsync(relayerToken, ZERO, order.relayerAddress);
await assertTokenBalanceAsync(relayerToken, ZERO, relayerAccount);

await subject();

const expectedNewBalance = ether(3).mul(subjectQuantityToFill).div(ether(4));
await assertTokenBalanceAsync(relayerToken, expectedNewBalance, order.relayerAddress);
await assertTokenBalanceAsync(relayerToken, expectedNewBalance, relayerAccount);
});

it('mints the correct partial quantity of the set for the user', async () => {
Expand Down
Loading