@zofai/zo-sdk 0.2.26 → 0.2.28

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.
Files changed (54) hide show
  1. package/dist/consts/deployments-slp-mainnet.json +1 -1
  2. package/dist/consts/deployments-zo-oracle-mainnet.json +9 -0
  3. package/dist/implementations/SLPAPI.cjs +424 -209
  4. package/dist/implementations/SLPAPI.cjs.map +1 -1
  5. package/dist/implementations/SLPAPI.d.cts +19 -2
  6. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  7. package/dist/implementations/SLPAPI.d.mts +19 -2
  8. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  9. package/dist/implementations/SLPAPI.mjs +425 -210
  10. package/dist/implementations/SLPAPI.mjs.map +1 -1
  11. package/dist/implementations/SLPDataAPI.cjs +69 -7
  12. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  13. package/dist/implementations/SLPDataAPI.d.cts +10 -0
  14. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  15. package/dist/implementations/SLPDataAPI.d.mts +10 -0
  16. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  17. package/dist/implementations/SLPDataAPI.mjs +70 -8
  18. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  19. package/dist/interfaces/slp.d.cts +16 -0
  20. package/dist/interfaces/slp.d.cts.map +1 -1
  21. package/dist/interfaces/slp.d.mts +16 -0
  22. package/dist/interfaces/slp.d.mts.map +1 -1
  23. package/dist/oracle.cjs +4 -1
  24. package/dist/oracle.cjs.map +1 -1
  25. package/dist/oracle.d.cts.map +1 -1
  26. package/dist/oracle.d.mts.map +1 -1
  27. package/dist/oracle.mjs +4 -1
  28. package/dist/oracle.mjs.map +1 -1
  29. package/dist/oraclePro.cjs +145 -8
  30. package/dist/oraclePro.cjs.map +1 -1
  31. package/dist/oraclePro.d.cts +57 -1
  32. package/dist/oraclePro.d.cts.map +1 -1
  33. package/dist/oraclePro.d.mts +57 -1
  34. package/dist/oraclePro.d.mts.map +1 -1
  35. package/dist/oraclePro.mjs +138 -8
  36. package/dist/oraclePro.mjs.map +1 -1
  37. package/dist/pythProClient.cjs +12 -8
  38. package/dist/pythProClient.cjs.map +1 -1
  39. package/dist/pythProClient.d.cts +1 -0
  40. package/dist/pythProClient.d.cts.map +1 -1
  41. package/dist/pythProClient.d.mts +1 -0
  42. package/dist/pythProClient.d.mts.map +1 -1
  43. package/dist/pythProClient.mjs +11 -7
  44. package/dist/pythProClient.mjs.map +1 -1
  45. package/package.json +1 -1
  46. package/src/consts/deployments-slp-mainnet.json +1 -1
  47. package/src/consts/deployments-zo-oracle-mainnet.json +9 -0
  48. package/src/implementations/SLPAPI.ts +723 -239
  49. package/src/implementations/SLPDataAPI.ts +83 -9
  50. package/src/interfaces/slp.ts +170 -0
  51. package/src/oracle.ts +4 -1
  52. package/src/oraclePro.ts +229 -10
  53. package/src/pythProClient.ts +12 -7
  54. package/tests/pythProClient.test.ts +1 -1
@@ -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 SLPDataAPI_1 = require("./SLPDataAPI.cjs");
15
17
  class SLPAPI extends abstract_1.BaseAPI {
@@ -17,6 +19,65 @@ class SLPAPI extends abstract_1.BaseAPI {
17
19
  super(network, provider, apiEndpoint, connectionURL, consts_1.LPToken.SLP);
18
20
  this.dataAPI = new SLPDataAPI_1.SLPDataAPI(network, provider, apiEndpoint, connectionURL);
19
21
  }
22
+ slpLpType() {
23
+ return `${this.consts.sudoCore.package}::slp::SLP`;
24
+ }
25
+ positionTypeArgs(collateralToken, indexToken, long) {
26
+ return [
27
+ this.slpLpType(),
28
+ this.consts.coins[collateralToken].module,
29
+ this.consts.coins[indexToken].module,
30
+ `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
31
+ this.consts.coins[collateralToken].module,
32
+ ];
33
+ }
34
+ redeemTypeArgs(collateralToken, indexToken, long) {
35
+ return [
36
+ this.slpLpType(),
37
+ this.consts.coins[collateralToken].module,
38
+ this.consts.coins[indexToken].module,
39
+ `${this.consts.sudoCore.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
+ getValuationOracleTokens() {
51
+ const tokens = new Set(Object.keys(this.consts.sudoCore.vaults));
52
+ for (const key of Object.keys(this.consts.sudoCore.symbols)) {
53
+ const [, token] = (0, utils_2.parseSymbolKey)(key);
54
+ tokens.add(token);
55
+ }
56
+ return [...tokens];
57
+ }
58
+ async initValuationOracle(tx) {
59
+ const tokens = this.getValuationOracleTokens();
60
+ const pythProUpdateBytes = await this.fetchPythProUpdateBytesForTokens(tokens);
61
+ return this.initV3OracleForTokens(tokens, tx, pythProUpdateBytes);
62
+ }
63
+ async resolveSponsoredSui(tx, collateralToken, relayerFee, sponsoredTx, sender) {
64
+ if (!sponsoredTx) {
65
+ return undefined;
66
+ }
67
+ const additional = collateralToken === 'sui' ? relayerFee : 0n;
68
+ if (additional === 0n) {
69
+ return undefined;
70
+ }
71
+ return (0, coins_1.resolveSpendableSuiCoin)(tx, this.provider, this.requireSenderForSponsored(sender), additional);
72
+ }
73
+ positionFeeOracleArgs(tx, collateralToken, indexToken, long, oracle) {
74
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
75
+ return [
76
+ tx.object(this.consts.sudoCore.vaults[collateralToken].reservingFeeModel),
77
+ tx.object(this.consts.sudoCore.symbols[symbol].fundingFeeModel),
78
+ ...(0, oraclePro_1.oracleArgsAlt)((0, oraclePro_1.buildOracleInputsAlt)(oracle)),
79
+ ];
80
+ }
20
81
  calcPositionReserveFeeAmount(_position) {
21
82
  throw new Error(`Method not implemented in ${this.constructor.name}.`);
22
83
  }
@@ -28,48 +89,16 @@ class SLPAPI extends abstract_1.BaseAPI {
28
89
  */
29
90
  async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx) {
30
91
  let tx = new transactions_1.Transaction();
31
- // Add referral if needed
32
92
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
33
93
  tx = await this.addReferral(referralAddress, tx);
34
94
  }
35
- // Initialize oracle transaction
36
- const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
37
- // Handle sponsored transaction case
38
- if (sponsoredTx) {
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.sudoCore.upgradedPackage}::market::deposit`,
48
- typeArguments: [
49
- `${this.consts.sudoCore.package}::slp::SLP`,
50
- this.consts.coins[coin].module,
51
- ],
52
- arguments: [
53
- tx.object(this.consts.sudoCore.market),
54
- tx.object(this.consts.sudoCore.rebaseFeeModel),
55
- depositObject,
56
- tx.pure.u64(minAmountOut),
57
- vaultsValuation,
58
- symbolsValuation,
59
- ],
60
- });
61
- return tx;
62
- }
63
- // Handle non-sponsored transaction case
64
- tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
65
- const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sender });
66
- const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
95
+ const { tx: txWithOracle, oracle } = await this.initValuationOracle(tx);
96
+ tx = txWithOracle;
97
+ const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sponsoredTx, sender });
98
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV3(tx, oracle);
67
99
  tx.moveCall({
68
100
  target: `${this.consts.sudoCore.upgradedPackage}::market::deposit`,
69
- typeArguments: [
70
- `${this.consts.sudoCore.package}::slp::SLP`,
71
- this.consts.coins[coin].module,
72
- ],
101
+ typeArguments: [this.slpLpType(), this.consts.coins[coin].module],
73
102
  arguments: [
74
103
  tx.object(this.consts.sudoCore.market),
75
104
  tx.object(this.consts.sudoCore.rebaseFeeModel),
@@ -88,45 +117,16 @@ class SLPAPI extends abstract_1.BaseAPI {
88
117
  if (!tx) {
89
118
  tx = new transactions_1.Transaction();
90
119
  }
91
- // Add referral if needed
92
120
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
93
121
  tx = await this.addReferral(referralAddress, tx);
94
122
  }
95
- // Initialize oracle transaction
96
- const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
97
- // Handle sponsored transaction case
98
- if (sponsoredTx) {
99
- const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
100
- sender: this.requireSenderForSponsored(sender),
101
- additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
102
- });
103
- tx = oracle.tx;
104
- const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sponsoredTx: true, suiCoinObject: oracle.suiCoinObject, sender });
105
- const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
106
- const [mintedCoin] = tx.moveCall({
107
- target: `${this.consts.sudoCore.upgradedPackage}::market::deposit_ptb`,
108
- typeArguments: [`${this.consts.sudoCore.package}::slp::SLP`, this.consts.coins[coin].module],
109
- arguments: [
110
- tx.object(this.consts.sudoCore.market),
111
- tx.object(this.consts.sudoCore.rebaseFeeModel),
112
- depositObject,
113
- tx.pure.u64(minAmountOut),
114
- vaultsValuation,
115
- symbolsValuation,
116
- ],
117
- });
118
- return mintedCoin;
119
- }
120
- // Handle non-sponsored transaction case
121
- tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
122
- const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sender });
123
- const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
123
+ const { tx: txWithOracle, oracle } = await this.initValuationOracle(tx);
124
+ tx = txWithOracle;
125
+ const depositObject = await this.resolveSplitCoinObject(tx, coin, BigInt(amount), coinObjects, { sponsoredTx, sender });
126
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV3(tx, oracle);
124
127
  const [mintedCoin] = tx.moveCall({
125
128
  target: `${this.consts.sudoCore.upgradedPackage}::market::deposit_ptb`,
126
- typeArguments: [
127
- `${this.consts.sudoCore.package}::slp::SLP`,
128
- this.consts.coins[coin].module,
129
- ],
129
+ typeArguments: [this.slpLpType(), this.consts.coins[coin].module],
130
130
  arguments: [
131
131
  tx.object(this.consts.sudoCore.market),
132
132
  tx.object(this.consts.sudoCore.rebaseFeeModel),
@@ -145,47 +145,15 @@ class SLPAPI extends abstract_1.BaseAPI {
145
145
  if (!tx) {
146
146
  tx = new transactions_1.Transaction();
147
147
  }
148
- // Add referral if needed
149
148
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
150
149
  tx = await this.addReferral(referralAddress, tx);
151
150
  }
152
- // Initialize oracle transaction
153
- const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
154
- // Handle sponsored transaction case
155
- if (sponsoredTx) {
156
- const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
157
- sender: this.requireSenderForSponsored(sender),
158
- additionalSuiAmount: 0n,
159
- });
160
- tx = oracle.tx;
161
- const { suiCoinObject } = oracle;
162
- const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
163
- tx.moveCall({
164
- target: `${this.consts.sudoCore.upgradedPackage}::market::deposit`,
165
- typeArguments: [
166
- `${this.consts.sudoCore.package}::slp::SLP`,
167
- this.consts.coins[coin].module,
168
- ],
169
- arguments: [
170
- tx.object(this.consts.sudoCore.market),
171
- tx.object(this.consts.sudoCore.rebaseFeeModel),
172
- depositObject,
173
- tx.pure.u64(minAmountOut),
174
- vaultsValuation,
175
- symbolsValuation,
176
- ],
177
- });
178
- return tx;
179
- }
180
- // Handle non-sponsored transaction case
181
- tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
182
- const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
151
+ const { tx: txWithOracle, oracle } = await this.initValuationOracle(tx);
152
+ tx = txWithOracle;
153
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV3(tx, oracle);
183
154
  tx.moveCall({
184
155
  target: `${this.consts.sudoCore.upgradedPackage}::market::deposit`,
185
- typeArguments: [
186
- `${this.consts.sudoCore.package}::slp::SLP`,
187
- this.consts.coins[coin].module,
188
- ],
156
+ typeArguments: [this.slpLpType(), this.consts.coins[coin].module],
189
157
  arguments: [
190
158
  tx.object(this.consts.sudoCore.market),
191
159
  tx.object(this.consts.sudoCore.rebaseFeeModel),
@@ -205,28 +173,13 @@ class SLPAPI extends abstract_1.BaseAPI {
205
173
  throw new Error(`${this.constructor.name}: lpCoinObjects or sender is required`);
206
174
  }
207
175
  let tx = new transactions_1.Transaction();
208
- // Initialize oracle transaction
209
- const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
210
- let suiCoinObject;
211
- if (sponsoredTx) {
212
- const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
213
- sender: this.requireSenderForSponsored(sender),
214
- additionalSuiAmount: 0n,
215
- });
216
- tx = oracle.tx;
217
- suiCoinObject = oracle.suiCoinObject;
218
- }
219
- else {
220
- tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
221
- }
222
- const withdrawObject = await this.resolveSplitCoinObject(tx, 'slp', BigInt(amount), lpCoinObjects, { sponsoredTx, suiCoinObject, sender });
223
- const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
176
+ const { tx: txWithOracle, oracle } = await this.initValuationOracle(tx);
177
+ tx = txWithOracle;
178
+ const withdrawObject = await this.resolveSplitCoinObject(tx, 'slp', BigInt(amount), lpCoinObjects, { sponsoredTx, sender });
179
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV3(tx, oracle);
224
180
  tx.moveCall({
225
181
  target: `${this.consts.sudoCore.upgradedPackage}::market::withdraw`,
226
- typeArguments: [
227
- `${this.consts.sudoCore.package}::slp::SLP`,
228
- this.consts.coins[coin].module,
229
- ],
182
+ typeArguments: [this.slpLpType(), this.consts.coins[coin].module],
230
183
  arguments: [
231
184
  tx.object(this.consts.sudoCore.market),
232
185
  tx.object(this.consts.sudoCore.rebaseFeeModel),
@@ -245,16 +198,12 @@ class SLPAPI extends abstract_1.BaseAPI {
245
198
  if (!tx) {
246
199
  tx = new transactions_1.Transaction();
247
200
  }
248
- // Initialize oracle transaction
249
- const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
250
- tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
251
- const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
201
+ const { tx: txWithOracle, oracle } = await this.initValuationOracle(tx);
202
+ tx = txWithOracle;
203
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV3(tx, oracle);
252
204
  tx.moveCall({
253
205
  target: `${this.consts.sudoCore.upgradedPackage}::market::withdraw`,
254
- typeArguments: [
255
- `${this.consts.sudoCore.package}::slp::SLP`,
256
- this.consts.coins[coin].module,
257
- ],
206
+ typeArguments: [this.slpLpType(), this.consts.coins[coin].module],
258
207
  arguments: [
259
208
  tx.object(this.consts.sudoCore.market),
260
209
  tx.object(this.consts.sudoCore.rebaseFeeModel),
@@ -273,28 +222,13 @@ class SLPAPI extends abstract_1.BaseAPI {
273
222
  if (!tx) {
274
223
  tx = new transactions_1.Transaction();
275
224
  }
276
- // Initialize oracle transaction
277
- const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
278
- let suiCoinObject;
279
- if (sponsoredTx) {
280
- const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
281
- sender: this.requireSenderForSponsored(sender),
282
- additionalSuiAmount: 0n,
283
- });
284
- tx = oracle.tx;
285
- suiCoinObject = oracle.suiCoinObject;
286
- }
287
- else {
288
- tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
289
- }
290
- const withdrawObject = await this.resolveSplitCoinObject(tx, 'slp', BigInt(amount), lpCoinObjects, { sponsoredTx, suiCoinObject, sender });
291
- const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
225
+ const { tx: txWithOracle, oracle } = await this.initValuationOracle(tx);
226
+ tx = txWithOracle;
227
+ const withdrawObject = await this.resolveSplitCoinObject(tx, 'slp', BigInt(amount), lpCoinObjects, { sponsoredTx, sender });
228
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuateV3(tx, oracle);
292
229
  const [withdrawCoin] = tx.moveCall({
293
230
  target: `${this.consts.sudoCore.upgradedPackage}::market::withdraw_ptb`,
294
- typeArguments: [
295
- `${this.consts.sudoCore.package}::slp::SLP`,
296
- this.consts.coins[coin].module,
297
- ],
231
+ typeArguments: [this.slpLpType(), this.consts.coins[coin].module],
298
232
  arguments: [
299
233
  tx.object(this.consts.sudoCore.market),
300
234
  tx.object(this.consts.sudoCore.rebaseFeeModel),
@@ -998,36 +932,17 @@ class SLPAPI extends abstract_1.BaseAPI {
998
932
  return transaction;
999
933
  }
1000
934
  async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, sender) {
1001
- let tx = new transactions_1.Transaction();
1002
- // Handle oracle initialization and coin processing
1003
- let suiCoinObject;
1004
- if (sponsoredTx) {
1005
- const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
1006
- sender: this.requireSenderForSponsored(sender),
1007
- additionalSuiAmount: collateralToken === 'sui' ? BigInt(amount) : 0n,
1008
- });
1009
- tx = oracle.tx;
1010
- suiCoinObject = oracle.suiCoinObject;
1011
- }
1012
- else {
1013
- tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
1014
- }
1015
- const depositObject = await this.resolveSplitCoinObject(tx, collateralToken, BigInt(amount), coinObjects, { sponsoredTx, suiCoinObject, sender });
935
+ const tx = new transactions_1.Transaction();
936
+ const depositObject = await this.resolveSplitCoinObject(tx, collateralToken, BigInt(amount), coinObjects, { sponsoredTx, sender });
1016
937
  tx.moveCall({
1017
938
  target: `${this.consts.sudoCore.upgradedPackage}::market::pledge_in_position`,
1018
- typeArguments: [
1019
- `${this.consts.sudoCore.package}::slp::SLP`,
1020
- this.consts.coins[collateralToken].module,
1021
- this.consts.coins[indexToken].module,
1022
- `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1023
- ],
939
+ typeArguments: this.redeemTypeArgs(collateralToken, indexToken, long),
1024
940
  arguments: [
1025
941
  tx.object(this.consts.sudoCore.market),
1026
942
  tx.object(pcpId),
1027
943
  depositObject,
1028
944
  ],
1029
945
  });
1030
- this.returnUnusedSuiCoin(tx, suiCoinObject, sender);
1031
946
  return tx;
1032
947
  }
1033
948
  async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, sender) {
@@ -1077,7 +992,7 @@ class SLPAPI extends abstract_1.BaseAPI {
1077
992
  break;
1078
993
  }
1079
994
  case 'OPEN_MARKET': {
1080
- functionName = 'clear_open_market_order';
995
+ functionName = 'clear_open_position_order_unified';
1081
996
  break;
1082
997
  }
1083
998
  case 'DECREASE_POSITION': {
@@ -1085,7 +1000,7 @@ class SLPAPI extends abstract_1.BaseAPI {
1085
1000
  break;
1086
1001
  }
1087
1002
  case 'DECREASE_MARKET': {
1088
- functionName = 'clear_decrease_market_order';
1003
+ functionName = 'clear_decrease_position_order_unified';
1089
1004
  break;
1090
1005
  }
1091
1006
  default: {
@@ -1121,7 +1036,7 @@ class SLPAPI extends abstract_1.BaseAPI {
1121
1036
  break;
1122
1037
  }
1123
1038
  case 'OPEN_MARKET': {
1124
- functionName = 'clear_open_market_order';
1039
+ functionName = 'clear_open_position_order_unified';
1125
1040
  break;
1126
1041
  }
1127
1042
  case 'DECREASE_POSITION': {
@@ -1129,7 +1044,7 @@ class SLPAPI extends abstract_1.BaseAPI {
1129
1044
  break;
1130
1045
  }
1131
1046
  case 'DECREASE_MARKET': {
1132
- functionName = 'clear_decrease_market_order';
1047
+ functionName = 'clear_decrease_position_order_unified';
1133
1048
  break;
1134
1049
  }
1135
1050
  default: {
@@ -1162,7 +1077,7 @@ class SLPAPI extends abstract_1.BaseAPI {
1162
1077
  arguments: [tx.object(this.consts.sudoCore.market), tx.object(pcpId)],
1163
1078
  });
1164
1079
  }
1165
- clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order = true) {
1080
+ clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order = false) {
1166
1081
  tx.moveCall({
1167
1082
  target: `${this.consts.sudoCore.upgradedPackage}::market::clear_open_position_order_unified`,
1168
1083
  typeArguments: [
@@ -1178,7 +1093,7 @@ class SLPAPI extends abstract_1.BaseAPI {
1178
1093
  ],
1179
1094
  });
1180
1095
  }
1181
- clearDecreasePositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order = true) {
1096
+ clearDecreasePositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order = false) {
1182
1097
  tx.moveCall({
1183
1098
  target: `${this.consts.sudoCore.upgradedPackage}::market::clear_decrease_position_order_unified`,
1184
1099
  typeArguments: [
@@ -1194,33 +1109,11 @@ class SLPAPI extends abstract_1.BaseAPI {
1194
1109
  ],
1195
1110
  });
1196
1111
  }
1197
- clearOpenMarketOrder(orderCapId, collateralToken, indexToken, long, tx, _isV11Order) {
1198
- const funcName = 'clear_open_market_order';
1199
- tx.moveCall({
1200
- target: `${this.consts.sudoCore.upgradedPackage}::market::${funcName}`,
1201
- typeArguments: [
1202
- `${this.consts.sudoCore.package}::slp::SLP`,
1203
- this.consts.coins[collateralToken].module,
1204
- this.consts.coins[indexToken].module,
1205
- `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1206
- this.consts.coins[collateralToken].module,
1207
- ],
1208
- arguments: [tx.object(this.consts.sudoCore.market), tx.object(orderCapId)],
1209
- });
1112
+ clearOpenMarketOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order = false) {
1113
+ this.clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order);
1210
1114
  }
1211
- clearDecreaseMarketOrder(orderCapId, collateralToken, indexToken, long, tx, _isV11Order) {
1212
- const funcName = 'clear_decrease_market_order';
1213
- tx.moveCall({
1214
- target: `${this.consts.sudoCore.upgradedPackage}::market::${funcName}`,
1215
- typeArguments: [
1216
- `${this.consts.sudoCore.package}::slp::SLP`,
1217
- this.consts.coins[collateralToken].module,
1218
- this.consts.coins[indexToken].module,
1219
- `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1220
- this.consts.coins[collateralToken].module,
1221
- ],
1222
- arguments: [tx.object(this.consts.sudoCore.market), tx.object(orderCapId)],
1223
- });
1115
+ clearDecreaseMarketOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order = false) {
1116
+ this.clearDecreasePositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order);
1224
1117
  }
1225
1118
  async openPositionWithSCard(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
1226
1119
  let tx = new transactions_1.Transaction();
@@ -1883,6 +1776,328 @@ class SLPAPI extends abstract_1.BaseAPI {
1883
1776
  ],
1884
1777
  });
1885
1778
  }
1779
+ // --- Pyth Pro + Stork (v3_1 / swap_v4) ---
1780
+ async swapV4(fromToken, toToken, fromAmount, fromCoinObjects, pythProUpdateBytes, minAmountOut, tx) {
1781
+ if (!tx) {
1782
+ tx = new transactions_1.Transaction();
1783
+ }
1784
+ const { tx: tx_, oracle } = await this.initV3OracleForTokens(Object.keys(this.consts.sudoCore.vaults), tx, pythProUpdateBytes, true);
1785
+ const fromCoinObject = this.processCoins(tx_, fromToken, fromCoinObjects);
1786
+ const [fromDepositObject] = tx_.splitCoins(fromCoinObject, [tx_.pure.u64(fromAmount)]);
1787
+ const vaultsValuation = this.dataAPI.valuateVaultsV3(tx_, oracle);
1788
+ tx_.moveCall({
1789
+ target: `${this.consts.sudoCore.upgradedPackage}::market::swap_v4`,
1790
+ typeArguments: [this.slpLpType(), this.consts.coins[fromToken].module, this.consts.coins[toToken].module],
1791
+ arguments: [
1792
+ tx_.object(this.consts.sudoCore.market),
1793
+ tx_.object(this.consts.sudoCore.rebaseFeeModel),
1794
+ fromDepositObject,
1795
+ tx_.pure.u64(minAmountOut || 0),
1796
+ vaultsValuation,
1797
+ ...(0, oraclePro_1.oracleArgsRegistryFirst)(oracle),
1798
+ ],
1799
+ });
1800
+ return tx_;
1801
+ }
1802
+ async swapV4Ptb(fromToken, toToken, fromAmount, fromCoinObjects, pythProUpdateBytes, minAmountOut, tx) {
1803
+ if (!tx) {
1804
+ tx = new transactions_1.Transaction();
1805
+ }
1806
+ const { tx: tx_, oracle } = await this.initV3OracleForTokens(Object.keys(this.consts.sudoCore.vaults), tx, pythProUpdateBytes, true);
1807
+ const fromCoinObject = this.processCoins(tx_, fromToken, fromCoinObjects);
1808
+ const [fromDepositObject] = tx_.splitCoins(fromCoinObject, [tx_.pure.u64(fromAmount)]);
1809
+ const vaultsValuation = this.dataAPI.valuateVaultsV3(tx_, oracle);
1810
+ const [outputCoin] = tx_.moveCall({
1811
+ target: `${this.consts.sudoCore.upgradedPackage}::market::swap_v4_ptb`,
1812
+ typeArguments: [this.slpLpType(), this.consts.coins[fromToken].module, this.consts.coins[toToken].module],
1813
+ arguments: [
1814
+ tx_.object(this.consts.sudoCore.market),
1815
+ tx_.object(this.consts.sudoCore.rebaseFeeModel),
1816
+ fromDepositObject,
1817
+ tx_.pure.u64(minAmountOut || 0),
1818
+ vaultsValuation,
1819
+ ...(0, oraclePro_1.oracleArgsRegistryFirst)(oracle),
1820
+ ],
1821
+ });
1822
+ return outputCoin;
1823
+ }
1824
+ 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) {
1825
+ let tx = new transactions_1.Transaction();
1826
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1827
+ tx = await this.addReferral(referralAddress, tx);
1828
+ }
1829
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1830
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
1831
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1832
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1833
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1834
+ if (isLimitOrder) {
1835
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1836
+ }
1837
+ const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
1838
+ tx = tx_;
1839
+ const suiCoinObject = await this.resolveSponsoredSui(tx, collateralToken, relayerFee, sponsoredTx, sender);
1840
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1841
+ tx.moveCall({
1842
+ target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_v3_1`,
1843
+ typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
1844
+ arguments: [
1845
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1846
+ tx.object(this.consts.sudoCore.market),
1847
+ tx.object(this.consts.sudoCore.symbols[symbol].positionConfig),
1848
+ ...(0, oraclePro_1.oracleArgsAlt)((0, oraclePro_1.buildOracleInputsAlt)(oracle)),
1849
+ depositObject,
1850
+ feeObject,
1851
+ tx.pure.u8(allowTrade),
1852
+ tx.pure.u64(size),
1853
+ tx.pure.u64(reserveAmount),
1854
+ tx.pure.u256(adjustCollateralPrice),
1855
+ tx.pure.u256(adjustPrice),
1856
+ tx.pure.u256(indexPriceThreshold),
1857
+ ],
1858
+ });
1859
+ return tx;
1860
+ }
1861
+ 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) {
1862
+ let tx = new transactions_1.Transaction();
1863
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1864
+ tx = await this.addReferral(referralAddress, tx);
1865
+ }
1866
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1867
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
1868
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1869
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1870
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1871
+ if (isLimitOrder) {
1872
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1873
+ }
1874
+ const kioskTx = new kiosk_1.KioskTransaction({ transaction: tx, kioskClient, cap: kioskCap });
1875
+ const [sudoCard, promise] = kioskTx.borrow({
1876
+ itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
1877
+ itemId: scard,
1878
+ });
1879
+ const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
1880
+ tx = tx_;
1881
+ const suiCoinObject = await this.resolveSponsoredSui(tx, collateralToken, relayerFee, sponsoredTx, sender);
1882
+ const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
1883
+ tx.moveCall({
1884
+ target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_with_scard_v3_1`,
1885
+ typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
1886
+ arguments: [
1887
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1888
+ tx.object(this.consts.sudoCore.market),
1889
+ tx.object(this.consts.sudoCore.symbols[symbol].positionConfig),
1890
+ ...(0, oraclePro_1.oracleArgsAlt)((0, oraclePro_1.buildOracleInputsAlt)(oracle)),
1891
+ depositObject,
1892
+ feeObject,
1893
+ tx.pure.u8(allowTrade),
1894
+ tx.pure.u64(size),
1895
+ tx.pure.u64(reserveAmount),
1896
+ tx.pure.u256(adjustCollateralPrice),
1897
+ tx.pure.u256(adjustPrice),
1898
+ tx.pure.u256(indexPriceThreshold),
1899
+ sudoCard,
1900
+ ],
1901
+ });
1902
+ kioskTx.return({
1903
+ itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
1904
+ item: sudoCard,
1905
+ promise,
1906
+ }).finalize();
1907
+ return tx;
1908
+ }
1909
+ 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) {
1910
+ if (!tx) {
1911
+ tx = new transactions_1.Transaction();
1912
+ }
1913
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1914
+ tx = await this.addReferral(referralAddress, tx);
1915
+ }
1916
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1917
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
1918
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1919
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1920
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1921
+ if (isLimitOrder) {
1922
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1923
+ }
1924
+ const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
1925
+ tx = tx_;
1926
+ const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
1927
+ tx.moveCall({
1928
+ target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_v3_1`,
1929
+ typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
1930
+ arguments: [
1931
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1932
+ tx.object(this.consts.sudoCore.market),
1933
+ tx.object(this.consts.sudoCore.symbols[symbol].positionConfig),
1934
+ ...(0, oraclePro_1.oracleArgsAlt)((0, oraclePro_1.buildOracleInputsAlt)(oracle)),
1935
+ coinObj,
1936
+ feeObject,
1937
+ tx.pure.u8(allowTrade),
1938
+ tx.pure.u64(size),
1939
+ tx.pure.u64(reserveAmount),
1940
+ tx.pure.u256(adjustCollateralPrice),
1941
+ tx.pure.u256(adjustPrice),
1942
+ tx.pure.u256(indexPriceThreshold),
1943
+ ],
1944
+ });
1945
+ return tx;
1946
+ }
1947
+ 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) {
1948
+ if (!tx) {
1949
+ tx = new transactions_1.Transaction();
1950
+ }
1951
+ if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
1952
+ tx = await this.addReferral(referralAddress, tx);
1953
+ }
1954
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
1955
+ const adjustPrice = this.processSlippage(indexPrice, long, isLimitOrder ? 0 : pricesSlippage);
1956
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
1957
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
1958
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
1959
+ if (isLimitOrder) {
1960
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
1961
+ }
1962
+ const kioskTx = new kiosk_1.KioskTransaction({ transaction: tx, kioskClient, cap: kioskCap });
1963
+ const [sudoCard, promise] = kioskTx.borrow({
1964
+ itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
1965
+ itemId: scard,
1966
+ });
1967
+ const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
1968
+ tx = tx_;
1969
+ const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
1970
+ tx.moveCall({
1971
+ target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_with_scard_v3_1`,
1972
+ typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
1973
+ arguments: [
1974
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
1975
+ tx.object(this.consts.sudoCore.market),
1976
+ tx.object(this.consts.sudoCore.symbols[symbol].positionConfig),
1977
+ ...(0, oraclePro_1.oracleArgsAlt)((0, oraclePro_1.buildOracleInputsAlt)(oracle)),
1978
+ coinObj,
1979
+ feeObject,
1980
+ tx.pure.u8(allowTrade),
1981
+ tx.pure.u64(size),
1982
+ tx.pure.u64(reserveAmount),
1983
+ tx.pure.u256(adjustCollateralPrice),
1984
+ tx.pure.u256(adjustPrice),
1985
+ tx.pure.u256(indexPriceThreshold),
1986
+ sudoCard,
1987
+ ],
1988
+ });
1989
+ kioskTx.return({
1990
+ itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
1991
+ item: sudoCard,
1992
+ promise,
1993
+ }).finalize();
1994
+ return tx;
1995
+ }
1996
+ 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) {
1997
+ if (!coinObjects?.length && !sender) {
1998
+ throw new Error(`${this.constructor.name}: coinObjects or sender is required`);
1999
+ }
2000
+ let tx = new transactions_1.Transaction();
2001
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
2002
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
2003
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
2004
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
2005
+ if (isTriggerOrder) {
2006
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
2007
+ }
2008
+ else {
2009
+ isTakeProfitOrder = true;
2010
+ }
2011
+ const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
2012
+ tx = tx_;
2013
+ const suiCoinObject = await this.resolveSponsoredSui(tx, collateralToken, relayerFee, sponsoredTx, sender);
2014
+ const feeObject = await this.resolveRelayerFeeObject(tx, collateralToken, coinObjects ?? [], relayerFee, sponsoredTx, suiCoinObject, sender);
2015
+ tx.moveCall({
2016
+ target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_v3_1`,
2017
+ typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
2018
+ arguments: [
2019
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
2020
+ tx.object(this.consts.sudoCore.market),
2021
+ tx.object(pcpId),
2022
+ ...(0, oraclePro_1.oracleArgsAlt)((0, oraclePro_1.buildOracleInputsAlt)(oracle)),
2023
+ feeObject,
2024
+ tx.pure.u8(allowTrade),
2025
+ tx.pure.bool(isTakeProfitOrder),
2026
+ tx.pure.u64(amount),
2027
+ tx.pure.u256(adjustCollateralPrice),
2028
+ tx.pure.u256(adjustPrice),
2029
+ tx.pure.u256(indexPriceThreshold),
2030
+ ],
2031
+ });
2032
+ return tx;
2033
+ }
2034
+ 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) {
2035
+ if (!coinObjects?.length && !sender) {
2036
+ throw new Error(`${this.constructor.name}: coinObjects or sender is required`);
2037
+ }
2038
+ let tx = new transactions_1.Transaction();
2039
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
2040
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
2041
+ const indexPriceThreshold = this.processPriceThreshold(indexPrice, pricesSlippage);
2042
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
2043
+ if (isTriggerOrder) {
2044
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
2045
+ }
2046
+ else {
2047
+ isTakeProfitOrder = true;
2048
+ }
2049
+ const kioskTx = new kiosk_1.KioskTransaction({ transaction: tx, kioskClient, cap: kioskCap });
2050
+ const [sudoCard, promise] = kioskTx.borrow({
2051
+ itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
2052
+ itemId: scard,
2053
+ });
2054
+ const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
2055
+ tx = tx_;
2056
+ const suiCoinObject = await this.resolveSponsoredSui(tx, collateralToken, relayerFee, sponsoredTx, sender);
2057
+ const feeObject = await this.resolveRelayerFeeObject(tx, collateralToken, coinObjects ?? [], relayerFee, sponsoredTx, suiCoinObject, sender);
2058
+ tx.moveCall({
2059
+ target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_with_scard_v3_1`,
2060
+ typeArguments: this.positionTypeArgs(collateralToken, indexToken, long),
2061
+ arguments: [
2062
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
2063
+ tx.object(this.consts.sudoCore.market),
2064
+ tx.object(pcpId),
2065
+ ...(0, oraclePro_1.oracleArgsAlt)((0, oraclePro_1.buildOracleInputsAlt)(oracle)),
2066
+ feeObject,
2067
+ tx.pure.u8(allowTrade),
2068
+ tx.pure.bool(isTakeProfitOrder),
2069
+ tx.pure.u64(amount),
2070
+ tx.pure.u256(adjustCollateralPrice),
2071
+ tx.pure.u256(adjustPrice),
2072
+ tx.pure.u256(indexPriceThreshold),
2073
+ sudoCard,
2074
+ ],
2075
+ });
2076
+ kioskTx.return({
2077
+ itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
2078
+ item: sudoCard,
2079
+ promise,
2080
+ }).finalize();
2081
+ return tx;
2082
+ }
2083
+ async redeemFromPositionV3(pcpId, collateralToken, indexToken, amount, long, pythProUpdateBytes, tx) {
2084
+ if (!tx) {
2085
+ tx = new transactions_1.Transaction();
2086
+ }
2087
+ const { tx: tx_, oracle } = await this.initV3OracleForTokens([collateralToken, indexToken], tx, pythProUpdateBytes);
2088
+ tx_.moveCall({
2089
+ target: `${this.consts.sudoCore.upgradedPackage}::market::redeem_from_position_v3_1`,
2090
+ typeArguments: this.redeemTypeArgs(collateralToken, indexToken, long),
2091
+ arguments: [
2092
+ tx_.object(utils_1.SUI_CLOCK_OBJECT_ID),
2093
+ tx_.object(this.consts.sudoCore.market),
2094
+ tx_.object(pcpId),
2095
+ ...this.positionFeeOracleArgs(tx_, collateralToken, indexToken, long, oracle),
2096
+ tx_.pure.u64(amount),
2097
+ ],
2098
+ });
2099
+ return tx_;
2100
+ }
1886
2101
  // SLP Specific APIs
1887
2102
  claimTokenFromSCard(token, coinObjects, kioskClient, kioskCap, scard) {
1888
2103
  const tx = new transactions_1.Transaction();