@stake-dao/reader 0.4.93 → 0.4.95
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.
- package/dist/esm/prices.js +15 -10
- package/dist/esm/prices.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/prices.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/prices.ts +20 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prices.d.ts","sourceRoot":"","sources":["../../src/prices.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prices.d.ts","sourceRoot":"","sources":["../../src/prices.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,KAAK,GAAG;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,mBAAmB,wBAAkB,MAmBjD,CAAA;AAED,eAAO,MAAM,kBAAkB,WAAkB,GAAG,EAAE,wCAAmC,GAAG,KAAG,OAAO,CAAC,KAAK,EAAE,CAgC7G,CAAA;AAED,eAAO,MAAM,kBAAkB,YAAmB,MAAM,iBAKvD,CAAA;AAED,eAAO,MAAM,2BAA2B,wBAAkB,MAiBzD,CAAA;AAED,eAAO,MAAM,0BAA0B,WAC7B,GAAG,EAAE,wCAEO,GAAG,KACtB,OAAO,CAAC,KAAK,EAAE,CA4BjB,CAAA;AAED,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;CACf;AAED,eAAO,MAAM,SAAS,WAAkB,YAAY,EAAE,uBAAgB,OAAO,CAAC,KAAK,EAAE,CAmBpF,CAAA;AAED,eAAO,MAAM,WAAW,eAAsB,KAAK,EAAE,UAAU,YAAY,EAAE,uBAAgB,OAAO,CAAC,KAAK,EAAE,CAO3G,CAAA;AAED,eAAO,MAAM,SAAS,WAAY,KAAK,EAAE,gBAAgB,MAAM,KAAG,MAEjE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stake-dao/reader",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.95",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"graphql-request": "^6.0.0",
|
|
36
36
|
"lodash-es": "^4.17.21",
|
|
37
37
|
"viem": "^2.29.1",
|
|
38
|
-
"@stake-dao/constants": "0.4.
|
|
38
|
+
"@stake-dao/constants": "0.4.50"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/lodash-es": "^4.17.12",
|
package/src/prices.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chunk, uniq } from 'lodash-es'
|
|
2
|
+
import { TOKENS_CHUNK_SIZE } from './strategies/curve/fetch/curveApiData/config.js'
|
|
2
3
|
import { equalTlc } from './utils.js'
|
|
3
4
|
|
|
4
5
|
const LLAMA_API_URL = 'https://coins.llama.fi'
|
|
@@ -34,19 +35,26 @@ export const getLlamaTokenPrefix = (chainId = 1): string => {
|
|
|
34
35
|
export const getPricesFromLlama = async (tokens: any[], chainId = 1, defaultErrorValue?: any): Promise<Price[]> => {
|
|
35
36
|
if (tokens.length > 0) {
|
|
36
37
|
try {
|
|
37
|
-
const
|
|
38
|
+
const parsedPrice: { symbol: string; address: string; usdPrice: number }[] = []
|
|
38
39
|
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
const prefix: string = getLlamaTokenPrefix(chainId)
|
|
41
|
+
const tokensChunks = chunk(tokens, TOKENS_CHUNK_SIZE)
|
|
42
|
+
|
|
43
|
+
for (const tokensChunk of tokensChunks) {
|
|
44
|
+
const httpArgs = uniq(tokensChunk.map((t) => `${prefix}:${t.address}`)).toString()
|
|
45
|
+
const httpRequest = await fetch(`${LLAMA_API_URL}/prices/current/${httpArgs}`).then((res) => res.json())
|
|
46
|
+
const coinsData = httpRequest.coins
|
|
47
|
+
|
|
48
|
+
parsedPrice.push(
|
|
49
|
+
...tokensChunk.map((t) => {
|
|
50
|
+
return {
|
|
51
|
+
symbol: t.symbol,
|
|
52
|
+
address: t.address,
|
|
53
|
+
usdPrice: coinsData[`${prefix}:${t.address}`] ? coinsData[`${prefix}:${t.address}`].price : 0,
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
)
|
|
57
|
+
}
|
|
50
58
|
|
|
51
59
|
return parsedPrice
|
|
52
60
|
} catch (e) {
|