@1delta/margin-fetcher 0.0.11 → 0.0.13

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 (83) hide show
  1. package/dist/lending/aave-v2-type/types.d.ts +2 -0
  2. package/dist/lending/aave-v2-type/types.d.ts.map +1 -1
  3. package/dist/lending/fetchLender.d.ts.map +1 -1
  4. package/dist/lending/fetchLender.js +25 -29
  5. package/dist/lending/fetchLenderAll.d.ts +2 -1
  6. package/dist/lending/fetchLenderAll.d.ts.map +1 -1
  7. package/dist/lending/fetchLenderAll.js +3 -3
  8. package/dist/lending/fetchLenderExt.d.ts +2 -1
  9. package/dist/lending/fetchLenderExt.d.ts.map +1 -1
  10. package/dist/lending/fetchLenderExt.js +28 -14
  11. package/dist/lending/index.d.ts +2 -0
  12. package/dist/lending/index.d.ts.map +1 -1
  13. package/dist/lending/index.js +2 -0
  14. package/dist/lending/morpho/convertPublic.d.ts +3 -5
  15. package/dist/lending/morpho/convertPublic.d.ts.map +1 -1
  16. package/dist/lending/morpho/convertPublic.js +16 -12
  17. package/dist/lending/morpho/fetchPublic.js +1 -1
  18. package/dist/lending/morpho/publicCallBuild.d.ts +1 -4
  19. package/dist/lending/morpho/publicCallBuild.d.ts.map +1 -1
  20. package/dist/lending/morpho/types.d.ts +2 -0
  21. package/dist/lending/morpho/types.d.ts.map +1 -1
  22. package/dist/lending/user-data/aave-v3-type/userCallBuild.d.ts.map +1 -1
  23. package/dist/lending/user-data/aave-v3-type/userCallBuild.js +4 -7
  24. package/dist/lending/user-data/abis.d.ts +88 -0
  25. package/dist/lending/user-data/abis.d.ts.map +1 -1
  26. package/dist/lending/user-data/abis.js +5 -1
  27. package/dist/lending/user-data/compound-v3/userCallParse.d.ts.map +1 -1
  28. package/dist/lending/user-data/compound-v3/userCallParse.js +1 -0
  29. package/dist/lending/user-data/fetchUserData.d.ts +4 -4
  30. package/dist/lending/user-data/fetchUserData.d.ts.map +1 -1
  31. package/dist/lending/user-data/fetchUserData.js +46 -25
  32. package/dist/lending/user-data/morpho/userCallBuild.d.ts +4 -5
  33. package/dist/lending/user-data/morpho/userCallBuild.d.ts.map +1 -1
  34. package/dist/lending/user-data/morpho/userCallBuild.js +15 -9
  35. package/dist/lending/user-data/morpho/userCallParse.d.ts +1 -2
  36. package/dist/lending/user-data/morpho/userCallParse.d.ts.map +1 -1
  37. package/dist/lending/user-data/morpho/userCallParse.js +15 -12
  38. package/dist/lending/user-data/types.d.ts +30 -19
  39. package/dist/lending/user-data/types.d.ts.map +1 -1
  40. package/dist/lending/user-data/types.js +12 -0
  41. package/dist/lending/user-data/utils/createGeneralUserState.d.ts +4 -4
  42. package/dist/lending/user-data/utils/createGeneralUserState.d.ts.map +1 -1
  43. package/dist/lending/user-data/utils/createGeneralUserState.js +24 -17
  44. package/dist/utils/index.d.ts +5 -3
  45. package/dist/utils/index.d.ts.map +1 -1
  46. package/dist/utils/index.js +20 -11
  47. package/dist/utils/parsing.d.ts +1 -0
  48. package/dist/utils/parsing.d.ts.map +1 -1
  49. package/dist/utils/parsing.js +3 -0
  50. package/dist/yields/index.d.ts.map +1 -1
  51. package/dist/yields/index.js +12 -5
  52. package/package.json +1 -1
  53. package/src/abis/morpho/blue.ts +99 -0
  54. package/src/abis/morpho/lens.ts +31 -0
  55. package/src/lending/aave-v2-type/types.ts +2 -0
  56. package/src/lending/fetchLender.ts +86 -49
  57. package/src/lending/fetchLenderAll.ts +30 -0
  58. package/src/lending/fetchLenderExt.ts +82 -0
  59. package/src/lending/index.ts +3 -1
  60. package/src/lending/morpho/convertPublic.ts +153 -0
  61. package/src/lending/morpho/fetchPublic.ts +80 -0
  62. package/src/lending/morpho/publicCallBuild.ts +11 -0
  63. package/src/lending/morpho/types.ts +129 -0
  64. package/src/lending/user-data/aave-v3-type/userCallBuild.ts +2 -8
  65. package/src/lending/user-data/abis.ts +4 -1
  66. package/src/lending/user-data/compound-v3/userCallParse.ts +1 -0
  67. package/src/lending/user-data/fetchUserData.ts +114 -33
  68. package/src/lending/user-data/morpho/decoder.ts +71 -0
  69. package/src/lending/user-data/morpho/morphoLib.ts +61 -0
  70. package/src/lending/user-data/morpho/types.ts +12 -0
  71. package/src/lending/user-data/morpho/userCallBuild.ts +63 -0
  72. package/src/lending/user-data/morpho/userCallParse.ts +150 -0
  73. package/src/lending/user-data/morpho/userCallParseNoDeploy.ts +168 -0
  74. package/src/lending/user-data/types.ts +64 -42
  75. package/src/lending/user-data/utils/createGeneralUserState.ts +56 -32
  76. package/src/utils/index.ts +32 -14
  77. package/src/utils/parsing.ts +5 -0
  78. package/src/yields/index.ts +13 -4
  79. package/test/lenderData.test.ts +13251 -13649
  80. package/test/mainPrices.test.ts +1 -13
  81. package/test/morpho.test.ts +20 -0
  82. package/test/userDataMorpho.test.ts +79 -0
  83. package/test/utils.ts +13 -0
@@ -1,8 +1,16 @@
1
- import { AAVE_FORK_POOL_DATA, AAVE_STYLE_RESERVE_ASSETS, AAVE_V2_LENDERS, AAVE_V3_LENDERS, COMPOUND_BASE_TOKENS, COMPOUND_STYLE_RESERVE_ASSETS, INIT_STYLE_RESERVE_ASSETS, Lender, SWAYLEND_RESERVE_ASSETS, INIT_CONFIG_DATA, } from "@1delta/asset-registry";
1
+ import { AAVE_FORK_POOL_DATA, AAVE_STYLE_RESERVE_ASSETS, AAVE_V2_LENDERS, AAVE_V3_LENDERS, COMPOUND_BASE_TOKENS, COMPOUND_STYLE_RESERVE_ASSETS, INIT_STYLE_RESERVE_ASSETS, Lender, SWAYLEND_RESERVE_ASSETS, INIT_CONFIG_DATA, MORPHO_BLUE_POOL_DATA, } from "@1delta/asset-registry";
2
2
  import { uniq } from "lodash";
3
3
  import { COMPOSERS } from "./constants";
4
4
  const AAVE_V3_KEY = "AAVE_V3";
5
5
  const COMPOUND_V3_KEY = "COMPOUND_V3";
6
+ export function isCompoundV3(lender) { return lender.startsWith(COMPOUND_V3_KEY); }
7
+ export function isCompoundV3Type(lender) { return lender.startsWith(COMPOUND_V3_KEY); }
8
+ export function isInit(lender) { return lender === Lender.INIT; }
9
+ export function isMorphoType(lender) {
10
+ return [
11
+ Lender.MORPHO_BLUE
12
+ ].includes(lender);
13
+ }
6
14
  const SWAYLEND_KEY = "SWAYLEND";
7
15
  export const AAVE_V3_2_PROTOCOLS = [Lender.AAVE_V3, Lender.AAVE_V3_ETHER_FI, Lender.AAVE_V3_PRIME];
8
16
  export function isAaveV3Type(lender) {
@@ -23,15 +31,6 @@ export function isAaveV32Type(lender) {
23
31
  export function isAaveType(lender) {
24
32
  return [...AAVE_V3_LENDERS, ...AAVE_V2_LENDERS].includes(lender);
25
33
  }
26
- export function isCompoundV3(lender) {
27
- return lender.startsWith(COMPOUND_V3_KEY);
28
- }
29
- export function isCompoundV3Type(lender) {
30
- return lender.startsWith(COMPOUND_V3_KEY);
31
- }
32
- export function isInit(lender) {
33
- return lender === Lender.INIT;
34
- }
35
34
  export function isSwaylend(lender) {
36
35
  return lender.startsWith(SWAYLEND_KEY);
37
36
  }
@@ -55,6 +54,12 @@ export const getLendersForChain = (c) => {
55
54
  if (chains.includes(c))
56
55
  lenders.push(l);
57
56
  });
57
+ // morpho
58
+ Object.entries(MORPHO_BLUE_POOL_DATA).forEach(([l, data]) => {
59
+ const chains = Object.keys(data);
60
+ if (chains.includes(c))
61
+ lenders.push(l);
62
+ });
58
63
  return lenders;
59
64
  };
60
65
  /** Filter lenders by protocol list */
@@ -63,8 +68,9 @@ export const filterLendersByProtocol = (allLenders, protocolList) => {
63
68
  if (!protocolList || protocolList.length === 0) {
64
69
  return allLenders;
65
70
  }
71
+ const hasMorpho = protocolList.includes(Lender.MORPHO_BLUE);
66
72
  // Filter lenders based on protocol list
67
- return allLenders.filter((lender) => protocolList.includes(lender));
73
+ return allLenders.filter((lender) => protocolList.includes(lender) || (hasMorpho && lender.startsWith("MORPHO_BLUE")));
68
74
  };
69
75
  const getAavesForChain = () => {
70
76
  let lenders = {};
@@ -95,3 +101,6 @@ export const getLenderAssets = (chainId, lendingProtocol = Lender.AAVE_V3) => {
95
101
  return SWAYLEND_RESERVE_ASSETS[lendingProtocol]?.[chainId ?? 0] ?? [];
96
102
  return [];
97
103
  };
104
+ export function isMultiMarket(lender) {
105
+ return lender.startsWith("MORPHO_BLUE");
106
+ }
@@ -7,6 +7,7 @@ export declare enum TimeScale {
7
7
  }
8
8
  export declare const aprToApy: (apr: number) => number;
9
9
  export declare const apyToApr: (apy: number) => number;
10
+ export declare const apyToAprPercent: (apy: number) => number;
10
11
  export declare const formatAaveYieldToNumber: (n?: string | bigint) => number;
11
12
  export declare const calculateRateForCompound: (n: string, chainId: string, lender?: Lender) => number;
12
13
  export declare const formatAaveRawApyToApr: (raw: bigint | string | undefined) => number;
@@ -1 +1 @@
1
- {"version":3,"file":"parsing.d.ts","sourceRoot":"","sources":["../../src/utils/parsing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAIvD,eAAO,MAAM,GAAG,QAAQ,CAAC;AAEzB,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,iBAAa,KAAG,MAO/D,CAAC;AAEF,oBAAY,SAAS;IACnB,KAAK,IAAA;IACL,EAAE,IAAA;CACH;AAYD,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,WAEnC,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,WAEnC,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,IAAI,MAAM,GAAG,MAAM,KAAG,MAG7D,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,GAAG,MAAM,EACT,SAAS,MAAM,EACf,eAAiC,KAChC,MAgBF,CAAC;AACF,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,WAGrE,CAAC;AAGF,eAAO,MAAM,gBAAgB,GAAI,eAAe,MAAM,GAAG,MAAM,WAI9D,CAAC"}
1
+ {"version":3,"file":"parsing.d.ts","sourceRoot":"","sources":["../../src/utils/parsing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAIvD,eAAO,MAAM,GAAG,QAAQ,CAAC;AAEzB,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,iBAAa,KAAG,MAO/D,CAAC;AAEF,oBAAY,SAAS;IACnB,KAAK,IAAA;IACL,EAAE,IAAA;CACH;AAYD,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,WAEnC,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,WAEnC,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,WAE1C,CAAC;AAGF,eAAO,MAAM,uBAAuB,GAAI,IAAI,MAAM,GAAG,MAAM,KAAG,MAG7D,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,GAAG,MAAM,EACT,SAAS,MAAM,EACf,eAAiC,KAChC,MAgBF,CAAC;AACF,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,WAGrE,CAAC;AAGF,eAAO,MAAM,gBAAgB,GAAI,eAAe,MAAM,GAAG,MAAM,WAI9D,CAAC"}
@@ -30,6 +30,9 @@ export const aprToApy = (apr) => {
30
30
  export const apyToApr = (apy) => {
31
31
  return ((apy + 1) ** (1 / SECONDS_PER_YEAR) - 1) * SECONDS_PER_YEAR;
32
32
  };
33
+ export const apyToAprPercent = (apy) => {
34
+ return 100 * ((apy / 100 + 1) ** (1 / SECONDS_PER_YEAR) - 1) * SECONDS_PER_YEAR;
35
+ };
33
36
  export const formatAaveYieldToNumber = (n) => {
34
37
  if (!n)
35
38
  return 0;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/yields/index.ts"],"names":[],"mappings":"AAiCA,UAAU,iBAAiB;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,qBAAqB,EAAE,GAAG,CAAA;IAC1B,oBAAoB,EAAE,GAAG,CAAA;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACnC,eAAe,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;IACxD,aAAa,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG;YAAE,CAAC,MAAM,EAAE,MAAM,GAAG;gBAAE,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAA;CACrG;AAYD,eAAO,MAAM,kBAAkB,uCA6I9B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/yields/index.ts"],"names":[],"mappings":"AAkCA,UAAU,iBAAiB;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,qBAAqB,EAAE,GAAG,CAAA;IAC1B,oBAAoB,EAAE,GAAG,CAAA;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACnC,eAAe,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;IACxD,aAAa,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG;YAAE,CAAC,MAAM,EAAE,MAAM,GAAG;gBAAE,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAA;CACrG;AAYD,eAAO,MAAM,kBAAkB,uCAqJ9B,CAAA"}
@@ -1,4 +1,4 @@
1
- import { apyToApr } from "../utils/parsing";
1
+ import { apyToAprPercent, apyToApr } from "../utils/parsing";
2
2
  const FeedData = {
3
3
  WSTETH: 'https://eth-api.lido.fi/v1/protocol/steth/apr/sma',
4
4
  STMATIC: 'https://polygon.lido.fi/api/stats',
@@ -11,6 +11,7 @@ const FeedData = {
11
11
  WEETH: 'https://www.ether.fi/api/apr',
12
12
  SAVAX: "https://api.benqi.fi/liquidstaking/apr",
13
13
  RSETH: "https://universe.kelpdao.xyz/rseth/totalApy",
14
+ TRUMATIC: "https://api.trufin.io/staker/apy?staker=MATIC"
14
15
  };
15
16
  const LenderAPIs = {
16
17
  MERIDIAN: 'https://omnidex.bmaa3ajd1gjri.eu-west-2.cs.amazonlightsail.com/lending_yields'
@@ -81,7 +82,7 @@ export const fetchGeneralYields = async () => {
81
82
  const susdePromise = safeFetch('SUSDE', async () => {
82
83
  try {
83
84
  const res = await fetch(FeedData.SUSDE).then(r => r.json());
84
- return Number(res?.data[0]?.apy ?? 0);
85
+ return apyToAprPercent(res?.data[0]?.apy ?? 0);
85
86
  }
86
87
  catch (e) {
87
88
  return 0;
@@ -89,7 +90,11 @@ export const fetchGeneralYields = async () => {
89
90
  });
90
91
  const rsethPromise = safeFetch('RSETH', async () => {
91
92
  const res = await fetch(FeedData.RSETH).then(r => r.json());
92
- return Number(res.totalAPY);
93
+ return apyToAprPercent(res.totalAPY);
94
+ });
95
+ const trumaticPromise = safeFetch('TRUMATIC', async () => {
96
+ const res = await fetch(FeedData.TRUMATIC).then(r => r.json());
97
+ return apyToAprPercent(res.apy);
93
98
  });
94
99
  const cbethPromise = safeFetch('CBETH', async () => {
95
100
  try {
@@ -99,7 +104,7 @@ export const fetchGeneralYields = async () => {
99
104
  "Content-Type": "application/json"
100
105
  }
101
106
  }).then(r => r.json());
102
- return Number(res.apy) * 100;
107
+ return apyToAprPercent(res.apy) * 100;
103
108
  }
104
109
  catch (e) {
105
110
  console.log("CBETH failed", e);
@@ -116,7 +121,7 @@ export const fetchGeneralYields = async () => {
116
121
  }
117
122
  })));
118
123
  });
119
- const [wstethData, ezethData, rethData, weethData, stmaticData, methData, maticXdata, susdeData, meridianData, savaxData, cbethData, rsethData,] = await Promise.all([
124
+ const [wstethData, ezethData, rethData, weethData, stmaticData, methData, maticXdata, susdeData, meridianData, savaxData, cbethData, rsethData, trumaticData] = await Promise.all([
120
125
  wstethPromise,
121
126
  ezethPromise,
122
127
  rethPromise,
@@ -129,6 +134,7 @@ export const fetchGeneralYields = async () => {
129
134
  savaxPromise,
130
135
  cbethPromise,
131
136
  rsethPromise,
137
+ trumaticPromise,
132
138
  ]);
133
139
  const data = {
134
140
  intrinsicYields: {
@@ -146,6 +152,7 @@ export const fetchGeneralYields = async () => {
146
152
  SAVAX: savaxData,
147
153
  CBETH: cbethData,
148
154
  RSETH: rsethData,
155
+ TRUMATIC: trumaticData,
149
156
  },
150
157
  lenderRewards: {
151
158
  "167000": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1delta/margin-fetcher",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,99 @@
1
+ export const MorphoBlueAbi = [
2
+ {
3
+ "inputs": [
4
+ {
5
+ "internalType": "Id",
6
+ "name": "",
7
+ "type": "bytes32"
8
+ },
9
+ {
10
+ "internalType": "address",
11
+ "name": "",
12
+ "type": "address"
13
+ }
14
+ ],
15
+ "name": "position",
16
+ "outputs": [
17
+ {
18
+ "internalType": "uint256",
19
+ "name": "supplyShares",
20
+ "type": "uint256"
21
+ },
22
+ {
23
+ "internalType": "uint128",
24
+ "name": "borrowShares",
25
+ "type": "uint128"
26
+ },
27
+ {
28
+ "internalType": "uint128",
29
+ "name": "collateral",
30
+ "type": "uint128"
31
+ }
32
+ ],
33
+ "stateMutability": "view",
34
+ "type": "function"
35
+ },
36
+ {
37
+ "inputs": [
38
+ {
39
+ "internalType": "bytes32[]",
40
+ "name": "slots",
41
+ "type": "bytes32[]"
42
+ }
43
+ ],
44
+ "name": "extSloads",
45
+ "outputs": [
46
+ {
47
+ "internalType": "bytes32[]",
48
+ "name": "res",
49
+ "type": "bytes32[]"
50
+ }
51
+ ],
52
+ "stateMutability": "view",
53
+ "type": "function"
54
+ },
55
+ {
56
+ "inputs": [
57
+ {
58
+ "internalType": "Id",
59
+ "name": "",
60
+ "type": "bytes32"
61
+ }
62
+ ],
63
+ "name": "market",
64
+ "outputs": [
65
+ {
66
+ "internalType": "uint128",
67
+ "name": "totalSupplyAssets",
68
+ "type": "uint128"
69
+ },
70
+ {
71
+ "internalType": "uint128",
72
+ "name": "totalSupplyShares",
73
+ "type": "uint128"
74
+ },
75
+ {
76
+ "internalType": "uint128",
77
+ "name": "totalBorrowAssets",
78
+ "type": "uint128"
79
+ },
80
+ {
81
+ "internalType": "uint128",
82
+ "name": "totalBorrowShares",
83
+ "type": "uint128"
84
+ },
85
+ {
86
+ "internalType": "uint128",
87
+ "name": "lastUpdate",
88
+ "type": "uint128"
89
+ },
90
+ {
91
+ "internalType": "uint128",
92
+ "name": "fee",
93
+ "type": "uint128"
94
+ }
95
+ ],
96
+ "stateMutability": "view",
97
+ "type": "function"
98
+ },
99
+ ] as const
@@ -0,0 +1,31 @@
1
+ export const MorphoLensAbi = [
2
+ {
3
+ "inputs": [
4
+ {
5
+ "internalType": "bytes32[]",
6
+ "name": "marketsIds",
7
+ "type": "bytes32[]"
8
+ },
9
+ {
10
+ "internalType": "address",
11
+ "name": "user",
12
+ "type": "address"
13
+ },
14
+ {
15
+ "internalType": "address",
16
+ "name": "morpho",
17
+ "type": "address"
18
+ }
19
+ ],
20
+ "name": "getUserDataCompact",
21
+ "outputs": [
22
+ {
23
+ "internalType": "bytes",
24
+ "name": "data",
25
+ "type": "bytes"
26
+ }
27
+ ],
28
+ "stateMutability": "view",
29
+ "type": "function"
30
+ }
31
+ ]
@@ -1,4 +1,5 @@
1
1
  import { RewardsMap } from "../aave-v3-type/types";
2
+ import { GenericCurrency } from "../types";
2
3
 
3
4
 
4
5
  export enum AaveV2TypeGetReserveDataIndexes {
@@ -53,6 +54,7 @@ export enum AaveV2TypeIncentivesControllerPoolInfoIndexes {
53
54
  export interface AaveV2GeneralPublicResponse {
54
55
  data: {
55
56
  [tokenSymbol: string]: {
57
+ asset: GenericCurrency
56
58
  // token amounts
57
59
  totalDeposits: number;
58
60
  totalDebtStable: number;
@@ -1,4 +1,3 @@
1
-
2
1
  // aave v2 style
3
2
  import { ProtocolDataProviderAbi } from '../abis/aave-v2/ProtocolDataProvider'
4
3
  import { IncentivesControllerAbi } from '../abis/lendle/IncentivesController'
@@ -17,7 +16,13 @@ import { CometAbi } from '../abis/compound-v3/Comet'
17
16
  import { CometExtAbi } from '../abis/compound-v3/CometExt'
18
17
  import { IrgetterAbi } from '../abis/compound-v3/IrGetter'
19
18
 
20
- import { isAaveV2Type, isAaveV3Original, isAaveV3Type, isCompoundV3, isInit } from '../utils'
19
+ import {
20
+ isAaveV2Type,
21
+ isAaveV3Original,
22
+ isAaveV3Type,
23
+ isCompoundV3,
24
+ isInit,
25
+ } from '../utils'
21
26
  import { AdditionalYields, MulticallRetryFunction } from '../types'
22
27
  import { buildAaveV2StyleLenderReserveCall } from './aave-v2-type/publicCallBuild'
23
28
  import { buildAaveV3StyleLenderReserveCall } from './aave-v3-type/publicCallBuild'
@@ -35,10 +40,14 @@ import { YLDRProtocolDataProviderAbi } from '../abis/aave-v2/YLDR'
35
40
  import { GenericTokenList } from './types'
36
41
 
37
42
  function buildLenderCall(chainId: string, lender: Lender) {
38
- if (isAaveV2Type(lender)) return buildAaveV2StyleLenderReserveCall(chainId, lender)
39
- if (isAaveV3Type(lender)) return buildAaveV3StyleLenderReserveCall(chainId, lender)
43
+ if (isAaveV2Type(lender))
44
+ return buildAaveV2StyleLenderReserveCall(chainId, lender)
45
+ if (isAaveV3Type(lender))
46
+ return buildAaveV3StyleLenderReserveCall(chainId, lender)
47
+ if (isCompoundV3(lender))
48
+ return buildCompoundV3StyleLenderReserveCall(chainId, lender)
40
49
  if (isInit(lender)) return buildInitStyleLenderReserveCall(chainId, lender)
41
- return buildCompoundV3StyleLenderReserveCall(chainId, lender)
50
+ return []
42
51
  }
43
52
 
44
53
  function getLenderDataConverter(
@@ -46,44 +55,63 @@ function getLenderDataConverter(
46
55
  chainId: string,
47
56
  prices: { [a: string]: number },
48
57
  additionalYields: AdditionalYields,
49
- tokenList: GenericTokenList = {}
58
+ tokenList: GenericTokenList = {},
50
59
  ) {
51
- if (isAaveV2Type(lender)) return getAaveV2ReservesDataConverter(lender, chainId, prices, additionalYields, tokenList)
52
- if (isAaveV3Type(lender)) return getAaveV3ReservesDataConverter(lender, chainId, prices, additionalYields, tokenList)
53
- if (isInit(lender)) return getInitReservesDataConverter(lender, chainId, prices, additionalYields, tokenList)
54
- return getCompoundV3ReservesDataConverter(lender, chainId, prices, additionalYields, tokenList)
60
+ if (isAaveV2Type(lender))
61
+ return getAaveV2ReservesDataConverter(
62
+ lender,
63
+ chainId,
64
+ prices,
65
+ additionalYields,
66
+ tokenList,
67
+ )
68
+ if (isAaveV3Type(lender))
69
+ return getAaveV3ReservesDataConverter(
70
+ lender,
71
+ chainId,
72
+ prices,
73
+ additionalYields,
74
+ tokenList,
75
+ )
76
+ if (isCompoundV3(lender))
77
+ return getCompoundV3ReservesDataConverter(
78
+ lender,
79
+ chainId,
80
+ prices,
81
+ additionalYields,
82
+ tokenList,
83
+ )
84
+
85
+ if (isInit(lender))
86
+ return getInitReservesDataConverter(
87
+ lender,
88
+ chainId,
89
+ prices,
90
+ additionalYields,
91
+ tokenList,
92
+ )
93
+ return [() => null, 0] as any
55
94
  }
56
95
 
57
96
  const getAbi = (lender: string) => {
58
- if (isAaveV2Type(lender)) return [
59
- ...ProtocolDataProviderAbi,
60
- ...UniswapV2PairAbi,
61
- ...RewarderAbi,
62
- ...IncentivesControllerAbi
63
- ]
64
-
65
- if (isAaveV3Original(lender)) return [
66
- ...AavePoolV3UpgradedAbi,
67
- ...AaveV3ProtocolDataProviderAbi
68
- ]
69
- if (lender === Lender.YLDR) return [
70
- ...YLDRProtocolDataProviderAbi,
71
- ]
72
-
73
- if (isAaveV3Type(lender)) return [
74
- ...AavePoolLegacyAbi,
75
- ...AavePoolDataProviderLegacyAbi
76
- ]
77
-
78
-
79
- if (isCompoundV3(lender)) return [
80
- ...IrgetterAbi,
81
- ...CometAbi,
82
- ...CometExtAbi
83
- ]
97
+ if (isAaveV2Type(lender))
98
+ return [
99
+ ...ProtocolDataProviderAbi,
100
+ ...UniswapV2PairAbi,
101
+ ...RewarderAbi,
102
+ ...IncentivesControllerAbi,
103
+ ]
84
104
 
85
- if (isInit(lender))
86
- return InitLensAbi
105
+ if (isAaveV3Original(lender))
106
+ return [...AavePoolV3UpgradedAbi, ...AaveV3ProtocolDataProviderAbi]
107
+ if (lender === Lender.YLDR) return [...YLDRProtocolDataProviderAbi]
108
+
109
+ if (isAaveV3Type(lender))
110
+ return [...AavePoolLegacyAbi, ...AavePoolDataProviderLegacyAbi]
111
+
112
+ if (isCompoundV3(lender)) return [...IrgetterAbi, ...CometAbi, ...CometExtAbi]
113
+
114
+ if (isInit(lender)) return InitLensAbi
87
115
 
88
116
  return []
89
117
  }
@@ -94,7 +122,9 @@ export const getLenderPublicData = async (
94
122
  prices: { [asset: string]: number },
95
123
  additionalYields: AdditionalYields,
96
124
  multicallRetry: MulticallRetryFunction,
97
- tokenList: () => Promise<GenericTokenList> = async () => { return {} }
125
+ tokenList: () => Promise<GenericTokenList> = async () => {
126
+ return {}
127
+ },
98
128
  ): Promise<{ [lender: string]: any }> => {
99
129
  let calls: {
100
130
  call: Call
@@ -127,17 +157,24 @@ export const getLenderPublicData = async (
127
157
 
128
158
  let currentSlice = 0
129
159
  for (const lender of lenders) {
130
- const [converter, sliceLength] = getLenderDataConverter(lender, chainId, prices, additionalYields, list)
131
-
132
- const data = rawResults.slice(currentSlice, currentSlice + sliceLength)
133
- const convertedData = converter(data)
134
- if (!convertedData) {
135
- invalidLenders.push(lender)
136
- } else {
137
- lenderData[lender] = convertedData
160
+ const [converter, sliceLength] = getLenderDataConverter(
161
+ lender,
162
+ chainId,
163
+ prices,
164
+ additionalYields,
165
+ list,
166
+ )
167
+ if (sliceLength > 0) {
168
+ const data = rawResults.slice(currentSlice, currentSlice + sliceLength)
169
+ const convertedData = converter(data)
170
+ if (!convertedData) {
171
+ invalidLenders.push(lender)
172
+ } else {
173
+ lenderData[lender] = convertedData
174
+ }
175
+
176
+ currentSlice += sliceLength
138
177
  }
139
-
140
- currentSlice += sliceLength
141
178
  }
142
179
 
143
180
  return lenderData
@@ -0,0 +1,30 @@
1
+ import { AdditionalYields, MulticallRetryFunction } from '../types'
2
+ import { Lender } from '@1delta/asset-registry'
3
+ import { getLenderPublicData } from './fetchLender'
4
+ import { getLenderPublicDataViaApi } from './fetchLenderExt'
5
+ import { GenericTokenList } from './types'
6
+
7
+ const LENDERS_VIA_API: string[] = [Lender.MORPHO_BLUE]
8
+
9
+ export const getLenderPublicDataAll = async (
10
+ chainId: string,
11
+ lenders: Lender[],
12
+ prices: { [asset: string]: number },
13
+ additionalYields: AdditionalYields,
14
+ multicallRetry: MulticallRetryFunction,
15
+ tokenList?: () => Promise<GenericTokenList>
16
+ ): Promise<{ [lender: string]: any }> => {
17
+
18
+ const lendersApi = lenders.filter(l => LENDERS_VIA_API.includes(l))
19
+
20
+ const lendersOnChain = lenders.filter(l => !LENDERS_VIA_API.includes(l))
21
+
22
+ const onChain = getLenderPublicData(chainId, lendersOnChain, prices, additionalYields, multicallRetry, tokenList)
23
+
24
+ const api = getLenderPublicDataViaApi(chainId, lendersApi, prices, additionalYields, tokenList)
25
+
26
+ const [onChainRes, apiRes] = await Promise.all([onChain, api])
27
+
28
+ return { ...onChainRes, ...apiRes }
29
+
30
+ }
@@ -0,0 +1,82 @@
1
+ import { isMorphoType, isMultiMarket } from '../utils'
2
+ import { AdditionalYields } from '../types'
3
+ import { Lender } from '@1delta/asset-registry'
4
+ import { GenericTokenList } from './types'
5
+ import { fetchMorphoMarkets } from './morpho/fetchPublic'
6
+ import { convertMarketsToMorphoResponse } from './morpho/convertPublic'
7
+
8
+ async function getLenderDataFromApi(
9
+ lender: Lender,
10
+ chainId: string,
11
+ prices: { [a: string]: number },
12
+ additionalYields: AdditionalYields,
13
+ ) {
14
+ if (isMorphoType(lender)) return await fetchMorphoMarkets(chainId)
15
+ return {}
16
+ }
17
+
18
+ function convertLenderDataFromApi(
19
+ lender: Lender,
20
+ chainId: string,
21
+ data: any,
22
+ prices: { [a: string]: number },
23
+ additionalYields: AdditionalYields,
24
+ list: GenericTokenList = {},
25
+ ) {
26
+ if (isMorphoType(lender))
27
+ return convertMarketsToMorphoResponse(data, chainId, additionalYields, list)
28
+ return {}
29
+ }
30
+
31
+ export const getLenderPublicDataViaApi = async (
32
+ chainId: string,
33
+ lenders: Lender[],
34
+ prices: { [asset: string]: number },
35
+ additionalYields: AdditionalYields,
36
+ tokenList: () => Promise<GenericTokenList> = async () => {
37
+ return {}
38
+ },
39
+ ): Promise<{ [lender: string]: any }> => {
40
+ let promises: any[] = []
41
+ for (const lender of lenders) {
42
+ promises.push(
43
+ getLenderDataFromApi(lender, chainId, prices, additionalYields),
44
+ )
45
+ }
46
+
47
+ const [list, ...results] = await Promise.all([tokenList(), ...promises])
48
+
49
+ const lenderData: { [lender: string]: any } = {}
50
+ for (let i = 0; i < lenders.length; i++) {
51
+ try {
52
+ const lender = lenders[i]
53
+ if (isMultiMarket(lender)) {
54
+ const dataObtained = results[i]
55
+ const converted: any = convertLenderDataFromApi(
56
+ lender,
57
+ chainId,
58
+ dataObtained,
59
+ prices,
60
+ additionalYields,
61
+ list,
62
+ )
63
+ Object.keys(converted).forEach((marketId: string) => {
64
+ lenderData[marketId] = converted[marketId]
65
+ })
66
+ } else {
67
+ lenderData[lender] = convertLenderDataFromApi(
68
+ lender,
69
+ chainId,
70
+ results[i],
71
+ prices,
72
+ additionalYields,
73
+ list,
74
+ )
75
+ }
76
+ } catch (e) {
77
+ console.log('error fetching from API on', chainId, ':', e)
78
+ }
79
+ }
80
+
81
+ return lenderData
82
+ }
@@ -1,3 +1,5 @@
1
1
  export * from "./fetchLender"
2
+ export * from "./fetchLenderExt"
3
+ export * from "./fetchLenderAll"
2
4
  export * from "./user-data"
3
- export * from "./types"
5
+ export * from "./types"