@sentio/sdk 2.57.12 → 2.57.13-rc.10
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/ext/aptos-dex.d.ts +1 -1
- package/lib/aptos/ext/aptos-dex.d.ts.map +1 -1
- package/lib/aptos/ext/aptos-dex.js +2 -2
- package/lib/aptos/ext/aptos-dex.js.map +1 -1
- package/lib/core/template.d.ts +1 -5
- package/lib/core/template.d.ts.map +1 -1
- package/lib/core/template.js +1 -4
- package/lib/core/template.js.map +1 -1
- package/lib/eth/base-processor-template.d.ts +1 -1
- package/lib/eth/base-processor-template.d.ts.map +1 -1
- package/lib/eth/base-processor-template.js +2 -2
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/move/ext/coin.d.ts +1 -1
- package/lib/move/ext/coin.d.ts.map +1 -1
- package/lib/move/ext/move-dex.d.ts +1 -1
- package/lib/move/ext/move-dex.d.ts.map +1 -1
- package/lib/move/ext/move-dex.js +11 -11
- package/lib/move/ext/move-dex.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 +4 -3
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js +22 -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/sui-object-processor.js +1 -1
- package/lib/sui/sui-object-processor.js.map +1 -1
- package/lib/testing/memory-database.d.ts.map +1 -1
- package/lib/testing/memory-database.js +7 -3
- package/lib/testing/memory-database.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/ext/aptos-dex.ts +2 -2
- package/src/core/template.ts +1 -6
- package/src/eth/base-processor-template.ts +2 -2
- package/src/move/ext/coin.ts +1 -1
- package/src/move/ext/move-dex.ts +11 -11
- package/src/store/codegen.ts +55 -19
- package/src/store/store.ts +32 -6
- package/src/store/types.ts +10 -1
- package/src/sui/sui-object-processor.ts +1 -1
- package/src/testing/memory-database.ts +8 -3
- package/src/utils/price.ts +26 -20
@@ -208,16 +208,17 @@ export class MemoryDatabase {
|
|
208
208
|
return entities
|
209
209
|
}
|
210
210
|
|
211
|
-
let results =
|
211
|
+
let results = entities
|
212
|
+
// filter combined with AND
|
212
213
|
for (const f of filters ?? []) {
|
213
|
-
results =
|
214
|
+
results = results.filter((e) => filter(e, f))
|
214
215
|
}
|
215
216
|
return results
|
216
217
|
}
|
217
218
|
}
|
218
219
|
|
219
220
|
function filter(entity: RichStruct, filter: DBRequest_DBFilter) {
|
220
|
-
const value = entity
|
221
|
+
const value = getValue(entity, filter.field)
|
221
222
|
|
222
223
|
switch (filter.op) {
|
223
224
|
case DBRequest_DBOperator.EQ:
|
@@ -252,6 +253,10 @@ function filter(entity: RichStruct, filter: DBRequest_DBFilter) {
|
|
252
253
|
}
|
253
254
|
}
|
254
255
|
|
256
|
+
function getValue(entity: RichStruct, field: string) {
|
257
|
+
return entity.fields[field]
|
258
|
+
}
|
259
|
+
|
255
260
|
function equal(field: RichValue, value?: RichValueList): boolean {
|
256
261
|
if (field.stringValue !== undefined) {
|
257
262
|
return field.stringValue === value?.values[0]?.stringValue
|
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
|
})
|