@sentio/sdk 2.13.0-rc.1 → 2.13.0-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/aptos-chain-adapter.d.ts +14 -0
- package/lib/aptos/aptos-chain-adapter.js +69 -0
- package/lib/aptos/aptos-chain-adapter.js.map +1 -0
- package/lib/aptos/aptos-plugin.js +2 -0
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +7 -7
- package/lib/aptos/aptos-processor.js +15 -22
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/builtin/0x1.d.ts +1138 -493
- package/lib/aptos/builtin/0x1.js +1939 -1458
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +227 -104
- package/lib/aptos/builtin/0x3.js +373 -333
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/codegen/codegen.d.ts +1 -1
- package/lib/aptos/codegen/codegen.js +6 -47
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/codegen/run.js +1 -1
- package/lib/aptos/codegen/run.js.map +1 -1
- package/lib/aptos/context.d.ts +3 -0
- package/lib/aptos/context.js +5 -0
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/ext/aptos-dex.d.ts +2 -1
- package/lib/aptos/ext/aptos-dex.js +1 -2
- package/lib/aptos/ext/aptos-dex.js.map +1 -1
- package/lib/aptos/index.d.ts +1 -0
- package/lib/aptos/index.js +1 -0
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +3 -11
- package/lib/aptos/models.js.map +1 -1
- package/lib/aptos/module-client.js +1 -1
- package/lib/aptos/module-client.js.map +1 -1
- package/lib/aptos/move-coder.d.ts +10 -10
- package/lib/aptos/move-coder.js +37 -18
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/eth/base-processor-template.d.ts +4 -3
- package/lib/eth/base-processor-template.js +7 -7
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/base-processor.d.ts +9 -8
- package/lib/eth/base-processor.js +13 -11
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/eth-plugin.js +2 -0
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/eth/eth.d.ts +7 -2
- package/lib/eth/eth.js +8 -1
- package/lib/eth/eth.js.map +1 -1
- package/lib/move/abstract-codegen.d.ts +11 -11
- package/lib/move/abstract-codegen.js +59 -22
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +19 -25
- package/lib/move/abstract-move-coder.js +74 -51
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/chain-adapter.d.ts +11 -0
- package/lib/move/chain-adapter.js +3 -0
- package/lib/move/chain-adapter.js.map +1 -0
- package/lib/move/index.d.ts +1 -0
- package/lib/move/index.js +1 -0
- package/lib/move/index.js.map +1 -1
- package/lib/move/types.d.ts +28 -1
- package/lib/move/types.js +65 -16
- package/lib/move/types.js.map +1 -1
- package/lib/sui/builtin/0x1.d.ts +37 -18
- package/lib/sui/builtin/0x1.js +58 -32
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +275 -125
- package/lib/sui/builtin/0x2.js +463 -322
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/builtin/0x3.d.ts +135 -60
- package/lib/sui/builtin/0x3.js +229 -272
- package/lib/sui/builtin/0x3.js.map +1 -1
- package/lib/sui/codegen/codegen.d.ts +1 -1
- package/lib/sui/codegen/codegen.js +10 -36
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/codegen/run.js +1 -1
- package/lib/sui/codegen/run.js.map +1 -1
- package/lib/sui/context.d.ts +5 -1
- package/lib/sui/context.js +8 -1
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/index.d.ts +1 -0
- package/lib/sui/index.js +1 -0
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/models.d.ts +3 -11
- package/lib/sui/models.js.map +1 -1
- package/lib/sui/move-coder.d.ts +15 -15
- package/lib/sui/move-coder.js +43 -39
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/sui-chain-adapter.d.ts +14 -0
- package/lib/sui/sui-chain-adapter.js +69 -0
- package/lib/sui/sui-chain-adapter.js.map +1 -0
- package/lib/sui/sui-plugin.js +1 -0
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +6 -3
- package/lib/sui/sui-processor.js +23 -14
- package/lib/sui/sui-processor.js.map +1 -1
- package/lib/sui/utils.d.ts +0 -2
- package/lib/sui/utils.js +0 -6
- package/lib/sui/utils.js.map +1 -1
- package/lib/testing/sui-facet.d.ts +2 -2
- package/lib/testing/sui-facet.js +16 -26
- package/lib/testing/sui-facet.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/aptos-chain-adapter.ts +81 -0
- package/src/aptos/aptos-plugin.ts +2 -0
- package/src/aptos/aptos-processor.ts +35 -31
- package/src/aptos/builtin/0x1.ts +2742 -500
- package/src/aptos/builtin/0x3.ts +529 -106
- package/src/aptos/codegen/codegen.ts +13 -57
- package/src/aptos/codegen/run.ts +1 -1
- package/src/aptos/context.ts +5 -0
- package/src/aptos/ext/aptos-dex.ts +4 -12
- package/src/aptos/index.ts +2 -0
- package/src/aptos/models.ts +3 -13
- package/src/aptos/module-client.ts +1 -1
- package/src/aptos/move-coder.ts +48 -25
- package/src/eth/base-processor-template.ts +20 -10
- package/src/eth/base-processor.ts +45 -25
- package/src/eth/eth-plugin.ts +2 -0
- package/src/eth/eth.ts +15 -2
- package/src/move/abstract-codegen.ts +74 -37
- package/src/move/abstract-move-coder.ts +87 -75
- package/src/move/chain-adapter.ts +17 -0
- package/src/move/index.ts +1 -0
- package/src/move/types.ts +83 -17
- package/src/sui/builtin/0x1.ts +75 -20
- package/src/sui/builtin/0x2.ts +670 -126
- package/src/sui/builtin/0x3.ts +326 -61
- package/src/sui/codegen/codegen.ts +17 -43
- package/src/sui/codegen/run.ts +1 -1
- package/src/sui/context.ts +9 -1
- package/src/sui/index.ts +1 -0
- package/src/sui/models.ts +3 -13
- package/src/sui/move-coder.ts +58 -53
- package/src/sui/sui-chain-adapter.ts +86 -0
- package/src/sui/sui-plugin.ts +1 -0
- package/src/sui/sui-processor.ts +39 -26
- package/src/sui/utils.ts +0 -8
- package/src/testing/sui-facet.ts +15 -30
- package/lib/aptos/utils.d.ts +0 -2
- package/lib/aptos/utils.js +0 -10
- package/lib/aptos/utils.js.map +0 -1
- package/src/aptos/utils.ts +0 -11
@@ -1,76 +1,32 @@
|
|
1
1
|
import * as fs from 'fs'
|
2
|
-
import { MoveModuleBytecode,
|
3
|
-
import { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'
|
2
|
+
import { Event, MoveModuleBytecode, MoveResource } from '../move-types.js'
|
4
3
|
import chalk from 'chalk'
|
5
4
|
import { AptosNetwork } from '../network.js'
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'
|
5
|
+
import { join } from 'path'
|
6
|
+
import { AptosChainAdapter } from '../aptos-chain-adapter.js'
|
9
7
|
import { AbstractCodegen } from '../../move/abstract-codegen.js'
|
10
|
-
import {join} from "path";
|
11
8
|
|
12
|
-
export async function codegen(
|
9
|
+
export async function codegen(
|
10
|
+
abisDir: string,
|
11
|
+
outDir = join('src', 'types', 'aptos'),
|
12
|
+
genExample = false,
|
13
|
+
builtin = false
|
14
|
+
) {
|
13
15
|
if (!fs.existsSync(abisDir)) {
|
14
16
|
return
|
15
17
|
}
|
16
18
|
const gen = new AptosCodegen()
|
17
|
-
const numFiles = await gen.generate(abisDir, outDir)
|
19
|
+
const numFiles = await gen.generate(abisDir, outDir, builtin)
|
18
20
|
console.log(chalk.green(`Generated ${numFiles} for Aptos`))
|
19
21
|
}
|
20
22
|
|
21
|
-
|
22
|
-
switch (network) {
|
23
|
-
case AptosNetwork.TEST_NET:
|
24
|
-
return 'https://testnet.aptoslabs.com/'
|
25
|
-
}
|
26
|
-
return 'https://mainnet.aptoslabs.com/'
|
27
|
-
}
|
28
|
-
|
29
|
-
function getRpcClient(network: AptosNetwork): AptosClient {
|
30
|
-
return new AptosClient(getRpcEndpoint(network))
|
31
|
-
}
|
32
|
-
|
33
|
-
class AptosCodegen extends AbstractCodegen<MoveModuleBytecode[], AptosNetwork> {
|
23
|
+
class AptosCodegen extends AbstractCodegen<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
|
34
24
|
ADDRESS_TYPE = 'Address'
|
35
25
|
MAIN_NET = AptosNetwork.MAIN_NET
|
36
26
|
TEST_NET = AptosNetwork.TEST_NET
|
37
27
|
PREFIX = 'Aptos'
|
38
28
|
|
39
|
-
|
40
|
-
|
41
|
-
return await client.getAccountModules(account)
|
42
|
-
}
|
43
|
-
|
44
|
-
toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {
|
45
|
-
return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))
|
46
|
-
}
|
47
|
-
|
48
|
-
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
|
49
|
-
return getMeaningfulFunctionParams(params)
|
50
|
-
}
|
51
|
-
|
52
|
-
getEventStructs(module: InternalMoveModule) {
|
53
|
-
const qname = moduleQname(module)
|
54
|
-
const structMap = new Map<string, InternalMoveStruct>()
|
55
|
-
const eventMap = new Map<string, InternalMoveStruct>()
|
56
|
-
|
57
|
-
for (const struct of module.structs) {
|
58
|
-
structMap.set(qname + SPLITTER + struct.name, struct)
|
59
|
-
}
|
60
|
-
|
61
|
-
for (const struct of module.structs) {
|
62
|
-
for (const field of struct.fields) {
|
63
|
-
const t = field.type
|
64
|
-
if (t.qname === '0x1::event::EventHandle') {
|
65
|
-
const event = t.typeArgs[0].qname
|
66
|
-
const eventStruct = structMap.get(event)
|
67
|
-
if (eventStruct) {
|
68
|
-
eventMap.set(event, eventStruct)
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
return eventMap
|
29
|
+
constructor() {
|
30
|
+
super(AptosChainAdapter.INSTANCE)
|
75
31
|
}
|
76
32
|
}
|
package/src/aptos/codegen/run.ts
CHANGED
package/src/aptos/context.ts
CHANGED
@@ -2,6 +2,7 @@ import { RecordMetaData } from '@sentio/protos'
|
|
2
2
|
import { type Labels, BaseContext, normalizeLabels } from '@sentio/sdk'
|
3
3
|
import { Transaction_UserTransaction } from './move-types.js'
|
4
4
|
import { AptosNetwork, getChainId } from './network.js'
|
5
|
+
import { defaultMoveCoder, MoveCoder } from './move-coder.js'
|
5
6
|
|
6
7
|
export class AptosContext extends BaseContext {
|
7
8
|
address: string
|
@@ -10,6 +11,7 @@ export class AptosContext extends BaseContext {
|
|
10
11
|
version: bigint
|
11
12
|
transaction: Transaction_UserTransaction
|
12
13
|
eventIndex: number
|
14
|
+
coder: MoveCoder
|
13
15
|
|
14
16
|
constructor(
|
15
17
|
moduleName: string,
|
@@ -25,6 +27,7 @@ export class AptosContext extends BaseContext {
|
|
25
27
|
this.moduleName = moduleName
|
26
28
|
this.version = version
|
27
29
|
this.eventIndex = eventIndex
|
30
|
+
this.coder = defaultMoveCoder(network)
|
28
31
|
if (transaction) {
|
29
32
|
this.transaction = transaction
|
30
33
|
}
|
@@ -54,6 +57,7 @@ export class AptosResourcesContext extends BaseContext {
|
|
54
57
|
network: AptosNetwork
|
55
58
|
version: bigint
|
56
59
|
timestampInMicros: number
|
60
|
+
coder: MoveCoder
|
57
61
|
|
58
62
|
constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number) {
|
59
63
|
super()
|
@@ -61,6 +65,7 @@ export class AptosResourcesContext extends BaseContext {
|
|
61
65
|
this.network = network
|
62
66
|
this.version = version
|
63
67
|
this.timestampInMicros = timestampInMicros
|
68
|
+
this.coder = defaultMoveCoder(network)
|
64
69
|
}
|
65
70
|
|
66
71
|
getChainId(): string {
|
@@ -1,19 +1,14 @@
|
|
1
1
|
import { Gauge } from '@sentio/sdk'
|
2
2
|
import { BigDecimal } from '@sentio/bigdecimal'
|
3
3
|
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'
|
4
|
-
import {
|
5
|
-
|
6
|
-
TypedMoveResource,
|
7
|
-
MoveResource,
|
8
|
-
defaultMoveCoder,
|
9
|
-
AptosContext,
|
10
|
-
} from '@sentio/sdk/aptos'
|
4
|
+
import { AptosResourcesContext, TypedMoveResource, MoveResource, AptosContext } from '@sentio/sdk/aptos'
|
5
|
+
import { TypeDescriptor } from '../../move/index.js'
|
11
6
|
|
12
7
|
export interface PoolAdaptor<T> {
|
13
8
|
getXReserve(pool: T): bigint
|
14
9
|
getYReserve(pool: T): bigint
|
15
10
|
getExtraPoolTags(pool: TypedMoveResource<T>): any
|
16
|
-
|
11
|
+
poolType: TypeDescriptor<T>
|
17
12
|
}
|
18
13
|
|
19
14
|
export class AptosDex<T> {
|
@@ -104,10 +99,7 @@ export class AptosDex<T> {
|
|
104
99
|
ctx: AptosResourcesContext,
|
105
100
|
poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void
|
106
101
|
) {
|
107
|
-
const pools
|
108
|
-
this.poolAdaptor.poolTypeName,
|
109
|
-
resources
|
110
|
-
)
|
102
|
+
const pools = await ctx.coder.filterAndDecodeResources(this.poolAdaptor.poolType, resources)
|
111
103
|
|
112
104
|
const volumeByCoin = new Map<string, BigDecimal>()
|
113
105
|
const timestamp = ctx.timestampInMicros
|
package/src/aptos/index.ts
CHANGED
package/src/aptos/models.ts
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js'
|
2
|
+
import { DecodedStruct } from '../move/types.js'
|
2
3
|
|
3
4
|
export type EventInstance = Event & {
|
4
5
|
version: string
|
5
6
|
}
|
6
7
|
|
7
|
-
export type TypedEventInstance<T> = EventInstance
|
8
|
-
|
9
|
-
* decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
10
|
-
*/
|
11
|
-
data_decoded: T
|
12
|
-
|
13
|
-
type_arguments: string[]
|
14
|
-
}
|
8
|
+
export type TypedEventInstance<T> = DecodedStruct<EventInstance, T>
|
9
|
+
export type TypedMoveResource<T> = DecodedStruct<MoveResource, T>
|
15
10
|
|
16
11
|
// Don't use intermediate type to make IDE happier
|
17
12
|
export type TypedFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
|
@@ -20,8 +15,3 @@ export type TypedFunctionPayload<T extends Array<any>> = TransactionPayload_Entr
|
|
20
15
|
*/
|
21
16
|
arguments_decoded: T
|
22
17
|
}
|
23
|
-
|
24
|
-
export type TypedMoveResource<T> = MoveResource & {
|
25
|
-
data_decoded: T
|
26
|
-
type_arguments: string[]
|
27
|
-
}
|
@@ -17,7 +17,7 @@ export class ModuleClient {
|
|
17
17
|
ledger_version?: bigint
|
18
18
|
): Promise<any[]> {
|
19
19
|
const coder = defaultMoveCoder()
|
20
|
-
const encodedArgs = coder.encodeCallArgs(args, func)
|
20
|
+
const encodedArgs = await coder.encodeCallArgs(args, func)
|
21
21
|
|
22
22
|
const request: Types.ViewRequest = {
|
23
23
|
function: func,
|
package/src/aptos/move-coder.ts
CHANGED
@@ -6,43 +6,62 @@ import {
|
|
6
6
|
TransactionPayload_EntryFunctionPayload,
|
7
7
|
} from './move-types.js'
|
8
8
|
|
9
|
-
import { TypedEventInstance,
|
10
|
-
import { getMeaningfulFunctionParams } from './utils.js'
|
9
|
+
import { TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'
|
11
10
|
import { AbstractMoveCoder } from '../move/abstract-move-coder.js'
|
12
|
-
import {
|
11
|
+
import { AptosNetwork } from './network.js'
|
12
|
+
import { AptosChainAdapter } from './aptos-chain-adapter.js'
|
13
|
+
import { parseMoveType, TypeDescriptor } from '../move/index.js'
|
14
|
+
|
15
|
+
export class MoveCoder extends AbstractMoveCoder<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
|
16
|
+
constructor(network: AptosNetwork) {
|
17
|
+
super(network)
|
18
|
+
this.adapter = new AptosChainAdapter()
|
19
|
+
}
|
13
20
|
|
14
|
-
export class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
|
15
21
|
load(module: MoveModuleBytecode) {
|
16
22
|
if (!module.abi) {
|
17
23
|
throw Error('Module without abi')
|
18
24
|
}
|
19
|
-
|
20
|
-
|
25
|
+
let m = this.moduleMapping.get(module.abi.address + '::' + module.abi.name)
|
26
|
+
// if (this.contains(module.abi.address, module.abi.name)) {
|
27
|
+
// return
|
28
|
+
// }
|
29
|
+
if (m) {
|
30
|
+
return m
|
21
31
|
}
|
22
|
-
|
32
|
+
m = toInternalModule(module)
|
33
|
+
this.loadInternal(m)
|
34
|
+
return m
|
23
35
|
}
|
24
36
|
|
25
|
-
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {
|
26
|
-
return this.decodedStruct<T>(event) as
|
37
|
+
decodeEvent<T>(event: Event): Promise<TypedEventInstance<T> | undefined> {
|
38
|
+
return this.decodedStruct<T>(event) as any
|
27
39
|
}
|
28
|
-
filterAndDecodeEvents<T>(
|
29
|
-
|
40
|
+
filterAndDecodeEvents<T>(type: string | TypeDescriptor<T>, resources: Event[]): Promise<TypedEventInstance<T>[]> {
|
41
|
+
if (typeof type === 'string') {
|
42
|
+
type = parseMoveType(type)
|
43
|
+
}
|
44
|
+
return this.filterAndDecodeStruct(type, resources) as any
|
30
45
|
}
|
31
|
-
decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {
|
46
|
+
decodeResource<T>(res: MoveResource): Promise<TypedMoveResource<T> | undefined> {
|
32
47
|
return this.decodedStruct<T>(res)
|
33
48
|
}
|
34
|
-
filterAndDecodeResources<T>(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
49
|
+
filterAndDecodeResources<T>(
|
50
|
+
type: string | TypeDescriptor<T>,
|
51
|
+
resources: MoveResource[]
|
52
|
+
): Promise<TypedMoveResource<T>[]> {
|
53
|
+
if (typeof type === 'string') {
|
54
|
+
type = parseMoveType(type)
|
55
|
+
}
|
56
|
+
return this.filterAndDecodeStruct(type, resources)
|
40
57
|
}
|
41
58
|
|
42
|
-
decodeFunctionPayload(
|
43
|
-
|
44
|
-
|
45
|
-
const
|
59
|
+
async decodeFunctionPayload(
|
60
|
+
payload: TransactionPayload_EntryFunctionPayload
|
61
|
+
): Promise<TransactionPayload_EntryFunctionPayload> {
|
62
|
+
const func = await this.getMoveFunction(payload.function)
|
63
|
+
const params = this.adapter.getMeaningfulFunctionParams(func.params)
|
64
|
+
const argumentsDecoded = await this.decodeArray(payload.arguments, params)
|
46
65
|
|
47
66
|
return {
|
48
67
|
...payload,
|
@@ -51,8 +70,12 @@ export class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
|
|
51
70
|
}
|
52
71
|
}
|
53
72
|
|
54
|
-
|
73
|
+
const MOVE_CODER = new MoveCoder(AptosNetwork.MAIN_NET)
|
74
|
+
const TESTNET_MOVE_CODER = new MoveCoder(AptosNetwork.TEST_NET)
|
55
75
|
|
56
|
-
export function defaultMoveCoder(): MoveCoder {
|
57
|
-
|
76
|
+
export function defaultMoveCoder(network: AptosNetwork = AptosNetwork.MAIN_NET): MoveCoder {
|
77
|
+
if (network == AptosNetwork.MAIN_NET) {
|
78
|
+
return MOVE_CODER
|
79
|
+
}
|
80
|
+
return TESTNET_MOVE_CODER
|
58
81
|
}
|
@@ -30,6 +30,7 @@ export abstract class BaseProcessorTemplate<
|
|
30
30
|
handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
|
31
31
|
blockInterval?: HandleInterval
|
32
32
|
timeIntervalInMinutes?: HandleInterval
|
33
|
+
fetchConfig?: EthFetchConfig
|
33
34
|
}[] = []
|
34
35
|
traceHandlers: {
|
35
36
|
signature: string
|
@@ -64,7 +65,7 @@ export abstract class BaseProcessorTemplate<
|
|
64
65
|
processor.onTrace(th.signature, th.handler, th.fetchConfig)
|
65
66
|
}
|
66
67
|
for (const bh of this.blockHandlers) {
|
67
|
-
processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)
|
68
|
+
processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.fetchConfig)
|
68
69
|
}
|
69
70
|
|
70
71
|
const instance: TemplateInstance = {
|
@@ -103,32 +104,41 @@ export abstract class BaseProcessorTemplate<
|
|
103
104
|
public onBlockInterval(
|
104
105
|
handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
105
106
|
blockInterval = 1000,
|
106
|
-
backfillBlockInterval = 4000
|
107
|
+
backfillBlockInterval = 4000,
|
108
|
+
fetchConfig?: EthFetchConfig
|
107
109
|
) {
|
108
|
-
return this.onInterval(
|
109
|
-
|
110
|
-
|
111
|
-
|
110
|
+
return this.onInterval(
|
111
|
+
handler,
|
112
|
+
undefined,
|
113
|
+
{
|
114
|
+
recentInterval: blockInterval,
|
115
|
+
backfillInterval: backfillBlockInterval,
|
116
|
+
},
|
117
|
+
fetchConfig
|
118
|
+
)
|
112
119
|
}
|
113
120
|
|
114
121
|
public onTimeInterval(
|
115
122
|
handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
116
123
|
timeIntervalInMinutes = 60,
|
117
|
-
backfillBlockInterval = 240
|
124
|
+
backfillBlockInterval = 240,
|
125
|
+
fetchConfig?: EthFetchConfig
|
118
126
|
) {
|
119
127
|
return this.onInterval(
|
120
128
|
handler,
|
121
129
|
{ recentInterval: timeIntervalInMinutes, backfillInterval: backfillBlockInterval },
|
122
|
-
undefined
|
130
|
+
undefined,
|
131
|
+
fetchConfig
|
123
132
|
)
|
124
133
|
}
|
125
134
|
|
126
135
|
public onInterval(
|
127
136
|
handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
128
137
|
timeInterval: HandleInterval | undefined,
|
129
|
-
blockInterval: HandleInterval | undefined
|
138
|
+
blockInterval: HandleInterval | undefined,
|
139
|
+
fetchConfig: EthFetchConfig | undefined
|
130
140
|
) {
|
131
|
-
this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval
|
141
|
+
this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval, fetchConfig })
|
132
142
|
return this
|
133
143
|
}
|
134
144
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { BaseContract, DeferredTopicFilter, TransactionResponseParams } from 'ethers'
|
2
|
-
import {
|
2
|
+
import { Network } from 'ethers/providers'
|
3
3
|
|
4
4
|
import { BoundContractView, ContractContext, ContractView, GlobalContext } from './context.js'
|
5
5
|
import {
|
@@ -15,8 +15,7 @@ import {
|
|
15
15
|
import { BindOptions } from './bind-options.js'
|
16
16
|
import { PromiseOrVoid } from '../core/promises.js'
|
17
17
|
import { ServerError, Status } from 'nice-grpc'
|
18
|
-
import { fixEmptyKey, TypedEvent, TypedCallTrace, formatEthData } from './eth.js'
|
19
|
-
import * as console from 'console'
|
18
|
+
import { fixEmptyKey, TypedEvent, TypedCallTrace, formatEthData, RichBlock } from './eth.js'
|
20
19
|
import { getNetworkFromCtxOrNetworkish } from './provider.js'
|
21
20
|
import sha3 from 'js-sha3'
|
22
21
|
import { ListStateStorage } from '@sentio/runtime'
|
@@ -42,6 +41,7 @@ export class BlockHandler {
|
|
42
41
|
blockInterval?: HandleInterval
|
43
42
|
timeIntervalInMinutes?: HandleInterval
|
44
43
|
handler: (block: Data_EthBlock) => Promise<ProcessResult>
|
44
|
+
fetchConfig: EthFetchConfig
|
45
45
|
}
|
46
46
|
|
47
47
|
export class TransactionHandler {
|
@@ -88,25 +88,33 @@ export class GlobalProcessor {
|
|
88
88
|
}
|
89
89
|
|
90
90
|
public onBlockInterval(
|
91
|
-
handler: (block:
|
91
|
+
handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
|
92
92
|
blockInterval = 250,
|
93
|
-
backfillBlockInterval = 1000
|
93
|
+
backfillBlockInterval = 1000,
|
94
|
+
fetchConfig?: Partial<EthFetchConfig>
|
94
95
|
): this {
|
95
|
-
return this.onInterval(
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
return this.onInterval(
|
97
|
+
handler,
|
98
|
+
undefined,
|
99
|
+
{
|
100
|
+
recentInterval: blockInterval,
|
101
|
+
backfillInterval: backfillBlockInterval,
|
102
|
+
},
|
103
|
+
fetchConfig
|
104
|
+
)
|
99
105
|
}
|
100
106
|
|
101
107
|
public onTimeInterval(
|
102
|
-
handler: (block:
|
108
|
+
handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
|
103
109
|
timeIntervalInMinutes = 60,
|
104
|
-
backfillTimeIntervalInMinutes = 240
|
110
|
+
backfillTimeIntervalInMinutes = 240,
|
111
|
+
fetchConfig?: Partial<EthFetchConfig>
|
105
112
|
): this {
|
106
113
|
return this.onInterval(
|
107
114
|
handler,
|
108
115
|
{ recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
|
109
|
-
undefined
|
116
|
+
undefined,
|
117
|
+
fetchConfig
|
110
118
|
)
|
111
119
|
}
|
112
120
|
|
@@ -115,9 +123,10 @@ export class GlobalProcessor {
|
|
115
123
|
}
|
116
124
|
|
117
125
|
public onInterval(
|
118
|
-
handler: (block:
|
126
|
+
handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
|
119
127
|
timeInterval: HandleInterval | undefined,
|
120
|
-
blockInterval: HandleInterval | undefined
|
128
|
+
blockInterval: HandleInterval | undefined,
|
129
|
+
fetchConfig: Partial<EthFetchConfig> | undefined
|
121
130
|
): this {
|
122
131
|
const chainId = this.getChainId()
|
123
132
|
|
@@ -135,6 +144,7 @@ export class GlobalProcessor {
|
|
135
144
|
},
|
136
145
|
timeIntervalInMinutes: timeInterval,
|
137
146
|
blockInterval: blockInterval,
|
147
|
+
fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
|
138
148
|
})
|
139
149
|
return this
|
140
150
|
}
|
@@ -245,32 +255,41 @@ export abstract class BaseProcessor<
|
|
245
255
|
}
|
246
256
|
|
247
257
|
public onBlockInterval(
|
248
|
-
handler: (block:
|
258
|
+
handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
249
259
|
blockInterval = 250,
|
250
|
-
backfillBlockInterval = 1000
|
260
|
+
backfillBlockInterval = 1000,
|
261
|
+
fetchConfig?: Partial<EthFetchConfig>
|
251
262
|
): this {
|
252
|
-
return this.onInterval(
|
253
|
-
|
254
|
-
|
255
|
-
|
263
|
+
return this.onInterval(
|
264
|
+
handler,
|
265
|
+
undefined,
|
266
|
+
{
|
267
|
+
recentInterval: blockInterval,
|
268
|
+
backfillInterval: backfillBlockInterval,
|
269
|
+
},
|
270
|
+
fetchConfig
|
271
|
+
)
|
256
272
|
}
|
257
273
|
|
258
274
|
public onTimeInterval(
|
259
|
-
handler: (block:
|
275
|
+
handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
260
276
|
timeIntervalInMinutes = 60,
|
261
|
-
backfillTimeIntervalInMinutes = 240
|
277
|
+
backfillTimeIntervalInMinutes = 240,
|
278
|
+
fetchConfig?: Partial<EthFetchConfig>
|
262
279
|
): this {
|
263
280
|
return this.onInterval(
|
264
281
|
handler,
|
265
282
|
{ recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
|
266
|
-
undefined
|
283
|
+
undefined,
|
284
|
+
fetchConfig
|
267
285
|
)
|
268
286
|
}
|
269
287
|
|
270
288
|
public onInterval(
|
271
|
-
handler: (block:
|
289
|
+
handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
272
290
|
timeInterval: HandleInterval | undefined,
|
273
|
-
blockInterval: HandleInterval | undefined
|
291
|
+
blockInterval: HandleInterval | undefined,
|
292
|
+
fetchConfig: Partial<EthFetchConfig> | undefined
|
274
293
|
): this {
|
275
294
|
const chainId = this.getChainId()
|
276
295
|
const processor = this
|
@@ -300,6 +319,7 @@ export abstract class BaseProcessor<
|
|
300
319
|
},
|
301
320
|
timeIntervalInMinutes: timeInterval,
|
302
321
|
blockInterval: blockInterval,
|
322
|
+
fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
|
303
323
|
})
|
304
324
|
return this
|
305
325
|
}
|
package/src/eth/eth-plugin.ts
CHANGED
@@ -62,6 +62,7 @@ export class EthPlugin extends Plugin {
|
|
62
62
|
minutes: 0,
|
63
63
|
minutesInterval: blockHandler.timeIntervalInMinutes,
|
64
64
|
handlerId: handlerId,
|
65
|
+
fetchConfig: blockHandler.fetchConfig,
|
65
66
|
})
|
66
67
|
}
|
67
68
|
|
@@ -140,6 +141,7 @@ export class EthPlugin extends Plugin {
|
|
140
141
|
minutes: 0,
|
141
142
|
minutesInterval: blockHandler.timeIntervalInMinutes,
|
142
143
|
handlerId: handlerId,
|
144
|
+
fetchConfig: blockHandler.fetchConfig,
|
143
145
|
})
|
144
146
|
}
|
145
147
|
|
package/src/eth/eth.ts
CHANGED
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
object,
|
12
12
|
formatData,
|
13
13
|
} from 'ethers/providers'
|
14
|
-
import { CallExceptionError, LogDescription, Result, DeferredTopicFilter } from 'ethers'
|
14
|
+
import { CallExceptionError, LogDescription, Result, DeferredTopicFilter, BlockParams } from 'ethers'
|
15
15
|
import { ContractContext } from './context.js'
|
16
16
|
import { getAddress } from 'ethers/address'
|
17
17
|
import { getBigInt, getNumber, hexlify } from 'ethers/utils'
|
@@ -34,6 +34,11 @@ export interface TypedEvent<TArgsArray extends Array<any> = any, TArgsObject = a
|
|
34
34
|
|
35
35
|
export type TypedEventFilter<_TEvent extends TypedEvent> = DeferredTopicFilter
|
36
36
|
|
37
|
+
export interface RichBlock extends BlockParams {
|
38
|
+
traces?: Trace[]
|
39
|
+
transactionReceipts?: TransactionReceiptParams[]
|
40
|
+
}
|
41
|
+
|
37
42
|
export class SimpleEthersError extends Error {
|
38
43
|
e: Error
|
39
44
|
|
@@ -132,7 +137,7 @@ export function formatEthData(data: {
|
|
132
137
|
if (data.block && !data.block.transactions) {
|
133
138
|
data.block.transactions = []
|
134
139
|
}
|
135
|
-
const block = data.block ?
|
140
|
+
const block = data.block ? formatRichBlock(data.block) : undefined
|
136
141
|
const trace = data.trace ? (data.trace as Trace) : undefined
|
137
142
|
const transaction = data.transaction ? formatTransactionResponse(data.transaction) : undefined
|
138
143
|
const transactionReceipt = data.transactionReceipt ? formatTransactionReceipt(data.transactionReceipt) : undefined
|
@@ -145,6 +150,14 @@ export function formatEthData(data: {
|
|
145
150
|
}
|
146
151
|
}
|
147
152
|
|
153
|
+
export function formatRichBlock(block: RichBlock): RichBlock {
|
154
|
+
formatBlock(block)
|
155
|
+
if (block.transactionReceipts) {
|
156
|
+
block.transactionReceipts = block.transactionReceipts.map((t) => formatTransactionReceipt(t))
|
157
|
+
}
|
158
|
+
return block
|
159
|
+
}
|
160
|
+
|
148
161
|
export interface TypedCallTrace<TArgsArray extends Array<any> = any, TArgsObject = any> extends Trace {
|
149
162
|
args: TArgsObject & IResult
|
150
163
|
name: string
|