@@ -29,16 +29,14 @@ contract BatchNoConversionPayments is Ownable {
29
29
ChainlinkConversionPath public chainlinkConversionPath;
30
30
31
31
/** Used to calculate batch fees: batchFee = 30 represent 0.30% of fee */
32
- uint256 public batchFee;
32
+ uint16 public batchFee;
33
33
/** Used to calculate batch fees: divide batchFee by feeDenominator */
34
- uint256 internal feeDenominator = 10000 ;
34
+ uint16 internal feeDenominator = 10000 ;
35
35
/** The amount of the batch fee cannot exceed a predefined amount in USD */
36
- uint256 public batchFeeAmountUSDLimit;
36
+ uint64 public batchFeeAmountUSDLimit;
37
37
38
38
/** payerAuthorized is set to true only when needed for batch Eth conversion */
39
39
bool internal payerAuthorized = false ;
40
- /** batchPayment function is the caller */
41
- bool internal batchPaymentOrigin = false ;
42
40
/** transferBackRemainingEth is set to false only if the payer use batchPayment
43
41
and call both batchEthPayments and batchConversionEthPaymentsWithReference */
44
42
bool internal transferBackRemainingEth = true ;
@@ -108,22 +106,71 @@ contract BatchNoConversionPayments is Ownable {
108
106
* @notice Send a batch of ETH (or EVM native token) payments with fees and paymentReferences to multiple accounts.
109
107
* If one payment fails, the whole batch reverts.
110
108
* @param requestDetails List of ETH requests to pay.
111
- * @param applyFeeLimitUSD It set to true to apply the USD fee limit.
112
- * @param batchFeeAmountUSD The batch fee amount in USD already paid.
109
+ * @param skipFeeUSDLimit Setting the value to true skips the USD fee limit, and reduce gas consumption.
113
110
* @param feeAddress The fee recipient.
114
111
* @dev It uses EthereumFeeProxy to pay an invoice and fees with a payment reference.
115
112
* Make sure: msg.value >= sum(_amouts)+sum(_feeAmounts)+sumBatchFeeAmount
116
113
*/
117
114
function batchEthPayments (
118
115
RequestDetail[] calldata requestDetails ,
119
- bool applyFeeLimitUSD ,
120
- uint256 batchFeeAmountUSD ,
116
+ bool skipFeeUSDLimit ,
121
117
address payable feeAddress
122
118
) public payable returns (uint256 ) {
123
- // Avoid the possibility to manually put high value to batchFeeAmountUSD
124
- if (batchPaymentOrigin != true && applyFeeLimitUSD == true ) {
125
- batchFeeAmountUSD = 0 ;
126
- }
119
+ return _batchEthPayments (requestDetails, skipFeeUSDLimit, 0 , payable (feeAddress));
120
+ }
121
+
122
+ /**
123
+ * @notice Send a batch of ERC20 payments with fees and paymentReferences to multiple accounts.
124
+ * @param requestDetails List of ERC20 requests to pay, with only one ERC20 token.
125
+ * @param pathsToUSD The list of paths into USD for every token, used to limit the batch fees.
126
+ * Without paths, there is not a fee limitation, and it consumes less gas.
127
+ * @param feeAddress The fee recipient.
128
+ * @dev Uses ERC20FeeProxy to pay an invoice and fees, with a payment reference.
129
+ * Make sure this contract has enough allowance to spend the payer's token.
130
+ * Make sure the payer has enough tokens to pay the amount, the fee, and the batch fee.
131
+ */
132
+ function batchERC20Payments (
133
+ RequestDetail[] calldata requestDetails ,
134
+ address [][] calldata pathsToUSD ,
135
+ address feeAddress
136
+ ) public returns (uint256 ) {
137
+ return _batchERC20Payments (requestDetails, pathsToUSD, 0 , feeAddress);
138
+ }
139
+
140
+ /**
141
+ * @notice Send a batch of ERC20 payments with fees and paymentReferences to multiple accounts, with multiple tokens.
142
+ * @param requestDetails List of ERC20 requests to pay.
143
+ * @param pathsToUSD The list of paths into USD for every token, used to limit the batch fees.
144
+ * Without paths, there is not a fee limitation, and it consumes less gas.
145
+ * @param feeAddress The fee recipient.
146
+ * @dev It uses ERC20FeeProxy to pay an invoice and fees, with a payment reference.
147
+ * Make sure this contract has enough allowance to spend the payer's token.
148
+ * Make sure the payer has enough tokens to pay the amount, the fee, and the batch fee.
149
+ */
150
+ function batchMultiERC20Payments (
151
+ RequestDetail[] calldata requestDetails ,
152
+ address [][] calldata pathsToUSD ,
153
+ address feeAddress
154
+ ) public returns (uint256 ) {
155
+ return _batchMultiERC20Payments (requestDetails, pathsToUSD, 0 , feeAddress);
156
+ }
157
+
158
+ /**
159
+ * @notice Send a batch of ETH (or EVM native token) payments with fees and paymentReferences to multiple accounts.
160
+ * If one payment fails, the whole batch reverts.
161
+ * @param requestDetails List of ETH requests to pay.
162
+ * @param skipFeeUSDLimit Setting the value to true skips the USD fee limit, and reduce gas consumption.
163
+ * @param batchFeeAmountUSD The batch fee amount in USD already paid.
164
+ * @param feeAddress The fee recipient.
165
+ * @dev It uses EthereumFeeProxy to pay an invoice and fees with a payment reference.
166
+ * Make sure: msg.value >= sum(_amouts)+sum(_feeAmounts)+sumBatchFeeAmount
167
+ */
168
+ function _batchEthPayments (
169
+ RequestDetail[] calldata requestDetails ,
170
+ bool skipFeeUSDLimit ,
171
+ uint256 batchFeeAmountUSD ,
172
+ address payable feeAddress
173
+ ) internal returns (uint256 ) {
127
174
// amount is used to get the total amount and then used as batch fee amount
128
175
uint256 amount = 0 ;
129
176
@@ -143,7 +190,7 @@ contract BatchNoConversionPayments is Ownable {
143
190
144
191
// amount is updated into batch fee amount
145
192
amount = (amount * batchFee) / feeDenominator;
146
- if (applyFeeLimitUSD == true ) {
193
+ if (skipFeeUSDLimit == false ) {
147
194
(amount, batchFeeAmountUSD) = calculateBatchFeeToPay (
148
195
amount,
149
196
pathsEthToUSD[0 ][0 ],
@@ -168,23 +215,19 @@ contract BatchNoConversionPayments is Ownable {
168
215
* @notice Send a batch of ERC20 payments with fees and paymentReferences to multiple accounts.
169
216
* @param requestDetails List of ERC20 requests to pay, with only one ERC20 token.
170
217
* @param pathsToUSD The list of paths into USD for every token, used to limit the batch fees.
171
- * Without paths, there is not limitation.
218
+ * Without paths, there is not a fee limitation, and it consumes less gas .
172
219
* @param batchFeeAmountUSD The batch fee amount in USD already paid.
173
220
* @param feeAddress The fee recipient.
174
221
* @dev Uses ERC20FeeProxy to pay an invoice and fees, with a payment reference.
175
222
* Make sure this contract has enough allowance to spend the payer's token.
176
223
* Make sure the payer has enough tokens to pay the amount, the fee, and the batch fee.
177
224
*/
178
- function batchERC20Payments (
225
+ function _batchERC20Payments (
179
226
RequestDetail[] calldata requestDetails ,
180
227
address [][] calldata pathsToUSD ,
181
228
uint256 batchFeeAmountUSD ,
182
229
address feeAddress
183
- ) public returns (uint256 ) {
184
- // Avoid the possibility to manually put high value to batchFeeAmountUSD
185
- if (batchPaymentOrigin != true ) {
186
- batchFeeAmountUSD = 0 ;
187
- }
230
+ ) internal returns (uint256 ) {
188
231
uint256 amountAndFee = 0 ;
189
232
uint256 batchFeeAmount = 0 ;
190
233
for (uint256 i = 0 ; i < requestDetails.length ; i++ ) {
@@ -236,23 +279,19 @@ contract BatchNoConversionPayments is Ownable {
236
279
* @notice Send a batch of ERC20 payments with fees and paymentReferences to multiple accounts, with multiple tokens.
237
280
* @param requestDetails List of ERC20 requests to pay.
238
281
* @param pathsToUSD The list of paths into USD for every token, used to limit the batch fees.
239
- * Without paths, there is not limitation.
282
+ * Without paths, there is not a fee limitation, and it consumes less gas .
240
283
* @param batchFeeAmountUSD The batch fee amount in USD already paid.
241
284
* @param feeAddress The fee recipient.
242
285
* @dev It uses ERC20FeeProxy to pay an invoice and fees, with a payment reference.
243
286
* Make sure this contract has enough allowance to spend the payer's token.
244
287
* Make sure the payer has enough tokens to pay the amount, the fee, and the batch fee.
245
288
*/
246
- function batchMultiERC20Payments (
289
+ function _batchMultiERC20Payments (
247
290
RequestDetail[] calldata requestDetails ,
248
291
address [][] calldata pathsToUSD ,
249
292
uint256 batchFeeAmountUSD ,
250
293
address feeAddress
251
- ) public returns (uint256 ) {
252
- // Avoid the possibility to manually put high value to batchFeeAmountUSD
253
- if (batchPaymentOrigin != true ) {
254
- batchFeeAmountUSD = 0 ;
255
- }
294
+ ) internal returns (uint256 ) {
256
295
Token[] memory uTokens = getUTokens (requestDetails);
257
296
258
297
// The payer transfers tokens to the batch contract and pays batch fee
@@ -398,7 +437,7 @@ contract BatchNoConversionPayments is Ownable {
398
437
* @param tokenAddress The address of the token
399
438
* @param batchFeeAmountUSD The batch fee amount in USD already paid.
400
439
* @param pathsToUSD The list of paths into USD for every token, used to limit the batch fees.
401
- * Without paths, there is not limitation.
440
+ * Without paths, there is not a fee limitation, and it consumes less gas .
402
441
*/
403
442
function calculateBatchFeeToPay (
404
443
uint256 batchFeeToPay ,
@@ -505,7 +544,7 @@ contract BatchNoConversionPayments is Ownable {
505
544
* @notice Fees added when using Erc20/Eth batch functions
506
545
* @param _batchFee Between 0 and 200, i.e: batchFee = 30 represent 0.30% of fee
507
546
*/
508
- function setBatchFee (uint256 _batchFee ) external onlyOwner {
547
+ function setBatchFee (uint16 _batchFee ) external onlyOwner {
509
548
// safety to avoid wrong setting
510
549
require (_batchFee <= 200 , 'The batch fee value is too high: > 2% ' );
511
550
batchFee = _batchFee;
@@ -548,7 +587,7 @@ contract BatchNoConversionPayments is Ownable {
548
587
/**
549
588
* @param _batchFeeAmountUSDLimit The limitation of the batch fee amount in USD.
550
589
*/
551
- function setBatchFeeAmountUSDLimit (uint256 _batchFeeAmountUSDLimit ) external onlyOwner {
590
+ function setBatchFeeAmountUSDLimit (uint64 _batchFeeAmountUSDLimit ) external onlyOwner {
552
591
batchFeeAmountUSDLimit = _batchFeeAmountUSDLimit;
553
592
}
554
593
}
0 commit comments