@sentio/sdk 1.30.0 → 1.30.2
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/cli/webpack.config.js +3 -2
- package/lib/core/exporter.d.ts +4 -0
- package/lib/core/exporter.js +7 -3
- package/lib/core/exporter.js.map +1 -1
- package/lib/core/meter.d.ts +14 -1
- package/lib/core/meter.js +39 -10
- package/lib/core/meter.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +1 -1
- package/lib/processor-runner.js.map +1 -1
- package/lib/service.js +4 -2
- package/lib/service.js.map +1 -1
- package/lib/{processor-state.d.ts → state/processor-state.d.ts} +4 -7
- package/lib/{processor-state.js → state/processor-state.js} +1 -2
- package/lib/state/processor-state.js.map +1 -0
- package/lib/state/state-storage.d.ts +12 -0
- package/lib/state/state-storage.js +46 -0
- package/lib/state/state-storage.js.map +1 -0
- package/lib/state/state-storage.test.d.ts +1 -0
- package/lib/state/state-storage.test.js.map +1 -0
- package/lib/testing/test-processor-server.js +1 -1
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/utils/dex-price.test.js.map +1 -1
- package/lib/utils/erc20.test.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/cli/webpack.config.js +3 -2
- package/src/core/exporter.ts +6 -2
- package/src/core/meter.ts +41 -9
- package/src/index.ts +1 -1
- package/src/processor-runner.ts +1 -1
- package/src/service.ts +5 -2
- package/src/{processor-state.ts → state/processor-state.ts} +4 -8
- package/src/state/state-storage.ts +49 -0
- package/src/testing/test-processor-server.ts +1 -1
- package/src/utils/price.ts +54 -25
- package/lib/processor-state.js.map +0 -1
|
@@ -21,7 +21,7 @@ import { Block, Log } from '@ethersproject/abstract-provider'
|
|
|
21
21
|
import Long from 'long'
|
|
22
22
|
import { getNetwork, Networkish } from '@ethersproject/providers'
|
|
23
23
|
import { Endpoints } from '../endpoints'
|
|
24
|
-
import { ProcessorState } from '../processor-state'
|
|
24
|
+
import { ProcessorState } from '../state/processor-state'
|
|
25
25
|
import { ProcessorServiceImpl } from '../service'
|
|
26
26
|
import { Trace } from '../core/trace'
|
|
27
27
|
import { setProvider } from '../provider'
|
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
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processor-state.js","sourceRoot":"","sources":["../src/processor-state.ts"],"names":[],"mappings":";;;AAgBA,MAAa,cAAc;IACzB,mDAAmD;IACnD,SAAS,GAAG,IAAI,GAAG,EAAsC,CAAA;IACzD,qBAAqB;IACrB,UAAU,GAAwE,EAAE,CAAA;IACpF,oCAAoC;IACpC,YAAY,GAAG,IAAI,GAAG,EAAmC,CAAA;IACzD,0BAA0B;IAC1B,SAAS,GAAgF,EAAE,CAAA;IAC3F,wCAAwC;IACxC,kBAAkB,GAAuB,EAAE,CAAA;IAE3C,gBAAgB,GAA0B,EAAE,CAAA;IAE5C,aAAa,GAAuB,EAAE,CAAA;IAEtC,eAAe,GAAyB,EAAE,CAAA;IAC1C,sBAAsB,GAA4B,EAAE,CAAA;IAEpD,aAAa,GAAmB,EAAE,CAAA;IAElC,SAAS,GAAe,EAAE,CAAA;IAE1B,OAAO,GAAa,EAAE,CAAA;CACvB;AAxBD,wCAwBC","sourcesContent":["import {\n BaseProcessor,\n BoundContractView,\n ContractView,\n BaseProcessorTemplate,\n SolanaBaseProcessor,\n SuiBaseProcessor,\n EventTracker,\n} from './core'\n\nimport { BaseContract } from 'ethers'\nimport { TemplateInstance } from './gen'\nimport { Metric } from './core/meter'\nimport { Exporter } from './core/exporter'\nimport { AptosBaseProcessor, AptosAccountProcessor } from './aptos/aptos-processor'\n\nexport class ProcessorState {\n // from abiName_address_chainId => contract wrapper\n contracts = new Map<string, ContractView<BaseContract>>()\n // all evm processors\n processors: BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>[] = []\n // from abiName_options to contracts\n processorMap = new Map<string, BaseProcessor<any, any>>()\n // evm processor templates\n templates: BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>[] = []\n // evm processor template instances spec\n templatesInstances: TemplateInstance[] = []\n\n solanaProcessors: SolanaBaseProcessor[] = []\n\n suiProcessors: SuiBaseProcessor[] = []\n\n aptosProcessors: AptosBaseProcessor[] = []\n aptosAccountProcessors: AptosAccountProcessor[] = []\n\n eventTrackers: EventTracker[] = []\n\n exporters: Exporter[] = []\n\n metrics: Metric[] = []\n}\n"]}
|