wowok 1.0.3 → 1.0.4
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 +79 -73
- package/dist/machine.js +130 -65
- package/dist/passport.js +14 -5
- package/dist/permission.js +111 -49
- package/dist/progress.js +74 -30
- package/dist/protocol.js +84 -52
- package/dist/repository.js +138 -50
- package/dist/reward.js +134 -28
- package/dist/service.js +457 -161
- package/dist/util.js +16 -1
- package/dist/vote.js +134 -56
- package/package.json +4 -5
- package/src/address.graphql +0 -0
- package/src/demand.ts +96 -52
- package/src/guard.ts +88 -82
- package/src/machine.ts +126 -81
- package/src/object.graphql +30 -0
- package/src/passport.ts +7 -7
- package/src/permission.ts +110 -59
- package/src/progress.ts +89 -58
- package/src/protocol.ts +80 -33
- package/src/repository.ts +146 -70
- package/src/reward.ts +131 -45
- package/src/service.ts +433 -209
- package/src/util.ts +16 -1
- package/src/vote.ts +141 -74
package/src/reward.ts
CHANGED
|
@@ -1,84 +1,117 @@
|
|
|
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 function reward_add_guard(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
97
|
+
export function reward_add_guard(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
98
|
+
permission:PermissionObject, gurads:RewardGuardPortions[], passport?:PassportObject) : boolean {
|
|
99
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
100
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
101
|
+
if (!gurads) return false;
|
|
102
|
+
|
|
103
|
+
let bValid = true;
|
|
104
|
+
gurads.forEach((v) => {
|
|
105
|
+
if (!IsValidUint(v.portions)) bValid = false;
|
|
106
|
+
if (!IsValidObjects([v.guard])) bValid = false;
|
|
107
|
+
})
|
|
108
|
+
if (!bValid) return false;
|
|
109
|
+
|
|
77
110
|
if (passport) {
|
|
78
111
|
gurads.forEach((guard) =>
|
|
79
112
|
txb.moveCall({
|
|
80
113
|
target:PROTOCOL.RewardFn('guard_add_with_passport') as FnCallType,
|
|
81
|
-
arguments:[passport, reward, guard.guard, txb.pure(guard.portions, BCS.U64), permission],
|
|
114
|
+
arguments:[passport, TXB_OBJECT(txb, reward), TXB_OBJECT(txb, guard.guard), txb.pure(guard.portions, BCS.U64), TXB_OBJECT(txb, permission)],
|
|
82
115
|
typeArguments:[reward_type]
|
|
83
116
|
})
|
|
84
117
|
)
|
|
@@ -86,24 +119,31 @@ export function reward_add_guard(reward_type:string, txb:TransactionBlock, rewar
|
|
|
86
119
|
gurads.forEach((guard) =>
|
|
87
120
|
txb.moveCall({
|
|
88
121
|
target:PROTOCOL.RewardFn('guard_add') as FnCallType,
|
|
89
|
-
arguments:[reward, guard.guard, txb.pure(guard.portions, BCS.U64), permission],
|
|
122
|
+
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, guard.guard), txb.pure(guard.portions, BCS.U64), TXB_OBJECT(txb, permission)],
|
|
90
123
|
typeArguments:[reward_type]
|
|
91
124
|
})
|
|
92
125
|
)
|
|
93
126
|
}
|
|
127
|
+
return true
|
|
94
128
|
}
|
|
95
|
-
export function reward_remove_guard(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
129
|
+
export function reward_remove_guard(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
130
|
+
permission:PermissionObject, guards:string[], removeall?:boolean, passport?:PassportObject) : boolean {
|
|
131
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
132
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
133
|
+
if (!removeall && !guards) return false;
|
|
134
|
+
if (guards && !IsValidArray(guards, IsValidAddress)) return false;
|
|
135
|
+
|
|
96
136
|
if (passport) {
|
|
97
137
|
if (removeall) {
|
|
98
138
|
txb.moveCall({
|
|
99
139
|
target:PROTOCOL.RewardFn('guard_remove_all_with_passport') as FnCallType,
|
|
100
|
-
arguments:[passport, reward, permission],
|
|
140
|
+
arguments:[passport, TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission)],
|
|
101
141
|
typeArguments:[reward_type]
|
|
102
142
|
})
|
|
103
143
|
} else {
|
|
104
144
|
txb.moveCall({
|
|
105
145
|
target:PROTOCOL.RewardFn('guard_remove_with_passport') as FnCallType,
|
|
106
|
-
arguments:[passport, reward, txb.pure(guards, 'vector<address>'), permission],
|
|
146
|
+
arguments:[passport, TXB_OBJECT(txb, reward), txb.pure(array_unique(guards), 'vector<address>'), TXB_OBJECT(txb, permission)],
|
|
107
147
|
typeArguments:[reward_type]
|
|
108
148
|
})
|
|
109
149
|
}
|
|
@@ -111,74 +151,120 @@ export function reward_remove_guard(reward_type:string, txb:TransactionBlock, re
|
|
|
111
151
|
if (removeall) {
|
|
112
152
|
txb.moveCall({
|
|
113
153
|
target:PROTOCOL.RewardFn('guard_remove_all') as FnCallType,
|
|
114
|
-
arguments:[reward, permission],
|
|
154
|
+
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission)],
|
|
115
155
|
typeArguments:[reward_type]
|
|
116
156
|
})
|
|
117
157
|
} else {
|
|
118
158
|
txb.moveCall({
|
|
119
159
|
target:PROTOCOL.RewardFn('guard_remove') as FnCallType,
|
|
120
|
-
arguments:[reward, txb.pure(guards, 'vector<address>'), permission],
|
|
160
|
+
arguments:[TXB_OBJECT(txb, reward), txb.pure(guards, 'vector<address>'), TXB_OBJECT(txb, permission)],
|
|
121
161
|
typeArguments:[reward_type]
|
|
122
162
|
})
|
|
123
163
|
}
|
|
124
164
|
}
|
|
165
|
+
return true
|
|
125
166
|
}
|
|
126
|
-
export function
|
|
167
|
+
export function allow_repeat_claim(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
168
|
+
permission:PermissionObject, allow_repeat_claim:boolean, passport?:PassportObject) : boolean {
|
|
169
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
170
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
171
|
+
|
|
172
|
+
if (passport) {
|
|
173
|
+
txb.moveCall({
|
|
174
|
+
target:PROTOCOL.RewardFn('allow_repeat_claim_with_passport') as FnCallType,
|
|
175
|
+
arguments:[passport, TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission), txb.pure(allow_repeat_claim, BCS.BOOL)],
|
|
176
|
+
typeArguments:[reward_type]
|
|
177
|
+
})
|
|
178
|
+
} else {
|
|
179
|
+
txb.moveCall({
|
|
180
|
+
target:PROTOCOL.RewardFn('allow_repeat_claim_with_passport') as FnCallType,
|
|
181
|
+
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission), txb.pure(allow_repeat_claim, BCS.BOOL)],
|
|
182
|
+
typeArguments:[reward_type]
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
return true
|
|
186
|
+
}
|
|
187
|
+
export function reward_set_description(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
188
|
+
permission:PermissionObject, description:string, passport?:PassportObject) : boolean {
|
|
189
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
190
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
191
|
+
if (!IsValidDesription(description)) return false;
|
|
192
|
+
|
|
127
193
|
if (passport) {
|
|
128
194
|
txb.moveCall({
|
|
129
195
|
target:PROTOCOL.RewardFn('description_set_with_passport') as FnCallType,
|
|
130
|
-
arguments:[passport, reward, txb.pure(
|
|
196
|
+
arguments:[passport, TXB_OBJECT(txb, reward), txb.pure(description), TXB_OBJECT(txb, permission)],
|
|
131
197
|
typeArguments:[reward_type]
|
|
132
198
|
})
|
|
133
199
|
} else {
|
|
134
200
|
txb.moveCall({
|
|
135
201
|
target:PROTOCOL.RewardFn('description_set') as FnCallType,
|
|
136
|
-
arguments:[reward, txb.pure(
|
|
202
|
+
arguments:[TXB_OBJECT(txb, reward), txb.pure(description), TXB_OBJECT(txb, permission)],
|
|
137
203
|
typeArguments:[reward_type]
|
|
138
204
|
})
|
|
139
205
|
}
|
|
206
|
+
return true
|
|
140
207
|
}
|
|
141
|
-
export function reward_lock_guards(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
208
|
+
export function reward_lock_guards(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
209
|
+
permission:PermissionObject, passport?:PassportObject) : boolean {
|
|
210
|
+
if (!IsValidObjects([reward, permission])) return false;
|
|
211
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
212
|
+
|
|
142
213
|
if (passport) {
|
|
143
214
|
txb.moveCall({
|
|
144
215
|
target:PROTOCOL.RewardFn('guard_lock_with_passport') as FnCallType,
|
|
145
|
-
arguments:[passport, reward, permission],
|
|
216
|
+
arguments:[passport, TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission)],
|
|
146
217
|
typeArguments:[reward_type]
|
|
147
218
|
})
|
|
148
219
|
} else {
|
|
149
220
|
txb.moveCall({
|
|
150
221
|
target:PROTOCOL.RewardFn('guard_lock') as FnCallType,
|
|
151
|
-
arguments:[reward, permission],
|
|
222
|
+
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission)],
|
|
152
223
|
typeArguments:[reward_type]
|
|
153
224
|
})
|
|
154
225
|
}
|
|
226
|
+
return true
|
|
155
227
|
}
|
|
156
|
-
export function claim(reward_type:string, txb:TransactionBlock, reward:RewardObject, passport?:PassportObject) {
|
|
228
|
+
export function claim(reward_type:string, txb:TransactionBlock, reward:RewardObject, passport?:PassportObject) : boolean {
|
|
229
|
+
if (!IsValidObjects([reward])) return false;
|
|
230
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
157
231
|
if (passport) {
|
|
158
232
|
txb.moveCall({
|
|
159
233
|
target:PROTOCOL.RewardFn('claim_with_passport') as FnCallType,
|
|
160
|
-
arguments:[passport, reward, txb.object(CLOCK_OBJECT)],
|
|
234
|
+
arguments:[passport, TXB_OBJECT(txb, reward), txb.object(CLOCK_OBJECT)],
|
|
161
235
|
typeArguments:[reward_type]
|
|
162
236
|
})
|
|
163
237
|
} else {
|
|
164
238
|
txb.moveCall({
|
|
165
|
-
target:PROTOCOL.RewardFn('
|
|
166
|
-
arguments:[reward, txb.object(CLOCK_OBJECT)],
|
|
239
|
+
target:PROTOCOL.RewardFn('claim') as FnCallType,
|
|
240
|
+
arguments:[TXB_OBJECT(txb, reward), txb.object(CLOCK_OBJECT)],
|
|
167
241
|
typeArguments:[reward_type]
|
|
168
242
|
})
|
|
169
243
|
}
|
|
244
|
+
return true;
|
|
170
245
|
}
|
|
171
|
-
export function deposit(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
246
|
+
export function deposit(reward_type:string, txb:TransactionBlock, reward:RewardObject, rewards:Reward[]) : boolean {
|
|
247
|
+
if (!IsValidObjects([reward])) return false;
|
|
248
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
249
|
+
if (!rewards && !IsValidObjects(rewards)) return false;
|
|
250
|
+
|
|
172
251
|
txb.moveCall({
|
|
173
252
|
target:PROTOCOL.RewardFn('deposit') as FnCallType,
|
|
174
|
-
arguments:[reward, txb.makeMoveVec({objects:
|
|
253
|
+
arguments:[TXB_OBJECT(txb, reward), txb.makeMoveVec({objects:array_unique(rewards)})], //@
|
|
175
254
|
typeArguments:[reward_type]
|
|
176
255
|
})
|
|
256
|
+
return true
|
|
177
257
|
}
|
|
178
|
-
|
|
258
|
+
|
|
259
|
+
export function change_permission(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
260
|
+
old_permission:PermissionObject, new_permission:PermissionObject) : boolean{
|
|
261
|
+
if (!IsValidObjects([reward, old_permission, new_permission])) return false;
|
|
262
|
+
if (!IsValidArgType(reward_type)) return false;
|
|
263
|
+
|
|
179
264
|
txb.moveCall({
|
|
180
265
|
target:PROTOCOL.RewardFn('permission_set') as FnCallType,
|
|
181
|
-
arguments: [reward, old_permission, new_permission],
|
|
266
|
+
arguments: [TXB_OBJECT(txb, reward), TXB_OBJECT(txb, old_permission), TXB_OBJECT(txb, new_permission)],
|
|
182
267
|
typeArguments:[reward_type]
|
|
183
268
|
})
|
|
269
|
+
return true
|
|
184
270
|
}
|