@1delta/margin-fetcher 0.0.18 → 0.0.19

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 (72) hide show
  1. package/dist/assets/liquidityThresholds.d.ts +10 -0
  2. package/dist/assets/liquidityThresholds.d.ts.map +1 -1
  3. package/dist/assets/liquidityThresholds.js +9 -2
  4. package/dist/flash-liquidity/fetchLiquidity.d.ts +2 -2
  5. package/dist/flash-liquidity/fetchLiquidity.d.ts.map +1 -1
  6. package/dist/flash-liquidity/fetchLiquidity.js +85 -54
  7. package/dist/flash-liquidity/types.d.ts +1 -0
  8. package/dist/flash-liquidity/types.d.ts.map +1 -1
  9. package/dist/lending/aave-v3-type/publicCallBuild.d.ts +1 -1
  10. package/dist/lending/aave-v3-type/publicCallBuild.d.ts.map +1 -1
  11. package/dist/lending/aave-v3-type/publicCallBuild.js +46 -48
  12. package/dist/lending/aave-v3-type/publicCallParse.d.ts.map +1 -1
  13. package/dist/lending/aave-v3-type/publicCallParse.js +8 -2
  14. package/dist/lending/compound-v3/publicCallParse.d.ts.map +1 -1
  15. package/dist/lending/compound-v3/publicCallParse.js +8 -3
  16. package/dist/lending/fetchLender.js +2 -2
  17. package/dist/lending/morpho/convertPublic.js +1 -1
  18. package/dist/lending/user-data/types.js +2 -2
  19. package/dist/lending-pairs/computeLendingPairs.d.ts +10 -1
  20. package/dist/lending-pairs/computeLendingPairs.d.ts.map +1 -1
  21. package/dist/lending-pairs/computeLendingPairs.js +26 -22
  22. package/dist/prices/defillama/index.d.ts.map +1 -1
  23. package/dist/prices/defillama/index.js +162 -151
  24. package/dist/prices/index.d.ts +3 -2
  25. package/dist/prices/index.d.ts.map +1 -1
  26. package/dist/prices/index.js +3 -2
  27. package/dist/prices/main-prices/addresses/aaveOracles.d.ts +159 -143
  28. package/dist/prices/main-prices/addresses/aaveOracles.d.ts.map +1 -1
  29. package/dist/prices/main-prices/addresses/aaveOracles.js +276 -260
  30. package/dist/prices/main-prices/addresses/morpho.d.ts.map +1 -1
  31. package/dist/prices/main-prices/addresses/morpho.js +114 -0
  32. package/dist/prices/main-prices/fetchOracleData.d.ts.map +1 -1
  33. package/dist/prices/main-prices/fetchOracleData.js +21 -9
  34. package/dist/prices/pendle/fetchPendlePrices.d.ts +7 -0
  35. package/dist/prices/pendle/fetchPendlePrices.d.ts.map +1 -0
  36. package/dist/prices/pendle/fetchPendlePrices.js +148 -0
  37. package/dist/prices/pendle/index.d.ts +2 -0
  38. package/dist/prices/pendle/index.d.ts.map +1 -0
  39. package/dist/prices/pendle/index.js +1 -0
  40. package/dist/types/apiReturnType.d.ts +2 -0
  41. package/dist/types/apiReturnType.d.ts.map +1 -1
  42. package/dist/utils/index.d.ts +1 -3
  43. package/dist/utils/index.d.ts.map +1 -1
  44. package/dist/utils/index.js +10 -16
  45. package/dist/yields/index.d.ts.map +1 -1
  46. package/dist/yields/index.js +46 -33
  47. package/package.json +3 -6
  48. package/src/assets/liquidityThresholds.ts +22 -3
  49. package/src/flash-liquidity/fetchLiquidity.ts +298 -261
  50. package/src/flash-liquidity/types.ts +1 -0
  51. package/src/lending/aave-v3-type/publicCallBuild.ts +74 -68
  52. package/src/lending/aave-v3-type/publicCallParse.ts +8 -2
  53. package/src/lending/compound-v3/publicCallParse.ts +10 -3
  54. package/src/lending/fetchLender.ts +2 -2
  55. package/src/lending/morpho/convertPublic.ts +1 -1
  56. package/src/lending/user-data/types.ts +2 -2
  57. package/src/lending-pairs/computeLendingPairs.ts +423 -410
  58. package/src/prices/defillama/index.ts +233 -227
  59. package/src/prices/index.ts +3 -2
  60. package/src/prices/main-prices/addresses/aaveOracles.ts +292 -277
  61. package/src/prices/main-prices/addresses/morpho.ts +114 -0
  62. package/src/prices/main-prices/fetchOracleData.ts +29 -22
  63. package/src/prices/pendle/fetchPendlePrices.ts +208 -0
  64. package/src/prices/pendle/index.ts +1 -0
  65. package/src/types/apiReturnType.ts +42 -39
  66. package/src/utils/index.ts +11 -18
  67. package/src/yields/index.ts +205 -179
  68. package/test/flashLiquidity.test.ts +40 -0
  69. package/test/lenderData.test.ts +18 -13254
  70. package/test/mainPrices.test.ts +24 -19
  71. package/test/morphoPrice.test.ts +1 -1
  72. package/test/userDataAave.test.ts +73 -0
@@ -1,300 +1,337 @@
1
- import { getAaveStyleProtocolTokenMap, getAaveTypePoolAddress, getAssetMeta } from "../assets";
2
- import { AAVES_PER_CHAIN } from "../utils";
3
1
  import {
4
- RELEVANT_BALANCER_V2_FORKS,
5
- RELEVANT_BALANCER_V3_FORKS,
6
- RELEVANT_LENDING_ASSETS,
7
- RELEVANT_MORPHOB_FORKS,
8
- RELEVANT_UNISWAP_V4_FORKS
9
- } from "./assets";
10
- import { Call } from "../utils/multicall";
11
- import { MulticallRetryFunction } from "../types";
12
- import { FlashAbi } from "../abis/flashloan-united/flashAbi";
13
- import { FlashLiquiditiesOnChain, FlashLoanIds } from "./types";
14
- import { FLASH_LOAN_IDS } from "@1delta/dex-registry";
15
- import { formatUnits, zeroAddress } from "viem";
16
- import { AAVE_V2_LENDERS, AAVE_V3_LENDERS } from "@1delta/asset-registry";
17
- import _ from "lodash"
18
- import { MULTICALL_ADDRESS } from "../utils/constants";
19
-
20
- const DEFAULT_BATCH_SIZE = 4096;
2
+ getAaveStyleProtocolTokenMap,
3
+ getAaveTypePoolAddress,
4
+ getAssetMeta,
5
+ } from '../assets'
6
+ import { AAVES_PER_CHAIN } from '../utils'
7
+ import {
8
+ RELEVANT_BALANCER_V2_FORKS,
9
+ RELEVANT_BALANCER_V3_FORKS,
10
+ RELEVANT_LENDING_ASSETS,
11
+ RELEVANT_MORPHOB_FORKS,
12
+ RELEVANT_UNISWAP_V4_FORKS,
13
+ } from './assets'
14
+ import { Call } from '../utils/multicall'
15
+ import { MulticallRetryFunction } from '../types'
16
+ import { FlashAbi } from '../abis/flashloan-united/flashAbi'
17
+ import { FlashLiquiditiesOnChain, FlashLoanIds } from './types'
18
+ import { FLASH_LOAN_IDS } from '@1delta/dex-registry'
19
+ import { formatUnits, zeroAddress } from 'viem'
20
+ import { AAVE_V2_LENDERS, AAVE_V3_LENDERS } from '@1delta/asset-registry'
21
+ import _ from 'lodash'
22
+ import { MULTICALL_ADDRESS } from '../utils/constants'
23
+
24
+ const DEFAULT_BATCH_SIZE = 4096
21
25
 
22
26
  enum BalanceFetchCall {
23
- balanceOf = "balanceOf",
24
- getEthBalance = "getEthBalance"
27
+ balanceOf = 'balanceOf',
28
+ getEthBalance = 'getEthBalance',
25
29
  }
26
30
 
27
31
  // Aave V3 flash loan flag enabled flag
28
- const FLASHLOAN_ENABLED_MASK = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFFF');
32
+ const FLASHLOAN_ENABLED_MASK = BigInt(
33
+ '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFFF',
34
+ )
29
35
  function getFlashLoanEnabled(data: bigint): boolean {
30
- return (data & ~FLASHLOAN_ENABLED_MASK) !== BigInt(0);
36
+ return (data & ~FLASHLOAN_ENABLED_MASK) !== BigInt(0)
31
37
  }
32
38
 
33
39
  export async function fetchFlashLiquidityForChain(
34
- chain: string,
35
- multicallRetry: MulticallRetryFunction
40
+ chain: string,
41
+ multicallRetry: MulticallRetryFunction,
36
42
  ) {
43
+ let callLengths: { [l: string]: number } = {}
44
+ let aaveAssets: { [l: string]: string[] } = {}
37
45
 
38
- let callLengths: { [l: string]: number } = {}
39
- let aaveAssets: { [l: string]: string[] } = {}
40
-
41
- let aaveCalls: Call[] = []
46
+ let aaveCalls: Call[] = []
42
47
 
43
- const aaveProtocols = AAVES_PER_CHAIN[chain] ?? []
48
+ const aaveProtocols = AAVES_PER_CHAIN[chain] ?? []
44
49
 
45
- // we only ned to check aave flash liquidity for aave assets
46
- aaveProtocols.forEach(aaveFork => {
47
- const underlyingsAndATokens = Object.entries(getAaveStyleProtocolTokenMap(chain, aaveFork))
50
+ // we only ned to check aave flash liquidity for aave assets
51
+ aaveProtocols.forEach((aaveFork) => {
52
+ const underlyingsAndATokens = Object.entries(
53
+ getAaveStyleProtocolTokenMap(chain, aaveFork),
54
+ )
48
55
 
49
- const pool = getAaveTypePoolAddress(chain, aaveFork)
56
+ const pool = getAaveTypePoolAddress(chain, aaveFork)
50
57
 
51
- const tokenCalls = underlyingsAndATokens
52
- .map(([a, b]: [string, any]) => [
53
- { name: BalanceFetchCall.balanceOf, address: a, args: [b.aToken] },
54
- { name: "getConfiguration", address: pool, args: [a] }
55
- ])
56
- .reduce((acc, b) => [...acc, ...b], [])
58
+ const tokenCalls = underlyingsAndATokens
59
+ .map(([a, b]: [string, any]) => [
60
+ { name: BalanceFetchCall.balanceOf, address: a, args: [b.aToken] },
61
+ { name: 'getConfiguration', address: pool, args: [a] },
62
+ ])
63
+ .reduce((acc, b) => [...acc, ...b], [])
57
64
 
58
- aaveAssets[aaveFork] = underlyingsAndATokens.map(a => a[0])
65
+ aaveAssets[aaveFork] = underlyingsAndATokens.map((a) => a[0])
59
66
 
60
- callLengths[aaveFork] = tokenCalls.length * 2 + 1
67
+ callLengths[aaveFork] = tokenCalls.length * 2 + 1
61
68
 
69
+ aaveCalls = [
70
+ ...aaveCalls,
71
+ ...tokenCalls,
72
+ { name: 'FLASHLOAN_PREMIUM_TOTAL', address: pool },
73
+ ]
74
+ })
62
75
 
63
- aaveCalls = [
64
- ...aaveCalls,
65
- ...tokenCalls,
66
- { name: "FLASHLOAN_PREMIUM_TOTAL", address: pool },
67
- ]
68
- })
76
+ // @ts-ignore
77
+ const morphoBs = RELEVANT_MORPHOB_FORKS[chain] ?? []
69
78
 
70
- // @ts-ignore
71
- const morphoBs = RELEVANT_MORPHOB_FORKS[chain] ?? []
79
+ const otherAssets = RELEVANT_LENDING_ASSETS[chain] ?? []
72
80
 
73
- const otherAssets = RELEVANT_LENDING_ASSETS[chain] ?? []
81
+ let morphoCalls: Call[] = []
74
82
 
75
- let morphoCalls: Call[] = []
83
+ if (morphoBs && morphoBs.length > 0) {
84
+ morphoBs.forEach((bFork) => {
85
+ callLengths[bFork.pool] = otherAssets.length
86
+ morphoCalls = [
87
+ ...morphoCalls,
88
+ ...otherAssets.map((address) =>
89
+ address === zeroAddress
90
+ ? {
91
+ name: BalanceFetchCall.getEthBalance,
92
+ address: MULTICALL_ADDRESS[chain],
93
+ args: [bFork.address],
94
+ }
95
+ : {
96
+ name: BalanceFetchCall.balanceOf,
97
+ address,
98
+ args: [bFork.address],
99
+ },
100
+ ),
101
+ ]
102
+ })
103
+ }
76
104
 
77
- if (morphoBs && morphoBs.length > 0) {
78
- morphoBs.forEach(bFork => {
79
- callLengths[bFork.pool] = otherAssets.length
80
- morphoCalls = [
81
- ...morphoCalls,
82
- ...otherAssets.map(address => address === zeroAddress ? ({
83
- name: BalanceFetchCall.getEthBalance,
84
- address: MULTICALL_ADDRESS[chain],
85
- args: [bFork.address],
86
- }) : ({ name: BalanceFetchCall.balanceOf, address, args: [bFork.address] }))
87
- ]
88
- })
89
- }
90
-
91
- const balancerV2s = RELEVANT_BALANCER_V2_FORKS[chain] ?? []
92
-
93
- let balancerV2Calls: Call[] = []
94
- if (balancerV2s && balancerV2s.length > 0) {
95
- balancerV2s.forEach(bFork => {
96
- callLengths[bFork.pool] = otherAssets.length
97
- balancerV2Calls = [
98
- ...balancerV2Calls,
99
- ...otherAssets.map(address => address === zeroAddress ? ({
100
- name: BalanceFetchCall.getEthBalance,
101
- address: MULTICALL_ADDRESS[chain],
102
- args: [bFork.address],
103
- }) : ({ name: BalanceFetchCall.balanceOf, address, args: [bFork.address] }))
104
- ]
105
- })
106
- }
107
-
108
- const balancerV3s = RELEVANT_BALANCER_V3_FORKS[chain] ?? []
109
- let balancerV3Calls: Call[] = []
110
- if (balancerV3s && balancerV3s.length > 0) {
111
- balancerV3s.forEach(bFork => {
112
- callLengths[bFork.pool] = otherAssets.length
113
- balancerV3Calls = [
114
- ...balancerV3Calls,
115
- ...otherAssets.map(address => address === zeroAddress ? ({
116
- name: BalanceFetchCall.getEthBalance,
117
- address: MULTICALL_ADDRESS[chain],
118
- args: [bFork.address],
119
- }) : ({ name: BalanceFetchCall.balanceOf, address, args: [bFork.address] }))
120
- ]
121
- })
122
- }
123
-
124
- const uniswapV4s = RELEVANT_UNISWAP_V4_FORKS[chain] ?? []
125
- let uniswapV4Calls: Call[] = []
126
- if (uniswapV4s && uniswapV4s.length > 0) {
127
- uniswapV4s.forEach(u4Fork => {
128
- callLengths[u4Fork.pool] = otherAssets.length
129
- uniswapV4Calls = [
130
- ...uniswapV4Calls,
131
- ...otherAssets.map(address => address === zeroAddress ? ({
132
- name: BalanceFetchCall.getEthBalance,
133
- address: MULTICALL_ADDRESS[chain],
134
- args: [u4Fork.address],
135
- }) : ({ name: BalanceFetchCall.balanceOf, address, args: [u4Fork.address] }))
136
- ]
137
- })
138
- }
105
+ const balancerV2s = RELEVANT_BALANCER_V2_FORKS[chain] ?? []
139
106
 
140
- const calls = [
141
- ...aaveCalls,
107
+ let balancerV2Calls: Call[] = []
108
+ if (balancerV2s && balancerV2s.length > 0) {
109
+ balancerV2s.forEach((bFork) => {
110
+ callLengths[bFork.pool] = otherAssets.length
111
+ balancerV2Calls = [
142
112
  ...balancerV2Calls,
143
- ...morphoCalls,
113
+ ...otherAssets.map((address) =>
114
+ address === zeroAddress
115
+ ? {
116
+ name: BalanceFetchCall.getEthBalance,
117
+ address: MULTICALL_ADDRESS[chain],
118
+ args: [bFork.address],
119
+ }
120
+ : {
121
+ name: BalanceFetchCall.balanceOf,
122
+ address,
123
+ args: [bFork.address],
124
+ },
125
+ ),
126
+ ]
127
+ })
128
+ }
129
+
130
+ const balancerV3s = RELEVANT_BALANCER_V3_FORKS[chain] ?? []
131
+ let balancerV3Calls: Call[] = []
132
+ if (balancerV3s && balancerV3s.length > 0) {
133
+ balancerV3s.forEach((bFork) => {
134
+ callLengths[bFork.pool] = otherAssets.length
135
+ balancerV3Calls = [
144
136
  ...balancerV3Calls,
137
+ ...otherAssets.map((address) =>
138
+ address === zeroAddress
139
+ ? {
140
+ name: BalanceFetchCall.getEthBalance,
141
+ address: MULTICALL_ADDRESS[chain],
142
+ args: [bFork.address],
143
+ }
144
+ : {
145
+ name: BalanceFetchCall.balanceOf,
146
+ address,
147
+ args: [bFork.address],
148
+ },
149
+ ),
150
+ ]
151
+ })
152
+ }
153
+
154
+ const uniswapV4s = RELEVANT_UNISWAP_V4_FORKS[chain] ?? []
155
+ let uniswapV4Calls: Call[] = []
156
+ if (uniswapV4s && uniswapV4s.length > 0) {
157
+ uniswapV4s.forEach((u4Fork) => {
158
+ callLengths[u4Fork.pool] = otherAssets.length
159
+ uniswapV4Calls = [
145
160
  ...uniswapV4Calls,
146
- ]
147
-
148
- const rawResults = await multicallRetry(
149
- chain,
150
- calls,
151
- FlashAbi,
152
- DEFAULT_BATCH_SIZE,
153
- 3,
154
- 0,
155
- false
156
- )
157
-
158
- let liquidity: FlashLiquiditiesOnChain = {}
159
-
160
- let currentOffset = 0
161
- aaveProtocols.forEach(aave => {
162
- const callLen = aaveAssets[aave].length * 2 + 1
163
-
164
- const data: any[] = rawResults.slice(currentOffset, callLen + currentOffset)
165
- const fee = data[callLen - 1]
166
- // update offset
167
- currentOffset += callLen;
168
-
169
-
170
- aaveAssets[aave].forEach((asset, i) => {
171
- const decimals = getAssetMeta(chain, asset)?.decimals
172
- const rawAmount = data[2 * i]
173
-
174
- const config = data[2 * i + 1]
175
- const enabled = !AAVE_V3_LENDERS.includes(aave as any) || getFlashLoanEnabled(config)
176
- if (enabled && rawAmount > 0n) {
177
- if (!liquidity[asset]) liquidity[asset] = []
178
- liquidity[asset].push({
179
- id: FLASH_LOAN_IDS[aave],
180
- name: aave,
181
- type: AAVE_V2_LENDERS.includes(aave as any) ? FlashLoanIds.AAVE_V2 : FlashLoanIds.AAVE_V3,
182
- source: getAaveTypePoolAddress(chain, aave),
183
- fee: fee.toString(),
184
- availableRaw: rawAmount.toString(),
185
- available: Number(formatUnits(rawAmount, decimals ?? 18))
186
- })
187
- }
161
+ ...otherAssets.map((address) =>
162
+ address === zeroAddress
163
+ ? {
164
+ name: BalanceFetchCall.getEthBalance,
165
+ address: MULTICALL_ADDRESS[chain],
166
+ args: [u4Fork.address],
167
+ }
168
+ : {
169
+ name: BalanceFetchCall.balanceOf,
170
+ address,
171
+ args: [u4Fork.address],
172
+ },
173
+ ),
174
+ ]
175
+ })
176
+ }
177
+
178
+ const calls = [
179
+ ...aaveCalls,
180
+ ...balancerV2Calls,
181
+ ...morphoCalls,
182
+ ...balancerV3Calls,
183
+ ...uniswapV4Calls,
184
+ ]
185
+
186
+ const rawResults = await multicallRetry(
187
+ chain,
188
+ calls,
189
+ FlashAbi,
190
+ DEFAULT_BATCH_SIZE,
191
+ 3,
192
+ 0,
193
+ false,
194
+ )
195
+
196
+ let liquidity: FlashLiquiditiesOnChain = {}
197
+
198
+ let currentOffset = 0
199
+ aaveProtocols.forEach((aave) => {
200
+ const callLen = aaveAssets[aave].length * 2 + 1
201
+
202
+ const data: any[] = rawResults.slice(currentOffset, callLen + currentOffset)
203
+ const fee = data[callLen - 1]
204
+ // update offset
205
+ currentOffset += callLen
206
+
207
+ aaveAssets[aave].forEach((asset, i) => {
208
+ const decimals = getAssetMeta(chain, asset)?.decimals
209
+ const rawAmount = data[2 * i]
210
+
211
+ const config = data[2 * i + 1]
212
+ const enabled =
213
+ !AAVE_V3_LENDERS.includes(aave as any) || getFlashLoanEnabled(config)
214
+ if (enabled && rawAmount > 0n && FLASH_LOAN_IDS[aave] !== undefined) {
215
+ if (!liquidity[asset]) liquidity[asset] = []
216
+ liquidity[asset].push({
217
+ id: FLASH_LOAN_IDS[aave],
218
+ name: aave,
219
+ type: AAVE_V2_LENDERS.includes(aave as any)
220
+ ? FlashLoanIds.AAVE_V2
221
+ : FlashLoanIds.AAVE_V3,
222
+ source: getAaveTypePoolAddress(chain, aave),
223
+ fee: fee.toString(),
224
+ availableRaw: rawAmount.toString(),
225
+ available: Number(formatUnits(rawAmount, decimals ?? 18)),
226
+ decimals,
188
227
  })
228
+ }
189
229
  })
190
-
191
-
192
- balancerV2s.forEach(balancer => {
193
- const callLen = otherAssets.length
194
-
195
- const data: any[] = rawResults.slice(currentOffset, callLen + currentOffset)
196
- // update offset
197
- currentOffset += callLen;
198
-
199
-
200
- otherAssets.forEach((asset, i) => {
201
- const decimals = getAssetMeta(chain, asset)?.decimals
202
- const rawAmount = data[i]
203
- if (rawAmount > 0n) {
204
- if (!liquidity[asset]) liquidity[asset] = []
205
- liquidity[asset].push({
206
- id: FLASH_LOAN_IDS[balancer.pool],
207
- name: balancer.pool,
208
- type: FlashLoanIds.BALANCER_V2,
209
- source: balancer.address,
210
- fee: "0",
211
- availableRaw: rawAmount.toString(),
212
- available: Number(formatUnits(rawAmount, decimals ?? 18))
213
- })
214
- }
230
+ })
231
+
232
+ balancerV2s.forEach((balancer) => {
233
+ const callLen = otherAssets.length
234
+
235
+ const data: any[] = rawResults.slice(currentOffset, callLen + currentOffset)
236
+ // update offset
237
+ currentOffset += callLen
238
+
239
+ otherAssets.forEach((asset, i) => {
240
+ const decimals = getAssetMeta(chain, asset)?.decimals
241
+ const rawAmount = data[i]
242
+ if (rawAmount > 0n) {
243
+ if (!liquidity[asset]) liquidity[asset] = []
244
+ liquidity[asset].push({
245
+ id: FLASH_LOAN_IDS[balancer.pool],
246
+ name: balancer.pool,
247
+ type: FlashLoanIds.BALANCER_V2,
248
+ source: balancer.address,
249
+ fee: '0',
250
+ availableRaw: rawAmount.toString(),
251
+ available: Number(formatUnits(rawAmount, decimals ?? 18)),
252
+ decimals,
215
253
  })
254
+ }
216
255
  })
217
-
218
-
219
-
220
- morphoBs.forEach(morpho => {
221
- const callLen = otherAssets.length
222
-
223
- const data: any[] = rawResults.slice(currentOffset, callLen + currentOffset)
224
- // update offset
225
- currentOffset += callLen;
226
-
227
-
228
- otherAssets.forEach((asset, i) => {
229
- const decimals = getAssetMeta(chain, asset)?.decimals
230
- const rawAmount = data[i]
231
- if (rawAmount > 0n) {
232
- if (!liquidity[asset]) liquidity[asset] = []
233
- liquidity[asset].push({
234
- id: FLASH_LOAN_IDS[morpho.pool],
235
- name: morpho.pool,
236
- type: FlashLoanIds.MORPHO,
237
- source: morpho.address,
238
- fee: "0",
239
- availableRaw: rawAmount.toString(),
240
- available: Number(formatUnits(rawAmount, decimals ?? 18))
241
- })
242
- }
256
+ })
257
+
258
+ morphoBs.forEach((morpho) => {
259
+ const callLen = otherAssets.length
260
+
261
+ const data: any[] = rawResults.slice(currentOffset, callLen + currentOffset)
262
+ // update offset
263
+ currentOffset += callLen
264
+
265
+ otherAssets.forEach((asset, i) => {
266
+ const rawAmount = data[i]
267
+ if (rawAmount > 0n) {
268
+ if (!liquidity[asset]) liquidity[asset] = []
269
+ const decimals = getAssetMeta(chain, asset)?.decimals
270
+ liquidity[asset].push({
271
+ id: FLASH_LOAN_IDS[morpho.pool],
272
+ name: morpho.pool,
273
+ type: FlashLoanIds.MORPHO,
274
+ source: morpho.address,
275
+ fee: '0',
276
+ availableRaw: rawAmount.toString(),
277
+ available: Number(formatUnits(rawAmount, decimals ?? 18)),
278
+ decimals,
243
279
  })
280
+ }
244
281
  })
245
-
246
- balancerV3s.forEach(balancerV3 => {
247
- const callLen = otherAssets.length
248
-
249
- const data: any[] = rawResults.slice(currentOffset, callLen + currentOffset)
250
- // update offset
251
- currentOffset += callLen;
252
-
253
-
254
- otherAssets.forEach((asset, i) => {
255
- const decimals = getAssetMeta(chain, asset)?.decimals
256
- const rawAmount = data[i]
257
- if (rawAmount > 0n) {
258
- if (!liquidity[asset]) liquidity[asset] = []
259
- liquidity[asset].push({
260
- id: FLASH_LOAN_IDS[balancerV3.pool],
261
- name: balancerV3.pool,
262
- type: FlashLoanIds.SINGLETON,
263
- source: balancerV3.address,
264
- fee: "0",
265
- availableRaw: rawAmount.toString(),
266
- available: Number(formatUnits(rawAmount, decimals ?? 18))
267
- })
268
- }
282
+ })
283
+
284
+ balancerV3s.forEach((balancerV3) => {
285
+ const callLen = otherAssets.length
286
+
287
+ const data: any[] = rawResults.slice(currentOffset, callLen + currentOffset)
288
+ // update offset
289
+ currentOffset += callLen
290
+
291
+ otherAssets.forEach((asset, i) => {
292
+ const decimals = getAssetMeta(chain, asset)?.decimals
293
+ const rawAmount = data[i]
294
+ if (rawAmount > 0n) {
295
+ if (!liquidity[asset]) liquidity[asset] = []
296
+ liquidity[asset].push({
297
+ id: FLASH_LOAN_IDS[balancerV3.pool],
298
+ name: balancerV3.pool,
299
+ type: FlashLoanIds.SINGLETON,
300
+ source: balancerV3.address,
301
+ fee: '0',
302
+ availableRaw: rawAmount.toString(),
303
+ available: Number(formatUnits(rawAmount, decimals ?? 18)),
304
+ decimals,
269
305
  })
306
+ }
270
307
  })
271
-
272
- uniswapV4s.forEach(uniV4 => {
273
- const callLen = otherAssets.length
274
-
275
- const data: any[] = rawResults.slice(currentOffset, callLen + currentOffset)
276
- // update offset
277
- currentOffset += callLen;
278
-
279
-
280
- otherAssets.forEach((asset, i) => {
281
- const decimals = getAssetMeta(chain, asset)?.decimals
282
- const rawAmount = data[i]
283
- if (rawAmount > 0n) {
284
- if (!liquidity[asset]) liquidity[asset] = []
285
- liquidity[asset].push({
286
- id: FLASH_LOAN_IDS[uniV4.pool],
287
- name: uniV4.pool,
288
- type: FlashLoanIds.SINGLETON,
289
- source: uniV4.address,
290
- fee: "0",
291
- availableRaw: rawAmount.toString(),
292
- available: Number(formatUnits(rawAmount, decimals ?? 18))
293
- })
294
- }
308
+ })
309
+
310
+ uniswapV4s.forEach((uniV4) => {
311
+ const callLen = otherAssets.length
312
+
313
+ const data: any[] = rawResults.slice(currentOffset, callLen + currentOffset)
314
+ // update offset
315
+ currentOffset += callLen
316
+
317
+ otherAssets.forEach((asset, i) => {
318
+ const decimals = getAssetMeta(chain, asset)?.decimals
319
+ const rawAmount = data[i]
320
+ if (rawAmount > 0n) {
321
+ if (!liquidity[asset]) liquidity[asset] = []
322
+ liquidity[asset].push({
323
+ id: FLASH_LOAN_IDS[uniV4.pool],
324
+ name: uniV4.pool,
325
+ type: FlashLoanIds.SINGLETON,
326
+ source: uniV4.address,
327
+ fee: '0',
328
+ availableRaw: rawAmount.toString(),
329
+ available: Number(formatUnits(rawAmount, decimals ?? 18)),
330
+ decimals,
295
331
  })
332
+ }
296
333
  })
334
+ })
297
335
 
298
- return liquidity;
299
-
300
- }
336
+ return liquidity
337
+ }
@@ -13,6 +13,7 @@ export interface FlashLoanLiquidityForAsset {
13
13
  fee: string
14
14
  availableRaw: string
15
15
  available: number
16
+ decimals: number
16
17
  }
17
18
 
18
19
  export type FlashLiquiditiesOnChain = { [asset: string]: FlashLoanLiquidityForAsset[] }