@scallop-io/sui-scallop-sdk 1.3.3 → 1.3.4-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.
Files changed (37) hide show
  1. package/dist/constants/coinGecko.d.ts +2 -0
  2. package/dist/constants/index.d.ts +7 -0
  3. package/dist/constants/poolAddress.d.ts +5 -0
  4. package/dist/constants/pyth.d.ts +2 -0
  5. package/dist/constants/queryKeys.d.ts +2 -1
  6. package/dist/index.js +1471 -1311
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +1463 -1311
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/models/scallopQuery.d.ts +4 -4
  11. package/dist/models/scallopUtils.d.ts +6 -1
  12. package/dist/queries/sCoinQuery.d.ts +1 -1
  13. package/dist/queries/spoolQuery.d.ts +1 -1
  14. package/dist/types/query/core.d.ts +1 -0
  15. package/dist/types/utils.d.ts +12 -0
  16. package/dist/utils/util.d.ts +2 -2
  17. package/package.json +1 -1
  18. package/src/constants/coinGecko.ts +18 -0
  19. package/src/constants/enum.ts +11 -4
  20. package/src/constants/index.ts +7 -0
  21. package/src/constants/poolAddress.ts +94 -0
  22. package/src/constants/pyth.ts +19 -0
  23. package/src/constants/queryKeys.ts +2 -2
  24. package/src/constants/testAddress.ts +76 -35
  25. package/src/models/scallopBuilder.ts +2 -3
  26. package/src/models/scallopQuery.ts +4 -3
  27. package/src/models/scallopUtils.ts +64 -29
  28. package/src/queries/coreQuery.ts +222 -216
  29. package/src/queries/isolatedAsset.ts +4 -4
  30. package/src/queries/portfolioQuery.ts +6 -9
  31. package/src/queries/referralQuery.ts +0 -1
  32. package/src/queries/spoolQuery.ts +1 -1
  33. package/src/types/query/core.ts +1 -0
  34. package/src/types/utils.ts +13 -0
  35. package/src/utils/util.ts +2 -1
  36. package/dist/models/scallopPrice.d.ts +0 -0
  37. package/src/models/scallopPrice.ts +0 -0
@@ -18,6 +18,8 @@ import {
18
18
  SUPPORT_SCOIN,
19
19
  sCoinIds,
20
20
  suiBridgeCoins,
21
+ COIN_GECKGO_IDS,
22
+ POOL_ADDRESSES,
21
23
  } from '../constants';
22
24
  import { getPythPrice, queryObligation } from '../queries';
23
25
  import {
@@ -28,7 +30,7 @@ import {
28
30
  isSuiBridgeAsset,
29
31
  isWormholeAsset,
30
32
  } from '../utils';
31
- import { PYTH_ENDPOINTS } from 'src/constants/pyth';
33
+ import { PYTH_ENDPOINTS, PYTH_FEED_IDS } from 'src/constants/pyth';
32
34
  import { ScallopCache } from './scallopCache';
33
35
  import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
34
36
  import type {
@@ -45,6 +47,7 @@ import type {
45
47
  ScallopUtilsInstanceParams,
46
48
  SupportSuiBridgeCoins,
47
49
  SupportWormholeCoins,
50
+ PoolAddressInfo,
48
51
  } from '../types';
49
52
  import { queryKeys } from 'src/constants';
50
53
  import type { SuiObjectArg, SuiTxArg, SuiTxBlock } from '@scallop-io/sui-kit';
@@ -129,10 +132,9 @@ export class ScallopUtils {
129
132
  * @param address - ScallopAddress instance.
130
133
  */
131
134
  public async init(force: boolean = false, address?: ScallopAddress) {
132
- if (force || !this.address.getAddresses() || !address?.getAddresses()) {
135
+ if (address && !this.address) this.address = address;
136
+ if (force || !this.address.getAddresses()) {
133
137
  await this.address.read();
134
- } else {
135
- this.address = address;
136
138
  }
137
139
  }
138
140
 
@@ -553,39 +555,51 @@ export class ScallopUtils {
553
555
  const priceId = this.address.get(
554
556
  `core.coins.${coinName}.oracle.pyth.feed`
555
557
  );
556
- acc[coinName] = priceId;
558
+ if (priceId) {
559
+ acc[coinName] = priceId;
560
+ }
557
561
  return acc;
558
562
  },
559
563
  {} as Record<SupportAssetCoins, string>
560
564
  );
561
565
 
562
566
  await Promise.allSettled(
563
- Object.entries(priceIds).map(async ([coinName, priceId]) => {
564
- const pythConnection = new SuiPriceServiceConnection(endpoint);
565
- try {
566
- const feed = await this.cache.queryClient.fetchQuery({
567
- queryKey: queryKeys.oracle.getPythLatestPriceFeed(priceId),
568
- queryFn: async () => {
569
- return (
570
- (await pythConnection.getLatestPriceFeeds([priceId])) ?? []
571
- );
572
- },
573
- });
574
- if (feed[0]) {
575
- const data = parseDataFromPythPriceFeed(feed[0], this.address);
576
- this._priceMap.set(coinName as SupportAssetCoins, {
577
- price: data.price,
578
- publishTime: data.publishTime,
567
+ Object.entries(priceIds)
568
+ .filter(([_, priceId]) => !!priceId)
569
+ .map(async ([coinName, priceId]) => {
570
+ // console.log({ coinName, priceId, endpoint });
571
+ const pythConnection = new SuiPriceServiceConnection(endpoint);
572
+ try {
573
+ const feed = await this.cache.queryClient.fetchQuery({
574
+ queryKey: queryKeys.oracle.getPythLatestPriceFeed(
575
+ priceId,
576
+ endpoint
577
+ ),
578
+ queryFn: async () => {
579
+ return (
580
+ (await pythConnection.getLatestPriceFeeds([priceId])) ??
581
+ []
582
+ );
583
+ },
579
584
  });
580
- coinPrices[coinName as SupportAssetCoins] = data.price;
585
+ if (feed[0]) {
586
+ const data = parseDataFromPythPriceFeed(
587
+ feed[0],
588
+ this.address
589
+ );
590
+ this._priceMap.set(coinName as SupportAssetCoins, {
591
+ price: data.price,
592
+ publishTime: data.publishTime,
593
+ });
594
+ coinPrices[coinName as SupportAssetCoins] = data.price;
595
+ failedRequests.delete(coinName as SupportAssetCoins); // remove success price feed to prevent duplicate request on the next endpoint
596
+ }
597
+ } catch (e) {
598
+ console.warn(
599
+ `Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
600
+ );
581
601
  }
582
- failedRequests.delete(coinName as SupportAssetCoins); // remove success price feed to prevent duplicate request on the next endpoint
583
- } catch (e) {
584
- console.warn(
585
- `Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
586
- );
587
- }
588
- })
602
+ })
589
603
  );
590
604
  if (failedRequests.size === 0) break;
591
605
  }
@@ -670,4 +684,25 @@ export class ScallopUtils {
670
684
  }
671
685
  return findClosestUnlockRound(newUnlockAtInSecondTimestamp);
672
686
  }
687
+
688
+ /**
689
+ * Get detailed contract address and price id information for supported pool in Scallop
690
+ * @returns Supported pool informations
691
+ */
692
+ public getSupportedPoolAddresses(): PoolAddressInfo[] {
693
+ return SUPPORT_POOLS.map((poolName) => {
694
+ const sCoinName = this.parseSCoinName(poolName)!;
695
+ return {
696
+ name: this.parseSymbol(poolName),
697
+ coingeckoId: COIN_GECKGO_IDS[poolName],
698
+ decimal: coinDecimals[poolName],
699
+ pythFeedId: PYTH_FEED_IDS[poolName],
700
+ ...POOL_ADDRESSES[poolName],
701
+ sCoinAddress: sCoinIds[sCoinName],
702
+ marketCoinAddress: this.parseMarketCoinType(poolName),
703
+ coinAddress: this.parseCoinType(poolName),
704
+ sCoinName: sCoinName ? this.parseSymbol(sCoinName) : undefined,
705
+ };
706
+ });
707
+ }
673
708
  }