-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathPermit2PaymentCollector.sol
More file actions
54 lines (48 loc) · 2.15 KB
/
Copy pathPermit2PaymentCollector.sol
File metadata and controls
54 lines (48 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {ISignatureTransfer} from "permit2/interfaces/ISignatureTransfer.sol";
import {TokenCollector} from "./TokenCollector.sol";
import {ERC6492SignatureHandler} from "./ERC6492SignatureHandler.sol";
import {AuthCaptureEscrow} from "../AuthCaptureEscrow.sol";
/// @title Permit2PaymentCollector
///
/// @notice Collect payments using Permit2 signatures
///
/// @author Coinbase (https://github.com/base/commerce-payments)
contract Permit2PaymentCollector is TokenCollector, ERC6492SignatureHandler {
/// @inheritdoc TokenCollector
TokenCollector.CollectorType public constant override collectorType = TokenCollector.CollectorType.Payment;
/// @notice Permit2 singleton
ISignatureTransfer public immutable permit2;
/// @notice Constructor
///
/// @param authCaptureEscrow_ AuthCaptureEscrow singleton that calls to collect tokens
/// @param permit2_ Permit2 singleton
/// @param multicall3_ Public Multicall3 singleton for safe ERC-6492 external calls
constructor(address authCaptureEscrow_, address permit2_, address multicall3_)
TokenCollector(authCaptureEscrow_)
ERC6492SignatureHandler(multicall3_)
{
permit2 = ISignatureTransfer(permit2_);
}
/// @inheritdoc TokenCollector
///
/// @dev Use Permit2 signature transfer to collect any ERC-20 from payers
function _collectTokens(
AuthCaptureEscrow.PaymentInfo calldata paymentInfo,
address tokenStore,
uint256 amount,
bytes calldata collectorData
) internal override {
permit2.permitTransferFrom({
permit: ISignatureTransfer.PermitTransferFrom({
permitted: ISignatureTransfer.TokenPermissions({token: paymentInfo.token, amount: paymentInfo.maxAmount}),
nonce: uint256(_getHashPayerAgnostic(paymentInfo)),
deadline: paymentInfo.preApprovalExpiry
}),
transferDetails: ISignatureTransfer.SignatureTransferDetails({to: tokenStore, requestedAmount: amount}),
owner: paymentInfo.payer,
signature: _handleERC6492Signature(collectorData)
});
}
}