zo-sdk 0.1.19 → 0.1.21

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.
Files changed (54) hide show
  1. package/dist/abstract/BaseDataAPI.d.cts +2 -2
  2. package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
  3. package/dist/abstract/BaseDataAPI.d.mts +2 -2
  4. package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
  5. package/dist/consts/deployments-zlp-mainnet.json +16 -0
  6. package/dist/consts/deployments-zlp-testnet.json +16 -0
  7. package/dist/consts/index.cjs.map +1 -1
  8. package/dist/consts/index.d.cts +10 -0
  9. package/dist/consts/index.d.cts.map +1 -1
  10. package/dist/consts/index.d.mts +10 -0
  11. package/dist/consts/index.d.mts.map +1 -1
  12. package/dist/consts/index.mjs.map +1 -1
  13. package/dist/implementations/SLPDataAPI.cjs +32 -54
  14. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  15. package/dist/implementations/SLPDataAPI.d.cts +2 -2
  16. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  17. package/dist/implementations/SLPDataAPI.d.mts +2 -2
  18. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  19. package/dist/implementations/SLPDataAPI.mjs +32 -54
  20. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  21. package/dist/implementations/USDZAPI.cjs +1 -1
  22. package/dist/implementations/USDZAPI.cjs.map +1 -1
  23. package/dist/implementations/USDZAPI.d.cts +1 -1
  24. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  25. package/dist/implementations/USDZAPI.d.mts +1 -1
  26. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  27. package/dist/implementations/USDZAPI.mjs +1 -1
  28. package/dist/implementations/USDZAPI.mjs.map +1 -1
  29. package/dist/implementations/ZLPAPI.cjs +45 -0
  30. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  31. package/dist/implementations/ZLPAPI.d.cts +2 -0
  32. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  33. package/dist/implementations/ZLPAPI.d.mts +2 -0
  34. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  35. package/dist/implementations/ZLPAPI.mjs +45 -0
  36. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  37. package/dist/interfaces/base.d.cts +2 -2
  38. package/dist/interfaces/base.d.cts.map +1 -1
  39. package/dist/interfaces/base.d.mts +2 -2
  40. package/dist/interfaces/base.d.mts.map +1 -1
  41. package/dist/interfaces/zlp.d.cts +2 -0
  42. package/dist/interfaces/zlp.d.cts.map +1 -1
  43. package/dist/interfaces/zlp.d.mts +2 -0
  44. package/dist/interfaces/zlp.d.mts.map +1 -1
  45. package/package.json +8 -8
  46. package/src/abstract/BaseDataAPI.ts +2 -2
  47. package/src/consts/deployments-zlp-mainnet.json +16 -0
  48. package/src/consts/deployments-zlp-testnet.json +16 -0
  49. package/src/consts/index.ts +10 -0
  50. package/src/implementations/SLPDataAPI.ts +41 -71
  51. package/src/implementations/USDZAPI.ts +1 -1
  52. package/src/implementations/ZLPAPI.ts +63 -0
  53. package/src/interfaces/base.ts +2 -2
  54. package/src/interfaces/zlp.ts +15 -0
@@ -326,47 +326,33 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
326
326
  public async getPositionInfoList(
327
327
  positionCapInfoList: ISLPPositionCapInfo[],
328
328
  owner: string,
329
- batchSize = 10,
330
329
  ): Promise<ISLPPositionInfo[]> {
331
330
  const positionInfoList: ISLPPositionInfo[] = []
332
-
333
- // Process in batches of 10
334
- for (let i = 0; i < positionCapInfoList.length; i += batchSize) {
335
- const batch = positionCapInfoList.slice(i, i + batchSize)
336
-
337
- await Promise.all(batch.map(async (positionCapInfo) => {
338
- try {
339
- const positionRaw = await this.provider.getDynamicFieldObject({
340
- parentId: this.consts.sudoCore.positionsParent,
341
- name: {
342
- type: `${this.consts.sudoCore.package}::market::PositionName<${
343
- positionCapInfo.symbol0
344
- }, ${positionCapInfo.symbol1}, ${
345
- this.consts.sudoCore.package
331
+ await Promise.all(
332
+ positionCapInfoList.map(async (positionCapInfo) => {
333
+ const positionRaw = await this.provider.getDynamicFieldObject({
334
+ parentId: this.consts.sudoCore.positionsParent,
335
+ name: {
336
+ type: `${this.consts.sudoCore.package}::market::PositionName<${positionCapInfo.symbol0
337
+ }, ${positionCapInfo.symbol1}, ${this.consts.sudoCore.package
346
338
  }::market::${positionCapInfo.long ? 'LONG' : 'SHORT'}>`,
347
- value: {
348
- owner,
349
- id: positionCapInfo.positionCapId,
350
- },
339
+ value: {
340
+ owner,
341
+ id: positionCapInfo.positionCapId,
351
342
  },
352
- })
343
+ },
344
+ })
353
345
 
354
- if (positionRaw?.data?.content) {
355
- positionInfoList.push(
356
- await this.parsePositionInfo(
357
- positionRaw,
358
- positionCapInfo.positionCapId,
359
- ),
360
- )
361
- }
362
- }
363
- catch (error) {
364
- // Position might have been deleted after force settlement
365
- console.warn(`Failed to parse position info for position cap ID ${positionCapInfo.positionCapId}: ${error}`)
366
- // Continue with next position without adding this one to the list
346
+ if (positionRaw?.data?.content) {
347
+ positionInfoList.push(
348
+ await this.parsePositionInfo(
349
+ positionRaw,
350
+ positionCapInfo.positionCapId,
351
+ ),
352
+ )
367
353
  }
368
- }))
369
- }
354
+ }),
355
+ )
370
356
 
371
357
  return positionInfoList.sort((a, b) =>
372
358
  a.openTimestamp > b.openTimestamp ? 1 : -1,
@@ -822,47 +808,31 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
822
808
  public async getOrderInfoList(
823
809
  orderCapInfoList: ISLPOrderCapInfo[],
824
810
  owner: string,
825
- batchSize = 10,
826
811
  ): Promise<ISLPOrderInfo[]> {
827
812
  const orderInfoList: ISLPOrderInfo[] = []
828
-
829
- // Process in batches of 10
830
- for (let i = 0; i < orderCapInfoList.length; i += batchSize) {
831
- const batch = orderCapInfoList.slice(i, i + batchSize)
832
-
833
- await Promise.all(batch.map(async (orderCapInfo) => {
834
- try {
835
- const orderRaw = await this.provider.getDynamicFieldObject({
836
- parentId: this.consts.sudoCore.ordersParent,
837
- name: {
838
- type: `${this.consts.sudoCore.package}::market::OrderName<${
839
- orderCapInfo.symbol0
840
- }, ${orderCapInfo.symbol1}, ${
841
- this.consts.sudoCore.package
842
- }::market::${orderCapInfo.long ? 'LONG' : 'SHORT'}, ${
843
- this.consts.coins.sui.module
813
+ await Promise.all(
814
+ orderCapInfoList.map(async (orderCapInfo) => {
815
+ const orderRaw = await this.provider.getDynamicFieldObject({
816
+ parentId: this.consts.sudoCore.ordersParent,
817
+ name: {
818
+ type: `${this.consts.sudoCore.package}::market::OrderName<${orderCapInfo.symbol0
819
+ }, ${orderCapInfo.symbol1}, ${this.consts.sudoCore.package
820
+ }::market::${orderCapInfo.long ? 'LONG' : 'SHORT'}, ${this.consts.coins.sui.module
844
821
  }>`,
845
- value: {
846
- owner,
847
- id: orderCapInfo.orderCapId,
848
- position_id: {
849
- vec: orderCapInfo.positionId ? [orderCapInfo.positionId] : [],
850
- },
822
+ value: {
823
+ owner,
824
+ id: orderCapInfo.orderCapId,
825
+ position_id: {
826
+ vec: orderCapInfo.positionId ? [orderCapInfo.positionId] : [],
851
827
  },
852
828
  },
853
- })
854
- orderInfoList.push(
855
- this.parseOrderInfo(orderRaw, orderCapInfo.orderCapId),
856
- )
857
- }
858
- catch (error) {
859
- // Order might have been deleted
860
- console.warn(`Failed to parse order info for order cap ID ${orderCapInfo.orderCapId}: ${error}`)
861
- // Continue with next order without adding this one to the list
862
- }
863
- }))
864
- }
865
-
829
+ },
830
+ })
831
+ orderInfoList.push(
832
+ this.parseOrderInfo(orderRaw, orderCapInfo.orderCapId),
833
+ )
834
+ }),
835
+ )
866
836
  return orderInfoList.sort((a, b) => (a.createdAt > b.createdAt ? 1 : -1))
867
837
  }
868
838
 
@@ -113,7 +113,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
113
113
  throw new Error(`Method not implemented in ${this.constructor.name}.`)
114
114
  }
115
115
 
116
- public getPositionInfoList(_positionCapInfoList: IBasePositionCapInfo[], _owner: string, _batchSize?: number): Promise<IBasePositionInfo[]> {
116
+ public getPositionInfoList(_positionCapInfoList: IBasePositionCapInfo[], _owner: string): Promise<IBasePositionInfo[]> {
117
117
  throw new Error(`Method not implemented in ${this.constructor.name}.`)
118
118
  }
119
119
 
@@ -1390,4 +1390,67 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
1390
1390
 
1391
1391
  return tx
1392
1392
  }
1393
+
1394
+ // V2 Lootbox Methods for new contract
1395
+ public adminIssueLootboxV2(
1396
+ coin: string,
1397
+ tiers: number[],
1398
+ beneficiaries: string[],
1399
+ amounts: number[],
1400
+ titles: string[],
1401
+ descriptions: string[],
1402
+ tx: Transaction,
1403
+ ): void {
1404
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`
1405
+ if (coin !== 'zlp') {
1406
+ module = this.consts.coins[coin].module
1407
+ }
1408
+
1409
+ for (const [i, beneficiary] of beneficiaries.entries()) {
1410
+ const moveCallArgs = {
1411
+ target: `${this.consts.zoLootboxV2.package}::lootbox::admin_issue_lootbox`,
1412
+ typeArguments: [module],
1413
+ arguments: [
1414
+ tx.object(this.consts.zoLootboxV2.adminCap),
1415
+ tx.object(this.consts.zoLootboxV2.lootboxTreasury),
1416
+ tx.pure.u8(tiers[i]),
1417
+ tx.pure.address(beneficiary),
1418
+ tx.pure.u64(amounts[i]),
1419
+ tx.pure.bool(amounts[i] > 0),
1420
+ tx.pure.string(titles[i]),
1421
+ tx.pure.string(descriptions[i]),
1422
+ tx.object(`${this.consts.zoLootboxV2.lootboxSettings}`),
1423
+ ],
1424
+ }
1425
+
1426
+ tx.moveCall(moveCallArgs)
1427
+ }
1428
+ }
1429
+
1430
+ public openLootboxV2(
1431
+ coin: string,
1432
+ lootbox: string,
1433
+ ): Transaction {
1434
+ const tx = new Transaction()
1435
+
1436
+ let module = `${this.consts.zoCore.package}::zlp::ZLP`
1437
+ let metadata = this.consts.zoCore.zlpMetadata
1438
+ if (coin !== 'zlp') {
1439
+ module = this.consts.coins[coin].module
1440
+ metadata = this.consts.coins[coin].metadata
1441
+ }
1442
+
1443
+ tx.moveCall({
1444
+ target: `${this.consts.zoLootboxV2.package}::lootbox::open_lootbox`,
1445
+ typeArguments: [module],
1446
+ arguments: [
1447
+ tx.object(this.consts.zoLootboxV2.lootboxTreasury),
1448
+ tx.object(lootbox),
1449
+ tx.object(metadata),
1450
+ tx.object(this.consts.zoLootboxV2.lootboxSettings),
1451
+ ],
1452
+ })
1453
+
1454
+ return tx
1455
+ }
1393
1456
  }
@@ -238,9 +238,9 @@ export interface IBaseDataAPI {
238
238
 
239
239
  // User data methods
240
240
  getPositionCapInfoList: (owner: string) => Promise<IBasePositionCapInfo[]>
241
- getPositionInfoList: (positionCapInfoList: IBasePositionCapInfo[], owner: string, batchSize?: number) => Promise<IBasePositionInfo[]>
241
+ getPositionInfoList: (positionCapInfoList: IBasePositionCapInfo[], owner: string) => Promise<IBasePositionInfo[]>
242
242
  getOrderCapInfoList: (owner: string) => Promise<IBaseOrderCapInfo[]>
243
- getOrderInfoList: (orderCapInfoList: IBaseOrderCapInfo[], owner: string, batchSize?: number) => Promise<IBaseOrderInfo[]>
243
+ getOrderInfoList: (orderCapInfoList: IBaseOrderCapInfo[], owner: string) => Promise<IBaseOrderInfo[]>
244
244
  getHistory: (trader: string, page: number, limit: number, orderType?: string, symbol?: string) => Promise<IBaseHistoryResponse>
245
245
 
246
246
  // Staking methods
@@ -118,4 +118,19 @@ export interface IZLPAPI extends IBaseAPI {
118
118
  coin: string,
119
119
  lootbox: string
120
120
  ) => Transaction
121
+
122
+ adminIssueLootboxV2: (
123
+ coin: string,
124
+ tiers: number[],
125
+ beneficiaries: string[],
126
+ amounts: number[],
127
+ titles: string[],
128
+ descriptions: string[],
129
+ tx: Transaction,
130
+ ) => void
131
+
132
+ openLootboxV2: (
133
+ coin: string,
134
+ lootbox: string
135
+ ) => Transaction
121
136
  }