@zofai/zo-sdk 0.2.9 → 0.2.11
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 +7 -1
- package/dist/abstract/BaseAPI.cjs.map +1 -1
- package/dist/abstract/BaseAPI.d.cts +11 -10
- package/dist/abstract/BaseAPI.d.cts.map +1 -1
- package/dist/abstract/BaseAPI.d.mts +11 -10
- package/dist/abstract/BaseAPI.d.mts.map +1 -1
- package/dist/abstract/BaseAPI.mjs +7 -1
- package/dist/abstract/BaseAPI.mjs.map +1 -1
- package/dist/abstract/BaseDataAPI.d.cts +1 -1
- package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
- package/dist/abstract/BaseDataAPI.d.mts +1 -1
- package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
- package/dist/api.cjs +12 -12
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +1 -1
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +1 -1
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +12 -12
- package/dist/api.mjs.map +1 -1
- package/dist/bcs.d.cts +41 -71
- package/dist/bcs.d.cts.map +1 -1
- package/dist/bcs.d.mts +41 -71
- package/dist/bcs.d.mts.map +1 -1
- package/dist/coins.cjs +74 -0
- package/dist/coins.cjs.map +1 -0
- package/dist/coins.d.cts +37 -0
- package/dist/coins.d.cts.map +1 -0
- package/dist/coins.d.mts +37 -0
- package/dist/coins.d.mts.map +1 -0
- package/dist/coins.mjs +67 -0
- package/dist/coins.mjs.map +1 -0
- package/dist/data.d.cts +6 -6
- package/dist/data.d.cts.map +1 -1
- package/dist/data.d.mts +6 -6
- package/dist/data.d.mts.map +1 -1
- package/dist/factory/SDKFactory.d.cts +1 -1
- package/dist/factory/SDKFactory.d.cts.map +1 -1
- package/dist/factory/SDKFactory.d.mts +1 -1
- package/dist/factory/SDKFactory.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.cjs +192 -100
- package/dist/implementations/SLPAPI.cjs.map +1 -1
- package/dist/implementations/SLPAPI.d.cts +24 -24
- package/dist/implementations/SLPAPI.d.cts.map +1 -1
- package/dist/implementations/SLPAPI.d.mts +24 -24
- package/dist/implementations/SLPAPI.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.mjs +192 -100
- package/dist/implementations/SLPAPI.mjs.map +1 -1
- package/dist/implementations/SLPDataAPI.cjs +2 -2
- package/dist/implementations/SLPDataAPI.cjs.map +1 -1
- package/dist/implementations/SLPDataAPI.d.cts +5 -5
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/SLPDataAPI.d.mts +5 -5
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/SLPDataAPI.mjs +2 -2
- package/dist/implementations/SLPDataAPI.mjs.map +1 -1
- package/dist/implementations/USDZAPI.cjs +176 -92
- package/dist/implementations/USDZAPI.cjs.map +1 -1
- package/dist/implementations/USDZAPI.d.cts +22 -22
- package/dist/implementations/USDZAPI.d.cts.map +1 -1
- package/dist/implementations/USDZAPI.d.mts +22 -22
- package/dist/implementations/USDZAPI.d.mts.map +1 -1
- package/dist/implementations/USDZAPI.mjs +176 -92
- package/dist/implementations/USDZAPI.mjs.map +1 -1
- package/dist/implementations/USDZDataAPI.d.cts +5 -5
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
- package/dist/implementations/USDZDataAPI.d.mts +5 -5
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.cjs +84 -46
- package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.cts +12 -12
- package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.mts +12 -12
- package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.mjs +84 -46
- package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.cts +5 -5
- package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.mts +5 -5
- package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -1
- package/dist/implementations/ZLPAPI.cjs +192 -100
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +24 -24
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +24 -24
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +192 -100
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.cts +5 -5
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.mts +5 -5
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +26 -22
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +26 -22
- package/dist/interfaces/base.d.mts.map +1 -1
- package/dist/interfaces/slp.d.cts +1 -1
- package/dist/interfaces/slp.d.cts.map +1 -1
- package/dist/interfaces/slp.d.mts +1 -1
- package/dist/interfaces/slp.d.mts.map +1 -1
- package/dist/interfaces/usdz.d.cts +1 -1
- package/dist/interfaces/usdz.d.cts.map +1 -1
- package/dist/interfaces/usdz.d.mts +1 -1
- package/dist/interfaces/usdz.d.mts.map +1 -1
- package/dist/interfaces/zbtcvc.d.cts +1 -1
- package/dist/interfaces/zbtcvc.d.cts.map +1 -1
- package/dist/interfaces/zbtcvc.d.mts +1 -1
- package/dist/interfaces/zbtcvc.d.mts.map +1 -1
- package/dist/interfaces/zlp.d.cts +1 -1
- package/dist/interfaces/zlp.d.cts.map +1 -1
- package/dist/interfaces/zlp.d.mts +1 -1
- package/dist/interfaces/zlp.d.mts.map +1 -1
- package/dist/oracle.cjs +27 -22
- package/dist/oracle.cjs.map +1 -1
- package/dist/oracle.d.cts +14 -2
- package/dist/oracle.d.cts.map +1 -1
- package/dist/oracle.d.mts +14 -2
- package/dist/oracle.d.mts.map +1 -1
- package/dist/oracle.mjs +27 -22
- package/dist/oracle.mjs.map +1 -1
- package/dist/suiClient.cjs +8 -0
- package/dist/suiClient.cjs.map +1 -0
- package/dist/suiClient.d.cts +8 -0
- package/dist/suiClient.d.cts.map +1 -0
- package/dist/suiClient.d.mts +8 -0
- package/dist/suiClient.d.mts.map +1 -0
- package/dist/suiClient.mjs +2 -0
- package/dist/suiClient.mjs.map +1 -0
- package/dist/utils.cjs +7 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +7 -3
- package/dist/utils.mjs.map +1 -1
- package/package.json +4 -4
- package/src/abstract/BaseAPI.ts +11 -9
- package/src/abstract/BaseDataAPI.ts +1 -1
- package/src/api.ts +13 -17
- package/src/coins.ts +116 -0
- package/src/data.ts +1 -1
- package/src/factory/SDKFactory.ts +1 -1
- package/src/implementations/SLPAPI.ts +200 -116
- package/src/implementations/SLPDataAPI.ts +3 -3
- package/src/implementations/USDZAPI.ts +185 -95
- package/src/implementations/USDZDataAPI.ts +1 -1
- package/src/implementations/ZBTCVCAPI.ts +99 -53
- package/src/implementations/ZBTCVCDataAPI.ts +1 -1
- package/src/implementations/ZLPAPI.ts +200 -111
- package/src/implementations/ZLPDataAPI.ts +1 -1
- package/src/index.ts +3 -1
- package/src/interfaces/base.ts +14 -22
- package/src/interfaces/slp.ts +0 -1
- package/src/interfaces/usdz.ts +0 -1
- package/src/interfaces/zbtcvc.ts +0 -1
- package/src/interfaces/zlp.ts +0 -1
- package/src/oracle.ts +70 -30
- package/src/suiClient.ts +11 -0
- package/src/utils.ts +9 -3
- package/tsconfig.json +8 -1
|
@@ -88,7 +88,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
88
88
|
arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
-
async openPositionWithSCard(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx
|
|
91
|
+
async openPositionWithSCard(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
92
92
|
let tx = new Transaction();
|
|
93
93
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
94
94
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -112,11 +112,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
112
112
|
// Handle oracle initialization and coin processing
|
|
113
113
|
let suiCoinObject;
|
|
114
114
|
if (sponsoredTx) {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
116
|
+
sender: this.requireSenderForSponsored(sender),
|
|
117
|
+
additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
|
|
118
|
+
});
|
|
119
|
+
tx = oracle.tx;
|
|
120
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
117
121
|
}
|
|
118
122
|
else {
|
|
119
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
123
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
120
124
|
}
|
|
121
125
|
// Process coin splitting
|
|
122
126
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -156,7 +160,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
156
160
|
.finalize();
|
|
157
161
|
return tx;
|
|
158
162
|
}
|
|
159
|
-
async openPositionWithCoinAndSCard(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx
|
|
163
|
+
async openPositionWithCoinAndSCard(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
160
164
|
if (!tx) {
|
|
161
165
|
tx = new Transaction();
|
|
162
166
|
}
|
|
@@ -182,11 +186,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
182
186
|
// Handle oracle initialization and coin processing
|
|
183
187
|
let suiCoinObject;
|
|
184
188
|
if (sponsoredTx) {
|
|
185
|
-
|
|
186
|
-
|
|
189
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
190
|
+
sender: this.requireSenderForSponsored(sender),
|
|
191
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
192
|
+
});
|
|
193
|
+
tx = oracle.tx;
|
|
194
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
187
195
|
}
|
|
188
196
|
else {
|
|
189
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
197
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
190
198
|
}
|
|
191
199
|
// Process coin splitting
|
|
192
200
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -226,7 +234,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
226
234
|
.finalize();
|
|
227
235
|
return tx;
|
|
228
236
|
}
|
|
229
|
-
async decreasePositionWithSCard(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx,
|
|
237
|
+
async decreasePositionWithSCard(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, sender) {
|
|
230
238
|
if (!coinObjects) {
|
|
231
239
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
232
240
|
}
|
|
@@ -253,11 +261,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
253
261
|
// Handle oracle initialization and coin processing
|
|
254
262
|
let suiCoinObject;
|
|
255
263
|
if (sponsoredTx) {
|
|
256
|
-
|
|
257
|
-
|
|
264
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
265
|
+
sender: this.requireSenderForSponsored(sender),
|
|
266
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
267
|
+
});
|
|
268
|
+
tx = oracle.tx;
|
|
269
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
258
270
|
}
|
|
259
271
|
else {
|
|
260
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
272
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
261
273
|
}
|
|
262
274
|
// Process coin splitting
|
|
263
275
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -296,18 +308,19 @@ export class USDZAPI extends BaseAPI {
|
|
|
296
308
|
.finalize();
|
|
297
309
|
return tx;
|
|
298
310
|
}
|
|
299
|
-
async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx,
|
|
311
|
+
async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender) {
|
|
300
312
|
if (!tx) {
|
|
301
313
|
tx = new Transaction();
|
|
302
314
|
}
|
|
303
315
|
// Handle oracle initialization and coin processing
|
|
304
316
|
let suiCoinObject;
|
|
305
317
|
if (sponsoredTx) {
|
|
306
|
-
|
|
307
|
-
tx =
|
|
318
|
+
const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
|
|
319
|
+
tx = oracle.tx;
|
|
320
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
308
321
|
}
|
|
309
322
|
else {
|
|
310
|
-
tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
|
|
323
|
+
tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
|
|
311
324
|
}
|
|
312
325
|
const kioskTx = new KioskTransaction({
|
|
313
326
|
transaction: tx,
|
|
@@ -369,7 +382,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
369
382
|
.finalize();
|
|
370
383
|
return tx;
|
|
371
384
|
}
|
|
372
|
-
async openPositionWithSCardV2(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx
|
|
385
|
+
async openPositionWithSCardV2(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
373
386
|
let tx = new Transaction();
|
|
374
387
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
375
388
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -394,11 +407,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
394
407
|
// Handle oracle initialization and coin processing
|
|
395
408
|
let suiCoinObject;
|
|
396
409
|
if (sponsoredTx) {
|
|
397
|
-
|
|
398
|
-
|
|
410
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
411
|
+
sender: this.requireSenderForSponsored(sender),
|
|
412
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
413
|
+
});
|
|
414
|
+
tx = oracle.tx;
|
|
415
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
399
416
|
}
|
|
400
417
|
else {
|
|
401
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
418
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
402
419
|
}
|
|
403
420
|
// Process coin splitting
|
|
404
421
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -438,7 +455,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
438
455
|
return tx;
|
|
439
456
|
}
|
|
440
457
|
// S Card operations
|
|
441
|
-
async openPositionWithCoinAndSCardV2(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx
|
|
458
|
+
async openPositionWithCoinAndSCardV2(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
442
459
|
if (!tx) {
|
|
443
460
|
tx = new Transaction();
|
|
444
461
|
}
|
|
@@ -465,11 +482,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
465
482
|
// Handle oracle initialization and coin processing
|
|
466
483
|
let suiCoinObject;
|
|
467
484
|
if (sponsoredTx) {
|
|
468
|
-
|
|
469
|
-
|
|
485
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
486
|
+
sender: this.requireSenderForSponsored(sender),
|
|
487
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
488
|
+
});
|
|
489
|
+
tx = oracle.tx;
|
|
490
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
470
491
|
}
|
|
471
492
|
else {
|
|
472
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
493
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
473
494
|
}
|
|
474
495
|
// Process coin splitting
|
|
475
496
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -508,7 +529,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
508
529
|
.finalize();
|
|
509
530
|
return tx;
|
|
510
531
|
}
|
|
511
|
-
async decreasePositionWithSCardV2(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx,
|
|
532
|
+
async decreasePositionWithSCardV2(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, sender) {
|
|
512
533
|
if (!coinObjects) {
|
|
513
534
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
514
535
|
}
|
|
@@ -535,11 +556,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
535
556
|
// Handle oracle initialization and coin processing
|
|
536
557
|
let suiCoinObject;
|
|
537
558
|
if (sponsoredTx) {
|
|
538
|
-
|
|
539
|
-
|
|
559
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
560
|
+
sender: this.requireSenderForSponsored(sender),
|
|
561
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
562
|
+
});
|
|
563
|
+
tx = oracle.tx;
|
|
564
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
540
565
|
}
|
|
541
566
|
else {
|
|
542
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
567
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
543
568
|
}
|
|
544
569
|
// Process coin splitting
|
|
545
570
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -577,14 +602,21 @@ export class USDZAPI extends BaseAPI {
|
|
|
577
602
|
.finalize();
|
|
578
603
|
return tx;
|
|
579
604
|
}
|
|
580
|
-
async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx,
|
|
581
|
-
|
|
605
|
+
async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender, feeObjects) {
|
|
606
|
+
let transaction = tx ?? new Transaction();
|
|
582
607
|
// Handle oracle initialization and coin processing
|
|
583
608
|
const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
609
|
+
let suiCoinObject;
|
|
610
|
+
if (sponsoredTx) {
|
|
611
|
+
const oracle = await this.initOracleTxb(tokens, transaction, true, {
|
|
612
|
+
sender: this.requireSenderForSponsored(sender),
|
|
613
|
+
});
|
|
614
|
+
transaction = oracle.tx;
|
|
615
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
|
|
619
|
+
}
|
|
588
620
|
if (!feeObjects || feeObjects.length !== positions.length) {
|
|
589
621
|
throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
|
|
590
622
|
}
|
|
@@ -649,7 +681,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
649
681
|
/**
|
|
650
682
|
* Deposits collateral into USDZ vault
|
|
651
683
|
*/
|
|
652
|
-
async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx
|
|
684
|
+
async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx) {
|
|
653
685
|
let tx = new Transaction();
|
|
654
686
|
// Add referral if needed
|
|
655
687
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
@@ -659,8 +691,12 @@ export class USDZAPI extends BaseAPI {
|
|
|
659
691
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
660
692
|
// Handle sponsored transaction case
|
|
661
693
|
if (sponsoredTx) {
|
|
662
|
-
const
|
|
663
|
-
|
|
694
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
695
|
+
sender: this.requireSenderForSponsored(sender),
|
|
696
|
+
additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
|
|
697
|
+
});
|
|
698
|
+
tx = oracle.tx;
|
|
699
|
+
const { suiCoinObject } = oracle;
|
|
664
700
|
// Process deposit coins
|
|
665
701
|
const depositObject = coin === 'sui'
|
|
666
702
|
? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
|
|
@@ -681,7 +717,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
681
717
|
return tx;
|
|
682
718
|
}
|
|
683
719
|
// Handle non-sponsored transaction case
|
|
684
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
720
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
685
721
|
const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
|
|
686
722
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
687
723
|
tx.moveCall({
|
|
@@ -704,7 +740,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
704
740
|
/**
|
|
705
741
|
* Deposits collateral into USDZ vault
|
|
706
742
|
*/
|
|
707
|
-
async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx
|
|
743
|
+
async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
|
|
708
744
|
if (!tx) {
|
|
709
745
|
tx = new Transaction();
|
|
710
746
|
}
|
|
@@ -716,8 +752,12 @@ export class USDZAPI extends BaseAPI {
|
|
|
716
752
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
717
753
|
// Handle sponsored transaction case
|
|
718
754
|
if (sponsoredTx) {
|
|
719
|
-
const
|
|
720
|
-
|
|
755
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
756
|
+
sender: this.requireSenderForSponsored(sender),
|
|
757
|
+
additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
|
|
758
|
+
});
|
|
759
|
+
tx = oracle.tx;
|
|
760
|
+
const { suiCoinObject } = oracle;
|
|
721
761
|
// Process deposit coins
|
|
722
762
|
const depositObject = coin === 'sui'
|
|
723
763
|
? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
|
|
@@ -738,7 +778,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
738
778
|
return mintedCoin;
|
|
739
779
|
}
|
|
740
780
|
// Handle non-sponsored transaction case
|
|
741
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
781
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
742
782
|
const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
|
|
743
783
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
744
784
|
const [mintedCoin] = tx.moveCall({
|
|
@@ -761,16 +801,20 @@ export class USDZAPI extends BaseAPI {
|
|
|
761
801
|
/**
|
|
762
802
|
* Withdraws collateral from USDZ vault
|
|
763
803
|
*/
|
|
764
|
-
async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx,
|
|
804
|
+
async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, sender) {
|
|
765
805
|
let tx = new Transaction();
|
|
766
806
|
// Initialize oracle transaction
|
|
767
807
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
768
808
|
if (sponsoredTx) {
|
|
769
|
-
const
|
|
770
|
-
|
|
809
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
810
|
+
sender: this.requireSenderForSponsored(sender),
|
|
811
|
+
additionalSuiAmount: 0n,
|
|
812
|
+
});
|
|
813
|
+
tx = oracle.tx;
|
|
814
|
+
const { suiCoinObject } = oracle;
|
|
771
815
|
}
|
|
772
816
|
else {
|
|
773
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
817
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
774
818
|
}
|
|
775
819
|
const usdzCoinObject = this.processCoins(tx, 'usdz', lpCoinObjects, false);
|
|
776
820
|
const [withdrawObject] = tx.splitCoins(usdzCoinObject, [tx.pure.u64(amount)]);
|
|
@@ -801,7 +845,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
801
845
|
}
|
|
802
846
|
// Initialize oracle transaction
|
|
803
847
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
804
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
848
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
805
849
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
806
850
|
tx.moveCall({
|
|
807
851
|
target: `${this.consts.zoCore.upgradedPackage}::market::withdraw`,
|
|
@@ -983,7 +1027,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
983
1027
|
return rewardCoin;
|
|
984
1028
|
}
|
|
985
1029
|
async swap(fromToken, toToken, fromAmount, fromCoinObjects, minAmountOut) {
|
|
986
|
-
const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
|
|
1030
|
+
const { tx } = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
|
|
987
1031
|
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
|
|
988
1032
|
const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)]);
|
|
989
1033
|
const vaultsValuation = this.dataAPI.valuateVaults(tx);
|
|
@@ -1015,7 +1059,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
1015
1059
|
if (!tx) {
|
|
1016
1060
|
tx = new Transaction();
|
|
1017
1061
|
}
|
|
1018
|
-
tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx);
|
|
1062
|
+
tx = (await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx)).tx;
|
|
1019
1063
|
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
|
|
1020
1064
|
const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
|
|
1021
1065
|
tx.pure.u64(fromAmount),
|
|
@@ -1041,7 +1085,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
1041
1085
|
/**
|
|
1042
1086
|
* Opens a new position in USDZ
|
|
1043
1087
|
*/
|
|
1044
|
-
async openPosition(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx
|
|
1088
|
+
async openPosition(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
1045
1089
|
let tx = new Transaction();
|
|
1046
1090
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
1047
1091
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -1056,11 +1100,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
1056
1100
|
// Handle oracle initialization and coin processing
|
|
1057
1101
|
let suiCoinObject;
|
|
1058
1102
|
if (sponsoredTx) {
|
|
1059
|
-
|
|
1060
|
-
|
|
1103
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1104
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1105
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1106
|
+
});
|
|
1107
|
+
tx = oracle.tx;
|
|
1108
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1061
1109
|
}
|
|
1062
1110
|
else {
|
|
1063
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1111
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1064
1112
|
}
|
|
1065
1113
|
// Process coin splitting
|
|
1066
1114
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1095,7 +1143,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
1095
1143
|
/**
|
|
1096
1144
|
* Opens a new position in USDZ (V2)
|
|
1097
1145
|
*/
|
|
1098
|
-
async openPositionV2(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx
|
|
1146
|
+
async openPositionV2(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
1099
1147
|
let tx = new Transaction();
|
|
1100
1148
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
1101
1149
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -1111,11 +1159,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
1111
1159
|
// Handle oracle initialization and coin processing
|
|
1112
1160
|
let suiCoinObject;
|
|
1113
1161
|
if (sponsoredTx) {
|
|
1114
|
-
|
|
1115
|
-
|
|
1162
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1163
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1164
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1165
|
+
});
|
|
1166
|
+
tx = oracle.tx;
|
|
1167
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1116
1168
|
}
|
|
1117
1169
|
else {
|
|
1118
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1170
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1119
1171
|
}
|
|
1120
1172
|
// Process coin splitting
|
|
1121
1173
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1149,7 +1201,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
1149
1201
|
/**
|
|
1150
1202
|
* Opens a new position in USDZ
|
|
1151
1203
|
*/
|
|
1152
|
-
async openPositionWithCoin(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx
|
|
1204
|
+
async openPositionWithCoin(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
1153
1205
|
if (!tx) {
|
|
1154
1206
|
tx = new Transaction();
|
|
1155
1207
|
}
|
|
@@ -1166,11 +1218,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
1166
1218
|
// Handle oracle initialization and coin processing
|
|
1167
1219
|
let suiCoinObject;
|
|
1168
1220
|
if (sponsoredTx) {
|
|
1169
|
-
|
|
1170
|
-
|
|
1221
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1222
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1223
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1224
|
+
});
|
|
1225
|
+
tx = oracle.tx;
|
|
1226
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1171
1227
|
}
|
|
1172
1228
|
else {
|
|
1173
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1229
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1174
1230
|
}
|
|
1175
1231
|
// Process coin splitting
|
|
1176
1232
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -1205,7 +1261,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
1205
1261
|
/**
|
|
1206
1262
|
* Opens a new position with Coin in USDZ (V2)
|
|
1207
1263
|
*/
|
|
1208
|
-
async openPositionWithCoinV2(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx
|
|
1264
|
+
async openPositionWithCoinV2(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
1209
1265
|
if (!tx) {
|
|
1210
1266
|
tx = new Transaction();
|
|
1211
1267
|
}
|
|
@@ -1223,11 +1279,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
1223
1279
|
// Handle oracle initialization and coin processing
|
|
1224
1280
|
let suiCoinObject;
|
|
1225
1281
|
if (sponsoredTx) {
|
|
1226
|
-
|
|
1227
|
-
|
|
1282
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1283
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1284
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1285
|
+
});
|
|
1286
|
+
tx = oracle.tx;
|
|
1287
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1228
1288
|
}
|
|
1229
1289
|
else {
|
|
1230
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1290
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1231
1291
|
}
|
|
1232
1292
|
// Process coin splitting
|
|
1233
1293
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -1261,7 +1321,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
1261
1321
|
/**
|
|
1262
1322
|
* Decreases an existing position in USDZ
|
|
1263
1323
|
*/
|
|
1264
|
-
async decreasePosition(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx,
|
|
1324
|
+
async decreasePosition(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, sender) {
|
|
1265
1325
|
if (!coinObjects) {
|
|
1266
1326
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
1267
1327
|
}
|
|
@@ -1279,11 +1339,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
1279
1339
|
// Handle oracle initialization and coin processing
|
|
1280
1340
|
let suiCoinObject;
|
|
1281
1341
|
if (sponsoredTx) {
|
|
1282
|
-
|
|
1283
|
-
|
|
1342
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1343
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1344
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1345
|
+
});
|
|
1346
|
+
tx = oracle.tx;
|
|
1347
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1284
1348
|
}
|
|
1285
1349
|
else {
|
|
1286
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1350
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1287
1351
|
}
|
|
1288
1352
|
// Process coin splitting
|
|
1289
1353
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1317,7 +1381,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
1317
1381
|
/**
|
|
1318
1382
|
* Decreases an existing position in USDZ (V2)
|
|
1319
1383
|
*/
|
|
1320
|
-
async decreasePositionV2(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx,
|
|
1384
|
+
async decreasePositionV2(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, sender) {
|
|
1321
1385
|
if (!coinObjects) {
|
|
1322
1386
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
1323
1387
|
}
|
|
@@ -1335,11 +1399,15 @@ export class USDZAPI extends BaseAPI {
|
|
|
1335
1399
|
// Handle oracle initialization and coin processing
|
|
1336
1400
|
let suiCoinObject;
|
|
1337
1401
|
if (sponsoredTx) {
|
|
1338
|
-
|
|
1339
|
-
|
|
1402
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1403
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1404
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1405
|
+
});
|
|
1406
|
+
tx = oracle.tx;
|
|
1407
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1340
1408
|
}
|
|
1341
1409
|
else {
|
|
1342
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1410
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1343
1411
|
}
|
|
1344
1412
|
// Process coin splitting
|
|
1345
1413
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1369,18 +1437,19 @@ export class USDZAPI extends BaseAPI {
|
|
|
1369
1437
|
});
|
|
1370
1438
|
return tx;
|
|
1371
1439
|
}
|
|
1372
|
-
async decreaseMultiPositions(positions, tx, sponsoredTx,
|
|
1440
|
+
async decreaseMultiPositions(positions, tx, sponsoredTx, sender) {
|
|
1373
1441
|
if (!tx) {
|
|
1374
1442
|
tx = new Transaction();
|
|
1375
1443
|
}
|
|
1376
1444
|
// Handle oracle initialization and coin processing
|
|
1377
1445
|
let suiCoinObject;
|
|
1378
1446
|
if (sponsoredTx) {
|
|
1379
|
-
|
|
1380
|
-
tx =
|
|
1447
|
+
const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
|
|
1448
|
+
tx = oracle.tx;
|
|
1449
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1381
1450
|
}
|
|
1382
1451
|
else {
|
|
1383
|
-
tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
|
|
1452
|
+
tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
|
|
1384
1453
|
}
|
|
1385
1454
|
for (const position of positions) {
|
|
1386
1455
|
const { pcpId, collateralToken, coinObjects = [], indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), } = position;
|
|
@@ -1425,14 +1494,21 @@ export class USDZAPI extends BaseAPI {
|
|
|
1425
1494
|
}
|
|
1426
1495
|
return tx;
|
|
1427
1496
|
}
|
|
1428
|
-
async decreaseMultiPositionsV2(positions, tx, sponsoredTx,
|
|
1429
|
-
|
|
1497
|
+
async decreaseMultiPositionsV2(positions, tx, sponsoredTx, sender, feeObjects) {
|
|
1498
|
+
let transaction = tx ?? new Transaction();
|
|
1430
1499
|
// Handle oracle initialization and coin processing
|
|
1431
1500
|
const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1501
|
+
let suiCoinObject;
|
|
1502
|
+
if (sponsoredTx) {
|
|
1503
|
+
const oracle = await this.initOracleTxb(tokens, transaction, true, {
|
|
1504
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1505
|
+
});
|
|
1506
|
+
transaction = oracle.tx;
|
|
1507
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1508
|
+
}
|
|
1509
|
+
else {
|
|
1510
|
+
transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
|
|
1511
|
+
}
|
|
1436
1512
|
if (!feeObjects || feeObjects.length !== positions.length) {
|
|
1437
1513
|
throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
|
|
1438
1514
|
}
|
|
@@ -1480,16 +1556,20 @@ export class USDZAPI extends BaseAPI {
|
|
|
1480
1556
|
/**
|
|
1481
1557
|
* Pledges in position (USDZ-specific functionality)
|
|
1482
1558
|
*/
|
|
1483
|
-
async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx,
|
|
1559
|
+
async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, sender) {
|
|
1484
1560
|
let tx = new Transaction();
|
|
1485
1561
|
// Handle oracle initialization and coin processing
|
|
1486
1562
|
let suiCoinObject;
|
|
1487
1563
|
if (sponsoredTx) {
|
|
1488
|
-
|
|
1489
|
-
|
|
1564
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1565
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1566
|
+
additionalSuiAmount: collateralToken === 'sui' ? BigInt(amount) : 0n,
|
|
1567
|
+
});
|
|
1568
|
+
tx = oracle.tx;
|
|
1569
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1490
1570
|
}
|
|
1491
1571
|
else {
|
|
1492
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1572
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1493
1573
|
}
|
|
1494
1574
|
// Process coin splitting
|
|
1495
1575
|
const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(amount)], sponsoredTx, suiCoinObject);
|
|
@@ -1505,16 +1585,20 @@ export class USDZAPI extends BaseAPI {
|
|
|
1505
1585
|
});
|
|
1506
1586
|
return tx;
|
|
1507
1587
|
}
|
|
1508
|
-
async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx,
|
|
1588
|
+
async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, sender) {
|
|
1509
1589
|
let tx = new Transaction();
|
|
1510
1590
|
// Handle oracle initialization and coin processing
|
|
1511
1591
|
let suiCoinObject;
|
|
1512
1592
|
if (sponsoredTx) {
|
|
1513
|
-
|
|
1514
|
-
|
|
1593
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1594
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1595
|
+
additionalSuiAmount: 0n,
|
|
1596
|
+
});
|
|
1597
|
+
tx = oracle.tx;
|
|
1598
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1515
1599
|
}
|
|
1516
1600
|
else {
|
|
1517
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1601
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1518
1602
|
}
|
|
1519
1603
|
const symbol = joinSymbol(long ? 'long' : 'short', indexToken);
|
|
1520
1604
|
tx.moveCall({
|
|
@@ -1633,7 +1717,7 @@ export class USDZAPI extends BaseAPI {
|
|
|
1633
1717
|
return tx;
|
|
1634
1718
|
}
|
|
1635
1719
|
async adminUpdatePriceFeed(collateralToken, indexToken) {
|
|
1636
|
-
const tx = await this.initOracleTxb([collateralToken, indexToken]);
|
|
1720
|
+
const { tx } = await this.initOracleTxb([collateralToken, indexToken]);
|
|
1637
1721
|
return tx;
|
|
1638
1722
|
}
|
|
1639
1723
|
adminSettlePosition(positionId, owner, collateralToken, indexToken, long) {
|