zo-sdk 0.1.2 → 0.1.4
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 -4
- package/dist/abstract/BaseAPI.cjs.map +1 -1
- package/dist/abstract/BaseAPI.d.cts +13 -13
- package/dist/abstract/BaseAPI.d.cts.map +1 -1
- package/dist/abstract/BaseAPI.d.mts +13 -13
- package/dist/abstract/BaseAPI.d.mts.map +1 -1
- package/dist/abstract/BaseAPI.mjs +3 -4
- package/dist/abstract/BaseAPI.mjs.map +1 -1
- package/dist/abstract/BaseDataAPI.cjs +2 -2
- package/dist/abstract/BaseDataAPI.cjs.map +1 -1
- package/dist/abstract/BaseDataAPI.d.cts +2 -2
- package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
- package/dist/abstract/BaseDataAPI.d.mts +2 -2
- package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
- package/dist/abstract/BaseDataAPI.mjs +2 -2
- package/dist/abstract/BaseDataAPI.mjs.map +1 -1
- package/dist/abstract/index.cjs +3 -3
- package/dist/abstract/index.cjs.map +1 -1
- package/dist/abstract/index.d.cts +1 -1
- package/dist/abstract/index.d.cts.map +1 -1
- package/dist/abstract/index.d.mts +1 -1
- package/dist/abstract/index.d.mts.map +1 -1
- package/dist/abstract/index.mjs +1 -1
- package/dist/abstract/index.mjs.map +1 -1
- package/dist/api.cjs +2 -1
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +2 -1
- package/dist/api.mjs.map +1 -1
- package/dist/bcs.cjs.map +1 -1
- package/dist/bcs.d.cts.map +1 -1
- package/dist/bcs.d.mts.map +1 -1
- package/dist/bcs.mjs.map +1 -1
- package/dist/consts/deployments-slp-mainnet.json +0 -70
- package/dist/consts/deployments-usdz-mainnet.json +1 -133
- package/dist/consts/index.cjs +56 -15
- package/dist/consts/index.cjs.map +1 -1
- package/dist/consts/index.d.cts.map +1 -1
- package/dist/consts/index.d.mts.map +1 -1
- package/dist/consts/index.mjs +56 -15
- package/dist/consts/index.mjs.map +1 -1
- package/dist/factory/SDKFactory.cjs +21 -14
- package/dist/factory/SDKFactory.cjs.map +1 -1
- package/dist/factory/SDKFactory.d.cts +4 -4
- package/dist/factory/SDKFactory.d.cts.map +1 -1
- package/dist/factory/SDKFactory.d.mts +4 -4
- package/dist/factory/SDKFactory.d.mts.map +1 -1
- package/dist/factory/SDKFactory.mjs +22 -15
- package/dist/factory/SDKFactory.mjs.map +1 -1
- package/dist/implementations/SLPAPI.cjs +143 -110
- package/dist/implementations/SLPAPI.cjs.map +1 -1
- package/dist/implementations/SLPAPI.d.cts +49 -47
- package/dist/implementations/SLPAPI.d.cts.map +1 -1
- package/dist/implementations/SLPAPI.d.mts +49 -47
- package/dist/implementations/SLPAPI.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.mjs +143 -110
- package/dist/implementations/SLPAPI.mjs.map +1 -1
- package/dist/implementations/SLPDataAPI.cjs +98 -89
- package/dist/implementations/SLPDataAPI.cjs.map +1 -1
- package/dist/implementations/SLPDataAPI.d.cts +21 -21
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/SLPDataAPI.d.mts +21 -21
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/SLPDataAPI.mjs +98 -89
- package/dist/implementations/SLPDataAPI.mjs.map +1 -1
- package/dist/implementations/USDZAPI.cjs +128 -84
- package/dist/implementations/USDZAPI.cjs.map +1 -1
- package/dist/implementations/USDZAPI.d.cts +46 -45
- package/dist/implementations/USDZAPI.d.cts.map +1 -1
- package/dist/implementations/USDZAPI.d.mts +46 -45
- package/dist/implementations/USDZAPI.d.mts.map +1 -1
- package/dist/implementations/USDZAPI.mjs +128 -84
- package/dist/implementations/USDZAPI.mjs.map +1 -1
- package/dist/implementations/USDZDataAPI.cjs +48 -47
- package/dist/implementations/USDZDataAPI.cjs.map +1 -1
- package/dist/implementations/USDZDataAPI.d.cts +19 -19
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
- package/dist/implementations/USDZDataAPI.d.mts +19 -19
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
- package/dist/implementations/USDZDataAPI.mjs +49 -48
- package/dist/implementations/USDZDataAPI.mjs.map +1 -1
- package/dist/implementations/ZLPAPI.cjs +137 -89
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +50 -48
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +50 -48
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +137 -89
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.cjs +62 -63
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.cts +19 -19
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.mts +19 -19
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPDataAPI.mjs +63 -64
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
- package/dist/implementations/index.cjs +5 -5
- package/dist/implementations/index.cjs.map +1 -1
- package/dist/implementations/index.d.cts +2 -2
- package/dist/implementations/index.d.cts.map +1 -1
- package/dist/implementations/index.d.mts +2 -2
- package/dist/implementations/index.d.mts.map +1 -1
- package/dist/implementations/index.mjs +2 -2
- package/dist/implementations/index.mjs.map +1 -1
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces/base.cjs +0 -1
- package/dist/interfaces/base.cjs.map +1 -1
- package/dist/interfaces/base.d.cts +57 -57
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +57 -57
- package/dist/interfaces/base.d.mts.map +1 -1
- package/dist/interfaces/base.mjs +1 -1
- package/dist/interfaces/base.mjs.map +1 -1
- package/dist/interfaces/index.d.cts +4 -4
- package/dist/interfaces/index.d.cts.map +1 -1
- package/dist/interfaces/index.d.mts +4 -4
- package/dist/interfaces/index.d.mts.map +1 -1
- package/dist/interfaces/slp.cjs +0 -2
- package/dist/interfaces/slp.cjs.map +1 -1
- package/dist/interfaces/slp.d.cts +5 -5
- package/dist/interfaces/slp.d.cts.map +1 -1
- package/dist/interfaces/slp.d.mts +5 -5
- package/dist/interfaces/slp.d.mts.map +1 -1
- package/dist/interfaces/slp.mjs +1 -2
- package/dist/interfaces/slp.mjs.map +1 -1
- package/dist/interfaces/usdz.d.cts +1 -1
- package/dist/interfaces/usdz.d.cts.map +1 -1
- package/dist/interfaces/usdz.d.mts +1 -1
- package/dist/interfaces/usdz.d.mts.map +1 -1
- package/dist/interfaces/zlp.d.cts +5 -5
- package/dist/interfaces/zlp.d.cts.map +1 -1
- package/dist/interfaces/zlp.d.mts +5 -5
- package/dist/interfaces/zlp.d.mts.map +1 -1
- package/dist/oracle.cjs +12 -2
- package/dist/oracle.cjs.map +1 -1
- package/dist/oracle.d.cts +4 -3
- package/dist/oracle.d.cts.map +1 -1
- package/dist/oracle.d.mts +4 -3
- package/dist/oracle.d.mts.map +1 -1
- package/dist/oracle.mjs +13 -3
- package/dist/oracle.mjs.map +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +1 -1
- package/dist/utils.mjs.map +1 -1
- package/eslint.config.mjs +18 -0
- package/package.json +16 -15
- package/src/abstract/BaseAPI.ts +55 -49
- package/src/abstract/BaseDataAPI.ts +19 -17
- package/src/abstract/index.ts +1 -1
- package/src/api.ts +3 -1
- package/src/bcs.ts +9 -9
- package/src/consts/deployments-slp-mainnet.json +0 -70
- package/src/consts/deployments-usdz-mainnet.json +1 -133
- package/src/consts/index.ts +61 -16
- package/src/factory/SDKFactory.ts +49 -41
- package/src/implementations/SLPAPI.ts +299 -210
- package/src/implementations/SLPDataAPI.ts +163 -146
- package/src/implementations/USDZAPI.ts +238 -133
- package/src/implementations/USDZDataAPI.ts +79 -74
- package/src/implementations/ZLPAPI.ts +296 -174
- package/src/implementations/ZLPDataAPI.ts +93 -88
- package/src/implementations/index.ts +3 -3
- package/src/index.ts +17 -17
- package/src/interfaces/base.ts +123 -116
- package/src/interfaces/index.ts +14 -17
- package/src/interfaces/slp.ts +20 -19
- package/src/interfaces/usdz.ts +13 -13
- package/src/interfaces/zlp.ts +22 -21
- package/src/oracle.ts +25 -5
- package/src/utils.ts +9 -9
- package/tsconfig.json +1 -1
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
* Implements USDZ-specific trading and transaction methods
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import type { KioskClient, KioskOwnerCap } from '@mysten/kiosk'
|
|
6
7
|
import type { SuiClient } from '@mysten/sui/client'
|
|
7
8
|
import { Transaction } from '@mysten/sui/transactions'
|
|
8
9
|
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils'
|
|
10
|
+
|
|
11
|
+
import { BaseAPI } from '../abstract'
|
|
9
12
|
import type { Network } from '../consts'
|
|
10
13
|
import { ALLOW_TRADE_CAN_TRADE, ALLOW_TRADE_MUST_TRADE, ALLOW_TRADE_NO_TRADE, LPToken } from '../consts'
|
|
11
|
-
import {
|
|
12
|
-
IUSDZAPI,
|
|
14
|
+
import type {
|
|
13
15
|
IBaseCredential,
|
|
14
16
|
IBaseHistoryResponse,
|
|
15
17
|
IBaseMarketInfo,
|
|
@@ -19,16 +21,15 @@ import {
|
|
|
19
21
|
IBasePositionCapInfo,
|
|
20
22
|
IBasePositionConfig,
|
|
21
23
|
IBasePositionInfo,
|
|
24
|
+
IBaseRebaseFeeModel,
|
|
22
25
|
IBaseStaked,
|
|
26
|
+
IBaseStakePool,
|
|
23
27
|
IBaseSymbolInfo,
|
|
24
28
|
IBaseVaultInfo,
|
|
25
|
-
|
|
26
|
-
IBaseStakePool
|
|
29
|
+
IUSDZAPI,
|
|
27
30
|
} from '../interfaces'
|
|
28
|
-
import { BaseAPI } from '../abstract'
|
|
29
|
-
import { USDZDataAPI } from './USDZDataAPI'
|
|
30
31
|
import { joinSymbol } from '../utils'
|
|
31
|
-
import {
|
|
32
|
+
import { USDZDataAPI } from './USDZDataAPI'
|
|
32
33
|
|
|
33
34
|
export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
34
35
|
public dataAPI: USDZDataAPI
|
|
@@ -37,110 +38,142 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
37
38
|
network: Network,
|
|
38
39
|
provider: SuiClient,
|
|
39
40
|
apiEndpoint: string,
|
|
40
|
-
connectionURL: string
|
|
41
|
+
connectionURL: string,
|
|
41
42
|
) {
|
|
42
43
|
super(network, provider, apiEndpoint, connectionURL, LPToken.USDZ)
|
|
43
44
|
this.dataAPI = new USDZDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
public stake(
|
|
47
|
-
throw new Error(
|
|
47
|
+
public stake(_lpCoinObjects: string[], _amount: bigint, _pool: string, _tx?: Transaction): Transaction {
|
|
48
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
|
|
51
|
+
public unstake(_credentials: IBaseCredential[], _amount: bigint, _pool: string, _tx?: Transaction): Transaction {
|
|
52
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
|
|
55
|
+
public clearClosedPosition(_pcpId: string, _collateralToken: string, _indexToken: string, _long: boolean, _tx: Transaction): void {
|
|
56
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
54
57
|
}
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
|
|
59
|
+
public clearOpenPositionOrder(_orderCapId: string, _collateralToken: string, _indexToken: string, _long: boolean, _tx: Transaction, _isV11Order?: boolean): void {
|
|
60
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
57
61
|
}
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
|
|
63
|
+
public clearDecreasePositionOrder(_orderCapId: string, _collateralToken: string, _indexToken: string, _long: boolean, _tx: Transaction, _isV11Order?: boolean): void {
|
|
64
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
|
|
67
|
+
public openPositionWithSCard(_collateralToken: string, _indexToken: string, _size: bigint, _collateralAmount: bigint, _coinObjects: string[], _long: boolean, _reserveAmount: bigint, _indexPrice: number, _collateralPrice: number, _kioskClient: KioskClient, _kioskCap: KioskOwnerCap, _scard: string, _isLimitOrder?: boolean, _isIocOrder?: boolean, _pricesSlippage?: number, _collateralSlippage?: number, _relayerFee?: bigint, _referralAddress?: string, _sender?: string): Promise<Transaction> {
|
|
68
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
63
69
|
}
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
|
|
71
|
+
public decreasePositionWithSCard(_pcpId: string, _collateralToken: string, _indexToken: string, _amount: bigint, _long: boolean, _indexPrice: number, _collateralPrice: number, _kioskClient: KioskClient, _kioskCap: KioskOwnerCap, _scard: string, _isTriggerOrder?: boolean, _isTakeProfitOrder?: boolean, _isIocOrder?: boolean, _pricesSlippage?: number, _collateralSlippage?: number, _relayerFee?: bigint, _coinObjects?: string[]): Promise<Transaction> {
|
|
72
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
66
73
|
}
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
|
|
75
|
+
public decreaseMultiPositionsWithSCard(_positions: Array<{ pcpId: string, collateralToken: string, indexToken: string, amount: bigint, long: boolean, indexPrice: number, collateralPrice: number, isTriggerOrder?: boolean, isTakeProfitOrder?: boolean, isIocOrder?: boolean, pricesSlippage?: number, collateralSlippage?: number, relayerFee?: bigint, coinObjects?: string[] }>, _kioskClient: KioskClient, _kioskCap: KioskOwnerCap, _scard: string, _tx?: Transaction): Promise<Transaction> {
|
|
76
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
|
|
79
|
+
public claimTokenFromSCard(_token: string, _coinObjects: string[], _kioskClient: KioskClient, _kioskCap: KioskOwnerCap, _scard: string): Transaction {
|
|
80
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
72
81
|
}
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
|
|
83
|
+
public valuateVaults(_tx: Transaction) {
|
|
84
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
75
85
|
}
|
|
76
|
-
|
|
77
|
-
|
|
86
|
+
|
|
87
|
+
public valuateSymbols(_tx: Transaction) {
|
|
88
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
78
89
|
}
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
|
|
91
|
+
public valuate(_tx: Transaction): { vaultsValuation: any, symbolsValuation: any } {
|
|
92
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
81
93
|
}
|
|
94
|
+
|
|
82
95
|
public valuateMarket(): Promise<IBaseMarketValuationInfo> {
|
|
83
|
-
throw new Error(
|
|
96
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
84
97
|
}
|
|
85
|
-
|
|
86
|
-
|
|
98
|
+
|
|
99
|
+
public fundingFeeRate(_indexToken: string, _long: boolean): Promise<number> {
|
|
100
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
87
101
|
}
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
|
|
103
|
+
public rebaseFeeRate(_collateralToken: string, _increase: boolean, _amount: number): Promise<number> {
|
|
104
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
90
105
|
}
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
|
|
107
|
+
public reservingFeeRate(_collateralToken: string, _amount: number): Promise<number> {
|
|
108
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
93
109
|
}
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
|
|
111
|
+
public calcPositionReserveFeeAmount(_position: IBasePositionInfo): Promise<number> {
|
|
112
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
96
113
|
}
|
|
97
|
-
|
|
98
|
-
|
|
114
|
+
|
|
115
|
+
public calcPositionFundingFeeValue(_position: IBasePositionInfo): Promise<number> {
|
|
116
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
99
117
|
}
|
|
118
|
+
|
|
100
119
|
public getMarketInfo(): Promise<IBaseMarketInfo> {
|
|
101
|
-
throw new Error(
|
|
120
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
102
121
|
}
|
|
103
|
-
|
|
104
|
-
|
|
122
|
+
|
|
123
|
+
public getVaultInfo(_vault: string): Promise<IBaseVaultInfo> {
|
|
124
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
105
125
|
}
|
|
106
|
-
|
|
107
|
-
|
|
126
|
+
|
|
127
|
+
public getSymbolInfo(_tokenId: string, _long: boolean): Promise<IBaseSymbolInfo> {
|
|
128
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
108
129
|
}
|
|
109
|
-
|
|
110
|
-
|
|
130
|
+
|
|
131
|
+
public getPositionConfig(_indexToken: string, _long: boolean): Promise<IBasePositionConfig> {
|
|
132
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
111
133
|
}
|
|
134
|
+
|
|
112
135
|
public getRebaseFeeModel(): Promise<IBaseRebaseFeeModel> {
|
|
113
|
-
throw new Error(
|
|
136
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
114
137
|
}
|
|
138
|
+
|
|
115
139
|
public getOpenPositions(): Promise<IBasePositionInfo[]> {
|
|
116
|
-
throw new Error(
|
|
140
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
117
141
|
}
|
|
118
|
-
|
|
119
|
-
|
|
142
|
+
|
|
143
|
+
public getPositionCapInfoList(_owner: string): Promise<IBasePositionCapInfo[]> {
|
|
144
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
120
145
|
}
|
|
121
|
-
|
|
122
|
-
|
|
146
|
+
|
|
147
|
+
public getPositionInfoList(_positionCapInfoList: IBasePositionCapInfo[], _owner: string): Promise<IBasePositionInfo[]> {
|
|
148
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
123
149
|
}
|
|
124
|
-
|
|
125
|
-
|
|
150
|
+
|
|
151
|
+
public getOrderCapInfoList(_owner: string): Promise<IBaseOrderCapInfo[]> {
|
|
152
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
126
153
|
}
|
|
127
|
-
|
|
128
|
-
|
|
154
|
+
|
|
155
|
+
public getOrderInfoList(_orderCapInfoList: IBaseOrderCapInfo[], _owner: string): Promise<IBaseOrderInfo[]> {
|
|
156
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
129
157
|
}
|
|
130
|
-
|
|
131
|
-
|
|
158
|
+
|
|
159
|
+
public getHistory(_trader: string, _page: number, _limit: number, _orderType?: string, _symbol?: string): Promise<IBaseHistoryResponse> {
|
|
160
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
132
161
|
}
|
|
133
|
-
|
|
134
|
-
|
|
162
|
+
|
|
163
|
+
public getStaked(_owner: string): Promise<IBaseStaked> {
|
|
164
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
135
165
|
}
|
|
166
|
+
|
|
136
167
|
public getStakePool(): Promise<IBaseStakePool> {
|
|
137
|
-
throw new Error(
|
|
168
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
138
169
|
}
|
|
139
|
-
|
|
140
|
-
|
|
170
|
+
|
|
171
|
+
public hasReferral(_referree: string): Promise<boolean> {
|
|
172
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
141
173
|
}
|
|
142
|
-
|
|
143
|
-
|
|
174
|
+
|
|
175
|
+
public getReferralData(_referree: string): Promise<any> {
|
|
176
|
+
throw new Error(`Method not implemented in ${this.constructor.name}.`)
|
|
144
177
|
}
|
|
145
178
|
|
|
146
179
|
/**
|
|
@@ -150,27 +183,70 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
150
183
|
coin: string,
|
|
151
184
|
coinObjects: string[],
|
|
152
185
|
amount: number,
|
|
153
|
-
minAmountOut
|
|
186
|
+
minAmountOut = 0,
|
|
154
187
|
referralAddress?: string,
|
|
155
|
-
sender?: string
|
|
188
|
+
sender?: string,
|
|
189
|
+
sponsoredTx?: boolean,
|
|
190
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
191
|
+
isDepositingSui?: boolean,
|
|
156
192
|
): Promise<Transaction> {
|
|
157
|
-
let tx =
|
|
193
|
+
let tx = new Transaction()
|
|
194
|
+
|
|
195
|
+
// Add referral if needed
|
|
158
196
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
159
197
|
tx = await this.addReferral(referralAddress, tx)
|
|
160
198
|
}
|
|
161
|
-
|
|
162
|
-
|
|
199
|
+
|
|
200
|
+
// Initialize oracle transaction
|
|
201
|
+
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder)
|
|
202
|
+
|
|
203
|
+
// Handle sponsored transaction case
|
|
204
|
+
if (sponsoredTx) {
|
|
205
|
+
const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
|
|
206
|
+
tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject)
|
|
207
|
+
|
|
208
|
+
// Process deposit coins
|
|
209
|
+
const depositObject = isDepositingSui
|
|
210
|
+
? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
|
|
211
|
+
: tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0]
|
|
212
|
+
|
|
213
|
+
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
|
|
214
|
+
|
|
215
|
+
tx.moveCall({
|
|
216
|
+
target: `${this.consts.zoCore.package}::market::deposit`,
|
|
217
|
+
typeArguments: [`${this.consts.zoCore.package}::usdz::USDZ`, this.consts.coins[coin].module],
|
|
218
|
+
arguments: [
|
|
219
|
+
tx.object(this.consts.zoCore.market),
|
|
220
|
+
tx.object(this.consts.zoCore.rebaseFeeModel),
|
|
221
|
+
depositObject,
|
|
222
|
+
tx.pure.u64(minAmountOut),
|
|
223
|
+
vaultsValuation,
|
|
224
|
+
symbolsValuation,
|
|
225
|
+
],
|
|
226
|
+
})
|
|
227
|
+
return tx
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Handle non-sponsored transaction case
|
|
231
|
+
tx = await this.initOracleTxb(pythFeederKeys, tx)
|
|
232
|
+
const depositObject = tx.splitCoins(
|
|
233
|
+
this.processCoins(tx, coin, coinObjects, false),
|
|
234
|
+
[tx.pure.u64(amount)],
|
|
235
|
+
)[0]
|
|
163
236
|
|
|
164
237
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
|
|
165
238
|
|
|
166
239
|
tx.moveCall({
|
|
167
240
|
target: `${this.consts.zoCore.package}::market::deposit`,
|
|
168
|
-
typeArguments: [
|
|
241
|
+
typeArguments: [
|
|
242
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
243
|
+
this.consts.coins[coin].module,
|
|
244
|
+
],
|
|
169
245
|
arguments: [
|
|
170
246
|
tx.object(this.consts.zoCore.market),
|
|
171
247
|
tx.object(this.consts.zoCore.rebaseFeeModel),
|
|
172
248
|
depositObject,
|
|
173
|
-
tx.pure.u64(minAmountOut
|
|
249
|
+
tx.pure.u64(minAmountOut),
|
|
174
250
|
vaultsValuation,
|
|
175
251
|
symbolsValuation,
|
|
176
252
|
],
|
|
@@ -185,22 +261,37 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
185
261
|
coin: string,
|
|
186
262
|
lpCoinObjects: string[],
|
|
187
263
|
amount: number,
|
|
188
|
-
minAmountOut
|
|
264
|
+
minAmountOut = 0,
|
|
265
|
+
sponsoredTx?: boolean,
|
|
266
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
189
267
|
): Promise<Transaction> {
|
|
190
|
-
|
|
191
|
-
const usdzCoinObject = this.processCoins(tx, 'usdz', lpCoinObjects)
|
|
192
|
-
const [withdrawObject] = tx.splitCoins(usdzCoinObject, [tx.pure.u64(amount)])
|
|
268
|
+
let tx = new Transaction()
|
|
193
269
|
|
|
270
|
+
// Initialize oracle transaction
|
|
271
|
+
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder)
|
|
272
|
+
|
|
273
|
+
if (sponsoredTx) {
|
|
274
|
+
const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
|
|
275
|
+
tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject)
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
tx = await this.initOracleTxb(pythFeederKeys, tx)
|
|
279
|
+
}
|
|
280
|
+
const usdzCoinObject = this.processCoins(tx, 'usdz', lpCoinObjects, false)
|
|
281
|
+
const [withdrawObject] = tx.splitCoins(usdzCoinObject, [tx.pure.u64(amount)])
|
|
194
282
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
|
|
195
283
|
|
|
196
284
|
tx.moveCall({
|
|
197
285
|
target: `${this.consts.zoCore.package}::market::withdraw`,
|
|
198
|
-
typeArguments: [
|
|
286
|
+
typeArguments: [
|
|
287
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
288
|
+
this.consts.coins[coin].module,
|
|
289
|
+
],
|
|
199
290
|
arguments: [
|
|
200
291
|
tx.object(this.consts.zoCore.market),
|
|
201
292
|
tx.object(this.consts.zoCore.rebaseFeeModel),
|
|
202
293
|
withdrawObject,
|
|
203
|
-
tx.pure.u64(minAmountOut
|
|
294
|
+
tx.pure.u64(minAmountOut),
|
|
204
295
|
vaultsValuation,
|
|
205
296
|
symbolsValuation,
|
|
206
297
|
],
|
|
@@ -208,13 +299,12 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
208
299
|
return tx
|
|
209
300
|
}
|
|
210
301
|
|
|
211
|
-
|
|
212
302
|
public async swap(
|
|
213
303
|
fromToken: string,
|
|
214
304
|
toToken: string,
|
|
215
305
|
fromAmount: bigint,
|
|
216
306
|
fromCoinObjects: string[],
|
|
217
|
-
minAmountOut?: number
|
|
307
|
+
minAmountOut?: number,
|
|
218
308
|
): Promise<Transaction> {
|
|
219
309
|
const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults))
|
|
220
310
|
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects)
|
|
@@ -258,7 +348,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
258
348
|
collateralSlippage?: number,
|
|
259
349
|
relayerFee?: bigint,
|
|
260
350
|
referralAddress?: string,
|
|
261
|
-
sender?: string
|
|
351
|
+
sender?: string,
|
|
262
352
|
): Promise<Transaction> {
|
|
263
353
|
let tx = new Transaction()
|
|
264
354
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
@@ -323,11 +413,14 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
323
413
|
isTriggerOrder = false,
|
|
324
414
|
isTakeProfitOrder = true,
|
|
325
415
|
isIocOrder = false,
|
|
326
|
-
pricesSlippage
|
|
327
|
-
collateralSlippage
|
|
416
|
+
pricesSlippage = 0.003,
|
|
417
|
+
collateralSlippage = 0.5,
|
|
328
418
|
relayerFee = BigInt(0.5),
|
|
329
|
-
coinObjects?: string[]
|
|
419
|
+
coinObjects?: string[],
|
|
330
420
|
): Promise<Transaction> {
|
|
421
|
+
if (!coinObjects) {
|
|
422
|
+
throw new Error(`${this.constructor.name}: coinObjects is required`)
|
|
423
|
+
}
|
|
331
424
|
const tx = await this.initOracleTxb([collateralToken, indexToken])
|
|
332
425
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
333
426
|
const coinObject = this.processCoins(tx, collateralToken, coinObjects || [])
|
|
@@ -339,7 +432,8 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
339
432
|
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
340
433
|
if (isTriggerOrder) {
|
|
341
434
|
allowTrade = isIocOrder || !isTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
342
|
-
}
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
343
437
|
isTakeProfitOrder = true
|
|
344
438
|
}
|
|
345
439
|
|
|
@@ -373,43 +467,56 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
373
467
|
}
|
|
374
468
|
|
|
375
469
|
public async decreaseMultiPositions(positions: Array<{
|
|
376
|
-
pcpId: string
|
|
377
|
-
collateralToken: string
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
relayerFee
|
|
470
|
+
pcpId: string
|
|
471
|
+
collateralToken: string
|
|
472
|
+
indexToken: string
|
|
473
|
+
amount: bigint
|
|
474
|
+
long: boolean
|
|
475
|
+
indexPrice: number
|
|
476
|
+
collateralPrice: number
|
|
477
|
+
isTriggerOrder?: boolean
|
|
478
|
+
isTakeProfitOrder?: boolean
|
|
479
|
+
isIocOrder?: boolean
|
|
480
|
+
pricesSlippage?: number
|
|
481
|
+
collateralSlippage?: number
|
|
482
|
+
relayerFee?: bigint
|
|
483
|
+
coinObjects?: string[]
|
|
389
484
|
}>, tx?: Transaction): Promise<Transaction> {
|
|
390
485
|
if (!tx) {
|
|
391
486
|
tx = new Transaction()
|
|
392
487
|
}
|
|
393
|
-
tx = await this.initOracleTxb(positions.
|
|
488
|
+
tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)
|
|
394
489
|
|
|
395
490
|
for (const position of positions) {
|
|
396
491
|
const {
|
|
397
492
|
pcpId,
|
|
398
493
|
collateralToken,
|
|
399
|
-
coinObjects
|
|
494
|
+
coinObjects = [],
|
|
495
|
+
indexToken,
|
|
496
|
+
amount,
|
|
497
|
+
long,
|
|
498
|
+
indexPrice,
|
|
499
|
+
collateralPrice,
|
|
500
|
+
isTriggerOrder = false,
|
|
501
|
+
isTakeProfitOrder = true,
|
|
502
|
+
isIocOrder = false,
|
|
503
|
+
pricesSlippage = 0.003,
|
|
504
|
+
collateralSlippage = 0.5,
|
|
505
|
+
relayerFee = BigInt(0.5),
|
|
400
506
|
} = position
|
|
401
507
|
let innerIsTakeProfitOrder = isTakeProfitOrder
|
|
402
508
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
403
509
|
const coinObject = this.processCoins(tx, collateralToken, coinObjects)
|
|
404
510
|
const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)])
|
|
405
511
|
|
|
406
|
-
const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 :
|
|
407
|
-
const adjustCollateralPrice = this.processSlippage(collateralPrice, false,
|
|
512
|
+
const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
|
|
513
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
|
|
408
514
|
|
|
409
515
|
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
410
516
|
if (isTriggerOrder) {
|
|
411
517
|
allowTrade = isIocOrder || !innerIsTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
412
|
-
}
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
413
520
|
innerIsTakeProfitOrder = true
|
|
414
521
|
}
|
|
415
522
|
|
|
@@ -451,7 +558,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
451
558
|
indexToken: string,
|
|
452
559
|
amount: number,
|
|
453
560
|
coinObjects: string[],
|
|
454
|
-
long: boolean
|
|
561
|
+
long: boolean,
|
|
455
562
|
): Promise<Transaction> {
|
|
456
563
|
const tx = await this.initOracleTxb([collateralToken, indexToken])
|
|
457
564
|
const coinObject = this.processCoins(tx, collateralToken, coinObjects)
|
|
@@ -503,14 +610,14 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
503
610
|
return tx
|
|
504
611
|
}
|
|
505
612
|
|
|
506
|
-
public
|
|
613
|
+
public cancelOrder(
|
|
507
614
|
orderCapId: string,
|
|
508
615
|
collateralToken: string,
|
|
509
616
|
indexToken: string,
|
|
510
617
|
long: boolean,
|
|
511
618
|
type: string,
|
|
512
|
-
isV11Order?: boolean
|
|
513
|
-
):
|
|
619
|
+
isV11Order?: boolean,
|
|
620
|
+
): Transaction {
|
|
514
621
|
const tx = new Transaction()
|
|
515
622
|
let functionName = ''
|
|
516
623
|
switch (type) {
|
|
@@ -542,16 +649,17 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
542
649
|
return tx
|
|
543
650
|
}
|
|
544
651
|
|
|
545
|
-
public
|
|
652
|
+
public cancelMultiOrders(
|
|
546
653
|
orders: Array<{
|
|
547
|
-
orderCapId: string
|
|
548
|
-
collateralToken: string
|
|
549
|
-
indexToken: string
|
|
550
|
-
long: boolean
|
|
551
|
-
type: string
|
|
654
|
+
orderCapId: string
|
|
655
|
+
collateralToken: string
|
|
656
|
+
indexToken: string
|
|
657
|
+
long: boolean
|
|
658
|
+
type: string
|
|
552
659
|
isV11Order?: boolean
|
|
553
|
-
}>,
|
|
554
|
-
|
|
660
|
+
}>,
|
|
661
|
+
tx?: Transaction,
|
|
662
|
+
): Transaction {
|
|
555
663
|
if (!tx) {
|
|
556
664
|
tx = new Transaction()
|
|
557
665
|
}
|
|
@@ -592,7 +700,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
592
700
|
|
|
593
701
|
public addReferral(
|
|
594
702
|
referralAddress: string,
|
|
595
|
-
tx?: Transaction
|
|
703
|
+
tx?: Transaction,
|
|
596
704
|
): Transaction {
|
|
597
705
|
if (!tx) {
|
|
598
706
|
tx = new Transaction()
|
|
@@ -608,19 +716,19 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
608
716
|
|
|
609
717
|
public async adminUpdatePriceFeed(
|
|
610
718
|
collateralToken: string,
|
|
611
|
-
indexToken: string
|
|
719
|
+
indexToken: string,
|
|
612
720
|
): Promise<Transaction> {
|
|
613
721
|
const tx = await this.initOracleTxb([collateralToken, indexToken])
|
|
614
722
|
return tx
|
|
615
723
|
}
|
|
616
724
|
|
|
617
|
-
public
|
|
725
|
+
public adminSettlePosition(
|
|
618
726
|
positionId: string,
|
|
619
727
|
owner: string,
|
|
620
728
|
collateralToken: string,
|
|
621
729
|
indexToken: string,
|
|
622
|
-
long: boolean
|
|
623
|
-
):
|
|
730
|
+
long: boolean,
|
|
731
|
+
): Transaction {
|
|
624
732
|
const tx = new Transaction()
|
|
625
733
|
|
|
626
734
|
tx.moveCall({
|
|
@@ -645,7 +753,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
645
753
|
return tx
|
|
646
754
|
}
|
|
647
755
|
|
|
648
|
-
public
|
|
756
|
+
public adminDecreasePosition(
|
|
649
757
|
positionId: string,
|
|
650
758
|
owner: string,
|
|
651
759
|
collateralToken: string,
|
|
@@ -653,10 +761,7 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
653
761
|
positionAmount: number,
|
|
654
762
|
amount: bigint,
|
|
655
763
|
long: boolean,
|
|
656
|
-
|
|
657
|
-
collateralSlippage?: number,
|
|
658
|
-
relayerFee?: bigint
|
|
659
|
-
): Promise<Transaction> {
|
|
764
|
+
): Transaction {
|
|
660
765
|
const tx = new Transaction()
|
|
661
766
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
662
767
|
|
|
@@ -688,14 +793,14 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
688
793
|
return tx
|
|
689
794
|
}
|
|
690
795
|
|
|
691
|
-
public
|
|
796
|
+
public adminClearClosedPosition(
|
|
692
797
|
positionId: string,
|
|
693
798
|
owner: string,
|
|
694
799
|
collateralToken: string,
|
|
695
800
|
indexToken: string,
|
|
696
801
|
long: boolean,
|
|
697
|
-
tx: Transaction
|
|
698
|
-
):
|
|
802
|
+
tx: Transaction,
|
|
803
|
+
): void {
|
|
699
804
|
tx.moveCall({
|
|
700
805
|
target: `${this.consts.zoCore.package}::market::force_clear_closed_position`,
|
|
701
806
|
typeArguments: [
|
|
@@ -712,4 +817,4 @@ export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
|
712
817
|
],
|
|
713
818
|
})
|
|
714
819
|
}
|
|
715
|
-
}
|
|
820
|
+
}
|