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

Commit

Permalink
Merge pull request #278 from Loopring/refactory-based-on-1.3
Browse files Browse the repository at this point in the history
Refactor code (not tested)
  • Loading branch information
kongliangzhong authored Mar 25, 2018
2 parents 411f4a8 + cdaf3e2 commit 2448dd5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 56 deletions.
2 changes: 1 addition & 1 deletion contracts/LoopringProtocolImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ contract LoopringProtocolImpl is LoopringProtocol {
require(0x0 != _nameRegistryAddress);

require(_rateRatioCVSThreshold > 0);
require(_walletSplitPercentage > 0);
require(_walletSplitPercentage > 0 && _walletSplitPercentage < 100);

lrcTokenAddress = _lrcTokenAddress;
tokenRegistryAddress = _tokenRegistryAddress;
Expand Down
130 changes: 75 additions & 55 deletions contracts/TokenTransferDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ contract TokenTransferDelegate is Claimable {
{
uint len = batch.length;
require(len % 7 == 0);
require(walletSplitPercentage >= 0 && walletSplitPercentage <= 100);
require(walletSplitPercentage > 0 && walletSplitPercentage < 100);

ERC20 lrc = ERC20(lrcTokenAddress);

Expand All @@ -182,66 +182,48 @@ contract TokenTransferDelegate is Claimable {

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

// Here batch[i+2] has been checked not to be 0.
// Here batch[i + 2] has been checked not to be 0.
if (owner != prevOwner) {
require(
token.transferFrom(owner, prevOwner, uint(batch[i + 2]))
token.transferFrom(
owner,
prevOwner,
uint(batch[i + 2])
)
);
}

if (minerFeeRecipient != 0x0 && owner != minerFeeRecipient) {
bytes32 item = batch[i + 3];
// address walletFeeRecipient = address(batch[i + 6]);
if (item != 0) {
if (address(batch[i + 6]) != 0x0 && walletSplitPercentage > 0) {
require(
token.transferFrom(owner,
minerFeeRecipient,
uint(item).mul(100 - walletSplitPercentage) / 100
)
);
require(
token.transferFrom(owner,
address(batch[i + 6]),
uint(item).mul(walletSplitPercentage) / 100
)
);
} else {
require(
token.transferFrom(owner, minerFeeRecipient, uint(item))
);
}
}

item = batch[i + 4];
if (item != 0) {
require(
lrc.transferFrom(minerFeeRecipient, owner, uint(item))
);
}

item = batch[i + 5];
if (item != 0) {
if (address(batch[i + 6]) != 0x0 && walletSplitPercentage > 0) {
require(
lrc.transferFrom(owner,
minerFeeRecipient,
uint(item).mul(100 - walletSplitPercentage) / 100
)
);
require(
lrc.transferFrom(owner,
address(batch[i + 6]),
uint(item).mul(walletSplitPercentage) / 100
)
);
} else {
require(
lrc.transferFrom(owner, minerFeeRecipient, uint(item))
);
}
}
// Miner pays LRx fee to order owner
uint lrcReward = uint(batch[i + 4]);
if (lrcReward != 0 && minerFeeRecipient != owner) {
require(
lrc.transferFrom(
minerFeeRecipient,
owner,
lrcReward
)
);
}

// Split margin-split income between miner and wallet
splitPayFee(
token,
uint(batch[i + 3]),
owner,
minerFeeRecipient,
address(batch[i + 6]),
walletSplitPercentage
);

// Split LRx fee income between miner and wallet
splitPayFee(
lrc,
uint(batch[i + 5]),
owner,
minerFeeRecipient,
address(batch[i + 6]),
walletSplitPercentage
);
}
}

Expand All @@ -252,4 +234,42 @@ contract TokenTransferDelegate is Claimable {
{
return addressInfos[addr].authorized;
}

function splitPayFee(
ERC20 token,
uint fee,
address owner,
address minerFeeRecipient,
address walletFeeRecipient,
uint walletSplitPercentage
)
internal
{
if (fee == 0) {
return;
}

uint walletFee = (walletFeeRecipient == 0x0) ? 0 : fee.mul(walletSplitPercentage) / 100;
uint minerFee = fee - walletFee;

if (walletFee > 0 && walletFeeRecipient != owner) {
require(
token.transferFrom(
owner,
walletFeeRecipient,
walletFee
)
);
}

if (minerFee > 0 && minerFeeRecipient != 0x0 && minerFeeRecipient != owner) {
require(
token.transferFrom(
owner,
minerFeeRecipient,
minerFee
)
);
}
}
}

0 comments on commit 2448dd5

Please sign in to comment.