Skip to content

Commit b4fb245

Browse files
authored
Merge pull request #68 from Merit-Systems/refactor/remove-totalGrossAmount
Remove totalGrossAmount loop
2 parents 6d49692 + 19dae92 commit b4fb245

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

interface/IEscrow.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ struct DepositParams {
2828
* - A protocol fee can be configured and applied to deposits.
2929
*/
3030
interface IEscrow {
31-
event Deposited (uint indexed depositId, address indexed token, address indexed recipient, address sender, uint amount, uint claimDeadline);
31+
event Deposited (uint indexed depositId, address indexed token, address indexed recipient, address sender, uint netAmount, uint feeAmount, uint claimDeadline);
3232
event Claimed (uint indexed depositId, address indexed recipient, uint amount);
3333
event Reclaimed (uint indexed depositId, address indexed sender, uint amount);
3434
event CanClaimSet (address indexed recipient, bool status);
3535
event ProtocolFeeSet (uint newFeeBps);
3636
event FeeRecipientSet (address newFeeRecipient);
3737
event TokenWhitelisted (address indexed token);
3838
event TokenRemovedFromWhitelist(address indexed token);
39-
event BatchDeposited (uint indexed batchId, uint repoId, uint timestamp, uint[] depositIds, uint totalGrossAmount);
39+
event BatchDeposited (uint indexed batchId, uint repoId, uint timestamp, uint[] depositIds);
4040

4141
/**
4242
* @notice Deposits tokens into the escrow on behalf of a specified sender and recipient.

src/Escrow.sol

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ contract Escrow is Owned, IEscrow {
7878
require(_whitelistedTokens.contains(address(param.token)), Errors.INVALID_TOKEN);
7979

8080
uint feeAmount;
81-
uint amountToEscrow = param.amount;
81+
uint netAmount = param.amount;
8282
if (protocolFeeBps > 0) {
83-
feeAmount = param.amount.mulDivUp(protocolFeeBps, 10_000);
84-
amountToEscrow = param.amount - feeAmount;
85-
require(amountToEscrow > 0, Errors.INVALID_AMOUNT_AFTER_FEE);
83+
feeAmount = param.amount.mulDivUp(protocolFeeBps, 10_000);
84+
netAmount = param.amount - feeAmount;
85+
require(netAmount > 0, Errors.INVALID_AMOUNT_AFTER_FEE);
8686
}
8787

8888
param.token.safeTransferFrom(msg.sender, address(this), param.amount);
@@ -92,7 +92,7 @@ contract Escrow is Owned, IEscrow {
9292
}
9393

9494
deposits[depositCount] = Deposit({
95-
amount: amountToEscrow,
95+
amount: netAmount,
9696
token: param.token,
9797
recipient: param.recipient,
9898
sender: param.sender,
@@ -108,7 +108,8 @@ contract Escrow is Owned, IEscrow {
108108
address(param.token),
109109
param.recipient,
110110
param.sender,
111-
amountToEscrow,
111+
netAmount,
112+
feeAmount,
112113
block.timestamp + param.claimPeriod
113114
);
114115

@@ -124,15 +125,13 @@ contract Escrow is Owned, IEscrow {
124125
external
125126
returns (uint[] memory depositIds)
126127
{
127-
uint totalGrossAmount;
128128
depositIds = new uint[](params.length);
129129

130130
for (uint256 i = 0; i < params.length; i++) {
131131
depositIds[i] = deposit(params[i]);
132-
totalGrossAmount += params[i].amount;
133132
}
134133

135-
emit BatchDeposited(batchCount++, repoId, timestamp, depositIds, totalGrossAmount);
134+
emit BatchDeposited(batchCount++, repoId, timestamp, depositIds);
136135
}
137136

138137
/*//////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)