@sentio/sdk 2.13.0-rc.5 → 2.13.0-rc.7
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 +4 -2
- package/lib/aptos/aptos-chain-adapter.js +9 -0
- package/lib/aptos/aptos-chain-adapter.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +5 -4
- package/lib/aptos/aptos-processor.js +9 -5
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/ext/aptos-dex.js +1 -1
- package/lib/aptos/ext/aptos-dex.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 +6 -6
- package/lib/aptos/move-coder.js +12 -6
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/eth/base-processor.d.ts +8 -8
- package/lib/eth/base-processor.js +0 -1
- package/lib/eth/base-processor.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 +6 -6
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +15 -20
- package/lib/move/abstract-move-coder.js +68 -51
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/chain-adapter.d.ts +3 -1
- package/lib/move/chain-adapter.js.map +1 -1
- package/lib/move/types.d.ts +6 -0
- package/lib/move/types.js +20 -0
- package/lib/move/types.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +1 -4
- package/lib/sui/builtin/0x2.js +0 -5
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/codegen/codegen.js +3 -0
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/context.d.ts +1 -0
- package/lib/sui/context.js +2 -0
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/move-coder.d.ts +9 -9
- package/lib/sui/move-coder.js +19 -28
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/sui-chain-adapter.d.ts +4 -2
- package/lib/sui/sui-chain-adapter.js +22 -1
- package/lib/sui/sui-chain-adapter.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +4 -3
- package/lib/sui/sui-processor.js +8 -4
- package/lib/sui/sui-processor.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/aptos-chain-adapter.ts +13 -2
- package/src/aptos/aptos-processor.ts +16 -10
- package/src/aptos/codegen/codegen.ts +2 -2
- package/src/aptos/ext/aptos-dex.ts +4 -1
- package/src/aptos/module-client.ts +1 -1
- package/src/aptos/move-coder.ts +20 -12
- package/src/eth/base-processor.ts +8 -9
- package/src/eth/eth.ts +15 -2
- package/src/move/abstract-codegen.ts +6 -6
- package/src/move/abstract-move-coder.ts +77 -67
- package/src/move/chain-adapter.ts +4 -1
- package/src/move/types.ts +21 -0
- package/src/sui/builtin/0x2.ts +1 -4
- package/src/sui/codegen/codegen.ts +5 -2
- package/src/sui/context.ts +2 -0
- package/src/sui/move-coder.ts +34 -42
- package/src/sui/sui-chain-adapter.ts +32 -2
- package/src/sui/sui-processor.ts +13 -7
@@ -1,12 +1,14 @@
|
|
1
1
|
import { ChainAdapter, TypeDescriptor } from '../move/index.js';
|
2
|
-
import { MoveModuleBytecode } from './move-types.js';
|
2
|
+
import { Event, MoveModuleBytecode, MoveResource } from './move-types.js';
|
3
3
|
import { AptosNetwork } from './network.js';
|
4
4
|
import { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js';
|
5
|
-
export declare class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleBytecode> {
|
5
|
+
export declare class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
|
6
6
|
static INSTANCE: AptosChainAdapter;
|
7
7
|
fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]>;
|
8
8
|
fetchModule(account: string, module: string, network: AptosNetwork): Promise<MoveModuleBytecode>;
|
9
9
|
toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[];
|
10
10
|
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[];
|
11
11
|
getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>;
|
12
|
+
getType(data: Event | MoveResource): string;
|
13
|
+
getData(data: Event | MoveResource): any;
|
12
14
|
}
|
@@ -45,6 +45,15 @@ class AptosChainAdapter extends ChainAdapter {
|
|
45
45
|
}
|
46
46
|
return eventMap;
|
47
47
|
}
|
48
|
+
getType(data) {
|
49
|
+
return data.type;
|
50
|
+
}
|
51
|
+
getData(data) {
|
52
|
+
if ('data' in data && 'type' in data) {
|
53
|
+
return data.data;
|
54
|
+
}
|
55
|
+
return data;
|
56
|
+
}
|
48
57
|
}
|
49
58
|
export { AptosChainAdapter };
|
50
59
|
function getRpcClient(network) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aptos-chain-adapter.js","sourceRoot":"","sources":["../../src/aptos/aptos-chain-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAkB,MAAM,kBAAkB,CAAA;AACtF,OAAO,
|
1
|
+
{"version":3,"file":"aptos-chain-adapter.js","sourceRoot":"","sources":["../../src/aptos/aptos-chain-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAkB,MAAM,kBAAkB,CAAA;AACtF,OAAO,EAA2C,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,MAAa,iBAAkB,SAAQ,YAAoE;IACzG,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;IAEzC,KAAK,CAAC,YAAY,CAAC,OAA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,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;YACnC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE;gBACjC,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAA;gBACpB,IAAI,CAAC,CAAC,KAAK,KAAK,yBAAyB,EAAE;oBACzC,MAAM,KAAK,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;oBACjC,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;oBACxC,IAAI,WAAW,EAAE;wBACf,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;qBACjC;iBACF;aACF;SACF;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,OAAO,CAAC,IAA0B;QAChC,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,OAAO,CAAC,IAA0B;QAChC,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,EAAE;YACpC,OAAO,IAAI,CAAC,IAAI,CAAA;SACjB;QACD,OAAO,IAAI,CAAA;IACb,CAAC;;SA7DU,iBAAiB;AAgE9B,SAAS,YAAY,CAAC,OAAqB;IACzC,OAAO,IAAI,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,cAAc,CAAC,OAAqB;IAC3C,QAAQ,OAAO,EAAE;QACf,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,gCAAgC,CAAA;KAC1C;IACD,OAAO,gCAAgC,CAAA;AACzC,CAAC","sourcesContent":["import { ChainAdapter, moduleQname, SPLITTER, TypeDescriptor } from '../move/index.js'\nimport { Event, MoveModuleBytecode, MoveResource, toInternalModule } from './move-types.js'\nimport { AptosNetwork } from './network.js'\nimport { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'\nimport { AptosClient } from 'aptos-sdk'\n\nexport class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {\n static INSTANCE = new AptosChainAdapter()\n\n async fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]> {\n const client = getRpcClient(network)\n return await client.getAccountModules(account)\n }\n\n async fetchModule(account: string, module: string, network: AptosNetwork): Promise<MoveModuleBytecode> {\n const client = getRpcClient(network)\n return await client.getAccountModule(account, module)\n }\n\n toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {\n return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n if (params.length === 0) {\n return params\n }\n if (params[0].qname === 'signer' && params[0].reference) {\n params = params.slice(1)\n }\n return params\n }\n\n getEventStructs(module: InternalMoveModule) {\n const qname = moduleQname(module)\n const structMap = new Map<string, InternalMoveStruct>()\n const eventMap = new Map<string, InternalMoveStruct>()\n\n for (const struct of module.structs) {\n structMap.set(qname + SPLITTER + struct.name, struct)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n const t = field.type\n if (t.qname === '0x1::event::EventHandle') {\n const event = t.typeArgs[0].qname\n const eventStruct = structMap.get(event)\n if (eventStruct) {\n eventMap.set(event, eventStruct)\n }\n }\n }\n }\n\n return eventMap\n }\n\n getType(data: Event | MoveResource): string {\n return data.type\n }\n\n getData(data: Event | MoveResource) {\n if ('data' in data && 'type' in data) {\n return data.data\n }\n return data\n }\n}\n\nfunction getRpcClient(network: AptosNetwork): AptosClient {\n return new AptosClient(getRpcEndpoint(network))\n}\n\nfunction getRpcEndpoint(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'https://testnet.aptoslabs.com/'\n }\n return 'https://mainnet.aptoslabs.com/'\n}\n"]}
|
@@ -6,6 +6,7 @@ import { EventInstance } from './models.js';
|
|
6
6
|
import { ListStateStorage } from '@sentio/runtime';
|
7
7
|
import { MoveFetchConfig, Data_AptResource, HandleInterval, ProcessResult, Data_AptEvent, Data_AptCall } from '@sentio/protos';
|
8
8
|
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js';
|
9
|
+
import { PromiseOrVoid } from '../core/index.js';
|
9
10
|
type IndexConfigure = {
|
10
11
|
address: string;
|
11
12
|
network: AptosNetwork;
|
@@ -27,9 +28,9 @@ export declare class AptosBaseProcessor {
|
|
27
28
|
callHandlers: CallHandler<Data_AptCall>[];
|
28
29
|
coder: MoveCoder;
|
29
30
|
constructor(moduleName: string, options: AptosBindOptions);
|
30
|
-
onTransaction(handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) =>
|
31
|
+
onTransaction(handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => PromiseOrVoid, includedFailed?: boolean, fetchConfig?: Partial<MoveFetchConfig>): this;
|
31
32
|
onMoveEvent(handler: (event: EventInstance, ctx: AptosContext) => void, filter: EventFilter | EventFilter[], fetchConfig?: Partial<MoveFetchConfig>): this;
|
32
|
-
onEntryFunctionCall(handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) =>
|
33
|
+
onEntryFunctionCall(handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => PromiseOrVoid, filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[], fetchConfig?: Partial<MoveFetchConfig>): this;
|
33
34
|
getChainId(): string;
|
34
35
|
}
|
35
36
|
export declare class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {
|
@@ -42,7 +43,7 @@ export declare class AptosResourcesProcessor {
|
|
42
43
|
protected constructor(options: AptosBindOptions);
|
43
44
|
getChainId(): string;
|
44
45
|
private onInterval;
|
45
|
-
onTimeInterval(handler: (resources: MoveResource[], ctx: AptosResourcesContext) =>
|
46
|
-
onVersionInterval(handler: (resources: MoveResource[], ctx: AptosResourcesContext) =>
|
46
|
+
onTimeInterval(handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string): this;
|
47
|
+
onVersionInterval(handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid, versionInterval?: number, backfillVersionInterval?: number, typePrefix?: string): this;
|
47
48
|
}
|
48
49
|
export {};
|
@@ -5,6 +5,10 @@ import { ListStateStorage, mergeProcessResults } from '@sentio/runtime';
|
|
5
5
|
import { MoveFetchConfig, } from '@sentio/protos';
|
6
6
|
import { ServerError, Status } from 'nice-grpc';
|
7
7
|
import { parseMoveType } from '../move/index.js';
|
8
|
+
const DEFAULT_FETCH_CONFIG = {
|
9
|
+
resourceChanges: false,
|
10
|
+
allEvents: true,
|
11
|
+
};
|
8
12
|
class ResourceHandlder {
|
9
13
|
type;
|
10
14
|
versionInterval;
|
@@ -32,7 +36,7 @@ export class AptosBaseProcessor {
|
|
32
36
|
// return undefined
|
33
37
|
// }
|
34
38
|
onTransaction(handler, includedFailed = false, fetchConfig) {
|
35
|
-
const _fetchConfig = MoveFetchConfig.fromPartial(fetchConfig
|
39
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig });
|
36
40
|
// const address = this.config.address
|
37
41
|
// const moduleName = this.moduleName
|
38
42
|
const processor = this;
|
@@ -53,7 +57,7 @@ export class AptosBaseProcessor {
|
|
53
57
|
}
|
54
58
|
onMoveEvent(handler, filter, fetchConfig) {
|
55
59
|
let _filters = [];
|
56
|
-
const _fetchConfig = MoveFetchConfig.fromPartial(fetchConfig
|
60
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig });
|
57
61
|
if (Array.isArray(filter)) {
|
58
62
|
_filters = filter;
|
59
63
|
}
|
@@ -80,7 +84,7 @@ export class AptosBaseProcessor {
|
|
80
84
|
}
|
81
85
|
const ctx = new AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(txn.version), txn, idx);
|
82
86
|
const eventInstance = evt;
|
83
|
-
const decoded = processor.coder.decodeEvent(eventInstance);
|
87
|
+
const decoded = await processor.coder.decodeEvent(eventInstance);
|
84
88
|
await handler(decoded || eventInstance, ctx);
|
85
89
|
processResults.push(ctx.getProcessResult());
|
86
90
|
}
|
@@ -93,7 +97,7 @@ export class AptosBaseProcessor {
|
|
93
97
|
}
|
94
98
|
onEntryFunctionCall(handler, filter, fetchConfig) {
|
95
99
|
let _filters = [];
|
96
|
-
const _fetchConfig = MoveFetchConfig.fromPartial(fetchConfig
|
100
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig });
|
97
101
|
if (Array.isArray(filter)) {
|
98
102
|
_filters = filter;
|
99
103
|
}
|
@@ -112,7 +116,7 @@ export class AptosBaseProcessor {
|
|
112
116
|
const ctx = new AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(tx.version), tx, 0);
|
113
117
|
if (tx) {
|
114
118
|
const payload = tx.payload;
|
115
|
-
const decoded = processor.coder.decodeFunctionPayload(payload);
|
119
|
+
const decoded = await processor.coder.decodeFunctionPayload(payload);
|
116
120
|
await handler(decoded, ctx);
|
117
121
|
}
|
118
122
|
return ctx.getProcessResult();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAoB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EACL,eAAe,GAMhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAqE,aAAa,EAAE,MAAM,k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E,YAAY;YACnC,eAAe,EAAE,eAAe;YAChC,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,cAAc,CACnB,OAAwE,EACxE,qBAAqB,GAAG,EAAE,EAC1B,6BAA6B,GAAG,GAAG,EACnC,IAAa;QAEb,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP;YACE,cAAc,EAAE,qBAAqB;YACrC,gBAAgB,EAAE,6BAA6B;SAChD,EACD,SAAS,EACT,IAAI,CACL,CAAA;IACH,CAAC;IAEM,iBAAiB,CACtB,OAAwE,EACxE,eAAe,GAAG,MAAM,EACxB,uBAAuB,GAAG,MAAM,EAChC,UAAmB;QAEnB,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP,SAAS,EACT,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,EAC9E,UAAU,CACX,CAAA;IACH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,OAAyB;IAC1C,IAAI,YAAY,GAAG,EAAE,CAAA;IACrB,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;QACtC,IAAI,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE;YAC5C,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;SAC5C;aAAM;YACL,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;SACpC;KACF;IAED,OAAO;QACL,YAAY,EAAE,YAAY;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,QAAQ;KAClD,CAAA;AACH,CAAC","sourcesContent":["import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js'\n\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { AptosBindOptions, AptosNetwork, getChainId } from './network.js'\nimport { AptosContext, AptosResourcesContext } from './context.js'\nimport { EventInstance } from './models.js'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport {\n MoveFetchConfig,\n Data_AptResource,\n HandleInterval,\n ProcessResult,\n Data_AptEvent,\n Data_AptCall,\n} from '@sentio/protos'\nimport { ServerError, Status } from 'nice-grpc'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: bigint\n // endSeqNumber?: Long\n}\n\nclass ResourceHandlder {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_AptResource) => Promise<ProcessResult>\n}\n\nexport class AptosProcessorState extends ListStateStorage<AptosBaseProcessor> {\n static INSTANCE = new AptosProcessorState()\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler<Data_AptEvent>[] = []\n callHandlers: CallHandler<Data_AptCall>[] = []\n coder: MoveCoder\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.config = configure(options)\n AptosProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n // this.loadTypes(this.coder)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void,\n includedFailed = false,\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n const _fetchConfig = MoveFetchConfig.fromPartial(fetchConfig || {})\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const call = data.transaction as Transaction_UserTransaction\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(data.transaction.version),\n call,\n 0\n )\n await handler(call, ctx)\n return ctx.getProcessResult()\n },\n filters: [{ function: '', includeFailed: includedFailed }],\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onMoveEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial(fetchConfig || {})\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as Transaction_UserTransaction\n if (!txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of txn.events.entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(txn.version),\n txn,\n idx\n )\n const eventInstance = evt as EventInstance\n const decoded = processor.coder.decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial(fetchConfig || {})\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as Transaction_UserTransaction\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx,\n 0\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = processor.coder.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n // loadTypes(registry: MoveCoder) {\n // if (registry.contains(this.config.address, this.moduleName)) {\n // return\n // }\n // this.loadTypesInternal(registry)\n // }\n //\n // protected loadTypesInternal(registry: MoveCoder) {\n // // should be override by subclass\n // console.log('')\n // }\n}\n\nexport class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {\n static INSTANCE = new AptosAccountProcessorState()\n}\n\nexport class AptosResourcesProcessor {\n config: IndexConfigure\n\n resourcesHandlers: ResourceHandlder[] = []\n\n static bind(options: AptosBindOptions): AptosResourcesProcessor {\n return new AptosResourcesProcessor(options)\n }\n\n protected constructor(options: AptosBindOptions) {\n this.config = configure(options)\n AptosAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.resourcesHandlers.push({\n handler: async function (data) {\n if (data.timestampMicros > Number.MAX_SAFE_INTEGER) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n const timestamp = Number(data.timestampMicros)\n\n const ctx = new AptosResourcesContext(\n processor.config.network,\n processor.config.address,\n data.version,\n timestamp\n )\n await handler(data.resources as MoveResource[], ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type: type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onVersionInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,\n versionInterval = 100000,\n backfillVersionInterval = 400000,\n typePrefix?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },\n typePrefix\n )\n }\n}\n\nfunction configure(options: AptosBindOptions): IndexConfigure {\n let startVersion = 0n\n if (options.startVersion !== undefined) {\n if (typeof options.startVersion === 'number') {\n startVersion = BigInt(options.startVersion)\n } else {\n startVersion = options.startVersion\n }\n }\n\n return {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAoB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EACL,eAAe,GAMhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAqE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAGnH,MAAM,oBAAoB,GAAoB;IAC5C,eAAe,EAAE,KAAK;IACtB,SAAS,EAAE,IAAI;CAChB,CAAA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gBACpD,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;YAC/B,CAAC;YACD,qBAAqB,EAAE,YAAY;YACnC,eAAe,EAAE,eAAe;YAChC,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,cAAc,CACnB,OAAiF,EACjF,qBAAqB,GAAG,EAAE,EAC1B,6BAA6B,GAAG,GAAG,EACnC,IAAa;QAEb,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP;YACE,cAAc,EAAE,qBAAqB;YACrC,gBAAgB,EAAE,6BAA6B;SAChD,EACD,SAAS,EACT,IAAI,CACL,CAAA;IACH,CAAC;IAEM,iBAAiB,CACtB,OAAiF,EACjF,eAAe,GAAG,MAAM,EACxB,uBAAuB,GAAG,MAAM,EAChC,UAAmB;QAEnB,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP,SAAS,EACT,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,EAC9E,UAAU,CACX,CAAA;IACH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,OAAyB;IAC1C,IAAI,YAAY,GAAG,EAAE,CAAA;IACrB,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;QACtC,IAAI,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE;YAC5C,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;SAC5C;aAAM;YACL,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;SACpC;KACF;IAED,OAAO;QACL,YAAY,EAAE,YAAY;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,QAAQ;KAClD,CAAA;AACH,CAAC","sourcesContent":["import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js'\n\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { AptosBindOptions, AptosNetwork, getChainId } from './network.js'\nimport { AptosContext, AptosResourcesContext } from './context.js'\nimport { EventInstance } from './models.js'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport {\n MoveFetchConfig,\n Data_AptResource,\n HandleInterval,\n ProcessResult,\n Data_AptEvent,\n Data_AptCall,\n} from '@sentio/protos'\nimport { ServerError, Status } from 'nice-grpc'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'\nimport { PromiseOrVoid } from '../core/index.js'\n\nconst DEFAULT_FETCH_CONFIG: MoveFetchConfig = {\n resourceChanges: false,\n allEvents: true,\n}\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: bigint\n // endSeqNumber?: Long\n}\n\nclass ResourceHandlder {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_AptResource) => Promise<ProcessResult>\n}\n\nexport class AptosProcessorState extends ListStateStorage<AptosBaseProcessor> {\n static INSTANCE = new AptosProcessorState()\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler<Data_AptEvent>[] = []\n callHandlers: CallHandler<Data_AptCall>[] = []\n coder: MoveCoder\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.config = configure(options)\n AptosProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n // this.loadTypes(this.coder)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => PromiseOrVoid,\n includedFailed = false,\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const call = data.transaction as Transaction_UserTransaction\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(data.transaction.version),\n call,\n 0\n )\n await handler(call, ctx)\n return ctx.getProcessResult()\n },\n filters: [{ function: '', includeFailed: includedFailed }],\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onMoveEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as Transaction_UserTransaction\n if (!txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of txn.events.entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(txn.version),\n txn,\n idx\n )\n const eventInstance = evt as EventInstance\n const decoded = await processor.coder.decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => PromiseOrVoid,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as Transaction_UserTransaction\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx,\n 0\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = await processor.coder.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n // loadTypes(registry: MoveCoder) {\n // if (registry.contains(this.config.address, this.moduleName)) {\n // return\n // }\n // this.loadTypesInternal(registry)\n // }\n //\n // protected loadTypesInternal(registry: MoveCoder) {\n // // should be override by subclass\n // console.log('')\n // }\n}\n\nexport class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {\n static INSTANCE = new AptosAccountProcessorState()\n}\n\nexport class AptosResourcesProcessor {\n config: IndexConfigure\n\n resourcesHandlers: ResourceHandlder[] = []\n\n static bind(options: AptosBindOptions): AptosResourcesProcessor {\n return new AptosResourcesProcessor(options)\n }\n\n protected constructor(options: AptosBindOptions) {\n this.config = configure(options)\n AptosAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.resourcesHandlers.push({\n handler: async function (data) {\n if (data.timestampMicros > Number.MAX_SAFE_INTEGER) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n const timestamp = Number(data.timestampMicros)\n\n const ctx = new AptosResourcesContext(\n processor.config.network,\n processor.config.address,\n data.version,\n timestamp\n )\n await handler(data.resources as MoveResource[], ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type: type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onVersionInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n versionInterval = 100000,\n backfillVersionInterval = 400000,\n typePrefix?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },\n typePrefix\n )\n }\n}\n\nfunction configure(options: AptosBindOptions): IndexConfigure {\n let startVersion = 0n\n if (options.startVersion !== undefined) {\n if (typeof options.startVersion === 'number') {\n startVersion = BigInt(options.startVersion)\n } else {\n startVersion = options.startVersion\n }\n }\n\n return {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n}\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/aptos/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AAExB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC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,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACpD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,QAAQ,YAAY,CAAC,CAAC,CAAA;AAC7D,CAAC;AAED,MAAM,YAAa,SAAQ,eAAuE;IAChG,YAAY,GAAG,SAAS,CAAA;IACxB,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAA;IAChC,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAA;IAChC,MAAM,GAAG,OAAO,CAAA;IAEhB;QACE,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IACnC,CAAC;CACF","sourcesContent":["import * as fs from 'fs'\nimport { Event, MoveModuleBytecode, MoveResource } from '../move-types.js'\nimport chalk from 'chalk'\nimport { AptosNetwork } from '../network.js'\nimport { join } from 'path'\nimport { AptosChainAdapter } from '../aptos-chain-adapter.js'\nimport { AbstractCodegen } from '../../move/abstract-codegen.js'\n\nexport async function codegen(abisDir: string, outDir = join('src', 'types', 'aptos'), genExample = false) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n const gen = new AptosCodegen()\n const numFiles = await gen.generate(abisDir, outDir)\n console.log(chalk.green(`Generated ${numFiles} for Aptos`))\n}\n\nclass AptosCodegen extends AbstractCodegen<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {\n ADDRESS_TYPE = 'Address'\n MAIN_NET = AptosNetwork.MAIN_NET\n TEST_NET = AptosNetwork.TEST_NET\n PREFIX = 'Aptos'\n\n constructor() {\n super(AptosChainAdapter.INSTANCE)\n }\n}\n"]}
|
@@ -66,7 +66,7 @@ export class AptosDex {
|
|
66
66
|
return result;
|
67
67
|
}
|
68
68
|
async syncPools(resources, ctx, poolsHandler) {
|
69
|
-
const pools = ctx.coder.filterAndDecodeResources(this.poolAdaptor.poolTypeName, resources);
|
69
|
+
const pools = await ctx.coder.filterAndDecodeResources(this.poolAdaptor.poolTypeName, resources);
|
70
70
|
const volumeByCoin = new Map();
|
71
71
|
const timestamp = ctx.timestampInMicros;
|
72
72
|
console.log('num of pools: ', pools.length, ctx.version.toString());
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aptos-dex.js","sourceRoot":"","sources":["../../../src/aptos/ext/aptos-dex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAUzF,MAAM,OAAO,QAAQ;IACnB,WAAW,CAAgB;IAC3B,MAAM,CAAO;IACb,YAAY,CAAO;IACnB,MAAM,CAAO;IACb,SAAS,CAAO;IAChB,SAAS,CAAO;IAEhB,YACE,MAAa,EACb,YAAmB,EACnB,MAAa,EACb,SAAgB,EAChB,SAAgB,EAChB,WAA2B;QAE3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,mBAAmB,CACvB,GAAiB,EACjB,KAAa,EACb,KAAa,EACb,WAAmB,EACnB,WAAmB,EACnB,WAAiB;QAEjB,IAAI,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;QAE1B,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;QACrC,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;QACrC,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE;YAC9B,OAAO,MAAM,CAAA;SACd;QACD,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,CAAA;QAC1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AG,CAAC,CAAA;IAE5B,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE;QAC9B,OAAO,MAAM,CAAA;KACd;IAED,IAAI,UAAU,EAAE;QACd,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAC1E,MAAM,GAAG,KAAK,CAAA;QAEd,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;KACF;IACD,IAAI,UAAU,EAAE;QACd,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAE1E,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { Gauge } from '@sentio/sdk'\nimport { BigDecimal } from '@sentio/bigdecimal'\nimport { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'\nimport { AptosResourcesContext, TypedMoveResource, MoveResource, AptosContext } from '@sentio/sdk/aptos'\n\nexport interface PoolAdaptor<T> {\n getXReserve(pool: T): bigint\n getYReserve(pool: T): bigint\n getExtraPoolTags(pool: TypedMoveResource<T>): any\n poolTypeName: string\n}\n\nexport class AptosDex<T> {\n poolAdaptor: PoolAdaptor<T>\n volume: Gauge\n volumeByCoin: Gauge\n tvlAll: Gauge\n tvlByPool: Gauge\n tvlByCoin: Gauge\n\n constructor(\n volume: Gauge,\n volumeByCoin: Gauge,\n tvlAll: Gauge,\n tvlByCoin: Gauge,\n tvlByPool: Gauge,\n poolAdaptor: PoolAdaptor<T>\n ) {\n this.volume = volume\n this.volumeByCoin = volumeByCoin\n this.tvlAll = tvlAll\n this.tvlByPool = tvlByPool\n this.tvlByCoin = tvlByCoin\n this.poolAdaptor = poolAdaptor\n }\n\n async recordTradingVolume(\n ctx: AptosContext,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint,\n extraLabels?: any\n ): Promise<BigDecimal> {\n let result = BigDecimal(0)\n\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n if (!whitelistx && !whitelisty) {\n return result\n }\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n const timestamp = ctx.transaction.timestamp\n let resultX = BigDecimal(0)\n let resultY = BigDecimal(0)\n const pair = await getPair(coinx, coiny)\n const baseLabels: Record<string, string> = extraLabels ? { ...extraLabels, pair } : { pair }\n if (whitelistx) {\n resultX = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n }\n if (whitelisty) {\n resultY = await calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n }\n if (resultX.eq(0)) {\n resultX = BigDecimal(resultY)\n }\n if (resultY.eq(0)) {\n resultY = BigDecimal(resultX)\n }\n const total = resultX.plus(resultY)\n if (total.gt(0)) {\n this.volume.record(ctx, total, {\n ...baseLabels,\n bridge: coinXInfo.bridge,\n })\n }\n if (resultX.gt(0)) {\n this.volumeByCoin.record(ctx, resultX, {\n coin: coinXInfo.symbol,\n bridge: coinXInfo.bridge,\n type: coinXInfo.token_type.type,\n })\n }\n if (resultY.gt(0)) {\n this.volumeByCoin.record(ctx, resultY, {\n coin: coinYInfo.symbol,\n bridge: coinYInfo.bridge,\n type: coinYInfo.token_type.type,\n })\n }\n result = resultX.plus(resultY).div(2)\n return result\n }\n\n async syncPools(\n resources: MoveResource[],\n ctx: AptosResourcesContext,\n poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void\n ) {\n const pools: TypedMoveResource<T>[] = ctx.coder.filterAndDecodeResources(this.poolAdaptor.poolTypeName, resources)\n\n const volumeByCoin = new Map<string, BigDecimal>()\n const timestamp = ctx.timestampInMicros\n\n console.log('num of pools: ', pools.length, ctx.version.toString())\n\n let tvlAllValue = BigDecimal(0)\n for (const pool of pools) {\n // savePool(ctx.version, pool.type_arguments)\n const coinx = pool.type_arguments[0]\n const coiny = pool.type_arguments[1]\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n if (!whitelistx && !whitelisty) {\n continue\n }\n\n const pair = await getPair(coinx, coiny)\n const extraLabels = this.poolAdaptor.getExtraPoolTags(pool)\n const baseLabels: Record<string, string> = { ...extraLabels, pair }\n\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n\n const coinx_amount = this.poolAdaptor.getXReserve(pool.data_decoded)\n const coiny_amount = this.poolAdaptor.getYReserve(pool.data_decoded)\n\n let resultX = BigDecimal(0)\n let resultY = BigDecimal(0)\n\n if (whitelistx) {\n resultX = await calculateValueInUsd(coinx_amount, coinXInfo, timestamp)\n let coinXTotal = volumeByCoin.get(coinXInfo.token_type.type)\n if (!coinXTotal) {\n coinXTotal = resultX\n } else {\n coinXTotal = coinXTotal.plus(resultX)\n }\n volumeByCoin.set(coinXInfo.token_type.type, coinXTotal)\n }\n if (whitelisty) {\n resultY = await calculateValueInUsd(coiny_amount, coinYInfo, timestamp)\n let coinYTotal = volumeByCoin.get(coinYInfo.token_type.type)\n if (!coinYTotal) {\n coinYTotal = resultY\n } else {\n coinYTotal = coinYTotal.plus(resultY)\n }\n volumeByCoin.set(coinYInfo.token_type.type, coinYTotal)\n }\n\n if (resultX.eq(0)) {\n resultX = BigDecimal(resultY)\n }\n if (resultY.eq(0)) {\n resultY = BigDecimal(resultX)\n }\n\n const poolValue = resultX.plus(resultY)\n\n if (poolValue.isGreaterThan(0)) {\n this.tvlByPool.record(ctx, poolValue, baseLabels)\n }\n tvlAllValue = tvlAllValue.plus(poolValue)\n }\n this.tvlAll.record(ctx, tvlAllValue)\n\n if (poolsHandler) {\n poolsHandler(pools)\n }\n\n for (const [k, v] of volumeByCoin) {\n const coinInfo = whitelistCoins().get(k)\n if (!coinInfo) {\n throw Error('unexpected coin ' + k)\n }\n // const price = await getPrice(coinInfo, timestamp)\n // priceGauge.record(ctx, price, { coin: coinInfo.symbol })\n if (v.isGreaterThan(0)) {\n this.tvlByCoin.record(ctx, v, {\n coin: coinInfo.symbol,\n bridge: coinInfo.bridge,\n type: coinInfo.token_type.type,\n })\n }\n }\n }\n}\n\nexport async function getPair(coinx: string, coiny: string): Promise<string> {\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n if (coinXInfo.symbol.localeCompare(coinYInfo.symbol) > 0) {\n return `${coinYInfo.symbol}-${coinXInfo.symbol}`\n }\n return `${coinXInfo.symbol}-${coinYInfo.symbol}`\n}\n\nexport async function getPairValue(\n ctx: AptosContext,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint\n): Promise<BigDecimal> {\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n const timestamp = ctx.transaction.timestamp\n let result = BigDecimal(0.0)\n\n if (!whitelistx || !whitelisty) {\n return result\n }\n\n if (whitelistx) {\n const value = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n result = value\n\n if (!whitelisty) {\n result = result.plus(value)\n }\n }\n if (whitelisty) {\n const value = await calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n\n if (!whitelistx) {\n result = result.plus(value)\n }\n }\n\n return result\n}\n"]}
|
1
|
+
{"version":3,"file":"aptos-dex.js","sourceRoot":"","sources":["../../../src/aptos/ext/aptos-dex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAUzF,MAAM,OAAO,QAAQ;IACnB,WAAW,CAAgB;IAC3B,MAAM,CAAO;IACb,YAAY,CAAO;IACnB,MAAM,CAAO;IACb,SAAS,CAAO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IAAI,CAAC,UAAU,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { Gauge } from '@sentio/sdk'\nimport { BigDecimal } from '@sentio/bigdecimal'\nimport { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'\nimport { AptosResourcesContext, TypedMoveResource, MoveResource, AptosContext } from '@sentio/sdk/aptos'\n\nexport interface PoolAdaptor<T> {\n getXReserve(pool: T): bigint\n getYReserve(pool: T): bigint\n getExtraPoolTags(pool: TypedMoveResource<T>): any\n poolTypeName: string\n}\n\nexport class AptosDex<T> {\n poolAdaptor: PoolAdaptor<T>\n volume: Gauge\n volumeByCoin: Gauge\n tvlAll: Gauge\n tvlByPool: Gauge\n tvlByCoin: Gauge\n\n constructor(\n volume: Gauge,\n volumeByCoin: Gauge,\n tvlAll: Gauge,\n tvlByCoin: Gauge,\n tvlByPool: Gauge,\n poolAdaptor: PoolAdaptor<T>\n ) {\n this.volume = volume\n this.volumeByCoin = volumeByCoin\n this.tvlAll = tvlAll\n this.tvlByPool = tvlByPool\n this.tvlByCoin = tvlByCoin\n this.poolAdaptor = poolAdaptor\n }\n\n async recordTradingVolume(\n ctx: AptosContext,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint,\n extraLabels?: any\n ): Promise<BigDecimal> {\n let result = BigDecimal(0)\n\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n if (!whitelistx && !whitelisty) {\n return result\n }\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n const timestamp = ctx.transaction.timestamp\n let resultX = BigDecimal(0)\n let resultY = BigDecimal(0)\n const pair = await getPair(coinx, coiny)\n const baseLabels: Record<string, string> = extraLabels ? { ...extraLabels, pair } : { pair }\n if (whitelistx) {\n resultX = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n }\n if (whitelisty) {\n resultY = await calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n }\n if (resultX.eq(0)) {\n resultX = BigDecimal(resultY)\n }\n if (resultY.eq(0)) {\n resultY = BigDecimal(resultX)\n }\n const total = resultX.plus(resultY)\n if (total.gt(0)) {\n this.volume.record(ctx, total, {\n ...baseLabels,\n bridge: coinXInfo.bridge,\n })\n }\n if (resultX.gt(0)) {\n this.volumeByCoin.record(ctx, resultX, {\n coin: coinXInfo.symbol,\n bridge: coinXInfo.bridge,\n type: coinXInfo.token_type.type,\n })\n }\n if (resultY.gt(0)) {\n this.volumeByCoin.record(ctx, resultY, {\n coin: coinYInfo.symbol,\n bridge: coinYInfo.bridge,\n type: coinYInfo.token_type.type,\n })\n }\n result = resultX.plus(resultY).div(2)\n return result\n }\n\n async syncPools(\n resources: MoveResource[],\n ctx: AptosResourcesContext,\n poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void\n ) {\n const pools: TypedMoveResource<T>[] = await ctx.coder.filterAndDecodeResources(\n this.poolAdaptor.poolTypeName,\n resources\n )\n\n const volumeByCoin = new Map<string, BigDecimal>()\n const timestamp = ctx.timestampInMicros\n\n console.log('num of pools: ', pools.length, ctx.version.toString())\n\n let tvlAllValue = BigDecimal(0)\n for (const pool of pools) {\n // savePool(ctx.version, pool.type_arguments)\n const coinx = pool.type_arguments[0]\n const coiny = pool.type_arguments[1]\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n if (!whitelistx && !whitelisty) {\n continue\n }\n\n const pair = await getPair(coinx, coiny)\n const extraLabels = this.poolAdaptor.getExtraPoolTags(pool)\n const baseLabels: Record<string, string> = { ...extraLabels, pair }\n\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n\n const coinx_amount = this.poolAdaptor.getXReserve(pool.data_decoded)\n const coiny_amount = this.poolAdaptor.getYReserve(pool.data_decoded)\n\n let resultX = BigDecimal(0)\n let resultY = BigDecimal(0)\n\n if (whitelistx) {\n resultX = await calculateValueInUsd(coinx_amount, coinXInfo, timestamp)\n let coinXTotal = volumeByCoin.get(coinXInfo.token_type.type)\n if (!coinXTotal) {\n coinXTotal = resultX\n } else {\n coinXTotal = coinXTotal.plus(resultX)\n }\n volumeByCoin.set(coinXInfo.token_type.type, coinXTotal)\n }\n if (whitelisty) {\n resultY = await calculateValueInUsd(coiny_amount, coinYInfo, timestamp)\n let coinYTotal = volumeByCoin.get(coinYInfo.token_type.type)\n if (!coinYTotal) {\n coinYTotal = resultY\n } else {\n coinYTotal = coinYTotal.plus(resultY)\n }\n volumeByCoin.set(coinYInfo.token_type.type, coinYTotal)\n }\n\n if (resultX.eq(0)) {\n resultX = BigDecimal(resultY)\n }\n if (resultY.eq(0)) {\n resultY = BigDecimal(resultX)\n }\n\n const poolValue = resultX.plus(resultY)\n\n if (poolValue.isGreaterThan(0)) {\n this.tvlByPool.record(ctx, poolValue, baseLabels)\n }\n tvlAllValue = tvlAllValue.plus(poolValue)\n }\n this.tvlAll.record(ctx, tvlAllValue)\n\n if (poolsHandler) {\n poolsHandler(pools)\n }\n\n for (const [k, v] of volumeByCoin) {\n const coinInfo = whitelistCoins().get(k)\n if (!coinInfo) {\n throw Error('unexpected coin ' + k)\n }\n // const price = await getPrice(coinInfo, timestamp)\n // priceGauge.record(ctx, price, { coin: coinInfo.symbol })\n if (v.isGreaterThan(0)) {\n this.tvlByCoin.record(ctx, v, {\n coin: coinInfo.symbol,\n bridge: coinInfo.bridge,\n type: coinInfo.token_type.type,\n })\n }\n }\n }\n}\n\nexport async function getPair(coinx: string, coiny: string): Promise<string> {\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n if (coinXInfo.symbol.localeCompare(coinYInfo.symbol) > 0) {\n return `${coinYInfo.symbol}-${coinXInfo.symbol}`\n }\n return `${coinXInfo.symbol}-${coinYInfo.symbol}`\n}\n\nexport async function getPairValue(\n ctx: AptosContext,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint\n): Promise<BigDecimal> {\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n const timestamp = ctx.transaction.timestamp\n let result = BigDecimal(0.0)\n\n if (!whitelistx || !whitelisty) {\n return result\n }\n\n if (whitelistx) {\n const value = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n result = value\n\n if (!whitelisty) {\n result = result.plus(value)\n }\n }\n if (whitelisty) {\n const value = await calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n\n if (!whitelistx) {\n result = result.plus(value)\n }\n }\n\n return result\n}\n"]}
|
@@ -12,7 +12,7 @@ export class ModuleClient {
|
|
12
12
|
}
|
13
13
|
async viewDecoded(func, typeArguments, args, ledger_version) {
|
14
14
|
const coder = defaultMoveCoder();
|
15
|
-
const encodedArgs = coder.encodeCallArgs(args, func);
|
15
|
+
const encodedArgs = await coder.encodeCallArgs(args, func);
|
16
16
|
const request = {
|
17
17
|
function: func,
|
18
18
|
type_arguments: typeArguments,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"module-client.js","sourceRoot":"","sources":["../../src/aptos/module-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAS,MAAM,WAAW,CAAA;AAE9C,MAAM,OAAO,YAAY;IACvB,MAAM,CAAa;IACnB,YAAY,MAA4B;QACtC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;SACtC;aAAM;YACL,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;SACrB;IACH,CAAC;IACM,KAAK,CAAC,WAAW,CACtB,IAAY,EACZ,aAAuB,EACvB,IAAW,EACX,cAAuB;QAEvB,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAA;QAChC,MAAM,WAAW,GAAG,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;
|
1
|
+
{"version":3,"file":"module-client.js","sourceRoot":"","sources":["../../src/aptos/module-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAS,MAAM,WAAW,CAAA;AAE9C,MAAM,OAAO,YAAY;IACvB,MAAM,CAAa;IACnB,YAAY,MAA4B;QACtC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;SACtC;aAAM;YACL,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;SACrB;IACH,CAAC;IACM,KAAK,CAAC,WAAW,CACtB,IAAY,EACZ,aAAuB,EACvB,IAAW,EACX,cAAuB;QAEvB,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAA;QAChC,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAE1D,MAAM,OAAO,GAAsB;YACjC,QAAQ,EAAE,IAAI;YACd,cAAc,EAAE,aAAa;YAC7B,SAAS,EAAE,WAAW;SACvB,CAAA;QACD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,CAAA;QACvE,OAAO,KAAK,CAAC,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC1C,CAAC;CACF","sourcesContent":["import { defaultMoveCoder } from './index.js'\nimport { AptosClient, Types } from 'aptos-sdk'\n\nexport class ModuleClient {\n client: AptosClient\n constructor(client: AptosClient | string) {\n if (typeof client === 'string') {\n this.client = new AptosClient(client)\n } else {\n this.client = client\n }\n }\n public async viewDecoded(\n func: string,\n typeArguments: string[],\n args: any[],\n ledger_version?: bigint\n ): Promise<any[]> {\n const coder = defaultMoveCoder()\n const encodedArgs = await coder.encodeCallArgs(args, func)\n\n const request: Types.ViewRequest = {\n function: func,\n type_arguments: typeArguments,\n arguments: encodedArgs,\n }\n const res = await this.client.view(request, ledger_version?.toString())\n return coder.decodeCallResult(res, func)\n }\n}\n"]}
|
@@ -4,11 +4,11 @@ import { AbstractMoveCoder } from '../move/abstract-move-coder.js';
|
|
4
4
|
import { AptosNetwork } from './network.js';
|
5
5
|
export declare class MoveCoder extends AbstractMoveCoder<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
|
6
6
|
constructor(network: AptosNetwork);
|
7
|
-
load(module: MoveModuleBytecode):
|
8
|
-
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined
|
9
|
-
filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[]
|
10
|
-
decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined
|
11
|
-
filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[]
|
12
|
-
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload
|
7
|
+
load(module: MoveModuleBytecode): import("../move/internal-models.js").InternalMoveModule;
|
8
|
+
decodeEvent<T>(event: Event): Promise<TypedEventInstance<T> | undefined>;
|
9
|
+
filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): Promise<TypedEventInstance<T>[]>;
|
10
|
+
decodeResource<T>(res: MoveResource): Promise<TypedMoveResource<T> | undefined>;
|
11
|
+
filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): Promise<TypedMoveResource<T>[]>;
|
12
|
+
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): Promise<TransactionPayload_EntryFunctionPayload>;
|
13
13
|
}
|
14
14
|
export declare function defaultMoveCoder(network?: AptosNetwork): MoveCoder;
|
package/lib/aptos/move-coder.js
CHANGED
@@ -11,10 +11,16 @@ export class MoveCoder extends AbstractMoveCoder {
|
|
11
11
|
if (!module.abi) {
|
12
12
|
throw Error('Module without abi');
|
13
13
|
}
|
14
|
-
|
15
|
-
|
14
|
+
let m = this.moduleMapping.get(module.abi.address + '::' + module.abi.name);
|
15
|
+
// if (this.contains(module.abi.address, module.abi.name)) {
|
16
|
+
// return
|
17
|
+
// }
|
18
|
+
if (m) {
|
19
|
+
return m;
|
16
20
|
}
|
17
|
-
|
21
|
+
m = toInternalModule(module);
|
22
|
+
this.loadInternal(m);
|
23
|
+
return m;
|
18
24
|
}
|
19
25
|
decodeEvent(event) {
|
20
26
|
return this.decodedStruct(event);
|
@@ -28,10 +34,10 @@ export class MoveCoder extends AbstractMoveCoder {
|
|
28
34
|
filterAndDecodeResources(typeQname, resources) {
|
29
35
|
return this.filterAndDecodeStruct(typeQname, resources);
|
30
36
|
}
|
31
|
-
decodeFunctionPayload(payload) {
|
32
|
-
const func = this.getMoveFunction(payload.function);
|
37
|
+
async decodeFunctionPayload(payload) {
|
38
|
+
const func = await this.getMoveFunction(payload.function);
|
33
39
|
const params = this.adapter.getMeaningfulFunctionParams(func.params);
|
34
|
-
const argumentsDecoded = this.decodeArray(payload.arguments, params);
|
40
|
+
const argumentsDecoded = await this.decodeArray(payload.arguments, params);
|
35
41
|
return {
|
36
42
|
...payload,
|
37
43
|
arguments_decoded: argumentsDecoded,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/aptos/move-coder.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,gBAAgB,GAEjB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE5D,MAAM,OAAO,SAAU,SAAQ,iBAAyE;IACtG,YAAY,OAAqB;QAC/B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aAAa,CAAI,KAAK,CAAQ,CAAA;IAC5C,CAAC;IACD,qBAAqB,CAAI,SAAiB,EAAE,SAAkB;QAC5D,OAAO,IAAI,CAAC,qBAAqB,CAAC,SAAS,EAAE,SAAS,CAAQ,CAAA;IAChE,CAAC;IACD,cAAc,CAAI,GAAiB;QACjC,OAAO,IAAI,CAAC,aAAa,CAAI,GAAG,CAAC,CAAA;IACnC,CAAC;IACD,wBAAwB,CAAI,SAAiB,EAAE,SAAyB;QACtE,OAAO,IAAI,CAAC,qBAAqB,CAAC,SAAS,EAAE,SAAS,CAAQ,CAAA;IAChE,CAAC;IAED,KAAK,CAAC,qBAAqB,CACzB,OAAgD;QAEhD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACzD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACpE,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAE1E,OAAO;YACL,GAAG,OAAO;YACV,iBAAiB,EAAE,gBAAgB;SACP,CAAA;IAChC,CAAC;CACF;AAED,MAAM,UAAU,GAAG,IAAI,SAAS,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;AACvD,MAAM,kBAAkB,GAAG,IAAI,SAAS,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;AAE/D,MAAM,UAAU,gBAAgB,CAAC,UAAwB,YAAY,CAAC,QAAQ;IAC5E,IAAI,OAAO,IAAI,YAAY,CAAC,QAAQ,EAAE;QACpC,OAAO,UAAU,CAAA;KAClB;IACD,OAAO,kBAAkB,CAAA;AAC3B,CAAC","sourcesContent":["import {\n Event,\n MoveModuleBytecode,\n MoveResource,\n toInternalModule,\n TransactionPayload_EntryFunctionPayload,\n} from './move-types.js'\n\nimport { TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'\nimport { AbstractMoveCoder } from '../move/abstract-move-coder.js'\nimport { AptosNetwork } from './network.js'\nimport { AptosChainAdapter } from './aptos-chain-adapter.js'\n\nexport class MoveCoder extends AbstractMoveCoder<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {\n constructor(network: AptosNetwork) {\n super(network)\n this.adapter = new AptosChainAdapter()\n }\n\n load(module: MoveModuleBytecode) {\n if (!module.abi) {\n throw Error('Module without abi')\n }\n let m = this.moduleMapping.get(module.abi.address + '::' + module.abi.name)\n // if (this.contains(module.abi.address, module.abi.name)) {\n // return\n // }\n if (m) {\n return m\n }\n m = toInternalModule(module)\n this.loadInternal(m)\n return m\n }\n\n decodeEvent<T>(event: Event): Promise<TypedEventInstance<T> | undefined> {\n return this.decodedStruct<T>(event) as any\n }\n filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): Promise<TypedEventInstance<T>[]> {\n return this.filterAndDecodeStruct(typeQname, resources) as any\n }\n decodeResource<T>(res: MoveResource): Promise<TypedMoveResource<T> | undefined> {\n return this.decodedStruct<T>(res)\n }\n filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): Promise<TypedMoveResource<T>[]> {\n return this.filterAndDecodeStruct(typeQname, resources) as any\n }\n\n async decodeFunctionPayload(\n payload: TransactionPayload_EntryFunctionPayload\n ): Promise<TransactionPayload_EntryFunctionPayload> {\n const func = await this.getMoveFunction(payload.function)\n const params = this.adapter.getMeaningfulFunctionParams(func.params)\n const argumentsDecoded = await this.decodeArray(payload.arguments, params)\n\n return {\n ...payload,\n arguments_decoded: argumentsDecoded,\n } as TypedFunctionPayload<any>\n }\n}\n\nconst MOVE_CODER = new MoveCoder(AptosNetwork.MAIN_NET)\nconst TESTNET_MOVE_CODER = new MoveCoder(AptosNetwork.TEST_NET)\n\nexport function defaultMoveCoder(network: AptosNetwork = AptosNetwork.MAIN_NET): MoveCoder {\n if (network == AptosNetwork.MAIN_NET) {\n return MOVE_CODER\n }\n return TESTNET_MOVE_CODER\n}\n"]}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { BaseContract, DeferredTopicFilter, TransactionResponseParams } from 'ethers';
|
2
|
-
import {
|
2
|
+
import { Network } from 'ethers/providers';
|
3
3
|
import { BoundContractView, ContractContext, ContractView, GlobalContext } from './context.js';
|
4
4
|
import { AddressType, Data_EthBlock, Data_EthLog, Data_EthTrace, Data_EthTransaction, EthFetchConfig, HandleInterval, ProcessResult } from '@sentio/protos';
|
5
5
|
import { BindOptions } from './bind-options.js';
|
6
6
|
import { PromiseOrVoid } from '../core/promises.js';
|
7
|
-
import { TypedEvent, TypedCallTrace } from './eth.js';
|
7
|
+
import { TypedEvent, TypedCallTrace, RichBlock } from './eth.js';
|
8
8
|
import { ListStateStorage } from '@sentio/runtime';
|
9
9
|
export interface AddressOrTypeEventFilter extends DeferredTopicFilter {
|
10
10
|
addressType?: AddressType;
|
@@ -45,10 +45,10 @@ export declare class GlobalProcessor {
|
|
45
45
|
transactionHandler: TransactionHandler[];
|
46
46
|
static bind(config: Omit<BindOptions, 'address'>): GlobalProcessor;
|
47
47
|
constructor(config: Omit<BindOptions, 'address'>);
|
48
|
-
onBlockInterval(handler: (block:
|
49
|
-
onTimeInterval(handler: (block:
|
48
|
+
onBlockInterval(handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid, blockInterval?: number, backfillBlockInterval?: number): this;
|
49
|
+
onTimeInterval(handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number): this;
|
50
50
|
getChainId(): number;
|
51
|
-
onInterval(handler: (block:
|
51
|
+
onInterval(handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid, timeInterval: HandleInterval | undefined, blockInterval: HandleInterval | undefined): this;
|
52
52
|
onTransaction(handler: (transaction: TransactionResponseParams, ctx: GlobalContext) => PromiseOrVoid, fetchConfig?: Partial<EthFetchConfig>): this;
|
53
53
|
}
|
54
54
|
export declare abstract class BaseProcessor<TContract extends BaseContract, TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>> {
|
@@ -60,9 +60,9 @@ export declare abstract class BaseProcessor<TContract extends BaseContract, TBou
|
|
60
60
|
protected abstract CreateBoundContractView(): TBoundContractView;
|
61
61
|
getChainId(): number;
|
62
62
|
onEvent(handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: DeferredTopicFilter | DeferredTopicFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
63
|
-
onBlockInterval(handler: (block:
|
64
|
-
onTimeInterval(handler: (block:
|
65
|
-
onInterval(handler: (block:
|
63
|
+
onBlockInterval(handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, blockInterval?: number, backfillBlockInterval?: number): this;
|
64
|
+
onTimeInterval(handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number): this;
|
65
|
+
onInterval(handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeInterval: HandleInterval | undefined, blockInterval: HandleInterval | undefined): this;
|
66
66
|
onAllEvents(handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, fetchConfig?: Partial<EthFetchConfig>): this;
|
67
67
|
onTrace(signatures: string | string[], handler: (trace: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, fetchConfig?: Partial<EthFetchConfig>): this;
|
68
68
|
onAllTraces(handler: (event: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, fetchConfig?: Partial<EthFetchConfig>): this;
|
@@ -2,7 +2,6 @@ import { ContractContext, GlobalContext } from './context.js';
|
|
2
2
|
import { EthFetchConfig, ProcessResult, } from '@sentio/protos';
|
3
3
|
import { ServerError, Status } from 'nice-grpc';
|
4
4
|
import { fixEmptyKey, formatEthData } from './eth.js';
|
5
|
-
import * as console from 'console';
|
6
5
|
import { getNetworkFromCtxOrNetworkish } from './provider.js';
|
7
6
|
import sha3 from 'js-sha3';
|
8
7
|
import { ListStateStorage } from '@sentio/runtime';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/eth/base-processor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAqB,eAAe,EAAgB,aAAa,EAAE,MAAM,cAAc,CAAA;AAC9F,OAAO,EAML,cAAc,EAEd,aAAa,GACd,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,WAAW,EAA8B,aAAa,EAAE,MAAM,UAAU,CAAA;AACjF,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,IAAI,MAAM,SAAS,CAAA;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAOlD,MAAM,OAAO,aAAa;IACxB,OAAO,CAA4B;IACnC,OAAO,CAAgD;IACvD,WAAW,CAAgB;CAC5B;AAED,MAAM,OAAO,YAAY;IACvB,UAAU,CAAU;IACpB,OAAO,CAAkD;IACzD,WAAW,CAAgB;CAC5B;AAED,MAAM,OAAO,YAAY;IACvB,aAAa,CAAiB;IAC9B,qBAAqB,CAAiB;IACtC,OAAO,CAAkD;CAC1D;AAED,MAAM,OAAO,kBAAkB;IAC7B,OAAO,CAAwD;IAC/D,WAAW,CAAgB;CAC5B;AAED,MAAM,mBAAmB;IACvB,OAAO,CAAQ;IACf,OAAO,CAAS;IAChB,IAAI,CAAQ;IACZ,UAAU,CAAQ;IAClB,QAAQ,CAAS;CAClB;AAED,MAAa,oBAAqB,SAAQ,gBAAiC;IACzE,MAAM,CAAC,QAAQ,GAAG,IAAI,oBAAoB,EAAE,CAAA;;SADjC,oBAAoB;AA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ACjB,SAAS,EACT,UAAU,KAAK,EAAE,GAAG;YAClB,OAAO,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAC5B,CAAC,EACD,WAAW,CACZ,CAAA;IACH,CAAC;CACF","sourcesContent":["import { BaseContract, DeferredTopicFilter, TransactionResponseParams } from 'ethers'\nimport { BlockParams, Network } from 'ethers/providers'\n\nimport { BoundContractView, ContractContext, ContractView, GlobalContext } from './context.js'\nimport {\n AddressType,\n Data_EthBlock,\n Data_EthLog,\n Data_EthTrace,\n Data_EthTransaction,\n EthFetchConfig,\n HandleInterval,\n ProcessResult,\n} from '@sentio/protos'\nimport { BindOptions } from './bind-options.js'\nimport { PromiseOrVoid } from '../core/promises.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { fixEmptyKey, TypedEvent, TypedCallTrace, formatEthData } from './eth.js'\nimport * as console from 'console'\nimport { getNetworkFromCtxOrNetworkish } from './provider.js'\nimport sha3 from 'js-sha3'\nimport { ListStateStorage } from '@sentio/runtime'\n\nexport interface AddressOrTypeEventFilter extends DeferredTopicFilter {\n addressType?: AddressType\n address?: string\n}\n\nexport class EventsHandler {\n filters: AddressOrTypeEventFilter[]\n handler: (event: Data_EthLog) => Promise<ProcessResult>\n fetchConfig: EthFetchConfig\n}\n\nexport class TraceHandler {\n signatures: string[]\n handler: (trace: Data_EthTrace) => Promise<ProcessResult>\n fetchConfig: EthFetchConfig\n}\n\nexport class BlockHandler {\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (block: Data_EthBlock) => Promise<ProcessResult>\n}\n\nexport class TransactionHandler {\n handler: (block: Data_EthTransaction) => Promise<ProcessResult>\n fetchConfig: EthFetchConfig\n}\n\nclass BindInternalOptions {\n address: string\n network: Network\n name: string\n startBlock: bigint\n endBlock?: bigint\n}\n\nexport class GlobalProcessorState extends ListStateStorage<GlobalProcessor> {\n static INSTANCE = new GlobalProcessorState()\n}\n\nexport class GlobalProcessor {\n config: BindInternalOptions\n blockHandlers: BlockHandler[] = []\n transactionHandler: TransactionHandler[] = []\n\n static bind(config: Omit<BindOptions, 'address'>): GlobalProcessor {\n const processor = new GlobalProcessor(config)\n GlobalProcessorState.INSTANCE.addValue(processor)\n return processor\n }\n\n constructor(config: Omit<BindOptions, 'address'>) {\n this.config = {\n address: '*',\n name: config.name || 'Global',\n network: getNetworkFromCtxOrNetworkish(config.network),\n startBlock: 0n,\n }\n if (config.startBlock) {\n this.config.startBlock = BigInt(config.startBlock)\n }\n if (config.endBlock) {\n this.config.endBlock = BigInt(config.endBlock)\n }\n }\n\n public onBlockInterval(\n handler: (block: BlockParams, ctx: GlobalContext) => PromiseOrVoid,\n blockInterval = 250,\n backfillBlockInterval = 1000\n ): this {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: BlockParams, ctx: GlobalContext) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240\n ): this {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },\n undefined\n )\n }\n\n public getChainId(): number {\n return Number(this.config.network.chainId)\n }\n\n public onInterval(\n handler: (block: BlockParams, ctx: GlobalContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined\n ): this {\n const chainId = this.getChainId()\n\n this.blockHandlers.push({\n handler: async function (data: Data_EthBlock) {\n const { block } = formatEthData(data)\n\n if (!block) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty')\n }\n\n const ctx = new GlobalContext(chainId, new Date(block.timestamp * 1000), block, undefined, undefined)\n await handler(block, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n blockInterval: blockInterval,\n })\n return this\n }\n\n public onTransaction(\n handler: (transaction: TransactionResponseParams, ctx: GlobalContext) => PromiseOrVoid,\n fetchConfig?: Partial<EthFetchConfig>\n ): this {\n const chainId = this.getChainId()\n this.transactionHandler.push({\n handler: async function (data: Data_EthTransaction) {\n const { trace, block, transaction, transactionReceipt } = formatEthData(data)\n\n if (!transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'transaction is empty')\n }\n const ctx = new GlobalContext(chainId, data.timestamp, block, undefined, trace, transaction, transactionReceipt)\n await handler(transaction, ctx)\n return ctx.getProcessResult()\n },\n fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),\n })\n return this\n }\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: BlockHandler[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: getNetworkFromCtxOrNetworkish(config.network),\n startBlock: 0n,\n }\n if (config.startBlock) {\n this.config.startBlock = BigInt(config.startBlock)\n }\n if (config.endBlock) {\n this.config.endBlock = BigInt(config.endBlock)\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return Number(this.config.network.chainId)\n }\n\n public onEvent(\n handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: DeferredTopicFilter | DeferredTopicFilter[],\n fetchConfig?: Partial<EthFetchConfig>\n ): this {\n const chainId = this.getChainId()\n let _filters: DeferredTopicFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractName = this.config.name\n const processor = this\n this.eventHandlers.push({\n filters: _filters,\n fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),\n handler: async function (data: Data_EthLog) {\n const { log, block, transaction, transactionReceipt } = formatEthData(data)\n if (!log) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty')\n }\n const contractView = processor.CreateBoundContractView()\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n data.timestamp,\n block,\n log,\n undefined,\n transaction,\n transactionReceipt\n )\n const logParam = log as any as { topics: Array<string>; data: string }\n\n const parsed = contractView.rawContract.interface.parseLog(logParam)\n\n if (parsed) {\n const event: TypedEvent = { ...log, name: parsed.name, args: fixEmptyKey(parsed) }\n await handler(event, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n return this\n }\n\n public onBlockInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 250,\n backfillBlockInterval = 1000\n ): this {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240\n ): this {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },\n undefined\n )\n }\n\n public onInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined\n ): this {\n const chainId = this.getChainId()\n const processor = this\n const contractName = this.config.name\n\n this.blockHandlers.push({\n handler: async function (data: Data_EthBlock) {\n const { block } = formatEthData(data)\n\n if (!block) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty')\n }\n\n const contractView = processor.CreateBoundContractView()\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n new Date(block.timestamp * 1000),\n block,\n undefined,\n undefined\n )\n await handler(block, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n blockInterval: blockInterval,\n })\n return this\n }\n\n public onAllEvents(\n handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n fetchConfig?: Partial<EthFetchConfig>\n ): this {\n const _filters: DeferredTopicFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const fragment of tmpContract.rawContract.interface.fragments) {\n if (fragment.type === 'event') {\n const filter = tmpContract.rawContract.filters[fragment.format()]\n _filters.push(filter())\n }\n }\n return this.onEvent(\n function (log, ctx) {\n return handler(log, ctx)\n },\n _filters,\n fetchConfig\n )\n }\n\n public onTrace(\n signatures: string | string[],\n handler: (trace: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n fetchConfig?: Partial<EthFetchConfig>\n ): this {\n const chainId = this.getChainId()\n const contractName = this.config.name\n const processor = this\n if (typeof signatures === 'string') {\n signatures = [signatures]\n }\n\n this.traceHandlers.push({\n signatures,\n fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),\n handler: async function (data: Data_EthTrace) {\n const contractView = processor.CreateBoundContractView()\n const contractInterface = contractView.rawContract.interface\n const { trace, block, transaction, transactionReceipt } = formatEthData(data)\n const sighash = trace?.action.input?.slice(0, 10)\n if (!sighash) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'trace has no sighash')\n }\n const fragment = contractInterface.getFunction(sighash)\n\n if (!trace || !fragment) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'trace is null')\n }\n const typedTrace = trace as TypedCallTrace\n typedTrace.name = fragment.name\n typedTrace.functionSignature = fragment.format()\n // const trace = data.trace as Trace\n if (!trace?.action.input) {\n return ProcessResult.fromPartial({})\n }\n const traceData = '0x' + trace.action.input.slice(10)\n try {\n typedTrace.args = contractInterface.getAbiCoder().decode(fragment.inputs, traceData, true)\n } catch (e) {\n if (!trace.error) {\n throw e\n }\n console.error('Failed to decode successful trace', e)\n }\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n data.timestamp,\n block,\n undefined,\n trace,\n transaction,\n transactionReceipt\n )\n await handler(typedTrace, ctx)\n return ctx.getProcessResult()\n },\n })\n return this\n }\n\n public onAllTraces(\n handler: (event: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n fetchConfig?: Partial<EthFetchConfig>\n ): this {\n const tmpContract = this.CreateBoundContractView()\n const sighashes = []\n\n for (const fragment of tmpContract.rawContract.interface.fragments) {\n if (fragment.type === 'function') {\n const signature = fragment.format()\n const test = new TextEncoder().encode(signature)\n const sighash = '0x' + sha3.keccak_256(test).substring(0, 8)\n sighashes.push(sighash)\n }\n }\n return this.onTrace(\n sighashes,\n function (trace, ctx) {\n return handler(trace, ctx)\n },\n fetchConfig\n )\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/eth/base-processor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAqB,eAAe,EAAgB,aAAa,EAAE,MAAM,cAAc,CAAA;AAC9F,OAAO,EAML,cAAc,EAEd,aAAa,GACd,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,WAAW,EAA8B,aAAa,EAAa,MAAM,UAAU,CAAA;AAC5F,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,IAAI,MAAM,SAAS,CAAA;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAOlD,MAAM,OAAO,aAAa;IACxB,OAAO,CAA4B;IACnC,OAAO,CAAgD;IACvD,WAAW,CAAgB;CAC5B;AAED,MAAM,OAAO,YAAY;IACvB,UAAU,CAAU;IACpB,OAAO,CAAkD;IACzD,WAAW,CAAgB;CAC5B;AAED,MAAM,OAAO,YAAY;IACvB,aAAa,CAAiB;IAC9B,qBAAqB,CAAiB;IACtC,OAAO,CAAkD;CAC1D;AAED,MAAM,OAAO,kBAAkB;IAC7B,OAAO,CAAwD;IAC/D,WAAW,CAAgB;CAC5B;AAED,MAAM,mBAAmB;IACvB,OAAO,CAAQ;I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G,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;gBAC5D,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;aACxB;SACF;QACD,OAAO,IAAI,CAAC,OAAO,CACjB,SAAS,EACT,UAAU,KAAK,EAAE,GAAG;YAClB,OAAO,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAC5B,CAAC,EACD,WAAW,CACZ,CAAA;IACH,CAAC;CACF","sourcesContent":["import { BaseContract, DeferredTopicFilter, TransactionResponseParams } from 'ethers'\nimport { Network } from 'ethers/providers'\n\nimport { BoundContractView, ContractContext, ContractView, GlobalContext } from './context.js'\nimport {\n AddressType,\n Data_EthBlock,\n Data_EthLog,\n Data_EthTrace,\n Data_EthTransaction,\n EthFetchConfig,\n HandleInterval,\n ProcessResult,\n} from '@sentio/protos'\nimport { BindOptions } from './bind-options.js'\nimport { PromiseOrVoid } from '../core/promises.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { fixEmptyKey, TypedEvent, TypedCallTrace, formatEthData, RichBlock } from './eth.js'\nimport { getNetworkFromCtxOrNetworkish } from './provider.js'\nimport sha3 from 'js-sha3'\nimport { ListStateStorage } from '@sentio/runtime'\n\nexport interface AddressOrTypeEventFilter extends DeferredTopicFilter {\n addressType?: AddressType\n address?: string\n}\n\nexport class EventsHandler {\n filters: AddressOrTypeEventFilter[]\n handler: (event: Data_EthLog) => Promise<ProcessResult>\n fetchConfig: EthFetchConfig\n}\n\nexport class TraceHandler {\n signatures: string[]\n handler: (trace: Data_EthTrace) => Promise<ProcessResult>\n fetchConfig: EthFetchConfig\n}\n\nexport class BlockHandler {\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (block: Data_EthBlock) => Promise<ProcessResult>\n}\n\nexport class TransactionHandler {\n handler: (block: Data_EthTransaction) => Promise<ProcessResult>\n fetchConfig: EthFetchConfig\n}\n\nclass BindInternalOptions {\n address: string\n network: Network\n name: string\n startBlock: bigint\n endBlock?: bigint\n}\n\nexport class GlobalProcessorState extends ListStateStorage<GlobalProcessor> {\n static INSTANCE = new GlobalProcessorState()\n}\n\nexport class GlobalProcessor {\n config: BindInternalOptions\n blockHandlers: BlockHandler[] = []\n transactionHandler: TransactionHandler[] = []\n\n static bind(config: Omit<BindOptions, 'address'>): GlobalProcessor {\n const processor = new GlobalProcessor(config)\n GlobalProcessorState.INSTANCE.addValue(processor)\n return processor\n }\n\n constructor(config: Omit<BindOptions, 'address'>) {\n this.config = {\n address: '*',\n name: config.name || 'Global',\n network: getNetworkFromCtxOrNetworkish(config.network),\n startBlock: 0n,\n }\n if (config.startBlock) {\n this.config.startBlock = BigInt(config.startBlock)\n }\n if (config.endBlock) {\n this.config.endBlock = BigInt(config.endBlock)\n }\n }\n\n public onBlockInterval(\n handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,\n blockInterval = 250,\n backfillBlockInterval = 1000\n ): this {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240\n ): this {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },\n undefined\n )\n }\n\n public getChainId(): number {\n return Number(this.config.network.chainId)\n }\n\n public onInterval(\n handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined\n ): this {\n const chainId = this.getChainId()\n\n this.blockHandlers.push({\n handler: async function (data: Data_EthBlock) {\n const { block } = formatEthData(data)\n\n if (!block) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty')\n }\n\n const ctx = new GlobalContext(chainId, new Date(block.timestamp * 1000), block, undefined, undefined)\n await handler(block, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n blockInterval: blockInterval,\n })\n return this\n }\n\n public onTransaction(\n handler: (transaction: TransactionResponseParams, ctx: GlobalContext) => PromiseOrVoid,\n fetchConfig?: Partial<EthFetchConfig>\n ): this {\n const chainId = this.getChainId()\n this.transactionHandler.push({\n handler: async function (data: Data_EthTransaction) {\n const { trace, block, transaction, transactionReceipt } = formatEthData(data)\n\n if (!transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'transaction is empty')\n }\n const ctx = new GlobalContext(chainId, data.timestamp, block, undefined, trace, transaction, transactionReceipt)\n await handler(transaction, ctx)\n return ctx.getProcessResult()\n },\n fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),\n })\n return this\n }\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: BlockHandler[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: getNetworkFromCtxOrNetworkish(config.network),\n startBlock: 0n,\n }\n if (config.startBlock) {\n this.config.startBlock = BigInt(config.startBlock)\n }\n if (config.endBlock) {\n this.config.endBlock = BigInt(config.endBlock)\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return Number(this.config.network.chainId)\n }\n\n public onEvent(\n handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: DeferredTopicFilter | DeferredTopicFilter[],\n fetchConfig?: Partial<EthFetchConfig>\n ): this {\n const chainId = this.getChainId()\n let _filters: DeferredTopicFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractName = this.config.name\n const processor = this\n this.eventHandlers.push({\n filters: _filters,\n fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),\n handler: async function (data: Data_EthLog) {\n const { log, block, transaction, transactionReceipt } = formatEthData(data)\n if (!log) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty')\n }\n const contractView = processor.CreateBoundContractView()\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n data.timestamp,\n block,\n log,\n undefined,\n transaction,\n transactionReceipt\n )\n const logParam = log as any as { topics: Array<string>; data: string }\n\n const parsed = contractView.rawContract.interface.parseLog(logParam)\n\n if (parsed) {\n const event: TypedEvent = { ...log, name: parsed.name, args: fixEmptyKey(parsed) }\n await handler(event, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n return this\n }\n\n public onBlockInterval(\n handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 250,\n backfillBlockInterval = 1000\n ): this {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240\n ): this {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },\n undefined\n )\n }\n\n public onInterval(\n handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined\n ): this {\n const chainId = this.getChainId()\n const processor = this\n const contractName = this.config.name\n\n this.blockHandlers.push({\n handler: async function (data: Data_EthBlock) {\n const { block } = formatEthData(data)\n\n if (!block) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty')\n }\n\n const contractView = processor.CreateBoundContractView()\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n new Date(block.timestamp * 1000),\n block,\n undefined,\n undefined\n )\n await handler(block, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n blockInterval: blockInterval,\n })\n return this\n }\n\n public onAllEvents(\n handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n fetchConfig?: Partial<EthFetchConfig>\n ): this {\n const _filters: DeferredTopicFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const fragment of tmpContract.rawContract.interface.fragments) {\n if (fragment.type === 'event') {\n const filter = tmpContract.rawContract.filters[fragment.format()]\n _filters.push(filter())\n }\n }\n return this.onEvent(\n function (log, ctx) {\n return handler(log, ctx)\n },\n _filters,\n fetchConfig\n )\n }\n\n public onTrace(\n signatures: string | string[],\n handler: (trace: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n fetchConfig?: Partial<EthFetchConfig>\n ): this {\n const chainId = this.getChainId()\n const contractName = this.config.name\n const processor = this\n if (typeof signatures === 'string') {\n signatures = [signatures]\n }\n\n this.traceHandlers.push({\n signatures,\n fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),\n handler: async function (data: Data_EthTrace) {\n const contractView = processor.CreateBoundContractView()\n const contractInterface = contractView.rawContract.interface\n const { trace, block, transaction, transactionReceipt } = formatEthData(data)\n const sighash = trace?.action.input?.slice(0, 10)\n if (!sighash) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'trace has no sighash')\n }\n const fragment = contractInterface.getFunction(sighash)\n\n if (!trace || !fragment) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'trace is null')\n }\n const typedTrace = trace as TypedCallTrace\n typedTrace.name = fragment.name\n typedTrace.functionSignature = fragment.format()\n // const trace = data.trace as Trace\n if (!trace?.action.input) {\n return ProcessResult.fromPartial({})\n }\n const traceData = '0x' + trace.action.input.slice(10)\n try {\n typedTrace.args = contractInterface.getAbiCoder().decode(fragment.inputs, traceData, true)\n } catch (e) {\n if (!trace.error) {\n throw e\n }\n console.error('Failed to decode successful trace', e)\n }\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n data.timestamp,\n block,\n undefined,\n trace,\n transaction,\n transactionReceipt\n )\n await handler(typedTrace, ctx)\n return ctx.getProcessResult()\n },\n })\n return this\n }\n\n public onAllTraces(\n handler: (event: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n fetchConfig?: Partial<EthFetchConfig>\n ): this {\n const tmpContract = this.CreateBoundContractView()\n const sighashes = []\n\n for (const fragment of tmpContract.rawContract.interface.fragments) {\n if (fragment.type === 'function') {\n const signature = fragment.format()\n const test = new TextEncoder().encode(signature)\n const sighash = '0x' + sha3.keccak_256(test).substring(0, 8)\n sighashes.push(sighash)\n }\n }\n return this.onTrace(\n sighashes,\n function (trace, ctx) {\n return handler(trace, ctx)\n },\n fetchConfig\n )\n }\n}\n"]}
|