Function payInvoiceERC20Escrow
function payInvoiceERC20Escrow(
address _payee,
address _feeAddress,
uint256 _amount,
uint256 _feeAmount,
bytes calldata _paymentReference,
uint8 _shouldPayoutViaRequestNetwork
) external nonReentrant whenNotPaused {
PaymentERC20 storage paymentERC20 = paymentMapping[_paymentReference];
uint256 totalAmount = _amount + _feeAmount;
if(_amount == 0) revert ZeroAmount();
if(_payee == address(0)) revert ZeroPayeeAddress();
if(_feeAddress == address(0)) revert ZeroFeeAddress();
if(paymentERC20.amount != 0) revert PaymentReferenceInUse();
if(totalAmount < minTotalAmountParameter) revert InvalidTotalAmount();
IERC20(baseAsset).safeTransferFrom(msg.sender, address(this), totalAmount);
uint256 cUsdcbalanceBeforeSupply = getContractCometBalance();
IComet(cometAddress).supply(baseAsset, totalAmount);
uint256 cUsdcbalanceAfterSupply = getContractCometBalance();
uint256 cUsdcAmountToWrap = cUsdcbalanceAfterSupply - cUsdcbalanceBeforeSupply;
uint256 wrappedShares = IWrapper(wrapperAddress).deposit(cUsdcAmountToWrap, address(this));
paymentMapping[_paymentReference] = PaymentERC20({
amount: _amount,
feeAmount: _feeAmount,
wrapperSharesReceived: wrappedShares,
dueDate: 0,
payer: msg.sender,
payee: _payee,
feeAddress: _feeAddress,
shouldPayoutViaRequestNetwork: _shouldPayoutViaRequestNetwork
});
emit PaymentERC20Event(baseAsset, _payee, _feeAddress, _amount, 0, _feeAmount, _paymentReference);
}
Parameter
Description
Interact with the payInvoiceERC20 function:
Last updated