/
StaderLibrary.sol
49 lines (43 loc) · 1.45 KB
/
StaderLibrary.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import { IStaderStakePoolsManager, IStaderOracle } from "src/interfaces/ProviderInterfaces.sol";
import { WadRayMath } from "src/libraries/math/WadRayMath.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
library StaderLibrary {
using WadRayMath for uint256;
using Math for uint256;
function getEthAmountInForLstAmountOut(
IStaderStakePoolsManager staderDeposit,
uint256 lstAmount
)
internal
view
returns (uint256)
{
uint256 supply = IStaderOracle(staderDeposit.staderConfig().getStaderOracle()).getExchangeRate().totalETHXSupply;
return lstAmount.mulDiv(staderDeposit.totalAssets(), supply, Math.Rounding.Ceil);
}
function getLstAmountOutForEthAmountIn(
IStaderStakePoolsManager staderDeposit,
uint256 ethAmount
)
internal
view
returns (uint256)
{
return staderDeposit.previewDeposit(ethAmount);
}
function depositForLst(IStaderStakePoolsManager staderDeposit, uint256 ethAmount) internal returns (uint256) {
return staderDeposit.deposit{ value: ethAmount }(address(this));
}
function depositForLst(
IStaderStakePoolsManager staderDeposit,
uint256 ethAmount,
address receiver
)
internal
returns (uint256)
{
return staderDeposit.deposit{ value: ethAmount }(receiver);
}
}