@@ -4,23 +4,15 @@ import "@iconfoundation/xcall-solidity-library/utils/ParseAddress.sol";
4
4
5
5
import "./Types.sol " ;
6
6
import "./IPermit2.sol " ;
7
+ import {console} from "forge-std/console.sol " ;
7
8
8
- /**
9
- * @notice Permit2OrderLib knows how to process a particular type of external Permit2Order so that it can be used in Across.
10
- * @dev This library is responsible for validating the order and communicating with Permit2 to pull the tokens in.
11
- * This is a library to allow it to be pulled directly into the SpokePool in a future version.
12
- */
13
9
library Permit2OrderLib {
14
10
using ParseAddress for string ;
15
11
16
- // Type strings and hashes
17
- bytes private constant OUTPUT_TOKEN_TYPE =
18
- "OutputToken(address recipient,address token,uint256 amount,uint256 chainId) " ;
19
- bytes32 private constant OUTPUT_TOKEN_TYPE_HASH = keccak256 (OUTPUT_TOKEN_TYPE);
20
-
21
12
bytes internal constant ORDER_TYPE =
22
13
abi.encodePacked (
23
14
"SwapOrder( " ,
15
+ "uint256 id, " ,
24
16
"string emitter, " ,
25
17
"string srcNID, " ,
26
18
"string dstNID, " ,
@@ -30,55 +22,57 @@ library Permit2OrderLib {
30
22
"uint256 amount, " ,
31
23
"string toToken, " ,
32
24
"uint256 toAmount, " ,
33
- "bytes data, "
25
+ "bytes data) "
34
26
);
35
27
bytes32 internal constant ORDER_TYPE_HASH = keccak256 (ORDER_TYPE);
36
- string private constant TOKEN_PERMISSIONS_TYPE = "TokenPermissions(address token,uint256 amount) " ;
28
+ string private constant TOKEN_PERMISSIONS_TYPE =
29
+ "TokenPermissions(address token,uint256 amount) " ;
37
30
string internal constant PERMIT2_ORDER_TYPE =
38
- string (abi.encodePacked ("SwapOrder witness) " , ORDER_TYPE, TOKEN_PERMISSIONS_TYPE));
39
-
31
+ string (
32
+ abi.encodePacked (
33
+ "SwapOrder witness) " ,
34
+ ORDER_TYPE,
35
+ TOKEN_PERMISSIONS_TYPE
36
+ )
37
+ );
40
38
// Hashes an order to get an order hash. Needed for permit2.
41
- function _hashOrder (Types.SwapOrder memory order ) internal pure returns (bytes32 ) {
39
+ function _hashOrder (
40
+ Types.SwapOrder memory order
41
+ ) internal pure returns (bytes32 ) {
42
42
bytes memory orderData = abi.encode (
43
43
ORDER_TYPE_HASH,
44
- order.emitter,
45
- order.srcNID,
46
- order.dstNID,
47
- order.creator,
48
- order.destinationAddress,
49
- order.token,
44
+ order.id,
45
+ keccak256 (abi.encodePacked (order.emitter)),
46
+ keccak256 (abi.encodePacked (order.srcNID)),
47
+ keccak256 (abi.encodePacked (order.dstNID)),
48
+ keccak256 (abi.encodePacked (order.creator)),
49
+ keccak256 (abi.encodePacked (order.destinationAddress)),
50
+ keccak256 (abi.encodePacked (order.token)),
50
51
order.amount,
51
- order.toToken,
52
+ keccak256 ( abi.encodePacked ( order.toToken)) ,
52
53
order.toAmount,
53
- order.data
54
+ keccak256 ( order.data)
54
55
);
55
56
56
57
return keccak256 (orderData);
57
58
}
58
59
59
- function _processPermit2Order (IPermit2 permit2 , Types.SwapOrder memory order , bytes memory signature , uint32 deadline )
60
- internal
61
- {
62
- address token = order.token.parseAddress ("IllegalArgument " );
63
- IPermit2.PermitTransferFrom memory permit = IPermit2.PermitTransferFrom ({
64
- permitted: IPermit2.TokenPermissions ({ token: token , amount: order.amount }),
65
- nonce: order.id,
66
- deadline: deadline
67
- });
68
-
69
- IPermit2.SignatureTransferDetails memory signatureTransferDetails = IPermit2.SignatureTransferDetails ({
70
- to: address (this ),
71
- requestedAmount: order.amount
72
- });
73
-
74
- // Pull user funds.
60
+ function _processPermit2Order (
61
+ IPermit2 permit2 ,
62
+ Types.SwapOrder memory order ,
63
+ bytes memory signature ,
64
+ IPermit2.PermitTransferFrom memory permit
65
+ ) internal {
75
66
permit2.permitWitnessTransferFrom (
76
67
permit,
77
- signatureTransferDetails,
68
+ IPermit2.SignatureTransferDetails ({
69
+ to: address (this ),
70
+ requestedAmount: order.amount
71
+ }),
78
72
order.creator.parseAddress ("IllegalArgument " ),
79
73
_hashOrder (order),
80
74
PERMIT2_ORDER_TYPE,
81
75
signature
82
76
);
83
77
}
84
- }
78
+ }
0 commit comments