@scallop-io/sui-scallop-sdk 0.47.0-alpha.2 → 0.47.0-alpha.4
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 +4 -4
- package/dist/index.js +65 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -48
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +8 -2
- package/dist/queries/borrowIncentiveQuery.d.ts +9 -9
- package/dist/queries/coreQuery.d.ts +2 -0
- package/dist/queries/portfolioQuery.d.ts +1 -0
- package/dist/queries/sCoinQuery.d.ts +1 -1
- package/dist/queries/spoolQuery.d.ts +1 -0
- package/package.json +6 -3
- package/src/constants/common.ts +4 -0
- package/src/constants/enum.ts +9 -0
- package/src/queries/borrowIncentiveQuery.ts +15 -17
- package/src/queries/coreQuery.ts +44 -39
- package/src/queries/spoolQuery.ts +7 -5
|
@@ -51,6 +51,7 @@ export declare class ScallopQuery {
|
|
|
51
51
|
* @return Market pools data.
|
|
52
52
|
*/
|
|
53
53
|
getMarketPools(poolCoinNames?: SupportPoolCoins[], indexer?: boolean): Promise<{
|
|
54
|
+
usdc?: import("../types").MarketPool | undefined;
|
|
54
55
|
weth?: import("../types").MarketPool | undefined;
|
|
55
56
|
wbtc?: import("../types").MarketPool | undefined;
|
|
56
57
|
wusdc?: import("../types").MarketPool | undefined;
|
|
@@ -84,6 +85,7 @@ export declare class ScallopQuery {
|
|
|
84
85
|
* @return Market collaterals data.
|
|
85
86
|
*/
|
|
86
87
|
getMarketCollaterals(collateralCoinNames?: SupportCollateralCoins[], indexer?: boolean): Promise<{
|
|
88
|
+
usdc?: import("../types").MarketCollateral | undefined;
|
|
87
89
|
weth?: import("../types").MarketCollateral | undefined;
|
|
88
90
|
wbtc?: import("../types").MarketCollateral | undefined;
|
|
89
91
|
wusdc?: import("../types").MarketCollateral | undefined;
|
|
@@ -173,6 +175,7 @@ export declare class ScallopQuery {
|
|
|
173
175
|
* @return Spools data.
|
|
174
176
|
*/
|
|
175
177
|
getSpools(stakeMarketCoinNames?: SupportStakeMarketCoins[], indexer?: boolean): Promise<{
|
|
178
|
+
susdc?: import("../types").Spool | undefined;
|
|
176
179
|
sweth?: import("../types").Spool | undefined;
|
|
177
180
|
ssui?: import("../types").Spool | undefined;
|
|
178
181
|
swusdc?: import("../types").Spool | undefined;
|
|
@@ -216,6 +219,7 @@ export declare class ScallopQuery {
|
|
|
216
219
|
* @return Stake pools data.
|
|
217
220
|
*/
|
|
218
221
|
getStakePools(stakeMarketCoinNames?: SupportStakeMarketCoins[]): Promise<{
|
|
222
|
+
susdc?: import("../types").StakePool | undefined;
|
|
219
223
|
sweth?: import("../types").StakePool | undefined;
|
|
220
224
|
ssui?: import("../types").StakePool | undefined;
|
|
221
225
|
swusdc?: import("../types").StakePool | undefined;
|
|
@@ -247,6 +251,7 @@ export declare class ScallopQuery {
|
|
|
247
251
|
* @return Stake reward pools data.
|
|
248
252
|
*/
|
|
249
253
|
getStakeRewardPools(stakeMarketCoinNames?: SupportStakeMarketCoins[]): Promise<{
|
|
254
|
+
susdc?: import("../types").StakeRewardPool | undefined;
|
|
250
255
|
sweth?: import("../types").StakeRewardPool | undefined;
|
|
251
256
|
ssui?: import("../types").StakeRewardPool | undefined;
|
|
252
257
|
swusdc?: import("../types").StakeRewardPool | undefined;
|
|
@@ -310,6 +315,7 @@ export declare class ScallopQuery {
|
|
|
310
315
|
* @return All lending and spool infomation.
|
|
311
316
|
*/
|
|
312
317
|
getLendings(poolCoinNames?: SupportPoolCoins[], ownerAddress?: string, indexer?: boolean): Promise<{
|
|
318
|
+
usdc?: import("../types").Lending | undefined;
|
|
313
319
|
weth?: import("../types").Lending | undefined;
|
|
314
320
|
wbtc?: import("../types").Lending | undefined;
|
|
315
321
|
wusdc?: import("../types").Lending | undefined;
|
|
@@ -421,7 +427,7 @@ export declare class ScallopQuery {
|
|
|
421
427
|
* @param ownerAddress - The owner address.
|
|
422
428
|
* @return All market sCoin amounts.
|
|
423
429
|
*/
|
|
424
|
-
getSCoinAmounts(sCoinNames?: SupportSCoin[], ownerAddress?: string): Promise<import("../types").OptionalKeys<Record<"sweth" | "ssui" | "swusdc" | "swusdt" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "swsol" | "swbtc", number>>>;
|
|
430
|
+
getSCoinAmounts(sCoinNames?: SupportSCoin[], ownerAddress?: string): Promise<import("../types").OptionalKeys<Record<"susdc" | "sweth" | "ssui" | "swusdc" | "swusdt" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "swsol" | "swbtc", number>>>;
|
|
425
431
|
/**
|
|
426
432
|
* Get sCoin amount.
|
|
427
433
|
*
|
|
@@ -436,7 +442,7 @@ export declare class ScallopQuery {
|
|
|
436
442
|
* @returns
|
|
437
443
|
*/
|
|
438
444
|
getSCoinSwapRate(fromSCoin: SupportSCoin, toSCoin: SupportSCoin): Promise<number>;
|
|
439
|
-
getFlashLoanFees(assetCoinNames?: SupportAssetCoins[]): Promise<Record<"weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca", number>>;
|
|
445
|
+
getFlashLoanFees(assetCoinNames?: SupportAssetCoins[]): Promise<Record<"usdc" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca", number>>;
|
|
440
446
|
/**
|
|
441
447
|
* Get supply limit of supply pool
|
|
442
448
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ScallopAddress, ScallopQuery, ScallopUtils } from '../models';
|
|
2
|
-
import type { SupportBorrowIncentiveCoins } from '../types';
|
|
2
|
+
import type { SupportBorrowIncentiveCoins, BorrowIncentivePool } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Query borrow incentive pools data.
|
|
5
5
|
*
|
|
@@ -9,14 +9,14 @@ import type { SupportBorrowIncentiveCoins } from '../types';
|
|
|
9
9
|
* @return Borrow incentive pools data.
|
|
10
10
|
*/
|
|
11
11
|
export declare const queryBorrowIncentivePools: (query: ScallopQuery, borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[], indexer?: boolean) => Promise<{
|
|
12
|
-
weth?:
|
|
13
|
-
wusdc?:
|
|
14
|
-
wusdt?:
|
|
15
|
-
sui?:
|
|
16
|
-
afsui?:
|
|
17
|
-
hasui?:
|
|
18
|
-
vsui?:
|
|
19
|
-
sca?:
|
|
12
|
+
weth?: BorrowIncentivePool | undefined;
|
|
13
|
+
wusdc?: BorrowIncentivePool | undefined;
|
|
14
|
+
wusdt?: BorrowIncentivePool | undefined;
|
|
15
|
+
sui?: BorrowIncentivePool | undefined;
|
|
16
|
+
afsui?: BorrowIncentivePool | undefined;
|
|
17
|
+
hasui?: BorrowIncentivePool | undefined;
|
|
18
|
+
vsui?: BorrowIncentivePool | undefined;
|
|
19
|
+
sca?: BorrowIncentivePool | undefined;
|
|
20
20
|
}>;
|
|
21
21
|
/**
|
|
22
22
|
* Query borrow incentive accounts data.
|
|
@@ -26,6 +26,7 @@ export declare const queryMarket: (query: ScallopQuery, indexer?: boolean) => Pr
|
|
|
26
26
|
* @return Market pools data.
|
|
27
27
|
*/
|
|
28
28
|
export declare const getMarketPools: (query: ScallopQuery, poolCoinNames?: SupportPoolCoins[], indexer?: boolean) => Promise<{
|
|
29
|
+
usdc?: MarketPool | undefined;
|
|
29
30
|
weth?: MarketPool | undefined;
|
|
30
31
|
wbtc?: MarketPool | undefined;
|
|
31
32
|
wusdc?: MarketPool | undefined;
|
|
@@ -63,6 +64,7 @@ export declare const getMarketPool: (query: ScallopQuery, poolCoinName: SupportP
|
|
|
63
64
|
* @return Market collaterals data.
|
|
64
65
|
*/
|
|
65
66
|
export declare const getMarketCollaterals: (query: ScallopQuery, collateralCoinNames?: SupportCollateralCoins[], indexer?: boolean) => Promise<{
|
|
67
|
+
usdc?: MarketCollateral | undefined;
|
|
66
68
|
weth?: MarketCollateral | undefined;
|
|
67
69
|
wbtc?: MarketCollateral | undefined;
|
|
68
70
|
wusdc?: MarketCollateral | undefined;
|
|
@@ -10,6 +10,7 @@ import type { Market, SupportPoolCoins, MarketPool, Spool, StakeAccount, Lending
|
|
|
10
10
|
* @return User lending infomation for specific pools.
|
|
11
11
|
*/
|
|
12
12
|
export declare const getLendings: (query: ScallopQuery, poolCoinNames?: SupportPoolCoins[], ownerAddress?: string, indexer?: boolean) => Promise<{
|
|
13
|
+
usdc?: Lending | undefined;
|
|
13
14
|
weth?: Lending | undefined;
|
|
14
15
|
wbtc?: Lending | undefined;
|
|
15
16
|
wusdc?: Lending | undefined;
|
|
@@ -19,7 +19,7 @@ export declare const getSCoinTotalSupply: ({ utils, }: {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare const getSCoinAmounts: ({ utils, }: {
|
|
21
21
|
utils: ScallopUtils;
|
|
22
|
-
}, sCoinNames?: SupportSCoin[], ownerAddress?: string) => Promise<OptionalKeys<Record<"sweth" | "ssui" | "swusdc" | "swusdt" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "swsol" | "swbtc", number>>>;
|
|
22
|
+
}, sCoinNames?: SupportSCoin[], ownerAddress?: string) => Promise<OptionalKeys<Record<"susdc" | "sweth" | "ssui" | "swusdc" | "swusdt" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca" | "swsol" | "swbtc", number>>>;
|
|
23
23
|
/**
|
|
24
24
|
* Query owned sCoin amount.
|
|
25
25
|
*
|
|
@@ -9,6 +9,7 @@ import type { MarketPool, Spool, StakePool, StakeRewardPool, StakeAccounts, Supp
|
|
|
9
9
|
* @return Spools data.
|
|
10
10
|
*/
|
|
11
11
|
export declare const getSpools: (query: ScallopQuery, stakeMarketCoinNames?: SupportStakeMarketCoins[], indexer?: boolean) => Promise<{
|
|
12
|
+
susdc?: Spool | undefined;
|
|
12
13
|
sweth?: Spool | undefined;
|
|
13
14
|
ssui?: Spool | undefined;
|
|
14
15
|
swusdc?: Spool | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scallop-io/sui-scallop-sdk",
|
|
3
|
-
"version": "0.47.0-alpha.
|
|
3
|
+
"version": "0.47.0-alpha.4",
|
|
4
4
|
"description": "Typescript sdk for interacting with Scallop contract on SUI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -38,8 +38,9 @@
|
|
|
38
38
|
"src"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
+
"@graphql-typed-document-node/core": "^3.2.0",
|
|
41
42
|
"@mysten/bcs": "^0.8.1",
|
|
42
|
-
"@mysten/sui.js": "^0.
|
|
43
|
+
"@mysten/sui.js": "^0.54.1",
|
|
43
44
|
"@noble/curves": "^1.2.0",
|
|
44
45
|
"@noble/hashes": "^1.3.2",
|
|
45
46
|
"@pythnetwork/price-service-client": "^1.8.2",
|
|
@@ -50,6 +51,8 @@
|
|
|
50
51
|
"axios": "^1.6.0",
|
|
51
52
|
"bech32": "^2.0.0",
|
|
52
53
|
"bignumber.js": "^9.1.2",
|
|
54
|
+
"gql.tada": "^1.8.10",
|
|
55
|
+
"graphql": "^16.9.0",
|
|
53
56
|
"superstruct": "^1.0.3",
|
|
54
57
|
"tweetnacl": "^1.0.3",
|
|
55
58
|
"zod": "^3.23.8"
|
|
@@ -76,7 +79,7 @@
|
|
|
76
79
|
"vitest": "^0.34.6"
|
|
77
80
|
},
|
|
78
81
|
"peerDependencies": {
|
|
79
|
-
"@mysten/sui.js": "0.
|
|
82
|
+
"@mysten/sui.js": "0.54.1",
|
|
80
83
|
"@scallop-io/sui-kit": "0.52.0",
|
|
81
84
|
"bn.js": "^5.2.1"
|
|
82
85
|
},
|
package/src/constants/common.ts
CHANGED
|
@@ -34,6 +34,7 @@ export const OLD_BORROW_INCENTIVE_PROTOCOL_ID =
|
|
|
34
34
|
'0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410' as const;
|
|
35
35
|
|
|
36
36
|
export const SUPPORT_POOLS = [
|
|
37
|
+
'usdc', // native USDC
|
|
37
38
|
'weth',
|
|
38
39
|
'wbtc',
|
|
39
40
|
'wusdc',
|
|
@@ -49,6 +50,7 @@ export const SUPPORT_POOLS = [
|
|
|
49
50
|
] as const;
|
|
50
51
|
|
|
51
52
|
export const SUPPORT_COLLATERALS = [
|
|
53
|
+
'usdc',
|
|
52
54
|
'weth',
|
|
53
55
|
'wbtc',
|
|
54
56
|
'wusdc',
|
|
@@ -64,6 +66,7 @@ export const SUPPORT_COLLATERALS = [
|
|
|
64
66
|
] as const;
|
|
65
67
|
|
|
66
68
|
export const SUPPORT_SPOOLS = [
|
|
69
|
+
'susdc',
|
|
67
70
|
'sweth',
|
|
68
71
|
'ssui',
|
|
69
72
|
'swusdc',
|
|
@@ -75,6 +78,7 @@ export const SUPPORT_SPOOLS = [
|
|
|
75
78
|
] as const;
|
|
76
79
|
|
|
77
80
|
export const SUPPORT_SCOIN = [
|
|
81
|
+
'susdc',
|
|
78
82
|
'ssui',
|
|
79
83
|
'swusdc',
|
|
80
84
|
'swusdt',
|
package/src/constants/enum.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type * as types from '../types';
|
|
|
2
2
|
import { IS_VE_SCA_TEST } from './common';
|
|
3
3
|
|
|
4
4
|
export const coinDecimals: types.SupportCoinDecimals = {
|
|
5
|
+
usdc: 6,
|
|
5
6
|
weth: 8,
|
|
6
7
|
wbtc: 8,
|
|
7
8
|
wusdc: 6,
|
|
@@ -14,6 +15,7 @@ export const coinDecimals: types.SupportCoinDecimals = {
|
|
|
14
15
|
hasui: 9,
|
|
15
16
|
vsui: 9,
|
|
16
17
|
sca: 9,
|
|
18
|
+
susdc: 6,
|
|
17
19
|
sweth: 8,
|
|
18
20
|
swbtc: 8,
|
|
19
21
|
swusdc: 6,
|
|
@@ -29,6 +31,7 @@ export const coinDecimals: types.SupportCoinDecimals = {
|
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
export const assetCoins: types.AssetCoins = {
|
|
34
|
+
usdc: 'usdc',
|
|
32
35
|
weth: 'weth',
|
|
33
36
|
wbtc: 'wbtc',
|
|
34
37
|
wusdc: 'wusdc',
|
|
@@ -44,6 +47,7 @@ export const assetCoins: types.AssetCoins = {
|
|
|
44
47
|
};
|
|
45
48
|
|
|
46
49
|
export const marketCoins: types.MarketCoins = {
|
|
50
|
+
susdc: 'susdc',
|
|
47
51
|
sweth: 'sweth',
|
|
48
52
|
swbtc: 'swbtc',
|
|
49
53
|
swusdc: 'swusdc',
|
|
@@ -59,6 +63,7 @@ export const marketCoins: types.MarketCoins = {
|
|
|
59
63
|
};
|
|
60
64
|
|
|
61
65
|
export const sCoins: types.SCoins = {
|
|
66
|
+
susdc: 'susdc',
|
|
62
67
|
sweth: 'sweth',
|
|
63
68
|
swusdc: 'swusdc',
|
|
64
69
|
swusdt: 'swusdt',
|
|
@@ -73,6 +78,7 @@ export const sCoins: types.SCoins = {
|
|
|
73
78
|
};
|
|
74
79
|
|
|
75
80
|
export const stakeMarketCoins: types.StakeMarketCoins = {
|
|
81
|
+
susdc: 'susdc',
|
|
76
82
|
sweth: 'sweth',
|
|
77
83
|
ssui: 'ssui',
|
|
78
84
|
swusdc: 'swusdc',
|
|
@@ -92,6 +98,7 @@ export const spoolRewardCoins: types.StakeRewardCoins = {
|
|
|
92
98
|
safsui: 'sui',
|
|
93
99
|
shasui: 'sui',
|
|
94
100
|
svsui: 'sui',
|
|
101
|
+
susdc: 'sui',
|
|
95
102
|
};
|
|
96
103
|
|
|
97
104
|
export const borrowIncentiveRewardCoins: types.BorrowIncentiveRewardCoins = {
|
|
@@ -106,6 +113,7 @@ export const borrowIncentiveRewardCoins: types.BorrowIncentiveRewardCoins = {
|
|
|
106
113
|
};
|
|
107
114
|
|
|
108
115
|
export const coinIds: types.AssetCoinIds = {
|
|
116
|
+
usdc: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7',
|
|
109
117
|
sui: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
110
118
|
weth: '0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5',
|
|
111
119
|
wbtc: '0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881',
|
|
@@ -137,6 +145,7 @@ export const voloCoinIds: types.VoloCoinIds = {
|
|
|
137
145
|
|
|
138
146
|
// PROD VERSION
|
|
139
147
|
export const sCoinIds: types.SCoinIds = {
|
|
148
|
+
susdc: '', // TODO: sCoin contract
|
|
140
149
|
ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
|
|
141
150
|
scetus:
|
|
142
151
|
'0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS',
|
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
SupportBorrowIncentiveRewardCoins,
|
|
19
19
|
BorrowIncentivePoolPoints,
|
|
20
20
|
OptionalKeys,
|
|
21
|
+
BorrowIncentivePool,
|
|
21
22
|
} from '../types';
|
|
22
23
|
import BigNumber from 'bignumber.js';
|
|
23
24
|
|
|
@@ -31,13 +32,11 @@ import BigNumber from 'bignumber.js';
|
|
|
31
32
|
*/
|
|
32
33
|
export const queryBorrowIncentivePools = async (
|
|
33
34
|
query: ScallopQuery,
|
|
34
|
-
borrowIncentiveCoinNames
|
|
35
|
+
borrowIncentiveCoinNames: SupportBorrowIncentiveCoins[] = [
|
|
36
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
37
|
+
],
|
|
35
38
|
indexer: boolean = false
|
|
36
39
|
) => {
|
|
37
|
-
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
38
|
-
...SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
39
|
-
];
|
|
40
|
-
|
|
41
40
|
const borrowIncentivePools: BorrowIncentivePools = {};
|
|
42
41
|
|
|
43
42
|
const coinPrices = await query.utils.getCoinPrices(
|
|
@@ -52,18 +51,17 @@ export const queryBorrowIncentivePools = async (
|
|
|
52
51
|
if (indexer) {
|
|
53
52
|
const borrowIncentivePoolsIndexer =
|
|
54
53
|
await query.indexer.getBorrowIncentivePools();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
54
|
+
|
|
55
|
+
const updateBorrowIncentivePool = (pool: BorrowIncentivePool) => {
|
|
56
|
+
if (!borrowIncentiveCoinNames.includes(pool.coinName)) return;
|
|
57
|
+
pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
|
|
58
|
+
borrowIncentivePools[pool.coinName] = pool;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
62
|
+
updateBorrowIncentivePool
|
|
63
|
+
);
|
|
64
|
+
|
|
67
65
|
return borrowIncentivePools;
|
|
68
66
|
}
|
|
69
67
|
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -60,20 +60,25 @@ export const queryMarket = async (
|
|
|
60
60
|
|
|
61
61
|
if (indexer) {
|
|
62
62
|
const marketIndexer = await query.indexer.getMarket();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
);
|
|
73
|
-
|
|
63
|
+
|
|
64
|
+
const updatePools = (item: MarketPool) => {
|
|
65
|
+
item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
|
|
66
|
+
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
67
|
+
pools[item.coinName] = item;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const updateCollaterals = (item: MarketCollateral) => {
|
|
71
|
+
item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
|
|
72
|
+
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
73
|
+
collaterals[item.coinName] = item;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
Object.values(marketIndexer.pools).forEach(updatePools);
|
|
77
|
+
Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
|
|
78
|
+
|
|
74
79
|
return {
|
|
75
|
-
pools
|
|
76
|
-
collaterals
|
|
80
|
+
pools,
|
|
81
|
+
collaterals,
|
|
77
82
|
};
|
|
78
83
|
}
|
|
79
84
|
|
|
@@ -221,10 +226,9 @@ export const queryMarket = async (
|
|
|
221
226
|
*/
|
|
222
227
|
export const getMarketPools = async (
|
|
223
228
|
query: ScallopQuery,
|
|
224
|
-
poolCoinNames
|
|
229
|
+
poolCoinNames: SupportPoolCoins[] = [...SUPPORT_POOLS],
|
|
225
230
|
indexer: boolean = false
|
|
226
231
|
) => {
|
|
227
|
-
poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
|
|
228
232
|
const marketId = query.address.get('core.market');
|
|
229
233
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
230
234
|
showContent: true,
|
|
@@ -235,15 +239,18 @@ export const getMarketPools = async (
|
|
|
235
239
|
|
|
236
240
|
if (indexer) {
|
|
237
241
|
const marketPoolsIndexer = await query.indexer.getMarketPools();
|
|
238
|
-
|
|
239
|
-
|
|
242
|
+
|
|
243
|
+
const updateMarketPool = (marketPool: MarketPool) => {
|
|
244
|
+
if (!poolCoinNames.includes(marketPool.coinName)) return;
|
|
240
245
|
marketPool.coinPrice =
|
|
241
246
|
coinPrices[marketPool.coinName] || marketPool.coinPrice;
|
|
242
247
|
marketPool.coinWrappedType = query.utils.getCoinWrappedType(
|
|
243
248
|
marketPool.coinName
|
|
244
249
|
);
|
|
245
250
|
marketPools[marketPool.coinName] = marketPool;
|
|
246
|
-
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
Object.values(marketPoolsIndexer).forEach(updateMarketPool);
|
|
247
254
|
|
|
248
255
|
return marketPools;
|
|
249
256
|
}
|
|
@@ -290,6 +297,10 @@ export const getMarketPool = async (
|
|
|
290
297
|
let interestModel: InterestModel | undefined;
|
|
291
298
|
let borrowFeeRate: { value: string } | undefined;
|
|
292
299
|
|
|
300
|
+
coinPrice =
|
|
301
|
+
coinPrice ||
|
|
302
|
+
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
303
|
+
|
|
293
304
|
if (indexer) {
|
|
294
305
|
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
295
306
|
marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
|
|
@@ -309,10 +320,6 @@ export const getMarketPool = async (
|
|
|
309
320
|
})
|
|
310
321
|
)?.data;
|
|
311
322
|
|
|
312
|
-
coinPrice =
|
|
313
|
-
coinPrice ||
|
|
314
|
-
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
315
|
-
|
|
316
323
|
if (marketObject) {
|
|
317
324
|
if (marketObject.content && 'fields' in marketObject.content) {
|
|
318
325
|
const fields = marketObject.content.fields as any;
|
|
@@ -507,33 +514,31 @@ export const getMarketPool = async (
|
|
|
507
514
|
*/
|
|
508
515
|
export const getMarketCollaterals = async (
|
|
509
516
|
query: ScallopQuery,
|
|
510
|
-
collateralCoinNames
|
|
517
|
+
collateralCoinNames: SupportCollateralCoins[] = [...SUPPORT_COLLATERALS],
|
|
511
518
|
indexer: boolean = false
|
|
512
519
|
) => {
|
|
513
|
-
collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
|
|
514
520
|
const marketId = query.address.get('core.market');
|
|
515
|
-
const
|
|
516
|
-
await query.cache.queryGetObject(marketId, {
|
|
517
|
-
showContent: true,
|
|
518
|
-
}),
|
|
519
|
-
await query.utils.getCoinPrices(collateralCoinNames ?? []),
|
|
520
|
-
]);
|
|
521
|
+
const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
|
|
521
522
|
const marketCollaterals: MarketCollaterals = {};
|
|
522
523
|
|
|
523
524
|
if (indexer) {
|
|
524
525
|
const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
|
|
525
|
-
|
|
526
|
-
if (!collateralCoinNames.includes(marketCollateral.coinName))
|
|
526
|
+
const updateMarketCollateral = (marketCollateral: MarketCollateral) => {
|
|
527
|
+
if (!collateralCoinNames.includes(marketCollateral.coinName)) return;
|
|
527
528
|
marketCollateral.coinPrice =
|
|
528
529
|
coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
|
|
529
530
|
marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
|
|
530
531
|
marketCollateral.coinName
|
|
531
532
|
);
|
|
532
533
|
marketCollaterals[marketCollateral.coinName] = marketCollateral;
|
|
533
|
-
}
|
|
534
|
+
};
|
|
535
|
+
Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
|
|
534
536
|
return marketCollaterals;
|
|
535
537
|
}
|
|
536
538
|
|
|
539
|
+
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
540
|
+
showContent: true,
|
|
541
|
+
});
|
|
537
542
|
await Promise.allSettled(
|
|
538
543
|
collateralCoinNames.map(async (collateralCoinName) => {
|
|
539
544
|
const marketCollateral = await getMarketCollateral(
|
|
@@ -570,6 +575,12 @@ export const getMarketCollateral = async (
|
|
|
570
575
|
marketObject?: SuiObjectData | null,
|
|
571
576
|
coinPrice?: number
|
|
572
577
|
) => {
|
|
578
|
+
coinPrice =
|
|
579
|
+
coinPrice ||
|
|
580
|
+
(await query.utils.getCoinPrices([collateralCoinName]))?.[
|
|
581
|
+
collateralCoinName
|
|
582
|
+
];
|
|
583
|
+
|
|
573
584
|
if (indexer) {
|
|
574
585
|
const marketCollateralIndexer =
|
|
575
586
|
await query.indexer.getMarketCollateral(collateralCoinName);
|
|
@@ -595,12 +606,6 @@ export const getMarketCollateral = async (
|
|
|
595
606
|
})
|
|
596
607
|
)?.data;
|
|
597
608
|
|
|
598
|
-
coinPrice =
|
|
599
|
-
coinPrice ||
|
|
600
|
-
(await query.utils.getCoinPrices([collateralCoinName]))?.[
|
|
601
|
-
collateralCoinName
|
|
602
|
-
];
|
|
603
|
-
|
|
604
609
|
if (marketObject) {
|
|
605
610
|
if (marketObject.content && 'fields' in marketObject.content) {
|
|
606
611
|
const fields = marketObject.content.fields as any;
|
|
@@ -31,10 +31,9 @@ import type {
|
|
|
31
31
|
*/
|
|
32
32
|
export const getSpools = async (
|
|
33
33
|
query: ScallopQuery,
|
|
34
|
-
stakeMarketCoinNames
|
|
34
|
+
stakeMarketCoinNames: SupportStakeMarketCoins[] = [...SUPPORT_SPOOLS],
|
|
35
35
|
indexer: boolean = false
|
|
36
36
|
) => {
|
|
37
|
-
stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
|
|
38
37
|
const stakeCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) =>
|
|
39
38
|
query.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName)
|
|
40
39
|
);
|
|
@@ -52,8 +51,8 @@ export const getSpools = async (
|
|
|
52
51
|
|
|
53
52
|
if (indexer) {
|
|
54
53
|
const spoolsIndexer = await query.indexer.getSpools();
|
|
55
|
-
|
|
56
|
-
if (!stakeMarketCoinNames.includes(spool.marketCoinName))
|
|
54
|
+
const updateSpools = (spool: Spool) => {
|
|
55
|
+
if (!stakeMarketCoinNames.includes(spool.marketCoinName)) return;
|
|
57
56
|
const coinName = query.utils.parseCoinName<SupportStakeCoins>(
|
|
58
57
|
spool.marketCoinName
|
|
59
58
|
);
|
|
@@ -68,7 +67,8 @@ export const getSpools = async (
|
|
|
68
67
|
spool.rewardCoinPrice =
|
|
69
68
|
coinPrices[rewardCoinName] || spool.rewardCoinPrice;
|
|
70
69
|
spools[spool.marketCoinName] = spool;
|
|
71
|
-
}
|
|
70
|
+
};
|
|
71
|
+
Object.values(spoolsIndexer).forEach(updateSpools);
|
|
72
72
|
|
|
73
73
|
// console.log(spools);
|
|
74
74
|
return spools;
|
|
@@ -117,6 +117,7 @@ export const getSpool = async (
|
|
|
117
117
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
118
118
|
);
|
|
119
119
|
let spool: Spool | undefined = undefined;
|
|
120
|
+
coinPrices = coinPrices || (await query.utils.getCoinPrices([coinName]));
|
|
120
121
|
|
|
121
122
|
if (indexer) {
|
|
122
123
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
@@ -271,6 +272,7 @@ export const getStakeAccounts = async (
|
|
|
271
272
|
} while (hasNextPage);
|
|
272
273
|
|
|
273
274
|
const stakeAccounts: StakeAccounts = {
|
|
275
|
+
susdc: [],
|
|
274
276
|
sweth: [],
|
|
275
277
|
ssui: [],
|
|
276
278
|
swusdc: [],
|