@typemove/aptos 1.0.0-rc.22 → 1.0.0-rc.23

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/Readme.md ADDED
@@ -0,0 +1,45 @@
1
+ # Typemove
2
+ Generate TypeScript bindings for Aptos contracts.
3
+ ## Features
4
+ - Code generation for Aptos smart contract based on ABI
5
+ - Typesafe encode/decoding, object filtering, transaction building, etc
6
+ - Automatically manage depended modules
7
+ ## Usage
8
+ ### Install package
9
+ ```shell
10
+ yarn add @typemove/aptos
11
+ ```
12
+ or
13
+
14
+ ```shell
15
+ pnpm add @typemove/aptos
16
+ ```
17
+
18
+ ### Code Generation
19
+ ```typescript
20
+ yarn typemove-aptos <abi-address | path-of-entry-abi-file> <path-of-target-ts-directory> <testnet|mainnet>
21
+ ```
22
+
23
+ e.g.
24
+ ```typescript
25
+ yarn typemove-aptos 0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af ./src/types mainnet
26
+ ```
27
+
28
+ ### Decode object
29
+ ```typescript
30
+ import { defaultMoveCoder } from '@typemove/aptos'
31
+ import { stable_pool } from "./types/0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af";
32
+
33
+ const pool = await defaultMoveCoder().decodedType(stable_pool.StablePool.type(), object)
34
+ ```
35
+
36
+ Checkout our [tests](./src/tests/move-coder.test.ts) for more examples。
37
+
38
+ ### View function
39
+ ```typescript
40
+ const aptosClient = new AptosClient("https://fullnode.mainnet.aptoslabs.com")
41
+ const [lpName] = await stable_pool.view.lpNameById(client, { type_arguments: [], arguments: [3n] })
42
+ const [poolBalances, weights, supply] = await stable_pool.view.poolInfo(client, { type_arguments: [], arguments: [lpName] })
43
+ ```
44
+
45
+ Checkout our [tests](./src/tests/move-call.test.ts) for more examples。
@@ -1,7 +1,10 @@
1
1
  // #!/usr/bin/env node
2
2
  import { codegen } from './codegen.js';
3
+ import { AptosClient } from 'aptos';
4
+ import * as path from 'path';
5
+ import * as fs from 'fs';
3
6
  if (process.argv.length > 3) {
4
- const abisDir = process.argv[2];
7
+ let abisDir = process.argv[2];
5
8
  const targetDir = process.argv[3];
6
9
  let endpoint = process.argv[4];
7
10
  if (!endpoint || endpoint == 'mainnet') {
@@ -10,6 +13,16 @@ if (process.argv.length > 3) {
10
13
  if (endpoint == 'testnet') {
11
14
  endpoint = 'https://testnet.aptoslabs.com/';
12
15
  }
16
+ const aptosClient = new AptosClient(endpoint);
17
+ if (abisDir.startsWith('0x')) {
18
+ const abiAddress = abisDir;
19
+ const abi = await aptosClient.getAccountModules(abiAddress);
20
+ abisDir = path.join(targetDir, '..', 'abis');
21
+ if (!fs.existsSync(abisDir)) {
22
+ fs.mkdirSync(abisDir, { recursive: true });
23
+ }
24
+ fs.writeFileSync(path.join(abisDir, abiAddress + '.json'), JSON.stringify(abi, null, 2));
25
+ }
13
26
  await codegen(abisDir, targetDir, endpoint, true);
14
27
  }
15
28
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/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;IACjC,IAAI,QAAQ,GAAuB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAClD,IAAI,CAAC,QAAQ,IAAI,QAAQ,IAAI,SAAS,EAAE;QACtC,QAAQ,GAAG,gCAAgC,CAAA;KAC5C;IACD,IAAI,QAAQ,IAAI,SAAS,EAAE;QACzB,QAAQ,GAAG,gCAAgC,CAAA;KAC5C;IAED,MAAM,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,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3B,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;SAC3C;QACD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;KACzF;IAED,MAAM,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;CAClD;KAAM;IACL,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;CAChB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typemove/aptos",
3
- "version": "1.0.0-rc.22",
3
+ "version": "1.0.0-rc.23",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -15,7 +15,6 @@
15
15
  },
16
16
  "main": "./dist/cjs/index.js",
17
17
  "module": "./dist/esm/index.js",
18
- "types": "./dist/cjs/index.d.ts",
19
18
  "bin": {
20
19
  "typemove-aptos": "./dist/esm/codegen/run.js"
21
20
  },
@@ -25,11 +24,12 @@
25
24
  "!**/*.test.{js,ts}",
26
25
  "!{dist,src}/*/tests"
27
26
  ],
27
+ "types": "./dist/cjs/index.d.ts",
28
28
  "dependencies": {
29
29
  "aptos": "^1.16.0",
30
30
  "chalk": "^5.2.0",
31
31
  "radash": "^11.0.0",
32
- "@typemove/move": "1.0.0-rc.22"
32
+ "@typemove/move": "1.0.0-rc.23"
33
33
  },
34
34
  "url": "https://github.com/sentioxyz/typemove",
35
35
  "scripts": {
@@ -37,7 +37,8 @@
37
37
  "build:all": "pnpm --filter=$(node -p \"require('./package.json').name\")... build",
38
38
  "build:cjs": "tsc --project tsconfig.cjs.json && cp ../../package.cjs.json ./dist/cjs/package.json",
39
39
  "gen": "pnpm gen:test && ts-node-esm src/codegen/run.ts src/abis src/builtin",
40
- "gen:test": "ts-node-esm src/codegen/run.ts src/tests/abis/testnet src/tests/types/testnet testnet",
40
+ "gen:test": "ts-node-esm src/codegen/run.ts src/tests/abis src/tests/types mainnet",
41
+ "gen-with-address": "ts-node-esm src/codegen/run.ts 0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af ./src/tests/types mainnet\n",
41
42
  "test": "NODE_OPTIONS=--experimental-vm-modules pnpm jest"
42
43
  }
43
44
  }
@@ -1,9 +1,12 @@
1
1
  // #!/usr/bin/env node
2
2
 
3
3
  import { codegen } from './codegen.js'
4
+ import { AptosClient } from 'aptos'
5
+ import * as path from 'path'
6
+ import * as fs from 'fs'
4
7
 
5
8
  if (process.argv.length > 3) {
6
- const abisDir = process.argv[2]
9
+ let abisDir = process.argv[2]
7
10
  const targetDir = process.argv[3]
8
11
  let endpoint: string | undefined = process.argv[4]
9
12
  if (!endpoint || endpoint == 'mainnet') {
@@ -12,6 +15,16 @@ if (process.argv.length > 3) {
12
15
  if (endpoint == 'testnet') {
13
16
  endpoint = 'https://testnet.aptoslabs.com/'
14
17
  }
18
+ const aptosClient = new AptosClient(endpoint)
19
+ if (abisDir.startsWith('0x')) {
20
+ const abiAddress = abisDir
21
+ const abi = await aptosClient.getAccountModules(abiAddress)
22
+ abisDir = path.join(targetDir, '..', 'abis')
23
+ if (!fs.existsSync(abisDir)) {
24
+ fs.mkdirSync(abisDir, { recursive: true })
25
+ }
26
+ fs.writeFileSync(path.join(abisDir, abiAddress + '.json'), JSON.stringify(abi, null, 2))
27
+ }
15
28
 
16
29
  await codegen(abisDir, targetDir, endpoint, true)
17
30
  } else {