zo-sdk 0.0.51 → 0.1.1
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/README.md +272 -20
- package/dist/abstract/BaseAPI.cjs +117 -0
- package/dist/abstract/BaseAPI.cjs.map +1 -0
- package/dist/abstract/BaseAPI.d.cts +131 -0
- package/dist/abstract/BaseAPI.d.cts.map +1 -0
- package/dist/abstract/BaseAPI.d.mts +131 -0
- package/dist/abstract/BaseAPI.d.mts.map +1 -0
- package/dist/abstract/BaseAPI.mjs +113 -0
- package/dist/abstract/BaseAPI.mjs.map +1 -0
- package/dist/abstract/BaseDataAPI.cjs +139 -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 +135 -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/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-slp-mainnet.json +710 -0
- package/dist/consts/deployments-slp-testnet.json +109 -0
- package/dist/consts/deployments-usdz-mainnet.json +180 -0
- package/dist/consts/deployments-usdz-testnet.json +98 -0
- package/dist/consts/{deployments-mainnet.json → deployments-zlp-mainnet.json} +278 -42
- package/dist/consts/index.cjs +49 -13
- package/dist/consts/index.cjs.map +1 -1
- package/dist/consts/index.d.cts +81 -11
- package/dist/consts/index.d.cts.map +1 -1
- package/dist/consts/index.d.mts +81 -11
- package/dist/consts/index.d.mts.map +1 -1
- package/dist/consts/index.mjs +48 -12
- package/dist/consts/index.mjs.map +1 -1
- package/dist/consts/price_id_to_object_id.mainnet.json +9 -1
- package/dist/factory/SDKFactory.cjs +185 -0
- package/dist/factory/SDKFactory.cjs.map +1 -0
- package/dist/factory/SDKFactory.d.cts +74 -0
- package/dist/factory/SDKFactory.d.cts.map +1 -0
- package/dist/factory/SDKFactory.d.mts +74 -0
- package/dist/factory/SDKFactory.d.mts.map +1 -0
- package/dist/factory/SDKFactory.mjs +179 -0
- package/dist/factory/SDKFactory.mjs.map +1 -0
- package/dist/implementations/SLPAPI.cjs +829 -0
- package/dist/implementations/SLPAPI.cjs.map +1 -0
- package/dist/implementations/SLPAPI.d.cts +120 -0
- package/dist/implementations/SLPAPI.d.cts.map +1 -0
- package/dist/implementations/SLPAPI.d.mts +120 -0
- package/dist/implementations/SLPAPI.d.mts.map +1 -0
- package/dist/implementations/SLPAPI.mjs +825 -0
- package/dist/implementations/SLPAPI.mjs.map +1 -0
- package/dist/implementations/SLPDataAPI.cjs +916 -0
- package/dist/implementations/SLPDataAPI.cjs.map +1 -0
- package/dist/implementations/SLPDataAPI.d.cts +102 -0
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -0
- package/dist/implementations/SLPDataAPI.d.mts +102 -0
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -0
- package/dist/implementations/SLPDataAPI.mjs +912 -0
- package/dist/implementations/SLPDataAPI.mjs.map +1 -0
- package/dist/implementations/USDZAPI.cjs +522 -0
- package/dist/implementations/USDZAPI.cjs.map +1 -0
- package/dist/implementations/USDZAPI.d.cts +118 -0
- package/dist/implementations/USDZAPI.d.cts.map +1 -0
- package/dist/implementations/USDZAPI.d.mts +118 -0
- package/dist/implementations/USDZAPI.d.mts.map +1 -0
- package/dist/implementations/USDZAPI.mjs +518 -0
- package/dist/implementations/USDZAPI.mjs.map +1 -0
- package/dist/implementations/USDZDataAPI.cjs +697 -0
- package/dist/implementations/USDZDataAPI.cjs.map +1 -0
- package/dist/implementations/USDZDataAPI.d.cts +86 -0
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -0
- package/dist/implementations/USDZDataAPI.d.mts +86 -0
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -0
- package/dist/implementations/USDZDataAPI.mjs +693 -0
- package/dist/implementations/USDZDataAPI.mjs.map +1 -0
- package/dist/implementations/ZLPAPI.cjs +809 -0
- package/dist/implementations/ZLPAPI.cjs.map +1 -0
- package/dist/implementations/ZLPAPI.d.cts +121 -0
- package/dist/implementations/ZLPAPI.d.cts.map +1 -0
- package/dist/implementations/ZLPAPI.d.mts +121 -0
- package/dist/implementations/ZLPAPI.d.mts.map +1 -0
- package/dist/implementations/ZLPAPI.mjs +805 -0
- package/dist/implementations/ZLPAPI.mjs.map +1 -0
- package/dist/implementations/ZLPDataAPI.cjs +724 -0
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -0
- package/dist/implementations/ZLPDataAPI.d.cts +83 -0
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -0
- package/dist/implementations/ZLPDataAPI.d.mts +83 -0
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -0
- package/dist/implementations/ZLPDataAPI.mjs +720 -0
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -0
- package/dist/implementations/index.cjs +22 -0
- package/dist/implementations/index.cjs.map +1 -0
- package/dist/implementations/index.d.cts +11 -0
- package/dist/implementations/index.d.cts.map +1 -0
- package/dist/implementations/index.d.mts +11 -0
- package/dist/implementations/index.d.mts.map +1 -0
- package/dist/implementations/index.mjs +13 -0
- package/dist/implementations/index.mjs.map +1 -0
- package/dist/index.cjs +47 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +45 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +45 -0
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces/base.cjs +8 -0
- package/dist/interfaces/base.cjs.map +1 -0
- package/dist/interfaces/base.d.cts +293 -0
- package/dist/interfaces/base.d.cts.map +1 -0
- package/dist/interfaces/base.d.mts +293 -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 +29 -0
- package/dist/interfaces/index.cjs.map +1 -0
- package/dist/interfaces/index.d.cts +13 -0
- package/dist/interfaces/index.d.cts.map +1 -0
- package/dist/interfaces/index.d.mts +13 -0
- package/dist/interfaces/index.d.mts.map +1 -0
- package/dist/interfaces/index.mjs +13 -0
- package/dist/interfaces/index.mjs.map +1 -0
- package/dist/interfaces/slp.cjs +9 -0
- package/dist/interfaces/slp.cjs.map +1 -0
- package/dist/interfaces/slp.d.cts +115 -0
- package/dist/interfaces/slp.d.cts.map +1 -0
- package/dist/interfaces/slp.d.mts +115 -0
- package/dist/interfaces/slp.d.mts.map +1 -0
- package/dist/interfaces/slp.mjs +7 -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 +40 -0
- package/dist/interfaces/usdz.d.cts.map +1 -0
- package/dist/interfaces/usdz.d.mts +40 -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/zlp.cjs +7 -0
- package/dist/interfaces/zlp.cjs.map +1 -0
- package/dist/interfaces/zlp.d.cts +45 -0
- package/dist/interfaces/zlp.d.cts.map +1 -0
- package/dist/interfaces/zlp.d.mts +45 -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 +7 -35
- package/dist/oracle.cjs.map +1 -1
- package/dist/oracle.d.cts +3 -4
- package/dist/oracle.d.cts.map +1 -1
- package/dist/oracle.d.mts +3 -4
- package/dist/oracle.d.mts.map +1 -1
- package/dist/oracle.mjs +8 -32
- package/dist/oracle.mjs.map +1 -1
- package/package.json +1 -1
- package/src/abstract/BaseAPI.ts +429 -0
- package/src/abstract/BaseDataAPI.ts +204 -0
- package/src/abstract/index.ts +7 -0
- package/src/bcs.ts +45 -0
- package/src/consts/deployments-slp-mainnet.json +710 -0
- package/src/consts/deployments-slp-testnet.json +109 -0
- package/src/consts/deployments-usdz-mainnet.json +180 -0
- package/src/consts/deployments-usdz-testnet.json +98 -0
- package/src/consts/{deployments-mainnet.json → deployments-zlp-mainnet.json} +279 -43
- package/src/consts/index.ts +143 -41
- package/src/consts/price_id_to_object_id.mainnet.json +10 -2
- package/src/factory/SDKFactory.ts +282 -0
- package/src/implementations/SLPAPI.ts +1207 -0
- package/src/implementations/SLPDataAPI.ts +1188 -0
- package/src/implementations/USDZAPI.ts +715 -0
- package/src/implementations/USDZDataAPI.ts +826 -0
- package/src/implementations/ZLPAPI.ts +1130 -0
- package/src/implementations/ZLPDataAPI.ts +856 -0
- package/src/implementations/index.ts +14 -0
- package/src/index.ts +53 -0
- package/src/interfaces/base.ts +556 -0
- package/src/interfaces/index.ts +45 -0
- package/src/interfaces/slp.ts +156 -0
- package/src/interfaces/usdz.ts +71 -0
- package/src/interfaces/zlp.ts +96 -0
- package/src/oracle.ts +12 -42
- package/tsconfig.json +4 -2
- package/dist/consts/staking/deployments-mainnet.json +0 -12
- package/dist/consts/staking/deployments-testnet.json +0 -11
- package/src/consts/staking/deployments-mainnet.json +0 -12
- package/src/consts/staking/deployments-testnet.json +0 -11
- /package/dist/consts/{deployments-testnet.json → deployments-zlp-testnet.json} +0 -0
- /package/src/consts/{deployments-testnet.json → deployments-zlp-testnet.json} +0 -0
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* USDZ API implementation
|
|
3
|
+
* Implements USDZ-specific trading and transaction methods
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { SuiClient } from '@mysten/sui/client'
|
|
7
|
+
import { Transaction } from '@mysten/sui/transactions'
|
|
8
|
+
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils'
|
|
9
|
+
import type { Network } from '../consts'
|
|
10
|
+
import { ALLOW_TRADE_CAN_TRADE, ALLOW_TRADE_MUST_TRADE, ALLOW_TRADE_NO_TRADE, LPToken } from '../consts'
|
|
11
|
+
import {
|
|
12
|
+
IUSDZAPI,
|
|
13
|
+
IBaseCredential,
|
|
14
|
+
IBaseHistoryResponse,
|
|
15
|
+
IBaseMarketInfo,
|
|
16
|
+
IBaseMarketValuationInfo,
|
|
17
|
+
IBaseOrderCapInfo,
|
|
18
|
+
IBaseOrderInfo,
|
|
19
|
+
IBasePositionCapInfo,
|
|
20
|
+
IBasePositionConfig,
|
|
21
|
+
IBasePositionInfo,
|
|
22
|
+
IBaseStaked,
|
|
23
|
+
IBaseSymbolInfo,
|
|
24
|
+
IBaseVaultInfo,
|
|
25
|
+
IBaseRebaseFeeModel,
|
|
26
|
+
IBaseStakePool
|
|
27
|
+
} from '../interfaces'
|
|
28
|
+
import { BaseAPI } from '../abstract'
|
|
29
|
+
import { USDZDataAPI } from './USDZDataAPI'
|
|
30
|
+
import { joinSymbol } from '../utils'
|
|
31
|
+
import { KioskClient, KioskOwnerCap } from '@mysten/kiosk'
|
|
32
|
+
|
|
33
|
+
export class USDZAPI extends BaseAPI implements IUSDZAPI {
|
|
34
|
+
public dataAPI: USDZDataAPI
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
network: Network,
|
|
38
|
+
provider: SuiClient,
|
|
39
|
+
apiEndpoint: string,
|
|
40
|
+
connectionURL: string
|
|
41
|
+
) {
|
|
42
|
+
super(network, provider, apiEndpoint, connectionURL, LPToken.USDZ)
|
|
43
|
+
this.dataAPI = new USDZDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public stake(lpCoinObjects: string[], amount: bigint, pool: string, tx?: Transaction): Promise<Transaction> {
|
|
47
|
+
throw new Error('Method not implemented.')
|
|
48
|
+
}
|
|
49
|
+
public unstake(credentials: IBaseCredential[], amount: bigint, pool: string, tx?: Transaction): Promise<Transaction> {
|
|
50
|
+
throw new Error('Method not implemented.')
|
|
51
|
+
}
|
|
52
|
+
public clearClosedPosition(pcpId: string, collateralToken: string, indexToken: string, long: boolean, tx: Transaction): void {
|
|
53
|
+
throw new Error('Method not implemented.')
|
|
54
|
+
}
|
|
55
|
+
public clearOpenPositionOrder(orderCapId: string, collateralToken: string, indexToken: string, long: boolean, tx: Transaction, isV11Order?: boolean): void {
|
|
56
|
+
throw new Error('Method not implemented.')
|
|
57
|
+
}
|
|
58
|
+
public clearDecreasePositionOrder(orderCapId: string, collateralToken: string, indexToken: string, long: boolean, tx: Transaction, isV11Order?: boolean): void {
|
|
59
|
+
throw new Error('Method not implemented.')
|
|
60
|
+
}
|
|
61
|
+
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> {
|
|
62
|
+
throw new Error('Method not implemented.')
|
|
63
|
+
}
|
|
64
|
+
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> {
|
|
65
|
+
throw new Error('Method not implemented.')
|
|
66
|
+
}
|
|
67
|
+
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> {
|
|
68
|
+
throw new Error('Method not implemented.')
|
|
69
|
+
}
|
|
70
|
+
public claimTokenFromSCard(token: string, coinObjects: string[], kioskClient: KioskClient, kioskCap: KioskOwnerCap, scard: string): Promise<Transaction> {
|
|
71
|
+
throw new Error('Method not implemented.')
|
|
72
|
+
}
|
|
73
|
+
public valuateVaults(tx: Transaction) {
|
|
74
|
+
throw new Error('Method not implemented.')
|
|
75
|
+
}
|
|
76
|
+
public valuateSymbols(tx: Transaction) {
|
|
77
|
+
throw new Error('Method not implemented.')
|
|
78
|
+
}
|
|
79
|
+
public valuate(tx: Transaction): { vaultsValuation: any; symbolsValuation: any } {
|
|
80
|
+
throw new Error('Method not implemented.')
|
|
81
|
+
}
|
|
82
|
+
public valuateMarket(): Promise<IBaseMarketValuationInfo> {
|
|
83
|
+
throw new Error('Method not implemented.')
|
|
84
|
+
}
|
|
85
|
+
public fundingFeeRate(indexToken: string, long: boolean): Promise<number> {
|
|
86
|
+
throw new Error('Method not implemented.')
|
|
87
|
+
}
|
|
88
|
+
public rebaseFeeRate(collateralToken: string, increase: boolean, amount: number): Promise<number> {
|
|
89
|
+
throw new Error('Method not implemented.')
|
|
90
|
+
}
|
|
91
|
+
public reservingFeeRate(collateralToken: string, amount: number): Promise<number> {
|
|
92
|
+
throw new Error('Method not implemented.')
|
|
93
|
+
}
|
|
94
|
+
public calcPositionReserveFeeAmount(position: IBasePositionInfo): Promise<number> {
|
|
95
|
+
throw new Error('Method not implemented.')
|
|
96
|
+
}
|
|
97
|
+
public calcPositionFundingFeeValue(position: IBasePositionInfo): Promise<number> {
|
|
98
|
+
throw new Error('Method not implemented.')
|
|
99
|
+
}
|
|
100
|
+
public getMarketInfo(): Promise<IBaseMarketInfo> {
|
|
101
|
+
throw new Error('Method not implemented.')
|
|
102
|
+
}
|
|
103
|
+
public getVaultInfo(vault: string): Promise<IBaseVaultInfo> {
|
|
104
|
+
throw new Error('Method not implemented.')
|
|
105
|
+
}
|
|
106
|
+
public getSymbolInfo(tokenId: string, long: boolean): Promise<IBaseSymbolInfo> {
|
|
107
|
+
throw new Error('Method not implemented.')
|
|
108
|
+
}
|
|
109
|
+
public getPositionConfig(indexToken: string, long: boolean): Promise<IBasePositionConfig> {
|
|
110
|
+
throw new Error('Method not implemented.')
|
|
111
|
+
}
|
|
112
|
+
public getRebaseFeeModel(): Promise<IBaseRebaseFeeModel> {
|
|
113
|
+
throw new Error('Method not implemented.')
|
|
114
|
+
}
|
|
115
|
+
public getOpenPositions(): Promise<IBasePositionInfo[]> {
|
|
116
|
+
throw new Error('Method not implemented.')
|
|
117
|
+
}
|
|
118
|
+
public getPositionCapInfoList(owner: string): Promise<IBasePositionCapInfo[]> {
|
|
119
|
+
throw new Error('Method not implemented.')
|
|
120
|
+
}
|
|
121
|
+
public getPositionInfoList(positionCapInfoList: IBasePositionCapInfo[], owner: string): Promise<IBasePositionInfo[]> {
|
|
122
|
+
throw new Error('Method not implemented.')
|
|
123
|
+
}
|
|
124
|
+
public getOrderCapInfoList(owner: string): Promise<IBaseOrderCapInfo[]> {
|
|
125
|
+
throw new Error('Method not implemented.')
|
|
126
|
+
}
|
|
127
|
+
public getOrderInfoList(orderCapInfoList: IBaseOrderCapInfo[], owner: string): Promise<IBaseOrderInfo[]> {
|
|
128
|
+
throw new Error('Method not implemented.')
|
|
129
|
+
}
|
|
130
|
+
public getHistory(trader: string, page: number, limit: number, orderType?: string, symbol?: string): Promise<IBaseHistoryResponse> {
|
|
131
|
+
throw new Error('Method not implemented.')
|
|
132
|
+
}
|
|
133
|
+
public getStaked(owner: string): Promise<IBaseStaked> {
|
|
134
|
+
throw new Error('Method not implemented.')
|
|
135
|
+
}
|
|
136
|
+
public getStakePool(): Promise<IBaseStakePool> {
|
|
137
|
+
throw new Error('Method not implemented.')
|
|
138
|
+
}
|
|
139
|
+
public hasReferral(referree: string): Promise<boolean> {
|
|
140
|
+
throw new Error('Method not implemented.')
|
|
141
|
+
}
|
|
142
|
+
public getReferralData(referree: string): Promise<any> {
|
|
143
|
+
throw new Error('Method not implemented.')
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Deposits collateral into USDZ vault
|
|
148
|
+
*/
|
|
149
|
+
public async deposit(
|
|
150
|
+
coin: string,
|
|
151
|
+
coinObjects: string[],
|
|
152
|
+
amount: number,
|
|
153
|
+
minAmountOut?: number,
|
|
154
|
+
referralAddress?: string,
|
|
155
|
+
sender?: string
|
|
156
|
+
): Promise<Transaction> {
|
|
157
|
+
let tx = await this.initOracleTxb(Object.keys(this.consts.pythFeeder.feeder))
|
|
158
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
159
|
+
tx = await this.addReferral(referralAddress, tx)
|
|
160
|
+
}
|
|
161
|
+
const coinObject = this.processCoins(tx, coin, coinObjects)
|
|
162
|
+
const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)])
|
|
163
|
+
|
|
164
|
+
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
|
|
165
|
+
|
|
166
|
+
tx.moveCall({
|
|
167
|
+
target: `${this.consts.zoCore.package}::market::deposit`,
|
|
168
|
+
typeArguments: [`${this.consts.zoCore.package}::usdz::USDZ`, this.consts.coins[coin].module],
|
|
169
|
+
arguments: [
|
|
170
|
+
tx.object(this.consts.zoCore.market),
|
|
171
|
+
tx.object(this.consts.zoCore.rebaseFeeModel),
|
|
172
|
+
depositObject,
|
|
173
|
+
tx.pure.u64(minAmountOut || 0),
|
|
174
|
+
vaultsValuation,
|
|
175
|
+
symbolsValuation,
|
|
176
|
+
],
|
|
177
|
+
})
|
|
178
|
+
return tx
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Withdraws collateral from USDZ vault
|
|
183
|
+
*/
|
|
184
|
+
public async withdraw(
|
|
185
|
+
coin: string,
|
|
186
|
+
lpCoinObjects: string[],
|
|
187
|
+
amount: number,
|
|
188
|
+
minAmountOut?: number
|
|
189
|
+
): Promise<Transaction> {
|
|
190
|
+
const tx = await this.initOracleTxb(Object.keys(this.consts.pythFeeder.feeder))
|
|
191
|
+
const usdzCoinObject = this.processCoins(tx, 'usdz', lpCoinObjects)
|
|
192
|
+
const [withdrawObject] = tx.splitCoins(usdzCoinObject, [tx.pure.u64(amount)])
|
|
193
|
+
|
|
194
|
+
const { vaultsValuation, symbolsValuation } = this.valuate(tx)
|
|
195
|
+
|
|
196
|
+
tx.moveCall({
|
|
197
|
+
target: `${this.consts.zoCore.package}::market::withdraw`,
|
|
198
|
+
typeArguments: [`${this.consts.zoCore.package}::usdz::USDZ`, this.consts.coins[coin].module],
|
|
199
|
+
arguments: [
|
|
200
|
+
tx.object(this.consts.zoCore.market),
|
|
201
|
+
tx.object(this.consts.zoCore.rebaseFeeModel),
|
|
202
|
+
withdrawObject,
|
|
203
|
+
tx.pure.u64(minAmountOut || 0),
|
|
204
|
+
vaultsValuation,
|
|
205
|
+
symbolsValuation,
|
|
206
|
+
],
|
|
207
|
+
})
|
|
208
|
+
return tx
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
public async swap(
|
|
213
|
+
fromToken: string,
|
|
214
|
+
toToken: string,
|
|
215
|
+
fromAmount: bigint,
|
|
216
|
+
fromCoinObjects: string[],
|
|
217
|
+
minAmountOut?: number
|
|
218
|
+
): Promise<Transaction> {
|
|
219
|
+
const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults))
|
|
220
|
+
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects)
|
|
221
|
+
const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)])
|
|
222
|
+
const vaultsValuation = this.dataAPI.valuateVaults(tx)
|
|
223
|
+
|
|
224
|
+
tx.moveCall({
|
|
225
|
+
target: `${this.consts.zoCore.package}::market::swap`,
|
|
226
|
+
typeArguments: [
|
|
227
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
228
|
+
this.consts.coins[fromToken].module,
|
|
229
|
+
this.consts.coins[toToken].module,
|
|
230
|
+
],
|
|
231
|
+
arguments: [
|
|
232
|
+
tx.object(this.consts.zoCore.market),
|
|
233
|
+
tx.object(this.consts.zoCore.rebaseFeeModel),
|
|
234
|
+
fromDepositObject,
|
|
235
|
+
tx.pure.u64(minAmountOut || 0),
|
|
236
|
+
vaultsValuation,
|
|
237
|
+
],
|
|
238
|
+
})
|
|
239
|
+
return tx
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Opens a new position in USDZ
|
|
244
|
+
*/
|
|
245
|
+
public async openPosition(
|
|
246
|
+
collateralToken: string,
|
|
247
|
+
indexToken: string,
|
|
248
|
+
size: bigint,
|
|
249
|
+
collateralAmount: bigint,
|
|
250
|
+
coinObjects: string[],
|
|
251
|
+
long: boolean,
|
|
252
|
+
reserveAmount: bigint,
|
|
253
|
+
indexPrice: number,
|
|
254
|
+
collateralPrice: number,
|
|
255
|
+
isLimitOrder?: boolean,
|
|
256
|
+
isIocOrder?: boolean,
|
|
257
|
+
pricesSlippage?: number,
|
|
258
|
+
collateralSlippage?: number,
|
|
259
|
+
relayerFee?: bigint,
|
|
260
|
+
referralAddress?: string,
|
|
261
|
+
sender?: string
|
|
262
|
+
): Promise<Transaction> {
|
|
263
|
+
let tx = new Transaction()
|
|
264
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
265
|
+
tx = await this.addReferral(referralAddress, tx)
|
|
266
|
+
}
|
|
267
|
+
tx = await this.initOracleTxb([collateralToken, indexToken], tx)
|
|
268
|
+
const coinObject = this.processCoins(tx, collateralToken, coinObjects)
|
|
269
|
+
const [depositObject, feeObject] = tx.splitCoins(coinObject, [
|
|
270
|
+
tx.pure.u64(collateralAmount),
|
|
271
|
+
tx.pure.u64(relayerFee || BigInt(0.5)),
|
|
272
|
+
])
|
|
273
|
+
|
|
274
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
275
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage || 0.003)
|
|
276
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage || 0.5)
|
|
277
|
+
|
|
278
|
+
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
279
|
+
if (isLimitOrder) {
|
|
280
|
+
allowTrade = isIocOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
tx.moveCall({
|
|
284
|
+
target: `${this.consts.zoCore.package}::market::open_position`,
|
|
285
|
+
typeArguments: [
|
|
286
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
287
|
+
this.consts.coins[collateralToken].module,
|
|
288
|
+
this.consts.coins[indexToken].module,
|
|
289
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
290
|
+
this.consts.coins[collateralToken].module,
|
|
291
|
+
],
|
|
292
|
+
arguments: [
|
|
293
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
294
|
+
tx.object(this.consts.zoCore.market),
|
|
295
|
+
tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
|
|
296
|
+
tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
|
|
297
|
+
tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
|
|
298
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
299
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
300
|
+
depositObject,
|
|
301
|
+
feeObject,
|
|
302
|
+
tx.pure.u8(allowTrade),
|
|
303
|
+
tx.pure.u64(size),
|
|
304
|
+
tx.pure.u64(reserveAmount),
|
|
305
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
306
|
+
tx.pure.u256(adjustPrice),
|
|
307
|
+
],
|
|
308
|
+
})
|
|
309
|
+
return tx
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Decreases an existing position in USDZ
|
|
314
|
+
*/
|
|
315
|
+
public async decreasePosition(
|
|
316
|
+
pcpId: string,
|
|
317
|
+
collateralToken: string,
|
|
318
|
+
indexToken: string,
|
|
319
|
+
amount: bigint,
|
|
320
|
+
long: boolean,
|
|
321
|
+
indexPrice: number,
|
|
322
|
+
collateralPrice: number,
|
|
323
|
+
isTriggerOrder = false,
|
|
324
|
+
isTakeProfitOrder = true,
|
|
325
|
+
isIocOrder = false,
|
|
326
|
+
pricesSlippage: number = 0.003,
|
|
327
|
+
collateralSlippage: number = 0.5,
|
|
328
|
+
relayerFee = BigInt(0.5),
|
|
329
|
+
coinObjects?: string[]
|
|
330
|
+
): Promise<Transaction> {
|
|
331
|
+
const tx = await this.initOracleTxb([collateralToken, indexToken])
|
|
332
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
333
|
+
const coinObject = this.processCoins(tx, collateralToken, coinObjects || [])
|
|
334
|
+
const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)])
|
|
335
|
+
|
|
336
|
+
const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
|
|
337
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
|
|
338
|
+
|
|
339
|
+
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
340
|
+
if (isTriggerOrder) {
|
|
341
|
+
allowTrade = isIocOrder || !isTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
342
|
+
} else {
|
|
343
|
+
isTakeProfitOrder = true
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
tx.moveCall({
|
|
347
|
+
target: `${this.consts.zoCore.package}::market::decrease_position`,
|
|
348
|
+
typeArguments: [
|
|
349
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
350
|
+
this.consts.coins[collateralToken].module,
|
|
351
|
+
this.consts.coins[indexToken].module,
|
|
352
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
353
|
+
this.consts.coins[collateralToken].module,
|
|
354
|
+
],
|
|
355
|
+
arguments: [
|
|
356
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
357
|
+
tx.object(this.consts.zoCore.market),
|
|
358
|
+
tx.object(pcpId),
|
|
359
|
+
tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
|
|
360
|
+
tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
|
|
361
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
362
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
363
|
+
feeObject,
|
|
364
|
+
tx.pure.u8(allowTrade),
|
|
365
|
+
tx.pure.bool(isTakeProfitOrder),
|
|
366
|
+
tx.pure.u64(amount),
|
|
367
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
368
|
+
tx.pure.u256(adjustPrice),
|
|
369
|
+
],
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
return tx
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
public async decreaseMultiPositions(positions: Array<{
|
|
376
|
+
pcpId: string,
|
|
377
|
+
collateralToken: string,
|
|
378
|
+
coinObjects: string[],
|
|
379
|
+
indexToken: string,
|
|
380
|
+
amount: bigint,
|
|
381
|
+
long: boolean,
|
|
382
|
+
indexPrice: number,
|
|
383
|
+
collateralPrice: number,
|
|
384
|
+
isTriggerOrder: boolean,
|
|
385
|
+
isTakeProfitOrder: boolean,
|
|
386
|
+
isIocOrder: boolean,
|
|
387
|
+
slippage: number,
|
|
388
|
+
relayerFee: bigint,
|
|
389
|
+
}>, tx?: Transaction): Promise<Transaction> {
|
|
390
|
+
if (!tx) {
|
|
391
|
+
tx = new Transaction()
|
|
392
|
+
}
|
|
393
|
+
tx = await this.initOracleTxb(positions.map(position => [position.collateralToken, position.indexToken]).flat(), tx)
|
|
394
|
+
|
|
395
|
+
for (const position of positions) {
|
|
396
|
+
const {
|
|
397
|
+
pcpId,
|
|
398
|
+
collateralToken,
|
|
399
|
+
coinObjects, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder, isTakeProfitOrder, isIocOrder, slippage, relayerFee
|
|
400
|
+
} = position
|
|
401
|
+
let innerIsTakeProfitOrder = isTakeProfitOrder
|
|
402
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
403
|
+
const coinObject = this.processCoins(tx, collateralToken, coinObjects)
|
|
404
|
+
const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)])
|
|
405
|
+
|
|
406
|
+
const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : slippage)
|
|
407
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, 0.5)
|
|
408
|
+
|
|
409
|
+
let allowTrade = ALLOW_TRADE_MUST_TRADE
|
|
410
|
+
if (isTriggerOrder) {
|
|
411
|
+
allowTrade = isIocOrder || !innerIsTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
|
|
412
|
+
} else {
|
|
413
|
+
innerIsTakeProfitOrder = true
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
tx.moveCall({
|
|
417
|
+
target: `${this.consts.zoCore.package}::market::decrease_position`,
|
|
418
|
+
typeArguments: [
|
|
419
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
420
|
+
this.consts.coins[collateralToken].module,
|
|
421
|
+
this.consts.coins[indexToken].module,
|
|
422
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
423
|
+
this.consts.coins[collateralToken].module,
|
|
424
|
+
],
|
|
425
|
+
arguments: [
|
|
426
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
427
|
+
tx.object(this.consts.zoCore.market),
|
|
428
|
+
tx.object(pcpId),
|
|
429
|
+
tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
|
|
430
|
+
tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
|
|
431
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
432
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
433
|
+
feeObject,
|
|
434
|
+
tx.pure.u8(allowTrade),
|
|
435
|
+
tx.pure.bool(innerIsTakeProfitOrder),
|
|
436
|
+
tx.pure.u64(amount),
|
|
437
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
438
|
+
tx.pure.u256(adjustPrice),
|
|
439
|
+
],
|
|
440
|
+
})
|
|
441
|
+
}
|
|
442
|
+
return tx
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Pledges in position (USDZ-specific functionality)
|
|
447
|
+
*/
|
|
448
|
+
public async pledgeInPosition(
|
|
449
|
+
pcpId: string,
|
|
450
|
+
collateralToken: string,
|
|
451
|
+
indexToken: string,
|
|
452
|
+
amount: number,
|
|
453
|
+
coinObjects: string[],
|
|
454
|
+
long: boolean
|
|
455
|
+
): Promise<Transaction> {
|
|
456
|
+
const tx = await this.initOracleTxb([collateralToken, indexToken])
|
|
457
|
+
const coinObject = this.processCoins(tx, collateralToken, coinObjects)
|
|
458
|
+
const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)])
|
|
459
|
+
|
|
460
|
+
tx.moveCall({
|
|
461
|
+
target: `${this.consts.zoCore.package}::market::pledge_in_position`,
|
|
462
|
+
typeArguments: [
|
|
463
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
464
|
+
this.consts.coins[collateralToken].module,
|
|
465
|
+
this.consts.coins[indexToken].module,
|
|
466
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
467
|
+
],
|
|
468
|
+
arguments: [tx.object(this.consts.zoCore.market), tx.object(pcpId), depositObject],
|
|
469
|
+
})
|
|
470
|
+
return tx
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
public async redeemFromPosition(
|
|
474
|
+
pcpId: string,
|
|
475
|
+
collateralToken: string,
|
|
476
|
+
indexToken: string,
|
|
477
|
+
amount: number,
|
|
478
|
+
long: boolean,
|
|
479
|
+
): Promise<Transaction> {
|
|
480
|
+
const tx = await this.initOracleTxb([collateralToken, indexToken])
|
|
481
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
482
|
+
|
|
483
|
+
tx.moveCall({
|
|
484
|
+
target: `${this.consts.zoCore.package}::market::redeem_from_position`,
|
|
485
|
+
typeArguments: [
|
|
486
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
487
|
+
this.consts.coins[collateralToken].module,
|
|
488
|
+
this.consts.coins[indexToken].module,
|
|
489
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
490
|
+
],
|
|
491
|
+
arguments: [
|
|
492
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
493
|
+
tx.object(this.consts.zoCore.market),
|
|
494
|
+
tx.object(pcpId),
|
|
495
|
+
tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
|
|
496
|
+
tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
|
|
497
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
498
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
499
|
+
tx.pure.u64(amount),
|
|
500
|
+
],
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
return tx
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
public async cancelOrder(
|
|
507
|
+
orderCapId: string,
|
|
508
|
+
collateralToken: string,
|
|
509
|
+
indexToken: string,
|
|
510
|
+
long: boolean,
|
|
511
|
+
type: string,
|
|
512
|
+
isV11Order?: boolean
|
|
513
|
+
): Promise<Transaction> {
|
|
514
|
+
const tx = new Transaction()
|
|
515
|
+
let functionName = ''
|
|
516
|
+
switch (type) {
|
|
517
|
+
case 'OPEN_POSITION': {
|
|
518
|
+
functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order'
|
|
519
|
+
break
|
|
520
|
+
}
|
|
521
|
+
case 'DECREASE_POSITION': {
|
|
522
|
+
functionName = isV11Order
|
|
523
|
+
? 'clear_decrease_position_order'
|
|
524
|
+
: 'clear_decrease_position_order'
|
|
525
|
+
break
|
|
526
|
+
}
|
|
527
|
+
default: {
|
|
528
|
+
throw new Error('invalid order type')
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
tx.moveCall({
|
|
532
|
+
target: `${this.consts.zoCore.package}::market::${functionName}`,
|
|
533
|
+
typeArguments: [
|
|
534
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
535
|
+
this.consts.coins[collateralToken].module,
|
|
536
|
+
this.consts.coins[indexToken].module,
|
|
537
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
538
|
+
this.consts.coins[collateralToken].module,
|
|
539
|
+
],
|
|
540
|
+
arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
|
|
541
|
+
})
|
|
542
|
+
return tx
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
public async cancelMultiOrders(
|
|
546
|
+
orders: Array<{
|
|
547
|
+
orderCapId: string,
|
|
548
|
+
collateralToken: string,
|
|
549
|
+
indexToken: string,
|
|
550
|
+
long: boolean,
|
|
551
|
+
type: string,
|
|
552
|
+
isV11Order?: boolean
|
|
553
|
+
}>, tx?: Transaction
|
|
554
|
+
): Promise<Transaction> {
|
|
555
|
+
if (!tx) {
|
|
556
|
+
tx = new Transaction()
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
for (const order of orders) {
|
|
560
|
+
const { orderCapId, collateralToken, indexToken, long, type, isV11Order } = order
|
|
561
|
+
let functionName = ''
|
|
562
|
+
switch (type) {
|
|
563
|
+
case 'OPEN_POSITION': {
|
|
564
|
+
functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order'
|
|
565
|
+
break
|
|
566
|
+
}
|
|
567
|
+
case 'DECREASE_POSITION': {
|
|
568
|
+
functionName = isV11Order
|
|
569
|
+
? 'clear_decrease_position_order'
|
|
570
|
+
: 'clear_decrease_position_order'
|
|
571
|
+
break
|
|
572
|
+
}
|
|
573
|
+
default: {
|
|
574
|
+
throw new Error('invalid order type')
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
tx.moveCall({
|
|
579
|
+
target: `${this.consts.zoCore.package}::market::${functionName}`,
|
|
580
|
+
typeArguments: [
|
|
581
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
582
|
+
this.consts.coins[collateralToken].module,
|
|
583
|
+
this.consts.coins[indexToken].module,
|
|
584
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
585
|
+
this.consts.coins[collateralToken].module,
|
|
586
|
+
],
|
|
587
|
+
arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
|
|
588
|
+
})
|
|
589
|
+
}
|
|
590
|
+
return tx
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
public addReferral(
|
|
594
|
+
referralAddress: string,
|
|
595
|
+
tx?: Transaction
|
|
596
|
+
): Transaction {
|
|
597
|
+
if (!tx) {
|
|
598
|
+
tx = new Transaction()
|
|
599
|
+
}
|
|
600
|
+
tx.moveCall({
|
|
601
|
+
target: `${this.consts.zoCore.package}::market::add_new_referral`,
|
|
602
|
+
typeArguments: [`${this.consts.zoCore.package}::usdz::USDZ`],
|
|
603
|
+
arguments: [tx.object(this.consts.zoCore.market), tx.object(referralAddress)],
|
|
604
|
+
})
|
|
605
|
+
|
|
606
|
+
return tx
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
public async adminUpdatePriceFeed(
|
|
610
|
+
collateralToken: string,
|
|
611
|
+
indexToken: string
|
|
612
|
+
): Promise<Transaction> {
|
|
613
|
+
const tx = await this.initOracleTxb([collateralToken, indexToken])
|
|
614
|
+
return tx
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
public async adminSettlePosition(
|
|
618
|
+
positionId: string,
|
|
619
|
+
owner: string,
|
|
620
|
+
collateralToken: string,
|
|
621
|
+
indexToken: string,
|
|
622
|
+
long: boolean
|
|
623
|
+
): Promise<Transaction> {
|
|
624
|
+
const tx = new Transaction()
|
|
625
|
+
|
|
626
|
+
tx.moveCall({
|
|
627
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::force_settle_position`,
|
|
628
|
+
typeArguments: [
|
|
629
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
630
|
+
this.consts.coins[collateralToken].module,
|
|
631
|
+
this.consts.coins[indexToken].module,
|
|
632
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
633
|
+
],
|
|
634
|
+
arguments: [
|
|
635
|
+
tx.object(this.consts.zoCore.adminCap),
|
|
636
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
637
|
+
tx.object(this.consts.zoCore.market),
|
|
638
|
+
tx.object(owner),
|
|
639
|
+
tx.object(positionId),
|
|
640
|
+
],
|
|
641
|
+
})
|
|
642
|
+
|
|
643
|
+
this.adminClearClosedPosition(positionId, owner, collateralToken, indexToken, long, tx)
|
|
644
|
+
|
|
645
|
+
return tx
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
public async adminDecreasePosition(
|
|
649
|
+
positionId: string,
|
|
650
|
+
owner: string,
|
|
651
|
+
collateralToken: string,
|
|
652
|
+
indexToken: string,
|
|
653
|
+
positionAmount: number,
|
|
654
|
+
amount: bigint,
|
|
655
|
+
long: boolean,
|
|
656
|
+
collateralPrice?: number,
|
|
657
|
+
collateralSlippage?: number,
|
|
658
|
+
relayerFee?: bigint
|
|
659
|
+
): Promise<Transaction> {
|
|
660
|
+
const tx = new Transaction()
|
|
661
|
+
const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
|
|
662
|
+
|
|
663
|
+
tx.moveCall({
|
|
664
|
+
target: `${this.consts.zoCore.package}::market::force_close_position`,
|
|
665
|
+
typeArguments: [
|
|
666
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
667
|
+
this.consts.coins[collateralToken].module,
|
|
668
|
+
this.consts.coins[indexToken].module,
|
|
669
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
670
|
+
],
|
|
671
|
+
arguments: [
|
|
672
|
+
tx.object(this.consts.zoCore.adminCap),
|
|
673
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
674
|
+
tx.object(this.consts.zoCore.market),
|
|
675
|
+
tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
|
|
676
|
+
tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
|
|
677
|
+
tx.object(this.consts.pythFeeder.feeder[collateralToken]),
|
|
678
|
+
tx.object(this.consts.pythFeeder.feeder[indexToken]),
|
|
679
|
+
tx.object(owner),
|
|
680
|
+
tx.object(positionId),
|
|
681
|
+
],
|
|
682
|
+
})
|
|
683
|
+
|
|
684
|
+
if (amount === BigInt(positionAmount)) {
|
|
685
|
+
this.adminClearClosedPosition(positionId, owner, collateralToken, indexToken, long, tx)
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
return tx
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
public async adminClearClosedPosition(
|
|
692
|
+
positionId: string,
|
|
693
|
+
owner: string,
|
|
694
|
+
collateralToken: string,
|
|
695
|
+
indexToken: string,
|
|
696
|
+
long: boolean,
|
|
697
|
+
tx: Transaction
|
|
698
|
+
): Promise<void> {
|
|
699
|
+
tx.moveCall({
|
|
700
|
+
target: `${this.consts.zoCore.package}::market::force_clear_closed_position`,
|
|
701
|
+
typeArguments: [
|
|
702
|
+
`${this.consts.zoCore.package}::usdz::USDZ`,
|
|
703
|
+
this.consts.coins[collateralToken].module,
|
|
704
|
+
this.consts.coins[indexToken].module,
|
|
705
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
706
|
+
],
|
|
707
|
+
arguments: [
|
|
708
|
+
tx.object(this.consts.zoCore.adminCap),
|
|
709
|
+
tx.object(this.consts.zoCore.market),
|
|
710
|
+
tx.object(positionId),
|
|
711
|
+
tx.object(owner),
|
|
712
|
+
],
|
|
713
|
+
})
|
|
714
|
+
}
|
|
715
|
+
}
|