@sentio/cli 2.3.0-rc.1 → 2.3.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.
@@ -7,8 +7,7 @@ import { codegen } from './build.js';
7
7
  // @ts-ignore no types
8
8
  import { init } from 'etherscan-api';
9
9
  import { AptosClient } from 'aptos-sdk';
10
- import * as console from 'console';
11
- import * as process from 'process';
10
+ import { JsonRpcProvider } from '@mysten/sui.js';
12
11
  export async function runAdd(argv) {
13
12
  const optionDefinitions = [
14
13
  {
@@ -22,7 +21,7 @@ export async function runAdd(argv) {
22
21
  alias: 'c',
23
22
  type: String,
24
23
  defaultValue: 'homestead',
25
- description: 'Chain identifier, can be: homestead/mainnet,goerli,arbitrum,avalanche, or apots, aptos/testnet',
24
+ description: 'Chain identifier, can be: homestead/mainnet,goerli,arbitrum,avalanche, apots, aptos/testnet and sui, sui/testnet',
26
25
  },
27
26
  {
28
27
  name: 'address',
@@ -30,12 +29,18 @@ export async function runAdd(argv) {
30
29
  description: 'Address of the contract',
31
30
  type: String,
32
31
  },
32
+ {
33
+ name: 'name',
34
+ alias: 'n',
35
+ description: 'File name for the downloaded contract, if empty, use address as file name',
36
+ type: String,
37
+ },
33
38
  ];
34
- const options = commandLineArgs(optionDefinitions, { argv });
39
+ const options = commandLineArgs(optionDefinitions, { argv, partial: true });
35
40
  const usage = commandLineUsage([
36
41
  {
37
42
  header: "Add contract's ABI to the project",
38
- content: 'sentio add [--chain <chain>] <address>',
43
+ content: 'sentio add [--chain <chain> --name <name>] <address>',
39
44
  },
40
45
  {
41
46
  header: 'Options',
@@ -50,10 +55,12 @@ export async function runAdd(argv) {
50
55
  const address = options.address;
51
56
  if (!address.startsWith('0x')) {
52
57
  console.error(chalk.red('Address must start with 0x'));
58
+ console.log(usage);
53
59
  process.exit(1);
54
60
  }
55
61
  let ethApi;
56
62
  let aptosClient;
63
+ let suiClient;
57
64
  switch (chain) {
58
65
  case 'aptos':
59
66
  aptosClient = new AptosClient('https://mainnet.aptoslabs.com/');
@@ -61,6 +68,13 @@ export async function runAdd(argv) {
61
68
  case 'aptos/testnet':
62
69
  aptosClient = new AptosClient('https://testnet.aptoslabs.com/');
63
70
  break;
71
+ case 'sui':
72
+ throw Error('SUI mainnet is not support yet, try sui/testnet');
73
+ // suiClient = new JsonRpcProvider('https://fullnode.mainnet.sui.io/')
74
+ // break
75
+ case 'sui/testnet':
76
+ suiClient = new JsonRpcProvider('https://fullnode.testnet.sui.io/');
77
+ break;
64
78
  case 'mainnet':
65
79
  case 'homestead':
66
80
  ethApi = init();
@@ -69,10 +83,21 @@ export async function runAdd(argv) {
69
83
  ethApi = init(undefined, chain);
70
84
  }
71
85
  const baseErrMsg = chalk.red(`Failed to automatic download contract ${address} from ${chain}, please manually download abi and put it into abis/eth directory`);
86
+ const filename = options.name ? options.name : address;
72
87
  if (aptosClient) {
73
88
  try {
74
89
  const module = await aptosClient.getAccountModules(address);
75
- writeToDirectory(JSON.stringify(module), chain, address);
90
+ writeToDirectory(module, chain, filename);
91
+ }
92
+ catch (e) {
93
+ console.error(baseErrMsg, e);
94
+ process.exit(1);
95
+ }
96
+ }
97
+ if (suiClient) {
98
+ try {
99
+ const module = await suiClient.getNormalizedMoveModulesByPackage(address);
100
+ writeToDirectory(module, chain, filename);
76
101
  }
77
102
  catch (e) {
78
103
  console.error(baseErrMsg, e);
@@ -85,7 +110,7 @@ export async function runAdd(argv) {
85
110
  if (resp.status !== '1') {
86
111
  throw Error(resp.message);
87
112
  }
88
- writeToDirectory(resp.result, chain, address);
113
+ writeToDirectory(resp.result, chain, filename);
89
114
  }
90
115
  catch (e) {
91
116
  console.error(baseErrMsg, e);
@@ -96,8 +121,22 @@ export async function runAdd(argv) {
96
121
  await codegen();
97
122
  }
98
123
  }
99
- function writeToDirectory(data, chain, name) {
100
- const output = path.join('abis', chain, name + '.json');
124
+ function writeToDirectory(obj, chain, name) {
125
+ if (typeof obj === 'string') {
126
+ obj = JSON.parse(obj);
127
+ }
128
+ const data = JSON.stringify(obj, null, 2);
129
+ let subpath = chain;
130
+ switch (chain) {
131
+ case 'aptos':
132
+ case 'aptos/testnet':
133
+ case 'sui':
134
+ case 'sui/testnet':
135
+ break;
136
+ default:
137
+ subpath = 'eth';
138
+ }
139
+ const output = path.join('abis', subpath, name + '.json');
101
140
  fs.mkdirSync(path.dirname(output), { recursive: true });
102
141
  fs.writeFileSync(output, data);
103
142
  console.log(chalk.green('ABI has been downloaded to', output));
@@ -1 +1 @@
1
- {"version":3,"file":"run-add.js","sourceRoot":"","sources":["../../src/commands/run-add.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,sBAAsB;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAElC,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAc;IACzC,MAAM,iBAAiB,GAAG;QACxB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,2BAA2B;SACzC;QACD;YACE,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,MAAM;YACZ,YAAY,EAAE,WAAW;YACzB,WAAW,EAAE,gGAAgG;SAC9G;QACD;YACE,IAAI,EAAE,SAAS;YACf,aAAa,EAAE,IAAI;YACnB,WAAW,EAAE,yBAAyB;YACtC,IAAI,EAAE,MAAM;SACb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C,KAAK,CAAC,4BAA4B,EAAE,MAAM,CAAC,CAAC,CAAA;AAChE,CAAC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport path from 'path'\nimport fs from 'fs-extra'\nimport chalk from 'chalk'\n\nimport { codegen } from './build.js'\n\n// @ts-ignore no types\nimport { init } from 'etherscan-api'\nimport { AptosClient } from 'aptos-sdk'\nimport * as console from 'console'\nimport * as process from 'process'\n\nexport async function runAdd(argv: string[]) {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'chain',\n alias: 'c',\n type: String,\n defaultValue: 'homestead',\n description: 'Chain identifier, can be: homestead/mainnet,goerli,arbitrum,avalanche, or apots, aptos/testnet',\n },\n {\n name: 'address',\n defaultOption: true,\n description: 'Address of the contract',\n type: String,\n },\n ]\n\n const options = commandLineArgs(optionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: \"Add contract's ABI to the project\",\n content: 'sentio add [--chain <chain>] <address>',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n\n if (options.help || !options.address) {\n console.log(usage)\n } else {\n const chain: string = options['chain'].toLowerCase()\n const address: string = options.address\n if (!address.startsWith('0x')) {\n console.error(chalk.red('Address must start with 0x'))\n process.exit(1)\n }\n\n let ethApi\n let aptosClient: AptosClient | undefined\n switch (chain) {\n case 'aptos':\n aptosClient = new AptosClient('https://mainnet.aptoslabs.com/')\n break\n case 'aptos/testnet':\n aptosClient = new AptosClient('https://testnet.aptoslabs.com/')\n break\n case 'mainnet':\n case 'homestead':\n ethApi = init()\n break\n default:\n ethApi = init(undefined, chain)\n }\n\n const baseErrMsg = chalk.red(\n `Failed to automatic download contract ${address} from ${chain}, please manually download abi and put it into abis/eth directory`\n )\n if (aptosClient) {\n try {\n const module = await aptosClient.getAccountModules(address)\n writeToDirectory(JSON.stringify(module), chain, address)\n } catch (e) {\n console.error(baseErrMsg, e)\n process.exit(1)\n }\n }\n\n if (ethApi) {\n try {\n const resp = await ethApi.contract.getabi(address)\n if (resp.status !== '1') {\n throw Error(resp.message)\n }\n writeToDirectory(resp.result, chain, address)\n } catch (e) {\n console.error(baseErrMsg, e)\n process.exit(1)\n }\n }\n // Run gen\n await codegen()\n }\n}\n\nfunction writeToDirectory(data: string, chain: string, name: string) {\n const output = path.join('abis', chain, name + '.json')\n fs.mkdirSync(path.dirname(output), { recursive: true })\n fs.writeFileSync(output, data)\n console.log(chalk.green('ABI has been downloaded to', output))\n}\n"]}
1
+ {"version":3,"file":"run-add.js","sourceRoot":"","sources":["../../src/commands/run-add.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,sBAAsB;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAc;IACzC,MAAM,iBAAiB,GAAG;QACxB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,2BAA2B;SACzC;QACD;YACE,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,MAAM;YACZ,YAAY,EAAE,WAAW;YACzB,WAAW,EACT,kHAAkH;SACrH;QACD;YACE,IAAI,EAAE,SAAS;YACf,aAAa,EAAE,IAAI;YACnB,WAAW,EAAE,yBAAyB;YACtC,IAAI,EAAE,MAAM;SACb;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AAC,CAAA;AAChE,CAAC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport path from 'path'\nimport fs from 'fs-extra'\nimport chalk from 'chalk'\n\nimport { codegen } from './build.js'\n\n// @ts-ignore no types\nimport { init } from 'etherscan-api'\nimport { AptosClient } from 'aptos-sdk'\nimport { JsonRpcProvider } from '@mysten/sui.js'\n\nexport async function runAdd(argv: string[]) {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'chain',\n alias: 'c',\n type: String,\n defaultValue: 'homestead',\n description:\n 'Chain identifier, can be: homestead/mainnet,goerli,arbitrum,avalanche, apots, aptos/testnet and sui, sui/testnet',\n },\n {\n name: 'address',\n defaultOption: true,\n description: 'Address of the contract',\n type: String,\n },\n {\n name: 'name',\n alias: 'n',\n description: 'File name for the downloaded contract, if empty, use address as file name',\n type: String,\n },\n ]\n\n const options = commandLineArgs(optionDefinitions, { argv, partial: true })\n const usage = commandLineUsage([\n {\n header: \"Add contract's ABI to the project\",\n content: 'sentio add [--chain <chain> --name <name>] <address>',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n\n if (options.help || !options.address) {\n console.log(usage)\n } else {\n const chain: string = options['chain'].toLowerCase()\n const address: string = options.address\n if (!address.startsWith('0x')) {\n console.error(chalk.red('Address must start with 0x'))\n console.log(usage)\n process.exit(1)\n }\n\n let ethApi\n let aptosClient: AptosClient | undefined\n let suiClient: JsonRpcProvider | undefined\n switch (chain) {\n case 'aptos':\n aptosClient = new AptosClient('https://mainnet.aptoslabs.com/')\n break\n case 'aptos/testnet':\n aptosClient = new AptosClient('https://testnet.aptoslabs.com/')\n break\n case 'sui':\n throw Error('SUI mainnet is not support yet, try sui/testnet')\n // suiClient = new JsonRpcProvider('https://fullnode.mainnet.sui.io/')\n // break\n case 'sui/testnet':\n suiClient = new JsonRpcProvider('https://fullnode.testnet.sui.io/')\n break\n case 'mainnet':\n case 'homestead':\n ethApi = init()\n break\n default:\n ethApi = init(undefined, chain)\n }\n\n const baseErrMsg = chalk.red(\n `Failed to automatic download contract ${address} from ${chain}, please manually download abi and put it into abis/eth directory`\n )\n\n const filename = options.name ? options.name : address\n\n if (aptosClient) {\n try {\n const module = await aptosClient.getAccountModules(address)\n writeToDirectory(module, chain, filename)\n } catch (e) {\n console.error(baseErrMsg, e)\n process.exit(1)\n }\n }\n if (suiClient) {\n try {\n const module = await suiClient.getNormalizedMoveModulesByPackage(address)\n writeToDirectory(module, chain, filename)\n } catch (e) {\n console.error(baseErrMsg, e)\n process.exit(1)\n }\n }\n\n if (ethApi) {\n try {\n const resp = await ethApi.contract.getabi(address)\n if (resp.status !== '1') {\n throw Error(resp.message)\n }\n writeToDirectory(resp.result, chain, filename)\n } catch (e) {\n console.error(baseErrMsg, e)\n process.exit(1)\n }\n }\n // Run gen\n await codegen()\n }\n}\n\nfunction writeToDirectory(obj: object | string, chain: string, name: string) {\n if (typeof obj === 'string') {\n obj = JSON.parse(obj)\n }\n const data = JSON.stringify(obj, null, 2)\n let subpath = chain\n switch (chain) {\n case 'aptos':\n case 'aptos/testnet':\n case 'sui':\n case 'sui/testnet':\n break\n default:\n subpath = 'eth'\n }\n\n const output = path.join('abis', subpath, name + '.json')\n fs.mkdirSync(path.dirname(output), { recursive: true })\n fs.writeFileSync(output, data)\n console.log(chalk.green('ABI has been downloaded to', output))\n}\n"]}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "license": "Apache-2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
- "version": "2.3.0-rc.1",
6
+ "version": "2.3.0",
7
7
  "scripts": {
8
8
  "compile": "tsc",
9
9
  "build": "yarn compile",
@@ -14,6 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@jest/types": "^29.4.1",
17
+ "@mysten/sui.js": "npm:@sentio/sui.js@0.17.0",
17
18
  "@types/jest": "^29.0.0",
18
19
  "@types/node": "^18.11.18",
19
20
  "aptos-sdk": "npm:@sentio/aptos@^1.6.0",
@@ -9,8 +9,7 @@ import { codegen } from './build.js'
9
9
  // @ts-ignore no types
10
10
  import { init } from 'etherscan-api'
11
11
  import { AptosClient } from 'aptos-sdk'
12
- import * as console from 'console'
13
- import * as process from 'process'
12
+ import { JsonRpcProvider } from '@mysten/sui.js'
14
13
 
15
14
  export async function runAdd(argv: string[]) {
16
15
  const optionDefinitions = [
@@ -25,7 +24,8 @@ export async function runAdd(argv: string[]) {
25
24
  alias: 'c',
26
25
  type: String,
27
26
  defaultValue: 'homestead',
28
- description: 'Chain identifier, can be: homestead/mainnet,goerli,arbitrum,avalanche, or apots, aptos/testnet',
27
+ description:
28
+ 'Chain identifier, can be: homestead/mainnet,goerli,arbitrum,avalanche, apots, aptos/testnet and sui, sui/testnet',
29
29
  },
30
30
  {
31
31
  name: 'address',
@@ -33,13 +33,19 @@ export async function runAdd(argv: string[]) {
33
33
  description: 'Address of the contract',
34
34
  type: String,
35
35
  },
36
+ {
37
+ name: 'name',
38
+ alias: 'n',
39
+ description: 'File name for the downloaded contract, if empty, use address as file name',
40
+ type: String,
41
+ },
36
42
  ]
37
43
 
38
- const options = commandLineArgs(optionDefinitions, { argv })
44
+ const options = commandLineArgs(optionDefinitions, { argv, partial: true })
39
45
  const usage = commandLineUsage([
40
46
  {
41
47
  header: "Add contract's ABI to the project",
42
- content: 'sentio add [--chain <chain>] <address>',
48
+ content: 'sentio add [--chain <chain> --name <name>] <address>',
43
49
  },
44
50
  {
45
51
  header: 'Options',
@@ -54,11 +60,13 @@ export async function runAdd(argv: string[]) {
54
60
  const address: string = options.address
55
61
  if (!address.startsWith('0x')) {
56
62
  console.error(chalk.red('Address must start with 0x'))
63
+ console.log(usage)
57
64
  process.exit(1)
58
65
  }
59
66
 
60
67
  let ethApi
61
68
  let aptosClient: AptosClient | undefined
69
+ let suiClient: JsonRpcProvider | undefined
62
70
  switch (chain) {
63
71
  case 'aptos':
64
72
  aptosClient = new AptosClient('https://mainnet.aptoslabs.com/')
@@ -66,6 +74,13 @@ export async function runAdd(argv: string[]) {
66
74
  case 'aptos/testnet':
67
75
  aptosClient = new AptosClient('https://testnet.aptoslabs.com/')
68
76
  break
77
+ case 'sui':
78
+ throw Error('SUI mainnet is not support yet, try sui/testnet')
79
+ // suiClient = new JsonRpcProvider('https://fullnode.mainnet.sui.io/')
80
+ // break
81
+ case 'sui/testnet':
82
+ suiClient = new JsonRpcProvider('https://fullnode.testnet.sui.io/')
83
+ break
69
84
  case 'mainnet':
70
85
  case 'homestead':
71
86
  ethApi = init()
@@ -77,10 +92,22 @@ export async function runAdd(argv: string[]) {
77
92
  const baseErrMsg = chalk.red(
78
93
  `Failed to automatic download contract ${address} from ${chain}, please manually download abi and put it into abis/eth directory`
79
94
  )
95
+
96
+ const filename = options.name ? options.name : address
97
+
80
98
  if (aptosClient) {
81
99
  try {
82
100
  const module = await aptosClient.getAccountModules(address)
83
- writeToDirectory(JSON.stringify(module), chain, address)
101
+ writeToDirectory(module, chain, filename)
102
+ } catch (e) {
103
+ console.error(baseErrMsg, e)
104
+ process.exit(1)
105
+ }
106
+ }
107
+ if (suiClient) {
108
+ try {
109
+ const module = await suiClient.getNormalizedMoveModulesByPackage(address)
110
+ writeToDirectory(module, chain, filename)
84
111
  } catch (e) {
85
112
  console.error(baseErrMsg, e)
86
113
  process.exit(1)
@@ -93,7 +120,7 @@ export async function runAdd(argv: string[]) {
93
120
  if (resp.status !== '1') {
94
121
  throw Error(resp.message)
95
122
  }
96
- writeToDirectory(resp.result, chain, address)
123
+ writeToDirectory(resp.result, chain, filename)
97
124
  } catch (e) {
98
125
  console.error(baseErrMsg, e)
99
126
  process.exit(1)
@@ -104,8 +131,23 @@ export async function runAdd(argv: string[]) {
104
131
  }
105
132
  }
106
133
 
107
- function writeToDirectory(data: string, chain: string, name: string) {
108
- const output = path.join('abis', chain, name + '.json')
134
+ function writeToDirectory(obj: object | string, chain: string, name: string) {
135
+ if (typeof obj === 'string') {
136
+ obj = JSON.parse(obj)
137
+ }
138
+ const data = JSON.stringify(obj, null, 2)
139
+ let subpath = chain
140
+ switch (chain) {
141
+ case 'aptos':
142
+ case 'aptos/testnet':
143
+ case 'sui':
144
+ case 'sui/testnet':
145
+ break
146
+ default:
147
+ subpath = 'eth'
148
+ }
149
+
150
+ const output = path.join('abis', subpath, name + '.json')
109
151
  fs.mkdirSync(path.dirname(output), { recursive: true })
110
152
  fs.writeFileSync(output, data)
111
153
  console.log(chalk.green('ABI has been downloaded to', output))