Skip to content
This repository was archived by the owner on Mar 19, 2019. 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
45 changes: 23 additions & 22 deletions contracts/LoopringProtocolImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -425,42 +425,43 @@ contract LoopringProtocolImpl is LoopringProtocol {
returns (uint[] memory orderInfoList)
{
bytes32[] memory batch = new bytes32[](ringSize * 7); // ringSize * (owner + tokenS + 4 amounts + wallet)
bytes32[] memory historyBatch = new bytes32[](ringSize * 2); // ringSize * (orderhash, fillAmount)
orderInfoList = new uint[](ringSize * 6);

uint p = 0;
uint q = 0;
uint r = 0;
uint prevSplitB = orders[ringSize - 1].splitB;
for (uint i = 0; i < ringSize; i++) {
OrderState memory state = orders[i];
uint nextFillAmountS = orders[(i + 1) % ringSize].fillAmountS;

// Store owner and tokenS of every order
batch[p] = bytes32(state.owner);
batch[p + 1] = bytes32(state.tokenS);
batch[p++] = bytes32(state.owner);
batch[p++] = bytes32(state.tokenS);

// Store all amounts
batch[p + 2] = bytes32(state.fillAmountS - prevSplitB);
batch[p + 3] = bytes32(prevSplitB + state.splitS);
batch[p + 4] = bytes32(state.lrcReward);
batch[p + 5] = bytes32(state.lrcFeeState);
batch[p + 6] = bytes32(state.wallet);
p += 7;

// Update fill records
if (state.buyNoMoreThanAmountB) {
delegate.addCancelledOrFilled(state.orderHash, nextFillAmountS);
} else {
delegate.addCancelledOrFilled(state.orderHash, state.fillAmountS);
}

orderInfoList[i * 6 + 0] = uint(state.orderHash);
orderInfoList[i * 6 + 1] = state.fillAmountS;
orderInfoList[i * 6 + 2] = state.lrcReward;
orderInfoList[i * 6 + 3] = state.lrcFeeState;
orderInfoList[i * 6 + 4] = state.splitS;
orderInfoList[i * 6 + 5] = state.splitB;
batch[p++] = bytes32(state.fillAmountS - prevSplitB);
batch[p++] = bytes32(prevSplitB + state.splitS);
batch[p++] = bytes32(state.lrcReward);
batch[p++] = bytes32(state.lrcFeeState);
batch[p++] = bytes32(state.wallet);

historyBatch[r++] = state.orderHash;
historyBatch[r++] =
bytes32(state.buyNoMoreThanAmountB ? nextFillAmountS : state.fillAmountS);

orderInfoList[q++] = uint(state.orderHash);
orderInfoList[q++] = state.fillAmountS;
orderInfoList[q++] = state.lrcReward;
orderInfoList[q++] = state.lrcFeeState;
orderInfoList[q++] = state.splitS;
orderInfoList[q++] = state.splitB;

prevSplitB = state.splitB;
}
// Update fill records
delegate.batchAddCancelledOrFilled(historyBatch);

// Do all transactions
delegate.batchTransferToken(
Expand Down
5 changes: 4 additions & 1 deletion contracts/TokenTransferDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ contract TokenTransferDelegate {
external;

function addCancelledOrFilled(bytes32 orderHash, uint cancelOrFillAmount)
external;
public;

function batchAddCancelledOrFilled(bytes32[] batch)
public;

function setCutoffs(uint t)
external;
Expand Down
14 changes: 12 additions & 2 deletions contracts/TokenTransferDelegateImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ contract TokenTransferDelegateImpl is TokenTransferDelegate, Claimable {

// Pay token to previous order, or to miner as previous order's
// margin split or/and this order's margin split.

ERC20 token = ERC20(address(batch[i + 1]));

// Here batch[i + 2] has been checked not to be 0.
Expand Down Expand Up @@ -258,11 +257,22 @@ contract TokenTransferDelegateImpl is TokenTransferDelegate, Claimable {

function addCancelledOrFilled(bytes32 orderHash, uint cancelOrFillAmount)
onlyAuthorized
external
public
{
cancelledOrFilled[orderHash] = cancelledOrFilled[orderHash].add(cancelOrFillAmount);
}

function batchAddCancelledOrFilled(bytes32[] batch)
onlyAuthorized
public
{
require(batch.length % 2 == 0);
for (uint i = 0; i < batch.length / 2; i++) {
cancelledOrFilled[batch[i * 2]] =
cancelledOrFilled[batch[i * 2]].add(uint(batch[i * 2 + 1]));
}
}

function setCutoffs(uint t)
onlyAuthorized
external
Expand Down