wowok 1.4.27 → 1.4.31

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.4.27",
3
+ "version": "1.4.31",
4
4
  "description": "Create, collaborate, and transact on your own terms with the AI-driven web3 collaboration protocol.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/guard.ts CHANGED
@@ -277,29 +277,35 @@ export class Guard {
277
277
  [MODULES.payment, 'Treasury Address', 1212, [], ValueType.TYPE_ADDRESS, 'The Treasury from which the payment comes.', []],
278
278
  [MODULES.payment, 'Biz-ID', 1213, [], ValueType.TYPE_U64, 'Bisiness ID number of the payment.', []],
279
279
 
280
- [MODULES.withholding, 'Amount', 1300, [], ValueType.TYPE_U64, 'Total amount deposited with withholding.' , []],
281
- [MODULES.withholding, 'Original Type Deposited', 1301, [], ValueType.TYPE_STRING, "Original type name of asserts deposited.", []],
282
- [MODULES.withholding, 'Original Package', 1302, [], ValueType.TYPE_ADDRESS, 'Original package address of asserts deposited.', []],
283
- [MODULES.withholding, 'Original Module', 1303, [], ValueType.TYPE_STRING, 'Original module name of asserts deposited.', []],
284
- [MODULES.withholding, 'Type Deposited', 1304, [], ValueType.TYPE_STRING, 'Type name of asserts deposited.', []],
285
- [MODULES.withholding, 'Package', 1305, [], ValueType.TYPE_ADDRESS, 'Package address of asserts deposited.', , []],
286
- [MODULES.withholding, 'Module', 1306, [], ValueType.TYPE_STRING, 'Module name of asserts deposited.', []],
287
- [MODULES.withholding, 'Balance', 1307, [], ValueType.TYPE_U64, 'The amount currently remaining in withholding.', []],
288
- [MODULES.withholding, 'Deposit Time', 1308, [], ValueType.TYPE_U64, 'Deposit time.', []],
289
- [MODULES.withholding, 'Be Withdrawable', 1309, [], ValueType.TYPE_BOOL, 'Whether to allow amount withdrawal?' , []],
290
- [MODULES.withholding, 'Be Deposited from', 1310, [], ValueType.TYPE_BOOL, 'Is the deposit from source set?', []],
291
- [MODULES.withholding, 'Deposited from Object', 1311, [], ValueType.TYPE_ADDRESS, 'The source object set when depositing.', []],
292
- [MODULES.withholding, 'Contains Guard', 1312, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Whether the guard for withdrawal is set up?', []],
293
- [MODULES.withholding, 'Withdrawal percentage', 1313, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U8, 'The percentage of withdrawals corresponding to Guard.', ['address']],
294
- [MODULES.withholding, 'Number of withdrawals', 1314, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'Number of withdrawals.'],
280
+ [MODULES.reward, 'Amount', 1300, [], ValueType.TYPE_U64, 'Total amount deposited with reward.' , []],
281
+ [MODULES.reward, 'Original Type Deposited', 1301, [], ValueType.TYPE_STRING, "Original type name of asserts deposited.", []],
282
+ [MODULES.reward, 'Original Package', 1302, [], ValueType.TYPE_ADDRESS, 'Original package address of asserts deposited.', []],
283
+ [MODULES.reward, 'Original Module', 1303, [], ValueType.TYPE_STRING, 'Original module name of asserts deposited.', []],
284
+ [MODULES.reward, 'Type Deposited', 1304, [], ValueType.TYPE_STRING, 'Type name of asserts deposited.', []],
285
+ [MODULES.reward, 'Package', 1305, [], ValueType.TYPE_ADDRESS, 'Package address of asserts deposited.', , []],
286
+ [MODULES.reward, 'Module', 1306, [], ValueType.TYPE_STRING, 'Module name of asserts deposited.', []],
287
+ [MODULES.reward, 'Balance', 1307, [], ValueType.TYPE_U64, 'The amount currently remaining in reward.', []],
288
+ [MODULES.reward, 'Deposit Time', 1308, [], ValueType.TYPE_U64, 'Deposit time.', []],
289
+ [MODULES.reward, 'Be Withdrawable', 1309, [], ValueType.TYPE_BOOL, 'Whether to allow amount withdrawal?' , []],
290
+ [MODULES.reward, 'Be Deposited from', 1310, [], ValueType.TYPE_BOOL, 'Is the deposit from source set?', []],
291
+ [MODULES.reward, 'Deposited from Object', 1311, [], ValueType.TYPE_ADDRESS, 'The source object set when depositing.', []],
292
+ [MODULES.reward, 'Contains Guard', 1312, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Whether the guard for withdrawal is set up?', []],
293
+ [MODULES.reward, 'Withdrawal percentage', 1313, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U8, 'The percentage of withdrawals corresponding to Guard.', ['address']],
294
+ [MODULES.reward, 'Number of withdrawals', 1314, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'Number of withdrawals.'],
295
295
 
296
296
  [MODULES.treasury, 'Permission', 1400, [], ValueType.TYPE_ADDRESS, 'Permission object address.', []],
297
297
  [MODULES.treasury, 'Balance', 1401, [], ValueType.TYPE_U64, "Treasury balance.", []],
298
298
  [MODULES.treasury, 'Number of Flow Records', 1402, [], ValueType.TYPE_U64, 'Number of treasury transactions.', []],
299
299
  [MODULES.treasury, 'Inflow Amount', 1403, [], ValueType.TYPE_U128, 'Treasury inflow amount.', []],
300
300
  [MODULES.treasury, 'Outflow Amount', 1404, [], ValueType.TYPE_U128, 'Treasury outflow amount.', []],
301
- [MODULES.treasury, 'Number of Payment', 1405, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The number of flows generated by a payment.', ['payment address']],
302
- [MODULES.treasury, 'Can anyone deposit ', 1406, [], ValueType.TYPE_BOOL, "Whether to allow any address to deposit?", []],
301
+ [MODULES.treasury, 'Has Payment', 1405, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is there a payment in the Treasury flows?', ['payment address']],
302
+ [MODULES.treasury, 'Has Deposit Guard', 1406, [], ValueType.TYPE_BOOL, 'Whether the deposit Guard set?', []],
303
+ [MODULES.treasury, 'Deposit Guard', 1407, [], ValueType.TYPE_ADDRESS, 'Deposit Guard address.', []],
304
+ [MODULES.treasury, 'Number of Withdraw Guards', 1408, [], ValueType.TYPE_U64, 'Number of withdraw guards.', []],
305
+ [MODULES.treasury, 'Has Withdraw Guard', 1409, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Has a Withdraw Guard added?', ['guard address']],
306
+ [MODULES.treasury, 'Withdrawal Amount with Guard', 1410, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'withdrawal amount corresponding the Guard.', ['guard address']],
307
+ [MODULES.treasury, 'Has Payment with operation', 1411, [ValueType.TYPE_ADDRESS, ValueType.TYPE_U8], ValueType.TYPE_BOOL, 'Is there a payment with the operation in the Treasury flows?', ['payment address', 'operation']],
308
+ [MODULES.treasury, 'Withdraw Mode', 1412, [], ValueType.TYPE_U8, 'Treasury withdrawal mode', []],
303
309
  ];
304
310
 
305
311
  static BoolCmd = Guard.QUERIES.filter(q => q[4] === ValueType.TYPE_BOOL);
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './demand'
2
2
  export * from './progress'
3
- export * from './reward'
4
3
  export * from './utils'
5
4
  export * from './permission'
6
5
  export * from './guard'
@@ -16,4 +15,4 @@ export * from './wowok'
16
15
  export * from './resource'
17
16
  export * from './treasury'
18
17
  export * from './payment'
19
- export * from './withholding'
18
+ export * from './reward'
package/src/passport.ts CHANGED
@@ -255,7 +255,6 @@ export class GuardParser {
255
255
  res.forEach((r) => {
256
256
  const c = r.data?.content as any;
257
257
  if (!c) ERROR(Errors.Fail, 'Parse_Guard_Helper invalid content');
258
-
259
258
  const index = protocol.WOWOK_OBJECTS_TYPE().findIndex(v => {return v.includes('guard::Guard') && v == c.type});
260
259
  if (index === -1) ERROR(Errors.Fail, 'Parse_Guard_Helper invalid type: ' + c.type);
261
260
 
package/src/permission.ts CHANGED
@@ -83,7 +83,10 @@ export enum PermissionIndex {
83
83
  treasury_deposit = 702,
84
84
  treasury_withdraw = 703,
85
85
  treasury_descritption = 704,
86
- treasury_free_deposit_set = 705,
86
+ treasury_deposit_guard = 705,
87
+ treasury_withdraw_mode = 706,
88
+ treasury_withdraw_guard = 707,
89
+
87
90
  user_defined_start = 1000,
88
91
  }
89
92
 
@@ -150,12 +153,12 @@ export const PermissionInfo : PermissionInfoType[] = [
150
153
  //{index:PermissionIndex.service_change_order_required_pubkey, name:'Order pubkey', description:'Update Serivce order pubkey', module: 'service'},
151
154
  {index:PermissionIndex.service_pause, name:'Pause', description:'Pause/Unpause Service', module: 'service'},
152
155
 
153
- {index:PermissionIndex.reward, name:'Reward', description:'Launch new Reward', module: 'reward'},
154
- {index:PermissionIndex.reward_refund, name:'Refund', description:'Refund from Reward', module: 'reward'},
155
- {index:PermissionIndex.reward_expand_time, name:'Expand deadline', description:'Expand Reward deadline', module: 'reward'},
156
- {index:PermissionIndex.reward_guard, name:'Guard', description:'Set Reward guard', module: 'reward'},
157
- {index:PermissionIndex.reward_description, name:'Description', description:'Set Reward description', module: 'reward'},
158
- {index:PermissionIndex.reward_lock_guards, name:'Lock Guard', description:'Set Reward guard immutable', module: 'reward'},
156
+ {index:PermissionIndex.reward, name:'reward', description:'Launch new reward', module: 'reward'},
157
+ {index:PermissionIndex.reward_refund, name:'Refund', description:'Refund from reward', module: 'reward'},
158
+ {index:PermissionIndex.reward_expand_time, name:'Expand deadline', description:'Expand reward deadline', module: 'reward'},
159
+ {index:PermissionIndex.reward_guard, name:'Guard', description:'Set reward guard', module: 'reward'},
160
+ {index:PermissionIndex.reward_description, name:'Description', description:'Set reward description', module: 'reward'},
161
+ {index:PermissionIndex.reward_lock_guards, name:'Lock Guard', description:'Set reward guard immutable', module: 'reward'},
159
162
  {index:PermissionIndex.reward_claim_repeatably, name:'Claim repeatably', description:'Allow claimming repeatably', module: 'reward'},
160
163
  {index:PermissionIndex.reward_allow_claiming, name:'Allow claiming', description:'Allow claiming', module: 'reward'},
161
164
 
@@ -186,8 +189,9 @@ export const PermissionInfo : PermissionInfoType[] = [
186
189
  {index:PermissionIndex.treasury_deposit, name: 'Deposit', description:'Deposit coins', module: 'treasury'},
187
190
  {index:PermissionIndex.treasury_receive, name: 'Receive', description:'Receive coins from some address sent', module: 'treasury'},
188
191
  {index:PermissionIndex.treasury_withdraw, name: 'Withdraw', description:'Withdraw coins', module: 'treasury'},
189
- {index:PermissionIndex.treasury_free_deposit_set, name: 'Be Free Deposit', description:'Set whether deposits can be made without permission', module: 'treasury'},
190
- {index:PermissionIndex.treasury_descritption, name: 'Description', description:'Set Treasury description', module: 'treasury'},
192
+ {index:PermissionIndex.treasury_withdraw_guard, name: 'Withdraw Guard', description:'Add/Remove Treasury withdraw guard', module: 'treasury'},
193
+ {index:PermissionIndex.treasury_withdraw_mode, name: 'Withdraw mode', description:'Set Treasury withdraw mode', module: 'treasury'},
194
+ {index:PermissionIndex.treasury_deposit_guard, name: 'Deposit Guard', description:'Set Treasury deposit guard', module: 'treasury'},
191
195
  ]
192
196
 
193
197
  export type PermissionIndexType = PermissionIndex | number;
package/src/protocol.ts CHANGED
@@ -9,7 +9,6 @@ import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui/utils'
9
9
 
10
10
  export enum MODULES {
11
11
  machine = 'machine',
12
- node = 'node',
13
12
  progress = 'progress',
14
13
  repository = 'repository',
15
14
  permission = 'permission',
@@ -25,7 +24,6 @@ export enum MODULES {
25
24
  wowok = 'wowok',
26
25
  treasury = 'treasury',
27
26
  payment = 'payment',
28
- withholding = 'withholding',
29
27
  }
30
28
 
31
29
  export type PermissionAddress = TransactionResult;
@@ -215,11 +213,12 @@ const TESTNET = {
215
213
  }
216
214
  */
217
215
  const TESTNET = {
218
- wowok: "0xb82ef16ea48fb4f732310c3a0c86c34d0b8711f4dac1c4ca693005345047bfa4",
219
- base: '0x74fb58a0b148f19852a721293a797fdeb59dec5da71ca31838fc810af2d32fdd',
220
- wowok_object: '0x41c93c2903227632a33394d37fd3b7f62a33bc72b16a7f9aafc8161b78b232be',
221
- entity_object: '0x0b34c975a4b179755dabdec5c50505bd21c0439c463d171a54fa44f215e3bb57',
222
- treasury_cap:'0xacb8b1d380d4f75a802dd7412142290bebd7f6266785690de2daf68f6a7ba9ce',
216
+ wowok: "0xdc41a2bf843f25c079205f763b5664d503300590329b01772e227bf62adef4dd",
217
+ wowok_origin:'0xdc41a2bf843f25c079205f763b5664d503300590329b01772e227bf62adef4dd' ,
218
+ base: '0x7efcdab72af2351e5915e34ad2ac8d4ea7f4f408e08138d3498af35a362db782',
219
+ wowok_object: '0x346ad6492d083d7a345f233e4af16f451bbd2307cdf7b100faa3bc2a9c8dc8d9',
220
+ entity_object: '0xd2d1b91a348300915b3213c30310fbf2f112c6b2b273096ca78fd85f7c9b8217',
221
+ treasury_cap:'0x538cf8f32d59f58c0450a3a97c1eeed3096f4ce63e07e0bdf343a5cc1464887c',
223
222
  }
224
223
  const MAINNET = {
225
224
  wowok: "",
@@ -270,6 +269,7 @@ export class Protocol {
270
269
  case ENTRYPOINT.testnet:
271
270
  this.package.set('wowok', TESTNET.wowok);
272
271
  this.package.set('base', TESTNET.base);
272
+ this.package.set('wowok_origin', TESTNET.wowok_origin); //@ orgin package!!!
273
273
  this.wowok_object = TESTNET.wowok_object;
274
274
  this.entity_object= TESTNET.entity_object;
275
275
  this.treasury_cap = TESTNET.treasury_cap;
@@ -312,7 +312,6 @@ export class Protocol {
312
312
  RepositoryFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.repository}::${fn}`};
313
313
  PermissionFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.permission}::${fn}`};
314
314
  PassportFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.passport}::${fn}`};
315
- GuardFn = (fn: any) => { return `${this.package.get('base')}::${MODULES.guard}::${fn}`};
316
315
  VoteFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.vote}::${fn}`};
317
316
  DemandFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.demand}::${fn}`};
318
317
  OrderFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.order}::${fn}`};
@@ -323,7 +322,8 @@ export class Protocol {
323
322
  WowokFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.wowok}::${fn}`};
324
323
  TreasuryFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.treasury}::${fn}`};
325
324
  PaymentFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.payment}::${fn}`};
326
- WithholdingFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.withholding}::${fn}`};
325
+ GuardFn = (fn: any) => { return `${this.package.get('base')}::${MODULES.guard}::${fn}`};
326
+ MintFn = (fn: any) => { return `${this.package.get('base')}::${MODULES.wowok}::${fn}`};
327
327
 
328
328
  Query = async (objects: Query_Param[], options:SuiObjectDataOptions={showContent:true}) : Promise<SuiObjectResponse[]> => {
329
329
  const client = new SuiClient({ url: this.NetworkUrl() });
@@ -367,8 +367,8 @@ export class Protocol {
367
367
  static SUI_TOKEN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'; // TOKEN_TYPE
368
368
  // used in demand, reward, ...
369
369
  static SUI_COIN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0x2::sui::SUI>'; // COIN TYPE
370
- WOWOK_TOKEN_TYPE = () => { return this.package.get('wowok') + '::wowok::WOWOK' }
371
- WOWOK_COIN_TYPE = () => { return '0x2::coin::Coin<' + this.package.get('wowok') + '::wowok::WOWOK>'}
370
+ WOWOK_TOKEN_TYPE = () => { return this.package.get('base') + '::wowok::WOWOK' }
371
+ WOWOK_COIN_TYPE = () => { return '0x2::coin::Coin<' + this.package.get('base') + '::wowok::WOWOK>'}
372
372
  COINS_TYPE = () => {
373
373
  switch(this.network) {
374
374
  case ENTRYPOINT.testnet:
@@ -403,13 +403,13 @@ export class Protocol {
403
403
  CoinTypes_Testnet:CoinTypeInfo[] = [
404
404
  {symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9, alias:true},
405
405
  {symbol:'SUI', type:'0x2::sui::SUI', decimals:9, },
406
- {symbol:'WOW', type:TESTNET.wowok + '::wowok::WOWOK', decimals:9},
406
+ {symbol:'WOW', type:TESTNET.base + '::wowok::WOWOK', decimals:9},
407
407
  ];
408
408
 
409
409
  CoinTypes_Mainnet:CoinTypeInfo[] = [
410
410
  {symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9, alias:true},
411
411
  {symbol:'SUI', type:'0x2::sui::SUI', decimals:9, },
412
- {symbol:'WOW', type:TESTNET.wowok + '::wowok::WOWOK', decimals:9},
412
+ {symbol:'WOW', type:TESTNET.base + '::wowok::WOWOK', decimals:9},
413
413
  {symbol:'USDT', type:'0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', decimals:6},
414
414
  {symbol:'USDC', type:'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN', decimals:6},
415
415
  {symbol:'WETH', type:'0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN', decimals:8},
@@ -449,9 +449,9 @@ export class Protocol {
449
449
  })
450
450
  }
451
451
  WOWOK_OBJECTS_TYPE = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) =>
452
- { let i = this.package.get('wowok') + '::' + key + '::'; return i + capitalize(key); })
452
+ { let i = (key === MODULES.guard ? this.package.get('base') : this.package.get('wowok')) + '::' + key + '::'; return i + capitalize(key); })
453
453
  WOWOK_OBJECTS_PREFIX_TYPE = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) =>
454
- { return this.package.get('wowok') + '::' + key + '::'; })
454
+ { return (key === MODULES.guard ? this.package.get('base') : this.package.get('wowok')) + '::' + key + '::'; })
455
455
  private hasPackage(pack:string) : boolean {
456
456
  for (let value of this.package.values()) {
457
457
  if (value === pack) {
package/src/resource.ts CHANGED
@@ -46,15 +46,34 @@ export class Resource {
46
46
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
47
47
  });
48
48
  }
49
- add(name:string, object:string[]) {
50
- if (!IsValidName(name)) ERROR(Errors.IsValidName, 'add');
51
- if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'add');
49
+ add(name:string, object:string[] | TransactionResult[]) {
50
+ if (object.length === 0) return ;
51
+ var bString = false;
52
+
53
+ if (!IsValidName(name)) ERROR(Errors.IsValidName, 'add.name');
54
+ if (!IsValidArray(object, (item:any) => {
55
+ if (typeof(item) === 'string') {
56
+ bString = true;
57
+ return IsValidAddress(item)
58
+ }
59
+ return true;
60
+ })) {
61
+ ERROR(Errors.IsValidArray, 'add.object');
62
+ }
52
63
 
53
- this.txb.moveCall({
54
- target:Protocol.Instance().ResourceFn('add') as FnCallType,
55
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
56
- this.txb.pure.vector('address', object)]
57
- });
64
+ if (bString) {
65
+ this.txb.moveCall({
66
+ target:Protocol.Instance().ResourceFn('add') as FnCallType,
67
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
68
+ this.txb.pure.vector('address', object as string[])]
69
+ });
70
+ } else {
71
+ this.txb.moveCall({
72
+ target:Protocol.Instance().ResourceFn('add') as FnCallType,
73
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
74
+ this.txb.makeMoveVec({elements:object as TransactionResult[], type:'address'})]
75
+ });
76
+ }
58
77
  }
59
78
 
60
79
  add2(object:TxbObject, name:string[]) {
package/src/reward.ts CHANGED
@@ -264,14 +264,14 @@ export class Reward {
264
264
  }
265
265
  }
266
266
 
267
- deposit(rewards:(TransactionResult | TransactionArgument)[]) {
268
- if (!rewards || !Protocol.IsValidObjects(rewards)) {
267
+ deposit(objects:(TransactionResult | TransactionArgument)[]) {
268
+ if (!objects || !Protocol.IsValidObjects(objects)) {
269
269
  ERROR(Errors.IsValidArray)
270
270
  }
271
271
 
272
272
  this.txb.moveCall({
273
273
  target:Protocol.Instance().RewardFn('deposit') as FnCallType,
274
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.makeMoveVec({elements:array_unique(rewards)})], //@
274
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.makeMoveVec({elements:array_unique(objects)})], //@
275
275
  typeArguments:[this.earnest_type]
276
276
  })
277
277
  }
package/src/treasury.ts CHANGED
@@ -4,6 +4,13 @@ import { FnCallType, Protocol, PassportObject, PermissionObject, TreasuryAddress
4
4
  import { IsValidDesription, IsValidU64, IsValidAddress, IsValidArgType, IsValidArray, parseObjectType} from './utils'
5
5
  import { Errors, ERROR} from './exception'
6
6
 
7
+ export enum WithdrawMode {
8
+ PERMISSION = 0,
9
+ GUARD_ONLY_AND_IMMUTABLE = 1,
10
+ BOTH_PERMISSION_AND_GUARD = 2,
11
+ }
12
+
13
+
7
14
  export interface DepositParam {
8
15
  coin: CoinObject,
9
16
  index: bigint,
@@ -22,6 +29,7 @@ export interface WithdrawParam {
22
29
  remark: string,
23
30
  for_object?: string,
24
31
  for_guard?: string,
32
+ withdraw_guard?: string,
25
33
  }
26
34
  export class Treasury {
27
35
  protected token_type;
@@ -44,13 +52,12 @@ export class Treasury {
44
52
  this.txb = txb;
45
53
  this.object = '';
46
54
  }
47
- static New(txb:TransactionBlock, token_type:string, permission:PermissionObject, description:string,
48
- bFreeDeposit:boolean=false, passport?:PassportObject) : Treasury {
55
+ static New(txb:TransactionBlock, token_type:string, permission:PermissionObject, description:string, passport?:PassportObject) : Treasury {
49
56
  if (!Protocol.IsValidObjects([permission])) {
50
- ERROR(Errors.IsValidObjects, 'permission, bounty');
57
+ ERROR(Errors.IsValidObjects, 'Treasury.New permission, bounty');
51
58
  }
52
59
  if (!IsValidDesription(description)) {
53
- ERROR(Errors.IsValidDesription);
60
+ ERROR(Errors.IsValidDesription, 'Treasury.New.description');
54
61
  }
55
62
  if (!IsValidArgType(token_type)) {
56
63
  ERROR(Errors.IsValidArgType, token_type);
@@ -60,13 +67,13 @@ export class Treasury {
60
67
  if (passport) {
61
68
  d.object = txb.moveCall({
62
69
  target:Protocol.Instance().TreasuryFn('new_with_passport') as FnCallType,
63
- arguments:[passport, txb.pure.bool(bFreeDeposit), txb.pure.string(description), Protocol.TXB_OBJECT(txb, permission)],
70
+ arguments:[passport, txb.pure.string(description), Protocol.TXB_OBJECT(txb, permission)],
64
71
  typeArguments:[token_type],
65
72
  })
66
73
  } else {
67
74
  d.object = txb.moveCall({
68
75
  target:Protocol.Instance().TreasuryFn('new') as FnCallType,
69
- arguments:[txb.pure.bool(bFreeDeposit), txb.pure.string(description), Protocol.TXB_OBJECT(txb, permission)],
76
+ arguments:[txb.pure.string(description), Protocol.TXB_OBJECT(txb, permission)],
70
77
  typeArguments:[token_type],
71
78
  })
72
79
  }
@@ -89,24 +96,47 @@ export class Treasury {
89
96
  })
90
97
  }
91
98
 
92
- set_free_deposit(bFreeDeposit:boolean, passport?:PassportObject) {
99
+ set_deposit_guard(guard?:string, passport?:PassportObject) {
100
+ if (guard && !IsValidAddress(guard)) {
101
+ ERROR(Errors.IsValidAddress, 'set_deposit_guard.guard')
102
+ }
103
+
93
104
  if (passport) {
94
- this.txb.moveCall({
95
- target:Protocol.Instance().TreasuryFn('free_deposit_set_with_passport') as FnCallType,
96
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
97
- this.txb.pure.bool(bFreeDeposit), Protocol.TXB_OBJECT(this.txb, this.permission)],
98
- typeArguments:[this.token_type],
99
- })
105
+ if (guard) {
106
+ this.txb.moveCall({
107
+ target:Protocol.Instance().TreasuryFn('deposit_guard_set_with_passport') as FnCallType,
108
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
109
+ this.txb.object(guard), Protocol.TXB_OBJECT(this.txb, this.permission)],
110
+ typeArguments:[this.token_type],
111
+ })
112
+ } else {
113
+ this.txb.moveCall({
114
+ target:Protocol.Instance().TreasuryFn('deposit_guard_none_with_passport') as FnCallType,
115
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
116
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
117
+ typeArguments:[this.token_type],
118
+ })
119
+ }
100
120
  } else {
101
- this.txb.moveCall({
102
- target:Protocol.Instance().TreasuryFn('free_deposit_set') as FnCallType,
103
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(bFreeDeposit), Protocol.TXB_OBJECT(this.txb, this.permission)],
104
- typeArguments:[this.token_type],
105
- })
121
+ if (guard) {
122
+ this.txb.moveCall({
123
+ target:Protocol.Instance().TreasuryFn('deposit_guard_set') as FnCallType,
124
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
125
+ this.txb.object(guard), Protocol.TXB_OBJECT(this.txb, this.permission)],
126
+ typeArguments:[this.token_type],
127
+ })
128
+ } else {
129
+ this.txb.moveCall({
130
+ target:Protocol.Instance().TreasuryFn('deposit_guard_none') as FnCallType,
131
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
132
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
133
+ typeArguments:[this.token_type],
134
+ })
135
+ }
106
136
  }
107
137
  }
108
138
 
109
- deposit(param:DepositParam, bFreeDeposit:boolean=false, passport?:PassportObject) :TxbObject {
139
+ deposit(param:DepositParam, passport?:PassportObject) :TxbObject {
110
140
  if (!Protocol.IsValidObjects([param.coin])) {
111
141
  ERROR(Errors.IsValidObjects, 'deposit.param.coin')
112
142
  }
@@ -126,76 +156,59 @@ export class Treasury {
126
156
  const for_obj = this.txb.pure.option('address', param.for_object ?? undefined);
127
157
  const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
128
158
 
129
- if (bFreeDeposit) {
159
+ if (passport) {
130
160
  if (param.for_guard) {
131
161
  return this.txb.moveCall({
132
- target:Protocol.Instance().TreasuryFn('free_deposit_forGuard') as FnCallType,
133
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
134
- this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock)],
162
+ target:Protocol.Instance().TreasuryFn('deposit_forGuard_with_passport') as FnCallType,
163
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
164
+ this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
135
165
  typeArguments:[this.token_type],
136
166
  })
137
167
  } else {
138
168
  return this.txb.moveCall({
139
- target:Protocol.Instance().TreasuryFn('free_deposit') as FnCallType,
140
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
141
- this.txb.pure.string(param.remark), for_obj, this.txb.object(clock)],
169
+ target:Protocol.Instance().TreasuryFn('deposit_with_passport') as FnCallType,
170
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
171
+ this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
142
172
  typeArguments:[this.token_type],
143
173
  })
144
174
  }
145
175
  } else {
146
- if (passport) {
147
- if (param.for_guard) {
148
- return this.txb.moveCall({
149
- target:Protocol.Instance().TreasuryFn('deposit_forGuard_with_passport') as FnCallType,
150
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
151
- this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
152
- typeArguments:[this.token_type],
153
- })
154
- } else {
155
- return this.txb.moveCall({
156
- target:Protocol.Instance().TreasuryFn('deposit_with_passport') as FnCallType,
157
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
158
- this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
159
- typeArguments:[this.token_type],
160
- })
161
- }
176
+ if (param.for_guard) {
177
+ return this.txb.moveCall({
178
+ target:Protocol.Instance().TreasuryFn('deposit_forGuard') as FnCallType,
179
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
180
+ this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
181
+ typeArguments:[this.token_type],
182
+ })
162
183
  } else {
163
- if (param.for_guard) {
164
- return this.txb.moveCall({
165
- target:Protocol.Instance().TreasuryFn('deposit_forGuard') as FnCallType,
166
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
167
- this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
168
- typeArguments:[this.token_type],
169
- })
170
- } else {
171
- return this.txb.moveCall({
172
- target:Protocol.Instance().TreasuryFn('deposit') as FnCallType,
173
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
174
- this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
175
- typeArguments:[this.token_type],
176
- })
177
- }
184
+ return this.txb.moveCall({
185
+ target:Protocol.Instance().TreasuryFn('deposit') as FnCallType,
186
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
187
+ this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
188
+ typeArguments:[this.token_type],
189
+ })
178
190
  }
179
191
  }
192
+
180
193
  }
181
194
 
182
195
  receive(payment:PaymentObject, received:ReceivedObject, passport?:PassportObject) {
183
196
  if (!Protocol.IsValidObjects([payment, received])) {
184
197
  ERROR(Errors.IsValidArray, 'receive.payment&received');
185
198
  }
186
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
199
+
187
200
  if (passport) {
188
201
  return this.txb.moveCall({
189
202
  target:Protocol.Instance().TreasuryFn('receive_with_passport') as FnCallType,
190
203
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(received), this.txb.object(payment),
191
- this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
204
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
192
205
  typeArguments:[this.token_type],
193
206
  })
194
207
  } else {
195
208
  return this.txb.moveCall({
196
209
  target:Protocol.Instance().TreasuryFn('receive') as FnCallType,
197
210
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(received), this.txb.object(payment),
198
- this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
211
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
199
212
  typeArguments:[this.token_type],
200
213
  })
201
214
  }
@@ -218,47 +231,73 @@ export class Treasury {
218
231
  if (param?.for_object && !IsValidAddress(param.for_object)) {
219
232
  ERROR(Errors.IsValidAddress, 'withdraw.param.for_object')
220
233
  }
234
+ if (param?.withdraw_guard && !IsValidAddress(param.withdraw_guard)) {
235
+ ERROR(Errors.IsValidAddress, 'withdraw.param.withdraw_guard')
236
+ }
237
+ if (param?.withdraw_guard && !passport) {
238
+ ERROR(Errors.IsValidAddress, 'withdraw.param.withdraw_guard')
239
+ }
221
240
 
222
241
  const for_obj = this.txb.pure.option('address', param.for_object ?? undefined);
223
242
  const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
224
243
 
225
- if (passport) {
244
+ if (param.withdraw_guard && passport) { //@ dont need passport, use withdraw guard!
226
245
  if (param.for_guard) {
227
246
  return this.txb.moveCall({
228
- target:Protocol.Instance().TreasuryFn('withdraw_forGuard_with_passport') as FnCallType,
247
+ target:Protocol.Instance().TreasuryFn('withdraw_useGuard_forGuard') as FnCallType,
229
248
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
230
- this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
231
- this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
249
+ this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index), this.txb.pure.string(param.remark),
250
+ for_obj, this.txb.object(param.for_guard), this.txb.object(clock), this.txb.object(param.withdraw_guard)],
232
251
  typeArguments:[this.token_type],
233
252
  })
234
253
  } else {
235
254
  return this.txb.moveCall({
236
- target:Protocol.Instance().TreasuryFn('withdraw_with_passport') as FnCallType,
255
+ target:Protocol.Instance().TreasuryFn('withdraw_useGuard') as FnCallType,
237
256
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
238
- this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
239
- this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
257
+ this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index), this.txb.pure.string(param.remark),
258
+ for_obj, this.txb.object(clock), this.txb.object(param.withdraw_guard)],
240
259
  typeArguments:[this.token_type],
241
260
  })
242
261
  }
243
262
  } else {
244
- if (param.for_guard) {
245
- return this.txb.moveCall({
246
- target:Protocol.Instance().TreasuryFn('withdraw_forGuard') as FnCallType,
247
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
248
- this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
249
- this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
250
- typeArguments:[this.token_type],
251
- })
263
+ if (passport) {
264
+ if (param.for_guard) {
265
+ return this.txb.moveCall({
266
+ target:Protocol.Instance().TreasuryFn('withdraw_forGuard_with_passport') as FnCallType,
267
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
268
+ this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
269
+ this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
270
+ typeArguments:[this.token_type],
271
+ })
272
+ } else {
273
+ return this.txb.moveCall({
274
+ target:Protocol.Instance().TreasuryFn('withdraw_with_passport') as FnCallType,
275
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
276
+ this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
277
+ this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
278
+ typeArguments:[this.token_type],
279
+ })
280
+ }
252
281
  } else {
253
- console.log(param)
254
- return this.txb.moveCall({
255
- target:Protocol.Instance().TreasuryFn('withdraw') as FnCallType,
256
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
257
- this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
258
- this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
259
- typeArguments:[this.token_type],
260
- })
261
- }
282
+ if (param.for_guard) {
283
+ return this.txb.moveCall({
284
+ target:Protocol.Instance().TreasuryFn('withdraw_forGuard') as FnCallType,
285
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
286
+ this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
287
+ this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
288
+ typeArguments:[this.token_type],
289
+ })
290
+ } else {
291
+ console.log(param)
292
+ return this.txb.moveCall({
293
+ target:Protocol.Instance().TreasuryFn('withdraw') as FnCallType,
294
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
295
+ this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
296
+ this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
297
+ typeArguments:[this.token_type],
298
+ })
299
+ }
300
+ }
262
301
  }
263
302
  }
264
303
 
@@ -283,6 +322,90 @@ export class Treasury {
283
322
  }
284
323
  }
285
324
 
325
+ set_withdraw_mode(mode: WithdrawMode, passport?: PassportObject) {
326
+ if (passport) {
327
+ this.txb.moveCall({
328
+ target:Protocol.Instance().TreasuryFn('withdraw_mode_set_with_passport') as FnCallType,
329
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(mode), Protocol.TXB_OBJECT(this.txb, this.permission)],
330
+ typeArguments:[this.token_type],
331
+ })
332
+ } else {
333
+ this.txb.moveCall({
334
+ target:Protocol.Instance().TreasuryFn('withdraw_mode_set') as FnCallType,
335
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(mode), Protocol.TXB_OBJECT(this.txb, this.permission)],
336
+ typeArguments:[this.token_type],
337
+ })
338
+ }
339
+ }
340
+
341
+ add_withdraw_guard(guard:string, amount:bigint, passport?:PassportObject) {
342
+ if (!IsValidAddress(guard)) {
343
+ ERROR(Errors.IsValidAddress, 'add_withdraw_guard.guard')
344
+ }
345
+
346
+ if (!IsValidU64(amount)) {
347
+ ERROR(Errors.IsValidU64, 'add_withdraw_guard.amount')
348
+ }
349
+
350
+ if (passport) {
351
+ this.txb.moveCall({
352
+ target:Protocol.Instance().TreasuryFn('withdraw_guard_add_with_passport') as FnCallType,
353
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(guard), this.txb.pure.u64(amount),
354
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
355
+ typeArguments:[this.token_type],
356
+ })
357
+ } else {
358
+ this.txb.moveCall({
359
+ target:Protocol.Instance().TreasuryFn('withdraw_guard_add') as FnCallType,
360
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(guard), this.txb.pure.u64(amount),
361
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
362
+ typeArguments:[this.token_type],
363
+ })
364
+ }
365
+ }
366
+
367
+ remove_withdraw_guard(guard:string[], removeall?:boolean, passport?:PassportObject) {
368
+ if (guard.length === 0 && !removeall) return ;
369
+
370
+ if (!IsValidArray(guard, IsValidAddress)) {
371
+ ERROR(Errors.IsValidArray, 'add_withdraw_guard.guard')
372
+ }
373
+
374
+ if (passport) {
375
+ if (removeall) {
376
+ this.txb.moveCall({
377
+ target:Protocol.Instance().TreasuryFn('withdraw_guard_remove_all_with_passport') as FnCallType,
378
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
379
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
380
+ typeArguments:[this.token_type],
381
+ })
382
+ } else {
383
+ this.txb.moveCall({
384
+ target:Protocol.Instance().TreasuryFn('withdraw_guard_remove_with_passport') as FnCallType,
385
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', guard),
386
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
387
+ typeArguments:[this.token_type],
388
+ })
389
+ }
390
+ } else {
391
+ if (removeall) {
392
+ this.txb.moveCall({
393
+ target:Protocol.Instance().TreasuryFn('withdraw_guard_remove_all') as FnCallType,
394
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
395
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
396
+ typeArguments:[this.token_type],
397
+ })
398
+ } else {
399
+ this.txb.moveCall({
400
+ target:Protocol.Instance().TreasuryFn('withdraw_guard_remove') as FnCallType,
401
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', guard),
402
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
403
+ typeArguments:[this.token_type],
404
+ })
405
+ }
406
+ }
407
+ }
408
+
286
409
  change_permission(new_permission:PermissionObject) {
287
410
  if (!Protocol.IsValidObjects([new_permission])) {
288
411
  ERROR(Errors.IsValidObjects, 'change_permission.new_permission')
@@ -302,5 +425,6 @@ export class Treasury {
302
425
  static OP_WITHDRAW = 0;
303
426
  static OP_DEPOSIT = 1;
304
427
  static OP_RECEIVE = 2;
428
+ static MAX_WITHDRAW_GUARD_COUNT = 16;
305
429
  }
306
430
 
package/src/wowok.ts CHANGED
@@ -52,7 +52,7 @@ export class Wowok {
52
52
  if (!IsValidAddress(recipient)) ERROR(Errors.IsValidAddress, 'mint');
53
53
  if (!IsValidU64(amount)) ERROR(Errors.IsValidU64, 'mint');
54
54
  this.txb.moveCall({
55
- target:Protocol.Instance().WowokFn('mint') as FnCallType,
55
+ target:Protocol.Instance().MintFn('mint') as FnCallType, //@ base package
56
56
  arguments:[Protocol.TXB_OBJECT(this.txb, Protocol.Instance().TreasuryCap()), this.txb.pure.u64(amount),
57
57
  this.txb.pure.address(recipient)]
58
58
  })
@@ -1,164 +0,0 @@
1
- import { FnCallType, PaymentObject, ReceivedObject, PaymentAddress, Protocol, TxbObject, CoinObject, PassportObject} from './protocol';
2
- import { IsValidDesription, IsValidAddress, Bcs, array_unique, IsValidArray, IsValidName, IsValidU64, IsValidU256, IsValidU8 } from './utils';
3
- import { ERROR, Errors } from './exception';
4
- import { DepositParam, WithdrawParam, WithdrawItem } from './treasury';
5
- import { Transaction as TransactionBlock} from '@mysten/sui/transactions';
6
-
7
- export interface WithholdingGuard {
8
- guard: string,
9
- amount: bigint,
10
- }
11
- export interface WithholdingParam {
12
- guards: WithholdingGuard[]
13
- }
14
-
15
- export class Withholding {
16
- protected object : TxbObject;
17
- protected pay_token_type;
18
- protected txb;
19
-
20
- get_pay_type() { return this.pay_token_type }
21
- get_object() { return this.object }
22
- private constructor(txb:TransactionBlock, pay_token_type:string, ) {
23
- this.object = '';
24
- this.pay_token_type = pay_token_type;
25
- this.txb = txb;
26
- }
27
-
28
- static From(txb:TransactionBlock, pay_token_type:string, object:TxbObject) : Withholding {
29
- if (!pay_token_type) ERROR(Errors.InvalidParam, 'Withholding.From.pay_token_type');
30
- let v = new Withholding(txb, pay_token_type);
31
- v.object = Protocol.TXB_OBJECT(txb, object)
32
- return v
33
- }
34
-
35
- static New(txb:TransactionBlock, pay_token_type:string, param:WithholdingParam) : Withholding {
36
- if (!pay_token_type) ERROR(Errors.InvalidParam, 'Withholding.New_fromAddress.pay_token_type');
37
- if (param.guards.length === 0 || param.guards.length > Withholding.MAX_GUARD_COUNT) {
38
- ERROR(Errors.InvalidParam, 'Withholding.New.param.guards length')
39
- }
40
- if (!IsValidArray(param.guards, (item:WithholdingGuard) => IsValidAddress(item.guard) && IsValidU64(item.amount))) {
41
- ERROR(Errors.InvalidParam, 'Withholding.New.param.guards')
42
- }
43
-
44
- let v = new Withholding(txb, pay_token_type);
45
- const clock = txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
46
-
47
- v.object = txb.moveCall({
48
- target:Protocol.Instance().WithholdingFn('new') as FnCallType,
49
- arguments:[],
50
- typeArguments:[pay_token_type],
51
- })
52
-
53
- param.guards.forEach((i) => {
54
- txb.moveCall({
55
- target:Protocol.Instance().WithholdingFn('add_guard') as FnCallType,
56
- arguments:[txb.object(v.object), txb.object(i.guard), txb.pure.u64(i.amount)],
57
- typeArguments:[pay_token_type],
58
- })
59
- })
60
- return v
61
- }
62
-
63
- launch() : PaymentAddress {
64
- return this.txb.moveCall({
65
- target:Protocol.Instance().WithholdingFn('create') as FnCallType,
66
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
67
- typeArguments:[this.pay_token_type],
68
- })
69
- }
70
-
71
- receive(payment:PaymentObject, received:ReceivedObject) {
72
- if (!Protocol.IsValidObjects([payment, received])) {
73
- ERROR(Errors.IsValidArray, 'receive.payment&received');
74
- }
75
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
76
-
77
- return this.txb.moveCall({
78
- target:Protocol.Instance().WithholdingFn('receive') as FnCallType,
79
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(received), this.txb.object(payment),
80
- this.txb.object(clock)],
81
- typeArguments:[this.pay_token_type],
82
- })
83
- }
84
-
85
- deposit(param:DepositParam) {
86
- if (!Protocol.IsValidObjects([param.coin])) {
87
- ERROR(Errors.IsValidObjects, 'deposit.param.coin')
88
- }
89
- if (!IsValidDesription(param.remark)) {
90
- ERROR(Errors.IsValidDesription, 'deposit.param.remark')
91
- }
92
- if (param?.for_object && !IsValidAddress(param.for_object)) {
93
- ERROR(Errors.IsValidAddress, 'deposit.param.for_object')
94
- }
95
- if (param?.for_guard && !IsValidAddress(param.for_guard)) {
96
- ERROR(Errors.IsValidAddress, 'deposit.param.for_guard')
97
- }
98
- if (param.index !== undefined && !IsValidU64(param.index)) {
99
- ERROR(Errors.InvalidParam, 'deposit.param.index')
100
- }
101
-
102
- const for_obj = this.txb.pure.option('address', param.for_object ?? undefined);
103
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
104
-
105
- if (param.for_guard) {
106
- return this.txb.moveCall({
107
- target:Protocol.Instance().WithholdingFn('deposit_forGuard') as FnCallType,
108
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
109
- this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock)],
110
- typeArguments:[this.pay_token_type],
111
- })
112
- } else {
113
- return this.txb.moveCall({
114
- target:Protocol.Instance().WithholdingFn('deposit') as FnCallType,
115
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
116
- this.txb.pure.string(param.remark), for_obj, this.txb.object(clock)],
117
- typeArguments:[this.pay_token_type],
118
- })
119
- }
120
- }
121
-
122
- // param.treasury -> coins ; param.receiver -> null
123
- withdraw(guard:string, param:WithdrawParam, passport:PassportObject) {
124
- if (param.items.length === 0) return undefined;
125
- if (!IsValidArray(param.items, (item:WithdrawItem) => IsValidU64(item.amount) && IsValidAddress(item.address))) {
126
- ERROR(Errors.IsValidArray, 'withdraw.param.items')
127
- }
128
- if (!IsValidDesription(param.remark)) {
129
- ERROR(Errors.IsValidDesription, 'withdraw.param.remark')
130
- }
131
- if (!IsValidU64(param.index)) {
132
- ERROR(Errors.IsValidU64, 'withdraw.param.index')
133
- }
134
- if (param?.for_guard && !IsValidAddress(param.for_guard)) {
135
- ERROR(Errors.IsValidAddress, 'withdraw.param.for_guard')
136
- }
137
- if (param?.for_object && !IsValidAddress(param.for_object)) {
138
- ERROR(Errors.IsValidAddress, 'withdraw.param.for_object')
139
- }
140
-
141
- const for_obj = this.txb.pure.option('address', param.for_object ?? undefined);
142
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
143
-
144
- if (param.for_guard) {
145
- return this.txb.moveCall({
146
- target:Protocol.Instance().WithholdingFn('withdraw_forGuard') as FnCallType,
147
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(guard), this.txb.object(passport),
148
- this.txb.pure.vector('address', param.items.map(i=>i.address)), this.txb.pure.vector('u64', param.items.map(i=>i.amount)),
149
- this.txb.pure.u64(param.index), this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock)],
150
- typeArguments:[this.pay_token_type],
151
- })
152
- } else {
153
- return this.txb.moveCall({
154
- target:Protocol.Instance().WithholdingFn('withdraw') as FnCallType,
155
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(guard), this.txb.object(passport),
156
- this.txb.pure.vector('address', param.items.map(i=>i.address)), this.txb.pure.vector('u64', param.items.map(i=>i.amount)),
157
- this.txb.pure.u64(param.index), this.txb.pure.string(param.remark), for_obj, this.txb.object(clock)],
158
- typeArguments:[this.pay_token_type],
159
- })
160
- }
161
- }
162
-
163
- static MAX_GUARD_COUNT = 16;
164
- }