@zofai/zo-sdk 0.2.25 → 0.2.27

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