@thalalabs/surf 0.0.13 → 0.0.14

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 (91) hide show
  1. package/.changeset/README.md +1 -1
  2. package/.github/dependabot.yml +3 -3
  3. package/.github/workflows/publish.yml +2 -2
  4. package/CHANGELOG.md +6 -0
  5. package/README.md +18 -11
  6. package/build/cjs/abi/aggregator.js +56 -74
  7. package/build/cjs/abi/aggregator.js.map +1 -1
  8. package/build/cjs/abi/aptos_coin.js +98 -125
  9. package/build/cjs/abi/aptos_coin.js.map +1 -1
  10. package/build/cjs/abi/coin.js +456 -587
  11. package/build/cjs/abi/coin.js.map +1 -1
  12. package/build/cjs/abi/event.js +66 -106
  13. package/build/cjs/abi/event.js.map +1 -1
  14. package/build/cjs/abi/fixed_point64.js +287 -320
  15. package/build/cjs/abi/fixed_point64.js.map +1 -1
  16. package/build/cjs/abi/guid.js +84 -129
  17. package/build/cjs/abi/guid.js.map +1 -1
  18. package/build/cjs/abi/optional_aggregator.js +79 -108
  19. package/build/cjs/abi/optional_aggregator.js.map +1 -1
  20. package/build/cjs/abi/table.js +131 -222
  21. package/build/cjs/abi/table.js.map +1 -1
  22. package/build/cjs/core/Client.js +6 -2
  23. package/build/cjs/core/Client.js.map +1 -1
  24. package/build/cjs/core/createEntryPayload.js.map +1 -1
  25. package/build/cjs/ensureTypes.js +11 -10
  26. package/build/cjs/ensureTypes.js.map +1 -1
  27. package/build/cjs/index.js.map +1 -1
  28. package/build/esm/abi/aggregator.js +56 -74
  29. package/build/esm/abi/aggregator.js.map +1 -1
  30. package/build/esm/abi/aptos_coin.js +98 -125
  31. package/build/esm/abi/aptos_coin.js.map +1 -1
  32. package/build/esm/abi/coin.js +456 -587
  33. package/build/esm/abi/coin.js.map +1 -1
  34. package/build/esm/abi/event.js +66 -106
  35. package/build/esm/abi/event.js.map +1 -1
  36. package/build/esm/abi/fixed_point64.js +287 -320
  37. package/build/esm/abi/fixed_point64.js.map +1 -1
  38. package/build/esm/abi/guid.js +84 -129
  39. package/build/esm/abi/guid.js.map +1 -1
  40. package/build/esm/abi/optional_aggregator.js +79 -108
  41. package/build/esm/abi/optional_aggregator.js.map +1 -1
  42. package/build/esm/abi/table.js +131 -222
  43. package/build/esm/abi/table.js.map +1 -1
  44. package/build/esm/core/Client.js +6 -2
  45. package/build/esm/core/Client.js.map +1 -1
  46. package/build/esm/core/createEntryPayload.js.map +1 -1
  47. package/build/esm/ensureTypes.js +11 -10
  48. package/build/esm/ensureTypes.js.map +1 -1
  49. package/build/esm/index.js +1 -1
  50. package/build/esm/index.js.map +1 -1
  51. package/build/types/abi/aggregator.d.ts.map +1 -1
  52. package/build/types/abi/aptos_coin.d.ts.map +1 -1
  53. package/build/types/abi/coin.d.ts.map +1 -1
  54. package/build/types/abi/event.d.ts.map +1 -1
  55. package/build/types/abi/fixed_point64.d.ts.map +1 -1
  56. package/build/types/abi/guid.d.ts.map +1 -1
  57. package/build/types/abi/optional_aggregator.d.ts.map +1 -1
  58. package/build/types/abi/table.d.ts.map +1 -1
  59. package/build/types/core/Client.d.ts.map +1 -1
  60. package/build/types/ensureTypes.d.ts.map +1 -1
  61. package/build/types/index.d.ts +2 -2
  62. package/build/types/index.d.ts.map +1 -1
  63. package/build/types/types/client/abiClient.d.ts +2 -0
  64. package/build/types/types/client/abiClient.d.ts.map +1 -1
  65. package/build/types/types/convertor/argsConvertor.d.ts +1 -1
  66. package/build/types/types/convertor/argsConvertor.d.ts.map +1 -1
  67. package/build/types/types/convertor/structConvertor.d.ts.map +1 -1
  68. package/build/types/types/moveTypes.d.ts.map +1 -1
  69. package/package.json +2 -2
  70. package/src/abi/aggregator.ts +73 -91
  71. package/src/abi/aptos_coin.ts +117 -144
  72. package/src/abi/coin.ts +646 -777
  73. package/src/abi/event.ts +83 -123
  74. package/src/abi/fixed_point64.ts +340 -373
  75. package/src/abi/guid.ts +102 -147
  76. package/src/abi/optional_aggregator.ts +103 -132
  77. package/src/abi/table.ts +181 -272
  78. package/src/core/Client.ts +6 -1
  79. package/src/core/__tests__/accountResource.test.ts +54 -14
  80. package/src/core/__tests__/createEntryPayload.test.ts +244 -250
  81. package/src/core/__tests__/createViewPayload.test.ts +44 -58
  82. package/src/core/__tests__/option.test.ts +1 -1
  83. package/src/core/__tests__/useABI.test.ts +72 -63
  84. package/src/core/__tests__/view.test.ts +76 -60
  85. package/src/core/createEntryPayload.ts +4 -3
  86. package/src/ensureTypes.ts +31 -28
  87. package/src/index.ts +8 -8
  88. package/src/types/client/abiClient.ts +2 -0
  89. package/src/types/convertor/argsConvertor.ts +1 -1
  90. package/src/types/convertor/structConvertor.ts +16 -15
  91. package/src/types/moveTypes.ts +5 -1
package/src/abi/table.ts CHANGED
@@ -1,295 +1,204 @@
1
1
  export const TABLE_ABI = {
2
- "address": "0x1",
3
- "name": "table",
4
- "friends": [
5
- "0x1::table_with_length"
6
- ],
7
- "exposed_functions": [
2
+ address: '0x1',
3
+ name: 'table',
4
+ friends: ['0x1::table_with_length'],
5
+ exposed_functions: [
6
+ {
7
+ name: 'add',
8
+ visibility: 'public',
9
+ is_entry: false,
10
+ is_view: false,
11
+ generic_type_params: [
8
12
  {
9
- "name": "add",
10
- "visibility": "public",
11
- "is_entry": false,
12
- "is_view": false,
13
- "generic_type_params": [
14
- {
15
- "constraints": [
16
- "copy",
17
- "drop"
18
- ]
19
- },
20
- {
21
- "constraints": []
22
- }
23
- ],
24
- "params": [
25
- "&mut 0x1::table::Table<T0, T1>",
26
- "T0",
27
- "T1"
28
- ],
29
- "return": []
13
+ constraints: ['copy', 'drop'],
30
14
  },
31
15
  {
32
- "name": "borrow",
33
- "visibility": "public",
34
- "is_entry": false,
35
- "is_view": false,
36
- "generic_type_params": [
37
- {
38
- "constraints": [
39
- "copy",
40
- "drop"
41
- ]
42
- },
43
- {
44
- "constraints": []
45
- }
46
- ],
47
- "params": [
48
- "&0x1::table::Table<T0, T1>",
49
- "T0"
50
- ],
51
- "return": [
52
- "&T1"
53
- ]
16
+ constraints: [],
54
17
  },
18
+ ],
19
+ params: ['&mut 0x1::table::Table<T0, T1>', 'T0', 'T1'],
20
+ return: [],
21
+ },
22
+ {
23
+ name: 'borrow',
24
+ visibility: 'public',
25
+ is_entry: false,
26
+ is_view: false,
27
+ generic_type_params: [
55
28
  {
56
- "name": "borrow_mut",
57
- "visibility": "public",
58
- "is_entry": false,
59
- "is_view": false,
60
- "generic_type_params": [
61
- {
62
- "constraints": [
63
- "copy",
64
- "drop"
65
- ]
66
- },
67
- {
68
- "constraints": []
69
- }
70
- ],
71
- "params": [
72
- "&mut 0x1::table::Table<T0, T1>",
73
- "T0"
74
- ],
75
- "return": [
76
- "&mut T1"
77
- ]
29
+ constraints: ['copy', 'drop'],
78
30
  },
79
31
  {
80
- "name": "borrow_mut_with_default",
81
- "visibility": "public",
82
- "is_entry": false,
83
- "is_view": false,
84
- "generic_type_params": [
85
- {
86
- "constraints": [
87
- "copy",
88
- "drop"
89
- ]
90
- },
91
- {
92
- "constraints": [
93
- "drop"
94
- ]
95
- }
96
- ],
97
- "params": [
98
- "&mut 0x1::table::Table<T0, T1>",
99
- "T0",
100
- "T1"
101
- ],
102
- "return": [
103
- "&mut T1"
104
- ]
32
+ constraints: [],
105
33
  },
34
+ ],
35
+ params: ['&0x1::table::Table<T0, T1>', 'T0'],
36
+ return: ['&T1'],
37
+ },
38
+ {
39
+ name: 'borrow_mut',
40
+ visibility: 'public',
41
+ is_entry: false,
42
+ is_view: false,
43
+ generic_type_params: [
106
44
  {
107
- "name": "borrow_with_default",
108
- "visibility": "public",
109
- "is_entry": false,
110
- "is_view": false,
111
- "generic_type_params": [
112
- {
113
- "constraints": [
114
- "copy",
115
- "drop"
116
- ]
117
- },
118
- {
119
- "constraints": []
120
- }
121
- ],
122
- "params": [
123
- "&0x1::table::Table<T0, T1>",
124
- "T0",
125
- "&T1"
126
- ],
127
- "return": [
128
- "&T1"
129
- ]
45
+ constraints: ['copy', 'drop'],
130
46
  },
131
47
  {
132
- "name": "contains",
133
- "visibility": "public",
134
- "is_entry": false,
135
- "is_view": false,
136
- "generic_type_params": [
137
- {
138
- "constraints": [
139
- "copy",
140
- "drop"
141
- ]
142
- },
143
- {
144
- "constraints": []
145
- }
146
- ],
147
- "params": [
148
- "&0x1::table::Table<T0, T1>",
149
- "T0"
150
- ],
151
- "return": [
152
- "bool"
153
- ]
48
+ constraints: [],
154
49
  },
50
+ ],
51
+ params: ['&mut 0x1::table::Table<T0, T1>', 'T0'],
52
+ return: ['&mut T1'],
53
+ },
54
+ {
55
+ name: 'borrow_mut_with_default',
56
+ visibility: 'public',
57
+ is_entry: false,
58
+ is_view: false,
59
+ generic_type_params: [
155
60
  {
156
- "name": "destroy",
157
- "visibility": "friend",
158
- "is_entry": false,
159
- "is_view": false,
160
- "generic_type_params": [
161
- {
162
- "constraints": [
163
- "copy",
164
- "drop"
165
- ]
166
- },
167
- {
168
- "constraints": []
169
- }
170
- ],
171
- "params": [
172
- "0x1::table::Table<T0, T1>"
173
- ],
174
- "return": []
61
+ constraints: ['copy', 'drop'],
175
62
  },
176
63
  {
177
- "name": "new",
178
- "visibility": "public",
179
- "is_entry": false,
180
- "is_view": false,
181
- "generic_type_params": [
182
- {
183
- "constraints": [
184
- "copy",
185
- "drop"
186
- ]
187
- },
188
- {
189
- "constraints": [
190
- "store"
191
- ]
192
- }
193
- ],
194
- "params": [],
195
- "return": [
196
- "0x1::table::Table<T0, T1>"
197
- ]
64
+ constraints: ['drop'],
198
65
  },
66
+ ],
67
+ params: ['&mut 0x1::table::Table<T0, T1>', 'T0', 'T1'],
68
+ return: ['&mut T1'],
69
+ },
70
+ {
71
+ name: 'borrow_with_default',
72
+ visibility: 'public',
73
+ is_entry: false,
74
+ is_view: false,
75
+ generic_type_params: [
199
76
  {
200
- "name": "remove",
201
- "visibility": "public",
202
- "is_entry": false,
203
- "is_view": false,
204
- "generic_type_params": [
205
- {
206
- "constraints": [
207
- "copy",
208
- "drop"
209
- ]
210
- },
211
- {
212
- "constraints": []
213
- }
214
- ],
215
- "params": [
216
- "&mut 0x1::table::Table<T0, T1>",
217
- "T0"
218
- ],
219
- "return": [
220
- "T1"
221
- ]
77
+ constraints: ['copy', 'drop'],
222
78
  },
223
79
  {
224
- "name": "upsert",
225
- "visibility": "public",
226
- "is_entry": false,
227
- "is_view": false,
228
- "generic_type_params": [
229
- {
230
- "constraints": [
231
- "copy",
232
- "drop"
233
- ]
234
- },
235
- {
236
- "constraints": [
237
- "drop"
238
- ]
239
- }
240
- ],
241
- "params": [
242
- "&mut 0x1::table::Table<T0, T1>",
243
- "T0",
244
- "T1"
245
- ],
246
- "return": []
247
- }
248
- ],
249
- "structs": [
80
+ constraints: [],
81
+ },
82
+ ],
83
+ params: ['&0x1::table::Table<T0, T1>', 'T0', '&T1'],
84
+ return: ['&T1'],
85
+ },
86
+ {
87
+ name: 'contains',
88
+ visibility: 'public',
89
+ is_entry: false,
90
+ is_view: false,
91
+ generic_type_params: [
92
+ {
93
+ constraints: ['copy', 'drop'],
94
+ },
95
+ {
96
+ constraints: [],
97
+ },
98
+ ],
99
+ params: ['&0x1::table::Table<T0, T1>', 'T0'],
100
+ return: ['bool'],
101
+ },
102
+ {
103
+ name: 'destroy',
104
+ visibility: 'friend',
105
+ is_entry: false,
106
+ is_view: false,
107
+ generic_type_params: [
108
+ {
109
+ constraints: ['copy', 'drop'],
110
+ },
111
+ {
112
+ constraints: [],
113
+ },
114
+ ],
115
+ params: ['0x1::table::Table<T0, T1>'],
116
+ return: [],
117
+ },
118
+ {
119
+ name: 'new',
120
+ visibility: 'public',
121
+ is_entry: false,
122
+ is_view: false,
123
+ generic_type_params: [
124
+ {
125
+ constraints: ['copy', 'drop'],
126
+ },
127
+ {
128
+ constraints: ['store'],
129
+ },
130
+ ],
131
+ params: [],
132
+ return: ['0x1::table::Table<T0, T1>'],
133
+ },
134
+ {
135
+ name: 'remove',
136
+ visibility: 'public',
137
+ is_entry: false,
138
+ is_view: false,
139
+ generic_type_params: [
140
+ {
141
+ constraints: ['copy', 'drop'],
142
+ },
143
+ {
144
+ constraints: [],
145
+ },
146
+ ],
147
+ params: ['&mut 0x1::table::Table<T0, T1>', 'T0'],
148
+ return: ['T1'],
149
+ },
150
+ {
151
+ name: 'upsert',
152
+ visibility: 'public',
153
+ is_entry: false,
154
+ is_view: false,
155
+ generic_type_params: [
156
+ {
157
+ constraints: ['copy', 'drop'],
158
+ },
159
+ {
160
+ constraints: ['drop'],
161
+ },
162
+ ],
163
+ params: ['&mut 0x1::table::Table<T0, T1>', 'T0', 'T1'],
164
+ return: [],
165
+ },
166
+ ],
167
+ structs: [
168
+ {
169
+ name: 'Box',
170
+ is_native: false,
171
+ abilities: ['drop', 'store', 'key'],
172
+ generic_type_params: [
250
173
  {
251
- "name": "Box",
252
- "is_native": false,
253
- "abilities": [
254
- "drop",
255
- "store",
256
- "key"
257
- ],
258
- "generic_type_params": [
259
- {
260
- "constraints": []
261
- }
262
- ],
263
- "fields": [
264
- {
265
- "name": "val",
266
- "type": "T0"
267
- }
268
- ]
174
+ constraints: [],
269
175
  },
176
+ ],
177
+ fields: [
270
178
  {
271
- "name": "Table",
272
- "is_native": false,
273
- "abilities": [
274
- "store"
275
- ],
276
- "generic_type_params": [
277
- {
278
- "constraints": [
279
- "copy",
280
- "drop"
281
- ]
282
- },
283
- {
284
- "constraints": []
285
- }
286
- ],
287
- "fields": [
288
- {
289
- "name": "handle",
290
- "type": "address"
291
- }
292
- ]
293
- }
294
- ]
295
- } as const;
179
+ name: 'val',
180
+ type: 'T0',
181
+ },
182
+ ],
183
+ },
184
+ {
185
+ name: 'Table',
186
+ is_native: false,
187
+ abilities: ['store'],
188
+ generic_type_params: [
189
+ {
190
+ constraints: ['copy', 'drop'],
191
+ },
192
+ {
193
+ constraints: [],
194
+ },
195
+ ],
196
+ fields: [
197
+ {
198
+ name: 'handle',
199
+ type: 'address',
200
+ },
201
+ ],
202
+ },
203
+ ],
204
+ } as const;
@@ -168,7 +168,9 @@ export class Client<TABITable extends ABITable> {
168
168
  type_arguments: args[0].type_arguments,
169
169
  arguments: args[0].arguments,
170
170
  });
171
- return this.view(payload);
171
+ return this.view(payload, {
172
+ ledger_version: args[0].ledger_version,
173
+ });
172
174
  };
173
175
  },
174
176
  }),
@@ -218,6 +220,9 @@ export class Client<TABITable extends ABITable> {
218
220
  return this.client.getAccountResource(
219
221
  args[0].account,
220
222
  `${abi.address}::${abi.name}::${structName}`,
223
+ {
224
+ ledgerVersion: args[0].ledger_version,
225
+ },
221
226
  );
222
227
 
223
228
  // TODO: decode the u64, u128, u256 to bigint
@@ -13,10 +13,10 @@ describe('get account resource', () => {
13
13
  });
14
14
 
15
15
  // Act before assertions
16
- beforeAll(async () => { });
16
+ beforeAll(async () => {});
17
17
 
18
18
  // Teardown (cleanup) after assertions
19
- afterAll(() => { });
19
+ afterAll(() => {});
20
20
 
21
21
  it('get CoinStore', async () => {
22
22
  const result = await client.useABI(COIN_ABI).resource.CoinStore({
@@ -30,7 +30,9 @@ describe('get account resource', () => {
30
30
  expect(result.data.withdraw_events).toBeDefined();
31
31
 
32
32
  // can inference nested struct
33
- expect(result.data.deposit_events.guid.id.creation_num.startsWith).toBeDefined();
33
+ expect(
34
+ result.data.deposit_events.guid.id.creation_num.startsWith,
35
+ ).toBeDefined();
34
36
 
35
37
  // @ts-expect-error field not exist
36
38
  expect(result.data.deposit_events.guid.id.abc).toBeUndefined();
@@ -39,10 +41,48 @@ describe('get account resource', () => {
39
41
  expect(result.abc).toBeUndefined();
40
42
  }, 60000);
41
43
 
44
+ it('get CoinStore with ledger version', async () => {
45
+ const result = await client.useABI(COIN_ABI).resource.CoinStore({
46
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
47
+ account: '0x1',
48
+ ledger_version: '562606728',
49
+ });
50
+
51
+ expect(result).toMatchInlineSnapshot(`
52
+ {
53
+ "data": {
54
+ "coin": {
55
+ "value": "50000358",
56
+ },
57
+ "deposit_events": {
58
+ "counter": "61",
59
+ "guid": {
60
+ "id": {
61
+ "addr": "0x1",
62
+ "creation_num": "12",
63
+ },
64
+ },
65
+ },
66
+ "frozen": false,
67
+ "withdraw_events": {
68
+ "counter": "0",
69
+ "guid": {
70
+ "id": {
71
+ "addr": "0x1",
72
+ "creation_num": "13",
73
+ },
74
+ },
75
+ },
76
+ },
77
+ "type": "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
78
+ }
79
+ `);
80
+ }, 60000);
81
+
42
82
  it('use customized ABITable', async () => {
43
83
  async () => {
44
84
  type ABITAble = DefaultABITable & {
45
- '0x4dcae85fc5559071906cd5c76b7420fcbb4b0a92f00ab40ffc394aadbbff5ee9::fixed_point64': typeof FIXED_POINT64_ABI,
85
+ '0x4dcae85fc5559071906cd5c76b7420fcbb4b0a92f00ab40ffc394aadbbff5ee9::fixed_point64': typeof FIXED_POINT64_ABI;
46
86
  };
47
87
 
48
88
  const client = createClient<ABITAble>({
@@ -60,7 +100,7 @@ describe('get account resource', () => {
60
100
 
61
101
  // @ts-expect-error field not exist
62
102
  result.data.ratio.abc;
63
- }
103
+ };
64
104
  }, 60000);
65
105
 
66
106
  it('vector struct type', async () => {
@@ -71,12 +111,12 @@ describe('get account resource', () => {
71
111
  });
72
112
 
73
113
  result.data.coins[0]?.value.startsWith;
74
- }
114
+ };
75
115
  }, 60000);
76
116
 
77
117
  it('option type', async () => {
78
118
  const { data } = await client.useABI(COIN_ABI).resource.CoinInfo({
79
- type_arguments: ["0x1::aptos_coin::AptosCoin"],
119
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
80
120
  account: '0x1',
81
121
  });
82
122
 
@@ -84,7 +124,7 @@ describe('get account resource', () => {
84
124
  expect(data.supply.vec[0]?.integer.vec).toBeDefined();
85
125
 
86
126
  // @ts-expect-error out of index, option only has 0 or 1 item
87
- expect(data.supply.vec[1]).toBeUndefined();
127
+ expect(data.supply.vec[1]).toBeUndefined();
88
128
  }, 60000);
89
129
  });
90
130
 
@@ -101,12 +141,12 @@ const TEST_ABI = {
101
141
  generic_type_params: [],
102
142
  fields: [
103
143
  {
104
- "name": "ratio",
105
- "type": "0x4dcae85fc5559071906cd5c76b7420fcbb4b0a92f00ab40ffc394aadbbff5ee9::fixed_point64::FixedPoint64"
144
+ name: 'ratio',
145
+ type: '0x4dcae85fc5559071906cd5c76b7420fcbb4b0a92f00ab40ffc394aadbbff5ee9::fixed_point64::FixedPoint64',
106
146
  },
107
147
  {
108
- "name": "coin",
109
- "type": "0x1::coin::Coin<T0>"
148
+ name: 'coin',
149
+ type: '0x1::coin::Coin<T0>',
110
150
  },
111
151
  ],
112
152
  },
@@ -117,8 +157,8 @@ const TEST_ABI = {
117
157
  generic_type_params: [],
118
158
  fields: [
119
159
  {
120
- "name": "coins",
121
- "type": "vector<0x1::coin::Coin<T0>>"
160
+ name: 'coins',
161
+ type: 'vector<0x1::coin::Coin<T0>>',
122
162
  },
123
163
  ],
124
164
  },