@sentio/sdk 2.13.0-rc.2 → 2.13.0-rc.4
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 +11 -0
- package/lib/aptos/aptos-chain-adapter.js +56 -0
- package/lib/aptos/aptos-chain-adapter.js.map +1 -0
- package/lib/aptos/aptos-processor.d.ts +1 -2
- package/lib/aptos/aptos-processor.js +6 -14
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/builtin/0x1.js +2 -1
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.js +2 -1
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/codegen/codegen.js +4 -45
- package/lib/aptos/codegen/codegen.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.js +1 -2
- package/lib/aptos/ext/aptos-dex.js.map +1 -1
- package/lib/aptos/move-coder.d.ts +4 -5
- package/lib/aptos/move-coder.js +14 -8
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/move/abstract-codegen.d.ts +4 -4
- package/lib/move/abstract-codegen.js +22 -10
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +5 -2
- package/lib/move/abstract-move-coder.js +7 -1
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/chain-adapter.d.ts +9 -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/sui/builtin/0x1.js +2 -1
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.js +2 -1
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/builtin/0x3.js +2 -1
- package/lib/sui/builtin/0x3.js.map +1 -1
- package/lib/sui/codegen/codegen.js +4 -34
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/context.d.ts +2 -0
- package/lib/sui/context.js +3 -0
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/move-coder.d.ts +5 -5
- package/lib/sui/move-coder.js +14 -8
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/sui-chain-adapter.d.ts +11 -0
- package/lib/sui/sui-chain-adapter.js +43 -0
- package/lib/sui/sui-chain-adapter.js.map +1 -0
- package/lib/sui/sui-processor.d.ts +2 -0
- package/lib/sui/sui-processor.js +4 -2
- 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/package.json +4 -4
- package/src/aptos/aptos-chain-adapter.ts +65 -0
- package/src/aptos/aptos-processor.ts +17 -15
- package/src/aptos/builtin/0x1.ts +2 -1
- package/src/aptos/builtin/0x3.ts +2 -1
- package/src/aptos/codegen/codegen.ts +5 -54
- package/src/aptos/context.ts +5 -0
- package/src/aptos/ext/aptos-dex.ts +2 -11
- package/src/aptos/move-coder.ts +17 -12
- package/src/move/abstract-codegen.ts +28 -17
- package/src/move/abstract-move-coder.ts +10 -3
- package/src/move/chain-adapter.ts +14 -0
- package/src/move/index.ts +1 -0
- package/src/sui/builtin/0x1.ts +2 -1
- package/src/sui/builtin/0x2.ts +2 -1
- package/src/sui/builtin/0x3.ts +2 -1
- package/src/sui/codegen/codegen.ts +5 -40
- package/src/sui/context.ts +3 -0
- package/src/sui/move-coder.ts +18 -11
- package/src/sui/sui-chain-adapter.ts +50 -0
- package/src/sui/sui-processor.ts +5 -3
- package/src/sui/utils.ts +0 -8
- 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,12 +1,9 @@
|
|
1
1
|
import * as fs from 'fs';
|
2
|
-
import { toInternalModule } from '../move-types.js';
|
3
|
-
import { moduleQname, SPLITTER } from '../../move/index.js';
|
4
2
|
import chalk from 'chalk';
|
5
3
|
import { AptosNetwork } from '../network.js';
|
6
|
-
import {
|
7
|
-
import {
|
4
|
+
import { join } from 'path';
|
5
|
+
import { AptosChainAdapter } from '../aptos-chain-adapter.js';
|
8
6
|
import { AbstractCodegen } from '../../move/abstract-codegen.js';
|
9
|
-
import { join } from "path";
|
10
7
|
export async function codegen(abisDir, outDir = join('src', 'types', 'aptos'), genExample = false) {
|
11
8
|
if (!fs.existsSync(abisDir)) {
|
12
9
|
return;
|
@@ -15,51 +12,13 @@ export async function codegen(abisDir, outDir = join('src', 'types', 'aptos'), g
|
|
15
12
|
const numFiles = await gen.generate(abisDir, outDir);
|
16
13
|
console.log(chalk.green(`Generated ${numFiles} for Aptos`));
|
17
14
|
}
|
18
|
-
function getRpcEndpoint(network) {
|
19
|
-
switch (network) {
|
20
|
-
case AptosNetwork.TEST_NET:
|
21
|
-
return 'https://testnet.aptoslabs.com/';
|
22
|
-
}
|
23
|
-
return 'https://mainnet.aptoslabs.com/';
|
24
|
-
}
|
25
|
-
function getRpcClient(network) {
|
26
|
-
return new AptosClient(getRpcEndpoint(network));
|
27
|
-
}
|
28
15
|
class AptosCodegen extends AbstractCodegen {
|
29
16
|
ADDRESS_TYPE = 'Address';
|
30
17
|
MAIN_NET = AptosNetwork.MAIN_NET;
|
31
18
|
TEST_NET = AptosNetwork.TEST_NET;
|
32
19
|
PREFIX = 'Aptos';
|
33
|
-
|
34
|
-
|
35
|
-
return await client.getAccountModules(account);
|
36
|
-
}
|
37
|
-
toInternalModules(modules) {
|
38
|
-
return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []));
|
39
|
-
}
|
40
|
-
getMeaningfulFunctionParams(params) {
|
41
|
-
return getMeaningfulFunctionParams(params);
|
42
|
-
}
|
43
|
-
getEventStructs(module) {
|
44
|
-
const qname = moduleQname(module);
|
45
|
-
const structMap = new Map();
|
46
|
-
const eventMap = new Map();
|
47
|
-
for (const struct of module.structs) {
|
48
|
-
structMap.set(qname + SPLITTER + struct.name, struct);
|
49
|
-
}
|
50
|
-
for (const struct of module.structs) {
|
51
|
-
for (const field of struct.fields) {
|
52
|
-
const t = field.type;
|
53
|
-
if (t.qname === '0x1::event::EventHandle') {
|
54
|
-
const event = t.typeArgs[0].qname;
|
55
|
-
const eventStruct = structMap.get(event);
|
56
|
-
if (eventStruct) {
|
57
|
-
eventMap.set(event, eventStruct);
|
58
|
-
}
|
59
|
-
}
|
60
|
-
}
|
61
|
-
}
|
62
|
-
return eventMap;
|
20
|
+
constructor() {
|
21
|
+
super(AptosChainAdapter.INSTANCE);
|
63
22
|
}
|
64
23
|
}
|
65
24
|
//# sourceMappingURL=codegen.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/aptos/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;
|
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;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAEhE,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAe,EAAE,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,KAAK;IACvG,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC3B,OAAM;KACP;IACD,MAAM,GAAG,GAAG,IAAI,YAAY,EAAE,CAAA;IAC9B,MAAM,QAAQ,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,eAAmD;IAC5E,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 { MoveModuleBytecode } 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<MoveModuleBytecode[], AptosNetwork> {\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"]}
|
package/lib/aptos/context.d.ts
CHANGED
@@ -2,6 +2,7 @@ import { RecordMetaData } from '@sentio/protos';
|
|
2
2
|
import { type Labels, BaseContext } from '@sentio/sdk';
|
3
3
|
import { Transaction_UserTransaction } from './move-types.js';
|
4
4
|
import { AptosNetwork } from './network.js';
|
5
|
+
import { MoveCoder } from './move-coder.js';
|
5
6
|
export declare class AptosContext extends BaseContext {
|
6
7
|
address: string;
|
7
8
|
network: AptosNetwork;
|
@@ -9,6 +10,7 @@ export declare class AptosContext extends BaseContext {
|
|
9
10
|
version: bigint;
|
10
11
|
transaction: Transaction_UserTransaction;
|
11
12
|
eventIndex: number;
|
13
|
+
coder: MoveCoder;
|
12
14
|
constructor(moduleName: string, network: AptosNetwork, address: string, version: bigint, transaction: Transaction_UserTransaction, eventIndex: number);
|
13
15
|
getChainId(): string;
|
14
16
|
getMetaData(name: string, labels: Labels): RecordMetaData;
|
@@ -18,6 +20,7 @@ export declare class AptosResourcesContext extends BaseContext {
|
|
18
20
|
network: AptosNetwork;
|
19
21
|
version: bigint;
|
20
22
|
timestampInMicros: number;
|
23
|
+
coder: MoveCoder;
|
21
24
|
constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number);
|
22
25
|
getChainId(): string;
|
23
26
|
getMetaData(name: string, labels: Labels): RecordMetaData;
|
package/lib/aptos/context.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { BaseContext, normalizeLabels } from '@sentio/sdk';
|
2
2
|
import { getChainId } from './network.js';
|
3
|
+
import { defaultMoveCoder } from './move-coder.js';
|
3
4
|
export class AptosContext extends BaseContext {
|
4
5
|
address;
|
5
6
|
network;
|
@@ -7,6 +8,7 @@ export class AptosContext extends BaseContext {
|
|
7
8
|
version;
|
8
9
|
transaction;
|
9
10
|
eventIndex;
|
11
|
+
coder;
|
10
12
|
constructor(moduleName, network, address, version, transaction, eventIndex) {
|
11
13
|
super();
|
12
14
|
this.address = address.toLowerCase();
|
@@ -14,6 +16,7 @@ export class AptosContext extends BaseContext {
|
|
14
16
|
this.moduleName = moduleName;
|
15
17
|
this.version = version;
|
16
18
|
this.eventIndex = eventIndex;
|
19
|
+
this.coder = defaultMoveCoder(network);
|
17
20
|
if (transaction) {
|
18
21
|
this.transaction = transaction;
|
19
22
|
}
|
@@ -40,12 +43,14 @@ export class AptosResourcesContext extends BaseContext {
|
|
40
43
|
network;
|
41
44
|
version;
|
42
45
|
timestampInMicros;
|
46
|
+
coder;
|
43
47
|
constructor(network, address, version, timestampInMicros) {
|
44
48
|
super();
|
45
49
|
this.address = address;
|
46
50
|
this.network = network;
|
47
51
|
this.version = version;
|
48
52
|
this.timestampInMicros = timestampInMicros;
|
53
|
+
this.coder = defaultMoveCoder(network);
|
49
54
|
}
|
50
55
|
getChainId() {
|
51
56
|
return getChainId(this.network);
|
package/lib/aptos/context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEvE,OAAO,EAAgB,UAAU,EAAE,MAAM,cAAc,CAAA;
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEvE,OAAO,EAAgB,UAAU,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAA;AAE7D,MAAM,OAAO,YAAa,SAAQ,WAAW;IAC3C,OAAO,CAAQ;IACf,OAAO,CAAc;IACrB,UAAU,CAAQ;IAClB,OAAO,CAAQ;IACf,WAAW,CAA6B;IACxC,UAAU,CAAQ;IAClB,KAAK,CAAW;IAEhB,YACE,UAAkB,EAClB,OAAqB,EACrB,OAAe,EACf,OAAe,EACf,WAAwC,EACxC,UAAkB;QAElB,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,O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IAED,WAAW,CAAC,IAAY,EAAE,MAAc;QACtC,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,WAAW;YACzB,WAAW,EAAE,IAAI,CAAC,OAAO;YACzB,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YAC1B,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF","sourcesContent":["import { RecordMetaData } from '@sentio/protos'\nimport { type Labels, BaseContext, normalizeLabels } from '@sentio/sdk'\nimport { Transaction_UserTransaction } from './move-types.js'\nimport { AptosNetwork, getChainId } from './network.js'\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\n\nexport class AptosContext extends BaseContext {\n address: string\n network: AptosNetwork\n moduleName: string\n version: bigint\n transaction: Transaction_UserTransaction\n eventIndex: number\n coder: MoveCoder\n\n constructor(\n moduleName: string,\n network: AptosNetwork,\n address: string,\n version: bigint,\n transaction: Transaction_UserTransaction,\n eventIndex: number\n ) {\n super()\n this.address = address.toLowerCase()\n this.network = network\n this.moduleName = moduleName\n this.version = version\n this.eventIndex = eventIndex\n this.coder = defaultMoveCoder(network)\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getChainId(): string {\n return getChainId(this.network)\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.version,\n transactionIndex: 0,\n transactionHash: this.transaction?.hash || '', // TODO\n logIndex: this.eventIndex,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class AptosResourcesContext extends BaseContext {\n address: string\n network: AptosNetwork\n version: bigint\n timestampInMicros: number\n coder: MoveCoder\n\n constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number) {\n super()\n this.address = address\n this.network = network\n this.version = version\n this.timestampInMicros = timestampInMicros\n this.coder = defaultMoveCoder(network)\n }\n\n getChainId(): string {\n return getChainId(this.network)\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: 'resources',\n blockNumber: this.version,\n transactionIndex: 0,\n transactionHash: '',\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { BigDecimal } from '@sentio/bigdecimal';
|
2
2
|
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js';
|
3
|
-
import { defaultMoveCoder, } from '@sentio/sdk/aptos';
|
4
3
|
export class AptosDex {
|
5
4
|
poolAdaptor;
|
6
5
|
volume;
|
@@ -67,7 +66,7 @@ export class AptosDex {
|
|
67
66
|
return result;
|
68
67
|
}
|
69
68
|
async syncPools(resources, ctx, poolsHandler) {
|
70
|
-
const pools =
|
69
|
+
const pools = ctx.coder.filterAndDecodeResources(this.poolAdaptor.poolTypeName, resources);
|
71
70
|
const volumeByCoin = new Map();
|
72
71
|
const timestamp = ctx.timestampInMicros;
|
73
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;AACzF,OAAO,EAIL,gBAAgB,GAEjB,MAAM,mBAAmB,CAAA;AAS1B,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,MA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AK,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 {\n AptosResourcesContext,\n TypedMoveResource,\n MoveResource,\n defaultMoveCoder,\n AptosContext,\n} 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>[] = defaultMoveCoder().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"]}
|
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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KAAK,CAAC,CAAA;IACrC,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;IACrC,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAA;IAC3C,IAAI,MAAM,GAAG,UAAU,CAAC,GAAG,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,15 +1,14 @@
|
|
1
1
|
import { Event, MoveModuleBytecode, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js';
|
2
2
|
import { TypedEventInstance, TypedMoveResource } from './models.js';
|
3
3
|
import { AbstractMoveCoder } from '../move/abstract-move-coder.js';
|
4
|
-
import {
|
5
|
-
export declare class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
|
4
|
+
import { AptosNetwork } from './network.js';
|
5
|
+
export declare class MoveCoder extends AbstractMoveCoder<AptosNetwork, MoveModuleBytecode[], Event | MoveResource> {
|
6
|
+
constructor(network: AptosNetwork);
|
6
7
|
load(module: MoveModuleBytecode): void;
|
7
8
|
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined;
|
8
9
|
filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[];
|
9
10
|
decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined;
|
10
11
|
filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[];
|
11
|
-
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[];
|
12
12
|
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload;
|
13
13
|
}
|
14
|
-
export declare
|
15
|
-
export declare function defaultMoveCoder(): MoveCoder;
|
14
|
+
export declare function defaultMoveCoder(network?: AptosNetwork): MoveCoder;
|
package/lib/aptos/move-coder.js
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
import { toInternalModule, } from './move-types.js';
|
2
|
-
import { getMeaningfulFunctionParams } from './utils.js';
|
3
2
|
import { AbstractMoveCoder } from '../move/abstract-move-coder.js';
|
3
|
+
import { AptosNetwork } from './network.js';
|
4
|
+
import { AptosChainAdapter } from './aptos-chain-adapter.js';
|
4
5
|
export class MoveCoder extends AbstractMoveCoder {
|
6
|
+
constructor(network) {
|
7
|
+
super(network);
|
8
|
+
this.adapter = new AptosChainAdapter();
|
9
|
+
}
|
5
10
|
load(module) {
|
6
11
|
if (!module.abi) {
|
7
12
|
throw Error('Module without abi');
|
@@ -23,12 +28,9 @@ export class MoveCoder extends AbstractMoveCoder {
|
|
23
28
|
filterAndDecodeResources(typeQname, resources) {
|
24
29
|
return this.filterAndDecodeStruct(typeQname, resources);
|
25
30
|
}
|
26
|
-
getMeaningfulFunctionParams(params) {
|
27
|
-
return getMeaningfulFunctionParams(params);
|
28
|
-
}
|
29
31
|
decodeFunctionPayload(payload) {
|
30
32
|
const func = this.getMoveFunction(payload.function);
|
31
|
-
const params = getMeaningfulFunctionParams(func.params);
|
33
|
+
const params = this.adapter.getMeaningfulFunctionParams(func.params);
|
32
34
|
const argumentsDecoded = this.decodeArray(payload.arguments, params);
|
33
35
|
return {
|
34
36
|
...payload,
|
@@ -36,8 +38,12 @@ export class MoveCoder extends AbstractMoveCoder {
|
|
36
38
|
};
|
37
39
|
}
|
38
40
|
}
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
const MOVE_CODER = new MoveCoder(AptosNetwork.MAIN_NET);
|
42
|
+
const TESTNET_MOVE_CODER = new MoveCoder(AptosNetwork.TEST_NET);
|
43
|
+
export function defaultMoveCoder(network = AptosNetwork.MAIN_NET) {
|
44
|
+
if (network == AptosNetwork.MAIN_NET) {
|
45
|
+
return MOVE_CODER;
|
46
|
+
}
|
47
|
+
return TESTNET_MOVE_CODER;
|
42
48
|
}
|
43
49
|
//# sourceMappingURL=move-coder.js.map
|
@@ -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,
|
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,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G,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAEpE,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 if (this.contains(module.abi.address, module.abi.name)) {\n return\n }\n this.loadInternal(toInternalModule(module))\n }\n\n decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {\n return this.decodedStruct<T>(event) as TypedEventInstance<T>\n }\n filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {\n return this.filterAndDecodeStruct(typeQname, resources) as TypedEventInstance<T>[]\n }\n decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {\n return this.decodedStruct<T>(res)\n }\n filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {\n return this.filterAndDecodeStruct(typeQname, resources) as any\n }\n\n decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {\n const func = this.getMoveFunction(payload.function)\n const params = this.adapter.getMeaningfulFunctionParams(func.params)\n const argumentsDecoded = 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,6 +1,7 @@
|
|
1
1
|
import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js';
|
2
2
|
import { AccountRegister } from './account.js';
|
3
3
|
import { TypeDescriptor } from './types.js';
|
4
|
+
import { ChainAdapter } from './chain-adapter.js';
|
4
5
|
interface OutputFile {
|
5
6
|
fileName: string;
|
6
7
|
fileContent: string;
|
@@ -19,10 +20,9 @@ export declare abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
19
20
|
GENERATE_CLIENT: boolean;
|
20
21
|
GENERATE_ON_ENTRY: boolean;
|
21
22
|
PAYLOAD_OPTIONAL: boolean;
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[];
|
23
|
+
SYSTEM_MODULES: Set<string>;
|
24
|
+
chainAdapter: ChainAdapter<NetworkType, ModuleTypes>;
|
25
|
+
protected constructor(chainAdapter: ChainAdapter<NetworkType, ModuleTypes>);
|
26
26
|
readModulesFile(fullPath: string): any;
|
27
27
|
generate(srcDir: string, outputDir: string): Promise<number>;
|
28
28
|
generateForNetwork(srcDir: string, outputDir: string, network: NetworkType): Promise<number>;
|
@@ -15,6 +15,11 @@ export class AbstractCodegen {
|
|
15
15
|
GENERATE_CLIENT = false;
|
16
16
|
GENERATE_ON_ENTRY = true;
|
17
17
|
PAYLOAD_OPTIONAL = false;
|
18
|
+
SYSTEM_MODULES = new Set(['0x1', '0x2', '0x3']);
|
19
|
+
chainAdapter;
|
20
|
+
constructor(chainAdapter) {
|
21
|
+
this.chainAdapter = chainAdapter;
|
22
|
+
}
|
18
23
|
readModulesFile(fullPath) {
|
19
24
|
return JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
|
20
25
|
}
|
@@ -33,9 +38,9 @@ export class AbstractCodegen {
|
|
33
38
|
fs.mkdirSync(outputDir, { recursive: true });
|
34
39
|
const loader = new AccountRegister();
|
35
40
|
// when generating user code, don't need to generate framework account
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
for (const sysModule of this.SYSTEM_MODULES) {
|
42
|
+
loader.accountImports.set(sysModule, new AccountModulesImportInfo(sysModule, sysModule));
|
43
|
+
}
|
39
44
|
// const client = getRpcClient(network)
|
40
45
|
for (const file of files) {
|
41
46
|
if (!file.endsWith('.json')) {
|
@@ -43,7 +48,7 @@ export class AbstractCodegen {
|
|
43
48
|
}
|
44
49
|
const fullPath = path.resolve(srcDir, file);
|
45
50
|
const abi = this.readModulesFile(fullPath);
|
46
|
-
const modules = this.toInternalModules(abi);
|
51
|
+
const modules = this.chainAdapter.toInternalModules(abi);
|
47
52
|
for (const module of modules) {
|
48
53
|
loader.register(module, path.basename(file, '.json'));
|
49
54
|
}
|
@@ -58,8 +63,8 @@ export class AbstractCodegen {
|
|
58
63
|
for (const account of loader.pendingAccounts) {
|
59
64
|
console.log(`download dependent module for account ${account} at ${network}`);
|
60
65
|
try {
|
61
|
-
const rawModules = await this.fetchModules(account, network);
|
62
|
-
const modules = this.toInternalModules(rawModules);
|
66
|
+
const rawModules = await this.chainAdapter.fetchModules(account, network);
|
67
|
+
const modules = this.chainAdapter.toInternalModules(rawModules);
|
63
68
|
fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(rawModules, null, '\t'));
|
64
69
|
for (const module of modules) {
|
65
70
|
loader.register(module, account);
|
@@ -109,7 +114,7 @@ export class AbstractCodegen {
|
|
109
114
|
const clientFunctions = this.GENERATE_CLIENT
|
110
115
|
? module.exposedFunctions.map((f) => this.generateClientFunctions(module, f)).filter((s) => s !== '')
|
111
116
|
: [];
|
112
|
-
const eventStructs = this.getEventStructs(module);
|
117
|
+
const eventStructs = this.chainAdapter.getEventStructs(module);
|
113
118
|
const eventTypes = new Set(eventStructs.keys());
|
114
119
|
const events = Array.from(eventStructs.values())
|
115
120
|
.map((e) => this.generateOnEvents(module, e))
|
@@ -214,7 +219,7 @@ export class AbstractCodegen {
|
|
214
219
|
if (!func.isEntry) {
|
215
220
|
return;
|
216
221
|
}
|
217
|
-
const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {
|
222
|
+
const fields = this.chainAdapter.getMeaningfulFunctionParams(func.params).map((param) => {
|
218
223
|
return this.generateTypeForDescriptor(param, module.address) + (this.PAYLOAD_OPTIONAL ? ' | undefined' : '');
|
219
224
|
});
|
220
225
|
const camelFuncName = upperFirst(camelCase(func.name));
|
@@ -236,7 +241,7 @@ export class AbstractCodegen {
|
|
236
241
|
}
|
237
242
|
// const moduleName = normalizeToJSName(module.name)
|
238
243
|
const funcName = camelCase(func.name);
|
239
|
-
const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {
|
244
|
+
const fields = this.chainAdapter.getMeaningfulFunctionParams(func.params).map((param) => {
|
240
245
|
return this.generateTypeForDescriptor(param, module.address);
|
241
246
|
});
|
242
247
|
const genericString = this.generateFunctionTypeParameters(func);
|
@@ -407,6 +412,13 @@ export class AccountCodegen {
|
|
407
412
|
dependedAccounts.push(account);
|
408
413
|
}
|
409
414
|
}
|
415
|
+
let loadAllTypes = `loadAllTypes(defaultMoveCoder(${this.moduleGen.PREFIX}Network.${this.moduleGen.generateNetworkOption(this.config.network)}))`;
|
416
|
+
if (this.moduleGen.SYSTEM_MODULES.has(address)) {
|
417
|
+
loadAllTypes = `
|
418
|
+
loadAllTypes(defaultMoveCoder(${this.moduleGen.PREFIX}Network.MAIN_NET))
|
419
|
+
loadAllTypes(defaultMoveCoder(${this.moduleGen.PREFIX}Network.TEST_NET))
|
420
|
+
`;
|
421
|
+
}
|
410
422
|
const source = `
|
411
423
|
/* Autogenerated file. Do not edit manually. */
|
412
424
|
/* tslint:disable */
|
@@ -429,7 +441,7 @@ export class AccountCodegen {
|
|
429
441
|
}
|
430
442
|
}
|
431
443
|
|
432
|
-
loadAllTypes
|
444
|
+
${loadAllTypes}
|
433
445
|
`; // source
|
434
446
|
return [
|
435
447
|
{
|