zo-sdk 0.1.30 → 0.1.32
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/consts/deployments-shared-mainnet.json +1 -0
- package/dist/consts/deployments-slp-mainnet.json +1 -1
- package/dist/implementations/SLPAPI.cjs +142 -118
- package/dist/implementations/SLPAPI.cjs.map +1 -1
- package/dist/implementations/SLPAPI.d.cts +24 -14
- package/dist/implementations/SLPAPI.d.cts.map +1 -1
- package/dist/implementations/SLPAPI.d.mts +24 -14
- package/dist/implementations/SLPAPI.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.mjs +142 -118
- package/dist/implementations/SLPAPI.mjs.map +1 -1
- package/dist/implementations/SLPDataAPI.cjs +50 -3
- package/dist/implementations/SLPDataAPI.cjs.map +1 -1
- package/dist/implementations/SLPDataAPI.d.cts +6 -1
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/SLPDataAPI.d.mts +6 -1
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/SLPDataAPI.mjs +50 -3
- package/dist/implementations/SLPDataAPI.mjs.map +1 -1
- package/dist/implementations/USDZAPI.cjs +43 -4
- package/dist/implementations/USDZAPI.cjs.map +1 -1
- package/dist/implementations/USDZAPI.d.cts +13 -2
- package/dist/implementations/USDZAPI.d.cts.map +1 -1
- package/dist/implementations/USDZAPI.d.mts +13 -2
- package/dist/implementations/USDZAPI.d.mts.map +1 -1
- package/dist/implementations/USDZAPI.mjs +43 -4
- package/dist/implementations/USDZAPI.mjs.map +1 -1
- package/dist/implementations/ZBTCVCAPI.cjs +4 -4
- package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCAPI.mjs +4 -4
- package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
- package/dist/implementations/ZLPAPI.cjs +100 -4
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +16 -1
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +16 -1
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +100 -4
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +4 -3
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +4 -3
- package/dist/interfaces/base.d.mts.map +1 -1
- package/dist/interfaces/slp.d.cts +26 -1
- package/dist/interfaces/slp.d.cts.map +1 -1
- package/dist/interfaces/slp.d.mts +26 -1
- package/dist/interfaces/slp.d.mts.map +1 -1
- package/dist/interfaces/usdz.d.cts +5 -3
- package/dist/interfaces/usdz.d.cts.map +1 -1
- package/dist/interfaces/usdz.d.mts +5 -3
- package/dist/interfaces/usdz.d.mts.map +1 -1
- package/dist/interfaces/zbtcvc.d.cts +3 -3
- package/dist/interfaces/zbtcvc.d.cts.map +1 -1
- package/dist/interfaces/zbtcvc.d.mts +3 -3
- package/dist/interfaces/zbtcvc.d.mts.map +1 -1
- package/dist/interfaces/zlp.d.cts +5 -1
- package/dist/interfaces/zlp.d.cts.map +1 -1
- package/dist/interfaces/zlp.d.mts +5 -1
- package/dist/interfaces/zlp.d.mts.map +1 -1
- package/package.json +1 -1
- package/src/consts/deployments-shared-mainnet.json +1 -0
- package/src/consts/deployments-slp-mainnet.json +1 -1
- package/src/implementations/SLPAPI.ts +199 -132
- package/src/implementations/SLPDataAPI.ts +57 -6
- package/src/implementations/USDZAPI.ts +57 -6
- package/src/implementations/ZBTCVCAPI.ts +4 -4
- package/src/implementations/ZLPAPI.ts +137 -6
- package/src/interfaces/base.ts +10 -3
- package/src/interfaces/slp.ts +57 -2
- package/src/interfaces/usdz.ts +18 -4
- package/src/interfaces/zbtcvc.ts +5 -4
- package/src/interfaces/zlp.ts +32 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"zo_staking": {
|
|
3
3
|
"package": "0x87c13bb9157c3d51d61c7802704539d9d4782e838aadc41df0d6f0cc117298ba",
|
|
4
|
+
"upgraded_package": "0x5051f5b6c6df40c508e75b848181314caaa2e4e36308d197f9568f2327d0091f",
|
|
4
5
|
"upgrade_cap": "0x0b2ebbdedd751039cf033c1b24f61069b26cb2f99523789e150b5db59f13ccfd",
|
|
5
6
|
"admin_cap": "0xe339faca7f7558bdf8256e7174d0543e5db99befcd0e5b9bef9c421cecabc195",
|
|
6
7
|
"acl_control": "0x2de40211db8cc6aac0fe01acd8ea53943a577fa9ce13e0419ef1b821b75c8b9b",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"sudo_core": {
|
|
3
3
|
"package": "0xc44d97a4bc4e5a33ca847b72b123172c88a6328196b71414f32c3070233604b2",
|
|
4
|
-
"upgraded_package": "
|
|
4
|
+
"upgraded_package": "0x6ca4e4490e85a0e5a7c5006ef10e6e23031cb104eb072343f50ed3b35da6465f",
|
|
5
5
|
"upgrade_cap": "0x2092387c072fe18f91b57b9dde362f758259ee88d993a5faf569b4f2eb288b12",
|
|
6
6
|
"admin_cap": "0x0b4183c84de542c6f9623acd521294ea7e8205a2a7a23f4fac97e964fe4da30e",
|
|
7
7
|
"market": "0x4d753c2c69109cbeb806393956cfeba28d832354a37d59d9a019ee580f82893d",
|
|
@@ -147,6 +147,66 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
147
147
|
});
|
|
148
148
|
return tx;
|
|
149
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Deposits collateral into SLP vault and returns a coin
|
|
152
|
+
*/
|
|
153
|
+
async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
|
|
154
|
+
if (!tx) {
|
|
155
|
+
tx = new transactions_1.Transaction();
|
|
156
|
+
}
|
|
157
|
+
// Add referral if needed
|
|
158
|
+
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
159
|
+
tx = await this.addReferral(referralAddress, tx);
|
|
160
|
+
}
|
|
161
|
+
// Initialize oracle transaction
|
|
162
|
+
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
163
|
+
// Handle sponsored transaction case
|
|
164
|
+
if (sponsoredTx) {
|
|
165
|
+
const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
|
|
166
|
+
tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
|
|
167
|
+
// Process deposit coins
|
|
168
|
+
const depositObject = coin === 'sui'
|
|
169
|
+
? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
|
|
170
|
+
: tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0];
|
|
171
|
+
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
172
|
+
const [mintedCoin] = tx.moveCall({
|
|
173
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::deposit_ptb`,
|
|
174
|
+
typeArguments: [`${this.consts.sudoCore.package}::slp::SLP`, this.consts.coins[coin].module],
|
|
175
|
+
arguments: [
|
|
176
|
+
tx.object(this.consts.sudoCore.market),
|
|
177
|
+
tx.object(this.consts.sudoCore.rebaseFeeModel),
|
|
178
|
+
depositObject,
|
|
179
|
+
tx.pure.u64(minAmountOut),
|
|
180
|
+
vaultsValuation,
|
|
181
|
+
symbolsValuation,
|
|
182
|
+
],
|
|
183
|
+
});
|
|
184
|
+
return mintedCoin;
|
|
185
|
+
}
|
|
186
|
+
// Handle non-sponsored transaction case
|
|
187
|
+
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
188
|
+
const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
|
|
189
|
+
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
190
|
+
const [mintedCoin] = tx.moveCall({
|
|
191
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::deposit_ptb`,
|
|
192
|
+
typeArguments: [
|
|
193
|
+
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
194
|
+
this.consts.coins[coin].module,
|
|
195
|
+
],
|
|
196
|
+
arguments: [
|
|
197
|
+
tx.object(this.consts.sudoCore.market),
|
|
198
|
+
tx.object(this.consts.sudoCore.rebaseFeeModel),
|
|
199
|
+
depositObject,
|
|
200
|
+
tx.pure.u64(minAmountOut),
|
|
201
|
+
vaultsValuation,
|
|
202
|
+
symbolsValuation,
|
|
203
|
+
],
|
|
204
|
+
});
|
|
205
|
+
return mintedCoin;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Deposits collateral pool with PTB deposit object
|
|
209
|
+
*/
|
|
150
210
|
async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx, suiCoinObjectsForPythUpdate) {
|
|
151
211
|
if (!tx) {
|
|
152
212
|
tx = new transactions_1.Transaction();
|
|
@@ -290,81 +350,17 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
290
350
|
});
|
|
291
351
|
return tx;
|
|
292
352
|
}
|
|
293
|
-
/**
|
|
294
|
-
* Stakes SLP tokens in Sudo staking pools
|
|
295
|
-
*/
|
|
296
|
-
stake(lpCoinObjects, amount, pool) {
|
|
297
|
-
if (!this.consts.sudoStaking) {
|
|
298
|
-
throw new Error('Sudo staking configuration not found');
|
|
299
|
-
}
|
|
300
|
-
const tx = new transactions_1.Transaction();
|
|
301
|
-
const coinObject = this.processCoins(tx, 'slp', lpCoinObjects);
|
|
302
|
-
const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
|
|
303
|
-
tx.moveCall({
|
|
304
|
-
target: `${this.consts.sudoStaking.package}::pool::deposit`,
|
|
305
|
-
typeArguments: [
|
|
306
|
-
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
307
|
-
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
308
|
-
],
|
|
309
|
-
arguments: [
|
|
310
|
-
tx.object(pool),
|
|
311
|
-
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
312
|
-
depositObject,
|
|
313
|
-
],
|
|
314
|
-
});
|
|
315
|
-
return tx;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Unstakes SLP tokens from Sudo staking pools
|
|
319
|
-
*/
|
|
320
|
-
unstake(credentials, amount, pool) {
|
|
321
|
-
if (!this.consts.sudoStaking) {
|
|
322
|
-
throw new Error('Sudo staking configuration not found');
|
|
323
|
-
}
|
|
324
|
-
const tx = new transactions_1.Transaction();
|
|
325
|
-
for (const credential of credentials) {
|
|
326
|
-
const withdrawAmount = (() => {
|
|
327
|
-
const min = (a, b) => a < b ? a : b;
|
|
328
|
-
return min(amount, credential.amount);
|
|
329
|
-
})();
|
|
330
|
-
amount -= withdrawAmount;
|
|
331
|
-
tx.moveCall({
|
|
332
|
-
target: `${this.consts.sudoStaking.package}::pool::withdraw`,
|
|
333
|
-
typeArguments: [
|
|
334
|
-
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
335
|
-
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
336
|
-
],
|
|
337
|
-
arguments: [
|
|
338
|
-
tx.object(pool),
|
|
339
|
-
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
340
|
-
tx.object(credential.id),
|
|
341
|
-
tx.pure.u64(withdrawAmount),
|
|
342
|
-
],
|
|
343
|
-
});
|
|
344
|
-
if (credential.amount === BigInt(0)) {
|
|
345
|
-
tx.moveCall({
|
|
346
|
-
target: `${this.consts.sudoStaking.package}::pool::clear_empty_credential`,
|
|
347
|
-
typeArguments: [
|
|
348
|
-
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
349
|
-
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
350
|
-
],
|
|
351
|
-
arguments: [tx.object(credential.id)],
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return tx;
|
|
356
|
-
}
|
|
357
353
|
/**
|
|
358
354
|
* Stakes SLP tokens in ZO staking pools
|
|
359
355
|
*/
|
|
360
|
-
|
|
356
|
+
stake(lpCoinObjects, amount, pool, tx) {
|
|
361
357
|
if (!tx) {
|
|
362
358
|
tx = new transactions_1.Transaction();
|
|
363
359
|
}
|
|
364
360
|
const coinObject = this.processCoins(tx, 'slp', lpCoinObjects);
|
|
365
361
|
const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
|
|
366
362
|
tx.moveCall({
|
|
367
|
-
target: `${this.sharedConfig.zoStaking.
|
|
363
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::deposit`,
|
|
368
364
|
typeArguments: [
|
|
369
365
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
370
366
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
@@ -380,12 +376,12 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
380
376
|
/**
|
|
381
377
|
* Stakes SLP tokens using coin object only (PTB)
|
|
382
378
|
*/
|
|
383
|
-
|
|
379
|
+
stakeCoinObject(coinObject, pool, tx) {
|
|
384
380
|
if (!tx) {
|
|
385
381
|
tx = new transactions_1.Transaction();
|
|
386
382
|
}
|
|
387
383
|
tx.moveCall({
|
|
388
|
-
target: `${this.sharedConfig.zoStaking.
|
|
384
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::deposit`,
|
|
389
385
|
typeArguments: [
|
|
390
386
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
391
387
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
@@ -401,7 +397,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
401
397
|
/**
|
|
402
398
|
* Unstakes SLP tokens from ZO staking pools
|
|
403
399
|
*/
|
|
404
|
-
|
|
400
|
+
unstake(credentials, amount, pool, tx) {
|
|
405
401
|
let unstakeAmount = amount;
|
|
406
402
|
if (!tx) {
|
|
407
403
|
tx = new transactions_1.Transaction();
|
|
@@ -413,7 +409,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
413
409
|
})();
|
|
414
410
|
unstakeAmount -= withdrawAmount;
|
|
415
411
|
tx.moveCall({
|
|
416
|
-
target: `${this.sharedConfig.zoStaking.
|
|
412
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::withdraw`,
|
|
417
413
|
typeArguments: [
|
|
418
414
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
419
415
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
@@ -427,7 +423,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
427
423
|
});
|
|
428
424
|
if (credential.amount === BigInt(0)) {
|
|
429
425
|
tx.moveCall({
|
|
430
|
-
target: `${this.sharedConfig.zoStaking.
|
|
426
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::clear_empty_credential`,
|
|
431
427
|
typeArguments: [
|
|
432
428
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
433
429
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
@@ -438,6 +434,45 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
438
434
|
}
|
|
439
435
|
return tx;
|
|
440
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* Withdraws SLP tokens from a staking pool credential (PTB)
|
|
439
|
+
* Returns the withdrawn coin object for use in programmable transaction blocks
|
|
440
|
+
*/
|
|
441
|
+
withdrawFromVaultPtb(pool, credential, withdrawAmount, tx) {
|
|
442
|
+
const [withdrawnCoin] = tx.moveCall({
|
|
443
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::withdraw_ptb`,
|
|
444
|
+
typeArguments: [
|
|
445
|
+
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
446
|
+
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
447
|
+
],
|
|
448
|
+
arguments: [
|
|
449
|
+
tx.object(pool),
|
|
450
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
451
|
+
tx.object(credential),
|
|
452
|
+
tx.pure.u64(withdrawAmount),
|
|
453
|
+
],
|
|
454
|
+
});
|
|
455
|
+
return withdrawnCoin;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Claims rewards from a staking pool credential (PTB)
|
|
459
|
+
* Returns the reward coin object for use in programmable transaction blocks
|
|
460
|
+
*/
|
|
461
|
+
claimRewardsPtb(pool, credential, tx) {
|
|
462
|
+
const [rewardCoin] = tx.moveCall({
|
|
463
|
+
target: `${this.sharedConfig.zoStaking.upgradedPackage}::pool::claim_rewards_ptb`,
|
|
464
|
+
typeArguments: [
|
|
465
|
+
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
466
|
+
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
467
|
+
],
|
|
468
|
+
arguments: [
|
|
469
|
+
tx.object(pool),
|
|
470
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
471
|
+
tx.object(credential),
|
|
472
|
+
],
|
|
473
|
+
});
|
|
474
|
+
return rewardCoin;
|
|
475
|
+
}
|
|
441
476
|
/**
|
|
442
477
|
* Opens a position using Sudo SDK approach
|
|
443
478
|
*/
|
|
@@ -455,26 +490,23 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
455
490
|
}
|
|
456
491
|
// Handle oracle initialization and coin processing
|
|
457
492
|
let suiCoinObject;
|
|
458
|
-
let feeObject;
|
|
459
493
|
if (sponsoredTx) {
|
|
460
494
|
suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
|
|
461
|
-
feeObject = tx.splitCoins(suiCoinObject, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
|
|
462
495
|
tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
|
|
463
496
|
}
|
|
464
497
|
else {
|
|
465
|
-
feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
|
|
466
498
|
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
467
499
|
}
|
|
468
500
|
// Process coin splitting
|
|
469
|
-
const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount)], sponsoredTx, suiCoinObject);
|
|
501
|
+
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
470
502
|
tx.moveCall({
|
|
471
|
-
target: `${this.consts.sudoCore.upgradedPackage}::market::
|
|
503
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_v2_1`,
|
|
472
504
|
typeArguments: [
|
|
473
505
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
474
506
|
this.consts.coins[collateralToken].module,
|
|
475
507
|
this.consts.coins[indexToken].module,
|
|
476
508
|
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
477
|
-
this.consts.coins.
|
|
509
|
+
this.consts.coins[collateralToken].module,
|
|
478
510
|
],
|
|
479
511
|
arguments: [
|
|
480
512
|
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
@@ -491,7 +523,6 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
491
523
|
tx.pure.u64(reserveAmount),
|
|
492
524
|
tx.pure.u256(adjustCollateralPrice),
|
|
493
525
|
tx.pure.u256(adjustPrice),
|
|
494
|
-
tx.pure.bool(isLimitOrder),
|
|
495
526
|
],
|
|
496
527
|
});
|
|
497
528
|
return tx;
|
|
@@ -500,6 +531,9 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
500
531
|
* Decreases an existing position in SLP using Sudo SDK approach
|
|
501
532
|
*/
|
|
502
533
|
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, suiCoinObjectsForPythUpdate) {
|
|
534
|
+
if (!coinObjects) {
|
|
535
|
+
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
536
|
+
}
|
|
503
537
|
let tx = new transactions_1.Transaction();
|
|
504
538
|
const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
|
|
505
539
|
const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
|
|
@@ -513,24 +547,22 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
513
547
|
}
|
|
514
548
|
// Handle oracle initialization and coin processing
|
|
515
549
|
let suiCoinObject;
|
|
516
|
-
|
|
550
|
+
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
517
551
|
if (sponsoredTx) {
|
|
518
552
|
suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
|
|
519
|
-
feeObject = tx.splitCoins(suiCoinObject, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
|
|
520
553
|
tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
|
|
521
554
|
}
|
|
522
555
|
else {
|
|
523
|
-
feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
|
|
524
556
|
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
525
557
|
}
|
|
526
558
|
tx.moveCall({
|
|
527
|
-
target: `${this.consts.sudoCore.upgradedPackage}::market::
|
|
559
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_v2_1`,
|
|
528
560
|
typeArguments: [
|
|
529
561
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
530
562
|
this.consts.coins[collateralToken].module,
|
|
531
563
|
this.consts.coins[indexToken].module,
|
|
532
564
|
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
533
|
-
this.consts.coins.
|
|
565
|
+
this.consts.coins[collateralToken].module,
|
|
534
566
|
],
|
|
535
567
|
arguments: [
|
|
536
568
|
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
@@ -546,7 +578,6 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
546
578
|
tx.pure.u64(amount),
|
|
547
579
|
tx.pure.u256(adjustCollateralPrice),
|
|
548
580
|
tx.pure.u256(adjustPrice),
|
|
549
|
-
tx.pure.bool(isTriggerOrder),
|
|
550
581
|
],
|
|
551
582
|
});
|
|
552
583
|
return tx;
|
|
@@ -580,13 +611,13 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
580
611
|
// Process coin splitting
|
|
581
612
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
582
613
|
tx.moveCall({
|
|
583
|
-
target: `${this.consts.sudoCore.upgradedPackage}::market::
|
|
614
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_v2_1`,
|
|
584
615
|
typeArguments: [
|
|
585
616
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
586
617
|
this.consts.coins[collateralToken].module,
|
|
587
618
|
this.consts.coins[indexToken].module,
|
|
588
619
|
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
589
|
-
this.consts.coins.
|
|
620
|
+
this.consts.coins[collateralToken].module,
|
|
590
621
|
],
|
|
591
622
|
arguments: [
|
|
592
623
|
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
@@ -602,7 +633,6 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
602
633
|
tx.pure.u64(amount),
|
|
603
634
|
tx.pure.u256(adjustCollateralPrice),
|
|
604
635
|
tx.pure.u256(adjustPrice),
|
|
605
|
-
tx.pure.bool(isTriggerOrder),
|
|
606
636
|
],
|
|
607
637
|
});
|
|
608
638
|
}
|
|
@@ -670,16 +700,16 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
670
700
|
});
|
|
671
701
|
return tx;
|
|
672
702
|
}
|
|
673
|
-
cancelOrder(orderCapId, collateralToken, indexToken, long, type) {
|
|
703
|
+
cancelOrder(orderCapId, collateralToken, indexToken, long, type, isV11Order) {
|
|
674
704
|
const tx = new transactions_1.Transaction();
|
|
675
705
|
let functionName = '';
|
|
676
706
|
switch (type) {
|
|
677
707
|
case 'OPEN_POSITION': {
|
|
678
|
-
functionName = '
|
|
708
|
+
functionName = 'clear_open_position_order_unified';
|
|
679
709
|
break;
|
|
680
710
|
}
|
|
681
711
|
case 'DECREASE_POSITION': {
|
|
682
|
-
functionName = '
|
|
712
|
+
functionName = 'clear_decrease_position_order_unified';
|
|
683
713
|
break;
|
|
684
714
|
}
|
|
685
715
|
default: {
|
|
@@ -693,7 +723,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
693
723
|
this.consts.coins[collateralToken].module,
|
|
694
724
|
this.consts.coins[indexToken].module,
|
|
695
725
|
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
696
|
-
this.consts.coins.sui.module,
|
|
726
|
+
isV11Order ? this.consts.coins.sui.module : this.consts.coins[collateralToken].module,
|
|
697
727
|
],
|
|
698
728
|
arguments: [
|
|
699
729
|
tx.object(this.consts.sudoCore.market),
|
|
@@ -707,17 +737,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
707
737
|
tx = new transactions_1.Transaction();
|
|
708
738
|
}
|
|
709
739
|
for (const order of orders) {
|
|
710
|
-
const { orderCapId, collateralToken, indexToken, long, type
|
|
740
|
+
const { orderCapId, collateralToken, indexToken, long, type } = order;
|
|
711
741
|
let functionName = '';
|
|
712
742
|
switch (type) {
|
|
713
743
|
case 'OPEN_POSITION': {
|
|
714
|
-
functionName =
|
|
744
|
+
functionName = 'clear_open_position_order_unified';
|
|
715
745
|
break;
|
|
716
746
|
}
|
|
717
747
|
case 'DECREASE_POSITION': {
|
|
718
|
-
functionName =
|
|
719
|
-
? 'clear_decrease_position_order_v1_1'
|
|
720
|
-
: 'clear_decrease_position_order_v1_1';
|
|
748
|
+
functionName = 'clear_decrease_position_order_unified';
|
|
721
749
|
break;
|
|
722
750
|
}
|
|
723
751
|
default: {
|
|
@@ -750,15 +778,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
750
778
|
arguments: [tx.object(this.consts.sudoCore.market), tx.object(pcpId)],
|
|
751
779
|
});
|
|
752
780
|
}
|
|
753
|
-
clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx) {
|
|
781
|
+
clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order = true) {
|
|
754
782
|
tx.moveCall({
|
|
755
|
-
target: `${this.consts.sudoCore.upgradedPackage}::market::
|
|
783
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::clear_open_position_order_unified`,
|
|
756
784
|
typeArguments: [
|
|
757
785
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
758
786
|
this.consts.coins[collateralToken].module,
|
|
759
787
|
this.consts.coins[indexToken].module,
|
|
760
788
|
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
761
|
-
this.consts.coins.sui.module,
|
|
789
|
+
isV11Order ? this.consts.coins.sui.module : this.consts.coins[collateralToken].module,
|
|
762
790
|
],
|
|
763
791
|
arguments: [
|
|
764
792
|
tx.object(this.consts.sudoCore.market),
|
|
@@ -766,15 +794,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
766
794
|
],
|
|
767
795
|
});
|
|
768
796
|
}
|
|
769
|
-
clearDecreasePositionOrder(orderCapId, collateralToken, indexToken, long, tx) {
|
|
797
|
+
clearDecreasePositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order = true) {
|
|
770
798
|
tx.moveCall({
|
|
771
|
-
target: `${this.consts.sudoCore.upgradedPackage}::market::
|
|
799
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::clear_decrease_position_order_unified`,
|
|
772
800
|
typeArguments: [
|
|
773
801
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
774
802
|
this.consts.coins[collateralToken].module,
|
|
775
803
|
this.consts.coins[indexToken].module,
|
|
776
804
|
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
777
|
-
this.consts.coins.sui.module,
|
|
805
|
+
isV11Order ? this.consts.coins.sui.module : this.consts.coins[collateralToken].module,
|
|
778
806
|
],
|
|
779
807
|
arguments: [
|
|
780
808
|
tx.object(this.consts.sudoCore.market),
|
|
@@ -805,26 +833,23 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
805
833
|
});
|
|
806
834
|
// Handle oracle initialization and coin processing
|
|
807
835
|
let suiCoinObject;
|
|
808
|
-
let feeObject;
|
|
809
836
|
if (sponsoredTx) {
|
|
810
837
|
suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
|
|
811
|
-
feeObject = tx.splitCoins(suiCoinObject, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
|
|
812
838
|
tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
|
|
813
839
|
}
|
|
814
840
|
else {
|
|
815
|
-
feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
|
|
816
841
|
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
817
842
|
}
|
|
818
843
|
// Process coin splitting
|
|
819
|
-
const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount)], sponsoredTx, suiCoinObject);
|
|
844
|
+
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
820
845
|
tx.moveCall({
|
|
821
|
-
target: `${this.consts.sudoCore.upgradedPackage}::market::
|
|
846
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::open_position_with_scard_v1`,
|
|
822
847
|
typeArguments: [
|
|
823
848
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
824
849
|
this.consts.coins[collateralToken].module,
|
|
825
850
|
this.consts.coins[indexToken].module,
|
|
826
851
|
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
827
|
-
this.consts.coins.
|
|
852
|
+
this.consts.coins[collateralToken].module,
|
|
828
853
|
],
|
|
829
854
|
arguments: [
|
|
830
855
|
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
@@ -841,7 +866,6 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
841
866
|
tx.pure.u64(reserveAmount),
|
|
842
867
|
tx.pure.u256(adjustCollateralPrice),
|
|
843
868
|
tx.pure.u256(adjustPrice),
|
|
844
|
-
tx.pure.bool(isLimitOrder),
|
|
845
869
|
sudoCard,
|
|
846
870
|
],
|
|
847
871
|
});
|
|
@@ -855,6 +879,9 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
855
879
|
return tx;
|
|
856
880
|
}
|
|
857
881
|
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, suiCoinObjectsForPythUpdate) {
|
|
882
|
+
if (!coinObjects) {
|
|
883
|
+
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
884
|
+
}
|
|
858
885
|
let tx = new transactions_1.Transaction();
|
|
859
886
|
const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
|
|
860
887
|
const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
|
|
@@ -877,24 +904,23 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
877
904
|
});
|
|
878
905
|
// Handle oracle initialization and coin processing
|
|
879
906
|
let suiCoinObject;
|
|
880
|
-
let feeObject;
|
|
881
907
|
if (sponsoredTx) {
|
|
882
908
|
suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
|
|
883
|
-
feeObject = tx.splitCoins(suiCoinObject, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
|
|
884
909
|
tx = await this.initOracleTxb([collateralToken, indexToken], tx, true, suiCoinObject);
|
|
885
910
|
}
|
|
886
911
|
else {
|
|
887
|
-
feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
|
|
888
912
|
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
889
913
|
}
|
|
914
|
+
// Process coin splitting
|
|
915
|
+
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
890
916
|
tx.moveCall({
|
|
891
|
-
target: `${this.consts.sudoCore.upgradedPackage}::market::
|
|
917
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_with_scard_v1`,
|
|
892
918
|
typeArguments: [
|
|
893
919
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
894
920
|
this.consts.coins[collateralToken].module,
|
|
895
921
|
this.consts.coins[indexToken].module,
|
|
896
922
|
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
897
|
-
this.consts.coins.
|
|
923
|
+
this.consts.coins[collateralToken].module,
|
|
898
924
|
],
|
|
899
925
|
arguments: [
|
|
900
926
|
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
@@ -910,7 +936,6 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
910
936
|
tx.pure.u64(amount),
|
|
911
937
|
tx.pure.u256(adjustCollateralPrice),
|
|
912
938
|
tx.pure.u256(adjustPrice),
|
|
913
|
-
tx.pure.bool(isTriggerOrder),
|
|
914
939
|
sudoCard,
|
|
915
940
|
],
|
|
916
941
|
});
|
|
@@ -961,13 +986,13 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
961
986
|
// Process coin splitting
|
|
962
987
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
963
988
|
tx.moveCall({
|
|
964
|
-
target: `${this.consts.sudoCore.upgradedPackage}::market::
|
|
989
|
+
target: `${this.consts.sudoCore.upgradedPackage}::market::decrease_position_with_scard_v1`,
|
|
965
990
|
typeArguments: [
|
|
966
991
|
`${this.consts.sudoCore.package}::slp::SLP`,
|
|
967
992
|
this.consts.coins[collateralToken].module,
|
|
968
993
|
this.consts.coins[indexToken].module,
|
|
969
994
|
`${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
|
|
970
|
-
this.consts.coins.
|
|
995
|
+
this.consts.coins[collateralToken].module,
|
|
971
996
|
],
|
|
972
997
|
arguments: [
|
|
973
998
|
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
@@ -983,7 +1008,6 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
983
1008
|
tx.pure.u64(amount),
|
|
984
1009
|
tx.pure.u256(adjustCollateralPrice),
|
|
985
1010
|
tx.pure.u256(adjustPrice),
|
|
986
|
-
tx.pure.bool(isTriggerOrder),
|
|
987
1011
|
sudoCard,
|
|
988
1012
|
],
|
|
989
1013
|
});
|