@@ -165,7 +165,7 @@ contract GrinderAI is IGrinderAI {
165165 /// @notice transmit grAI from `from` to `to`
166166 /// @param to address of `to`
167167 /// @param amount amount of grAI to burn
168- function _transmit (address from , address to , uint256 amount ) internal returns (uint256 transmited ) {
168+ function _transmitGRAI (address from , address to , uint256 amount ) internal returns (uint256 transmited ) {
169169 if (amount > 0 ) {
170170 transmited = grAI.transmit (from, to, amount);
171171 }
@@ -175,6 +175,12 @@ contract GrinderAI is IGrinderAI {
175175
176176 //// GRINDING FUNCTIONS ////////////////////////////////////////////////////////////////
177177
178+ /// @notice airdrops grETH to pool participants
179+ function _airdropGRETH (uint256 poolId ) internal {
180+ uint256 grethAmount = ratePerGRAI[address (0 )];
181+ poolsNFT.airdrop (poolId, grethAmount);
182+ }
183+
178184 /// @notice grind
179185 /// @dev first make macromanagement, second micromamagement
180186 /// @param poolId id of pool
@@ -190,23 +196,24 @@ contract GrinderAI is IGrinderAI {
190196 grinder = metaGrinder;
191197 address ownerOf = poolsNFT.ownerOf (poolId);
192198 IAgent agent = IAgent (poolsNFT.agentOf (poolId));
193- uint256 transmited = _transmit (ownerOf, grinder, oneGRAI);
194199 try agent.macroOps (poolId) returns (bool _success ) {
195200 if (_success) {
196- poolsNFT.airdropGRETH (poolId);
201+ _transmitGRAI (ownerOf, grinder, oneGRAI);
202+ _airdropGRETH (poolId);
197203 }
198204 return _success;
199205 } catch {
200206 // go on
201207 }
202208 try poolsNFT.microOps (poolId) returns (bool _success ) {
209+ if (_success) {
210+ _transmitGRAI (ownerOf, grinder, oneGRAI);
211+ _airdropGRETH (poolId);
212+ }
203213 success = _success;
204214 } catch {
205215 success = false ;
206216 }
207- if (! success) {
208- _transmit (grinder, ownerOf, transmited);
209- }
210217 grinder = payable (address (0 ));
211218 }
212219
@@ -232,24 +239,27 @@ contract GrinderAI is IGrinderAI {
232239 }
233240 }
234241
235- /// @notice grind operation on behalf of `msg.sender`
242+ /// @notice grind operation on behalf of `msg.sender`
236243 /// @param poolId id of pool
237- /// @param op operation on IURUS.Op enumeration; 0 - buy, 1 - sell, 2 - hedge_sell, 3 - hedge_rebuy, 4 - branch , 5 unbranch
244+ /// @param op operation on IURUS.Op enumeration; 0 - buy, 1 - sell, 2 - hedge_sell, 3 - hedge_rebuy; 4 , 5,... agent related
238245 function grindOp (uint256 poolId , uint8 op ) public override returns (bool ) {
239246 return grindOpTo (poolId, op, payable (msg .sender ));
240247 }
241248
242249 /// @notice grind operation
243250 /// @dev can be called by anyone, especially by grinder EOA
244251 /// @param poolId id of pool
245- /// @param op operation on IURUS.Op enumeration; 0 - buy, 1 - sell, 2 - hedge_sell, 3 - hedge_rebuy, 4 - branch , 5 unbranch
252+ /// @param op operation on IURUS.Op enumeration; 0 - buy, 1 - sell, 2 - hedge_sell, 3 - hedge_rebuy; 4 , 5,... agent related
246253 /// @param metaGrinder address of grinder
247254 function grindOpTo (uint256 poolId , uint8 op , address payable metaGrinder ) public override returns (bool success ) {
248255 grinder = metaGrinder;
249256 address ownerOf = poolsNFT.ownerOf (poolId);
250- uint256 transmited = _transmit (ownerOf, grinder, oneGRAI);
251257 if (op <= uint8 (IURUS.Op.HEDGE_REBUY)) {
252258 try poolsNFT.microOp (poolId, op) returns (bool _success ) {
259+ if (_success) {
260+ _transmitGRAI (ownerOf, grinder, oneGRAI);
261+ _airdropGRETH (poolId);
262+ }
253263 success = _success;
254264 } catch {
255265 success = false ;
@@ -258,16 +268,14 @@ contract GrinderAI is IGrinderAI {
258268 IAgent agent = IAgent (poolsNFT.agentOf (poolId));
259269 try agent.macroOp (poolId, op) returns (bool _success ) {
260270 if (_success) {
261- poolsNFT.airdropGRETH (poolId);
271+ _transmitGRAI (ownerOf, grinder, oneGRAI);
272+ _airdropGRETH (poolId);
262273 }
263274 success = _success;
264275 } catch {
265276 success = false ;
266277 }
267278 }
268- if (! success) {
269- _transmit (grinder, ownerOf, transmited);
270- }
271279 grinder = payable (address (0 ));
272280 }
273281
@@ -311,13 +319,13 @@ contract GrinderAI is IGrinderAI {
311319 function microOpTo (uint256 poolId , uint8 op , address payable metaGrinder ) public override returns (bool success ) {
312320 grinder = metaGrinder;
313321 address ownerOf = poolsNFT.ownerOf (poolId);
314- uint256 transmited = _transmit (ownerOf, grinder, oneGRAI);
315322 if (op > uint8 (IURUS.Op.HEDGE_REBUY)) {
316323 revert NotMicroOp ();
317324 }
318325 success = poolsNFT.microOp (poolId, op);
319- if (! success) {
320- _transmit (grinder, ownerOf, transmited);
326+ if (success) {
327+ _transmitGRAI (ownerOf, grinder, oneGRAI);
328+ _airdropGRETH (poolId);
321329 }
322330 grinder = payable (address (0 ));
323331 }
@@ -334,16 +342,13 @@ contract GrinderAI is IGrinderAI {
334342 grinder = metaGrinder;
335343 address ownerOf = poolsNFT.ownerOf (poolId);
336344 IAgent agent = IAgent (poolsNFT.agentOf (poolId));
337- uint256 transmited = _transmit (ownerOf, grinder, oneGRAI);
338345 if (op <= uint8 (IURUS.Op.HEDGE_REBUY)) {
339346 revert NotMacroOp ();
340347 }
341348 success = agent.macroOp (poolId, op);
342- if (success) {
343- poolsNFT.airdropGRETH (poolId);
344- }
345- if (! success) {
346- _transmit (grinder, ownerOf, transmited);
349+ if (success) {
350+ _transmitGRAI (ownerOf, grinder, oneGRAI);
351+ _airdropGRETH (poolId);
347352 }
348353 grinder = payable (address (0 ));
349354 }
0 commit comments