-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Builder #157
base: main
Are you sure you want to change the base?
Builder #157
Conversation
function invest(address asset, uint amount) external nonReentrant returns (uint48 amountUSD) { | ||
IPriceReader priceReader = IPriceReader(IPlatform(platform()).priceReader()); | ||
(uint price, bool trusted) = priceReader.getPrice(asset); | ||
if (!trusted) { | ||
revert NotTrustedPriceFor(asset); | ||
} | ||
amountUSD = uint48(amount * price / 10 ** IERC20Metadata(asset).decimals() * USD_DENOMINATOR / 1e18); | ||
if (amountUSD == 0) { | ||
revert ZeroAmountToInvest(); | ||
} | ||
|
||
BuilderStorage storage $ = _getStorage(); | ||
uint tokenId = $.ownedToken[msg.sender]; | ||
|
||
if (tokenId == 0) { | ||
if (amountUSD < MIN_AMOUNT_FOR_MINTING) { | ||
revert TooLittleAmountToInvest(amountUSD, MIN_AMOUNT_FOR_MINTING); | ||
} | ||
tokenId = $.newTokenId; | ||
$.newTokenId = tokenId + 1; | ||
$.ownedToken[msg.sender] = tokenId; | ||
_mint(msg.sender, tokenId); | ||
} else { | ||
if (amountUSD < MIN_AMOUNT_FOR_ADDING) { | ||
revert TooLittleAmountToInvest(amountUSD, MIN_AMOUNT_FOR_ADDING); | ||
} | ||
} | ||
|
||
TokenData storage tokenData = $.tokenData[tokenId]; | ||
tokenData.invested += amountUSD; | ||
|
||
IERC20(asset).safeTransferFrom(msg.sender, address(this), amount); | ||
|
||
emit Invested(msg.sender, tokenId, asset, amount, amountUSD); | ||
} |
Check warning
Code scanning / Slither
Divide before multiply Medium
- amountUSD = uint48(amount * price / 10 ** IERC20Metadata(asset).decimals() * USD_DENOMINATOR / 1e18)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #157 +/- ##
==========================================
+ Coverage 94.76% 98.00% +3.24%
==========================================
Files 60 61 +1
Lines 4428 4456 +28
Branches 477 481 +4
==========================================
+ Hits 4196 4367 +171
- Misses 77 82 +5
+ Partials 155 7 -148 ☔ View full report in Codecov by Sentry. |
No description provided.