@1delta/margin-fetcher 0.0.24 → 0.0.25

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 (25) hide show
  1. package/dist/lending/user-data/compound-v3/index.d.ts +0 -1
  2. package/dist/lending/user-data/compound-v3/index.d.ts.map +1 -1
  3. package/dist/lending/user-data/compound-v3/index.js +0 -1
  4. package/dist/lending/user-data/compound-v3/userCallBuild.d.ts +2 -2
  5. package/dist/lending/user-data/compound-v3/userCallBuild.d.ts.map +1 -1
  6. package/dist/lending/user-data/compound-v3/userCallBuild.js +6 -10
  7. package/dist/lending/user-data/compound-v3/userCallParse.js +2 -2
  8. package/dist/lending/user-data/fetchUserData.d.ts.map +1 -1
  9. package/dist/lending/user-data/morpho/userCallParse.d.ts.map +1 -1
  10. package/dist/lending/user-data/morpho/userCallParse.js +8 -1
  11. package/dist/prices/main-prices/addresses/morpho.d.ts.map +1 -1
  12. package/dist/prices/main-prices/addresses/morpho.js +1311 -0
  13. package/package.json +1 -1
  14. package/src/lending/user-data/compound-v3/index.ts +1 -2
  15. package/src/lending/user-data/compound-v3/userCallBuild.ts +18 -16
  16. package/src/lending/user-data/compound-v3/userCallParse.ts +2 -2
  17. package/src/lending/user-data/fetchUserData.ts +0 -1
  18. package/src/lending/user-data/morpho/userCallParse.ts +11 -3
  19. package/src/prices/main-prices/addresses/morpho.ts +1311 -0
  20. package/test/morphoPrice.test.ts +1 -1
  21. package/test/userDataMorpho.test.ts +203 -13
  22. package/dist/lending/user-data/compound-v3/addresses.d.ts +0 -10
  23. package/dist/lending/user-data/compound-v3/addresses.d.ts.map +0 -1
  24. package/dist/lending/user-data/compound-v3/addresses.js +0 -33
  25. package/src/lending/user-data/compound-v3/addresses.ts +0 -59
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1delta/margin-fetcher",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,3 +1,2 @@
1
1
  export * from "./userCallBuild"
2
- export * from "./userCallParse"
3
- export * from "./addresses"
2
+ export * from "./userCallParse"
@@ -1,14 +1,21 @@
1
- import { Lender } from "@1delta/asset-registry"
2
- import { Call } from "../../../utils/multicall"
3
- import { getLenderAssets } from "../../../utils"
4
- import { getCompoundV3BaseAsset, getCompoundV3CometAddress, getCompoundV3CometRewardsAddress } from "./addresses"
1
+ import { Lender } from '@1delta/asset-registry'
2
+ import { Call } from '../../../utils/multicall'
3
+ import { getLenderAssets } from '../../../utils'
4
+ import {
5
+ getCompoundV3BaseAsset,
6
+ getCompoundV3CometAddress,
7
+ getCompoundV3CometRewardsAddress,
8
+ } from '../../addresses/compoundV3'
5
9
 
6
- export const buildCompoundV3UserCall = (chainId: string, lender: Lender, account: string): Call[] => {
7
-
8
- const baseAsset = getCompoundV3BaseAsset(lender, chainId).baseAsset
10
+ export const buildCompoundV3UserCall = (
11
+ chainId: string,
12
+ lender: Lender,
13
+ account: string,
14
+ ): Call[] => {
15
+ const baseAsset = getCompoundV3BaseAsset(lender, chainId)?.baseAsset
9
16
  const cometContractAddress = getCompoundV3CometAddress(chainId, lender)!
10
17
  const assets = getLenderAssets(chainId, lender)
11
- const assetsNoBase = assets.filter(a => a !== baseAsset)
18
+ const assetsNoBase = assets.filter((a) => a !== baseAsset)
12
19
 
13
20
  const baseCalls = [
14
21
  {
@@ -20,7 +27,7 @@ export const buildCompoundV3UserCall = (chainId: string, lender: Lender, account
20
27
  address: cometContractAddress,
21
28
  name: 'borrowBalanceOf',
22
29
  params: [account],
23
- }
30
+ },
24
31
  ]
25
32
 
26
33
  const callsNonBase: Call[] = assetsNoBase.map((tk) => {
@@ -36,11 +43,6 @@ export const buildCompoundV3UserCall = (chainId: string, lender: Lender, account
36
43
  name: 'getRewardOwed',
37
44
  params: [cometContractAddress, account],
38
45
  }
39
- const calls = [
40
- ...callsNonBase,
41
- ...baseCalls,
42
- callEarnedBalances
43
- ]
46
+ const calls = [...callsNonBase, ...baseCalls, callEarnedBalances]
44
47
  return calls
45
-
46
- }
48
+ }
@@ -6,7 +6,7 @@ import {
6
6
  toGenericPriceKey,
7
7
  toOracleKey,
8
8
  } from '../../../assets'
9
- import { getCompoundV3BaseAsset } from './addresses'
9
+ import { getCompoundV3BaseAsset } from '../../addresses/compoundV3'
10
10
  import { parseRawAmount } from '../../../utils/parsing'
11
11
  import { Asset as SupportedAssets } from '@1delta/asset-registry'
12
12
  import { createBaseTypeUserState } from '../utils'
@@ -20,7 +20,7 @@ export const getCompoundV3UserDataConverter = (
20
20
  lenderData: any,
21
21
  ): [(data: any[]) => CompoundV3UserReserveResponse | undefined, number] => {
22
22
  const assetAddresses = getCompoundV3Assets(chainId, lender)
23
- const baseAsset = getCompoundV3BaseAsset(lender, chainId).baseAsset
23
+ const baseAsset = getCompoundV3BaseAsset(lender, chainId)?.baseAsset
24
24
  const assetsNoBase = assetAddresses.filter((a) => a !== baseAsset)
25
25
  const expectedNumberOfCalls = assetsNoBase.length + 2 + 1
26
26
  return [
@@ -162,7 +162,6 @@ export const convertLenderUserDataResult = (
162
162
  lenderState: any,
163
163
  ): { [lender: string]: any } => {
164
164
  const queries = organizeUserQueries(queriesRaw)
165
-
166
165
  const lenderData: { [lender: string]: any } = {}
167
166
  let currentSlice = 0
168
167
  for (const query of queries) {
@@ -66,16 +66,24 @@ export const getMorphoUserDataConverterWithlens = (
66
66
  if (data.length !== expectedNumberOfCalls) {
67
67
  return undefined
68
68
  }
69
+
70
+ // we map the index from the return data
71
+ // to the real chunk
72
+ // it is
73
+ // (chunk number) * (chunksize = 100) + index
74
+ function mapMarketToChunk(i: number, c: number) {
75
+ return (c + 1) * 100 + i
76
+ }
77
+
69
78
  let marketsHandled: string[] = []
70
79
  // de-chunk the calldata
71
80
  const returnDatas = data.flatMap((d) => decodePackedDataset(d))
72
-
73
81
  let datas: { [market: string]: MorphoUserReserveResponse } = {}
74
82
  for (let i = 0; i < returnDatas.length; i++) {
75
83
  let totalDebt24h = 0
76
84
  let totalDeposits24h = 0
77
85
  const balanceData = returnDatas[i]
78
- const markeId = markets[balanceData.index]
86
+ const markeId = markets[mapMarketToChunk(balanceData.index, i)]
79
87
  marketsHandled.push(markeId)
80
88
  const market = lenderData[markeId]?.params?.market
81
89
  const { dataForMarket, addedDebt, addedDeposits } =
@@ -114,7 +122,7 @@ export const getMorphoUserDataConverterWithlens = (
114
122
 
115
123
  for (const marketId of markets) {
116
124
  const pubData = lenderData[marketId]
117
- if (marketsHandled.includes(marketId)) continue;
125
+ if (marketsHandled.includes(marketId)) continue
118
126
  const payload = {
119
127
  chainId,
120
128
  account,