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
26 changes: 13 additions & 13 deletions contracts/core/extensions/CoreIssuance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ contract CoreIssuance is
* Composite method to redeem and withdraw with a single transaction
*
* Normally, you should expect to be able to withdraw all of the tokens.
* However, some have central abilities to freeze transfers (e.g. EOS). _toWithdraw
* allows you to optionally specify which component tokens to transfer
* back to the user. The rest will remain in the vault under the users' addresses.
* However, some have central abilities to freeze transfers (e.g. EOS). _toExclude
* allows you to optionally specify which component tokens to exclude when
* redeeming. They will remain in the vault under the users' addresses.
*
* @param _set The address of the Set token
* @param _quantity The number of tokens to redeem
* @param _toWithdraw Mask of indexes of tokens to withdraw
* @param _toExclude Mask of indexes of tokens to exclude from withdrawing
*/
function redeemAndWithdraw(
address _set,
uint256 _quantity,
uint256 _toWithdraw
uint256 _toExclude
)
external
{
Expand Down Expand Up @@ -147,19 +147,19 @@ contract CoreIssuance is
// Calculate bit index of current component
uint256 componentBitIndex = 2 ** i;

// Transfer to user if component is included in _toWithdraw
if ((_toWithdraw & componentBitIndex) != 0) {
// Call Vault to withdraw tokens from Vault to user
vault.withdrawTo(
components[i],
// Transfer to user unless component index is included in _toExclude
if ((_toExclude & componentBitIndex) != 0) {
// Just increment vault balance for user for component
vault.incrementTokenOwner(
msg.sender,
components[i],
componentQuantity
);
} else {
// Otherwise, increment the component amount for the user
vault.incrementTokenOwner(
msg.sender,
// Call Vault to withdraw tokens from Vault to user
vault.withdrawTo(
components[i],
msg.sender,
componentQuantity
);
}
Expand Down
18 changes: 9 additions & 9 deletions test/core/extensions/coreIssuance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ contract('CoreIssuance', accounts => {
let subjectCaller: Address;
let subjectQuantityToRedeem: BigNumber;
let subjectSetToRedeem: Address;
let subjectComponentsToWithdrawMask: BigNumber;
let subjectComponentsToExcludeMask: BigNumber;

const naturalUnit: BigNumber = ether(2);
const numComponents: number = 3;
Expand All @@ -470,14 +470,14 @@ contract('CoreIssuance', accounts => {
subjectCaller = ownerAccount;
subjectQuantityToRedeem = naturalUnit;
subjectSetToRedeem = setToken.address;
subjectComponentsToWithdrawMask = coreWrapper.maskForAllComponents(numComponents);
subjectComponentsToExcludeMask = ZERO;
});

async function subject(): Promise<string> {
return core.redeemAndWithdraw.sendTransactionAsync(
subjectSetToRedeem,
subjectQuantityToRedeem,
subjectComponentsToWithdrawMask,
subjectComponentsToExcludeMask,
{ from: subjectCaller },
);
}
Expand Down Expand Up @@ -520,14 +520,14 @@ contract('CoreIssuance', accounts => {
expect(newTokenBalances).to.eql(expectedNewBalances);
});

describe('when the withdraw mask includes one component', async () => {
const componentIndicesToWithdraw: number[] = [0];
describe('when the exclude mask includes two of three components', async () => {
const componentIndicesToExclude: number[] = [1, 2];

beforeEach(async () => {
subjectComponentsToWithdrawMask = coreWrapper.maskForComponentsAtIndexes(componentIndicesToWithdraw);
subjectComponentsToExcludeMask = coreWrapper.maskForComponentsAtIndexes(componentIndicesToExclude);
});

it('transfers the component back to the user', async () => {
it('transfers the first component back to the user', async () => {
const componentToWithdraw = _.first(components);
const existingComponentBalance = await componentToWithdraw.balanceOf.callAsync(ownerAccount);

Expand Down Expand Up @@ -556,9 +556,9 @@ contract('CoreIssuance', accounts => {
});
});

describe('when the withdraw mask does not include any of the components', async () => {
describe('when the exclude mask includes all of the components', async () => {
beforeEach(async () => {
subjectComponentsToWithdrawMask = ZERO;
subjectComponentsToExcludeMask = coreWrapper.maskForAllComponents(numComponents);
});

it('increments the balances of the tokens back to the user in vault', async () => {
Expand Down
3 changes: 2 additions & 1 deletion truffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ module.exports = {
reporter: 'eth-gas-reporter',
reporterOptions : {
currency: 'USD',
gasPrice: 5
gasPrice: 5,
onlyCalledMethods: true
}
},
};
2 changes: 1 addition & 1 deletion utils/coreWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class CoreWrapper {
return new BigNumber(
_.sum(
_.map(
indexes, (_, idx) => Math.pow(2, idx))
indexes, (_, idx) => Math.pow(2, indexes[idx]))
)
);
}
Expand Down