zo-sdk 0.0.43 → 0.0.45
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/dist/data.cjs +125 -134
- package/dist/data.cjs.map +1 -1
- package/dist/data.d.cts +14 -19
- package/dist/data.d.cts.map +1 -1
- package/dist/data.d.mts +14 -19
- package/dist/data.d.mts.map +1 -1
- package/dist/data.mjs +125 -134
- package/dist/data.mjs.map +1 -1
- package/package.json +8 -8
- package/src/data.ts +155 -175
package/src/data.ts
CHANGED
|
@@ -156,21 +156,21 @@ export interface IPositionConfig {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
export interface IHistory {
|
|
159
|
-
owner: string
|
|
160
|
-
txid: string
|
|
161
|
-
id: string
|
|
162
|
-
created: number
|
|
163
|
-
eventName: string
|
|
164
|
-
indexToken: string
|
|
165
|
-
direction: string
|
|
166
|
-
collateralAmount: number
|
|
167
|
-
collateralPrice: number
|
|
168
|
-
indexPrice: number
|
|
169
|
-
pnl: number
|
|
170
|
-
positionId: string
|
|
171
|
-
volume: number
|
|
172
|
-
fee: number
|
|
173
|
-
network: string
|
|
159
|
+
owner: string
|
|
160
|
+
txid: string
|
|
161
|
+
id: string
|
|
162
|
+
created: number
|
|
163
|
+
eventName: string
|
|
164
|
+
indexToken: string
|
|
165
|
+
direction: string
|
|
166
|
+
collateralAmount: number
|
|
167
|
+
collateralPrice: number
|
|
168
|
+
indexPrice: number
|
|
169
|
+
pnl: number
|
|
170
|
+
positionId: string
|
|
171
|
+
volume: number
|
|
172
|
+
fee: number
|
|
173
|
+
network: string
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
export interface IStaked {
|
|
@@ -199,16 +199,6 @@ export interface IStakePool {
|
|
|
199
199
|
lockDuration: number
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
export interface IMarketValidationResult {
|
|
203
|
-
handledVaults: Record<string, {
|
|
204
|
-
weight: number;
|
|
205
|
-
value: number;
|
|
206
|
-
}>;
|
|
207
|
-
totalWeight: number;
|
|
208
|
-
totalVaultsValue: number;
|
|
209
|
-
marketValue: number;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
202
|
export class DataAPI extends OracleAPI {
|
|
213
203
|
provider: SuiClient
|
|
214
204
|
apiEndpoint: string
|
|
@@ -315,30 +305,6 @@ export class DataAPI extends OracleAPI {
|
|
|
315
305
|
}
|
|
316
306
|
}
|
|
317
307
|
|
|
318
|
-
/**
|
|
319
|
-
* Validates the market valuation by calling the validate_market_valuation Move function
|
|
320
|
-
* @param tx Transaction object
|
|
321
|
-
* @returns An object containing handled vaults, total weight, total vaults value, and market value
|
|
322
|
-
*/
|
|
323
|
-
validateMarketValuation = (tx: Transaction) => {
|
|
324
|
-
// First, create the valuations using existing methods
|
|
325
|
-
const vaultsValuation = this.valuateVaults(tx);
|
|
326
|
-
const symbolsValuation = this.valuateSymbols(tx);
|
|
327
|
-
|
|
328
|
-
// Call the validate_market_valuation Move function
|
|
329
|
-
const result = tx.moveCall({
|
|
330
|
-
target: `${this.consts.zoCore.upgradedPackage}::market::validate_market_valuation`,
|
|
331
|
-
typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`],
|
|
332
|
-
arguments: [
|
|
333
|
-
tx.object(this.consts.zoCore.market),
|
|
334
|
-
vaultsValuation,
|
|
335
|
-
symbolsValuation,
|
|
336
|
-
],
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
return result;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
308
|
#parseMarketInfo(raw: any): IMarketInfo {
|
|
343
309
|
const content = raw.data.content.fields
|
|
344
310
|
|
|
@@ -715,147 +681,106 @@ export class DataAPI extends OracleAPI {
|
|
|
715
681
|
}
|
|
716
682
|
|
|
717
683
|
public async getPositionCapInfoList(owner: string): Promise<IPositionCapInfo[]> {
|
|
718
|
-
const
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
owner,
|
|
725
|
-
filter: {
|
|
726
|
-
MoveModule: {
|
|
727
|
-
package: this.consts.zoCore.package,
|
|
728
|
-
module: 'market',
|
|
729
|
-
},
|
|
730
|
-
},
|
|
731
|
-
options: {
|
|
732
|
-
showType: true,
|
|
684
|
+
const positionCaps = await this.provider.getOwnedObjects({
|
|
685
|
+
owner,
|
|
686
|
+
filter: {
|
|
687
|
+
MoveModule: {
|
|
688
|
+
package: this.consts.zoCore.package,
|
|
689
|
+
module: 'market',
|
|
733
690
|
},
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
691
|
+
},
|
|
692
|
+
options: {
|
|
693
|
+
showType: true,
|
|
694
|
+
},
|
|
695
|
+
})
|
|
696
|
+
const positionCapInfoList = []
|
|
697
|
+
for (const positionCap of positionCaps.data) {
|
|
698
|
+
if (positionCap.data?.type?.includes('PositionCap')) {
|
|
699
|
+
positionCapInfoList.push({
|
|
700
|
+
positionCapId: positionCap.data.objectId,
|
|
701
|
+
symbol0: positionCap.data.type.split('<')[1].split(',')[0].trim(),
|
|
702
|
+
symbol1: positionCap.data.type.split('<')[1].split(',')[1].split(',')[0].trim(),
|
|
703
|
+
long: positionCap.data.type.includes('LONG'),
|
|
704
|
+
})
|
|
746
705
|
}
|
|
747
|
-
|
|
748
|
-
// If we don't want to fetch all pages or there are no more pages, break the loop
|
|
749
|
-
hasNextPage = positionCaps.hasNextPage
|
|
750
|
-
cursor = positionCaps.nextCursor
|
|
751
706
|
}
|
|
752
|
-
|
|
753
707
|
return positionCapInfoList
|
|
754
708
|
}
|
|
755
709
|
|
|
756
|
-
public async getPositionInfoList(positionCapInfoList: IPositionCapInfo[], owner: string
|
|
710
|
+
public async getPositionInfoList(positionCapInfoList: IPositionCapInfo[], owner: string) {
|
|
757
711
|
const positionInfoList: IPositionInfo[] = []
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
name: {
|
|
768
|
-
type: `${this.consts.zoCore.package}::market::PositionName<${positionCapInfo.symbol0}, ${positionCapInfo.symbol1}, ${this.consts.zoCore.package}::market::${positionCapInfo.long ? 'LONG' : 'SHORT'}>`,
|
|
769
|
-
value: {
|
|
770
|
-
owner,
|
|
771
|
-
id: positionCapInfo.positionCapId,
|
|
772
|
-
},
|
|
712
|
+
await Promise.all(positionCapInfoList.map(async (positionCapInfo) => {
|
|
713
|
+
try {
|
|
714
|
+
const positionRaw = await this.provider.getDynamicFieldObject({
|
|
715
|
+
parentId: this.consts.zoCore.positionsParent,
|
|
716
|
+
name: {
|
|
717
|
+
type: `${this.consts.zoCore.package}::market::PositionName<${positionCapInfo.symbol0}, ${positionCapInfo.symbol1}, ${this.consts.zoCore.package}::market::${positionCapInfo.long ? 'LONG' : 'SHORT'}>`,
|
|
718
|
+
value: {
|
|
719
|
+
owner,
|
|
720
|
+
id: positionCapInfo.positionCapId,
|
|
773
721
|
},
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
|
|
722
|
+
},
|
|
723
|
+
})
|
|
724
|
+
positionInfoList.push(await this.#parsePositionInfo(positionRaw, positionCapInfo.positionCapId))
|
|
725
|
+
}
|
|
726
|
+
catch (error) {
|
|
727
|
+
// Position might have been deleted after force settlement
|
|
728
|
+
console.warn(`Failed to parse position info for position cap ID ${positionCapInfo.positionCapId}: ${error}`)
|
|
729
|
+
// Continue with next position without adding this one to the list
|
|
730
|
+
}
|
|
731
|
+
}))
|
|
783
732
|
|
|
784
733
|
return positionInfoList.sort((a, b) => a.openTimestamp > b.openTimestamp ? 1 : -1)
|
|
785
734
|
}
|
|
786
735
|
|
|
787
|
-
public async getOrderCapInfoList(owner: string)
|
|
788
|
-
const
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
owner,
|
|
795
|
-
filter: {
|
|
796
|
-
MoveModule: {
|
|
797
|
-
package: this.consts.zoCore.package,
|
|
798
|
-
module: 'market',
|
|
799
|
-
},
|
|
800
|
-
},
|
|
801
|
-
options: {
|
|
802
|
-
showType: true,
|
|
803
|
-
showContent: true,
|
|
736
|
+
public async getOrderCapInfoList(owner: string) {
|
|
737
|
+
const orderCaps = await this.provider.getOwnedObjects({
|
|
738
|
+
owner,
|
|
739
|
+
filter: {
|
|
740
|
+
MoveModule: {
|
|
741
|
+
package: this.consts.zoCore.package,
|
|
742
|
+
module: 'market',
|
|
804
743
|
},
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
744
|
+
},
|
|
745
|
+
options: {
|
|
746
|
+
showType: true,
|
|
747
|
+
showContent: true,
|
|
748
|
+
},
|
|
749
|
+
})
|
|
750
|
+
const orderCapInfoList = []
|
|
751
|
+
for (const orderCap of orderCaps.data) {
|
|
752
|
+
if (orderCap.data?.type?.includes('OrderCap')) {
|
|
753
|
+
orderCapInfoList.push({
|
|
754
|
+
orderCapId: orderCap.data.objectId,
|
|
755
|
+
symbol0: orderCap.data.type.split('<')[1].split(',')[0].trim(),
|
|
756
|
+
symbol1: orderCap.data.type.split('<')[1].split(',')[1].split(',')[0].trim(),
|
|
757
|
+
long: orderCap.data.type.includes('LONG'),
|
|
758
|
+
positionId: (orderCap.data.content as any)?.fields?.position_id,
|
|
759
|
+
})
|
|
818
760
|
}
|
|
819
|
-
|
|
820
|
-
hasNextPage = orderCaps.hasNextPage;
|
|
821
|
-
cursor = orderCaps.nextCursor;
|
|
822
761
|
}
|
|
823
|
-
|
|
824
762
|
return orderCapInfoList
|
|
825
763
|
}
|
|
826
764
|
|
|
827
|
-
public async getOrderInfoList(orderCapInfoList: IOrderCapInfo[], owner: string
|
|
765
|
+
public async getOrderInfoList(orderCapInfoList: IOrderCapInfo[], owner: string) {
|
|
828
766
|
const orderInfoList: IOrderInfo[] = []
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
type: `${this.consts.zoCore.package}::market::OrderName<${orderCapInfo.symbol0}, ${orderCapInfo.symbol1}, ${this.consts.zoCore.package}::market::${orderCapInfo.long ? 'LONG' : 'SHORT'}, ${orderCapInfo.symbol0}>`,
|
|
841
|
-
value: {
|
|
842
|
-
owner,
|
|
843
|
-
id: orderCapInfo.orderCapId,
|
|
844
|
-
position_id: {
|
|
845
|
-
vec: orderCapInfo.positionId ? [orderCapInfo.positionId] : [],
|
|
846
|
-
},
|
|
847
|
-
},
|
|
767
|
+
await Promise.all(orderCapInfoList.map(async (orderCapInfo) => {
|
|
768
|
+
const orderRaw = await this.provider.getDynamicFieldObject({
|
|
769
|
+
parentId: this.consts.zoCore.ordersParent,
|
|
770
|
+
name: {
|
|
771
|
+
// We have enforced collateral coin type to match with fee coin type so we can use symbol0 in the first slot and the last slot of the OrderName
|
|
772
|
+
type: `${this.consts.zoCore.package}::market::OrderName<${orderCapInfo.symbol0}, ${orderCapInfo.symbol1}, ${this.consts.zoCore.package}::market::${orderCapInfo.long ? 'LONG' : 'SHORT'}, ${orderCapInfo.symbol0}>`,
|
|
773
|
+
value: {
|
|
774
|
+
owner,
|
|
775
|
+
id: orderCapInfo.orderCapId,
|
|
776
|
+
position_id: {
|
|
777
|
+
vec: orderCapInfo.positionId ? [orderCapInfo.positionId] : [],
|
|
848
778
|
},
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
// Continue with next order without adding this one to the list
|
|
855
|
-
}
|
|
856
|
-
}))
|
|
857
|
-
}
|
|
858
|
-
|
|
779
|
+
},
|
|
780
|
+
},
|
|
781
|
+
})
|
|
782
|
+
orderInfoList.push(this.#parseOrderInfo(orderRaw, orderCapInfo.orderCapId))
|
|
783
|
+
}))
|
|
859
784
|
return orderInfoList.sort((a, b) => a.createdAt > b.createdAt ? 1 : -1)
|
|
860
785
|
}
|
|
861
786
|
|
|
@@ -928,16 +853,71 @@ export class DataAPI extends OracleAPI {
|
|
|
928
853
|
return this.#calcReservingFeeRate(vaultInfo.reservingFeeModel, utilization, SECONDS_PER_EIGHT_HOUR)
|
|
929
854
|
}
|
|
930
855
|
|
|
931
|
-
getProxiedHistories = async (trader: string): Promise<IHistory[]> => {
|
|
932
|
-
const
|
|
856
|
+
getProxiedHistories = async (trader: string, page?: number, limit?: number): Promise<IHistory[]> => {
|
|
857
|
+
const params = new URLSearchParams({ trader })
|
|
858
|
+
if (page !== undefined) {
|
|
859
|
+
params.append('page', page.toString())
|
|
860
|
+
}
|
|
861
|
+
if (limit !== undefined) {
|
|
862
|
+
params.append('limit', limit.toString())
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
const url = `${this.apiEndpoint}/traderEvents?${params}`
|
|
933
866
|
const res = await fetch(url, {
|
|
934
867
|
method: 'GET',
|
|
935
868
|
headers: {
|
|
936
869
|
'Content-Type': 'application/json',
|
|
937
870
|
},
|
|
938
|
-
})
|
|
939
|
-
const
|
|
940
|
-
|
|
871
|
+
})
|
|
872
|
+
const response = await res.json() as any
|
|
873
|
+
|
|
874
|
+
// Handle both old format (array) and new format (object with data)
|
|
875
|
+
if (Array.isArray(response)) {
|
|
876
|
+
return response
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
return response.data?.histories || []
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
getProxiedHistoriesWithPagination = async (
|
|
883
|
+
trader: string,
|
|
884
|
+
page = 1,
|
|
885
|
+
limit = 20,
|
|
886
|
+
orderType?: string,
|
|
887
|
+
symbol?: string
|
|
888
|
+
) => {
|
|
889
|
+
const params = new URLSearchParams({
|
|
890
|
+
trader,
|
|
891
|
+
page: page.toString(),
|
|
892
|
+
limit: limit.toString(),
|
|
893
|
+
})
|
|
894
|
+
|
|
895
|
+
// Add filter parameters if provided
|
|
896
|
+
if (orderType && orderType !== 'all') {
|
|
897
|
+
params.append('orderType', orderType)
|
|
898
|
+
}
|
|
899
|
+
if (symbol && symbol !== 'all') {
|
|
900
|
+
params.append('symbol', symbol)
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
const url = `${this.apiEndpoint}/traderEvents?${params}`
|
|
904
|
+
const res = await fetch(url, {
|
|
905
|
+
method: 'GET',
|
|
906
|
+
headers: {
|
|
907
|
+
'Content-Type': 'application/json',
|
|
908
|
+
},
|
|
909
|
+
})
|
|
910
|
+
const response = await res.json() as any
|
|
911
|
+
|
|
912
|
+
return {
|
|
913
|
+
histories: response.data?.histories || [],
|
|
914
|
+
pagination: response.data?.pagination || {
|
|
915
|
+
total: 0,
|
|
916
|
+
page: 1,
|
|
917
|
+
limit: 20,
|
|
918
|
+
pages: 0,
|
|
919
|
+
},
|
|
920
|
+
}
|
|
941
921
|
}
|
|
942
922
|
|
|
943
923
|
getStaked = async (owner: string): Promise<IStaked> => {
|