Skip to content

Commit

Permalink
fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgo0018 committed Dec 16, 2023
1 parent b77b481 commit a78d0ee
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions contracts/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,14 @@ contract Vault {
) public view returns (uint256 share) {
uint256 totalValue = calculateTotalValue();
uint256 currentTotalSupply = shareToken.totalSupply();
if (totalValue == 0 || currentTotalSupply == 0) share = amount;
else share = (currentTotalSupply * amount) / totalValue;

if (totalValue == 0 || currentTotalSupply == 0) {
uint256 stableTokenUnit = 10 ** stableToken.decimals();
uint256 shareTokenUnit = 10 ** shareToken.decimals();
share = (amount * shareTokenUnit) / stableTokenUnit;
} else {
share = (currentTotalSupply * amount) / totalValue;
}
}

function calculateTotalValue() public view returns (uint256 total) {
Expand Down

0 comments on commit a78d0ee

Please sign in to comment.