@gearbox-protocol/sdk 2.1.34 → 3.0.0-next.2
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/lib/apy/convexAPY.d.ts +4 -6
- package/lib/apy/convexAPY.js +15 -16
- package/lib/apy/curveAPY.d.ts +2 -2
- package/lib/apy/curveAPY.js +3 -4
- package/lib/apy/index.d.ts +1 -1
- package/lib/apy/index.js +2 -2
- package/lib/apy/lidoAPY.js +2 -2
- package/lib/apy/yearnAPY.d.ts +1 -1
- package/lib/apy/yearnAPY.js +3 -5
- package/lib/contracts/contractsRegister.d.ts +1 -1
- package/lib/contracts/contractsRegister.js +6 -7
- package/lib/core/creditAccount.js +20 -22
- package/lib/core/creditAccount.spec.js +32 -34
- package/lib/core/creditManager.js +16 -17
- package/lib/core/creditSession.js +12 -13
- package/lib/core/events.js +34 -35
- package/lib/core/pool/data.js +22 -23
- package/lib/core/priceOracle.js +3 -3
- package/lib/core/rewardClaimer.d.ts +1 -3
- package/lib/core/rewardConvex.d.ts +1 -4
- package/lib/core/rewardConvex.js +7 -10
- package/lib/core/rewardConvex.spec.js +15 -16
- package/lib/core/strategy.js +14 -16
- package/lib/core/strategy.spec.js +20 -22
- package/lib/core/trade.d.ts +1 -1
- package/lib/core/trade.js +12 -15
- package/lib/core/transactions.d.ts +1 -1
- package/lib/core/transactions.js +18 -20
- package/lib/index.d.ts +2 -20
- package/lib/index.js +27 -24
- package/lib/parsers/ERC20Parser.d.ts +1 -1
- package/lib/parsers/abstractParser.d.ts +1 -1
- package/lib/parsers/abstractParser.js +3 -4
- package/lib/parsers/convexBaseRewardPoolAdapterParser.d.ts +1 -1
- package/lib/parsers/convexBaseRewardPoolAdapterParser.js +2 -2
- package/lib/parsers/convexBaseRewardPoolAdapterParser.spec.js +4 -4
- package/lib/parsers/convexBoosterAdapterParser.d.ts +1 -1
- package/lib/parsers/convexBoosterAdapterParser.js +3 -3
- package/lib/parsers/convexBoosterAdapterParser.spec.js +3 -3
- package/lib/parsers/convextRewardPoolParser.d.ts +1 -1
- package/lib/parsers/creditFacadeParser.d.ts +1 -1
- package/lib/parsers/creditFacadeParser.spec.js +8 -9
- package/lib/parsers/curveAdapterParser.d.ts +1 -2
- package/lib/parsers/curveAdapterParser.js +5 -5
- package/lib/parsers/curveAdapterParser.spec.js +13 -13
- package/lib/parsers/lidoAdapterParser.d.ts +1 -1
- package/lib/parsers/lidoAdapterParser.spec.js +2 -2
- package/lib/parsers/lidoSTETHParser.d.ts +1 -1
- package/lib/parsers/txParser.d.ts +1 -3
- package/lib/parsers/txParser.js +12 -15
- package/lib/parsers/uniV2AdapterParser.d.ts +1 -1
- package/lib/parsers/uniV2AdapterParser.spec.js +15 -16
- package/lib/parsers/uniV3AdapterParser.d.ts +1 -1
- package/lib/parsers/uniV3AdapterParser.spec.js +15 -16
- package/lib/parsers/wstETHAdapterParser.d.ts +1 -1
- package/lib/parsers/wstETHAdapterParser.spec.js +3 -3
- package/lib/parsers/yearnAdapterParser.spec.js +12 -12
- package/lib/parsers/yearnV2AdapterParser.d.ts +1 -1
- package/lib/parsers/yearnV2AdapterParser.js +2 -2
- package/lib/pathfinder/pathOptions.d.ts +1 -2
- package/lib/pathfinder/pathOptions.js +12 -16
- package/lib/pathfinder/pathOptions.spec.js +36 -36
- package/lib/pathfinder/pathfinder.d.ts +1 -2
- package/lib/pathfinder/pathfinder.js +9 -10
- package/lib/pathfinder/pathfinder.spec.js +11 -12
- package/lib/payload/creditAccount.d.ts +1 -1
- package/lib/payload/creditManager.d.ts +1 -1
- package/lib/payload/pool.d.ts +1 -1
- package/lib/tokens/tokenData.d.ts +0 -4
- package/lib/tokens/tokenData.js +1 -16
- package/lib/utils/formatter.js +3 -3
- package/lib/utils/math.js +5 -5
- package/lib/utils/price.js +4 -4
- package/lib/watchers/creditAccountWatcher.js +2 -2
- package/lib/watchers/creditAccountWatcher.spec.js +18 -18
- package/lib/watchers/creditManagerWatcher.spec.js +19 -19
- package/package.json +2 -1
- package/lib/contracts/adapters.d.ts +0 -24
- package/lib/contracts/adapters.js +0 -28
- package/lib/contracts/contracts.d.ts +0 -112
- package/lib/contracts/contracts.js +0 -654
- package/lib/contracts/protocols.d.ts +0 -12
- package/lib/contracts/protocols.js +0 -16
- package/lib/contracts/utilsContracts.d.ts +0 -7
- package/lib/contracts/utilsContracts.js +0 -28
- package/lib/core/chains.d.ts +0 -23
- package/lib/core/chains.js +0 -63
- package/lib/core/constants.d.ts +0 -21
- package/lib/core/constants.js +0 -31
- package/lib/tokens/aave.d.ts +0 -20
- package/lib/tokens/aave.js +0 -62
- package/lib/tokens/balancer.d.ts +0 -12
- package/lib/tokens/balancer.js +0 -36
- package/lib/tokens/compound.d.ts +0 -11
- package/lib/tokens/compound.js +0 -38
- package/lib/tokens/convex.d.ts +0 -30
- package/lib/tokens/convex.js +0 -262
- package/lib/tokens/curveLP.d.ts +0 -27
- package/lib/tokens/curveLP.js +0 -141
- package/lib/tokens/decimals.d.ts +0 -2
- package/lib/tokens/decimals.js +0 -115
- package/lib/tokens/gear.d.ts +0 -14
- package/lib/tokens/gear.js +0 -47
- package/lib/tokens/normal.d.ts +0 -9
- package/lib/tokens/normal.js +0 -194
- package/lib/tokens/quoted.d.ts +0 -3
- package/lib/tokens/quoted.js +0 -7
- package/lib/tokens/token.d.ts +0 -25
- package/lib/tokens/token.js +0 -305
- package/lib/tokens/tokenType.d.ts +0 -15
- package/lib/tokens/tokenType.js +0 -19
- package/lib/tokens/tokens.spec.d.ts +0 -1
- package/lib/tokens/tokens.spec.js +0 -151
- package/lib/tokens/yearn.d.ts +0 -26
- package/lib/tokens/yearn.js +0 -52
- package/lib/utils/mappers.d.ts +0 -8
- package/lib/utils/mappers.js +0 -13
- package/lib/utils/multicall.d.ts +0 -36
- package/lib/utils/multicall.js +0 -90
- package/lib/utils/safeEnum.d.ts +0 -1
- package/lib/utils/safeEnum.js +0 -10
- package/lib/utils/types.d.ts +0 -10
- package/lib/utils/types.js +0 -2
package/lib/apy/convexAPY.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { ConvexPoolContract, ConvexPoolParams, CurveGEARPoolParams, CurveParams, CurveSteCRVPoolParams, MCall, NetworkType } from "@gearbox-protocol/sdk-gov";
|
|
2
|
+
import { CurveLPToken } from "@gearbox-protocol/sdk-gov/lib/tokens/curveLP";
|
|
3
|
+
import { SupportedToken } from "@gearbox-protocol/sdk-gov/lib/tokens/token";
|
|
1
4
|
import { BigNumber } from "ethers";
|
|
2
|
-
import { ConvexPoolContract, ConvexPoolParams, CurveGEARPoolParams, CurveParams, CurveSteCRVPoolParams } from "../contracts/contracts";
|
|
3
|
-
import { NetworkType } from "../core/chains";
|
|
4
|
-
import { CurveLPToken } from "../tokens/curveLP";
|
|
5
|
-
import { SupportedToken } from "../tokens/token";
|
|
6
|
-
import { MCall } from "../utils/multicall";
|
|
7
5
|
import { CurveAPYResult } from "./curveAPY";
|
|
8
6
|
type GetTokenPriceCallback = (tokenAddress: string, currency?: string) => bigint;
|
|
9
7
|
export interface GetConvexAPYBulkProps {
|
|
@@ -31,7 +29,7 @@ export interface GetConvexAPYBulkCallsProps {
|
|
|
31
29
|
}
|
|
32
30
|
export declare function getConvexAPYBulkCalls({ pools, networkType, }: GetConvexAPYBulkCallsProps): {
|
|
33
31
|
poolsInfo: PoolInfo[];
|
|
34
|
-
calls: [MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBaseRewardPool").IBaseRewardPoolInterface>, MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBaseRewardPool").IBaseRewardPoolInterface>, MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBaseRewardPool").IBaseRewardPoolInterface>, MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool").ICurvePoolInterface>, MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IConvexToken").IConvexTokenInterface>, ...(MCall<
|
|
32
|
+
calls: [MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBaseRewardPool").IBaseRewardPoolInterface>, MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBaseRewardPool").IBaseRewardPoolInterface>, MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBaseRewardPool").IBaseRewardPoolInterface>, MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool").ICurvePoolInterface>, MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IConvexToken").IConvexTokenInterface>, ...(MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBaseRewardPool").IBaseRewardPoolInterface> | MCall<any>)[]][];
|
|
35
33
|
};
|
|
36
34
|
export interface CalculateConvexAPYProps {
|
|
37
35
|
cvxPoolRate: bigint;
|
package/lib/apy/convexAPY.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCVXMintAmount = exports.getConvexAPYBulkCalls = exports.getConvexAPYBulk = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
|
+
const token_1 = require("@gearbox-protocol/sdk-gov/lib/tokens/token");
|
|
4
6
|
const utils_1 = require("ethers/lib/utils");
|
|
5
|
-
const contracts_1 = require("../contracts/contracts");
|
|
6
|
-
const constants_1 = require("../core/constants");
|
|
7
|
-
const token_1 = require("../tokens/token");
|
|
8
7
|
const types_1 = require("../types");
|
|
9
8
|
const formatter_1 = require("../utils/formatter");
|
|
10
9
|
const V2_POOLS = { 20: true };
|
|
@@ -44,15 +43,15 @@ function getConvexAPYBulk(props) {
|
|
|
44
43
|
exports.getConvexAPYBulk = getConvexAPYBulk;
|
|
45
44
|
function getPoolInfo({ pool, networkType }) {
|
|
46
45
|
const tokenList = token_1.tokenDataByNetwork[networkType];
|
|
47
|
-
const contractsList =
|
|
48
|
-
const poolParams =
|
|
46
|
+
const contractsList = sdk_gov_1.contractsByNetwork[networkType];
|
|
47
|
+
const poolParams = sdk_gov_1.contractParams[pool];
|
|
49
48
|
const basePoolAddress = contractsList[pool];
|
|
50
49
|
const extraPoolAddresses = poolParams.extraRewards.map(d => d.poolAddress[networkType]);
|
|
51
50
|
const stakedTokenParams = token_1.supportedTokens[poolParams.stakedToken];
|
|
52
51
|
const { underlying } = stakedTokenParams;
|
|
53
52
|
const crvParams = token_1.supportedTokens[underlying];
|
|
54
53
|
const swapPoolAddress = contractsList[crvParams.pool];
|
|
55
|
-
const crvPoolParams =
|
|
54
|
+
const crvPoolParams = sdk_gov_1.contractParams[crvParams.pool];
|
|
56
55
|
const crvLpPrice = V2_POOLS[crvPoolParams["version"]]
|
|
57
56
|
? [swapPoolAddress]
|
|
58
57
|
: [];
|
|
@@ -124,9 +123,9 @@ function getPoolDataCalls(props) {
|
|
|
124
123
|
];
|
|
125
124
|
return calls;
|
|
126
125
|
}
|
|
127
|
-
const CVX_MAX_SUPPLY =
|
|
126
|
+
const CVX_MAX_SUPPLY = sdk_gov_1.WAD * 100000000n;
|
|
128
127
|
const CVX_REDUCTION_PER_CLIFF = 100000n;
|
|
129
|
-
const CVX_TOTAL_CLIFFS =
|
|
128
|
+
const CVX_TOTAL_CLIFFS = sdk_gov_1.WAD * 1000n;
|
|
130
129
|
const CURRENCY_LIST = {
|
|
131
130
|
stkcvxsteCRV: "WETH",
|
|
132
131
|
stkcvxcrvCVXETH: "WETH",
|
|
@@ -143,21 +142,21 @@ function calculateConvexAPY(props) {
|
|
|
143
142
|
const crvPrice = props.getTokenPrice(tokenList.CRV, currency);
|
|
144
143
|
const crvPerSecond = props.cvxPoolRate;
|
|
145
144
|
const vPrice = getVirtualPrice(props);
|
|
146
|
-
const virtualSupply = (props.cvxPoolSupply * vPrice) /
|
|
147
|
-
const crvPerUnderlying = (crvPerSecond *
|
|
148
|
-
const crvPerYear = crvPerUnderlying * BigInt(
|
|
145
|
+
const virtualSupply = (props.cvxPoolSupply * vPrice) / sdk_gov_1.WAD;
|
|
146
|
+
const crvPerUnderlying = (crvPerSecond * sdk_gov_1.WAD) / virtualSupply;
|
|
147
|
+
const crvPerYear = crvPerUnderlying * BigInt(sdk_gov_1.SECONDS_PER_YEAR);
|
|
149
148
|
const cvxPerYear = getCVXMintAmount(crvPerYear, props.cvxTokenSupply);
|
|
150
149
|
const baseFinished = props.cvxPoolRewardsFinish <= currentTimestamp;
|
|
151
|
-
const crvAPY = baseFinished ? 0n : (crvPerYear * crvPrice) /
|
|
152
|
-
const cvxAPY = baseFinished ? 0n : (cvxPerYear * cvxPrice) /
|
|
150
|
+
const crvAPY = baseFinished ? 0n : (crvPerYear * crvPrice) / sdk_gov_1.PRICE_DECIMALS;
|
|
151
|
+
const cvxAPY = baseFinished ? 0n : (cvxPerYear * cvxPrice) / sdk_gov_1.PRICE_DECIMALS;
|
|
153
152
|
const extraAPRs = cvxExtraPools.map((_, index) => {
|
|
154
153
|
const extraRewardSymbol = cvxPool.extraRewards[index].rewardToken;
|
|
155
154
|
const extraPoolRate = props.cvxExtraRewards[index];
|
|
156
155
|
const extraFinished = props.cvxExtraRewardsFinish[index];
|
|
157
|
-
const perUnderlying = (extraPoolRate *
|
|
158
|
-
const perYear = perUnderlying * BigInt(
|
|
156
|
+
const perUnderlying = (extraPoolRate * sdk_gov_1.WAD) / virtualSupply;
|
|
157
|
+
const perYear = perUnderlying * BigInt(sdk_gov_1.SECONDS_PER_YEAR);
|
|
159
158
|
const extraPrice = props.getTokenPrice(tokenList[extraRewardSymbol], currency);
|
|
160
|
-
const extraAPY = (perYear * extraPrice) /
|
|
159
|
+
const extraAPY = (perYear * extraPrice) / sdk_gov_1.PRICE_DECIMALS;
|
|
161
160
|
const finished = extraFinished <= currentTimestamp;
|
|
162
161
|
return finished ? 0n : extraAPY;
|
|
163
162
|
});
|
package/lib/apy/curveAPY.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CurveLPToken } from "
|
|
2
|
-
import { GearboxToken } from "
|
|
1
|
+
import { CurveLPToken } from "@gearbox-protocol/sdk-gov/lib/tokens/curveLP";
|
|
2
|
+
import { GearboxToken } from "@gearbox-protocol/sdk-gov/lib/tokens/gear";
|
|
3
3
|
type CurveAPYTokens = CurveLPToken | GearboxToken;
|
|
4
4
|
interface CurveAPY {
|
|
5
5
|
base: bigint;
|
package/lib/apy/curveAPY.js
CHANGED
|
@@ -4,10 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getCurveAPY = void 0;
|
|
7
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
7
8
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const constants_1 = require("../core/constants");
|
|
9
9
|
const formatter_1 = require("../utils/formatter");
|
|
10
|
-
const mappers_1 = require("../utils/mappers");
|
|
11
10
|
const APY_DICTIONARY = {
|
|
12
11
|
"3Crv": "0",
|
|
13
12
|
FRAX3CRV: "34",
|
|
@@ -54,7 +53,7 @@ async function getCurveAPY() {
|
|
|
54
53
|
return poolData.map(p => [p.id, p]);
|
|
55
54
|
})
|
|
56
55
|
.flat(1));
|
|
57
|
-
const curveAPY =
|
|
56
|
+
const curveAPY = sdk_gov_1.TypedObjectUtils.entries(APY_DICTIONARY).reduce((acc, [curveSymbol, poolId]) => {
|
|
58
57
|
const { baseApy, crvApy } = apys[poolId] || {};
|
|
59
58
|
if (baseApy === undefined)
|
|
60
59
|
console.warn(`No base apy for: ${curveSymbol}, ${poolId}`);
|
|
@@ -83,5 +82,5 @@ async function getCurveAPY() {
|
|
|
83
82
|
}
|
|
84
83
|
exports.getCurveAPY = getCurveAPY;
|
|
85
84
|
function curveAPYToBn(baseApy) {
|
|
86
|
-
return (0, formatter_1.toBN)((baseApy / CRV_APY_RESPONSE_DECIMALS).toString(),
|
|
85
|
+
return (0, formatter_1.toBN)((baseApy / CRV_APY_RESPONSE_DECIMALS).toString(), sdk_gov_1.WAD_DECIMALS_POW);
|
|
87
86
|
}
|
package/lib/apy/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LPTokens, SupportedToken } from "
|
|
1
|
+
import { LPTokens, SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
2
2
|
export type AdditionalTokenWithAPY = Extract<SupportedToken, "STETH">;
|
|
3
3
|
export declare const additionalTokensWIthAPY: Record<AdditionalTokenWithAPY, true>;
|
|
4
4
|
export type TokensWithAPY = LPTokens | Extract<SupportedToken, "STETH">;
|
package/lib/apy/index.js
CHANGED
|
@@ -15,12 +15,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.isTokenWithAPY = exports.additionalTokensWIthAPY = void 0;
|
|
18
|
-
const
|
|
18
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
19
19
|
exports.additionalTokensWIthAPY = {
|
|
20
20
|
STETH: true,
|
|
21
21
|
};
|
|
22
22
|
const isTokenWithAPY = (t) => typeof t === "string" &&
|
|
23
|
-
(!!
|
|
23
|
+
(!!sdk_gov_1.lpTokens[t] ||
|
|
24
24
|
!!exports.additionalTokensWIthAPY[t]);
|
|
25
25
|
exports.isTokenWithAPY = isTokenWithAPY;
|
|
26
26
|
__exportStar(require("./convexAPY"), exports);
|
package/lib/apy/lidoAPY.js
CHANGED
|
@@ -4,15 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getLidoAPY = void 0;
|
|
7
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
7
8
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const constants_1 = require("../core/constants");
|
|
9
9
|
const formatter_1 = require("../utils/formatter");
|
|
10
10
|
const LIDO_URL = "https://eth-api.lido.fi/v1/protocol/steth/apr/sma";
|
|
11
11
|
async function getLidoAPY() {
|
|
12
12
|
try {
|
|
13
13
|
const res = await axios_1.default.get(LIDO_URL);
|
|
14
14
|
const { smaApr = 0 } = res?.data?.data || {};
|
|
15
|
-
return (0, formatter_1.toBN)(String(smaApr),
|
|
15
|
+
return (0, formatter_1.toBN)(String(smaApr), sdk_gov_1.WAD_DECIMALS_POW) / sdk_gov_1.PERCENTAGE_DECIMALS;
|
|
16
16
|
}
|
|
17
17
|
catch (e) {
|
|
18
18
|
console.error(e);
|
package/lib/apy/yearnAPY.d.ts
CHANGED
package/lib/apy/yearnAPY.js
CHANGED
|
@@ -4,11 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getYearnAPY = void 0;
|
|
7
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
7
8
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const constants_1 = require("../core/constants");
|
|
9
|
-
const yearn_1 = require("../tokens/yearn");
|
|
10
9
|
const formatter_1 = require("../utils/formatter");
|
|
11
|
-
const mappers_1 = require("../utils/mappers");
|
|
12
10
|
const RESPONSE_DECIMALS = 1;
|
|
13
11
|
const URL = "https://api.yearn.finance/v1/chains/1/vaults/all";
|
|
14
12
|
const transformSymbol = (s) => s.replaceAll("_", "-").toLowerCase();
|
|
@@ -19,10 +17,10 @@ async function getYearnAPY() {
|
|
|
19
17
|
acc[d.symbol.toLowerCase()] = d;
|
|
20
18
|
return acc;
|
|
21
19
|
}, {});
|
|
22
|
-
const yearnAPY =
|
|
20
|
+
const yearnAPY = sdk_gov_1.TypedObjectUtils.entries(sdk_gov_1.yearnTokens).reduce((acc, [yearnSymbol]) => {
|
|
23
21
|
const { apy } = dataBySymbol[transformSymbol(yearnSymbol)] || {};
|
|
24
22
|
const { net_apy: netApy } = apy || {};
|
|
25
|
-
acc[yearnSymbol] = (0, formatter_1.toBN)((netApy / RESPONSE_DECIMALS).toString(),
|
|
23
|
+
acc[yearnSymbol] = (0, formatter_1.toBN)((netApy / RESPONSE_DECIMALS).toString(), sdk_gov_1.WAD_DECIMALS_POW);
|
|
26
24
|
return acc;
|
|
27
25
|
}, {});
|
|
28
26
|
return yearnAPY;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NetworkType } from "
|
|
1
|
+
import { NetworkType } from "@gearbox-protocol/sdk-gov";
|
|
2
2
|
export declare const stEthPoolWrapper: Record<NetworkType, string>;
|
|
3
3
|
type MainnetCreditManagersV1 = "DAI_V1" | "USDC_V1" | "WETH_V1" | "WBTC_V1";
|
|
4
4
|
type MainnetCreditManagersV2 = "DAI_V2" | "USDC_V2" | "WETH_V2" | "WSTETH_V2" | "WBTC_V2" | "FRAX_V2";
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getContractName = exports.poolByNetwork = exports.creditManagerByAddress = exports.creditManagerByNetwork = exports.stEthPoolWrapper = void 0;
|
|
4
|
-
const
|
|
5
|
-
const contracts_1 = require("./contracts");
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
6
5
|
exports.stEthPoolWrapper = {
|
|
7
6
|
Mainnet: "0x5a97e3E43dCBFe620ccF7865739075f92E93F5E4",
|
|
8
7
|
Arbitrum: "0x3fe62a62C022A069952069b32C9d56718D30B7ec",
|
|
@@ -23,9 +22,9 @@ exports.creditManagerByNetwork = {
|
|
|
23
22
|
},
|
|
24
23
|
Arbitrum: {},
|
|
25
24
|
};
|
|
26
|
-
exports.creditManagerByAddress =
|
|
25
|
+
exports.creditManagerByAddress = sdk_gov_1.TypedObjectUtils.entries(exports.creditManagerByNetwork).reduce((acc, [, cms]) => ({
|
|
27
26
|
...acc,
|
|
28
|
-
...
|
|
27
|
+
...sdk_gov_1.TypedObjectUtils.fromEntries(sdk_gov_1.TypedObjectUtils.entries(cms)
|
|
29
28
|
.map(([k, v]) => [v.toLowerCase(), k])
|
|
30
29
|
.filter(k => !!k)),
|
|
31
30
|
}), {});
|
|
@@ -63,14 +62,14 @@ const deployedContractNames = {
|
|
|
63
62
|
[exports.poolByNetwork.Mainnet.WSTETH_V1]: "wstETH",
|
|
64
63
|
[exports.poolByNetwork.Mainnet.FRAX_V1]: "FRAX",
|
|
65
64
|
};
|
|
66
|
-
const contractNames = Object.entries(
|
|
67
|
-
const params =
|
|
65
|
+
const contractNames = Object.entries(sdk_gov_1.contractsByAddress).reduce((acc, [addr, cSymbol]) => {
|
|
66
|
+
const params = sdk_gov_1.contractParams[cSymbol];
|
|
68
67
|
if (!params)
|
|
69
68
|
return acc;
|
|
70
69
|
return { ...acc, [addr]: params.name };
|
|
71
70
|
}, {});
|
|
72
71
|
const contractsFullList = {
|
|
73
|
-
...
|
|
72
|
+
...sdk_gov_1.TypedObjectUtils.keyToLowercase(deployedContractNames),
|
|
74
73
|
...contractNames,
|
|
75
74
|
};
|
|
76
75
|
function getContractName(address) {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreditAccountData = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
4
5
|
const apy_1 = require("../apy");
|
|
5
|
-
const decimals_1 = require("../tokens/decimals");
|
|
6
|
-
const token_1 = require("../tokens/token");
|
|
7
6
|
const formatter_1 = require("../utils/formatter");
|
|
8
7
|
const price_1 = require("../utils/price");
|
|
9
|
-
const constants_1 = require("./constants");
|
|
10
8
|
class CreditAccountData {
|
|
11
9
|
addr;
|
|
12
10
|
borrower;
|
|
@@ -47,9 +45,9 @@ class CreditAccountData {
|
|
|
47
45
|
this.totalValue = (0, formatter_1.toBigInt)(payload.totalValue || 0);
|
|
48
46
|
this.healthFactor = payload.healthFactor.toNumber();
|
|
49
47
|
this.borrowRate = Number(((0, formatter_1.toBigInt)(payload.borrowRate || 0) *
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
sdk_gov_1.PERCENTAGE_FACTOR *
|
|
49
|
+
sdk_gov_1.PERCENTAGE_DECIMALS) /
|
|
50
|
+
sdk_gov_1.RAY);
|
|
53
51
|
payload.balances.forEach(b => {
|
|
54
52
|
const tokenLC = b.token.toLowerCase();
|
|
55
53
|
if (b.isAllowed) {
|
|
@@ -78,8 +76,8 @@ class CreditAccountData {
|
|
|
78
76
|
const addr2Lc = addr2.toLowerCase();
|
|
79
77
|
const token1 = tokens[addr1Lc];
|
|
80
78
|
const token2 = tokens[addr2Lc];
|
|
81
|
-
const price1 = prices[addr1Lc] ||
|
|
82
|
-
const price2 = prices[addr2Lc] ||
|
|
79
|
+
const price1 = prices[addr1Lc] || sdk_gov_1.PRICE_DECIMALS;
|
|
80
|
+
const price2 = prices[addr2Lc] || sdk_gov_1.PRICE_DECIMALS;
|
|
83
81
|
const totalPrice1 = price_1.PriceUtils.calcTotalPrice(price1, amount1, token1?.decimals);
|
|
84
82
|
const totalPrice2 = price_1.PriceUtils.calcTotalPrice(price2, amount2, token2?.decimals);
|
|
85
83
|
if (totalPrice1 === totalPrice2) {
|
|
@@ -117,7 +115,7 @@ class CreditAccountData {
|
|
|
117
115
|
static isTokenEnabled(index, enabledTokenMask) {
|
|
118
116
|
return ((2n ** BigInt(index)) & enabledTokenMask) !== 0n;
|
|
119
117
|
}
|
|
120
|
-
static calcMaxDebtIncrease(healthFactor, borrowAmountPlusInterest, underlyingLT, minHf = Number(
|
|
118
|
+
static calcMaxDebtIncrease(healthFactor, borrowAmountPlusInterest, underlyingLT, minHf = Number(sdk_gov_1.PERCENTAGE_FACTOR)) {
|
|
121
119
|
const result = (borrowAmountPlusInterest * BigInt(healthFactor - minHf)) /
|
|
122
120
|
BigInt(minHf - underlyingLT);
|
|
123
121
|
return result < 0 ? 0n : result;
|
|
@@ -131,30 +129,30 @@ class CreditAccountData {
|
|
|
131
129
|
return undefined;
|
|
132
130
|
const assetAPYMoney = caAssets.reduce((acc, { token: tokenAddress, balance: amount }) => {
|
|
133
131
|
const tokenAddressLC = tokenAddress.toLowerCase();
|
|
134
|
-
const symbol =
|
|
132
|
+
const symbol = sdk_gov_1.tokenSymbolByAddress[tokenAddressLC];
|
|
135
133
|
if (!(0, apy_1.isTokenWithAPY)(symbol))
|
|
136
134
|
return acc;
|
|
137
135
|
const apy = lpAPY[symbol] || 0;
|
|
138
136
|
const price = prices[tokenAddressLC] || 0n;
|
|
139
|
-
const tokenDecimals =
|
|
137
|
+
const tokenDecimals = sdk_gov_1.decimals[symbol];
|
|
140
138
|
const money = price_1.PriceUtils.calcTotalPrice(price, amount, tokenDecimals);
|
|
141
139
|
const apyMoney = money * BigInt(apy);
|
|
142
140
|
return acc + apyMoney;
|
|
143
141
|
}, 0n);
|
|
144
142
|
const underlyingTokenAddressLC = underlyingToken.toLowerCase();
|
|
145
|
-
const underlyingTokenSymbol =
|
|
146
|
-
const underlyingTokenDecimals =
|
|
147
|
-
const underlyingPrice = prices[underlyingTokenAddressLC] ||
|
|
143
|
+
const underlyingTokenSymbol = sdk_gov_1.tokenSymbolByAddress[underlyingTokenAddressLC] || "";
|
|
144
|
+
const underlyingTokenDecimals = sdk_gov_1.decimals[underlyingTokenSymbol] || 18;
|
|
145
|
+
const underlyingPrice = prices[underlyingTokenAddressLC] || sdk_gov_1.PRICE_DECIMALS;
|
|
148
146
|
const assetAPYAmountInUnderlying = price_1.PriceUtils.convertByPrice(assetAPYMoney, {
|
|
149
147
|
price: underlyingPrice,
|
|
150
148
|
decimals: underlyingTokenDecimals,
|
|
151
149
|
});
|
|
152
150
|
const debtAPY = debt * BigInt(borrowRate);
|
|
153
151
|
const yourAssets = totalValue - debt;
|
|
154
|
-
const apyInPercent = ((assetAPYAmountInUnderlying - debtAPY) *
|
|
152
|
+
const apyInPercent = ((assetAPYAmountInUnderlying - debtAPY) * sdk_gov_1.WAD) /
|
|
155
153
|
yourAssets /
|
|
156
|
-
|
|
157
|
-
return Number((0, formatter_1.toSignificant)(apyInPercent,
|
|
154
|
+
sdk_gov_1.PERCENTAGE_FACTOR;
|
|
155
|
+
return Number((0, formatter_1.toSignificant)(apyInPercent, sdk_gov_1.WAD_DECIMALS_POW));
|
|
158
156
|
}
|
|
159
157
|
hash() {
|
|
160
158
|
return CreditAccountData.hash(this.creditManager, this.borrower);
|
|
@@ -164,17 +162,17 @@ class CreditAccountData {
|
|
|
164
162
|
}
|
|
165
163
|
static calcHealthFactor({ assets, prices, liquidationThresholds, underlyingToken, borrowed, }) {
|
|
166
164
|
const assetLTMoney = assets.reduce((acc, { token: tokenAddress, balance: amount }) => {
|
|
167
|
-
const tokenSymbol =
|
|
168
|
-
const tokenDecimals =
|
|
165
|
+
const tokenSymbol = sdk_gov_1.tokenSymbolByAddress[tokenAddress.toLowerCase()];
|
|
166
|
+
const tokenDecimals = sdk_gov_1.decimals[tokenSymbol];
|
|
169
167
|
const lt = liquidationThresholds[tokenAddress.toLowerCase()] || 0n;
|
|
170
168
|
const price = prices[tokenAddress.toLowerCase()] || 0n;
|
|
171
169
|
const money = price_1.PriceUtils.calcTotalPrice(price, amount, tokenDecimals);
|
|
172
170
|
const ltMoney = money * lt;
|
|
173
171
|
return acc + ltMoney;
|
|
174
172
|
}, 0n);
|
|
175
|
-
const underlyingSymbol =
|
|
176
|
-
const underlyingDecimals =
|
|
177
|
-
const underlyingPrice = prices[underlyingToken.toLowerCase()] ||
|
|
173
|
+
const underlyingSymbol = sdk_gov_1.tokenSymbolByAddress[underlyingToken.toLowerCase()];
|
|
174
|
+
const underlyingDecimals = sdk_gov_1.decimals[underlyingSymbol];
|
|
175
|
+
const underlyingPrice = prices[underlyingToken.toLowerCase()] || sdk_gov_1.PRICE_DECIMALS;
|
|
178
176
|
const borrowedMoney = price_1.PriceUtils.calcTotalPrice(underlyingPrice, borrowed, underlyingDecimals);
|
|
179
177
|
const hfInPercent = borrowedMoney > 0n ? assetLTMoney / borrowedMoney : 0n;
|
|
180
178
|
return Number(hfInPercent);
|
|
@@ -1,50 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
3
4
|
const chai_1 = require("chai");
|
|
4
|
-
const decimals_1 = require("../tokens/decimals");
|
|
5
|
-
const token_1 = require("../tokens/token");
|
|
6
5
|
const formatter_1 = require("../utils/formatter");
|
|
7
6
|
const price_1 = require("../utils/price");
|
|
8
7
|
const assets_1 = require("./assets");
|
|
9
|
-
const constants_1 = require("./constants");
|
|
10
8
|
const creditAccount_1 = require("./creditAccount");
|
|
11
9
|
const prices = {
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
10
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()]: (0, formatter_1.toBN)("1738.11830000", sdk_gov_1.PRICE_DECIMALS_POW),
|
|
11
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()]: (0, formatter_1.toBN)("0.99941103", sdk_gov_1.PRICE_DECIMALS_POW),
|
|
12
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH.toLowerCase()]: (0, formatter_1.toBN)("1703.87588096", sdk_gov_1.PRICE_DECIMALS_POW),
|
|
15
13
|
};
|
|
16
14
|
const lpAPY = { STETH: 38434 };
|
|
17
15
|
const caWithoutLP = {
|
|
18
16
|
assets: [
|
|
19
17
|
{
|
|
20
|
-
balance: (0, formatter_1.toBN)("54780",
|
|
21
|
-
token:
|
|
18
|
+
balance: (0, formatter_1.toBN)("54780", sdk_gov_1.decimals.DAI),
|
|
19
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase(),
|
|
22
20
|
},
|
|
23
21
|
{
|
|
24
|
-
balance: (0, formatter_1.toBN)("3.5",
|
|
25
|
-
token:
|
|
22
|
+
balance: (0, formatter_1.toBN)("3.5", sdk_gov_1.decimals.WETH),
|
|
23
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase(),
|
|
26
24
|
},
|
|
27
25
|
],
|
|
28
|
-
totalValue: (0, formatter_1.toBN)("60860",
|
|
29
|
-
debt: (0, formatter_1.toBN)("54780",
|
|
26
|
+
totalValue: (0, formatter_1.toBN)("60860", sdk_gov_1.decimals.DAI),
|
|
27
|
+
debt: (0, formatter_1.toBN)("54780", sdk_gov_1.decimals.DAI),
|
|
30
28
|
borrowRate: 7712,
|
|
31
|
-
underlyingToken:
|
|
29
|
+
underlyingToken: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase(),
|
|
32
30
|
};
|
|
33
31
|
const caWithLP = {
|
|
34
32
|
assets: [
|
|
35
33
|
{
|
|
36
|
-
balance: (0, formatter_1.toBN)("119.999999999999999997",
|
|
37
|
-
token:
|
|
34
|
+
balance: (0, formatter_1.toBN)("119.999999999999999997", sdk_gov_1.decimals.STETH),
|
|
35
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.STETH.toLowerCase(),
|
|
38
36
|
},
|
|
39
37
|
{
|
|
40
|
-
balance: (0, formatter_1.toBN)("3.5",
|
|
41
|
-
token:
|
|
38
|
+
balance: (0, formatter_1.toBN)("3.5", sdk_gov_1.decimals.WETH),
|
|
39
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase(),
|
|
42
40
|
},
|
|
43
41
|
],
|
|
44
|
-
totalValue: (0, formatter_1.toBN)("117.635897231615362429",
|
|
45
|
-
debt: (0, formatter_1.toBN)("90.000000000000000000",
|
|
42
|
+
totalValue: (0, formatter_1.toBN)("117.635897231615362429", sdk_gov_1.decimals.WETH),
|
|
43
|
+
debt: (0, formatter_1.toBN)("90.000000000000000000", sdk_gov_1.decimals.WETH),
|
|
46
44
|
borrowRate: 5736,
|
|
47
|
-
underlyingToken:
|
|
45
|
+
underlyingToken: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase(),
|
|
48
46
|
};
|
|
49
47
|
describe("CreditAccount CreditAccountData.calcOverallAPY test", () => {
|
|
50
48
|
it("overall APY calculation for caWithoutLP is correct", () => {
|
|
@@ -136,24 +134,24 @@ describe("CreditAccount calcMaxIncreaseBorrow test", () => {
|
|
|
136
134
|
});
|
|
137
135
|
});
|
|
138
136
|
const liquidationThresholds = {
|
|
139
|
-
[
|
|
140
|
-
[
|
|
137
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()]: 9300n,
|
|
138
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()]: 8500n,
|
|
141
139
|
};
|
|
142
140
|
const defaultCA = {
|
|
143
141
|
assets: [
|
|
144
142
|
{
|
|
145
|
-
balance: (0, formatter_1.toBN)("156552",
|
|
146
|
-
token:
|
|
143
|
+
balance: (0, formatter_1.toBN)("156552", sdk_gov_1.decimals.DAI),
|
|
144
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase(),
|
|
147
145
|
},
|
|
148
146
|
{
|
|
149
|
-
balance: (0, formatter_1.toBN)("10",
|
|
150
|
-
token:
|
|
147
|
+
balance: (0, formatter_1.toBN)("10", sdk_gov_1.decimals.WETH),
|
|
148
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase(),
|
|
151
149
|
},
|
|
152
150
|
],
|
|
153
|
-
debt: (0, formatter_1.toBN)("156552",
|
|
151
|
+
debt: (0, formatter_1.toBN)("156552", sdk_gov_1.decimals.DAI),
|
|
154
152
|
healthFactor: 10244,
|
|
155
|
-
underlyingToken:
|
|
156
|
-
underlyingDecimals:
|
|
153
|
+
underlyingToken: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase(),
|
|
154
|
+
underlyingDecimals: sdk_gov_1.decimals.DAI,
|
|
157
155
|
};
|
|
158
156
|
describe("CreditManager calcHealthFactor test", () => {
|
|
159
157
|
it("health factor calculation is calculated correctly", () => {
|
|
@@ -178,8 +176,8 @@ describe("CreditManager calcHealthFactor test", () => {
|
|
|
178
176
|
});
|
|
179
177
|
it("health factor after add collateral is calculated correctly", () => {
|
|
180
178
|
const collateral = {
|
|
181
|
-
balance: (0, formatter_1.toBN)("10",
|
|
182
|
-
token:
|
|
179
|
+
balance: (0, formatter_1.toBN)("10", sdk_gov_1.decimals.WETH),
|
|
180
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase(),
|
|
183
181
|
};
|
|
184
182
|
const afterAdd = assets_1.AssetUtils.sumAssets(defaultCA.assets, [collateral]);
|
|
185
183
|
const result = creditAccount_1.CreditAccountData.calcHealthFactor({
|
|
@@ -233,11 +231,11 @@ describe("CreditManager calcHealthFactor test", () => {
|
|
|
233
231
|
token: defaultCA.underlyingToken,
|
|
234
232
|
};
|
|
235
233
|
const underlyingPrice = prices[defaultCA.underlyingToken];
|
|
236
|
-
const wethPrice = prices[
|
|
237
|
-
const getAmount = price_1.PriceUtils.convertByPrice(price_1.PriceUtils.calcTotalPrice(underlyingPrice, defaultCA.debt, defaultCA.underlyingDecimals), { price: wethPrice, decimals:
|
|
234
|
+
const wethPrice = prices[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()];
|
|
235
|
+
const getAmount = price_1.PriceUtils.convertByPrice(price_1.PriceUtils.calcTotalPrice(underlyingPrice, defaultCA.debt, defaultCA.underlyingDecimals), { price: wethPrice, decimals: sdk_gov_1.decimals.WETH });
|
|
238
236
|
const getAsset = {
|
|
239
237
|
balance: getAmount,
|
|
240
|
-
token:
|
|
238
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase(),
|
|
241
239
|
};
|
|
242
240
|
const afterSub = assets_1.AssetUtils.subAssets(defaultCA.assets, [swapAsset]);
|
|
243
241
|
const afterSwap = assets_1.AssetUtils.sumAssets(afterSub, [getAsset]);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChartsCreditManagerData = exports.CreditManagerData = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
4
5
|
const txParser_1 = require("../parsers/txParser");
|
|
5
|
-
const token_1 = require("../tokens/token");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
7
|
const formatter_1 = require("../utils/formatter");
|
|
8
|
-
const constants_1 = require("./constants");
|
|
9
8
|
const errors_1 = require("./errors");
|
|
10
9
|
class CreditManagerData {
|
|
11
10
|
address;
|
|
@@ -45,9 +44,9 @@ class CreditManagerData {
|
|
|
45
44
|
this.canBorrow = payload.canBorrow;
|
|
46
45
|
this.maxEnabledTokensLength = payload.maxEnabledTokensLength;
|
|
47
46
|
this.borrowRate = Number(((0, formatter_1.toBigInt)(payload.borrowRate || 0) *
|
|
48
|
-
((0, formatter_1.toBigInt)(payload.feeInterest || 0) +
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
((0, formatter_1.toBigInt)(payload.feeInterest || 0) + sdk_gov_1.PERCENTAGE_FACTOR) *
|
|
48
|
+
sdk_gov_1.PERCENTAGE_DECIMALS) /
|
|
49
|
+
sdk_gov_1.RAY);
|
|
51
50
|
this.minAmount = (0, formatter_1.toBigInt)(payload.minAmount || 0);
|
|
52
51
|
this.maxAmount = (0, formatter_1.toBigInt)(payload.maxAmount || 0);
|
|
53
52
|
this.maxLeverageFactor = Number((0, formatter_1.toBigInt)(payload.maxLeverageFactor || 0));
|
|
@@ -86,8 +85,8 @@ class CreditManagerData {
|
|
|
86
85
|
}
|
|
87
86
|
: undefined;
|
|
88
87
|
txParser_1.TxParser.addCreditManager(this.address, this.version);
|
|
89
|
-
if (this.creditFacade !== "" && this.creditFacade !==
|
|
90
|
-
txParser_1.TxParser.addCreditFacade(this.creditFacade,
|
|
88
|
+
if (this.creditFacade !== "" && this.creditFacade !== sdk_gov_1.ADDRESS_0X0) {
|
|
89
|
+
txParser_1.TxParser.addCreditFacade(this.creditFacade, sdk_gov_1.tokenSymbolByAddress[this.underlyingToken]);
|
|
91
90
|
txParser_1.TxParser.addAdapters(payload.adapters.map(a => ({
|
|
92
91
|
adapter: a.adapter,
|
|
93
92
|
contract: a.allowedContract,
|
|
@@ -156,7 +155,7 @@ class CreditManagerData {
|
|
|
156
155
|
throw new errors_1.OpenAccountError("amountLessMin", this.minAmount);
|
|
157
156
|
if (collateral > this.maxAmount)
|
|
158
157
|
throw new errors_1.OpenAccountError("amountGreaterMax", this.maxAmount);
|
|
159
|
-
const leverage = Number((debt *
|
|
158
|
+
const leverage = Number((debt * sdk_gov_1.LEVERAGE_DECIMALS) / collateral);
|
|
160
159
|
if (!leverage || leverage < 0)
|
|
161
160
|
throw new errors_1.OpenAccountError("wrongLeverage", 0n);
|
|
162
161
|
if (leverage > this.maxLeverageFactor)
|
|
@@ -231,14 +230,14 @@ class ChartsCreditManagerData {
|
|
|
231
230
|
this.version = payload.version || 2;
|
|
232
231
|
this.isWETH = payload.isWeth || false;
|
|
233
232
|
this.borrowRate = Number(((0, formatter_1.toBigInt)(payload.borrowRate || 0) *
|
|
234
|
-
((0, formatter_1.toBigInt)(payload.feeInterest || 0) +
|
|
235
|
-
|
|
236
|
-
|
|
233
|
+
((0, formatter_1.toBigInt)(payload.feeInterest || 0) + sdk_gov_1.PERCENTAGE_FACTOR) *
|
|
234
|
+
sdk_gov_1.PERCENTAGE_DECIMALS) /
|
|
235
|
+
sdk_gov_1.RAY);
|
|
237
236
|
this.borrowRateOld = Number(((0, formatter_1.toBigInt)(payload.borrowRateOld || 0) *
|
|
238
|
-
((0, formatter_1.toBigInt)(payload.feeInterest || 0) +
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
this.borrowRateChange = Number((0, formatter_1.toBigInt)(payload.borrowRate10kBasis || 0) *
|
|
237
|
+
((0, formatter_1.toBigInt)(payload.feeInterest || 0) + sdk_gov_1.PERCENTAGE_FACTOR) *
|
|
238
|
+
sdk_gov_1.PERCENTAGE_DECIMALS) /
|
|
239
|
+
sdk_gov_1.RAY);
|
|
240
|
+
this.borrowRateChange = Number((0, formatter_1.toBigInt)(payload.borrowRate10kBasis || 0) * sdk_gov_1.PERCENTAGE_DECIMALS);
|
|
242
241
|
this.maxLeverageFactor = payload.maxLeverageFactor || 0;
|
|
243
242
|
this.feeInterest = payload.feeInterest || 0;
|
|
244
243
|
this.feeLiquidation = payload.feeLiquidation || 0;
|
|
@@ -254,7 +253,7 @@ class ChartsCreditManagerData {
|
|
|
254
253
|
this.totalBorrowed = (0, formatter_1.toBigInt)(payload.totalBorrowed || 0);
|
|
255
254
|
this.totalBorrowedOld = (0, formatter_1.toBigInt)(payload.totalBorrowedBIOld || 0);
|
|
256
255
|
this.totalBorrowedInUSD = payload.totalBorrowedInUSD || 0;
|
|
257
|
-
this.totalBorrowedChange = Number((0, formatter_1.toBigInt)(payload.totalBorrowedBI10kBasis || 0) *
|
|
256
|
+
this.totalBorrowedChange = Number((0, formatter_1.toBigInt)(payload.totalBorrowedBI10kBasis || 0) * sdk_gov_1.PERCENTAGE_DECIMALS);
|
|
258
257
|
this.totalLosses = (0, formatter_1.toBigInt)(payload.totalLosses || 0);
|
|
259
258
|
this.totalLossesOld = (0, formatter_1.toBigInt)(payload.totalLossesOld || 0);
|
|
260
259
|
this.totalLossesInUSD = payload.totalLossesInUSD || 0;
|
|
@@ -263,7 +262,7 @@ class ChartsCreditManagerData {
|
|
|
263
262
|
this.totalProfit = (0, formatter_1.toBigInt)(payload.totalProfit || 0);
|
|
264
263
|
this.totalProfitOld = (0, formatter_1.toBigInt)(payload.totalProfitOld || 0);
|
|
265
264
|
this.totalProfitInUSD = payload.totalProfitInUSD || 0;
|
|
266
|
-
this.pnlChange = Number((0, formatter_1.toBigInt)(payload.pnl10kBasis || 0) *
|
|
265
|
+
this.pnlChange = Number((0, formatter_1.toBigInt)(payload.pnl10kBasis || 0) * sdk_gov_1.PERCENTAGE_DECIMALS);
|
|
267
266
|
this.openedAccountsCount = payload.openedAccountsCount || 0;
|
|
268
267
|
this.openedAccountsCountChange = payload.openedAccountsCountChange || 0;
|
|
269
268
|
this.totalOpenedAccounts = payload.totalOpenedAccounts || 0;
|