@zofai/zo-sdk 0.2.9 → 0.2.10
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 +8 -7
- package/dist/abstract/BaseAPI.d.cts.map +1 -1
- package/dist/abstract/BaseAPI.d.mts +8 -7
- 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/api.cjs +12 -12
- package/dist/api.cjs.map +1 -1
- package/dist/api.mjs +12 -12
- package/dist/api.mjs.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/implementations/SLPAPI.cjs +192 -100
- package/dist/implementations/SLPAPI.cjs.map +1 -1
- package/dist/implementations/SLPAPI.d.cts +23 -23
- package/dist/implementations/SLPAPI.d.cts.map +1 -1
- package/dist/implementations/SLPAPI.d.mts +23 -23
- 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.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 +21 -21
- package/dist/implementations/USDZAPI.d.cts.map +1 -1
- package/dist/implementations/USDZAPI.d.mts +21 -21
- 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/ZBTCVCAPI.cjs +84 -46
- package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.cts +11 -11
- package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.mts +11 -11
- 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/ZLPAPI.cjs +192 -100
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +23 -23
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +23 -23
- 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/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +25 -21
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +25 -21
- 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 +13 -1
- package/dist/oracle.d.cts.map +1 -1
- package/dist/oracle.d.mts +13 -1
- package/dist/oracle.d.mts.map +1 -1
- package/dist/oracle.mjs +27 -22
- package/dist/oracle.mjs.map +1 -1
- package/package.json +1 -1
- package/src/abstract/BaseAPI.ts +10 -8
- package/src/api.ts +12 -12
- package/src/coins.ts +115 -0
- package/src/implementations/SLPAPI.ts +199 -115
- package/src/implementations/SLPDataAPI.ts +2 -2
- package/src/implementations/USDZAPI.ts +184 -94
- package/src/implementations/ZBTCVCAPI.ts +98 -52
- package/src/implementations/ZLPAPI.ts +199 -110
- package/src/index.ts +1 -0
- package/src/interfaces/base.ts +13 -21
- 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 +64 -28
|
@@ -91,7 +91,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
91
91
|
arguments: [tx.object(this.consts.zoCore.market), tx.object(orderCapId)],
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
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
|
|
94
|
+
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) {
|
|
95
95
|
let tx = new transactions_1.Transaction();
|
|
96
96
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
97
97
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -115,11 +115,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
115
115
|
// Handle oracle initialization and coin processing
|
|
116
116
|
let suiCoinObject;
|
|
117
117
|
if (sponsoredTx) {
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
119
|
+
sender: this.requireSenderForSponsored(sender),
|
|
120
|
+
additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
|
|
121
|
+
});
|
|
122
|
+
tx = oracle.tx;
|
|
123
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
120
124
|
}
|
|
121
125
|
else {
|
|
122
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
126
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
123
127
|
}
|
|
124
128
|
// Process coin splitting
|
|
125
129
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -159,7 +163,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
159
163
|
.finalize();
|
|
160
164
|
return tx;
|
|
161
165
|
}
|
|
162
|
-
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
|
|
166
|
+
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
167
|
if (!tx) {
|
|
164
168
|
tx = new transactions_1.Transaction();
|
|
165
169
|
}
|
|
@@ -185,11 +189,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
185
189
|
// Handle oracle initialization and coin processing
|
|
186
190
|
let suiCoinObject;
|
|
187
191
|
if (sponsoredTx) {
|
|
188
|
-
|
|
189
|
-
|
|
192
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
193
|
+
sender: this.requireSenderForSponsored(sender),
|
|
194
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
195
|
+
});
|
|
196
|
+
tx = oracle.tx;
|
|
197
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
190
198
|
}
|
|
191
199
|
else {
|
|
192
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
200
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
193
201
|
}
|
|
194
202
|
// Process coin splitting
|
|
195
203
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -229,7 +237,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
229
237
|
.finalize();
|
|
230
238
|
return tx;
|
|
231
239
|
}
|
|
232
|
-
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,
|
|
240
|
+
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) {
|
|
233
241
|
if (!coinObjects) {
|
|
234
242
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
235
243
|
}
|
|
@@ -256,11 +264,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
256
264
|
// Handle oracle initialization and coin processing
|
|
257
265
|
let suiCoinObject;
|
|
258
266
|
if (sponsoredTx) {
|
|
259
|
-
|
|
260
|
-
|
|
267
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
268
|
+
sender: this.requireSenderForSponsored(sender),
|
|
269
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
270
|
+
});
|
|
271
|
+
tx = oracle.tx;
|
|
272
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
261
273
|
}
|
|
262
274
|
else {
|
|
263
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
275
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
264
276
|
}
|
|
265
277
|
// Process coin splitting
|
|
266
278
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -299,18 +311,19 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
299
311
|
.finalize();
|
|
300
312
|
return tx;
|
|
301
313
|
}
|
|
302
|
-
async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx,
|
|
314
|
+
async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender) {
|
|
303
315
|
if (!tx) {
|
|
304
316
|
tx = new transactions_1.Transaction();
|
|
305
317
|
}
|
|
306
318
|
// Handle oracle initialization and coin processing
|
|
307
319
|
let suiCoinObject;
|
|
308
320
|
if (sponsoredTx) {
|
|
309
|
-
|
|
310
|
-
tx =
|
|
321
|
+
const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
|
|
322
|
+
tx = oracle.tx;
|
|
323
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
311
324
|
}
|
|
312
325
|
else {
|
|
313
|
-
tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
|
|
326
|
+
tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
|
|
314
327
|
}
|
|
315
328
|
const kioskTx = new kiosk_1.KioskTransaction({
|
|
316
329
|
transaction: tx,
|
|
@@ -372,7 +385,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
372
385
|
.finalize();
|
|
373
386
|
return tx;
|
|
374
387
|
}
|
|
375
|
-
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
|
|
388
|
+
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) {
|
|
376
389
|
let tx = new transactions_1.Transaction();
|
|
377
390
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
378
391
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -397,11 +410,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
397
410
|
// Handle oracle initialization and coin processing
|
|
398
411
|
let suiCoinObject;
|
|
399
412
|
if (sponsoredTx) {
|
|
400
|
-
|
|
401
|
-
|
|
413
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
414
|
+
sender: this.requireSenderForSponsored(sender),
|
|
415
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
416
|
+
});
|
|
417
|
+
tx = oracle.tx;
|
|
418
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
402
419
|
}
|
|
403
420
|
else {
|
|
404
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
421
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
405
422
|
}
|
|
406
423
|
// Process coin splitting
|
|
407
424
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -441,7 +458,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
441
458
|
return tx;
|
|
442
459
|
}
|
|
443
460
|
// S Card operations
|
|
444
|
-
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
|
|
461
|
+
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) {
|
|
445
462
|
if (!tx) {
|
|
446
463
|
tx = new transactions_1.Transaction();
|
|
447
464
|
}
|
|
@@ -468,11 +485,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
468
485
|
// Handle oracle initialization and coin processing
|
|
469
486
|
let suiCoinObject;
|
|
470
487
|
if (sponsoredTx) {
|
|
471
|
-
|
|
472
|
-
|
|
488
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
489
|
+
sender: this.requireSenderForSponsored(sender),
|
|
490
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
491
|
+
});
|
|
492
|
+
tx = oracle.tx;
|
|
493
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
473
494
|
}
|
|
474
495
|
else {
|
|
475
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
496
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
476
497
|
}
|
|
477
498
|
// Process coin splitting
|
|
478
499
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -511,7 +532,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
511
532
|
.finalize();
|
|
512
533
|
return tx;
|
|
513
534
|
}
|
|
514
|
-
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,
|
|
535
|
+
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) {
|
|
515
536
|
if (!coinObjects) {
|
|
516
537
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
517
538
|
}
|
|
@@ -538,11 +559,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
538
559
|
// Handle oracle initialization and coin processing
|
|
539
560
|
let suiCoinObject;
|
|
540
561
|
if (sponsoredTx) {
|
|
541
|
-
|
|
542
|
-
|
|
562
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
563
|
+
sender: this.requireSenderForSponsored(sender),
|
|
564
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
565
|
+
});
|
|
566
|
+
tx = oracle.tx;
|
|
567
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
543
568
|
}
|
|
544
569
|
else {
|
|
545
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
570
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
546
571
|
}
|
|
547
572
|
// Process coin splitting
|
|
548
573
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -580,14 +605,21 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
580
605
|
.finalize();
|
|
581
606
|
return tx;
|
|
582
607
|
}
|
|
583
|
-
async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx,
|
|
584
|
-
|
|
608
|
+
async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender, feeObjects) {
|
|
609
|
+
let transaction = tx ?? new transactions_1.Transaction();
|
|
585
610
|
// Handle oracle initialization and coin processing
|
|
586
611
|
const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
612
|
+
let suiCoinObject;
|
|
613
|
+
if (sponsoredTx) {
|
|
614
|
+
const oracle = await this.initOracleTxb(tokens, transaction, true, {
|
|
615
|
+
sender: this.requireSenderForSponsored(sender),
|
|
616
|
+
});
|
|
617
|
+
transaction = oracle.tx;
|
|
618
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
|
|
622
|
+
}
|
|
591
623
|
if (!feeObjects || feeObjects.length !== positions.length) {
|
|
592
624
|
throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
|
|
593
625
|
}
|
|
@@ -652,7 +684,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
652
684
|
/**
|
|
653
685
|
* Deposits collateral into USDZ vault
|
|
654
686
|
*/
|
|
655
|
-
async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx
|
|
687
|
+
async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx) {
|
|
656
688
|
let tx = new transactions_1.Transaction();
|
|
657
689
|
// Add referral if needed
|
|
658
690
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
@@ -662,8 +694,12 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
662
694
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
663
695
|
// Handle sponsored transaction case
|
|
664
696
|
if (sponsoredTx) {
|
|
665
|
-
const
|
|
666
|
-
|
|
697
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
698
|
+
sender: this.requireSenderForSponsored(sender),
|
|
699
|
+
additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
|
|
700
|
+
});
|
|
701
|
+
tx = oracle.tx;
|
|
702
|
+
const { suiCoinObject } = oracle;
|
|
667
703
|
// Process deposit coins
|
|
668
704
|
const depositObject = coin === 'sui'
|
|
669
705
|
? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
|
|
@@ -684,7 +720,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
684
720
|
return tx;
|
|
685
721
|
}
|
|
686
722
|
// Handle non-sponsored transaction case
|
|
687
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
723
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
688
724
|
const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
|
|
689
725
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
690
726
|
tx.moveCall({
|
|
@@ -707,7 +743,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
707
743
|
/**
|
|
708
744
|
* Deposits collateral into USDZ vault
|
|
709
745
|
*/
|
|
710
|
-
async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx
|
|
746
|
+
async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
|
|
711
747
|
if (!tx) {
|
|
712
748
|
tx = new transactions_1.Transaction();
|
|
713
749
|
}
|
|
@@ -719,8 +755,12 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
719
755
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
720
756
|
// Handle sponsored transaction case
|
|
721
757
|
if (sponsoredTx) {
|
|
722
|
-
const
|
|
723
|
-
|
|
758
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
759
|
+
sender: this.requireSenderForSponsored(sender),
|
|
760
|
+
additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
|
|
761
|
+
});
|
|
762
|
+
tx = oracle.tx;
|
|
763
|
+
const { suiCoinObject } = oracle;
|
|
724
764
|
// Process deposit coins
|
|
725
765
|
const depositObject = coin === 'sui'
|
|
726
766
|
? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
|
|
@@ -741,7 +781,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
741
781
|
return mintedCoin;
|
|
742
782
|
}
|
|
743
783
|
// Handle non-sponsored transaction case
|
|
744
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
784
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
745
785
|
const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
|
|
746
786
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
747
787
|
const [mintedCoin] = tx.moveCall({
|
|
@@ -764,16 +804,20 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
764
804
|
/**
|
|
765
805
|
* Withdraws collateral from USDZ vault
|
|
766
806
|
*/
|
|
767
|
-
async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx,
|
|
807
|
+
async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, sender) {
|
|
768
808
|
let tx = new transactions_1.Transaction();
|
|
769
809
|
// Initialize oracle transaction
|
|
770
810
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
771
811
|
if (sponsoredTx) {
|
|
772
|
-
const
|
|
773
|
-
|
|
812
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
813
|
+
sender: this.requireSenderForSponsored(sender),
|
|
814
|
+
additionalSuiAmount: 0n,
|
|
815
|
+
});
|
|
816
|
+
tx = oracle.tx;
|
|
817
|
+
const { suiCoinObject } = oracle;
|
|
774
818
|
}
|
|
775
819
|
else {
|
|
776
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
820
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
777
821
|
}
|
|
778
822
|
const usdzCoinObject = this.processCoins(tx, 'usdz', lpCoinObjects, false);
|
|
779
823
|
const [withdrawObject] = tx.splitCoins(usdzCoinObject, [tx.pure.u64(amount)]);
|
|
@@ -804,7 +848,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
804
848
|
}
|
|
805
849
|
// Initialize oracle transaction
|
|
806
850
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
807
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
851
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
808
852
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
809
853
|
tx.moveCall({
|
|
810
854
|
target: `${this.consts.zoCore.upgradedPackage}::market::withdraw`,
|
|
@@ -986,7 +1030,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
986
1030
|
return rewardCoin;
|
|
987
1031
|
}
|
|
988
1032
|
async swap(fromToken, toToken, fromAmount, fromCoinObjects, minAmountOut) {
|
|
989
|
-
const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
|
|
1033
|
+
const { tx } = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
|
|
990
1034
|
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
|
|
991
1035
|
const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)]);
|
|
992
1036
|
const vaultsValuation = this.dataAPI.valuateVaults(tx);
|
|
@@ -1018,7 +1062,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1018
1062
|
if (!tx) {
|
|
1019
1063
|
tx = new transactions_1.Transaction();
|
|
1020
1064
|
}
|
|
1021
|
-
tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx);
|
|
1065
|
+
tx = (await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx)).tx;
|
|
1022
1066
|
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
|
|
1023
1067
|
const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
|
|
1024
1068
|
tx.pure.u64(fromAmount),
|
|
@@ -1044,7 +1088,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1044
1088
|
/**
|
|
1045
1089
|
* Opens a new position in USDZ
|
|
1046
1090
|
*/
|
|
1047
|
-
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
|
|
1091
|
+
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) {
|
|
1048
1092
|
let tx = new transactions_1.Transaction();
|
|
1049
1093
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
1050
1094
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -1059,11 +1103,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1059
1103
|
// Handle oracle initialization and coin processing
|
|
1060
1104
|
let suiCoinObject;
|
|
1061
1105
|
if (sponsoredTx) {
|
|
1062
|
-
|
|
1063
|
-
|
|
1106
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1107
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1108
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1109
|
+
});
|
|
1110
|
+
tx = oracle.tx;
|
|
1111
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1064
1112
|
}
|
|
1065
1113
|
else {
|
|
1066
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1114
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1067
1115
|
}
|
|
1068
1116
|
// Process coin splitting
|
|
1069
1117
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1098,7 +1146,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1098
1146
|
/**
|
|
1099
1147
|
* Opens a new position in USDZ (V2)
|
|
1100
1148
|
*/
|
|
1101
|
-
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
|
|
1149
|
+
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) {
|
|
1102
1150
|
let tx = new transactions_1.Transaction();
|
|
1103
1151
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
1104
1152
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -1114,11 +1162,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1114
1162
|
// Handle oracle initialization and coin processing
|
|
1115
1163
|
let suiCoinObject;
|
|
1116
1164
|
if (sponsoredTx) {
|
|
1117
|
-
|
|
1118
|
-
|
|
1165
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1166
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1167
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1168
|
+
});
|
|
1169
|
+
tx = oracle.tx;
|
|
1170
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1119
1171
|
}
|
|
1120
1172
|
else {
|
|
1121
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1173
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1122
1174
|
}
|
|
1123
1175
|
// Process coin splitting
|
|
1124
1176
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1152,7 +1204,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1152
1204
|
/**
|
|
1153
1205
|
* Opens a new position in USDZ
|
|
1154
1206
|
*/
|
|
1155
|
-
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
|
|
1207
|
+
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) {
|
|
1156
1208
|
if (!tx) {
|
|
1157
1209
|
tx = new transactions_1.Transaction();
|
|
1158
1210
|
}
|
|
@@ -1169,11 +1221,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1169
1221
|
// Handle oracle initialization and coin processing
|
|
1170
1222
|
let suiCoinObject;
|
|
1171
1223
|
if (sponsoredTx) {
|
|
1172
|
-
|
|
1173
|
-
|
|
1224
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1225
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1226
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1227
|
+
});
|
|
1228
|
+
tx = oracle.tx;
|
|
1229
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1174
1230
|
}
|
|
1175
1231
|
else {
|
|
1176
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1232
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1177
1233
|
}
|
|
1178
1234
|
// Process coin splitting
|
|
1179
1235
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -1208,7 +1264,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1208
1264
|
/**
|
|
1209
1265
|
* Opens a new position with Coin in USDZ (V2)
|
|
1210
1266
|
*/
|
|
1211
|
-
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
|
|
1267
|
+
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) {
|
|
1212
1268
|
if (!tx) {
|
|
1213
1269
|
tx = new transactions_1.Transaction();
|
|
1214
1270
|
}
|
|
@@ -1226,11 +1282,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1226
1282
|
// Handle oracle initialization and coin processing
|
|
1227
1283
|
let suiCoinObject;
|
|
1228
1284
|
if (sponsoredTx) {
|
|
1229
|
-
|
|
1230
|
-
|
|
1285
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1286
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1287
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1288
|
+
});
|
|
1289
|
+
tx = oracle.tx;
|
|
1290
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1231
1291
|
}
|
|
1232
1292
|
else {
|
|
1233
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1293
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1234
1294
|
}
|
|
1235
1295
|
// Process coin splitting
|
|
1236
1296
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -1264,7 +1324,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1264
1324
|
/**
|
|
1265
1325
|
* Decreases an existing position in USDZ
|
|
1266
1326
|
*/
|
|
1267
|
-
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,
|
|
1327
|
+
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) {
|
|
1268
1328
|
if (!coinObjects) {
|
|
1269
1329
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
1270
1330
|
}
|
|
@@ -1282,11 +1342,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1282
1342
|
// Handle oracle initialization and coin processing
|
|
1283
1343
|
let suiCoinObject;
|
|
1284
1344
|
if (sponsoredTx) {
|
|
1285
|
-
|
|
1286
|
-
|
|
1345
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1346
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1347
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1348
|
+
});
|
|
1349
|
+
tx = oracle.tx;
|
|
1350
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1287
1351
|
}
|
|
1288
1352
|
else {
|
|
1289
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1353
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1290
1354
|
}
|
|
1291
1355
|
// Process coin splitting
|
|
1292
1356
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1320,7 +1384,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1320
1384
|
/**
|
|
1321
1385
|
* Decreases an existing position in USDZ (V2)
|
|
1322
1386
|
*/
|
|
1323
|
-
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,
|
|
1387
|
+
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) {
|
|
1324
1388
|
if (!coinObjects) {
|
|
1325
1389
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
1326
1390
|
}
|
|
@@ -1338,11 +1402,15 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1338
1402
|
// Handle oracle initialization and coin processing
|
|
1339
1403
|
let suiCoinObject;
|
|
1340
1404
|
if (sponsoredTx) {
|
|
1341
|
-
|
|
1342
|
-
|
|
1405
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1406
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1407
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1408
|
+
});
|
|
1409
|
+
tx = oracle.tx;
|
|
1410
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1343
1411
|
}
|
|
1344
1412
|
else {
|
|
1345
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1413
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1346
1414
|
}
|
|
1347
1415
|
// Process coin splitting
|
|
1348
1416
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1372,18 +1440,19 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1372
1440
|
});
|
|
1373
1441
|
return tx;
|
|
1374
1442
|
}
|
|
1375
|
-
async decreaseMultiPositions(positions, tx, sponsoredTx,
|
|
1443
|
+
async decreaseMultiPositions(positions, tx, sponsoredTx, sender) {
|
|
1376
1444
|
if (!tx) {
|
|
1377
1445
|
tx = new transactions_1.Transaction();
|
|
1378
1446
|
}
|
|
1379
1447
|
// Handle oracle initialization and coin processing
|
|
1380
1448
|
let suiCoinObject;
|
|
1381
1449
|
if (sponsoredTx) {
|
|
1382
|
-
|
|
1383
|
-
tx =
|
|
1450
|
+
const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
|
|
1451
|
+
tx = oracle.tx;
|
|
1452
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1384
1453
|
}
|
|
1385
1454
|
else {
|
|
1386
|
-
tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
|
|
1455
|
+
tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
|
|
1387
1456
|
}
|
|
1388
1457
|
for (const position of positions) {
|
|
1389
1458
|
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;
|
|
@@ -1428,14 +1497,21 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1428
1497
|
}
|
|
1429
1498
|
return tx;
|
|
1430
1499
|
}
|
|
1431
|
-
async decreaseMultiPositionsV2(positions, tx, sponsoredTx,
|
|
1432
|
-
|
|
1500
|
+
async decreaseMultiPositionsV2(positions, tx, sponsoredTx, sender, feeObjects) {
|
|
1501
|
+
let transaction = tx ?? new transactions_1.Transaction();
|
|
1433
1502
|
// Handle oracle initialization and coin processing
|
|
1434
1503
|
const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1504
|
+
let suiCoinObject;
|
|
1505
|
+
if (sponsoredTx) {
|
|
1506
|
+
const oracle = await this.initOracleTxb(tokens, transaction, true, {
|
|
1507
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1508
|
+
});
|
|
1509
|
+
transaction = oracle.tx;
|
|
1510
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1511
|
+
}
|
|
1512
|
+
else {
|
|
1513
|
+
transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
|
|
1514
|
+
}
|
|
1439
1515
|
if (!feeObjects || feeObjects.length !== positions.length) {
|
|
1440
1516
|
throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
|
|
1441
1517
|
}
|
|
@@ -1483,16 +1559,20 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1483
1559
|
/**
|
|
1484
1560
|
* Pledges in position (USDZ-specific functionality)
|
|
1485
1561
|
*/
|
|
1486
|
-
async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx,
|
|
1562
|
+
async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, sender) {
|
|
1487
1563
|
let tx = new transactions_1.Transaction();
|
|
1488
1564
|
// Handle oracle initialization and coin processing
|
|
1489
1565
|
let suiCoinObject;
|
|
1490
1566
|
if (sponsoredTx) {
|
|
1491
|
-
|
|
1492
|
-
|
|
1567
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1568
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1569
|
+
additionalSuiAmount: collateralToken === 'sui' ? BigInt(amount) : 0n,
|
|
1570
|
+
});
|
|
1571
|
+
tx = oracle.tx;
|
|
1572
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1493
1573
|
}
|
|
1494
1574
|
else {
|
|
1495
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1575
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1496
1576
|
}
|
|
1497
1577
|
// Process coin splitting
|
|
1498
1578
|
const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(amount)], sponsoredTx, suiCoinObject);
|
|
@@ -1508,16 +1588,20 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1508
1588
|
});
|
|
1509
1589
|
return tx;
|
|
1510
1590
|
}
|
|
1511
|
-
async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx,
|
|
1591
|
+
async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, sender) {
|
|
1512
1592
|
let tx = new transactions_1.Transaction();
|
|
1513
1593
|
// Handle oracle initialization and coin processing
|
|
1514
1594
|
let suiCoinObject;
|
|
1515
1595
|
if (sponsoredTx) {
|
|
1516
|
-
|
|
1517
|
-
|
|
1596
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1597
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1598
|
+
additionalSuiAmount: 0n,
|
|
1599
|
+
});
|
|
1600
|
+
tx = oracle.tx;
|
|
1601
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1518
1602
|
}
|
|
1519
1603
|
else {
|
|
1520
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1604
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1521
1605
|
}
|
|
1522
1606
|
const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
|
|
1523
1607
|
tx.moveCall({
|
|
@@ -1636,7 +1720,7 @@ class USDZAPI extends abstract_1.BaseAPI {
|
|
|
1636
1720
|
return tx;
|
|
1637
1721
|
}
|
|
1638
1722
|
async adminUpdatePriceFeed(collateralToken, indexToken) {
|
|
1639
|
-
const tx = await this.initOracleTxb([collateralToken, indexToken]);
|
|
1723
|
+
const { tx } = await this.initOracleTxb([collateralToken, indexToken]);
|
|
1640
1724
|
return tx;
|
|
1641
1725
|
}
|
|
1642
1726
|
adminSettlePosition(positionId, owner, collateralToken, indexToken, long) {
|