Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit cf4f94b

Browse files
authored
WIP:batch updating history (#324)
batch updating history
1 parent 3d71430 commit cf4f94b

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

contracts/LoopringProtocolImpl.sol

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -425,42 +425,43 @@ contract LoopringProtocolImpl is LoopringProtocol {
425425
returns (uint[] memory orderInfoList)
426426
{
427427
bytes32[] memory batch = new bytes32[](ringSize * 7); // ringSize * (owner + tokenS + 4 amounts + wallet)
428+
bytes32[] memory historyBatch = new bytes32[](ringSize * 2); // ringSize * (orderhash, fillAmount)
428429
orderInfoList = new uint[](ringSize * 6);
429430

430431
uint p = 0;
432+
uint q = 0;
433+
uint r = 0;
431434
uint prevSplitB = orders[ringSize - 1].splitB;
432435
for (uint i = 0; i < ringSize; i++) {
433436
OrderState memory state = orders[i];
434437
uint nextFillAmountS = orders[(i + 1) % ringSize].fillAmountS;
435438

436439
// Store owner and tokenS of every order
437-
batch[p] = bytes32(state.owner);
438-
batch[p + 1] = bytes32(state.tokenS);
440+
batch[p++] = bytes32(state.owner);
441+
batch[p++] = bytes32(state.tokenS);
439442

440443
// Store all amounts
441-
batch[p + 2] = bytes32(state.fillAmountS - prevSplitB);
442-
batch[p + 3] = bytes32(prevSplitB + state.splitS);
443-
batch[p + 4] = bytes32(state.lrcReward);
444-
batch[p + 5] = bytes32(state.lrcFeeState);
445-
batch[p + 6] = bytes32(state.wallet);
446-
p += 7;
447-
448-
// Update fill records
449-
if (state.buyNoMoreThanAmountB) {
450-
delegate.addCancelledOrFilled(state.orderHash, nextFillAmountS);
451-
} else {
452-
delegate.addCancelledOrFilled(state.orderHash, state.fillAmountS);
453-
}
454-
455-
orderInfoList[i * 6 + 0] = uint(state.orderHash);
456-
orderInfoList[i * 6 + 1] = state.fillAmountS;
457-
orderInfoList[i * 6 + 2] = state.lrcReward;
458-
orderInfoList[i * 6 + 3] = state.lrcFeeState;
459-
orderInfoList[i * 6 + 4] = state.splitS;
460-
orderInfoList[i * 6 + 5] = state.splitB;
444+
batch[p++] = bytes32(state.fillAmountS - prevSplitB);
445+
batch[p++] = bytes32(prevSplitB + state.splitS);
446+
batch[p++] = bytes32(state.lrcReward);
447+
batch[p++] = bytes32(state.lrcFeeState);
448+
batch[p++] = bytes32(state.wallet);
449+
450+
historyBatch[r++] = state.orderHash;
451+
historyBatch[r++] =
452+
bytes32(state.buyNoMoreThanAmountB ? nextFillAmountS : state.fillAmountS);
453+
454+
orderInfoList[q++] = uint(state.orderHash);
455+
orderInfoList[q++] = state.fillAmountS;
456+
orderInfoList[q++] = state.lrcReward;
457+
orderInfoList[q++] = state.lrcFeeState;
458+
orderInfoList[q++] = state.splitS;
459+
orderInfoList[q++] = state.splitB;
461460

462461
prevSplitB = state.splitB;
463462
}
463+
// Update fill records
464+
delegate.batchAddCancelledOrFilled(historyBatch);
464465

465466
// Do all transactions
466467
delegate.batchTransferToken(

contracts/TokenTransferDelegate.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ contract TokenTransferDelegate {
9898
external;
9999

100100
function addCancelledOrFilled(bytes32 orderHash, uint cancelOrFillAmount)
101-
external;
101+
public;
102+
103+
function batchAddCancelledOrFilled(bytes32[] batch)
104+
public;
102105

103106
function setCutoffs(uint t)
104107
external;

contracts/TokenTransferDelegateImpl.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ contract TokenTransferDelegateImpl is TokenTransferDelegate, Claimable {
151151

152152
// Pay token to previous order, or to miner as previous order's
153153
// margin split or/and this order's margin split.
154-
155154
ERC20 token = ERC20(address(batch[i + 1]));
156155

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

259258
function addCancelledOrFilled(bytes32 orderHash, uint cancelOrFillAmount)
260259
onlyAuthorized
261-
external
260+
public
262261
{
263262
cancelledOrFilled[orderHash] = cancelledOrFilled[orderHash].add(cancelOrFillAmount);
264263
}
265264

265+
function batchAddCancelledOrFilled(bytes32[] batch)
266+
onlyAuthorized
267+
public
268+
{
269+
require(batch.length % 2 == 0);
270+
for (uint i = 0; i < batch.length / 2; i++) {
271+
cancelledOrFilled[batch[i * 2]] =
272+
cancelledOrFilled[batch[i * 2]].add(uint(batch[i * 2 + 1]));
273+
}
274+
}
275+
266276
function setCutoffs(uint t)
267277
onlyAuthorized
268278
external

0 commit comments

Comments
 (0)