@zofai/zo-sdk 0.1.92
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/.claude/settings.local.json +9 -0
- package/.gitattributes +4 -0
- package/.prettierrc.js +9 -0
- package/README.md +28 -0
- package/dist/abstract/BaseAPI.cjs +206 -0
- package/dist/abstract/BaseAPI.cjs.map +1 -0
- package/dist/abstract/BaseAPI.d.cts +172 -0
- package/dist/abstract/BaseAPI.d.cts.map +1 -0
- package/dist/abstract/BaseAPI.d.mts +172 -0
- package/dist/abstract/BaseAPI.d.mts.map +1 -0
- package/dist/abstract/BaseAPI.mjs +202 -0
- package/dist/abstract/BaseAPI.mjs.map +1 -0
- package/dist/abstract/BaseDataAPI.cjs +140 -0
- package/dist/abstract/BaseDataAPI.cjs.map +1 -0
- package/dist/abstract/BaseDataAPI.d.cts +89 -0
- package/dist/abstract/BaseDataAPI.d.cts.map +1 -0
- package/dist/abstract/BaseDataAPI.d.mts +89 -0
- package/dist/abstract/BaseDataAPI.d.mts.map +1 -0
- package/dist/abstract/BaseDataAPI.mjs +136 -0
- package/dist/abstract/BaseDataAPI.mjs.map +1 -0
- package/dist/abstract/index.cjs +12 -0
- package/dist/abstract/index.cjs.map +1 -0
- package/dist/abstract/index.d.cts +7 -0
- package/dist/abstract/index.d.cts.map +1 -0
- package/dist/abstract/index.d.mts +7 -0
- package/dist/abstract/index.d.mts.map +1 -0
- package/dist/abstract/index.mjs +7 -0
- package/dist/abstract/index.mjs.map +1 -0
- package/dist/api.cjs +779 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +75 -0
- package/dist/api.d.cts.map +1 -0
- package/dist/api.d.mts +75 -0
- package/dist/api.d.mts.map +1 -0
- package/dist/api.mjs +775 -0
- package/dist/api.mjs.map +1 -0
- package/dist/bcs.cjs +42 -0
- package/dist/bcs.cjs.map +1 -0
- package/dist/bcs.d.cts +91 -0
- package/dist/bcs.d.cts.map +1 -0
- package/dist/bcs.d.mts +91 -0
- package/dist/bcs.d.mts.map +1 -0
- package/dist/bcs.mjs +39 -0
- package/dist/bcs.mjs.map +1 -0
- package/dist/consts/deployments-shared-mainnet.json +50 -0
- package/dist/consts/deployments-shared-testnet.json +45 -0
- package/dist/consts/deployments-slp-mainnet.json +600 -0
- package/dist/consts/deployments-slp-testnet.json +87 -0
- package/dist/consts/deployments-usdz-mainnet.json +494 -0
- package/dist/consts/deployments-usdz-testnet.json +98 -0
- package/dist/consts/deployments-zbtcvc-mainnet.json +180 -0
- package/dist/consts/deployments-zlp-mainnet.json +791 -0
- package/dist/consts/deployments-zlp-testnet.json +76 -0
- package/dist/consts/index.cjs +200 -0
- package/dist/consts/index.cjs.map +1 -0
- package/dist/consts/index.d.cts +157 -0
- package/dist/consts/index.d.cts.map +1 -0
- package/dist/consts/index.d.mts +157 -0
- package/dist/consts/index.d.mts.map +1 -0
- package/dist/consts/index.mjs +189 -0
- package/dist/consts/index.mjs.map +1 -0
- package/dist/consts/price_id_to_object_id.mainnet.json +56 -0
- package/dist/consts/price_id_to_object_id.testnet.json +17 -0
- package/dist/data.cjs +919 -0
- package/dist/data.cjs.map +1 -0
- package/dist/data.d.cts +235 -0
- package/dist/data.d.cts.map +1 -0
- package/dist/data.d.mts +235 -0
- package/dist/data.d.mts.map +1 -0
- package/dist/data.mjs +915 -0
- package/dist/data.mjs.map +1 -0
- package/dist/factory/SDKFactory.cjs +228 -0
- package/dist/factory/SDKFactory.cjs.map +1 -0
- package/dist/factory/SDKFactory.d.cts +84 -0
- package/dist/factory/SDKFactory.d.cts.map +1 -0
- package/dist/factory/SDKFactory.d.mts +84 -0
- package/dist/factory/SDKFactory.d.mts.map +1 -0
- package/dist/factory/SDKFactory.mjs +222 -0
- package/dist/factory/SDKFactory.mjs.map +1 -0
- package/dist/implementations/SLPAPI.cjs +1794 -0
- package/dist/implementations/SLPAPI.cjs.map +1 -0
- package/dist/implementations/SLPAPI.d.cts +183 -0
- package/dist/implementations/SLPAPI.d.cts.map +1 -0
- package/dist/implementations/SLPAPI.d.mts +183 -0
- package/dist/implementations/SLPAPI.d.mts.map +1 -0
- package/dist/implementations/SLPAPI.mjs +1790 -0
- package/dist/implementations/SLPAPI.mjs.map +1 -0
- package/dist/implementations/SLPDataAPI.cjs +1384 -0
- package/dist/implementations/SLPDataAPI.cjs.map +1 -0
- package/dist/implementations/SLPDataAPI.d.cts +158 -0
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -0
- package/dist/implementations/SLPDataAPI.d.mts +158 -0
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -0
- package/dist/implementations/SLPDataAPI.mjs +1380 -0
- package/dist/implementations/SLPDataAPI.mjs.map +1 -0
- package/dist/implementations/USDZAPI.cjs +1676 -0
- package/dist/implementations/USDZAPI.cjs.map +1 -0
- package/dist/implementations/USDZAPI.d.cts +180 -0
- package/dist/implementations/USDZAPI.d.cts.map +1 -0
- package/dist/implementations/USDZAPI.d.mts +180 -0
- package/dist/implementations/USDZAPI.d.mts.map +1 -0
- package/dist/implementations/USDZAPI.mjs +1672 -0
- package/dist/implementations/USDZAPI.mjs.map +1 -0
- package/dist/implementations/USDZDataAPI.cjs +1209 -0
- package/dist/implementations/USDZDataAPI.cjs.map +1 -0
- package/dist/implementations/USDZDataAPI.d.cts +191 -0
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -0
- package/dist/implementations/USDZDataAPI.d.mts +191 -0
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -0
- package/dist/implementations/USDZDataAPI.mjs +1205 -0
- package/dist/implementations/USDZDataAPI.mjs.map +1 -0
- package/dist/implementations/ZBTCVCAPI.cjs +906 -0
- package/dist/implementations/ZBTCVCAPI.cjs.map +1 -0
- package/dist/implementations/ZBTCVCAPI.d.cts +107 -0
- package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -0
- package/dist/implementations/ZBTCVCAPI.d.mts +107 -0
- package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -0
- package/dist/implementations/ZBTCVCAPI.mjs +902 -0
- package/dist/implementations/ZBTCVCAPI.mjs.map +1 -0
- package/dist/implementations/ZBTCVCDataAPI.cjs +829 -0
- package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -0
- package/dist/implementations/ZBTCVCDataAPI.d.cts +94 -0
- package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -0
- package/dist/implementations/ZBTCVCDataAPI.d.mts +94 -0
- package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -0
- package/dist/implementations/ZBTCVCDataAPI.mjs +825 -0
- package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -0
- package/dist/implementations/ZLPAPI.cjs +1948 -0
- package/dist/implementations/ZLPAPI.cjs.map +1 -0
- package/dist/implementations/ZLPAPI.d.cts +192 -0
- package/dist/implementations/ZLPAPI.d.cts.map +1 -0
- package/dist/implementations/ZLPAPI.d.mts +192 -0
- package/dist/implementations/ZLPAPI.d.mts.map +1 -0
- package/dist/implementations/ZLPAPI.mjs +1944 -0
- package/dist/implementations/ZLPAPI.mjs.map +1 -0
- package/dist/implementations/ZLPDataAPI.cjs +1267 -0
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -0
- package/dist/implementations/ZLPDataAPI.d.cts +193 -0
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -0
- package/dist/implementations/ZLPDataAPI.d.mts +193 -0
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -0
- package/dist/implementations/ZLPDataAPI.mjs +1263 -0
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -0
- package/dist/implementations/index.cjs +26 -0
- package/dist/implementations/index.cjs.map +1 -0
- package/dist/implementations/index.d.cts +13 -0
- package/dist/implementations/index.d.cts.map +1 -0
- package/dist/implementations/index.d.mts +13 -0
- package/dist/implementations/index.d.mts.map +1 -0
- package/dist/implementations/index.mjs +15 -0
- package/dist/implementations/index.mjs.map +1 -0
- package/dist/index.cjs +69 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +51 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +51 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +51 -0
- package/dist/index.mjs.map +1 -0
- package/dist/interfaces/base.cjs +7 -0
- package/dist/interfaces/base.cjs.map +1 -0
- package/dist/interfaces/base.d.cts +346 -0
- package/dist/interfaces/base.d.cts.map +1 -0
- package/dist/interfaces/base.d.mts +346 -0
- package/dist/interfaces/base.d.mts.map +1 -0
- package/dist/interfaces/base.mjs +6 -0
- package/dist/interfaces/base.mjs.map +1 -0
- package/dist/interfaces/index.cjs +31 -0
- package/dist/interfaces/index.cjs.map +1 -0
- package/dist/interfaces/index.d.cts +15 -0
- package/dist/interfaces/index.d.cts.map +1 -0
- package/dist/interfaces/index.d.mts +15 -0
- package/dist/interfaces/index.d.mts.map +1 -0
- package/dist/interfaces/index.mjs +15 -0
- package/dist/interfaces/index.mjs.map +1 -0
- package/dist/interfaces/slp.cjs +7 -0
- package/dist/interfaces/slp.cjs.map +1 -0
- package/dist/interfaces/slp.d.cts +179 -0
- package/dist/interfaces/slp.d.cts.map +1 -0
- package/dist/interfaces/slp.d.mts +179 -0
- package/dist/interfaces/slp.d.mts.map +1 -0
- package/dist/interfaces/slp.mjs +6 -0
- package/dist/interfaces/slp.mjs.map +1 -0
- package/dist/interfaces/usdz.cjs +7 -0
- package/dist/interfaces/usdz.cjs.map +1 -0
- package/dist/interfaces/usdz.d.cts +104 -0
- package/dist/interfaces/usdz.d.cts.map +1 -0
- package/dist/interfaces/usdz.d.mts +104 -0
- package/dist/interfaces/usdz.d.mts.map +1 -0
- package/dist/interfaces/usdz.mjs +6 -0
- package/dist/interfaces/usdz.mjs.map +1 -0
- package/dist/interfaces/zbtcvc.cjs +7 -0
- package/dist/interfaces/zbtcvc.cjs.map +1 -0
- package/dist/interfaces/zbtcvc.d.cts +64 -0
- package/dist/interfaces/zbtcvc.d.cts.map +1 -0
- package/dist/interfaces/zbtcvc.d.mts +64 -0
- package/dist/interfaces/zbtcvc.d.mts.map +1 -0
- package/dist/interfaces/zbtcvc.mjs +6 -0
- package/dist/interfaces/zbtcvc.mjs.map +1 -0
- package/dist/interfaces/zlp.cjs +7 -0
- package/dist/interfaces/zlp.cjs.map +1 -0
- package/dist/interfaces/zlp.d.cts +114 -0
- package/dist/interfaces/zlp.d.cts.map +1 -0
- package/dist/interfaces/zlp.d.mts +114 -0
- package/dist/interfaces/zlp.d.mts.map +1 -0
- package/dist/interfaces/zlp.mjs +6 -0
- package/dist/interfaces/zlp.mjs.map +1 -0
- package/dist/oracle.cjs +118 -0
- package/dist/oracle.cjs.map +1 -0
- package/dist/oracle.d.cts +25 -0
- package/dist/oracle.d.cts.map +1 -0
- package/dist/oracle.d.mts +25 -0
- package/dist/oracle.d.mts.map +1 -0
- package/dist/oracle.mjs +114 -0
- package/dist/oracle.mjs.map +1 -0
- package/dist/utils.cjs +129 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +44 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +44 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +115 -0
- package/dist/utils.mjs.map +1 -0
- package/docs/SUMMARY.md +10 -0
- package/docs/api-reference.md +32 -0
- package/docs/architecture.md +14 -0
- package/docs/common-operations.md +52 -0
- package/docs/error-handling.md +17 -0
- package/docs/getting-started.md +60 -0
- package/docs/introduction.md +15 -0
- package/docs/lp-specific-features.md +96 -0
- package/docs/type-safety.md +29 -0
- package/eslint.config.mjs +18 -0
- package/package.json +42 -0
- package/src/abstract/BaseAPI.ts +575 -0
- package/src/abstract/BaseDataAPI.ts +207 -0
- package/src/abstract/index.ts +7 -0
- package/src/api.ts +1100 -0
- package/src/bcs.ts +45 -0
- package/src/consts/deployments-shared-mainnet.json +50 -0
- package/src/consts/deployments-shared-testnet.json +45 -0
- package/src/consts/deployments-slp-mainnet.json +600 -0
- package/src/consts/deployments-slp-testnet.json +87 -0
- package/src/consts/deployments-usdz-mainnet.json +494 -0
- package/src/consts/deployments-usdz-testnet.json +98 -0
- package/src/consts/deployments-zbtcvc-mainnet.json +180 -0
- package/src/consts/deployments-zlp-mainnet.json +791 -0
- package/src/consts/deployments-zlp-testnet.json +76 -0
- package/src/consts/index.ts +345 -0
- package/src/consts/price_id_to_object_id.mainnet.json +56 -0
- package/src/consts/price_id_to_object_id.testnet.json +17 -0
- package/src/data.ts +1279 -0
- package/src/factory/SDKFactory.ts +340 -0
- package/src/implementations/SLPAPI.ts +2722 -0
- package/src/implementations/SLPDataAPI.ts +1839 -0
- package/src/implementations/USDZAPI.ts +2488 -0
- package/src/implementations/USDZDataAPI.ts +1548 -0
- package/src/implementations/ZBTCVCAPI.ts +1337 -0
- package/src/implementations/ZBTCVCDataAPI.ts +993 -0
- package/src/implementations/ZLPAPI.ts +2888 -0
- package/src/implementations/ZLPDataAPI.ts +1603 -0
- package/src/implementations/index.ts +16 -0
- package/src/index.ts +58 -0
- package/src/interfaces/base.ts +838 -0
- package/src/interfaces/index.ts +50 -0
- package/src/interfaces/slp.ts +268 -0
- package/src/interfaces/usdz.ts +181 -0
- package/src/interfaces/zbtcvc.ts +116 -0
- package/src/interfaces/zlp.ts +244 -0
- package/src/oracle.ts +153 -0
- package/src/utils.ts +168 -0
- package/tests/api.test.ts +219 -0
- package/tests/data.test.ts +156 -0
- package/tests/oracle.test.ts +33 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for all DataAPI implementations
|
|
3
|
+
* Provides common functionality and enforces interface contracts
|
|
4
|
+
*/
|
|
5
|
+
/* eslint-disable class-methods-use-this -- base class helpers used by subclasses */
|
|
6
|
+
|
|
7
|
+
import type { SuiClient } from '@mysten/sui/client'
|
|
8
|
+
import type { Transaction } from '@mysten/sui/transactions'
|
|
9
|
+
|
|
10
|
+
import type { LPToken, Network } from '../consts'
|
|
11
|
+
import type {
|
|
12
|
+
IBaseDataAPI,
|
|
13
|
+
IBaseHistoryResponse,
|
|
14
|
+
IBaseMarketInfo,
|
|
15
|
+
IBaseMarketValuationInfo,
|
|
16
|
+
IBaseOrderCapInfo,
|
|
17
|
+
IBaseOrderInfo,
|
|
18
|
+
IBasePositionCapInfo,
|
|
19
|
+
IBasePositionConfig,
|
|
20
|
+
IBasePositionInfo,
|
|
21
|
+
IBaseRebaseFeeModel,
|
|
22
|
+
IBaseStaked,
|
|
23
|
+
IBaseStakePool,
|
|
24
|
+
IBaseSymbolInfo,
|
|
25
|
+
IBaseVaultInfo,
|
|
26
|
+
} from '../interfaces'
|
|
27
|
+
import { OracleAPI } from '../oracle'
|
|
28
|
+
|
|
29
|
+
export abstract class BaseDataAPI extends OracleAPI implements IBaseDataAPI {
|
|
30
|
+
public readonly provider: SuiClient
|
|
31
|
+
public readonly apiEndpoint: string
|
|
32
|
+
public readonly connectionURL: string
|
|
33
|
+
public readonly lpToken: LPToken
|
|
34
|
+
|
|
35
|
+
// Cache management
|
|
36
|
+
protected vaultInfoCache: Record<string, IBaseVaultInfo> = {}
|
|
37
|
+
protected symbolInfoCache: Record<string, IBaseSymbolInfo> = {}
|
|
38
|
+
protected marketInfoCache: IBaseMarketInfo | null = null
|
|
39
|
+
protected positionConfigCache: Record<string, IBasePositionConfig> = {}
|
|
40
|
+
protected rebaseFeeModelCache: IBaseRebaseFeeModel | null = null
|
|
41
|
+
protected lastUpdate = 0
|
|
42
|
+
protected readonly CACHE_DURATION = 1000 * 60 * 3 // 3 minutes
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
network: Network,
|
|
46
|
+
provider: SuiClient,
|
|
47
|
+
apiEndpoint: string,
|
|
48
|
+
connectionURL: string,
|
|
49
|
+
lpToken: LPToken,
|
|
50
|
+
) {
|
|
51
|
+
super(network, provider, connectionURL, lpToken)
|
|
52
|
+
this.provider = provider
|
|
53
|
+
this.apiEndpoint = apiEndpoint
|
|
54
|
+
this.connectionURL = connectionURL
|
|
55
|
+
this.lpToken = lpToken
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Validates and clears cache if expired
|
|
60
|
+
*/
|
|
61
|
+
public validateCache(): void {
|
|
62
|
+
super.validateCache()
|
|
63
|
+
if (this.lastUpdate + this.CACHE_DURATION < Date.now()) {
|
|
64
|
+
this.clearCache()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Clears all cached data
|
|
70
|
+
*/
|
|
71
|
+
protected clearCache(): void {
|
|
72
|
+
this.lastUpdate = Date.now()
|
|
73
|
+
this.vaultInfoCache = {}
|
|
74
|
+
this.symbolInfoCache = {}
|
|
75
|
+
this.marketInfoCache = null
|
|
76
|
+
this.positionConfigCache = {}
|
|
77
|
+
this.rebaseFeeModelCache = null
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Gets cached vault info or fetches if not cached
|
|
82
|
+
*/
|
|
83
|
+
protected async getCachedVaultInfo(vault: string): Promise<IBaseVaultInfo> {
|
|
84
|
+
this.validateCache()
|
|
85
|
+
if (!this.vaultInfoCache[vault]) {
|
|
86
|
+
this.vaultInfoCache[vault] = await this.getVaultInfo(vault)
|
|
87
|
+
}
|
|
88
|
+
return this.vaultInfoCache[vault]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Gets cached symbol info or fetches if not cached
|
|
93
|
+
*/
|
|
94
|
+
protected async getCachedSymbolInfo(tokenId: string, long: boolean): Promise<IBaseSymbolInfo> {
|
|
95
|
+
this.validateCache()
|
|
96
|
+
const key = `${tokenId}_${long}`
|
|
97
|
+
if (!this.symbolInfoCache[key]) {
|
|
98
|
+
this.symbolInfoCache[key] = await this.getSymbolInfo(tokenId, long)
|
|
99
|
+
}
|
|
100
|
+
return this.symbolInfoCache[key]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Gets cached market info or fetches if not cached
|
|
105
|
+
*/
|
|
106
|
+
protected async getCachedMarketInfo(): Promise<IBaseMarketInfo> {
|
|
107
|
+
this.validateCache()
|
|
108
|
+
if (!this.marketInfoCache) {
|
|
109
|
+
this.marketInfoCache = await this.getMarketInfo()
|
|
110
|
+
}
|
|
111
|
+
return this.marketInfoCache
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Gets cached position config or fetches if not cached
|
|
116
|
+
*/
|
|
117
|
+
protected async getCachedPositionConfig(indexToken: string, long: boolean): Promise<IBasePositionConfig> {
|
|
118
|
+
this.validateCache()
|
|
119
|
+
const key = `${indexToken}_${long}`
|
|
120
|
+
if (!this.positionConfigCache[key]) {
|
|
121
|
+
this.positionConfigCache[key] = await this.getPositionConfig(indexToken, long)
|
|
122
|
+
}
|
|
123
|
+
return this.positionConfigCache[key]
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Gets cached rebase fee model or fetches if not cached
|
|
128
|
+
*/
|
|
129
|
+
protected async getCachedRebaseFeeModel(): Promise<IBaseRebaseFeeModel> {
|
|
130
|
+
this.validateCache()
|
|
131
|
+
if (!this.rebaseFeeModelCache) {
|
|
132
|
+
this.rebaseFeeModelCache = await this.getRebaseFeeModel()
|
|
133
|
+
}
|
|
134
|
+
return this.rebaseFeeModelCache
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Abstract methods that must be implemented by concrete classes
|
|
138
|
+
public abstract valuateVaults(tx: Transaction): any
|
|
139
|
+
public abstract valuateSymbols(tx: Transaction): any
|
|
140
|
+
public abstract valuate(tx: Transaction): { vaultsValuation: any, symbolsValuation: any }
|
|
141
|
+
public abstract valuateMarket(): Promise<IBaseMarketValuationInfo>
|
|
142
|
+
|
|
143
|
+
public abstract fundingFeeRate(indexToken: string, long: boolean, sender?: string): Promise<number>
|
|
144
|
+
public abstract rebaseFeeRate(collateralToken: string, increase: boolean, amount: number, sender?: string): Promise<number>
|
|
145
|
+
public abstract reservingFeeRate(collateralToken: string, amount: number, sender?: string): Promise<number>
|
|
146
|
+
|
|
147
|
+
public abstract getMarketInfo(): Promise<IBaseMarketInfo>
|
|
148
|
+
public abstract getVaultInfo(vault: string): Promise<IBaseVaultInfo>
|
|
149
|
+
public abstract getSymbolInfo(tokenId: string, long: boolean): Promise<IBaseSymbolInfo>
|
|
150
|
+
public abstract getPositionConfig(indexToken: string, long: boolean): Promise<IBasePositionConfig>
|
|
151
|
+
public abstract getRebaseFeeModel(): Promise<IBaseRebaseFeeModel>
|
|
152
|
+
public abstract getOpenPositions(batchSize: number, symbol: string): Promise<IBasePositionInfo[]>
|
|
153
|
+
|
|
154
|
+
public abstract getPositionCapInfoList(owner: string): Promise<IBasePositionCapInfo[]>
|
|
155
|
+
public abstract getPositionInfoList(positionCapInfoList: IBasePositionCapInfo[], owner: string, batchSize?: number): Promise<IBasePositionInfo[]>
|
|
156
|
+
public abstract getOrderCapInfoList(owner: string): Promise<IBaseOrderCapInfo[]>
|
|
157
|
+
public abstract getOrderInfoList(orderCapInfoList: IBaseOrderCapInfo[], owner: string, batchSize?: number): Promise<IBaseOrderInfo[]>
|
|
158
|
+
public abstract getHistory(trader: string, page: number, limit: number, orderType?: string, symbol?: string): Promise<IBaseHistoryResponse>
|
|
159
|
+
|
|
160
|
+
public abstract getStaked(owner: string): Promise<IBaseStaked>
|
|
161
|
+
public abstract getStakePool(): Promise<IBaseStakePool>
|
|
162
|
+
|
|
163
|
+
public abstract hasReferral(referree: string): Promise<boolean>
|
|
164
|
+
public abstract getReferralData(referree: string): Promise<any>
|
|
165
|
+
/**
|
|
166
|
+
* Helper method to handle API requests with error handling
|
|
167
|
+
*/
|
|
168
|
+
protected async makeAPIRequest<T>(endpoint: string): Promise<T> {
|
|
169
|
+
try {
|
|
170
|
+
const response = await fetch(`${this.apiEndpoint}${endpoint}`)
|
|
171
|
+
if (!response.ok) {
|
|
172
|
+
throw new Error(`HTTP error! status: ${response.status}`)
|
|
173
|
+
}
|
|
174
|
+
return await response.json()
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error(`Error fetching data from ${endpoint}:`, error)
|
|
178
|
+
throw error
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Helper method to parse numeric values from API responses
|
|
184
|
+
*/
|
|
185
|
+
protected parseNumericValue(value: any, decimals = 0): number {
|
|
186
|
+
if (typeof value === 'string') {
|
|
187
|
+
return Number(value) / 10 ** decimals
|
|
188
|
+
}
|
|
189
|
+
if (typeof value === 'bigint') {
|
|
190
|
+
return Number(value) / 10 ** decimals
|
|
191
|
+
}
|
|
192
|
+
return Number(value) || 0
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Helper method to parse bigint values from API responses
|
|
197
|
+
*/
|
|
198
|
+
protected parseBigIntValue(value: any): bigint {
|
|
199
|
+
if (typeof value === 'string') {
|
|
200
|
+
return BigInt(value)
|
|
201
|
+
}
|
|
202
|
+
if (typeof value === 'bigint') {
|
|
203
|
+
return value
|
|
204
|
+
}
|
|
205
|
+
return BigInt(Number(value) || 0)
|
|
206
|
+
}
|
|
207
|
+
}
|