-
Notifications
You must be signed in to change notification settings - Fork 9
/
SwellLibrary.sol
45 lines (40 loc) · 1.45 KB
/
SwellLibrary.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import { WadRayMath } from "../libraries/math/WadRayMath.sol";
import { ISwEth } from "../interfaces/ProviderInterfaces.sol";
/**
* @title SwellLibrary
*
* @notice A helper library for Swell-related conversions.
*
* @custom:security-contact security@molecularlabs.io
*/
library SwellLibrary {
using WadRayMath for uint256;
/**
* @notice Returns the amount of ETH needed to mint the given amount of swETH.
* @param swEth address.
* @param lstAmount Desired output amount. [WAD]
*/
function getEthAmountInForLstAmountOut(ISwEth swEth, uint256 lstAmount) internal view returns (uint256) {
return lstAmount.wadDivUp(swEth.ethToSwETHRate());
}
/**
*
* @param swEth address.
* @param ethAmount Amount of ETH to deposit. [WAD]
*/
function getLstAmountOutForEthAmountIn(ISwEth swEth, uint256 ethAmount) internal view returns (uint256) {
// lstToken and depositContract are same
return swEth.ethToSwETHRate().wadMulDown(ethAmount);
}
/**
* @notice Deposits ETH into the swETH contract and returns the amount of swETH received.
* @param swEth address.
* @param ethAmount Amount of ETH to deposit. [WAD]
*/
function depositForLst(ISwEth swEth, uint256 ethAmount) internal returns (uint256) {
swEth.deposit{ value: ethAmount }();
return getLstAmountOutForEthAmountIn(swEth, ethAmount);
}
}