@gearbox-protocol/sdk 0.0.102 → 0.0.103
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/.eslintignore +4 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.js +3 -5
- package/lib/apy/lidoAPY.js +8 -9
- package/lib/contracts/contracts.d.ts +3 -3
- package/lib/contracts/contracts.js +2 -2
- package/lib/core/constants.d.ts +1 -1
- package/lib/core/constants.js +2 -2
- package/lib/core/creditAccount.js +7 -5
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +1 -7
- package/lib/core/creditSession.js +14 -3
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +23 -21
- package/lib/core/pool.d.ts +1 -1
- package/lib/core/pool.js +1 -7
- package/lib/core/price.js +6 -1
- package/lib/core/strategy.d.ts +1 -3
- package/lib/core/strategy.js +14 -13
- package/lib/core/tokenDistributor.js +1 -1
- package/lib/core/transactions.d.ts +18 -3
- package/lib/core/transactions.js +39 -3
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -1
- package/lib/oracles/priceFeeds.js +1 -1
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +26 -29
- package/lib/pathfinder/curveLP.d.ts +1 -1
- package/lib/pathfinder/curveLP.js +5 -7
- package/lib/pathfinder/path.d.ts +1 -1
- package/lib/pathfinder/path.js +38 -42
- package/lib/pathfinder/trade.d.ts +1 -2
- package/lib/pathfinder/tradeTypes.d.ts +5 -5
- package/lib/pathfinder/yVault.d.ts +2 -2
- package/lib/pathfinder/yVault.js +18 -15
- package/lib/strategies/curve.d.ts +6 -60
- package/lib/strategies/curve.js +6 -0
- package/lib/strategies/uniswapV2.js +3 -19
- package/lib/strategies/uniswapV3.js +1 -1
- package/lib/strategies/yearn.js +15 -11
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +2 -2
- package/lib/tokens/curveLP.js +1 -1
- package/lib/tokens/gear.d.ts +2 -2
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/token.js +4 -4
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +3 -3
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +17 -14
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.js +2 -2
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/validate.js +1 -1
- package/package.json +26 -8
- package/src/apy/convexAPY.ts +6 -6
- package/src/apy/lidoAPY.ts +12 -11
- package/src/contracts/contracts.ts +8 -7
- package/src/core/constants.ts +1 -1
- package/src/core/creditAccount.ts +28 -5
- package/src/core/creditManager.ts +29 -4
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +1 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +85 -24
- package/src/core/history.ts +46 -46
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +16 -4
- package/src/core/price.ts +7 -3
- package/src/core/strategy.ts +27 -23
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +1 -3
- package/src/oracles/priceFeeds.ts +523 -523
- package/src/pathfinder/contracts.ts +15 -13
- package/src/pathfinder/convexLP.ts +29 -25
- package/src/pathfinder/curveLP.ts +57 -53
- package/src/pathfinder/path.ts +17 -9
- package/src/pathfinder/priority.ts +11 -11
- package/src/pathfinder/trade.ts +84 -77
- package/src/pathfinder/tradeTypes.ts +98 -94
- package/src/pathfinder/yVault.ts +26 -11
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +217 -210
- package/src/strategies/creditFacade.ts +70 -53
- package/src/strategies/curve.ts +263 -194
- package/src/strategies/lido.ts +33 -37
- package/src/strategies/uniswapV2.ts +90 -112
- package/src/strategies/uniswapV3.ts +114 -91
- package/src/strategies/yearn.ts +58 -62
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +170 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +9 -5
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +126 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +22 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +8 -6
- package/src/utils/multicall.ts +2 -0
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/validate.ts +1 -1
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.103",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -9,22 +9,40 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"dev": "tsc -w",
|
|
12
|
-
"pub": "rm -rf ./src/types/hardhat.ts && cp ./src/types/*.d.ts ./lib/types && tsc && yarn publish"
|
|
12
|
+
"pub": "rm -rf ./src/types/hardhat.ts && cp ./src/types/*.d.ts ./lib/types && tsc && yarn publish",
|
|
13
|
+
"lint": "eslint . --ext .tsx,.ts --fix",
|
|
14
|
+
"prepush": "yarn lint --max-warnings=0",
|
|
15
|
+
"prepare": "husky install"
|
|
13
16
|
},
|
|
14
17
|
"dependencies": {
|
|
15
18
|
"decimal.js-light": "^2.5.1",
|
|
16
|
-
"moment": "^2.29.1"
|
|
19
|
+
"moment": "^2.29.1",
|
|
20
|
+
"prettier": "^2.7.1"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
|
-
"@types/jest": "^26.0.
|
|
20
|
-
"@types/node": "^
|
|
23
|
+
"@types/jest": "^26.0.15",
|
|
24
|
+
"@types/node": "^17.0.41",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
|
26
|
+
"@typescript-eslint/parser": "^5.7.0",
|
|
21
27
|
"axios": "^0.27.2",
|
|
22
28
|
"dotenv": "^16.0.1",
|
|
23
|
-
"
|
|
29
|
+
"eslint": "^7.11.0",
|
|
30
|
+
"eslint-config-airbnb": "^19.0.2",
|
|
31
|
+
"eslint-config-airbnb-typescript": "^16.1.0",
|
|
32
|
+
"eslint-config-prettier": "^8.3.0",
|
|
33
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
34
|
+
"eslint-plugin-import": "^2.22.1",
|
|
35
|
+
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
36
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
37
|
+
"eslint-plugin-react": "^7.27.1",
|
|
38
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
39
|
+
"ethers": "5.6.9",
|
|
40
|
+
"husky": "^8.0.0",
|
|
41
|
+
"husky-init": "^8.0.0",
|
|
24
42
|
"jest": "^26.1.0",
|
|
25
|
-
"prettier": "^2.
|
|
43
|
+
"prettier": "^2.7.1",
|
|
26
44
|
"ts-node": "^10.1.0",
|
|
27
45
|
"tslog": "^3.3.3",
|
|
28
|
-
"typescript": "^4.
|
|
46
|
+
"typescript": "^4.7.3"
|
|
29
47
|
}
|
|
30
48
|
}
|
package/src/apy/convexAPY.ts
CHANGED
|
@@ -73,14 +73,14 @@ export async function getConvexApy(
|
|
|
73
73
|
poolParams.stakedToken
|
|
74
74
|
] as ConvexPhantomTokenData;
|
|
75
75
|
|
|
76
|
-
const underlying = stakedTokenParams
|
|
76
|
+
const { underlying } = stakedTokenParams;
|
|
77
77
|
const basePoolAddress = contractsList[pool];
|
|
78
78
|
const swapPoolAddress = contractsList[curveSwapByPool[pool]];
|
|
79
79
|
const cvxAddress = tokenList.CVX;
|
|
80
80
|
|
|
81
|
-
const extraPoolAddresses = poolParams.extraRewards.map(
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
const extraPoolAddresses = poolParams.extraRewards.map(
|
|
82
|
+
d => d.poolAddress[networkType]
|
|
83
|
+
);
|
|
84
84
|
|
|
85
85
|
const [basePoolRate, basePoolSupply, vPrice, cvxSupply, ...extra] =
|
|
86
86
|
await getPoolData(
|
|
@@ -91,8 +91,8 @@ export async function getConvexApy(
|
|
|
91
91
|
provider
|
|
92
92
|
);
|
|
93
93
|
|
|
94
|
-
const cvxPrice = getTokenPrice(tokenList
|
|
95
|
-
const crvPrice = getTokenPrice(tokenList
|
|
94
|
+
const cvxPrice = getTokenPrice(tokenList.CVX);
|
|
95
|
+
const crvPrice = getTokenPrice(tokenList.CRV);
|
|
96
96
|
|
|
97
97
|
const crvPerSecond = basePoolRate;
|
|
98
98
|
const virtualSupply = basePoolSupply.mul(vPrice).div(WAD);
|
package/src/apy/lidoAPY.ts
CHANGED
|
@@ -17,10 +17,9 @@ type ILidoOracleInterface = ILidoOracle["interface"];
|
|
|
17
17
|
|
|
18
18
|
type IstETHInterface = IstETH["interface"];
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
.oracle;
|
|
20
|
+
const lidoOracles = (contractParams.LIDO_STETH_GATEWAY as LidoParams).oracle;
|
|
22
21
|
|
|
23
|
-
const
|
|
22
|
+
const lidoStEth: Record<NetworkType, string> = {
|
|
24
23
|
Mainnet: tokenDataByNetwork.Mainnet.STETH,
|
|
25
24
|
Kovan: tokenDataByNetwork.Kovan.STETH
|
|
26
25
|
};
|
|
@@ -29,17 +28,19 @@ export async function getLidoApy(
|
|
|
29
28
|
provider: providers.Provider,
|
|
30
29
|
networkType: NetworkType
|
|
31
30
|
) {
|
|
32
|
-
if (!
|
|
33
|
-
throw
|
|
31
|
+
if (!lidoOracles[networkType]) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`No Lido APR oracle found on current network: ${networkType}`
|
|
34
|
+
);
|
|
34
35
|
}
|
|
35
|
-
if (!
|
|
36
|
-
throw `No Lido stETH found on current network: ${networkType}
|
|
36
|
+
if (!lidoStEth[networkType]) {
|
|
37
|
+
throw new Error(`No Lido stETH found on current network: ${networkType}`);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
const [{ postTotalPooledEther, preTotalPooledEther, timeElapsed }, fee] =
|
|
40
41
|
await geLidoData(
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
lidoOracles[networkType],
|
|
43
|
+
lidoStEth[networkType],
|
|
43
44
|
provider,
|
|
44
45
|
networkType
|
|
45
46
|
);
|
|
@@ -53,6 +54,8 @@ export async function getLidoApy(
|
|
|
53
54
|
return [lidoAPRRay, fee] as const;
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
export const LIDO_FEE_DECIMALS = 10000;
|
|
58
|
+
|
|
56
59
|
async function geLidoData(
|
|
57
60
|
lidoOracleAddress: string,
|
|
58
61
|
stETHAddress: string,
|
|
@@ -84,5 +87,3 @@ async function geLidoData(
|
|
|
84
87
|
|
|
85
88
|
return [stats, fee] as const;
|
|
86
89
|
}
|
|
87
|
-
|
|
88
|
-
export const LIDO_FEE_DECIMALS = 10000;
|
|
@@ -13,9 +13,9 @@ import { AdapterInterface } from "./adapters";
|
|
|
13
13
|
import { NetworkType } from "../core/constants";
|
|
14
14
|
import { Protocols } from "./protocols";
|
|
15
15
|
import { tokenDataByNetwork } from "../tokens/token";
|
|
16
|
-
import { ConvexStakedPhantomToken } from "../tokens/convex";
|
|
17
|
-
import { CurveLPToken } from "../tokens/curveLP";
|
|
18
|
-
import { NormalToken } from "../tokens/normal";
|
|
16
|
+
import type { ConvexStakedPhantomToken } from "../tokens/convex";
|
|
17
|
+
import type { CurveLPToken } from "../tokens/curveLP";
|
|
18
|
+
import type { NormalToken } from "../tokens/normal";
|
|
19
19
|
|
|
20
20
|
export type UniswapV2Contract = "UNISWAP_V2_ROUTER" | "SUSHISWAP_ROUTER";
|
|
21
21
|
|
|
@@ -420,9 +420,10 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
|
|
|
420
420
|
|
|
421
421
|
export const contractsByAddress = objectEntries(contractsByNetwork).reduce<
|
|
422
422
|
Record<string, SupportedContract>
|
|
423
|
-
>(
|
|
424
|
-
|
|
423
|
+
>(
|
|
424
|
+
(acc, [, contracts]) => ({
|
|
425
425
|
...acc,
|
|
426
426
|
...filterEmptyKeys(keyToLowercase(swapKeyValue(contracts)))
|
|
427
|
-
}
|
|
428
|
-
|
|
427
|
+
}),
|
|
428
|
+
{}
|
|
429
|
+
);
|
package/src/core/constants.ts
CHANGED
|
@@ -48,4 +48,4 @@ export const timeRanges: Record<string, number> = {
|
|
|
48
48
|
|
|
49
49
|
export const LEVERAGE_DECIMALS = 100;
|
|
50
50
|
export const SLIPPAGE_DECIMALS = 100;
|
|
51
|
-
export const
|
|
51
|
+
export const ADDRESS_0X0 = "0x0000000000000000000000000000000000000000";
|
|
@@ -18,19 +18,33 @@ export class CreditAccountData {
|
|
|
18
18
|
public readonly id: string;
|
|
19
19
|
|
|
20
20
|
public readonly addr: string;
|
|
21
|
+
|
|
21
22
|
public readonly borrower: string;
|
|
23
|
+
|
|
22
24
|
public readonly inUse: boolean;
|
|
25
|
+
|
|
23
26
|
public readonly creditManager: string;
|
|
27
|
+
|
|
24
28
|
public readonly underlyingToken: string;
|
|
29
|
+
|
|
25
30
|
public borrowedAmountPlusInterest: BigNumber;
|
|
31
|
+
|
|
26
32
|
public totalValue: BigNumber;
|
|
33
|
+
|
|
27
34
|
public healthFactor: number;
|
|
35
|
+
|
|
28
36
|
public borrowRate: number;
|
|
37
|
+
|
|
29
38
|
public readonly allowedTokens: Array<string> = [];
|
|
39
|
+
|
|
30
40
|
public readonly allTokens: Array<string> = [];
|
|
41
|
+
|
|
31
42
|
public balances: Record<string, BigNumber> = {};
|
|
43
|
+
|
|
32
44
|
public allBalances: Record<string, BigNumber> = {};
|
|
45
|
+
|
|
33
46
|
public isDeleting: boolean;
|
|
47
|
+
|
|
34
48
|
public readonly version: number = 1;
|
|
35
49
|
|
|
36
50
|
constructor(payload: CreditAccountDataPayload) {
|
|
@@ -94,11 +108,15 @@ export function sortBalances(
|
|
|
94
108
|
const totalPrice1 = calcTotalPrice(price1, amount1, token1?.decimals);
|
|
95
109
|
const totalPrice2 = calcTotalPrice(price2, amount2, token2?.decimals);
|
|
96
110
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
if (totalPrice1.eq(totalPrice2)) {
|
|
112
|
+
return tokensAbcComparator(token1, token2);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (totalPrice1.gt(totalPrice2)) {
|
|
116
|
+
return -1;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return 1;
|
|
102
120
|
});
|
|
103
121
|
}
|
|
104
122
|
|
|
@@ -111,10 +129,15 @@ export function tokensAbcComparator(t1?: TokenData, t2?: TokenData) {
|
|
|
111
129
|
|
|
112
130
|
export class CreditAccountDataExtended extends CreditAccountData {
|
|
113
131
|
public readonly repayAmount: BigNumber;
|
|
132
|
+
|
|
114
133
|
public readonly liquidationAmount: BigNumber;
|
|
134
|
+
|
|
115
135
|
public readonly borrowedAmount: BigNumber;
|
|
136
|
+
|
|
116
137
|
public readonly canBeClosed: boolean;
|
|
138
|
+
|
|
117
139
|
public readonly cumulativeIndexAtOpen: BigNumber;
|
|
140
|
+
|
|
118
141
|
public readonly since: number;
|
|
119
142
|
|
|
120
143
|
constructor(payload: CreditAccountDataExtendedPayload) {
|
|
@@ -22,26 +22,45 @@ import { OpenAccountError } from "./errors";
|
|
|
22
22
|
|
|
23
23
|
export class CreditManagerData {
|
|
24
24
|
public readonly id: string;
|
|
25
|
+
|
|
25
26
|
public readonly address: string;
|
|
27
|
+
|
|
26
28
|
public readonly underlyingToken: string;
|
|
29
|
+
|
|
27
30
|
public readonly isWETH: boolean;
|
|
31
|
+
|
|
28
32
|
public readonly canBorrow: boolean;
|
|
33
|
+
|
|
29
34
|
public readonly borrowRate: number;
|
|
35
|
+
|
|
30
36
|
public readonly minAmount: BigNumber;
|
|
37
|
+
|
|
31
38
|
public readonly maxAmount: BigNumber;
|
|
39
|
+
|
|
32
40
|
public readonly maxLeverageFactor: number; // for V1 only
|
|
41
|
+
|
|
33
42
|
public readonly availableLiquidity: BigNumber;
|
|
43
|
+
|
|
34
44
|
public readonly allowedTokens: Array<string>;
|
|
45
|
+
|
|
35
46
|
public readonly adapters: Record<string, string>;
|
|
36
47
|
|
|
37
48
|
public readonly liquidationThresholds: Record<string, BigNumber>;
|
|
49
|
+
|
|
38
50
|
public readonly version: number;
|
|
51
|
+
|
|
39
52
|
public readonly creditFacade: string; // V2 only: address of creditFacade
|
|
53
|
+
|
|
40
54
|
public readonly isDegenMode: boolean; // V2 only: true if contract is in Degen mode
|
|
55
|
+
|
|
41
56
|
public readonly degenNFT: string; // V2 only: degenNFT, address(0) if not in degen mode
|
|
57
|
+
|
|
42
58
|
public readonly isIncreaseDebtForbidden: boolean; // V2 only: true if increasing debt is forbidden
|
|
59
|
+
|
|
43
60
|
public readonly forbiddenTokenMask: BigNumber; // V2 only: mask which forbids some particular tokens
|
|
44
61
|
|
|
62
|
+
public readonly isPaused: boolean = false;
|
|
63
|
+
|
|
45
64
|
constructor(payload: CreditManagerDataPayload) {
|
|
46
65
|
this.id = payload.addr;
|
|
47
66
|
this.address = payload.addr;
|
|
@@ -92,10 +111,6 @@ export class CreditManagerData {
|
|
|
92
111
|
this.forbiddenTokenMask = BigNumber.from(payload.forbiddenTokenMask || 0);
|
|
93
112
|
}
|
|
94
113
|
|
|
95
|
-
get isPaused(): boolean {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
114
|
getContractETH(signer: Signer | ethers.providers.Provider): ICreditManager {
|
|
100
115
|
return ICreditManager__factory.connect(this.address, signer);
|
|
101
116
|
}
|
|
@@ -229,15 +244,25 @@ export function calcHealthFactorAfterAddingCollateral(
|
|
|
229
244
|
|
|
230
245
|
export class CreditManagerStat extends CreditManagerData {
|
|
231
246
|
public readonly uniqueUsers: number;
|
|
247
|
+
|
|
232
248
|
public readonly openedAccountsCount: number;
|
|
249
|
+
|
|
233
250
|
public readonly totalOpenedAccounts: number;
|
|
251
|
+
|
|
234
252
|
public readonly totalClosedAccounts: number;
|
|
253
|
+
|
|
235
254
|
public readonly totalRepaidAccounts: number;
|
|
255
|
+
|
|
236
256
|
public readonly totalLiquidatedAccounts: number;
|
|
257
|
+
|
|
237
258
|
public readonly totalBorrowed: BigNumber;
|
|
259
|
+
|
|
238
260
|
public readonly cumulativeBorrowed: BigNumber;
|
|
261
|
+
|
|
239
262
|
public readonly totalRepaid: BigNumber;
|
|
263
|
+
|
|
240
264
|
public readonly totalProfit: BigNumber;
|
|
265
|
+
|
|
241
266
|
public readonly totalLosses: BigNumber;
|
|
242
267
|
|
|
243
268
|
constructor(payload: CreditManagerStatPayload) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export interface CreditOperation {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
id: number;
|
|
3
|
+
txHash: string;
|
|
4
|
+
blockNum: number;
|
|
5
|
+
protocol: string;
|
|
6
|
+
operation: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
date: string;
|
|
9
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
|
+
import moment from "moment";
|
|
2
3
|
import { CreditOperation } from "./creditOperation";
|
|
3
4
|
import { CreditSessionPayload } from "../payload/creditSession";
|
|
4
|
-
import moment from "moment";
|
|
5
5
|
import { PERCENTAGE_FACTOR } from "./constants";
|
|
6
6
|
|
|
7
7
|
export type CreditSessionStatus = "active" | "closed" | "repaid" | "liquidated";
|
|
@@ -10,29 +10,46 @@ const statusEnum: Array<CreditSessionStatus> = [
|
|
|
10
10
|
"active",
|
|
11
11
|
"closed",
|
|
12
12
|
"repaid",
|
|
13
|
-
"liquidated"
|
|
13
|
+
"liquidated"
|
|
14
14
|
];
|
|
15
15
|
|
|
16
16
|
export class CreditSession {
|
|
17
17
|
public readonly id: string;
|
|
18
18
|
|
|
19
19
|
public readonly status: CreditSessionStatus;
|
|
20
|
+
|
|
20
21
|
public readonly name: string;
|
|
22
|
+
|
|
21
23
|
public readonly background: string;
|
|
24
|
+
|
|
22
25
|
public readonly borrower: string;
|
|
26
|
+
|
|
23
27
|
public readonly creditManager: string;
|
|
28
|
+
|
|
24
29
|
public readonly account: string;
|
|
30
|
+
|
|
25
31
|
public readonly since: number;
|
|
32
|
+
|
|
26
33
|
public readonly sinceDate: string;
|
|
34
|
+
|
|
27
35
|
public readonly closedAt: number;
|
|
36
|
+
|
|
28
37
|
public readonly closedAtDate: string;
|
|
38
|
+
|
|
29
39
|
public readonly initialAmount: BigNumber;
|
|
40
|
+
|
|
30
41
|
public readonly borrowedAmount: BigNumber;
|
|
42
|
+
|
|
31
43
|
public readonly totalValue: BigNumber;
|
|
44
|
+
|
|
32
45
|
public readonly healthFactor: number;
|
|
46
|
+
|
|
33
47
|
public readonly profit: BigNumber;
|
|
48
|
+
|
|
34
49
|
public readonly profitPercentage: number;
|
|
50
|
+
|
|
35
51
|
public readonly score: number;
|
|
52
|
+
|
|
36
53
|
public readonly operations: Array<CreditOperation>;
|
|
37
54
|
|
|
38
55
|
constructor(payload: CreditSessionPayload) {
|
|
@@ -53,9 +70,12 @@ export class CreditSession {
|
|
|
53
70
|
this.healthFactor =
|
|
54
71
|
BigNumber.from(payload.healthFactor || 0).toNumber() / PERCENTAGE_FACTOR;
|
|
55
72
|
this.score = payload.score;
|
|
56
|
-
this.operations = (payload.operations || []).map(
|
|
57
|
-
|
|
58
|
-
|
|
73
|
+
this.operations = (payload.operations || []).map(op => {
|
|
74
|
+
const formattedOp = {
|
|
75
|
+
...op,
|
|
76
|
+
date: moment(op.timestamp * 1000).format("Do MMM YYYY")
|
|
77
|
+
};
|
|
78
|
+
return formattedOp;
|
|
59
79
|
});
|
|
60
80
|
this.sinceDate = moment(payload.sinceTimestamp * 1000).format(
|
|
61
81
|
"Do MMM YYYY"
|
package/src/core/errors.ts
CHANGED
package/src/core/eventOrTx.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TokenData } from "../tokens/tokenData";
|
|
2
|
-
import { TxSerialized } from "./transactions";
|
|
2
|
+
import type { TxSerialized } from "./transactions";
|
|
3
3
|
|
|
4
4
|
export interface Display {
|
|
5
5
|
toString(tokenData: Record<string, TokenData>): string;
|
|
@@ -16,8 +16,11 @@ export interface EventOrTxProps {
|
|
|
16
16
|
|
|
17
17
|
export abstract class EventOrTx implements Display {
|
|
18
18
|
public block: number;
|
|
19
|
+
|
|
19
20
|
public readonly txHash: string;
|
|
21
|
+
|
|
20
22
|
public readonly timestamp: number;
|
|
23
|
+
|
|
21
24
|
protected _txStatus: TxStatus;
|
|
22
25
|
|
|
23
26
|
constructor({ block, txHash, txStatus, timestamp = 0 }: EventOrTxProps) {
|
|
@@ -70,10 +73,10 @@ export abstract class EVMTx extends EventOrTx {
|
|
|
70
73
|
timestamp = 0
|
|
71
74
|
}: EVMTxProps) {
|
|
72
75
|
super({
|
|
73
|
-
block
|
|
74
|
-
txStatus
|
|
75
|
-
txHash
|
|
76
|
-
timestamp
|
|
76
|
+
block,
|
|
77
|
+
txStatus,
|
|
78
|
+
txHash,
|
|
79
|
+
timestamp
|
|
77
80
|
});
|
|
78
81
|
if (this.txStatus !== "pending" && this.block === 0) {
|
|
79
82
|
throw new Error("Block not specified for non-pending tx");
|