wowok 1.0.3 → 1.0.5
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/LICENSE +201 -0
- package/README.md +17 -0
- package/dist/demand.js +91 -30
- package/dist/guard.js +206 -80
- package/dist/machine.js +130 -65
- package/dist/passport.js +14 -5
- package/dist/permission.js +117 -49
- package/dist/progress.js +74 -30
- package/dist/protocol.js +85 -53
- package/dist/repository.js +154 -50
- package/dist/reward.js +134 -28
- package/dist/service.js +457 -161
- package/dist/util.js +25 -1
- package/dist/vote.js +134 -56
- package/package.json +11 -7
- package/src/demand.ts +96 -52
- package/src/graphql.ts +103 -0
- package/src/guard.ts +268 -114
- package/src/index.ts +12 -0
- package/src/machine.ts +137 -86
- package/src/passport.ts +67 -30
- package/src/permission.ts +115 -59
- package/src/progress.ts +149 -63
- package/src/protocol.ts +94 -40
- package/src/repository.ts +152 -79
- package/src/reward.ts +134 -45
- package/src/service.ts +437 -209
- package/src/util.ts +28 -1
- package/src/vote.ts +141 -74
package/src/reward.ts
CHANGED
|
@@ -1,84 +1,119 @@
|
|
|
1
|
-
import { TransactionBlock,
|
|
2
|
-
import { BCS
|
|
3
|
-
import { CLOCK_OBJECT, FnCallType,
|
|
4
|
-
|
|
5
|
-
import {
|
|
1
|
+
import { TransactionBlock, type TransactionResult } from '@mysten/sui.js/transactions';
|
|
2
|
+
import { BCS} from '@mysten/bcs';
|
|
3
|
+
import { CLOCK_OBJECT, FnCallType, GuardObject, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidObjects, IsValidUint, PROTOCOL, PassportObject, PermissionObject,
|
|
4
|
+
RewardAddress, RewardObject, TXB_OBJECT} from './protocol';
|
|
5
|
+
import { array_unique } from './util';
|
|
6
6
|
|
|
7
|
-
export type RewardObject = TransactionResult;
|
|
8
|
-
export type RewardAddress = TransactionResult;
|
|
9
7
|
export type Reward = TransactionResult;
|
|
8
|
+
export type CoinReward = TransactionResult;
|
|
9
|
+
|
|
10
|
+
export function reward(reward_type:string, txb:TransactionBlock, permission:PermissionObject, description:string,
|
|
11
|
+
minutes_duration:number, passport?:PassportObject) : RewardObject | boolean {
|
|
12
|
+
if (!IsValidObjects([permission])) return false;
|
|
13
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
14
|
+
if (!IsValidDesription(description)) return false;
|
|
15
|
+
if (!IsValidUint(minutes_duration)) return false;
|
|
10
16
|
|
|
11
|
-
export function reward(reward_type:string, txb:TransactionBlock, permission:PermissionObject, description:string, minutes_duration:number, passport?:PassportObject) : RewardObject {
|
|
12
17
|
if (passport) {
|
|
13
18
|
return txb.moveCall({
|
|
14
19
|
target:PROTOCOL.RewardFn('new_with_passport') as FnCallType,
|
|
15
|
-
arguments:[passport, txb.pure(
|
|
16
|
-
txb.object(CLOCK_OBJECT), permission],
|
|
20
|
+
arguments:[passport, txb.pure(description), txb.pure(minutes_duration, BCS.U64),
|
|
21
|
+
txb.object(CLOCK_OBJECT), TXB_OBJECT(txb, permission)],
|
|
17
22
|
typeArguments:[reward_type]
|
|
18
23
|
})
|
|
19
24
|
} else {
|
|
20
25
|
return txb.moveCall({
|
|
21
26
|
target:PROTOCOL.RewardFn('new') as FnCallType,
|
|
22
|
-
arguments:[txb.pure(
|
|
23
|
-
txb.object(CLOCK_OBJECT), permission],
|
|
27
|
+
arguments:[txb.pure(description), txb.pure(minutes_duration, BCS.U64),
|
|
28
|
+
txb.object(CLOCK_OBJECT), TXB_OBJECT(txb, permission)],
|
|
24
29
|
typeArguments:[reward_type]
|
|
25
30
|
})
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
|
-
export function launch(reward_type:string, txb:TransactionBlock, reward:RewardObject): RewardAddress {
|
|
33
|
+
export function launch(reward_type:string, txb:TransactionBlock, reward:RewardObject): RewardAddress | boolean {
|
|
34
|
+
if (!IsValidObjects([reward])) return false;
|
|
35
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
29
36
|
return txb.moveCall({
|
|
30
37
|
target:PROTOCOL.RewardFn('create') as FnCallType,
|
|
31
|
-
arguments:[reward],
|
|
38
|
+
arguments:[TXB_OBJECT(txb, reward)],
|
|
32
39
|
typeArguments:[reward_type]
|
|
33
40
|
})
|
|
34
41
|
}
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
|
|
43
|
+
export function destroy(reward_type:string, txb:TransactionBlock, reward:RewardObject) : boolean {
|
|
44
|
+
if (!IsValidObjects([reward])) return false;
|
|
45
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
46
|
+
txb.moveCall({
|
|
37
47
|
target:PROTOCOL.RewardFn('destroy') as FnCallType,
|
|
38
|
-
arguments: [reward],
|
|
48
|
+
arguments: [TXB_OBJECT(txb, reward)],
|
|
39
49
|
})
|
|
50
|
+
return true
|
|
40
51
|
}
|
|
41
|
-
export function reward_refund(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
52
|
+
export function reward_refund(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
53
|
+
permission:PermissionObject, passport?:PassportObject) : boolean {
|
|
54
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
55
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
42
56
|
if (passport) {
|
|
43
57
|
txb.moveCall({
|
|
44
58
|
target:PROTOCOL.RewardFn('refund_with_passport') as FnCallType,
|
|
45
|
-
arguments:[passport, reward, txb.object(CLOCK_OBJECT), permission],
|
|
59
|
+
arguments:[passport, TXB_OBJECT(txb, reward), txb.object(CLOCK_OBJECT), TXB_OBJECT(txb, permission)],
|
|
46
60
|
typeArguments:[reward_type]
|
|
47
61
|
})
|
|
48
62
|
} else {
|
|
49
63
|
txb.moveCall({
|
|
50
64
|
target:PROTOCOL.RewardFn('refund') as FnCallType,
|
|
51
|
-
arguments:[reward, txb.object(CLOCK_OBJECT), permission],
|
|
65
|
+
arguments:[TXB_OBJECT(txb, reward), txb.object(CLOCK_OBJECT), TXB_OBJECT(txb, permission)],
|
|
52
66
|
typeArguments:[reward_type]
|
|
53
67
|
})
|
|
54
68
|
}
|
|
69
|
+
return true
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
export function reward_expand_time(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
72
|
+
export function reward_expand_time(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
73
|
+
permission:PermissionObject, minutes_expand:number, passport?:PassportObject) : boolean {
|
|
74
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
75
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
76
|
+
if (!IsValidUint(minutes_expand)) return false;
|
|
77
|
+
|
|
58
78
|
if (passport) {
|
|
59
79
|
txb.moveCall({
|
|
60
80
|
target:PROTOCOL.RewardFn('time_expand_with_passport') as FnCallType,
|
|
61
|
-
arguments:[passport, reward, txb.pure(minutes_expand, BCS.U64), permission],
|
|
81
|
+
arguments:[passport, TXB_OBJECT(txb, reward), txb.pure(minutes_expand, BCS.U64), TXB_OBJECT(txb, permission)],
|
|
62
82
|
typeArguments:[reward_type]
|
|
63
83
|
})
|
|
64
84
|
} else {
|
|
65
85
|
txb.moveCall({
|
|
66
86
|
target:PROTOCOL.RewardFn('time_expand') as FnCallType,
|
|
67
|
-
arguments:[reward, txb.pure(minutes_expand, BCS.U64), permission],
|
|
87
|
+
arguments:[TXB_OBJECT(txb, reward), txb.pure(minutes_expand, BCS.U64), TXB_OBJECT(txb, permission)],
|
|
68
88
|
typeArguments:[reward_type]
|
|
69
89
|
})
|
|
70
90
|
}
|
|
91
|
+
return true
|
|
71
92
|
}
|
|
72
93
|
export type RewardGuardPortions = {
|
|
73
94
|
guard:GuardObject;
|
|
74
95
|
portions:number;
|
|
75
96
|
}
|
|
76
|
-
export
|
|
97
|
+
export const MAX_PORTIONS_COUNT = 255;
|
|
98
|
+
|
|
99
|
+
export function reward_add_guard(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
100
|
+
permission:PermissionObject, gurads:RewardGuardPortions[], passport?:PassportObject) : boolean {
|
|
101
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
102
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
103
|
+
if (!gurads) return false;
|
|
104
|
+
|
|
105
|
+
let bValid = true;
|
|
106
|
+
gurads.forEach((v) => {
|
|
107
|
+
if (!IsValidUint(v.portions) || v.portions > MAX_PORTIONS_COUNT) bValid = false;
|
|
108
|
+
if (!IsValidObjects([v.guard])) bValid = false;
|
|
109
|
+
})
|
|
110
|
+
if (!bValid) return false;
|
|
111
|
+
|
|
77
112
|
if (passport) {
|
|
78
113
|
gurads.forEach((guard) =>
|
|
79
114
|
txb.moveCall({
|
|
80
115
|
target:PROTOCOL.RewardFn('guard_add_with_passport') as FnCallType,
|
|
81
|
-
arguments:[passport, reward, guard.guard, txb.pure(guard.portions, BCS.
|
|
116
|
+
arguments:[passport, TXB_OBJECT(txb, reward), TXB_OBJECT(txb, guard.guard), txb.pure(guard.portions, BCS.U8), TXB_OBJECT(txb, permission)],
|
|
82
117
|
typeArguments:[reward_type]
|
|
83
118
|
})
|
|
84
119
|
)
|
|
@@ -86,24 +121,31 @@ export function reward_add_guard(reward_type:string, txb:TransactionBlock, rewar
|
|
|
86
121
|
gurads.forEach((guard) =>
|
|
87
122
|
txb.moveCall({
|
|
88
123
|
target:PROTOCOL.RewardFn('guard_add') as FnCallType,
|
|
89
|
-
arguments:[reward, guard.guard, txb.pure(guard.portions, BCS.
|
|
124
|
+
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, guard.guard), txb.pure(guard.portions, BCS.U8), TXB_OBJECT(txb, permission)],
|
|
90
125
|
typeArguments:[reward_type]
|
|
91
126
|
})
|
|
92
127
|
)
|
|
93
128
|
}
|
|
129
|
+
return true
|
|
94
130
|
}
|
|
95
|
-
export function reward_remove_guard(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
131
|
+
export function reward_remove_guard(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
132
|
+
permission:PermissionObject, guards:string[], removeall?:boolean, passport?:PassportObject) : boolean {
|
|
133
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
134
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
135
|
+
if (!removeall && !guards) return false;
|
|
136
|
+
if (guards && !IsValidArray(guards, IsValidAddress)) return false;
|
|
137
|
+
|
|
96
138
|
if (passport) {
|
|
97
139
|
if (removeall) {
|
|
98
140
|
txb.moveCall({
|
|
99
141
|
target:PROTOCOL.RewardFn('guard_remove_all_with_passport') as FnCallType,
|
|
100
|
-
arguments:[passport, reward, permission],
|
|
142
|
+
arguments:[passport, TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission)],
|
|
101
143
|
typeArguments:[reward_type]
|
|
102
144
|
})
|
|
103
145
|
} else {
|
|
104
146
|
txb.moveCall({
|
|
105
147
|
target:PROTOCOL.RewardFn('guard_remove_with_passport') as FnCallType,
|
|
106
|
-
arguments:[passport, reward, txb.pure(guards, 'vector<address>'), permission],
|
|
148
|
+
arguments:[passport, TXB_OBJECT(txb, reward), txb.pure(array_unique(guards), 'vector<address>'), TXB_OBJECT(txb, permission)],
|
|
107
149
|
typeArguments:[reward_type]
|
|
108
150
|
})
|
|
109
151
|
}
|
|
@@ -111,74 +153,121 @@ export function reward_remove_guard(reward_type:string, txb:TransactionBlock, re
|
|
|
111
153
|
if (removeall) {
|
|
112
154
|
txb.moveCall({
|
|
113
155
|
target:PROTOCOL.RewardFn('guard_remove_all') as FnCallType,
|
|
114
|
-
arguments:[reward, permission],
|
|
156
|
+
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission)],
|
|
115
157
|
typeArguments:[reward_type]
|
|
116
158
|
})
|
|
117
159
|
} else {
|
|
118
160
|
txb.moveCall({
|
|
119
161
|
target:PROTOCOL.RewardFn('guard_remove') as FnCallType,
|
|
120
|
-
arguments:[reward, txb.pure(guards, 'vector<address>'), permission],
|
|
162
|
+
arguments:[TXB_OBJECT(txb, reward), txb.pure(guards, 'vector<address>'), TXB_OBJECT(txb, permission)],
|
|
121
163
|
typeArguments:[reward_type]
|
|
122
164
|
})
|
|
123
165
|
}
|
|
124
166
|
}
|
|
167
|
+
return true
|
|
168
|
+
}
|
|
169
|
+
export function allow_repeat_claim(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
170
|
+
permission:PermissionObject, allow_repeat_claim:boolean, passport?:PassportObject) : boolean {
|
|
171
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
172
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
173
|
+
|
|
174
|
+
if (passport) {
|
|
175
|
+
txb.moveCall({
|
|
176
|
+
target:PROTOCOL.RewardFn('allow_repeat_claim_with_passport') as FnCallType,
|
|
177
|
+
arguments:[passport, TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission), txb.pure(allow_repeat_claim, BCS.BOOL)],
|
|
178
|
+
typeArguments:[reward_type]
|
|
179
|
+
})
|
|
180
|
+
} else {
|
|
181
|
+
txb.moveCall({
|
|
182
|
+
target:PROTOCOL.RewardFn('allow_repeat_claim') as FnCallType,
|
|
183
|
+
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission), txb.pure(allow_repeat_claim, BCS.BOOL)],
|
|
184
|
+
typeArguments:[reward_type]
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
return true
|
|
125
188
|
}
|
|
126
|
-
export function reward_set_description(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
189
|
+
export function reward_set_description(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
190
|
+
permission:PermissionObject, description:string, passport?:PassportObject) : boolean {
|
|
191
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
192
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
193
|
+
if (!IsValidDesription(description)) return false;
|
|
194
|
+
|
|
127
195
|
if (passport) {
|
|
128
196
|
txb.moveCall({
|
|
129
197
|
target:PROTOCOL.RewardFn('description_set_with_passport') as FnCallType,
|
|
130
|
-
arguments:[passport, reward, txb.pure(
|
|
198
|
+
arguments:[passport, TXB_OBJECT(txb, reward), txb.pure(description), TXB_OBJECT(txb, permission)],
|
|
131
199
|
typeArguments:[reward_type]
|
|
132
200
|
})
|
|
133
201
|
} else {
|
|
134
202
|
txb.moveCall({
|
|
135
203
|
target:PROTOCOL.RewardFn('description_set') as FnCallType,
|
|
136
|
-
arguments:[reward, txb.pure(
|
|
204
|
+
arguments:[TXB_OBJECT(txb, reward), txb.pure(description), TXB_OBJECT(txb, permission)],
|
|
137
205
|
typeArguments:[reward_type]
|
|
138
206
|
})
|
|
139
207
|
}
|
|
208
|
+
return true
|
|
140
209
|
}
|
|
141
|
-
export function reward_lock_guards(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
210
|
+
export function reward_lock_guards(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
211
|
+
permission:PermissionObject, passport?:PassportObject) : boolean {
|
|
212
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
213
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
214
|
+
|
|
142
215
|
if (passport) {
|
|
143
216
|
txb.moveCall({
|
|
144
217
|
target:PROTOCOL.RewardFn('guard_lock_with_passport') as FnCallType,
|
|
145
|
-
arguments:[passport, reward, permission],
|
|
218
|
+
arguments:[passport, TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission)],
|
|
146
219
|
typeArguments:[reward_type]
|
|
147
220
|
})
|
|
148
221
|
} else {
|
|
149
222
|
txb.moveCall({
|
|
150
223
|
target:PROTOCOL.RewardFn('guard_lock') as FnCallType,
|
|
151
|
-
arguments:[reward, permission],
|
|
224
|
+
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission)],
|
|
152
225
|
typeArguments:[reward_type]
|
|
153
226
|
})
|
|
154
227
|
}
|
|
228
|
+
return true
|
|
155
229
|
}
|
|
156
|
-
export function claim(reward_type:string, txb:TransactionBlock, reward:RewardObject, passport?:PassportObject) {
|
|
230
|
+
export function claim(reward_type:string, txb:TransactionBlock, reward:RewardObject, passport?:PassportObject) : boolean {
|
|
231
|
+
if (!IsValidObjects([reward])) return false;
|
|
232
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
233
|
+
|
|
157
234
|
if (passport) {
|
|
158
235
|
txb.moveCall({
|
|
159
236
|
target:PROTOCOL.RewardFn('claim_with_passport') as FnCallType,
|
|
160
|
-
arguments:[passport, reward, txb.object(CLOCK_OBJECT)],
|
|
237
|
+
arguments:[passport, TXB_OBJECT(txb, reward), txb.object(CLOCK_OBJECT)],
|
|
161
238
|
typeArguments:[reward_type]
|
|
162
239
|
})
|
|
163
240
|
} else {
|
|
164
241
|
txb.moveCall({
|
|
165
|
-
target:PROTOCOL.RewardFn('
|
|
166
|
-
arguments:[reward, txb.object(CLOCK_OBJECT)],
|
|
242
|
+
target:PROTOCOL.RewardFn('claim') as FnCallType,
|
|
243
|
+
arguments:[TXB_OBJECT(txb, reward), txb.object(CLOCK_OBJECT)],
|
|
167
244
|
typeArguments:[reward_type]
|
|
168
245
|
})
|
|
169
246
|
}
|
|
247
|
+
return true;
|
|
170
248
|
}
|
|
171
|
-
export function deposit(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
249
|
+
export function deposit(reward_type:string, txb:TransactionBlock, reward:RewardObject, rewards:Reward[]) : boolean {
|
|
250
|
+
if (!IsValidObjects([reward])) return false;
|
|
251
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
252
|
+
if (!rewards && !IsValidObjects(rewards)) return false;
|
|
253
|
+
|
|
172
254
|
txb.moveCall({
|
|
173
255
|
target:PROTOCOL.RewardFn('deposit') as FnCallType,
|
|
174
|
-
arguments:[reward, txb.makeMoveVec({objects:
|
|
256
|
+
arguments:[TXB_OBJECT(txb, reward), txb.makeMoveVec({objects:array_unique(rewards)})], //@
|
|
175
257
|
typeArguments:[reward_type]
|
|
176
258
|
})
|
|
259
|
+
return true
|
|
177
260
|
}
|
|
178
|
-
|
|
261
|
+
|
|
262
|
+
export function change_permission(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
263
|
+
old_permission:PermissionObject, new_permission:PermissionObject) : boolean{
|
|
264
|
+
if (!IsValidObjects([reward, old_permission, new_permission])) return false;
|
|
265
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
266
|
+
|
|
179
267
|
txb.moveCall({
|
|
180
268
|
target:PROTOCOL.RewardFn('permission_set') as FnCallType,
|
|
181
|
-
arguments: [reward, old_permission, new_permission],
|
|
269
|
+
arguments: [TXB_OBJECT(txb, reward), TXB_OBJECT(txb, old_permission), TXB_OBJECT(txb, new_permission)],
|
|
182
270
|
typeArguments:[reward_type]
|
|
183
271
|
})
|
|
272
|
+
return true
|
|
184
273
|
}
|