@@ -189,7 +189,6 @@ contract Escrow is IEscrow, ReentrancyGuard {
189189 trusted
190190 notBroke
191191 notComplete
192- notPaid
193192 nonReentrant
194193 returns (bool )
195194 {
@@ -218,6 +217,8 @@ contract Escrow is IEscrow, ReentrancyGuard {
218217 return true ;
219218 }
220219
220+ // For backward compatibility: this function can only be called on existing escrows,
221+ // as the "Paid" status is not set anywhere for new escrows.
221222 function complete () external override notExpired trustedOrReputationOracle {
222223 require (status == EscrowStatuses.Paid, 'Escrow not in Paid state ' );
223224 status = EscrowStatuses.Complete;
@@ -243,7 +244,7 @@ contract Escrow is IEscrow, ReentrancyGuard {
243244
244245 /**
245246 * @dev Performs bulk payout to multiple workers
246- * Escrow needs to be complted / cancelled, so that it can be paid out.
247+ * Escrow needs to be completed / cancelled, so that it can be paid out.
247248 * Every recipient is paid with the amount after reputation and recording oracle fees taken out.
248249 * If the amount is less than the fee, the recipient is not paid.
249250 * If the fee is zero, reputation, and recording oracle are not paid.
@@ -257,20 +258,21 @@ contract Escrow is IEscrow, ReentrancyGuard {
257258 * @param _url URL storing results as transaction details
258259 * @param _hash Hash of the results
259260 * @param _txId Transaction ID
261+ * @param forceComplete Boolean parameter indicating if remaining balance should be transferred to the escrow creator
260262 */
261263 function bulkPayOut (
262264 address [] memory _recipients ,
263265 uint256 [] memory _amounts ,
264266 string memory _url ,
265267 string memory _hash ,
266- uint256 _txId
268+ uint256 _txId ,
269+ bool forceComplete
267270 )
268- external
271+ public
269272 override
270273 trustedOrReputationOracle
271274 notBroke
272275 notLaunched
273- notPaid
274276 notExpired
275277 nonReentrant
276278 {
@@ -343,15 +345,22 @@ contract Escrow is IEscrow, ReentrancyGuard {
343345
344346 remainingFunds = cachedRemainingFunds;
345347
348+ // Check the forceComplete flag and transfer remaining funds if true
349+ if (forceComplete && cachedRemainingFunds > 0 ) {
350+ _safeTransfer (token, launcher, cachedRemainingFunds);
351+ cachedRemainingFunds = 0 ;
352+ }
353+
346354 if (cachedRemainingFunds == 0 ) {
347- status = EscrowStatuses.Paid ;
355+ status = EscrowStatuses.Complete ;
348356 emit BulkTransferV2 (
349357 _txId,
350358 _recipients,
351359 _amounts,
352360 false ,
353361 finalResultsUrl
354362 );
363+ emit Completed ();
355364 } else {
356365 status = EscrowStatuses.Partial;
357366 emit BulkTransferV2 (
@@ -364,6 +373,26 @@ contract Escrow is IEscrow, ReentrancyGuard {
364373 }
365374 }
366375
376+ /**
377+ * @dev Overloaded function to perform bulk payout with default forceComplete set to false.
378+ * Calls the main bulkPayout function with forceComplete as false.
379+ *
380+ * @param _recipients Array of recipients
381+ * @param _amounts Array of amounts to be paid to each recipient.
382+ * @param _url URL storing results as transaction details
383+ * @param _hash Hash of the results
384+ * @param _txId Transaction ID
385+ */
386+ function bulkPayOut (
387+ address [] memory _recipients ,
388+ uint256 [] memory _amounts ,
389+ string memory _url ,
390+ string memory _hash ,
391+ uint256 _txId
392+ ) external {
393+ bulkPayOut (_recipients, _amounts, _url, _hash, _txId, false );
394+ }
395+
367396 function _safeTransfer (address _token , address to , uint256 value ) internal {
368397 SafeERC20.safeTransfer (IERC20 (_token), to, value);
369398 }
0 commit comments