Skip to content

Commit b3b5f72

Browse files
committed
update contract comment and receiver function
1 parent 61b2899 commit b3b5f72

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

packages/smart-contracts/src/contracts/BatchConversionPayments.sol

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ contract BatchConversionPayments is BatchNoConversionPayments {
2424
IERC20ConversionProxy public paymentErc20ConversionProxy;
2525
IEthConversionProxy public paymentNativeConversionProxy;
2626

27+
/** payerAuthorized is set to true to workaround the non-payable aspect in batch native conversion */
28+
bool private payerAuthorized = false;
29+
2730
/**
2831
* @dev Used by the batchPayment to handle information for heterogeneous batches, grouped by payment network:
2932
* - paymentNetworkId: from 0 to 4, cf. `batchPayment()` method
@@ -61,6 +64,15 @@ contract BatchConversionPayments is BatchNoConversionPayments {
6164
paymentNativeConversionProxy = IEthConversionProxy(_paymentNativeConversionFeeProxy);
6265
}
6366

67+
/**
68+
* This contract is non-payable.
69+
* Making a Native payment with conversion requires the contract to accept incoming Native tokens.
70+
* @dev See the end of `paymentNativeConversionProxy.transferWithReferenceAndFee` where the leftover is given back.
71+
*/
72+
receive() external payable override {
73+
require(payerAuthorized || msg.value == 0, 'Non-payable');
74+
}
75+
6476
/**
6577
* @notice Batch payments on different payment networks at once.
6678
* @param metaDetails contains paymentNetworkId and requestDetails
@@ -194,7 +206,7 @@ contract BatchConversionPayments is BatchNoConversionPayments {
194206
for (uint256 k = 0; k < uTokens.length && uTokens[k].amountAndFee > 0; k++) {
195207
uTokens[k].batchFeeAmount = (uTokens[k].amountAndFee * batchFee) / feeDenominator;
196208
requestedToken = IERC20(uTokens[k].tokenAddress);
197-
contractAllowanceApprovalTransfer(
209+
transferToContract(
198210
requestedToken,
199211
uTokens[k].amountAndFee,
200212
uTokens[k].batchFeeAmount,
@@ -204,16 +216,16 @@ contract BatchConversionPayments is BatchNoConversionPayments {
204216

205217
// Batch pays the requests using Erc20ConversionFeeProxy
206218
for (uint256 i = 0; i < requestDetails.length; i++) {
207-
RequestDetail memory rI = requestDetails[i];
219+
RequestDetail calldata rD = requestDetails[i];
208220
paymentErc20ConversionProxy.transferFromWithReferenceAndFee(
209-
rI.recipient,
210-
rI.requestAmount,
211-
rI.path,
212-
rI.paymentReference,
213-
rI.feeAmount,
221+
rD.recipient,
222+
rD.requestAmount,
223+
rD.path,
224+
rD.paymentReference,
225+
rD.feeAmount,
214226
feeAddress,
215-
rI.maxToSpend,
216-
rI.maxRateTimespan
227+
rD.maxToSpend,
228+
rD.maxRateTimespan
217229
);
218230
}
219231

@@ -271,7 +283,7 @@ contract BatchConversionPayments is BatchNoConversionPayments {
271283

272284
// Batch contract pays the requests through nativeConversionProxy
273285
for (uint256 i = 0; i < requestDetails.length; i++) {
274-
RequestDetail memory rD = requestDetails[i];
286+
RequestDetail calldata rD = requestDetails[i];
275287
paymentNativeConversionProxy.transferWithReferenceAndFee{value: address(this).balance}(
276288
payable(rD.recipient),
277289
rD.requestAmount,

packages/smart-contracts/src/contracts/BatchNoConversionPayments.sol

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ contract BatchNoConversionPayments is Ownable {
3636
batchFeeAmountUSDLimit = 150 * 1e8 represents $150 */
3737
uint64 public batchFeeAmountUSDLimit;
3838

39-
/** payerAuthorized is set to true only when needed for batch native conversion */
40-
bool internal payerAuthorized = false;
4139
/** transferBackRemainingNativeTokens is set to false only if the payer use batchPayment
4240
and call both batchNativePayments and batchNativeConversionPayments */
4341
bool internal transferBackRemainingNativeTokens = true;
@@ -97,11 +95,10 @@ contract BatchNoConversionPayments is Ownable {
9795

9896
/**
9997
* This contract is non-payable.
100-
* Making a Native payment with conversion requires the contract to accept incoming Native tokens.
101-
* @dev See the end of `paymentNativeConversionProxy.transferWithReferenceAndFee` where the leftover is given back.
98+
* @dev See the end of `paymentNativeProxy.transferWithReferenceAndFee` where the leftover is given back.
10299
*/
103-
receive() external payable {
104-
require(payerAuthorized || msg.value == 0, 'Non-payable');
100+
receive() external payable virtual {
101+
require(msg.value == 0, 'Non-payable');
105102
}
106103

107104
/**
@@ -178,7 +175,7 @@ contract BatchNoConversionPayments is Ownable {
178175

179176
// Batch contract pays the requests thourgh NativeFeeProxy (EthFeeProxy)
180177
for (uint256 i = 0; i < requestDetails.length; i++) {
181-
RequestDetail memory rD = requestDetails[i];
178+
RequestDetail calldata rD = requestDetails[i];
182179
require(address(this).balance >= rD.requestAmount + rD.feeAmount, 'Not enough funds');
183180
amount += rD.requestAmount;
184181

@@ -248,12 +245,7 @@ contract BatchNoConversionPayments is Ownable {
248245

249246
IERC20 requestedToken = IERC20(requestDetails[0].path[0]);
250247

251-
contractAllowanceApprovalTransfer(
252-
requestedToken,
253-
amountAndFee,
254-
batchFeeAmount,
255-
address(paymentErc20Proxy)
256-
);
248+
transferToContract(requestedToken, amountAndFee, batchFeeAmount, address(paymentErc20Proxy));
257249

258250
// Payer pays batch fee amount
259251
require(
@@ -263,7 +255,7 @@ contract BatchNoConversionPayments is Ownable {
263255

264256
// Batch contract pays the requests using Erc20FeeProxy
265257
for (uint256 i = 0; i < requestDetails.length; i++) {
266-
RequestDetail memory rD = requestDetails[i];
258+
RequestDetail calldata rD = requestDetails[i];
267259
paymentErc20Proxy.transferFromWithReferenceAndFee(
268260
rD.path[0],
269261
rD.recipient,
@@ -300,7 +292,7 @@ contract BatchNoConversionPayments is Ownable {
300292
for (uint256 i = 0; i < uTokens.length && uTokens[i].amountAndFee > 0; i++) {
301293
uTokens[i].batchFeeAmount = (uTokens[i].batchFeeAmount * batchFee) / feeDenominator;
302294
IERC20 requestedToken = IERC20(uTokens[i].tokenAddress);
303-
contractAllowanceApprovalTransfer(
295+
transferToContract(
304296
requestedToken,
305297
uTokens[i].amountAndFee,
306298
uTokens[i].batchFeeAmount,
@@ -326,7 +318,7 @@ contract BatchNoConversionPayments is Ownable {
326318

327319
// Batch contract pays the requests using Erc20FeeProxy
328320
for (uint256 i = 0; i < requestDetails.length; i++) {
329-
RequestDetail memory rD = requestDetails[i];
321+
RequestDetail calldata rD = requestDetails[i];
330322
paymentErc20Proxy.transferFromWithReferenceAndFee(
331323
rD.path[0],
332324
rD.recipient,
@@ -344,17 +336,19 @@ contract BatchNoConversionPayments is Ownable {
344336
*/
345337

346338
/**
347-
* It:
339+
* Top up the contract with enough `requestedToken` to pay `amountAndFee`.
340+
*
341+
* It also performs a few checks:
348342
* - checks that the batch contract has enough allowance from the payer
349-
* - checks that the payer has enough fund, including batch fees
350-
* - does the transfer of token from the payer to the batch contract
343+
* - checks that the payer has enough funds, including batch fees
351344
* - increases the allowance of the contract to use the payment proxy if needed
345+
*
352346
* @param requestedToken The token to pay
353347
* @param amountAndFee The amount and the fee for a token to pay
354348
* @param batchFeeAmount The batch fee amount for a token to pay
355349
* @param paymentProxyAddress The payment proxy address used to pay
356350
*/
357-
function contractAllowanceApprovalTransfer(
351+
function transferToContract(
358352
IERC20 requestedToken,
359353
uint256 amountAndFee,
360354
uint256 batchFeeAmount,
@@ -400,7 +394,7 @@ contract BatchNoConversionPayments is Ownable {
400394
uTokens = new Token[](requestDetails.length);
401395
for (uint256 i = 0; i < requestDetails.length; i++) {
402396
for (uint256 k = 0; k < requestDetails.length; k++) {
403-
RequestDetail memory rD = requestDetails[i];
397+
RequestDetail calldata rD = requestDetails[i];
404398
// If the token is already in the existing uTokens list
405399
if (uTokens[k].tokenAddress == rD.path[rD.path.length - 1]) {
406400
if (rD.path.length > 1) {

packages/smart-contracts/src/contracts/BatchPayments.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ contract BatchPayments is Ownable, ReentrancyGuard {
6464
* @dev It uses EthereumFeeProxy to pay an invoice and fees, with a payment reference.
6565
* Make sure: msg.value >= sum(_amouts)+sum(_feeAmounts)+sumBatchFeeAmount
6666
*/
67-
function batchNativePaymentsWithReference(
67+
function batchEthPaymentsWithReference(
6868
address[] calldata _recipients,
6969
uint256[] calldata _amounts,
7070
bytes[] calldata _paymentReferences,

0 commit comments

Comments
 (0)