@@ -23,17 +23,21 @@ import { GraphDirectory } from "../utilities/GraphDirectory.sol";
23
23
contract PaymentsEscrow is Initializable , MulticallUpgradeable , GraphDirectory , IPaymentsEscrow {
24
24
using TokenUtils for IGraphToken;
25
25
26
- /// @notice Escrow account details for payer-collector-receiver tuples
27
- mapping (address payer = > mapping (address collector = > mapping (address receiver = > IPaymentsEscrow.EscrowAccount escrowAccount )))
28
- public escrowAccounts;
29
-
30
26
/// @notice The maximum thawing period (in seconds) for both escrow withdrawal and collector revocation
31
27
/// @dev This is a precautionary measure to avoid inadvertedly locking funds for too long
32
28
uint256 public constant MAX_WAIT_PERIOD = 90 days ;
33
29
34
30
/// @notice Thawing period in seconds for escrow funds withdrawal
35
31
uint256 public immutable WITHDRAW_ESCROW_THAWING_PERIOD;
36
32
33
+ /// @notice Escrow account details for payer-collector-receiver tuples
34
+ mapping (address payer = > mapping (address collector = > mapping (address receiver = > IPaymentsEscrow.EscrowAccount escrowAccount )))
35
+ public escrowAccounts;
36
+
37
+ /**
38
+ * @notice Modifier to prevent function execution when contract is paused
39
+ * @dev Reverts if the controller indicates the contract is paused
40
+ */
37
41
modifier notPaused () {
38
42
require (! _graphController ().paused (), PaymentsEscrowIsPaused ());
39
43
_;
@@ -78,19 +82,9 @@ contract PaymentsEscrow is Initializable, MulticallUpgradeable, GraphDirectory,
78
82
* @notice See {IPaymentsEscrow-thaw}
79
83
*/
80
84
function thaw (address collector , address receiver , uint256 tokens ) external override notPaused {
81
- EscrowAccount storage account = escrowAccounts[msg .sender ][collector][receiver];
82
-
83
- // if amount thawing is zero and requested amount is zero this is an invalid request.
84
- // otherwise if amount thawing is greater than zero and requested amount is zero this
85
- // is a cancel thaw request.
86
- if (tokens == 0 ) {
87
- require (account.tokensThawing != 0 , PaymentsEscrowNotThawing ());
88
- account.tokensThawing = 0 ;
89
- account.thawEndTimestamp = 0 ;
90
- emit CancelThaw (msg .sender , receiver);
91
- return ;
92
- }
85
+ require (tokens > 0 , PaymentsEscrowInvalidZeroTokens ());
93
86
87
+ EscrowAccount storage account = escrowAccounts[msg .sender ][collector][receiver];
94
88
require (account.balance >= tokens, PaymentsEscrowInsufficientBalance (account.balance, tokens));
95
89
96
90
account.tokensThawing = tokens;
@@ -99,6 +93,21 @@ contract PaymentsEscrow is Initializable, MulticallUpgradeable, GraphDirectory,
99
93
emit Thaw (msg .sender , collector, receiver, tokens, account.thawEndTimestamp);
100
94
}
101
95
96
+ /**
97
+ * @notice See {IPaymentsEscrow-cancelThaw}
98
+ */
99
+ function cancelThaw (address collector , address receiver ) external override notPaused {
100
+ EscrowAccount storage account = escrowAccounts[msg .sender ][collector][receiver];
101
+ require (account.tokensThawing != 0 , PaymentsEscrowNotThawing ());
102
+
103
+ uint256 tokensThawing = account.tokensThawing;
104
+ uint256 thawEndTimestamp = account.thawEndTimestamp;
105
+ account.tokensThawing = 0 ;
106
+ account.thawEndTimestamp = 0 ;
107
+
108
+ emit CancelThaw (msg .sender , collector, receiver, tokensThawing, thawEndTimestamp);
109
+ }
110
+
102
111
/**
103
112
* @notice See {IPaymentsEscrow-withdraw}
104
113
*/
@@ -138,29 +147,27 @@ contract PaymentsEscrow is Initializable, MulticallUpgradeable, GraphDirectory,
138
147
// Reduce amount from account balance
139
148
account.balance -= tokens;
140
149
141
- uint256 balanceBefore = _graphToken ().balanceOf (address (this ));
150
+ uint256 escrowBalanceBefore = _graphToken ().balanceOf (address (this ));
142
151
143
152
_graphToken ().approve (address (_graphPayments ()), tokens);
144
153
_graphPayments ().collect (paymentType, receiver, tokens, dataService, dataServiceCut);
145
154
146
- uint256 balanceAfter = _graphToken ().balanceOf (address (this ));
155
+ // Verify that the escrow balance is consistent with the collected tokens
156
+ uint256 escrowBalanceAfter = _graphToken ().balanceOf (address (this ));
147
157
require (
148
- balanceBefore == tokens + balanceAfter ,
149
- PaymentsEscrowInconsistentCollection (balanceBefore, balanceAfter , tokens)
158
+ escrowBalanceBefore == tokens + escrowBalanceAfter ,
159
+ PaymentsEscrowInconsistentCollection (escrowBalanceBefore, escrowBalanceAfter , tokens)
150
160
);
151
161
152
- emit EscrowCollected (payer, msg .sender , receiver, tokens);
162
+ emit EscrowCollected (paymentType, payer, msg .sender , receiver, tokens);
153
163
}
154
164
155
165
/**
156
166
* @notice See {IPaymentsEscrow-getBalance}
157
167
*/
158
168
function getBalance (address payer , address collector , address receiver ) external view override returns (uint256 ) {
159
169
EscrowAccount storage account = escrowAccounts[payer][collector][receiver];
160
- if (account.balance <= account.tokensThawing) {
161
- return 0 ;
162
- }
163
- return account.balance - account.tokensThawing;
170
+ return account.balance > account.tokensThawing ? account.balance - account.tokensThawing : 0 ;
164
171
}
165
172
166
173
/**
0 commit comments