Skip to content

Commit

Permalink
Added sharePrice view function
Browse files Browse the repository at this point in the history
  • Loading branch information
ggviana committed Nov 8, 2022
1 parent 61504ab commit 820fbfd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions abi/STETHVault.json
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "sharePrice",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "sharePriceDecimals",
Expand Down
8 changes: 8 additions & 0 deletions contracts/vaults/STETHVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ contract STETHVault is BaseVault {
sharePriceDecimals = _asset.decimals();
}

/**
* @notice Return the stETH price per share
* @dev Each share is considered to be 10^(assets.decimals())
*/
function sharePrice() external view returns (uint256) {
return totalAssets().mulDiv(10**sharePriceDecimals, totalSupply(), Math.Rounding.Down);
}

function _afterRoundStart() internal override {
uint256 supply = totalSupply();

Expand Down
3 changes: 2 additions & 1 deletion test/vaults/STETHVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe('STETHVault', () => {
})

describe('Events', () => {
it('endSharePrice should be consistent with the vault state', async () => {
it.only('endSharePrice should be consistent with the vault state', async () => {
// This test will only work if InvestRatio = 50%
const assetAmount = ethers.utils.parseEther('100')

Expand Down Expand Up @@ -334,6 +334,7 @@ describe('STETHVault', () => {
await asset.connect(yieldGenerator).transfer(investor.address, ethers.utils.parseEther('100'))
const endRoundTx2 = await vault.connect(vaultController).endRound()
await expect(endRoundTx2).to.emit(vault, 'SharePrice').withArgs('2', '1050000000000000000', '1614695121951219512')
expect(await vault.sharePrice()).to.be.equal('1614695121951219512')
})
})

Expand Down

0 comments on commit 820fbfd

Please sign in to comment.