@@ -24,14 +24,14 @@ import {UIntMath} from "../utils/UIntMath.sol";
2424
2525/*
2626
27- ███╗ ██╗ ██████╗ ██████╗ ██╗ ███████╗
28- ████╗ ██║██╔═══██╗██╔══██╗██║ ██╔════╝
29- ██╔██╗ ██║██║ ██║██████╔╝██║ █████╗
30- ██║╚██╗██║██║ ██║██╔══██╗██║ ██╔══╝
31- ██║ ╚████║╚██████╔╝██████╔╝███████╗███████╗
32- ╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝
33-
34- ██████╗ ██████╗ ██╗ ██╗ █████╗ ██████╗
27+ ███╗ ██╗ ██████╗ ██████╗ ██╗ ███████╗
28+ ████╗ ██║██╔═══██╗██╔══██╗██║ ██╔════╝
29+ ██╔██╗ ██║██║ ██║██████╔╝██║ █████╗
30+ ██║╚██╗██║██║ ██║██╔══██╗██║ ██╔══╝
31+ ██║ ╚████║╚██████╔╝██████╔╝███████╗███████╗
32+ ╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝
33+
34+ ██████╗ ██████╗ ██╗ ██╗ █████╗ ██████╗
3535██╔══██╗██╔═══██╗██║ ██║ ██╔══██╗██╔══██╗
3636██║ ██║██║ ██║██║ ██║ ███████║██████╔╝
3737██║ ██║██║ ██║██║ ██║ ██╔══██║██╔══██╗
@@ -94,17 +94,17 @@ contract NobleDollar is HypERC20 {
9494 _getUSDNStorage ().index = IndexingMath.EXP_SCALED_ONE;
9595 }
9696
97- /// @dev Returns the current index used for yield calculations.
97+ /// @notice Returns the current index used for yield calculations.
9898 function index () public view returns (uint128 ) {
9999 return _getUSDNStorage ().index;
100100 }
101101
102- /// @dev Returns the amount of principal in existence.
102+ /// @notice Returns the amount of principal in existence.
103103 function totalPrincipal () public view returns (uint112 ) {
104104 return _getUSDNStorage ().totalPrincipal;
105105 }
106106
107- /// @dev Returns the amount of principal owned for a given account.
107+ /// @notice Returns the amount of principal owned for a given account.
108108 function principalOf (address account ) public view returns (uint112 ) {
109109 return _getUSDNStorage ().principal[account];
110110 }
@@ -134,23 +134,32 @@ contract NobleDollar is HypERC20 {
134134 return expectedBalance > currentBalance ? expectedBalance - currentBalance : 0 ;
135135 }
136136
137+ /// @notice Claims all available yield for the caller.
138+ function claim () public {
139+ claim (msg .sender );
140+ }
141+
137142 /**
138- * @notice Claims all available yield for the caller .
143+ * @notice Internal function to claim all available yield for a specified address .
139144 * @dev Calculates the claimable yield based on the difference between the expected balance
140145 * (principal * current index) and the actual token balance. Transfers the yield amount
141- * from the contract to the caller and emits a YieldClaimed event.
142- * @custom:throws NoClaimableYield if the caller has no yield available to claim.
146+ * from the contract to the specified address and emits a YieldClaimed event.
147+ * @param user The address to claim yield for.
148+ * @return The amount of yield claimed.
149+ * @custom:throws NoClaimableYield if the address has no yield available to claim.
143150 * @custom:emits YieldClaimed when yield is successfully claimed.
144151 */
145- function claim () public {
152+ function claim (address user ) internal returns ( uint256 ) {
146153 // Avoid DOS claiming by taking min of the contract's balance and user's yield.
147- uint256 amount = UIntMath.min256 (balanceOf (address (this )), yield (msg . sender ));
154+ uint256 amount = UIntMath.min256 (balanceOf (address (this )), yield (user ));
148155
149156 if (amount == 0 ) revert NoClaimableYield ();
150157
151- _update (address (this ), msg .sender , amount);
158+ _update (address (this ), user, amount);
159+
160+ emit YieldClaimed (user, amount);
152161
153- emit YieldClaimed ( msg . sender , amount) ;
162+ return amount;
154163 }
155164
156165 /**
0 commit comments