@sentio/sdk 1.28.0 → 1.29.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/api.d.ts +2 -0
- package/lib/aptos/api.js +14 -0
- package/lib/aptos/api.js.map +1 -0
- package/lib/aptos/aptos-processor.d.ts +5 -4
- package/lib/aptos/aptos-processor.js +8 -9
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/context.d.ts +3 -2
- package/lib/aptos/context.js +3 -3
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/index.d.ts +3 -2
- package/lib/aptos/index.js +18 -3
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +23 -0
- package/lib/aptos/models.js +3 -0
- package/lib/aptos/models.js.map +1 -0
- package/lib/aptos/type-registry.d.ts +21 -0
- package/lib/aptos/type-registry.js +156 -0
- package/lib/aptos/type-registry.js.map +1 -0
- package/lib/aptos/types.d.ts +1 -33
- package/lib/aptos/types.js +49 -142
- package/lib/aptos/types.js.map +1 -1
- package/lib/aptos/types.test.js.map +1 -1
- package/lib/aptos/utils.d.ts +0 -2
- package/lib/aptos/utils.js +1 -8
- package/lib/aptos/utils.js.map +1 -1
- package/lib/aptos-codegen/codegen.js +2 -1
- package/lib/aptos-codegen/codegen.js.map +1 -1
- package/lib/aptos-codegen/typegen.d.ts +0 -1
- package/lib/aptos-codegen/typegen.js +3 -61
- package/lib/aptos-codegen/typegen.js.map +1 -1
- package/lib/cli/upload.js +2 -1
- package/lib/cli/upload.js.map +1 -1
- package/lib/core/base-context.d.ts +12 -0
- package/lib/core/base-context.js +25 -0
- package/lib/core/base-context.js.map +1 -0
- package/lib/core/base-processor.d.ts +1 -2
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/context.d.ts +2 -11
- package/lib/core/context.js +5 -24
- package/lib/core/context.js.map +1 -1
- package/lib/core/event-tracker.d.ts +1 -1
- package/lib/core/event-tracker.js +2 -2
- package/lib/core/event-tracker.js.map +1 -1
- package/lib/core/exporter.d.ts +1 -1
- package/lib/core/exporter.js.map +1 -1
- package/lib/core/generic-processor.test.js.map +1 -1
- package/lib/core/logger.d.ts +1 -1
- package/lib/core/logger.js.map +1 -1
- package/lib/core/meter.d.ts +3 -1
- package/lib/core/meter.js +12 -0
- package/lib/core/meter.js.map +1 -1
- package/lib/endpoints.d.ts +6 -0
- package/lib/endpoints.js +11 -0
- package/lib/endpoints.js.map +1 -0
- package/lib/processor-runner.js +6 -0
- package/lib/processor-runner.js.map +1 -1
- package/lib/processor-state.d.ts +2 -6
- package/lib/processor-state.js +0 -2
- package/lib/processor-state.js.map +1 -1
- package/lib/provider.js +5 -5
- package/lib/provider.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +4 -1
- package/lib/testing/test-processor-server.js +15 -7
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/utils/conversion.d.ts +2 -1
- package/lib/utils/conversion.js +3 -3
- package/lib/utils/conversion.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 +9 -1
- package/lib/utils/price.js +49 -1
- package/lib/utils/price.js.map +1 -1
- package/lib/utils/token.d.ts +1 -1
- package/lib/utils/token.js +2 -2
- package/lib/utils/token.js.map +1 -1
- package/package.json +5 -2
- package/src/aptos/api.ts +11 -0
- package/src/aptos/aptos-processor.ts +7 -10
- package/src/aptos/context.ts +3 -3
- package/src/aptos/index.ts +3 -2
- package/src/aptos/models.ts +34 -0
- package/src/aptos/type-registry.ts +187 -0
- package/src/aptos/types.ts +53 -199
- package/src/aptos/utils.ts +0 -9
- package/src/aptos-codegen/codegen.ts +2 -1
- package/src/aptos-codegen/typegen.ts +1 -67
- package/src/cli/upload.ts +2 -1
- package/src/core/base-context.ts +28 -0
- package/src/core/base-processor.ts +1 -2
- package/src/core/context.ts +2 -26
- package/src/core/event-tracker.ts +2 -2
- package/src/core/exporter.ts +1 -1
- package/src/core/logger.ts +1 -1
- package/src/core/meter.ts +15 -1
- package/src/endpoints.ts +9 -0
- package/src/processor-runner.ts +6 -0
- package/src/processor-state.ts +2 -7
- package/src/provider.ts +5 -5
- package/src/testing/test-processor-server.ts +10 -6
- package/src/utils/conversion.ts +2 -1
- package/src/utils/price.ts +51 -1
- package/src/utils/token.ts +1 -1
package/src/core/logger.ts
CHANGED
package/src/core/meter.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseContext } from './context'
|
|
1
|
+
import { BaseContext } from './base-context'
|
|
2
2
|
import { toMetricValue, Numberish } from './numberish'
|
|
3
3
|
import { DescriptorWithUsage, Labels } from './metadata'
|
|
4
4
|
import { DataDescriptor } from '../gen'
|
|
@@ -56,6 +56,13 @@ export class Metric extends DescriptorWithUsage {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export class Counter extends Metric {
|
|
59
|
+
static register(name: string, option?: MetricDescriptorOptions): Counter {
|
|
60
|
+
// TODO also dedup
|
|
61
|
+
const metric = new Counter(name, option)
|
|
62
|
+
global.PROCESSOR_STATE.metrics.push(metric)
|
|
63
|
+
return metric
|
|
64
|
+
}
|
|
65
|
+
|
|
59
66
|
add(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
|
|
60
67
|
this.record(ctx, value, labels, true)
|
|
61
68
|
}
|
|
@@ -94,6 +101,13 @@ export class CounterBinding {
|
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
export class Gauge extends Metric {
|
|
104
|
+
static register(name: string, option?: MetricDescriptorOptions): Gauge {
|
|
105
|
+
// TODO also dedup
|
|
106
|
+
const metric = new Gauge(name, option)
|
|
107
|
+
global.PROCESSOR_STATE.metrics.push(metric)
|
|
108
|
+
return metric
|
|
109
|
+
}
|
|
110
|
+
|
|
97
111
|
record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
|
|
98
112
|
ctx.res.gauges.push({
|
|
99
113
|
metadata: ctx.getMetaData(this.getShortDescriptor(), labels),
|
package/src/endpoints.ts
ADDED
package/src/processor-runner.ts
CHANGED
|
@@ -11,8 +11,10 @@ import fs from 'fs-extra'
|
|
|
11
11
|
import { ProcessorState } from './processor-state'
|
|
12
12
|
import { load } from './loader'
|
|
13
13
|
import { CompressionAlgorithms } from '@grpc/grpc-js/build/src/compression-algorithms'
|
|
14
|
+
import { Endpoints } from './endpoints'
|
|
14
15
|
|
|
15
16
|
global.PROCESSOR_STATE = new ProcessorState()
|
|
17
|
+
global.ENDPOINTS = new Endpoints()
|
|
16
18
|
|
|
17
19
|
const optionDefinitions = [
|
|
18
20
|
{ name: 'target', type: String, defaultOption: true },
|
|
@@ -25,6 +27,8 @@ const optionDefinitions = [
|
|
|
25
27
|
type: String,
|
|
26
28
|
defaultValue: 'chains-config.json',
|
|
27
29
|
},
|
|
30
|
+
{ name: 'chainquery-server', type: String, defaultValue: '' },
|
|
31
|
+
{ name: 'pricefeed-server', type: String, defaultValue: '' },
|
|
28
32
|
]
|
|
29
33
|
|
|
30
34
|
const options = commandLineArgs(optionDefinitions, { partial: true })
|
|
@@ -35,6 +39,8 @@ const fullPath = path.resolve(options['chains-config'])
|
|
|
35
39
|
const chainsConfig = fs.readJsonSync(fullPath)
|
|
36
40
|
|
|
37
41
|
setProvider(chainsConfig, options.concurrency, options['use-chainserver'])
|
|
42
|
+
globalThis.ENDPOINTS.chainQueryAPI = options['chainquery-server']
|
|
43
|
+
globalThis.ENDPOINTS.priceFeedAPI = options['pricefeed-server']
|
|
38
44
|
|
|
39
45
|
console.log('Start Server', options)
|
|
40
46
|
|
package/src/processor-state.ts
CHANGED
|
@@ -5,17 +5,14 @@ import {
|
|
|
5
5
|
BaseProcessorTemplate,
|
|
6
6
|
SolanaBaseProcessor,
|
|
7
7
|
SuiBaseProcessor,
|
|
8
|
+
EventTracker,
|
|
8
9
|
} from './core'
|
|
9
10
|
|
|
10
|
-
import { AptosBaseProcessor } from './aptos'
|
|
11
|
-
|
|
12
11
|
import { BaseContract } from 'ethers'
|
|
13
12
|
import { TemplateInstance } from './gen'
|
|
14
|
-
import { Provider } from '@ethersproject/providers'
|
|
15
|
-
import { EventTracker } from './core'
|
|
16
13
|
import { Metric } from './core/meter'
|
|
17
|
-
import { AptosAccountProcessor } from './aptos/aptos-processor'
|
|
18
14
|
import { Exporter } from './core/exporter'
|
|
15
|
+
import { AptosBaseProcessor, AptosAccountProcessor } from './aptos/aptos-processor'
|
|
19
16
|
|
|
20
17
|
export class ProcessorState {
|
|
21
18
|
// from abiName_address_chainId => contract wrapper
|
|
@@ -24,8 +21,6 @@ export class ProcessorState {
|
|
|
24
21
|
processors: BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>[] = []
|
|
25
22
|
// from abiName_options to contracts
|
|
26
23
|
processorMap = new Map<string, BaseProcessor<any, any>>()
|
|
27
|
-
// evm providers
|
|
28
|
-
providers = new Map<number, Provider>()
|
|
29
24
|
// evm processor templates
|
|
30
25
|
templates: BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>[] = []
|
|
31
26
|
// evm processor template instances spec
|
package/src/provider.ts
CHANGED
|
@@ -12,23 +12,23 @@ export function getProvider(networkish?: Networkish): Provider {
|
|
|
12
12
|
}
|
|
13
13
|
const network = getNetwork(networkish)
|
|
14
14
|
|
|
15
|
-
if (!global.
|
|
15
|
+
if (!global.ENDPOINTS.providers) {
|
|
16
16
|
throw Error('Provider not set')
|
|
17
17
|
}
|
|
18
|
-
const value = global.
|
|
18
|
+
const value = global.ENDPOINTS.providers.get(network.chainId)
|
|
19
19
|
if (value === undefined) {
|
|
20
20
|
throw Error(
|
|
21
21
|
'Provider not found for chain ' +
|
|
22
22
|
network.chainId +
|
|
23
23
|
', configured chains: ' +
|
|
24
|
-
[...global.
|
|
24
|
+
[...global.ENDPOINTS.providers.keys()].join(' ')
|
|
25
25
|
)
|
|
26
26
|
}
|
|
27
27
|
return value
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function setProvider(config: Record<string, ChainConfig>, concurrency = 4, useChainServer = false) {
|
|
31
|
-
|
|
31
|
+
globalThis.ENDPOINTS.providers = new Map<number, Provider>()
|
|
32
32
|
|
|
33
33
|
for (const chainIdStr in config) {
|
|
34
34
|
if (isNaN(Number.parseInt(chainIdStr))) {
|
|
@@ -56,7 +56,7 @@ export function setProvider(config: Record<string, ChainConfig>, concurrency = 4
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const provider = new QueuedStaticJsonRpcProvider(rpcAddress, chainId, concurrency)
|
|
59
|
-
global.
|
|
59
|
+
global.ENDPOINTS.providers.set(chainId, provider)
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -9,14 +9,10 @@ import {
|
|
|
9
9
|
ProcessConfigRequest,
|
|
10
10
|
ProcessConfigResponse,
|
|
11
11
|
ProcessInstructionsRequest,
|
|
12
|
-
ProcessorServiceImpl,
|
|
13
12
|
ProcessorServiceImplementation,
|
|
14
|
-
ProcessorState,
|
|
15
13
|
ProcessTransactionsRequest,
|
|
16
|
-
setProvider,
|
|
17
14
|
StartRequest,
|
|
18
|
-
|
|
19
|
-
} from '@sentio/sdk'
|
|
15
|
+
} from '../gen'
|
|
20
16
|
import { CallContext } from 'nice-grpc-common'
|
|
21
17
|
import { Empty } from '../gen/google/protobuf/empty'
|
|
22
18
|
import { ChainConfig } from '../chain-config'
|
|
@@ -24,11 +20,19 @@ import { CHAIN_MAP } from '../utils/chain'
|
|
|
24
20
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
25
21
|
import Long from 'long'
|
|
26
22
|
import { getNetwork, Networkish } from '@ethersproject/providers'
|
|
23
|
+
import { Endpoints } from '../endpoints'
|
|
24
|
+
import { ProcessorState } from '../processor-state'
|
|
25
|
+
import { ProcessorServiceImpl } from '../service'
|
|
26
|
+
import { Trace } from '../core/trace'
|
|
27
|
+
import { setProvider } from '../provider'
|
|
27
28
|
|
|
28
29
|
export const TEST_CONTEXT: CallContext = <CallContext>{}
|
|
29
30
|
|
|
30
|
-
function cleanTest() {
|
|
31
|
+
export function cleanTest() {
|
|
31
32
|
global.PROCESSOR_STATE = new ProcessorState()
|
|
33
|
+
if (!global.ENDPOINTS) {
|
|
34
|
+
global.ENDPOINTS = new Endpoints()
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
export class TestProcessorServer implements ProcessorServiceImplementation {
|
package/src/utils/conversion.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BigNumber } from 'ethers'
|
|
2
|
-
import { BigDecimal
|
|
2
|
+
import { BigDecimal } from '../core/big-decimal'
|
|
3
3
|
import { Numberish } from '../core'
|
|
4
|
+
import { MetricValue } from '../gen'
|
|
4
5
|
|
|
5
6
|
export function toBigDecimal(n: BigNumber | bigint) {
|
|
6
7
|
return new BigDecimal(n.toString())
|
package/src/utils/price.ts
CHANGED
|
@@ -1,8 +1,58 @@
|
|
|
1
1
|
import { PriceServiceClient, PriceServiceDefinition } from '../gen/service/price/protos/price'
|
|
2
2
|
import { createChannel, createClient } from 'nice-grpc'
|
|
3
3
|
|
|
4
|
-
export function getPriceClient(address
|
|
4
|
+
export function getPriceClient(address?: string): PriceServiceClient {
|
|
5
|
+
if (!address) {
|
|
6
|
+
address = global.ENDPOINTS.priceFeedAPI
|
|
7
|
+
}
|
|
5
8
|
const channel = createChannel(address)
|
|
6
9
|
|
|
7
10
|
return createClient(PriceServiceDefinition, channel)
|
|
8
11
|
}
|
|
12
|
+
|
|
13
|
+
const priceMap = new Map<string, number>()
|
|
14
|
+
let priceClient: PriceServiceClient
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param chainId chain id refers to CHAIN_MAP
|
|
19
|
+
* @param coinType
|
|
20
|
+
* @param date
|
|
21
|
+
*/
|
|
22
|
+
export async function getPriceByType(chainId: string, coinType: string, date: Date): Promise<number> {
|
|
23
|
+
if (!priceClient) {
|
|
24
|
+
priceClient = getPriceClient()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const dateStr = [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')
|
|
28
|
+
const key = `${coinType}-${dateStr}`
|
|
29
|
+
const price = priceMap.get(key)
|
|
30
|
+
if (price) {
|
|
31
|
+
return price
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
|
35
|
+
while (true) {
|
|
36
|
+
try {
|
|
37
|
+
const response = await priceClient.getPrice({
|
|
38
|
+
timestamp: date,
|
|
39
|
+
coinId: {
|
|
40
|
+
address: {
|
|
41
|
+
chain: chainId,
|
|
42
|
+
address: coinType,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
const price = response.price
|
|
47
|
+
priceMap.set(key, price)
|
|
48
|
+
return price
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.log('error getting price', e, dateStr, coinType)
|
|
51
|
+
await delay(1000)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function delay(ms: number) {
|
|
57
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
58
|
+
}
|
package/src/utils/token.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BigNumber } from '@ethersproject/bignumber'
|
|
|
3
3
|
import { transformEtherError } from '../error'
|
|
4
4
|
import { getERC20Contract } from '../builtin/erc20'
|
|
5
5
|
import { getERC20BytesContract } from '../builtin/internal/erc20bytes_processor'
|
|
6
|
-
import { BigDecimal } from '
|
|
6
|
+
import { BigDecimal } from '../core/big-decimal'
|
|
7
7
|
import { toBigDecimal } from './conversion'
|
|
8
8
|
import { utils } from 'ethers'
|
|
9
9
|
|