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