-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathPriceLibV1.sol
More file actions
60 lines (50 loc) · 2.01 KB
/
PriceLibV1.sol
File metadata and controls
60 lines (50 loc) · 2.01 KB
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
50
51
52
53
54
55
56
57
58
59
60
// Neptune Mutual Protocol (https://neptunemutual.com)
// SPDX-License-Identifier: BUSL-1.1
/* solhint-disable ordering */
pragma solidity ^0.8.0;
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "../interfaces/IStore.sol";
import "../interfaces/IPriceOracle.sol";
import "../dependencies/uniswap-v2/IUniswapV2RouterLike.sol";
import "../dependencies/uniswap-v2/IUniswapV2PairLike.sol";
import "../dependencies/uniswap-v2/IUniswapV2FactoryLike.sol";
import "./ProtoUtilV1.sol";
library PriceLibV1 {
using ProtoUtilV1 for IStore;
using StoreKeyUtil for IStore;
function getPriceOracleInternal(IStore s) public view returns (IPriceOracle) {
return IPriceOracle(s.getNpmPriceOracleInternal());
}
function setNpmPrice(IStore s) internal {
IPriceOracle oracle = getPriceOracleInternal(s);
if (address(oracle) == address(0)) {
return;
}
oracle.update();
}
function convertNpmLpUnitsToStabelcoinInternal(IStore s, uint256 amountIn) external view returns (uint256) {
return getPriceOracleInternal(s).consultPair(amountIn);
}
function getLastUpdatedOnInternal(IStore s, bytes32 coverKey) external view returns (uint256) {
bytes32 key = getLastUpdateKeyInternal(coverKey);
return s.getUintByKey(key);
}
function setLastUpdatedOnInternal(IStore s, bytes32 coverKey) external {
bytes32 key = getLastUpdateKeyInternal(coverKey);
s.setUintByKey(key, block.timestamp); // solhint-disable-line
}
/**
* @dev Hash key of the "last state update" for the given cover.
*
* Warning: this function does not validate the cover key supplied.
*
* @param coverKey Enter cover key
*
*/
function getLastUpdateKeyInternal(bytes32 coverKey) public pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_LAST_LIQUIDITY_STATE_UPDATE, coverKey));
}
function getNpmPriceInternal(IStore s, uint256 amountIn) external view returns (uint256) {
return getPriceOracleInternal(s).consult(s.getNpmTokenAddressInternal(), amountIn);
}
}