zo-sdk 0.0.46 → 0.0.48

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/data.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable class-methods-use-this */
2
2
 
3
- import type { SuiClient } from '@mysten/sui/client'
3
+ import type { DynamicFieldInfo, SuiClient } from '@mysten/sui/client'
4
4
  import type { Transaction } from '@mysten/sui/transactions'
5
5
  import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils'
6
6
 
@@ -784,6 +784,50 @@ export class DataAPI extends OracleAPI {
784
784
  return positionInfoList.sort((a, b) => a.openTimestamp > b.openTimestamp ? 1 : -1)
785
785
  }
786
786
 
787
+ // find all open positions by positionsParent
788
+ public async getOpenPositions() {
789
+ let positionDynamicFields: DynamicFieldInfo[] = [];
790
+ let _continue = true;
791
+ let cursor = undefined;
792
+ while (_continue) {
793
+ // data here will be a list of dynamic fields containing name and value
794
+ const { data, nextCursor, hasNextPage } =
795
+ await this.provider.getDynamicFields({
796
+ parentId: this.consts.zoCore.positionsParent,
797
+ cursor,
798
+ });
799
+
800
+ positionDynamicFields = positionDynamicFields.concat(data);
801
+ _continue = hasNextPage;
802
+ cursor = nextCursor;
803
+ }
804
+
805
+ // then we query by dynamic field names and order by time
806
+ const positionInfoList: IPositionInfo[] = [];
807
+ await Promise.all(
808
+ positionDynamicFields.map(async positionDynamicField => {
809
+ const positionRaw = await this.provider.getDynamicFieldObject({
810
+ parentId: this.consts.zoCore.positionsParent,
811
+ name: positionDynamicField.name,
812
+ });
813
+
814
+ if (positionRaw?.data?.content) {
815
+ const positionInfo = await this.#parsePositionInfo(
816
+ positionRaw,
817
+ positionDynamicField.objectId,
818
+ );
819
+ if (positionInfo) {
820
+ positionInfoList.push(positionInfo);
821
+ }
822
+ }
823
+ }),
824
+ );
825
+
826
+ return positionInfoList
827
+ .filter(positionInfo => !positionInfo.closed)
828
+ .sort((a, b) => (a.openTimestamp > b.openTimestamp ? 1 : -1));
829
+ }
830
+
787
831
  public async getOrderCapInfoList(owner: string): Promise<IOrderCapInfo[]> {
788
832
  const orderCapInfoList: IOrderCapInfo[] = [];
789
833
  let cursor: string | undefined | null = undefined;