@scallop-io/sui-scallop-sdk 0.47.0-alpha.3 → 0.47.0-alpha.5
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.js +59 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -60
- package/dist/index.mjs.map +1 -1
- package/dist/queries/borrowIncentiveQuery.d.ts +9 -9
- package/package.json +6 -3
- package/src/builders/coreBuilder.ts +1 -1
- package/src/queries/borrowIncentiveQuery.ts +18 -21
- package/src/queries/coreQuery.ts +46 -40
- package/src/queries/spoolQuery.ts +10 -8
|
@@ -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.
|
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.5",
|
|
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
|
},
|
|
@@ -392,7 +392,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
392
392
|
(await builder.utils.getObligationCoinNames(
|
|
393
393
|
obligationInfo.obligationId
|
|
394
394
|
)) ?? [];
|
|
395
|
-
const updateCoinNames = [...
|
|
395
|
+
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
396
396
|
await updateOracles(builder, txBlock, updateCoinNames);
|
|
397
397
|
return txBlock.borrow(
|
|
398
398
|
obligationInfo.obligationId,
|
|
@@ -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,39 +32,35 @@ 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
|
-
const coinPrices =
|
|
44
|
-
[
|
|
42
|
+
const coinPrices =
|
|
43
|
+
(await query.utils.getCoinPrices([
|
|
45
44
|
...new Set([
|
|
46
45
|
...borrowIncentiveCoinNames,
|
|
47
46
|
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
48
47
|
]),
|
|
49
|
-
] ??
|
|
50
|
-
);
|
|
48
|
+
])) ?? {};
|
|
51
49
|
|
|
52
50
|
if (indexer) {
|
|
53
51
|
const borrowIncentivePoolsIndexer =
|
|
54
52
|
await query.indexer.getBorrowIncentivePools();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
53
|
+
|
|
54
|
+
const updateBorrowIncentivePool = (pool: BorrowIncentivePool) => {
|
|
55
|
+
if (!borrowIncentiveCoinNames.includes(pool.coinName)) return;
|
|
56
|
+
pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
|
|
57
|
+
borrowIncentivePools[pool.coinName] = pool;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
61
|
+
updateBorrowIncentivePool
|
|
62
|
+
);
|
|
63
|
+
|
|
67
64
|
return borrowIncentivePools;
|
|
68
65
|
}
|
|
69
66
|
|
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,29 +226,31 @@ 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,
|
|
231
235
|
});
|
|
232
|
-
const coinPrices = await query.utils.getCoinPrices(poolCoinNames ??
|
|
236
|
+
const coinPrices = (await query.utils.getCoinPrices(poolCoinNames)) ?? {};
|
|
233
237
|
|
|
234
238
|
const marketPools: MarketPools = {};
|
|
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,32 @@ 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.
|
|
517
|
-
showContent: true,
|
|
518
|
-
}),
|
|
519
|
-
await query.utils.getCoinPrices(collateralCoinNames ?? []),
|
|
520
|
-
]);
|
|
521
|
+
const coinPrices =
|
|
522
|
+
(await query.utils.getCoinPrices(collateralCoinNames)) ?? {};
|
|
521
523
|
const marketCollaterals: MarketCollaterals = {};
|
|
522
524
|
|
|
523
525
|
if (indexer) {
|
|
524
526
|
const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
|
|
525
|
-
|
|
526
|
-
if (!collateralCoinNames.includes(marketCollateral.coinName))
|
|
527
|
+
const updateMarketCollateral = (marketCollateral: MarketCollateral) => {
|
|
528
|
+
if (!collateralCoinNames.includes(marketCollateral.coinName)) return;
|
|
527
529
|
marketCollateral.coinPrice =
|
|
528
530
|
coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
|
|
529
531
|
marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
|
|
530
532
|
marketCollateral.coinName
|
|
531
533
|
);
|
|
532
534
|
marketCollaterals[marketCollateral.coinName] = marketCollateral;
|
|
533
|
-
}
|
|
535
|
+
};
|
|
536
|
+
Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
|
|
534
537
|
return marketCollaterals;
|
|
535
538
|
}
|
|
536
539
|
|
|
540
|
+
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
541
|
+
showContent: true,
|
|
542
|
+
});
|
|
537
543
|
await Promise.allSettled(
|
|
538
544
|
collateralCoinNames.map(async (collateralCoinName) => {
|
|
539
545
|
const marketCollateral = await getMarketCollateral(
|
|
@@ -570,6 +576,12 @@ export const getMarketCollateral = async (
|
|
|
570
576
|
marketObject?: SuiObjectData | null,
|
|
571
577
|
coinPrice?: number
|
|
572
578
|
) => {
|
|
579
|
+
coinPrice =
|
|
580
|
+
coinPrice ||
|
|
581
|
+
(await query.utils.getCoinPrices([collateralCoinName]))?.[
|
|
582
|
+
collateralCoinName
|
|
583
|
+
];
|
|
584
|
+
|
|
573
585
|
if (indexer) {
|
|
574
586
|
const marketCollateralIndexer =
|
|
575
587
|
await query.indexer.getMarketCollateral(collateralCoinName);
|
|
@@ -595,12 +607,6 @@ export const getMarketCollateral = async (
|
|
|
595
607
|
})
|
|
596
608
|
)?.data;
|
|
597
609
|
|
|
598
|
-
coinPrice =
|
|
599
|
-
coinPrice ||
|
|
600
|
-
(await query.utils.getCoinPrices([collateralCoinName]))?.[
|
|
601
|
-
collateralCoinName
|
|
602
|
-
];
|
|
603
|
-
|
|
604
610
|
if (marketObject) {
|
|
605
611
|
if (marketObject.content && 'fields' in marketObject.content) {
|
|
606
612
|
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
|
);
|
|
@@ -43,17 +42,18 @@ export const getSpools = async (
|
|
|
43
42
|
query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
|
|
44
43
|
return rewardCoinName;
|
|
45
44
|
});
|
|
46
|
-
const coinPrices =
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
const coinPrices =
|
|
46
|
+
(await query.utils.getCoinPrices([
|
|
47
|
+
...new Set([...stakeCoinNames, ...rewardCoinNames]),
|
|
48
|
+
])) ?? {};
|
|
49
49
|
|
|
50
50
|
const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
|
|
51
51
|
const spools: Spools = {};
|
|
52
52
|
|
|
53
53
|
if (indexer) {
|
|
54
54
|
const spoolsIndexer = await query.indexer.getSpools();
|
|
55
|
-
|
|
56
|
-
if (!stakeMarketCoinNames.includes(spool.marketCoinName))
|
|
55
|
+
const updateSpools = (spool: Spool) => {
|
|
56
|
+
if (!stakeMarketCoinNames.includes(spool.marketCoinName)) return;
|
|
57
57
|
const coinName = query.utils.parseCoinName<SupportStakeCoins>(
|
|
58
58
|
spool.marketCoinName
|
|
59
59
|
);
|
|
@@ -68,7 +68,8 @@ export const getSpools = async (
|
|
|
68
68
|
spool.rewardCoinPrice =
|
|
69
69
|
coinPrices[rewardCoinName] || spool.rewardCoinPrice;
|
|
70
70
|
spools[spool.marketCoinName] = spool;
|
|
71
|
-
}
|
|
71
|
+
};
|
|
72
|
+
Object.values(spoolsIndexer).forEach(updateSpools);
|
|
72
73
|
|
|
73
74
|
// console.log(spools);
|
|
74
75
|
return spools;
|
|
@@ -117,6 +118,7 @@ export const getSpool = async (
|
|
|
117
118
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
118
119
|
);
|
|
119
120
|
let spool: Spool | undefined = undefined;
|
|
121
|
+
coinPrices = coinPrices || (await query.utils.getCoinPrices([coinName]));
|
|
120
122
|
|
|
121
123
|
if (indexer) {
|
|
122
124
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|