wowok 1.0.3

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.
@@ -0,0 +1,213 @@
1
+ import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js/transactions';
2
+ import { BCS } from '@mysten/bcs';
3
+ import { name_data, FnCallType, Data_Type, PROTOCOL, description_data} from './protocol';
4
+ import { PassportObject, verify, } from './passport'
5
+ import { PermissionIndex, PermissionObject } from './permission'
6
+
7
+ export const MAX_POLICY_COUNT = 128;
8
+
9
+ export enum Repository_Policy_Mode {
10
+ POLICY_MODE_FREE = 0,
11
+ POLICY_MODE_STRICT = 1,
12
+ }
13
+ export type Repository_Policy = {
14
+ name:string;
15
+ description: string;
16
+ permission?: PermissionIndex;
17
+ value_type: Data_Type;
18
+ }
19
+ export type Repository_Policy_Data = {
20
+ name: string;
21
+ data: Repository_Value[];
22
+ value_type?: Data_Type;
23
+ }
24
+ export type Repository_Value = {
25
+ address: string; // UID: address or objectid
26
+ value: Uint8Array;
27
+ }
28
+
29
+ export type RepositoryAddress = TransactionResult;
30
+ export type RepositoryObject = TransactionResult;
31
+
32
+ export function repository(txb:TransactionBlock, permission:PermissionObject,
33
+ description:string, policy_mode: Repository_Policy_Mode, passport?:PassportObject) : RepositoryObject {
34
+ if (passport) {
35
+ return txb.moveCall({
36
+ target:PROTOCOL.RepositoryFn('new_with_passport') as FnCallType,
37
+ arguments:[passport, txb.pure(description_data(description)), txb.pure(policy_mode, BCS.U8), permission],
38
+ })
39
+ } else {
40
+ return txb.moveCall({
41
+ target:PROTOCOL.RepositoryFn('new') as FnCallType,
42
+ arguments:[txb.pure(description_data(description)), txb.pure(policy_mode, BCS.U8), permission],
43
+ })
44
+ }
45
+ }
46
+
47
+ export function launch(txb:TransactionBlock, repository:RepositoryObject) : RepositoryAddress {
48
+ return txb.moveCall({
49
+ target:PROTOCOL.RepositoryFn('create') as FnCallType,
50
+ arguments:[repository],
51
+ })
52
+ }
53
+ export function destroy(txb:TransactionBlock, repository:RepositoryObject) {
54
+ return txb.moveCall({
55
+ target:PROTOCOL.RepositoryFn('destroy') as FnCallType,
56
+ arguments: [repository],
57
+ })
58
+ }
59
+ export function add_data(txb:TransactionBlock, repository:RepositoryObject, permission:PermissionObject, data:Repository_Policy_Data) {
60
+ if (data?.value_type) {
61
+ data.data.forEach((d) => txb.moveCall({
62
+ target:PROTOCOL.RepositoryFn('add') as FnCallType,
63
+ arguments:[repository,
64
+ txb.pure(d.address, BCS.ADDRESS),
65
+ txb.pure(name_data(data.name)),
66
+ txb.pure(data.value_type, BCS.U8),
67
+ txb.pure(d.value, 'vector<u8>'),
68
+ permission,
69
+ ],
70
+ }))
71
+ } else {
72
+ data.data.forEach((d) => txb.moveCall({
73
+ target:PROTOCOL.RepositoryFn('add_typed_data') as FnCallType,
74
+ arguments:[repository,
75
+ txb.pure(d.address, BCS.ADDRESS),
76
+ txb.pure(name_data(data.name)),
77
+ txb.pure(d.value, 'vector<u8>'),
78
+ permission,
79
+ ],
80
+ }))
81
+ }
82
+ }
83
+
84
+ export function remove(txb:TransactionBlock, repository:RepositoryObject, permission:PermissionObject, address:string, name:string) {
85
+ txb.moveCall({
86
+ target:PROTOCOL.RepositoryFn('remove') as FnCallType,
87
+ arguments:[repository,
88
+ txb.pure(address, BCS.ADDRESS),
89
+ txb.pure(name_data(name)),
90
+ permission,
91
+ ],
92
+ })
93
+ }
94
+ // add or modify the old
95
+ export function repository_add_policies(txb:TransactionBlock, repository:RepositoryObject, permission:PermissionObject, policies:Repository_Policy[], passport?:PassportObject) {
96
+ policies.forEach((policy) => {
97
+ let permission_index = policy?.permission ? txb.pure(policy.permission, BCS.U64) : txb.pure([0], BCS.U8);
98
+ if (passport) {
99
+ txb.moveCall({
100
+ target:PROTOCOL.RepositoryFn('policy_add_with_passport') as FnCallType,
101
+ arguments:[passport, repository,
102
+ txb.pure(name_data(policy.name)),
103
+ txb.pure(description_data(policy.description)),
104
+ permission_index, txb.pure(policy.value_type, BCS.U8)]
105
+ })
106
+ } else {
107
+ txb.moveCall({
108
+ target:PROTOCOL.RepositoryFn('policy_add') as FnCallType,
109
+ arguments:[repository,
110
+ txb.pure(name_data(policy.name)),
111
+ txb.pure(description_data(policy.description)),
112
+ permission_index, txb.pure(policy.value_type, BCS.U8)]
113
+ })
114
+ }
115
+ });
116
+ }
117
+
118
+ export function repository_remove_policies(txb:TransactionBlock, repository:RepositoryObject, permission:PermissionObject, policy_names:string[], removeall?:boolean, passport?:PassportObject) {
119
+ if (passport) {
120
+ if (removeall) {
121
+ txb.moveCall({
122
+ target:PROTOCOL.RepositoryFn('policy_remove_all_with_passport') as FnCallType,
123
+ arguments:[passport, repository, permission]
124
+ })
125
+ } else {
126
+ policy_names.forEach((name) => {
127
+ txb.moveCall({
128
+ target:PROTOCOL.RepositoryFn('policy_remove_with_passport') as FnCallType,
129
+ arguments:[passport, repository, txb.pure(name_data(name)), permission]
130
+ })
131
+ })
132
+ }
133
+ } else {
134
+ if (removeall) {
135
+ txb.moveCall({
136
+ target:PROTOCOL.RepositoryFn('policy_remove_all') as FnCallType,
137
+ arguments:[repository, permission]
138
+ })
139
+ } else {
140
+ policy_names.forEach((name) => {
141
+ txb.moveCall({
142
+ target:PROTOCOL.RepositoryFn('policy_remove') as FnCallType,
143
+ arguments:[repository, txb.pure(name_data(name)), permission]
144
+ })
145
+ })
146
+ }
147
+ }
148
+ }
149
+ // PermissionIndex.repository_description_set
150
+ export function repository_set_description(txb:TransactionBlock, repository:RepositoryObject, permission:PermissionObject, description:string, passport?:PassportObject) {
151
+ if (passport) {
152
+ txb.moveCall({
153
+ target:PROTOCOL.RepositoryFn('description_set_with_passport') as FnCallType,
154
+ arguments:[passport, repository, txb.pure(description_data(description)), permission]
155
+ })
156
+ } else {
157
+ txb.moveCall({
158
+ target:PROTOCOL.RepositoryFn('description_set') as FnCallType,
159
+ arguments:[repository, txb.pure(description_data(description)), permission]
160
+ })
161
+ }
162
+ }
163
+
164
+ export function repository_set_policy_mode(txb:TransactionBlock, repository: RepositoryObject, permission:PermissionObject, policy_mode:Repository_Policy_Mode, passport?:PassportObject) {
165
+ if (passport) {
166
+ txb.moveCall({
167
+ target:PROTOCOL.RepositoryFn('policy_mode_set_with_passport') as FnCallType,
168
+ arguments:[passport, repository, txb.pure(policy_mode), permission]
169
+ })
170
+ } else {
171
+ txb.moveCall({
172
+ target:PROTOCOL.RepositoryFn('policy_mode_set') as FnCallType,
173
+ arguments:[repository, txb.pure(policy_mode), permission]
174
+ })
175
+ }
176
+ }
177
+
178
+ export function repository_set_policy_description(txb:TransactionBlock, repository: RepositoryObject, permission:PermissionObject, description:string, passport?:PassportObject) {
179
+ if (passport) {
180
+ txb.moveCall({
181
+ target:PROTOCOL.RepositoryFn('description_set_with_passport') as FnCallType,
182
+ arguments:[passport, repository, txb.pure(description_data(description)), permission]
183
+ })
184
+ } else {
185
+ txb.moveCall({
186
+ target:PROTOCOL.RepositoryFn('description_set') as FnCallType,
187
+ arguments:[repository, txb.pure(description_data(description)), permission]
188
+ })
189
+ }
190
+ }
191
+
192
+ export function repository_set_policy_permission(txb:TransactionBlock, repository: RepositoryObject, permission:PermissionObject, permission_index:number, passport?:PassportObject) {
193
+ if (passport) {
194
+ txb.moveCall({
195
+ target:PROTOCOL.RepositoryFn('policy_mode_set_with_passport') as FnCallType,
196
+ arguments:[passport, repository, txb.pure(permission_index, BCS.U64), permission]
197
+ })
198
+ } else {
199
+ txb.moveCall({
200
+ target:PROTOCOL.RepositoryFn('policy_mode_set') as FnCallType,
201
+ arguments:[repository, txb.pure(permission_index, BCS.U64), permission]
202
+ })
203
+ }
204
+ }
205
+
206
+ export function change_permission(txb:TransactionBlock, repository:RepositoryObject, old_permission:PermissionObject, new_permission:PermissionObject) {
207
+ txb.moveCall({
208
+ target:PROTOCOL.RepositoryFn('permission_set') as FnCallType,
209
+ arguments: [repository, old_permission, new_permission],
210
+ typeArguments:[]
211
+ })
212
+ }
213
+
package/src/reward.ts ADDED
@@ -0,0 +1,184 @@
1
+ import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js/transactions';
2
+ import { BCS, getSuiMoveConfig, toHEX, fromHEX, BcsReader } from '@mysten/bcs';
3
+ import { CLOCK_OBJECT, FnCallType, description_data, GuardObject, PROTOCOL} from './protocol';
4
+ import { verify, PassportObject} from './passport'
5
+ import { PermissionIndex, PermissionObject } from './permission'
6
+
7
+ export type RewardObject = TransactionResult;
8
+ export type RewardAddress = TransactionResult;
9
+ export type Reward = TransactionResult;
10
+
11
+ export function reward(reward_type:string, txb:TransactionBlock, permission:PermissionObject, description:string, minutes_duration:number, passport?:PassportObject) : RewardObject {
12
+ if (passport) {
13
+ return txb.moveCall({
14
+ target:PROTOCOL.RewardFn('new_with_passport') as FnCallType,
15
+ arguments:[passport, txb.pure(description_data(description)), txb.pure(minutes_duration, BCS.U64),
16
+ txb.object(CLOCK_OBJECT), permission],
17
+ typeArguments:[reward_type]
18
+ })
19
+ } else {
20
+ return txb.moveCall({
21
+ target:PROTOCOL.RewardFn('new') as FnCallType,
22
+ arguments:[txb.pure(description_data(description)), txb.pure(minutes_duration, BCS.U64),
23
+ txb.object(CLOCK_OBJECT), permission],
24
+ typeArguments:[reward_type]
25
+ })
26
+ }
27
+ }
28
+ export function launch(reward_type:string, txb:TransactionBlock, reward:RewardObject): RewardAddress {
29
+ return txb.moveCall({
30
+ target:PROTOCOL.RewardFn('create') as FnCallType,
31
+ arguments:[reward],
32
+ typeArguments:[reward_type]
33
+ })
34
+ }
35
+ export function destroy(reward_type:string, txb:TransactionBlock, reward:RewardObject) {
36
+ return txb.moveCall({
37
+ target:PROTOCOL.RewardFn('destroy') as FnCallType,
38
+ arguments: [reward],
39
+ })
40
+ }
41
+ export function reward_refund(reward_type:string, txb:TransactionBlock, reward:RewardObject, permission:PermissionObject, passport?:PassportObject) {
42
+ if (passport) {
43
+ txb.moveCall({
44
+ target:PROTOCOL.RewardFn('refund_with_passport') as FnCallType,
45
+ arguments:[passport, reward, txb.object(CLOCK_OBJECT), permission],
46
+ typeArguments:[reward_type]
47
+ })
48
+ } else {
49
+ txb.moveCall({
50
+ target:PROTOCOL.RewardFn('refund') as FnCallType,
51
+ arguments:[reward, txb.object(CLOCK_OBJECT), permission],
52
+ typeArguments:[reward_type]
53
+ })
54
+ }
55
+ }
56
+
57
+ export function reward_expand_time(reward_type:string, txb:TransactionBlock, reward:RewardObject, permission:PermissionObject, minutes_expand:number, passport?:PassportObject) {
58
+ if (passport) {
59
+ txb.moveCall({
60
+ target:PROTOCOL.RewardFn('time_expand_with_passport') as FnCallType,
61
+ arguments:[passport, reward, txb.pure(minutes_expand, BCS.U64), permission],
62
+ typeArguments:[reward_type]
63
+ })
64
+ } else {
65
+ txb.moveCall({
66
+ target:PROTOCOL.RewardFn('time_expand') as FnCallType,
67
+ arguments:[reward, txb.pure(minutes_expand, BCS.U64), permission],
68
+ typeArguments:[reward_type]
69
+ })
70
+ }
71
+ }
72
+ export type RewardGuardPortions = {
73
+ guard:GuardObject;
74
+ portions:number;
75
+ }
76
+ export function reward_add_guard(reward_type:string, txb:TransactionBlock, reward:RewardObject, permission:PermissionObject, gurads:RewardGuardPortions[], passport?:PassportObject) {
77
+ if (passport) {
78
+ gurads.forEach((guard) =>
79
+ txb.moveCall({
80
+ target:PROTOCOL.RewardFn('guard_add_with_passport') as FnCallType,
81
+ arguments:[passport, reward, guard.guard, txb.pure(guard.portions, BCS.U64), permission],
82
+ typeArguments:[reward_type]
83
+ })
84
+ )
85
+ } else {
86
+ gurads.forEach((guard) =>
87
+ txb.moveCall({
88
+ target:PROTOCOL.RewardFn('guard_add') as FnCallType,
89
+ arguments:[reward, guard.guard, txb.pure(guard.portions, BCS.U64), permission],
90
+ typeArguments:[reward_type]
91
+ })
92
+ )
93
+ }
94
+ }
95
+ export function reward_remove_guard(reward_type:string, txb:TransactionBlock, reward:RewardObject, permission:PermissionObject, guards:string[], removeall?:boolean, passport?:PassportObject) {
96
+ if (passport) {
97
+ if (removeall) {
98
+ txb.moveCall({
99
+ target:PROTOCOL.RewardFn('guard_remove_all_with_passport') as FnCallType,
100
+ arguments:[passport, reward, permission],
101
+ typeArguments:[reward_type]
102
+ })
103
+ } else {
104
+ txb.moveCall({
105
+ target:PROTOCOL.RewardFn('guard_remove_with_passport') as FnCallType,
106
+ arguments:[passport, reward, txb.pure(guards, 'vector<address>'), permission],
107
+ typeArguments:[reward_type]
108
+ })
109
+ }
110
+ } else {
111
+ if (removeall) {
112
+ txb.moveCall({
113
+ target:PROTOCOL.RewardFn('guard_remove_all') as FnCallType,
114
+ arguments:[reward, permission],
115
+ typeArguments:[reward_type]
116
+ })
117
+ } else {
118
+ txb.moveCall({
119
+ target:PROTOCOL.RewardFn('guard_remove') as FnCallType,
120
+ arguments:[reward, txb.pure(guards, 'vector<address>'), permission],
121
+ typeArguments:[reward_type]
122
+ })
123
+ }
124
+ }
125
+ }
126
+ export function reward_set_description(reward_type:string, txb:TransactionBlock, reward:RewardObject, permission:PermissionObject, description:string, passport?:PassportObject) {
127
+ if (passport) {
128
+ txb.moveCall({
129
+ target:PROTOCOL.RewardFn('description_set_with_passport') as FnCallType,
130
+ arguments:[passport, reward, txb.pure(description_data(description)), permission],
131
+ typeArguments:[reward_type]
132
+ })
133
+ } else {
134
+ txb.moveCall({
135
+ target:PROTOCOL.RewardFn('description_set') as FnCallType,
136
+ arguments:[reward, txb.pure(description_data(description)), permission],
137
+ typeArguments:[reward_type]
138
+ })
139
+ }
140
+ }
141
+ export function reward_lock_guards(reward_type:string, txb:TransactionBlock, reward:RewardObject, permission:PermissionObject, passport?:PassportObject) {
142
+ if (passport) {
143
+ txb.moveCall({
144
+ target:PROTOCOL.RewardFn('guard_lock_with_passport') as FnCallType,
145
+ arguments:[passport, reward, permission],
146
+ typeArguments:[reward_type]
147
+ })
148
+ } else {
149
+ txb.moveCall({
150
+ target:PROTOCOL.RewardFn('guard_lock') as FnCallType,
151
+ arguments:[reward, permission],
152
+ typeArguments:[reward_type]
153
+ })
154
+ }
155
+ }
156
+ export function claim(reward_type:string, txb:TransactionBlock, reward:RewardObject, passport?:PassportObject) {
157
+ if (passport) {
158
+ txb.moveCall({
159
+ target:PROTOCOL.RewardFn('claim_with_passport') as FnCallType,
160
+ arguments:[passport, reward, txb.object(CLOCK_OBJECT)],
161
+ typeArguments:[reward_type]
162
+ })
163
+ } else {
164
+ txb.moveCall({
165
+ target:PROTOCOL.RewardFn('claim_with_passport') as FnCallType,
166
+ arguments:[reward, txb.object(CLOCK_OBJECT)],
167
+ typeArguments:[reward_type]
168
+ })
169
+ }
170
+ }
171
+ export function deposit(reward_type:string, txb:TransactionBlock, reward:RewardObject, reward_objects:Reward[]) {
172
+ txb.moveCall({
173
+ target:PROTOCOL.RewardFn('deposit') as FnCallType,
174
+ arguments:[reward, txb.makeMoveVec({objects:reward_objects})], //@
175
+ typeArguments:[reward_type]
176
+ })
177
+ }
178
+ export function change_permission(reward_type:string, txb:TransactionBlock, reward:RewardObject, old_permission:PermissionObject, new_permission:PermissionObject) {
179
+ txb.moveCall({
180
+ target:PROTOCOL.RewardFn('permission_set') as FnCallType,
181
+ arguments: [reward, old_permission, new_permission],
182
+ typeArguments:[reward_type]
183
+ })
184
+ }