Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.

Commit 38b4941

Browse files
authored
refactor: remove remaining request (#52)
1 parent 88ca910 commit 38b4941

File tree

10 files changed

+108
-105
lines changed

10 files changed

+108
-105
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"order": "asc"
3737
}
3838
}
39-
]
39+
],
40+
"capitalized-comments": "off"
4041
},
4142
"overrides": [
4243
{

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
!contains(github.head_ref, 'dependabot') &&
5555
github.ref != 'refs/heads/master'
5656
run: |
57-
yarn release:canary --yes --no-verify-access
57+
yarn release:canary --yes --no-verify-access --dist-tag ${{ github.sha }}
5858
#- uses: actions/github-script@v4
5959
# if: |
6060
# github.event.pull_request.head.repo.full_name == github.repository &&

packages/math-utils/src/formatters/user/calculate-reward.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,42 @@ export interface CalculateRewardRequest {
1515
emissionEndTimestamp: number;
1616
}
1717

18-
export function calculateReward(request: CalculateRewardRequest): string {
18+
export function calculateReward({
19+
principalUserBalance,
20+
reserveIndex,
21+
userIndex,
22+
precision,
23+
rewardTokenDecimals,
24+
reserveIndexTimestamp,
25+
emissionPerSecond,
26+
totalSupply,
27+
currentTimestamp,
28+
emissionEndTimestamp,
29+
}: CalculateRewardRequest): string {
1930
const actualCurrentTimestamp =
20-
request.currentTimestamp > request.emissionEndTimestamp
21-
? request.emissionEndTimestamp
22-
: request.currentTimestamp;
31+
currentTimestamp > emissionEndTimestamp
32+
? emissionEndTimestamp
33+
: currentTimestamp;
2334

24-
const timeDelta = actualCurrentTimestamp - request.reserveIndexTimestamp;
35+
const timeDelta = actualCurrentTimestamp - reserveIndexTimestamp;
2536

2637
let currentReserveIndex;
2738
if (
28-
request.reserveIndexTimestamp === Number(request.currentTimestamp) ||
29-
request.reserveIndexTimestamp >= request.emissionEndTimestamp
39+
reserveIndexTimestamp === Number(currentTimestamp) ||
40+
reserveIndexTimestamp >= emissionEndTimestamp
3041
) {
31-
currentReserveIndex = valueToZDBigNumber(request.reserveIndex);
42+
currentReserveIndex = valueToZDBigNumber(reserveIndex);
3243
} else {
33-
currentReserveIndex = valueToZDBigNumber(request.emissionPerSecond)
44+
currentReserveIndex = valueToZDBigNumber(emissionPerSecond)
3445
.multipliedBy(timeDelta)
35-
.shiftedBy(request.precision)
36-
.dividedBy(request.totalSupply)
37-
.plus(request.reserveIndex);
46+
.shiftedBy(precision)
47+
.dividedBy(totalSupply)
48+
.plus(reserveIndex);
3849
}
3950

40-
const reward = valueToZDBigNumber(request.principalUserBalance)
41-
.multipliedBy(currentReserveIndex.minus(request.userIndex))
42-
.shiftedBy(request.precision * -1);
51+
const reward = valueToZDBigNumber(principalUserBalance)
52+
.multipliedBy(currentReserveIndex.minus(userIndex))
53+
.shiftedBy(precision * -1);
4354

44-
return normalize(reward, request.rewardTokenDecimals);
55+
return normalize(reward, rewardTokenDecimals);
4556
}

packages/math-utils/src/formatters/user/calculate-supplies.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ interface ReserveSupplyData {
2424
lastUpdateTimestamp: number;
2525
}
2626

27-
export function calculateSupplies(request: SuppliesRequest): SuppliesResponse {
27+
export function calculateSupplies({
28+
reserve,
29+
currentTimestamp,
30+
}: SuppliesRequest): SuppliesResponse {
2831
const {
2932
totalVariableDebt,
3033
totalStableDebt,
3134
} = calculateReserveDebtSuppliesRaw({
32-
reserve: request.reserve,
33-
currentTimestamp: request.currentTimestamp,
35+
reserve: reserve,
36+
currentTimestamp: currentTimestamp,
3437
});
3538

3639
const totalDebt = totalVariableDebt.plus(totalStableDebt);
3740

38-
const totalLiquidity = totalDebt.plus(request.reserve.availableLiquidity);
41+
const totalLiquidity = totalDebt.plus(reserve.availableLiquidity);
3942
return {
4043
totalVariableDebt,
4144
totalStableDebt,
@@ -58,26 +61,24 @@ interface ReserveDebtSuppliesRawResponse {
5861
* @param reserve
5962
* @param currentTimestamp unix timestamp which must be higher than reserve.lastUpdateTimestamp
6063
*/
61-
function calculateReserveDebtSuppliesRaw(
62-
request: ReserveDebtSuppliesRawRequest,
63-
): ReserveDebtSuppliesRawResponse {
64+
function calculateReserveDebtSuppliesRaw({
65+
reserve,
66+
currentTimestamp,
67+
}: ReserveDebtSuppliesRawRequest): ReserveDebtSuppliesRawResponse {
6468
const totalVariableDebt = rayMul(
65-
rayMul(
66-
request.reserve.totalScaledVariableDebt,
67-
request.reserve.variableBorrowIndex,
68-
),
69+
rayMul(reserve.totalScaledVariableDebt, reserve.variableBorrowIndex),
6970
calculateCompoundedInterest({
70-
rate: request.reserve.variableBorrowRate,
71-
currentTimestamp: request.currentTimestamp,
72-
lastUpdateTimestamp: request.reserve.lastUpdateTimestamp,
71+
rate: reserve.variableBorrowRate,
72+
currentTimestamp,
73+
lastUpdateTimestamp: reserve.lastUpdateTimestamp,
7374
}),
7475
);
7576
const totalStableDebt = rayMul(
76-
request.reserve.totalPrincipalStableDebt,
77+
reserve.totalPrincipalStableDebt,
7778
calculateCompoundedInterest({
78-
rate: request.reserve.averageStableRate,
79-
currentTimestamp: request.currentTimestamp,
80-
lastUpdateTimestamp: request.reserve.stableDebtLastUpdateTimestamp,
79+
rate: reserve.averageStableRate,
80+
currentTimestamp,
81+
lastUpdateTimestamp: reserve.stableDebtLastUpdateTimestamp,
8182
}),
8283
);
8384
return { totalVariableDebt, totalStableDebt };

packages/math-utils/src/formatters/user/calculate-user-reserve-totals.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ interface UserReserveTotalsResponse {
1414
currentLiquidationThreshold: BigNumber;
1515
}
1616

17-
export function calculateUserReserveTotals(
18-
request: UserReserveTotalsRequest,
19-
): UserReserveTotalsResponse {
17+
export function calculateUserReserveTotals({
18+
userReserves,
19+
}: UserReserveTotalsRequest): UserReserveTotalsResponse {
2020
let totalLiquidityETH = valueToZDBigNumber('0');
2121
let totalCollateralETH = valueToZDBigNumber('0');
2222
let totalBorrowsETH = valueToZDBigNumber('0');
2323
let currentLtv = valueToBigNumber('0');
2424
let currentLiquidationThreshold = valueToBigNumber('0');
2525

26-
request.userReserves.forEach(userReserveSummary => {
26+
userReserves.forEach(userReserveSummary => {
2727
totalLiquidityETH = totalLiquidityETH.plus(
2828
userReserveSummary.underlyingBalanceETH,
2929
);

packages/math-utils/src/formatters/user/format-user-reserve.ts

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ export interface FormatUserReserveResponse {
1616
reserve: ComputedUserReserve;
1717
}
1818

19-
export function formatUserReserve(
20-
request: FormatUserReserveRequest,
21-
): ComputedUserReserve {
22-
const rawUserReserve = request.reserve;
23-
const userReserve = rawUserReserve.userReserve;
19+
export function formatUserReserve({
20+
reserve: _reserve,
21+
}: FormatUserReserveRequest): ComputedUserReserve {
22+
const userReserve = _reserve.userReserve;
2423
const reserve = userReserve.reserve;
2524
const reserveDecimals = reserve.decimals;
2625

@@ -45,35 +44,26 @@ export function formatUserReserve(
4544
userReserve.variableBorrowIndex,
4645
RAY_DECIMALS,
4746
),
48-
underlyingBalance: normalize(
49-
rawUserReserve.underlyingBalance,
50-
reserveDecimals,
51-
),
47+
underlyingBalance: normalize(_reserve.underlyingBalance, reserveDecimals),
5248
underlyingBalanceETH: normalize(
53-
rawUserReserve.underlyingBalanceETH,
49+
_reserve.underlyingBalanceETH,
5450
ETH_DECIMALS,
5551
),
5652
underlyingBalanceUSD: normalize(
57-
rawUserReserve.underlyingBalanceUSD,
58-
USD_DECIMALS,
59-
),
60-
stableBorrows: normalizeWithReserve(rawUserReserve.stableBorrows),
61-
stableBorrowsETH: normalize(rawUserReserve.stableBorrowsETH, ETH_DECIMALS),
62-
stableBorrowsUSD: normalize(rawUserReserve.stableBorrowsUSD, USD_DECIMALS),
63-
variableBorrows: normalizeWithReserve(rawUserReserve.variableBorrows),
64-
variableBorrowsETH: normalize(
65-
rawUserReserve.variableBorrowsETH,
66-
ETH_DECIMALS,
67-
),
68-
variableBorrowsUSD: normalize(
69-
rawUserReserve.variableBorrowsUSD,
53+
_reserve.underlyingBalanceUSD,
7054
USD_DECIMALS,
7155
),
72-
totalBorrows: normalizeWithReserve(rawUserReserve.totalBorrows),
73-
totalBorrowsETH: normalize(rawUserReserve.totalBorrowsETH, ETH_DECIMALS),
74-
totalBorrowsUSD: normalize(rawUserReserve.totalBorrowsUSD, USD_DECIMALS),
75-
totalLiquidity: normalizeWithReserve(rawUserReserve.totalLiquidity),
76-
totalStableDebt: normalizeWithReserve(rawUserReserve.totalStableDebt),
77-
totalVariableDebt: normalizeWithReserve(rawUserReserve.totalVariableDebt),
56+
stableBorrows: normalizeWithReserve(_reserve.stableBorrows),
57+
stableBorrowsETH: normalize(_reserve.stableBorrowsETH, ETH_DECIMALS),
58+
stableBorrowsUSD: normalize(_reserve.stableBorrowsUSD, USD_DECIMALS),
59+
variableBorrows: normalizeWithReserve(_reserve.variableBorrows),
60+
variableBorrowsETH: normalize(_reserve.variableBorrowsETH, ETH_DECIMALS),
61+
variableBorrowsUSD: normalize(_reserve.variableBorrowsUSD, USD_DECIMALS),
62+
totalBorrows: normalizeWithReserve(_reserve.totalBorrows),
63+
totalBorrowsETH: normalize(_reserve.totalBorrowsETH, ETH_DECIMALS),
64+
totalBorrowsUSD: normalize(_reserve.totalBorrowsUSD, USD_DECIMALS),
65+
totalLiquidity: normalizeWithReserve(_reserve.totalLiquidity),
66+
totalStableDebt: normalizeWithReserve(_reserve.totalStableDebt),
67+
totalVariableDebt: normalizeWithReserve(_reserve.totalVariableDebt),
7868
};
7969
}

packages/math-utils/src/formatters/user/generate-raw-user-summary.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ describe('generateRawUserSummary', () => {
4040
const rawSummary: RawUserSummaryResponse = generateRawUserSummary({
4141
userReserves: [rawUSDCSummary, rawXSUSHISummary, rawETHSummary],
4242
usdPriceEth,
43-
currentTimestamp,
4443
});
4544

4645
const rawUSDCSummaryModified: UserReserveSummaryResponse = generateUserReserveSummary(
@@ -66,15 +65,13 @@ describe('generateRawUserSummary', () => {
6665
{
6766
userReserves: [rawUSDCSummaryModified, rawXSUSHISummary, rawETHSummary],
6867
usdPriceEth,
69-
currentTimestamp,
7068
},
7169
);
7270

7371
const rawSummaryBorrowChange: RawUserSummaryResponse = generateRawUserSummary(
7472
{
7573
userReserves: [rawUSDCSummary, rawXSUSHISummary, rawETHSummaryModified],
7674
usdPriceEth,
77-
currentTimestamp,
7875
},
7976
);
8077

packages/math-utils/src/formatters/user/generate-raw-user-summary.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { UserReserveSummaryResponse } from './generate-user-reserve-summary';
1111
export interface RawUserSummaryRequest {
1212
userReserves: UserReserveSummaryResponse[];
1313
usdPriceEth: BigNumberValue;
14-
currentTimestamp: number;
1514
}
1615

1716
export interface RawUserSummaryResponse {
@@ -34,21 +33,22 @@ function convertToUsd(
3433
return value.shiftedBy(USD_DECIMALS).dividedBy(usdPriceEth);
3534
}
3635

37-
export function generateRawUserSummary(
38-
request: RawUserSummaryRequest,
39-
): RawUserSummaryResponse {
36+
export function generateRawUserSummary({
37+
userReserves,
38+
usdPriceEth,
39+
}: RawUserSummaryRequest): RawUserSummaryResponse {
4040
const {
4141
totalLiquidityETH,
4242
totalBorrowsETH,
4343
totalCollateralETH,
4444
currentLtv,
4545
currentLiquidationThreshold,
46-
} = calculateUserReserveTotals({ userReserves: request.userReserves });
46+
} = calculateUserReserveTotals({ userReserves: userReserves });
4747

4848
return {
49-
totalLiquidityUSD: convertToUsd(totalLiquidityETH, request.usdPriceEth),
50-
totalCollateralUSD: convertToUsd(totalCollateralETH, request.usdPriceEth),
51-
totalBorrowsUSD: convertToUsd(totalBorrowsETH, request.usdPriceEth),
49+
totalLiquidityUSD: convertToUsd(totalLiquidityETH, usdPriceEth),
50+
totalCollateralUSD: convertToUsd(totalCollateralETH, usdPriceEth),
51+
totalBorrowsUSD: convertToUsd(totalBorrowsETH, usdPriceEth),
5252
totalLiquidityETH,
5353
totalCollateralETH,
5454
totalBorrowsETH,

packages/math-utils/src/formatters/user/generate-user-reserve-summary.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@ export interface UserReserveSummaryResponse {
3434
totalVariableDebt: BigNumber;
3535
}
3636

37-
export function generateUserReserveSummary(
38-
request: UserReserveSummaryRequest,
39-
): UserReserveSummaryResponse {
40-
const poolReserve = request.userReserve.reserve;
37+
export function generateUserReserveSummary({
38+
userReserve,
39+
usdPriceEth,
40+
currentTimestamp,
41+
}: UserReserveSummaryRequest): UserReserveSummaryResponse {
42+
const poolReserve = userReserve.reserve;
4143
const {
4244
price: { priceInEth },
4345
decimals,
4446
} = poolReserve;
4547
const underlyingBalance = getLinearBalance({
46-
balance: request.userReserve.scaledATokenBalance,
48+
balance: userReserve.scaledATokenBalance,
4749
index: poolReserve.liquidityIndex,
4850
rate: poolReserve.liquidityRate,
4951
lastUpdateTimestamp: poolReserve.lastUpdateTimestamp,
50-
currentTimestamp: request.currentTimestamp,
52+
currentTimestamp,
5153
});
5254
const {
5355
ethBalance: underlyingBalanceETH,
@@ -56,15 +58,15 @@ export function generateUserReserveSummary(
5658
balance: underlyingBalance,
5759
priceInEth,
5860
decimals,
59-
usdPriceEth: request.usdPriceEth,
61+
usdPriceEth,
6062
});
6163

6264
const variableBorrows = getCompoundedBalance({
63-
principalBalance: request.userReserve.scaledVariableDebt,
65+
principalBalance: userReserve.scaledVariableDebt,
6466
reserveIndex: poolReserve.variableBorrowIndex,
6567
reserveRate: poolReserve.variableBorrowRate,
6668
lastUpdateTimestamp: poolReserve.lastUpdateTimestamp,
67-
currentTimestamp: request.currentTimestamp,
69+
currentTimestamp,
6870
});
6971

7072
const {
@@ -74,14 +76,14 @@ export function generateUserReserveSummary(
7476
balance: variableBorrows,
7577
priceInEth,
7678
decimals,
77-
usdPriceEth: request.usdPriceEth,
79+
usdPriceEth,
7880
});
7981

8082
const stableBorrows = getCompoundedStableBalance({
81-
principalBalance: request.userReserve.principalStableDebt,
82-
userStableRate: request.userReserve.stableBorrowRate,
83-
lastUpdateTimestamp: request.userReserve.stableBorrowLastUpdateTimestamp,
84-
currentTimestamp: request.currentTimestamp,
83+
principalBalance: userReserve.principalStableDebt,
84+
userStableRate: userReserve.stableBorrowRate,
85+
lastUpdateTimestamp: userReserve.stableBorrowLastUpdateTimestamp,
86+
currentTimestamp,
8587
});
8688

8789
const {
@@ -91,7 +93,7 @@ export function generateUserReserveSummary(
9193
balance: stableBorrows,
9294
priceInEth,
9395
decimals,
94-
usdPriceEth: request.usdPriceEth,
96+
usdPriceEth,
9597
});
9698

9799
const {
@@ -109,11 +111,11 @@ export function generateUserReserveSummary(
109111
stableDebtLastUpdateTimestamp: poolReserve.stableDebtLastUpdateTimestamp,
110112
lastUpdateTimestamp: poolReserve.lastUpdateTimestamp,
111113
},
112-
currentTimestamp: request.currentTimestamp,
114+
currentTimestamp,
113115
});
114116

115117
return {
116-
userReserve: request.userReserve,
118+
userReserve,
117119
underlyingBalance,
118120
underlyingBalanceETH,
119121
underlyingBalanceUSD,

0 commit comments

Comments
 (0)