wowok 1.4.23 → 1.4.27

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/src/reward.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TransactionArgument, Transaction as TransactionBlock, type TransactionResult, } from '@mysten/sui/transactions';
2
2
  import { FnCallType, GuardObject, PassportObject, PermissionObject, RewardAddress, Protocol, TxbObject, } from './protocol';
3
- import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidUintLarge, } from './utils';
3
+ import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidU64, parseObjectType} from './utils';
4
4
  import { ERROR, Errors } from './exception';
5
5
 
6
6
  export type CoinReward = TransactionResult;
@@ -39,7 +39,7 @@ export class Reward {
39
39
  if (!IsValidDesription(description)) {
40
40
  ERROR(Errors.IsValidDesription)
41
41
  }
42
- if (!IsValidUintLarge(time)) {
42
+ if (!IsValidU64(time)) {
43
43
  ERROR(Errors.IsValidUint, 'time')
44
44
  }
45
45
 
@@ -96,7 +96,7 @@ export class Reward {
96
96
  }
97
97
 
98
98
  expand_time(ms_expand:boolean, time:number, passport?:PassportObject) {
99
- if (!IsValidUintLarge(time)) {
99
+ if (!IsValidU64(time)) {
100
100
  ERROR(Errors.IsValidUint, 'minutes_expand')
101
101
  }
102
102
 
@@ -117,20 +117,20 @@ export class Reward {
117
117
  }
118
118
  }
119
119
 
120
- add_guard(gurads:RewardGuardPortions[], passport?:PassportObject) {
121
- if (gurads.length === 0) return;
120
+ add_guard(guards:RewardGuardPortions[], passport?:PassportObject) {
121
+ if (guards.length === 0) return;
122
122
 
123
123
  let bValid = true;
124
- gurads.forEach((v) => {
125
- if (!IsValidUintLarge(v.portions) || v.portions > Reward.MAX_PORTIONS_COUNT) bValid = false;
124
+ guards.forEach((v) => {
125
+ if (!IsValidU64(v.portions) || v.portions > Reward.MAX_PORTIONS_COUNT) bValid = false;
126
126
  if (!Protocol.IsValidObjects([v.guard])) bValid = false;
127
127
  })
128
128
  if (!bValid) {
129
- ERROR(Errors.InvalidParam, 'gurads')
129
+ ERROR(Errors.InvalidParam, 'guards')
130
130
  }
131
131
 
132
132
  if (passport) {
133
- gurads.forEach((guard) =>
133
+ guards.forEach((guard) =>
134
134
  this.txb.moveCall({
135
135
  target:Protocol.Instance().RewardFn('guard_add_with_passport') as FnCallType,
136
136
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
@@ -140,7 +140,7 @@ export class Reward {
140
140
  })
141
141
  )
142
142
  } else {
143
- gurads.forEach((guard) =>
143
+ guards.forEach((guard) =>
144
144
  this.txb.moveCall({
145
145
  target:Protocol.Instance().RewardFn('guard_add') as FnCallType,
146
146
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard.guard),
@@ -277,7 +277,6 @@ export class Reward {
277
277
  }
278
278
 
279
279
  allow_claim(bAllowClaim: boolean, passport?:PassportObject) {
280
-
281
280
  if (passport) {
282
281
  this.txb.moveCall({
283
282
  target:Protocol.Instance().RewardFn('allow_claim_with_passport') as FnCallType,
@@ -298,7 +297,6 @@ export class Reward {
298
297
  if (!Protocol.IsValidObjects([new_permission])) {
299
298
  ERROR(Errors.IsValidObjects)
300
299
  }
301
-
302
300
 
303
301
  this.txb.moveCall({
304
302
  target:Protocol.Instance().RewardFn('permission_set') as FnCallType,
@@ -308,15 +306,7 @@ export class Reward {
308
306
  this.permission = new_permission
309
307
  }
310
308
  static parseObjectType = (chain_type:string) : string => {
311
- if (chain_type) {
312
- const s = 'reward::Reward<'
313
- const i = chain_type.indexOf(s);
314
- if (i > 0) {
315
- let r = chain_type.slice(i + s.length, chain_type.length-1);
316
- return r
317
- }
318
- }
319
- return '';
309
+ return parseObjectType(chain_type, 'reward::Reward<')
320
310
  }
321
311
  static MAX_PORTIONS_COUNT = 600;
322
312
  static MAX_GUARD_COUNT = 16;
package/src/service.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, Bcs, array_unique, IsValidTokenType, IsValidDesription,
1
+ import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, parseObjectType, array_unique, IsValidTokenType, IsValidDesription,
2
2
  IsValidAddress, IsValidEndpoint, IsValidU64, } from './utils'
3
3
  import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryObject, MachineObject, ServiceAddress,
4
4
  ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol, ValueType,
@@ -1031,25 +1031,11 @@ export class Service {
1031
1031
  }
1032
1032
 
1033
1033
  static parseObjectType = (chain_type:string | undefined | null) : string => {
1034
- if (chain_type) {
1035
- const s = 'service::Service<'
1036
- const i = chain_type.indexOf(s);
1037
- if (i > 0) {
1038
- return chain_type.slice(i + s.length, chain_type.length-1);
1039
- }
1040
- }
1041
- return '';
1034
+ return parseObjectType(chain_type, 'service::Service<')
1042
1035
  }
1043
1036
 
1044
1037
  static parseOrderObjectType = (chain_type:string | undefined | null) : string => {
1045
- if (chain_type) {
1046
- const s = 'order::Order<'
1047
- const i = chain_type.indexOf(s);
1048
- if (i > 0) {
1049
- return chain_type.slice(i + s.length, chain_type.length-1);
1050
- }
1051
- }
1052
- return '';
1038
+ return parseObjectType(chain_type, 'order::Order<')
1053
1039
  }
1054
1040
 
1055
1041
  static endpoint = (service_endpoint:string, item_endpoint:string, item_name:string) => {
@@ -1062,7 +1048,7 @@ export class Service {
1062
1048
 
1063
1049
  static DiscountObjects = (owner:string, handleDiscountObject:handleDiscountObject) => {
1064
1050
  Protocol.Client().getOwnedObjects({owner:owner,
1065
- filter:{MoveModule:{module:'order', package:Protocol.Instance().Package()}},
1051
+ filter:{MoveModule:{module:'order', package:Protocol.Instance().Package('wowok')}},
1066
1052
  options:{showContent:true, showType:true}}).then((res) => {
1067
1053
  handleDiscountObject(owner, res.data.map((v)=>v.data));
1068
1054
  }).catch((e) => {
package/src/treasury.ts CHANGED
@@ -1,8 +1,28 @@
1
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'
2
+ import { FnCallType, Protocol, PassportObject, PermissionObject, TreasuryAddress, TxbObject, CoinObject, PaymentObject,
3
+ ReceivedObject } from './protocol';
4
+ import { IsValidDesription, IsValidU64, IsValidAddress, IsValidArgType, IsValidArray, parseObjectType} from './utils'
4
5
  import { Errors, ERROR} from './exception'
5
6
 
7
+ export interface DepositParam {
8
+ coin: CoinObject,
9
+ index: bigint,
10
+ remark: string,
11
+ for_object?: string,
12
+ for_guard?: string,
13
+ }
14
+
15
+ export interface WithdrawItem {
16
+ address: string,
17
+ amount: bigint,
18
+ }
19
+ export interface WithdrawParam {
20
+ items: WithdrawItem[],
21
+ index: bigint,
22
+ remark: string,
23
+ for_object?: string,
24
+ for_guard?: string,
25
+ }
6
26
  export class Treasury {
7
27
  protected token_type;
8
28
  protected permission ;
@@ -53,7 +73,7 @@ export class Treasury {
53
73
  return d
54
74
  }
55
75
 
56
- launch() : DemandAddress {
76
+ launch() : TreasuryAddress {
57
77
  return this.txb.moveCall({
58
78
  target:Protocol.Instance().TreasuryFn('create') as FnCallType,
59
79
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
@@ -69,125 +89,176 @@ export class Treasury {
69
89
  })
70
90
  }
71
91
 
72
- set_free_deposits(bFreeDeposit:boolean, passport?:PassportObject) {
92
+ set_free_deposit(bFreeDeposit:boolean, passport?:PassportObject) {
73
93
  if (passport) {
74
94
  this.txb.moveCall({
75
- target:Protocol.Instance().TreasuryFn('free_deposits_set_with_passport') as FnCallType,
95
+ target:Protocol.Instance().TreasuryFn('free_deposit_set_with_passport') as FnCallType,
76
96
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
77
97
  this.txb.pure.bool(bFreeDeposit), Protocol.TXB_OBJECT(this.txb, this.permission)],
78
98
  typeArguments:[this.token_type],
79
99
  })
80
100
  } else {
81
101
  this.txb.moveCall({
82
- target:Protocol.Instance().TreasuryFn('free_deposits_set') as FnCallType,
102
+ target:Protocol.Instance().TreasuryFn('free_deposit_set') as FnCallType,
83
103
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(bFreeDeposit), Protocol.TXB_OBJECT(this.txb, this.permission)],
84
104
  typeArguments:[this.token_type],
85
105
  })
86
106
  }
87
107
  }
88
108
 
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')
109
+ deposit(param:DepositParam, bFreeDeposit:boolean=false, passport?:PassportObject) :TxbObject {
110
+ if (!Protocol.IsValidObjects([param.coin])) {
111
+ ERROR(Errors.IsValidObjects, 'deposit.param.coin')
92
112
  }
93
- if (!IsValidDesription(tips)) {
94
- ERROR(Errors.IsValidDesription, 'deposit.tips')
113
+ if (!IsValidDesription(param.remark)) {
114
+ ERROR(Errors.IsValidDesription, 'deposit.param.remark')
95
115
  }
96
- if (for_object && !IsValidAddress(for_object)) {
97
- ERROR(Errors.IsValidAddress, 'deposit.tips')
116
+ if (param?.for_object && !IsValidAddress(param.for_object)) {
117
+ ERROR(Errors.IsValidAddress, 'deposit.param.for_object')
98
118
  }
99
- if (from_object && !IsValidAddress(from_object)) {
100
- ERROR(Errors.IsValidAddress, 'deposit.from_object')
119
+ if (param?.for_guard && !IsValidAddress(param.for_guard)) {
120
+ ERROR(Errors.IsValidAddress, 'deposit.param.for_guard')
101
121
  }
102
- if (index !== undefined && !IsValidU64(index)) {
103
- ERROR(Errors.InvalidParam, 'deposit.index')
122
+ if (param.index !== undefined && !IsValidU64(param.index)) {
123
+ ERROR(Errors.InvalidParam, 'deposit.param.index')
104
124
  }
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);
125
+
126
+ const for_obj = this.txb.pure.option('address', param.for_object ?? undefined);
108
127
  const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
109
128
 
129
+ if (bFreeDeposit) {
130
+ if (param.for_guard) {
131
+ 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)],
135
+ typeArguments:[this.token_type],
136
+ })
137
+ } else {
138
+ 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)],
142
+ typeArguments:[this.token_type],
143
+ })
144
+ }
145
+ } 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
+ }
162
+ } 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
+ }
178
+ }
179
+ }
180
+ }
181
+
182
+ receive(payment:PaymentObject, received:ReceivedObject, passport?:PassportObject) {
183
+ if (!Protocol.IsValidObjects([payment, received])) {
184
+ ERROR(Errors.IsValidArray, 'receive.payment&received');
185
+ }
186
+ const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
110
187
  if (passport) {
111
188
  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)],
189
+ target:Protocol.Instance().TreasuryFn('receive_with_passport') as FnCallType,
190
+ 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)],
115
192
  typeArguments:[this.token_type],
116
193
  })
117
194
  } else {
118
195
  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)],
196
+ target:Protocol.Instance().TreasuryFn('receive') as FnCallType,
197
+ 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)],
122
199
  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')
200
+ })
142
201
  }
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
202
  }
155
203
 
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')
204
+ withdraw(param:WithdrawParam, passport?:PassportObject) {
205
+ if (param.items.length === 0) return undefined;
206
+ if (!IsValidArray(param.items, (item:WithdrawItem) => IsValidU64(item.amount) && IsValidAddress(item.address))) {
207
+ ERROR(Errors.IsValidArray, 'withdraw.param.items')
159
208
  }
160
- if (!IsValidDesription(tips)) {
161
- ERROR(Errors.IsValidDesription, 'withdraw.tips')
209
+ if (!IsValidDesription(param.remark)) {
210
+ ERROR(Errors.IsValidDesription, 'withdraw.param.remark')
162
211
  }
163
- if (for_object && !IsValidAddress(for_object)) {
164
- ERROR(Errors.IsValidAddress, 'withdraw.for_object')
212
+ if (!IsValidU64(param.index)) {
213
+ ERROR(Errors.IsValidU64, 'withdraw.param.index')
165
214
  }
166
- if (to_object && !IsValidAddress(to_object)) {
167
- ERROR(Errors.IsValidAddress, 'withdraw.to_object')
215
+ if (param?.for_guard && !IsValidAddress(param.for_guard)) {
216
+ ERROR(Errors.IsValidAddress, 'withdraw.param.for_guard')
168
217
  }
169
- if (index !== undefined && !IsValidU64(index)) {
170
- ERROR(Errors.InvalidParam, 'withdraw.index')
218
+ if (param?.for_object && !IsValidAddress(param.for_object)) {
219
+ ERROR(Errors.IsValidAddress, 'withdraw.param.for_object')
171
220
  }
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);
221
+
222
+ const for_obj = this.txb.pure.option('address', param.for_object ?? undefined);
175
223
  const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
176
224
 
177
225
  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
- })
226
+ if (param.for_guard) {
227
+ return this.txb.moveCall({
228
+ target:Protocol.Instance().TreasuryFn('withdraw_forGuard_with_passport') as FnCallType,
229
+ 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)],
232
+ typeArguments:[this.token_type],
233
+ })
234
+ } else {
235
+ return this.txb.moveCall({
236
+ target:Protocol.Instance().TreasuryFn('withdraw_with_passport') as FnCallType,
237
+ 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)],
240
+ typeArguments:[this.token_type],
241
+ })
242
+ }
184
243
  } 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
- })
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
+ })
252
+ } 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
+ }
191
262
  }
192
263
  }
193
264
 
@@ -225,15 +296,11 @@ export class Treasury {
225
296
  this.permission = new_permission
226
297
  }
227
298
  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 '';
299
+ return parseObjectType(chain_type, 'treasury::Treasury<')
237
300
  }
301
+
302
+ static OP_WITHDRAW = 0;
303
+ static OP_DEPOSIT = 1;
304
+ static OP_RECEIVE = 2;
238
305
  }
239
306
 
package/src/utils.ts CHANGED
@@ -119,6 +119,17 @@ export const concatenate = (resultConstructor:any, ...arrays:any[]) => {
119
119
  return result;
120
120
  }
121
121
 
122
+ export const parseObjectType = (chain_type:string | null | undefined, header:string='payment::Payment<') : string => {
123
+ if (chain_type) {
124
+ const i = chain_type.indexOf(header);
125
+ if (i > 0) {
126
+ let r = chain_type.slice(i + header.length, chain_type.length-1);
127
+ return r
128
+ }
129
+ }
130
+ return '';
131
+ }
132
+
122
133
  export const array_equal = (arr1: any[], arr2: any[]) => {
123
134
  if (arr1.length !== arr2.length) {
124
135
  return false;
@@ -399,20 +410,17 @@ export const IsValidBigint = (value:string | number | undefined | bigint, max:bi
399
410
  }; return false
400
411
  }
401
412
 
402
- export const IsValidUintLarge = (value:string | number | undefined | bigint) : boolean => {
403
- return IsValidBigint(value, MAX_U64, BigInt(0))
404
- }
405
- export const IsValidU8 = (value:string | number | undefined | bigint) : boolean => {
406
- return IsValidBigint(value, MAX_U8, BigInt(0))
413
+ export const IsValidU8 = (value:string | number | undefined | bigint, min=0) : boolean => {
414
+ return IsValidBigint(value, MAX_U8, BigInt(min))
407
415
  }
408
- export const IsValidU64 = (value:string | number | undefined | bigint) : boolean => {
409
- return IsValidBigint(value, MAX_U64, BigInt(0))
416
+ export const IsValidU64 = (value:string | number | undefined | bigint, min=0) : boolean => {
417
+ return IsValidBigint(value, MAX_U64, BigInt(min))
410
418
  }
411
- export const IsValidU128 = (value:string | number | undefined | bigint) : boolean => {
412
- return IsValidBigint(value, MAX_U128, BigInt(0))
419
+ export const IsValidU128 = (value:string | number | undefined | bigint, min=0) : boolean => {
420
+ return IsValidBigint(value, MAX_U128, BigInt(min))
413
421
  }
414
- export const IsValidU256 = (value:string | number | undefined | bigint) : boolean => {
415
- return IsValidBigint(value, MAX_U256, BigInt(0))
422
+ export const IsValidU256 = (value:string | number | undefined | bigint, min=0) : boolean => {
423
+ return IsValidBigint(value, MAX_U256, BigInt(min))
416
424
  }
417
425
 
418
426
  export const IsValidTokenType = (argType: string) : boolean => {
@@ -466,19 +474,40 @@ export const ResolveU64 = (value:bigint) : bigint => {
466
474
  }
467
475
  }
468
476
 
477
+ function removeTrailingZeros(numberString: string): string {
478
+ const trimmedString = numberString.trim();
479
+ const decimalIndex = trimmedString.indexOf('.');
480
+
481
+ if (decimalIndex !== -1) {
482
+ let endIndex = trimmedString.length - 1;
483
+
484
+ while (trimmedString[endIndex] === '0') {
485
+ endIndex--;
486
+ }
487
+
488
+ if (trimmedString[endIndex] === '.') {
489
+ endIndex--; // 如果小数点后面全是零,也去掉小数点
490
+ }
491
+
492
+ return trimmedString.slice(0, endIndex + 1);
493
+ }
494
+
495
+ return trimmedString;
496
+ }
497
+
469
498
  export const ResolveBalance = (balance:string, decimals:number) : string => {
470
499
  if (!balance) return ''
471
500
  if (balance === '0') return '0'
472
501
  if (decimals <= 0) return balance;
473
502
  var pos = decimals - balance.length;
474
503
  if (pos === 0) {
475
- return '.' + balance;
504
+ return removeTrailingZeros('.' + (balance));
476
505
  } else if (pos < 0) {
477
506
  let start = balance.slice(0, Math.abs(pos));
478
507
  let end = balance.slice(Math.abs(pos));
479
- return start + '.' + end;
508
+ return removeTrailingZeros(start + '.' + end);
480
509
  } else {
481
- return '.' + balance.padStart(decimals, '0');
510
+ return removeTrailingZeros('.' + balance.padStart(decimals, '0'));
482
511
  }
483
512
  }
484
513