@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,575 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for all API implementations
|
|
3
|
+
* Extends BaseDataAPI with trading functionality
|
|
4
|
+
*/
|
|
5
|
+
/* eslint-disable class-methods-use-this -- base class helpers used by subclasses */
|
|
6
|
+
|
|
7
|
+
import type { KioskClient, KioskOwnerCap } from '@mysten/kiosk'
|
|
8
|
+
import type { SuiClient } from '@mysten/sui/client'
|
|
9
|
+
import { Transaction } from '@mysten/sui/transactions'
|
|
10
|
+
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils'
|
|
11
|
+
|
|
12
|
+
import type { LPToken, Network } from '../consts'
|
|
13
|
+
import { ALLOW_TRADE_CAN_TRADE, ALLOW_TRADE_MUST_TRADE, ALLOW_TRADE_NO_TRADE } from '../consts'
|
|
14
|
+
import type {
|
|
15
|
+
IBaseDataAPI,
|
|
16
|
+
IBaseAPI,
|
|
17
|
+
IBaseCredential,
|
|
18
|
+
IBaseHistoryResponse,
|
|
19
|
+
IBaseMarketInfo,
|
|
20
|
+
IBaseMarketValuationInfo,
|
|
21
|
+
IBaseOrderCapInfo,
|
|
22
|
+
IBaseOrderInfo,
|
|
23
|
+
IBasePositionCapInfo,
|
|
24
|
+
IBasePositionConfig,
|
|
25
|
+
IBasePositionInfo,
|
|
26
|
+
IBaseRebaseFeeModel,
|
|
27
|
+
IBaseStaked,
|
|
28
|
+
IBaseStakePool,
|
|
29
|
+
IBaseSymbolInfo,
|
|
30
|
+
IBaseVaultInfo,
|
|
31
|
+
} from '../interfaces'
|
|
32
|
+
import { BaseDataAPI } from './BaseDataAPI'
|
|
33
|
+
|
|
34
|
+
export abstract class BaseAPI extends BaseDataAPI implements IBaseAPI {
|
|
35
|
+
/** Subclasses must provide their DataAPI instance; data methods delegate to it. */
|
|
36
|
+
protected abstract get dataAPI(): IBaseDataAPI
|
|
37
|
+
|
|
38
|
+
/* eslint-disable-next-line @typescript-eslint/no-useless-constructor -- passes params to super */
|
|
39
|
+
constructor(
|
|
40
|
+
network: Network,
|
|
41
|
+
provider: SuiClient,
|
|
42
|
+
apiEndpoint: string,
|
|
43
|
+
connectionURL: string,
|
|
44
|
+
lpToken: LPToken,
|
|
45
|
+
) {
|
|
46
|
+
super(network, provider, apiEndpoint, connectionURL, lpToken)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Delegate BaseDataAPI methods to this.dataAPI so subclasses don't need stub implementations
|
|
50
|
+
public valuateVaults(tx: Transaction) {
|
|
51
|
+
return this.dataAPI.valuateVaults(tx)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public valuateSymbols(tx: Transaction) {
|
|
55
|
+
return this.dataAPI.valuateSymbols(tx)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public valuate(tx: Transaction): { vaultsValuation: any, symbolsValuation: any } {
|
|
59
|
+
return this.dataAPI.valuate(tx)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public valuateMarket(): Promise<IBaseMarketValuationInfo> {
|
|
63
|
+
return this.dataAPI.valuateMarket()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public fundingFeeRate(indexToken: string, long: boolean, sender?: string): Promise<number> {
|
|
67
|
+
return this.dataAPI.fundingFeeRate(indexToken, long, sender)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public rebaseFeeRate(collateralToken: string, increase: boolean, amount: number, sender?: string): Promise<number> {
|
|
71
|
+
return this.dataAPI.rebaseFeeRate(collateralToken, increase, amount, sender)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public reservingFeeRate(collateralToken: string, amount: number, sender?: string): Promise<number> {
|
|
75
|
+
return this.dataAPI.reservingFeeRate(collateralToken, amount, sender)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public getMarketInfo(): Promise<IBaseMarketInfo> {
|
|
79
|
+
return this.dataAPI.getMarketInfo()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public getVaultInfo(vault: string): Promise<IBaseVaultInfo> {
|
|
83
|
+
return this.dataAPI.getVaultInfo(vault)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public getSymbolInfo(tokenId: string, long: boolean): Promise<IBaseSymbolInfo> {
|
|
87
|
+
return this.dataAPI.getSymbolInfo(tokenId, long)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public getPositionConfig(indexToken: string, long: boolean): Promise<IBasePositionConfig> {
|
|
91
|
+
return this.dataAPI.getPositionConfig(indexToken, long)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public getRebaseFeeModel(): Promise<IBaseRebaseFeeModel> {
|
|
95
|
+
return this.dataAPI.getRebaseFeeModel()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public getOpenPositions(batchSize: number, symbol: string): Promise<IBasePositionInfo[]> {
|
|
99
|
+
return this.dataAPI.getOpenPositions(batchSize, symbol)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public getPositionCapInfoList(owner: string): Promise<IBasePositionCapInfo[]> {
|
|
103
|
+
return this.dataAPI.getPositionCapInfoList(owner)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public getPositionInfoList(positionCapInfoList: IBasePositionCapInfo[], owner: string, batchSize?: number): Promise<IBasePositionInfo[]> {
|
|
107
|
+
return this.dataAPI.getPositionInfoList(positionCapInfoList, owner, batchSize)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public getOrderCapInfoList(owner: string): Promise<IBaseOrderCapInfo[]> {
|
|
111
|
+
return this.dataAPI.getOrderCapInfoList(owner)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public getOrderInfoList(orderCapInfoList: IBaseOrderCapInfo[], owner: string, batchSize?: number): Promise<IBaseOrderInfo[]> {
|
|
115
|
+
return this.dataAPI.getOrderInfoList(orderCapInfoList, owner, batchSize)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public getHistory(trader: string, page: number, limit: number, orderType?: string, symbol?: string): Promise<IBaseHistoryResponse> {
|
|
119
|
+
return this.dataAPI.getHistory(trader, page, limit, orderType, symbol)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public getStaked(owner: string): Promise<IBaseStaked> {
|
|
123
|
+
return this.dataAPI.getStaked(owner)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public getStakePool(): Promise<IBaseStakePool> {
|
|
127
|
+
return this.dataAPI.getStakePool()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public hasReferral(referree: string): Promise<boolean> {
|
|
131
|
+
return this.dataAPI.hasReferral(referree)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public getReferralData(referree: string): Promise<any> {
|
|
135
|
+
return this.dataAPI.getReferralData(referree)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Processes coin objects for transactions
|
|
140
|
+
* Handles SUI gas coin and merges multiple coin objects if needed
|
|
141
|
+
*/
|
|
142
|
+
protected processCoins(tx: Transaction, coin: string, coinObjects: string[], sponsoredTx = false) {
|
|
143
|
+
if (coin === 'sui' && !sponsoredTx) {
|
|
144
|
+
return tx.gas
|
|
145
|
+
}
|
|
146
|
+
if (coinObjects.length > 1) {
|
|
147
|
+
tx.mergeCoins(
|
|
148
|
+
tx.object(coinObjects[0]),
|
|
149
|
+
coinObjects.slice(1).map(coinObject => tx.object(coinObject)),
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
return tx.object(coinObjects[0])
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
protected processCoinSplitting(tx: Transaction, token: string, coinObjects: string[], amounts: any[], sponsoredTx?: boolean, suiCoinObject?: any) {
|
|
156
|
+
if (sponsoredTx) {
|
|
157
|
+
const sourceObject = token === 'sui'
|
|
158
|
+
? suiCoinObject
|
|
159
|
+
: this.processCoins(tx, token, coinObjects, true)
|
|
160
|
+
return tx.splitCoins(sourceObject, amounts)
|
|
161
|
+
}
|
|
162
|
+
const coinObject = this.processCoins(tx, token, coinObjects)
|
|
163
|
+
return tx.splitCoins(coinObject, amounts)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Processes slippage for price calculations
|
|
168
|
+
*/
|
|
169
|
+
protected processSlippage(indexPrice: number, long: boolean, slippage: number): bigint {
|
|
170
|
+
const raw = long ? indexPrice * (1 + slippage) : indexPrice * (1 - slippage)
|
|
171
|
+
return BigInt(Math.round(raw * 1e18))
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Processes slippage for price calculations
|
|
176
|
+
*/
|
|
177
|
+
protected processPriceThreshold(indexPrice: number, slippage: number): bigint {
|
|
178
|
+
const raw = indexPrice * slippage
|
|
179
|
+
return BigInt(Math.round(raw * 1e18))
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Determines trade allowance based on order type
|
|
184
|
+
*/
|
|
185
|
+
protected getTradeAllowance(isLimitOrder: boolean, isIocOrder: boolean): number {
|
|
186
|
+
if (isLimitOrder) {
|
|
187
|
+
return isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
188
|
+
}
|
|
189
|
+
return ALLOW_TRADE_MUST_TRADE
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Abstract methods for trading functionality
|
|
193
|
+
|
|
194
|
+
// LP operations
|
|
195
|
+
public abstract deposit(
|
|
196
|
+
coin: string,
|
|
197
|
+
coinObjects: string[],
|
|
198
|
+
amount: number,
|
|
199
|
+
minAmountOut?: number,
|
|
200
|
+
referralAddress?: string,
|
|
201
|
+
sender?: string,
|
|
202
|
+
sponsoredTx?: boolean,
|
|
203
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
204
|
+
): Promise<Transaction>
|
|
205
|
+
|
|
206
|
+
public abstract withdraw(
|
|
207
|
+
coin: string,
|
|
208
|
+
lpCoinObjects: string[],
|
|
209
|
+
amount: number,
|
|
210
|
+
minAmountOut?: number,
|
|
211
|
+
sponsoredTx?: boolean,
|
|
212
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
213
|
+
): Promise<Transaction>
|
|
214
|
+
|
|
215
|
+
public abstract swap(
|
|
216
|
+
fromToken: string,
|
|
217
|
+
toToken: string,
|
|
218
|
+
fromAmount: bigint,
|
|
219
|
+
fromCoinObjects: string[],
|
|
220
|
+
): Promise<Transaction>
|
|
221
|
+
|
|
222
|
+
// Staking operations
|
|
223
|
+
public abstract stake(
|
|
224
|
+
lpCoinObjects: string[],
|
|
225
|
+
amount: bigint,
|
|
226
|
+
pool: string,
|
|
227
|
+
tx?: Transaction
|
|
228
|
+
): Transaction
|
|
229
|
+
|
|
230
|
+
public abstract unstake(
|
|
231
|
+
credentials: IBaseCredential[],
|
|
232
|
+
amount: bigint,
|
|
233
|
+
pool: string,
|
|
234
|
+
tx?: Transaction
|
|
235
|
+
): Transaction
|
|
236
|
+
|
|
237
|
+
// Trading operations
|
|
238
|
+
public abstract openPosition(
|
|
239
|
+
collateralToken: string,
|
|
240
|
+
indexToken: string,
|
|
241
|
+
size: bigint,
|
|
242
|
+
collateralAmount: bigint,
|
|
243
|
+
coinObjects: string[],
|
|
244
|
+
long: boolean,
|
|
245
|
+
reserveAmount: bigint,
|
|
246
|
+
indexPrice: number,
|
|
247
|
+
collateralPrice: number,
|
|
248
|
+
isLimitOrder?: boolean,
|
|
249
|
+
isIocOrder?: boolean,
|
|
250
|
+
pricesSlippage?: number,
|
|
251
|
+
collateralSlippage?: number,
|
|
252
|
+
relayerFee?: bigint,
|
|
253
|
+
referralAddress?: string,
|
|
254
|
+
sender?: string,
|
|
255
|
+
sponsoredTx?: boolean,
|
|
256
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
257
|
+
): Promise<Transaction>
|
|
258
|
+
|
|
259
|
+
public abstract decreasePosition(
|
|
260
|
+
pcpId: string,
|
|
261
|
+
collateralToken: string,
|
|
262
|
+
indexToken: string,
|
|
263
|
+
amount: bigint,
|
|
264
|
+
long: boolean,
|
|
265
|
+
indexPrice: number,
|
|
266
|
+
collateralPrice: number,
|
|
267
|
+
isTriggerOrder?: boolean,
|
|
268
|
+
isTakeProfitOrder?: boolean,
|
|
269
|
+
isIocOrder?: boolean,
|
|
270
|
+
pricesSlippage?: number,
|
|
271
|
+
collateralSlippage?: number,
|
|
272
|
+
relayerFee?: bigint,
|
|
273
|
+
coinObjects?: string[],
|
|
274
|
+
sponsoredTx?: boolean,
|
|
275
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
276
|
+
): Promise<Transaction>
|
|
277
|
+
|
|
278
|
+
public abstract decreaseMultiPositions(
|
|
279
|
+
positions: Array<{
|
|
280
|
+
pcpId: string
|
|
281
|
+
collateralToken: string
|
|
282
|
+
indexToken: string
|
|
283
|
+
amount: bigint
|
|
284
|
+
long: boolean
|
|
285
|
+
indexPrice: number
|
|
286
|
+
collateralPrice: number
|
|
287
|
+
isTriggerOrder?: boolean
|
|
288
|
+
isTakeProfitOrder?: boolean
|
|
289
|
+
isIocOrder?: boolean
|
|
290
|
+
pricesSlippage?: number
|
|
291
|
+
collateralSlippage?: number
|
|
292
|
+
relayerFee?: bigint
|
|
293
|
+
coinObjects?: string[]
|
|
294
|
+
}>, tx?: Transaction
|
|
295
|
+
): Promise<Transaction>
|
|
296
|
+
|
|
297
|
+
public abstract pledgeInPosition(
|
|
298
|
+
pcpId: string,
|
|
299
|
+
collateralToken: string,
|
|
300
|
+
indexToken: string,
|
|
301
|
+
amount: number,
|
|
302
|
+
coinObjects: string[],
|
|
303
|
+
long: boolean,
|
|
304
|
+
sponsoredTx?: boolean,
|
|
305
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
306
|
+
): Promise<Transaction>
|
|
307
|
+
|
|
308
|
+
public abstract redeemFromPosition(
|
|
309
|
+
pcpId: string,
|
|
310
|
+
collateralToken: string,
|
|
311
|
+
indexToken: string,
|
|
312
|
+
amount: number,
|
|
313
|
+
long: boolean,
|
|
314
|
+
sponsoredTx?: boolean,
|
|
315
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
316
|
+
): Promise<Transaction>
|
|
317
|
+
|
|
318
|
+
public abstract cancelOrder(
|
|
319
|
+
orderCapId: string,
|
|
320
|
+
collateralToken: string,
|
|
321
|
+
indexToken: string,
|
|
322
|
+
long: boolean,
|
|
323
|
+
type: string,
|
|
324
|
+
isV11Order?: boolean
|
|
325
|
+
): Transaction
|
|
326
|
+
|
|
327
|
+
public abstract cancelMultiOrders(
|
|
328
|
+
orders: Array<{
|
|
329
|
+
orderCapId: string
|
|
330
|
+
collateralToken: string
|
|
331
|
+
indexToken: string
|
|
332
|
+
long: boolean
|
|
333
|
+
type: string
|
|
334
|
+
isV11Order?: boolean
|
|
335
|
+
}>, tx?: Transaction
|
|
336
|
+
): Transaction
|
|
337
|
+
|
|
338
|
+
public abstract clearClosedPosition(
|
|
339
|
+
pcpId: string,
|
|
340
|
+
collateralToken: string,
|
|
341
|
+
indexToken: string,
|
|
342
|
+
long: boolean,
|
|
343
|
+
tx: Transaction,
|
|
344
|
+
): void
|
|
345
|
+
|
|
346
|
+
public abstract clearOpenPositionOrder(
|
|
347
|
+
orderCapId: string,
|
|
348
|
+
collateralToken: string,
|
|
349
|
+
indexToken: string,
|
|
350
|
+
long: boolean,
|
|
351
|
+
tx: Transaction,
|
|
352
|
+
isV11Order?: boolean
|
|
353
|
+
): void
|
|
354
|
+
|
|
355
|
+
public abstract clearDecreasePositionOrder(
|
|
356
|
+
orderCapId: string,
|
|
357
|
+
collateralToken: string,
|
|
358
|
+
indexToken: string,
|
|
359
|
+
long: boolean,
|
|
360
|
+
tx: Transaction,
|
|
361
|
+
isV11Order?: boolean
|
|
362
|
+
): void
|
|
363
|
+
|
|
364
|
+
// S Card operations
|
|
365
|
+
public abstract openPositionWithSCard(
|
|
366
|
+
collateralToken: string,
|
|
367
|
+
indexToken: string,
|
|
368
|
+
size: bigint,
|
|
369
|
+
collateralAmount: bigint,
|
|
370
|
+
coinObjects: string[],
|
|
371
|
+
long: boolean,
|
|
372
|
+
reserveAmount: bigint,
|
|
373
|
+
indexPrice: number,
|
|
374
|
+
collateralPrice: number,
|
|
375
|
+
kioskClient: KioskClient,
|
|
376
|
+
kioskCap: KioskOwnerCap,
|
|
377
|
+
scard: string,
|
|
378
|
+
isLimitOrder?: boolean,
|
|
379
|
+
isIocOrder?: boolean,
|
|
380
|
+
pricesSlippage?: number,
|
|
381
|
+
collateralSlippage?: number,
|
|
382
|
+
relayerFee?: bigint,
|
|
383
|
+
referralAddress?: string,
|
|
384
|
+
sender?: string,
|
|
385
|
+
): Promise<Transaction>
|
|
386
|
+
|
|
387
|
+
public abstract decreasePositionWithSCard(
|
|
388
|
+
pcpId: string,
|
|
389
|
+
collateralToken: string,
|
|
390
|
+
indexToken: string,
|
|
391
|
+
amount: bigint,
|
|
392
|
+
long: boolean,
|
|
393
|
+
indexPrice: number,
|
|
394
|
+
collateralPrice: number,
|
|
395
|
+
kioskClient: KioskClient,
|
|
396
|
+
kioskCap: KioskOwnerCap,
|
|
397
|
+
scard: string,
|
|
398
|
+
isTriggerOrder?: boolean,
|
|
399
|
+
isTakeProfitOrder?: boolean,
|
|
400
|
+
isIocOrder?: boolean,
|
|
401
|
+
pricesSlippage?: number,
|
|
402
|
+
collateralSlippage?: number,
|
|
403
|
+
relayerFee?: bigint,
|
|
404
|
+
coinObjects?: string[]
|
|
405
|
+
): Promise<Transaction>
|
|
406
|
+
|
|
407
|
+
public abstract decreaseMultiPositionsWithSCard(
|
|
408
|
+
positions: Array<{
|
|
409
|
+
pcpId: string
|
|
410
|
+
collateralToken: string
|
|
411
|
+
indexToken: string
|
|
412
|
+
amount: bigint
|
|
413
|
+
long: boolean
|
|
414
|
+
indexPrice: number
|
|
415
|
+
collateralPrice: number
|
|
416
|
+
isTriggerOrder?: boolean
|
|
417
|
+
isTakeProfitOrder?: boolean
|
|
418
|
+
isIocOrder?: boolean
|
|
419
|
+
pricesSlippage?: number
|
|
420
|
+
collateralSlippage?: number
|
|
421
|
+
relayerFee?: bigint
|
|
422
|
+
coinObjects?: string[]
|
|
423
|
+
}>,
|
|
424
|
+
kioskClient: KioskClient,
|
|
425
|
+
kioskCap: KioskOwnerCap,
|
|
426
|
+
scard: string,
|
|
427
|
+
tx?: Transaction
|
|
428
|
+
): Promise<Transaction>
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Default: not supported. Override in subclasses that support S Card claim (e.g. SLP).
|
|
432
|
+
*/
|
|
433
|
+
public claimTokenFromSCard(
|
|
434
|
+
_token: string,
|
|
435
|
+
_coinObjects: string[],
|
|
436
|
+
_kioskClient: KioskClient,
|
|
437
|
+
_kioskCap: KioskOwnerCap,
|
|
438
|
+
_scard: string,
|
|
439
|
+
): Transaction {
|
|
440
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Miscellaneous
|
|
444
|
+
public abstract addReferral(
|
|
445
|
+
referrer: string,
|
|
446
|
+
tx?: Transaction
|
|
447
|
+
): Transaction
|
|
448
|
+
|
|
449
|
+
// Admin operations
|
|
450
|
+
public abstract adminUpdatePriceFeed(
|
|
451
|
+
collateralToken: string,
|
|
452
|
+
indexToken: string
|
|
453
|
+
): Promise<Transaction>
|
|
454
|
+
|
|
455
|
+
public abstract adminSettlePosition(
|
|
456
|
+
positionId: string,
|
|
457
|
+
owner: string,
|
|
458
|
+
collateralToken: string,
|
|
459
|
+
indexToken: string,
|
|
460
|
+
long: boolean
|
|
461
|
+
): Transaction
|
|
462
|
+
|
|
463
|
+
public abstract adminDecreasePosition(
|
|
464
|
+
positionId: string,
|
|
465
|
+
owner: string,
|
|
466
|
+
collateralToken: string,
|
|
467
|
+
indexToken: string,
|
|
468
|
+
positionAmount: number,
|
|
469
|
+
amount: bigint,
|
|
470
|
+
long: boolean,
|
|
471
|
+
collateralPrice?: number,
|
|
472
|
+
collateralSlippage?: number,
|
|
473
|
+
relayerFee?: bigint
|
|
474
|
+
): Transaction
|
|
475
|
+
|
|
476
|
+
public abstract adminClearClosedPosition(
|
|
477
|
+
positionId: string,
|
|
478
|
+
owner: string,
|
|
479
|
+
collateralToken: string,
|
|
480
|
+
indexToken: string,
|
|
481
|
+
long: boolean,
|
|
482
|
+
tx: Transaction
|
|
483
|
+
): void
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Helper method to initialize oracle transaction block
|
|
487
|
+
* This is commonly used across all LP token implementations
|
|
488
|
+
*/
|
|
489
|
+
protected async initOracleTransaction(tokens: string[], tx?: Transaction): Promise<Transaction> {
|
|
490
|
+
const txToUse = tx ?? new Transaction()
|
|
491
|
+
return await this.initOracleTxb(tokens, txToUse)
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Helper method to add clock object to transaction
|
|
496
|
+
*/
|
|
497
|
+
protected addClockToTransaction(tx: Transaction) {
|
|
498
|
+
return tx.object(SUI_CLOCK_OBJECT_ID)
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Helper method to create move call arguments array
|
|
503
|
+
*/
|
|
504
|
+
protected createMoveCallArgs(tx: Transaction, args: any[]): any[] {
|
|
505
|
+
return args.map((arg) => {
|
|
506
|
+
if (typeof arg === 'string' && arg.startsWith('0x')) {
|
|
507
|
+
return tx.object(arg)
|
|
508
|
+
}
|
|
509
|
+
if (typeof arg === 'number') {
|
|
510
|
+
return tx.pure.u64(arg)
|
|
511
|
+
}
|
|
512
|
+
if (typeof arg === 'bigint') {
|
|
513
|
+
return tx.pure.u256(arg)
|
|
514
|
+
}
|
|
515
|
+
return arg
|
|
516
|
+
})
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Helper method to validate transaction parameters
|
|
521
|
+
*/
|
|
522
|
+
protected validateTransactionParams(params: {
|
|
523
|
+
coin?: string
|
|
524
|
+
coinObjects?: string[]
|
|
525
|
+
amount?: number
|
|
526
|
+
minAmountOut?: number
|
|
527
|
+
}): void {
|
|
528
|
+
const { coin, coinObjects, amount, minAmountOut } = params
|
|
529
|
+
|
|
530
|
+
if (coin && !this.consts.coins[coin]) {
|
|
531
|
+
throw new Error(`Unsupported coin: ${coin}`)
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (coinObjects && coinObjects.length === 0) {
|
|
535
|
+
throw new Error('At least one coin object is required')
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (amount !== undefined && amount <= 0) {
|
|
539
|
+
throw new Error('Amount must be greater than 0')
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
if (minAmountOut !== undefined && minAmountOut < 0) {
|
|
543
|
+
throw new Error('Minimum amount out cannot be negative')
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Helper method to validate position parameters
|
|
549
|
+
*/
|
|
550
|
+
protected validatePositionParams(params: {
|
|
551
|
+
collateralToken: string
|
|
552
|
+
indexToken: string
|
|
553
|
+
size: bigint
|
|
554
|
+
collateralAmount: bigint
|
|
555
|
+
long: boolean
|
|
556
|
+
}): void {
|
|
557
|
+
const { collateralToken, indexToken, size, collateralAmount } = params
|
|
558
|
+
|
|
559
|
+
if (!this.consts.coins[collateralToken]) {
|
|
560
|
+
throw new Error(`Unsupported collateral token: ${collateralToken}`)
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if (!this.consts.coins[indexToken]) {
|
|
564
|
+
throw new Error(`Unsupported index token: ${indexToken}`)
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (size <= 0n) {
|
|
568
|
+
throw new Error('Position size must be greater than 0')
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (collateralAmount <= 0n) {
|
|
572
|
+
throw new Error('Collateral amount must be greater than 0')
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|