wowok 1.4.21 → 1.4.23
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 +1 -1
- package/src/guard.ts +34 -33
- package/src/index.ts +2 -1
- package/src/machine.ts +0 -1
- package/src/permission.ts +6 -2
- package/src/protocol.ts +6 -5
- package/src/service.ts +21 -10
- package/src/treasury.ts +239 -0
- package/src/vote.ts +7 -5
- package/src/withholding.ts +0 -0
package/package.json
CHANGED
package/src/guard.ts
CHANGED
|
@@ -54,7 +54,7 @@ export class Guard {
|
|
|
54
54
|
target: Protocol.Instance().GuardFn('new') as FnCallType,
|
|
55
55
|
arguments: [txb.pure.string(description), txb.pure.vector('u8', [].slice.call(input.reverse()))],
|
|
56
56
|
});
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
constants?.forEach((v, k) => {
|
|
59
59
|
if (v.bWitness) {
|
|
60
60
|
const n = new Uint8Array(1); n.set([v.type], 0);
|
|
@@ -238,6 +238,29 @@ export class Guard {
|
|
|
238
238
|
[MODULES.wowok, 'Grantor Expired Time', 907, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The expiration time of a grantor.', ['address']],
|
|
239
239
|
[MODULES.wowok, 'Grantee Object for Grantor', 908, [ValueType.TYPE_ADDRESS], ValueType.TYPE_ADDRESS, 'Grantee repository address of a grantor.', ['address']],
|
|
240
240
|
|
|
241
|
+
[MODULES.vote, 'Permission', 1101, [], ValueType.TYPE_ADDRESS, 'Permission object address.', []],
|
|
242
|
+
[MODULES.vote, 'Be Voting', 1102, [], ValueType.TYPE_BOOL, 'Whether to start voting and options will not be changed?', []],
|
|
243
|
+
[MODULES.vote, 'Deadline Locked', 1103, [], ValueType.TYPE_BOOL, 'Whether the deadline cannot be modified?', []],
|
|
244
|
+
[MODULES.vote, 'Vote-Guard Locked', 1104, [], ValueType.TYPE_BOOL, 'Whether the Guard for voting cannot be modified?', []],
|
|
245
|
+
[MODULES.vote, 'Max Choice Count', 1105, [], ValueType.TYPE_U8, 'The maximum number of options that can be selected in one vote.', []],
|
|
246
|
+
[MODULES.vote, 'Deadline', 1106, [], ValueType.TYPE_U64, 'Deadline for voting.', []],
|
|
247
|
+
[MODULES.vote, 'Has Reference', 1107, [], ValueType.TYPE_BOOL, 'Whether to vote for a reference Object?', []],
|
|
248
|
+
[MODULES.vote, 'Reference', 1108, [], ValueType.TYPE_ADDRESS, 'Reference Object that voting for.', []],
|
|
249
|
+
[MODULES.vote, 'Has Vote-Guard', 1109, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is a certain Guard included in the Vote-Guard settings?', ['guard address']],
|
|
250
|
+
[MODULES.vote, 'Vote-Guard Wight', 1110, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The voting weight corresponding to the Vote-Guard.', ['guard address']],
|
|
251
|
+
[MODULES.vote, 'Has Voted by Address', 1111, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Whether an address has already voted?', ['address']],
|
|
252
|
+
[MODULES.vote, 'Voted Weight by Address', 1112, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The weight of whether an address has been voted on.', ['adddress']],
|
|
253
|
+
[MODULES.vote, 'Has Option', 1113, [ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Whether a voting option is included?', ['option name']],
|
|
254
|
+
[MODULES.vote, 'Has Object of Option', 1114, [ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Whether a voting option refers to an object?', ['option name']],
|
|
255
|
+
[MODULES.vote, 'Option Object', 1115, [ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The object referenced by a voting option.', ['option name']],
|
|
256
|
+
[MODULES.vote, 'Option Counts', 1116, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The number of votes for the voting option.', ['option name']],
|
|
257
|
+
[MODULES.vote, 'Option Votes', 1117, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The number of voted addresses for the voting option.', ['option name']],
|
|
258
|
+
[MODULES.vote, 'Address Count Voted', 1118, [], ValueType.TYPE_U64, 'Total number of addresses voted.', []],
|
|
259
|
+
[MODULES.vote, 'Top1 Option by Addresses', 1119, [], ValueType.TYPE_STRING, 'The name of the voting option ranked first by the number of voting addresses.', []],
|
|
260
|
+
[MODULES.vote, 'Top1 Counts by Addresses', 1120, [], ValueType.TYPE_U64, 'Number of votes for the top voting option by number of voting addresses.', []],
|
|
261
|
+
[MODULES.vote, 'Top1 Option by Votes', 1121, [], ValueType.TYPE_STRING, 'The name of the voting option ranked first by the number of votes.', []],
|
|
262
|
+
[MODULES.vote, 'Top1 Counts by Votes', 1122, [], ValueType.TYPE_U64, 'Number of votes for the top voting option by number of votes.', []],
|
|
263
|
+
|
|
241
264
|
[MODULES.payment, 'Sender', 1200, [], ValueType.TYPE_ADDRESS, 'Payment originator address.', []],
|
|
242
265
|
[MODULES.payment, 'Total Amount', 1201, [], ValueType.TYPE_U64, "Payment amount.", []],
|
|
243
266
|
[MODULES.payment, 'Tips', 1202, [], ValueType.TYPE_STRING, 'Payment remarks.', ['address']],
|
|
@@ -253,52 +276,30 @@ export class Guard {
|
|
|
253
276
|
[MODULES.payment, 'Treasury Address', 1212, [], ValueType.TYPE_ADDRESS, 'The Treasury from which the payment comes.', []],
|
|
254
277
|
[MODULES.payment, 'Index', 1213, [], ValueType.TYPE_U64, 'Payment index or id.', []],
|
|
255
278
|
|
|
256
|
-
[MODULES.withholding, '
|
|
279
|
+
[MODULES.withholding, 'Amount', 1300, [], ValueType.TYPE_U64, 'Total amount deposited with withholding.' , []],
|
|
257
280
|
[MODULES.withholding, 'Original Type Deposited', 1301, [], ValueType.TYPE_STRING, "Original type name of asserts deposited.", []],
|
|
258
281
|
[MODULES.withholding, 'Original Package', 1302, [], ValueType.TYPE_ADDRESS, 'Original package address of asserts deposited.', []],
|
|
259
282
|
[MODULES.withholding, 'Original Module', 1303, [], ValueType.TYPE_STRING, 'Original module name of asserts deposited.', []],
|
|
260
283
|
[MODULES.withholding, 'Type Deposited', 1304, [], ValueType.TYPE_STRING, 'Type name of asserts deposited.', []],
|
|
261
284
|
[MODULES.withholding, 'Package', 1305, [], ValueType.TYPE_ADDRESS, 'Package address of asserts deposited.', , []],
|
|
262
285
|
[MODULES.withholding, 'Module', 1306, [], ValueType.TYPE_STRING, 'Module name of asserts deposited.', []],
|
|
263
|
-
[MODULES.withholding, '
|
|
286
|
+
[MODULES.withholding, 'Balance', 1307, [], ValueType.TYPE_U64, 'The amount currently remaining in withholding.', []],
|
|
264
287
|
[MODULES.withholding, 'Deposit Time', 1308, [], ValueType.TYPE_U64, 'Deposit time.', []],
|
|
265
|
-
[MODULES.withholding, '
|
|
266
|
-
[MODULES.withholding, '
|
|
267
|
-
[MODULES.withholding, '
|
|
268
|
-
[MODULES.withholding, '
|
|
269
|
-
[MODULES.withholding, '
|
|
288
|
+
[MODULES.withholding, 'Be Withdrawable', 1309, [], ValueType.TYPE_BOOL, 'Whether to allow amount withdrawal?' , []],
|
|
289
|
+
[MODULES.withholding, 'Be Deposited from', 1310, [], ValueType.TYPE_BOOL, 'Is the deposit from source set?', []],
|
|
290
|
+
[MODULES.withholding, 'Deposited from Object', 1311, [], ValueType.TYPE_ADDRESS, 'The source object set when depositing.', []],
|
|
291
|
+
[MODULES.withholding, 'Contains Guard', 1312, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Whether the guard for withdrawal is set up?', []],
|
|
292
|
+
[MODULES.withholding, 'Withdrawal percentage', 1313, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U8, 'The percentage of withdrawals corresponding to Guard.', ['address']],
|
|
293
|
+
[MODULES.withholding, 'Number of withdrawals', 1314, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'Number of withdrawals.'],
|
|
270
294
|
|
|
271
295
|
[MODULES.treasury, 'Permission', 1400, [], ValueType.TYPE_ADDRESS, 'Permission object address.', []],
|
|
272
296
|
[MODULES.treasury, 'Balance', 1401, [], ValueType.TYPE_U64, "Treasury balance.", []],
|
|
273
297
|
[MODULES.treasury, 'Number of Flow Records', 1402, [], ValueType.TYPE_U64, 'Number of treasury transactions.', []],
|
|
274
298
|
[MODULES.treasury, 'Deposit Flow', 1403, [], ValueType.TYPE_U128, 'Treasury inflow amount.', []],
|
|
275
|
-
[MODULES.treasury, '
|
|
299
|
+
[MODULES.treasury, 'Withdraw Flow', 1404, [], ValueType.TYPE_U128, 'Treasury outflow amount.', []],
|
|
276
300
|
[MODULES.treasury, 'Flow over a Period of Time', 1405, [ValueType.TYPE_U64, ValueType.TYPE_U64], ValueType.TYPE_U128, 'The flow amount between certain periods.', ['begin time', 'end time']],
|
|
277
301
|
[MODULES.treasury, 'Deposit Flow over a Period of Time', 1406, [ValueType.TYPE_U64, ValueType.TYPE_U64], ValueType.TYPE_U128, "The inflow amount between certain periods.", ['begin time', 'end time']],
|
|
278
|
-
[MODULES.treasury, '
|
|
279
|
-
|
|
280
|
-
/* [MODULES.vote, 'Permission', 171, [], ValueType.TYPE_ADDRESS],
|
|
281
|
-
[MODULES.vote, 'Options Locked', 172, [], ValueType.TYPE_BOOL],
|
|
282
|
-
[MODULES.vote, 'Deadline Locked', 173, [], ValueType.TYPE_BOOL],
|
|
283
|
-
[MODULES.vote, 'Vote-Guard Locked', 174, [], ValueType.TYPE_BOOL],
|
|
284
|
-
[MODULES.vote, 'Max Choice Count', 175, [], ValueType.TYPE_U8],
|
|
285
|
-
[MODULES.vote, 'Deadline', 176, [], ValueType.TYPE_U64],
|
|
286
|
-
[MODULES.vote, 'Has Reference', 177, [], ValueType.TYPE_BOOL],
|
|
287
|
-
[MODULES.vote, 'Reference', 178, [], ValueType.TYPE_ADDRESS],
|
|
288
|
-
[MODULES.vote, 'Has Vote-Guard', 179, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL],
|
|
289
|
-
[MODULES.vote, 'Vote-Guard', 180, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
|
|
290
|
-
[MODULES.vote, 'Has Voted by Address', 181, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL],
|
|
291
|
-
[MODULES.vote, 'Voted Weight by Address', 182, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
|
|
292
|
-
[MODULES.vote, 'Has Option', 183, [ValueType.TYPE_STRING], ValueType.TYPE_BOOL],
|
|
293
|
-
[MODULES.vote, 'Has Object of Option', 184, [ValueType.TYPE_STRING], ValueType.TYPE_BOOL],
|
|
294
|
-
[MODULES.vote, 'Option Object', 185, [ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS],
|
|
295
|
-
[MODULES.vote, 'Option Count', 186, [ValueType.TYPE_STRING], ValueType.TYPE_U64],
|
|
296
|
-
[MODULES.vote, 'Option Votes', 187, [ValueType.TYPE_STRING], ValueType.TYPE_U64],
|
|
297
|
-
[MODULES.vote, 'Address Count Voted', 188, [], ValueType.TYPE_U64],
|
|
298
|
-
[MODULES.vote, 'Top1 Option by Addresses', 189, [], ValueType.TYPE_STRING],
|
|
299
|
-
[MODULES.vote, 'Top1 Count by Addresses', 190, [], ValueType.TYPE_U64],
|
|
300
|
-
[MODULES.vote, 'Top1 Option by Votes', 191, [], ValueType.TYPE_STRING],
|
|
301
|
-
[MODULES.vote, 'Top1 Count by Votes', 192, [], ValueType.TYPE_U64], */
|
|
302
|
+
[MODULES.treasury, 'Withdraw Flow over a Period of Time', 1407, [ValueType.TYPE_U64, ValueType.TYPE_U64], ValueType.TYPE_U128, 'The outflow amount between certain periods.', ['begin time', 'end time']],
|
|
302
303
|
];
|
|
303
304
|
|
|
304
305
|
static BoolCmd = Guard.QUERIES.filter(q => q[4] === ValueType.TYPE_BOOL);
|
package/src/index.ts
CHANGED
package/src/machine.ts
CHANGED
|
@@ -65,7 +65,6 @@ export class Machine {
|
|
|
65
65
|
|
|
66
66
|
let m = new Machine(txb, permission);
|
|
67
67
|
let ep = txb.pure.option('string', endpoint ? endpoint : undefined);
|
|
68
|
-
|
|
69
68
|
if (passport) {
|
|
70
69
|
m.object = txb.moveCall({
|
|
71
70
|
target:Protocol.Instance().MachineFn('new_with_passport') as FnCallType,
|
package/src/permission.ts
CHANGED
|
@@ -81,7 +81,9 @@ export enum PermissionIndex {
|
|
|
81
81
|
|
|
82
82
|
treasury = 700,
|
|
83
83
|
treasury_deposit = 701,
|
|
84
|
-
|
|
84
|
+
treasury_withdraw = 702,
|
|
85
|
+
treasury_free_deposit_set = 703,
|
|
86
|
+
treasury_descritption = 704,
|
|
85
87
|
user_defined_start = 1000,
|
|
86
88
|
}
|
|
87
89
|
|
|
@@ -182,7 +184,9 @@ export const PermissionInfo : PermissionInfoType[] = [
|
|
|
182
184
|
|
|
183
185
|
{index:PermissionIndex.treasury, name: 'Treasury', description:'Launch new Treasury', module: 'treasury'},
|
|
184
186
|
{index:PermissionIndex.treasury_deposit, name: 'Deposit', description:'Deposit coins', module: 'treasury'},
|
|
185
|
-
{index:PermissionIndex.
|
|
187
|
+
{index:PermissionIndex.treasury_withdraw, name: 'Withdraw', description:'Withdraw coins', module: 'treasury'},
|
|
188
|
+
{index:PermissionIndex.treasury_free_deposit_set, name: 'Be Free Deposit', description:'Set whether deposits can be made without permission', module: 'treasury'},
|
|
189
|
+
{index:PermissionIndex.treasury_descritption, name: 'Description', description:'Set Treasury description', module: 'treasury'},
|
|
186
190
|
]
|
|
187
191
|
|
|
188
192
|
export type PermissionIndexType = PermissionIndex | number;
|
package/src/protocol.ts
CHANGED
|
@@ -211,10 +211,10 @@ const TESTNET = {
|
|
|
211
211
|
}
|
|
212
212
|
*/
|
|
213
213
|
const TESTNET = {
|
|
214
|
-
package: "
|
|
215
|
-
wowok_object: '
|
|
216
|
-
entity_object: '
|
|
217
|
-
treasury_cap:'
|
|
214
|
+
package: "0xf108d64c8143ec040da0d5538e834a67f0a9c661f92011195b60f51b3bc33a46",
|
|
215
|
+
wowok_object: '0xc4fc2a42a5fbcfc68b3d8ac079e4d5a07f637c541e0183446a9da655965cda5e',
|
|
216
|
+
entity_object: '0x8bbab9023092dc89c3c60c766b204c0dfbe3da46a2de486d8ab92ba91a4c905f',
|
|
217
|
+
treasury_cap:'0x07e7b3c355b63bade82c1e0e2653e655a1b20da6cc531db5707ad1292fd418e4',
|
|
218
218
|
}
|
|
219
219
|
const MAINNET = {
|
|
220
220
|
package: "",
|
|
@@ -311,6 +311,7 @@ export class Protocol {
|
|
|
311
311
|
ResourceFn = (fn: any) => { return `${this.package}::${MODULES.resource}::${fn}`};
|
|
312
312
|
EntityFn = (fn: any) => { return `${this.package}::${MODULES.entity}::${fn}`};
|
|
313
313
|
WowokFn = (fn: any) => { return `${this.package}::${MODULES.wowok}::${fn}`};
|
|
314
|
+
TreasuryFn = (fn: any) => { return `${this.package}::${MODULES.treasury}::${fn}`};
|
|
314
315
|
|
|
315
316
|
Query = async (objects: Query_Param[], options:SuiObjectDataOptions={showContent:true}) : Promise<SuiObjectResponse[]> => {
|
|
316
317
|
const client = new SuiClient({ url: this.NetworkUrl() });
|
|
@@ -465,7 +466,7 @@ export class RpcResultParser {
|
|
|
465
466
|
return names;
|
|
466
467
|
}
|
|
467
468
|
static objectids_from_response = (protocol:Protocol, response:SuiTransactionBlockResponse, concat_result?:Map<string, TxbObject[]>): Map<string, TxbObject[]> => {
|
|
468
|
-
//
|
|
469
|
+
//console.log(response)
|
|
469
470
|
let ret = new Map<string, string[]>();
|
|
470
471
|
if (response?.objectChanges) {
|
|
471
472
|
response.objectChanges.forEach((change) => {
|
package/src/service.ts
CHANGED
|
@@ -626,15 +626,21 @@ export class Service {
|
|
|
626
626
|
}
|
|
627
627
|
|
|
628
628
|
// support both withdraw guard and permission guard
|
|
629
|
-
withdraw(order:OrderObject, passport?:PassportObject) {
|
|
629
|
+
withdraw(order:OrderObject, withdraw_guard?:string, passport?:PassportObject) {
|
|
630
630
|
if (!Protocol.IsValidObjects([order])) {
|
|
631
|
-
ERROR(Errors.IsValidObjects, 'order')
|
|
631
|
+
ERROR(Errors.IsValidObjects, 'withdraw.order')
|
|
632
632
|
}
|
|
633
|
-
|
|
634
|
-
|
|
633
|
+
if (withdraw_guard && !IsValidAddress(withdraw_guard)) {
|
|
634
|
+
ERROR(Errors.IsValidAddress, 'withdraw.withdraw_guard')
|
|
635
|
+
}
|
|
636
|
+
if (passport && !withdraw_guard) {
|
|
637
|
+
ERROR(Errors.InvalidParam, 'withdraw.passport need withdraw_guard')
|
|
638
|
+
}
|
|
639
|
+
if (passport && withdraw_guard) {
|
|
635
640
|
this.txb.moveCall({
|
|
636
641
|
target:Protocol.Instance().ServiceFn('withdraw_with_passport') as FnCallType,
|
|
637
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, order),
|
|
642
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, order),
|
|
643
|
+
this.txb.object(withdraw_guard), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
638
644
|
typeArguments:[this.pay_token_type]
|
|
639
645
|
})
|
|
640
646
|
} else {
|
|
@@ -868,15 +874,20 @@ export class Service {
|
|
|
868
874
|
}
|
|
869
875
|
}
|
|
870
876
|
|
|
871
|
-
refund(order:OrderObject, passport?:PassportObject) {
|
|
877
|
+
refund(order:OrderObject, refund_guard?:string, passport?:PassportObject) {
|
|
872
878
|
if (!Protocol.IsValidObjects([order])) {
|
|
873
|
-
ERROR(Errors.IsValidObjects, 'order')
|
|
879
|
+
ERROR(Errors.IsValidObjects, 'refund.order')
|
|
874
880
|
}
|
|
875
|
-
|
|
876
|
-
|
|
881
|
+
if (refund_guard && !IsValidAddress(refund_guard)) {
|
|
882
|
+
ERROR(Errors.IsValidAddress, 'refund.refund_guard')
|
|
883
|
+
}
|
|
884
|
+
if (passport && !refund_guard) {
|
|
885
|
+
ERROR(Errors.InvalidParam, 'refund.passport need refund_guard')
|
|
886
|
+
}
|
|
887
|
+
if (passport && refund_guard) {
|
|
877
888
|
this.txb.moveCall({
|
|
878
889
|
target:Protocol.Instance().ServiceFn('refund_with_passport') as FnCallType,
|
|
879
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, order), passport],
|
|
890
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, order), this.txb.object(refund_guard), passport],
|
|
880
891
|
typeArguments:[this.pay_token_type]
|
|
881
892
|
})
|
|
882
893
|
} else {
|
package/src/treasury.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
2
|
+
import { FnCallType, Protocol, PassportObject, PermissionObject, DemandAddress, TxbObject, CoinObject} from './protocol';
|
|
3
|
+
import { IsValidDesription, IsValidU64, IsValidAddress, IsValidArgType, } from './utils'
|
|
4
|
+
import { Errors, ERROR} from './exception'
|
|
5
|
+
|
|
6
|
+
export class Treasury {
|
|
7
|
+
protected token_type;
|
|
8
|
+
protected permission ;
|
|
9
|
+
protected object : TxbObject;
|
|
10
|
+
protected txb;
|
|
11
|
+
|
|
12
|
+
get_token_type() { return this.token_type }
|
|
13
|
+
get_object() { return this.object }
|
|
14
|
+
|
|
15
|
+
static From(txb:TransactionBlock, token_type:string, permission:PermissionObject, object:TxbObject) : Treasury {
|
|
16
|
+
let d = new Treasury(txb, token_type, permission)
|
|
17
|
+
d.object = Protocol.TXB_OBJECT(txb, object)
|
|
18
|
+
return d
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private constructor(txb:TransactionBlock, token_type:string, permission:PermissionObject) {
|
|
22
|
+
this.token_type = token_type;
|
|
23
|
+
this.permission = permission;
|
|
24
|
+
this.txb = txb;
|
|
25
|
+
this.object = '';
|
|
26
|
+
}
|
|
27
|
+
static New(txb:TransactionBlock, token_type:string, permission:PermissionObject, description:string,
|
|
28
|
+
bFreeDeposit:boolean=false, passport?:PassportObject) : Treasury {
|
|
29
|
+
if (!Protocol.IsValidObjects([permission])) {
|
|
30
|
+
ERROR(Errors.IsValidObjects, 'permission, bounty');
|
|
31
|
+
}
|
|
32
|
+
if (!IsValidDesription(description)) {
|
|
33
|
+
ERROR(Errors.IsValidDesription);
|
|
34
|
+
}
|
|
35
|
+
if (!IsValidArgType(token_type)) {
|
|
36
|
+
ERROR(Errors.IsValidArgType, token_type);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let d = new Treasury(txb, token_type, permission);
|
|
40
|
+
if (passport) {
|
|
41
|
+
d.object = txb.moveCall({
|
|
42
|
+
target:Protocol.Instance().TreasuryFn('new_with_passport') as FnCallType,
|
|
43
|
+
arguments:[passport, txb.pure.bool(bFreeDeposit), txb.pure.string(description), Protocol.TXB_OBJECT(txb, permission)],
|
|
44
|
+
typeArguments:[token_type],
|
|
45
|
+
})
|
|
46
|
+
} else {
|
|
47
|
+
d.object = txb.moveCall({
|
|
48
|
+
target:Protocol.Instance().TreasuryFn('new') as FnCallType,
|
|
49
|
+
arguments:[txb.pure.bool(bFreeDeposit), txb.pure.string(description), Protocol.TXB_OBJECT(txb, permission)],
|
|
50
|
+
typeArguments:[token_type],
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
return d
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
launch() : DemandAddress {
|
|
57
|
+
return this.txb.moveCall({
|
|
58
|
+
target:Protocol.Instance().TreasuryFn('create') as FnCallType,
|
|
59
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
|
|
60
|
+
typeArguments:[this.token_type],
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
destroy() {
|
|
65
|
+
this.txb.moveCall({
|
|
66
|
+
target:Protocol.Instance().TreasuryFn('destroy') as FnCallType,
|
|
67
|
+
arguments: [Protocol.TXB_OBJECT(this.txb, this.object)],
|
|
68
|
+
typeArguments:[this.token_type]
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
set_free_deposits(bFreeDeposit:boolean, passport?:PassportObject) {
|
|
73
|
+
if (passport) {
|
|
74
|
+
this.txb.moveCall({
|
|
75
|
+
target:Protocol.Instance().TreasuryFn('free_deposits_set_with_passport') as FnCallType,
|
|
76
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
77
|
+
this.txb.pure.bool(bFreeDeposit), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
78
|
+
typeArguments:[this.token_type],
|
|
79
|
+
})
|
|
80
|
+
} else {
|
|
81
|
+
this.txb.moveCall({
|
|
82
|
+
target:Protocol.Instance().TreasuryFn('free_deposits_set') as FnCallType,
|
|
83
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(bFreeDeposit), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
84
|
+
typeArguments:[this.token_type],
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
deposit(coin:CoinObject, tips:string, for_object?:string, index?:number, from_object?:string, passport?:PassportObject) :TxbObject {
|
|
90
|
+
if (!Protocol.IsValidObjects([coin])) {
|
|
91
|
+
ERROR(Errors.IsValidObjects, 'deposit.coin')
|
|
92
|
+
}
|
|
93
|
+
if (!IsValidDesription(tips)) {
|
|
94
|
+
ERROR(Errors.IsValidDesription, 'deposit.tips')
|
|
95
|
+
}
|
|
96
|
+
if (for_object && !IsValidAddress(for_object)) {
|
|
97
|
+
ERROR(Errors.IsValidAddress, 'deposit.tips')
|
|
98
|
+
}
|
|
99
|
+
if (from_object && !IsValidAddress(from_object)) {
|
|
100
|
+
ERROR(Errors.IsValidAddress, 'deposit.from_object')
|
|
101
|
+
}
|
|
102
|
+
if (index !== undefined && !IsValidU64(index)) {
|
|
103
|
+
ERROR(Errors.InvalidParam, 'deposit.index')
|
|
104
|
+
}
|
|
105
|
+
const for_obj = this.txb.pure.option('address', for_object ?? undefined);
|
|
106
|
+
const idx = this.txb.pure.option('u64', index ?? undefined);
|
|
107
|
+
const from_obj = this.txb.pure.option('address', from_object ?? undefined);
|
|
108
|
+
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
109
|
+
|
|
110
|
+
if (passport) {
|
|
111
|
+
return this.txb.moveCall({
|
|
112
|
+
target:Protocol.Instance().TreasuryFn('deposit_with_passport') as FnCallType,
|
|
113
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, coin),
|
|
114
|
+
this.txb.pure.string(tips), for_obj, idx, from_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
115
|
+
typeArguments:[this.token_type],
|
|
116
|
+
})
|
|
117
|
+
} else {
|
|
118
|
+
return this.txb.moveCall({
|
|
119
|
+
target:Protocol.Instance().TreasuryFn('deposit') as FnCallType,
|
|
120
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, coin),
|
|
121
|
+
this.txb.pure.string(tips), for_obj, idx, from_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
122
|
+
typeArguments:[this.token_type],
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
free_deposit(coin:CoinObject, tips:string, for_object?:string, index?:number, from_object?:string) : TxbObject {
|
|
128
|
+
if (!Protocol.IsValidObjects([coin])) {
|
|
129
|
+
ERROR(Errors.IsValidObjects, 'free_deposit.coin')
|
|
130
|
+
}
|
|
131
|
+
if (!IsValidDesription(tips)) {
|
|
132
|
+
ERROR(Errors.IsValidDesription, 'free_deposit.tips')
|
|
133
|
+
}
|
|
134
|
+
if (for_object && !IsValidAddress(for_object)) {
|
|
135
|
+
ERROR(Errors.IsValidAddress, 'free_deposit.for_object')
|
|
136
|
+
}
|
|
137
|
+
if (from_object && !IsValidAddress(from_object)) {
|
|
138
|
+
ERROR(Errors.IsValidAddress, 'free_deposit.from_object')
|
|
139
|
+
}
|
|
140
|
+
if (index !== undefined && !IsValidU64(index)) {
|
|
141
|
+
ERROR(Errors.InvalidParam, 'free_deposit.index')
|
|
142
|
+
}
|
|
143
|
+
const for_obj = this.txb.pure.option('address', for_object ?? undefined);
|
|
144
|
+
const idx = this.txb.pure.option('u64', index ?? undefined);
|
|
145
|
+
const from_obj = this.txb.pure.option('address', from_object ?? undefined);
|
|
146
|
+
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
147
|
+
|
|
148
|
+
return this.txb.moveCall({
|
|
149
|
+
target:Protocol.Instance().TreasuryFn('deposit2') as FnCallType,
|
|
150
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, coin),
|
|
151
|
+
this.txb.pure.string(tips), for_obj, idx, from_obj, this.txb.object(clock)],
|
|
152
|
+
typeArguments:[this.token_type],
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
withdraw(amount:number, tips:string, for_object?:string, index?:number, to_object?:string, passport?:PassportObject) : CoinObject {
|
|
157
|
+
if (!IsValidU64(amount)) {
|
|
158
|
+
ERROR(Errors.IsValidObjects, 'withdraw.amount')
|
|
159
|
+
}
|
|
160
|
+
if (!IsValidDesription(tips)) {
|
|
161
|
+
ERROR(Errors.IsValidDesription, 'withdraw.tips')
|
|
162
|
+
}
|
|
163
|
+
if (for_object && !IsValidAddress(for_object)) {
|
|
164
|
+
ERROR(Errors.IsValidAddress, 'withdraw.for_object')
|
|
165
|
+
}
|
|
166
|
+
if (to_object && !IsValidAddress(to_object)) {
|
|
167
|
+
ERROR(Errors.IsValidAddress, 'withdraw.to_object')
|
|
168
|
+
}
|
|
169
|
+
if (index !== undefined && !IsValidU64(index)) {
|
|
170
|
+
ERROR(Errors.InvalidParam, 'withdraw.index')
|
|
171
|
+
}
|
|
172
|
+
const for_obj = this.txb.pure.option('address', for_object ?? undefined);
|
|
173
|
+
const idx = this.txb.pure.option('u64', index ?? undefined);
|
|
174
|
+
const to_obj = this.txb.pure.option('address', to_object ?? undefined);
|
|
175
|
+
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
176
|
+
|
|
177
|
+
if (passport) {
|
|
178
|
+
return this.txb.moveCall({
|
|
179
|
+
target:Protocol.Instance().TreasuryFn('withdraw_with_passport') as FnCallType,
|
|
180
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u64(amount),
|
|
181
|
+
this.txb.pure.string(tips), for_obj, idx, to_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
182
|
+
typeArguments:[this.token_type],
|
|
183
|
+
})
|
|
184
|
+
} else {
|
|
185
|
+
return this.txb.moveCall({
|
|
186
|
+
target:Protocol.Instance().TreasuryFn('withdraw') as FnCallType,
|
|
187
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u64(amount),
|
|
188
|
+
this.txb.pure.string(tips), for_obj, idx, to_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
189
|
+
typeArguments:[this.token_type],
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
set_description(description:string, passport?:PassportObject) {
|
|
195
|
+
if (!IsValidDesription(description)) {
|
|
196
|
+
ERROR(Errors.IsValidDesription, 'set_description.description');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (passport) {
|
|
200
|
+
this.txb.moveCall({
|
|
201
|
+
target:Protocol.Instance().TreasuryFn('description_set_with_passport') as FnCallType,
|
|
202
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description),
|
|
203
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
204
|
+
typeArguments:[this.token_type],
|
|
205
|
+
})
|
|
206
|
+
} else {
|
|
207
|
+
this.txb.moveCall({
|
|
208
|
+
target:Protocol.Instance().TreasuryFn('description_set') as FnCallType,
|
|
209
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
210
|
+
typeArguments:[this.token_type],
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
change_permission(new_permission:PermissionObject) {
|
|
216
|
+
if (!Protocol.IsValidObjects([new_permission])) {
|
|
217
|
+
ERROR(Errors.IsValidObjects, 'change_permission.new_permission')
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
this.txb.moveCall({
|
|
221
|
+
target:Protocol.Instance().TreasuryFn('permission_set') as FnCallType,
|
|
222
|
+
arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
|
|
223
|
+
typeArguments:[this.token_type]
|
|
224
|
+
})
|
|
225
|
+
this.permission = new_permission
|
|
226
|
+
}
|
|
227
|
+
static parseObjectType = (chain_type:string) : string => {
|
|
228
|
+
if (chain_type) {
|
|
229
|
+
const s = 'treasury::Treasury<'
|
|
230
|
+
const i = chain_type.indexOf(s);
|
|
231
|
+
if (i > 0) {
|
|
232
|
+
let r = chain_type.slice(i + s.length, chain_type.length-1);
|
|
233
|
+
return r
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return '';
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
package/src/vote.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { ERROR, Errors } from './exception';
|
|
|
4
4
|
import { ValueType } from './protocol';
|
|
5
5
|
import { Transaction as TransactionBlock} from '@mysten/sui/transactions';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
export const MAX_CHOICE_COUNT = 200;
|
|
7
|
+
|
|
9
8
|
|
|
10
9
|
export type VoteOption = {
|
|
11
10
|
name:string;
|
|
@@ -42,7 +41,7 @@ export class Vote {
|
|
|
42
41
|
if (max_choice_count && !IsValidUintLarge(max_choice_count)) {
|
|
43
42
|
ERROR(Errors.IsValidUint, 'max_choice_count')
|
|
44
43
|
}
|
|
45
|
-
if (max_choice_count && max_choice_count > MAX_CHOICE_COUNT) {
|
|
44
|
+
if (max_choice_count && max_choice_count > Vote.MAX_CHOICE_COUNT) {
|
|
46
45
|
ERROR(Errors.InvalidParam, 'max_choice_count')
|
|
47
46
|
}
|
|
48
47
|
if (reference_address && !IsValidAddress(reference_address)) {
|
|
@@ -250,7 +249,7 @@ export class Vote {
|
|
|
250
249
|
}
|
|
251
250
|
}
|
|
252
251
|
set_max_choice_count(max_choice_count:number, passport?:PassportObject) {
|
|
253
|
-
if (!IsValidUintLarge(max_choice_count) || max_choice_count > MAX_CHOICE_COUNT) {
|
|
252
|
+
if (!IsValidUintLarge(max_choice_count) || max_choice_count > Vote.MAX_CHOICE_COUNT) {
|
|
254
253
|
ERROR(Errors.InvalidParam, 'max_choice_count')
|
|
255
254
|
}
|
|
256
255
|
|
|
@@ -333,7 +332,7 @@ export class Vote {
|
|
|
333
332
|
|
|
334
333
|
agree(options:string[], passport?:PassportObject) {
|
|
335
334
|
if (options.length === 0) return;
|
|
336
|
-
if (options.length > MAX_CHOICE_COUNT) {
|
|
335
|
+
if (options.length > Vote.MAX_CHOICE_COUNT) {
|
|
337
336
|
ERROR(Errors.InvalidParam, 'agree')
|
|
338
337
|
}
|
|
339
338
|
|
|
@@ -363,4 +362,7 @@ export class Vote {
|
|
|
363
362
|
})
|
|
364
363
|
this.permission = new_permission
|
|
365
364
|
}
|
|
365
|
+
|
|
366
|
+
static MAX_AGREES_COUNT = 100;
|
|
367
|
+
static MAX_CHOICE_COUNT = 100;
|
|
366
368
|
}
|
|
File without changes
|