@zofai/zo-sdk 0.2.30 → 0.2.31
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/abstract/BaseAPI.cjs +3 -0
- package/dist/abstract/BaseAPI.cjs.map +1 -1
- package/dist/abstract/BaseAPI.d.cts +3 -2
- package/dist/abstract/BaseAPI.d.cts.map +1 -1
- package/dist/abstract/BaseAPI.d.mts +3 -2
- package/dist/abstract/BaseAPI.d.mts.map +1 -1
- package/dist/abstract/BaseAPI.mjs +3 -0
- package/dist/abstract/BaseAPI.mjs.map +1 -1
- package/dist/abstract/BaseDataAPI.cjs +48 -2
- package/dist/abstract/BaseDataAPI.cjs.map +1 -1
- package/dist/abstract/BaseDataAPI.d.cts +15 -2
- package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
- package/dist/abstract/BaseDataAPI.d.mts +15 -2
- package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
- package/dist/abstract/BaseDataAPI.mjs +48 -2
- package/dist/abstract/BaseDataAPI.mjs.map +1 -1
- package/dist/data.cjs +19 -7
- package/dist/data.cjs.map +1 -1
- package/dist/data.d.cts.map +1 -1
- package/dist/data.d.mts.map +1 -1
- package/dist/data.mjs +19 -7
- package/dist/data.mjs.map +1 -1
- package/dist/implementations/SLPDataAPI.cjs +26 -8
- package/dist/implementations/SLPDataAPI.cjs.map +1 -1
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/SLPDataAPI.mjs +26 -8
- package/dist/implementations/SLPDataAPI.mjs.map +1 -1
- package/dist/implementations/USDZDataAPI.cjs +26 -8
- package/dist/implementations/USDZDataAPI.cjs.map +1 -1
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
- package/dist/implementations/USDZDataAPI.mjs +26 -8
- package/dist/implementations/USDZDataAPI.mjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.cjs +19 -7
- package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.mjs +19 -7
- package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.cjs +26 -8
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPDataAPI.mjs +26 -8
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +14 -1
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +14 -1
- package/dist/interfaces/base.d.mts.map +1 -1
- package/dist/traderPositions.cjs +130 -0
- package/dist/traderPositions.cjs.map +1 -0
- package/dist/traderPositions.d.cts +72 -0
- package/dist/traderPositions.d.cts.map +1 -0
- package/dist/traderPositions.d.mts +72 -0
- package/dist/traderPositions.d.mts.map +1 -0
- package/dist/traderPositions.mjs +124 -0
- package/dist/traderPositions.mjs.map +1 -0
- package/package.json +1 -1
- package/src/abstract/BaseAPI.ts +6 -2
- package/src/abstract/BaseDataAPI.ts +67 -3
- package/src/data.ts +19 -7
- package/src/implementations/SLPDataAPI.ts +34 -16
- package/src/implementations/USDZDataAPI.ts +32 -14
- package/src/implementations/ZBTCVCDataAPI.ts +23 -11
- package/src/implementations/ZLPDataAPI.ts +37 -14
- package/src/index.ts +1 -0
- package/src/interfaces/base.ts +15 -1
- package/src/traderPositions.ts +218 -0
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/* eslint-disable class-methods-use-this -- base class helpers used by subclasses */
|
|
6
6
|
|
|
7
|
-
import type { SuiClient } from '../suiClient'
|
|
8
7
|
import type { Transaction } from '@mysten/sui/transactions'
|
|
9
8
|
|
|
10
9
|
import type { LPToken, Network } from '../consts'
|
|
10
|
+
import { LPToken as LPTokenEnum } from '../consts'
|
|
11
11
|
import type {
|
|
12
12
|
IBaseDataAPI,
|
|
13
13
|
IBaseHistoryResponse,
|
|
@@ -23,8 +23,15 @@ import type {
|
|
|
23
23
|
IBaseStakePool,
|
|
24
24
|
IBaseSymbolInfo,
|
|
25
25
|
IBaseVaultInfo,
|
|
26
|
+
IGetTraderOpenPositionsOptions,
|
|
26
27
|
} from '../interfaces'
|
|
27
28
|
import { OracleAPI } from '../oracle'
|
|
29
|
+
import type { SuiClient } from '../suiClient'
|
|
30
|
+
import {
|
|
31
|
+
fetchAllTraderPositions,
|
|
32
|
+
traderPositionToCapInfo,
|
|
33
|
+
} from '../traderPositions'
|
|
34
|
+
import { joinSymbol } from '../utils'
|
|
28
35
|
|
|
29
36
|
export abstract class BaseDataAPI extends OracleAPI implements IBaseDataAPI {
|
|
30
37
|
public readonly provider: SuiClient
|
|
@@ -38,6 +45,8 @@ export abstract class BaseDataAPI extends OracleAPI implements IBaseDataAPI {
|
|
|
38
45
|
protected marketInfoCache: IBaseMarketInfo | null = null
|
|
39
46
|
protected positionConfigCache: Record<string, IBasePositionConfig> = {}
|
|
40
47
|
protected rebaseFeeModelCache: IBaseRebaseFeeModel | null = null
|
|
48
|
+
/** Per index-token OI funding state; `null` means fetched and missing on-chain. */
|
|
49
|
+
protected oiFundingStateCache: Record<string, unknown | null> = {}
|
|
41
50
|
protected lastUpdate = 0
|
|
42
51
|
protected readonly CACHE_DURATION = 1000 * 60 * 3 // 3 minutes
|
|
43
52
|
|
|
@@ -75,6 +84,7 @@ export abstract class BaseDataAPI extends OracleAPI implements IBaseDataAPI {
|
|
|
75
84
|
this.marketInfoCache = null
|
|
76
85
|
this.positionConfigCache = {}
|
|
77
86
|
this.rebaseFeeModelCache = null
|
|
87
|
+
this.oiFundingStateCache = {}
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
/**
|
|
@@ -93,7 +103,7 @@ export abstract class BaseDataAPI extends OracleAPI implements IBaseDataAPI {
|
|
|
93
103
|
*/
|
|
94
104
|
protected async getCachedSymbolInfo(tokenId: string, long: boolean): Promise<IBaseSymbolInfo> {
|
|
95
105
|
this.validateCache()
|
|
96
|
-
const key =
|
|
106
|
+
const key = joinSymbol(long ? 'long' : 'short', tokenId)
|
|
97
107
|
if (!this.symbolInfoCache[key]) {
|
|
98
108
|
this.symbolInfoCache[key] = await this.getSymbolInfo(tokenId, long)
|
|
99
109
|
}
|
|
@@ -116,7 +126,7 @@ export abstract class BaseDataAPI extends OracleAPI implements IBaseDataAPI {
|
|
|
116
126
|
*/
|
|
117
127
|
protected async getCachedPositionConfig(indexToken: string, long: boolean): Promise<IBasePositionConfig> {
|
|
118
128
|
this.validateCache()
|
|
119
|
-
const key =
|
|
129
|
+
const key = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
120
130
|
if (!this.positionConfigCache[key]) {
|
|
121
131
|
this.positionConfigCache[key] = await this.getPositionConfig(indexToken, long)
|
|
122
132
|
}
|
|
@@ -134,6 +144,60 @@ export abstract class BaseDataAPI extends OracleAPI implements IBaseDataAPI {
|
|
|
134
144
|
return this.rebaseFeeModelCache
|
|
135
145
|
}
|
|
136
146
|
|
|
147
|
+
/** Package id used to filter `/trader-positions` rows for this LP. */
|
|
148
|
+
protected getMarketPackageId(): string {
|
|
149
|
+
return this.lpToken === LPTokenEnum.SLP
|
|
150
|
+
? this.consts.sudoCore.package
|
|
151
|
+
: this.consts.zoCore.package
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Load OPEN position caps from zo API `/trader-positions` for this LP package.
|
|
156
|
+
*/
|
|
157
|
+
protected async fetchTraderOpenPositionCapsFromApi(
|
|
158
|
+
owner: string,
|
|
159
|
+
options?: IGetTraderOpenPositionsOptions,
|
|
160
|
+
): Promise<IBasePositionCapInfo[]> {
|
|
161
|
+
const packageId = this.getMarketPackageId().toLowerCase()
|
|
162
|
+
const records = await fetchAllTraderPositions(
|
|
163
|
+
this.apiEndpoint,
|
|
164
|
+
{
|
|
165
|
+
owner,
|
|
166
|
+
status: 'OPEN',
|
|
167
|
+
indexToken: options?.indexToken,
|
|
168
|
+
collateralToken: options?.collateralToken,
|
|
169
|
+
},
|
|
170
|
+
options?.limit,
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
const caps: IBasePositionCapInfo[] = []
|
|
174
|
+
for (const record of records) {
|
|
175
|
+
if (record.address?.trim().toLowerCase() !== packageId) {
|
|
176
|
+
continue
|
|
177
|
+
}
|
|
178
|
+
const cap = traderPositionToCapInfo(record, this.consts)
|
|
179
|
+
if (cap) {
|
|
180
|
+
caps.push(cap)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return caps
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Fetch OPEN positions from zo API, then hydrate live position details via RPC
|
|
188
|
+
* (same accrual path as getPositionInfoList).
|
|
189
|
+
*/
|
|
190
|
+
public async getTraderOpenPositionInfoList(
|
|
191
|
+
owner: string,
|
|
192
|
+
options?: IGetTraderOpenPositionsOptions,
|
|
193
|
+
): Promise<IBasePositionInfo[]> {
|
|
194
|
+
const caps = await this.fetchTraderOpenPositionCapsFromApi(owner, options)
|
|
195
|
+
if (caps.length === 0) {
|
|
196
|
+
return []
|
|
197
|
+
}
|
|
198
|
+
return this.getPositionInfoList(caps, owner, options?.batchSize)
|
|
199
|
+
}
|
|
200
|
+
|
|
137
201
|
// Abstract methods that must be implemented by concrete classes
|
|
138
202
|
public abstract valuateVaults(tx: Transaction): any
|
|
139
203
|
public abstract valuateSymbols(tx: Transaction): any
|
package/src/data.ts
CHANGED
|
@@ -483,8 +483,10 @@ export class DataAPI extends OracleAPI {
|
|
|
483
483
|
openTimestamp: parseValue(positionFields.open_timestamp),
|
|
484
484
|
}
|
|
485
485
|
|
|
486
|
-
|
|
487
|
-
positionInfo.
|
|
486
|
+
const vaultInfo = await this.getVaultInfo(positionInfo.collateralToken)
|
|
487
|
+
positionInfo.reservingFeeAmount = this.#calculatePositionReserveFee(positionInfo, vaultInfo, vaultInfo.reservingFeeModel, Date.now() / 1000)
|
|
488
|
+
const symbolInfo = await this.getSymbolInfo(positionInfo.indexToken, positionInfo.long)
|
|
489
|
+
positionInfo.fundingFeeValue = this.#calculatePositionFundingFee(positionInfo, symbolInfo, symbolInfo.fundingFeeModel, (await this.getOraclePrice(positionInfo.indexToken)).getPriceUnchecked().getPriceAsNumberUnchecked(), (await this.getMarketInfo()).lpSupplyWithDecimals, Date.now() / 1000)
|
|
488
490
|
|
|
489
491
|
return positionInfo
|
|
490
492
|
}
|
|
@@ -664,7 +666,9 @@ export class DataAPI extends OracleAPI {
|
|
|
664
666
|
showContent: true,
|
|
665
667
|
},
|
|
666
668
|
})
|
|
667
|
-
|
|
669
|
+
const info = this.#parseMarketInfo(rawData)
|
|
670
|
+
this.marketInfoCache = info
|
|
671
|
+
return info
|
|
668
672
|
}
|
|
669
673
|
|
|
670
674
|
public async getVaultInfo(vaultToken: string) {
|
|
@@ -680,7 +684,9 @@ export class DataAPI extends OracleAPI {
|
|
|
680
684
|
value: { dummy_field: false },
|
|
681
685
|
},
|
|
682
686
|
})
|
|
683
|
-
|
|
687
|
+
const info = await this.#parseVaultInfo(rawData)
|
|
688
|
+
this.vaultInfoCache[vaultToken] = info
|
|
689
|
+
return info
|
|
684
690
|
}
|
|
685
691
|
|
|
686
692
|
public async getSymbolInfo(indexToken: string, long: boolean) {
|
|
@@ -696,7 +702,9 @@ export class DataAPI extends OracleAPI {
|
|
|
696
702
|
value: { dummy_field: false },
|
|
697
703
|
},
|
|
698
704
|
})
|
|
699
|
-
|
|
705
|
+
const info = await this.#parseSymbolInfo(rawData, long)
|
|
706
|
+
this.symbolInfoCache[symbol] = info
|
|
707
|
+
return info
|
|
700
708
|
}
|
|
701
709
|
|
|
702
710
|
public async getPositionConfig(indexToken: string, long: boolean) {
|
|
@@ -711,7 +719,9 @@ export class DataAPI extends OracleAPI {
|
|
|
711
719
|
showContent: true,
|
|
712
720
|
},
|
|
713
721
|
})
|
|
714
|
-
|
|
722
|
+
const info = this.#parsePositionConfig(rawData)
|
|
723
|
+
this.positionConfigCache[symbol] = info
|
|
724
|
+
return info
|
|
715
725
|
}
|
|
716
726
|
|
|
717
727
|
public async getPositionCapInfoList(owner: string): Promise<IPositionCapInfo[]> {
|
|
@@ -952,7 +962,9 @@ export class DataAPI extends OracleAPI {
|
|
|
952
962
|
showContent: true,
|
|
953
963
|
},
|
|
954
964
|
})
|
|
955
|
-
|
|
965
|
+
const info = this.#parseRebaseFeeModel(rawData)
|
|
966
|
+
this.rebaseFeeModelCache = info
|
|
967
|
+
return info
|
|
956
968
|
}
|
|
957
969
|
|
|
958
970
|
fundingFeeRate = async (indexToken: string, long: boolean) => {
|
|
@@ -39,13 +39,13 @@ import type {
|
|
|
39
39
|
ISwapFeeBreakdown,
|
|
40
40
|
} from '../interfaces'
|
|
41
41
|
import type { OracleInputs } from '../oraclePro'
|
|
42
|
-
import type { DynamicFieldInfo, SuiClient } from '../suiClient'
|
|
43
42
|
import {
|
|
44
43
|
buildPythProPriceFeedMap,
|
|
45
44
|
resolveTokenUsdPriceFromPythPro,
|
|
46
45
|
valuateSymbolsV3,
|
|
47
46
|
valuateVaultsV3,
|
|
48
47
|
} from '../oraclePro'
|
|
48
|
+
import type { DynamicFieldInfo, SuiClient } from '../suiClient'
|
|
49
49
|
import { joinSymbol, parseSymbolKey, parseValue, suiSymbolToSymbol } from '../utils'
|
|
50
50
|
|
|
51
51
|
export interface GetCumulativeAprResponse {
|
|
@@ -117,7 +117,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
117
117
|
public async getRebaseFeeModel(): Promise<ISLPRebaseFeeModel> {
|
|
118
118
|
this.validateCache()
|
|
119
119
|
if (this.rebaseFeeModelCache) {
|
|
120
|
-
return this.rebaseFeeModelCache
|
|
120
|
+
return this.rebaseFeeModelCache as ISLPRebaseFeeModel
|
|
121
121
|
}
|
|
122
122
|
const rawData = await this.provider.getObject({
|
|
123
123
|
id: this.consts.sudoCore.rebaseFeeModel,
|
|
@@ -131,7 +131,9 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
131
131
|
this.consts.sudoCore.rebaseFeeModel,
|
|
132
132
|
this.consts.sudoCore.upgradedPackage,
|
|
133
133
|
)
|
|
134
|
-
|
|
134
|
+
const info = { ...model, exponent }
|
|
135
|
+
this.rebaseFeeModelCache = info
|
|
136
|
+
return info
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
/**
|
|
@@ -448,7 +450,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
448
450
|
public async getMarketInfo(): Promise<ISLPMarketInfo> {
|
|
449
451
|
this.validateCache()
|
|
450
452
|
if (this.marketInfoCache) {
|
|
451
|
-
return this.marketInfoCache
|
|
453
|
+
return this.marketInfoCache as ISLPMarketInfo
|
|
452
454
|
}
|
|
453
455
|
|
|
454
456
|
const rawData = await this.provider.getObject({
|
|
@@ -458,10 +460,12 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
458
460
|
},
|
|
459
461
|
})
|
|
460
462
|
const apr = await this.getCumulativeApr()
|
|
461
|
-
|
|
463
|
+
const info = {
|
|
462
464
|
...SLPDataAPI.parseMarketInfo(rawData),
|
|
463
465
|
apr,
|
|
464
466
|
}
|
|
467
|
+
this.marketInfoCache = info
|
|
468
|
+
return info
|
|
465
469
|
}
|
|
466
470
|
|
|
467
471
|
/**
|
|
@@ -470,7 +474,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
470
474
|
public async getVaultInfo(vaultToken: string): Promise<ISLPVaultInfo> {
|
|
471
475
|
this.validateCache()
|
|
472
476
|
if (this.vaultInfoCache[vaultToken]) {
|
|
473
|
-
return this.vaultInfoCache[vaultToken]
|
|
477
|
+
return this.vaultInfoCache[vaultToken] as ISLPVaultInfo
|
|
474
478
|
}
|
|
475
479
|
|
|
476
480
|
const rawData = await this.provider.getDynamicFieldObject({
|
|
@@ -480,7 +484,9 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
480
484
|
value: { dummy_field: false },
|
|
481
485
|
},
|
|
482
486
|
})
|
|
483
|
-
|
|
487
|
+
const info = await this.parseVaultInfo(rawData)
|
|
488
|
+
this.vaultInfoCache[vaultToken] = info
|
|
489
|
+
return info
|
|
484
490
|
}
|
|
485
491
|
|
|
486
492
|
/**
|
|
@@ -490,7 +496,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
490
496
|
this.validateCache()
|
|
491
497
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
492
498
|
if (this.symbolInfoCache[symbol]) {
|
|
493
|
-
return this.symbolInfoCache[symbol]
|
|
499
|
+
return this.symbolInfoCache[symbol] as ISLPSymbolInfo
|
|
494
500
|
}
|
|
495
501
|
|
|
496
502
|
const rawData = await this.provider.getDynamicFieldObject({
|
|
@@ -503,7 +509,9 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
503
509
|
},
|
|
504
510
|
})
|
|
505
511
|
|
|
506
|
-
|
|
512
|
+
const info = await this.parseSymbolInfo(rawData, long)
|
|
513
|
+
this.symbolInfoCache[symbol] = info
|
|
514
|
+
return info
|
|
507
515
|
}
|
|
508
516
|
|
|
509
517
|
/**
|
|
@@ -556,6 +564,9 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
556
564
|
*/
|
|
557
565
|
public async getSymbolOiFundingState(indexToken: string): Promise<ISLPOiFundingState | null> {
|
|
558
566
|
this.validateCache()
|
|
567
|
+
if (Object.prototype.hasOwnProperty.call(this.oiFundingStateCache, indexToken)) {
|
|
568
|
+
return this.oiFundingStateCache[indexToken] as ISLPOiFundingState | null
|
|
569
|
+
}
|
|
559
570
|
try {
|
|
560
571
|
const rawData = await this.provider.getDynamicFieldObject({
|
|
561
572
|
parentId: this.consts.sudoCore.market,
|
|
@@ -564,11 +575,14 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
564
575
|
value: { dummy_field: false },
|
|
565
576
|
},
|
|
566
577
|
})
|
|
567
|
-
|
|
578
|
+
const info = SLPDataAPI.parseOiFundingState(rawData)
|
|
579
|
+
this.oiFundingStateCache[indexToken] = info
|
|
580
|
+
return info
|
|
568
581
|
}
|
|
569
582
|
catch (e: any) {
|
|
570
583
|
// If the dynamic field doesn't exist, return null
|
|
571
584
|
console.error('Error Fetching SLP Symbol OI Funding State:', e)
|
|
585
|
+
this.oiFundingStateCache[indexToken] = null
|
|
572
586
|
return null
|
|
573
587
|
}
|
|
574
588
|
}
|
|
@@ -1075,7 +1089,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
1075
1089
|
this.validateCache()
|
|
1076
1090
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
1077
1091
|
if (this.positionConfigCache[symbol]) {
|
|
1078
|
-
return this.positionConfigCache[symbol]
|
|
1092
|
+
return this.positionConfigCache[symbol] as ISLPPositionConfig
|
|
1079
1093
|
}
|
|
1080
1094
|
|
|
1081
1095
|
const rawData = await this.provider.getObject({
|
|
@@ -1084,7 +1098,9 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
1084
1098
|
showContent: true,
|
|
1085
1099
|
},
|
|
1086
1100
|
})
|
|
1087
|
-
|
|
1101
|
+
const info = SLPDataAPI.parsePositionConfig(rawData)
|
|
1102
|
+
this.positionConfigCache[symbol] = info
|
|
1103
|
+
return info
|
|
1088
1104
|
}
|
|
1089
1105
|
|
|
1090
1106
|
public async getOpenPositions(batchSize = 50, symbol = 'sui'): Promise<ISLPPositionInfo[]> {
|
|
@@ -1925,21 +1941,23 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
|
|
|
1925
1941
|
|
|
1926
1942
|
if (!positionFields.closed) {
|
|
1927
1943
|
try {
|
|
1944
|
+
const vaultInfo = await this.getVaultInfo(positionInfo.collateralToken)
|
|
1928
1945
|
positionInfo.reservingFeeAmount = SLPDataAPI.calculatePositionReserveFee(
|
|
1929
1946
|
positionInfo,
|
|
1930
|
-
|
|
1931
|
-
|
|
1947
|
+
vaultInfo,
|
|
1948
|
+
vaultInfo.reservingFeeModel,
|
|
1932
1949
|
Date.now() / 1000,
|
|
1933
1950
|
)
|
|
1934
1951
|
|
|
1935
1952
|
// OI context for funding: fetch state and paired side size when enabled
|
|
1936
1953
|
const oiState = await this.getSymbolOiFundingState(positionInfo.indexToken)
|
|
1937
1954
|
const pairedSymbol = await this.getSymbolInfo(positionInfo.indexToken, !positionInfo.long)
|
|
1955
|
+
const symbolInfo = await this.getSymbolInfo(positionInfo.indexToken, positionInfo.long)
|
|
1938
1956
|
|
|
1939
1957
|
positionInfo.fundingFeeValue = SLPDataAPI.calculatePositionFundingFee(
|
|
1940
1958
|
positionInfo,
|
|
1941
|
-
|
|
1942
|
-
|
|
1959
|
+
symbolInfo,
|
|
1960
|
+
symbolInfo.fundingFeeModel,
|
|
1943
1961
|
(await this.getOraclePrice(positionInfo.indexToken)).getPriceUnchecked().getPriceAsNumberUnchecked(),
|
|
1944
1962
|
(await this.getMarketInfo()).lpSupplyWithDecimals,
|
|
1945
1963
|
Date.now() / 1000,
|
|
@@ -308,7 +308,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
308
308
|
public async getMarketInfo(): Promise<IUSDZMarketInfo> {
|
|
309
309
|
this.validateCache()
|
|
310
310
|
if (this.marketInfoCache) {
|
|
311
|
-
return this.marketInfoCache
|
|
311
|
+
return this.marketInfoCache as IUSDZMarketInfo
|
|
312
312
|
}
|
|
313
313
|
const rawData = await this.provider.getObject({
|
|
314
314
|
id: this.consts.zoCore.market,
|
|
@@ -316,7 +316,9 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
316
316
|
showContent: true,
|
|
317
317
|
},
|
|
318
318
|
})
|
|
319
|
-
|
|
319
|
+
const info = USDZDataAPI.parseMarketInfo(rawData)
|
|
320
|
+
this.marketInfoCache = info
|
|
321
|
+
return info
|
|
320
322
|
}
|
|
321
323
|
|
|
322
324
|
/**
|
|
@@ -325,7 +327,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
325
327
|
public async getVaultInfo(vaultToken: string): Promise<IUSDZVaultInfo> {
|
|
326
328
|
this.validateCache()
|
|
327
329
|
if (this.vaultInfoCache[vaultToken]) {
|
|
328
|
-
return this.vaultInfoCache[vaultToken]
|
|
330
|
+
return this.vaultInfoCache[vaultToken] as IUSDZVaultInfo
|
|
329
331
|
}
|
|
330
332
|
|
|
331
333
|
const rawData = await this.provider.getDynamicFieldObject({
|
|
@@ -335,7 +337,9 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
335
337
|
value: { dummy_field: false },
|
|
336
338
|
},
|
|
337
339
|
})
|
|
338
|
-
|
|
340
|
+
const info = await this.parseVaultInfo(rawData)
|
|
341
|
+
this.vaultInfoCache[vaultToken] = info
|
|
342
|
+
return info
|
|
339
343
|
}
|
|
340
344
|
|
|
341
345
|
/**
|
|
@@ -345,7 +349,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
345
349
|
this.validateCache()
|
|
346
350
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
347
351
|
if (this.symbolInfoCache[symbol]) {
|
|
348
|
-
return this.symbolInfoCache[symbol]
|
|
352
|
+
return this.symbolInfoCache[symbol] as IUSDZSymbolInfo
|
|
349
353
|
}
|
|
350
354
|
const rawData = await this.provider.getDynamicFieldObject({
|
|
351
355
|
parentId: this.consts.zoCore.symbolsParent,
|
|
@@ -354,14 +358,16 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
354
358
|
value: { dummy_field: false },
|
|
355
359
|
},
|
|
356
360
|
})
|
|
357
|
-
|
|
361
|
+
const info = await this.parseSymbolInfo(rawData, long)
|
|
362
|
+
this.symbolInfoCache[symbol] = info
|
|
363
|
+
return info
|
|
358
364
|
}
|
|
359
365
|
|
|
360
366
|
public async getPositionConfig(indexToken: string, long: boolean): Promise<IUSDZPositionConfig> {
|
|
361
367
|
this.validateCache()
|
|
362
368
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
363
369
|
if (this.positionConfigCache[symbol]) {
|
|
364
|
-
return this.positionConfigCache[symbol]
|
|
370
|
+
return this.positionConfigCache[symbol] as IUSDZPositionConfig
|
|
365
371
|
}
|
|
366
372
|
const rawData = await this.provider.getObject({
|
|
367
373
|
id: this.consts.zoCore.symbols[symbol].positionConfig,
|
|
@@ -369,7 +375,9 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
369
375
|
showContent: true,
|
|
370
376
|
},
|
|
371
377
|
})
|
|
372
|
-
|
|
378
|
+
const info = USDZDataAPI.parsePositionConfig(rawData)
|
|
379
|
+
this.positionConfigCache[symbol] = info
|
|
380
|
+
return info
|
|
373
381
|
}
|
|
374
382
|
|
|
375
383
|
/**
|
|
@@ -399,6 +407,9 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
399
407
|
*/
|
|
400
408
|
public async getSymbolOiFundingState(indexToken: string): Promise<IUSDZOiFundingState | null> {
|
|
401
409
|
this.validateCache()
|
|
410
|
+
if (Object.prototype.hasOwnProperty.call(this.oiFundingStateCache, indexToken)) {
|
|
411
|
+
return this.oiFundingStateCache[indexToken] as IUSDZOiFundingState | null
|
|
412
|
+
}
|
|
402
413
|
try {
|
|
403
414
|
const rawData = await this.provider.getDynamicFieldObject({
|
|
404
415
|
parentId: this.consts.zoCore.market,
|
|
@@ -407,10 +418,13 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
407
418
|
value: { dummy_field: false },
|
|
408
419
|
},
|
|
409
420
|
})
|
|
410
|
-
|
|
421
|
+
const info = USDZDataAPI.parseOiFundingState(rawData)
|
|
422
|
+
this.oiFundingStateCache[indexToken] = info
|
|
423
|
+
return info
|
|
411
424
|
}
|
|
412
425
|
catch (e: any) {
|
|
413
426
|
console.error('Error Fetching USDZ Symbol OI Funding State:', e)
|
|
427
|
+
this.oiFundingStateCache[indexToken] = null
|
|
414
428
|
return null
|
|
415
429
|
}
|
|
416
430
|
}
|
|
@@ -816,7 +830,9 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
816
830
|
showContent: true,
|
|
817
831
|
},
|
|
818
832
|
})
|
|
819
|
-
|
|
833
|
+
const info = USDZDataAPI.parseRebaseFeeModel(rawData)
|
|
834
|
+
this.rebaseFeeModelCache = info
|
|
835
|
+
return info
|
|
820
836
|
}
|
|
821
837
|
|
|
822
838
|
public async fundingFeeRate(indexToken: string, long: boolean): Promise<number> {
|
|
@@ -1205,20 +1221,22 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
1205
1221
|
openTimestamp: parseValue(positionFields.open_timestamp),
|
|
1206
1222
|
}
|
|
1207
1223
|
|
|
1224
|
+
const vaultInfo = await this.getVaultInfo(positionInfo.collateralToken)
|
|
1208
1225
|
positionInfo.reservingFeeAmount = USDZDataAPI.calculatePositionReserveFee(
|
|
1209
1226
|
positionInfo,
|
|
1210
|
-
|
|
1211
|
-
|
|
1227
|
+
vaultInfo,
|
|
1228
|
+
vaultInfo.reservingFeeModel,
|
|
1212
1229
|
Date.now() / 1000,
|
|
1213
1230
|
)
|
|
1214
1231
|
|
|
1215
1232
|
// OI context for funding: fetch state and paired side size when enabled
|
|
1216
1233
|
const oiState = await this.getSymbolOiFundingState(positionInfo.indexToken)
|
|
1217
1234
|
const pairedSymbol = await this.getSymbolInfo(positionInfo.indexToken, !positionInfo.long)
|
|
1235
|
+
const symbolInfo = await this.getSymbolInfo(positionInfo.indexToken, positionInfo.long)
|
|
1218
1236
|
positionInfo.fundingFeeValue = USDZDataAPI.calculatePositionFundingFee(
|
|
1219
1237
|
positionInfo,
|
|
1220
|
-
|
|
1221
|
-
|
|
1238
|
+
symbolInfo,
|
|
1239
|
+
symbolInfo.fundingFeeModel,
|
|
1222
1240
|
(await this.getOraclePrice(positionInfo.indexToken)).getPriceUnchecked().getPriceAsNumberUnchecked(),
|
|
1223
1241
|
(await this.getMarketInfo()).lpSupplyWithDecimals,
|
|
1224
1242
|
Date.now() / 1000,
|
|
@@ -230,7 +230,7 @@ export class ZBTCVCDataAPI extends BaseDataAPI implements IZBTCVCDataAPI {
|
|
|
230
230
|
public async getMarketInfo(): Promise<IZBTCVCMarketInfo> {
|
|
231
231
|
this.validateCache()
|
|
232
232
|
if (this.marketInfoCache) {
|
|
233
|
-
return this.marketInfoCache
|
|
233
|
+
return this.marketInfoCache as IZBTCVCMarketInfo
|
|
234
234
|
}
|
|
235
235
|
const rawData = await this.provider.getObject({
|
|
236
236
|
id: this.consts.zoCore.market,
|
|
@@ -238,7 +238,9 @@ export class ZBTCVCDataAPI extends BaseDataAPI implements IZBTCVCDataAPI {
|
|
|
238
238
|
showContent: true,
|
|
239
239
|
},
|
|
240
240
|
})
|
|
241
|
-
|
|
241
|
+
const info = ZBTCVCDataAPI.parseMarketInfo(rawData)
|
|
242
|
+
this.marketInfoCache = info
|
|
243
|
+
return info
|
|
242
244
|
}
|
|
243
245
|
|
|
244
246
|
/**
|
|
@@ -247,7 +249,7 @@ export class ZBTCVCDataAPI extends BaseDataAPI implements IZBTCVCDataAPI {
|
|
|
247
249
|
public async getVaultInfo(vaultToken: string): Promise<IZBTCVCVaultInfo> {
|
|
248
250
|
this.validateCache()
|
|
249
251
|
if (this.vaultInfoCache[vaultToken]) {
|
|
250
|
-
return this.vaultInfoCache[vaultToken]
|
|
252
|
+
return this.vaultInfoCache[vaultToken] as IZBTCVCVaultInfo
|
|
251
253
|
}
|
|
252
254
|
|
|
253
255
|
const rawData = await this.provider.getDynamicFieldObject({
|
|
@@ -257,7 +259,9 @@ export class ZBTCVCDataAPI extends BaseDataAPI implements IZBTCVCDataAPI {
|
|
|
257
259
|
value: { dummy_field: false },
|
|
258
260
|
},
|
|
259
261
|
})
|
|
260
|
-
|
|
262
|
+
const info = await this.parseVaultInfo(rawData)
|
|
263
|
+
this.vaultInfoCache[vaultToken] = info
|
|
264
|
+
return info
|
|
261
265
|
}
|
|
262
266
|
|
|
263
267
|
/**
|
|
@@ -267,7 +271,7 @@ export class ZBTCVCDataAPI extends BaseDataAPI implements IZBTCVCDataAPI {
|
|
|
267
271
|
this.validateCache()
|
|
268
272
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
269
273
|
if (this.symbolInfoCache[symbol]) {
|
|
270
|
-
return this.symbolInfoCache[symbol]
|
|
274
|
+
return this.symbolInfoCache[symbol] as IZBTCVCSymbolInfo
|
|
271
275
|
}
|
|
272
276
|
const rawData = await this.provider.getDynamicFieldObject({
|
|
273
277
|
parentId: this.consts.zoCore.symbolsParent,
|
|
@@ -276,14 +280,16 @@ export class ZBTCVCDataAPI extends BaseDataAPI implements IZBTCVCDataAPI {
|
|
|
276
280
|
value: { dummy_field: false },
|
|
277
281
|
},
|
|
278
282
|
})
|
|
279
|
-
|
|
283
|
+
const info = await this.parseSymbolInfo(rawData, long)
|
|
284
|
+
this.symbolInfoCache[symbol] = info
|
|
285
|
+
return info
|
|
280
286
|
}
|
|
281
287
|
|
|
282
288
|
public async getPositionConfig(indexToken: string, long: boolean): Promise<IZBTCVCPositionConfig> {
|
|
283
289
|
this.validateCache()
|
|
284
290
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
285
291
|
if (this.positionConfigCache[symbol]) {
|
|
286
|
-
return this.positionConfigCache[symbol]
|
|
292
|
+
return this.positionConfigCache[symbol] as IZBTCVCPositionConfig
|
|
287
293
|
}
|
|
288
294
|
const rawData = await this.provider.getObject({
|
|
289
295
|
id: this.consts.zoCore.symbols[symbol].positionConfig,
|
|
@@ -291,7 +297,9 @@ export class ZBTCVCDataAPI extends BaseDataAPI implements IZBTCVCDataAPI {
|
|
|
291
297
|
showContent: true,
|
|
292
298
|
},
|
|
293
299
|
})
|
|
294
|
-
|
|
300
|
+
const info = ZBTCVCDataAPI.parsePositionConfig(rawData)
|
|
301
|
+
this.positionConfigCache[symbol] = info
|
|
302
|
+
return info
|
|
295
303
|
}
|
|
296
304
|
|
|
297
305
|
/**
|
|
@@ -536,7 +544,9 @@ export class ZBTCVCDataAPI extends BaseDataAPI implements IZBTCVCDataAPI {
|
|
|
536
544
|
showContent: true,
|
|
537
545
|
},
|
|
538
546
|
})
|
|
539
|
-
|
|
547
|
+
const info = ZBTCVCDataAPI.parseRebaseFeeModel(rawData)
|
|
548
|
+
this.rebaseFeeModelCache = info
|
|
549
|
+
return info
|
|
540
550
|
}
|
|
541
551
|
|
|
542
552
|
public async fundingFeeRate(indexToken: string, long: boolean): Promise<number> {
|
|
@@ -837,8 +847,10 @@ export class ZBTCVCDataAPI extends BaseDataAPI implements IZBTCVCDataAPI {
|
|
|
837
847
|
openTimestamp: parseValue(positionFields.open_timestamp),
|
|
838
848
|
}
|
|
839
849
|
|
|
840
|
-
|
|
841
|
-
positionInfo.
|
|
850
|
+
const vaultInfo = await this.getVaultInfo(positionInfo.collateralToken)
|
|
851
|
+
positionInfo.reservingFeeAmount = ZBTCVCDataAPI.calculatePositionReserveFee(positionInfo, vaultInfo, vaultInfo.reservingFeeModel, Date.now() / 1000)
|
|
852
|
+
const symbolInfo = await this.getSymbolInfo(positionInfo.indexToken, positionInfo.long)
|
|
853
|
+
positionInfo.fundingFeeValue = ZBTCVCDataAPI.calculatePositionFundingFee(positionInfo, symbolInfo, symbolInfo.fundingFeeModel, (await this.getOraclePrice(positionInfo.indexToken)).getPriceUnchecked().getPriceAsNumberUnchecked(), (await this.getMarketInfo()).lpSupplyWithDecimals, Date.now() / 1000)
|
|
842
854
|
|
|
843
855
|
return positionInfo
|
|
844
856
|
}
|