wowok 1.4.28 → 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.28",
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/permission.ts CHANGED
@@ -83,7 +83,9 @@ 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,
87
89
 
88
90
  user_defined_start = 1000,
89
91
  }
@@ -151,12 +153,12 @@ export const PermissionInfo : PermissionInfoType[] = [
151
153
  //{index:PermissionIndex.service_change_order_required_pubkey, name:'Order pubkey', description:'Update Serivce order pubkey', module: 'service'},
152
154
  {index:PermissionIndex.service_pause, name:'Pause', description:'Pause/Unpause Service', module: 'service'},
153
155
 
154
- {index:PermissionIndex.reward, name:'Reward', description:'Launch new Reward', module: 'reward'},
155
- {index:PermissionIndex.reward_refund, name:'Refund', description:'Refund from Reward', module: 'reward'},
156
- {index:PermissionIndex.reward_expand_time, name:'Expand deadline', description:'Expand Reward deadline', module: 'reward'},
157
- {index:PermissionIndex.reward_guard, name:'Guard', description:'Set Reward guard', module: 'reward'},
158
- {index:PermissionIndex.reward_description, name:'Description', description:'Set Reward description', module: 'reward'},
159
- {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'},
160
162
  {index:PermissionIndex.reward_claim_repeatably, name:'Claim repeatably', description:'Allow claimming repeatably', module: 'reward'},
161
163
  {index:PermissionIndex.reward_allow_claiming, name:'Allow claiming', description:'Allow claiming', module: 'reward'},
162
164
 
@@ -187,8 +189,9 @@ export const PermissionInfo : PermissionInfoType[] = [
187
189
  {index:PermissionIndex.treasury_deposit, name: 'Deposit', description:'Deposit coins', module: 'treasury'},
188
190
  {index:PermissionIndex.treasury_receive, name: 'Receive', description:'Receive coins from some address sent', module: 'treasury'},
189
191
  {index:PermissionIndex.treasury_withdraw, name: 'Withdraw', description:'Withdraw coins', module: 'treasury'},
190
- {index:PermissionIndex.treasury_free_deposit_set, name: 'Be Free Deposit', description:'Set whether deposits can be made without permission', module: 'treasury'},
191
- {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'},
192
195
  ]
193
196
 
194
197
  export type PermissionIndexType = PermissionIndex | number;
package/src/protocol.ts CHANGED
@@ -24,7 +24,6 @@ export enum MODULES {
24
24
  wowok = 'wowok',
25
25
  treasury = 'treasury',
26
26
  payment = 'payment',
27
- withholding = 'withholding',
28
27
  }
29
28
 
30
29
  export type PermissionAddress = TransactionResult;
@@ -214,11 +213,11 @@ const TESTNET = {
214
213
  }
215
214
  */
216
215
  const TESTNET = {
217
- wowok: "0x6c0d4f3c5f1ceb981721cd44c516bbeadf22f53791906ed00893a64bb788d56c",
218
- wowok_origin:'0xa487291ecede9b713400360ce81d242ad227af8184f07ace1a3dab1bfc920660' ,
216
+ wowok: "0xdc41a2bf843f25c079205f763b5664d503300590329b01772e227bf62adef4dd",
217
+ wowok_origin:'0xdc41a2bf843f25c079205f763b5664d503300590329b01772e227bf62adef4dd' ,
219
218
  base: '0x7efcdab72af2351e5915e34ad2ac8d4ea7f4f408e08138d3498af35a362db782',
220
- wowok_object: '0xb56d70321b3205e994eb8e7664eabc91f361a55d75f363a321c8d4cf012fd6b2',
221
- entity_object: '0x33881b1d2a65886c3068917a20d849e3956771df1bceb7a05678e40bcff30aa2',
219
+ wowok_object: '0x346ad6492d083d7a345f233e4af16f451bbd2307cdf7b100faa3bc2a9c8dc8d9',
220
+ entity_object: '0xd2d1b91a348300915b3213c30310fbf2f112c6b2b273096ca78fd85f7c9b8217',
222
221
  treasury_cap:'0x538cf8f32d59f58c0450a3a97c1eeed3096f4ce63e07e0bdf343a5cc1464887c',
223
222
  }
224
223
  const MAINNET = {
@@ -323,7 +322,6 @@ 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}`};
327
325
  GuardFn = (fn: any) => { return `${this.package.get('base')}::${MODULES.guard}::${fn}`};
328
326
  MintFn = (fn: any) => { return `${this.package.get('base')}::${MODULES.wowok}::${fn}`};
329
327
 
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,8 +52,7 @@ 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
57
  ERROR(Errors.IsValidObjects, 'Treasury.New permission, bounty');
51
58
  }
@@ -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
 
@@ -1,167 +0,0 @@
1
- import { FnCallType, PaymentObject, ReceivedObject, PaymentAddress, Protocol, TxbObject, CoinObject, PassportObject} from './protocol';
2
- import { IsValidDesription, IsValidAddress, IsValidArray, IsValidU64, parseObjectType } 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
- description: string,
14
- }
15
-
16
- export class Withholding {
17
- protected object : TxbObject;
18
- protected pay_token_type;
19
- protected txb;
20
-
21
- get_pay_type() { return this.pay_token_type }
22
- get_object() { return this.object }
23
- private constructor(txb:TransactionBlock, pay_token_type:string, ) {
24
- this.object = '';
25
- this.pay_token_type = pay_token_type;
26
- this.txb = txb;
27
- }
28
-
29
- static From(txb:TransactionBlock, pay_token_type:string, object:TxbObject) : Withholding {
30
- if (!pay_token_type) ERROR(Errors.InvalidParam, 'Withholding.From.pay_token_type');
31
- let v = new Withholding(txb, pay_token_type);
32
- v.object = Protocol.TXB_OBJECT(txb, object)
33
- return v
34
- }
35
-
36
- static New(txb:TransactionBlock, pay_token_type:string, param:WithholdingParam) : Withholding {
37
- if (!pay_token_type) ERROR(Errors.InvalidParam, 'Withholding.New_fromAddress.pay_token_type');
38
- if (!IsValidDesription(param.description)) ERROR(Errors.IsValidDesription, 'Withholding.New.param')
39
-
40
- if (param.guards.length === 0 || param.guards.length > Withholding.MAX_GUARD_COUNT) {
41
- ERROR(Errors.InvalidParam, 'Withholding.New.param.guards length')
42
- }
43
- if (!IsValidArray(param.guards, (item:WithholdingGuard) => IsValidAddress(item.guard) && IsValidU64(item.amount))) {
44
- ERROR(Errors.InvalidParam, 'Withholding.New.param.guards')
45
- }
46
-
47
- let v = new Withholding(txb, pay_token_type);
48
- v.object = txb.moveCall({
49
- target:Protocol.Instance().WithholdingFn('new') as FnCallType,
50
- arguments:[txb.pure.string(param.description)],
51
- typeArguments:[pay_token_type],
52
- })
53
-
54
- param.guards.forEach((i) => {
55
- v.object = txb.moveCall({
56
- target:Protocol.Instance().WithholdingFn('add_guard') as FnCallType,
57
- arguments:[txb.object(v.object), txb.object(i.guard), txb.pure.u64(i.amount)],
58
- typeArguments:[pay_token_type],
59
- })
60
- })
61
- return v
62
- }
63
-
64
- launch() : PaymentAddress {
65
- return this.txb.moveCall({
66
- target:Protocol.Instance().WithholdingFn('create') as FnCallType,
67
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
68
- typeArguments:[this.pay_token_type],
69
- })
70
- }
71
-
72
- receive(payment:PaymentObject, received:ReceivedObject) {
73
- if (!Protocol.IsValidObjects([payment, received])) {
74
- ERROR(Errors.IsValidArray, 'receive.payment&received');
75
- }
76
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
77
-
78
- return this.txb.moveCall({
79
- target:Protocol.Instance().WithholdingFn('receive') as FnCallType,
80
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(received), this.txb.object(payment),
81
- this.txb.object(clock)],
82
- typeArguments:[this.pay_token_type],
83
- })
84
- }
85
-
86
- deposit(param:DepositParam) {
87
- if (!Protocol.IsValidObjects([param.coin])) {
88
- ERROR(Errors.IsValidObjects, 'deposit.param.coin')
89
- }
90
- if (!IsValidDesription(param.remark)) {
91
- ERROR(Errors.IsValidDesription, 'deposit.param.remark')
92
- }
93
- if (param?.for_object && !IsValidAddress(param.for_object)) {
94
- ERROR(Errors.IsValidAddress, 'deposit.param.for_object')
95
- }
96
- if (param?.for_guard && !IsValidAddress(param.for_guard)) {
97
- ERROR(Errors.IsValidAddress, 'deposit.param.for_guard')
98
- }
99
- if (param.index !== undefined && !IsValidU64(param.index)) {
100
- ERROR(Errors.InvalidParam, 'deposit.param.index')
101
- }
102
-
103
- const for_obj = this.txb.pure.option('address', param.for_object ?? undefined);
104
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
105
-
106
- if (param.for_guard) {
107
- return this.txb.moveCall({
108
- target:Protocol.Instance().WithholdingFn('deposit_forGuard') as FnCallType,
109
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
110
- this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock)],
111
- typeArguments:[this.pay_token_type],
112
- })
113
- } else {
114
- return this.txb.moveCall({
115
- target:Protocol.Instance().WithholdingFn('deposit') as FnCallType,
116
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
117
- this.txb.pure.string(param.remark), for_obj, this.txb.object(clock)],
118
- typeArguments:[this.pay_token_type],
119
- })
120
- }
121
- }
122
-
123
- // param.treasury -> coins ; param.receiver -> null
124
- withdraw(guard:string, param:WithdrawParam, passport:PassportObject) {
125
- if (param.items.length === 0) return undefined;
126
- if (!IsValidArray(param.items, (item:WithdrawItem) => IsValidU64(item.amount) && IsValidAddress(item.address))) {
127
- ERROR(Errors.IsValidArray, 'withdraw.param.items')
128
- }
129
- if (!IsValidDesription(param.remark)) {
130
- ERROR(Errors.IsValidDesription, 'withdraw.param.remark')
131
- }
132
- if (!IsValidU64(param.index)) {
133
- ERROR(Errors.IsValidU64, 'withdraw.param.index')
134
- }
135
- if (param?.for_guard && !IsValidAddress(param.for_guard)) {
136
- ERROR(Errors.IsValidAddress, 'withdraw.param.for_guard')
137
- }
138
- if (param?.for_object && !IsValidAddress(param.for_object)) {
139
- ERROR(Errors.IsValidAddress, 'withdraw.param.for_object')
140
- }
141
-
142
- const for_obj = this.txb.pure.option('address', param.for_object ?? undefined);
143
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
144
-
145
- if (param.for_guard) {
146
- return this.txb.moveCall({
147
- target:Protocol.Instance().WithholdingFn('withdraw_forGuard') as FnCallType,
148
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(guard), this.txb.object(passport),
149
- this.txb.pure.vector('address', param.items.map(i=>i.address)), this.txb.pure.vector('u64', param.items.map(i=>i.amount)),
150
- this.txb.pure.u64(param.index), this.txb.pure.string(param.remark), for_obj, this.txb.object(param.for_guard), this.txb.object(clock)],
151
- typeArguments:[this.pay_token_type],
152
- })
153
- } else {
154
- return this.txb.moveCall({
155
- target:Protocol.Instance().WithholdingFn('withdraw') as FnCallType,
156
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(guard), this.txb.object(passport),
157
- this.txb.pure.vector('address', param.items.map(i=>i.address)), this.txb.pure.vector('u64', param.items.map(i=>i.amount)),
158
- this.txb.pure.u64(param.index), this.txb.pure.string(param.remark), for_obj, this.txb.object(clock)],
159
- typeArguments:[this.pay_token_type],
160
- })
161
- }
162
- }
163
- static parseObjectType = (chain_type:string) : string => {
164
- return parseObjectType(chain_type, 'withholding::Withholding<')
165
- }
166
- static MAX_GUARD_COUNT = 16;
167
- }