@scallop-io/sui-scallop-sdk 1.4.0 → 1.4.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/constants/common.d.ts +1 -1
- package/dist/constants/enum.d.ts +1 -1
- package/dist/index.js +156 -107
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +155 -106
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +4 -4
- package/dist/models/scallopQuery.d.ts +42 -0
- package/dist/models/scallopUtils.d.ts +10 -10
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -2
- package/dist/queries/priceQuery.d.ts +36 -2
- package/dist/types/builder/borrowIncentive.d.ts +6 -6
- package/dist/types/constant/common.d.ts +1 -1
- package/dist/types/utils.d.ts +2 -6
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +2 -13
- package/src/constants/common.ts +4 -2
- package/src/constants/enum.ts +11 -16
- package/src/models/scallopClient.ts +27 -10
- package/src/models/scallopQuery.ts +18 -1
- package/src/models/scallopUtils.ts +23 -18
- package/src/queries/borrowIncentiveQuery.ts +29 -12
- package/src/queries/coreQuery.ts +4 -10
- package/src/queries/portfolioQuery.ts +65 -62
- package/src/queries/priceQuery.ts +35 -2
- package/src/queries/sCoinQuery.ts +1 -1
- package/src/queries/spoolQuery.ts +2 -4
- package/src/types/builder/borrowIncentive.ts +10 -15
- package/src/types/constant/common.ts +1 -2
- package/src/types/utils.ts +2 -10
- package/src/utils/query.ts +0 -87
|
@@ -7,7 +7,7 @@ import type { SuiTransactionBlockResponse } from '@mysten/sui/client';
|
|
|
7
7
|
import type { TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
8
8
|
import { ScallopCache } from './scallopCache';
|
|
9
9
|
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
10
|
-
import type { ScallopClientFnReturnType, ScallopClientParams, SupportPoolCoins, SupportCollateralCoins, SupportAssetCoins, SupportStakeCoins, SupportStakeMarketCoins,
|
|
10
|
+
import type { ScallopClientFnReturnType, ScallopClientParams, SupportPoolCoins, SupportCollateralCoins, SupportAssetCoins, SupportStakeCoins, SupportStakeMarketCoins, ScallopTxBlock, ScallopClientVeScaReturnType, ScallopClientInstanceParams } from '../types';
|
|
11
11
|
/**
|
|
12
12
|
* @description
|
|
13
13
|
* It provides contract interaction operations for general users.
|
|
@@ -284,16 +284,16 @@ export declare class ScallopClient {
|
|
|
284
284
|
*/
|
|
285
285
|
unstakeObligation<S extends boolean>(obligationId: string, obligationKeyId: string, sign?: S, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
|
|
286
286
|
/**
|
|
287
|
-
*
|
|
287
|
+
* Claim borrow incentive reward.
|
|
288
288
|
*
|
|
289
|
-
* @param
|
|
289
|
+
* @param poolName
|
|
290
290
|
* @param amount - The amount of coins would deposit.
|
|
291
291
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
292
292
|
* @param accountId - The stake account object.
|
|
293
293
|
* @param walletAddress - The wallet address of the owner.
|
|
294
294
|
* @return Transaction block response or transaction block
|
|
295
295
|
*/
|
|
296
|
-
claimBorrowIncentive<S extends boolean>(
|
|
296
|
+
claimBorrowIncentive<S extends boolean>(obligationId: string, obligationKeyId: string, sign?: S, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
|
|
297
297
|
/**
|
|
298
298
|
* Function to migrate all market coin in user wallet into sCoin
|
|
299
299
|
* @returns Transaction response
|
|
@@ -308,6 +308,7 @@ export declare class ScallopQuery {
|
|
|
308
308
|
getBorrowIncentivePools(coinNames?: SupportBorrowIncentiveCoins[], args?: {
|
|
309
309
|
coinPrices: CoinPrices;
|
|
310
310
|
indexer?: boolean;
|
|
311
|
+
marketPools?: MarketPools;
|
|
311
312
|
}): Promise<{
|
|
312
313
|
usdc?: import("../types").BorrowIncentivePool | undefined;
|
|
313
314
|
sbeth?: import("../types").BorrowIncentivePool | undefined;
|
|
@@ -514,4 +515,45 @@ export declare class ScallopQuery {
|
|
|
514
515
|
* @returns price data
|
|
515
516
|
*/
|
|
516
517
|
getCoinPriceByIndexer(poolName: SupportPoolCoins): Promise<number>;
|
|
518
|
+
/**
|
|
519
|
+
* Get all coin prices, including sCoin
|
|
520
|
+
* @returns prices data
|
|
521
|
+
*/
|
|
522
|
+
getAllCoinPrices(args?: {
|
|
523
|
+
marketPools?: MarketPools;
|
|
524
|
+
coinPrices?: CoinPrices;
|
|
525
|
+
}): Promise<{
|
|
526
|
+
susdc?: number | undefined;
|
|
527
|
+
ssbeth?: number | undefined;
|
|
528
|
+
sweth?: number | undefined;
|
|
529
|
+
swbtc?: number | undefined;
|
|
530
|
+
swusdc?: number | undefined;
|
|
531
|
+
swusdt?: number | undefined;
|
|
532
|
+
ssui?: number | undefined;
|
|
533
|
+
swsol?: number | undefined;
|
|
534
|
+
scetus?: number | undefined;
|
|
535
|
+
safsui?: number | undefined;
|
|
536
|
+
shasui?: number | undefined;
|
|
537
|
+
svsui?: number | undefined;
|
|
538
|
+
ssca?: number | undefined;
|
|
539
|
+
sfud?: number | undefined;
|
|
540
|
+
sdeep?: number | undefined;
|
|
541
|
+
usdc?: number | undefined;
|
|
542
|
+
sbeth?: number | undefined;
|
|
543
|
+
weth?: number | undefined;
|
|
544
|
+
wbtc?: number | undefined;
|
|
545
|
+
wusdc?: number | undefined;
|
|
546
|
+
wusdt?: number | undefined;
|
|
547
|
+
sui?: number | undefined;
|
|
548
|
+
wapt?: number | undefined;
|
|
549
|
+
wsol?: number | undefined;
|
|
550
|
+
cetus?: number | undefined;
|
|
551
|
+
afsui?: number | undefined;
|
|
552
|
+
hasui?: number | undefined;
|
|
553
|
+
vsui?: number | undefined;
|
|
554
|
+
sca?: number | undefined;
|
|
555
|
+
fud?: number | undefined;
|
|
556
|
+
deep?: number | undefined;
|
|
557
|
+
swapt?: number | undefined;
|
|
558
|
+
}>;
|
|
517
559
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SuiKit } from '@scallop-io/sui-kit';
|
|
2
2
|
import { ScallopAddress } from './scallopAddress';
|
|
3
3
|
import { ScallopCache } from './scallopCache';
|
|
4
|
-
import type { ScallopUtilsParams, SupportCoins, SupportAssetCoins, SupportMarketCoins, SupportStakeMarketCoins,
|
|
4
|
+
import type { ScallopUtilsParams, SupportCoins, SupportAssetCoins, SupportMarketCoins, SupportStakeMarketCoins, CoinWrappedType, SupportSCoin, ScallopUtilsInstanceParams, SupportSuiBridgeCoins, SupportWormholeCoins, PoolAddressInfo } from '../types';
|
|
5
5
|
import type { SuiObjectArg, SuiTxArg, SuiTxBlock } from '@scallop-io/sui-kit';
|
|
6
6
|
/**
|
|
7
7
|
* @description
|
|
@@ -50,7 +50,7 @@ export declare class ScallopUtils {
|
|
|
50
50
|
* @param coinName - Specific support coin name.
|
|
51
51
|
* @return Coin type.
|
|
52
52
|
*/
|
|
53
|
-
parseCoinType(coinName: SupportCoins): string;
|
|
53
|
+
parseCoinType(coinName: SupportCoins, useOldMarketCoin?: boolean): string;
|
|
54
54
|
/**
|
|
55
55
|
* Convert coin name to sCoin name.
|
|
56
56
|
*
|
|
@@ -58,6 +58,13 @@ export declare class ScallopUtils {
|
|
|
58
58
|
* @return sCoin name.
|
|
59
59
|
*/
|
|
60
60
|
parseSCoinName<T extends SupportSCoin>(coinName: SupportCoins | SupportMarketCoins): T | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Convert sCoin name to coin name.
|
|
63
|
+
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
64
|
+
* e.g: `scallop_sui -> ssui
|
|
65
|
+
* @return sCoin name
|
|
66
|
+
*/
|
|
67
|
+
parseCoinNameFromSCoinName(coinName: string): "susdc" | "ssbeth" | "sweth" | "swbtc" | "swusdc" | "swusdt" | "ssui" | "swsol" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "sfud" | "sdeep";
|
|
61
68
|
/**
|
|
62
69
|
* Convert sCoin name into sCoin type
|
|
63
70
|
* @param sCoinName
|
|
@@ -124,13 +131,6 @@ export declare class ScallopUtils {
|
|
|
124
131
|
* @return Spool reward coin name.
|
|
125
132
|
*/
|
|
126
133
|
getSpoolRewardCoinName: (stakeMarketCoinName: SupportStakeMarketCoins) => "sui";
|
|
127
|
-
/**
|
|
128
|
-
* Get reward type of borrow incentive pool.
|
|
129
|
-
*
|
|
130
|
-
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
131
|
-
* @return Borrow incentive reward coin name.
|
|
132
|
-
*/
|
|
133
|
-
getBorrowIncentiveRewardCoinName: (borrowIncentiveCoinName: SupportBorrowIncentiveCoins) => ("sui" | "sca")[];
|
|
134
134
|
/**
|
|
135
135
|
* Get coin decimal.
|
|
136
136
|
*
|
|
@@ -188,7 +188,7 @@ export declare class ScallopUtils {
|
|
|
188
188
|
* @param assetCoinNames - Specific an array of support asset coin name.
|
|
189
189
|
* @return Asset coin price.
|
|
190
190
|
*/
|
|
191
|
-
getCoinPrices(_?: SupportAssetCoins[]): Promise<import("../types").OptionalKeys<Record<
|
|
191
|
+
getCoinPrices(_?: SupportAssetCoins[]): Promise<import("../types").OptionalKeys<Record<SupportCoins, number>>>;
|
|
192
192
|
/**
|
|
193
193
|
* Convert apr to apy.
|
|
194
194
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ScallopAddress, ScallopQuery, ScallopUtils } from '../models';
|
|
2
|
-
import type { BorrowIncentivePoolsQueryInterface, SupportBorrowIncentiveCoins, BorrowIncentivePool, CoinPrices } from '../types';
|
|
2
|
+
import type { BorrowIncentivePoolsQueryInterface, SupportBorrowIncentiveCoins, BorrowIncentivePool, CoinPrices, MarketPools } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Query borrow incentive pools data using moveCall
|
|
5
5
|
* @param address
|
|
@@ -14,7 +14,7 @@ export declare const queryBorrowIncentivePools: (address: ScallopAddress) => Pro
|
|
|
14
14
|
* @param indexer - Whether to use indexer.
|
|
15
15
|
* @return Borrow incentive pools data.
|
|
16
16
|
*/
|
|
17
|
-
export declare const getBorrowIncentivePools: (query: ScallopQuery, borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[], indexer?: boolean, coinPrices?: CoinPrices) => Promise<{
|
|
17
|
+
export declare const getBorrowIncentivePools: (query: ScallopQuery, borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[], indexer?: boolean, marketPools?: MarketPools, coinPrices?: CoinPrices) => Promise<{
|
|
18
18
|
usdc?: BorrowIncentivePool | undefined;
|
|
19
19
|
sbeth?: BorrowIncentivePool | undefined;
|
|
20
20
|
weth?: BorrowIncentivePool | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
2
|
-
import type { ScallopAddress } from '../models';
|
|
3
|
-
import type { SupportAssetCoins } from '../types';
|
|
2
|
+
import type { ScallopAddress, ScallopQuery } from '../models';
|
|
3
|
+
import type { CoinPrices, MarketPools, SupportAssetCoins } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Get price from pyth fee object.
|
|
6
6
|
*
|
|
@@ -14,3 +14,37 @@ export declare const getPythPrice: ({ address, }: {
|
|
|
14
14
|
export declare const getPythPrices: ({ address, }: {
|
|
15
15
|
address: ScallopAddress;
|
|
16
16
|
}, assetCoinNames: SupportAssetCoins[]) => Promise<Record<SupportAssetCoins, number>>;
|
|
17
|
+
export declare const getAllCoinPrices: (query: ScallopQuery, marketPools?: MarketPools, coinPrices?: CoinPrices) => Promise<{
|
|
18
|
+
susdc?: number | undefined;
|
|
19
|
+
ssbeth?: number | undefined;
|
|
20
|
+
sweth?: number | undefined;
|
|
21
|
+
swbtc?: number | undefined;
|
|
22
|
+
swusdc?: number | undefined;
|
|
23
|
+
swusdt?: number | undefined;
|
|
24
|
+
ssui?: number | undefined;
|
|
25
|
+
swsol?: number | undefined;
|
|
26
|
+
scetus?: number | undefined;
|
|
27
|
+
safsui?: number | undefined;
|
|
28
|
+
shasui?: number | undefined;
|
|
29
|
+
svsui?: number | undefined;
|
|
30
|
+
ssca?: number | undefined;
|
|
31
|
+
sfud?: number | undefined;
|
|
32
|
+
sdeep?: number | undefined;
|
|
33
|
+
usdc?: number | undefined;
|
|
34
|
+
sbeth?: number | undefined;
|
|
35
|
+
weth?: number | undefined;
|
|
36
|
+
wbtc?: number | undefined;
|
|
37
|
+
wusdc?: number | undefined;
|
|
38
|
+
wusdt?: number | undefined;
|
|
39
|
+
sui?: number | undefined;
|
|
40
|
+
wapt?: number | undefined;
|
|
41
|
+
wsol?: number | undefined;
|
|
42
|
+
cetus?: number | undefined;
|
|
43
|
+
afsui?: number | undefined;
|
|
44
|
+
hasui?: number | undefined;
|
|
45
|
+
vsui?: number | undefined;
|
|
46
|
+
sca?: number | undefined;
|
|
47
|
+
fud?: number | undefined;
|
|
48
|
+
deep?: number | undefined;
|
|
49
|
+
swapt?: number | undefined;
|
|
50
|
+
}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SuiTxBlock as SuiKitTxBlock, SuiObjectArg } from '@scallop-io/sui-kit';
|
|
2
2
|
import type { TransactionResult } from '@mysten/sui/transactions';
|
|
3
3
|
import type { ScallopBuilder } from '../../models';
|
|
4
|
-
import type {
|
|
4
|
+
import type { SupportBorrowIncentiveRewardCoins } from '../constant';
|
|
5
5
|
export type BorrowIncentiveIds = {
|
|
6
6
|
borrowIncentivePkg: string;
|
|
7
7
|
query: string;
|
|
@@ -14,14 +14,14 @@ export type BorrowIncentiveNormalMethods = {
|
|
|
14
14
|
stakeObligation: (obligation: SuiObjectArg, obligationKey: SuiObjectArg) => void;
|
|
15
15
|
stakeObligationWithVesca: (obligation: SuiObjectArg, obligationKey: SuiObjectArg, veScaKey: SuiObjectArg) => void;
|
|
16
16
|
unstakeObligation: (obligation: SuiObjectArg, obligationKey: SuiObjectArg) => void;
|
|
17
|
-
claimBorrowIncentive: (obligation: SuiObjectArg, obligationKey: SuiObjectArg,
|
|
17
|
+
claimBorrowIncentive: (obligation: SuiObjectArg, obligationKey: SuiObjectArg, rewardType: SupportBorrowIncentiveRewardCoins) => TransactionResult;
|
|
18
18
|
deactivateBoost: (obligation: SuiObjectArg, veScaKey: SuiObjectArg) => void;
|
|
19
19
|
};
|
|
20
20
|
export type BorrowIncentiveQuickMethods = {
|
|
21
|
-
stakeObligationQuick(obligation?:
|
|
22
|
-
stakeObligationWithVeScaQuick(obligation?:
|
|
23
|
-
unstakeObligationQuick(obligation?:
|
|
24
|
-
claimBorrowIncentiveQuick(
|
|
21
|
+
stakeObligationQuick(obligation?: string, obligationKey?: string): Promise<void>;
|
|
22
|
+
stakeObligationWithVeScaQuick(obligation?: string, obligationKey?: string, veScaKey?: string): Promise<void>;
|
|
23
|
+
unstakeObligationQuick(obligation?: string, obligationKey?: string): Promise<void>;
|
|
24
|
+
claimBorrowIncentiveQuick(rewardType: SupportBorrowIncentiveRewardCoins, obligation?: string, obligationKey?: string): Promise<TransactionResult>;
|
|
25
25
|
};
|
|
26
26
|
export type SuiTxBlockWithBorrowIncentiveNormalMethods = SuiKitTxBlock & BorrowIncentiveNormalMethods;
|
|
27
27
|
export type BorrowIncentiveTxBlock = SuiTxBlockWithBorrowIncentiveNormalMethods & BorrowIncentiveQuickMethods;
|
|
@@ -2,7 +2,7 @@ import { SUPPORT_POOLS, SUPPORT_COLLATERALS, SUPPORT_ORACLES, SUPPORT_PACKAGES,
|
|
|
2
2
|
type ParseMarketCoins<T extends string> = `s${T}`;
|
|
3
3
|
type ParseCoins<T extends string> = T extends `s${infer R}` ? R : never;
|
|
4
4
|
export type SupportCoins = SupportAssetCoins | SupportMarketCoins | SupportStakeMarketCoins | SupportSCoin;
|
|
5
|
-
export type SupportAssetCoins = SupportPoolCoins | SupportCollateralCoins | SupportStakeRewardCoins
|
|
5
|
+
export type SupportAssetCoins = SupportPoolCoins | SupportCollateralCoins | SupportStakeRewardCoins;
|
|
6
6
|
export type SupportPoolCoins = (typeof SUPPORT_POOLS)[number];
|
|
7
7
|
export type SupportCollateralCoins = (typeof SUPPORT_COLLATERALS)[number];
|
|
8
8
|
export type SupportMarketCoins = ParseMarketCoins<SupportPoolCoins> | SupportStakeMarketCoins;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SupportCoins } from './constant';
|
|
2
2
|
export type OptionalKeys<T> = {
|
|
3
3
|
[K in keyof T]?: T[K];
|
|
4
4
|
};
|
|
5
|
-
export type CoinPrices = OptionalKeys<Record<
|
|
6
|
-
export type PriceMap = Map<SupportAssetCoins, {
|
|
7
|
-
price: number;
|
|
8
|
-
publishTime: number;
|
|
9
|
-
}>;
|
|
5
|
+
export type CoinPrices = OptionalKeys<Record<SupportCoins, number>>;
|
|
10
6
|
export type PoolAddressInfo = {
|
|
11
7
|
name: string;
|
|
12
8
|
coingeckoId: string;
|
package/package.json
CHANGED
|
@@ -143,17 +143,7 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
143
143
|
]
|
|
144
144
|
);
|
|
145
145
|
},
|
|
146
|
-
claimBorrowIncentive: (
|
|
147
|
-
obligationId,
|
|
148
|
-
obligationKey,
|
|
149
|
-
coinName,
|
|
150
|
-
rewardCoinName
|
|
151
|
-
) => {
|
|
152
|
-
const rewardCoinNames =
|
|
153
|
-
builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
154
|
-
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
155
|
-
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
156
|
-
}
|
|
146
|
+
claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
|
|
157
147
|
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
158
148
|
return txBlock.moveCall(
|
|
159
149
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
@@ -284,11 +274,11 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
|
|
|
284
274
|
}
|
|
285
275
|
},
|
|
286
276
|
claimBorrowIncentiveQuick: async (
|
|
287
|
-
coinName,
|
|
288
277
|
rewardCoinName,
|
|
289
278
|
obligation,
|
|
290
279
|
obligationKey
|
|
291
280
|
) => {
|
|
281
|
+
// check for available reward coin names
|
|
292
282
|
const { obligationId: obligationArg, obligationKey: obligationKeyArg } =
|
|
293
283
|
await requireObligationInfo(
|
|
294
284
|
builder,
|
|
@@ -300,7 +290,6 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
|
|
|
300
290
|
return txBlock.claimBorrowIncentive(
|
|
301
291
|
obligationArg,
|
|
302
292
|
obligationKeyArg,
|
|
303
|
-
coinName,
|
|
304
293
|
rewardCoinName
|
|
305
294
|
);
|
|
306
295
|
},
|
package/src/constants/common.ts
CHANGED
|
@@ -9,7 +9,6 @@ export const ADDRESSES_ID =
|
|
|
9
9
|
? ('65fb07c39c845425d71d7b18' as const)
|
|
10
10
|
: ('675c65cd301dd817ea262e76' as const);
|
|
11
11
|
// : ('66f8e7ed9bb9e07fdfb86bbb' as const);
|
|
12
|
-
// : ('664dfe22898c36c159e28bc8' as const);
|
|
13
12
|
|
|
14
13
|
export const PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST
|
|
15
14
|
? ('0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778' as const)
|
|
@@ -121,7 +120,10 @@ export const SUPPORT_BORROW_INCENTIVE_POOLS = [
|
|
|
121
120
|
'usdc',
|
|
122
121
|
] as const;
|
|
123
122
|
|
|
124
|
-
export const SUPPORT_BORROW_INCENTIVE_REWARDS = [
|
|
123
|
+
export const SUPPORT_BORROW_INCENTIVE_REWARDS = [
|
|
124
|
+
...SUPPORT_POOLS,
|
|
125
|
+
...SUPPORT_SCOIN,
|
|
126
|
+
] as const;
|
|
125
127
|
export const SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;
|
|
126
128
|
|
|
127
129
|
export const SUPPORT_PACKAGES = [
|
package/src/constants/enum.ts
CHANGED
|
@@ -120,19 +120,6 @@ export const suiBridgeCoins: types.SuiBridgeCoins = {
|
|
|
120
120
|
sbeth: 'sbeth',
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
export const borrowIncentiveRewardCoins: types.BorrowIncentiveRewardCoins = {
|
|
124
|
-
usdc: ['sui', 'sca'],
|
|
125
|
-
sui: ['sui', 'sca'],
|
|
126
|
-
wusdc: ['sui', 'sca'],
|
|
127
|
-
wusdt: ['sui', 'sca'],
|
|
128
|
-
sca: ['sui', 'sca'],
|
|
129
|
-
afsui: ['sui'],
|
|
130
|
-
hasui: ['sui'],
|
|
131
|
-
vsui: ['sui'],
|
|
132
|
-
weth: ['sui'],
|
|
133
|
-
sbeth: ['sui'],
|
|
134
|
-
};
|
|
135
|
-
|
|
136
123
|
export const coinIds: types.AssetCoinIds = {
|
|
137
124
|
usdc: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7',
|
|
138
125
|
sui: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
@@ -175,13 +162,13 @@ export const sCoinIds: types.SCoinIds = {
|
|
|
175
162
|
ssbeth:
|
|
176
163
|
'0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH',
|
|
177
164
|
ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
|
|
178
|
-
scetus:
|
|
179
|
-
'0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS',
|
|
180
|
-
ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
|
|
181
165
|
swusdc:
|
|
182
166
|
'0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
183
167
|
swusdt:
|
|
184
168
|
'0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
169
|
+
ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
|
|
170
|
+
scetus:
|
|
171
|
+
'0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS',
|
|
185
172
|
sweth:
|
|
186
173
|
'0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH',
|
|
187
174
|
safsui:
|
|
@@ -207,6 +194,14 @@ export const sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
|
207
194
|
{} as Record<string, types.SupportSCoin>
|
|
208
195
|
);
|
|
209
196
|
|
|
197
|
+
export const sCoinRawNameToName = Object.entries(sCoinIds).reduce(
|
|
198
|
+
(acc, [coinName, coinType]) => {
|
|
199
|
+
acc[coinType.split('::')[2].toLowerCase()] = coinName as types.SupportSCoin;
|
|
200
|
+
return acc;
|
|
201
|
+
},
|
|
202
|
+
{} as Record<string, types.SupportSCoin>
|
|
203
|
+
);
|
|
204
|
+
|
|
210
205
|
// TEST VERSION
|
|
211
206
|
// export const sCoinIds: types.SCoinIds = {
|
|
212
207
|
// ssui: '0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI',
|
|
@@ -4,7 +4,6 @@ import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
|
4
4
|
import {
|
|
5
5
|
ADDRESSES_ID,
|
|
6
6
|
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
7
|
-
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
8
7
|
SUPPORT_SCOIN,
|
|
9
8
|
SUPPORT_SPOOLS,
|
|
10
9
|
} from '../constants';
|
|
@@ -28,7 +27,6 @@ import type {
|
|
|
28
27
|
SupportAssetCoins,
|
|
29
28
|
SupportStakeCoins,
|
|
30
29
|
SupportStakeMarketCoins,
|
|
31
|
-
SupportBorrowIncentiveCoins,
|
|
32
30
|
ScallopTxBlock,
|
|
33
31
|
SupportSCoin,
|
|
34
32
|
ScallopClientVeScaReturnType,
|
|
@@ -945,9 +943,9 @@ export class ScallopClient {
|
|
|
945
943
|
}
|
|
946
944
|
|
|
947
945
|
/**
|
|
948
|
-
*
|
|
946
|
+
* Claim borrow incentive reward.
|
|
949
947
|
*
|
|
950
|
-
* @param
|
|
948
|
+
* @param poolName
|
|
951
949
|
* @param amount - The amount of coins would deposit.
|
|
952
950
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
953
951
|
* @param accountId - The stake account object.
|
|
@@ -955,7 +953,6 @@ export class ScallopClient {
|
|
|
955
953
|
* @return Transaction block response or transaction block
|
|
956
954
|
*/
|
|
957
955
|
public async claimBorrowIncentive<S extends boolean>(
|
|
958
|
-
coinName: SupportBorrowIncentiveCoins,
|
|
959
956
|
obligationId: string,
|
|
960
957
|
obligationKeyId: string,
|
|
961
958
|
sign: S = true as S,
|
|
@@ -965,17 +962,37 @@ export class ScallopClient {
|
|
|
965
962
|
const sender = walletAddress ?? this.walletAddress;
|
|
966
963
|
txBlock.setSender(sender);
|
|
967
964
|
|
|
968
|
-
const
|
|
969
|
-
|
|
965
|
+
const rewardCoinsCollection: Record<string, TransactionResult[]> = {};
|
|
966
|
+
const obligationAccount =
|
|
967
|
+
await this.query.getObligationAccount(obligationId);
|
|
968
|
+
const rewardCoinNames = Object.values(obligationAccount.borrowIncentives)
|
|
969
|
+
.flatMap(({ rewards }) =>
|
|
970
|
+
rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
|
|
971
|
+
)
|
|
972
|
+
.flatMap(({ coinName }) => coinName);
|
|
973
|
+
for (const rewardCoinName of rewardCoinNames) {
|
|
970
974
|
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
971
|
-
coinName,
|
|
972
975
|
rewardCoinName,
|
|
973
976
|
obligationId,
|
|
974
977
|
obligationKeyId
|
|
975
978
|
);
|
|
976
|
-
|
|
979
|
+
if (!rewardCoinsCollection[rewardCoinName]) {
|
|
980
|
+
rewardCoinsCollection[rewardCoinName] = [rewardCoin];
|
|
981
|
+
} else {
|
|
982
|
+
rewardCoinsCollection[rewardCoinName].push(rewardCoin);
|
|
983
|
+
}
|
|
977
984
|
}
|
|
978
|
-
|
|
985
|
+
|
|
986
|
+
txBlock.transferObjects(
|
|
987
|
+
Object.values(rewardCoinsCollection).map((rewardCoins) => {
|
|
988
|
+
const mergeDest = rewardCoins[0];
|
|
989
|
+
if (rewardCoins.length > 1) {
|
|
990
|
+
txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
|
|
991
|
+
}
|
|
992
|
+
return mergeDest;
|
|
993
|
+
}),
|
|
994
|
+
sender
|
|
995
|
+
);
|
|
979
996
|
|
|
980
997
|
if (sign) {
|
|
981
998
|
return (await this.suiKit.signAndSendTxn(
|
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
getSCoinAmounts,
|
|
48
48
|
getSCoinSwapRate,
|
|
49
49
|
getSCoinTotalSupply,
|
|
50
|
+
getAllCoinPrices,
|
|
50
51
|
} from '../queries';
|
|
51
52
|
import {
|
|
52
53
|
ScallopQueryParams,
|
|
@@ -544,12 +545,17 @@ export class ScallopQuery {
|
|
|
544
545
|
*/
|
|
545
546
|
public async getBorrowIncentivePools(
|
|
546
547
|
coinNames?: SupportBorrowIncentiveCoins[],
|
|
547
|
-
args?: {
|
|
548
|
+
args?: {
|
|
549
|
+
coinPrices: CoinPrices;
|
|
550
|
+
indexer?: boolean;
|
|
551
|
+
marketPools?: MarketPools;
|
|
552
|
+
}
|
|
548
553
|
) {
|
|
549
554
|
return await getBorrowIncentivePools(
|
|
550
555
|
this,
|
|
551
556
|
coinNames,
|
|
552
557
|
args?.indexer,
|
|
558
|
+
args?.marketPools,
|
|
553
559
|
args?.coinPrices
|
|
554
560
|
);
|
|
555
561
|
}
|
|
@@ -824,4 +830,15 @@ export class ScallopQuery {
|
|
|
824
830
|
public async getCoinPriceByIndexer(poolName: SupportPoolCoins) {
|
|
825
831
|
return this.indexer.getCoinPrice(poolName);
|
|
826
832
|
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Get all coin prices, including sCoin
|
|
836
|
+
* @returns prices data
|
|
837
|
+
*/
|
|
838
|
+
public async getAllCoinPrices(args?: {
|
|
839
|
+
marketPools?: MarketPools;
|
|
840
|
+
coinPrices?: CoinPrices;
|
|
841
|
+
}) {
|
|
842
|
+
return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
|
|
843
|
+
}
|
|
827
844
|
}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
SUPPORT_POOLS,
|
|
9
9
|
SUPPORT_COLLATERALS,
|
|
10
10
|
spoolRewardCoins,
|
|
11
|
-
borrowIncentiveRewardCoins,
|
|
12
11
|
coinDecimals,
|
|
13
12
|
wormholeCoinIds,
|
|
14
13
|
voloCoinIds,
|
|
@@ -21,6 +20,7 @@ import {
|
|
|
21
20
|
COIN_GECKGO_IDS,
|
|
22
21
|
POOL_ADDRESSES,
|
|
23
22
|
sCoinTypeToName,
|
|
23
|
+
sCoinRawNameToName,
|
|
24
24
|
} from '../constants';
|
|
25
25
|
import { getPythPrices, queryObligation } from '../queries';
|
|
26
26
|
import {
|
|
@@ -40,7 +40,6 @@ import type {
|
|
|
40
40
|
SupportAssetCoins,
|
|
41
41
|
SupportMarketCoins,
|
|
42
42
|
SupportStakeMarketCoins,
|
|
43
|
-
SupportBorrowIncentiveCoins,
|
|
44
43
|
CoinPrices,
|
|
45
44
|
CoinWrappedType,
|
|
46
45
|
SupportSCoin,
|
|
@@ -157,7 +156,14 @@ export class ScallopUtils {
|
|
|
157
156
|
* @param coinName - Specific support coin name.
|
|
158
157
|
* @return Coin type.
|
|
159
158
|
*/
|
|
160
|
-
public parseCoinType(
|
|
159
|
+
public parseCoinType(
|
|
160
|
+
coinName: SupportCoins,
|
|
161
|
+
useOldMarketCoin: boolean = false
|
|
162
|
+
) {
|
|
163
|
+
// try parse scoin first
|
|
164
|
+
if (sCoinIds[coinName as SupportSCoin] && !useOldMarketCoin) {
|
|
165
|
+
return sCoinIds[coinName as SupportSCoin];
|
|
166
|
+
}
|
|
161
167
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
162
168
|
const coinPackageId =
|
|
163
169
|
this.address.get(`core.coins.${coinName}.id`) ||
|
|
@@ -225,6 +231,16 @@ export class ScallopUtils {
|
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Convert sCoin name to coin name.
|
|
236
|
+
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
237
|
+
* e.g: `scallop_sui -> ssui
|
|
238
|
+
* @return sCoin name
|
|
239
|
+
*/
|
|
240
|
+
public parseCoinNameFromSCoinName(coinName: string) {
|
|
241
|
+
return sCoinRawNameToName[coinName];
|
|
242
|
+
}
|
|
243
|
+
|
|
228
244
|
/**
|
|
229
245
|
* Convert sCoin name into sCoin type
|
|
230
246
|
* @param sCoinName
|
|
@@ -272,7 +288,7 @@ export class ScallopUtils {
|
|
|
272
288
|
public parseMarketCoinType(coinName: SupportCoins) {
|
|
273
289
|
const protocolObjectId =
|
|
274
290
|
this.address.get('core.object') ?? PROTOCOL_OBJECT_ID;
|
|
275
|
-
const coinType = this.parseCoinType(coinName);
|
|
291
|
+
const coinType = this.parseCoinType(coinName, true);
|
|
276
292
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
277
293
|
}
|
|
278
294
|
|
|
@@ -297,12 +313,13 @@ export class ScallopUtils {
|
|
|
297
313
|
): T extends SupportCoins ? T : SupportCoins;
|
|
298
314
|
public parseCoinNameFromType(coinType: string) {
|
|
299
315
|
coinType = normalizeStructTag(coinType);
|
|
316
|
+
|
|
300
317
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
301
318
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
302
319
|
const isMarketCoinType = coinType.includes('reserve::MarketCoin');
|
|
303
320
|
coinType = coinTypeMatch?.[1] ?? coinType;
|
|
304
321
|
|
|
305
|
-
const
|
|
322
|
+
const wormholeCoinTypeMap: Record<string, SupportAssetCoins> = {
|
|
306
323
|
[`${
|
|
307
324
|
this.address.get('core.coins.wusdc.id') ?? wormholeCoinIds.wusdc
|
|
308
325
|
}::coin::COIN`]: 'wusdc',
|
|
@@ -339,7 +356,7 @@ export class ScallopUtils {
|
|
|
339
356
|
);
|
|
340
357
|
|
|
341
358
|
const assetCoinName =
|
|
342
|
-
|
|
359
|
+
wormholeCoinTypeMap[coinType] ||
|
|
343
360
|
voloCoinTypeMap[coinType] ||
|
|
344
361
|
suiBridgeTypeMap[coinType] ||
|
|
345
362
|
(coinType.split('::')[2].toLowerCase() as SupportAssetCoins);
|
|
@@ -383,18 +400,6 @@ export class ScallopUtils {
|
|
|
383
400
|
return spoolRewardCoins[stakeMarketCoinName];
|
|
384
401
|
};
|
|
385
402
|
|
|
386
|
-
/**
|
|
387
|
-
* Get reward type of borrow incentive pool.
|
|
388
|
-
*
|
|
389
|
-
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
390
|
-
* @return Borrow incentive reward coin name.
|
|
391
|
-
*/
|
|
392
|
-
public getBorrowIncentiveRewardCoinName = (
|
|
393
|
-
borrowIncentiveCoinName: SupportBorrowIncentiveCoins
|
|
394
|
-
) => {
|
|
395
|
-
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
396
|
-
};
|
|
397
|
-
|
|
398
403
|
/**
|
|
399
404
|
* Get coin decimal.
|
|
400
405
|
*
|