@sentio/sdk 1.29.1 → 1.30.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/context.d.ts +3 -3
- package/lib/aptos/context.js +7 -6
- package/lib/aptos/context.js.map +1 -1
- package/lib/cli/webpack.config.js +3 -2
- package/lib/core/base-context.d.ts +2 -2
- package/lib/core/base-context.js.map +1 -1
- package/lib/core/context.d.ts +4 -4
- package/lib/core/context.js +14 -13
- package/lib/core/context.js.map +1 -1
- package/lib/core/event-tracker.d.ts +2 -2
- package/lib/core/event-tracker.js +4 -5
- package/lib/core/event-tracker.js.map +1 -1
- package/lib/core/exporter.d.ts +2 -2
- package/lib/core/exporter.js +4 -5
- package/lib/core/exporter.js.map +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.js +2 -2
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger.d.ts +2 -2
- package/lib/core/logger.js +3 -4
- package/lib/core/logger.js.map +1 -1
- package/lib/core/metadata.d.ts +3 -6
- package/lib/core/metadata.js +6 -16
- package/lib/core/metadata.js.map +1 -1
- package/lib/core/meter.d.ts +14 -7
- package/lib/core/meter.js +16 -25
- package/lib/core/meter.js.map +1 -1
- package/lib/gen/chainquery/protos/chainquery.d.ts +48 -1
- package/lib/gen/chainquery/protos/chainquery.js +16 -0
- package/lib/gen/chainquery/protos/chainquery.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +20 -0
- package/lib/gen/processor/protos/processor.js +138 -2
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/service.js +1 -1
- package/lib/service.js.map +1 -1
- package/lib/testing/metric-utils.d.ts +1 -2
- package/lib/testing/metric-utils.js +2 -2
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/utils/price.d.ts +45 -3
- package/lib/utils/price.js +47 -27
- package/lib/utils/price.js.map +1 -1
- package/package.json +3 -1
- package/src/aptos/context.ts +6 -6
- package/src/cli/webpack.config.js +3 -2
- package/src/core/base-context.ts +2 -2
- package/src/core/context.ts +13 -13
- package/src/core/event-tracker.ts +4 -4
- package/src/core/exporter.ts +5 -5
- package/src/core/index.ts +1 -1
- package/src/core/logger.ts +4 -5
- package/src/core/metadata.ts +4 -15
- package/src/core/meter.ts +19 -28
- package/src/gen/chainquery/protos/chainquery.ts +37 -1
- package/src/gen/processor/protos/processor.ts +156 -0
- package/src/service.ts +1 -2
- package/src/testing/metric-utils.ts +3 -4
- package/src/utils/price.ts +54 -25
- package/templates/evm/src/processor.ts +1 -1
package/src/utils/price.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { PriceServiceClient, PriceServiceDefinition } from '../gen/service/price/protos/price'
|
|
2
|
-
import { createChannel,
|
|
2
|
+
import { createChannel, createClientFactory } from 'nice-grpc'
|
|
3
|
+
import { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'
|
|
3
4
|
|
|
4
|
-
export function getPriceClient(address?: string)
|
|
5
|
+
export function getPriceClient(address?: string) {
|
|
5
6
|
if (!address) {
|
|
6
7
|
address = global.ENDPOINTS.priceFeedAPI
|
|
7
8
|
}
|
|
8
9
|
const channel = createChannel(address)
|
|
9
10
|
|
|
10
|
-
return
|
|
11
|
+
return createClientFactory().use(retryMiddleware).create(PriceServiceDefinition, channel)
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
const priceMap = new Map<string, number>()
|
|
14
|
-
let priceClient: PriceServiceClient
|
|
15
|
+
let priceClient: PriceServiceClient<RetryOptions>
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
*
|
|
@@ -26,33 +27,61 @@ export async function getPriceByType(chainId: string, coinType: string, date: Da
|
|
|
26
27
|
|
|
27
28
|
const dateStr = [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')
|
|
28
29
|
const key = `${coinType}-${dateStr}`
|
|
29
|
-
|
|
30
|
+
let price = priceMap.get(key)
|
|
30
31
|
if (price) {
|
|
31
32
|
return price
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
address:
|
|
41
|
-
chain: chainId,
|
|
42
|
-
address: coinType,
|
|
43
|
-
},
|
|
35
|
+
const response = await priceClient.getPrice(
|
|
36
|
+
{
|
|
37
|
+
timestamp: date,
|
|
38
|
+
coinId: {
|
|
39
|
+
address: {
|
|
40
|
+
chain: chainId,
|
|
41
|
+
address: coinType,
|
|
44
42
|
},
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
console.log('error getting price', e, dateStr, coinType)
|
|
51
|
-
await delay(1000)
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
retry: true,
|
|
47
|
+
retryMaxAttempts: 8,
|
|
52
48
|
}
|
|
53
|
-
|
|
49
|
+
)
|
|
50
|
+
price = response.price
|
|
51
|
+
priceMap.set(key, price)
|
|
52
|
+
return price
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param symbol token symbol like BTC, etc
|
|
58
|
+
* @param date
|
|
59
|
+
*/
|
|
60
|
+
export async function getPriceBySymbol(symbol: string, date: Date): Promise<number> {
|
|
61
|
+
if (!priceClient) {
|
|
62
|
+
priceClient = getPriceClient()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const dateStr = [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')
|
|
66
|
+
const key = `${symbol}-${dateStr}`
|
|
67
|
+
let price = priceMap.get(key)
|
|
68
|
+
if (price) {
|
|
69
|
+
return price
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const response = await priceClient.getPrice(
|
|
73
|
+
{
|
|
74
|
+
timestamp: date,
|
|
75
|
+
coinId: {
|
|
76
|
+
symbol,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
retry: true,
|
|
81
|
+
retryMaxAttempts: 8,
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
price = response.price
|
|
85
|
+
priceMap.set(key, price)
|
|
86
|
+
return price
|
|
58
87
|
}
|
|
@@ -3,7 +3,7 @@ import { token } from '@sentio/sdk/lib/utils'
|
|
|
3
3
|
import { ERC20Processor } from '@sentio/sdk/lib/builtin/erc20'
|
|
4
4
|
import { X2y2Processor } from './types/x2y2'
|
|
5
5
|
|
|
6
|
-
const rewardPerBlock =
|
|
6
|
+
const rewardPerBlock = Gauge.register('reward_per_block', {
|
|
7
7
|
description: 'rewards for each block grouped by phase',
|
|
8
8
|
unit: 'x2y2',
|
|
9
9
|
})
|