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/src/graphql.ts DELETED
@@ -1,123 +0,0 @@
1
- import { gql } from "graphql-tag";
2
-
3
- export const GRAPHQL_OBJECTS_TYPE = gql(`
4
- query objects_type_version($filter:ObjectFilter!) {
5
- objects(filter:$filter) {
6
- nodes {
7
- address
8
- version
9
- asMoveObject {
10
- contents {
11
- type {
12
- repr
13
- }
14
- }
15
- }
16
- }
17
- }
18
- }
19
- `);
20
- export const GRAPHQL_CHILD_OBJECT = gql(`
21
- query object($ObjectID:SuiAddress!) {
22
- object(address:$ObjectID) {
23
- address
24
- asMoveObject {
25
- contents {
26
- json
27
- }
28
- }
29
- }
30
- }
31
- `);
32
-
33
- export const GRAPHQL_OBJECT = gql(`
34
- query object($ObjectID:SuiAddress!) {
35
- object(address:$ObjectID) {
36
- address
37
- asMoveObject {
38
- contents {
39
- json
40
- type {
41
- repr
42
- }
43
- }
44
- }
45
- dynamicFields {
46
- pageInfo {
47
- hasNextPage
48
- endCursor
49
- }
50
- nodes {
51
- name {
52
- json
53
- }
54
- value {
55
- ... on MoveValue {
56
- json
57
- }
58
- ... on MoveObject {
59
- contents {
60
- json
61
- }
62
- }
63
- }
64
- }
65
- }
66
- }
67
- }
68
- `);
69
-
70
- export const GRAPHQL_OWNER = gql(`
71
- query owner($ObjectID:SuiAddress!) {
72
- owner (address: $ObjectID) {
73
- address
74
- dynamicFields {
75
- pageInfo {
76
- hasNextPage
77
- endCursor
78
- }
79
- nodes {
80
- name {
81
- json
82
- }
83
- value {
84
- ... on MoveValue {
85
- json
86
- }
87
- ... on MoveObject {
88
- contents {
89
- json
90
- }
91
- }
92
- }
93
- }
94
- }
95
- }
96
- }
97
- `);
98
-
99
- export const GRAPHQL_OBJECTS = gql(`
100
- query objects($filter:ObjectFilter!){
101
- objects(filter:$filter) {
102
- nodes {
103
- address
104
- asMoveObject {
105
- contents {
106
- json
107
- type {
108
- repr
109
- }
110
- }
111
- }
112
- }
113
- }
114
- }
115
- `);
116
-
117
- export const GRAPHQL_DECIMALS = gql(`
118
- query getTotalSupply($coinType: String!) {
119
- coinMetadata(coinType: $coinType) {
120
- decimals
121
- }
122
- }
123
- `);
package/src/reward.ts DELETED
@@ -1,313 +0,0 @@
1
- import { TransactionArgument, Transaction as TransactionBlock, type TransactionResult, } from '@mysten/sui/transactions';
2
- import { FnCallType, GuardObject, PassportObject, PermissionObject, RewardAddress, Protocol, TxbObject, } from './protocol';
3
- import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidU64, parseObjectType} from './utils';
4
- import { ERROR, Errors } from './exception';
5
-
6
- export type CoinReward = TransactionResult;
7
- export type RewardGuardPortions = {
8
- guard:GuardObject;
9
- portions:number;
10
- }
11
-
12
- export class Reward {
13
- protected earnest_type;
14
- protected permission ;
15
- protected object:TxbObject;
16
- protected txb;
17
-
18
- get_earnest_type() { return this.earnest_type }
19
- get_object() { return this.object }
20
- private constructor(txb:TransactionBlock, earnest_type:string, permission:PermissionObject) {
21
- this.txb = txb
22
- this.earnest_type = earnest_type
23
- this.permission = permission
24
- this.object = ''
25
- }
26
- static From(txb:TransactionBlock, earnest_type:string, permission:PermissionObject, object:TxbObject) : Reward {
27
- let r = new Reward(txb, earnest_type, permission);
28
- r.object = Protocol.TXB_OBJECT(txb, object);
29
- return r
30
- }
31
- static New(txb:TransactionBlock, earnest_type:string, permission:PermissionObject, description:string,
32
- ms_expand:boolean, time:number, passport?:PassportObject) : Reward {
33
- if (!Protocol.IsValidObjects([permission])) {
34
- ERROR(Errors.IsValidObjects, 'permission')
35
- }
36
- if (!IsValidArgType(earnest_type)) {
37
- ERROR(Errors.IsValidArgType, 'earnest_type')
38
- }
39
- if (!IsValidDesription(description)) {
40
- ERROR(Errors.IsValidDesription)
41
- }
42
- if (!IsValidU64(time)) {
43
- ERROR(Errors.IsValidUint, 'time')
44
- }
45
-
46
- let r = new Reward(txb, earnest_type, permission);
47
- const clock = txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
48
- if (passport) {
49
- r.object = txb.moveCall({
50
- target:Protocol.Instance().RewardFn('new_with_passport') as FnCallType,
51
- arguments:[passport, txb.pure.string(description), txb.pure.bool(ms_expand), txb.pure.u64(time),
52
- txb.object(clock), Protocol.TXB_OBJECT(txb, permission)],
53
- typeArguments:[earnest_type]
54
- })
55
- } else {
56
- r.object = txb.moveCall({
57
- target:Protocol.Instance().RewardFn('new') as FnCallType,
58
- arguments:[txb.pure.string(description), txb.pure.bool(ms_expand), txb.pure.u64(time),
59
- txb.object(clock), Protocol.TXB_OBJECT(txb, permission)],
60
- typeArguments:[earnest_type]
61
- })
62
- }
63
- return r
64
- }
65
-
66
- launch(): RewardAddress {
67
- return this.txb.moveCall({
68
- target:Protocol.Instance().RewardFn('create') as FnCallType,
69
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
70
- typeArguments:[this.earnest_type]
71
- })
72
- }
73
-
74
- destroy() {
75
- this.txb.moveCall({
76
- target:Protocol.Instance().RewardFn('destroy') as FnCallType,
77
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object)],
78
- })
79
- }
80
-
81
- refund(passport?:PassportObject) {
82
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
83
- if (passport) {
84
- this.txb.moveCall({
85
- target:Protocol.Instance().RewardFn('refund_with_passport') as FnCallType,
86
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
87
- typeArguments:[this.earnest_type]
88
- })
89
- } else {
90
- this.txb.moveCall({
91
- target:Protocol.Instance().RewardFn('refund') as FnCallType,
92
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
93
- typeArguments:[this.earnest_type]
94
- })
95
- }
96
- }
97
-
98
- expand_time(ms_expand:boolean, time:number, passport?:PassportObject) {
99
- if (!IsValidU64(time)) {
100
- ERROR(Errors.IsValidUint, 'minutes_expand')
101
- }
102
-
103
- if (passport) {
104
- this.txb.moveCall({
105
- target:Protocol.Instance().RewardFn('time_expand_with_passport') as FnCallType,
106
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(ms_expand),
107
- this.txb.pure.u64(time), Protocol.TXB_OBJECT(this.txb, this.permission)],
108
- typeArguments:[this.earnest_type]
109
- })
110
- } else {
111
- this.txb.moveCall({
112
- target:Protocol.Instance().RewardFn('time_expand') as FnCallType,
113
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object),this.txb.pure.bool(ms_expand),
114
- this.txb.pure.u64(time), Protocol.TXB_OBJECT(this.txb, this.permission)],
115
- typeArguments:[this.earnest_type]
116
- })
117
- }
118
- }
119
-
120
- add_guard(guards:RewardGuardPortions[], passport?:PassportObject) {
121
- if (guards.length === 0) return;
122
-
123
- let bValid = true;
124
- guards.forEach((v) => {
125
- if (!IsValidU64(v.portions) || v.portions > Reward.MAX_PORTIONS_COUNT) bValid = false;
126
- if (!Protocol.IsValidObjects([v.guard])) bValid = false;
127
- })
128
- if (!bValid) {
129
- ERROR(Errors.InvalidParam, 'guards')
130
- }
131
-
132
- if (passport) {
133
- guards.forEach((guard) =>
134
- this.txb.moveCall({
135
- target:Protocol.Instance().RewardFn('guard_add_with_passport') as FnCallType,
136
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
137
- Protocol.TXB_OBJECT(this.txb, guard.guard), this.txb.pure.u8(guard.portions),
138
- Protocol.TXB_OBJECT(this.txb, this.permission)],
139
- typeArguments:[this.earnest_type]
140
- })
141
- )
142
- } else {
143
- guards.forEach((guard) =>
144
- this.txb.moveCall({
145
- target:Protocol.Instance().RewardFn('guard_add') as FnCallType,
146
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard.guard),
147
- this.txb.pure.u8(guard.portions), Protocol.TXB_OBJECT(this.txb, this.permission)],
148
- typeArguments:[this.earnest_type]
149
- })
150
- )
151
- }
152
- }
153
-
154
- remove_guard(guards:string[], removeall?:boolean, passport?:PassportObject) {
155
- if (!removeall && guards.length===0) {
156
- return
157
- }
158
-
159
- if (!IsValidArray(guards, IsValidAddress)) {
160
- ERROR(Errors.IsValidArray, 'guards')
161
- }
162
-
163
- if (passport) {
164
- if (removeall) {
165
- this.txb.moveCall({
166
- target:Protocol.Instance().RewardFn('guard_remove_all_with_passport') as FnCallType,
167
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
168
- typeArguments:[this.earnest_type]
169
- })
170
- } else {
171
- this.txb.moveCall({
172
- target:Protocol.Instance().RewardFn('guard_remove_with_passport') as FnCallType,
173
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(guards)),
174
- Protocol.TXB_OBJECT(this.txb, this.permission)],
175
- typeArguments:[this.earnest_type]
176
- })
177
- }
178
- } else {
179
- if (removeall) {
180
- this.txb.moveCall({
181
- target:Protocol.Instance().RewardFn('guard_remove_all') as FnCallType,
182
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
183
- typeArguments:[this.earnest_type]
184
- })
185
- } else {
186
- this.txb.moveCall({
187
- target:Protocol.Instance().RewardFn('guard_remove') as FnCallType,
188
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(guards)),
189
- Protocol.TXB_OBJECT(this.txb, this.permission)],
190
- typeArguments:[this.earnest_type]
191
- })
192
- }
193
- }
194
-
195
- }
196
- allow_repeat_claim(allow_repeat_claim:boolean, passport?:PassportObject) {
197
- if (passport) {
198
- this.txb.moveCall({
199
- target:Protocol.Instance().RewardFn('allow_repeat_claim_with_passport') as FnCallType,
200
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission),
201
- this.txb.pure.bool(allow_repeat_claim)],
202
- typeArguments:[this.earnest_type]
203
- })
204
- } else {
205
- this.txb.moveCall({
206
- target:Protocol.Instance().RewardFn('allow_repeat_claim') as FnCallType,
207
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission),
208
- this.txb.pure.bool(allow_repeat_claim)],
209
- typeArguments:[this.earnest_type]
210
- })
211
- }
212
- }
213
-
214
- set_description(description:string, passport?:PassportObject) {
215
- if (!IsValidDesription(description)) {
216
- ERROR(Errors.IsValidDesription)
217
- }
218
-
219
- if (passport) {
220
- this.txb.moveCall({
221
- target:Protocol.Instance().RewardFn('description_set_with_passport') as FnCallType,
222
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
223
- typeArguments:[this.earnest_type]
224
- })
225
- } else {
226
- this.txb.moveCall({
227
- target:Protocol.Instance().RewardFn('description_set') as FnCallType,
228
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
229
- typeArguments:[this.earnest_type]
230
- })
231
- }
232
- }
233
-
234
- lock_guards(passport?:PassportObject) {
235
- if (passport) {
236
- this.txb.moveCall({
237
- target:Protocol.Instance().RewardFn('guard_lock_with_passport') as FnCallType,
238
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
239
- typeArguments:[this.earnest_type]
240
- })
241
- } else {
242
- this.txb.moveCall({
243
- target:Protocol.Instance().RewardFn('guard_lock') as FnCallType,
244
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
245
- typeArguments:[this.earnest_type]
246
- })
247
- }
248
- }
249
-
250
- claim(passport?:PassportObject) {
251
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
252
- if (passport) {
253
- this.txb.moveCall({
254
- target:Protocol.Instance().RewardFn('claim_with_passport') as FnCallType,
255
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock)],
256
- typeArguments:[this.earnest_type]
257
- })
258
- } else {
259
- this.txb.moveCall({
260
- target:Protocol.Instance().RewardFn('claim') as FnCallType,
261
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock)],
262
- typeArguments:[this.earnest_type]
263
- })
264
- }
265
- }
266
-
267
- deposit(objects:(TransactionResult | TransactionArgument)[]) {
268
- if (!objects || !Protocol.IsValidObjects(objects)) {
269
- ERROR(Errors.IsValidArray)
270
- }
271
-
272
- this.txb.moveCall({
273
- target:Protocol.Instance().RewardFn('deposit') as FnCallType,
274
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.makeMoveVec({elements:array_unique(objects)})], //@
275
- typeArguments:[this.earnest_type]
276
- })
277
- }
278
-
279
- allow_claim(bAllowClaim: boolean, passport?:PassportObject) {
280
- if (passport) {
281
- this.txb.moveCall({
282
- target:Protocol.Instance().RewardFn('allow_claim_with_passport') as FnCallType,
283
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission),
284
- this.txb.pure.bool(bAllowClaim)],
285
- typeArguments:[this.earnest_type]
286
- })
287
- } else {
288
- this.txb.moveCall({
289
- target:Protocol.Instance().RewardFn('allow_claim') as FnCallType,
290
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.pure.bool(bAllowClaim)],
291
- typeArguments:[this.earnest_type]
292
- })
293
- }
294
- }
295
-
296
- change_permission(new_permission:PermissionObject) {
297
- if (!Protocol.IsValidObjects([new_permission])) {
298
- ERROR(Errors.IsValidObjects)
299
- }
300
-
301
- this.txb.moveCall({
302
- target:Protocol.Instance().RewardFn('permission_set') as FnCallType,
303
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
304
- typeArguments:[this.earnest_type]
305
- })
306
- this.permission = new_permission
307
- }
308
- static parseObjectType = (chain_type:string) : string => {
309
- return parseObjectType(chain_type, 'reward::Reward<')
310
- }
311
- static MAX_PORTIONS_COUNT = 600;
312
- static MAX_GUARD_COUNT = 16;
313
- }