@sentio/sdk 1.19.5 → 1.20.0

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.
Files changed (72) hide show
  1. package/lib/aptos/aptos-processor.d.ts +7 -6
  2. package/lib/aptos/aptos-processor.js +5 -10
  3. package/lib/aptos/aptos-processor.js.map +1 -1
  4. package/lib/aptos/bind-options.d.ts +5 -0
  5. package/lib/aptos/bind-options.js +7 -1
  6. package/lib/aptos/bind-options.js.map +1 -1
  7. package/lib/aptos/context.d.ts +3 -3
  8. package/lib/aptos/context.js.map +1 -1
  9. package/lib/aptos/index.d.ts +2 -2
  10. package/lib/aptos/index.js +2 -1
  11. package/lib/aptos/index.js.map +1 -1
  12. package/lib/aptos-codegen/codegen.d.ts +11 -0
  13. package/lib/aptos-codegen/codegen.js +110 -0
  14. package/lib/aptos-codegen/codegen.js.map +1 -0
  15. package/lib/cli/build.d.ts +3 -3
  16. package/lib/cli/build.js +44 -22
  17. package/lib/cli/build.js.map +1 -1
  18. package/lib/cli/cli.js +11 -11
  19. package/lib/cli/cli.js.map +1 -1
  20. package/lib/cli/config.d.ts +0 -7
  21. package/lib/cli/config.js +9 -4
  22. package/lib/cli/config.js.map +1 -1
  23. package/lib/cli/upload.js +1 -1
  24. package/lib/cli/upload.js.map +1 -1
  25. package/lib/cli/webpack.config.js +1 -0
  26. package/lib/processor-runner.js +2 -2
  27. package/lib/processor-runner.js.map +1 -1
  28. package/lib/service.js +1 -1
  29. package/lib/service.js.map +1 -1
  30. package/lib/{cli/solana-code-gen.d.ts → test-abi-code-gen.d.ts} +0 -0
  31. package/lib/test-abi-code-gen.js +19 -0
  32. package/lib/test-abi-code-gen.js.map +1 -0
  33. package/lib/tests/aptos.test.js +4 -4
  34. package/lib/tests/aptos.test.js.map +1 -1
  35. package/lib/tests/souffl3.js +16 -23
  36. package/lib/tests/souffl3.js.map +1 -1
  37. package/lib/tests/types/aptos/account-4188c8.d.ts +27 -0
  38. package/lib/tests/types/aptos/account-4188c8.js +137 -0
  39. package/lib/tests/types/aptos/account-4188c8.js.map +1 -0
  40. package/lib/tests/types/{basic_1.d.ts → solana/basic_1.d.ts} +0 -0
  41. package/lib/tests/types/{basic_1.js → solana/basic_1.js} +0 -0
  42. package/lib/tests/types/solana/basic_1.js.map +1 -0
  43. package/lib/tests/types/{basic_1_processor.d.ts → solana/basic_1_processor.d.ts} +0 -0
  44. package/lib/tests/types/{basic_1_processor.js → solana/basic_1_processor.js} +0 -0
  45. package/lib/tests/types/solana/basic_1_processor.js.map +1 -0
  46. package/package.json +6 -5
  47. package/src/aptos/aptos-processor.ts +25 -18
  48. package/src/aptos/bind-options.ts +6 -0
  49. package/src/aptos/context.ts +3 -3
  50. package/src/aptos/index.ts +2 -5
  51. package/src/aptos-codegen/codegen.ts +128 -0
  52. package/src/aptos-codegen/codgen.test.ts +11 -0
  53. package/src/aptos-codegen/tsconfig.json +9 -0
  54. package/src/cli/build.ts +49 -20
  55. package/src/cli/cli.ts +12 -12
  56. package/src/cli/config.ts +9 -9
  57. package/src/cli/upload.ts +1 -1
  58. package/src/cli/webpack.config.js +1 -0
  59. package/src/processor-runner.ts +1 -1
  60. package/src/service.ts +2 -2
  61. package/src/test-abi-code-gen.ts +14 -0
  62. package/src/tests/abis/aptos/0x4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807.json +389 -0
  63. package/src/tests/aptos.test.ts +4 -4
  64. package/src/tests/souffl3.ts +20 -30
  65. package/src/tests/types/aptos/account-4188c8.ts +241 -0
  66. package/src/tests/types/{basic_1.ts → solana/basic_1.ts} +0 -0
  67. package/src/tests/types/{basic_1_processor.ts → solana/basic_1_processor.ts} +0 -0
  68. package/lib/cli/solana-code-gen.js +0 -19
  69. package/lib/cli/solana-code-gen.js.map +0 -1
  70. package/lib/tests/types/basic_1.js.map +0 -1
  71. package/lib/tests/types/basic_1_processor.js.map +0 -1
  72. package/src/cli/solana-code-gen.ts +0 -16
package/src/cli/build.ts CHANGED
@@ -2,17 +2,18 @@ import chalk from 'chalk'
2
2
  import path from 'path'
3
3
  import fs from 'fs'
4
4
  import { exec } from 'child_process'
5
- import { EVM, SOLANA, Target } from './config'
5
+ import { AptosCodegen } from '../aptos-codegen/codegen'
6
+ // import { EVM, SOLANA, Target } from './config'
6
7
 
7
- export async function buildProcessor(onlyGen: boolean, targets: Target[]) {
8
+ export async function buildProcessor(onlyGen: boolean) {
8
9
  if (!onlyGen) {
9
10
  await installDeps()
10
11
  }
11
12
 
12
13
  // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))
13
- for (const target of targets) {
14
- await buildProcessorForTarget(onlyGen, target)
15
- }
14
+ // for (const target) {
15
+ await buildProcessorForTarget(onlyGen)
16
+ // }
16
17
 
17
18
  if (!onlyGen) {
18
19
  const WEBPACK_CONFIG = path.join(__dirname, 'webpack.config.js')
@@ -21,12 +22,10 @@ export async function buildProcessor(onlyGen: boolean, targets: Target[]) {
21
22
  }
22
23
  }
23
24
 
24
- async function buildProcessorForTarget(onlyGen: boolean, target: Target) {
25
- if (target.chain === EVM) {
26
- await codeGenEthersProcessor(target.abisDir ?? path.join('abis', 'evm'))
27
- } else if (target.chain === SOLANA) {
28
- codeGenSolanaProcessor(target.abisDir ?? path.join('abis', 'solana'))
29
- }
25
+ async function buildProcessorForTarget(onlyGen: boolean) {
26
+ await codeGenEthersProcessor(path.join('abis', 'evm'))
27
+ codeGenSolanaProcessor(path.join('abis', 'solana'))
28
+ codeGenAptosProcessor(path.join('abis', 'aptos'))
30
29
 
31
30
  if (onlyGen) {
32
31
  return
@@ -37,6 +36,27 @@ async function installDeps() {
37
36
  await execStep('yarn install --ignore-scripts', 'Yarn Install')
38
37
  }
39
38
 
39
+ export function codeGenAptosProcessor(abisDir: string, outDir = 'src/types/aptos') {
40
+ if (!fs.existsSync(abisDir)) {
41
+ return
42
+ }
43
+
44
+ const files = fs.readdirSync(abisDir)
45
+
46
+ console.log(chalk.green('Generated Types for Aptos'))
47
+ for (const file of files) {
48
+ if (path.extname(file) === '.json') {
49
+ if (!fs.existsSync(outDir)) {
50
+ fs.mkdirSync(outDir, { recursive: true })
51
+ }
52
+ }
53
+ const codegen = new AptosCodegen(path.join(abisDir, file), {
54
+ outputDir: outDir,
55
+ })
56
+ codegen.generate()
57
+ }
58
+ }
59
+
40
60
  export async function codeGenEthersProcessor(
41
61
  abisDir: string,
42
62
  ETHERS_TARGET = path.join(__dirname, '../target-ethers-sentio'),
@@ -58,6 +78,8 @@ export async function codeGenEthersProcessor(
58
78
  return
59
79
  }
60
80
 
81
+ console.log(chalk.green('Generated Types for EVM'))
82
+
61
83
  // TODO this will fail during postinstall, need to locate real typechain path
62
84
  await execStep(
63
85
  'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,
@@ -65,21 +87,28 @@ export async function codeGenEthersProcessor(
65
87
  )
66
88
  }
67
89
 
68
- export function codeGenSolanaProcessor(abisDir: string, root = '', targetPath = path.join('src', 'types')) {
69
- const abisFolder = path.join(root, abisDir)
70
- const abisFiles = fs.readdirSync(abisFolder)
71
- const typeFolder = path.join(root, targetPath)
90
+ export function codeGenSolanaProcessor(abisDir: string, targetPath = path.join('src', 'types', 'solana')) {
91
+ if (!fs.existsSync(abisDir)) {
92
+ return
93
+ }
94
+
95
+ const abisFiles = fs.readdirSync(abisDir)
96
+
97
+ if (abisFiles.length > 0) {
98
+ console.log(chalk.green('Generated Types for Solana'))
99
+ }
100
+
72
101
  for (const file of abisFiles) {
73
102
  if (path.extname(file) === '.json') {
74
- if (!fs.existsSync(typeFolder)) {
75
- fs.mkdirSync(typeFolder)
103
+ if (!fs.existsSync(targetPath)) {
104
+ fs.mkdirSync(targetPath, { recursive: true })
76
105
  }
77
- const idlContent = fs.readFileSync(path.join(abisFolder, file), 'utf-8')
106
+ const idlContent = fs.readFileSync(path.join(abisDir, file), 'utf-8')
78
107
  const idlObj = JSON.parse(idlContent)
79
108
  const idlName = idlObj.name
80
- const idlFile = path.join(typeFolder, idlName + '.ts')
109
+ const idlFile = path.join(targetPath, idlName + '.ts')
81
110
  fs.writeFileSync(idlFile, `export const ${idlName}_idl = ${idlContent}`)
82
- fs.writeFileSync(path.join(typeFolder, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj))
111
+ fs.writeFileSync(path.join(targetPath, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj))
83
112
  }
84
113
  }
85
114
  }
package/src/cli/cli.ts CHANGED
@@ -6,7 +6,7 @@ import fs from 'fs'
6
6
  import path from 'path'
7
7
 
8
8
  import yaml from 'js-yaml'
9
- import { EVM, finalizeHost, FinalizeProjectName, SentioProjectConfig } from './config'
9
+ import { finalizeHost, FinalizeProjectName, SentioProjectConfig } from './config'
10
10
  import { uploadFile } from './upload'
11
11
  import chalk from 'chalk'
12
12
  import { buildProcessor } from './build'
@@ -35,7 +35,7 @@ if (mainOptions.command === 'login') {
35
35
  // TODO move them to their own modules
36
36
 
37
37
  // Process configs
38
- let processorConfig: SentioProjectConfig = { host: '', project: '', source: '', build: true, targets: [] }
38
+ let processorConfig: SentioProjectConfig = { host: '', project: '', source: '', build: true }
39
39
  // Fist step, read from project yaml file
40
40
  try {
41
41
  console.log(chalk.blue('Loading Process config'))
@@ -68,14 +68,14 @@ if (mainOptions.command === 'login') {
68
68
  if (!processorConfig.source) {
69
69
  processorConfig.source = 'src/processor.ts'
70
70
  }
71
- if (!processorConfig.targets) {
72
- console.warn('targets is not defined, use EVM as the default target')
73
- processorConfig.targets = []
74
- }
75
- if (processorConfig.targets.length === 0) {
76
- // By default evm
77
- processorConfig.targets.push({ chain: EVM })
78
- }
71
+ // if (!processorConfig.targets) {
72
+ // console.warn('targets is not defined, use EVM as the default target')
73
+ // processorConfig.targets = []
74
+ // }
75
+ // if (processorConfig.targets.length === 0) {
76
+ // // By default evm
77
+ // processorConfig.targets.push({ chain: EVM })
78
+ // }
79
79
  } catch (e) {
80
80
  console.error(e)
81
81
  process.exit(1)
@@ -141,9 +141,9 @@ if (mainOptions.command === 'login') {
141
141
  uploadFile(processorConfig, apiOverride)
142
142
  }
143
143
  } else if (mainOptions.command === 'build') {
144
- buildProcessor(false, processorConfig.targets)
144
+ buildProcessor(false)
145
145
  } else if (mainOptions.command === 'gen') {
146
- buildProcessor(true, processorConfig.targets)
146
+ buildProcessor(true)
147
147
  } else {
148
148
  usage()
149
149
  }
package/src/cli/config.ts CHANGED
@@ -3,7 +3,7 @@ export interface SentioProjectConfig {
3
3
  host: string
4
4
  source: string
5
5
  build: boolean
6
- targets: Target[]
6
+ // targets: Target[]
7
7
  }
8
8
 
9
9
  export function getFinalizedHost(host: string): string {
@@ -36,11 +36,11 @@ export function FinalizeProjectName(config: SentioProjectConfig, owner: string |
36
36
  }
37
37
  }
38
38
 
39
- export interface Target {
40
- chain: string
41
- abisDir?: string
42
- }
43
-
44
- // Supported target chain, lower case
45
- export const EVM = 'evm'
46
- export const SOLANA = 'solana'
39
+ // export interface Target {
40
+ // chain: string
41
+ // abisDir?: string
42
+ // }
43
+ //
44
+ // // Supported target chain, lower case
45
+ // export const EVM = 'evm'
46
+ // export const SOLANA = 'solana'
package/src/cli/upload.ts CHANGED
@@ -24,7 +24,7 @@ async function createProject(options: SentioProjectConfig, apiKey: string) {
24
24
 
25
25
  export async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {
26
26
  if (options.build) {
27
- await buildProcessor(false, options.targets)
27
+ await buildProcessor(false)
28
28
  }
29
29
 
30
30
  console.log(chalk.blue('Prepare to upload'))
@@ -26,6 +26,7 @@ module.exports = {
26
26
  mode: 'production',
27
27
  externals: [
28
28
  {
29
+ aptos: 'commonjs2 aptos',
29
30
  ethers: 'commonjs2 ethers',
30
31
  bs58: 'commonjs2 bs58',
31
32
  "bignumber.js": 'commonjs2 bignumber.js',
@@ -2,7 +2,7 @@
2
2
 
3
3
  import commandLineArgs from 'command-line-args'
4
4
  import { createServer } from 'nice-grpc'
5
- import { ProcessorDefinition } from './gen/processor/protos/processor'
5
+ import { ProcessorDefinition } from './gen'
6
6
  import { ProcessorServiceImpl } from './service'
7
7
  import { setProvider } from './provider'
8
8
 
package/src/service.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Block, Log } from '@ethersproject/abstract-provider'
2
2
  import { CallContext, ServerError, Status } from 'nice-grpc'
3
- import { APTOS_TESTNET_ID, SOL_MAINMET_ID, SUI_DEVNET_ID } from './utils/chain'
3
+ import { SOL_MAINMET_ID, SUI_DEVNET_ID } from './utils/chain'
4
4
 
5
5
  import {
6
6
  AptosCallHandlerConfig,
@@ -212,7 +212,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
212
212
  processorType: USER_PROCESSOR,
213
213
  contract: {
214
214
  name: aptosProcessor.name,
215
- chainId: APTOS_TESTNET_ID,
215
+ chainId: aptosProcessor.getChainId(),
216
216
  address: aptosProcessor.config.address,
217
217
  abi: '',
218
218
  },
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { codeGenAptosProcessor, codeGenSolanaProcessor } from './cli/build'
4
+ import path from 'path'
5
+
6
+ if (process.argv.length > 3) {
7
+ const abisDir = process.argv[2]
8
+ const targetDir = process.argv[3]
9
+ codeGenAptosProcessor(path.join(abisDir, 'aptos'), path.join(targetDir, 'aptos'))
10
+ codeGenSolanaProcessor(path.join(abisDir, 'solana'), path.join(targetDir, 'solana'))
11
+ } else {
12
+ console.error('Not enough argument')
13
+ process.exit(1)
14
+ }