@@ -48,21 +48,22 @@ export interface ReserveData {
4848 lastUpdateTimestamp : number ;
4949}
5050
51- export function formatReserve (
52- request : FormatReserveRequest ,
53- ) : FormatReserveResponse {
51+ export function formatReserve ( {
52+ reserve,
53+ currentTimestamp,
54+ } : FormatReserveRequest ) : FormatReserveResponse {
5455 const calculateReserveDebtResult = calculateReserveDebt (
55- request . reserve ,
56- request . currentTimestamp ,
56+ reserve ,
57+ currentTimestamp ,
5758 ) ;
5859
5960 const totalLiquidity = calculateTotalLiquidity (
6061 calculateReserveDebtResult . totalDebt ,
61- request . reserve . availableLiquidity ,
62+ reserve . availableLiquidity ,
6263 ) ;
6364
6465 const normalizeWithReserve = ( n : BigNumberValue ) =>
65- normalize ( n , request . reserve . decimals ) ;
66+ normalize ( n , reserve . decimals ) ;
6667
6768 return {
6869 totalVariableDebt : normalizeWithReserve (
@@ -72,48 +73,37 @@ export function formatReserve(
7273 calculateReserveDebtResult . totalStableDebt ,
7374 ) ,
7475 totalLiquidity : normalizeWithReserve ( totalLiquidity ) ,
75- availableLiquidity : normalizeWithReserve (
76- request . reserve . availableLiquidity ,
77- ) ,
76+ availableLiquidity : normalizeWithReserve ( reserve . availableLiquidity ) ,
7877 utilizationRate : totalLiquidity . eq ( 0 )
7978 ? '0'
8079 : valueToBigNumber ( calculateReserveDebtResult . totalDebt )
8180 . dividedBy ( totalLiquidity )
8281 . toFixed ( ) ,
8382 totalDebt : normalizeWithReserve ( calculateReserveDebtResult . totalDebt ) ,
84- baseLTVasCollateral : normalize (
85- request . reserve . baseLTVasCollateral ,
86- LTV_PRECISION ,
87- ) ,
88- reserveFactor : normalize ( request . reserve . reserveFactor , LTV_PRECISION ) ,
89- variableBorrowRate : normalize (
90- request . reserve . variableBorrowRate ,
91- RAY_DECIMALS ,
92- ) ,
93- stableBorrowRate : normalize ( request . reserve . stableBorrowRate , RAY_DECIMALS ) ,
94- liquidityRate : normalize ( request . reserve . liquidityRate , RAY_DECIMALS ) ,
95- liquidityIndex : normalize ( request . reserve . liquidityIndex , RAY_DECIMALS ) ,
83+ baseLTVasCollateral : normalize ( reserve . baseLTVasCollateral , LTV_PRECISION ) ,
84+ reserveFactor : normalize ( reserve . reserveFactor , LTV_PRECISION ) ,
85+ variableBorrowRate : normalize ( reserve . variableBorrowRate , RAY_DECIMALS ) ,
86+ stableBorrowRate : normalize ( reserve . stableBorrowRate , RAY_DECIMALS ) ,
87+ liquidityRate : normalize ( reserve . liquidityRate , RAY_DECIMALS ) ,
88+ liquidityIndex : normalize ( reserve . liquidityIndex , RAY_DECIMALS ) ,
9689 reserveLiquidationThreshold : normalize (
97- request . reserve . reserveLiquidationThreshold ,
90+ reserve . reserveLiquidationThreshold ,
9891 4 ,
9992 ) ,
10093 // https://github.com/aave/protocol-v2/blob/baeb455fad42d3160d571bd8d3a795948b72dd85/contracts/protocol/lendingpool/LendingPoolConfigurator.sol#L284
10194 reserveLiquidationBonus : normalize (
102- valueToBigNumber ( request . reserve . reserveLiquidationBonus ) . minus (
95+ valueToBigNumber ( reserve . reserveLiquidationBonus ) . minus (
10396 10 ** LTV_PRECISION ,
10497 ) ,
10598 LTV_PRECISION ,
10699 ) ,
107100 totalScaledVariableDebt : normalizeWithReserve (
108- request . reserve . totalScaledVariableDebt ,
101+ reserve . totalScaledVariableDebt ,
109102 ) ,
110103 totalPrincipalStableDebt : normalizeWithReserve (
111- request . reserve . totalPrincipalStableDebt ,
112- ) ,
113- variableBorrowIndex : normalize (
114- request . reserve . variableBorrowIndex ,
115- RAY_DECIMALS ,
104+ reserve . totalPrincipalStableDebt ,
116105 ) ,
106+ variableBorrowIndex : normalize ( reserve . variableBorrowIndex , RAY_DECIMALS ) ,
117107 } ;
118108}
119109
0 commit comments