@thalalabs/surf 0.0.12 → 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 (105) 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 +12 -0
  5. package/README.md +22 -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/core/index.js +1 -3
  26. package/build/cjs/core/index.js.map +1 -1
  27. package/build/cjs/ensureTypes.js +11 -10
  28. package/build/cjs/ensureTypes.js.map +1 -1
  29. package/build/cjs/hooks/useWalletClient.js +2 -2
  30. package/build/cjs/hooks/useWalletClient.js.map +1 -1
  31. package/build/cjs/index.js.map +1 -1
  32. package/build/esm/abi/aggregator.js +56 -74
  33. package/build/esm/abi/aggregator.js.map +1 -1
  34. package/build/esm/abi/aptos_coin.js +98 -125
  35. package/build/esm/abi/aptos_coin.js.map +1 -1
  36. package/build/esm/abi/coin.js +456 -587
  37. package/build/esm/abi/coin.js.map +1 -1
  38. package/build/esm/abi/event.js +66 -106
  39. package/build/esm/abi/event.js.map +1 -1
  40. package/build/esm/abi/fixed_point64.js +287 -320
  41. package/build/esm/abi/fixed_point64.js.map +1 -1
  42. package/build/esm/abi/guid.js +84 -129
  43. package/build/esm/abi/guid.js.map +1 -1
  44. package/build/esm/abi/optional_aggregator.js +79 -108
  45. package/build/esm/abi/optional_aggregator.js.map +1 -1
  46. package/build/esm/abi/table.js +131 -222
  47. package/build/esm/abi/table.js.map +1 -1
  48. package/build/esm/core/Client.js +6 -2
  49. package/build/esm/core/Client.js.map +1 -1
  50. package/build/esm/core/createEntryPayload.js.map +1 -1
  51. package/build/esm/core/index.js +0 -1
  52. package/build/esm/core/index.js.map +1 -1
  53. package/build/esm/ensureTypes.js +11 -10
  54. package/build/esm/ensureTypes.js.map +1 -1
  55. package/build/esm/hooks/useWalletClient.js +2 -2
  56. package/build/esm/hooks/useWalletClient.js.map +1 -1
  57. package/build/esm/index.js +1 -1
  58. package/build/esm/index.js.map +1 -1
  59. package/build/types/abi/aggregator.d.ts.map +1 -1
  60. package/build/types/abi/aptos_coin.d.ts.map +1 -1
  61. package/build/types/abi/coin.d.ts.map +1 -1
  62. package/build/types/abi/event.d.ts.map +1 -1
  63. package/build/types/abi/fixed_point64.d.ts.map +1 -1
  64. package/build/types/abi/guid.d.ts.map +1 -1
  65. package/build/types/abi/optional_aggregator.d.ts.map +1 -1
  66. package/build/types/abi/table.d.ts.map +1 -1
  67. package/build/types/core/Client.d.ts.map +1 -1
  68. package/build/types/core/index.d.ts +0 -1
  69. package/build/types/core/index.d.ts.map +1 -1
  70. package/build/types/ensureTypes.d.ts.map +1 -1
  71. package/build/types/hooks/useWalletClient.d.ts +2 -2
  72. package/build/types/hooks/useWalletClient.d.ts.map +1 -1
  73. package/build/types/index.d.ts +2 -2
  74. package/build/types/index.d.ts.map +1 -1
  75. package/build/types/types/client/abiClient.d.ts +2 -0
  76. package/build/types/types/client/abiClient.d.ts.map +1 -1
  77. package/build/types/types/convertor/argsConvertor.d.ts +1 -1
  78. package/build/types/types/convertor/argsConvertor.d.ts.map +1 -1
  79. package/build/types/types/convertor/structConvertor.d.ts.map +1 -1
  80. package/build/types/types/moveTypes.d.ts.map +1 -1
  81. package/package.json +4 -4
  82. package/src/abi/aggregator.ts +73 -91
  83. package/src/abi/aptos_coin.ts +117 -144
  84. package/src/abi/coin.ts +646 -777
  85. package/src/abi/event.ts +83 -123
  86. package/src/abi/fixed_point64.ts +340 -373
  87. package/src/abi/guid.ts +102 -147
  88. package/src/abi/optional_aggregator.ts +103 -132
  89. package/src/abi/table.ts +181 -272
  90. package/src/core/Client.ts +6 -1
  91. package/src/core/__tests__/accountResource.test.ts +54 -14
  92. package/src/core/__tests__/createEntryPayload.test.ts +244 -250
  93. package/src/core/__tests__/createViewPayload.test.ts +44 -58
  94. package/src/core/__tests__/option.test.ts +1 -1
  95. package/src/core/__tests__/useABI.test.ts +72 -63
  96. package/src/core/__tests__/view.test.ts +76 -60
  97. package/src/core/createEntryPayload.ts +4 -3
  98. package/src/core/index.ts +0 -1
  99. package/src/ensureTypes.ts +31 -28
  100. package/src/hooks/useWalletClient.ts +2 -2
  101. package/src/index.ts +8 -8
  102. package/src/types/client/abiClient.ts +2 -0
  103. package/src/types/convertor/argsConvertor.ts +1 -1
  104. package/src/types/convertor/structConvertor.ts +16 -15
  105. package/src/types/moveTypes.ts +5 -1
@@ -4,10 +4,10 @@ import { createViewPayload } from '../createViewPayload';
4
4
  // TODO: add struct, vector of vector
5
5
  describe('createViewPayload', () => {
6
6
  // Act before assertions
7
- beforeAll(async () => { });
7
+ beforeAll(async () => {});
8
8
 
9
9
  // Teardown (cleanup) after assertions
10
- afterAll(() => { });
10
+ afterAll(() => {});
11
11
 
12
12
  it('basic type checking', async () => {
13
13
  // no need to run, type check only.
@@ -46,7 +46,7 @@ describe('createViewPayload', () => {
46
46
  // @ts-expect-error require a type_argument
47
47
  type_arguments: [],
48
48
  });
49
- }
49
+ };
50
50
  });
51
51
 
52
52
  it('basic', async () => {
@@ -87,7 +87,7 @@ describe('createViewPayload', () => {
87
87
  ],
88
88
  type_arguments: [],
89
89
  });
90
- }
90
+ };
91
91
 
92
92
  const payload = createViewPayload(TEST_ABI, {
93
93
  function: 'bool_as_input',
@@ -123,7 +123,7 @@ describe('createViewPayload', () => {
123
123
  ],
124
124
  type_arguments: [],
125
125
  });
126
- }
126
+ };
127
127
 
128
128
  const payload = createViewPayload(TEST_ABI, {
129
129
  function: 'address_as_input',
@@ -159,7 +159,7 @@ describe('createViewPayload', () => {
159
159
  ],
160
160
  type_arguments: [],
161
161
  });
162
- }
162
+ };
163
163
 
164
164
  const payload = createViewPayload(TEST_ABI, {
165
165
  function: 'number_as_input',
@@ -232,66 +232,52 @@ describe('createViewPayload', () => {
232
232
  });
233
233
 
234
234
  const TEST_ABI = {
235
- "address": "0x123",
236
- "name": "test",
237
- "friends": [],
238
- "exposed_functions": [
235
+ address: '0x123',
236
+ name: 'test',
237
+ friends: [],
238
+ exposed_functions: [
239
239
  {
240
- "name": "bool_as_input",
241
- "visibility": "public",
242
- "is_entry": false,
243
- "is_view": true,
244
- "generic_type_params": [],
245
- "params": [
246
- "bool",
247
- "bool",
248
- ],
249
- "return": []
240
+ name: 'bool_as_input',
241
+ visibility: 'public',
242
+ is_entry: false,
243
+ is_view: true,
244
+ generic_type_params: [],
245
+ params: ['bool', 'bool'],
246
+ return: [],
250
247
  },
251
248
  {
252
- "name": "number_as_input",
253
- "visibility": "public",
254
- "is_entry": false,
255
- "is_view": true,
256
- "generic_type_params": [],
257
- "params": [
258
- "u8",
259
- "u16",
260
- "u32",
261
- "u64",
262
- "u128",
263
- "u256",
264
- ],
265
- "return": []
249
+ name: 'number_as_input',
250
+ visibility: 'public',
251
+ is_entry: false,
252
+ is_view: true,
253
+ generic_type_params: [],
254
+ params: ['u8', 'u16', 'u32', 'u64', 'u128', 'u256'],
255
+ return: [],
266
256
  },
267
257
  {
268
- "name": "address_as_input",
269
- "visibility": "public",
270
- "is_entry": false,
271
- "is_view": true,
272
- "generic_type_params": [],
273
- "params": [
274
- "address",
275
- "address",
276
- ],
277
- "return": []
258
+ name: 'address_as_input',
259
+ visibility: 'public',
260
+ is_entry: false,
261
+ is_view: true,
262
+ generic_type_params: [],
263
+ params: ['address', 'address'],
264
+ return: [],
278
265
  },
279
266
  {
280
- "name": "vector_as_input",
281
- "visibility": "public",
282
- "is_entry": false,
283
- "is_view": true,
284
- "generic_type_params": [],
285
- "params": [
286
- "vector<u8>",
287
- "vector<u16>",
288
- "vector<u64>",
289
- "vector<bool>",
290
- "vector<address>",
267
+ name: 'vector_as_input',
268
+ visibility: 'public',
269
+ is_entry: false,
270
+ is_view: true,
271
+ generic_type_params: [],
272
+ params: [
273
+ 'vector<u8>',
274
+ 'vector<u16>',
275
+ 'vector<u64>',
276
+ 'vector<bool>',
277
+ 'vector<address>',
291
278
  ],
292
- "return": []
279
+ return: [],
293
280
  },
294
-
295
281
  ],
296
- "structs": []
282
+ structs: [],
297
283
  } as const;
@@ -112,7 +112,7 @@ describe('option type', () => {
112
112
  arguments: [[1, 2]],
113
113
  type_arguments: [],
114
114
  });
115
- }
115
+ };
116
116
  }, 60000);
117
117
  });
118
118
 
@@ -25,49 +25,49 @@ describe('useABI', () => {
25
25
  it('basic type checking', async () => {
26
26
  // no need to run, type check only
27
27
  () => {
28
- // @ts-expect-error cannot call a function not exist
29
- client.useABI(COIN_ABI).view.not_exist_func({
30
- arguments: ['0x1'],
31
- type_arguments: ['0x1::aptos_coin::AptosCoin'],
32
- });
33
-
34
- // @ts-expect-error cannot call a entry function from view
35
- client.useABI(COIN_ABI).view.transfer({
36
- arguments: ['0x1'],
37
- type_arguments: ['0x1::aptos_coin::AptosCoin'],
38
- });
39
-
40
- // @ts-expect-error cannot call a view function from entry
41
- client.useABI(COIN_ABI).entry.balance({
42
- arguments: ['0x1'],
43
- type_arguments: ['0x1::aptos_coin::AptosCoin'],
44
- });
45
-
46
- client.useABI(TEST_ABI).view.address_as_input({
47
- // @ts-expect-error require two args
48
- arguments: ['0x1'],
49
- type_arguments: [],
50
- });
51
-
52
- client.useABI(TEST_ABI).view.address_as_input({
53
- // @ts-expect-error require address
54
- arguments: ['0x1', 1],
55
- type_arguments: [],
56
- });
57
-
58
- client.useABI(COIN_ABI).entry.transfer({
59
- arguments: ['0x1', 1],
60
- // @ts-expect-error require a type argument
61
- type_arguments: [],
62
- account
63
- });
64
-
65
- // @ts-expect-error account is required for entry function
66
- client.useABI(COIN_ABI).entry.transfer({
67
- arguments: ['0x1', 1],
68
- type_arguments: ['0x1::aptos_coin::AptosCoin'],
69
- });
70
- }
28
+ // @ts-expect-error cannot call a function not exist
29
+ client.useABI(COIN_ABI).view.not_exist_func({
30
+ arguments: ['0x1'],
31
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
32
+ });
33
+
34
+ // @ts-expect-error cannot call a entry function from view
35
+ client.useABI(COIN_ABI).view.transfer({
36
+ arguments: ['0x1'],
37
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
38
+ });
39
+
40
+ // @ts-expect-error cannot call a view function from entry
41
+ client.useABI(COIN_ABI).entry.balance({
42
+ arguments: ['0x1'],
43
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
44
+ });
45
+
46
+ client.useABI(TEST_ABI).view.address_as_input({
47
+ // @ts-expect-error require two args
48
+ arguments: ['0x1'],
49
+ type_arguments: [],
50
+ });
51
+
52
+ client.useABI(TEST_ABI).view.address_as_input({
53
+ // @ts-expect-error require address
54
+ arguments: ['0x1', 1],
55
+ type_arguments: [],
56
+ });
57
+
58
+ client.useABI(COIN_ABI).entry.transfer({
59
+ arguments: ['0x1', 1],
60
+ // @ts-expect-error require a type argument
61
+ type_arguments: [],
62
+ account,
63
+ });
64
+
65
+ // @ts-expect-error account is required for entry function
66
+ client.useABI(COIN_ABI).entry.transfer({
67
+ arguments: ['0x1', 1],
68
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
69
+ });
70
+ };
71
71
  });
72
72
 
73
73
  it('view', async () => {
@@ -92,6 +92,19 @@ describe('useABI', () => {
92
92
  `);
93
93
  }, 60000);
94
94
 
95
+ it('view with ledger version', async () => {
96
+ const result = await client.useABI(COIN_ABI).view.balance({
97
+ arguments: ['0x1'],
98
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
99
+ ledger_version: '562606728',
100
+ });
101
+ expect(result).toMatchInlineSnapshot(`
102
+ [
103
+ 50000358n,
104
+ ]
105
+ `);
106
+ }, 60000);
107
+
95
108
  it('entry', async () => {
96
109
  const result = await client.useABI(COIN_ABI).entry.transfer({
97
110
  arguments: ['0x1', 1],
@@ -117,23 +130,19 @@ describe('useABI', () => {
117
130
  });
118
131
 
119
132
  const TEST_ABI = {
120
- "address": "0x123",
121
- "name": "test",
122
- "friends": [],
123
- "exposed_functions": [
124
- {
125
- "name": "address_as_input",
126
- "visibility": "public",
127
- "is_entry": false,
128
- "is_view": true,
129
- "generic_type_params": [],
130
- "params": [
131
- "address",
132
- "address",
133
- ],
134
- "return": []
135
- },
136
- ],
137
- "structs": []
138
- } as const;
139
-
133
+ address: '0x123',
134
+ name: 'test',
135
+ friends: [],
136
+ exposed_functions: [
137
+ {
138
+ name: 'address_as_input',
139
+ visibility: 'public',
140
+ is_entry: false,
141
+ is_view: true,
142
+ generic_type_params: [],
143
+ params: ['address', 'address'],
144
+ return: [],
145
+ },
146
+ ],
147
+ structs: [],
148
+ } as const;
@@ -7,84 +7,100 @@ import { createClient } from '../Client';
7
7
  import { createViewPayload } from '../createViewPayload';
8
8
 
9
9
  describe('call view functions', () => {
10
- const client = createClient({
11
- nodeUrl: 'https://fullnode.testnet.aptoslabs.com/v1',
12
- });
10
+ const client = createClient({
11
+ nodeUrl: 'https://fullnode.testnet.aptoslabs.com/v1',
12
+ });
13
13
 
14
- const clientMain = createClient({
15
- nodeUrl: 'https://fullnode.mainnet.aptoslabs.com/v1',
16
- });
14
+ const clientMain = createClient({
15
+ nodeUrl: 'https://fullnode.mainnet.aptoslabs.com/v1',
16
+ });
17
17
 
18
- // Act before assertions
19
- beforeAll(async () => { });
18
+ // Act before assertions
19
+ beforeAll(async () => {});
20
20
 
21
- // Teardown (cleanup) after assertions
22
- afterAll(() => { });
21
+ // Teardown (cleanup) after assertions
22
+ afterAll(() => {});
23
23
 
24
- it('basic', async () => {
25
- const viewPayload = createViewPayload(COIN_ABI, {
26
- function: 'name',
27
- arguments: [],
28
- type_arguments: ['0x1::aptos_coin::AptosCoin'],
29
- });
30
- const result = await client.view(viewPayload);
31
- expect(result).toMatchInlineSnapshot(`
24
+ it('basic', async () => {
25
+ const viewPayload = createViewPayload(COIN_ABI, {
26
+ function: 'name',
27
+ arguments: [],
28
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
29
+ });
30
+ const result = await client.view(viewPayload);
31
+ expect(result).toMatchInlineSnapshot(`
32
32
  [
33
33
  "Aptos Coin",
34
34
  ]
35
35
  `);
36
36
 
37
- const viewPayload2 = createViewPayload(COIN_ABI, {
38
- function: 'decimals',
39
- arguments: [],
40
- type_arguments: ['0x1::aptos_coin::AptosCoin'],
41
- });
42
- const result2 = await client.view(viewPayload2);
43
- expect(result2).toMatchInlineSnapshot(`
37
+ const viewPayload2 = createViewPayload(COIN_ABI, {
38
+ function: 'decimals',
39
+ arguments: [],
40
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
41
+ });
42
+ const result2 = await client.view(viewPayload2);
43
+ expect(result2).toMatchInlineSnapshot(`
44
44
  [
45
45
  8,
46
46
  ]
47
47
  `);
48
- }, 60000);
48
+ }, 60000);
49
49
 
50
- it('return struct', async () => {
51
- const viewPayload = createViewPayload(TIERED_ORACLE_ABI, {
52
- function: 'get_last_price',
53
- arguments: [],
54
- type_arguments: ['0x1::aptos_coin::AptosCoin'],
55
- });
50
+ it('ledger version', async () => {
51
+ const viewPayload = createViewPayload(COIN_ABI, {
52
+ function: 'balance',
53
+ arguments: ['0x1'],
54
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
55
+ });
56
+ const result = await client.view(viewPayload, {
57
+ ledger_version: '562606728',
58
+ });
59
+ expect(result).toMatchInlineSnapshot(`
60
+ [
61
+ 50000358n,
62
+ ]
63
+ `);
64
+ }, 60000);
65
+
66
+ it('return struct', async () => {
67
+ const viewPayload = createViewPayload(TIERED_ORACLE_ABI, {
68
+ function: 'get_last_price',
69
+ arguments: [],
70
+ type_arguments: ['0x1::aptos_coin::AptosCoin'],
71
+ });
56
72
 
57
- // The declaration in Move:
58
- // struct FixedPoint64 has copy, drop, store { value: u128 }
59
- const result = await clientMain.view(viewPayload);
60
- expect(result.length).toBe(1);
61
- expect((result[0] as any).v).toBeDefined();
62
- expect(typeof (result[0] as any).v).toEqual('string');
63
- }, 60000);
73
+ // The declaration in Move:
74
+ // struct FixedPoint64 has copy, drop, store { value: u128 }
75
+ const result = await clientMain.view(viewPayload);
76
+ expect(result.length).toBe(1);
77
+ expect((result[0] as any).v).toBeDefined();
78
+ expect(typeof (result[0] as any).v).toEqual('string');
79
+ }, 60000);
64
80
  });
65
81
 
66
82
  const TIERED_ORACLE_ABI = {
67
- address: '0x92e95ed77b5ac815d3fbc2227e76db238339e9ca43ace45031ec2589bea5b8c',
68
- name: 'tiered_oracle',
69
- friends: [
70
- '0x92e95ed77b5ac815d3fbc2227e76db238339e9ca43ace45031ec2589bea5b8c::oracle',
71
- ],
72
- exposed_functions: [
83
+ address: '0x92e95ed77b5ac815d3fbc2227e76db238339e9ca43ace45031ec2589bea5b8c',
84
+ name: 'tiered_oracle',
85
+ friends: [
86
+ '0x92e95ed77b5ac815d3fbc2227e76db238339e9ca43ace45031ec2589bea5b8c::oracle',
87
+ ],
88
+ exposed_functions: [
89
+ {
90
+ name: 'get_last_price',
91
+ visibility: 'public',
92
+ is_entry: false,
93
+ is_view: true,
94
+ generic_type_params: [
73
95
  {
74
- name: 'get_last_price',
75
- visibility: 'public',
76
- is_entry: false,
77
- is_view: true,
78
- generic_type_params: [
79
- {
80
- constraints: [],
81
- },
82
- ],
83
- params: [],
84
- return: [
85
- '0x4dcae85fc5559071906cd5c76b7420fcbb4b0a92f00ab40ffc394aadbbff5ee9::fixed_point64::FixedPoint64',
86
- ],
96
+ constraints: [],
87
97
  },
88
- ],
89
- structs: [],
98
+ ],
99
+ params: [],
100
+ return: [
101
+ '0x4dcae85fc5559071906cd5c76b7420fcbb4b0a92f00ab40ffc394aadbbff5ee9::fixed_point64::FixedPoint64',
102
+ ],
103
+ },
104
+ ],
105
+ structs: [],
90
106
  } as const;
@@ -139,11 +139,12 @@ function argToBCS(type: string, arg: any, serializer: BCS.Serializer) {
139
139
 
140
140
  const optionRegex = /0x1::option::Option<([^]+)>/;
141
141
  const optionMatch = type.match(optionRegex);
142
- if (optionMatch) { // It's 0x1::option::Option
142
+ if (optionMatch) {
143
+ // It's 0x1::option::Option
143
144
  const innerType = optionMatch[1]!;
144
145
  serializer.serializeU32AsUleb128(arg.length);
145
- if(!(arg instanceof Array) || arg.length > 1) {
146
- throw new Error('Invalid input value for 0x1::option::Option.');
146
+ if (!(arg instanceof Array) || arg.length > 1) {
147
+ throw new Error('Invalid input value for 0x1::option::Option.');
147
148
  }
148
149
  arg.forEach((arg) => argToBCS(innerType, arg, serializer));
149
150
  return;
package/src/core/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { WalletClient as MoveTsWalletClient } from './WalletClient.js';
2
1
  export { Client as MoveTsClient, createClient } from './Client.js';
3
2
  export { createViewPayload } from './createViewPayload.js';
4
3
  export { createEntryPayload } from './createEntryPayload.js';
@@ -1,42 +1,45 @@
1
1
  function assertType(val: any, types: string[] | string, message?: string) {
2
- if (!types?.includes(typeof val)) {
3
- throw new Error(
4
- message || `Invalid arg: ${val} type should be ${types instanceof Array ? types.join(" or ") : types}`,
5
- );
6
- }
2
+ if (!types?.includes(typeof val)) {
3
+ throw new Error(
4
+ message ||
5
+ `Invalid arg: ${val} type should be ${
6
+ types instanceof Array ? types.join(' or ') : types
7
+ }`,
8
+ );
9
+ }
7
10
  }
8
11
 
9
12
  export function ensureBoolean(val: boolean | string): boolean {
10
- assertType(val, ["boolean", "string"]);
11
- if (typeof val === "boolean") {
12
- return val;
13
- }
13
+ assertType(val, ['boolean', 'string']);
14
+ if (typeof val === 'boolean') {
15
+ return val;
16
+ }
14
17
 
15
- if (val === "true") {
16
- return true;
17
- }
18
- if (val === "false") {
19
- return false;
20
- }
18
+ if (val === 'true') {
19
+ return true;
20
+ }
21
+ if (val === 'false') {
22
+ return false;
23
+ }
21
24
 
22
- throw new Error("Invalid boolean string.");
25
+ throw new Error('Invalid boolean string.');
23
26
  }
24
27
 
25
28
  export function ensureNumber(val: number | string): number {
26
- assertType(val, ["number", "string"]);
27
- if (typeof val === "number") {
28
- return val;
29
- }
29
+ assertType(val, ['number', 'string']);
30
+ if (typeof val === 'number') {
31
+ return val;
32
+ }
30
33
 
31
- const res = Number.parseInt(val, 10);
32
- if (Number.isNaN(res)) {
33
- throw new Error("Invalid number string.");
34
- }
34
+ const res = Number.parseInt(val, 10);
35
+ if (Number.isNaN(res)) {
36
+ throw new Error('Invalid number string.');
37
+ }
35
38
 
36
- return res;
39
+ return res;
37
40
  }
38
41
 
39
42
  export function ensureBigInt(val: number | bigint | string): bigint {
40
- assertType(val, ["number", "bigint", "string"]);
41
- return BigInt(val);
42
- }
43
+ assertType(val, ['number', 'bigint', 'string']);
44
+ return BigInt(val);
45
+ }
@@ -1,12 +1,12 @@
1
1
  import { useWallet } from '@aptos-labs/wallet-adapter-react';
2
- import { MoveTsWalletClient } from '../core/index.js';
2
+ import { WalletClient } from '../core/WalletClient.js';
3
3
 
4
4
  export const useWalletClient = ({ nodeUrl }: { nodeUrl: string }) => {
5
5
  const wallet = useWallet();
6
6
  return {
7
7
  connected: wallet.connected,
8
8
  client: wallet.connected
9
- ? new MoveTsWalletClient({ wallet, nodeUrl })
9
+ ? new WalletClient({ wallet, nodeUrl })
10
10
  : undefined,
11
11
  };
12
12
  };
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export {
2
- createViewPayload,
3
- createEntryPayload,
4
- createClient
5
- } from "./core/index.js";
2
+ createViewPayload,
3
+ createEntryPayload,
4
+ createClient,
5
+ } from './core/index.js';
6
6
 
7
7
  export type {
8
- EntryPayload,
9
- ViewPayload,
10
- DefaultABITable
11
- } from "./types/index.js";
8
+ EntryPayload,
9
+ ViewPayload,
10
+ DefaultABITable,
11
+ } from './types/index.js';
@@ -24,6 +24,7 @@ export type ABIViewClient<T extends ABIRoot> = {
24
24
  [TFuncName in ViewFunctionName<T>]: (payload: {
25
25
  type_arguments: ExtractGenericArgsType<T, TFuncName>;
26
26
  arguments: ExtractArgsType<T, TFuncName>;
27
+ ledger_version?: string;
27
28
  }) => Promise<ExtractReturnType<T, TFuncName>>;
28
29
  };
29
30
 
@@ -40,6 +41,7 @@ export type ABIResourceClient<TABITable extends ABITable, T extends ABIRoot> = {
40
41
  [TStructName in ResourceStructName<T>]: (payload: {
41
42
  type_arguments: ExtractStructGenericArgsType<T, TStructName>;
42
43
  account: `0x${string}`;
44
+ ledger_version?: string;
43
45
  }) => Promise<{
44
46
  data: ExtractStructType<TABITable, T, TStructName>;
45
47
  type: string;
@@ -55,5 +55,5 @@ type ConvertNonStructArgType<TMoveType extends MoveNonStructTypes> =
55
55
  : TMoveType extends `0x1::object::Object<${string}>`
56
56
  ? `0x${string}`
57
57
  : TMoveType extends `0x1::option::Option<${infer TInner}>`
58
- ? ([ConvertArgType<TInner>] | [])
58
+ ? [ConvertArgType<TInner>] | []
59
59
  : UnknownStruct<TMoveType>;