From 65b5529ab6e00aa3c84b56479e91db92b84efa16 Mon Sep 17 00:00:00 2001 From: mmcallister-cll <139181225+mmcallister-cll@users.noreply.github.com> Date: Mon, 19 Feb 2024 13:16:02 -0500 Subject: [PATCH] DF-19409 use asset-quotes ws endpoint for coinmetrics lwba, removing pair-quotes (#3187) * DF-19409 use asset-quotes ws endpoint for coinmetrics lwba, removing pair-quotes * add changeset --- .changeset/mighty-trains-sniff.md | 5 +++ .../sources/coinmetrics/src/endpoint/lwba.ts | 19 ++-------- .../sources/coinmetrics/src/transport/lwba.ts | 36 ++++--------------- .../sources/coinmetrics/test-payload.json | 5 +++ .../test/integration/adapter-ws.test.ts | 2 +- 5 files changed, 21 insertions(+), 46 deletions(-) create mode 100644 .changeset/mighty-trains-sniff.md diff --git a/.changeset/mighty-trains-sniff.md b/.changeset/mighty-trains-sniff.md new file mode 100644 index 0000000000..0a912b31fc --- /dev/null +++ b/.changeset/mighty-trains-sniff.md @@ -0,0 +1,5 @@ +--- +'@chainlink/coinmetrics-adapter': patch +--- + +Updated LWBA to use asset-quotes endpoint exclusively diff --git a/packages/sources/coinmetrics/src/endpoint/lwba.ts b/packages/sources/coinmetrics/src/endpoint/lwba.ts index 167a3b6fb9..9d377c67e0 100644 --- a/packages/sources/coinmetrics/src/endpoint/lwba.ts +++ b/packages/sources/coinmetrics/src/endpoint/lwba.ts @@ -3,10 +3,9 @@ import { LwbaResponseDataFields, lwbaEndpointInputParametersDefinition, } from '@chainlink/external-adapter-framework/adapter' -import { TransportRoutes } from '@chainlink/external-adapter-framework/transports' import { InputParameters } from '@chainlink/external-adapter-framework/validation' import { config } from '../config' -import { assetQuoteWebsocketTransport, pairQuoteWebsocketTransport } from '../transport/lwba' +import { wsTransport } from '../transport/lwba' export const inputParameters = new InputParameters(lwbaEndpointInputParametersDefinition, [ { @@ -15,26 +14,14 @@ export const inputParameters = new InputParameters(lwbaEndpointInputParametersDe }, ]) -const assets: string[] = ['bnb', 'uni', 'sol', 'ltc', 'xrp', 'arb'] - export type BaseEndpointTypes = { Parameters: typeof inputParameters.definition Settings: typeof config.settings Response: LwbaResponseDataFields } -export const endpoint = new LwbaEndpoint({ +export const endpoint = new LwbaEndpoint({ name: 'crypto-lwba', - transportRoutes: new TransportRoutes() - .register('asset', assetQuoteWebsocketTransport) - .register('pair', pairQuoteWebsocketTransport), - customRouter: (req, _) => { - const { base } = req.requestContext.data as typeof inputParameters.validated & { - transport?: string - } - const route = assets.includes(base.toLowerCase()) ? 'asset' : 'pair' - - return route - }, + transport: wsTransport, inputParameters, }) diff --git a/packages/sources/coinmetrics/src/transport/lwba.ts b/packages/sources/coinmetrics/src/transport/lwba.ts index d93c511072..e3e9cdd7c7 100644 --- a/packages/sources/coinmetrics/src/transport/lwba.ts +++ b/packages/sources/coinmetrics/src/transport/lwba.ts @@ -60,28 +60,15 @@ export type WsTransportTypes = BaseEndpointTypes & { WsMessage: WsPairQuoteMessage } } -export const calculatePairQuotesUrl = ( +export const calculateUrl = ( context: EndpointContext, desiredSubs: (typeof inputParameters.validated)[], - isAssetQuote: boolean, ): string => { const { API_KEY, WS_API_ENDPOINT } = context.adapterSettings - let generated = new URL('/v4/timeseries-stream/pair-quotes', WS_API_ENDPOINT) - - // use asset-quotes api if base=[BNB,UNI,SOL,LTC,XRP] - if (isAssetQuote) { - generated = new URL('/v4/timeseries-stream/asset-quotes', WS_API_ENDPOINT) - const assets = [...new Set(desiredSubs.map((pair) => pair.base.toLowerCase()))].sort().join(',') - generated.searchParams.append('assets', assets) - } else { - const pairs = [ - ...new Set(desiredSubs.map((sub) => `${sub.base.toLowerCase()}-${sub.quote.toLowerCase()}`)), - ] - .sort() - .join(',') - generated.searchParams.append('pairs', pairs) - } + const generated = new URL('/v4/timeseries-stream/asset-quotes', WS_API_ENDPOINT) + const assets = [...new Set(desiredSubs.map((pair) => pair.base.toLowerCase()))].sort().join(',') + generated.searchParams.append('assets', assets) generated.searchParams.append('api_key', API_KEY) logger.debug(`Generated URL: ${generated.toString()}`) @@ -124,19 +111,10 @@ export const handleCryptoLwbaMessage = ( } return undefined } -export const pairQuoteWebsocketTransport = new WebSocketTransport({ - url: (context, desiredSubs) => { - return calculatePairQuotesUrl(context, desiredSubs, false) - }, - handlers: { - message(message: WsPairQuoteMessage): ProviderResult[] | undefined { - return handleCryptoLwbaMessage(message) - }, - }, -}) -export const assetQuoteWebsocketTransport = new WebSocketTransport({ + +export const wsTransport = new WebSocketTransport({ url: (context, desiredSubs) => { - return calculatePairQuotesUrl(context, desiredSubs, true) + return calculateUrl(context, desiredSubs) }, handlers: { message(message: WsPairQuoteMessage): ProviderResult[] | undefined { diff --git a/packages/sources/coinmetrics/test-payload.json b/packages/sources/coinmetrics/test-payload.json index 0645cb9cd4..e105f9283e 100644 --- a/packages/sources/coinmetrics/test-payload.json +++ b/packages/sources/coinmetrics/test-payload.json @@ -4,6 +4,11 @@ "from": "LINK", "to": "USD" }, + { + "from": "ETH", + "to": "USD", + "endpoint": "crypto-lwba" + }, { "from": "ETH", "to": "USD", diff --git a/packages/sources/coinmetrics/test/integration/adapter-ws.test.ts b/packages/sources/coinmetrics/test/integration/adapter-ws.test.ts index e8e7df89ca..3d66376286 100644 --- a/packages/sources/coinmetrics/test/integration/adapter-ws.test.ts +++ b/packages/sources/coinmetrics/test/integration/adapter-ws.test.ts @@ -14,7 +14,7 @@ describe('websocket', () => { let testAdapter: TestAdapter let oldEnv: NodeJS.ProcessEnv const wsEndpoint = 'ws://localhost:9090/v4/timeseries-stream/asset-metrics' - const wsEndpointLwba = 'ws://localhost:9090/v4/timeseries-stream/pair-quotes' + const wsEndpointLwba = 'ws://localhost:9090/v4/timeseries-stream/asset-quotes' const data = { base: 'ETH', quote: 'USD',