wowok 1.4.25 → 1.4.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.4.25",
3
+ "version": "1.4.28",
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",
@@ -36,7 +36,10 @@
36
36
  "grantor",
37
37
  "grantee",
38
38
  "move language",
39
- "move"
39
+ "move",
40
+ "treasury",
41
+ "payment",
42
+ "Withholding"
40
43
  ],
41
44
  "author": "wowok",
42
45
  "license": "Apache-2.0",
package/src/demand.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
2
- import { FnCallType, Protocol, PassportObject, PermissionObject, GuardObject, DemandAddress, TxbObject, ResourceObject} from './protocol';
3
- import { IsValidDesription, IsValidAddress, IsValidArgType, IsValidU64, } from './utils'
2
+ import { FnCallType, Protocol, PassportObject, PermissionObject, GuardObject, DemandAddress, TxbObject } from './protocol';
3
+ import { IsValidDesription, IsValidAddress, IsValidArgType, IsValidU64, parseObjectType } from './utils'
4
4
  import { Errors, ERROR} from './exception'
5
5
 
6
6
  export class Demand {
@@ -250,16 +250,8 @@ export class Demand {
250
250
  })
251
251
  this.permission = new_permission
252
252
  }
253
- static parseObjectType = (chain_type:string) : string => {
254
- if (chain_type) {
255
- const s = 'demand::Demand<'
256
- const i = chain_type.indexOf(s);
257
- if (i > 0) {
258
- let r = chain_type.slice(i + s.length, chain_type.length-1);
259
- return r
260
- }
261
- }
262
- return '';
253
+ static parseObjectType = (chain_type?:string | null) : string => {
254
+ return parseObjectType(chain_type, 'demand::Demand<')
263
255
  }
264
256
 
265
257
  static MAX_BOUNTY_COUNT = 300;
package/src/guard.ts CHANGED
@@ -263,19 +263,19 @@ export class Guard {
263
263
  [MODULES.vote, 'Voted Time by Address', 1113, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The time of whether an address has been voted on.', ['adddress']],
264
264
 
265
265
  [MODULES.payment, 'Sender', 1200, [], ValueType.TYPE_ADDRESS, 'Payment originator address.', []],
266
- [MODULES.payment, 'Total Amount', 1201, [], ValueType.TYPE_U64, "Payment amount.", []],
267
- [MODULES.payment, 'Tips', 1202, [], ValueType.TYPE_STRING, 'Payment remarks.', ['address']],
266
+ [MODULES.payment, 'Total Amount', 1201, [], ValueType.TYPE_U128, "Payment amount.", []],
267
+ [MODULES.payment, 'Remark', 1202, [], ValueType.TYPE_STRING, 'Payment remark.', ['address']],
268
268
  [MODULES.payment, 'Has Guard for Perpose', 1203, [], ValueType.TYPE_BOOL, 'Whether the payment references a Guard?', []],
269
269
  [MODULES.payment, 'Has Object for Perpose', 1204, [], ValueType.TYPE_BOOL, 'Whether the payment references an Object?', []],
270
270
  [MODULES.payment, 'Guard for Perpose', 1205, [], ValueType.TYPE_ADDRESS, 'The Guard referenced by this payment.', []],
271
271
  [MODULES.payment, 'Object for Perpose', 1206, [], ValueType.TYPE_ADDRESS, "The Object referenced by this payment.", []],
272
- [MODULES.payment, 'Number of Transfer', 1207, [], ValueType.TYPE_U64, 'Number of recipients to receive payment from.', []],
272
+ [MODULES.payment, 'Number of Recipients', 1207, [], ValueType.TYPE_U64, 'Number of recipients to receive payment from.', []],
273
273
  [MODULES.payment, 'Is a Recipient', 1208, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is a recipient received the payment?', ['address']],
274
274
  [MODULES.payment, 'Amount for a Recipient', 1209, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The amount of payment received by an address.', ['address']],
275
275
  [MODULES.payment, 'Time', 1210, [], ValueType.TYPE_U64, 'Payment time', []],
276
276
  [MODULES.payment, 'Is from Treasury', 1211, [], ValueType.TYPE_BOOL, 'Whether the payment comes from a Treasury?', []],
277
277
  [MODULES.payment, 'Treasury Address', 1212, [], ValueType.TYPE_ADDRESS, 'The Treasury from which the payment comes.', []],
278
- [MODULES.payment, 'Index', 1213, [], ValueType.TYPE_U64, 'Payment index or id.', []],
278
+ [MODULES.payment, 'Biz-ID', 1213, [], ValueType.TYPE_U64, 'Bisiness ID number of the payment.', []],
279
279
 
280
280
  [MODULES.withholding, 'Amount', 1300, [], ValueType.TYPE_U64, 'Total amount deposited with withholding.' , []],
281
281
  [MODULES.withholding, 'Original Type Deposited', 1301, [], ValueType.TYPE_STRING, "Original type name of asserts deposited.", []],
@@ -296,11 +296,10 @@ export class Guard {
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
- [MODULES.treasury, 'Deposit Flow', 1403, [], ValueType.TYPE_U128, 'Treasury inflow amount.', []],
300
- [MODULES.treasury, 'Withdraw Flow', 1404, [], ValueType.TYPE_U128, 'Treasury outflow amount.', []],
301
- [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']],
302
- [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']],
303
- [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']],
299
+ [MODULES.treasury, 'Inflow Amount', 1403, [], ValueType.TYPE_U128, 'Treasury inflow amount.', []],
300
+ [MODULES.treasury, 'Outflow Amount', 1404, [], ValueType.TYPE_U128, 'Treasury outflow amount.', []],
301
+ [MODULES.treasury, 'Number of Payment', 1405, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The number of flows generated by a payment.', ['payment address']],
302
+ [MODULES.treasury, 'Can anyone deposit ', 1406, [], ValueType.TYPE_BOOL, "Whether to allow any address to deposit?", []],
304
303
  ];
305
304
 
306
305
  static BoolCmd = Guard.QUERIES.filter(q => q[4] === ValueType.TYPE_BOOL);
package/src/index.ts CHANGED
@@ -14,4 +14,6 @@ export * from './graphql'
14
14
  export * from './entity'
15
15
  export * from './wowok'
16
16
  export * from './resource'
17
- export * from './treasury'
17
+ export * from './treasury'
18
+ export * from './payment'
19
+ export * from './withholding'
package/src/passport.ts CHANGED
@@ -94,7 +94,7 @@ export class GuardParser {
94
94
 
95
95
  // console.log(res[0].data?.content);
96
96
  let content = res[0].data!.content as any;
97
- if (content?.type != protocol.Package() + '::guard::Guard') {
97
+ if (content?.type != protocol.Package('base') + '::guard::Guard') {
98
98
  ERROR(Errors.Fail, 'GuardObject object invalid')
99
99
  }
100
100
 
@@ -255,12 +255,11 @@ export class GuardParser {
255
255
  res.forEach((r) => {
256
256
  const c = r.data?.content as any;
257
257
  if (!c) ERROR(Errors.Fail, 'Parse_Guard_Helper invalid content');
258
-
259
258
  const index = protocol.WOWOK_OBJECTS_TYPE().findIndex(v => {return v.includes('guard::Guard') && v == c.type});
260
259
  if (index === -1) ERROR(Errors.Fail, 'Parse_Guard_Helper invalid type: ' + c.type);
261
260
 
262
261
 
263
- if (c.fields.input.type === (protocol.Package() + '::bcs::BCS')) {
262
+ if (c.fields.input.type === (protocol.Package('base') + '::bcs::BCS')) {
264
263
  const constants = GuardParser.parse_constant(c.fields.constants); // MUST first
265
264
  const inputs = GuardParser.parse_bcs(constants, Uint8Array.from(c.fields.input.fields.bytes));
266
265
  me.guard_list.push({id: c.fields.id.id, input:[...inputs], constant:[...constants], digest:r.data?.digest??'', version:r.data?.version ?? ''});
package/src/payment.ts ADDED
@@ -0,0 +1,63 @@
1
+ import { CoinObject, FnCallType, PaymentAddress, Protocol, TxbObject} from './protocol';
2
+ import { IsValidDesription, IsValidAddress, IsValidArray, } from './utils';
3
+ import { ERROR, Errors } from './exception';
4
+ import { Transaction as TransactionBlock} from '@mysten/sui/transactions';
5
+
6
+ export interface Payment_Receiver {
7
+ address: string;
8
+ coin: CoinObject;
9
+ }
10
+
11
+ export interface PaymentParam {
12
+ receiver: Payment_Receiver[];
13
+ business_index: bigint;
14
+ business_remark: string;
15
+ for_object?: string;
16
+ for_guard?: string;
17
+ }
18
+
19
+ export const PAYMENT_MAX_RECEIVER_COUNT = 200;
20
+ export function create_payment(txb:TransactionBlock, pay_token_type:string, param:PaymentParam) : PaymentAddress {
21
+ if (!pay_token_type) ERROR(Errors.InvalidParam, 'Payment.New.pay_token_type');
22
+
23
+ if (param.receiver.length > PAYMENT_MAX_RECEIVER_COUNT) {
24
+ ERROR(Errors.InvalidParam, 'Payment.New.param.receiver');
25
+ }
26
+
27
+ if (!IsValidArray(param.receiver, (item:Payment_Receiver) => { return IsValidAddress(item.address) && Protocol.IsValidObjects([item.coin])})) {
28
+ ERROR(Errors.IsValidArray, 'Payment.New.param.receiver');
29
+ }
30
+
31
+ if (param?.for_object && !IsValidAddress(param.for_object)) {
32
+ ERROR(Errors.IsValidAddress, 'Payment.New.param.for_object')
33
+ }
34
+ if (param?.for_guard && !IsValidAddress(param.for_guard)) {
35
+ ERROR(Errors.IsValidAddress, 'Payment.New.param.for_guard')
36
+ }
37
+ if (param?.business_remark && !IsValidDesription(param?.business_remark)) {
38
+ ERROR(Errors.IsValidDesription, 'Payment.New.param.business_remark')
39
+ }
40
+
41
+ let obj = txb.pure.option('address', param.for_object ? param.for_object : undefined);
42
+ const clock = txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
43
+
44
+ if (param.for_guard) {
45
+ return txb.moveCall({
46
+ target:Protocol.Instance().PaymentFn('create_withGuard') as FnCallType,
47
+ arguments:[txb.pure.vector('address', param.receiver.map((i)=>i.address)), txb.makeMoveVec({elements:param.receiver.map((i)=>i.coin)}),
48
+ obj, txb.object(param.for_guard), txb.pure.u64(param.business_index), txb.pure.string(param.business_remark), txb.object(clock)],
49
+ typeArguments:[pay_token_type],
50
+ })
51
+ } else {
52
+ return txb.moveCall({
53
+ target:Protocol.Instance().PaymentFn('new') as FnCallType,
54
+ arguments:[txb.pure.vector('address', param.receiver.map((i)=>i.address)), txb.makeMoveVec({elements:param.receiver.map((i)=>i.coin)}),
55
+ obj, txb.pure.u64(param.business_index), txb.pure.string(param.business_remark), txb.object(clock)],
56
+ typeArguments:[pay_token_type],
57
+ })
58
+ }
59
+ }
60
+
61
+
62
+
63
+
package/src/permission.ts CHANGED
@@ -79,10 +79,12 @@ export enum PermissionIndex {
79
79
  progress_parent = 655,
80
80
 
81
81
  treasury = 700,
82
- treasury_deposit = 701,
83
- treasury_withdraw = 702,
84
- treasury_free_deposit_set = 703,
82
+ treasury_receive = 701,
83
+ treasury_deposit = 702,
84
+ treasury_withdraw = 703,
85
85
  treasury_descritption = 704,
86
+ treasury_free_deposit_set = 705,
87
+
86
88
  user_defined_start = 1000,
87
89
  }
88
90
 
@@ -183,6 +185,7 @@ export const PermissionInfo : PermissionInfoType[] = [
183
185
 
184
186
  {index:PermissionIndex.treasury, name: 'Treasury', description:'Launch new Treasury', module: 'treasury'},
185
187
  {index:PermissionIndex.treasury_deposit, name: 'Deposit', description:'Deposit coins', module: 'treasury'},
188
+ {index:PermissionIndex.treasury_receive, name: 'Receive', description:'Receive coins from some address sent', module: 'treasury'},
186
189
  {index:PermissionIndex.treasury_withdraw, name: 'Withdraw', description:'Withdraw coins', module: 'treasury'},
187
190
  {index:PermissionIndex.treasury_free_deposit_set, name: 'Be Free Deposit', description:'Set whether deposits can be made without permission', module: 'treasury'},
188
191
  {index:PermissionIndex.treasury_descritption, name: 'Description', description:'Set Treasury description', module: 'treasury'},
package/src/progress.ts CHANGED
@@ -78,7 +78,6 @@ export class Progress {
78
78
  }
79
79
 
80
80
  launch() : ProgressAddress {
81
-
82
81
  return this.txb.moveCall({
83
82
  target:Protocol.Instance().ProgressFn('create') as FnCallType,
84
83
  arguments: [Protocol.TXB_OBJECT(this.txb, this.object)],
package/src/protocol.ts CHANGED
@@ -9,9 +9,7 @@ import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui/utils'
9
9
 
10
10
  export enum MODULES {
11
11
  machine = 'machine',
12
- node = 'node',
13
12
  progress = 'progress',
14
- community = 'community',
15
13
  repository = 'repository',
16
14
  permission = 'permission',
17
15
  passport = 'passport',
@@ -56,6 +54,11 @@ export type ResourceObject = TransactionResult | string | TransactionArgument;
56
54
  export type ResourceAddress = TransactionResult;
57
55
  export type EntityObject = TransactionResult | string | TransactionArgument;
58
56
  export type EntityAddress = TransactionResult;
57
+ export type TreasuryAddress = TransactionResult;
58
+ export type PaymentObject = TransactionResult | string | TransactionArgument;
59
+ export type PaymentAddress = TransactionResult;
60
+ export type ReceivedObject = TransactionResult | string | TransactionArgument;
61
+ export type CoinWrapperObject = TransactionResult;
59
62
 
60
63
  export type TxbObject = string | TransactionResult | TransactionArgument | GuardObject | RepositoryObject | PermissionObject | MachineObject | PassportObject |
61
64
  DemandObject | ServiceObject | RewardObject | OrderObject | DiscountObject | VoteObject | DemandObject | ResourceObject | EntityObject;
@@ -204,20 +207,23 @@ export enum ENTRYPOINT {
204
207
  }
205
208
  /*
206
209
  const TESTNET = {
207
- package: "0xbd3d0929072f7647e521bf72851ccdc7e2169052b22bfdc5b49439c48cfb119a",
210
+ wowok: "0xbd3d0929072f7647e521bf72851ccdc7e2169052b22bfdc5b49439c48cfb119a",
208
211
  wowok_object: '0xb0a521a287e9d5e08932b3984dbe6ce159e836179c41bd08c556ef77ecdb7439',
209
212
  entity_object: '0x16aab98920e7341d1dc19631031253234b2b71fc2ab8c32d65ee3ded8072acef',
210
213
  treasury_cap:'0xb75a2ca2f651755c134ad521175f33f9e3f9008ad44340f76b3229e1f30cfdff',
211
214
  }
212
215
  */
213
216
  const TESTNET = {
214
- package: "0x0a0a86d4d364ba566d5392cd8ba7d980f4d65fc1e1586e5b2e49b0ecd8dfeae4",
215
- wowok_object: '0x8e5424a7899597dc75b456d597dd0a741296c1363282a72d52421b1c85d2460e',
216
- entity_object: '0xd88aaf554750437ab4148acca27e0ba51cff97c13882722a4a89289e57a7b8fa',
217
- treasury_cap:'0x01079f2baa2c320afc52e0f2680167c44bbaad9a6a21514bfd2e56356028be9d',
217
+ wowok: "0x6c0d4f3c5f1ceb981721cd44c516bbeadf22f53791906ed00893a64bb788d56c",
218
+ wowok_origin:'0xa487291ecede9b713400360ce81d242ad227af8184f07ace1a3dab1bfc920660' ,
219
+ base: '0x7efcdab72af2351e5915e34ad2ac8d4ea7f4f408e08138d3498af35a362db782',
220
+ wowok_object: '0xb56d70321b3205e994eb8e7664eabc91f361a55d75f363a321c8d4cf012fd6b2',
221
+ entity_object: '0x33881b1d2a65886c3068917a20d849e3956771df1bceb7a05678e40bcff30aa2',
222
+ treasury_cap:'0x538cf8f32d59f58c0450a3a97c1eeed3096f4ce63e07e0bdf343a5cc1464887c',
218
223
  }
219
224
  const MAINNET = {
220
- package: "",
225
+ wowok: "",
226
+ base:"",
221
227
  wowok_object: '',
222
228
  entity_object: '',
223
229
  treasury_cap:'',
@@ -231,7 +237,7 @@ export interface CoinTypeInfo {
231
237
  }
232
238
  export class Protocol {
233
239
  protected network = '';
234
- protected package = '';
240
+ protected package = new Map<string, string>();
235
241
  protected signer = '';
236
242
  protected wowok_object = '';
237
243
  protected entity_object = '';
@@ -262,14 +268,17 @@ export class Protocol {
262
268
  case ENTRYPOINT.devnet:
263
269
  break;
264
270
  case ENTRYPOINT.testnet:
265
- this.package = TESTNET.package;
271
+ this.package.set('wowok', TESTNET.wowok);
272
+ this.package.set('base', TESTNET.base);
273
+ this.package.set('wowok_origin', TESTNET.wowok_origin); //@ orgin package!!!
266
274
  this.wowok_object = TESTNET.wowok_object;
267
275
  this.entity_object= TESTNET.entity_object;
268
276
  this.treasury_cap = TESTNET.treasury_cap;
269
277
  this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
270
278
  break;
271
279
  case ENTRYPOINT.mainnet:
272
- this.package = MAINNET.package;
280
+ this.package.set('wowok', MAINNET.wowok);
281
+ this.package.set('base', MAINNET.base);
273
282
  this.wowok_object = MAINNET.wowok_object;
274
283
  this.entity_object= MAINNET.entity_object;
275
284
  this.treasury_cap = MAINNET.treasury_cap;
@@ -277,7 +286,10 @@ export class Protocol {
277
286
  break;
278
287
  };
279
288
  }
280
- Package(): string { return this.package }
289
+ Package(type:string): string {
290
+ return this.package.get(type) ?? ''
291
+ }
292
+
281
293
  WowokObject(): string { return this.wowok_object }
282
294
  EntityObject(): string { return this.entity_object }
283
295
  TreasuryCap() : string { return this.treasury_cap }
@@ -296,22 +308,24 @@ export class Protocol {
296
308
  }; return "";
297
309
  };
298
310
 
299
- MachineFn = (fn:any) => { return `${this.package}::${MODULES.machine}::${fn}`};
300
- ProgressFn = (fn:any) => { return `${this.package}::${MODULES.progress}::${fn}`};
301
- CommunityFn = (fn: any) => { return `${this.package}::${MODULES.community}::${fn}`};
302
- RepositoryFn = (fn:any) => { return `${this.package}::${MODULES.repository}::${fn}`};
303
- PermissionFn = (fn: any) => { return `${this.package}::${MODULES.permission}::${fn}`};
304
- PassportFn = (fn:any) => { return `${this.package}::${MODULES.passport}::${fn}`};
305
- GuardFn = (fn: any) => { return `${this.package}::${MODULES.guard}::${fn}`};
306
- VoteFn = (fn:any) => { return `${this.package}::${MODULES.vote}::${fn}`};
307
- DemandFn = (fn: any) => { return `${this.package}::${MODULES.demand}::${fn}`};
308
- OrderFn = (fn:any) => { return `${this.package}::${MODULES.order}::${fn}`};
309
- RewardFn = (fn: any) => { return `${this.package}::${MODULES.reward}::${fn}`};
310
- ServiceFn = (fn: any) => { return `${this.package}::${MODULES.service}::${fn}`};
311
- ResourceFn = (fn: any) => { return `${this.package}::${MODULES.resource}::${fn}`};
312
- EntityFn = (fn: any) => { return `${this.package}::${MODULES.entity}::${fn}`};
313
- WowokFn = (fn: any) => { return `${this.package}::${MODULES.wowok}::${fn}`};
314
- TreasuryFn = (fn: any) => { return `${this.package}::${MODULES.treasury}::${fn}`};
311
+ MachineFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.machine}::${fn}`};
312
+ ProgressFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.progress}::${fn}`};
313
+ RepositoryFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.repository}::${fn}`};
314
+ PermissionFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.permission}::${fn}`};
315
+ PassportFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.passport}::${fn}`};
316
+ VoteFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.vote}::${fn}`};
317
+ DemandFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.demand}::${fn}`};
318
+ OrderFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.order}::${fn}`};
319
+ RewardFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.reward}::${fn}`};
320
+ ServiceFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.service}::${fn}`};
321
+ ResourceFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.resource}::${fn}`};
322
+ EntityFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.entity}::${fn}`};
323
+ WowokFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.wowok}::${fn}`};
324
+ TreasuryFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.treasury}::${fn}`};
325
+ PaymentFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.payment}::${fn}`};
326
+ WithholdingFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.withholding}::${fn}`};
327
+ GuardFn = (fn: any) => { return `${this.package.get('base')}::${MODULES.guard}::${fn}`};
328
+ MintFn = (fn: any) => { return `${this.package.get('base')}::${MODULES.wowok}::${fn}`};
315
329
 
316
330
  Query = async (objects: Query_Param[], options:SuiObjectDataOptions={showContent:true}) : Promise<SuiObjectResponse[]> => {
317
331
  const client = new SuiClient({ url: this.NetworkUrl() });
@@ -342,7 +356,6 @@ export class Protocol {
342
356
 
343
357
  const privkey = fromHEX(priv_key);
344
358
  const keypair = Ed25519Keypair.fromSecretKey(privkey);
345
-
346
359
  const response = await client.signAndExecuteTransaction({
347
360
  transaction: this.CurrentSession(),
348
361
  signer: keypair,
@@ -356,8 +369,8 @@ export class Protocol {
356
369
  static SUI_TOKEN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'; // TOKEN_TYPE
357
370
  // used in demand, reward, ...
358
371
  static SUI_COIN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0x2::sui::SUI>'; // COIN TYPE
359
- WOWOK_TOKEN_TYPE = () => { return this.package + '::wowok::WOWOK' }
360
- WOWOK_COIN_TYPE = () => { return '0x2::coin::Coin<' + this.package + '::wowok::WOWOK>'}
372
+ WOWOK_TOKEN_TYPE = () => { return this.package.get('base') + '::wowok::WOWOK' }
373
+ WOWOK_COIN_TYPE = () => { return '0x2::coin::Coin<' + this.package.get('base') + '::wowok::WOWOK>'}
361
374
  COINS_TYPE = () => {
362
375
  switch(this.network) {
363
376
  case ENTRYPOINT.testnet:
@@ -392,13 +405,13 @@ export class Protocol {
392
405
  CoinTypes_Testnet:CoinTypeInfo[] = [
393
406
  {symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9, alias:true},
394
407
  {symbol:'SUI', type:'0x2::sui::SUI', decimals:9, },
395
- {symbol:'WOW', type:TESTNET.package + '::wowok::WOWOK', decimals:9},
408
+ {symbol:'WOW', type:TESTNET.base + '::wowok::WOWOK', decimals:9},
396
409
  ];
397
410
 
398
411
  CoinTypes_Mainnet:CoinTypeInfo[] = [
399
412
  {symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9, alias:true},
400
413
  {symbol:'SUI', type:'0x2::sui::SUI', decimals:9, },
401
- {symbol:'WOW', type:TESTNET.package + '::wowok::WOWOK', decimals:9},
414
+ {symbol:'WOW', type:TESTNET.base + '::wowok::WOWOK', decimals:9},
402
415
  {symbol:'USDT', type:'0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', decimals:6},
403
416
  {symbol:'USDC', type:'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN', decimals:6},
404
417
  {symbol:'WETH', type:'0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN', decimals:8},
@@ -438,13 +451,20 @@ export class Protocol {
438
451
  })
439
452
  }
440
453
  WOWOK_OBJECTS_TYPE = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) =>
441
- { let i = this.package + '::' + key + '::'; return i + capitalize(key); })
454
+ { let i = (key === MODULES.guard ? this.package.get('base') : this.package.get('wowok')) + '::' + key + '::'; return i + capitalize(key); })
442
455
  WOWOK_OBJECTS_PREFIX_TYPE = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) =>
443
- { return this.package + '::' + key + '::'; })
456
+ { return (key === MODULES.guard ? this.package.get('base') : this.package.get('wowok')) + '::' + key + '::'; })
457
+ private hasPackage(pack:string) : boolean {
458
+ for (let value of this.package.values()) {
459
+ if (value === pack) {
460
+ return true;
461
+ }
462
+ } return false;
463
+ }
444
464
  object_name_from_type_repr = (type_repr:string) : string => {
445
465
  if (!type_repr) return ''
446
466
  let i = type_repr.indexOf('::');
447
- if (i > 0 && type_repr.slice(0, i) === this.package) {
467
+ if (i > 0 && this.hasPackage(type_repr.slice(0, i))) {
448
468
  i = type_repr.indexOf('<');
449
469
  if (i > 0) {
450
470
  type_repr = type_repr.slice(0, i);
@@ -457,6 +477,22 @@ export class Protocol {
457
477
  }
458
478
  return ''
459
479
  }
480
+ module_object_name_from_type_repr = (type_repr:string) : string => {
481
+ if (!type_repr) return ''
482
+ let i = type_repr.indexOf('::');
483
+ if (i > 0 && this.hasPackage(type_repr.slice(0, i))) {
484
+ i = type_repr.indexOf('<');
485
+ if (i > 0) {
486
+ type_repr = type_repr.slice(0, i);
487
+ }
488
+
489
+ let n = type_repr.indexOf('::');
490
+ if (n > 0) {
491
+ return type_repr.slice(n+2);
492
+ }
493
+ }
494
+ return ''
495
+ }
460
496
  }
461
497
 
462
498
  export class RpcResultParser {
@@ -471,8 +507,7 @@ export class RpcResultParser {
471
507
  if (response?.objectChanges) {
472
508
  response.objectChanges.forEach((change) => {
473
509
  RpcResultParser.Object_Type_Extra().forEach((name) => {
474
- let type = protocol.Package() + '::' + name;
475
- if (change.type == 'created' && change.objectType.includes(type)) {
510
+ if (change.type == 'created' && protocol.module_object_name_from_type_repr(change.objectType)===name) {
476
511
  if (ret.has(name)) {
477
512
  ret.get(name)?.push(change.objectId);
478
513
  } else {
package/src/repository.ts CHANGED
@@ -2,7 +2,7 @@ import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress
2
2
  import { PermissionIndexType, Permission } from './permission'
3
3
  import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, IsValidName, ValueTypeConvert} from './utils';
4
4
  import { ERROR, Errors } from './exception';
5
- import { MAX_U8, MAX_U128, MAX_U256, MAX_U64, stringToUint8Array } from './utils';
5
+ import { MAX_U8, MAX_U128, MAX_U256, MAX_U64, parseObjectType } from './utils';
6
6
  import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
7
7
 
8
8
  export enum Repository_Policy_Mode {
@@ -394,16 +394,8 @@ export class Repository {
394
394
  static IsValidValue = (value:Uint8Array) => {
395
395
  return value.length < Repository.MAX_VALUE_LENGTH;
396
396
  }
397
- static parseObjectType = (chain_type:string) : string => {
398
- if (chain_type) {
399
- const s = 'repository::Repository<'
400
- const i = chain_type.indexOf(s);
401
- if (i > 0) {
402
- let r = chain_type.slice(i + s.length, chain_type.length-1);
403
- return r
404
- }
405
- }
406
- return '';
397
+ static parseObjectType = (chain_type?:string | null) : string => {
398
+ return parseObjectType(chain_type, 'repository::Repository<');
407
399
  }
408
400
 
409
401
  static rpc_de_data(fields:any) : RepData [] {
package/src/resource.ts CHANGED
@@ -21,6 +21,8 @@ export class Resource {
21
21
  static LikeName = "like";
22
22
  static DislikeName = "dislike";
23
23
  static FavorName = "favor";
24
+ static LaunchName = 'launch';
25
+ static OrderName = 'order';
24
26
 
25
27
  protected object:TxbObject;
26
28
  protected txb;
@@ -55,14 +57,14 @@ export class Resource {
55
57
  });
56
58
  }
57
59
 
58
- add2(object:string, name:string[]) {
59
- if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'add2');
60
+ add2(object:TxbObject, name:string[]) {
61
+ if (typeof(object) === 'string' && !IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'add2');
60
62
  if (!IsValidArray(name, IsValidName)) ERROR(Errors.IsValidArray, 'add2');
61
63
  if (!name) return
62
64
 
63
65
  this.txb.moveCall({
64
66
  target:Protocol.Instance().ResourceFn('add2') as FnCallType,
65
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(object),
67
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), typeof(object) === 'string' ? this.txb.pure.address(object) : object,
66
68
  this.txb.pure.vector('string', name)]
67
69
  });
68
70
  }
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, IsValidU64} 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;
@@ -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 ;
@@ -27,10 +47,10 @@ export class Treasury {
27
47
  static New(txb:TransactionBlock, token_type:string, permission:PermissionObject, description:string,
28
48
  bFreeDeposit:boolean=false, passport?:PassportObject) : Treasury {
29
49
  if (!Protocol.IsValidObjects([permission])) {
30
- ERROR(Errors.IsValidObjects, 'permission, bounty');
50
+ ERROR(Errors.IsValidObjects, 'Treasury.New permission, bounty');
31
51
  }
32
52
  if (!IsValidDesription(description)) {
33
- ERROR(Errors.IsValidDesription);
53
+ ERROR(Errors.IsValidDesription, 'Treasury.New.description');
34
54
  }
35
55
  if (!IsValidArgType(token_type)) {
36
56
  ERROR(Errors.IsValidArgType, token_type);
@@ -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?:bigint, 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:bigint, tips:string, for_object?:string, index?:bigint, 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;
@@ -463,19 +474,40 @@ export const ResolveU64 = (value:bigint) : bigint => {
463
474
  }
464
475
  }
465
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
+
466
498
  export const ResolveBalance = (balance:string, decimals:number) : string => {
467
499
  if (!balance) return ''
468
500
  if (balance === '0') return '0'
469
501
  if (decimals <= 0) return balance;
470
502
  var pos = decimals - balance.length;
471
503
  if (pos === 0) {
472
- return '.' + balance;
504
+ return removeTrailingZeros('.' + (balance));
473
505
  } else if (pos < 0) {
474
506
  let start = balance.slice(0, Math.abs(pos));
475
507
  let end = balance.slice(Math.abs(pos));
476
- return start + '.' + end;
508
+ return removeTrailingZeros(start + '.' + end);
477
509
  } else {
478
- return '.' + balance.padStart(decimals, '0');
510
+ return removeTrailingZeros('.' + balance.padStart(decimals, '0'));
479
511
  }
480
512
  }
481
513
 
@@ -0,0 +1,167 @@
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
+ }
package/src/wowok.ts CHANGED
@@ -52,7 +52,7 @@ export class Wowok {
52
52
  if (!IsValidAddress(recipient)) ERROR(Errors.IsValidAddress, 'mint');
53
53
  if (!IsValidU64(amount)) ERROR(Errors.IsValidU64, 'mint');
54
54
  this.txb.moveCall({
55
- target:Protocol.Instance().WowokFn('mint') as FnCallType,
55
+ target:Protocol.Instance().MintFn('mint') as FnCallType, //@ base package
56
56
  arguments:[Protocol.TXB_OBJECT(this.txb, Protocol.Instance().TreasuryCap()), this.txb.pure.u64(amount),
57
57
  this.txb.pure.address(recipient)]
58
58
  })