@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,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_strategy_you_can_earn_exports = {};
|
|
20
|
+
__export(get_strategy_you_can_earn_exports, {
|
|
21
|
+
getStrategyYouCanEarn: () => getStrategyYouCanEarn
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_strategy_you_can_earn_exports);
|
|
24
|
+
var import_is_strategy_cm_disabled = require("../../strategies/strategy-info/is-strategy-cm-disabled.js");
|
|
25
|
+
var import_get_chain_phantom_tokens = require("../tokens/get-chain-phantom-tokens.js");
|
|
26
|
+
var import_get_native_token_address = require("../tokens/get-native-token-address.js");
|
|
27
|
+
var import_get_cm_you_can_earn = require("./get-cm-you-can-earn.js");
|
|
28
|
+
function getStrategyYouCanEarn({
|
|
29
|
+
strategy,
|
|
30
|
+
creditManagers,
|
|
31
|
+
sdkState,
|
|
32
|
+
apyList,
|
|
33
|
+
quotaReserve,
|
|
34
|
+
slippage,
|
|
35
|
+
allPrices,
|
|
36
|
+
walletBalances
|
|
37
|
+
}) {
|
|
38
|
+
const strategyCMs = creditManagers;
|
|
39
|
+
const baseInfo = {
|
|
40
|
+
strategy: strategy.name,
|
|
41
|
+
strategyChainId: strategy.chainId,
|
|
42
|
+
strategyNetwork: strategy.network,
|
|
43
|
+
strategyType: strategy.strategyType,
|
|
44
|
+
strategyTokenOutAddress: strategy.tokenOutAddress
|
|
45
|
+
};
|
|
46
|
+
if (!strategyCMs || !walletBalances || !allPrices || !apyList || !sdkState) {
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
status: "error",
|
|
50
|
+
description: "No strategy cms or wallet balances or all prices or apy list or sdk state",
|
|
51
|
+
otherInfo: baseInfo,
|
|
52
|
+
data: void 0
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
const openableCMsList = Object.values(strategyCMs).filter(
|
|
57
|
+
(cm) => !(0, import_is_strategy_cm_disabled.isStrategyCMDisabled)(cm, cm.quotas[strategy.tokenOutAddress])
|
|
58
|
+
);
|
|
59
|
+
if (openableCMsList.length === 0) {
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
status: "error",
|
|
63
|
+
description: "No openable cms list",
|
|
64
|
+
otherInfo: baseInfo,
|
|
65
|
+
data: void 0
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
const pools = sdkState.pools;
|
|
70
|
+
const tokensList = sdkState.tokens?.tokenDataList;
|
|
71
|
+
if (!tokensList || !pools || Object.keys(pools).length === 0) {
|
|
72
|
+
return [
|
|
73
|
+
{
|
|
74
|
+
status: "error",
|
|
75
|
+
description: "No pools or tokens list",
|
|
76
|
+
otherInfo: baseInfo,
|
|
77
|
+
data: void 0
|
|
78
|
+
}
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
const ap = sdkState.addressProvider;
|
|
82
|
+
const nativeTokenAddress = (0, import_get_native_token_address.getNativeTokenAddress)();
|
|
83
|
+
const delayedPhantoms = (0, import_get_chain_phantom_tokens.getChainPhantomTokens)(sdkState.withdrawableAssets);
|
|
84
|
+
const results = openableCMsList.map(
|
|
85
|
+
(creditManager) => {
|
|
86
|
+
const info = (0, import_get_cm_you_can_earn.getCMYouCanEarn)({
|
|
87
|
+
allPrices,
|
|
88
|
+
creditManager,
|
|
89
|
+
tokensList,
|
|
90
|
+
delayedPhantoms,
|
|
91
|
+
nativeTokenAddress,
|
|
92
|
+
wrappedNativeTokenAddress: ap.wrappedNativeToken,
|
|
93
|
+
walletBalances,
|
|
94
|
+
strategy,
|
|
95
|
+
slippage,
|
|
96
|
+
quotaReserve,
|
|
97
|
+
apyList,
|
|
98
|
+
pools
|
|
99
|
+
});
|
|
100
|
+
return info;
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
return results;
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
getStrategyYouCanEarn
|
|
108
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var add_amount_in_target_exports = {};
|
|
20
|
+
__export(add_amount_in_target_exports, {
|
|
21
|
+
addAmountInTarget: () => addAmountInTarget
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(add_amount_in_target_exports);
|
|
24
|
+
var import_price_math = require("../../price-math.js");
|
|
25
|
+
function addAmountInTarget(asset, tokensList, prices, toPrice, toDecimals) {
|
|
26
|
+
const { balance: fromAmount, token: fromToken } = asset;
|
|
27
|
+
const { decimals: fromDecimals = 18, address: fromAddress } = tokensList[fromToken] || {};
|
|
28
|
+
const fromPrice = prices[fromAddress] || 0n;
|
|
29
|
+
const inTarget = import_price_math.PriceUtils.convertByPrice(
|
|
30
|
+
import_price_math.PriceUtils.calcTotalPrice(fromPrice, fromAmount, fromDecimals),
|
|
31
|
+
{
|
|
32
|
+
price: toPrice,
|
|
33
|
+
decimals: toDecimals
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
return { ...asset, amountInTarget: inTarget };
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
addAmountInTarget
|
|
41
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_test_utils = require("../../../test-utils/index.js");
|
|
4
|
+
var import_assets = require("../assets/assets.js");
|
|
5
|
+
var import_add_amount_in_target = require("./add-amount-in-target.js");
|
|
6
|
+
(0, import_vitest.describe)("addAmountInTarget", () => {
|
|
7
|
+
const fromToken = import_test_utils.mockToken1;
|
|
8
|
+
const toPrice = 4n;
|
|
9
|
+
const toDecimals = 18;
|
|
10
|
+
(0, import_vitest.it)("converts amount to target token using prices", () => {
|
|
11
|
+
const asset = {
|
|
12
|
+
...(0, import_assets.getDefaultAsset)(fromToken),
|
|
13
|
+
balance: 10n ** 18n
|
|
14
|
+
};
|
|
15
|
+
const result = (0, import_add_amount_in_target.addAmountInTarget)(
|
|
16
|
+
asset,
|
|
17
|
+
import_test_utils.mockTokenData,
|
|
18
|
+
import_test_utils.mockPrices,
|
|
19
|
+
toPrice,
|
|
20
|
+
toDecimals
|
|
21
|
+
);
|
|
22
|
+
(0, import_vitest.expect)(result.amountInTarget).toBe(75000000000000000000000000n);
|
|
23
|
+
});
|
|
24
|
+
(0, import_vitest.it)("handles missing price data gracefully", () => {
|
|
25
|
+
const asset = { ...(0, import_assets.getDefaultAsset)(fromToken), balance: 10n ** 18n };
|
|
26
|
+
const tokensList = {
|
|
27
|
+
[fromToken]: import_test_utils.mockTokenData[fromToken]
|
|
28
|
+
};
|
|
29
|
+
const result = (0, import_add_amount_in_target.addAmountInTarget)(
|
|
30
|
+
asset,
|
|
31
|
+
tokensList,
|
|
32
|
+
{},
|
|
33
|
+
toPrice,
|
|
34
|
+
toDecimals
|
|
35
|
+
);
|
|
36
|
+
(0, import_vitest.expect)(result.amountInTarget).toBe(0n);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_chain_phantom_tokens_exports = {};
|
|
20
|
+
__export(get_chain_phantom_tokens_exports, {
|
|
21
|
+
getChainPhantomTokens: () => getChainPhantomTokens
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_chain_phantom_tokens_exports);
|
|
24
|
+
function getChainPhantomTokens(config) {
|
|
25
|
+
const allConfigs = Object.values(config || {}).flat(1);
|
|
26
|
+
const r = allConfigs.reduce((acc, cfg) => {
|
|
27
|
+
acc[cfg.withdrawalPhantomToken] = true;
|
|
28
|
+
return acc;
|
|
29
|
+
}, {});
|
|
30
|
+
return r;
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
getChainPhantomTokens
|
|
35
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_list_with_amount_in_target_exports = {};
|
|
20
|
+
__export(get_list_with_amount_in_target_exports, {
|
|
21
|
+
getListWithAmountInTarget: () => getListWithAmountInTarget
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_list_with_amount_in_target_exports);
|
|
24
|
+
var import_add_amount_in_target = require("./add-amount-in-target.js");
|
|
25
|
+
function getListWithAmountInTarget({
|
|
26
|
+
assets,
|
|
27
|
+
targetToken,
|
|
28
|
+
prices,
|
|
29
|
+
tokensList
|
|
30
|
+
}) {
|
|
31
|
+
const { decimals: toDecimals = 18 } = tokensList[targetToken] || {};
|
|
32
|
+
const toPrice = prices[targetToken] || 0n;
|
|
33
|
+
const withAmount = assets.map((asset) => {
|
|
34
|
+
const a = (0, import_add_amount_in_target.addAmountInTarget)(asset, tokensList, prices, toPrice, toDecimals);
|
|
35
|
+
return a;
|
|
36
|
+
});
|
|
37
|
+
return withAmount;
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
getListWithAmountInTarget
|
|
42
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_test_utils = require("../../../test-utils/index.js");
|
|
4
|
+
var import_assets = require("../assets/assets.js");
|
|
5
|
+
var import_get_list_with_amount_in_target = require("./get-list-with-amount-in-target.js");
|
|
6
|
+
(0, import_vitest.describe)("getListWithAmountInTarget", () => {
|
|
7
|
+
const targetToken = import_test_utils.mockToken2;
|
|
8
|
+
(0, import_vitest.it)("converts multiple assets to target token using prices", () => {
|
|
9
|
+
const assets = [
|
|
10
|
+
{ ...(0, import_assets.getDefaultAsset)(import_test_utils.mockToken1), balance: 10n ** 18n },
|
|
11
|
+
{ ...(0, import_assets.getDefaultAsset)(import_test_utils.mockToken2), balance: 10n ** 18n }
|
|
12
|
+
];
|
|
13
|
+
const result = (0, import_get_list_with_amount_in_target.getListWithAmountInTarget)({
|
|
14
|
+
assets,
|
|
15
|
+
targetToken,
|
|
16
|
+
prices: import_test_utils.mockPrices,
|
|
17
|
+
tokensList: import_test_utils.mockTokenData
|
|
18
|
+
});
|
|
19
|
+
(0, import_vitest.expect)(result).toHaveLength(2);
|
|
20
|
+
(0, import_vitest.expect)(result[0].amountInTarget).toBe(1500000000000000000n);
|
|
21
|
+
(0, import_vitest.expect)(result[1].amountInTarget).toBe(1000000000000000000n);
|
|
22
|
+
});
|
|
23
|
+
(0, import_vitest.it)("returns empty array for empty assets", () => {
|
|
24
|
+
const result = (0, import_get_list_with_amount_in_target.getListWithAmountInTarget)({
|
|
25
|
+
assets: [],
|
|
26
|
+
targetToken,
|
|
27
|
+
prices: import_test_utils.mockPrices,
|
|
28
|
+
tokensList: import_test_utils.mockTokenData
|
|
29
|
+
});
|
|
30
|
+
(0, import_vitest.expect)(result).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_native_token_address_exports = {};
|
|
20
|
+
__export(get_native_token_address_exports, {
|
|
21
|
+
getNativeTokenAddress: () => getNativeTokenAddress
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_native_token_address_exports);
|
|
24
|
+
const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".toLowerCase();
|
|
25
|
+
function getNativeTokenAddress() {
|
|
26
|
+
return NATIVE_ADDRESS;
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
getNativeTokenAddress
|
|
31
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var is_apy_with_points_exception_exports = {};
|
|
20
|
+
__export(is_apy_with_points_exception_exports, {
|
|
21
|
+
RST_ETH_ADDRESS: () => RST_ETH_ADDRESS,
|
|
22
|
+
isApyWithPointsException: () => isApyWithPointsException
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(is_apy_with_points_exception_exports);
|
|
25
|
+
const RST_ETH_ADDRESS = "0x7a4EffD87C2f3C55CA251080b1343b605f327E3a".toLowerCase();
|
|
26
|
+
const SHOW_APY_FOR_TOKENS_WITH_POINTS = {
|
|
27
|
+
[RST_ETH_ADDRESS]: RST_ETH_ADDRESS
|
|
28
|
+
};
|
|
29
|
+
function isApyWithPointsException(token) {
|
|
30
|
+
return !!SHOW_APY_FOR_TOKENS_WITH_POINTS[(token || "").toLowerCase()];
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
RST_ETH_ADDRESS,
|
|
35
|
+
isApyWithPointsException
|
|
36
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var is_collateral_token_exports = {};
|
|
20
|
+
__export(is_collateral_token_exports, {
|
|
21
|
+
isCollateralToken: () => isCollateralToken
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(is_collateral_token_exports);
|
|
24
|
+
var import_is_obtainable_token = require("./is-obtainable-token.js");
|
|
25
|
+
var import_is_valid_extra_collateral_token = require("./is-valid-extra-collateral-token.js");
|
|
26
|
+
function isCollateralToken({
|
|
27
|
+
address,
|
|
28
|
+
tokensList,
|
|
29
|
+
creditManager,
|
|
30
|
+
zeroDebt = false,
|
|
31
|
+
delayedPhantoms,
|
|
32
|
+
extraCollateralConfigs,
|
|
33
|
+
prices
|
|
34
|
+
}) {
|
|
35
|
+
if (creditManager && address === creditManager.underlyingToken) return true;
|
|
36
|
+
if (zeroDebt && creditManager) return false;
|
|
37
|
+
const token = tokensList[address];
|
|
38
|
+
const cmCheckPassed = (0, import_is_obtainable_token.isObtainableToken)({
|
|
39
|
+
address,
|
|
40
|
+
creditManager,
|
|
41
|
+
delayedPhantoms
|
|
42
|
+
});
|
|
43
|
+
const { isPhantom = false } = token || {};
|
|
44
|
+
const allowedAsMain = !isPhantom && cmCheckPassed;
|
|
45
|
+
const allowedAsExtra = (0, import_is_valid_extra_collateral_token.isValidExtraCollateralToken)({
|
|
46
|
+
address,
|
|
47
|
+
extraCollateralConfigs,
|
|
48
|
+
creditManager,
|
|
49
|
+
delayedPhantoms,
|
|
50
|
+
tokensList,
|
|
51
|
+
zeroDebt,
|
|
52
|
+
prices
|
|
53
|
+
});
|
|
54
|
+
return allowedAsMain || allowedAsExtra;
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
isCollateralToken
|
|
59
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_vitest = require("vitest");
|
|
3
|
+
var import_test_utils = require("../../../test-utils/index.js");
|
|
4
|
+
var import_is_collateral_token = require("./is-collateral-token.js");
|
|
5
|
+
const buildAllPrices = (_, token, value = 100n) => {
|
|
6
|
+
return {
|
|
7
|
+
[token]: value
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
(0, import_vitest.describe)("isCollateralToken", () => {
|
|
11
|
+
const underlying = "0xunderlying";
|
|
12
|
+
const token = "0xtoken";
|
|
13
|
+
const tokensList = {
|
|
14
|
+
[token]: (0, import_test_utils.buildTokenData)(token, "TOKEN")
|
|
15
|
+
};
|
|
16
|
+
const baseCM = (0, import_test_utils.buildCreditManager)({
|
|
17
|
+
underlyingToken: underlying,
|
|
18
|
+
quotas: {}
|
|
19
|
+
});
|
|
20
|
+
(0, import_vitest.it)("returns true for underlying token", () => {
|
|
21
|
+
const result = (0, import_is_collateral_token.isCollateralToken)({
|
|
22
|
+
address: underlying,
|
|
23
|
+
tokensList,
|
|
24
|
+
creditManager: baseCM,
|
|
25
|
+
zeroDebt: false,
|
|
26
|
+
delayedPhantoms: {},
|
|
27
|
+
extraCollateralConfigs: void 0,
|
|
28
|
+
prices: void 0
|
|
29
|
+
});
|
|
30
|
+
(0, import_vitest.expect)(result).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
(0, import_vitest.it)("returns false when zeroDebt is true", () => {
|
|
33
|
+
const result = (0, import_is_collateral_token.isCollateralToken)({
|
|
34
|
+
address: token,
|
|
35
|
+
tokensList,
|
|
36
|
+
creditManager: baseCM,
|
|
37
|
+
zeroDebt: true,
|
|
38
|
+
delayedPhantoms: {},
|
|
39
|
+
extraCollateralConfigs: void 0,
|
|
40
|
+
prices: void 0
|
|
41
|
+
});
|
|
42
|
+
(0, import_vitest.expect)(result).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
(0, import_vitest.it)("returns false when cm check fails", () => {
|
|
45
|
+
const result = (0, import_is_collateral_token.isCollateralToken)({
|
|
46
|
+
address: token,
|
|
47
|
+
tokensList,
|
|
48
|
+
creditManager: baseCM,
|
|
49
|
+
zeroDebt: false,
|
|
50
|
+
delayedPhantoms: {},
|
|
51
|
+
extraCollateralConfigs: void 0,
|
|
52
|
+
prices: void 0
|
|
53
|
+
});
|
|
54
|
+
(0, import_vitest.expect)(result).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
(0, import_vitest.it)("returns true when not obtainable but listed as extra collateral for cm and has price", () => {
|
|
57
|
+
const result = (0, import_is_collateral_token.isCollateralToken)({
|
|
58
|
+
address: token,
|
|
59
|
+
tokensList,
|
|
60
|
+
creditManager: baseCM,
|
|
61
|
+
zeroDebt: false,
|
|
62
|
+
delayedPhantoms: {},
|
|
63
|
+
extraCollateralConfigs: [{ token, cm: baseCM.address }],
|
|
64
|
+
prices: buildAllPrices(baseCM, token)
|
|
65
|
+
});
|
|
66
|
+
(0, import_vitest.expect)(result).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
(0, import_vitest.it)("returns false when not obtainable but listed as extra collateral for cm and has no price", () => {
|
|
69
|
+
const zeroPriceResult = (0, import_is_collateral_token.isCollateralToken)({
|
|
70
|
+
address: token,
|
|
71
|
+
tokensList,
|
|
72
|
+
creditManager: baseCM,
|
|
73
|
+
zeroDebt: false,
|
|
74
|
+
delayedPhantoms: {},
|
|
75
|
+
extraCollateralConfigs: [{ token, cm: baseCM.address }],
|
|
76
|
+
prices: buildAllPrices(baseCM, token, 0n)
|
|
77
|
+
});
|
|
78
|
+
(0, import_vitest.expect)(zeroPriceResult).toBe(false);
|
|
79
|
+
const undefinedPriceResult = (0, import_is_collateral_token.isCollateralToken)({
|
|
80
|
+
address: token,
|
|
81
|
+
tokensList,
|
|
82
|
+
creditManager: baseCM,
|
|
83
|
+
zeroDebt: false,
|
|
84
|
+
delayedPhantoms: {},
|
|
85
|
+
extraCollateralConfigs: [{ token, cm: baseCM.address }],
|
|
86
|
+
prices: void 0
|
|
87
|
+
});
|
|
88
|
+
(0, import_vitest.expect)(undefinedPriceResult).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
(0, import_vitest.it)("returns false when extra collateral config targets different credit manager", () => {
|
|
91
|
+
const result = (0, import_is_collateral_token.isCollateralToken)({
|
|
92
|
+
address: token,
|
|
93
|
+
tokensList,
|
|
94
|
+
creditManager: baseCM,
|
|
95
|
+
zeroDebt: false,
|
|
96
|
+
delayedPhantoms: {},
|
|
97
|
+
extraCollateralConfigs: [{ token, cm: "0xother" }],
|
|
98
|
+
prices: buildAllPrices(baseCM, token)
|
|
99
|
+
});
|
|
100
|
+
(0, import_vitest.expect)(result).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
(0, import_vitest.it)("returns false when token is phantom", () => {
|
|
103
|
+
const phantomTokenList = {
|
|
104
|
+
[token]: (0, import_test_utils.buildTokenData)(token, "TOKEN", 18, true)
|
|
105
|
+
};
|
|
106
|
+
const result = (0, import_is_collateral_token.isCollateralToken)({
|
|
107
|
+
address: token,
|
|
108
|
+
tokensList: phantomTokenList,
|
|
109
|
+
creditManager: baseCM,
|
|
110
|
+
zeroDebt: false,
|
|
111
|
+
delayedPhantoms: {},
|
|
112
|
+
extraCollateralConfigs: void 0,
|
|
113
|
+
prices: void 0
|
|
114
|
+
});
|
|
115
|
+
(0, import_vitest.expect)(result).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
(0, import_vitest.it)("returns true when obtainable, non-phantom, not underlying", () => {
|
|
118
|
+
const cmWithSupportedToken = (0, import_test_utils.buildCreditManager)({
|
|
119
|
+
underlyingToken: underlying,
|
|
120
|
+
supportedTokens: { [token]: true },
|
|
121
|
+
liquidationThresholds: { [token]: 8000n },
|
|
122
|
+
quotas: {}
|
|
123
|
+
});
|
|
124
|
+
const result = (0, import_is_collateral_token.isCollateralToken)({
|
|
125
|
+
address: token,
|
|
126
|
+
tokensList,
|
|
127
|
+
creditManager: cmWithSupportedToken,
|
|
128
|
+
zeroDebt: false,
|
|
129
|
+
delayedPhantoms: {},
|
|
130
|
+
extraCollateralConfigs: void 0,
|
|
131
|
+
prices: void 0
|
|
132
|
+
});
|
|
133
|
+
(0, import_vitest.expect)(result).toBe(true);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var is_obtainable_token_exports = {};
|
|
20
|
+
__export(is_obtainable_token_exports, {
|
|
21
|
+
isObtainableToken: () => isObtainableToken
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(is_obtainable_token_exports);
|
|
24
|
+
var import_is_usable_token = require("../../strategies/tokens/is-usable-token.js");
|
|
25
|
+
function isObtainableToken({
|
|
26
|
+
address,
|
|
27
|
+
creditManager,
|
|
28
|
+
delayedPhantoms
|
|
29
|
+
}) {
|
|
30
|
+
const {
|
|
31
|
+
isActive,
|
|
32
|
+
limit = 0n,
|
|
33
|
+
totalQuoted = 0n
|
|
34
|
+
} = creditManager.quotas[address] || {};
|
|
35
|
+
const realLimit = isActive ? limit || 0n : 0n;
|
|
36
|
+
const quotaLeft = realLimit - totalQuoted;
|
|
37
|
+
return (creditManager.isQuoted(address) ? quotaLeft > 0 : true) && (0, import_is_usable_token.isUsableToken)({ address, creditManager }) && !delayedPhantoms[address];
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
isObtainableToken
|
|
42
|
+
});
|