Skip to content

Commit

Permalink
v7.5.6
Browse files Browse the repository at this point in the history
v7.5.6
  • Loading branch information
platschi authored Sep 4, 2023
2 parents 65f1e4b + d13cc3e commit eacbd88
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 47 deletions.
2 changes: 2 additions & 0 deletions packages/app/src/sections/dashboard/Stake/StakingHeading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ const BannerContainer = styled(FlexDivCentered)`
cursor: pointer;
border-radius: 8px;
white-space: pre-wrap;
text-align: center;
padding: 0px 5px;
`
31 changes: 0 additions & 31 deletions packages/sdk/src/constants/prices.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
import { formatBytes32String } from '@ethersproject/strings'

import { V2_MARKETS_LIST } from './futures'

// Additional commonly used currencies to fetch, besides the one returned by the SynthUtil.synthsRates
export const ADDITIONAL_SYNTHS = [
'SNX',
'ETH',
'BTC',
'LINK',
'SOL',
'AVAX',
'MATIC',
'EUR',
'AAVE',
'UNI',
'XAU',
'XAG',
'APE',
'DYDX',
'BNB',
'XMR',
'DOGE',
'OP',
'ATOM',
'FLOW',
'FTM',
'NEAR',
'AXS',
'AUD',
'GBP',
].map(formatBytes32String)

export const PYTH_IDS = {
mainnet: V2_MARKETS_LIST.filter((m) => !!m.pythIds).map((m) => m.pythIds!.mainnet) as string[],
testnet: V2_MARKETS_LIST.filter((m) => !!m.pythIds).map((m) => m.pythIds!.testnet) as string[],
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import RewardEscrowV2ABI from './abis/RewardEscrowV2.json'
import StakingRewardsABI from './abis/StakingRewards.json'
import SupplyScheduleABI from './abis/SupplySchedule.json'
import SynthRedeemerABI from './abis/SynthRedeemer.json'
import SynthUtilABI from './abis/SynthUtil.json'
import SystemStatusABI from './abis/SystemStatus.json'
import PerpsV3AccountProxyABI from './abis/PerpsV3AccountProxy.json'
import { ADDRESSES } from './constants'
Expand Down Expand Up @@ -199,6 +200,9 @@ export const getMulticallContractsByNetwork = (networkId: NetworkId) => {
SynthRedeemer: ADDRESSES.SynthRedeemer[networkId]
? new EthCallContract(ADDRESSES.SynthRedeemer[networkId], SynthRedeemerABI)
: undefined,
SynthUtil: ADDRESSES.SynthUtil[networkId]
? new EthCallContract(ADDRESSES.SynthUtil[networkId], SynthUtilABI)
: undefined,
ExchangeRates: ADDRESSES.ExchangeRates[networkId]
? new EthCallContract(ADDRESSES.ExchangeRates[networkId], ExchangeRatesABI)
: undefined,
Expand Down
36 changes: 20 additions & 16 deletions packages/sdk/src/services/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ import KwentaSDK from '..'
import * as sdkErrors from '../common/errors'
import { MARKETS, MARKET_ASSETS_BY_PYTH_ID } from '../constants/futures'
import { PERIOD_IN_SECONDS } from '../constants/period'
import { ADDITIONAL_SYNTHS, PRICE_UPDATE_THROTTLE, PYTH_IDS } from '../constants/prices'
import { PRICE_UPDATE_THROTTLE, PYTH_IDS } from '../constants/prices'
import { NetworkId, PriceServer } from '../types/common'
import { FuturesMarketKey } from '../types/futures'
import {
CurrencyPrice,
SynthPrice,
PricesListener,
PricesMap,
SynthPricesTuple,
} from '../types/prices'
import { SynthPrice, PricesListener, PricesMap, SynthPricesTuple } from '../types/prices'
import {
getDisplayAsset,
getPythNetworkUrl,
Expand All @@ -28,6 +22,7 @@ import {
import { startInterval } from '../utils/interval'
import { scale } from '../utils/number'
import { getRatesEndpoint } from '../utils/prices'
import { PerpsV2MarketData } from '../contracts/types'

const DEBUG_WS = false
const LOG_WS = process.env.NODE_ENV !== 'production' && DEBUG_WS
Expand Down Expand Up @@ -128,31 +123,40 @@ export default class PricesService {
}

public async getOnChainPrices() {
if (!this.sdk.context.contracts.SynthUtil || !this.sdk.context.contracts.ExchangeRates) {
if (
!this.sdk.context.multicallContracts.SynthUtil ||
!this.sdk.context.multicallContracts.PerpsV2MarketData
) {
throw new Error(sdkErrors.UNSUPPORTED_NETWORK)
}

const synthPrices: Record<string, Wei> = {}

const [synthsRates, ratesForCurrencies] = (await Promise.all([
this.sdk.context.contracts.SynthUtil.synthsRates(),
this.sdk.context.contracts.ExchangeRates.ratesForCurrencies(ADDITIONAL_SYNTHS),
])) as [SynthPricesTuple, CurrencyPrice[]]
const [synthsRates, perpsMarkets] = (await this.sdk.context.multicallProvider.all([
this.sdk.context.multicallContracts.SynthUtil.synthsRates(),
this.sdk.context.multicallContracts.PerpsV2MarketData.allProxiedMarketSummaries(),
])) as [SynthPricesTuple, PerpsV2MarketData.MarketSummaryStructOutput[]]

const synths = [...synthsRates[0], ...ADDITIONAL_SYNTHS]
const rates = [...synthsRates[1], ...ratesForCurrencies] as CurrencyPrice[]
const synths = synthsRates[0]
const synthRates = synthsRates[1]

synths.forEach((currencyKeyBytes32, i) => {
const currencyKey = parseBytes32String(currencyKeyBytes32)
const marketAsset = MarketAssetByKey[currencyKey as FuturesMarketKey]

const rate = Number(formatEther(rates[i]))
const rate = Number(formatEther(synthRates[i]))
const price = wei(rate)

synthPrices[currencyKey] = price
if (marketAsset) synthPrices[marketAsset] = price
})

perpsMarkets.forEach((market) => {
const marketAsset = parseBytes32String(market.asset)
const price = wei(market.price)
if (marketAsset) synthPrices[marketAsset] = price
})

return synthPrices
}

Expand Down

1 comment on commit eacbd88

@vercel
Copy link

@vercel vercel bot commented on eacbd88 Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kwenta – ./packages/app

kwenta-kwenta.vercel.app
kwenta.io
kwenta-git-main-kwenta.vercel.app

Please sign in to comment.