@scallop-io/sui-scallop-sdk 1.5.3 → 2.0.0-alpha.2
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/index.d.mts +451 -602
- package/dist/index.d.ts +451 -602
- package/dist/index.js +29 -60
- package/dist/index.mjs +6 -6
- package/package.json +1 -1
- package/src/builders/loyaltyProgramBuilder.ts +5 -3
- package/src/builders/oracle.ts +10 -24
- package/src/builders/referralBuilder.ts +5 -9
- package/src/builders/sCoinBuilder.ts +9 -8
- package/src/builders/spoolBuilder.ts +4 -6
- package/src/constants/common.ts +114 -126
- package/src/constants/index.ts +0 -5
- package/src/constants/pyth.ts +25 -34
- package/src/constants/queryKeys.ts +2 -0
- package/src/models/index.ts +1 -0
- package/src/models/scallop.ts +23 -19
- package/src/models/scallopAddress.ts +7 -4
- package/src/models/scallopBuilder.ts +36 -41
- package/src/models/scallopCache.ts +1 -1
- package/src/models/scallopClient.ts +93 -94
- package/src/models/scallopConstants.ts +342 -0
- package/src/models/scallopIndexer.ts +11 -24
- package/src/models/scallopQuery.ts +70 -77
- package/src/models/scallopUtils.ts +122 -249
- package/src/queries/borrowIncentiveQuery.ts +21 -56
- package/src/queries/borrowLimitQuery.ts +3 -6
- package/src/queries/coreQuery.ts +94 -112
- package/src/queries/flashloanFeeQuery.ts +86 -0
- package/src/queries/isolatedAssetQuery.ts +12 -11
- package/src/queries/poolAddressesQuery.ts +187 -112
- package/src/queries/portfolioQuery.ts +65 -67
- package/src/queries/priceQuery.ts +16 -22
- package/src/queries/sCoinQuery.ts +15 -16
- package/src/queries/spoolQuery.ts +49 -59
- package/src/queries/supplyLimitQuery.ts +2 -6
- package/src/queries/xOracleQuery.ts +4 -15
- package/src/types/address.ts +12 -18
- package/src/types/builder/borrowIncentive.ts +2 -3
- package/src/types/builder/core.ts +20 -27
- package/src/types/builder/index.ts +1 -2
- package/src/types/builder/referral.ts +4 -8
- package/src/types/builder/sCoin.ts +4 -8
- package/src/types/builder/spool.ts +7 -10
- package/src/types/constant/common.ts +43 -49
- package/src/types/constant/enum.ts +15 -27
- package/src/types/constant/xOracle.ts +3 -5
- package/src/types/model.ts +49 -28
- package/src/types/query/borrowIncentive.ts +7 -24
- package/src/types/query/core.ts +8 -18
- package/src/types/query/portfolio.ts +8 -17
- package/src/types/query/spool.ts +5 -11
- package/src/types/utils.ts +1 -21
- package/src/utils/core.ts +1 -1
- package/src/utils/query.ts +13 -20
- package/src/utils/util.ts +6 -84
- package/src/constants/coinGecko.ts +0 -34
- package/src/constants/enum.ts +0 -268
- package/src/constants/flashloan.ts +0 -18
- package/src/constants/poolAddress.ts +0 -898
- package/src/models/scallopPrice.ts +0 -0
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
2
2
|
import { SuiKit } from '@scallop-io/sui-kit';
|
|
3
|
-
import {
|
|
4
|
-
ADDRESS_ID,
|
|
5
|
-
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
6
|
-
SUPPORT_SCOIN,
|
|
7
|
-
SUPPORT_SPOOLS,
|
|
8
|
-
} from '../constants';
|
|
9
3
|
import { ScallopAddress } from './scallopAddress';
|
|
10
4
|
import { ScallopUtils } from './scallopUtils';
|
|
11
5
|
import { ScallopBuilder } from './scallopBuilder';
|
|
@@ -21,17 +15,12 @@ import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
|
21
15
|
import type {
|
|
22
16
|
ScallopClientFnReturnType,
|
|
23
17
|
ScallopClientParams,
|
|
24
|
-
SupportPoolCoins,
|
|
25
|
-
SupportCollateralCoins,
|
|
26
|
-
SupportAssetCoins,
|
|
27
|
-
SupportStakeCoins,
|
|
28
|
-
SupportStakeMarketCoins,
|
|
29
18
|
ScallopTxBlock,
|
|
30
|
-
SupportSCoin,
|
|
31
19
|
ScallopClientVeScaReturnType,
|
|
32
20
|
ScallopClientInstanceParams,
|
|
33
21
|
} from '../types';
|
|
34
22
|
import { newSuiKit } from './suiKit';
|
|
23
|
+
import { ScallopConstants } from './scallopConstants';
|
|
35
24
|
|
|
36
25
|
/**
|
|
37
26
|
* @description
|
|
@@ -50,6 +39,7 @@ export class ScallopClient {
|
|
|
50
39
|
|
|
51
40
|
public suiKit: SuiKit;
|
|
52
41
|
public address: ScallopAddress;
|
|
42
|
+
public constants: ScallopConstants;
|
|
53
43
|
public builder: ScallopBuilder;
|
|
54
44
|
public query: ScallopQuery;
|
|
55
45
|
public utils: ScallopUtils;
|
|
@@ -57,7 +47,7 @@ export class ScallopClient {
|
|
|
57
47
|
public walletAddress: string;
|
|
58
48
|
|
|
59
49
|
public constructor(
|
|
60
|
-
params: ScallopClientParams
|
|
50
|
+
params: ScallopClientParams,
|
|
61
51
|
instance?: ScallopClientInstanceParams
|
|
62
52
|
) {
|
|
63
53
|
this.params = params;
|
|
@@ -67,36 +57,42 @@ export class ScallopClient {
|
|
|
67
57
|
params?.walletAddress ?? this.suiKit.currentAddress()
|
|
68
58
|
);
|
|
69
59
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
this.
|
|
74
|
-
this.address = this.utils.address;
|
|
75
|
-
this.cache = this.address.cache;
|
|
76
|
-
} else {
|
|
77
|
-
this.cache = new ScallopCache(this.params, {
|
|
60
|
+
this.cache =
|
|
61
|
+
instance?.builder?.cache ??
|
|
62
|
+
instance?.cache ??
|
|
63
|
+
new ScallopCache(this.params, {
|
|
78
64
|
suiKit: this.suiKit,
|
|
79
65
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.utils = new ScallopUtils(this.params, {
|
|
66
|
+
|
|
67
|
+
this.address =
|
|
68
|
+
instance?.builder?.address ??
|
|
69
|
+
new ScallopAddress(this.params, {
|
|
70
|
+
cache: this.cache,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
this.constants =
|
|
74
|
+
instance?.builder?.constants ??
|
|
75
|
+
new ScallopConstants(this.params, {
|
|
91
76
|
address: this.address,
|
|
92
77
|
});
|
|
93
|
-
|
|
78
|
+
|
|
79
|
+
this.utils =
|
|
80
|
+
instance?.builder?.utils ??
|
|
81
|
+
new ScallopUtils(this.params, {
|
|
82
|
+
constants: this.constants,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
this.query =
|
|
86
|
+
instance?.builder?.query ??
|
|
87
|
+
new ScallopQuery(this.params, {
|
|
94
88
|
utils: this.utils,
|
|
95
89
|
});
|
|
96
|
-
|
|
90
|
+
|
|
91
|
+
this.builder =
|
|
92
|
+
instance?.builder ??
|
|
93
|
+
new ScallopBuilder(this.params, {
|
|
97
94
|
query: this.query,
|
|
98
95
|
});
|
|
99
|
-
}
|
|
100
96
|
}
|
|
101
97
|
|
|
102
98
|
/**
|
|
@@ -105,13 +101,13 @@ export class ScallopClient {
|
|
|
105
101
|
* @param force - Whether to force initialization.
|
|
106
102
|
*/
|
|
107
103
|
public async init(force: boolean = false) {
|
|
108
|
-
if (force || !this.
|
|
109
|
-
await this.
|
|
104
|
+
if (force || !this.constants.isInitialized) {
|
|
105
|
+
await this.constants.init();
|
|
110
106
|
}
|
|
111
107
|
|
|
112
|
-
await this.builder.init(force
|
|
113
|
-
await this.query.init(force
|
|
114
|
-
await this.utils.init(force
|
|
108
|
+
await this.builder.init(force);
|
|
109
|
+
await this.query.init(force);
|
|
110
|
+
await this.utils.init(force);
|
|
115
111
|
}
|
|
116
112
|
|
|
117
113
|
/* ==================== Query Method ==================== */
|
|
@@ -179,10 +175,7 @@ export class ScallopClient {
|
|
|
179
175
|
* @param ownerAddress - The owner address.
|
|
180
176
|
* @return Stake accounts data.
|
|
181
177
|
*/
|
|
182
|
-
async getStakeAccounts(
|
|
183
|
-
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
184
|
-
ownerAddress?: string
|
|
185
|
-
) {
|
|
178
|
+
async getStakeAccounts(stakeMarketCoinName: string, ownerAddress?: string) {
|
|
186
179
|
const owner = ownerAddress ?? this.walletAddress;
|
|
187
180
|
return await this.query.getStakeAccounts(stakeMarketCoinName, owner);
|
|
188
181
|
}
|
|
@@ -196,7 +189,7 @@ export class ScallopClient {
|
|
|
196
189
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
197
190
|
* @return Stake pool data.
|
|
198
191
|
*/
|
|
199
|
-
async getStakePool(stakeMarketCoinName:
|
|
192
|
+
async getStakePool(stakeMarketCoinName: string) {
|
|
200
193
|
return await this.query.getStakePool(stakeMarketCoinName);
|
|
201
194
|
}
|
|
202
195
|
|
|
@@ -209,7 +202,7 @@ export class ScallopClient {
|
|
|
209
202
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
210
203
|
* @return Reward pool data.
|
|
211
204
|
*/
|
|
212
|
-
async getStakeRewardPool(stakeMarketCoinName:
|
|
205
|
+
async getStakeRewardPool(stakeMarketCoinName: string) {
|
|
213
206
|
return await this.query.getStakeRewardPool(stakeMarketCoinName);
|
|
214
207
|
}
|
|
215
208
|
|
|
@@ -250,18 +243,18 @@ export class ScallopClient {
|
|
|
250
243
|
* @return Transaction block response or transaction block.
|
|
251
244
|
*/
|
|
252
245
|
public async depositCollateral(
|
|
253
|
-
collateralCoinName:
|
|
246
|
+
collateralCoinName: string,
|
|
254
247
|
amount: number
|
|
255
248
|
): Promise<SuiTransactionBlockResponse>;
|
|
256
249
|
public async depositCollateral<S extends boolean>(
|
|
257
|
-
collateralCoinName:
|
|
250
|
+
collateralCoinName: string,
|
|
258
251
|
amount: number,
|
|
259
252
|
sign?: S,
|
|
260
253
|
obligationId?: string,
|
|
261
254
|
walletAddress?: string
|
|
262
255
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
263
256
|
public async depositCollateral<S extends boolean>(
|
|
264
|
-
collateralCoinName:
|
|
257
|
+
collateralCoinName: string,
|
|
265
258
|
amount: number,
|
|
266
259
|
sign: S = true as S,
|
|
267
260
|
obligationId?: string,
|
|
@@ -307,7 +300,7 @@ export class ScallopClient {
|
|
|
307
300
|
* @return Transaction block response or transaction block.
|
|
308
301
|
*/
|
|
309
302
|
public async withdrawCollateral<S extends boolean>(
|
|
310
|
-
collateralCoinName:
|
|
303
|
+
collateralCoinName: string,
|
|
311
304
|
amount: number,
|
|
312
305
|
sign: S = true as S,
|
|
313
306
|
obligationId: string,
|
|
@@ -345,17 +338,17 @@ export class ScallopClient {
|
|
|
345
338
|
* @return Transaction block response or transaction block.
|
|
346
339
|
*/
|
|
347
340
|
public async deposit(
|
|
348
|
-
poolCoinName:
|
|
341
|
+
poolCoinName: string,
|
|
349
342
|
amount: number
|
|
350
343
|
): Promise<SuiTransactionBlockResponse>;
|
|
351
344
|
public async deposit<S extends boolean>(
|
|
352
|
-
poolCoinName:
|
|
345
|
+
poolCoinName: string,
|
|
353
346
|
amount: number,
|
|
354
347
|
sign?: S,
|
|
355
348
|
walletAddress?: string
|
|
356
349
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
357
350
|
public async deposit<S extends boolean>(
|
|
358
|
-
poolCoinName:
|
|
351
|
+
poolCoinName: string,
|
|
359
352
|
amount: number,
|
|
360
353
|
sign: S = true as S,
|
|
361
354
|
walletAddress?: string
|
|
@@ -387,18 +380,18 @@ export class ScallopClient {
|
|
|
387
380
|
* @return Transaction block response or transaction block.
|
|
388
381
|
*/
|
|
389
382
|
public async depositAndStake(
|
|
390
|
-
stakeCoinName:
|
|
383
|
+
stakeCoinName: string,
|
|
391
384
|
amount: number
|
|
392
385
|
): Promise<SuiTransactionBlockResponse>;
|
|
393
386
|
public async depositAndStake<S extends boolean>(
|
|
394
|
-
stakeCoinName:
|
|
387
|
+
stakeCoinName: string,
|
|
395
388
|
amount: number,
|
|
396
389
|
sign?: S,
|
|
397
390
|
stakeAccountId?: string,
|
|
398
391
|
walletAddress?: string
|
|
399
392
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
400
393
|
public async depositAndStake<S extends boolean>(
|
|
401
|
-
stakeCoinName:
|
|
394
|
+
stakeCoinName: string,
|
|
402
395
|
amount: number,
|
|
403
396
|
sign: S = true as S,
|
|
404
397
|
stakeAccountId?: string,
|
|
@@ -409,7 +402,7 @@ export class ScallopClient {
|
|
|
409
402
|
txBlock.setSender(sender);
|
|
410
403
|
|
|
411
404
|
const stakeMarketCoinName =
|
|
412
|
-
this.utils.parseMarketCoinName<
|
|
405
|
+
this.utils.parseMarketCoinName<string>(stakeCoinName);
|
|
413
406
|
const stakeAccounts =
|
|
414
407
|
await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
415
408
|
const targetStakeAccount = stakeAccountId ?? stakeAccounts[0]?.id;
|
|
@@ -446,17 +439,17 @@ export class ScallopClient {
|
|
|
446
439
|
* @return Transaction block response or transaction block.
|
|
447
440
|
*/
|
|
448
441
|
public async withdraw(
|
|
449
|
-
poolCoinName:
|
|
442
|
+
poolCoinName: string,
|
|
450
443
|
amount: number
|
|
451
444
|
): Promise<SuiTransactionBlockResponse>;
|
|
452
445
|
public async withdraw<S extends boolean>(
|
|
453
|
-
poolCoinName:
|
|
446
|
+
poolCoinName: string,
|
|
454
447
|
amount: number,
|
|
455
448
|
sign?: S,
|
|
456
449
|
walletAddress?: string
|
|
457
450
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
458
451
|
public async withdraw<S extends boolean>(
|
|
459
|
-
poolCoinName:
|
|
452
|
+
poolCoinName: string,
|
|
460
453
|
amount: number,
|
|
461
454
|
sign: S = true as S,
|
|
462
455
|
walletAddress?: string
|
|
@@ -489,7 +482,7 @@ export class ScallopClient {
|
|
|
489
482
|
* @return Transaction block response or transaction block.
|
|
490
483
|
*/
|
|
491
484
|
public async borrow<S extends boolean>(
|
|
492
|
-
poolCoinName:
|
|
485
|
+
poolCoinName: string,
|
|
493
486
|
amount: number,
|
|
494
487
|
sign: S = true as S,
|
|
495
488
|
obligationId: string,
|
|
@@ -501,7 +494,7 @@ export class ScallopClient {
|
|
|
501
494
|
txBlock.setSender(sender);
|
|
502
495
|
|
|
503
496
|
const availableStake = (
|
|
504
|
-
|
|
497
|
+
[...this.constants.whitelist.lending] as readonly string[]
|
|
505
498
|
).includes(poolCoinName);
|
|
506
499
|
if (sign && availableStake) {
|
|
507
500
|
await txBlock.unstakeObligationQuick(obligationId, obligationKey);
|
|
@@ -537,7 +530,7 @@ export class ScallopClient {
|
|
|
537
530
|
* @return Transaction block response or transaction block.
|
|
538
531
|
*/
|
|
539
532
|
public async repay<S extends boolean>(
|
|
540
|
-
poolCoinName:
|
|
533
|
+
poolCoinName: string,
|
|
541
534
|
amount: number,
|
|
542
535
|
sign: S = true as S,
|
|
543
536
|
obligationId: string,
|
|
@@ -549,7 +542,7 @@ export class ScallopClient {
|
|
|
549
542
|
txBlock.setSender(sender);
|
|
550
543
|
|
|
551
544
|
const availableStake = (
|
|
552
|
-
|
|
545
|
+
[...this.constants.whitelist.lending] as readonly string[]
|
|
553
546
|
).includes(poolCoinName);
|
|
554
547
|
if (sign && availableStake) {
|
|
555
548
|
await txBlock.unstakeObligationQuick(obligationId, obligationKey);
|
|
@@ -578,7 +571,7 @@ export class ScallopClient {
|
|
|
578
571
|
* @return Transaction block response or transaction block.
|
|
579
572
|
*/
|
|
580
573
|
public async flashLoan(
|
|
581
|
-
poolCoinName:
|
|
574
|
+
poolCoinName: string,
|
|
582
575
|
amount: number,
|
|
583
576
|
callback: (
|
|
584
577
|
txBlock: ScallopTxBlock,
|
|
@@ -586,7 +579,7 @@ export class ScallopClient {
|
|
|
586
579
|
) => SuiObjectArg
|
|
587
580
|
): Promise<SuiTransactionBlockResponse>;
|
|
588
581
|
public async flashLoan<S extends boolean>(
|
|
589
|
-
poolCoinName:
|
|
582
|
+
poolCoinName: string,
|
|
590
583
|
amount: number,
|
|
591
584
|
callback: (
|
|
592
585
|
txBlock: ScallopTxBlock,
|
|
@@ -596,7 +589,7 @@ export class ScallopClient {
|
|
|
596
589
|
walletAddress?: string
|
|
597
590
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
598
591
|
public async flashLoan<S extends boolean>(
|
|
599
|
-
poolCoinName:
|
|
592
|
+
poolCoinName: string,
|
|
600
593
|
amount: number,
|
|
601
594
|
callback: (
|
|
602
595
|
txBlock: ScallopTxBlock,
|
|
@@ -630,15 +623,15 @@ export class ScallopClient {
|
|
|
630
623
|
* @return Transaction block response or transaction block.
|
|
631
624
|
*/
|
|
632
625
|
public async createStakeAccount(
|
|
633
|
-
marketCoinName:
|
|
626
|
+
marketCoinName: string
|
|
634
627
|
): Promise<SuiTransactionBlockResponse>;
|
|
635
628
|
public async createStakeAccount<S extends boolean>(
|
|
636
|
-
marketCoinName:
|
|
629
|
+
marketCoinName: string,
|
|
637
630
|
sign?: S,
|
|
638
631
|
walletAddress?: string
|
|
639
632
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
640
633
|
public async createStakeAccount<S extends boolean>(
|
|
641
|
-
marketCoinName:
|
|
634
|
+
marketCoinName: string,
|
|
642
635
|
sign: S = true as S,
|
|
643
636
|
walletAddress?: string
|
|
644
637
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
@@ -669,18 +662,18 @@ export class ScallopClient {
|
|
|
669
662
|
* @return Transaction block response or transaction block.
|
|
670
663
|
*/
|
|
671
664
|
public async stake(
|
|
672
|
-
stakeMarketCoinName:
|
|
665
|
+
stakeMarketCoinName: string,
|
|
673
666
|
amount: number
|
|
674
667
|
): Promise<SuiTransactionBlockResponse>;
|
|
675
668
|
public async stake<S extends boolean>(
|
|
676
|
-
stakeMarketCoinName:
|
|
669
|
+
stakeMarketCoinName: string,
|
|
677
670
|
amount: number,
|
|
678
671
|
sign?: S,
|
|
679
672
|
stakeAccountId?: string,
|
|
680
673
|
walletAddress?: string
|
|
681
674
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
682
675
|
public async stake<S extends boolean>(
|
|
683
|
-
stakeMarketCoinName:
|
|
676
|
+
stakeMarketCoinName: string,
|
|
684
677
|
amount: number,
|
|
685
678
|
sign: S = true as S,
|
|
686
679
|
stakeAccountId?: string,
|
|
@@ -721,18 +714,18 @@ export class ScallopClient {
|
|
|
721
714
|
* @return Transaction block response or transaction block.
|
|
722
715
|
*/
|
|
723
716
|
public async unstake(
|
|
724
|
-
stakeMarketCoinName:
|
|
717
|
+
stakeMarketCoinName: string,
|
|
725
718
|
amount: number
|
|
726
719
|
): Promise<SuiTransactionBlockResponse>;
|
|
727
720
|
public async unstake<S extends boolean>(
|
|
728
|
-
stakeMarketCoinName:
|
|
721
|
+
stakeMarketCoinName: string,
|
|
729
722
|
amount: number,
|
|
730
723
|
sign?: S,
|
|
731
724
|
stakeAccountId?: string,
|
|
732
725
|
walletAddress?: string
|
|
733
726
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
734
727
|
public async unstake<S extends boolean>(
|
|
735
|
-
stakeMarketCoinName:
|
|
728
|
+
stakeMarketCoinName: string,
|
|
736
729
|
amount: number,
|
|
737
730
|
sign: S = true as S,
|
|
738
731
|
stakeAccountId?: string,
|
|
@@ -749,11 +742,15 @@ export class ScallopClient {
|
|
|
749
742
|
);
|
|
750
743
|
|
|
751
744
|
if (sCoin) {
|
|
745
|
+
const sCoinType = this.utils.parseSCoinType(stakeMarketCoinName);
|
|
746
|
+
if (!sCoinType)
|
|
747
|
+
throw new Error(`Invalid sCoin type: ${stakeMarketCoinName}`);
|
|
748
|
+
|
|
752
749
|
// merge to existing sCoins if exist
|
|
753
750
|
await this.utils.mergeSimilarCoins(
|
|
754
751
|
txBlock,
|
|
755
752
|
sCoin,
|
|
756
|
-
|
|
753
|
+
sCoinType,
|
|
757
754
|
requireSender(txBlock)
|
|
758
755
|
);
|
|
759
756
|
}
|
|
@@ -780,18 +777,18 @@ export class ScallopClient {
|
|
|
780
777
|
* @return Transaction block response or transaction block.
|
|
781
778
|
*/
|
|
782
779
|
public async unstakeAndWithdraw(
|
|
783
|
-
stakeMarketCoinName:
|
|
780
|
+
stakeMarketCoinName: string,
|
|
784
781
|
amount: number
|
|
785
782
|
): Promise<SuiTransactionBlockResponse>;
|
|
786
783
|
public async unstakeAndWithdraw<S extends boolean>(
|
|
787
|
-
stakeMarketCoinName:
|
|
784
|
+
stakeMarketCoinName: string,
|
|
788
785
|
amount: number,
|
|
789
786
|
sign?: S,
|
|
790
787
|
stakeAccountId?: string,
|
|
791
788
|
walletAddress?: string
|
|
792
789
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
793
790
|
public async unstakeAndWithdraw<S extends boolean>(
|
|
794
|
-
stakeMarketCoinName:
|
|
791
|
+
stakeMarketCoinName: string,
|
|
795
792
|
amount: number,
|
|
796
793
|
sign: S = true as S,
|
|
797
794
|
stakeAccountId?: string,
|
|
@@ -807,8 +804,7 @@ export class ScallopClient {
|
|
|
807
804
|
stakeAccountId,
|
|
808
805
|
false
|
|
809
806
|
);
|
|
810
|
-
const stakeCoinName =
|
|
811
|
-
this.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
|
|
807
|
+
const stakeCoinName = this.utils.parseCoinName(stakeMarketCoinName);
|
|
812
808
|
|
|
813
809
|
if (stakeMarketCoin) {
|
|
814
810
|
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
@@ -844,16 +840,16 @@ export class ScallopClient {
|
|
|
844
840
|
* @return Transaction block response or transaction block.
|
|
845
841
|
*/
|
|
846
842
|
public async claim(
|
|
847
|
-
stakeMarketCoinName:
|
|
843
|
+
stakeMarketCoinName: string
|
|
848
844
|
): Promise<SuiTransactionBlockResponse>;
|
|
849
845
|
public async claim<S extends boolean>(
|
|
850
|
-
stakeMarketCoinName:
|
|
846
|
+
stakeMarketCoinName: string,
|
|
851
847
|
sign?: S,
|
|
852
848
|
stakeAccountId?: string,
|
|
853
849
|
walletAddress?: string
|
|
854
850
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
855
851
|
public async claim<S extends boolean>(
|
|
856
|
-
stakeMarketCoinName:
|
|
852
|
+
stakeMarketCoinName: string,
|
|
857
853
|
sign: S = true as S,
|
|
858
854
|
stakeAccountId?: string,
|
|
859
855
|
walletAddress?: string
|
|
@@ -964,6 +960,7 @@ export class ScallopClient {
|
|
|
964
960
|
await this.query.getObligationAccount(obligationId);
|
|
965
961
|
if (!obligationAccount) throw new Error('Obligation not found');
|
|
966
962
|
const rewardCoinNames = Object.values(obligationAccount.borrowIncentives)
|
|
963
|
+
.filter((t): t is NonNullable<typeof t> => !!t)
|
|
967
964
|
.flatMap(({ rewards }) =>
|
|
968
965
|
rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
|
|
969
966
|
)
|
|
@@ -1015,7 +1012,7 @@ export class ScallopClient {
|
|
|
1015
1012
|
|
|
1016
1013
|
const toTransfer: SuiObjectArg[] = [];
|
|
1017
1014
|
await Promise.all(
|
|
1018
|
-
|
|
1015
|
+
[...this.constants.whitelist.scoin].map(async (sCoinName) => {
|
|
1019
1016
|
/**
|
|
1020
1017
|
* First check marketCoin inside mini wallet
|
|
1021
1018
|
* Then check stakedMarketCoin inside spool
|
|
@@ -1027,7 +1024,7 @@ export class ScallopClient {
|
|
|
1027
1024
|
try {
|
|
1028
1025
|
const marketCoins = await this.utils.selectCoins(
|
|
1029
1026
|
Number.MAX_SAFE_INTEGER,
|
|
1030
|
-
this.utils.parseMarketCoinType(sCoinName as
|
|
1027
|
+
this.utils.parseMarketCoinType(sCoinName as string),
|
|
1031
1028
|
this.walletAddress
|
|
1032
1029
|
); // throw error no coins found
|
|
1033
1030
|
|
|
@@ -1046,26 +1043,28 @@ export class ScallopClient {
|
|
|
1046
1043
|
if (toDestroyMarketCoin) {
|
|
1047
1044
|
// mint new sCoin
|
|
1048
1045
|
const sCoin = txBlock.mintSCoin(
|
|
1049
|
-
sCoinName as
|
|
1046
|
+
sCoinName as string,
|
|
1050
1047
|
toDestroyMarketCoin
|
|
1051
1048
|
);
|
|
1052
1049
|
|
|
1050
|
+
const sCoinType = this.utils.parseSCoinType(sCoinName as string);
|
|
1051
|
+
if (!sCoinType) throw new Error('Invalid sCoin type');
|
|
1053
1052
|
// Merge with existing sCoin
|
|
1054
1053
|
await this.utils.mergeSimilarCoins(
|
|
1055
1054
|
txBlock,
|
|
1056
1055
|
sCoin,
|
|
1057
|
-
|
|
1056
|
+
sCoinType,
|
|
1058
1057
|
requireSender(txBlock)
|
|
1059
1058
|
);
|
|
1060
1059
|
sCoins.push(sCoin);
|
|
1061
1060
|
}
|
|
1062
1061
|
if (includeStakePool) {
|
|
1063
1062
|
// check for staked market coin in spool
|
|
1064
|
-
if (
|
|
1063
|
+
if (this.constants.whitelist.spool.has(sCoinName as string)) {
|
|
1065
1064
|
try {
|
|
1066
1065
|
const sCoin = await txBlock.unstakeQuick(
|
|
1067
1066
|
Number.MAX_SAFE_INTEGER,
|
|
1068
|
-
sCoinName as
|
|
1067
|
+
sCoinName as string
|
|
1069
1068
|
);
|
|
1070
1069
|
if (sCoin) {
|
|
1071
1070
|
sCoins.push(sCoin);
|
|
@@ -1178,17 +1177,17 @@ export class ScallopClient {
|
|
|
1178
1177
|
* @return Transaction block response or transaction block.
|
|
1179
1178
|
*/
|
|
1180
1179
|
public async mintTestCoin(
|
|
1181
|
-
assetCoinName: Exclude<
|
|
1180
|
+
assetCoinName: Exclude<string, 'sui'>,
|
|
1182
1181
|
amount: number
|
|
1183
1182
|
): Promise<SuiTransactionBlockResponse>;
|
|
1184
1183
|
public async mintTestCoin<S extends boolean>(
|
|
1185
|
-
assetCoinName: Exclude<
|
|
1184
|
+
assetCoinName: Exclude<string, 'sui'>,
|
|
1186
1185
|
amount: number,
|
|
1187
1186
|
sign?: S,
|
|
1188
1187
|
receiveAddress?: string
|
|
1189
1188
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
1190
1189
|
public async mintTestCoin<S extends boolean>(
|
|
1191
|
-
assetCoinName: Exclude<
|
|
1190
|
+
assetCoinName: Exclude<string, 'sui'>,
|
|
1192
1191
|
amount: number,
|
|
1193
1192
|
sign: S = true as S,
|
|
1194
1193
|
receiveAddress?: string
|