Skip to content

Comments

feat: mint fee shares with pre-donation share price, perfect shares#1173

Closed
yan-man wants to merge 4 commits intodevfrom
feat/mint-feeAmount-safety
Closed

feat: mint fee shares with pre-donation share price, perfect shares#1173
yan-man wants to merge 4 commits intodevfrom
feat/mint-feeAmount-safety

Conversation

@yan-man
Copy link
Contributor

@yan-man yan-man commented Feb 3, 2026

  • calc fee shares at the beginning of an action, before user donation affects share price, then cache into transient storage
  • at the end of the action, mint the equivalent fee shares to feeReceiver
  • utilize as "perfect" of shares as possible, whatever remainder exists we keep in realizedFeesRay
  • use RAY precision to have a more precise remainder
  • this reduces the griefing vector, as rounded off donation is not thrown away but rather cached for next accrual action

asset.realizedFees += asset.getUnrealizedFees(drawnIndex).toUint120();
uint256 feeAmountRay = asset.realizedFeesRay + asset.getUnrealizedFees(drawnIndex).toRay();
uint256 feeShares = asset.toAddedSharesDown(feeAmountRay.fromRayDown());
uint256 perfectFeeAmountRay = feeShares == 0 ? 0 : asset.toAddedAssetsUp(feeShares.toRay());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: feeShares.toRay() first before converting to assets. Ex. if share price is 1.33333...., and feeShares is 1, then this will yield 1.33333 RAY. If we did toRay() after the conversion instead, it would only give us 2 RAY

also, round up so that the remaining realizedFeesRay is minimized

asset.realizedFeesRay = (feeAmountRay - perfectFeeAmountRay).toUint200();

FEE_SHARES_SLOT.tstore(0);
emit IHub.MintFeeShares(assetId, feeReceiver, feeShares, perfectFeeAmountRay.fromRayDown());
}
asset.realizedFeesRay = (feeAmountRay - perfectFeeAmountRay).toUint200();
Copy link
Contributor Author

@yan-man yan-man Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: whatever remainder exists beyond the perfect shares, cache for the next accrual

maybe needs to be capped bc perfectFeeAmountRay was rounded up, feeAmountRay <= perfectFeeAmountRay ? 0: feeAmountRay - perfectFeeAmountRay

@yan-man
Copy link
Contributor Author

yan-man commented Feb 3, 2026

see #1178

@yan-man yan-man closed this Feb 3, 2026
@yan-man yan-man deleted the feat/mint-feeAmount-safety branch February 10, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant