@@ -66,11 +66,11 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, IexecERC2
6666 }
6767
6868 /***************************************************************************
69- * Token Spender: Atomic Deposit+ Match *
69+ * Token Spender: Atomic Deposit + Match *
7070 ***************************************************************************/
7171
7272 /**
73- * @notice Receives approval, deposit and optionally executes an operation in one transaction
73+ * @notice Receives approval, deposit and optionally executes a supported operation in one transaction.
7474 *
7575 * Usage patterns:
7676 * 1. Simple deposit: RLC.approveAndCall(escrow, amount, "")
@@ -82,21 +82,21 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, IexecERC2
8282 *
8383 * @dev Implementation details:
8484 * - Deposits tokens first, then executes the operation if data is provided
85- * - Extracts function selector from data to determine which operation
86- * - Each operation has a validator (_validateMatchOrders, etc.) for preconditions
85+ * - Extracts function selector from data to determine the operation
86+ * - Each operation has a validator (_validateMatchOrders, etc.) to check preconditions
8787 * - After validation, _executeOperation performs the delegatecall
88- * - Error handling is generalized: bubbles up revert reasons or returns 'operation-failed'
88+ * - Error handling is generalized: reverts are bubbled up with revert reasons or custom errors
8989 * - Future operations can be added by implementing a validator and adding a selector case
9090 *
9191 * @dev matchOrders specific notes:
92- * - Sponsoring is NOT supported. The requester (sender ) always pays for the deal.
92+ * - Sponsoring is NOT supported. The requester (specified in the request order ) always pays for the deal.
9393 * - Clients must compute the exact deal cost and deposit the right amount.
9494 * The deal cost = (appPrice + datasetPrice + workerpoolPrice) * volume.
9595 *
9696 * @param sender The address that approved tokens
9797 * @param amount Amount of tokens approved and to be deposited
9898 * @param token Address of the token (must be RLC)
99- * @param data Optional: Function selector + ABI-encoded parameters for operation
99+ * @param data Optional: Function selector + ABI-encoded parameters
100100 * @return success True if operation succeeded
101101 *
102102 *
@@ -114,7 +114,7 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, IexecERC2
114114 * requestOrder
115115 * );
116116 *
117- * // One transaction does it all: approve, deposit, and match
117+ * // Call the RLC contract with the encoded data.
118118 * RLC(token).approveAndCall(iexecProxy, dealCost, data);
119119 * ```
120120 */
@@ -128,56 +128,52 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, IexecERC2
128128 require (token == address ($.m_baseToken), "wrong-token " );
129129 _deposit (sender, amount);
130130 _mint (sender, amount);
131-
132131 if (data.length > 0 ) {
133132 _executeOperation (sender, data);
134133 }
135134 return true ;
136135 }
137136
137+ /**
138+ * Executes a supported operation after depositing tokens.
139+ * @param sender The address that approved tokens and initiated the operation
140+ * @param data ABI-encoded function selector and parameters of the operation
141+ */
138142 function _executeOperation (address sender , bytes calldata data ) internal {
139143 // Extract the function selector (first 4 bytes)
140144 bytes4 selector = bytes4 (data[:4 ]);
141-
142145 // Validate operation-specific preconditions before execution
143146 if (selector == IexecPoco1.matchOrders.selector ) {
144147 _validateMatchOrders (sender, data);
145148 } else {
146- revert ( " unsupported-operation " );
149+ revert UnsupportedOperation (selector );
147150 }
148-
149151 // Execute the operation via delegatecall
150- // This preserves msg.sender context and allows the operation to access
151- // the diamond's storage and functions
152+ // This preserves `msg.sender` context and allows the operation to access
153+ // the diamond's storage and functions.
154+ // Note: here `msg.sender` is the RLC token contract.
152155 (bool success , bytes memory result ) = address (this ).delegatecall (data);
153-
156+ if (success) {
157+ return ;
158+ }
154159 // Handle failure and bubble up revert reason
155- if (! success) {
156- if (result.length > 0 ) {
157- // Decode and revert with the original error
158- assembly {
159- let returndata_size := mload (result)
160- revert (add (result, 32 ), returndata_size)
161- }
162- } else {
163- revert ("operation-failed " );
164- }
160+ if (result.length == 0 ) {
161+ revert OperationFailed ();
162+ }
163+ // Decode and revert with the original error
164+ assembly {
165+ let returndata_size := mload (result)
166+ revert (add (result, 32 ), returndata_size)
165167 }
166168 }
167169
168- /******************************************************************************
169- * Token Spender: Atomic Deposit+Match if used with RLC.approveAndCall *
170- *****************************************************************************/
171-
172170 /**
173171 * @dev Validates matchOrders preconditions
174172 * @param sender The user who deposited (must be the requester)
175- * @param data ABI-encoded matchOrders call with orders
173+ * @param data matchOrders calldata
176174 */
177175 function _validateMatchOrders (address sender , bytes calldata data ) internal pure {
178- // Decode only the request order to validate the requester
179- // Full decoding: (AppOrder, DatasetOrder, WorkerpoolOrder, RequestOrder)
180- // We only need to check requestorder.requester
176+ // Decode orders and check that the sender is the requester.
181177 (, , , IexecLibOrders_v5.RequestOrder memory requestorder ) = abi.decode (
182178 data[4 :],
183179 (
@@ -187,10 +183,8 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, IexecERC2
187183 IexecLibOrders_v5.RequestOrder
188184 )
189185 );
190- // Validate that sender is the requester
191- // This ensures the caller is authorized to create this deal
192186 if (requestorder.requester != sender) {
193- revert ( " caller-must-be-requester " );
187+ revert CallerIsNotTheRequester ( );
194188 }
195189 }
196190
0 commit comments