Skip to content

Commit 99a5c4f

Browse files
authored
Merge pull request #332 from fei-protocol/feat/fix-cr
CR Oracle fix
2 parents 5304abc + d47c8ba commit 99a5c4f

File tree

16 files changed

+1537
-8
lines changed

16 files changed

+1537
-8
lines changed

contract-addresses/mainnetAddresses.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,52 @@
11
const MainnetAddresses = {
2+
chainlinkLUSDOracle: {
3+
artifactName: 'ChainlinkOracleWrapper',
4+
address: '0xe61d11ec732d556A26fb863B192052BEa03eF8B5'
5+
},
6+
chainlinkCREAMEthOracle: {
7+
artifactName: 'ChainlinkOracleWrapper',
8+
address: '0xDE02522cDc4959117fe839a7326D80F9858f383C'
9+
},
10+
chainlinkBALEthOracle: {
11+
artifactName: 'ChainlinkOracleWrapper',
12+
address: '0x7261D245454Daa070C77B2a26eA192E3a4c8F655'
13+
},
14+
balUsdCompositeOracle: {
15+
artifactName: 'CompositeOracle',
16+
address: '0xDe0407851AEC6F073A63D27C7D29805CCD59D3e0'
17+
},
18+
creamUsdCompositeOracle: {
19+
artifactName: 'CompositeOracle',
20+
address: '0x2BDca027c7f57eD9AC1769Ba3a3D64600578bA49'
21+
},
22+
feiLusdLens: {
23+
artifactName: 'BPTLens',
24+
address: '0x1F05b337cB16CeA2a1C638Ba9b9571F0Cf4a5612'
25+
},
26+
aaveFeiPCVDepositWrapper: {
27+
artifactName: 'PCVDepositWrapper',
28+
address: '0xFAc571b6054619053ac311dA8112939C9a374A85'
29+
},
30+
creamDepositWrapper: {
31+
artifactName: 'ERC20PCVDepositWrapper',
32+
address: '0x3a1838Ac9EcA864054bebB82C32455Dd7d7Fc89c'
33+
},
34+
balDepositWrapper: {
35+
artifactName: 'ERC20PCVDepositWrapper',
36+
address: '0x7E28BA7a2D52Af88242E588d868E927119BA45dB'
37+
},
38+
staticPcvDepositWrapper2: {
39+
artifactName: 'StaticPCVDepositWrapper',
40+
address: '0xe72EB93de743F819fe91277582d7d0Fa9bb9b023'
41+
},
42+
feiBuybackLens: {
43+
artifactName: 'BPTLens',
44+
address: '0x107460564896377BA6CdcC7516c7eAb65E32E360'
45+
},
46+
cream: {
47+
artifactName: 'IERC20',
48+
address: '0x2ba592F78dB6436527729929AAf6c908497cB200'
49+
},
250
collateralizationOracleKeeper: {
351
artifactName: 'CollateralizationOracleKeeper',
452
address: '0x62378C316a6161A613D02E11F65290aED79B3eD5'
@@ -377,6 +425,10 @@ const MainnetAddresses = {
377425
artifactName: 'ERC20CompoundPCVDeposit',
378426
address: '0x74B235Fef146cDB5BE0D3786a9f3774674b3615E'
379427
},
428+
rariPool7LusdPCVDeposit: {
429+
artifactName: 'ERC20CompoundPCVDeposit',
430+
address: '0x6026a1559CDd44a63C5CA9A078CC996a9eb68ABB'
431+
},
380432
rariPool72FeiPCVDeposit: {
381433
artifactName: 'ERC20CompoundPCVDeposit',
382434
address: '0x4A5Af5A124E672C156241b76CAd4E41D09dd4883'
@@ -416,6 +468,10 @@ const MainnetAddresses = {
416468
artifactName: 'ERC20CompoundPCVDeposit',
417469
address: '0x9aAdFfe00eAe6d8e59bB4F7787C6b99388A6960D'
418470
},
471+
rariPool90FeiPCVDeposit: {
472+
artifactName: 'ERC20CompoundPCVDeposit',
473+
address: '0x61d26126D2F8A44b41c1D8E1B1F276551DC8EEc6'
474+
},
419475
rariPool91FeiPCVDeposit: {
420476
artifactName: 'ERC20CompoundPCVDeposit',
421477
address: '0x2296a2417D1f02d394ab22aF794a0f426eD53436'

contracts/Constants.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ library Constants {
1414

1515
/// @notice USD stand-in address
1616
address public constant USD = 0x1111111111111111111111111111111111111111;
17+
18+
/// @notice Wei per ETH, i.e. 10**18
19+
uint256 public constant ETH_GRANULARITY = 1e18;
20+
21+
/// @notice number of decimals in ETH, 18
22+
uint256 public constant ETH_DECIMALS = 18;
23+
1724
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//SPDX-License-Identifier: Unlicense
2+
pragma solidity ^0.8.4;
3+
4+
import "./abdk/ABDKMath64x64.sol";
5+
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
6+
7+
/**
8+
* @notice This contract contains math related utilities that allows to
9+
* compute fixed-point exponentiation or perform scaled arithmetic operations
10+
*/
11+
library ExtendedMath {
12+
using ABDKMath64x64 for int128;
13+
using ABDKMath64x64 for uint256;
14+
using SafeMath for uint256;
15+
16+
uint256 constant decimals = 18;
17+
uint256 constant decimalScale = 10**decimals;
18+
19+
/**
20+
* @notice Computes x**y where both `x` and `y` are fixed-point numbers
21+
*/
22+
function powf(int128 _x, int128 _y) internal pure returns (int128 _xExpy) {
23+
// 2^(y * log2(x))
24+
return _y.mul(_x.log_2()).exp_2();
25+
}
26+
27+
/**
28+
* @notice Computes `value * base ** exponent` where all of the parameters
29+
* are fixed point numbers scaled with `decimal`
30+
*/
31+
function mulPow(
32+
uint256 value,
33+
uint256 base,
34+
uint256 exponent,
35+
uint256 decimal
36+
) internal pure returns (uint256) {
37+
int128 basef = base.fromScaled(decimal);
38+
int128 expf = exponent.fromScaled(decimal);
39+
40+
return powf(basef, expf).mulu(value);
41+
}
42+
43+
/**
44+
* @notice Multiplies `a` and `b` scaling the result down by `_decimals`
45+
* `scaledMul(a, b, 18)` with an initial scale of 18 decimals for `a` and `b`
46+
* would keep the result to 18 decimals
47+
* The result of the computation is floored
48+
*/
49+
function scaledMul(
50+
uint256 a,
51+
uint256 b,
52+
uint256 _decimals
53+
) internal pure returns (uint256) {
54+
return a.mul(b).div(10**_decimals);
55+
}
56+
57+
function scaledMul(uint256 a, uint256 b) internal pure returns (uint256) {
58+
return scaledMul(a, b, decimals);
59+
}
60+
61+
/**
62+
* @notice Divides `a` and `b` scaling the result up by `_decimals`
63+
* `scaledDiv(a, b, 18)` with an initial scale of 18 decimals for `a` and `b`
64+
* would keep the result to 18 decimals
65+
* The result of the computation is floored
66+
*/
67+
function scaledDiv(
68+
uint256 a,
69+
uint256 b,
70+
uint256 _decimals
71+
) internal pure returns (uint256) {
72+
return a.mul(10**_decimals).div(b);
73+
}
74+
75+
/**
76+
* @notice See `scaledDiv(uint256 a, uint256 b, uint256 _decimals)`
77+
*/
78+
function scaledDiv(uint256 a, uint256 b) internal pure returns (uint256) {
79+
return scaledDiv(a, b, decimals);
80+
}
81+
82+
/**
83+
* @notice Computes a**b where a is a scaled fixed-point number and b is an integer
84+
* This keeps a scale of `_decimals` for `a`
85+
* The computation is performed in O(log n)
86+
*/
87+
function scaledPow(
88+
uint256 base,
89+
uint256 exp,
90+
uint256 _decimals
91+
) internal pure returns (uint256) {
92+
uint256 result = 10**_decimals;
93+
94+
while (exp > 0) {
95+
if (exp % 2 == 1) {
96+
result = scaledMul(result, base, _decimals);
97+
}
98+
exp /= 2;
99+
base = scaledMul(base, base, _decimals);
100+
}
101+
return result;
102+
}
103+
104+
/**
105+
* @notice See `scaledPow(uint256 base, uint256 exp, uint256 _decimals)`
106+
*/
107+
function scaledPow(uint256 base, uint256 exp) internal pure returns (uint256) {
108+
return scaledPow(base, exp, decimals);
109+
}
110+
}

0 commit comments

Comments
 (0)