@scallop-io/sui-scallop-sdk 2.3.4 → 2.3.6
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 +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/constants/queryKeys.ts +1 -1
- package/src/models/scallopUtils.ts +59 -42
- package/src/queries/spoolQuery.ts +0 -2
package/package.json
CHANGED
|
@@ -505,7 +505,7 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
505
505
|
* Get asset coin price.
|
|
506
506
|
*
|
|
507
507
|
* @description
|
|
508
|
-
* The strategy for obtaining the price is to get it through API first,
|
|
508
|
+
* The strategy for obtaining the price is to get it through pyth API first,
|
|
509
509
|
* and then on-chain data if API cannot be retrieved.
|
|
510
510
|
* Currently, we only support obtaining from pyth protocol, other
|
|
511
511
|
* oracles will be supported in the future.
|
|
@@ -519,16 +519,24 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
519
519
|
...this.constants.whitelist.lending,
|
|
520
520
|
...this.constants.whitelist.collateral,
|
|
521
521
|
]),
|
|
522
|
-
] as string[]
|
|
522
|
+
] as string[],
|
|
523
|
+
useOnChainObjects: boolean = false
|
|
523
524
|
) {
|
|
524
525
|
const priceIdsMap = new Map(
|
|
525
|
-
coinNames
|
|
526
|
-
coinName
|
|
527
|
-
|
|
528
|
-
|
|
526
|
+
coinNames
|
|
527
|
+
.map((coinName) => {
|
|
528
|
+
const priceId = this.address.get(
|
|
529
|
+
`core.coins.${coinName}.oracle.pyth.feed`
|
|
530
|
+
);
|
|
531
|
+
return priceId
|
|
532
|
+
? ([coinName, priceId] as [string, string])
|
|
533
|
+
: undefined;
|
|
534
|
+
})
|
|
535
|
+
.filter((entry): entry is [string, string] => !!entry)
|
|
529
536
|
);
|
|
530
537
|
|
|
531
538
|
const priceIds = Array.from(priceIdsMap.values());
|
|
539
|
+
const coinNamesMapped = Array.from(priceIdsMap.keys());
|
|
532
540
|
const state = this.queryClient.getQueryState(
|
|
533
541
|
queryKeys.oracle.getCoinPrices(priceIds)
|
|
534
542
|
);
|
|
@@ -538,45 +546,48 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
538
546
|
}
|
|
539
547
|
|
|
540
548
|
let coinPrices: CoinPrices = {};
|
|
541
|
-
for (const endpoint of this.pythEndpoints) {
|
|
542
|
-
const pythConnection = new SuiPriceServiceConnection(endpoint, {
|
|
543
|
-
timeout: this.timeout,
|
|
544
|
-
httpRetries: 0,
|
|
545
|
-
});
|
|
546
549
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
),
|
|
553
|
-
queryFn: async () => {
|
|
554
|
-
return await pythConnection.getLatestPriceFeeds(priceIds);
|
|
555
|
-
},
|
|
556
|
-
retry: false,
|
|
557
|
-
staleTime: 30_000,
|
|
558
|
-
gcTime: 30_000,
|
|
550
|
+
if (!useOnChainObjects) {
|
|
551
|
+
for (const endpoint of this.pythEndpoints) {
|
|
552
|
+
const pythConnection = new SuiPriceServiceConnection(endpoint, {
|
|
553
|
+
timeout: this.timeout,
|
|
554
|
+
httpRetries: 0,
|
|
559
555
|
});
|
|
560
|
-
if (!feeds) throw new Error('No feeds returned from pyth');
|
|
561
|
-
|
|
562
|
-
if (feeds.length !== priceIds.length)
|
|
563
|
-
throw new Error('Incomplete feeds returned from pyth');
|
|
564
556
|
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
557
|
+
try {
|
|
558
|
+
const feeds = await this.queryClient.fetchQuery({
|
|
559
|
+
queryKey: queryKeys.oracle.getPythLatestPriceFeeds(
|
|
560
|
+
endpoint,
|
|
561
|
+
priceIds
|
|
562
|
+
),
|
|
563
|
+
queryFn: async () => {
|
|
564
|
+
return await pythConnection.getLatestPriceFeeds(priceIds);
|
|
565
|
+
},
|
|
566
|
+
retry: false,
|
|
567
|
+
staleTime: 30_000,
|
|
568
|
+
gcTime: 30_000,
|
|
569
|
+
});
|
|
570
|
+
if (!feeds) throw new Error('No feeds returned from pyth');
|
|
571
|
+
|
|
572
|
+
if (feeds.length !== priceIds.length)
|
|
573
|
+
throw new Error('Incomplete feeds returned from pyth');
|
|
574
|
+
|
|
575
|
+
feeds.forEach((feed, idx) => {
|
|
576
|
+
const coinName = coinNamesMapped[idx] as string;
|
|
577
|
+
const data = this.parseDataFromPythPriceFeed(feed);
|
|
578
|
+
coinPrices[coinName as string] = data.price;
|
|
579
|
+
});
|
|
580
|
+
this.queryClient.setQueryData(
|
|
581
|
+
queryKeys.oracle.getCoinPrices(priceIds),
|
|
582
|
+
coinPrices
|
|
583
|
+
);
|
|
584
|
+
} catch (e: any) {
|
|
585
|
+
if ('status' in e && e.status === 403) {
|
|
586
|
+
console.log(`trying next pyth endpoint`);
|
|
587
|
+
continue; // try next endpoint
|
|
588
|
+
}
|
|
589
|
+
console.error(e.message);
|
|
578
590
|
}
|
|
579
|
-
console.error(e.message);
|
|
580
591
|
}
|
|
581
592
|
}
|
|
582
593
|
|
|
@@ -591,7 +602,13 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
591
602
|
);
|
|
592
603
|
}
|
|
593
604
|
|
|
594
|
-
return
|
|
605
|
+
return {
|
|
606
|
+
...coinNames.reduce((prev, coinName) => {
|
|
607
|
+
prev[coinName as string] = coinPrices[coinName as string] || 0;
|
|
608
|
+
return prev;
|
|
609
|
+
}, {} as CoinPrices),
|
|
610
|
+
...coinPrices,
|
|
611
|
+
};
|
|
595
612
|
}
|
|
596
613
|
|
|
597
614
|
/**
|
|
@@ -42,8 +42,6 @@ const queryRequiredSpoolObjects = async (
|
|
|
42
42
|
const objectDatas: SuiObjectData[] = [];
|
|
43
43
|
const batches = partitionArray(allObjectIds, 50);
|
|
44
44
|
|
|
45
|
-
console.log('Fetching spool objects in batches:', batches.length);
|
|
46
|
-
|
|
47
45
|
for (const batch of batches) {
|
|
48
46
|
const responses = await query.scallopSuiKit.queryGetObjects(batch);
|
|
49
47
|
if (responses.length > 0) {
|