@zofai/zo-sdk 0.2.29 → 0.2.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abstract/BaseAPI.cjs +3 -0
- package/dist/abstract/BaseAPI.cjs.map +1 -1
- package/dist/abstract/BaseAPI.d.cts +3 -2
- package/dist/abstract/BaseAPI.d.cts.map +1 -1
- package/dist/abstract/BaseAPI.d.mts +3 -2
- package/dist/abstract/BaseAPI.d.mts.map +1 -1
- package/dist/abstract/BaseAPI.mjs +3 -0
- package/dist/abstract/BaseAPI.mjs.map +1 -1
- package/dist/abstract/BaseDataAPI.cjs +48 -2
- package/dist/abstract/BaseDataAPI.cjs.map +1 -1
- package/dist/abstract/BaseDataAPI.d.cts +15 -2
- package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
- package/dist/abstract/BaseDataAPI.d.mts +15 -2
- package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
- package/dist/abstract/BaseDataAPI.mjs +48 -2
- package/dist/abstract/BaseDataAPI.mjs.map +1 -1
- package/dist/consts/deployments-zlp-mainnet.json +1 -1
- package/dist/consts/deployments-zo-oracle-mainnet.json +18 -1
- package/dist/data.cjs +19 -7
- package/dist/data.cjs.map +1 -1
- package/dist/data.d.cts.map +1 -1
- package/dist/data.d.mts.map +1 -1
- package/dist/data.mjs +19 -7
- package/dist/data.mjs.map +1 -1
- package/dist/implementations/SLPDataAPI.cjs +26 -8
- package/dist/implementations/SLPDataAPI.cjs.map +1 -1
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/SLPDataAPI.mjs +26 -8
- package/dist/implementations/SLPDataAPI.mjs.map +1 -1
- package/dist/implementations/USDZDataAPI.cjs +26 -8
- package/dist/implementations/USDZDataAPI.cjs.map +1 -1
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
- package/dist/implementations/USDZDataAPI.mjs +26 -8
- package/dist/implementations/USDZDataAPI.mjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.cjs +19 -7
- package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.mjs +19 -7
- package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -1
- package/dist/implementations/ZLPAPI.cjs +456 -123
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +46 -1
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +46 -1
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +457 -124
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.cjs +64 -8
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.cts +16 -0
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.mts +16 -0
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPDataAPI.mjs +64 -8
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +14 -1
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +14 -1
- package/dist/interfaces/base.d.mts.map +1 -1
- package/dist/interfaces/zlp.d.cts +19 -0
- package/dist/interfaces/zlp.d.cts.map +1 -1
- package/dist/interfaces/zlp.d.mts +19 -0
- package/dist/interfaces/zlp.d.mts.map +1 -1
- package/dist/traderPositions.cjs +130 -0
- package/dist/traderPositions.cjs.map +1 -0
- package/dist/traderPositions.d.cts +72 -0
- package/dist/traderPositions.d.cts.map +1 -0
- package/dist/traderPositions.d.mts +72 -0
- package/dist/traderPositions.d.mts.map +1 -0
- package/dist/traderPositions.mjs +124 -0
- package/dist/traderPositions.mjs.map +1 -0
- package/docs/api-reference.md +45 -0
- package/docs/architecture.md +21 -3
- package/docs/common-operations.md +56 -8
- package/docs/getting-started.md +8 -3
- package/docs/lp-specific-features.md +89 -12
- package/docs/swap-integration.md +52 -20
- package/package.json +1 -1
- package/src/abstract/BaseAPI.ts +6 -2
- package/src/abstract/BaseDataAPI.ts +67 -3
- package/src/consts/deployments-zlp-mainnet.json +1 -1
- package/src/consts/deployments-zo-oracle-mainnet.json +18 -1
- package/src/data.ts +19 -7
- package/src/implementations/SLPDataAPI.ts +34 -16
- package/src/implementations/USDZDataAPI.ts +32 -14
- package/src/implementations/ZBTCVCDataAPI.ts +23 -11
- package/src/implementations/ZLPAPI.ts +760 -151
- package/src/implementations/ZLPDataAPI.ts +79 -14
- package/src/index.ts +2 -0
- package/src/interfaces/base.ts +15 -1
- package/src/interfaces/zlp.ts +170 -0
- package/src/traderPositions.ts +218 -0
|
@@ -9,7 +9,9 @@ const kiosk_1 = require("@mysten/kiosk");
|
|
|
9
9
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
10
10
|
const utils_1 = require("@mysten/sui/utils");
|
|
11
11
|
const abstract_1 = require("../abstract/index.cjs");
|
|
12
|
+
const coins_1 = require("../coins.cjs");
|
|
12
13
|
const consts_1 = require("../consts/index.cjs");
|
|
14
|
+
const oraclePro_1 = require("../oraclePro.cjs");
|
|
13
15
|
const utils_2 = require("../utils.cjs");
|
|
14
16
|
const ZLPDataAPI_1 = require("./ZLPDataAPI.cjs");
|
|
15
17
|
class ZLPAPI extends abstract_1.BaseAPI {
|
|
@@ -17,6 +19,59 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
17
19
|
super(network, provider, apiEndpoint, connectionURL, consts_1.LPToken.ZLP);
|
|
18
20
|
this.dataAPI = new ZLPDataAPI_1.ZLPDataAPI(network, provider, apiEndpoint, connectionURL);
|
|
19
21
|
}
|
|
22
|
+
zlpLpType() {
|
|
23
|
+
return `${this.consts.zoCore.package}::zlp::ZLP`;
|
|
24
|
+
}
|
|
25
|
+
positionTypeArgs(collateralToken, indexToken, long) {
|
|
26
|
+
return [
|
|
27
|
+
this.zlpLpType(),
|
|
28
|
+
this.consts.coins[collateralToken].module,
|
|
29
|
+
this.consts.coins[indexToken].module,
|
|
30
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
31
|
+
this.consts.coins[collateralToken].module,
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
redeemTypeArgs(collateralToken, indexToken, long) {
|
|
35
|
+
return [
|
|
36
|
+
this.zlpLpType(),
|
|
37
|
+
this.consts.coins[collateralToken].module,
|
|
38
|
+
this.consts.coins[indexToken].module,
|
|
39
|
+
`${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
async initV3OracleForTokens(tokens, tx, pythProUpdateBytes, includeEmaPrice, options) {
|
|
43
|
+
const result = await this.initV3OracleTxb(tokens, tx, {
|
|
44
|
+
rawUpdateBytes: pythProUpdateBytes,
|
|
45
|
+
includeEmaPrice,
|
|
46
|
+
...options,
|
|
47
|
+
});
|
|
48
|
+
return { tx: result.tx, oracle: result.oracle };
|
|
49
|
+
}
|
|
50
|
+
/** Vault + symbol index tokens required for valuate_vault_v2 / valuate_symbol_v2. */
|
|
51
|
+
getValuationOracleTokens() {
|
|
52
|
+
const tokens = new Set(Object.keys(this.consts.zoCore.vaults));
|
|
53
|
+
for (const key of Object.keys(this.consts.zoCore.symbols)) {
|
|
54
|
+
const [, token] = (0, utils_2.parseSymbolKey)(key);
|
|
55
|
+
tokens.add(token);
|
|
56
|
+
}
|
|
57
|
+
return [...tokens];
|
|
58
|
+
}
|
|
59
|
+
/** Pyth Pro oracle init for deposit / withdraw market valuation. */
|
|
60
|
+
async initValuationOracle(tx) {
|
|
61
|
+
const tokens = this.getValuationOracleTokens();
|
|
62
|
+
const pythProUpdateBytes = await this.fetchPythProUpdateBytesForTokens(tokens);
|
|
63
|
+
return this.initV3OracleForTokens(tokens, tx, pythProUpdateBytes);
|
|
64
|
+
}
|
|
65
|
+
async resolveSponsoredSui(tx, collateralToken, relayerFee, sponsoredTx, sender) {
|
|
66
|
+
if (!sponsoredTx) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const additional = collateralToken === 'sui' ? relayerFee : 0n;
|
|
70
|
+
if (additional === 0n) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
return (0, coins_1.resolveSpendableSuiCoin)(tx, this.provider, this.requireSenderForSponsored(sender), additional);
|
|
74
|
+
}
|
|
20
75
|
calcPositionReserveFeeAmount(_position) {
|
|
21
76
|
throw new Error(`Method not implemented in ${this.constructor.name}.`);
|
|
22
77
|
}
|
|
@@ -32,35 +87,10 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
32
87
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
33
88
|
tx = await this.addReferral(referralAddress, tx);
|
|
34
89
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
40
|
-
sender: this.requireSenderForSponsored(sender),
|
|
41
|
-
additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
|
|
42
|
-
});
|
|
43
|
-
tx = oracle.tx;
|
|
44
|
-
const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sponsoredTx: true, suiCoinObject: oracle.suiCoinObject, sender });
|
|
45
|
-
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
46
|
-
tx.moveCall({
|
|
47
|
-
target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
|
|
48
|
-
typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`, this.consts.coins[coin].module],
|
|
49
|
-
arguments: [
|
|
50
|
-
tx.object(this.consts.zoCore.market),
|
|
51
|
-
tx.object(this.consts.zoCore.rebaseFeeModel),
|
|
52
|
-
depositObject,
|
|
53
|
-
tx.pure.u64(minAmountOut),
|
|
54
|
-
vaultsValuation,
|
|
55
|
-
symbolsValuation,
|
|
56
|
-
],
|
|
57
|
-
});
|
|
58
|
-
return tx;
|
|
59
|
-
}
|
|
60
|
-
// Handle non-sponsored transaction case
|
|
61
|
-
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
62
|
-
const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sender });
|
|
63
|
-
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
90
|
+
const { tx: txWithOracle, oracle: oracleBundle } = await this.initValuationOracle(tx);
|
|
91
|
+
tx = txWithOracle;
|
|
92
|
+
const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sponsoredTx, sender });
|
|
93
|
+
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV2(tx, oracleBundle);
|
|
64
94
|
tx.moveCall({
|
|
65
95
|
target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
|
|
66
96
|
typeArguments: [
|
|
@@ -89,35 +119,10 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
89
119
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
90
120
|
tx = await this.addReferral(referralAddress, tx);
|
|
91
121
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
97
|
-
sender: this.requireSenderForSponsored(sender),
|
|
98
|
-
additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
|
|
99
|
-
});
|
|
100
|
-
tx = oracle.tx;
|
|
101
|
-
const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sponsoredTx: true, suiCoinObject: oracle.suiCoinObject, sender });
|
|
102
|
-
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
103
|
-
const [mintedCoin] = tx.moveCall({
|
|
104
|
-
target: `${this.consts.zoCore.upgradedPackage}::market::deposit_ptb`,
|
|
105
|
-
typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`, this.consts.coins[coin].module],
|
|
106
|
-
arguments: [
|
|
107
|
-
tx.object(this.consts.zoCore.market),
|
|
108
|
-
tx.object(this.consts.zoCore.rebaseFeeModel),
|
|
109
|
-
depositObject,
|
|
110
|
-
tx.pure.u64(minAmountOut),
|
|
111
|
-
vaultsValuation,
|
|
112
|
-
symbolsValuation,
|
|
113
|
-
],
|
|
114
|
-
});
|
|
115
|
-
return mintedCoin;
|
|
116
|
-
}
|
|
117
|
-
// Handle non-sponsored transaction case
|
|
118
|
-
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
119
|
-
const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sender });
|
|
120
|
-
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
122
|
+
const { tx: txWithOracle, oracle: oracleBundle } = await this.initValuationOracle(tx);
|
|
123
|
+
tx = txWithOracle;
|
|
124
|
+
const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sponsoredTx, sender });
|
|
125
|
+
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV2(tx, oracleBundle);
|
|
121
126
|
const [mintedCoin] = tx.moveCall({
|
|
122
127
|
target: `${this.consts.zoCore.upgradedPackage}::market::deposit_ptb`,
|
|
123
128
|
typeArguments: [
|
|
@@ -135,7 +140,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
135
140
|
});
|
|
136
141
|
return mintedCoin;
|
|
137
142
|
}
|
|
138
|
-
async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx,
|
|
143
|
+
async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, _sponsoredTx) {
|
|
139
144
|
if (!tx) {
|
|
140
145
|
tx = new transactions_1.Transaction();
|
|
141
146
|
}
|
|
@@ -143,34 +148,9 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
143
148
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
144
149
|
tx = await this.addReferral(referralAddress, tx);
|
|
145
150
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (sponsoredTx) {
|
|
150
|
-
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
151
|
-
sender: this.requireSenderForSponsored(sender),
|
|
152
|
-
additionalSuiAmount: 0n,
|
|
153
|
-
});
|
|
154
|
-
tx = oracle.tx;
|
|
155
|
-
const { suiCoinObject } = oracle;
|
|
156
|
-
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
157
|
-
tx.moveCall({
|
|
158
|
-
target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
|
|
159
|
-
typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`, this.consts.coins[coin].module],
|
|
160
|
-
arguments: [
|
|
161
|
-
tx.object(this.consts.zoCore.market),
|
|
162
|
-
tx.object(this.consts.zoCore.rebaseFeeModel),
|
|
163
|
-
depositObject,
|
|
164
|
-
tx.pure.u64(minAmountOut),
|
|
165
|
-
vaultsValuation,
|
|
166
|
-
symbolsValuation,
|
|
167
|
-
],
|
|
168
|
-
});
|
|
169
|
-
return tx;
|
|
170
|
-
}
|
|
171
|
-
// Handle non-sponsored transaction case
|
|
172
|
-
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
173
|
-
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
151
|
+
const { tx: txWithOracle, oracle: oracleBundle } = await this.initValuationOracle(tx);
|
|
152
|
+
tx = txWithOracle;
|
|
153
|
+
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV2(tx, oracleBundle);
|
|
174
154
|
tx.moveCall({
|
|
175
155
|
target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
|
|
176
156
|
typeArguments: [
|
|
@@ -196,22 +176,10 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
196
176
|
throw new Error(`${this.constructor.name}: lpCoinObjects or sender is required`);
|
|
197
177
|
}
|
|
198
178
|
let tx = new transactions_1.Transaction();
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
204
|
-
sender: this.requireSenderForSponsored(sender),
|
|
205
|
-
additionalSuiAmount: 0n,
|
|
206
|
-
});
|
|
207
|
-
tx = oracle.tx;
|
|
208
|
-
suiCoinObject = oracle.suiCoinObject;
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
212
|
-
}
|
|
213
|
-
const withdrawObject = await this.resolveSplitCoinObject(tx, 'zlp', BigInt(amount), lpCoinObjects, { sponsoredTx, suiCoinObject, sender });
|
|
214
|
-
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
179
|
+
const { tx: txWithOracle, oracle: oracleBundle } = await this.initValuationOracle(tx);
|
|
180
|
+
tx = txWithOracle;
|
|
181
|
+
const withdrawObject = await this.resolveSplitCoinObject(tx, 'zlp', BigInt(amount), lpCoinObjects, { sponsoredTx, sender });
|
|
182
|
+
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV2(tx, oracleBundle);
|
|
215
183
|
tx.moveCall({
|
|
216
184
|
target: `${this.consts.zoCore.upgradedPackage}::market::withdraw`,
|
|
217
185
|
typeArguments: [
|
|
@@ -236,10 +204,9 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
236
204
|
if (!tx) {
|
|
237
205
|
tx = new transactions_1.Transaction();
|
|
238
206
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
207
|
+
const { tx: txWithOracle, oracle: oracleBundle } = await this.initValuationOracle(tx);
|
|
208
|
+
tx = txWithOracle;
|
|
209
|
+
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV2(tx, oracleBundle);
|
|
243
210
|
tx.moveCall({
|
|
244
211
|
target: `${this.consts.zoCore.upgradedPackage}::market::withdraw`,
|
|
245
212
|
typeArguments: [
|
|
@@ -264,22 +231,10 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
264
231
|
if (!tx) {
|
|
265
232
|
tx = new transactions_1.Transaction();
|
|
266
233
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
272
|
-
sender: this.requireSenderForSponsored(sender),
|
|
273
|
-
additionalSuiAmount: 0n,
|
|
274
|
-
});
|
|
275
|
-
tx = oracle.tx;
|
|
276
|
-
suiCoinObject = oracle.suiCoinObject;
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
280
|
-
}
|
|
281
|
-
const withdrawObject = await this.resolveSplitCoinObject(tx, 'zlp', BigInt(amount), lpCoinObjects, { sponsoredTx, suiCoinObject, sender });
|
|
282
|
-
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
234
|
+
const { tx: txWithOracle, oracle: oracleBundle } = await this.initValuationOracle(tx);
|
|
235
|
+
tx = txWithOracle;
|
|
236
|
+
const withdrawObject = await this.resolveSplitCoinObject(tx, 'zlp', BigInt(amount), lpCoinObjects, { sponsoredTx, sender });
|
|
237
|
+
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV2(tx, oracleBundle);
|
|
283
238
|
const [withdrawCoin] = tx.moveCall({
|
|
284
239
|
target: `${this.consts.zoCore.upgradedPackage}::market::withdraw_ptb`,
|
|
285
240
|
typeArguments: [
|
|
@@ -2066,6 +2021,384 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
2066
2021
|
});
|
|
2067
2022
|
return tx;
|
|
2068
2023
|
}
|
|
2024
|
+
// --- Pyth Pro + Stork (v3) ---
|
|
2025
|
+
/**
|
|
2026
|
+
* Swaps tokens using swap_v3 (Pyth Pro + Stork). Transfers output to sender.
|
|
2027
|
+
*/
|
|
2028
|
+
async swapV3(fromToken, toToken, fromAmount, fromCoinObjects, pythProUpdateBytes, minAmountOut, tx) {
|
|
2029
|
+
if (!tx) {
|
|
2030
|
+
tx = new transactions_1.Transaction();
|
|
2031
|
+
}
|
|
2032
|
+
const { tx: tx_, oracle } = await this.initV3OracleForTokens(Object.keys(this.consts.zoCore.vaults), tx, pythProUpdateBytes, true);
|
|
2033
|
+
const fromCoinObject = this.processCoins(tx_, fromToken, fromCoinObjects);
|
|
2034
|
+
const [fromDepositObject] = tx_.splitCoins(fromCoinObject, [tx_.pure.u64(fromAmount)]);
|
|
2035
|
+
const vaultsValuation = this.dataAPI.valuateVaultsV2(tx_, oracle);
|
|
2036
|
+
tx_.moveCall({
|
|
2037
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::swap_v3`,
|
|
2038
|
+
typeArguments: [
|
|
2039
|
+
this.zlpLpType(),
|
|
2040
|
+
this.consts.coins[fromToken].module,
|
|
2041
|
+
this.consts.coins[toToken].module,
|
|
2042
|
+
],
|
|
2043
|
+
arguments: [
|
|
2044
|
+
tx_.object(this.consts.zoCore.market),
|
|
2045
|
+
tx_.object(this.consts.zoCore.rebaseFeeModel),
|
|
2046
|
+
fromDepositObject,
|
|
2047
|
+
tx_.pure.u64(minAmountOut || 0),
|
|
2048
|
+
vaultsValuation,
|
|
2049
|
+
...(0, oraclePro_1.oracleArgsStandard)(oracle),
|
|
2050
|
+
],
|
|
2051
|
+
});
|
|
2052
|
+
return tx_;
|
|
2053
|
+
}
|
|
2054
|
+
/**
|
|
2055
|
+
* Swaps tokens and returns the output coin (swap_v3_ptb).
|
|
2056
|
+
*/
|
|
2057
|
+
async swapV3Ptb(fromToken, toToken, fromAmount, fromCoinObjects, pythProUpdateBytes, minAmountOut, tx) {
|
|
2058
|
+
if (!tx) {
|
|
2059
|
+
tx = new transactions_1.Transaction();
|
|
2060
|
+
}
|
|
2061
|
+
const { tx: tx_, oracle } = await this.initV3OracleForTokens(Object.keys(this.consts.zoCore.vaults), tx, pythProUpdateBytes, true);
|
|
2062
|
+
const fromCoinObject = this.processCoins(tx_, fromToken, fromCoinObjects);
|
|
2063
|
+
const [fromDepositObject] = tx_.splitCoins(fromCoinObject, [tx_.pure.u64(fromAmount)]);
|
|
2064
|
+
const vaultsValuation = this.dataAPI.valuateVaultsV2(tx_, oracle);
|
|
2065
|
+
const [outputCoin] = tx_.moveCall({
|
|
2066
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::swap_v3_ptb`,
|
|
2067
|
+
typeArguments: [
|
|
2068
|
+
this.zlpLpType(),
|
|
2069
|
+
this.consts.coins[fromToken].module,
|
|
2070
|
+
this.consts.coins[toToken].module,
|
|
2071
|
+
],
|
|
2072
|
+
arguments: [
|
|
2073
|
+
tx_.object(this.consts.zoCore.market),
|
|
2074
|
+
tx_.object(this.consts.zoCore.rebaseFeeModel),
|
|
2075
|
+
fromDepositObject,
|
|
2076
|
+
tx_.pure.u64(minAmountOut || 0),
|
|
2077
|
+
vaultsValuation,
|
|
2078
|
+
...(0, oraclePro_1.oracleArgsStandard)(oracle),
|
|
2079
|
+
],
|
|
2080
|
+
});
|
|
2081
|
+
return outputCoin;
|
|
2082
|
+
}
|
|
2083
|
+
/**
|
|
2084
|
+
* Opens a position using open_position_v3 (Pyth Pro + Stork).
|
|
2085
|
+
*/
|
|
2086
|
+
async openPositionV3(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, pythProUpdateBytes, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
2087
|
+
let tx = new transactions_1.Transaction();
|
|
2088
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
2089
|
+
tx = await this.addReferral(referralAddress, tx);
|
|
2090
|
+
}
|
|
2091
|
+
const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
|
|
2092
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
|
|
2093
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
|
|
2094
|
+
const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
|
|
2095
|
+
let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
|
|
2096
|
+
if (isLimitOrder) {
|
|
2097
|
+
allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
|
|
2098
|
+
}
|
|
2099
|
+
const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
|
|
2100
|
+
tx = tx_;
|
|
2101
|
+
const suiCoinObject = await this.resolveSponsoredSui(tx, collateralToken, relayerFee, sponsoredTx, sender);
|
|
2102
|
+
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
2103
|
+
tx.moveCall({
|
|
2104
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::open_position_v3`,
|
|
2105
|
+
typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
|
|
2106
|
+
arguments: [
|
|
2107
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
2108
|
+
tx.object(this.consts.zoCore.market),
|
|
2109
|
+
tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
|
|
2110
|
+
...(0, oraclePro_1.oracleArgsStandard)(oracle),
|
|
2111
|
+
depositObject,
|
|
2112
|
+
feeObject,
|
|
2113
|
+
tx.pure.u8(allowTrade),
|
|
2114
|
+
tx.pure.u64(size),
|
|
2115
|
+
tx.pure.u64(reserveAmount),
|
|
2116
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
2117
|
+
tx.pure.u256(adjustPrice),
|
|
2118
|
+
tx.pure.u256(indexPriceThreshold),
|
|
2119
|
+
],
|
|
2120
|
+
});
|
|
2121
|
+
return tx;
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Opens a position with S Card using open_position_with_scard_v3.
|
|
2125
|
+
*/
|
|
2126
|
+
async openPositionWithSCardV3(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, pythProUpdateBytes, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
2127
|
+
let tx = new transactions_1.Transaction();
|
|
2128
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
2129
|
+
tx = await this.addReferral(referralAddress, tx);
|
|
2130
|
+
}
|
|
2131
|
+
const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
|
|
2132
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
|
|
2133
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
|
|
2134
|
+
const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
|
|
2135
|
+
let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
|
|
2136
|
+
if (isLimitOrder) {
|
|
2137
|
+
allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
|
|
2138
|
+
}
|
|
2139
|
+
const kioskTx = new kiosk_1.KioskTransaction({
|
|
2140
|
+
transaction: tx,
|
|
2141
|
+
kioskClient,
|
|
2142
|
+
cap: kioskCap,
|
|
2143
|
+
});
|
|
2144
|
+
const [sudoCard, promise] = kioskTx.borrow({
|
|
2145
|
+
itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
|
|
2146
|
+
itemId: scard,
|
|
2147
|
+
});
|
|
2148
|
+
const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
|
|
2149
|
+
tx = tx_;
|
|
2150
|
+
const suiCoinObject = await this.resolveSponsoredSui(tx, collateralToken, relayerFee, sponsoredTx, sender);
|
|
2151
|
+
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
2152
|
+
tx.moveCall({
|
|
2153
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard_v3`,
|
|
2154
|
+
typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
|
|
2155
|
+
arguments: [
|
|
2156
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
2157
|
+
tx.object(this.consts.zoCore.market),
|
|
2158
|
+
tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
|
|
2159
|
+
...(0, oraclePro_1.oracleArgsStandard)(oracle),
|
|
2160
|
+
depositObject,
|
|
2161
|
+
feeObject,
|
|
2162
|
+
tx.pure.u8(allowTrade),
|
|
2163
|
+
tx.pure.u64(size),
|
|
2164
|
+
tx.pure.u64(reserveAmount),
|
|
2165
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
2166
|
+
tx.pure.u256(adjustPrice),
|
|
2167
|
+
tx.pure.u256(indexPriceThreshold),
|
|
2168
|
+
sudoCard,
|
|
2169
|
+
],
|
|
2170
|
+
});
|
|
2171
|
+
kioskTx
|
|
2172
|
+
.return({
|
|
2173
|
+
itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
|
|
2174
|
+
item: sudoCard,
|
|
2175
|
+
promise,
|
|
2176
|
+
})
|
|
2177
|
+
.finalize();
|
|
2178
|
+
return tx;
|
|
2179
|
+
}
|
|
2180
|
+
/**
|
|
2181
|
+
* Opens a position with a pre-composed collateral coin using open_position_v3 (Pyth Pro + Stork).
|
|
2182
|
+
*/
|
|
2183
|
+
async openPositionWithCoinV3(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, pythProUpdateBytes, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
2184
|
+
if (!tx) {
|
|
2185
|
+
tx = new transactions_1.Transaction();
|
|
2186
|
+
}
|
|
2187
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
2188
|
+
tx = await this.addReferral(referralAddress, tx);
|
|
2189
|
+
}
|
|
2190
|
+
const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
|
|
2191
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
|
|
2192
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
|
|
2193
|
+
const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
|
|
2194
|
+
let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
|
|
2195
|
+
if (isLimitOrder) {
|
|
2196
|
+
allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
|
|
2197
|
+
}
|
|
2198
|
+
const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
|
|
2199
|
+
tx = tx_;
|
|
2200
|
+
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
2201
|
+
tx.moveCall({
|
|
2202
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::open_position_v3`,
|
|
2203
|
+
typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
|
|
2204
|
+
arguments: [
|
|
2205
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
2206
|
+
tx.object(this.consts.zoCore.market),
|
|
2207
|
+
tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
|
|
2208
|
+
...(0, oraclePro_1.oracleArgsStandard)(oracle),
|
|
2209
|
+
coinObj,
|
|
2210
|
+
feeObject,
|
|
2211
|
+
tx.pure.u8(allowTrade),
|
|
2212
|
+
tx.pure.u64(size),
|
|
2213
|
+
tx.pure.u64(reserveAmount),
|
|
2214
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
2215
|
+
tx.pure.u256(adjustPrice),
|
|
2216
|
+
tx.pure.u256(indexPriceThreshold),
|
|
2217
|
+
],
|
|
2218
|
+
});
|
|
2219
|
+
return tx;
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* Opens a position with a pre-composed collateral coin and S Card using open_position_with_scard_v3.
|
|
2223
|
+
*/
|
|
2224
|
+
async openPositionWithCoinAndSCardV3(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, pythProUpdateBytes, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
2225
|
+
if (!tx) {
|
|
2226
|
+
tx = new transactions_1.Transaction();
|
|
2227
|
+
}
|
|
2228
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
2229
|
+
tx = await this.addReferral(referralAddress, tx);
|
|
2230
|
+
}
|
|
2231
|
+
const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
|
|
2232
|
+
const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
|
|
2233
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
|
|
2234
|
+
const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
|
|
2235
|
+
let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
|
|
2236
|
+
if (isLimitOrder) {
|
|
2237
|
+
allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
|
|
2238
|
+
}
|
|
2239
|
+
const kioskTx = new kiosk_1.KioskTransaction({
|
|
2240
|
+
transaction: tx,
|
|
2241
|
+
kioskClient,
|
|
2242
|
+
cap: kioskCap,
|
|
2243
|
+
});
|
|
2244
|
+
const [sudoCard, promise] = kioskTx.borrow({
|
|
2245
|
+
itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
|
|
2246
|
+
itemId: scard,
|
|
2247
|
+
});
|
|
2248
|
+
const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
|
|
2249
|
+
tx = tx_;
|
|
2250
|
+
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
2251
|
+
tx.moveCall({
|
|
2252
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::open_position_with_scard_v3`,
|
|
2253
|
+
typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
|
|
2254
|
+
arguments: [
|
|
2255
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
2256
|
+
tx.object(this.consts.zoCore.market),
|
|
2257
|
+
tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
|
|
2258
|
+
...(0, oraclePro_1.oracleArgsStandard)(oracle),
|
|
2259
|
+
coinObj,
|
|
2260
|
+
feeObject,
|
|
2261
|
+
tx.pure.u8(allowTrade),
|
|
2262
|
+
tx.pure.u64(size),
|
|
2263
|
+
tx.pure.u64(reserveAmount),
|
|
2264
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
2265
|
+
tx.pure.u256(adjustPrice),
|
|
2266
|
+
tx.pure.u256(indexPriceThreshold),
|
|
2267
|
+
sudoCard,
|
|
2268
|
+
],
|
|
2269
|
+
});
|
|
2270
|
+
kioskTx
|
|
2271
|
+
.return({
|
|
2272
|
+
itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
|
|
2273
|
+
item: sudoCard,
|
|
2274
|
+
promise,
|
|
2275
|
+
})
|
|
2276
|
+
.finalize();
|
|
2277
|
+
return tx;
|
|
2278
|
+
}
|
|
2279
|
+
/**
|
|
2280
|
+
* Decreases a position using decrease_position_v3.
|
|
2281
|
+
*/
|
|
2282
|
+
async decreasePositionV3(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, pythProUpdateBytes, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, sender) {
|
|
2283
|
+
if (!coinObjects?.length && !sender) {
|
|
2284
|
+
throw new Error(`${this.constructor.name}: coinObjects or sender is required`);
|
|
2285
|
+
}
|
|
2286
|
+
let tx = new transactions_1.Transaction();
|
|
2287
|
+
const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
|
|
2288
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
|
|
2289
|
+
const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
|
|
2290
|
+
let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
|
|
2291
|
+
if (isTriggerOrder) {
|
|
2292
|
+
allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
|
|
2293
|
+
}
|
|
2294
|
+
else {
|
|
2295
|
+
isTakeProfitOrder = true;
|
|
2296
|
+
}
|
|
2297
|
+
const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
|
|
2298
|
+
tx = tx_;
|
|
2299
|
+
const suiCoinObject = await this.resolveSponsoredSui(tx, collateralToken, relayerFee, sponsoredTx, sender);
|
|
2300
|
+
const feeObject = await this.resolveRelayerFeeObject(tx, collateralToken, coinObjects ?? [], relayerFee, sponsoredTx, suiCoinObject, sender);
|
|
2301
|
+
tx.moveCall({
|
|
2302
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_v3`,
|
|
2303
|
+
typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
|
|
2304
|
+
arguments: [
|
|
2305
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
2306
|
+
tx.object(this.consts.zoCore.market),
|
|
2307
|
+
tx.object(pcpId),
|
|
2308
|
+
...(0, oraclePro_1.oracleArgsStandard)(oracle),
|
|
2309
|
+
feeObject,
|
|
2310
|
+
tx.pure.u8(allowTrade),
|
|
2311
|
+
tx.pure.bool(isTakeProfitOrder),
|
|
2312
|
+
tx.pure.u64(amount),
|
|
2313
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
2314
|
+
tx.pure.u256(adjustPrice),
|
|
2315
|
+
tx.pure.u256(indexPriceThreshold),
|
|
2316
|
+
],
|
|
2317
|
+
});
|
|
2318
|
+
return tx;
|
|
2319
|
+
}
|
|
2320
|
+
/**
|
|
2321
|
+
* Decreases a position with S Card using decrease_position_with_scard_v3.
|
|
2322
|
+
*/
|
|
2323
|
+
async decreasePositionWithSCardV3(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, kioskClient, kioskCap, scard, pythProUpdateBytes, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, sender) {
|
|
2324
|
+
if (!coinObjects?.length && !sender) {
|
|
2325
|
+
throw new Error(`${this.constructor.name}: coinObjects or sender is required`);
|
|
2326
|
+
}
|
|
2327
|
+
let tx = new transactions_1.Transaction();
|
|
2328
|
+
const kioskTx = new kiosk_1.KioskTransaction({
|
|
2329
|
+
transaction: tx,
|
|
2330
|
+
kioskClient,
|
|
2331
|
+
cap: kioskCap,
|
|
2332
|
+
});
|
|
2333
|
+
const [sudoCard, promise] = kioskTx.borrow({
|
|
2334
|
+
itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
|
|
2335
|
+
itemId: scard,
|
|
2336
|
+
});
|
|
2337
|
+
const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
|
|
2338
|
+
const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
|
|
2339
|
+
const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
|
|
2340
|
+
let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
|
|
2341
|
+
if (isTriggerOrder) {
|
|
2342
|
+
allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
|
|
2343
|
+
}
|
|
2344
|
+
else {
|
|
2345
|
+
isTakeProfitOrder = true;
|
|
2346
|
+
}
|
|
2347
|
+
const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
|
|
2348
|
+
tx = tx_;
|
|
2349
|
+
const suiCoinObject = await this.resolveSponsoredSui(tx, collateralToken, relayerFee, sponsoredTx, sender);
|
|
2350
|
+
const feeObject = await this.resolveRelayerFeeObject(tx, collateralToken, coinObjects ?? [], relayerFee, sponsoredTx, suiCoinObject, sender);
|
|
2351
|
+
tx.moveCall({
|
|
2352
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::decrease_position_with_scard_v3`,
|
|
2353
|
+
typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
|
|
2354
|
+
arguments: [
|
|
2355
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
2356
|
+
tx.object(this.consts.zoCore.market),
|
|
2357
|
+
tx.object(pcpId),
|
|
2358
|
+
...(0, oraclePro_1.oracleArgsStandard)(oracle),
|
|
2359
|
+
feeObject,
|
|
2360
|
+
tx.pure.u8(allowTrade),
|
|
2361
|
+
tx.pure.bool(isTakeProfitOrder),
|
|
2362
|
+
tx.pure.u64(amount),
|
|
2363
|
+
tx.pure.u256(adjustCollateralPrice),
|
|
2364
|
+
tx.pure.u256(adjustPrice),
|
|
2365
|
+
tx.pure.u256(indexPriceThreshold),
|
|
2366
|
+
sudoCard,
|
|
2367
|
+
],
|
|
2368
|
+
});
|
|
2369
|
+
kioskTx
|
|
2370
|
+
.return({
|
|
2371
|
+
itemType: `0xe7e651e4974fe367aa2837712d68081efb299c470242a15e2b9c26ea326159ec::card::SudoCard`,
|
|
2372
|
+
item: sudoCard,
|
|
2373
|
+
promise,
|
|
2374
|
+
})
|
|
2375
|
+
.finalize();
|
|
2376
|
+
return tx;
|
|
2377
|
+
}
|
|
2378
|
+
/**
|
|
2379
|
+
* Redeems collateral from a position via redeem_from_position_v2 (Pyth Pro path).
|
|
2380
|
+
*/
|
|
2381
|
+
async redeemFromPositionV2(pcpId, collateralToken, indexToken, amount, long, pythProUpdateBytes, tx) {
|
|
2382
|
+
if (!tx) {
|
|
2383
|
+
tx = new transactions_1.Transaction();
|
|
2384
|
+
}
|
|
2385
|
+
const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
|
|
2386
|
+
const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
|
|
2387
|
+
tx_.moveCall({
|
|
2388
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::redeem_from_position_v2`,
|
|
2389
|
+
typeArguments: this.redeemTypeArgs(collateralToken, indexToken, long),
|
|
2390
|
+
arguments: [
|
|
2391
|
+
tx_.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
2392
|
+
tx_.object(this.consts.zoCore.market),
|
|
2393
|
+
tx_.object(pcpId),
|
|
2394
|
+
tx_.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
|
|
2395
|
+
tx_.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
|
|
2396
|
+
...(0, oraclePro_1.oracleArgsStandard)(oracle),
|
|
2397
|
+
tx_.pure.u64(amount),
|
|
2398
|
+
],
|
|
2399
|
+
});
|
|
2400
|
+
return tx_;
|
|
2401
|
+
}
|
|
2069
2402
|
}
|
|
2070
2403
|
exports.ZLPAPI = ZLPAPI;
|
|
2071
2404
|
//# sourceMappingURL=ZLPAPI.cjs.map
|