From d7e3bdf33762c0898f54f7ce97748dd5dbab99c2 Mon Sep 17 00:00:00 2001 From: Monkmansteve Date: Sun, 13 Oct 2024 15:50:47 +0300 Subject: [PATCH 1/2] add fallback logic --- src/api/prices/getPythPrices.ts | 21 +++++++++++++++++++-- src/constants/pyth.ts | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/api/prices/getPythPrices.ts b/src/api/prices/getPythPrices.ts index 820ea6e5e..5fe168906 100644 --- a/src/api/prices/getPythPrices.ts +++ b/src/api/prices/getPythPrices.ts @@ -8,11 +8,28 @@ import { BN } from 'utils/helpers' export default async function fetchPythPrices(priceFeedIds: string[], assets: Asset[]) { const pricesUrl = new URL(`${pythEndpoints.api}/latest_price_feeds`) + const fallbackUrl = new URL(`${pythEndpoints.fallbackApi}/latest_price_feeds`) + try { - priceFeedIds.forEach((id) => pricesUrl.searchParams.append('ids[]', id)) + priceFeedIds.forEach((id) => { + pricesUrl.searchParams.append('ids[]', id) + fallbackUrl.searchParams.append('ids[]', id) + }) const pythResponse: PythPriceData[] = await cacheFn( - () => fetchWithTimeout(pricesUrl.toString(), FETCH_TIMEOUT).then((res) => res.json()), + async () => { + try { + return await fetchWithTimeout(pricesUrl.toString(), FETCH_TIMEOUT).then((res) => + res.json(), + ) + } catch (error) { + console.warn('Primary Pyth API failed, falling back to fallback API', error) + + return await fetchWithTimeout(fallbackUrl.toString(), FETCH_TIMEOUT).then((res) => + res.json(), + ) + } + }, pythPriceCache, `pythPrices/${priceFeedIds.flat().join('-')}`, 30, diff --git a/src/constants/pyth.ts b/src/constants/pyth.ts index 3887c8d7c..348eafaf5 100644 --- a/src/constants/pyth.ts +++ b/src/constants/pyth.ts @@ -1,4 +1,5 @@ export const pythEndpoints = { api: process.env.NEXT_PUBLIC_PYTH_API ?? 'https://hermes.pyth.network/api', + fallbackApi: 'https://hermes.pyth.network/api', candles: 'https://benchmarks.pyth.network/v1/shims/tradingview', } From a664af63fd2cca6781cd0ba61a1ce44961436059 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:33:17 +0000 Subject: [PATCH 2/2] build(deps): bump secp256k1 from 4.0.3 to 4.0.4 Bumps [secp256k1](https://github.com/cryptocoinjs/secp256k1-node) from 4.0.3 to 4.0.4. - [Release notes](https://github.com/cryptocoinjs/secp256k1-node/releases) - [Commits](https://github.com/cryptocoinjs/secp256k1-node/compare/v4.0.3...v4.0.4) --- updated-dependencies: - dependency-name: secp256k1 dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/yarn.lock b/yarn.lock index 76bb1613f..713cef970 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6497,6 +6497,11 @@ node-addon-api@^2.0.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32" integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA== +node-addon-api@^5.0.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-5.1.0.tgz#49da1ca055e109a23d537e9de43c09cca21eb762" + integrity sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA== + node-addon-api@^7.0.0: version "7.1.1" resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-7.1.1.tgz#1aba6693b0f255258a049d621329329322aad558" @@ -7439,12 +7444,12 @@ scrypt-js@^3.0.0: integrity sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA== secp256k1@^4.0.1, secp256k1@^4.0.3: - version "4.0.3" - resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-4.0.3.tgz#c4559ecd1b8d3c1827ed2d1b94190d69ce267303" - integrity sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA== + version "4.0.4" + resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-4.0.4.tgz#58f0bfe1830fe777d9ca1ffc7574962a8189f8ab" + integrity sha512-6JfvwvjUOn8F/jUoBY2Q1v5WY5XS+rj8qSe0v8Y4ezH4InLgTEeOOPQsRll9OV429Pvo6BCHGavIyJfr3TAhsw== dependencies: - elliptic "^6.5.4" - node-addon-api "^2.0.0" + elliptic "^6.5.7" + node-addon-api "^5.0.0" node-gyp-build "^4.2.0" semver@^6.3.1: @@ -7679,8 +7684,16 @@ string-argv@~0.3.2: resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6" integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q== -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0: - name string-width-cjs +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +string-width@^4.1.0: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -7768,8 +7781,14 @@ string_decoder@^1.1.1: dependencies: safe-buffer "~5.2.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: - name strip-ansi-cjs +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==