@kontor/kontor-sdk 1.0.0-alpha.23 → 1.0.0-alpha.26

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 (30) hide show
  1. package/dist/cjs/sdk/contracts/wits.js +1 -3
  2. package/dist/cjs/sdk/contracts/wits.js.map +1 -1
  3. package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js +2 -2
  4. package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
  5. package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
  6. package/dist/esm/exports/index.js +1 -0
  7. package/dist/esm/exports/index.js.map +1 -1
  8. package/dist/esm/sdk/contracts/wits.js +1 -4
  9. package/dist/esm/sdk/contracts/wits.js.map +1 -1
  10. package/dist/esm/sdk/utils/wit/decode-wit-parameter.js +2 -2
  11. package/dist/esm/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
  12. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  13. package/dist/types/exports/index.d.ts +1 -0
  14. package/dist/types/exports/index.d.ts.map +1 -1
  15. package/dist/types/sdk/contracts/wits.d.ts +1 -1
  16. package/dist/types/sdk/contracts/wits.d.ts.map +1 -1
  17. package/dist/types/wit/wit-parser/core/types/utils.d.ts +2 -0
  18. package/dist/types/wit/wit-parser/core/types/utils.d.ts.map +1 -1
  19. package/package.json +1 -1
  20. package/src/exports/index.ts +2 -0
  21. package/src/sdk/contracts/wits.ts +1 -5
  22. package/src/sdk/types/contract.test-d.ts +21 -95
  23. package/src/sdk/utils/wit/decode-wit-parameter.ts +2 -2
  24. package/src/sdk/utils/wit/encode-function-data.test-d.ts +4 -6
  25. package/src/sdk/utils/wit/encode-function-data.test.ts +3 -47
  26. package/src/wit/wit-parser/core/types/records.test-d.ts +3 -0
  27. package/src/wit/wit-parser/core/types/utils.test-d.ts +7 -3
  28. package/src/wit/wit-parser/core/types/utils.ts +6 -2
  29. package/src/wit/wit-parser/parse-wit.test.ts +426 -146
  30. package/test/src/wits.ts +0 -4
@@ -2,195 +2,475 @@ import { expectTypeOf, describe, expect, test } from "vitest";
2
2
 
3
3
  import type { ParseWit } from "./parse-wit.js";
4
4
  import { parseWit } from "./parse-wit.js";
5
- // import type { nativeToken } from "../../sdk/contracts/wits.js";
6
- //
7
- //
8
- //
9
- // type t = ParseWit<typeof nativeToken.raw>;
10
- //
5
+ import { nativeToken } from "../../sdk/contracts/wits.js";
11
6
 
12
- test("ParseWit (types)", () => {
13
- // type-level assertions
7
+ expectTypeOf<ParseWit<typeof nativeToken.raw>>().toEqualTypeOf<
8
+ readonly [
9
+ {
10
+ readonly name: "mint";
11
+ readonly type: "function";
12
+ readonly context: "proc";
13
+ readonly inputs: readonly [
14
+ {
15
+ readonly name: "amt";
16
+ readonly type: "decimal";
17
+ readonly internalType: "decimal";
18
+ },
19
+ ];
20
+ readonly outputs: readonly [
21
+ {
22
+ readonly type: "result<tuple, error>";
23
+ readonly internalType: "result<mint, error>";
14
24
 
15
- expectTypeOf<
16
- ParseWit<
17
- [
18
- "record contract-address { name: string, height: s64, tx-index: s64 }",
19
- "export fib: func(ctx: borrow<proc-context>, arith-address: contract-address, n: u64) -> u64;",
20
- // "export fib-of-sub: func(ctx: borrow<proc-context>, arith-address: contract-address, x: string, y: string) -> result<u64, error>;",
21
- // "export cached-values: func(ctx: borrow<view-context>) -> list<u64>;",
22
- ]
23
- >
24
- >().toEqualTypeOf<
25
- readonly [
25
+ readonly components: readonly [
26
+ {
27
+ readonly name: "dst";
28
+ readonly type: "string";
29
+ readonly internalType: "string";
30
+ },
31
+ {
32
+ readonly name: "amt";
33
+ readonly type: "decimal";
34
+ readonly internalType: "decimal";
35
+ },
36
+ ];
37
+ },
38
+ ];
39
+ },
40
+ {
41
+ readonly name: "burn";
42
+ readonly type: "function";
43
+ readonly context: "proc";
44
+ readonly inputs: readonly [
45
+ {
46
+ readonly name: "amt";
47
+ readonly type: "decimal";
48
+ readonly internalType: "decimal";
49
+ },
50
+ ];
51
+ readonly outputs: readonly [
52
+ {
53
+ readonly type: "result<tuple, error>";
54
+ readonly internalType: "result<burn, error>";
55
+
56
+ readonly components: readonly [
57
+ {
58
+ readonly name: "src";
59
+ readonly type: "string";
60
+ readonly internalType: "string";
61
+ },
62
+ {
63
+ readonly name: "amt";
64
+ readonly type: "decimal";
65
+ readonly internalType: "decimal";
66
+ },
67
+ ];
68
+ },
69
+ ];
70
+ },
71
+ {
72
+ readonly name: "transfer";
73
+ readonly type: "function";
74
+ readonly context: "proc";
75
+ readonly inputs: readonly [
76
+ {
77
+ readonly name: "dst";
78
+ readonly type: "string";
79
+ readonly internalType: "string";
80
+ },
81
+ {
82
+ readonly name: "amt";
83
+ readonly type: "decimal";
84
+ readonly internalType: "decimal";
85
+ },
86
+ ];
87
+ readonly outputs: readonly [
88
+ {
89
+ readonly type: "result<tuple, error>";
90
+ readonly internalType: "result<transfer, error>";
91
+
92
+ readonly components: readonly [
93
+ {
94
+ readonly name: "src";
95
+ readonly type: "string";
96
+ readonly internalType: "string";
97
+ },
98
+ {
99
+ readonly name: "dst";
100
+ readonly type: "string";
101
+ readonly internalType: "string";
102
+ },
103
+ {
104
+ readonly name: "amt";
105
+ readonly type: "decimal";
106
+ readonly internalType: "decimal";
107
+ },
108
+ ];
109
+ },
110
+ ];
111
+ },
112
+ {
113
+ readonly name: "balance";
114
+ readonly type: "function";
115
+ readonly context: "view";
116
+ readonly inputs: readonly [
117
+ {
118
+ readonly name: "acc";
119
+ readonly type: "string";
120
+ readonly internalType: "string";
121
+ },
122
+ ];
123
+ readonly outputs: readonly [
124
+ {
125
+ readonly type: "option<decimal>";
126
+ readonly internalType: "option<decimal>";
127
+ },
128
+ ];
129
+ },
130
+
131
+ {
132
+ readonly name: "balances";
133
+ readonly type: "function";
134
+ readonly context: "view";
135
+ readonly inputs: readonly [];
136
+ readonly outputs: readonly [
137
+ {
138
+ readonly type: "list<tuple>";
139
+ readonly internalType: "list<balance>";
140
+ readonly components: readonly [
141
+ {
142
+ readonly name: "acc";
143
+ readonly type: "string";
144
+ readonly internalType: "string";
145
+ },
146
+ {
147
+ readonly name: "amt";
148
+ readonly type: "decimal";
149
+ readonly internalType: "decimal";
150
+ },
151
+ ];
152
+ },
153
+ ];
154
+ },
155
+
156
+ {
157
+ readonly name: "total-supply";
158
+ readonly type: "function";
159
+ readonly context: "view";
160
+ readonly inputs: readonly [];
161
+ readonly outputs: readonly [
162
+ {
163
+ readonly type: "decimal";
164
+ readonly internalType: "decimal";
165
+ },
166
+ ];
167
+ },
168
+ {
169
+ readonly name: "attach";
170
+ readonly type: "function";
171
+ readonly context: "proc";
172
+ readonly inputs: readonly [
173
+ {
174
+ readonly name: "vout";
175
+ readonly type: "u64";
176
+ readonly internalType: "u64";
177
+ },
178
+ {
179
+ readonly name: "amt";
180
+ readonly type: "decimal";
181
+ readonly internalType: "decimal";
182
+ },
183
+ ];
184
+ readonly outputs: readonly [
185
+ {
186
+ readonly type: "result<tuple, error>";
187
+ readonly internalType: "result<transfer, error>";
188
+ readonly components: readonly [
189
+ {
190
+ readonly name: "src";
191
+ readonly type: "string";
192
+ readonly internalType: "string";
193
+ },
194
+ {
195
+ readonly name: "dst";
196
+ readonly type: "string";
197
+ readonly internalType: "string";
198
+ },
199
+ {
200
+ readonly name: "amt";
201
+ readonly type: "decimal";
202
+ readonly internalType: "decimal";
203
+ },
204
+ ];
205
+ },
206
+ ];
207
+ },
208
+ {
209
+ readonly name: "detach";
210
+ readonly type: "function";
211
+ readonly context: "proc";
212
+ readonly inputs: readonly [];
213
+ readonly outputs: readonly [
214
+ {
215
+ readonly type: "result<tuple, error>";
216
+ readonly internalType: "result<transfer, error>";
217
+ readonly components: readonly [
218
+ {
219
+ readonly name: "src";
220
+ readonly type: "string";
221
+ readonly internalType: "string";
222
+ },
223
+ {
224
+ readonly name: "dst";
225
+ readonly type: "string";
226
+ readonly internalType: "string";
227
+ },
228
+ {
229
+ readonly name: "amt";
230
+ readonly type: "decimal";
231
+ readonly internalType: "decimal";
232
+ },
233
+ ];
234
+ },
235
+ ];
236
+ },
237
+ ]
238
+ >();
239
+
240
+ describe("parseWit (runtime)", () => {
241
+ test("parses nativeToken WIT into the expected ABI shape", () => {
242
+ const out = parseWit(nativeToken.raw);
243
+
244
+ expect(out).toEqual([
26
245
  {
27
- readonly name: "fib";
28
- readonly type: "function";
29
- readonly context: "proc";
30
- readonly inputs: readonly [
246
+ name: "init",
247
+ type: "function",
248
+ context: "proc",
249
+ inputs: [],
250
+ outputs: [],
251
+ },
252
+ {
253
+ name: "mint",
254
+ type: "function",
255
+ context: "proc",
256
+ inputs: [
31
257
  {
32
- readonly name: "arith-address";
33
- readonly type: "tuple";
34
- readonly internalType: "contract-address";
35
- readonly components: readonly [
36
- {
37
- readonly name: "name";
38
- readonly type: "string";
39
- readonly internalType: "string";
40
- },
258
+ name: "amt",
259
+ type: "decimal",
260
+ internalType: "decimal",
261
+ },
262
+ ],
263
+ outputs: [
264
+ {
265
+ type: "result<tuple, error>",
266
+ internalType: "result<mint, error>",
267
+ components: [
41
268
  {
42
- readonly name: "height";
43
- readonly type: "s64";
44
- readonly internalType: "s64";
269
+ name: "dst",
270
+ type: "string",
271
+ internalType: "string",
45
272
  },
46
273
  {
47
- readonly name: "tx-index";
48
- readonly type: "s64";
49
- readonly internalType: "s64";
274
+ name: "amt",
275
+ type: "decimal",
276
+ internalType: "decimal",
50
277
  },
51
- ];
52
- },
53
- {
54
- readonly name: "n";
55
- readonly type: "u64";
56
- readonly internalType: "u64";
278
+ ],
57
279
  },
58
- ];
59
- readonly outputs: readonly [
60
- { readonly type: "u64"; readonly internalType: "u64" },
61
- ];
280
+ ],
62
281
  },
63
- // {
64
- // readonly name: "fib-of-sub";
65
- // readonly type: "function";
66
- // readonly context: "proc";
67
- // readonly inputs: readonly [
68
- // {
69
- // readonly name: "arith-address";
70
- // readonly type: "tuple";
71
- // readonly internalType: "contract-address";
72
- //
73
- // readonly components: readonly [
74
- // {
75
- // readonly name: "name";
76
- // readonly type: "string";
77
- // readonly internalType: "string";
78
- // },
79
- // {
80
- // readonly name: "height";
81
- // readonly type: "s64";
82
- // readonly internalType: "s64";
83
- // },
84
- // {
85
- // readonly name: "tx-index";
86
- // readonly type: "s64";
87
- // readonly internalType: "s64";
88
- // },
89
- // ];
90
- // },
91
- // {
92
- // readonly name: "x";
93
- // readonly type: "string";
94
- // readonly internalType: "string";
95
- // },
96
- // {
97
- // readonly name: "y";
98
- // readonly type: "string";
99
- // readonly internalType: "string";
100
- // },
101
- // ];
102
- // readonly outputs: readonly [
103
- // {
104
- // readonly type: "result<u64, error>";
105
- // readonly internalType: "result<u64, error>";
106
- // },
107
- // ];
108
- // },
109
- // {
110
- // readonly name: "cached-values";
111
- // readonly type: "function";
112
- // readonly context: "view";
113
- // readonly inputs: readonly [];
114
- // readonly outputs: readonly [
115
- // { readonly type: "list<u64>"; readonly internalType: "list<u64>" },
116
- // ];
117
- // },
118
- ]
119
- >();
120
- });
121
-
122
- describe("parseWit (runtime)", () => {
123
- test("parses proc + view functions and strips ctx from inputs", () => {
124
- const input = [
125
- // TODO: build in record defs should be defined under the hood
126
- "record contract-address { name: string, height: s64, tx-index: s64 }",
127
- "export fib: func(ctx: borrow<proc-context>, arith-address: contract-address, n: u64) -> u64;",
128
- "export fib-of-sub: func(ctx: borrow<proc-context>, arith-address: contract-address, x: string, y: string) -> result<u64, error>;",
129
- "export cached-values: func(ctx: borrow<view-context>) -> list<u64>;",
130
- "export return-option: func(ctx: borrow<view-context>) -> option<u64>;",
131
- ] as const;
132
-
133
- const out = parseWit(input);
134
-
135
- expect(out).toEqual([
136
282
  {
137
- name: "fib",
283
+ name: "burn",
138
284
  type: "function",
139
285
  context: "proc",
140
286
  inputs: [
141
287
  {
142
- name: "arith-address",
143
- type: "tuple",
144
- internalType: "contract-address",
288
+ name: "amt",
289
+ type: "decimal",
290
+ internalType: "decimal",
291
+ },
292
+ ],
293
+ outputs: [
294
+ {
295
+ type: "result<tuple, error>",
296
+ internalType: "result<burn, error>",
145
297
  components: [
146
- { name: "name", type: "string", internalType: "string" },
147
- { name: "height", type: "s64", internalType: "s64" },
148
- { name: "tx-index", type: "s64", internalType: "s64" },
298
+ {
299
+ name: "src",
300
+ type: "string",
301
+ internalType: "string",
302
+ },
303
+ {
304
+ name: "amt",
305
+ type: "decimal",
306
+ internalType: "decimal",
307
+ },
149
308
  ],
150
309
  },
151
- { name: "n", type: "u64", internalType: "u64" },
152
310
  ],
153
- outputs: [{ type: "u64", internalType: "u64" }],
154
311
  },
155
312
  {
156
- name: "fib-of-sub",
313
+ name: "transfer",
157
314
  type: "function",
158
315
  context: "proc",
159
316
  inputs: [
160
317
  {
161
- name: "arith-address",
162
- type: "tuple",
163
- internalType: "contract-address",
164
-
318
+ name: "dst",
319
+ type: "string",
320
+ internalType: "string",
321
+ },
322
+ {
323
+ name: "amt",
324
+ type: "decimal",
325
+ internalType: "decimal",
326
+ },
327
+ ],
328
+ outputs: [
329
+ {
330
+ type: "result<tuple, error>",
331
+ internalType: "result<transfer, error>",
165
332
  components: [
166
- { name: "name", type: "string", internalType: "string" },
167
- { name: "height", type: "s64", internalType: "s64" },
168
- { name: "tx-index", type: "s64", internalType: "s64" },
333
+ {
334
+ name: "src",
335
+ type: "string",
336
+ internalType: "string",
337
+ },
338
+ {
339
+ name: "dst",
340
+ type: "string",
341
+ internalType: "string",
342
+ },
343
+ {
344
+ name: "amt",
345
+ type: "decimal",
346
+ internalType: "decimal",
347
+ },
169
348
  ],
170
349
  },
171
- { name: "x", type: "string", internalType: "string" },
172
- { name: "y", type: "string", internalType: "string" },
350
+ ],
351
+ },
352
+ {
353
+ name: "balance",
354
+ type: "function",
355
+ context: "view",
356
+ inputs: [
357
+ {
358
+ name: "acc",
359
+ type: "string",
360
+ internalType: "string",
361
+ },
173
362
  ],
174
363
  outputs: [
175
364
  {
176
- type: "result<u64, error>",
177
- internalType: "result<u64, error>",
365
+ type: "option<decimal>",
366
+ internalType: "option<decimal>",
178
367
  },
179
368
  ],
180
369
  },
181
370
  {
182
- name: "cached-values",
371
+ name: "balances",
183
372
  type: "function",
184
373
  context: "view",
185
374
  inputs: [],
186
- outputs: [{ type: "list<u64>", internalType: "list<u64>" }],
375
+ outputs: [
376
+ {
377
+ type: "list<tuple>",
378
+ internalType: "list<balance>",
379
+ components: [
380
+ {
381
+ name: "acc",
382
+ type: "string",
383
+ internalType: "string",
384
+ },
385
+ {
386
+ name: "amt",
387
+ type: "decimal",
388
+ internalType: "decimal",
389
+ },
390
+ ],
391
+ },
392
+ ],
187
393
  },
188
394
  {
189
- name: "return-option",
395
+ name: "total-supply",
190
396
  type: "function",
191
397
  context: "view",
192
398
  inputs: [],
193
- outputs: [{ type: "option<u64>", internalType: "option<u64>" }],
399
+ outputs: [
400
+ {
401
+ type: "decimal",
402
+ internalType: "decimal",
403
+ },
404
+ ],
405
+ },
406
+ {
407
+ name: "attach",
408
+ type: "function",
409
+ context: "proc",
410
+ inputs: [
411
+ {
412
+ name: "vout",
413
+ type: "u64",
414
+ internalType: "u64",
415
+ },
416
+ {
417
+ name: "amt",
418
+ type: "decimal",
419
+ internalType: "decimal",
420
+ },
421
+ ],
422
+ outputs: [
423
+ {
424
+ type: "result<tuple, error>",
425
+ internalType: "result<transfer, error>",
426
+ components: [
427
+ {
428
+ name: "src",
429
+ type: "string",
430
+ internalType: "string",
431
+ },
432
+ {
433
+ name: "dst",
434
+ type: "string",
435
+ internalType: "string",
436
+ },
437
+ {
438
+ name: "amt",
439
+ type: "decimal",
440
+ internalType: "decimal",
441
+ },
442
+ ],
443
+ },
444
+ ],
445
+ },
446
+ {
447
+ name: "detach",
448
+ type: "function",
449
+ context: "proc",
450
+ inputs: [],
451
+ outputs: [
452
+ {
453
+ type: "result<tuple, error>",
454
+ internalType: "result<transfer, error>",
455
+ components: [
456
+ {
457
+ name: "src",
458
+ type: "string",
459
+ internalType: "string",
460
+ },
461
+ {
462
+ name: "dst",
463
+ type: "string",
464
+ internalType: "string",
465
+ },
466
+ {
467
+ name: "amt",
468
+ type: "decimal",
469
+ internalType: "decimal",
470
+ },
471
+ ],
472
+ },
473
+ ],
194
474
  },
195
475
  ]);
196
476
  });
package/test/src/wits.ts CHANGED
@@ -5,10 +5,6 @@ export const nativeTokenRaw = [
5
5
  "record transfer { src: string, dst: string, amt: decimal }",
6
6
  "record burn { src: string, amt: decimal }",
7
7
  "record mint { dst: string, amt: decimal }",
8
-
9
- "export issuance: func(ctx: borrow<core-context>, amt: decimal) -> result<mint, error>;",
10
- "export hold: func(ctx: borrow<core-context>, amt: decimal) -> result<transfer, error>;",
11
- "export release: func(ctx: borrow<core-context>, burn-amt: decimal) -> result<burn, error>;",
12
8
  "export init: func(ctx: borrow<proc-context>);",
13
9
  "export mint: func(ctx: borrow<proc-context>, amt: decimal) -> result<mint, error>;",
14
10
  "export burn: func(ctx: borrow<proc-context>, amt: decimal) -> result<burn, error>;",