From 6802008f759a41020399f51058f16d76404026d0 Mon Sep 17 00:00:00 2001 From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:58:31 +0200 Subject: [PATCH] Chart fixes (#470) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛add pools back * 🐛fetch latest prices + fix decimal issue --- .../TradeChart/OsmosisTheGraphDataFeed.ts | 37 +++++++++++-------- src/constants/assets.ts | 8 +++- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/components/Trade/TradeChart/OsmosisTheGraphDataFeed.ts b/src/components/Trade/TradeChart/OsmosisTheGraphDataFeed.ts index 77e51a3f..d30f0d6c 100644 --- a/src/components/Trade/TradeChart/OsmosisTheGraphDataFeed.ts +++ b/src/components/Trade/TradeChart/OsmosisTheGraphDataFeed.ts @@ -189,18 +189,22 @@ export class OsmosisTheGraphDataFeed implements IDatafeedChartApi { const query = ` { candles( - first: ${this.batchSize}, + first: ${this.batchSize}, + orderBy: "timestamp", + orderDirection: "desc", where: { - interval: "${interval}", - quote: "${quote}", - base: "${base}" - }) { - timestamp - open - high - low - close - volume + interval: "${interval}", + quote: "${quote}", + base: "${base}" + poolId_in: ${JSON.stringify(this.supportedPools)} + } + ) { + timestamp + open + high + low + close + volume } } ` @@ -212,7 +216,7 @@ export class OsmosisTheGraphDataFeed implements IDatafeedChartApi { }) .then((res) => res.json()) .then((json: { data?: { candles: BarQueryData[] } }) => { - return this.resolveBarData(json.data?.candles || [], base) + return this.resolveBarData(json.data?.candles.reverse() || [], base, quote) }) .catch((err) => { if (this.debug) console.error(err) @@ -220,9 +224,10 @@ export class OsmosisTheGraphDataFeed implements IDatafeedChartApi { }) } - resolveBarData(bars: BarQueryData[], base: string) { - const assetDecimals = getAssetByDenom(base)?.decimals || 6 - const additionalDecimals = assetDecimals - this.baseDecimals + resolveBarData(bars: BarQueryData[], toDenom: string, fromDenom: string) { + const toDecimals = getAssetByDenom(toDenom)?.decimals || 6 + const fromDecimals = getAssetByDenom(fromDenom)?.decimals || 6 + const additionalDecimals = toDecimals - fromDecimals return bars.map((bar) => ({ time: BN(bar.timestamp).multipliedBy(1000).toNumber(), @@ -264,4 +269,4 @@ export class OsmosisTheGraphDataFeed implements IDatafeedChartApi { unsubscribeBars(listenerGuid: string): void { // TheGraph doesn't support websockets yet } -} +} \ No newline at end of file diff --git a/src/constants/assets.ts b/src/constants/assets.ts index 215a0be0..9fa301b5 100644 --- a/src/constants/assets.ts +++ b/src/constants/assets.ts @@ -37,6 +37,7 @@ export const ASSETS: Asset[] = [ isDisplayCurrency: true, isAutoLendEnabled: true, pythPriceFeedId: 'b00b60f88b03a6a625a8d1c048c3f66653edf217439983d037e7222c4e612819', + poolId: 1, }, { symbol: 'stATOM', @@ -52,6 +53,7 @@ export const ASSETS: Asset[] = [ isMarket: !IS_TESTNET, isDisplayCurrency: !IS_TESTNET, isAutoLendEnabled: true, + poolId: 803, }, { symbol: 'WBTC.axl', @@ -68,6 +70,7 @@ export const ASSETS: Asset[] = [ isDisplayCurrency: !IS_TESTNET, isAutoLendEnabled: true, pythPriceFeedId: 'e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43', + poolId: 712, }, { symbol: 'WETH.axl', @@ -84,6 +87,7 @@ export const ASSETS: Asset[] = [ isDisplayCurrency: !IS_TESTNET, isAutoLendEnabled: true, pythPriceFeedId: 'ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace', + poolId: 704, }, { symbol: 'MARS', @@ -120,6 +124,7 @@ export const ASSETS: Asset[] = [ isStable: true, isAutoLendEnabled: true, pythPriceFeedId: 'eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a', + poolId: 678, }, { symbol: 'AXL', @@ -136,6 +141,7 @@ export const ASSETS: Asset[] = [ isDisplayCurrency: !IS_TESTNET, isAutoLendEnabled: true, pythPriceFeedId: '60144b1d5c9e9851732ad1d9760e3485ef80be39b984f6bf60f82b28a2b7f126', + poolId: 812, }, { symbol: '$', @@ -223,4 +229,4 @@ export const ASSETS: Asset[] = [ hasOraclePrice: !IS_TESTNET, forceFetchPrice: !IS_TESTNET, }, -] +] \ No newline at end of file