@scallop-io/sui-scallop-sdk 1.4.21 → 1.4.22-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.
@@ -86,4 +86,5 @@ export declare class ScallopIndexer {
86
86
  * @return price data.
87
87
  */
88
88
  getCoinPrice(poolCoinName: SupportPoolCoins): Promise<number>;
89
+ getCoinPrices(): Promise<Record<string, number>>;
89
90
  }
@@ -532,6 +532,11 @@ export declare class ScallopQuery {
532
532
  * @returns price data
533
533
  */
534
534
  getCoinPriceByIndexer(poolName: SupportPoolCoins): Promise<number>;
535
+ /**
536
+ * Get all supported pool price from indexer
537
+ * @returns prices data
538
+ */
539
+ getCoinPricesByIndexer(): Promise<Record<string, number>>;
535
540
  /**
536
541
  * Get all coin prices, including sCoin
537
542
  * @returns prices data
@@ -539,6 +544,7 @@ export declare class ScallopQuery {
539
544
  getAllCoinPrices(args?: {
540
545
  marketPools?: MarketPools;
541
546
  coinPrices?: CoinPrices;
547
+ indexer?: boolean;
542
548
  }): Promise<{
543
549
  susdc?: number | undefined;
544
550
  ssbeth?: number | undefined;
@@ -14,7 +14,7 @@ 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<{
17
+ export declare const getAllCoinPrices: (query: ScallopQuery, marketPools?: MarketPools, coinPrices?: CoinPrices, indexer?: boolean) => Promise<{
18
18
  susdc?: number | undefined;
19
19
  ssbeth?: number | undefined;
20
20
  ssbusdt?: number | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "1.4.21",
3
+ "version": "1.4.22-alpha.1",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -269,4 +269,15 @@ export class ScallopIndexer {
269
269
  public async getCoinPrice(poolCoinName: SupportPoolCoins): Promise<number> {
270
270
  return (await this.getMarketPool(poolCoinName))?.coinPrice ?? 0;
271
271
  }
272
+
273
+ public async getCoinPrices(): Promise<Record<string, number>> {
274
+ const marketPools = await this.getMarketPools();
275
+ return Object.entries(marketPools).reduce(
276
+ (prev, [coinName, market]) => {
277
+ prev[coinName] = market.coinPrice;
278
+ return prev;
279
+ },
280
+ {} as Record<string, number>
281
+ );
282
+ }
272
283
  }
@@ -851,6 +851,14 @@ export class ScallopQuery {
851
851
  return this.indexer.getCoinPrice(poolName);
852
852
  }
853
853
 
854
+ /**
855
+ * Get all supported pool price from indexer
856
+ * @returns prices data
857
+ */
858
+ public async getCoinPricesByIndexer() {
859
+ return this.indexer.getCoinPrices();
860
+ }
861
+
854
862
  /**
855
863
  * Get all coin prices, including sCoin
856
864
  * @returns prices data
@@ -858,8 +866,14 @@ export class ScallopQuery {
858
866
  public async getAllCoinPrices(args?: {
859
867
  marketPools?: MarketPools;
860
868
  coinPrices?: CoinPrices;
869
+ indexer?: boolean;
861
870
  }) {
862
- return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
871
+ return getAllCoinPrices(
872
+ this,
873
+ args?.marketPools,
874
+ args?.coinPrices,
875
+ args?.indexer
876
+ );
863
877
  }
864
878
 
865
879
  /**
@@ -133,16 +133,23 @@ export const getPythPrices = async (
133
133
  export const getAllCoinPrices = async (
134
134
  query: ScallopQuery,
135
135
  marketPools?: MarketPools,
136
- coinPrices?: CoinPrices
136
+ coinPrices?: CoinPrices,
137
+ indexer: boolean = false
137
138
  ) => {
138
- coinPrices = coinPrices ?? (await query.utils.getCoinPrices());
139
+ coinPrices =
140
+ coinPrices ??
141
+ (indexer
142
+ ? await query.getCoinPricesByIndexer()
143
+ : await query.utils.getCoinPrices());
144
+
139
145
  marketPools =
140
146
  marketPools ??
141
- (await query.getMarketPools(undefined, { coinPrices })).pools;
147
+ (await query.getMarketPools(undefined, { coinPrices, indexer })).pools;
142
148
 
143
149
  if (!marketPools) {
144
150
  throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
145
151
  }
152
+
146
153
  const sCoinPrices: OptionalKeys<Record<SupportSCoin, number>> = {};
147
154
  SUPPORT_SCOIN.forEach((sCoinName) => {
148
155
  const coinName = query.utils.parseCoinName(sCoinName);