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
3 changes: 1 addition & 2 deletions contracts/LoopringProtocol.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ contract LoopringProtocol {

event RingMined(
uint _ringIndex,
bytes32 indexed _ringHash,
address _miner,
address indexed _miner,
Fill[] _fills
);

Expand Down
44 changes: 17 additions & 27 deletions contracts/LoopringProtocolImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -748,40 +748,32 @@ contract LoopringProtocolImpl is LoopringProtocol {
private
{
bytes32[] memory batch = new bytes32[](ctx.ringSize * 7);
bytes32[] memory historyBatch = new bytes32[](ctx.ringSize * 2);
Fill[] memory fills = new Fill[](ctx.ringSize);

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

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

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

// Update fill records
if (order.capByAmountB) {
ctx.delegate.addCancelledOrFilled(
order.orderHash,
nextFillAmountS
);
} else {
ctx.delegate.addCancelledOrFilled(
order.orderHash,
order.fillAmountS
);
}
batch[p++] = bytes32(order.fillAmountS - prevSplitB);
batch[p++] = bytes32(prevSplitB + order.splitS);
batch[p++] = bytes32(order.lrcReward);
batch[p++] = bytes32(order.lrcFeeState);
batch[p++] = bytes32(order.wallet);

historyBatch[q++] = order.orderHash;
historyBatch[q++] =
bytes32(order.capByAmountB ? nextFillAmountS : order.fillAmountS);

fills[i] = Fill(
order.orderHash,
Expand All @@ -795,17 +787,15 @@ contract LoopringProtocolImpl is LoopringProtocol {
prevSplitB = order.splitB;
}


// Do all transactions
ctx.delegate.batchTransferToken(
ctx.delegate.batchUpdateHistoryAndTransferTokens(
lrcTokenAddress,
ctx.miner,
historyBatch,
batch
);

emit RingMined(
ctx.ringIndex,
ctx.ringHash,
ctx.miner,
fills
);
Expand Down
5 changes: 3 additions & 2 deletions contracts/TokenTransferDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ contract TokenTransferDelegate {
)
external;

function batchTransferToken(
function batchUpdateHistoryAndTransferTokens(
address lrcTokenAddress,
address minerFeeRecipient,
bytes32[] batch
bytes32[] historyBatch,
bytes32[] transferBatch
)
external;

Expand Down
14 changes: 11 additions & 3 deletions contracts/TokenTransferDelegateImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,27 @@ contract TokenTransferDelegateImpl is TokenTransferDelegate, Claimable {
}
}

function batchTransferToken(
function batchUpdateHistoryAndTransferTokens(
address lrcAddr,
address miner,
bytes32[] historyBatch,
bytes32[] batch
)
onlyAuthorized
external
{
require(batch.length % 9 == 0, "invalid batch");
// require(batch.length % 9 == 0);
// require(historyBatch.length % 2 == 0);
// require(batch.length / 9 == historyBatch.length / 2);
uint i;
for (i = 0; i < historyBatch.length / 2; i += 2) {
cancelledOrFilled[historyBatch[i]] =
cancelledOrFilled[historyBatch[i]].add(uint(historyBatch[i + 1]));
}

address prevOwner = address(batch[batch.length - 9]);

for (uint i = 0; i < batch.length; i += 9) {
for (i = 0; i < batch.length; i += 9) {
address owner = address(batch[i]);
address signer = address(batch[i + 1]);
address tracker = address(batch[i + 2]);
Expand Down