@sentio/sdk 2.57.13-rc.8 → 2.58.0-rc.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.
- package/lib/aptos/codegen/codegen.d.ts.map +1 -1
- package/lib/aptos/codegen/codegen.js +13 -6
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/core/codegen.d.ts +2 -0
- package/lib/core/codegen.d.ts.map +1 -0
- package/lib/core/codegen.js +17 -0
- package/lib/core/codegen.js.map +1 -0
- package/lib/eth/codegen/codegen.d.ts.map +1 -1
- package/lib/eth/codegen/codegen.js +2 -1
- package/lib/eth/codegen/codegen.js.map +1 -1
- package/lib/fuel/codegen/codegen.d.ts.map +1 -1
- package/lib/fuel/codegen/codegen.js +6 -5
- package/lib/fuel/codegen/codegen.js.map +1 -1
- package/lib/solana/codegen/codegen.d.ts.map +1 -1
- package/lib/solana/codegen/codegen.js +7 -2
- package/lib/solana/codegen/codegen.js.map +1 -1
- package/lib/stark/codegen/codegen.d.ts.map +1 -1
- package/lib/stark/codegen/codegen.js +2 -1
- package/lib/stark/codegen/codegen.js.map +1 -1
- package/lib/store/codegen.js +52 -19
- package/lib/store/codegen.js.map +1 -1
- package/lib/store/store.d.ts +1 -1
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js.map +1 -1
- package/lib/store/types.d.ts +2 -0
- package/lib/store/types.d.ts.map +1 -1
- package/lib/store/types.js +9 -1
- package/lib/store/types.js.map +1 -1
- package/lib/sui/codegen/codegen.d.ts.map +1 -1
- package/lib/sui/codegen/codegen.js +10 -3
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/utils/price.d.ts +4 -3
- package/lib/utils/price.d.ts.map +1 -1
- package/lib/utils/price.js +25 -20
- package/lib/utils/price.js.map +1 -1
- package/lib/utils/price.test.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/codegen/codegen.ts +16 -14
- package/src/core/codegen.ts +27 -0
- package/src/eth/codegen/codegen.ts +5 -1
- package/src/fuel/codegen/codegen.ts +6 -5
- package/src/solana/codegen/codegen.ts +9 -4
- package/src/stark/codegen/codegen.ts +2 -1
- package/src/store/codegen.ts +55 -19
- package/src/store/store.ts +3 -1
- package/src/store/types.ts +10 -1
- package/src/sui/codegen/codegen.ts +13 -3
- package/src/utils/price.ts +26 -20
package/src/utils/price.ts
CHANGED
@@ -2,7 +2,7 @@ import { CoinID } from '@sentio/protos'
|
|
2
2
|
import { Endpoints, processMetrics } from '@sentio/runtime'
|
3
3
|
import { ChainId } from '@sentio/chain'
|
4
4
|
import { LRUCache } from 'lru-cache'
|
5
|
-
import {
|
5
|
+
import { client, PriceService } from '@sentio/api'
|
6
6
|
import path from 'path'
|
7
7
|
import fs from 'fs'
|
8
8
|
import os from 'os'
|
@@ -16,18 +16,17 @@ function getApiKey() {
|
|
16
16
|
}
|
17
17
|
|
18
18
|
export function getPriceClient(basePath = Endpoints.INSTANCE.priceFeedAPI) {
|
19
|
-
if (!basePath.startsWith('http')) {
|
19
|
+
if (basePath && !basePath.startsWith('http')) {
|
20
20
|
basePath = 'http://' + basePath
|
21
21
|
}
|
22
22
|
if (basePath.endsWith('/')) {
|
23
23
|
basePath = basePath.slice(0, -1)
|
24
24
|
}
|
25
|
-
|
26
|
-
basePath,
|
27
|
-
|
25
|
+
client.setConfig({
|
26
|
+
baseUrl: basePath || 'https://app.sentio.xyz',
|
27
|
+
auth: getApiKey()
|
28
28
|
})
|
29
|
-
|
30
|
-
return api
|
29
|
+
return PriceService
|
31
30
|
}
|
32
31
|
|
33
32
|
const priceMap = new LRUCache<string, Promise<number | undefined>>({
|
@@ -35,6 +34,7 @@ const priceMap = new LRUCache<string, Promise<number | undefined>>({
|
|
35
34
|
ttl: 1000 * 60 * 5 // 5 minutes
|
36
35
|
})
|
37
36
|
|
37
|
+
type PriceApi = typeof PriceService
|
38
38
|
let priceClient: PriceApi
|
39
39
|
|
40
40
|
interface PriceOptions {
|
@@ -69,20 +69,24 @@ export async function getPriceByTypeOrSymbolInternal(
|
|
69
69
|
|
70
70
|
processMetrics.process_pricecall_count.add(1)
|
71
71
|
const response = priceClient.getPrice({
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
query: {
|
73
|
+
timestamp: date.toISOString(),
|
74
|
+
'coinId.symbol': coinId.symbol,
|
75
|
+
'coinId.address.address': coinId.address?.address,
|
76
|
+
'coinId.address.chain': coinId.address?.chain
|
77
|
+
}
|
76
78
|
})
|
77
79
|
price = response
|
78
80
|
.then((res) => {
|
79
|
-
|
80
|
-
|
81
|
+
const { data } = res
|
82
|
+
if (data?.timestamp) {
|
83
|
+
const responseDate = new Date(data.timestamp)
|
84
|
+
const responseDateString = dateString(responseDate)
|
81
85
|
if (responseDateString === todayDateString) {
|
82
86
|
priceMap.delete(key)
|
83
87
|
} else {
|
84
88
|
// https://www.javatpoint.com/javascript-date-difference
|
85
|
-
const diff = Math.abs(
|
89
|
+
const diff = Math.abs(responseDate.getTime() - date.getTime())
|
86
90
|
const daysDiff = diff / (1000 * 60 * 60 * 24)
|
87
91
|
const tolerance = options?.toleranceInDays || 2
|
88
92
|
if (daysDiff > tolerance) {
|
@@ -93,7 +97,7 @@ export async function getPriceByTypeOrSymbolInternal(
|
|
93
97
|
} else {
|
94
98
|
priceMap.delete(key)
|
95
99
|
}
|
96
|
-
return
|
100
|
+
return data?.price
|
97
101
|
})
|
98
102
|
.catch((e) => {
|
99
103
|
setTimeout(() => {
|
@@ -162,15 +166,17 @@ export async function getCoinsThatHasPrice(chainId: ChainId) {
|
|
162
166
|
if (!priceClient) {
|
163
167
|
priceClient = getPriceClient()
|
164
168
|
}
|
165
|
-
const
|
166
|
-
|
167
|
-
|
169
|
+
const { data } = await priceClient.priceListCoins({
|
170
|
+
query: {
|
171
|
+
chain: chainId,
|
172
|
+
limit: 1000
|
173
|
+
}
|
168
174
|
})
|
169
175
|
|
170
|
-
if (!
|
176
|
+
if (!data?.coinAddressesInChain) {
|
171
177
|
return []
|
172
178
|
}
|
173
|
-
return Object.entries(
|
179
|
+
return Object.entries(data.coinAddressesInChain).map(([symbol, coin]) => {
|
174
180
|
coin.symbol = symbol
|
175
181
|
return coin
|
176
182
|
})
|