wowok 1.4.28 → 1.4.32
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 +2 -3
- package/src/exception.ts +1 -1
- package/src/guard.ts +23 -17
- package/src/index.ts +1 -2
- package/src/permission.ts +12 -9
- package/src/protocol.ts +4 -6
- package/src/resource.ts +27 -8
- package/src/reward.ts +3 -3
- package/src/treasury.ts +203 -80
- package/src/withholding.ts +0 -167
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wowok",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.32",
|
|
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",
|
|
@@ -38,8 +38,7 @@
|
|
|
38
38
|
"move language",
|
|
39
39
|
"move",
|
|
40
40
|
"treasury",
|
|
41
|
-
"payment"
|
|
42
|
-
"Withholding"
|
|
41
|
+
"payment"
|
|
43
42
|
],
|
|
44
43
|
"author": "wowok",
|
|
45
44
|
"license": "Apache-2.0",
|
package/src/exception.ts
CHANGED
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.
|
|
281
|
-
[MODULES.
|
|
282
|
-
[MODULES.
|
|
283
|
-
[MODULES.
|
|
284
|
-
[MODULES.
|
|
285
|
-
[MODULES.
|
|
286
|
-
[MODULES.
|
|
287
|
-
[MODULES.
|
|
288
|
-
[MODULES.
|
|
289
|
-
[MODULES.
|
|
290
|
-
[MODULES.
|
|
291
|
-
[MODULES.
|
|
292
|
-
[MODULES.
|
|
293
|
-
[MODULES.
|
|
294
|
-
[MODULES.
|
|
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, '
|
|
302
|
-
[MODULES.treasury, '
|
|
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 './
|
|
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
|
-
|
|
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:'
|
|
155
|
-
{index:PermissionIndex.reward_refund, name:'Refund', description:'Refund from
|
|
156
|
-
{index:PermissionIndex.reward_expand_time, name:'Expand deadline', description:'Expand
|
|
157
|
-
{index:PermissionIndex.reward_guard, name:'Guard', description:'Set
|
|
158
|
-
{index:PermissionIndex.reward_description, name:'Description', description:'Set
|
|
159
|
-
{index:PermissionIndex.reward_lock_guards, name:'Lock Guard', description:'Set
|
|
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.
|
|
191
|
-
{index:PermissionIndex.
|
|
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: "
|
|
218
|
-
wowok_origin:'
|
|
216
|
+
wowok: "0xe73417677a2f16a4f1d152f4f3ba0986d8aad0adc214a9477b4dcebd7dcfcc50",
|
|
217
|
+
wowok_origin:'0xe73417677a2f16a4f1d152f4f3ba0986d8aad0adc214a9477b4dcebd7dcfcc50' ,
|
|
219
218
|
base: '0x7efcdab72af2351e5915e34ad2ac8d4ea7f4f408e08138d3498af35a362db782',
|
|
220
|
-
wowok_object: '
|
|
221
|
-
entity_object: '
|
|
219
|
+
wowok_object: '0xf8279dc84a34795e8f9270ebee06a07d6d90bc6c8b2e6d809eb376035d796607',
|
|
220
|
+
entity_object: '0x04b091c8023806557065747ee50f89a9837655a957813c1dc0f235ba9652dee7',
|
|
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 (
|
|
51
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.txb.pure.
|
|
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(
|
|
268
|
-
if (!
|
|
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(
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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,
|
|
139
|
+
deposit(param:DepositParam, passport?:PassportObject) :TxbObject {
|
|
110
140
|
if (!Protocol.IsValidObjects([param.coin])) {
|
|
111
141
|
ERROR(Errors.IsValidObjects, 'deposit.param.coin')
|
|
112
142
|
}
|
|
@@ -125,58 +155,40 @@ export class Treasury {
|
|
|
125
155
|
|
|
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
|
-
|
|
129
|
-
if (bFreeDeposit) {
|
|
158
|
+
if (passport) {
|
|
130
159
|
if (param.for_guard) {
|
|
131
160
|
return this.txb.moveCall({
|
|
132
|
-
target:Protocol.Instance().TreasuryFn('
|
|
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)],
|
|
161
|
+
target:Protocol.Instance().TreasuryFn('deposit_forGuard_with_passport') as FnCallType,
|
|
162
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
|
|
163
|
+
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
164
|
typeArguments:[this.token_type],
|
|
136
165
|
})
|
|
137
166
|
} else {
|
|
138
167
|
return this.txb.moveCall({
|
|
139
|
-
target:Protocol.Instance().TreasuryFn('
|
|
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)],
|
|
168
|
+
target:Protocol.Instance().TreasuryFn('deposit_with_passport') as FnCallType,
|
|
169
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
|
|
170
|
+
this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
142
171
|
typeArguments:[this.token_type],
|
|
143
172
|
})
|
|
144
173
|
}
|
|
145
174
|
} else {
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
}
|
|
175
|
+
if (param.for_guard) {
|
|
176
|
+
return this.txb.moveCall({
|
|
177
|
+
target:Protocol.Instance().TreasuryFn('deposit_forGuard') as FnCallType,
|
|
178
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
|
|
179
|
+
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)],
|
|
180
|
+
typeArguments:[this.token_type],
|
|
181
|
+
})
|
|
162
182
|
} else {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
}
|
|
183
|
+
return this.txb.moveCall({
|
|
184
|
+
target:Protocol.Instance().TreasuryFn('deposit') as FnCallType,
|
|
185
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, param.coin), this.txb.pure.u64(param.index),
|
|
186
|
+
this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
187
|
+
typeArguments:[this.token_type],
|
|
188
|
+
})
|
|
178
189
|
}
|
|
179
190
|
}
|
|
191
|
+
|
|
180
192
|
}
|
|
181
193
|
|
|
182
194
|
receive(payment:PaymentObject, received:ReceivedObject, passport?:PassportObject) {
|
|
@@ -218,47 +230,73 @@ export class Treasury {
|
|
|
218
230
|
if (param?.for_object && !IsValidAddress(param.for_object)) {
|
|
219
231
|
ERROR(Errors.IsValidAddress, 'withdraw.param.for_object')
|
|
220
232
|
}
|
|
233
|
+
if (param?.withdraw_guard && !IsValidAddress(param.withdraw_guard)) {
|
|
234
|
+
ERROR(Errors.IsValidAddress, 'withdraw.param.withdraw_guard')
|
|
235
|
+
}
|
|
236
|
+
if (param?.withdraw_guard && !passport) {
|
|
237
|
+
ERROR(Errors.IsValidAddress, 'withdraw.param.withdraw_guard')
|
|
238
|
+
}
|
|
221
239
|
|
|
222
240
|
const for_obj = this.txb.pure.option('address', param.for_object ?? undefined);
|
|
223
241
|
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
224
242
|
|
|
225
|
-
if (passport) {
|
|
243
|
+
if (param.withdraw_guard && passport) { //@ dont need passport, use withdraw guard!
|
|
226
244
|
if (param.for_guard) {
|
|
227
245
|
return this.txb.moveCall({
|
|
228
|
-
target:Protocol.Instance().TreasuryFn('
|
|
246
|
+
target:Protocol.Instance().TreasuryFn('withdraw_useGuard_forGuard') as FnCallType,
|
|
229
247
|
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
|
-
|
|
248
|
+
this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index), this.txb.pure.string(param.remark),
|
|
249
|
+
for_obj, this.txb.object(param.for_guard), this.txb.object(clock), this.txb.object(param.withdraw_guard)],
|
|
232
250
|
typeArguments:[this.token_type],
|
|
233
251
|
})
|
|
234
252
|
} else {
|
|
235
253
|
return this.txb.moveCall({
|
|
236
|
-
target:Protocol.Instance().TreasuryFn('
|
|
254
|
+
target:Protocol.Instance().TreasuryFn('withdraw_useGuard') as FnCallType,
|
|
237
255
|
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
|
-
|
|
256
|
+
this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index), this.txb.pure.string(param.remark),
|
|
257
|
+
for_obj, this.txb.object(clock), this.txb.object(param.withdraw_guard)],
|
|
240
258
|
typeArguments:[this.token_type],
|
|
241
259
|
})
|
|
242
260
|
}
|
|
243
261
|
} else {
|
|
244
|
-
if (
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
this.txb.pure.vector('
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
262
|
+
if (passport) {
|
|
263
|
+
if (param.for_guard) {
|
|
264
|
+
return this.txb.moveCall({
|
|
265
|
+
target:Protocol.Instance().TreasuryFn('withdraw_forGuard_with_passport') as FnCallType,
|
|
266
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
|
|
267
|
+
this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
|
|
268
|
+
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)],
|
|
269
|
+
typeArguments:[this.token_type],
|
|
270
|
+
})
|
|
271
|
+
} else {
|
|
272
|
+
return this.txb.moveCall({
|
|
273
|
+
target:Protocol.Instance().TreasuryFn('withdraw_with_passport') as FnCallType,
|
|
274
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
|
|
275
|
+
this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
|
|
276
|
+
this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
277
|
+
typeArguments:[this.token_type],
|
|
278
|
+
})
|
|
279
|
+
}
|
|
252
280
|
} else {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
281
|
+
if (param.for_guard) {
|
|
282
|
+
return this.txb.moveCall({
|
|
283
|
+
target:Protocol.Instance().TreasuryFn('withdraw_forGuard') as FnCallType,
|
|
284
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
|
|
285
|
+
this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
|
|
286
|
+
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)],
|
|
287
|
+
typeArguments:[this.token_type],
|
|
288
|
+
})
|
|
289
|
+
} else {
|
|
290
|
+
console.log(param)
|
|
291
|
+
return this.txb.moveCall({
|
|
292
|
+
target:Protocol.Instance().TreasuryFn('withdraw') as FnCallType,
|
|
293
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', param.items.map(v=>v.address)),
|
|
294
|
+
this.txb.pure.vector('u64', param.items.map(v=>v.amount)), this.txb.pure.u64(param.index),
|
|
295
|
+
this.txb.pure.string(param.remark), for_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
296
|
+
typeArguments:[this.token_type],
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
}
|
|
262
300
|
}
|
|
263
301
|
}
|
|
264
302
|
|
|
@@ -283,6 +321,90 @@ export class Treasury {
|
|
|
283
321
|
}
|
|
284
322
|
}
|
|
285
323
|
|
|
324
|
+
set_withdraw_mode(mode: WithdrawMode, passport?: PassportObject) {
|
|
325
|
+
if (passport) {
|
|
326
|
+
this.txb.moveCall({
|
|
327
|
+
target:Protocol.Instance().TreasuryFn('withdraw_mode_set_with_passport') as FnCallType,
|
|
328
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(mode), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
329
|
+
typeArguments:[this.token_type],
|
|
330
|
+
})
|
|
331
|
+
} else {
|
|
332
|
+
this.txb.moveCall({
|
|
333
|
+
target:Protocol.Instance().TreasuryFn('withdraw_mode_set') as FnCallType,
|
|
334
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(mode), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
335
|
+
typeArguments:[this.token_type],
|
|
336
|
+
})
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
add_withdraw_guard(guard:string, amount:bigint, passport?:PassportObject) {
|
|
341
|
+
if (!IsValidAddress(guard)) {
|
|
342
|
+
ERROR(Errors.IsValidAddress, 'add_withdraw_guard.guard')
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (!IsValidU64(amount)) {
|
|
346
|
+
ERROR(Errors.IsValidU64, 'add_withdraw_guard.amount')
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (passport) {
|
|
350
|
+
this.txb.moveCall({
|
|
351
|
+
target:Protocol.Instance().TreasuryFn('withdraw_guard_add_with_passport') as FnCallType,
|
|
352
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(guard), this.txb.pure.u64(amount),
|
|
353
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
354
|
+
typeArguments:[this.token_type],
|
|
355
|
+
})
|
|
356
|
+
} else {
|
|
357
|
+
this.txb.moveCall({
|
|
358
|
+
target:Protocol.Instance().TreasuryFn('withdraw_guard_add') as FnCallType,
|
|
359
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(guard), this.txb.pure.u64(amount),
|
|
360
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
361
|
+
typeArguments:[this.token_type],
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
remove_withdraw_guard(guard:string[], removeall?:boolean, passport?:PassportObject) {
|
|
367
|
+
if (guard.length === 0 && !removeall) return ;
|
|
368
|
+
|
|
369
|
+
if (!IsValidArray(guard, IsValidAddress)) {
|
|
370
|
+
ERROR(Errors.IsValidArray, 'add_withdraw_guard.guard')
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (passport) {
|
|
374
|
+
if (removeall) {
|
|
375
|
+
this.txb.moveCall({
|
|
376
|
+
target:Protocol.Instance().TreasuryFn('withdraw_guard_remove_all_with_passport') as FnCallType,
|
|
377
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
378
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
379
|
+
typeArguments:[this.token_type],
|
|
380
|
+
})
|
|
381
|
+
} else {
|
|
382
|
+
this.txb.moveCall({
|
|
383
|
+
target:Protocol.Instance().TreasuryFn('withdraw_guard_remove_with_passport') as FnCallType,
|
|
384
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', guard),
|
|
385
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
386
|
+
typeArguments:[this.token_type],
|
|
387
|
+
})
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
if (removeall) {
|
|
391
|
+
this.txb.moveCall({
|
|
392
|
+
target:Protocol.Instance().TreasuryFn('withdraw_guard_remove_all') as FnCallType,
|
|
393
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
394
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
395
|
+
typeArguments:[this.token_type],
|
|
396
|
+
})
|
|
397
|
+
} else {
|
|
398
|
+
this.txb.moveCall({
|
|
399
|
+
target:Protocol.Instance().TreasuryFn('withdraw_guard_remove') as FnCallType,
|
|
400
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', guard),
|
|
401
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
402
|
+
typeArguments:[this.token_type],
|
|
403
|
+
})
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
286
408
|
change_permission(new_permission:PermissionObject) {
|
|
287
409
|
if (!Protocol.IsValidObjects([new_permission])) {
|
|
288
410
|
ERROR(Errors.IsValidObjects, 'change_permission.new_permission')
|
|
@@ -302,5 +424,6 @@ export class Treasury {
|
|
|
302
424
|
static OP_WITHDRAW = 0;
|
|
303
425
|
static OP_DEPOSIT = 1;
|
|
304
426
|
static OP_RECEIVE = 2;
|
|
427
|
+
static MAX_WITHDRAW_GUARD_COUNT = 16;
|
|
305
428
|
}
|
|
306
429
|
|
package/src/withholding.ts
DELETED
|
@@ -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
|
-
}
|