wowok 1.4.35 → 1.5.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.4.35",
3
+ "version": "1.5.38",
4
4
  "description": "Create, collaborate, and transact on your own terms with the AI-driven web3 collaboration protocol.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -38,7 +38,8 @@
38
38
  "move language",
39
39
  "move",
40
40
  "treasury",
41
- "payment"
41
+ "payment",
42
+ "arbitration"
42
43
  ],
43
44
  "author": "wowok",
44
45
  "license": "Apache-2.0",
@@ -0,0 +1,448 @@
1
+ import { IsValidArray, array_unique, IsValidTokenType, IsValidDesription, parseObjectType,
2
+ IsValidAddress, IsValidEndpoint, IsValidU64, IsValidName, } from './utils'
3
+ import { FnCallType, GuardObject, PassportObject, PermissionObject, CoinObject, Protocol,
4
+ TxbObject, ArbitrationAddress, OrderObject, ArbObject} from './protocol';
5
+ import { ERROR, Errors } from './exception';
6
+ import { Transaction as TransactionBlock, } from '@mysten/sui/transactions';
7
+
8
+ export interface VotingGuard {
9
+ guard: GuardObject,
10
+ voting_weight:string, // bigint
11
+ }
12
+
13
+ export interface Vote {
14
+ arb: ArbObject,
15
+ voting_guard?: GuardObject,
16
+ agrees: number[],
17
+ }
18
+
19
+ export interface Feedback {
20
+ arb:ArbObject,
21
+ feedback:string,
22
+ indemnity?:string, // bigint
23
+ }
24
+
25
+ export interface Dispute {
26
+ order: OrderObject,
27
+ order_token_type: string,
28
+ description: string,
29
+ votable_proposition: string[],
30
+ fee?: CoinObject,
31
+ }
32
+
33
+ export class Arbitration {
34
+ protected pay_token_type;
35
+ protected permission;
36
+ protected object : TxbObject;
37
+ protected txb;
38
+
39
+ //static token2coin = (token:string) => { return '0x2::coin::Coin<' + token + '>'};
40
+
41
+ get_pay_type() { return this.pay_token_type }
42
+ get_object() { return this.object }
43
+ private constructor(txb: TransactionBlock, pay_token_type:string, permission:PermissionObject) {
44
+ this.pay_token_type = pay_token_type
45
+ this.txb = txb
46
+ this.permission = permission
47
+ this.object = ''
48
+ }
49
+ static From(txb: TransactionBlock, token_type:string, permission:PermissionObject, object:TxbObject) : Arbitration {
50
+ let s = new Arbitration(txb, token_type, permission);
51
+ s.object = Protocol.TXB_OBJECT(txb, object);
52
+ return s
53
+ }
54
+ static New(txb: TransactionBlock, token_type:string, permission:PermissionObject, description:string,
55
+ fee:bigint, passport?:PassportObject) : Arbitration {
56
+ if (!Protocol.IsValidObjects([permission])) {
57
+ ERROR(Errors.IsValidObjects)
58
+ }
59
+ if (!IsValidTokenType(token_type)) {
60
+ ERROR(Errors.IsValidTokenType, 'New.token_type')
61
+ }
62
+ if (!IsValidDesription(description)) {
63
+ ERROR(Errors.IsValidDesription)
64
+ }
65
+ if (!IsValidU64(fee)) {
66
+ ERROR(Errors.IsValidU64, 'New.fee')
67
+ }
68
+
69
+ let pay_token_type = token_type;
70
+ let obj = new Arbitration(txb, pay_token_type, permission);
71
+
72
+ if (passport) {
73
+ obj.object = txb.moveCall({
74
+ target:Protocol.Instance().ArbitrationFn('new_with_passport') as FnCallType,
75
+ arguments:[passport, txb.pure.string(description), txb.pure.u64(fee), Protocol.TXB_OBJECT(txb, permission)],
76
+ typeArguments:[pay_token_type],
77
+ })
78
+ } else {
79
+ obj.object = txb.moveCall({
80
+ target:Protocol.Instance().ArbitrationFn('new') as FnCallType,
81
+ arguments:[txb.pure.string(description), txb.pure.u64(fee), Protocol.TXB_OBJECT(txb, permission)],
82
+ typeArguments:[pay_token_type],
83
+ })
84
+ }
85
+ return obj
86
+ }
87
+
88
+ launch() : ArbitrationAddress {
89
+ return this.txb.moveCall({
90
+ target:Protocol.Instance().ArbitrationFn('create') as FnCallType,
91
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
92
+ typeArguments:[this.pay_token_type]
93
+ })
94
+ }
95
+
96
+ set_description(description:string, passport?:PassportObject) {
97
+ if (!IsValidDesription(description)) {
98
+ ERROR(Errors.IsValidDesription, 'set_description.description')
99
+ }
100
+
101
+ if (passport) {
102
+ this.txb.moveCall({
103
+ target:Protocol.Instance().ArbitrationFn('description_set_with_passport') as FnCallType,
104
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
105
+ typeArguments:[this.pay_token_type]
106
+ })
107
+ } else {
108
+ this.txb.moveCall({
109
+ target:Protocol.Instance().ArbitrationFn('description_set') as FnCallType,
110
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
111
+ typeArguments:[this.pay_token_type]
112
+ })
113
+ }
114
+ }
115
+
116
+ set_fee(fee:bigint, passport?:PassportObject) {
117
+ if (!IsValidU64(fee)) {
118
+ ERROR(Errors.IsValidU64, 'set_fee.fee')
119
+ }
120
+
121
+ if (passport) {
122
+ this.txb.moveCall({
123
+ target:Protocol.Instance().ArbitrationFn('fee_set_with_passport') as FnCallType,
124
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u64(fee), Protocol.TXB_OBJECT(this.txb, this.permission)],
125
+ typeArguments:[this.pay_token_type]
126
+ })
127
+ } else {
128
+ this.txb.moveCall({
129
+ target:Protocol.Instance().ArbitrationFn('fee_set') as FnCallType,
130
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u64(fee), Protocol.TXB_OBJECT(this.txb, this.permission)],
131
+ typeArguments:[this.pay_token_type]
132
+ })
133
+ }
134
+ }
135
+
136
+ set_endpoint(endpoint?:string, passport?:PassportObject) {
137
+ if (endpoint && !IsValidEndpoint(endpoint)) {
138
+ ERROR(Errors.IsValidEndpoint, 'set_endpoint.endpoint')
139
+ }
140
+
141
+ if (passport) {
142
+ if (endpoint) {
143
+ this.txb.moveCall({
144
+ target:Protocol.Instance().ArbitrationFn('endpoint_set_with_passport') as FnCallType,
145
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(endpoint), Protocol.TXB_OBJECT(this.txb, this.permission)],
146
+ typeArguments:[this.pay_token_type]
147
+ })
148
+ } else {
149
+ this.txb.moveCall({
150
+ target:Protocol.Instance().ArbitrationFn('endpoint_none_with_passport') as FnCallType,
151
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
152
+ typeArguments:[this.pay_token_type]
153
+ })
154
+ }
155
+ } else {
156
+ if (endpoint) {
157
+ this.txb.moveCall({
158
+ target:Protocol.Instance().ArbitrationFn('endpoint_set') as FnCallType,
159
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(endpoint), Protocol.TXB_OBJECT(this.txb, this.permission)],
160
+ typeArguments:[this.pay_token_type]
161
+ })
162
+ } else {
163
+ this.txb.moveCall({
164
+ target:Protocol.Instance().ArbitrationFn('endpoint_none') as FnCallType,
165
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
166
+ typeArguments:[this.pay_token_type]
167
+ })
168
+ }
169
+ }
170
+ }
171
+
172
+ add_voting_guard(guard: VotingGuard[], passport?:PassportObject) {
173
+ if (guard.length === 0) return ;
174
+ if (!IsValidArray(guard, (g:VotingGuard) => Protocol.IsValidObjects([g.guard]) && IsValidU64(g.voting_weight))) {
175
+ ERROR(Errors.IsValidArray, 'add_voting_guard.guard')
176
+ }
177
+ if (passport) {
178
+ guard.forEach(v => {
179
+ this.txb.moveCall({
180
+ target:Protocol.Instance().ArbitrationFn('voting_guard_add_with_passport') as FnCallType,
181
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(v.guard),
182
+ this.txb.pure.u64(v.voting_weight), Protocol.TXB_OBJECT(this.txb, this.permission)],
183
+ typeArguments:[this.pay_token_type]
184
+ })
185
+ })
186
+ } else {
187
+ guard.forEach(v => {
188
+ this.txb.moveCall({
189
+ target:Protocol.Instance().ArbitrationFn('voting_guard_add') as FnCallType,
190
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(v.guard),
191
+ this.txb.pure.u64(v.voting_weight), Protocol.TXB_OBJECT(this.txb, this.permission)],
192
+ typeArguments:[this.pay_token_type]
193
+ })
194
+ })
195
+ }
196
+ }
197
+ remove_voting_guard(guard: string[], removeall?:boolean, passport?:PassportObject) {
198
+ if (!removeall && guard.length===0) return;
199
+
200
+ if (!IsValidArray(guard, IsValidAddress)) {
201
+ ERROR(Errors.IsValidArray, 'remove_voting_guard.guard');
202
+ }
203
+
204
+ if (passport) {
205
+ if (removeall) {
206
+ this.txb.moveCall({
207
+ target:Protocol.Instance().ArbitrationFn('voting_guard_removeall_with_passport') as FnCallType,
208
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
209
+ typeArguments:[this.pay_token_type]
210
+ })
211
+ } else {
212
+ this.txb.moveCall({
213
+ target:Protocol.Instance().ArbitrationFn('voting_guard_remove_with_passport') as FnCallType,
214
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', guard),
215
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
216
+ typeArguments:[this.pay_token_type]
217
+ })
218
+ }
219
+ } else {
220
+ if (removeall) {
221
+ this.txb.moveCall({
222
+ target:Protocol.Instance().ArbitrationFn('voting_guard_removeall') as FnCallType,
223
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
224
+ typeArguments:[this.pay_token_type]
225
+ })
226
+ } else {
227
+ this.txb.moveCall({
228
+ target:Protocol.Instance().ArbitrationFn('voting_guard_remove') as FnCallType,
229
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', guard),
230
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
231
+ typeArguments:[this.pay_token_type]
232
+ })
233
+ }
234
+ }
235
+ }
236
+
237
+ set_guard(apply_guard?:string, passport?:PassportObject) {
238
+ if (apply_guard && !IsValidAddress(apply_guard)) {
239
+ ERROR(Errors.IsValidAddress, 'set_guard.apply_guard')
240
+ }
241
+
242
+ if (passport) {
243
+ if (apply_guard) {
244
+ this.txb.moveCall({
245
+ target:Protocol.Instance().ArbitrationFn('usage_guard_set_with_passport') as FnCallType,
246
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(apply_guard), Protocol.TXB_OBJECT(this.txb, this.permission)],
247
+ typeArguments:[this.pay_token_type]
248
+ })
249
+ } else {
250
+ this.txb.moveCall({
251
+ target:Protocol.Instance().ArbitrationFn('usage_guard_none_with_passport') as FnCallType,
252
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
253
+ typeArguments:[this.pay_token_type]
254
+ })
255
+ }
256
+ } else {
257
+ if (apply_guard) {
258
+ this.txb.moveCall({
259
+ target:Protocol.Instance().ArbitrationFn('usage_guard_set') as FnCallType,
260
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(apply_guard), Protocol.TXB_OBJECT(this.txb, this.permission)],
261
+ typeArguments:[this.pay_token_type]
262
+ })
263
+ } else {
264
+ this.txb.moveCall({
265
+ target:Protocol.Instance().ArbitrationFn('usage_guard_none') as FnCallType,
266
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
267
+ typeArguments:[this.pay_token_type]
268
+ })
269
+ }
270
+ }
271
+ }
272
+ pause(pause:boolean, passport?:PassportObject) {
273
+ if (passport) {
274
+ this.txb.moveCall({
275
+ target:Protocol.Instance().ArbitrationFn('pause_with_passport') as FnCallType,
276
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(pause), Protocol.TXB_OBJECT(this.txb, this.permission)],
277
+ typeArguments:[this.pay_token_type]
278
+ })
279
+ } else {
280
+ this.txb.moveCall({
281
+ target:Protocol.Instance().ArbitrationFn('pause') as FnCallType,
282
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(pause), Protocol.TXB_OBJECT(this.txb, this.permission)],
283
+ typeArguments:[this.pay_token_type]
284
+ })
285
+ }
286
+ }
287
+ vote(param:Vote, passport?:PassportObject) {
288
+ if (param.voting_guard && !Protocol.IsValidObjects([param.voting_guard])) {
289
+ ERROR(Errors.IsValidObjects, 'vote.param.voting_guard')
290
+ }
291
+ if (!IsValidArray(param.agrees, (v:number)=> IsValidU64(v) && v < Arbitration.MAX_PROPOSITION_COUNT)) {
292
+ ERROR(Errors.IsValidArray, 'vote.param.agrees')
293
+ }
294
+ if (!Protocol.IsValidObjects([param.arb])) {
295
+ ERROR(Errors.IsValidObjects, 'vote.param.arb')
296
+ }
297
+
298
+ const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
299
+ if (passport) {
300
+ if (param.voting_guard) {
301
+ this.txb.moveCall({
302
+ target:Protocol.Instance().ArbitrationFn('vote_with_passport') as FnCallType,
303
+ arguments:[passport, this.txb.object(param.voting_guard), Protocol.TXB_OBJECT(this.txb, this.object),
304
+ this.txb.object(param.arb), this.txb.pure.vector('u8', param.agrees),
305
+ this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
306
+ typeArguments:[this.pay_token_type]
307
+ })
308
+ } else {
309
+ this.txb.moveCall({
310
+ target:Protocol.Instance().ArbitrationFn('vote2_with_passport') as FnCallType,
311
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(param.arb), this.txb.pure.vector('u8', param.agrees),
312
+ this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
313
+ typeArguments:[this.pay_token_type]
314
+ })
315
+ }
316
+ } else {
317
+ this.txb.moveCall({
318
+ target:Protocol.Instance().ArbitrationFn('vote') as FnCallType,
319
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(param.arb), this.txb.pure.vector('u8', param.agrees),
320
+ this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
321
+ typeArguments:[this.pay_token_type]
322
+ })
323
+ }
324
+ }
325
+
326
+ arbitration(param:Feedback, passport?:PassportObject) {
327
+ if (!IsValidDesription(param.feedback)) {
328
+ ERROR(Errors.IsValidDesription, 'arbitration.param.feedback')
329
+ }
330
+ if (!Protocol.IsValidObjects([param.arb])) {
331
+ ERROR(Errors.IsValidObjects, 'arbitration.param.arb')
332
+ }
333
+
334
+ if (param.indemnity && !IsValidU64(param.indemnity)) {
335
+ ERROR(Errors.IsValidU64, 'arbitration.param.indemnity')
336
+ }
337
+ let ind = this.txb.pure.option('u64', param.indemnity ? param.indemnity : undefined);
338
+
339
+ if (passport) {
340
+ this.txb.moveCall({
341
+ target:Protocol.Instance().ArbitrationFn('arbitration_with_passport') as FnCallType,
342
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
343
+ this.txb.object(param.arb), this.txb.pure.string(param.feedback), ind, Protocol.TXB_OBJECT(this.txb, this.permission)],
344
+ typeArguments:[this.pay_token_type]
345
+ })
346
+ } else {
347
+ this.txb.moveCall({
348
+ target:Protocol.Instance().ArbitrationFn('arbitration') as FnCallType,
349
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
350
+ this.txb.object(param.arb), this.txb.pure.string(param.feedback), ind, Protocol.TXB_OBJECT(this.txb, this.permission)],
351
+ typeArguments:[this.pay_token_type]
352
+ })
353
+ }
354
+ }
355
+
356
+ withdraw_fee(arb:ArbObject, passport?:PassportObject) {
357
+ if (!Protocol.IsValidObjects([arb])) {
358
+ ERROR(Errors.IsValidObjects, 'withdraw_fee.arb')
359
+ }
360
+ if (passport) {
361
+ this.txb.moveCall({
362
+ target:Protocol.Instance().ArbitrationFn('withdraw_with_passport') as FnCallType,
363
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
364
+ this.txb.object(arb), Protocol.TXB_OBJECT(this.txb, this.permission)],
365
+ typeArguments:[this.pay_token_type]
366
+ })
367
+ } else {
368
+ this.txb.moveCall({
369
+ target:Protocol.Instance().ArbitrationFn('withdraw') as FnCallType,
370
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
371
+ this.txb.object(arb), Protocol.TXB_OBJECT(this.txb, this.permission)],
372
+ typeArguments:[this.pay_token_type]
373
+ })
374
+ }
375
+ }
376
+
377
+ dispute(param:Dispute, passport?:PassportObject) {
378
+ if (!Protocol.IsValidObjects([param.order])) {
379
+ ERROR(Errors.IsValidObjects, 'dispute.param.order')
380
+ }
381
+ if (!IsValidTokenType(param.order_token_type)) {
382
+ ERROR(Errors.IsValidTokenType, 'dispute.param.order_token_type')
383
+ }
384
+ if (!IsValidDesription(param.description)) {
385
+ ERROR(Errors.IsValidDesription, 'dispute.param.description')
386
+ }
387
+ if (!IsValidArray(param.votable_proposition, IsValidName)) {
388
+ ERROR(Errors.IsValidArray, 'dispute.param.votable_proposition')
389
+ }
390
+
391
+ if (passport) {
392
+ if (param.fee) {
393
+ this.txb.moveCall({
394
+ target:Protocol.Instance().ArbitrationFn('dispute_with_passport') as FnCallType,
395
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(param.order), this.txb.pure.string(param.description),
396
+ this.txb.pure.vector('string', array_unique(param.votable_proposition)), this.txb.object(param.fee)],
397
+ typeArguments:[this.pay_token_type, param.order_token_type]
398
+ })
399
+ } else {
400
+ this.txb.moveCall({
401
+ target:Protocol.Instance().ArbitrationFn('free_dispute_with_passport') as FnCallType,
402
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(param.order), this.txb.pure.string(param.description),
403
+ this.txb.pure.vector('string', array_unique(param.votable_proposition))],
404
+ typeArguments:[this.pay_token_type, param.order_token_type]
405
+ })
406
+ }
407
+ } else {
408
+ if (param.fee) {
409
+ this.txb.moveCall({
410
+ target:Protocol.Instance().ArbitrationFn('dispute') as FnCallType,
411
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(param.order), this.txb.pure.string(param.description),
412
+ this.txb.pure.vector('string', array_unique(param.votable_proposition)), this.txb.object(param.fee)],
413
+ typeArguments:[this.pay_token_type, param.order_token_type]
414
+ })
415
+ } else {
416
+ this.txb.moveCall({
417
+ target:Protocol.Instance().ArbitrationFn('free_dispute') as FnCallType,
418
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(param.order), this.txb.pure.string(param.description),
419
+ this.txb.pure.vector('string', array_unique(param.votable_proposition))],
420
+ typeArguments:[this.pay_token_type, param.order_token_type]
421
+ })
422
+ }
423
+ }
424
+ }
425
+
426
+ change_permission(new_permission:PermissionObject) {
427
+ if (!Protocol.IsValidObjects([new_permission])) {
428
+ ERROR(Errors.IsValidObjects)
429
+ }
430
+
431
+ this.txb.moveCall({
432
+ target:Protocol.Instance().ArbitrationFn('permission_set') as FnCallType,
433
+ arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
434
+ typeArguments:[this.pay_token_type]
435
+ })
436
+ this.permission = new_permission
437
+ }
438
+
439
+ static parseObjectType = (chain_type:string | undefined | null) : string => {
440
+ return parseObjectType(chain_type, 'arbitration::Arbitration<')
441
+ }
442
+
443
+ static parseArbObjectType = (chain_type:string | undefined | null) : string => {
444
+ return parseObjectType(chain_type, 'arb::Arb<')
445
+ }
446
+ static MAX_PROPOSITION_COUNT = 16;
447
+ static MAX_VOTING_GUARD_COUNT = 16;
448
+ }