@defisaver/positions-sdk 0.0.166-dev6-liquity-v2 → 0.0.166-dev6

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.
Files changed (144) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/README.md +69 -69
  4. package/cjs/config/contracts.d.ts +32 -3
  5. package/cjs/config/contracts.js +3 -3
  6. package/cjs/contracts.d.ts +1 -1
  7. package/cjs/contracts.js +2 -2
  8. package/cjs/eulerV2/index.d.ts +41 -0
  9. package/cjs/eulerV2/index.js +218 -0
  10. package/cjs/helpers/eulerHelpers/index.d.ts +27 -0
  11. package/cjs/helpers/eulerHelpers/index.js +234 -0
  12. package/cjs/helpers/index.d.ts +1 -1
  13. package/cjs/helpers/index.js +2 -2
  14. package/cjs/index.d.ts +2 -2
  15. package/cjs/index.js +3 -3
  16. package/cjs/markets/euler/index.d.ts +8 -0
  17. package/cjs/markets/euler/index.js +30 -0
  18. package/cjs/markets/index.d.ts +1 -1
  19. package/cjs/markets/index.js +3 -3
  20. package/cjs/moneymarket/moneymarketCommonService.js +1 -1
  21. package/cjs/services/utils.d.ts +2 -0
  22. package/cjs/services/utils.js +4 -1
  23. package/cjs/staking/staking.js +0 -2
  24. package/cjs/types/contracts/generated/EulerV2View.d.ts +345 -0
  25. package/cjs/types/contracts/generated/index.d.ts +1 -1
  26. package/cjs/types/euler.d.ts +149 -0
  27. package/cjs/types/euler.js +14 -0
  28. package/cjs/types/index.d.ts +1 -1
  29. package/cjs/types/index.js +1 -1
  30. package/esm/config/contracts.d.ts +32 -3
  31. package/esm/config/contracts.js +3 -3
  32. package/esm/contracts.d.ts +1 -1
  33. package/esm/contracts.js +1 -1
  34. package/esm/eulerV2/index.d.ts +41 -0
  35. package/esm/eulerV2/index.js +210 -0
  36. package/esm/helpers/eulerHelpers/index.d.ts +27 -0
  37. package/esm/helpers/eulerHelpers/index.js +221 -0
  38. package/esm/helpers/index.d.ts +1 -1
  39. package/esm/helpers/index.js +1 -1
  40. package/esm/index.d.ts +2 -2
  41. package/esm/index.js +2 -2
  42. package/esm/markets/euler/index.d.ts +8 -0
  43. package/esm/markets/euler/index.js +24 -0
  44. package/esm/markets/index.d.ts +1 -1
  45. package/esm/markets/index.js +1 -1
  46. package/esm/moneymarket/moneymarketCommonService.js +1 -1
  47. package/esm/services/utils.d.ts +2 -0
  48. package/esm/services/utils.js +2 -0
  49. package/esm/staking/staking.js +0 -2
  50. package/esm/types/contracts/generated/EulerV2View.d.ts +345 -0
  51. package/esm/types/contracts/generated/index.d.ts +1 -1
  52. package/esm/types/euler.d.ts +149 -0
  53. package/esm/types/euler.js +11 -0
  54. package/esm/types/index.d.ts +1 -1
  55. package/esm/types/index.js +1 -1
  56. package/package.json +49 -49
  57. package/src/aaveV2/index.ts +227 -227
  58. package/src/aaveV3/index.ts +590 -590
  59. package/src/assets/index.ts +60 -60
  60. package/src/chickenBonds/index.ts +123 -123
  61. package/src/compoundV2/index.ts +219 -219
  62. package/src/compoundV3/index.ts +281 -281
  63. package/src/config/contracts.js +1040 -1040
  64. package/src/constants/index.ts +6 -6
  65. package/src/contracts.ts +130 -130
  66. package/src/curveUsd/index.ts +229 -229
  67. package/src/eulerV2/index.ts +302 -0
  68. package/src/exchange/index.ts +17 -17
  69. package/src/helpers/aaveHelpers/index.ts +194 -194
  70. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  71. package/src/helpers/compoundHelpers/index.ts +246 -246
  72. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  73. package/src/helpers/eulerHelpers/index.ts +233 -0
  74. package/src/helpers/index.ts +9 -9
  75. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  76. package/src/helpers/makerHelpers/index.ts +94 -94
  77. package/src/helpers/morphoBlueHelpers/index.ts +115 -115
  78. package/src/helpers/sparkHelpers/index.ts +150 -150
  79. package/src/index.ts +48 -48
  80. package/src/liquity/index.ts +116 -116
  81. package/src/llamaLend/index.ts +275 -275
  82. package/src/maker/index.ts +117 -117
  83. package/src/markets/aave/index.ts +152 -152
  84. package/src/markets/aave/marketAssets.ts +46 -46
  85. package/src/markets/compound/index.ts +173 -173
  86. package/src/markets/compound/marketsAssets.ts +64 -64
  87. package/src/markets/curveUsd/index.ts +69 -69
  88. package/src/markets/euler/index.ts +27 -0
  89. package/src/markets/index.ts +24 -23
  90. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  91. package/src/markets/llamaLend/index.ts +235 -235
  92. package/src/markets/morphoBlue/index.ts +728 -728
  93. package/src/markets/spark/index.ts +29 -29
  94. package/src/markets/spark/marketAssets.ts +10 -10
  95. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  96. package/src/morphoAaveV2/index.ts +256 -256
  97. package/src/morphoAaveV3/index.ts +630 -630
  98. package/src/morphoBlue/index.ts +171 -171
  99. package/src/multicall/index.ts +22 -22
  100. package/src/services/dsrService.ts +15 -15
  101. package/src/services/priceService.ts +21 -21
  102. package/src/services/utils.ts +57 -54
  103. package/src/setup.ts +8 -8
  104. package/src/spark/index.ts +424 -424
  105. package/src/staking/staking.ts +216 -218
  106. package/src/types/aave.ts +262 -262
  107. package/src/types/chickenBonds.ts +45 -45
  108. package/src/types/common.ts +84 -84
  109. package/src/types/compound.ts +129 -129
  110. package/src/types/contracts/generated/EulerV2View.ts +446 -0
  111. package/src/types/contracts/generated/index.ts +1 -1
  112. package/src/types/curveUsd.ts +118 -118
  113. package/src/types/euler.ts +172 -0
  114. package/src/types/index.ts +10 -10
  115. package/src/types/liquity.ts +30 -30
  116. package/src/types/llamaLend.ts +155 -155
  117. package/src/types/maker.ts +50 -50
  118. package/src/types/morphoBlue.ts +146 -146
  119. package/src/types/spark.ts +127 -127
  120. package/cjs/helpers/liquityV2Helpers/index.d.ts +0 -12
  121. package/cjs/helpers/liquityV2Helpers/index.js +0 -62
  122. package/cjs/liquityV2/index.d.ts +0 -11
  123. package/cjs/liquityV2/index.js +0 -108
  124. package/cjs/markets/liquityV2/index.d.ts +0 -8
  125. package/cjs/markets/liquityV2/index.js +0 -34
  126. package/cjs/types/contracts/generated/LiquityV2View.d.ts +0 -222
  127. package/cjs/types/liquityV2.d.ts +0 -84
  128. package/cjs/types/liquityV2.js +0 -8
  129. package/esm/helpers/liquityV2Helpers/index.d.ts +0 -12
  130. package/esm/helpers/liquityV2Helpers/index.js +0 -54
  131. package/esm/liquityV2/index.d.ts +0 -11
  132. package/esm/liquityV2/index.js +0 -99
  133. package/esm/markets/liquityV2/index.d.ts +0 -8
  134. package/esm/markets/liquityV2/index.js +0 -28
  135. package/esm/types/contracts/generated/LiquityV2View.d.ts +0 -222
  136. package/esm/types/liquityV2.d.ts +0 -84
  137. package/esm/types/liquityV2.js +0 -5
  138. package/src/helpers/liquityV2Helpers/index.ts +0 -79
  139. package/src/liquityV2/index.ts +0 -126
  140. package/src/markets/liquityV2/index.ts +0 -31
  141. package/src/types/contracts/generated/LiquityV2View.ts +0 -280
  142. package/src/types/liquityV2.ts +0 -90
  143. /package/cjs/types/contracts/generated/{LiquityV2View.js → EulerV2View.js} +0 -0
  144. /package/esm/types/contracts/generated/{LiquityV2View.js → EulerV2View.js} +0 -0
@@ -1,28 +0,0 @@
1
- import { NetworkNumber } from '../../types/common';
2
- import { LiquityV2Versions } from '../../types/liquityV2';
3
- export const LIQUITY_V2_ETH_MARKET = (networkId = NetworkNumber.Eth) => ({
4
- chainIds: [1],
5
- label: 'Liquity V2 ETH',
6
- shortLabel: 'ETH',
7
- value: LiquityV2Versions.LiquityV2Eth,
8
- url: 'eth',
9
- debtToken: 'BOLD',
10
- collateralToken: 'ETH',
11
- marketAddress: '0xd7199b16945f1ebaa0b301bf3d05bf489caa408b',
12
- protocolName: 'liquity-v2',
13
- });
14
- export const LIQUITY_V2_WSTETH_MARKET = (networkId = NetworkNumber.Eth) => ({
15
- chainIds: [1],
16
- label: 'Liquity V2 wstETH',
17
- shortLabel: 'wstETH',
18
- value: LiquityV2Versions.LiquityV2WstEth,
19
- url: 'wsteth',
20
- debtToken: 'BOLD',
21
- collateralToken: 'wstETH',
22
- marketAddress: '0x0d22113a543826eeaf2ae0fc9d10aea66efba156',
23
- protocolName: 'liquity-v2',
24
- });
25
- export const LiquityV2Markets = (networkId) => ({
26
- [LiquityV2Versions.LiquityV2Eth]: LIQUITY_V2_ETH_MARKET(networkId),
27
- [LiquityV2Versions.LiquityV2WstEth]: LIQUITY_V2_WSTETH_MARKET(networkId),
28
- });
@@ -1,222 +0,0 @@
1
- /// <reference types="node" />
2
- import type BN from "bn.js";
3
- import type { ContractOptions } from "web3-eth-contract";
4
- import type { EventLog } from "web3-core";
5
- import type { EventEmitter } from "events";
6
- import type { Callback, NonPayableTransactionObject, BlockType, BaseContract } from "./types";
7
- export interface EventOptions {
8
- filter?: object;
9
- fromBlock?: BlockType;
10
- topics?: string[];
11
- }
12
- export declare namespace LiquityV2View {
13
- type MarketDataStruct = [
14
- string,
15
- number | string | BN,
16
- number | string | BN,
17
- number | string | BN,
18
- number | string | BN,
19
- number | string | BN,
20
- number | string | BN,
21
- number | string | BN,
22
- string,
23
- string,
24
- string,
25
- string,
26
- string,
27
- string,
28
- string,
29
- string,
30
- string,
31
- number | string | BN,
32
- boolean
33
- ] | {
34
- market: string;
35
- CCR: number | string | BN;
36
- MCR: number | string | BN;
37
- SCR: number | string | BN;
38
- LIQUIDATION_PENALTY_SP: number | string | BN;
39
- LIQUIDATION_PENALTY_REDISTRIBUTION: number | string | BN;
40
- entireSystemColl: number | string | BN;
41
- entireSystemDebt: number | string | BN;
42
- collToken: string;
43
- troveNFT: string;
44
- borrowerOperations: string;
45
- troveManager: string;
46
- stabilityPool: string;
47
- sortedTroves: string;
48
- collSurplusPool: string;
49
- hintHelpers: string;
50
- priceFeed: string;
51
- collPrice: number | string | BN;
52
- isShutDown: boolean;
53
- };
54
- type MarketDataStructOutputArray = [
55
- string,
56
- string,
57
- string,
58
- string,
59
- string,
60
- string,
61
- string,
62
- string,
63
- string,
64
- string,
65
- string,
66
- string,
67
- string,
68
- string,
69
- string,
70
- string,
71
- string,
72
- string,
73
- boolean
74
- ];
75
- type MarketDataStructOutputStruct = {
76
- market: string;
77
- CCR: string;
78
- MCR: string;
79
- SCR: string;
80
- LIQUIDATION_PENALTY_SP: string;
81
- LIQUIDATION_PENALTY_REDISTRIBUTION: string;
82
- entireSystemColl: string;
83
- entireSystemDebt: string;
84
- collToken: string;
85
- troveNFT: string;
86
- borrowerOperations: string;
87
- troveManager: string;
88
- stabilityPool: string;
89
- sortedTroves: string;
90
- collSurplusPool: string;
91
- hintHelpers: string;
92
- priceFeed: string;
93
- collPrice: string;
94
- isShutDown: boolean;
95
- };
96
- type MarketDataStructOutput = MarketDataStructOutputArray & MarketDataStructOutputStruct;
97
- type TroveDataStruct = [
98
- number | string | BN,
99
- string,
100
- string,
101
- number | string | BN,
102
- number | string | BN,
103
- number | string | BN,
104
- number | string | BN,
105
- number | string | BN,
106
- number | string | BN,
107
- string,
108
- number | string | BN
109
- ] | {
110
- troveId: number | string | BN;
111
- owner: string;
112
- collToken: string;
113
- status: number | string | BN;
114
- collAmount: number | string | BN;
115
- debtAmount: number | string | BN;
116
- collPrice: number | string | BN;
117
- TCRatio: number | string | BN;
118
- annualInterestRate: number | string | BN;
119
- interestBatchManager: string;
120
- batchDebtShares: number | string | BN;
121
- };
122
- type TroveDataStructOutputArray = [
123
- string,
124
- string,
125
- string,
126
- string,
127
- string,
128
- string,
129
- string,
130
- string,
131
- string,
132
- string,
133
- string
134
- ];
135
- type TroveDataStructOutputStruct = {
136
- troveId: string;
137
- owner: string;
138
- collToken: string;
139
- status: string;
140
- collAmount: string;
141
- debtAmount: string;
142
- collPrice: string;
143
- TCRatio: string;
144
- annualInterestRate: string;
145
- interestBatchManager: string;
146
- batchDebtShares: string;
147
- };
148
- type TroveDataStructOutput = TroveDataStructOutputArray & TroveDataStructOutputStruct;
149
- }
150
- export interface LiquityV2View extends BaseContract {
151
- constructor(jsonInterface: any[], address?: string, options?: ContractOptions): LiquityV2View;
152
- clone(): LiquityV2View;
153
- methods: {
154
- findInsertPosition(_market: string, _interestRate: number | string | BN, _prevId: number | string | BN, _nextId: number | string | BN): NonPayableTransactionObject<[
155
- string,
156
- string
157
- ] & {
158
- prevId: string;
159
- nextId: string;
160
- }>;
161
- getApproxHint(_market: string, _collIndex: number | string | BN, _interestRate: number | string | BN, _numTrials: number | string | BN, _inputRandomSeed: number | string | BN): NonPayableTransactionObject<[
162
- string,
163
- string,
164
- string
165
- ] & {
166
- hintId: string;
167
- diff: string;
168
- latestRandomSeed: string;
169
- }>;
170
- getDebtInFront(_market: string, _troveId: number | string | BN, _acc: number | string | BN, _iterations: number | string | BN): NonPayableTransactionObject<[
171
- string,
172
- string
173
- ] & {
174
- next: string;
175
- debt: string;
176
- }>;
177
- getDebtInFrontByInterestRate(_market: string, _troveId: number | string | BN, _acc: number | string | BN, _iterations: number | string | BN, _targetIR: number | string | BN): NonPayableTransactionObject<[
178
- string,
179
- string
180
- ] & {
181
- next: string;
182
- debt: string;
183
- }>;
184
- getDebtInFrontByTroveNum(_market: string, _numTroves: number | string | BN): NonPayableTransactionObject<string>;
185
- getDepositorInfo(_market: string, _depositor: string): NonPayableTransactionObject<[
186
- string,
187
- string,
188
- string
189
- ] & {
190
- compoundedBOLD: string;
191
- collGain: string;
192
- boldGain: string;
193
- }>;
194
- getInsertPosition(_market: string, _collIndex: number | string | BN, _interestRate: number | string | BN, _numTrials: number | string | BN, _inputRandomSeed: number | string | BN): NonPayableTransactionObject<[
195
- string,
196
- string
197
- ] & {
198
- prevId: string;
199
- nextId: string;
200
- }>;
201
- getMarketData(_market: string): NonPayableTransactionObject<LiquityV2View.MarketDataStructOutput>;
202
- getNumOfTrovesInFrontOfTrove(_market: string, _troveId: number | string | BN, _iterations: number | string | BN): NonPayableTransactionObject<[
203
- string,
204
- string
205
- ] & {
206
- next: string;
207
- numTroves: string;
208
- }>;
209
- getTroveInfo(_market: string, _troveId: number | string | BN): NonPayableTransactionObject<LiquityV2View.TroveDataStructOutput>;
210
- getTrovePosition(_market: string, _collIndex: number | string | BN, _troveId: number | string | BN, _numTrials: number | string | BN, _inputRandomSeed: number | string | BN): NonPayableTransactionObject<[
211
- string,
212
- string
213
- ] & {
214
- prevId: string;
215
- nextId: string;
216
- }>;
217
- isShutDown(_market: string): NonPayableTransactionObject<boolean>;
218
- };
219
- events: {
220
- allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
221
- };
222
- }
@@ -1,84 +0,0 @@
1
- import { EthAddress, NetworkNumber } from './common';
2
- export declare enum LiquityV2Versions {
3
- LiquityV2Eth = "liquityv2eth",
4
- LiquityV2WstEth = "liquityv2wsteth"
5
- }
6
- export interface LiquityV2MarketInfo {
7
- chainIds: NetworkNumber[];
8
- label: string;
9
- shortLabel: string;
10
- url: string;
11
- value: LiquityV2Versions;
12
- debtToken: string;
13
- collateralToken: string;
14
- marketAddress: string;
15
- protocolName: string;
16
- }
17
- export interface LiquityV2AssetData {
18
- symbol: string;
19
- address: string;
20
- price: string;
21
- incentiveSupplyApy?: string;
22
- incentiveSupplyToken?: string;
23
- totalSupply: string;
24
- totalBorrow: string;
25
- canBeSupplied: boolean;
26
- canBeBorrowed: boolean;
27
- }
28
- export type LiquityV2AssetsData = {
29
- [key: string]: LiquityV2AssetData;
30
- };
31
- export interface InnerLiquityV2MarketData {
32
- minCollRatio: string;
33
- hintHelperAddress: EthAddress;
34
- }
35
- export interface LiquityV2MarketData {
36
- assetsData: LiquityV2AssetsData;
37
- marketData: InnerLiquityV2MarketData;
38
- }
39
- export interface LiquityV2UsedAsset {
40
- symbol: string;
41
- collateral?: boolean;
42
- supplied: string;
43
- suppliedUsd: string;
44
- borrowed: string;
45
- borrowedUsd: string;
46
- isSupplied: boolean;
47
- isBorrowed: boolean;
48
- }
49
- export type LiquityV2UsedAssets = {
50
- [key: string]: LiquityV2UsedAsset;
51
- };
52
- export interface LiquityV2AggregatedTroveData {
53
- suppliedUsd: string;
54
- borrowedUsd: string;
55
- borrowLimitUsd: string;
56
- leftToBorrowUsd: string;
57
- netApy: string;
58
- incentiveUsd: string;
59
- totalInterestUsd: string;
60
- leveragedType: string;
61
- leveragedAsset: string;
62
- liquidationPrice: string;
63
- ratio: string;
64
- }
65
- export interface LiquityV2TroveData {
66
- usedAssets: LiquityV2UsedAssets;
67
- troveId: string;
68
- ratio: string;
69
- collRatio: string;
70
- interestRate: string;
71
- leftToBorrowUsd: string;
72
- borrowLimitUsd: string;
73
- suppliedUsd: string;
74
- borrowedUsd: string;
75
- netApy: string;
76
- incentiveUsd: string;
77
- totalInterestUsd: string;
78
- interestBatchManager: EthAddress;
79
- troveStatus: string;
80
- leveragedType: string;
81
- leveragedAsset: string;
82
- liquidationPrice: string;
83
- debtInFront: string;
84
- }
@@ -1,5 +0,0 @@
1
- export var LiquityV2Versions;
2
- (function (LiquityV2Versions) {
3
- LiquityV2Versions["LiquityV2Eth"] = "liquityv2eth";
4
- LiquityV2Versions["LiquityV2WstEth"] = "liquityv2wsteth";
5
- })(LiquityV2Versions || (LiquityV2Versions = {}));
@@ -1,79 +0,0 @@
1
- import Dec from 'decimal.js';
2
- import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
3
- import {
4
- LiquityV2AggregatedTroveData, LiquityV2AssetsData, LiquityV2UsedAsset, LiquityV2UsedAssets,
5
- } from '../../types';
6
- import { calculateInterestEarned } from '../../staking';
7
-
8
- export const calculateNetApyLiquityV2 = (usedAssets: LiquityV2UsedAssets, assetsData: LiquityV2AssetsData, interestRate: string) => {
9
- const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
10
- const acc = { ..._acc };
11
- const assetData = assetsData[usedAsset.symbol];
12
-
13
- if (usedAsset.suppliedUsd) {
14
- const amount = usedAsset.suppliedUsd;
15
- acc.suppliedUsd = new Dec(acc.suppliedUsd).add(amount).toString();
16
- if (assetData.incentiveSupplyApy) {
17
- const incentiveInterest = calculateInterestEarned(amount, assetData.incentiveSupplyApy, 'year', true);
18
- acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
19
- }
20
- }
21
-
22
- if (usedAsset.borrowedUsd) {
23
- const amount = usedAsset.borrowedUsd;
24
- acc.borrowedUsd = new Dec(acc.borrowedUsd).add(amount).toString();
25
- const rate = interestRate;
26
- const borrowInterest = calculateInterestEarned(amount, rate as string, 'year', true);
27
- acc.borrowInterest = new Dec(acc.borrowInterest).sub(borrowInterest.toString()).toString();
28
- }
29
-
30
- return acc;
31
- }, {
32
- borrowInterest: '0', supplyInterest: '0', incentiveUsd: '0', borrowedUsd: '0', suppliedUsd: '0',
33
- });
34
-
35
- const {
36
- borrowedUsd, suppliedUsd, borrowInterest, supplyInterest, incentiveUsd,
37
- } = sumValues;
38
-
39
- const totalInterestUsd = new Dec(borrowInterest).add(supplyInterest).add(incentiveUsd).toString();
40
- const balance = new Dec(suppliedUsd).sub(borrowedUsd);
41
- const netApy = new Dec(totalInterestUsd).div(balance).times(100).toString();
42
-
43
- return { netApy, totalInterestUsd, incentiveUsd };
44
- };
45
-
46
- export const getLiquityV2AggregatedPositionData = ({
47
- usedAssets,
48
- assetsData,
49
- minCollRatio,
50
- interestRate,
51
- }: {
52
- usedAssets: LiquityV2UsedAssets
53
- assetsData: LiquityV2AssetsData
54
- minCollRatio: string
55
- interestRate: string
56
- }): LiquityV2AggregatedTroveData => {
57
- const payload = {} as LiquityV2AggregatedTroveData;
58
- payload.suppliedUsd = getAssetsTotal(usedAssets, (usedAsset: LiquityV2UsedAsset) => usedAsset, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
59
- payload.borrowedUsd = getAssetsTotal(usedAssets, (usedAsset: LiquityV2UsedAsset) => usedAsset, ({ borrowedUsd }: { borrowedUsd: string }) => borrowedUsd);
60
- payload.borrowLimitUsd = new Dec(payload.suppliedUsd).div(minCollRatio).mul(100).toString();
61
- const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
62
- payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
63
- payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
64
- const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApyLiquityV2(usedAssets, assetsData, interestRate);
65
- payload.netApy = netApy;
66
- payload.incentiveUsd = incentiveUsd;
67
- payload.totalInterestUsd = totalInterestUsd;
68
-
69
- const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
70
- payload.leveragedType = leveragedType;
71
- payload.leveragedAsset = leveragedAsset;
72
- payload.liquidationPrice = '';
73
- if (leveragedType !== '') {
74
- const assetPrice = assetsData[leveragedAsset].price;
75
- payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.borrowLimitUsd);
76
- }
77
-
78
- return payload;
79
- };
@@ -1,126 +0,0 @@
1
- import Web3 from 'web3';
2
- import Dec from 'decimal.js';
3
- import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
4
- import { LiquityV2ViewContract } from '../contracts';
5
- import { EthAddress, NetworkNumber } from '../types/common';
6
- import {
7
- InnerLiquityV2MarketData,
8
- LIQUITY_TROVE_STATUS_ENUM,
9
- LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData, LiquityV2UsedAssets,
10
- } from '../types';
11
- import { getStakingApy, STAKING_ASSETS } from '../staking';
12
- import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
13
- import { ethToWeth } from '../services/utils';
14
- import { ZERO_ADDRESS } from '../constants';
15
-
16
-
17
- export const getLiquityV2MarketData = async (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3): Promise<LiquityV2MarketData> => {
18
- const viewContract = LiquityV2ViewContract(web3, network);
19
- const { marketAddress, debtToken, collateralToken } = selectedMarket;
20
- const data = await viewContract.methods.getMarketData(marketAddress).call();
21
- const hintHelperAddress = data.hintHelpers;
22
- const assetsData: LiquityV2AssetsData = {};
23
- assetsData[debtToken] = {
24
- symbol: debtToken,
25
- address: getAssetInfo(debtToken, network).address,
26
- price: '1',
27
- totalSupply: '0',
28
- totalBorrow: assetAmountInEth(data.entireSystemDebt),
29
- canBeSupplied: false,
30
- canBeBorrowed: true,
31
- };
32
- assetsData[collateralToken] = {
33
- symbol: collateralToken,
34
- address: getAssetInfo(ethToWeth(collateralToken), network).address,
35
- price: assetAmountInEth(data.collPrice),
36
- totalSupply: assetAmountInEth(data.entireSystemColl),
37
- totalBorrow: '0',
38
- canBeSupplied: true,
39
- canBeBorrowed: false,
40
- };
41
- if (STAKING_ASSETS.includes(collateralToken)) {
42
- assetsData[collateralToken].incentiveSupplyApy = await getStakingApy(collateralToken, mainnetWeb3);
43
- assetsData[collateralToken].incentiveSupplyToken = collateralToken;
44
- }
45
-
46
- const minCollRatio = new Dec(data.MCR).div(1e16).toString();
47
- return { assetsData, marketData: { minCollRatio, hintHelperAddress } };
48
- };
49
-
50
- const _getDebtInFront = async (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum = '0', iterations = 2000) => viewContract.methods.getDebtInFront(marketAddress, troveId, accumulatedSum, iterations).call();
51
-
52
- export const getDebtInFrontLiquityV2 = async (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum = '0', iterations = 2000): Promise<string> => {
53
- const { debt, next } = await _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
54
- if (next === '0') return assetAmountInEth(debt);
55
- return getDebtInFrontLiquityV2(viewContract, marketAddress, next, debt, iterations);
56
- };
57
-
58
- export const getLiquityV2TroveData = async (
59
- web3: Web3,
60
- network: NetworkNumber,
61
- {
62
- selectedMarket,
63
- assetsData,
64
- marketData,
65
- troveId,
66
- }:
67
- {
68
- selectedMarket: LiquityV2MarketInfo,
69
- assetsData: LiquityV2AssetsData,
70
- marketData: InnerLiquityV2MarketData,
71
- troveId: string
72
- },
73
- ): Promise<LiquityV2TroveData> => {
74
- const viewContract = LiquityV2ViewContract(web3, network);
75
- const { minCollRatio } = marketData;
76
- const { collateralToken, marketAddress, debtToken } = selectedMarket;
77
- const [data, debtInFront] = await Promise.all([
78
- viewContract.methods.getTroveInfo(marketAddress, troveId).call(),
79
- getDebtInFrontLiquityV2(viewContract, marketAddress, troveId),
80
- ]);
81
- const usedAssets: LiquityV2UsedAssets = {};
82
-
83
- const debtAssetData = assetsData[debtToken];
84
- const borrowed = assetAmountInEth(data.debtAmount);
85
- usedAssets[debtToken] = {
86
- symbol: debtToken,
87
- supplied: '0',
88
- suppliedUsd: '0',
89
- borrowed,
90
- borrowedUsd: new Dec(borrowed).mul(debtAssetData.price).toString(),
91
- isBorrowed: true,
92
- isSupplied: false,
93
- };
94
-
95
- const collAssetData = assetsData[collateralToken];
96
- const suppliedColl = assetAmountInEth(data.collAmount);
97
- usedAssets[collateralToken] = {
98
- symbol: collateralToken,
99
- supplied: suppliedColl,
100
- suppliedUsd: new Dec(suppliedColl).mul(collAssetData.price).toString(),
101
- borrowed: '0',
102
- borrowedUsd: '0',
103
- isBorrowed: false,
104
- isSupplied: true,
105
- collateral: true,
106
- };
107
-
108
- const collRatio = new Dec(data.TCRatio).div(1e16).toString();
109
- const interestRate = new Dec(data.annualInterestRate).div(1e16).toString();
110
- const interestBatchManager = data.interestBatchManager;
111
-
112
- const payload: LiquityV2TroveData = {
113
- usedAssets,
114
- troveId,
115
- collRatio,
116
- interestRate,
117
- interestBatchManager,
118
- debtInFront,
119
- troveStatus: LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)],
120
- ...getLiquityV2AggregatedPositionData({
121
- usedAssets, assetsData, minCollRatio, interestRate,
122
- }),
123
- };
124
-
125
- return payload;
126
- };
@@ -1,31 +0,0 @@
1
- import { NetworkNumber } from '../../types/common';
2
- import { LiquityV2MarketInfo, LiquityV2Versions } from '../../types/liquityV2';
3
-
4
- export const LIQUITY_V2_ETH_MARKET = (networkId: NetworkNumber = NetworkNumber.Eth): LiquityV2MarketInfo => ({
5
- chainIds: [1],
6
- label: 'Liquity V2 ETH',
7
- shortLabel: 'ETH',
8
- value: LiquityV2Versions.LiquityV2Eth,
9
- url: 'eth',
10
- debtToken: 'BOLD',
11
- collateralToken: 'ETH',
12
- marketAddress: '0xd7199b16945f1ebaa0b301bf3d05bf489caa408b',
13
- protocolName: 'liquity-v2',
14
- });
15
-
16
- export const LIQUITY_V2_WSTETH_MARKET = (networkId: NetworkNumber = NetworkNumber.Eth): LiquityV2MarketInfo => ({
17
- chainIds: [1],
18
- label: 'Liquity V2 wstETH',
19
- shortLabel: 'wstETH',
20
- value: LiquityV2Versions.LiquityV2WstEth,
21
- url: 'wsteth',
22
- debtToken: 'BOLD',
23
- collateralToken: 'wstETH',
24
- marketAddress: '0x0d22113a543826eeaf2ae0fc9d10aea66efba156',
25
- protocolName: 'liquity-v2',
26
- });
27
-
28
- export const LiquityV2Markets = (networkId: NetworkNumber) => ({
29
- [LiquityV2Versions.LiquityV2Eth]: LIQUITY_V2_ETH_MARKET(networkId),
30
- [LiquityV2Versions.LiquityV2WstEth]: LIQUITY_V2_WSTETH_MARKET(networkId),
31
- }) as const;