@sentio/sdk 2.0.0-rc.14 → 2.0.0-rc.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/api.d.ts +5 -0
- package/lib/aptos/api.js +21 -0
- package/lib/aptos/api.js.map +1 -0
- package/lib/aptos/aptos-plugin.d.ts +14 -0
- package/lib/aptos/aptos-plugin.js +146 -0
- package/lib/aptos/aptos-plugin.js.map +1 -0
- package/lib/aptos/aptos-processor.d.ts +72 -0
- package/lib/aptos/aptos-processor.js +201 -0
- package/lib/aptos/aptos-processor.js.map +1 -0
- package/lib/aptos/builtin/0x1.d.ts +2140 -0
- package/lib/aptos/builtin/0x1.js +2727 -0
- package/lib/aptos/builtin/0x1.js.map +1 -0
- package/lib/aptos/builtin/0x3.d.ts +573 -0
- package/lib/aptos/builtin/0x3.js +496 -0
- package/lib/aptos/builtin/0x3.js.map +1 -0
- package/lib/aptos/builtin/index.d.ts +2 -0
- package/lib/aptos/builtin/index.js +6 -0
- package/lib/aptos/builtin/index.js.map +1 -0
- package/lib/aptos/codegen/codegen.d.ts +23 -0
- package/lib/aptos/codegen/codegen.js +388 -0
- package/lib/aptos/codegen/codegen.js.map +1 -0
- package/lib/aptos/codegen/index.d.ts +1 -0
- package/lib/aptos/codegen/index.js +2 -0
- package/lib/aptos/codegen/index.js.map +1 -0
- package/lib/aptos/codegen/typegen.d.ts +18 -0
- package/lib/aptos/codegen/typegen.js +145 -0
- package/lib/aptos/codegen/typegen.js.map +1 -0
- package/lib/aptos/codegen/typegen.test.d.ts +1 -0
- package/lib/aptos/codegen/typegen.test.js.map +1 -0
- package/lib/aptos/context.d.ts +21 -0
- package/lib/aptos/context.js +59 -0
- package/lib/aptos/context.js.map +1 -0
- package/lib/aptos/index.d.ts +9 -0
- package/lib/aptos/index.js +8 -0
- package/lib/aptos/index.js.map +1 -0
- package/lib/aptos/models.d.ts +37 -0
- package/lib/aptos/models.js +2 -0
- package/lib/aptos/models.js.map +1 -0
- package/lib/aptos/move-coder.d.ts +22 -0
- package/lib/aptos/move-coder.js +164 -0
- package/lib/aptos/move-coder.js.map +1 -0
- package/lib/aptos/move-types.d.ts +10 -0
- package/lib/aptos/move-types.js +2 -0
- package/lib/aptos/move-types.js.map +1 -0
- package/lib/aptos/network.d.ts +11 -0
- package/lib/aptos/network.js +27 -0
- package/lib/aptos/network.js.map +1 -0
- package/lib/aptos/run-codegen.d.ts +1 -0
- package/lib/aptos/run-codegen.js +12 -0
- package/lib/aptos/run-codegen.js.map +1 -0
- package/lib/aptos/tests/aptos.test.d.ts +1 -0
- package/lib/aptos/tests/aptos.test.js.map +1 -0
- package/lib/aptos/tests/souffl3.d.ts +1 -0
- package/lib/aptos/tests/souffl3.js +44 -0
- package/lib/aptos/tests/souffl3.js.map +1 -0
- package/lib/aptos/tests/types/index.d.ts +3 -0
- package/lib/aptos/tests/types/index.js +7 -0
- package/lib/aptos/tests/types/index.js.map +1 -0
- package/lib/aptos/tests/types/reserved.d.ts +445 -0
- package/lib/aptos/tests/types/reserved.js +301 -0
- package/lib/aptos/tests/types/reserved.js.map +1 -0
- package/lib/aptos/tests/types/soffl3.d.ts +1065 -0
- package/lib/aptos/tests/types/soffl3.js +548 -0
- package/lib/aptos/tests/types/soffl3.js.map +1 -0
- package/lib/aptos/tests/types/souffle.d.ts +440 -0
- package/lib/aptos/tests/types/souffle.js +295 -0
- package/lib/aptos/tests/types/souffle.js.map +1 -0
- package/lib/aptos/types.d.ts +9 -0
- package/lib/aptos/types.js +130 -0
- package/lib/aptos/types.js.map +1 -0
- package/lib/aptos/types.test.d.ts +1 -0
- package/lib/aptos/types.test.js.map +1 -0
- package/lib/aptos/utils.d.ts +7 -0
- package/lib/aptos/utils.js +20 -0
- package/lib/aptos/utils.js.map +1 -0
- package/lib/{utils/chain.d.ts → chain.d.ts} +0 -0
- package/lib/{utils/chain.js → chain.js} +0 -0
- package/lib/chain.js.map +1 -0
- package/lib/core/context.js +1 -1
- package/lib/core/context.js.map +1 -1
- package/lib/core/sui-plugin.js +1 -1
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/solana/builtin/index.d.ts +1 -0
- package/lib/solana/builtin/index.js +2 -0
- package/lib/solana/builtin/index.js.map +1 -0
- package/lib/solana/builtin/spl-token-processor.d.ts +39 -0
- package/lib/solana/builtin/spl-token-processor.js +254 -0
- package/lib/solana/builtin/spl-token-processor.js.map +1 -0
- package/lib/solana/builtin/types.d.ts +427 -0
- package/lib/solana/builtin/types.js +200 -0
- package/lib/solana/builtin/types.js.map +1 -0
- package/lib/solana/codegen/codegen.d.ts +1 -0
- package/lib/solana/codegen/codegen.js +122 -0
- package/lib/solana/codegen/codegen.js.map +1 -0
- package/lib/solana/codegen/index.d.ts +1 -0
- package/lib/solana/codegen/index.js +2 -0
- package/lib/solana/codegen/index.js.map +1 -0
- package/lib/solana/index.d.ts +4 -0
- package/lib/solana/index.js +5 -0
- package/lib/solana/index.js.map +1 -0
- package/lib/solana/run-codegen.d.ts +2 -0
- package/lib/solana/run-codegen.js +12 -0
- package/lib/solana/run-codegen.js.map +1 -0
- package/lib/solana/solana-context.d.ts +9 -0
- package/lib/solana/solana-context.js +28 -0
- package/lib/solana/solana-context.js.map +1 -0
- package/lib/solana/solana-options.d.ts +10 -0
- package/lib/solana/solana-options.js +10 -0
- package/lib/solana/solana-options.js.map +1 -0
- package/lib/solana/solana-plugin.d.ts +9 -0
- package/lib/solana/solana-plugin.js +87 -0
- package/lib/solana/solana-plugin.js.map +1 -0
- package/lib/solana/solana-processor.d.ts +43 -0
- package/lib/solana/solana-processor.js +72 -0
- package/lib/solana/solana-processor.js.map +1 -0
- package/lib/solana/tests/solana.test.d.ts +1 -0
- package/lib/solana/tests/solana.test.js.map +1 -0
- package/lib/solana/tests/types/basic_1.d.ts +26 -0
- package/lib/solana/tests/types/basic_1.js +63 -0
- package/lib/solana/tests/types/basic_1.js.map +1 -0
- package/lib/solana/tests/types/basic_1_processor.d.ts +21 -0
- package/lib/solana/tests/types/basic_1_processor.js +35 -0
- package/lib/solana/tests/types/basic_1_processor.js.map +1 -0
- package/lib/solana/tests/types/token_bridge.d.ts +29 -0
- package/lib/solana/tests/types/token_bridge.js +938 -0
- package/lib/solana/tests/types/token_bridge.js.map +1 -0
- package/lib/solana/tests/types/token_bridge_processor.d.ts +212 -0
- package/lib/solana/tests/types/token_bridge_processor.js +134 -0
- package/lib/solana/tests/types/token_bridge_processor.js.map +1 -0
- package/lib/solana/tests/wormhole-token-bridge.d.ts +15 -0
- package/lib/solana/tests/wormhole-token-bridge.js +79 -0
- package/lib/solana/tests/wormhole-token-bridge.js.map +1 -0
- package/lib/testing/test-processor-server.js +1 -1
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/testing/test-provider.js +1 -1
- package/lib/testing/test-provider.js.map +1 -1
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +33 -11
- package/src/aptos/abis/0x1.json +9205 -0
- package/src/aptos/abis/0x3.json +1515 -0
- package/src/aptos/api.ts +23 -0
- package/src/aptos/aptos-plugin.ts +183 -0
- package/src/aptos/aptos-processor.ts +331 -0
- package/src/aptos/builtin/0x1.ts +4911 -0
- package/src/aptos/builtin/0x3.ts +1092 -0
- package/src/aptos/builtin/index.ts +5 -0
- package/src/aptos/codegen/codegen.ts +470 -0
- package/src/aptos/codegen/index.ts +1 -0
- package/src/aptos/codegen/tsconfig.json +8 -0
- package/src/aptos/codegen/typegen.ts +165 -0
- package/src/aptos/context.ts +72 -0
- package/src/aptos/index.ts +10 -0
- package/src/aptos/models.ts +47 -0
- package/src/aptos/move-coder.ts +201 -0
- package/src/aptos/move-types.ts +11 -0
- package/src/aptos/network.ts +29 -0
- package/src/aptos/run-codegen.ts +13 -0
- package/src/aptos/tests/abis/reserved.json +402 -0
- package/src/aptos/tests/abis/soffl3.json +1411 -0
- package/src/aptos/tests/abis/souffle.json +389 -0
- package/src/aptos/tests/souffl3.ts +57 -0
- package/src/aptos/tests/types/index.ts +6 -0
- package/src/aptos/tests/types/reserved.ts +881 -0
- package/src/aptos/tests/types/soffl3.ts +1820 -0
- package/src/aptos/tests/types/souffle.ts +880 -0
- package/src/aptos/types.ts +149 -0
- package/src/aptos/utils.ts +26 -0
- package/src/{utils/chain.ts → chain.ts} +0 -0
- package/src/core/context.ts +1 -1
- package/src/core/sui-plugin.ts +1 -1
- package/src/index.ts +1 -1
- package/src/solana/builtin/index.ts +1 -0
- package/src/solana/builtin/spl-token-processor.ts +298 -0
- package/src/solana/builtin/types.ts +279 -0
- package/src/solana/codegen/codegen.ts +140 -0
- package/src/solana/codegen/index.ts +1 -0
- package/src/solana/codegen/tsconfig.json +8 -0
- package/src/solana/index.ts +4 -0
- package/src/solana/run-codegen.ts +13 -0
- package/src/solana/solana-context.ts +30 -0
- package/src/solana/solana-options.ts +11 -0
- package/src/solana/solana-plugin.ts +103 -0
- package/src/solana/solana-processor.ts +102 -0
- package/src/solana/tests/abis/basic_1.json +62 -0
- package/src/solana/tests/abis/token_bridge.json +937 -0
- package/src/solana/tests/types/basic_1.ts +62 -0
- package/src/solana/tests/types/basic_1_processor.ts +42 -0
- package/src/solana/tests/types/token_bridge.ts +937 -0
- package/src/solana/tests/types/token_bridge_processor.ts +150 -0
- package/src/solana/tests/wormhole-token-bridge.ts +96 -0
- package/src/testing/test-processor-server.ts +1 -1
- package/src/testing/test-provider.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/lib/utils/chain.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/aptos/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU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C,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,EACtG,EAAE,CACH,CAAA;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,KAAK,CAAA;KACb;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import * as fs from 'fs'\nimport * as path from 'path'\nimport { format } from 'prettier'\nimport { MoveFunction, MoveModule, MoveModuleBytecode, MoveStruct } from '../move-types.js'\nimport { AccountModulesImportInfo, AccountRegister, generateType, normalizeToJSName } from './typegen.js'\nimport { getMeaningfulFunctionParams, isFrameworkAccount, moduleQname, SPLITTER } from '../utils.js'\nimport chalk from 'chalk'\nimport { AptosNetwork, getAptosChainName } from '../network.js'\nimport { parseMoveType } from '../types.js'\nimport { AptosClient } from 'aptos-sdk'\n\nfunction getRpcEndpoint(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'https://testnet.aptoslabs.com/'\n }\n return 'https://mainnet.aptoslabs.com/'\n}\n\nfunction getRpcClient(network: AptosNetwork): AptosClient {\n return new AptosClient(getRpcEndpoint(network))\n}\n\nexport async function codeGenAptosProcessor(abisDir: string, outDir = 'src/types/aptos') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n console.log(chalk.green('Generated Types for Aptos'))\n await generate(abisDir, outDir)\n}\n\nexport async function generate(srcDir: string, outputDir: string) {\n await generateForNetwork(srcDir, outputDir, AptosNetwork.MAIN_NET)\n await generateForNetwork(path.join(srcDir, 'testnet'), path.join(outputDir, 'testnet'), AptosNetwork.TEST_NET)\n}\n\nexport async function generateForNetwork(srcDir: string, outputDir: string, network: AptosNetwork) {\n if (!fs.existsSync(srcDir)) {\n return\n }\n if (network === AptosNetwork.TEST_NET) {\n console.log('Found testnet directory, generate code for testnet modules')\n }\n const files = fs.readdirSync(srcDir)\n outputDir = path.resolve(outputDir)\n const outputs: OutputFile[] = []\n\n fs.mkdirSync(outputDir, { recursive: true })\n\n const loader = new AccountRegister()\n\n // when generating user code, don't need to generate framework account\n loader.accountImports.set('0x1', new AccountModulesImportInfo('0x1', '0x1'))\n loader.accountImports.set('0x2', new AccountModulesImportInfo('0x2', '0x2'))\n loader.accountImports.set('0x3', new AccountModulesImportInfo('0x3', '0x3'))\n const client = getRpcClient(network)\n\n for (const file of files) {\n if (!file.endsWith('.json')) {\n continue\n }\n const fullPath = path.resolve(srcDir, file)\n const modules = JSON.parse(fs.readFileSync(fullPath, 'utf-8'))\n\n for (const module of modules) {\n if (module.abi) {\n loader.register(module.abi, path.basename(file, '.json'))\n }\n }\n const codeGen = new AccountCodegen(loader, modules, {\n fileName: path.basename(file, '.json'),\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n }\n\n while (loader.pendingAccounts.size > 0) {\n for (const account of loader.pendingAccounts) {\n console.log(`download dependent module for account ${account} at ${getAptosChainName(network)}`)\n\n try {\n const modules = await client.getAccountModules(account)\n fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(modules, null, '\\t'))\n\n for (const module of modules) {\n if (module.abi) {\n loader.register(module.abi, account)\n }\n }\n const codeGen = new AccountCodegen(loader, modules, {\n fileName: account,\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n } catch (e) {\n console.error(\n chalk.red(\n 'Error downloading account module, check if you choose the right network,or download account modules manually into your director'\n )\n )\n console.error(e)\n process.exit(1)\n }\n }\n }\n\n for (const output of outputs) {\n const content = format(output.fileContent, { parser: 'typescript' })\n fs.writeFileSync(path.join(outputDir, output.fileName), content)\n }\n\n const rootFile = path.join(outputDir, 'index.ts')\n fs.writeFileSync(\n rootFile,\n `/* Autogenerated file. Do not edit manually. */\n/* tslint:disable */\n/* eslint-disable */\n`\n )\n for (const output of outputs) {\n const parsed = path.parse(output.fileName)\n const content = `export * as _${parsed.name} from './${parsed.name}.js'\\n`\n fs.appendFileSync(rootFile, content)\n }\n}\n\ninterface OutputFile {\n fileName: string\n fileContent: string\n}\n\ninterface Config {\n fileName: string\n outputDir: string\n network: AptosNetwork\n}\n\nexport class AccountCodegen {\n modules: MoveModuleBytecode[]\n config: Config\n loader: AccountRegister\n\n constructor(loader: AccountRegister, modules: MoveModuleBytecode[], config: Config) {\n // const json = fs.readFileSync(config.srcFile, 'utf-8')\n this.modules = modules\n this.config = config\n this.loader = loader\n }\n\n generate(): OutputFile[] {\n if (!this.modules) {\n return []\n }\n // const baseName = path.basename(this.config.fileName, '.json')\n\n let address: string | undefined\n for (const module of this.modules) {\n if (module.abi && module.abi.address) {\n address = module.abi.address\n }\n }\n if (!address) {\n return []\n }\n\n const imports = `\n import { \n MoveCoder, AptosBindOptions, AptosBaseProcessor, \n TypedEventInstance, AptosNetwork, TypedEntryFunctionPayload,\n AptosContext, CallFilter\n } from \"@sentio/sdk/aptos\"\n import { AptosFetchConfig } from \"@sentio/protos\"\n import { Address, MoveModule } from \"@sentio/sdk/aptos\"\n `\n\n const dependedAccounts: string[] = []\n\n const moduleImports: string[] = []\n\n const info = this.loader.accountImports.get(address)\n\n if (info) {\n for (const [account] of info.imports.entries()) {\n // Remap to user's filename if possible, TODO codepath not well tested\n const tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)\n if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {\n // Decide where to find runtime library\n moduleImports.push(`import { _${account} } from \"@sentio/sdk/aptos/builtin\"`)\n } else {\n moduleImports.push(`import * as _${account} from \"${tsAccountModule}.js\"`)\n }\n\n dependedAccounts.push(account)\n }\n }\n\n const source = `\n /* Autogenerated file. Do not edit manually. */\n /* tslint:disable */\n /* eslint-disable */\n \n /* Generated modules for account ${address} */\n \n ${imports}\n \n ${moduleImports.join('\\n')}\n \n ${this.modules.map((m) => generateModule(m, this.config.network)).join('\\n')}\n \n export function loadAllTypes(_r: MoveCoder) {\n ${dependedAccounts.map((a) => `_${a}.loadAllTypes(_r)`).join('\\n')}\n\n ${this.modules\n .map((m) => {\n return `_r.load(${normalizeToJSName(m.abi!.name)}.ABI)`\n })\n .join('\\n')}\n }\n ` // source\n\n return [\n {\n fileName: this.config.fileName + '.ts',\n fileContent: source,\n },\n ]\n }\n}\n\nfunction generateNetworkOption(network: AptosNetwork) {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'TEST_NET'\n }\n return 'MAIN_NET'\n}\n\nfunction generateModule(moduleByteCode: MoveModuleBytecode, network: AptosNetwork) {\n if (!moduleByteCode.abi) {\n return ''\n }\n const module = moduleByteCode.abi\n\n const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '')\n\n const eventStructs = getEventStructs(module)\n const eventTypes = new Set(eventStructs.keys())\n const events = Array.from(eventStructs.values())\n .map((e) => generateOnEvents(module, e))\n .filter((s) => s !== '')\n const structs = module.structs.map((s) => generateStructs(module, s, eventTypes))\n const callArgs = module.exposed_functions.map((f) => generateCallArgsStructs(module, f))\n\n const moduleName = normalizeToJSName(module.name)\n let processor = ''\n if (functions.length > 0 || events.length > 0) {\n processor = `export class ${moduleName} extends AptosBaseProcessor {\n\n constructor(options: AptosBindOptions) {\n super(\"${module.name}\", options)\n }\n static DEFAULT_OPTIONS: AptosBindOptions = {\n address: \"${module.address}\",\n network: AptosNetwork.${generateNetworkOption(network)} \n }\n\n static bind(options: Partial<AptosBindOptions> = {}): ${moduleName} {\n return new ${moduleName}({ ...${moduleName}.DEFAULT_OPTIONS, ...options })\n }\n \n ${functions.join('\\n')}\n \n ${events.join('\\n')}\n \n loadTypesInternal(registry: MoveCoder) {\n loadAllTypes(registry)\n }\n }\n `\n }\n\n return `\n ${processor}\n\n export namespace ${moduleName} {\n ${structs.join('\\n')}\n \n ${callArgs.join('\\n')}\n \n export function loadTypes(_r: MoveCoder) {\n loadAllTypes(_r)\n }\n export const ABI: MoveModule = JSON.parse('${JSON.stringify(module)}')\n }\n `\n}\n\nfunction generateStructs(module: MoveModule, struct: MoveStruct, events: Set<string>) {\n const genericString = generateStructTypeParameters(struct)\n const genericStringAny = generateStructTypeParameters(struct, true)\n\n const structName = normalizeToJSName(struct.name)\n\n const fields = struct.fields.map((field) => {\n return `${field.name}: ${generateType(field.type, module.address)}`\n })\n\n let eventPayload = ''\n if (events.has(moduleQname(module) + SPLITTER + struct.name)) {\n eventPayload = `\n export interface ${structName}Instance extends \n TypedEventInstance<${structName}${genericStringAny}> {\n /** @deprecated use {@link data_decoded} instead */\n data_typed: ${structName}${genericStringAny}\n data_decoded: ${structName}${genericStringAny}\n type_arguments: [${struct.generic_type_params.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n return `\n export class ${structName}${genericString} {\n static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'\n ${fields.join('\\n')} \n }\n \n ${eventPayload}\n `\n}\n\nfunction generateFunctionTypeParameters(func: MoveFunction) {\n let genericString = ''\n if (func.generic_type_params && func.generic_type_params.length > 0) {\n const params = func.generic_type_params\n .map((v, idx) => {\n return `T${idx}=any`\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n}\n\nfunction generateStructTypeParameters(struct: MoveStruct, useAny = false) {\n let genericString = ''\n\n if (struct.generic_type_params && struct.generic_type_params.length > 0) {\n const params = struct.generic_type_params\n .map((v, idx) => {\n return useAny ? 'any' : 'T' + idx\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n}\n\nfunction generateCallArgsStructs(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return\n }\n\n const fields = getMeaningfulFunctionParams(func).map((param) => {\n return `${generateType(param, module.address)}`\n })\n\n const camelFuncName = capitalizeFirstChar(camelize(func.name))\n\n const genericString = generateFunctionTypeParameters(func)\n return `\n export interface ${camelFuncName}Payload${genericString}\n extends TypedEntryFunctionPayload<[${fields.join(',')}]> {\n /** @deprecated use {@link arguments_decoded} instead */\n arguments_typed: [${fields.join(',')}],\n arguments_decoded: [${fields.join(',')}],\n type_arguments: [${func.generic_type_params.map((_) => 'string').join(', ')}]\n }\n `\n}\n\nfunction generateOnEntryFunctions(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return ''\n }\n\n // const genericString = generateFunctionTypeParameters(func)\n const moduleName = normalizeToJSName(module.name)\n\n const camelFuncName = capitalizeFirstChar(camelize(func.name))\n const source = `\n onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: AptosContext) => void, filter?: CallFilter, fetchConfig?: AptosFetchConfig): ${moduleName} {\n this.onEntryFunctionCall(func, {\n ...filter,\n function: '${module.name}::${func.name}'\n },\n fetchConfig)\n return this\n }`\n\n return source\n}\n\nfunction getEventStructs(module: MoveModule) {\n const qname = moduleQname(module)\n const structMap = new Map<string, MoveStruct>()\n const eventMap = new Map<string, MoveStruct>()\n\n for (const struct of module.structs) {\n structMap.set(qname + SPLITTER + struct.name, struct)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n const t = parseMoveType(field.type)\n if (t.qname === '0x1::event::EventHandle') {\n const event = t.typeArgs[0].qname\n const eventStruct = structMap.get(event)\n if (eventStruct) {\n eventMap.set(event, eventStruct)\n }\n }\n }\n }\n\n return eventMap\n}\n\nfunction generateOnEvents(module: MoveModule, struct: MoveStruct): string {\n // for struct that has drop + store\n // if (!isEvent(struct, module)) {\n // return ''\n // }\n\n // const genericString = generateStructTypeParameters(struct)\n\n const moduleName = normalizeToJSName(module.name)\n const source = `\n onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(\n struct.name\n )}Instance, ctx: AptosContext) => void, fetchConfig?: AptosFetchConfig): ${moduleName} {\n this.onEvent(func, {\n type: '${module.name}::${struct.name}'\n },\n fetchConfig)\n return this\n }\n `\n return source\n}\n\nfunction camelize(input: string): string {\n return input\n .split('_')\n .reduce(\n (res, word, i) =>\n i === 0 ? word.toLowerCase() : `${res}${word.charAt(0).toUpperCase()}${word.slice(1).toLowerCase()}`,\n ''\n )\n}\n\nfunction capitalizeFirstChar(input: string): string {\n if (!input) {\n return input\n }\n return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '')\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './codegen.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/aptos/codegen/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA","sourcesContent":["export * from './codegen.js'\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MoveModule } from '../move-types.js';
|
|
2
|
+
import { TypeDescriptor } from '../types.js';
|
|
3
|
+
export declare function generateType(type: string, currentAddress: string): string;
|
|
4
|
+
export declare class AccountModulesImportInfo {
|
|
5
|
+
imports: Map<string, Set<string>>;
|
|
6
|
+
account: string;
|
|
7
|
+
moduleName: string;
|
|
8
|
+
constructor(account: string, tsModuleName: string);
|
|
9
|
+
addImport(account: string, module: string): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class AccountRegister {
|
|
12
|
+
accountImports: Map<string, AccountModulesImportInfo>;
|
|
13
|
+
pendingAccounts: Set<string>;
|
|
14
|
+
typeDescriptors: Map<string, TypeDescriptor>;
|
|
15
|
+
private loadTypeDescriptor;
|
|
16
|
+
register(module: MoveModule, tsModuleName: string): AccountModulesImportInfo;
|
|
17
|
+
}
|
|
18
|
+
export declare function normalizeToJSName(name: string): string;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { parseMoveType } from '../types.js';
|
|
2
|
+
import { moduleQname, moduleQnameForType, SPLITTER, VECTOR_STR } from '../utils.js';
|
|
3
|
+
function generateTypeForDescriptor(type, currentAddress) {
|
|
4
|
+
// TODO &signer is defintely an address, but what if &OTHER_TYPE?
|
|
5
|
+
if (type.qname.startsWith('&')) {
|
|
6
|
+
return 'Address';
|
|
7
|
+
}
|
|
8
|
+
switch (type.qname) {
|
|
9
|
+
case 'signer': // TODO check this
|
|
10
|
+
case 'address':
|
|
11
|
+
return 'Address';
|
|
12
|
+
case '0x1::string::String':
|
|
13
|
+
return 'string';
|
|
14
|
+
case 'bool':
|
|
15
|
+
return 'Boolean';
|
|
16
|
+
case 'u8':
|
|
17
|
+
case 'u16':
|
|
18
|
+
case 'u32':
|
|
19
|
+
return 'number';
|
|
20
|
+
case 'u64':
|
|
21
|
+
case 'u128':
|
|
22
|
+
return 'bigint';
|
|
23
|
+
}
|
|
24
|
+
if (type.qname === VECTOR_STR) {
|
|
25
|
+
// vector<u8> as hex string
|
|
26
|
+
const elementTypeQname = type.typeArgs[0].qname;
|
|
27
|
+
if (elementTypeQname === 'u8') {
|
|
28
|
+
return 'string';
|
|
29
|
+
}
|
|
30
|
+
if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {
|
|
31
|
+
return `${elementTypeQname}[] | string`;
|
|
32
|
+
}
|
|
33
|
+
return generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]';
|
|
34
|
+
}
|
|
35
|
+
const simpleName = generateSimpleType(type.qname, currentAddress);
|
|
36
|
+
if (simpleName.length === 0) {
|
|
37
|
+
console.error('unexpected error');
|
|
38
|
+
}
|
|
39
|
+
if (simpleName.includes('vector')) {
|
|
40
|
+
console.error('unexpected error');
|
|
41
|
+
}
|
|
42
|
+
if (type.typeArgs.length > 0) {
|
|
43
|
+
// return simpleName
|
|
44
|
+
return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t, currentAddress)).join(',') + '>';
|
|
45
|
+
}
|
|
46
|
+
return simpleName;
|
|
47
|
+
}
|
|
48
|
+
function generateSimpleType(type, currentAddress) {
|
|
49
|
+
const parts = type.split(SPLITTER);
|
|
50
|
+
for (let i = 0; i < parts.length; i++) {
|
|
51
|
+
parts[i] = normalizeToJSName(parts[i]);
|
|
52
|
+
}
|
|
53
|
+
if (parts.length < 2) {
|
|
54
|
+
return parts[0];
|
|
55
|
+
}
|
|
56
|
+
if (parts[0] === currentAddress) {
|
|
57
|
+
return parts.slice(1).join('.');
|
|
58
|
+
}
|
|
59
|
+
return '_' + parts.join('.');
|
|
60
|
+
}
|
|
61
|
+
// TODO ctx need to have type parameters
|
|
62
|
+
export function generateType(type, currentAddress) {
|
|
63
|
+
return generateTypeForDescriptor(parseMoveType(type), currentAddress);
|
|
64
|
+
}
|
|
65
|
+
export class AccountModulesImportInfo {
|
|
66
|
+
// account to module
|
|
67
|
+
imports;
|
|
68
|
+
account;
|
|
69
|
+
moduleName;
|
|
70
|
+
constructor(account, tsModuleName) {
|
|
71
|
+
this.account = account;
|
|
72
|
+
this.moduleName = tsModuleName;
|
|
73
|
+
this.imports = new Map();
|
|
74
|
+
}
|
|
75
|
+
addImport(account, module) {
|
|
76
|
+
if (account === this.account) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let accountModules = this.imports.get(account);
|
|
80
|
+
if (!accountModules) {
|
|
81
|
+
accountModules = new Set();
|
|
82
|
+
this.imports.set(account, accountModules);
|
|
83
|
+
}
|
|
84
|
+
accountModules.add(module);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export class AccountRegister {
|
|
88
|
+
accountImports = new Map();
|
|
89
|
+
pendingAccounts = new Set();
|
|
90
|
+
// loadedAccount = new Set<string>()
|
|
91
|
+
typeDescriptors = new Map();
|
|
92
|
+
loadTypeDescriptor(type) {
|
|
93
|
+
let descriptor = this.typeDescriptors.get(type);
|
|
94
|
+
// const descriptparseMoveType(type)
|
|
95
|
+
if (!descriptor) {
|
|
96
|
+
descriptor = parseMoveType(type);
|
|
97
|
+
this.typeDescriptors.set(type, descriptor);
|
|
98
|
+
}
|
|
99
|
+
return descriptor;
|
|
100
|
+
}
|
|
101
|
+
register(module, tsModuleName) {
|
|
102
|
+
const currentModuleFqn = moduleQname(module);
|
|
103
|
+
let accountModuleImports = this.accountImports.get(module.address);
|
|
104
|
+
if (!accountModuleImports) {
|
|
105
|
+
accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName);
|
|
106
|
+
this.accountImports.set(module.address, accountModuleImports);
|
|
107
|
+
// the account has already be processed, delete pending task
|
|
108
|
+
this.pendingAccounts.delete(module.address);
|
|
109
|
+
}
|
|
110
|
+
for (const struct of module.structs) {
|
|
111
|
+
for (const field of struct.fields) {
|
|
112
|
+
for (const type of this.loadTypeDescriptor(field.type).dependedTypes()) {
|
|
113
|
+
const [account, module] = moduleQnameForType(type);
|
|
114
|
+
accountModuleImports.addImport(account, module);
|
|
115
|
+
if (!this.accountImports.has(account)) {
|
|
116
|
+
this.pendingAccounts.add(account);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (const func of module.exposed_functions) {
|
|
122
|
+
if (!func.is_entry) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
for (const param of func.params) {
|
|
126
|
+
for (const type of this.loadTypeDescriptor(param).dependedTypes()) {
|
|
127
|
+
const [account, module] = moduleQnameForType(type);
|
|
128
|
+
accountModuleImports.addImport(account, module);
|
|
129
|
+
if (!this.accountImports.has(account)) {
|
|
130
|
+
this.pendingAccounts.add(account);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
this.accountImports.set(currentModuleFqn, accountModuleImports);
|
|
136
|
+
return accountModuleImports;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export function normalizeToJSName(name) {
|
|
140
|
+
if (name === 'package' || name === 'volatile') {
|
|
141
|
+
return name + '_';
|
|
142
|
+
}
|
|
143
|
+
return name;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=typegen.js.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MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,aAAa,EAAE,EAAE;oBACjE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAA;oBAClD,oBAAoB,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;oBAC/C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;wBACrC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;qBAClC;iBACF;aACF;SACF;QACD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAA;QAC/D,OAAO,oBAAoB,CAAA;IAC7B,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,UAAU,EAAE;QAC7C,OAAO,IAAI,GAAG,GAAG,CAAA;KAClB;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { MoveModule } from '../move-types.js'\nimport { parseMoveType, TypeDescriptor } from '../types.js'\nimport { moduleQname, moduleQnameForType, SPLITTER, VECTOR_STR } from '../utils.js'\n\nfunction generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string): string {\n // TODO &signer is defintely an address, but what if &OTHER_TYPE?\n if (type.qname.startsWith('&')) {\n return 'Address'\n }\n\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n return 'Address'\n case '0x1::string::String':\n return 'string'\n case 'bool':\n return 'Boolean'\n case 'u8':\n case 'u16':\n case 'u32':\n return 'number'\n case 'u64':\n case 'u128':\n return 'bigint'\n }\n\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n const elementTypeQname = type.typeArgs[0].qname\n if (elementTypeQname === 'u8') {\n return 'string'\n }\n if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {\n return `${elementTypeQname}[] | string`\n }\n return generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]'\n }\n\n const simpleName = generateSimpleType(type.qname, currentAddress)\n if (simpleName.length === 0) {\n console.error('unexpected error')\n }\n if (simpleName.includes('vector')) {\n console.error('unexpected error')\n }\n if (type.typeArgs.length > 0) {\n // return simpleName\n return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t, currentAddress)).join(',') + '>'\n }\n return simpleName\n}\n\nfunction generateSimpleType(type: string, currentAddress: string): string {\n const parts = type.split(SPLITTER)\n\n for (let i = 0; i < parts.length; i++) {\n parts[i] = normalizeToJSName(parts[i])\n }\n\n if (parts.length < 2) {\n return parts[0]\n }\n if (parts[0] === currentAddress) {\n return parts.slice(1).join('.')\n }\n return '_' + parts.join('.')\n}\n\n// TODO ctx need to have type parameters\nexport function generateType(type: string, currentAddress: string): string {\n return generateTypeForDescriptor(parseMoveType(type), currentAddress)\n}\n\nexport class AccountModulesImportInfo {\n // account to module\n imports: Map<string, Set<string>>\n account: string\n moduleName: string\n\n constructor(account: string, tsModuleName: string) {\n this.account = account\n this.moduleName = tsModuleName\n this.imports = new Map<string, Set<string>>()\n }\n\n addImport(account: string, module: string) {\n if (account === this.account) {\n return\n }\n let accountModules = this.imports.get(account)\n if (!accountModules) {\n accountModules = new Set<string>()\n this.imports.set(account, accountModules)\n }\n accountModules.add(module)\n }\n}\n\nexport class AccountRegister {\n accountImports = new Map<string, AccountModulesImportInfo>()\n pendingAccounts = new Set<string>()\n\n // loadedAccount = new Set<string>()\n typeDescriptors = new Map<string, TypeDescriptor>()\n\n private loadTypeDescriptor(type: string) {\n let descriptor = this.typeDescriptors.get(type)\n\n // const descriptparseMoveType(type)\n if (!descriptor) {\n descriptor = parseMoveType(type)\n this.typeDescriptors.set(type, descriptor)\n }\n return descriptor\n }\n\n register(module: MoveModule, tsModuleName: string): AccountModulesImportInfo {\n const currentModuleFqn = moduleQname(module)\n\n let accountModuleImports = this.accountImports.get(module.address)\n if (!accountModuleImports) {\n accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName)\n this.accountImports.set(module.address, accountModuleImports)\n // the account has already be processed, delete pending task\n this.pendingAccounts.delete(module.address)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n for (const type of this.loadTypeDescriptor(field.type).dependedTypes()) {\n const [account, module] = moduleQnameForType(type)\n accountModuleImports.addImport(account, module)\n if (!this.accountImports.has(account)) {\n this.pendingAccounts.add(account)\n }\n }\n }\n }\n\n for (const func of module.exposed_functions) {\n if (!func.is_entry) {\n continue\n }\n for (const param of func.params) {\n for (const type of this.loadTypeDescriptor(param).dependedTypes()) {\n const [account, module] = moduleQnameForType(type)\n accountModuleImports.addImport(account, module)\n if (!this.accountImports.has(account)) {\n this.pendingAccounts.add(account)\n }\n }\n }\n }\n this.accountImports.set(currentModuleFqn, accountModuleImports)\n return accountModuleImports\n }\n}\n\nexport function normalizeToJSName(name: string) {\n if (name === 'package' || name === 'volatile') {\n return name + '_'\n }\n return name\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typegen.test.js","sourceRoot":"","sources":["../../../src/aptos/codegen/typegen.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,IAAI,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,GAAG,GAAG,aAAa,CAAC,8BAA8B,CAAC,CAAA;QAEzD,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,CAAA;QACzB,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,Q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ribe('type gen', () => {\n test('type gen for generic', async () => {\n const res = parseMoveType('x<g1<a,g2<c,d>>,b,g3<a,b>,e>')\n\n assert(res.qname === 'x')\n assert(res.typeArgs[0].typeArgs[1].qname === 'g2')\n assert(res.typeArgs[0].typeArgs[1].typeArgs[1].qname === 'd')\n })\n\n test('type gen for non generic', async () => {\n const res = parseMoveType('xyz')\n\n assert(res.qname === 'xyz')\n assert(res.typeArgs.length === 0)\n })\n\n test('test depended types', async () => {\n const typeString =\n '0x1::table_with_length::TableWithLength<T0, 0xd5f9f2b1c24faee8f07b790e570c75dfa1b7d8c1e9a60162fbd92ade03ea29e4::iterable_table::IterableValue<T0, T1>>'\n const res = parseMoveType(typeString)\n\n const deps = res.dependedTypes()\n assert(deps.length === 2)\n assert(\n deps[0] === '0xd5f9f2b1c24faee8f07b790e570c75dfa1b7d8c1e9a60162fbd92ade03ea29e4::iterable_table::IterableValue'\n )\n assert(deps[1] === '0x1::table_with_length::TableWithLength')\n\n const computedTypeString = res.getSignature()\n assert(computedTypeString === typeString)\n })\n // test('type type gen', async () => {\n //\n // const res = parseGenericType('x<g1<a,g2<c,d>>,b,g3<a,b>,e>')\n // console.log(res)\n //\n // assert(res.symbol === 'x')\n // assert(res.typeParams[0].typeParams[1].symbol === \"g2\")\n // assert(res.typeParams[0].typeParams[1].typeParams[1].symbol === \"d\")\n // })\n})\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RecordMetaData } from '@sentio/protos';
|
|
2
|
+
import { type Labels, BaseContext } from '@sentio/sdk';
|
|
3
|
+
import { Transaction_UserTransaction } from './move-types.js';
|
|
4
|
+
import { AptosNetwork } from './network.js';
|
|
5
|
+
export declare class AptosContext extends BaseContext {
|
|
6
|
+
address: string;
|
|
7
|
+
network: AptosNetwork;
|
|
8
|
+
moduleName: string;
|
|
9
|
+
version: bigint;
|
|
10
|
+
transaction: Transaction_UserTransaction;
|
|
11
|
+
constructor(moduleName: string, network: AptosNetwork, address: string, version: bigint, transaction?: Transaction_UserTransaction);
|
|
12
|
+
getMetaData(name: string, labels: Labels): RecordMetaData;
|
|
13
|
+
}
|
|
14
|
+
export declare class AptosResourceContext extends BaseContext {
|
|
15
|
+
address: string;
|
|
16
|
+
network: AptosNetwork;
|
|
17
|
+
version: bigint;
|
|
18
|
+
timestampInMicros: number;
|
|
19
|
+
constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number);
|
|
20
|
+
getMetaData(name: string, labels: Labels): RecordMetaData;
|
|
21
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BaseContext, normalizeLabels } from '@sentio/sdk';
|
|
2
|
+
import { getChainId } from './network.js';
|
|
3
|
+
export class AptosContext extends BaseContext {
|
|
4
|
+
address;
|
|
5
|
+
network;
|
|
6
|
+
moduleName;
|
|
7
|
+
version;
|
|
8
|
+
transaction;
|
|
9
|
+
constructor(moduleName, network, address, version, transaction) {
|
|
10
|
+
super();
|
|
11
|
+
this.address = address;
|
|
12
|
+
this.network = network;
|
|
13
|
+
this.moduleName = moduleName;
|
|
14
|
+
this.version = version;
|
|
15
|
+
if (transaction) {
|
|
16
|
+
this.transaction = transaction;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
getMetaData(name, labels) {
|
|
20
|
+
return {
|
|
21
|
+
address: this.address,
|
|
22
|
+
contractName: this.moduleName,
|
|
23
|
+
blockNumber: this.version,
|
|
24
|
+
transactionIndex: 0,
|
|
25
|
+
transactionHash: this.transaction?.hash || '',
|
|
26
|
+
logIndex: 0,
|
|
27
|
+
chainId: getChainId(this.network),
|
|
28
|
+
name: name,
|
|
29
|
+
labels: normalizeLabels(labels),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class AptosResourceContext extends BaseContext {
|
|
34
|
+
address;
|
|
35
|
+
network;
|
|
36
|
+
version;
|
|
37
|
+
timestampInMicros;
|
|
38
|
+
constructor(network, address, version, timestampInMicros) {
|
|
39
|
+
super();
|
|
40
|
+
this.address = address;
|
|
41
|
+
this.network = network;
|
|
42
|
+
this.version = version;
|
|
43
|
+
this.timestampInMicros = timestampInMicros;
|
|
44
|
+
}
|
|
45
|
+
getMetaData(name, labels) {
|
|
46
|
+
return {
|
|
47
|
+
address: this.address,
|
|
48
|
+
contractName: 'resources',
|
|
49
|
+
blockNumber: this.version,
|
|
50
|
+
transactionIndex: 0,
|
|
51
|
+
transactionHash: '',
|
|
52
|
+
logIndex: 0,
|
|
53
|
+
chainId: getChainId(this.network),
|
|
54
|
+
name: name,
|
|
55
|
+
labels: normalizeLabels(labels),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +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;AAEvD,MAAM,OAAO,YAAa,SAAQ,WAAW;IAC3C,OAAO,CAAQ;IACf,OAAO,CAAc;IACrB,UAAU,CAAQ;IAClB,OAAO,CAAQ;IACf,WAAW,CAA6B;IAExC,YACE,UAAkB,EAClB,OAAqB,EACrB,OAAe,EACf,OAAe,EACf,WAAyC;QAEzC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;SAC/B;IACH,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,MAAc;QACtC,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,WAAW,EAAE,IAAI,CAAC,OAAO;YACzB,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE;YAC7C,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;YACjC,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,WAAW;IACnD,OAAO,CAAQ;IACf,OAAO,CAAc;IACrB,OAAO,CAAQ;IACf,iBAAiB,CAAQ;IAEzB,YAAY,OAAqB,EAAE,OAAe,EAAE,OAAe,EAAE,iBAAyB;QAC5F,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;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,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;YACjC,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'\n\nexport class AptosContext extends BaseContext {\n address: string\n network: AptosNetwork\n moduleName: string\n version: bigint\n transaction: Transaction_UserTransaction\n\n constructor(\n moduleName: string,\n network: AptosNetwork,\n address: string,\n version: bigint,\n transaction?: Transaction_UserTransaction\n ) {\n super()\n this.address = address\n this.network = network\n this.moduleName = moduleName\n this.version = version\n if (transaction) {\n this.transaction = transaction\n }\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: 0,\n chainId: getChainId(this.network),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class AptosResourceContext extends BaseContext {\n address: string\n network: AptosNetwork\n version: bigint\n timestampInMicros: number\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 }\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: getChainId(this.network),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './move-types.js';
|
|
2
|
+
export type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload, TypedMoveResource } from './models.js';
|
|
3
|
+
export { defaultMoveCoder, MoveCoder } from './move-coder.js';
|
|
4
|
+
export type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor.js';
|
|
5
|
+
export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor.js';
|
|
6
|
+
export { AptosContext, AptosResourceContext } from './context.js';
|
|
7
|
+
export { AptosBindOptions, AptosNetwork } from './network.js';
|
|
8
|
+
export * from './api.js';
|
|
9
|
+
export { AptosPlugin } from './aptos-plugin.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './move-types.js';
|
|
2
|
+
export { defaultMoveCoder, MoveCoder } from './move-coder.js';
|
|
3
|
+
export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor.js';
|
|
4
|
+
export { AptosContext, AptosResourceContext } from './context.js';
|
|
5
|
+
export { AptosBindOptions, AptosNetwork } from './network.js';
|
|
6
|
+
export * from './api.js';
|
|
7
|
+
export { AptosPlugin } from './aptos-plugin.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;AAE7D,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACjE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,UAAU,CAAA;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA","sourcesContent":["export * from './move-types.js'\nexport type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload, TypedMoveResource } from './models.js'\nexport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nexport type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor.js'\nexport { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor.js'\nexport { AptosContext, AptosResourceContext } from './context.js'\nexport { AptosBindOptions, AptosNetwork } from './network.js'\nexport * from './api.js'\n\nexport { AptosPlugin } from './aptos-plugin.js'\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js';
|
|
2
|
+
export type EventInstance = Event & {
|
|
3
|
+
version: string;
|
|
4
|
+
};
|
|
5
|
+
export type TypedEventInstance<T> = EventInstance & {
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use {@link data_decoded} instead
|
|
8
|
+
*/
|
|
9
|
+
data_typed: T;
|
|
10
|
+
/**
|
|
11
|
+
* decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
12
|
+
*/
|
|
13
|
+
data_decoded: T;
|
|
14
|
+
type_arguments: string[];
|
|
15
|
+
};
|
|
16
|
+
export type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated use {@link arguments_decoded} instead
|
|
19
|
+
*/
|
|
20
|
+
arguments_typed: T;
|
|
21
|
+
/**
|
|
22
|
+
* decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
23
|
+
*/
|
|
24
|
+
arguments_decoded: T;
|
|
25
|
+
};
|
|
26
|
+
export type TypedMoveResource<T> = MoveResource & {
|
|
27
|
+
data_typed: T;
|
|
28
|
+
type_arguments: string[];
|
|
29
|
+
};
|
|
30
|
+
export interface StructWithTag {
|
|
31
|
+
type: string;
|
|
32
|
+
data: any;
|
|
33
|
+
}
|
|
34
|
+
export interface StructWithType<T> extends StructWithTag {
|
|
35
|
+
data_typed: T;
|
|
36
|
+
type_arguments: string[];
|
|
37
|
+
}
|
|
@@ -0,0 +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 & {\n /**\n * @deprecated use {@link data_decoded} instead\n */\n data_typed: T\n\n /**\n * decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch\n */\n data_decoded: T\n\n type_arguments: string[]\n}\n\n// Don't use intermediate type to make IDE happier\nexport type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {\n /**\n * @deprecated use {@link arguments_decoded} instead\n */\n arguments_typed: T\n\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\nexport type TypedMoveResource<T> = MoveResource & {\n data_typed: T\n type_arguments: string[]\n}\n\nexport interface StructWithTag {\n type: string\n data: any\n}\n\nexport interface StructWithType<T> extends StructWithTag {\n data_typed: T\n type_arguments: string[]\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Event, MoveFunction, MoveModule, MoveResource, MoveStruct, TransactionPayload_EntryFunctionPayload } from './move-types.js';
|
|
2
|
+
import { TypeDescriptor } from './types.js';
|
|
3
|
+
import { TypedEventInstance, TypedMoveResource } from './models.js';
|
|
4
|
+
export declare class MoveCoder {
|
|
5
|
+
private moduleMapping;
|
|
6
|
+
private typeMapping;
|
|
7
|
+
private funcMapping;
|
|
8
|
+
contains(account: string, name: string): boolean;
|
|
9
|
+
load(module: MoveModule): void;
|
|
10
|
+
getMoveStruct(type: string): MoveStruct;
|
|
11
|
+
getMoveFunction(type: string): MoveFunction;
|
|
12
|
+
decode(data: any, type: TypeDescriptor): any;
|
|
13
|
+
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined;
|
|
14
|
+
filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[];
|
|
15
|
+
decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined;
|
|
16
|
+
filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[];
|
|
17
|
+
private filterAndDecodeInternal;
|
|
18
|
+
private decodedInternal;
|
|
19
|
+
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload;
|
|
20
|
+
}
|
|
21
|
+
export declare const MOVE_CODER: MoveCoder;
|
|
22
|
+
export declare function defaultMoveCoder(): MoveCoder;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { getMeaningfulFunctionParams, moduleQname, SPLITTER, VECTOR_STR } from './utils.js';
|
|
2
|
+
import { parseMoveType } from './types.js';
|
|
3
|
+
export class MoveCoder {
|
|
4
|
+
moduleMapping = new Map();
|
|
5
|
+
typeMapping = new Map();
|
|
6
|
+
funcMapping = new Map();
|
|
7
|
+
contains(account, name) {
|
|
8
|
+
return this.moduleMapping.has(account + '::' + name);
|
|
9
|
+
}
|
|
10
|
+
load(module) {
|
|
11
|
+
if (this.contains(module.address, module.name)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
this.moduleMapping.set(moduleQname(module), module);
|
|
15
|
+
for (const struct of module.structs) {
|
|
16
|
+
// TODO move to util
|
|
17
|
+
const key = [module.address, module.name, struct.name].join(SPLITTER);
|
|
18
|
+
this.typeMapping.set(key, struct);
|
|
19
|
+
}
|
|
20
|
+
for (const func of module.exposed_functions) {
|
|
21
|
+
if (!func.is_entry) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const key = [module.address, module.name, func.name].join(SPLITTER);
|
|
25
|
+
this.funcMapping.set(key, func);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
getMoveStruct(type) {
|
|
29
|
+
const struct = this.typeMapping.get(type);
|
|
30
|
+
if (!struct) {
|
|
31
|
+
throw new Error('Failed to load type' + type);
|
|
32
|
+
}
|
|
33
|
+
return struct;
|
|
34
|
+
}
|
|
35
|
+
getMoveFunction(type) {
|
|
36
|
+
const func = this.funcMapping.get(type);
|
|
37
|
+
if (!func) {
|
|
38
|
+
throw new Error('Failed to load function' + type);
|
|
39
|
+
}
|
|
40
|
+
return func;
|
|
41
|
+
}
|
|
42
|
+
decode(data, type) {
|
|
43
|
+
// process simple type
|
|
44
|
+
if (type.qname.startsWith('&')) {
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
switch (type.qname) {
|
|
48
|
+
case 'signer': // TODO check this
|
|
49
|
+
case 'address':
|
|
50
|
+
case '0x1::string::String':
|
|
51
|
+
case 'bool':
|
|
52
|
+
case 'u8':
|
|
53
|
+
case 'u16':
|
|
54
|
+
case 'u32':
|
|
55
|
+
return data;
|
|
56
|
+
case 'u64':
|
|
57
|
+
case 'u128':
|
|
58
|
+
return BigInt(data);
|
|
59
|
+
}
|
|
60
|
+
// process vector
|
|
61
|
+
if (type.qname === VECTOR_STR) {
|
|
62
|
+
// vector<u8> as hex string
|
|
63
|
+
if (type.typeArgs[0].qname === 'u8') {
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
const res = [];
|
|
67
|
+
for (const entry of data) {
|
|
68
|
+
res.push(this.decode(entry, type.typeArgs[0]));
|
|
69
|
+
}
|
|
70
|
+
return res;
|
|
71
|
+
}
|
|
72
|
+
// Process complex type
|
|
73
|
+
const struct = this.getMoveStruct(type.qname);
|
|
74
|
+
const typeCtx = new Map();
|
|
75
|
+
for (const [idx, typeArg] of type.typeArgs.entries()) {
|
|
76
|
+
typeCtx.set('T' + idx, typeArg);
|
|
77
|
+
}
|
|
78
|
+
const typedData = {};
|
|
79
|
+
for (const field of struct.fields) {
|
|
80
|
+
let filedType = parseMoveType(field.type);
|
|
81
|
+
filedType = filedType.applyTypeArgs(typeCtx);
|
|
82
|
+
const value = this.decode(data[field.name], filedType);
|
|
83
|
+
typedData[field.name] = value;
|
|
84
|
+
}
|
|
85
|
+
return typedData;
|
|
86
|
+
}
|
|
87
|
+
decodeEvent(event) {
|
|
88
|
+
return this.decodedInternal(event);
|
|
89
|
+
}
|
|
90
|
+
filterAndDecodeEvents(typeQname, resources) {
|
|
91
|
+
return this.filterAndDecodeInternal(typeQname, resources);
|
|
92
|
+
}
|
|
93
|
+
decodeResource(res) {
|
|
94
|
+
return this.decodedInternal(res);
|
|
95
|
+
}
|
|
96
|
+
filterAndDecodeResources(typeQname, resources) {
|
|
97
|
+
return this.filterAndDecodeInternal(typeQname, resources);
|
|
98
|
+
}
|
|
99
|
+
filterAndDecodeInternal(typeQname, structs) {
|
|
100
|
+
if (!structs) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const results = [];
|
|
104
|
+
for (const resource of structs) {
|
|
105
|
+
if (resource.type.split('<')[0] !== typeQname) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const result = this.decodedInternal(resource);
|
|
109
|
+
if (result) {
|
|
110
|
+
results.push(result);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return results;
|
|
114
|
+
}
|
|
115
|
+
decodedInternal(typeStruct) {
|
|
116
|
+
const registry = MOVE_CODER;
|
|
117
|
+
// this.loadTypes(registry)
|
|
118
|
+
// TODO check if module is not loaded
|
|
119
|
+
const typeDescriptor = parseMoveType(typeStruct.type);
|
|
120
|
+
const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature());
|
|
121
|
+
let dataTyped = undefined;
|
|
122
|
+
try {
|
|
123
|
+
dataTyped = registry.decode(typeStruct.data, typeDescriptor);
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
console.error('Decoding error for ', JSON.stringify(typeStruct), e);
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
...typeStruct,
|
|
131
|
+
data_typed: dataTyped,
|
|
132
|
+
data_decoded: dataTyped,
|
|
133
|
+
type_arguments: typeArguments,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
decodeFunctionPayload(payload) {
|
|
137
|
+
const registry = MOVE_CODER;
|
|
138
|
+
// this.loadTypes(registry)
|
|
139
|
+
const argumentsTyped = [];
|
|
140
|
+
try {
|
|
141
|
+
const func = registry.getMoveFunction(payload.function);
|
|
142
|
+
const params = getMeaningfulFunctionParams(func);
|
|
143
|
+
for (const [idx, arg] of payload.arguments.entries()) {
|
|
144
|
+
// TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
|
|
145
|
+
const argType = parseMoveType(params[idx]);
|
|
146
|
+
argumentsTyped.push(registry.decode(arg, argType));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
console.error('Decoding error for ', JSON.stringify(payload), e);
|
|
151
|
+
return payload;
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
...payload,
|
|
155
|
+
arguments_typed: argumentsTyped,
|
|
156
|
+
arguments_decoded: argumentsTyped,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export const MOVE_CODER = new MoveCoder();
|
|
161
|
+
export function defaultMoveCoder() {
|
|
162
|
+
return MOVE_CODER;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=move-coder.js.map
|