Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Commit 17413eb

Browse files
committed
moved the calculation of grethAmount to grinderAI
1 parent d127a94 commit 17413eb

5 files changed

Lines changed: 54 additions & 66 deletions

File tree

src/GRETH.sol

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,34 +80,34 @@ contract GRETH is IGRETH, ERC20 {
8080
}
8181
}
8282

83-
/// @notice mint GRETH to actors.
83+
/// @notice mint GRETH to receivers.
8484
/// @dev callable only by `poolsNFT`
85-
/// @param actors array of actors
85+
/// @param receivers array of receivers
8686
/// @param amounts array of amounts that should be minted to amounts
87-
function mint(
88-
address[] memory actors,
87+
function multimint(
88+
address[] memory receivers,
8989
uint256[] memory amounts
9090
) public returns (uint256 totalShares) {
9191
_onlyPoolsNFT();
92-
if (actors.length != amounts.length) {
92+
if (receivers.length != amounts.length) {
9393
return 0;
9494
}
9595
address _owner = owner();
96-
uint256 len = actors.length;
96+
uint256 len = receivers.length;
9797
for (uint256 i; i < len; ) {
9898
if (amounts[i] > 0) {
99-
if (actors[i] == _owner) {
99+
if (receivers[i] == _owner) {
100100
_mint(address(this), amounts[i]);
101101
} else {
102-
_mint(actors[i], amounts[i]);
102+
_mint(receivers[i], amounts[i]);
103103
}
104-
totalGrindedBy[actors[i]] += amounts[i];
104+
totalGrindedBy[receivers[i]] += amounts[i];
105105
totalGrinded += amounts[i];
106106
totalShares += amounts[i];
107107
}
108108
unchecked { ++i; }
109109
}
110-
emit Mint(actors, amounts, totalShares);
110+
emit Mint(receivers, amounts, totalShares);
111111
}
112112

113113
/// @notice burns grETH and get weth

src/GrinderAI.sol

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/PoolsNFT.sol

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -442,16 +442,13 @@ contract PoolsNFT is IPoolsNFT, ERC721Enumerable {
442442
/// @notice grind the pool with `poolId`
443443
/// @dev grETH == fee spend on iterate
444444
/// @param poolId pool id of pool in array `pools`
445-
function microOps(uint256 poolId) external override returns (bool isGrinded) {
445+
function microOps(uint256 poolId) external override returns (bool success) {
446446
IStrategy pool = IStrategy(pools[poolId]);
447447
_checkCapital(pool);
448-
try pool.microOps() returns (bool iterated) {
449-
isGrinded = iterated;
448+
try pool.microOps() returns (bool _success) {
449+
success = _success;
450450
} catch {
451-
isGrinded = false;
452-
}
453-
if (isGrinded) {
454-
_airdropGRETH(poolId);
451+
success = false;
455452
}
456453
}
457454

@@ -472,31 +469,19 @@ contract PoolsNFT is IPoolsNFT, ERC721Enumerable {
472469
} else {
473470
revert NotMicroOp();
474471
}
475-
_airdropGRETH(poolId);
476472
return true;
477473
}
478474

479475
/// @notice airdrop greth
480476
/// @dev for executing agent related operations
481477
/// @param poolId pool id of pool in array `pools`
482-
function airdropGRETH(uint256 poolId) public override {
478+
function airdrop(uint256 poolId, uint256 grethAmount) public override {
483479
_onlyGrinderAI();
484-
_airdropGRETH(poolId);
485-
}
486-
487-
/// @notice airdrop for executing micro op
488-
function _airdropGRETH(uint256 poolId) internal {
489-
uint256 grethAmount;
490-
try grinderAI.ratePerGRAI(address(0)) returns (uint256 _rate) {
491-
grethAmount = _rate;
492-
} catch {
493-
grethAmount = 0.0001 ether;
494-
}
495-
(address[] memory actors, uint256[] memory _grethShares) = calcGRETHShares(
480+
(address[] memory receivers, uint256[] memory grethAmountShares) = calcGRETHShares(
496481
poolId,
497482
grethAmount
498483
);
499-
try grETH.mint(actors, _grethShares) {} catch {}
484+
try grETH.multimint(receivers, grethAmountShares) {} catch {}
500485
}
501486

502487
/// @notice transfert poolId from `msg.sender` to `to`
@@ -615,10 +600,10 @@ contract PoolsNFT is IPoolsNFT, ERC721Enumerable {
615600
function calcGRETHShares(
616601
uint256 poolId,
617602
uint256 grethAmount
618-
) public view override returns (address[] memory receivers, uint256[] memory _grethShares)
603+
) public view override returns (address[] memory receivers, uint256[] memory grethAmountShares)
619604
{
620605
receivers = new address[](4);
621-
_grethShares = new uint256[](4);
606+
grethAmountShares = new uint256[](4);
622607
receivers[0] = ownerOf(poolId); // poolOwner
623608
receivers[1] = getRoyaltyReceiver(poolId); // royalty receiver
624609
receivers[2] = address(grETH) != address(0) ? address(grETH) : owner; // grETH
@@ -627,10 +612,10 @@ contract PoolsNFT is IPoolsNFT, ERC721Enumerable {
627612
} catch {
628613
receivers[3] = owner;
629614
}
630-
_grethShares[0] = (grethAmount * grethShares.poolOwnerShare) / DENOMINATOR;
631-
_grethShares[1] = (grethAmount * grethShares.poolBuyerShare) / DENOMINATOR;
632-
_grethShares[2] = (grethAmount * grethShares.reserveShare) / DENOMINATOR;
633-
_grethShares[3] = grethAmount - (_grethShares[0] + _grethShares[1] + _grethShares[2]);
615+
grethAmountShares[0] = (grethAmount * grethShares.poolOwnerShare) / DENOMINATOR;
616+
grethAmountShares[1] = (grethAmount * grethShares.poolBuyerShare) / DENOMINATOR;
617+
grethAmountShares[2] = (grethAmount * grethShares.reserveShare) / DENOMINATOR;
618+
grethAmountShares[3] = grethAmount - (grethAmountShares[0] + grethAmountShares[1] + grethAmountShares[2]);
634619
}
635620

636621
/// @notice calculates royalty shares

src/interfaces/IGRETH.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface IGRETH is IToken {
3232

3333
function mintTo(address receiver) external payable returns (uint256 mintedAmount);
3434

35-
function mint(
35+
function multimint(
3636
address[] memory actors,
3737
uint256[] memory shares
3838
) external returns (uint256 totalShares);

src/interfaces/IPoolsNFT.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ interface IPoolsNFT is IERC721, IERC2981 {
182182

183183
function microOp(uint256 poolId, uint8 op) external returns (bool isGrinded);
184184

185-
function airdropGRETH(uint256 poolId) external;
185+
function airdrop(uint256 poolId, uint256 grethAmount) external;
186186

187187
function buyRoyalty(
188188
uint256 poolId
@@ -231,9 +231,7 @@ interface IPoolsNFT is IERC721, IERC2981 {
231231

232232
function getZeroConfig() external view returns (IURUS.Config memory);
233233

234-
function getRoyaltyReceiver(
235-
uint256 poolId
236-
) external view returns (address receiver);
234+
function getRoyaltyReceiver(uint256 poolId) external view returns (address receiver);
237235

238236
function isAgentOf(uint256 poolId, address account) external view returns (bool);
239237

0 commit comments

Comments
 (0)