wowok 1.2.4 → 1.2.7

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.
Files changed (49) hide show
  1. package/dist/demand.d.ts +3 -2
  2. package/dist/demand.d.ts.map +1 -1
  3. package/dist/demand.js +21 -7
  4. package/dist/entity.d.ts +2 -1
  5. package/dist/entity.d.ts.map +1 -1
  6. package/dist/entity.js +23 -7
  7. package/dist/exception.d.ts +3 -1
  8. package/dist/exception.d.ts.map +1 -1
  9. package/dist/exception.js +3 -1
  10. package/dist/guard.js +1 -1
  11. package/dist/machine.js +2 -2
  12. package/dist/permission.d.ts +23 -7
  13. package/dist/permission.d.ts.map +1 -1
  14. package/dist/permission.js +149 -16
  15. package/dist/protocol.d.ts +35 -10
  16. package/dist/protocol.d.ts.map +1 -1
  17. package/dist/protocol.js +129 -21
  18. package/dist/repository.d.ts +6 -3
  19. package/dist/repository.d.ts.map +1 -1
  20. package/dist/repository.js +59 -40
  21. package/dist/resource.d.ts +20 -6
  22. package/dist/resource.d.ts.map +1 -1
  23. package/dist/resource.js +58 -21
  24. package/dist/reward.d.ts +6 -3
  25. package/dist/reward.d.ts.map +1 -1
  26. package/dist/reward.js +43 -19
  27. package/dist/service.d.ts +15 -9
  28. package/dist/service.d.ts.map +1 -1
  29. package/dist/service.js +94 -56
  30. package/dist/utils.d.ts +18 -4
  31. package/dist/utils.d.ts.map +1 -1
  32. package/dist/utils.js +218 -45
  33. package/dist/vote.d.ts +2 -2
  34. package/dist/vote.d.ts.map +1 -1
  35. package/dist/vote.js +14 -14
  36. package/package.json +1 -1
  37. package/src/demand.ts +22 -8
  38. package/src/entity.ts +25 -6
  39. package/src/exception.ts +3 -1
  40. package/src/guard.ts +1 -1
  41. package/src/machine.ts +2 -2
  42. package/src/permission.ts +168 -14
  43. package/src/protocol.ts +127 -17
  44. package/src/repository.ts +64 -44
  45. package/src/resource.ts +61 -20
  46. package/src/reward.ts +46 -23
  47. package/src/service.ts +100 -57
  48. package/src/utils.ts +186 -22
  49. package/src/vote.ts +14 -14
package/src/permission.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BCS } from '@mysten/bcs';
2
2
  import { FnCallType, TxbObject, PermissionObject, PermissionAddress, GuardObject, Protocol} from './protocol';
3
- import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, IsValidUint, Bcs} from './utils';
3
+ import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, IsValidUint, Bcs, IsValidName} from './utils';
4
4
  import { ERROR, Errors } from './exception';
5
5
  import { ValueType } from './protocol';
6
6
 
@@ -9,12 +9,13 @@ export enum PermissionIndex {
9
9
  repository_set_description_set = 101,
10
10
  repository_set_policy_mode = 102,
11
11
  repository_add_policies = 103,
12
- repository_remove_policies = 104,
12
+ repository_remove_policies = 103,
13
13
  repository_set_policy_description = 105,
14
14
  repository_set_policy_permission = 106,
15
15
  repository_reference_add = 107,
16
- repository_reference_remove = 108,
17
- repository_reference_removeall = 108,
16
+ repository_reference_remove = 107,
17
+ repository_reference_removeall = 107,
18
+
18
19
  vote = 150,
19
20
  vote_set_description = 151,
20
21
  vote_set_reference = 152,
@@ -27,19 +28,23 @@ export enum PermissionIndex {
27
28
  vote_lock_deadline = 159,
28
29
  vote_expand_deadline = 160,
29
30
  vote_lock_guard = 161,
31
+
30
32
  service = 200,
31
33
  service_set_description = 201,
32
34
  service_set_price = 202,
33
35
  service_set_stock = 203,
34
36
  service_add_stock = 203,
35
37
  service_reduce_stock = 203,
38
+ service_set_sale_endpoint = 204,
36
39
  service_set_payee = 205,
37
40
  service_repository_add = 206,
38
41
  service_repository_remove = 207,
39
42
  service_add_withdraw_guards = 208,
40
- service_remove_withdraw_guards = 209,
43
+ service_remove_withdraw_guards = 208,
44
+ service_removeall_withdraw_guards = 208,
41
45
  service_add_refund_guards = 210,
42
- service_remove_refund_guards = 211,
46
+ service_remove_refund_guards = 210,
47
+ service_removeall_refund_guards = 210,
43
48
  service_add_sales = 212,
44
49
  service_remove_sales = 213,
45
50
  service_discount_transfer = 214,
@@ -54,11 +59,12 @@ export enum PermissionIndex {
54
59
  service_change_required_pubkey = 222,
55
60
  service_change_order_required_pubkey = 224,
56
61
  service_pause = 225,
62
+
57
63
  reward = 240,
58
64
  reward_refund = 241,
59
65
  reward_expand_time = 242,
60
66
  reward_add_guard = 243,
61
- reward_remove_guard = 244,
67
+ reward_remove_guard = 243,
62
68
  reward_set_description = 245,
63
69
  reward_lock_guards = 246,
64
70
  demand = 260,
@@ -86,6 +92,94 @@ export enum PermissionIndex {
86
92
  user_defined_start = 10000,
87
93
  }
88
94
 
95
+ export interface PermissionInfoType {
96
+ index: number;
97
+ name:string;
98
+ description:string;
99
+ module: string;
100
+ guard?: string;
101
+ }
102
+
103
+ export const PermissionInfo : PermissionInfoType[] = [
104
+ {index:PermissionIndex.repository, name:'Repository', description:'repository', module: 'repository'},
105
+ {index:PermissionIndex.repository_set_description_set, name:'Description', description:'repository_set_description_set', module: 'repository'},
106
+ {index:PermissionIndex.repository_set_policy_mode, name:'Policy mode', description:'repository_set_policy_mode', module: 'repository'},
107
+ {index:PermissionIndex.repository_add_policies, name:'Add Policy', description:'brepository_add_policies', module: 'repository'},
108
+ {index:PermissionIndex.repository_remove_policies, name:'Remove Policy', description:'build machine', module: 'repository'},
109
+ {index:PermissionIndex.repository_set_policy_description, name:'Policy Description', description:'build machine', module: 'repository'},
110
+ {index:PermissionIndex.repository_set_policy_permission, name:'Policy Permission', description:'build machine', module: 'repository'},
111
+ {index:PermissionIndex.repository_reference_add, name:'Add Reference', description:'build machine', module: 'repository'},
112
+ {index:PermissionIndex.repository_reference_remove, name:'Remove Reference', description:'build machine', module: 'repository'},
113
+
114
+ {index:PermissionIndex.vote, name:'Vote', description:'build machine', module: 'vote'},
115
+ {index:PermissionIndex.vote_set_description, name:'Description', description:'build machine', module: 'vote'},
116
+ {index:PermissionIndex.vote_set_reference, name:'Reference', description:'build machine', module: 'vote'},
117
+ {index:PermissionIndex.vote_add_guard, name:'Add Guard', description:'build machine', module: 'vote'},
118
+ {index:PermissionIndex.vote_remove_guard, name:'Remove Guard', description:'build machine', module: 'vote'},
119
+ {index:PermissionIndex.vote_add_option, name:'Add Option', description:'build machine', module: 'vote'},
120
+ {index:PermissionIndex.vote_remove_option, name:'Remove Option', description:'build machine', module: 'vote'},
121
+ {index:PermissionIndex.vote_set_max_choice_count, name:'Choice count', description:'build machine', module: 'vote'},
122
+ {index:PermissionIndex.vote_open_voting, name:'Open voting', description:'build machine', module: 'vote'},
123
+ {index:PermissionIndex.vote_lock_deadline, name:'Lock deadline', description:'build machine', module: 'vote'},
124
+ {index:PermissionIndex.vote_expand_deadline, name:'Expand deadline', description:'build machine', module: 'vote'},
125
+ {index:PermissionIndex.vote_lock_guard, name:'Lock Guard', description:'build machine', module: 'vote'},
126
+
127
+ {index:PermissionIndex.service, name:'Service', description:'build machine', module: 'service'},
128
+ {index:PermissionIndex.service_set_description, name:'Description', description:'build machine', module: 'service'},
129
+ {index:PermissionIndex.service_set_price, name:'Price', description:'build machine', module: 'service'},
130
+ {index:PermissionIndex.service_set_stock, name:'Inventory', description:'build machine', module: 'service'},
131
+ {index:PermissionIndex.service_set_payee, name:'Payee', description:'build machine', module: 'service'},
132
+ {index:PermissionIndex.service_repository_add, name:'Add Repository', description:'build machine', module: 'service'},
133
+ {index:PermissionIndex.service_repository_remove, name:'Remove Repository', description:'build machine', module: 'service'},
134
+ {index:PermissionIndex.service_add_withdraw_guards, name:'Withdraw Guard', description:'Add, remove withdraw guards', module: 'service'},
135
+ {index:PermissionIndex.service_add_refund_guards, name:'Refund Guard', description:'Add, remove refund guards', module: 'service'},
136
+ {index:PermissionIndex.service_remove_refund_guards, name:'Remove Refund Guard', description:'build machine', module: 'service'},
137
+ {index:PermissionIndex.service_add_sales, name:'Add sales', description:'build machine', module: 'service'},
138
+ {index:PermissionIndex.service_remove_sales, name:'Remove sales', description:'build machine', module: 'service'},
139
+ {index:PermissionIndex.service_discount_transfer, name:'Discount', description:'build machine', module: 'service'},
140
+ {index:PermissionIndex.service_withdraw, name:'Withdraw', description:'build machine', module: 'service'},
141
+ {index:PermissionIndex.service_set_buy_guard, name:'Buyer Guard', description:'build machine', module: 'service'},
142
+ {index:PermissionIndex.service_set_machine, name:'Machine', description:'build machine', module: 'service'},
143
+ {index:PermissionIndex.service_set_endpoint, name:'Endpoint', description:'build machine', module: 'service'},
144
+ {index:PermissionIndex.service_publish, name:'Publish', description:'build machine', module: 'service'},
145
+ {index:PermissionIndex.service_clone, name:'Clone', description:'build machine', module: 'service'},
146
+ {index:PermissionIndex.service_set_customer_required, name:'Buyer info', description:'build machine', module: 'service'},
147
+ {index:PermissionIndex.service_change_order_required_pubkey, name:'Order pubkey', description:'build machine', module: 'service'},
148
+ {index:PermissionIndex.service_pause, name:'Pause', description:'build machine', module: 'service'},
149
+
150
+ {index:PermissionIndex.reward, name:'Reward', description:'build machine', module: 'reward'},
151
+ {index:PermissionIndex.reward_refund, name:'Refund', description:'build machine', module: 'reward'},
152
+ {index:PermissionIndex.reward_expand_time, name:'Expand deadline', description:'build machine', module: 'reward'},
153
+ {index:PermissionIndex.reward_add_guard, name:'Add Guard', description:'build machine', module: 'reward'},
154
+ {index:PermissionIndex.reward_remove_guard, name:'Remove Guard', description:'build machine', module: 'reward'},
155
+ {index:PermissionIndex.reward_set_description, name:'Description', description:'build machine', module: 'reward'},
156
+ {index:PermissionIndex.reward_lock_guards, name:'Lock Guard', description:'build machine', module: 'reward'},
157
+
158
+ {index:PermissionIndex.demand, name:'Demand', description:'build machine', module: 'demand'},
159
+ {index:PermissionIndex.demand_refund, name:'Refund', description:'build machine', module: 'demand'},
160
+ {index:PermissionIndex.demand_expand_time, name:'Expand deadline', description:'build machine', module: 'demand'},
161
+ {index:PermissionIndex.demand_set_guard, name:'Guard', description:'build machine', module: 'demand'},
162
+ {index:PermissionIndex.demand_set_description, name:'Description', description:'build machine', module: 'demand'},
163
+ {index:PermissionIndex.demand_yes, name:'Yes', description:'build machine', module: 'demand'},
164
+
165
+ {index:PermissionIndex.machine, name: 'Machine', description:'build machine', module: 'machine'},
166
+ {index:PermissionIndex.machine_set_description, name: 'Description', description:'machine_set_description', module: 'machine'},
167
+ {index:PermissionIndex.machine_add_repository, name: 'Add Repository', description:'machine_add_repository', module: 'machine'},
168
+ {index:PermissionIndex.machine_remove_repository, name: 'Remove Repository', description:'machine_remove_repository', module: 'machine'},
169
+ {index:PermissionIndex.machine_clone, name: 'Clone', description:'machine_clone', module: 'machine'},
170
+ {index:PermissionIndex.machine_add_node, name: 'Add node', description:'machine_add_node/2', module: 'machine'},
171
+ {index:PermissionIndex.machine_remove_node, name: 'Remove node', description:'machine_remove_node', module: 'machine'},
172
+ {index:PermissionIndex.machine_set_endpoint, name: 'Endpoint', description:'machine_set_endpoint', module: 'machine'},
173
+ {index:PermissionIndex.machine_pause, name: 'Pause', description:'machine_pause', module: 'machine'},
174
+ {index:PermissionIndex.machine_publish, name: 'Publish', description:'machine_publish', module: 'machine'},
175
+
176
+ {index:PermissionIndex.progress, name: 'Progress', description:'build progress', module: 'progress'},
177
+ {index:PermissionIndex.progress_set_namedOperator, name: 'Operator', description:'progress_set_namedOperator', module: 'progress'},
178
+ {index:PermissionIndex.progress_bind_task, name: 'Bind', description:'progress_bind_task', module: 'progress'},
179
+ {index:PermissionIndex.progress_set_context_repository, name: 'Repository', description:'progress_set_context_repository', module: 'progress'},
180
+ {index:PermissionIndex.progress_unhold, name: 'Unhold', description:'progress_unhold', module: 'progress'},
181
+ ]
182
+
89
183
  export type PermissionIndexType = PermissionIndex | number;
90
184
 
91
185
  export type Permission_Index = {
@@ -102,7 +196,7 @@ export class Permission {
102
196
  protected protocol;
103
197
  protected object : TxbObject;
104
198
 
105
- get_object() { this.object }
199
+ get_object() { return this.object }
106
200
  private constructor(protocol:Protocol) {
107
201
  this.protocol = protocol;
108
202
  this.object = '';
@@ -117,7 +211,6 @@ export class Permission {
117
211
  if (!IsValidDesription(description)) {
118
212
  ERROR(Errors.IsValidDesription)
119
213
  }
120
-
121
214
  let p = new Permission(protocol);
122
215
  let txb = protocol.CurrentSession();
123
216
  p.object = txb.moveCall({
@@ -142,10 +235,71 @@ export class Permission {
142
235
  arguments: [Protocol.TXB_OBJECT(txb, this.object)],
143
236
  })
144
237
  }
238
+ add_userdefine(index: number, name:string) {
239
+ if (!Permission.IsValidUserDefinedIndex(index)) {
240
+ ERROR(Errors.IsValidUserDefinedIndex, 'add_userdefine');
241
+ }
242
+
243
+ if (!IsValidName(name)) {
244
+ ERROR(Errors.IsValidName, 'add_userdefine');
245
+ }
246
+ let txb = this.protocol.CurrentSession();
247
+ txb.moveCall({
248
+ target:this.protocol.PermissionFn('user_define_add') as FnCallType,
249
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64), txb.pure(name, BCS.STRING)]
250
+ })
251
+ }
252
+
253
+ remove_userdefine(index: number) {
254
+ if (!Permission.IsValidUserDefinedIndex(index)) {
255
+ ERROR(Errors.IsValidUserDefinedIndex, 'add_userdefine');
256
+ }
257
+
258
+ let txb = this.protocol.CurrentSession();
259
+ txb.moveCall({
260
+ target:this.protocol.PermissionFn('user_define_remove') as FnCallType,
261
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64)]
262
+ })
263
+ }
264
+
265
+ change_entity(old_entity: string, new_entity: string) {
266
+ if (!IsValidAddress(old_entity) || !IsValidAddress(new_entity)) {
267
+ ERROR(Errors.IsValidAddress, 'change_entity')
268
+ }
269
+ let txb = this.protocol.CurrentSession();
270
+ txb.moveCall({
271
+ target:this.protocol.PermissionFn('change_entity') as FnCallType,
272
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(old_entity, BCS.ADDRESS),
273
+ txb.pure(new_entity, BCS.ADDRESS) ]
274
+ })
275
+ }
276
+
277
+ add_entity2(entities: string[], index?:PermissionIndexType) {
278
+ if (!entities) {
279
+ ERROR(Errors.InvalidParam, 'add_entity2');
280
+ }
281
+ if (!IsValidArray(entities, IsValidAddress)) {
282
+ ERROR(Errors.IsValidArray, 'add_entity2');
283
+ }
284
+
285
+ let txb = this.protocol.CurrentSession();
286
+ if (index) {
287
+ txb.moveCall({
288
+ target:this.protocol.PermissionFn('add_with_index') as FnCallType,
289
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64),
290
+ txb.pure(array_unique(entities), 'vector<address>')]
291
+ })
292
+ } else {
293
+ txb.moveCall({
294
+ target:this.protocol.PermissionFn('add') as FnCallType,
295
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(entities), 'vector<address>')]
296
+ })
297
+ }
298
+ }
145
299
 
146
300
  add_entity(entities:Permission_Entity[]) {
147
301
  if (!entities) {
148
- ERROR(Errors.InvalidParam, 'entities');
302
+ ERROR(Errors.InvalidParam, 'add_entity');
149
303
  }
150
304
 
151
305
  let bValid = true;
@@ -180,13 +334,13 @@ export class Permission {
180
334
  }
181
335
  }
182
336
  }
183
- if (indexes.length > 0) {
337
+ //if (indexes.length > 0) {
184
338
  txb.moveCall({
185
339
  target:this.protocol.PermissionFn('add_batch') as FnCallType,
186
340
  arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity.entity_address, BCS.ADDRESS),
187
341
  txb.pure(indexes, 'vector<u64>')]
188
342
  })
189
- }
343
+ //}
190
344
  }
191
345
  // set guards
192
346
  guards.forEach(({entity_address, index, guard}) => {
@@ -220,8 +374,7 @@ export class Permission {
220
374
  arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity_address, BCS.ADDRESS),
221
375
  txb.pure(index, BCS.U64)]
222
376
  })
223
- }
224
- ;
377
+ };
225
378
  }
226
379
 
227
380
  remove_index(entity_address:string, index:PermissionIndexType[]) {
@@ -315,6 +468,7 @@ export class Permission {
315
468
  static MAX_ADMIN_COUNT = 64;
316
469
  static MAX_ENTITY_COUNT = 2000;
317
470
  static MAX_PERMISSION_INDEX_COUNT = 200;
471
+ static MAX_PERSONAL_PERMISSION_COUNT = 200;
318
472
  static IsValidUserDefinedIndex = (index:number) => {
319
473
  return index >= PermissionIndex.user_defined_start && IsValidUint(index)
320
474
  }
package/src/protocol.ts CHANGED
@@ -101,6 +101,49 @@ export enum ValueType {
101
101
  TYPE_VEC_STRING = 121,
102
102
  TYPE_U256 = 122,
103
103
  }
104
+ export enum RepositoryValueType {
105
+ Address = 200,
106
+ Address_Vec = 201,
107
+ PositiveNumber = 202,
108
+ PositiveNumber_Vec = 203,
109
+ String = 204,
110
+ String_Vec = 205,
111
+ }
112
+
113
+ export const RepositoryValueTypeInfo = [
114
+ {type: RepositoryValueType.Address, name:'Address', description:'Object id or Personal address.'},
115
+ {type: RepositoryValueType.Address_Vec, name:'Address vector', description:'Vector of address.'},
116
+ {type: RepositoryValueType.String, name:'String', description:'String.'},
117
+ {type: RepositoryValueType.String_Vec, name:'String vector', description:'Vector of string.'},
118
+ {type: RepositoryValueType.PositiveNumber, name:'Positive number', description:'Positive number. including u8, u16 ,..., u256'},
119
+ {type: RepositoryValueType.PositiveNumber_Vec, name:'Positive number vector', description:'Vector of positive number'},
120
+ ]
121
+
122
+ export const ValueTypeInfo = [
123
+ {type:ValueType.TYPE_BOOL, name:'bool'},
124
+ {type:ValueType.TYPE_ADDRESS, name:'address'},
125
+ {type:ValueType.TYPE_U64, name:'u64'},
126
+ {type:ValueType.TYPE_U8, name:'u8'},
127
+ {type:ValueType.TYPE_VEC_U8, name:'vec-u8'},
128
+ {type:ValueType.TYPE_U128, name:'u128'},
129
+ {type:ValueType.TYPE_VEC_ADDRESS, name:'vec-address'},
130
+ {type:ValueType.TYPE_VEC_BOOL, name:'vec-bool'},
131
+ {type:ValueType.TYPE_VEC_VEC_U8, name:'vec-vec-u8'},
132
+ {type:ValueType.TYPE_VEC_U64, name:'vec-u64'},
133
+ {type:ValueType.TYPE_VEC_U128, name:'vec-u128'},
134
+ {type:ValueType.TYPE_OPTION_ADDRESS, name:'opt-address'},
135
+ {type:ValueType.TYPE_OPTION_BOOL, name:'opt-bool'},
136
+ {type:ValueType.TYPE_OPTION_U8, name:'opt-u8'},
137
+ {type:ValueType.TYPE_OPTION_U64, name:'opt-u64'},
138
+ {type:ValueType.TYPE_OPTION_U128, name:'opt-u128'},
139
+ {type:ValueType.TYPE_OPTION_U256, name:'opt-u256'},
140
+ {type:ValueType.TYPE_OPTION_STRING, name:'opt-string'},
141
+ {type:ValueType.TYPE_OPTION_VEC_U8, name:'opt-vec-u8'},
142
+ {type:ValueType.TYPE_VEC_U256, name:'vec-u256'},
143
+ {type:ValueType.TYPE_STRING, name:'string'},
144
+ {type:ValueType.TYPE_VEC_STRING, name:'vec-string'},
145
+ {type:ValueType.TYPE_U256, name:'u256'},
146
+ ]
104
147
 
105
148
  export const OperatorTypeArray = (Object.values(OperatorType) as []).filter((v)=>typeof(v) === 'number') as number[];
106
149
  export const ValueTypeArray = (Object.values(ValueType) as []).filter((v)=>typeof(v) === 'number') as number[];
@@ -155,6 +198,23 @@ export enum ENTRYPOINT {
155
198
  localnet = 'localnet'
156
199
  }
157
200
 
201
+ const TESTNET = {
202
+ package: "0x852fa17575b1ae11932b475110bf46981458fdb67a2f07b922022e1516560fad",
203
+ wowok_object: '0xf98cc6d8bd9feadc5dce7365270b4ffb32f69a5320ab739193d301103e686e8c',
204
+ entity_object: '0xe0469c187499273ec39a575cc28d4d93f0a66b11e1b92028c61bc69bfc1167c6',
205
+ }
206
+
207
+ const MAINNET = {
208
+ package: "",
209
+ wowok_object: '',
210
+ entity_object: '',
211
+ }
212
+
213
+ export interface CoinTypeInfo {
214
+ symbol: string;
215
+ type: string;
216
+ decimals: number;
217
+ }
158
218
  export class Protocol {
159
219
  protected network = '';
160
220
  protected package = '';
@@ -175,6 +235,9 @@ export class Protocol {
175
235
  Protocol._instance = new Protocol();
176
236
  }; return Protocol._instance
177
237
  }
238
+ static Client() : SuiClient {
239
+ return new SuiClient({ url: Protocol.Instance().NetworkUrl() });
240
+ }
178
241
 
179
242
  UseNetwork(network:ENTRYPOINT=ENTRYPOINT.testnet) {
180
243
  this.network = network;
@@ -184,12 +247,16 @@ export class Protocol {
184
247
  case ENTRYPOINT.devnet:
185
248
  break;
186
249
  case ENTRYPOINT.testnet:
187
- this.package = "0x36cf5c284b715bfad79d281f040c225affe36be0e4c79646b946cfe4808243c8";
188
- this.wowok_object = '0x1fb5abaf85afa41a4b7766c07b3894dd5f81938693bf7c19c354f97f28ea2791';
189
- this.entity_object= '0xea38eaef3446eec1b131f21ca6a6f8b2b38bb16f5b660bafea5904b6a49128e9';
250
+ this.package = TESTNET.package;
251
+ this.wowok_object = TESTNET.wowok_object;
252
+ this.entity_object= TESTNET.entity_object;
190
253
  this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
191
254
  break;
192
255
  case ENTRYPOINT.mainnet:
256
+ this.package = MAINNET.package;
257
+ this.wowok_object = MAINNET.wowok_object;
258
+ this.entity_object= MAINNET.entity_object;
259
+ this.graphql = 'https://sui-mainnet.mystenlabs.com/graphql';
193
260
  break;
194
261
  };
195
262
  }
@@ -269,29 +336,70 @@ export class Protocol {
269
336
  }
270
337
 
271
338
  // used in service, discount, order, because service has COIN wrapper for TOKEN
272
- static SUI_TOKEN_TYPE = '0x2::sui::SUI'; // TOKEN_TYPE
339
+ static SUI_TOKEN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'; // TOKEN_TYPE
273
340
  // used in demand, reward, ...
274
- static SUI_COIN_TYPE = '0x2::coin::Coin<0x2::sui::SUI>'; // COIN TYPE
341
+ static SUI_COIN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0x2::sui::SUI>'; // COIN TYPE
275
342
  WOWOK_TOKEN_TYPE = () => { return this.package + '::wowok::WOWOK' }
276
343
  WOWOK_COIN_TYPE = () => { return '0x2::coin::Coin<' + this.package + '::wowok::WOWOK>'}
277
344
  COINS_TYPE = () => {
278
345
  switch(this.network) {
279
346
  case ENTRYPOINT.testnet:
280
- /*return [
281
- {name:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9},
282
- {name:'WOW', type:this.WOWOK_TOKEN_TYPE(), decimals:9},
283
- ];*/
347
+ return this.CoinTypes_Testnet;
284
348
  case ENTRYPOINT.mainnet:
285
- return [
286
- {name:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9},
287
- {name:'WOW', type:this.WOWOK_TOKEN_TYPE(), decimals:9},
288
- {name:'USDT', type:'0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', decimals:6},
289
- {name:'USDC', type:'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN', decimals:6},
290
- {name:'WETH', type:'0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN', decimals:8},
291
- {name:'WBNB', type:'0xb848cce11ef3a8f62eccea6eb5b35a12c4c2b1ee1af7755d02d7bd6218e8226f::coin::COIN', decimals:8},
292
- ];
349
+ return this.CoinTypes_Mainnet;
293
350
  }; return [];
294
351
  }
352
+ Update_CoinType = (token_type: string, decimals:number, symbol: string) => {
353
+ if (!symbol || !token_type) return ;
354
+ switch(this.network) {
355
+ case ENTRYPOINT.testnet:
356
+ var r = this.CoinTypes_Testnet.filter((v) => v?.type !== token_type);
357
+ r.push({symbol:symbol, type:token_type, decimals:decimals});
358
+ this.CoinTypes_Testnet = r;
359
+ break;
360
+ case ENTRYPOINT.mainnet:
361
+ var r = this.CoinTypes_Mainnet.filter((v) => v?.type !== token_type);
362
+ r.push({symbol:symbol, type:token_type, decimals:decimals});
363
+ this.CoinTypes_Mainnet = r;
364
+ break;
365
+ };
366
+ }
367
+ ExplorerUrl = (objectid: string, type:'object' | 'txblock' | 'account'='object') => {
368
+ if (this.network === ENTRYPOINT.testnet) {
369
+ return 'https://testnet.suivision.xyz/' + type + '/' + objectid;
370
+ } else if (this.network === ENTRYPOINT.mainnet) {
371
+ return 'https://suivision.xyz/' + type + '/' + objectid;
372
+ }; return ''
373
+ }
374
+
375
+ CoinTypes_Testnet:CoinTypeInfo[] = [
376
+ {symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9},
377
+ {symbol:'SUI', type:'0x2::sui::SUI', decimals:9},
378
+ {symbol:'WOW', type:TESTNET.package + '::wowok::WOWOK', decimals:9},
379
+ {symbol:'USDT', type:'0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', decimals:6},
380
+ {symbol:'USDC', type:'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN', decimals:6},
381
+ {symbol:'WETH', type:'0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN', decimals:8},
382
+ {symbol:'WBNB', type:'0xb848cce11ef3a8f62eccea6eb5b35a12c4c2b1ee1af7755d02d7bd6218e8226f::coin::COIN', decimals:8},
383
+ ];
384
+
385
+ CoinTypes_Mainnet:CoinTypeInfo[] = [
386
+ ];
387
+
388
+ GetCoinTypeInfo = (token_type: string, handler:(info:CoinTypeInfo)=>void) : CoinTypeInfo | 'loading' => {
389
+ let r = this.COINS_TYPE().find((v) => v?.type === token_type);
390
+ if (!r) {
391
+ Protocol.Client().getCoinMetadata({coinType:token_type}).then((res) => {
392
+ if (res?.decimals && res?.symbol) {
393
+ this.Update_CoinType(token_type, res?.decimals, res?.symbol);
394
+ handler({symbol:res.symbol, decimals:res.decimals, type:token_type});
395
+ }
396
+ }).catch((e) => {
397
+ console.log(e);
398
+ })
399
+ } else {
400
+ return r;
401
+ }; return 'loading';
402
+ }
295
403
 
296
404
  static CLOCK_OBJECT = Inputs.SharedObjectRef({
297
405
  objectId:"0x6",
@@ -316,6 +424,7 @@ export class Protocol {
316
424
  WOWOK_OBJECTS_PREFIX_TYPE = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) =>
317
425
  { return this.package + '::' + key + '::'; })
318
426
  object_name_from_type_repr = (type_repr:string) : string => {
427
+ if (!type_repr) return ''
319
428
  let i = type_repr.indexOf('::');
320
429
  if (i > 0 && type_repr.slice(0, i) === this.package) {
321
430
  i = type_repr.indexOf('<');
@@ -339,6 +448,7 @@ export class RpcResultParser {
339
448
  return names;
340
449
  }
341
450
  static objectids_from_response = (protocol:Protocol, response:SuiTransactionBlockResponse, concat_result?:Map<string, TxbObject[]>): Map<string, TxbObject[]> => {
451
+ // console.log(response)
342
452
  let ret = new Map<string, string[]>();
343
453
  if (response?.objectChanges) {
344
454
  response.objectChanges.forEach((change) => {