@sentio/sdk 2.13.0-rc.1 → 2.13.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/aptos-chain-adapter.d.ts +14 -0
- package/lib/aptos/aptos-chain-adapter.js +69 -0
- package/lib/aptos/aptos-chain-adapter.js.map +1 -0
- package/lib/aptos/aptos-plugin.js +5 -2
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +7 -7
- package/lib/aptos/aptos-processor.js +15 -22
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/builtin/0x1.d.ts +1138 -493
- package/lib/aptos/builtin/0x1.js +1939 -1458
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +227 -104
- package/lib/aptos/builtin/0x3.js +373 -333
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/codegen/codegen.d.ts +1 -1
- package/lib/aptos/codegen/codegen.js +6 -47
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/codegen/run.js +1 -1
- package/lib/aptos/codegen/run.js.map +1 -1
- package/lib/aptos/context.d.ts +3 -0
- package/lib/aptos/context.js +5 -0
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/ext/aptos-dex.d.ts +2 -1
- package/lib/aptos/ext/aptos-dex.js +1 -2
- package/lib/aptos/ext/aptos-dex.js.map +1 -1
- package/lib/aptos/index.d.ts +2 -0
- package/lib/aptos/index.js +2 -0
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +3 -11
- package/lib/aptos/models.js.map +1 -1
- package/lib/aptos/module-client.js +1 -1
- package/lib/aptos/module-client.js.map +1 -1
- package/lib/aptos/move-coder.d.ts +10 -10
- package/lib/aptos/move-coder.js +37 -18
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/aptos/utils.d.ts +2 -2
- package/lib/aptos/utils.js +10 -7
- package/lib/aptos/utils.js.map +1 -1
- package/lib/eth/base-processor-template.d.ts +4 -3
- package/lib/eth/base-processor-template.js +7 -7
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/base-processor.d.ts +9 -8
- package/lib/eth/base-processor.js +13 -11
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/eth-plugin.js +8 -5
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/eth/eth.d.ts +9 -2
- package/lib/eth/eth.js +23 -1
- package/lib/eth/eth.js.map +1 -1
- package/lib/move/abstract-codegen.d.ts +11 -11
- package/lib/move/abstract-codegen.js +59 -22
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +19 -25
- package/lib/move/abstract-move-coder.js +74 -51
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/chain-adapter.d.ts +11 -0
- package/lib/move/chain-adapter.js +3 -0
- package/lib/move/chain-adapter.js.map +1 -0
- package/lib/move/index.d.ts +1 -0
- package/lib/move/index.js +1 -0
- package/lib/move/index.js.map +1 -1
- package/lib/move/types.d.ts +31 -1
- package/lib/move/types.js +75 -16
- package/lib/move/types.js.map +1 -1
- package/lib/move/utils.js +6 -1
- package/lib/move/utils.js.map +1 -1
- package/lib/sui/builtin/0x1.d.ts +37 -18
- package/lib/sui/builtin/0x1.js +58 -32
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +275 -125
- package/lib/sui/builtin/0x2.js +463 -322
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/builtin/0x3.d.ts +135 -60
- package/lib/sui/builtin/0x3.js +229 -272
- package/lib/sui/builtin/0x3.js.map +1 -1
- package/lib/sui/codegen/codegen.d.ts +1 -1
- package/lib/sui/codegen/codegen.js +10 -36
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/codegen/run.js +1 -1
- package/lib/sui/codegen/run.js.map +1 -1
- package/lib/sui/context.d.ts +5 -1
- package/lib/sui/context.js +8 -1
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/index.d.ts +1 -0
- package/lib/sui/index.js +1 -0
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/models.d.ts +3 -11
- package/lib/sui/models.js.map +1 -1
- package/lib/sui/move-coder.d.ts +15 -15
- package/lib/sui/move-coder.js +43 -39
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/sui-chain-adapter.d.ts +14 -0
- package/lib/sui/sui-chain-adapter.js +69 -0
- package/lib/sui/sui-chain-adapter.js.map +1 -0
- package/lib/sui/sui-plugin.js +4 -2
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +6 -3
- package/lib/sui/sui-processor.js +23 -14
- package/lib/sui/sui-processor.js.map +1 -1
- package/lib/sui/utils.d.ts +3 -3
- package/lib/sui/utils.js +20 -5
- package/lib/sui/utils.js.map +1 -1
- package/lib/testing/sui-facet.d.ts +2 -2
- package/lib/testing/sui-facet.js +16 -26
- package/lib/testing/sui-facet.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/aptos-chain-adapter.ts +81 -0
- package/src/aptos/aptos-plugin.ts +5 -2
- package/src/aptos/aptos-processor.ts +35 -31
- package/src/aptos/builtin/0x1.ts +2742 -500
- package/src/aptos/builtin/0x3.ts +529 -106
- package/src/aptos/codegen/codegen.ts +13 -57
- package/src/aptos/codegen/run.ts +1 -1
- package/src/aptos/context.ts +5 -0
- package/src/aptos/ext/aptos-dex.ts +4 -12
- package/src/aptos/index.ts +4 -0
- package/src/aptos/models.ts +3 -13
- package/src/aptos/module-client.ts +1 -1
- package/src/aptos/move-coder.ts +48 -25
- package/src/aptos/utils.ts +11 -8
- package/src/eth/base-processor-template.ts +20 -10
- package/src/eth/base-processor.ts +45 -25
- package/src/eth/eth-plugin.ts +9 -6
- package/src/eth/eth.ts +31 -2
- package/src/move/abstract-codegen.ts +74 -37
- package/src/move/abstract-move-coder.ts +87 -75
- package/src/move/chain-adapter.ts +17 -0
- package/src/move/index.ts +1 -0
- package/src/move/types.ts +97 -17
- package/src/move/utils.ts +6 -1
- package/src/sui/builtin/0x1.ts +75 -20
- package/src/sui/builtin/0x2.ts +670 -126
- package/src/sui/builtin/0x3.ts +326 -61
- package/src/sui/codegen/codegen.ts +17 -43
- package/src/sui/codegen/run.ts +1 -1
- package/src/sui/context.ts +9 -1
- package/src/sui/index.ts +1 -0
- package/src/sui/models.ts +3 -13
- package/src/sui/move-coder.ts +58 -53
- package/src/sui/sui-chain-adapter.ts +86 -0
- package/src/sui/sui-plugin.ts +4 -2
- package/src/sui/sui-processor.ts +39 -26
- package/src/sui/utils.ts +25 -5
- package/src/testing/sui-facet.ts +15 -30
@@ -1 +1 @@
|
|
1
|
-
export declare function codegen(abisDir: string, outDir?: string, genExample?: boolean): Promise<void>;
|
1
|
+
export declare function codegen(abisDir: string, outDir?: string, genExample?: boolean, builtin?: boolean): Promise<void>;
|
@@ -1,65 +1,24 @@
|
|
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
|
-
|
10
|
-
export async function codegen(abisDir, outDir = join('src', 'types', 'aptos'), genExample = false) {
|
7
|
+
export async function codegen(abisDir, outDir = join('src', 'types', 'aptos'), genExample = false, builtin = false) {
|
11
8
|
if (!fs.existsSync(abisDir)) {
|
12
9
|
return;
|
13
10
|
}
|
14
11
|
const gen = new AptosCodegen();
|
15
|
-
const numFiles = await gen.generate(abisDir, outDir);
|
12
|
+
const numFiles = await gen.generate(abisDir, outDir, builtin);
|
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,CAC3B,OAAe,EACf,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EACtC,UAAU,GAAG,KAAK,EAClB,OAAO,GAAG,KAAK;IAEf,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,EAAE,OAAO,CAAC,CAAA;IAC7D,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(\n abisDir: string,\n outDir = join('src', 'types', 'aptos'),\n genExample = false,\n builtin = false\n) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n const gen = new AptosCodegen()\n const numFiles = await gen.generate(abisDir, outDir, builtin)\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"]}
|
package/lib/aptos/codegen/run.js
CHANGED
@@ -3,7 +3,7 @@ import { codegen } from './codegen.js';
|
|
3
3
|
if (process.argv.length > 3) {
|
4
4
|
const abisDir = process.argv[2];
|
5
5
|
const targetDir = process.argv[3];
|
6
|
-
await codegen(abisDir, targetDir);
|
6
|
+
await codegen(abisDir, targetDir, false, true);
|
7
7
|
}
|
8
8
|
else {
|
9
9
|
console.error('Not enough argument');
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/aptos/codegen/run.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;IAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAEjC,MAAM,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/aptos/codegen/run.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;IAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAEjC,MAAM,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;CAC/C;KAAM;IACL,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;CAChB","sourcesContent":["// #!/usr/bin/env node\n\nimport { codegen } from './codegen.js'\n\nif (process.argv.length > 3) {\n const abisDir = process.argv[2]\n const targetDir = process.argv[3]\n\n await codegen(abisDir, targetDir, false, true)\n} else {\n console.error('Not enough argument')\n process.exit(1)\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,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAA;QACtC,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;SAC/B;IACH,CAAC;IAED,UAAU;QACR,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,MAAc;QACt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AAM,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,11 +1,12 @@
|
|
1
1
|
import { Gauge } from '@sentio/sdk';
|
2
2
|
import { BigDecimal } from '@sentio/bigdecimal';
|
3
3
|
import { AptosResourcesContext, TypedMoveResource, MoveResource, AptosContext } from '@sentio/sdk/aptos';
|
4
|
+
import { TypeDescriptor } from '../../move/index.js';
|
4
5
|
export interface PoolAdaptor<T> {
|
5
6
|
getXReserve(pool: T): bigint;
|
6
7
|
getYReserve(pool: T): bigint;
|
7
8
|
getExtraPoolTags(pool: TypedMoveResource<T>): any;
|
8
|
-
|
9
|
+
poolType: TypeDescriptor<T>;
|
9
10
|
}
|
10
11
|
export declare class AptosDex<T> {
|
11
12
|
poolAdaptor: PoolAdaptor<T>;
|
@@ -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 = await ctx.coder.filterAndDecodeResources(this.poolAdaptor.poolType, 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;I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mB,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 {\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;AAWzF,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,CAA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AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,GAAiB,EACjB,KAAa,EACb,KAAa,EACb,WAAmB,EACnB,WAAmB;IAEnB,MAAM,UAAU,GAAG,WAAW,CAAC,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'\nimport { TypeDescriptor } from '../../move/index.js'\n\nexport interface PoolAdaptor<T> {\n getXReserve(pool: T): bigint\n getYReserve(pool: T): bigint\n getExtraPoolTags(pool: TypedMoveResource<T>): any\n poolType: TypeDescriptor<T>\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 = await ctx.coder.filterAndDecodeResources(this.poolAdaptor.poolType, 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"]}
|
package/lib/aptos/index.d.ts
CHANGED
@@ -7,3 +7,5 @@ export { AptosBindOptions, AptosNetwork } from './network.js';
|
|
7
7
|
export * from './api.js';
|
8
8
|
export { ModuleClient } from './module-client.js';
|
9
9
|
export { AptosPlugin } from './aptos-plugin.js';
|
10
|
+
export { BUILTIN_TYPES } from '../move/types.js';
|
11
|
+
export * from './utils.js';
|
package/lib/aptos/index.js
CHANGED
@@ -6,4 +6,6 @@ export { AptosBindOptions, AptosNetwork } from './network.js';
|
|
6
6
|
export * from './api.js';
|
7
7
|
export { ModuleClient } from './module-client.js';
|
8
8
|
export { AptosPlugin } from './aptos-plugin.js';
|
9
|
+
export { BUILTIN_TYPES } from '../move/types.js';
|
10
|
+
export * from './utils.js';
|
9
11
|
//# sourceMappingURL=index.js.map
|
package/lib/aptos/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAClF,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA","sourcesContent":["export * from './move-types.js'\nexport type { EventInstance, TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'\nexport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nexport { AptosBaseProcessor, AptosResourcesProcessor } from './aptos-processor.js'\nexport { AptosContext, AptosResourcesContext } from './context.js'\nexport { AptosBindOptions, AptosNetwork } from './network.js'\nexport * from './api.js'\nexport { ModuleClient } from './module-client.js'\n\nexport { AptosPlugin } from './aptos-plugin.js'\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAClF,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,cAAc,YAAY,CAAA","sourcesContent":["export * from './move-types.js'\nexport type { EventInstance, TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'\nexport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nexport { AptosBaseProcessor, AptosResourcesProcessor } from './aptos-processor.js'\nexport { AptosContext, AptosResourcesContext } from './context.js'\nexport { AptosBindOptions, AptosNetwork } from './network.js'\nexport * from './api.js'\nexport { ModuleClient } from './module-client.js'\n\nexport { AptosPlugin } from './aptos-plugin.js'\n\nexport { BUILTIN_TYPES } from '../move/types.js'\n\nexport * from './utils.js'\n"]}
|
package/lib/aptos/models.d.ts
CHANGED
@@ -1,21 +1,13 @@
|
|
1
1
|
import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js';
|
2
|
+
import { DecodedStruct } from '../move/types.js';
|
2
3
|
export type EventInstance = Event & {
|
3
4
|
version: string;
|
4
5
|
};
|
5
|
-
export type TypedEventInstance<T> = EventInstance
|
6
|
-
|
7
|
-
* decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
8
|
-
*/
|
9
|
-
data_decoded: T;
|
10
|
-
type_arguments: string[];
|
11
|
-
};
|
6
|
+
export type TypedEventInstance<T> = DecodedStruct<EventInstance, T>;
|
7
|
+
export type TypedMoveResource<T> = DecodedStruct<MoveResource, T>;
|
12
8
|
export type TypedFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
|
13
9
|
/**
|
14
10
|
* decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
15
11
|
*/
|
16
12
|
arguments_decoded: T;
|
17
13
|
};
|
18
|
-
export type TypedMoveResource<T> = MoveResource & {
|
19
|
-
data_decoded: T;
|
20
|
-
type_arguments: string[];
|
21
|
-
};
|
package/lib/aptos/models.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/aptos/models.ts"],"names":[],"mappings":"","sourcesContent":["import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js'\n\nexport type EventInstance = Event & {\n version: string\n}\n\nexport type TypedEventInstance<T> = EventInstance
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/aptos/models.ts"],"names":[],"mappings":"","sourcesContent":["import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js'\nimport { DecodedStruct } from '../move/types.js'\n\nexport type EventInstance = Event & {\n version: string\n}\n\nexport type TypedEventInstance<T> = DecodedStruct<EventInstance, T>\nexport type TypedMoveResource<T> = DecodedStruct<MoveResource, T>\n\n// Don't use intermediate type to make IDE happier\nexport type TypedFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {\n /**\n * decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch\n */\n arguments_decoded: T\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"]}
|
@@ -1,15 +1,15 @@
|
|
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 { AptosNetwork } from './network.js';
|
4
5
|
import { TypeDescriptor } from '../move/index.js';
|
5
|
-
export declare class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload
|
6
|
+
export declare class MoveCoder extends AbstractMoveCoder<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
|
7
|
+
constructor(network: AptosNetwork);
|
8
|
+
load(module: MoveModuleBytecode): import("../move/internal-models.js").InternalMoveModule;
|
9
|
+
decodeEvent<T>(event: Event): Promise<TypedEventInstance<T> | undefined>;
|
10
|
+
filterAndDecodeEvents<T>(type: string | TypeDescriptor<T>, resources: Event[]): Promise<TypedEventInstance<T>[]>;
|
11
|
+
decodeResource<T>(res: MoveResource): Promise<TypedMoveResource<T> | undefined>;
|
12
|
+
filterAndDecodeResources<T>(type: string | TypeDescriptor<T>, resources: MoveResource[]): Promise<TypedMoveResource<T>[]>;
|
13
|
+
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): Promise<TransactionPayload_EntryFunctionPayload>;
|
13
14
|
}
|
14
|
-
export declare
|
15
|
-
export declare function defaultMoveCoder(): MoveCoder;
|
15
|
+
export declare function defaultMoveCoder(network?: AptosNetwork): MoveCoder;
|
package/lib/aptos/move-coder.js
CHANGED
@@ -1,43 +1,62 @@
|
|
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';
|
5
|
+
import { parseMoveType } from '../move/index.js';
|
4
6
|
export class MoveCoder extends AbstractMoveCoder {
|
7
|
+
constructor(network) {
|
8
|
+
super(network);
|
9
|
+
this.adapter = new AptosChainAdapter();
|
10
|
+
}
|
5
11
|
load(module) {
|
6
12
|
if (!module.abi) {
|
7
13
|
throw Error('Module without abi');
|
8
14
|
}
|
9
|
-
|
10
|
-
|
15
|
+
let m = this.moduleMapping.get(module.abi.address + '::' + module.abi.name);
|
16
|
+
// if (this.contains(module.abi.address, module.abi.name)) {
|
17
|
+
// return
|
18
|
+
// }
|
19
|
+
if (m) {
|
20
|
+
return m;
|
11
21
|
}
|
12
|
-
|
22
|
+
m = toInternalModule(module);
|
23
|
+
this.loadInternal(m);
|
24
|
+
return m;
|
13
25
|
}
|
14
26
|
decodeEvent(event) {
|
15
27
|
return this.decodedStruct(event);
|
16
28
|
}
|
17
|
-
filterAndDecodeEvents(
|
18
|
-
|
29
|
+
filterAndDecodeEvents(type, resources) {
|
30
|
+
if (typeof type === 'string') {
|
31
|
+
type = parseMoveType(type);
|
32
|
+
}
|
33
|
+
return this.filterAndDecodeStruct(type, resources);
|
19
34
|
}
|
20
35
|
decodeResource(res) {
|
21
36
|
return this.decodedStruct(res);
|
22
37
|
}
|
23
|
-
filterAndDecodeResources(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
return
|
38
|
+
filterAndDecodeResources(type, resources) {
|
39
|
+
if (typeof type === 'string') {
|
40
|
+
type = parseMoveType(type);
|
41
|
+
}
|
42
|
+
return this.filterAndDecodeStruct(type, resources);
|
28
43
|
}
|
29
|
-
decodeFunctionPayload(payload) {
|
30
|
-
const func = this.getMoveFunction(payload.function);
|
31
|
-
const params = getMeaningfulFunctionParams(func.params);
|
32
|
-
const argumentsDecoded = this.decodeArray(payload.arguments, params);
|
44
|
+
async decodeFunctionPayload(payload) {
|
45
|
+
const func = await this.getMoveFunction(payload.function);
|
46
|
+
const params = this.adapter.getMeaningfulFunctionParams(func.params);
|
47
|
+
const argumentsDecoded = await this.decodeArray(payload.arguments, params);
|
33
48
|
return {
|
34
49
|
...payload,
|
35
50
|
arguments_decoded: argumentsDecoded,
|
36
51
|
};
|
37
52
|
}
|
38
53
|
}
|
39
|
-
|
40
|
-
|
41
|
-
|
54
|
+
const MOVE_CODER = new MoveCoder(AptosNetwork.MAIN_NET);
|
55
|
+
const TESTNET_MOVE_CODER = new MoveCoder(AptosNetwork.TEST_NET);
|
56
|
+
export function defaultMoveCoder(network = AptosNetwork.MAIN_NET) {
|
57
|
+
if (network == AptosNetwork.MAIN_NET) {
|
58
|
+
return MOVE_CODER;
|
59
|
+
}
|
60
|
+
return TESTNET_MOVE_CODER;
|
42
61
|
}
|
43
62
|
//# 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,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAA;AAEhE,MAAM,OAAO,SAAU,SAAQ,iBAAyE;IACtG,YAAY,OAAqB;QAC/B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAA;IACxC,CAAC;IAED,IAAI,CAAC,MAA0B;QAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,MAAM,KAAK,CAAC,oBAAoB,CAAC,CAAA;SAClC;QACD,IAAI,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,GA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AAO;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'\nimport { parseMoveType, TypeDescriptor } from '../move/index.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>(type: string | TypeDescriptor<T>, resources: Event[]): Promise<TypedEventInstance<T>[]> {\n if (typeof type === 'string') {\n type = parseMoveType(type)\n }\n return this.filterAndDecodeStruct(type, resources) as any\n }\n decodeResource<T>(res: MoveResource): Promise<TypedMoveResource<T> | undefined> {\n return this.decodedStruct<T>(res)\n }\n filterAndDecodeResources<T>(\n type: string | TypeDescriptor<T>,\n resources: MoveResource[]\n ): Promise<TypedMoveResource<T>[]> {\n if (typeof type === 'string') {\n type = parseMoveType(type)\n }\n return this.filterAndDecodeStruct(type, resources)\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"]}
|
package/lib/aptos/utils.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
export declare function
|
1
|
+
export declare function isValidAptosAddress(value: string): boolean;
|
2
|
+
export declare function validateAndNormalizeAddress(address: string): string;
|
package/lib/aptos/utils.js
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
import { HexString, TxnBuilderTypes } from 'aptos-sdk';
|
2
|
+
import { isFrameworkAccount } from '../move/index.js';
|
3
|
+
export function isValidAptosAddress(value) {
|
4
|
+
return TxnBuilderTypes.AccountAddress.isValid(value);
|
5
|
+
}
|
6
|
+
export function validateAndNormalizeAddress(address) {
|
7
|
+
const hex = TxnBuilderTypes.AccountAddress.fromHex(address).toHexString();
|
8
|
+
if (isFrameworkAccount(address)) {
|
9
|
+
return HexString.ensure(hex).toShortString();
|
7
10
|
}
|
8
|
-
return
|
11
|
+
return hex.toString();
|
9
12
|
}
|
10
13
|
//# sourceMappingURL=utils.js.map
|
package/lib/aptos/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/aptos/utils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/aptos/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAErD,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAO,eAAe,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AACtD,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,OAAe;IACzD,MAAM,GAAG,GAAG,eAAe,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAA;IACzE,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAAE;QAC/B,OAAO,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,EAAE,CAAA;KAC7C;IACD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;AACvB,CAAC","sourcesContent":["import { HexString, TxnBuilderTypes } from 'aptos-sdk'\nimport { isFrameworkAccount } from '../move/index.js'\n\nexport function isValidAptosAddress(value: string): boolean {\n return TxnBuilderTypes.AccountAddress.isValid(value)\n}\n\nexport function validateAndNormalizeAddress(address: string): string {\n const hex = TxnBuilderTypes.AccountAddress.fromHex(address).toHexString()\n if (isFrameworkAccount(address)) {\n return HexString.ensure(hex).toShortString()\n }\n return hex.toString()\n}\n"]}
|
@@ -21,6 +21,7 @@ export declare abstract class BaseProcessorTemplate<TContract extends BaseContra
|
|
21
21
|
handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid;
|
22
22
|
blockInterval?: HandleInterval;
|
23
23
|
timeIntervalInMinutes?: HandleInterval;
|
24
|
+
fetchConfig?: EthFetchConfig;
|
24
25
|
}[];
|
25
26
|
traceHandlers: {
|
26
27
|
signature: string;
|
@@ -35,9 +36,9 @@ export declare abstract class BaseProcessorTemplate<TContract extends BaseContra
|
|
35
36
|
constructor();
|
36
37
|
bind(options: BindOptions): void;
|
37
38
|
onEvent(handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: DeferredTopicFilter | DeferredTopicFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
38
|
-
onBlockInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, blockInterval?: number, backfillBlockInterval?: number): this;
|
39
|
-
onTimeInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillBlockInterval?: number): this;
|
40
|
-
onInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeInterval: HandleInterval | undefined, blockInterval: HandleInterval | undefined): this;
|
39
|
+
onBlockInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, blockInterval?: number, backfillBlockInterval?: number, fetchConfig?: EthFetchConfig): this;
|
40
|
+
onTimeInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillBlockInterval?: number, fetchConfig?: EthFetchConfig): this;
|
41
|
+
onInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeInterval: HandleInterval | undefined, blockInterval: HandleInterval | undefined, fetchConfig: EthFetchConfig | undefined): this;
|
41
42
|
onTrace(signature: string, handler: (trace: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, fetchConfig?: Partial<EthFetchConfig>): this;
|
42
43
|
protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>;
|
43
44
|
}
|