@gearbox-protocol/sdk 14.10.0 → 14.10.2-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common-utils/test-utils/index.js +139 -0
- package/dist/cjs/common-utils/utils/apy/calculate-borrow-rate-from-utilization.js +59 -0
- package/dist/cjs/common-utils/utils/apy/calculate-borrow-rate-from-utilization.spec.js +32 -0
- package/dist/cjs/common-utils/utils/apy/calculate-earnings.js +59 -0
- package/dist/cjs/common-utils/utils/apy/calculate-earnings.spec.js +62 -0
- package/dist/cjs/common-utils/utils/apy/calculate-safe-borrow-rate.js +55 -0
- package/dist/cjs/common-utils/utils/apy/calculate-safe-borrow-rate.spec.js +39 -0
- package/dist/cjs/common-utils/utils/apy/get-safe-base-borrow-rate.js +38 -0
- package/dist/cjs/common-utils/utils/constants.js +34 -0
- package/dist/cjs/common-utils/utils/strategies/assets/assets.js +30 -0
- package/dist/cjs/common-utils/utils/strategies/credit-managers/get-cm-allowed-collaterals.js +62 -0
- package/dist/cjs/common-utils/utils/strategies/credit-managers/get-cm-allowed-collaterals.spec.js +109 -0
- package/dist/cjs/common-utils/utils/strategies/credit-managers/get-wallet-balances-allowed-on-cm.js +75 -0
- package/dist/cjs/common-utils/utils/strategies/credit-managers/get-wallet-balances-allowed-on-cm.spec.js +93 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +63 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.spec.js +330 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/get-collateral-by-debt.js +34 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/get-collateral-by-debt.spec.js +30 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/get-recommended-debt.js +85 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/get-recommended-debt.spec.js +227 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/get-recommended-leverage-factor.js +33 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/get-recommended-leverage-factor.spec.js +23 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/max-leverage.js +2 -2
- package/dist/cjs/common-utils/utils/strategies/strategy-info/calculate-total-apy.js +112 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/calculate-total-apy.spec.js +183 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/calculate-total-points.js +74 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/calculate-total-points.spec.js +131 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +410 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.js +274 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-strategy-you-can-earn.js +108 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/add-amount-in-target.js +41 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/add-amount-in-target.spec.js +38 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/get-chain-phantom-tokens.js +35 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/get-list-with-amount-in-target.js +42 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/get-list-with-amount-in-target.spec.js +32 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/get-native-token-address.js +31 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/is-apy-with-points-exception.js +36 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/is-collateral-token.js +59 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/is-collateral-token.spec.js +135 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/is-obtainable-token.js +42 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/is-obtainable-token.spec.js +162 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/is-valid-extra-collateral-token.js +51 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/wrap-token-address.js +33 -0
- package/dist/cjs/common-utils/utils/strategies/tokens/wrap-token-address.spec.js +13 -0
- package/dist/cjs/common-utils/utils/strategies/types/strategy-data.js +16 -0
- package/dist/cjs/common-utils/utils/strategies/types/strategy-earnings.js +16 -0
- package/dist/cjs/common-utils/utils/validation/is-zero-balance.js +30 -0
- package/dist/cjs/common-utils/utils/validation/validate-balance.js +47 -0
- package/dist/cjs/common-utils/utils/validation/validate-balance.spec.js +52 -0
- package/dist/cjs/common-utils/utils/validation/validate-balances.js +44 -0
- package/dist/cjs/common-utils/utils/validation/validate-balances.spec.js +37 -0
- package/dist/cjs/common-utils/utils/validation/validate-credit-manager.js +34 -0
- package/dist/cjs/common-utils/utils/validation/validate-credit-manager.spec.js +36 -0
- package/dist/cjs/common-utils/utils/validation/validate-hf.js +38 -0
- package/dist/cjs/common-utils/utils/validation/validate-hf.spec.js +24 -0
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-quota-status.js +37 -0
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.js +43 -0
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.js +76 -0
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.spec.js +98 -0
- package/dist/cjs/common-utils/utils/validation/validate-open-account.js +41 -0
- package/dist/cjs/common-utils/utils/validation/validate-open-account.spec.js +54 -0
- package/dist/cjs/common-utils/utils/validation/validate-quota.js +49 -0
- package/dist/cjs/common-utils/utils/validation/validate-quota.spec.js +79 -0
- package/dist/cjs/common-utils/utils/validation/validate-token-to-obtain.js +42 -0
- package/dist/cjs/common-utils/utils/validation/validate-token-to-obtain.spec.js +35 -0
- package/dist/cjs/common-utils/utils/validation/validation-types.js +16 -0
- package/dist/cjs/dev/claimFromFaucet.js +17 -7
- package/dist/cjs/sdk/constants/math.js +3 -0
- package/dist/esm/common-utils/test-utils/index.js +104 -0
- package/dist/esm/common-utils/utils/apy/calculate-borrow-rate-from-utilization.js +35 -0
- package/dist/esm/common-utils/utils/apy/calculate-borrow-rate-from-utilization.spec.js +31 -0
- package/dist/esm/common-utils/utils/apy/calculate-earnings.js +35 -0
- package/dist/esm/common-utils/utils/apy/calculate-earnings.spec.js +65 -0
- package/dist/esm/common-utils/utils/apy/calculate-safe-borrow-rate.js +34 -0
- package/dist/esm/common-utils/utils/apy/calculate-safe-borrow-rate.spec.js +38 -0
- package/dist/esm/common-utils/utils/apy/get-safe-base-borrow-rate.js +16 -0
- package/dist/esm/common-utils/utils/constants.js +8 -0
- package/dist/esm/common-utils/utils/strategies/assets/assets.js +6 -0
- package/dist/esm/common-utils/utils/strategies/credit-managers/get-cm-allowed-collaterals.js +38 -0
- package/dist/esm/common-utils/utils/strategies/credit-managers/get-cm-allowed-collaterals.spec.js +115 -0
- package/dist/esm/common-utils/utils/strategies/credit-managers/get-wallet-balances-allowed-on-cm.js +51 -0
- package/dist/esm/common-utils/utils/strategies/credit-managers/get-wallet-balances-allowed-on-cm.spec.js +96 -0
- package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +42 -0
- package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.spec.js +332 -0
- package/dist/esm/common-utils/utils/strategies/leverage/get-collateral-by-debt.js +10 -0
- package/dist/esm/common-utils/utils/strategies/leverage/get-collateral-by-debt.spec.js +29 -0
- package/dist/esm/common-utils/utils/strategies/leverage/get-recommended-debt.js +61 -0
- package/dist/esm/common-utils/utils/strategies/leverage/get-recommended-debt.spec.js +226 -0
- package/dist/esm/common-utils/utils/strategies/leverage/get-recommended-leverage-factor.js +9 -0
- package/dist/esm/common-utils/utils/strategies/leverage/get-recommended-leverage-factor.spec.js +22 -0
- package/dist/esm/common-utils/utils/strategies/leverage/max-leverage.js +2 -2
- package/dist/esm/common-utils/utils/strategies/strategy-info/calculate-total-apy.js +88 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/calculate-total-apy.spec.js +187 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/calculate-total-points.js +54 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/calculate-total-points.spec.js +139 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +389 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.js +278 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-strategy-you-can-earn.js +84 -0
- package/dist/esm/common-utils/utils/strategies/tokens/add-amount-in-target.js +17 -0
- package/dist/esm/common-utils/utils/strategies/tokens/add-amount-in-target.spec.js +41 -0
- package/dist/esm/common-utils/utils/strategies/tokens/get-chain-phantom-tokens.js +11 -0
- package/dist/esm/common-utils/utils/strategies/tokens/get-list-with-amount-in-target.js +18 -0
- package/dist/esm/common-utils/utils/strategies/tokens/get-list-with-amount-in-target.spec.js +36 -0
- package/dist/esm/common-utils/utils/strategies/tokens/get-native-token-address.js +7 -0
- package/dist/esm/common-utils/utils/strategies/tokens/is-apy-with-points-exception.js +11 -0
- package/dist/esm/common-utils/utils/strategies/tokens/is-collateral-token.js +35 -0
- package/dist/esm/common-utils/utils/strategies/tokens/is-collateral-token.spec.js +137 -0
- package/dist/esm/common-utils/utils/strategies/tokens/is-obtainable-token.js +18 -0
- package/dist/esm/common-utils/utils/strategies/tokens/is-obtainable-token.spec.js +161 -0
- package/dist/esm/common-utils/utils/strategies/tokens/is-valid-extra-collateral-token.js +27 -0
- package/dist/esm/common-utils/utils/strategies/tokens/wrap-token-address.js +9 -0
- package/dist/esm/common-utils/utils/strategies/tokens/wrap-token-address.spec.js +12 -0
- package/dist/esm/common-utils/utils/strategies/types/strategy-data.js +0 -0
- package/dist/esm/common-utils/utils/strategies/types/strategy-earnings.js +0 -0
- package/dist/esm/common-utils/utils/validation/is-zero-balance.js +6 -0
- package/dist/esm/common-utils/utils/validation/validate-balance.js +23 -0
- package/dist/esm/common-utils/utils/validation/validate-balance.spec.js +51 -0
- package/dist/esm/common-utils/utils/validation/validate-balances.js +20 -0
- package/dist/esm/common-utils/utils/validation/validate-balances.spec.js +36 -0
- package/dist/esm/common-utils/utils/validation/validate-credit-manager.js +10 -0
- package/dist/esm/common-utils/utils/validation/validate-credit-manager.spec.js +35 -0
- package/dist/esm/common-utils/utils/validation/validate-hf.js +13 -0
- package/dist/esm/common-utils/utils/validation/validate-hf.spec.js +23 -0
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-quota-status.js +13 -0
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.js +46 -0
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.js +54 -0
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.spec.js +102 -0
- package/dist/esm/common-utils/utils/validation/validate-open-account.js +17 -0
- package/dist/esm/common-utils/utils/validation/validate-open-account.spec.js +56 -0
- package/dist/esm/common-utils/utils/validation/validate-quota.js +25 -0
- package/dist/esm/common-utils/utils/validation/validate-quota.spec.js +83 -0
- package/dist/esm/common-utils/utils/validation/validate-token-to-obtain.js +18 -0
- package/dist/esm/common-utils/utils/validation/validate-token-to-obtain.spec.js +34 -0
- package/dist/esm/common-utils/utils/validation/validation-types.js +0 -0
- package/dist/esm/dev/claimFromFaucet.js +17 -7
- package/dist/esm/sdk/constants/math.js +2 -0
- package/dist/types/common-utils/test-utils/index.d.ts +16 -0
- package/dist/types/common-utils/utils/apy/calculate-borrow-rate-from-utilization.d.ts +2 -0
- package/dist/types/common-utils/utils/apy/calculate-borrow-rate-from-utilization.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/apy/calculate-earnings.d.ts +16 -0
- package/dist/types/common-utils/utils/apy/calculate-earnings.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/apy/calculate-safe-borrow-rate.d.ts +11 -0
- package/dist/types/common-utils/utils/apy/calculate-safe-borrow-rate.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/apy/get-safe-base-borrow-rate.d.ts +4 -0
- package/dist/types/common-utils/utils/constants.d.ts +4 -0
- package/dist/types/common-utils/utils/strategies/assets/assets.d.ts +3 -0
- package/dist/types/common-utils/utils/strategies/credit-managers/get-cm-allowed-collaterals.d.ts +20 -0
- package/dist/types/common-utils/utils/strategies/credit-managers/get-cm-allowed-collaterals.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/credit-managers/get-wallet-balances-allowed-on-cm.d.ts +13 -0
- package/dist/types/common-utils/utils/strategies/credit-managers/get-wallet-balances-allowed-on-cm.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.d.ts +11 -0
- package/dist/types/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/leverage/get-collateral-by-debt.d.ts +2 -0
- package/dist/types/common-utils/utils/strategies/leverage/get-collateral-by-debt.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/leverage/get-recommended-debt.d.ts +21 -0
- package/dist/types/common-utils/utils/strategies/leverage/get-recommended-debt.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/leverage/get-recommended-leverage-factor.d.ts +4 -0
- package/dist/types/common-utils/utils/strategies/leverage/get-recommended-leverage-factor.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/calculate-total-apy.d.ts +28 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/calculate-total-apy.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/calculate-total-points.d.ts +22 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/calculate-total-points.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.d.ts +19 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/get-strategy-you-can-earn.d.ts +29 -0
- package/dist/types/common-utils/utils/strategies/tokens/add-amount-in-target.d.ts +6 -0
- package/dist/types/common-utils/utils/strategies/tokens/add-amount-in-target.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/tokens/get-chain-phantom-tokens.d.ts +6 -0
- package/dist/types/common-utils/utils/strategies/tokens/get-list-with-amount-in-target.d.ts +12 -0
- package/dist/types/common-utils/utils/strategies/tokens/get-list-with-amount-in-target.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/tokens/get-native-token-address.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/tokens/is-apy-with-points-exception.d.ts +3 -0
- package/dist/types/common-utils/utils/strategies/tokens/is-collateral-token.d.ts +16 -0
- package/dist/types/common-utils/utils/strategies/tokens/is-collateral-token.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/tokens/is-obtainable-token.d.ts +14 -0
- package/dist/types/common-utils/utils/strategies/tokens/is-obtainable-token.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/tokens/is-valid-extra-collateral-token.d.ts +20 -0
- package/dist/types/common-utils/utils/strategies/tokens/wrap-token-address.d.ts +2 -0
- package/dist/types/common-utils/utils/strategies/tokens/wrap-token-address.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/types/index.d.ts +2 -1
- package/dist/types/common-utils/utils/strategies/types/strategy-data.d.ts +64 -0
- package/dist/types/common-utils/utils/strategies/types/strategy-earnings.d.ts +43 -0
- package/dist/types/common-utils/utils/validation/is-zero-balance.d.ts +1 -0
- package/dist/types/common-utils/utils/validation/validate-balance.d.ts +22 -0
- package/dist/types/common-utils/utils/validation/validate-balance.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/validation/validate-balances.d.ts +9 -0
- package/dist/types/common-utils/utils/validation/validate-balances.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/validation/validate-credit-manager.d.ts +10 -0
- package/dist/types/common-utils/utils/validation/validate-credit-manager.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/validation/validate-hf.d.ts +9 -0
- package/dist/types/common-utils/utils/validation/validate-hf.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-quota-status.d.ts +7 -0
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-status.d.ts +23 -0
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-status.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/validation/validate-open-account.d.ts +21 -0
- package/dist/types/common-utils/utils/validation/validate-open-account.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/validation/validate-quota.d.ts +20 -0
- package/dist/types/common-utils/utils/validation/validate-quota.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/validation/validate-token-to-obtain.d.ts +13 -0
- package/dist/types/common-utils/utils/validation/validate-token-to-obtain.spec.d.ts +1 -0
- package/dist/types/common-utils/utils/validation/validation-types.d.ts +14 -0
- package/dist/types/dev/RevolverTransport.d.ts +4 -4
- package/dist/types/dev/claimFromFaucet.d.ts +1 -0
- package/dist/types/sdk/constants/math.d.ts +1 -0
- package/package.json +1 -1
- package/dist/cjs/common-utils/utils/strategies/__test-utils.js +0 -95
- package/dist/esm/common-utils/utils/strategies/__test-utils.js +0 -65
- package/dist/types/common-utils/utils/strategies/__test-utils.d.ts +0 -11
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LEVERAGE_DECIMALS,
|
|
3
|
+
WAD_DECIMALS_POW
|
|
4
|
+
} from "../../../../sdk/constants/math.js";
|
|
5
|
+
import { formatBN, toBigInt, toBN } from "../../../../sdk/utils/formatter.js";
|
|
6
|
+
import { calculateEarnings } from "../../apy/calculate-earnings.js";
|
|
7
|
+
import { calculateEffectiveBorrowRate } from "../../apy/calculate-effective-borrow-rate.js";
|
|
8
|
+
import { getComplexAPYList } from "../../apy/get-complex-apy-list.js";
|
|
9
|
+
import { getSafeBaseBorrowRate } from "../../apy/get-safe-base-borrow-rate.js";
|
|
10
|
+
import { AssetUtils } from "../../assets-math.js";
|
|
11
|
+
import { BigIntMath } from "../../bigint-math.js";
|
|
12
|
+
import { EMPTY_ADDRESS, EMPTY_OBJECT } from "../../constants.js";
|
|
13
|
+
import { calcHealthFactor } from "../../creditAccount/calc-health-factor.js";
|
|
14
|
+
import { calcQuotaUpdate } from "../../creditAccount/quota-utils.js";
|
|
15
|
+
import { PriceUtils } from "../../price-math.js";
|
|
16
|
+
import { isZeroBalance } from "../../validation/is-zero-balance.js";
|
|
17
|
+
import { validateBalances } from "../../validation/validate-balances.js";
|
|
18
|
+
import { validateCreditManager } from "../../validation/validate-credit-manager.js";
|
|
19
|
+
import { validateHF } from "../../validation/validate-hf.js";
|
|
20
|
+
import { validateOpenAccount } from "../../validation/validate-open-account.js";
|
|
21
|
+
import { validateOpenAccountPoolStatus } from "../../validation/validate-open-account-pool-status.js";
|
|
22
|
+
import { validateTokenToObtain } from "../../validation/validate-token-to-obtain.js";
|
|
23
|
+
import { getCMAllowedCollaterals } from "../credit-managers/get-cm-allowed-collaterals.js";
|
|
24
|
+
import { getWalletBalancesAllowedOnCM } from "../credit-managers/get-wallet-balances-allowed-on-cm.js";
|
|
25
|
+
import { getCollateralByDebt } from "../leverage/get-collateral-by-debt.js";
|
|
26
|
+
import { getLeverageFromFactor } from "../leverage/get-leverage-from-factor.js";
|
|
27
|
+
import { getRecommendedDebt } from "../leverage/get-recommended-debt.js";
|
|
28
|
+
import { getComplexPointsList } from "../points/get-complex-points-list.js";
|
|
29
|
+
import { getPointsInfo } from "../points/get-points-info.js";
|
|
30
|
+
import { getListWithAmountInTarget } from "../tokens/get-list-with-amount-in-target.js";
|
|
31
|
+
import { calculateTotalAPY } from "./calculate-total-apy.js";
|
|
32
|
+
import { calculateTotalPoints } from "./calculate-total-points.js";
|
|
33
|
+
function getCMYouCanEarn({
|
|
34
|
+
allPrices,
|
|
35
|
+
creditManager,
|
|
36
|
+
tokensList,
|
|
37
|
+
delayedPhantoms,
|
|
38
|
+
nativeTokenAddress,
|
|
39
|
+
wrappedNativeTokenAddress,
|
|
40
|
+
walletBalances,
|
|
41
|
+
strategy,
|
|
42
|
+
slippage,
|
|
43
|
+
quotaReserve,
|
|
44
|
+
apyList,
|
|
45
|
+
pools
|
|
46
|
+
}) {
|
|
47
|
+
const baseInfo = {
|
|
48
|
+
strategy: strategy.name,
|
|
49
|
+
strategyChainId: strategy.chainId,
|
|
50
|
+
strategyNetwork: strategy.network,
|
|
51
|
+
strategyType: strategy.strategyType,
|
|
52
|
+
creditManager: creditManager.address,
|
|
53
|
+
cmName: creditManager.name,
|
|
54
|
+
underlyingToken: tokensList[creditManager.underlyingToken]?.title || creditManager.underlyingToken,
|
|
55
|
+
targetToken: tokensList[strategy.tokenOutAddress]?.title || strategy.tokenOutAddress
|
|
56
|
+
};
|
|
57
|
+
if (!walletBalances) {
|
|
58
|
+
return {
|
|
59
|
+
status: "error",
|
|
60
|
+
description: "No wallet balances",
|
|
61
|
+
otherInfo: baseInfo,
|
|
62
|
+
data: void 0
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const targetTokenAddress = strategy.tokenOutAddress;
|
|
66
|
+
const targetDecimals = tokensList[targetTokenAddress]?.decimals || 18;
|
|
67
|
+
const prices = allPrices?.[creditManager?.pool || EMPTY_ADDRESS];
|
|
68
|
+
if (!prices) {
|
|
69
|
+
return {
|
|
70
|
+
status: "error",
|
|
71
|
+
description: "No prices for cm pool",
|
|
72
|
+
otherInfo: baseInfo,
|
|
73
|
+
data: void 0
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const collateralRecord = getCMAllowedCollaterals({
|
|
77
|
+
creditManager,
|
|
78
|
+
tokensList,
|
|
79
|
+
zeroDebt: false,
|
|
80
|
+
delayedPhantoms,
|
|
81
|
+
nativeTokenAddress,
|
|
82
|
+
wrappedNativeTokenAddress,
|
|
83
|
+
extraCollaterals: {
|
|
84
|
+
list: strategy.additionalCollaterals,
|
|
85
|
+
prices
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const walletBalancesSorted = getWalletBalancesAllowedOnCM({
|
|
89
|
+
walletBalances,
|
|
90
|
+
collateralRecord,
|
|
91
|
+
nativeTokenAddress,
|
|
92
|
+
wrappedNativeTokenAddress,
|
|
93
|
+
tokensList,
|
|
94
|
+
prices,
|
|
95
|
+
isPaused: creditManager?.isPaused
|
|
96
|
+
});
|
|
97
|
+
const filtered = walletBalancesSorted.filter((a) => !isZeroBalance(a.balance));
|
|
98
|
+
const collateral_initial = filtered[0];
|
|
99
|
+
if (!collateral_initial || collateral_initial.balance === 0n) {
|
|
100
|
+
return {
|
|
101
|
+
status: "error",
|
|
102
|
+
description: `Initial collateral is zero`,
|
|
103
|
+
otherInfo: {
|
|
104
|
+
...baseInfo,
|
|
105
|
+
walletBalancesSorted,
|
|
106
|
+
filtered
|
|
107
|
+
},
|
|
108
|
+
data: void 0
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const collateralPrice = prices[collateral_initial.token] || 0n;
|
|
112
|
+
const collateralDecimals = tokensList[collateral_initial.token]?.decimals || 18;
|
|
113
|
+
const underlyingPrice = prices[creditManager.underlyingToken] || 0n;
|
|
114
|
+
const underlyingDecimals = tokensList[creditManager.underlyingToken]?.decimals || 18;
|
|
115
|
+
const assetValueFrom_initial = PriceUtils.convertByPrice(
|
|
116
|
+
PriceUtils.calcTotalPrice(
|
|
117
|
+
collateralPrice,
|
|
118
|
+
collateral_initial.balance,
|
|
119
|
+
collateralDecimals
|
|
120
|
+
),
|
|
121
|
+
{
|
|
122
|
+
price: underlyingPrice,
|
|
123
|
+
decimals: underlyingDecimals
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
if (!assetValueFrom_initial || assetValueFrom_initial === 0n) {
|
|
127
|
+
return {
|
|
128
|
+
status: "error",
|
|
129
|
+
description: "Initial asset value from is zero",
|
|
130
|
+
otherInfo: baseInfo,
|
|
131
|
+
data: void 0
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const recommendedDebt_initial = getRecommendedDebt({
|
|
135
|
+
targetToken: targetTokenAddress,
|
|
136
|
+
amount: assetValueFrom_initial,
|
|
137
|
+
creditManager,
|
|
138
|
+
slippage,
|
|
139
|
+
swapCollateral: true,
|
|
140
|
+
leverageLimit: strategy.maxLeverage
|
|
141
|
+
});
|
|
142
|
+
const lt = creditManager.liquidationThresholds[targetTokenAddress] || 0n;
|
|
143
|
+
const recommendedAssetValueFrom = getCollateralByDebt(
|
|
144
|
+
recommendedDebt_initial.maxDebt,
|
|
145
|
+
lt,
|
|
146
|
+
toBN("1.013", 4)
|
|
147
|
+
);
|
|
148
|
+
const assetValueFrom = BigIntMath.min(
|
|
149
|
+
assetValueFrom_initial,
|
|
150
|
+
recommendedAssetValueFrom
|
|
151
|
+
);
|
|
152
|
+
if (!assetValueFrom || assetValueFrom === 0n) {
|
|
153
|
+
return {
|
|
154
|
+
status: "error",
|
|
155
|
+
description: "Asset value from is zero",
|
|
156
|
+
otherInfo: baseInfo,
|
|
157
|
+
data: void 0
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const assetValueFromTarget = PriceUtils.convertByPrice(
|
|
161
|
+
PriceUtils.calcTotalPrice(
|
|
162
|
+
underlyingPrice,
|
|
163
|
+
assetValueFrom,
|
|
164
|
+
underlyingDecimals
|
|
165
|
+
),
|
|
166
|
+
{
|
|
167
|
+
price: collateralPrice,
|
|
168
|
+
decimals: collateralDecimals
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
const collateral = [
|
|
172
|
+
{ token: collateral_initial.token, balance: assetValueFromTarget }
|
|
173
|
+
];
|
|
174
|
+
const recommendedDebt = getRecommendedDebt({
|
|
175
|
+
targetToken: targetTokenAddress,
|
|
176
|
+
amount: assetValueFrom,
|
|
177
|
+
creditManager,
|
|
178
|
+
slippage,
|
|
179
|
+
swapCollateral: true,
|
|
180
|
+
leverageLimit: strategy.maxLeverage
|
|
181
|
+
});
|
|
182
|
+
const debt = recommendedDebt.maxDebt;
|
|
183
|
+
const totalAmount = assetValueFrom + debt;
|
|
184
|
+
const targetPrice = prices[targetTokenAddress] || 0n;
|
|
185
|
+
const totalAmountInTarget = PriceUtils.convertByPrice(
|
|
186
|
+
PriceUtils.calcTotalPrice(underlyingPrice, totalAmount, underlyingDecimals),
|
|
187
|
+
{
|
|
188
|
+
price: targetPrice,
|
|
189
|
+
decimals: targetDecimals
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
const assets = [
|
|
193
|
+
{
|
|
194
|
+
token: targetTokenAddress,
|
|
195
|
+
balance: totalAmountInTarget
|
|
196
|
+
}
|
|
197
|
+
];
|
|
198
|
+
const assetsWithAmountInTarget = getListWithAmountInTarget({
|
|
199
|
+
assets,
|
|
200
|
+
targetToken: creditManager.underlyingToken,
|
|
201
|
+
prices,
|
|
202
|
+
tokensList
|
|
203
|
+
});
|
|
204
|
+
const assetsWithAmountInTargetRecord = AssetUtils.constructAssetRecord(
|
|
205
|
+
assetsWithAmountInTarget
|
|
206
|
+
);
|
|
207
|
+
const quotasAfter = calcQuotaUpdate({
|
|
208
|
+
quotas: creditManager.quotas,
|
|
209
|
+
initialQuotas: EMPTY_OBJECT,
|
|
210
|
+
assetsAfterUpdate: assetsWithAmountInTargetRecord,
|
|
211
|
+
allowedToObtain: assetsWithAmountInTargetRecord,
|
|
212
|
+
allowedToSpend: EMPTY_OBJECT,
|
|
213
|
+
quotaReserve: toBigInt(quotaReserve),
|
|
214
|
+
maxDebt: creditManager.maxDebt,
|
|
215
|
+
calcModification: void 0,
|
|
216
|
+
liquidationThresholds: creditManager.liquidationThresholds
|
|
217
|
+
});
|
|
218
|
+
const desiredQuota = quotasAfter.desiredQuota;
|
|
219
|
+
const quotaDecrease = quotasAfter.quotaDecrease;
|
|
220
|
+
const quotaIncrease = quotasAfter.quotaIncrease;
|
|
221
|
+
const quotaUpdate = [...quotaDecrease, ...quotaIncrease];
|
|
222
|
+
const hf = calcHealthFactor({
|
|
223
|
+
assets: assetsWithAmountInTarget,
|
|
224
|
+
quotas: desiredQuota,
|
|
225
|
+
prices,
|
|
226
|
+
liquidationThresholds: creditManager.liquidationThresholds,
|
|
227
|
+
underlyingToken: creditManager.underlyingToken,
|
|
228
|
+
debt,
|
|
229
|
+
quotasInfo: creditManager.quotas,
|
|
230
|
+
tokensList
|
|
231
|
+
});
|
|
232
|
+
const pool = pools?.[creditManager.pool];
|
|
233
|
+
const error = validateCreditManager({ creditManager }) || validateOpenAccountPoolStatus({
|
|
234
|
+
pool,
|
|
235
|
+
creditManager,
|
|
236
|
+
debt,
|
|
237
|
+
targetToken: targetTokenAddress
|
|
238
|
+
}) || validateTokenToObtain({
|
|
239
|
+
targetToken: strategy.tokenOutAddress,
|
|
240
|
+
creditManager
|
|
241
|
+
}) || validateBalances({
|
|
242
|
+
balances: walletBalances,
|
|
243
|
+
assets: collateral
|
|
244
|
+
}) || validateOpenAccount({
|
|
245
|
+
desiredQuota,
|
|
246
|
+
quotaUpdate,
|
|
247
|
+
debt,
|
|
248
|
+
creditManager,
|
|
249
|
+
loading: false
|
|
250
|
+
}) || validateHF({ hf });
|
|
251
|
+
if (error) {
|
|
252
|
+
return {
|
|
253
|
+
status: "error",
|
|
254
|
+
description: `Resulting CA did not pass validation: ${error.message}`,
|
|
255
|
+
otherInfo: {
|
|
256
|
+
...baseInfo,
|
|
257
|
+
hf
|
|
258
|
+
},
|
|
259
|
+
data: void 0
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const apyRecord = getComplexAPYList(
|
|
263
|
+
apyList?.apyList,
|
|
264
|
+
apyList?.extraCollateralAPYList,
|
|
265
|
+
creditManager.pool
|
|
266
|
+
);
|
|
267
|
+
if (!apyRecord) {
|
|
268
|
+
return {
|
|
269
|
+
status: "error",
|
|
270
|
+
description: "No complex apy record",
|
|
271
|
+
otherInfo: baseInfo,
|
|
272
|
+
data: void 0
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
const pointsList = getComplexPointsList(
|
|
276
|
+
apyList?.pointsList,
|
|
277
|
+
apyList?.extraCollateralPointsList,
|
|
278
|
+
pool?.address
|
|
279
|
+
);
|
|
280
|
+
if (!pointsList) {
|
|
281
|
+
return {
|
|
282
|
+
status: "error",
|
|
283
|
+
description: "No complex points record",
|
|
284
|
+
otherInfo: baseInfo,
|
|
285
|
+
data: void 0
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const pointsInfo = getPointsInfo({
|
|
289
|
+
chainId: strategy.chainId,
|
|
290
|
+
pointsList,
|
|
291
|
+
token: strategy.tokenOutAddress,
|
|
292
|
+
creditManagers: {
|
|
293
|
+
[creditManager.address]: creditManager
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
const baseBorrowRateTo = pool ? getSafeBaseBorrowRate({
|
|
297
|
+
creditManager,
|
|
298
|
+
pool,
|
|
299
|
+
availableLiquidityChange: debt * -1n
|
|
300
|
+
}) : creditManager.baseBorrowRate;
|
|
301
|
+
const effectiveBorrowRate = calculateEffectiveBorrowRate({
|
|
302
|
+
underlyingTokenAddress: creditManager.underlyingToken,
|
|
303
|
+
baseRateWithFee: baseBorrowRateTo,
|
|
304
|
+
apyList: apyRecord
|
|
305
|
+
});
|
|
306
|
+
const totalAPY = calculateTotalAPY({
|
|
307
|
+
caAssets: assetsWithAmountInTarget,
|
|
308
|
+
lpAPY: apyRecord,
|
|
309
|
+
prices,
|
|
310
|
+
quotaRates: creditManager.quotas,
|
|
311
|
+
quotas: desiredQuota,
|
|
312
|
+
feeInterest: creditManager.feeInterest,
|
|
313
|
+
totalValue: totalAmount,
|
|
314
|
+
debt,
|
|
315
|
+
underlyingToken: creditManager.underlyingToken,
|
|
316
|
+
tokensList,
|
|
317
|
+
pointsInfo,
|
|
318
|
+
effectiveBorrowRate,
|
|
319
|
+
showAPY: true
|
|
320
|
+
});
|
|
321
|
+
const earn = calculateEarnings({
|
|
322
|
+
overallAPYBigInt: totalAPY.overallAPYBigInt,
|
|
323
|
+
targetAmount: assetValueFrom,
|
|
324
|
+
targetToken: creditManager.underlyingToken,
|
|
325
|
+
tokensList,
|
|
326
|
+
prices
|
|
327
|
+
});
|
|
328
|
+
const points = calculateTotalPoints({
|
|
329
|
+
pointsAsset: pointsInfo ? assetsWithAmountInTarget[0] : void 0,
|
|
330
|
+
cmAddress: creditManager.address,
|
|
331
|
+
info: pointsInfo,
|
|
332
|
+
totalValue: totalAmount,
|
|
333
|
+
assetValue: assetValueFrom,
|
|
334
|
+
prices,
|
|
335
|
+
tokensList,
|
|
336
|
+
underlyingToken: creditManager.underlyingToken
|
|
337
|
+
});
|
|
338
|
+
const leverage = getLeverageFromFactor(
|
|
339
|
+
debt * LEVERAGE_DECIMALS / assetValueFrom
|
|
340
|
+
);
|
|
341
|
+
const info = {
|
|
342
|
+
info: {
|
|
343
|
+
strategy,
|
|
344
|
+
creditManager,
|
|
345
|
+
collateral,
|
|
346
|
+
assetsWithAmountInTarget,
|
|
347
|
+
assetValue: assetValueFrom,
|
|
348
|
+
debt,
|
|
349
|
+
totalAmount,
|
|
350
|
+
assetValueInUSD: PriceUtils.calcTotalPrice(
|
|
351
|
+
underlyingPrice,
|
|
352
|
+
assetValueFrom,
|
|
353
|
+
underlyingDecimals
|
|
354
|
+
),
|
|
355
|
+
maxAPY: totalAPY,
|
|
356
|
+
bonusAPY: void 0,
|
|
357
|
+
extraAPY: [],
|
|
358
|
+
maxLeverage: leverage
|
|
359
|
+
},
|
|
360
|
+
earnings: earn,
|
|
361
|
+
points,
|
|
362
|
+
otherInfo: {
|
|
363
|
+
...baseInfo,
|
|
364
|
+
collateral: collateral.map((c) => ({
|
|
365
|
+
token: tokensList[c.token]?.title || c.token,
|
|
366
|
+
balance: formatBN(c.balance, WAD_DECIMALS_POW, 4)
|
|
367
|
+
})),
|
|
368
|
+
apy: formatBN(totalAPY.overallAPYBigInt || 0, 4, 4),
|
|
369
|
+
earningsUSD: formatBN(earn.earningsUSD || 0n, WAD_DECIMALS_POW, 4),
|
|
370
|
+
assetValue: formatBN(assetValueFrom, targetDecimals, 4),
|
|
371
|
+
debt: formatBN(debt, targetDecimals, 4),
|
|
372
|
+
totalAmount: formatBN(totalAmount, underlyingDecimals, 4),
|
|
373
|
+
assetValueFrom_initial: formatBN(
|
|
374
|
+
assetValueFrom_initial,
|
|
375
|
+
targetDecimals,
|
|
376
|
+
4
|
|
377
|
+
),
|
|
378
|
+
debt_initial: formatBN(
|
|
379
|
+
recommendedDebt_initial.maxDebt,
|
|
380
|
+
targetDecimals,
|
|
381
|
+
4
|
|
382
|
+
)
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
return { status: "ok", description: "ok", data: info };
|
|
386
|
+
}
|
|
387
|
+
export {
|
|
388
|
+
getCMYouCanEarn
|
|
389
|
+
};
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { toBN } from "../../../../sdk/utils/formatter.js";
|
|
3
|
+
import {
|
|
4
|
+
buildCreditManager,
|
|
5
|
+
buildPool,
|
|
6
|
+
buildQuota,
|
|
7
|
+
buildTokenData
|
|
8
|
+
} from "../../../test-utils/index.js";
|
|
9
|
+
import { getCMYouCanEarn } from "./get-cm-you-can-earn.js";
|
|
10
|
+
describe("getCMYouCanEarn", () => {
|
|
11
|
+
const collateralTokenAddress = "0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee";
|
|
12
|
+
const targetTokenAddress = "0xe72b141df173b999ae7c1adcbf60cc9833ce56a8";
|
|
13
|
+
const underlyingTokenAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
|
|
14
|
+
const deth = "0x871ab8e36cae9af35c6a3488b049965233deb7ed";
|
|
15
|
+
const nativeTokenAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
16
|
+
const wrappedNativeTokenAddress = underlyingTokenAddress;
|
|
17
|
+
const tokenDataList = {
|
|
18
|
+
[collateralTokenAddress]: buildTokenData(collateralTokenAddress, "weETH"),
|
|
19
|
+
[targetTokenAddress]: buildTokenData(targetTokenAddress, "ethPlus"),
|
|
20
|
+
[underlyingTokenAddress]: buildTokenData(underlyingTokenAddress, "WETH"),
|
|
21
|
+
[nativeTokenAddress]: buildTokenData(nativeTokenAddress, "ETH"),
|
|
22
|
+
[deth]: buildTokenData(deth, "dETH")
|
|
23
|
+
};
|
|
24
|
+
const poolAddress = "0x0000000000000000000000000000000000000POOL";
|
|
25
|
+
const creditManagerAddress = "0x0000000000000000000000000000000000000CM1";
|
|
26
|
+
const creditManager = buildCreditManager({
|
|
27
|
+
address: creditManagerAddress,
|
|
28
|
+
pool: poolAddress,
|
|
29
|
+
underlyingToken: underlyingTokenAddress,
|
|
30
|
+
collateralTokens: [
|
|
31
|
+
collateralTokenAddress,
|
|
32
|
+
underlyingTokenAddress,
|
|
33
|
+
targetTokenAddress,
|
|
34
|
+
deth
|
|
35
|
+
],
|
|
36
|
+
supportedTokens: {
|
|
37
|
+
[collateralTokenAddress]: true,
|
|
38
|
+
[underlyingTokenAddress]: true,
|
|
39
|
+
[targetTokenAddress]: true,
|
|
40
|
+
[deth]: true
|
|
41
|
+
},
|
|
42
|
+
liquidationThresholds: {
|
|
43
|
+
[collateralTokenAddress]: 9300n,
|
|
44
|
+
[targetTokenAddress]: 9300n,
|
|
45
|
+
[underlyingTokenAddress]: 9500n,
|
|
46
|
+
[deth]: 8800n
|
|
47
|
+
},
|
|
48
|
+
quotas: {
|
|
49
|
+
[targetTokenAddress]: buildQuota({
|
|
50
|
+
isActive: true,
|
|
51
|
+
limit: 5000000000000000000000n,
|
|
52
|
+
quotaIncreaseFee: 0n,
|
|
53
|
+
rate: 100n,
|
|
54
|
+
token: "0xe72b141df173b999ae7c1adcbf60cc9833ce56a8",
|
|
55
|
+
totalQuoted: 1708445825184283030000n
|
|
56
|
+
}),
|
|
57
|
+
[collateralTokenAddress]: buildQuota({
|
|
58
|
+
token: collateralTokenAddress,
|
|
59
|
+
rate: 0n,
|
|
60
|
+
limit: toBN("1000000", 18)
|
|
61
|
+
}),
|
|
62
|
+
[deth]: buildQuota({
|
|
63
|
+
isActive: true,
|
|
64
|
+
limit: 500000000000000000000n,
|
|
65
|
+
quotaIncreaseFee: 0n,
|
|
66
|
+
rate: 100n,
|
|
67
|
+
token: deth,
|
|
68
|
+
totalQuoted: 28666207338545540000n
|
|
69
|
+
})
|
|
70
|
+
},
|
|
71
|
+
isQuoted: (t) => t.toLowerCase() !== underlyingTokenAddress,
|
|
72
|
+
feeInterest: 2e3,
|
|
73
|
+
isPaused: false,
|
|
74
|
+
baseBorrowRate: 18991,
|
|
75
|
+
maxDebt: 250000000000000000000n,
|
|
76
|
+
minDebt: 10000000000000000000n,
|
|
77
|
+
availableToBorrow: 859640767327531138355n
|
|
78
|
+
});
|
|
79
|
+
const pools = {
|
|
80
|
+
[poolAddress]: buildPool({
|
|
81
|
+
address: poolAddress,
|
|
82
|
+
chainId: 1,
|
|
83
|
+
network: "Mainnet",
|
|
84
|
+
underlyingToken: underlyingTokenAddress,
|
|
85
|
+
dieselToken: poolAddress,
|
|
86
|
+
isPaused: false,
|
|
87
|
+
version: 310,
|
|
88
|
+
expectedLiquidity: 5596004266940175413222n,
|
|
89
|
+
expectedLiquidityLimit: 6903325375622920584635n,
|
|
90
|
+
availableLiquidity: 1307321108682745171413n,
|
|
91
|
+
interestModel: {
|
|
92
|
+
interestModel: "0x12e6e5c6fe4b37576dd4052e03a97ee7b9c29e86",
|
|
93
|
+
U_1: 7000n,
|
|
94
|
+
U_2: 9200n,
|
|
95
|
+
R_base: 0n,
|
|
96
|
+
R_slope1: 113n,
|
|
97
|
+
R_slope2: 150n,
|
|
98
|
+
R_slope3: 1236n,
|
|
99
|
+
version: 310,
|
|
100
|
+
isBorrowingMoreU2Forbidden: true
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
};
|
|
104
|
+
const allPrices = {
|
|
105
|
+
[poolAddress]: {
|
|
106
|
+
[collateralTokenAddress]: 347896889077n,
|
|
107
|
+
[targetTokenAddress]: 342474099875n,
|
|
108
|
+
[underlyingTokenAddress]: 320438727057n,
|
|
109
|
+
[deth]: 322630065873n
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const walletBalances = {
|
|
113
|
+
[underlyingTokenAddress]: 0n,
|
|
114
|
+
[collateralTokenAddress]: 6191758000000000000n,
|
|
115
|
+
[targetTokenAddress]: 0n
|
|
116
|
+
};
|
|
117
|
+
const apyList = {
|
|
118
|
+
apyList: {
|
|
119
|
+
[targetTokenAddress]: 24600,
|
|
120
|
+
[collateralTokenAddress]: 27612,
|
|
121
|
+
[deth]: 16600
|
|
122
|
+
},
|
|
123
|
+
extraCollateralAPYList: {
|
|
124
|
+
[poolAddress]: {
|
|
125
|
+
[targetTokenAddress]: {
|
|
126
|
+
address: targetTokenAddress,
|
|
127
|
+
pool: poolAddress,
|
|
128
|
+
symbol: "ETHPlus",
|
|
129
|
+
type: "relative",
|
|
130
|
+
value: 0
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
pointsList: {
|
|
135
|
+
[collateralTokenAddress]: {
|
|
136
|
+
symbol: "weETH",
|
|
137
|
+
address: "0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee",
|
|
138
|
+
debtRewards: void 0,
|
|
139
|
+
rewards: [
|
|
140
|
+
{
|
|
141
|
+
name: "Ether.fi",
|
|
142
|
+
units: "points",
|
|
143
|
+
multiplier: 200n,
|
|
144
|
+
type: "etherfi"
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
[deth]: {
|
|
149
|
+
address: "0x871ab8e36cae9af35c6a3488b049965233deb7ed",
|
|
150
|
+
debtRewards: void 0,
|
|
151
|
+
rewards: [
|
|
152
|
+
{
|
|
153
|
+
name: "Makina",
|
|
154
|
+
units: "points",
|
|
155
|
+
multiplier: 36000n,
|
|
156
|
+
type: "makina"
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
symbol: "DETH"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
extraCollateralPointsList: {},
|
|
163
|
+
poolRewardsList: {},
|
|
164
|
+
tokenExtraRewardsList: {},
|
|
165
|
+
poolExternalAPYList: {},
|
|
166
|
+
poolExtraAPYList: {}
|
|
167
|
+
};
|
|
168
|
+
it("computes expected earnings for APY-only scenario", () => {
|
|
169
|
+
const strategy = {
|
|
170
|
+
id: "test-strategy",
|
|
171
|
+
tokenOutAddress: targetTokenAddress,
|
|
172
|
+
chainId: 1,
|
|
173
|
+
network: "Mainnet"
|
|
174
|
+
};
|
|
175
|
+
const result = getCMYouCanEarn({
|
|
176
|
+
creditManager,
|
|
177
|
+
pools,
|
|
178
|
+
strategy,
|
|
179
|
+
delayedPhantoms: {},
|
|
180
|
+
apyList,
|
|
181
|
+
tokensList: tokenDataList,
|
|
182
|
+
walletBalances,
|
|
183
|
+
nativeTokenAddress,
|
|
184
|
+
wrappedNativeTokenAddress,
|
|
185
|
+
allPrices,
|
|
186
|
+
slippage: 10,
|
|
187
|
+
quotaReserve: 500
|
|
188
|
+
});
|
|
189
|
+
expect(result.status).toEqual("ok");
|
|
190
|
+
expect(result.data?.info?.maxAPY).toEqual({
|
|
191
|
+
overallAPY: 7.392,
|
|
192
|
+
overallAPYBigInt: 73920n,
|
|
193
|
+
overallAPYStatus: "calculated"
|
|
194
|
+
});
|
|
195
|
+
expect(result.data?.earnings).toEqual({
|
|
196
|
+
earnings: 496914282513333354n,
|
|
197
|
+
earningsUSD: 1592305801450150145856n
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
it("computes expected earnings for APY and points scenario", () => {
|
|
201
|
+
const strategy = {
|
|
202
|
+
id: "test-strategy",
|
|
203
|
+
tokenOutAddress: collateralTokenAddress,
|
|
204
|
+
chainId: 1,
|
|
205
|
+
network: "Mainnet"
|
|
206
|
+
};
|
|
207
|
+
const result = getCMYouCanEarn({
|
|
208
|
+
creditManager,
|
|
209
|
+
pools,
|
|
210
|
+
strategy,
|
|
211
|
+
delayedPhantoms: {},
|
|
212
|
+
apyList,
|
|
213
|
+
tokensList: tokenDataList,
|
|
214
|
+
walletBalances,
|
|
215
|
+
nativeTokenAddress,
|
|
216
|
+
wrappedNativeTokenAddress,
|
|
217
|
+
allPrices,
|
|
218
|
+
slippage: 10,
|
|
219
|
+
quotaReserve: 500
|
|
220
|
+
});
|
|
221
|
+
expect(result.status).toEqual("ok");
|
|
222
|
+
expect(result.data?.info?.maxAPY).toEqual({
|
|
223
|
+
overallAPY: 11.233,
|
|
224
|
+
overallAPYBigInt: 112330n,
|
|
225
|
+
overallAPYStatus: "calculated"
|
|
226
|
+
});
|
|
227
|
+
expect(result.data?.earnings).toEqual({
|
|
228
|
+
earnings: 755118795383153892n,
|
|
229
|
+
earningsUSD: 2419693055693930817344n
|
|
230
|
+
});
|
|
231
|
+
expect(result.data?.points?.info).toEqual(
|
|
232
|
+
apyList.pointsList?.[collateralTokenAddress] || {}
|
|
233
|
+
);
|
|
234
|
+
expect(result.data?.points).toEqual({
|
|
235
|
+
debtRates: { rewards: [], rates: [] },
|
|
236
|
+
info: apyList.pointsList?.[collateralTokenAddress] || {},
|
|
237
|
+
rates: [2454n]
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
it("computes expected earnings for points-only scenario", () => {
|
|
241
|
+
const strategy = {
|
|
242
|
+
id: "test-strategy",
|
|
243
|
+
tokenOutAddress: deth,
|
|
244
|
+
chainId: 1,
|
|
245
|
+
network: "Mainnet"
|
|
246
|
+
};
|
|
247
|
+
const result = getCMYouCanEarn({
|
|
248
|
+
creditManager,
|
|
249
|
+
pools,
|
|
250
|
+
strategy,
|
|
251
|
+
delayedPhantoms: {},
|
|
252
|
+
apyList,
|
|
253
|
+
tokensList: tokenDataList,
|
|
254
|
+
walletBalances,
|
|
255
|
+
nativeTokenAddress,
|
|
256
|
+
wrappedNativeTokenAddress,
|
|
257
|
+
allPrices,
|
|
258
|
+
slippage: 10,
|
|
259
|
+
quotaReserve: 500
|
|
260
|
+
});
|
|
261
|
+
expect(result.status).toEqual("ok");
|
|
262
|
+
expect(result.data?.info?.maxAPY).toEqual({
|
|
263
|
+
overallAPY: void 0,
|
|
264
|
+
overallAPYBigInt: void 0,
|
|
265
|
+
overallAPYStatus: "negativeForPoints"
|
|
266
|
+
});
|
|
267
|
+
expect(result.data?.earnings).toEqual({
|
|
268
|
+
earnings: null,
|
|
269
|
+
earningsUSD: null
|
|
270
|
+
});
|
|
271
|
+
expect(result.data?.points?.info).toEqual(apyList.pointsList?.[deth] || {});
|
|
272
|
+
expect(result.data?.points).toEqual({
|
|
273
|
+
debtRates: { rewards: [], rates: [] },
|
|
274
|
+
info: apyList.pointsList?.[deth] || {},
|
|
275
|
+
rates: [259920n]
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
});
|