@typemove/sui 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 +128 -0
- package/package.json +2 -2
package/Readme.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Typemove
|
|
2
|
+
Generate TypeScript bindings for Sui contracts.
|
|
3
|
+
## Features
|
|
4
|
+
- Code generation for SUI smart contract based on ABI
|
|
5
|
+
- Typesafe encode/decoding, object filtering, transaction building, etc
|
|
6
|
+
- Automatically manage depended modules
|
|
7
|
+
- BCS schema (WIP)
|
|
8
|
+
## Usage
|
|
9
|
+
### Install package
|
|
10
|
+
```shell
|
|
11
|
+
yarn add @typemove/sui
|
|
12
|
+
```
|
|
13
|
+
or
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
pnpm add @typemove/sui
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Code Generation
|
|
20
|
+
```typescript
|
|
21
|
+
yarn typemove-sui <path-of-abi-file> <path-of-target-ts-directory> <testnet|mainnet>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Decode Object
|
|
25
|
+
```typescript
|
|
26
|
+
import { defaultMoveCoder } from '../move-coder.js'
|
|
27
|
+
import { single_collateral } from './types/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.js'
|
|
28
|
+
|
|
29
|
+
const res = await defaultMoveCoder().decodedType(
|
|
30
|
+
data,
|
|
31
|
+
single_collateral.Info.type()
|
|
32
|
+
)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
<details>
|
|
36
|
+
<summary>Without TypeMove</summary>
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
export interface Info {
|
|
40
|
+
index: string;
|
|
41
|
+
creator: string;
|
|
42
|
+
createTsMs: string;
|
|
43
|
+
round: string;
|
|
44
|
+
deliveryInfo?: DeliveryInfo;
|
|
45
|
+
}
|
|
46
|
+
export interface DeliveryInfo {
|
|
47
|
+
round: string;
|
|
48
|
+
price: string;
|
|
49
|
+
size: string;
|
|
50
|
+
premium: string;
|
|
51
|
+
tsMs: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let deliveryInfo: DeliveryInfo | undefined =
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
data.content.fields.info.fields.delivery_info
|
|
57
|
+
? {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
round: data.content.fields.info.fields.delivery_info.fields.round,
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
price: data.content.fields.info.fields.delivery_info.fields.price,
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
size: data.content.fields.info.fields.delivery_info.fields.size,
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
premium: data.content.fields.info.fields.delivery_info.fields.premium,
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
tsMs: data.content.fields.info.fields.delivery_info.fields.ts_ms,
|
|
68
|
+
}
|
|
69
|
+
: undefined;
|
|
70
|
+
let info: Info = {
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
index: data.content.fields.info.fields.index,
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
creator: data.content.fields.info.fields.creator,
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
createTsMs: data.content.fields.info.fields.create_ts_ms,
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
round: data.content.fields.info.fields.round,
|
|
79
|
+
deliveryInfo,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
</details>
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
### Decode dynamic fields
|
|
87
|
+
Get objects with specified type from a list of dynamic objects, and access field with fully typed object
|
|
88
|
+
```typescript
|
|
89
|
+
const decodedObjects = await coder.getDynamicFields(
|
|
90
|
+
objects,
|
|
91
|
+
BUILTIN_TYPES.U64_TYPE,
|
|
92
|
+
single_collateral.PortfolioVault.type()
|
|
93
|
+
)
|
|
94
|
+
console.log(decodedObjects[0].value.info.delivery_info?.price)
|
|
95
|
+
```
|
|
96
|
+
IDE could infer result type correctly.
|
|
97
|
+

|
|
98
|
+
|
|
99
|
+
### Building transaction
|
|
100
|
+
```typescript
|
|
101
|
+
import { clob_v2 } from './types/0xdee9.js'
|
|
102
|
+
|
|
103
|
+
clob_v2.builder.getMarketPrice(
|
|
104
|
+
tx,
|
|
105
|
+
['0x5d2687b354f2ad4bce90c828974346d91ac1787ff170e5d09cb769e5dbcdefae'],
|
|
106
|
+
[
|
|
107
|
+
'0x2::sui::SUI',
|
|
108
|
+
'0x219d80b1be5d586ff3bdbfeaf4d051ec721442c3a6498a3222773c6945a73d9f::usdt::USDT',
|
|
109
|
+
]
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
const result = await provider.devInspectTransactionBlock({
|
|
113
|
+
transactionBlock: tx
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
If you just want to call `devInspectTransactionBlock` for single function, you can simply do
|
|
117
|
+
```typescript
|
|
118
|
+
import { clob_v2 } from './types/0xdee9.js'
|
|
119
|
+
|
|
120
|
+
await clob_v2.view.getMarketPrice(provider,
|
|
121
|
+
['0x5d2687b354f2ad4bce90c828974346d91ac1787ff170e5d09cb769e5dbcdefae'],
|
|
122
|
+
[
|
|
123
|
+
'0x2::sui::SUI',
|
|
124
|
+
'0x219d80b1be5d586ff3bdbfeaf4d051ec721442c3a6498a3222773c6945a73d9f::usdt::USDT',
|
|
125
|
+
])
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Checkout our [example](./examples/sui) for full codes。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typemove/sui",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.23",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@mysten/sui.js": "^0.39.0",
|
|
31
31
|
"chalk": "^5.2.0",
|
|
32
32
|
"radash": "^11.0.0",
|
|
33
|
-
"@typemove/move": "1.0.0-rc.
|
|
33
|
+
"@typemove/move": "1.0.0-rc.23"
|
|
34
34
|
},
|
|
35
35
|
"url": "https://github.com/sentioxyz/typemove",
|
|
36
36
|
"scripts": {
|