@defisaver/positions-sdk 2.0.9--dev → 2.0.10-dev-linea-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.
Files changed (104) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/README.md +64 -64
  4. package/cjs/aaveV3/index.js +1 -1
  5. package/cjs/config/contracts.d.ts +194 -33
  6. package/cjs/config/contracts.js +18 -1
  7. package/cjs/contracts.d.ts +1283 -293
  8. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  9. package/cjs/markets/aave/index.js +1 -1
  10. package/cjs/markets/aave/marketAssets.d.ts +4 -0
  11. package/cjs/markets/aave/marketAssets.js +5 -1
  12. package/cjs/markets/compound/index.js +11 -0
  13. package/cjs/markets/compound/marketsAssets.d.ts +7 -0
  14. package/cjs/markets/compound/marketsAssets.js +7 -0
  15. package/cjs/markets/spark/marketAssets.d.ts +1 -0
  16. package/cjs/markets/spark/marketAssets.js +1 -0
  17. package/cjs/portfolio/index.js +2 -2
  18. package/cjs/services/viem.d.ts +46 -0
  19. package/cjs/services/viem.js +2 -0
  20. package/cjs/types/common.d.ts +2 -1
  21. package/cjs/types/common.js +1 -0
  22. package/esm/aaveV3/index.js +1 -1
  23. package/esm/config/contracts.d.ts +194 -33
  24. package/esm/config/contracts.js +18 -1
  25. package/esm/contracts.d.ts +1283 -293
  26. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  27. package/esm/markets/aave/index.js +1 -1
  28. package/esm/markets/aave/marketAssets.d.ts +4 -0
  29. package/esm/markets/aave/marketAssets.js +4 -0
  30. package/esm/markets/compound/index.js +11 -0
  31. package/esm/markets/compound/marketsAssets.d.ts +7 -0
  32. package/esm/markets/compound/marketsAssets.js +7 -0
  33. package/esm/markets/spark/marketAssets.d.ts +1 -0
  34. package/esm/markets/spark/marketAssets.js +1 -0
  35. package/esm/portfolio/index.js +2 -2
  36. package/esm/services/viem.d.ts +46 -0
  37. package/esm/services/viem.js +3 -1
  38. package/esm/types/common.d.ts +2 -1
  39. package/esm/types/common.js +1 -0
  40. package/package.json +47 -47
  41. package/src/aaveV2/index.ts +236 -236
  42. package/src/aaveV3/index.ts +489 -489
  43. package/src/compoundV2/index.ts +240 -240
  44. package/src/compoundV3/index.ts +270 -270
  45. package/src/config/contracts.ts +1107 -1090
  46. package/src/constants/index.ts +6 -6
  47. package/src/contracts.ts +107 -107
  48. package/src/curveUsd/index.ts +250 -250
  49. package/src/eulerV2/index.ts +314 -314
  50. package/src/exchange/index.ts +25 -25
  51. package/src/fluid/index.ts +1568 -1568
  52. package/src/helpers/aaveHelpers/index.ts +170 -170
  53. package/src/helpers/compoundHelpers/index.ts +261 -261
  54. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  55. package/src/helpers/eulerHelpers/index.ts +259 -259
  56. package/src/helpers/fluidHelpers/index.ts +324 -324
  57. package/src/helpers/index.ts +10 -10
  58. package/src/helpers/liquityV2Helpers/index.ts +80 -80
  59. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  60. package/src/helpers/makerHelpers/index.ts +52 -52
  61. package/src/helpers/morphoBlueHelpers/index.ts +390 -390
  62. package/src/helpers/sparkHelpers/index.ts +155 -155
  63. package/src/index.ts +45 -45
  64. package/src/liquity/index.ts +104 -104
  65. package/src/liquityV2/index.ts +408 -408
  66. package/src/llamaLend/index.ts +296 -296
  67. package/src/maker/index.ts +223 -223
  68. package/src/markets/aave/index.ts +116 -116
  69. package/src/markets/aave/marketAssets.ts +49 -44
  70. package/src/markets/compound/index.ts +227 -216
  71. package/src/markets/compound/marketsAssets.ts +90 -83
  72. package/src/markets/curveUsd/index.ts +69 -69
  73. package/src/markets/euler/index.ts +26 -26
  74. package/src/markets/fluid/index.ts +2456 -2456
  75. package/src/markets/index.ts +25 -25
  76. package/src/markets/liquityV2/index.ts +102 -102
  77. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  78. package/src/markets/llamaLend/index.ts +235 -235
  79. package/src/markets/morphoBlue/index.ts +895 -895
  80. package/src/markets/spark/index.ts +29 -29
  81. package/src/markets/spark/marketAssets.ts +11 -10
  82. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  83. package/src/morphoBlue/index.ts +222 -222
  84. package/src/portfolio/index.ts +285 -285
  85. package/src/services/priceService.ts +159 -159
  86. package/src/services/utils.ts +63 -63
  87. package/src/services/viem.ts +32 -30
  88. package/src/setup.ts +8 -8
  89. package/src/spark/index.ts +456 -456
  90. package/src/staking/staking.ts +192 -192
  91. package/src/types/aave.ts +194 -194
  92. package/src/types/common.ts +88 -87
  93. package/src/types/compound.ts +136 -136
  94. package/src/types/curveUsd.ts +121 -121
  95. package/src/types/euler.ts +174 -174
  96. package/src/types/fluid.ts +450 -450
  97. package/src/types/index.ts +11 -11
  98. package/src/types/liquity.ts +30 -30
  99. package/src/types/liquityV2.ts +126 -126
  100. package/src/types/llamaLend.ts +157 -157
  101. package/src/types/maker.ts +63 -63
  102. package/src/types/morphoBlue.ts +194 -194
  103. package/src/types/portfolio.ts +60 -60
  104. package/src/types/spark.ts +137 -137
@@ -1,224 +1,224 @@
1
- import Dec from 'decimal.js';
2
- import {
3
- assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset,
4
- } from '@defisaver/tokens';
5
- import { Client, PublicClient } from 'viem';
6
- import {
7
- Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances,
8
- } from '../types/common';
9
- import {
10
- getConfigContractAddress, McdDogContractViem, McdGetCdpsContractViem, McdJugContractViem, McdSpotterContractViem, McdVatContractViem, McdViewContractViem,
11
- } from '../contracts';
12
- import { CdpData, CdpInfo, CdpType } from '../types';
13
- import { wethToEth } from '../services/utils';
14
- import { parseCollateralInfo } from '../helpers/makerHelpers';
15
- import { getViemProvider, setViemBlockNumber } from '../services/viem';
16
-
17
- export const _getMakerAccountBalances = async (provider: PublicClient, network: NetworkNumber, block: Blockish, addressMapping: boolean, cdpId: string, _managerAddress?: EthAddress): Promise<PositionBalances> => {
18
- let balances: PositionBalances = {
19
- collateral: {},
20
- debt: {},
21
- };
22
- const managerAddress = _managerAddress || '0x5ef30b9986345249bc32d8928B7ee64DE9435E39'; // Default CDP Manager (This is used only to differentiate BProtocol CDPs)
23
-
24
- if (!cdpId) {
25
- return balances;
26
- }
27
-
28
- const viewContract = McdViewContractViem(provider, network, block);
29
- const vatContract = McdVatContractViem(provider, network, block);
30
- const spotterContract = McdSpotterContractViem(provider, network, block);
31
- const dogContract = McdDogContractViem(provider, network, block);
32
- const jugContract = McdJugContractViem(provider, network, block);
33
-
34
- let ilk;
35
-
36
- const needsIlk = block !== 'latest' && new Dec(block).lt(14410792) && new Dec(block).gte(14384301);
37
-
38
- if (needsIlk) {
39
- ilk = (await viewContract.read.getUrnAndIlk([managerAddress, BigInt(cdpId)], setViemBlockNumber(block)))[1];
40
- }
41
-
42
- // @ts-ignore
43
- // [urn, owner, userAddr, ilk, collateral, debt]
44
- const cdpInfo: any = await viewContract.read.getCdpInfo((needsIlk ? [managerAddress, cdpId, ilk] : [cdpId]), setViemBlockNumber(block));
45
- cdpInfo.ilk = cdpInfo[3];
46
-
47
- const [
48
- par,
49
- [_, mat],
50
- [artGlobal, rate, spot, line],
51
- [duty],
52
- futureRate,
53
- chop,
54
- ] = await Promise.all([
55
- spotterContract.read.par(setViemBlockNumber(block)),
56
- spotterContract.read.ilks(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
57
- vatContract.read.ilks(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
58
- jugContract.read.ilks(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
59
- jugContract.read.drip(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
60
- dogContract.read.chop(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
61
- ]);
62
-
63
- const ilkInfo = parseCollateralInfo(
64
- needsIlk ? ilk : cdpInfo.ilk,
65
- par.toString(),
66
- mat.toString(),
67
- artGlobal.toString(),
68
- rate.toString(),
69
- spot.toString(),
70
- line.toString(),
71
- duty.toString(),
72
- futureRate.toString(),
73
- chop.toString(),
74
- );
75
-
76
-
77
- const collateral = cdpInfo[4];
78
- const debt = cdpInfo[5];
79
-
80
- const asset = wethToEth(ilkToAsset(needsIlk ? ilk : cdpInfo.ilk));
81
-
82
- balances = {
83
- collateral: {
84
- [addressMapping ? getAssetInfo(asset, network).address.toLowerCase() : asset]: asset === 'WBTC' ? new Dec(collateral).div(1e10).floor().toString() : collateral,
85
- },
86
- debt: {
87
- [addressMapping ? getAssetInfo('DAI', network).address.toLowerCase() : 'DAI']: new Dec(debt).times(ilkInfo.currentRate).div(1e27).floor()
88
- .toString(),
89
- },
90
- };
91
-
92
- return balances;
93
- };
94
-
95
- export const getMakerAccountBalances = async (
96
- provider: EthereumProvider,
97
- network: NetworkNumber,
98
- block: Blockish,
99
- addressMapping: boolean,
100
- cdpId: string,
101
- _managerAddress?: EthAddress,
102
- ): Promise<PositionBalances> => _getMakerAccountBalances(getViemProvider(provider, network, { batch: { multicall: true } }), network, block, addressMapping, cdpId, _managerAddress);
103
-
104
- export const _getUserCdps = async (provider: Client, network: NetworkNumber, userAddress: EthAddress): Promise<CdpInfo[]> => {
105
- if (!userAddress) return [];
106
- const mcdGetCdpsContract = McdGetCdpsContractViem(provider, network);
107
-
108
- const mcdCdpManagerAddress = getConfigContractAddress('McdCdpManager', network);
109
-
110
- const standardCdps = await mcdGetCdpsContract.read.getCdpsAsc([mcdCdpManagerAddress, userAddress]);
111
-
112
- const parsedStandardCdps = standardCdps[0].map((id, i) => ({
113
- id: parseInt(id.toString(), 10),
114
- ilk: standardCdps[2][i].toLowerCase() as EthAddress, // collateral type
115
- ilkLabel: bytesToString(standardCdps[2][i].toLowerCase()),
116
- urn: standardCdps[1][i].toLowerCase() as EthAddress, // contract of cdp
117
- asset: ilkToAsset(standardCdps[2][i]),
118
- type: CdpType.MCD,
119
- owner: userAddress,
120
- }));
121
-
122
- return parsedStandardCdps;
123
- };
124
-
125
- export const getUserCdps = async (
126
- provider: EthereumProvider,
127
- network: NetworkNumber,
128
- userAddress: EthAddress,
129
- ): Promise<CdpInfo[]> => _getUserCdps(getViemProvider(provider, network), network, userAddress);
130
-
131
- export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo): Promise<CdpData> => {
132
- const vatContract = McdVatContractViem(provider, network);
133
- const spotterContract = McdSpotterContractViem(provider, network);
134
- const dogContract = McdDogContractViem(provider, network);
135
- const jugContract = McdJugContractViem(provider, network);
136
-
137
- const [
138
- [ink, art],
139
- coll,
140
- par,
141
- [_, mat],
142
- [artGlobal, rate, spot, line],
143
- [duty],
144
- futureRate,
145
- chop,
146
- ] = await Promise.all([
147
- vatContract.read.urns([cdp.ilk, cdp.urn]),
148
- vatContract.read.gem([cdp.ilk, cdp.urn]),
149
- spotterContract.read.par(),
150
- spotterContract.read.ilks([cdp.ilk]),
151
- vatContract.read.ilks([cdp.ilk]),
152
- jugContract.read.ilks([cdp.ilk]),
153
- jugContract.read.drip([cdp.ilk]),
154
- dogContract.read.chop([cdp.ilk]),
155
- ]);
156
-
157
- const collInfo = parseCollateralInfo(
158
- cdp.ilk,
159
- par.toString(),
160
- mat.toString(),
161
- artGlobal.toString(),
162
- rate.toString(),
163
- spot.toString(),
164
- line.toString(),
165
- duty.toString(),
166
- futureRate.toString(),
167
- chop.toString(),
168
- );
169
-
170
- const collateral = assetAmountInEth(ink.toString(), `MCD-${cdp.asset}`);
171
-
172
- const collateralUsd = new Dec(collateral).mul(collInfo.assetPrice).toString();
173
- const debt = new Dec(art).times(collInfo.currentRate).div(1e27).floor()
174
- .toString();
175
- const futureDebt = new Dec(art).times(collInfo.futureRate).div(1e27).floor()
176
- .toString(); // after drip
177
- const liquidationPrice = new Dec(debt).times(collInfo.liqRatio).div(ink).toString();
178
-
179
- let ratio = new Dec(ink).times(collInfo.assetPrice).div(debt).times(100)
180
- .toString();
181
- if (new Dec(debt).eq(0)) ratio = '0';
182
-
183
- const debtTooLow = new Dec(debt).gt(0) && new Dec(assetAmountInEth(debt, 'DAI')).lt(collInfo.minDebt);
184
-
185
- return {
186
- owner: cdp.owner,
187
- id: cdp.id.toString(),
188
- urn: cdp.urn,
189
- type: CdpType.MCD,
190
- ilk: cdp.ilk,
191
- ilkLabel: collInfo.ilkLabel,
192
- asset: cdp.asset,
193
- collateral,
194
- collateralUsd,
195
- futureDebt: assetAmountInEth(futureDebt, 'DAI'),
196
- debtDai: assetAmountInEth(debt, 'DAI'),
197
- debtUsd: assetAmountInEth(debt, 'DAI'),
198
- debtInAsset: assetAmountInEth(debt, 'DAI'),
199
- debtAssetPrice: '1',
200
- debtAssetMarketPrice: '1',
201
- liquidationPrice,
202
- ratio,
203
- liqRatio: collInfo.liqRatio.toString(),
204
- liqPercent: parseFloat(collInfo.liqPercent.toString()),
205
- assetPrice: collInfo.assetPrice,
206
- daiLabel: 'DAI',
207
- debtAsset: 'DAI',
208
- unclaimedCollateral: assetAmountInEth(coll.toString(), cdp.asset),
209
- debtTooLow,
210
- minDebt: collInfo.minDebt,
211
- stabilityFee: collInfo.stabilityFee,
212
- creatableDebt: collInfo.creatableDebt,
213
- globalDebtCeiling: collInfo.globalDebtCeiling,
214
- globalDebtCurrent: collInfo.globalDebtCurrent,
215
- liquidationFee: collInfo.liquidationFee,
216
- lastUpdated: Date.now(),
217
- };
218
- };
219
-
220
- export const getMakerCdpData = async (
221
- provider: EthereumProvider,
222
- network: NetworkNumber,
223
- cdp: CdpInfo,
1
+ import Dec from 'decimal.js';
2
+ import {
3
+ assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset,
4
+ } from '@defisaver/tokens';
5
+ import { Client, PublicClient } from 'viem';
6
+ import {
7
+ Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances,
8
+ } from '../types/common';
9
+ import {
10
+ getConfigContractAddress, McdDogContractViem, McdGetCdpsContractViem, McdJugContractViem, McdSpotterContractViem, McdVatContractViem, McdViewContractViem,
11
+ } from '../contracts';
12
+ import { CdpData, CdpInfo, CdpType } from '../types';
13
+ import { wethToEth } from '../services/utils';
14
+ import { parseCollateralInfo } from '../helpers/makerHelpers';
15
+ import { getViemProvider, setViemBlockNumber } from '../services/viem';
16
+
17
+ export const _getMakerAccountBalances = async (provider: PublicClient, network: NetworkNumber, block: Blockish, addressMapping: boolean, cdpId: string, _managerAddress?: EthAddress): Promise<PositionBalances> => {
18
+ let balances: PositionBalances = {
19
+ collateral: {},
20
+ debt: {},
21
+ };
22
+ const managerAddress = _managerAddress || '0x5ef30b9986345249bc32d8928B7ee64DE9435E39'; // Default CDP Manager (This is used only to differentiate BProtocol CDPs)
23
+
24
+ if (!cdpId) {
25
+ return balances;
26
+ }
27
+
28
+ const viewContract = McdViewContractViem(provider, network, block);
29
+ const vatContract = McdVatContractViem(provider, network, block);
30
+ const spotterContract = McdSpotterContractViem(provider, network, block);
31
+ const dogContract = McdDogContractViem(provider, network, block);
32
+ const jugContract = McdJugContractViem(provider, network, block);
33
+
34
+ let ilk;
35
+
36
+ const needsIlk = block !== 'latest' && new Dec(block).lt(14410792) && new Dec(block).gte(14384301);
37
+
38
+ if (needsIlk) {
39
+ ilk = (await viewContract.read.getUrnAndIlk([managerAddress, BigInt(cdpId)], setViemBlockNumber(block)))[1];
40
+ }
41
+
42
+ // @ts-ignore
43
+ // [urn, owner, userAddr, ilk, collateral, debt]
44
+ const cdpInfo: any = await viewContract.read.getCdpInfo((needsIlk ? [managerAddress, cdpId, ilk] : [cdpId]), setViemBlockNumber(block));
45
+ cdpInfo.ilk = cdpInfo[3];
46
+
47
+ const [
48
+ par,
49
+ [_, mat],
50
+ [artGlobal, rate, spot, line],
51
+ [duty],
52
+ futureRate,
53
+ chop,
54
+ ] = await Promise.all([
55
+ spotterContract.read.par(setViemBlockNumber(block)),
56
+ spotterContract.read.ilks(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
57
+ vatContract.read.ilks(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
58
+ jugContract.read.ilks(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
59
+ jugContract.read.drip(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
60
+ dogContract.read.chop(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
61
+ ]);
62
+
63
+ const ilkInfo = parseCollateralInfo(
64
+ needsIlk ? ilk : cdpInfo.ilk,
65
+ par.toString(),
66
+ mat.toString(),
67
+ artGlobal.toString(),
68
+ rate.toString(),
69
+ spot.toString(),
70
+ line.toString(),
71
+ duty.toString(),
72
+ futureRate.toString(),
73
+ chop.toString(),
74
+ );
75
+
76
+
77
+ const collateral = cdpInfo[4];
78
+ const debt = cdpInfo[5];
79
+
80
+ const asset = wethToEth(ilkToAsset(needsIlk ? ilk : cdpInfo.ilk));
81
+
82
+ balances = {
83
+ collateral: {
84
+ [addressMapping ? getAssetInfo(asset, network).address.toLowerCase() : asset]: asset === 'WBTC' ? new Dec(collateral).div(1e10).floor().toString() : collateral,
85
+ },
86
+ debt: {
87
+ [addressMapping ? getAssetInfo('DAI', network).address.toLowerCase() : 'DAI']: new Dec(debt).times(ilkInfo.currentRate).div(1e27).floor()
88
+ .toString(),
89
+ },
90
+ };
91
+
92
+ return balances;
93
+ };
94
+
95
+ export const getMakerAccountBalances = async (
96
+ provider: EthereumProvider,
97
+ network: NetworkNumber,
98
+ block: Blockish,
99
+ addressMapping: boolean,
100
+ cdpId: string,
101
+ _managerAddress?: EthAddress,
102
+ ): Promise<PositionBalances> => _getMakerAccountBalances(getViemProvider(provider, network, { batch: { multicall: true } }), network, block, addressMapping, cdpId, _managerAddress);
103
+
104
+ export const _getUserCdps = async (provider: Client, network: NetworkNumber, userAddress: EthAddress): Promise<CdpInfo[]> => {
105
+ if (!userAddress) return [];
106
+ const mcdGetCdpsContract = McdGetCdpsContractViem(provider, network);
107
+
108
+ const mcdCdpManagerAddress = getConfigContractAddress('McdCdpManager', network);
109
+
110
+ const standardCdps = await mcdGetCdpsContract.read.getCdpsAsc([mcdCdpManagerAddress, userAddress]);
111
+
112
+ const parsedStandardCdps = standardCdps[0].map((id, i) => ({
113
+ id: parseInt(id.toString(), 10),
114
+ ilk: standardCdps[2][i].toLowerCase() as EthAddress, // collateral type
115
+ ilkLabel: bytesToString(standardCdps[2][i].toLowerCase()),
116
+ urn: standardCdps[1][i].toLowerCase() as EthAddress, // contract of cdp
117
+ asset: ilkToAsset(standardCdps[2][i]),
118
+ type: CdpType.MCD,
119
+ owner: userAddress,
120
+ }));
121
+
122
+ return parsedStandardCdps;
123
+ };
124
+
125
+ export const getUserCdps = async (
126
+ provider: EthereumProvider,
127
+ network: NetworkNumber,
128
+ userAddress: EthAddress,
129
+ ): Promise<CdpInfo[]> => _getUserCdps(getViemProvider(provider, network), network, userAddress);
130
+
131
+ export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo): Promise<CdpData> => {
132
+ const vatContract = McdVatContractViem(provider, network);
133
+ const spotterContract = McdSpotterContractViem(provider, network);
134
+ const dogContract = McdDogContractViem(provider, network);
135
+ const jugContract = McdJugContractViem(provider, network);
136
+
137
+ const [
138
+ [ink, art],
139
+ coll,
140
+ par,
141
+ [_, mat],
142
+ [artGlobal, rate, spot, line],
143
+ [duty],
144
+ futureRate,
145
+ chop,
146
+ ] = await Promise.all([
147
+ vatContract.read.urns([cdp.ilk, cdp.urn]),
148
+ vatContract.read.gem([cdp.ilk, cdp.urn]),
149
+ spotterContract.read.par(),
150
+ spotterContract.read.ilks([cdp.ilk]),
151
+ vatContract.read.ilks([cdp.ilk]),
152
+ jugContract.read.ilks([cdp.ilk]),
153
+ jugContract.read.drip([cdp.ilk]),
154
+ dogContract.read.chop([cdp.ilk]),
155
+ ]);
156
+
157
+ const collInfo = parseCollateralInfo(
158
+ cdp.ilk,
159
+ par.toString(),
160
+ mat.toString(),
161
+ artGlobal.toString(),
162
+ rate.toString(),
163
+ spot.toString(),
164
+ line.toString(),
165
+ duty.toString(),
166
+ futureRate.toString(),
167
+ chop.toString(),
168
+ );
169
+
170
+ const collateral = assetAmountInEth(ink.toString(), `MCD-${cdp.asset}`);
171
+
172
+ const collateralUsd = new Dec(collateral).mul(collInfo.assetPrice).toString();
173
+ const debt = new Dec(art).times(collInfo.currentRate).div(1e27).floor()
174
+ .toString();
175
+ const futureDebt = new Dec(art).times(collInfo.futureRate).div(1e27).floor()
176
+ .toString(); // after drip
177
+ const liquidationPrice = new Dec(debt).times(collInfo.liqRatio).div(ink).toString();
178
+
179
+ let ratio = new Dec(ink).times(collInfo.assetPrice).div(debt).times(100)
180
+ .toString();
181
+ if (new Dec(debt).eq(0)) ratio = '0';
182
+
183
+ const debtTooLow = new Dec(debt).gt(0) && new Dec(assetAmountInEth(debt, 'DAI')).lt(collInfo.minDebt);
184
+
185
+ return {
186
+ owner: cdp.owner,
187
+ id: cdp.id.toString(),
188
+ urn: cdp.urn,
189
+ type: CdpType.MCD,
190
+ ilk: cdp.ilk,
191
+ ilkLabel: collInfo.ilkLabel,
192
+ asset: cdp.asset,
193
+ collateral,
194
+ collateralUsd,
195
+ futureDebt: assetAmountInEth(futureDebt, 'DAI'),
196
+ debtDai: assetAmountInEth(debt, 'DAI'),
197
+ debtUsd: assetAmountInEth(debt, 'DAI'),
198
+ debtInAsset: assetAmountInEth(debt, 'DAI'),
199
+ debtAssetPrice: '1',
200
+ debtAssetMarketPrice: '1',
201
+ liquidationPrice,
202
+ ratio,
203
+ liqRatio: collInfo.liqRatio.toString(),
204
+ liqPercent: parseFloat(collInfo.liqPercent.toString()),
205
+ assetPrice: collInfo.assetPrice,
206
+ daiLabel: 'DAI',
207
+ debtAsset: 'DAI',
208
+ unclaimedCollateral: assetAmountInEth(coll.toString(), cdp.asset),
209
+ debtTooLow,
210
+ minDebt: collInfo.minDebt,
211
+ stabilityFee: collInfo.stabilityFee,
212
+ creatableDebt: collInfo.creatableDebt,
213
+ globalDebtCeiling: collInfo.globalDebtCeiling,
214
+ globalDebtCurrent: collInfo.globalDebtCurrent,
215
+ liquidationFee: collInfo.liquidationFee,
216
+ lastUpdated: Date.now(),
217
+ };
218
+ };
219
+
220
+ export const getMakerCdpData = async (
221
+ provider: EthereumProvider,
222
+ network: NetworkNumber,
223
+ cdp: CdpInfo,
224
224
  ): Promise<CdpData> => _getMakerCdpData(getViemProvider(provider, network), network, cdp);