Skip to content

Commit 3dbbc53

Browse files
elwood lwba endpoint (#3061)
* update elwood to handle lwba * elwood LWBA endpoint * Soak test for LWBA * update readme --------- Co-authored-by: Alec Gard <[email protected]>
1 parent 2916f71 commit 3dbbc53

File tree

9 files changed

+51
-23
lines changed

9 files changed

+51
-23
lines changed

.changeset/lucky-rocks-sneeze.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/elwood-adapter': patch
3+
---
4+
5+
Convert crypto to lwba endpoint

packages/sources/elwood/README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ This document was generated automatically. Please see [README Generator](../../s
66

77
## Environment Variables
88

9-
| Required? | Name | Description | Type | Options | Default |
10-
| :-------: | :-------------: | :-------------------------------: | :----: | :-----: | :----------------------------------------: |
11-
|| API_KEY | API key | string | | |
12-
| | WS_API_ENDPOINT | The websocket url for coinmetrics | string | | `wss://api.chk.elwood.systems/v1/stream` |
13-
| | API_ENDPOINT | The API url for coinmetrics | string | | `https://api.chk.elwood.systems/v1/stream` |
9+
| Required? | Name | Description | Type | Options | Default |
10+
| :-------: | :-------------: | :--------------------------: | :----: | :-----: | :----------------------------------------: |
11+
|| API_KEY | API key | string | | |
12+
| | WS_API_ENDPOINT | The websocket url for elwood | string | | `wss://api.chk.elwood.systems/v1/stream` |
13+
| | API_ENDPOINT | The API url for elwood | string | | `https://api.chk.elwood.systems/v1/stream` |
1414

1515
---
1616

@@ -22,13 +22,13 @@ There are no rate limits for this adapter.
2222

2323
## Input Parameters
2424

25-
| Required? | Name | Description | Type | Options | Default |
26-
| :-------: | :------: | :-----------------: | :----: | :-------------------------------------------------: | :------: |
27-
| | endpoint | The endpoint to use | string | [crypto](#price-endpoint), [price](#price-endpoint) | `crypto` |
25+
| Required? | Name | Description | Type | Options | Default |
26+
| :-------: | :------: | :-----------------: | :----: | :------------------------------------------------------------------------------------------------------------------------------------------------: | :-----: |
27+
| | endpoint | The endpoint to use | string | [crypto-lwba](#price-endpoint), [crypto](#price-endpoint), [crypto_lwba](#price-endpoint), [cryptolwba](#price-endpoint), [price](#price-endpoint) | `price` |
2828

2929
## Price Endpoint
3030

31-
Supported names for this endpoint are: `crypto`, `price`.
31+
Supported names for this endpoint are: `crypto`, `crypto-lwba`, `crypto_lwba`, `cryptolwba`, `price`.
3232

3333
### Input Params
3434

packages/sources/elwood/src/config/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export const config = new AdapterConfig({
88
sensitive: true,
99
},
1010
WS_API_ENDPOINT: {
11-
description: 'The websocket url for coinmetrics',
11+
description: 'The websocket url for elwood',
1212
type: 'string',
1313
default: 'wss://api.chk.elwood.systems/v1/stream',
1414
},
1515
API_ENDPOINT: {
16-
description: 'The API url for coinmetrics',
16+
description: 'The API url for elwood',
1717
type: 'string',
1818
default: 'https://api.chk.elwood.systems/v1/stream',
1919
},

packages/sources/elwood/src/endpoint/crypto.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {
22
CryptoPriceEndpoint,
3+
DEFAULT_LWBA_ALIASES,
4+
LwbaResponseDataFields,
35
priceEndpointInputParametersDefinition,
46
} from '@chainlink/external-adapter-framework/adapter'
57
import { SingleNumberResultResponse } from '@chainlink/external-adapter-framework/util'
@@ -14,15 +16,17 @@ const inputParameters = new InputParameters(priceEndpointInputParametersDefiniti
1416
},
1517
])
1618

19+
type OmitResultFromLwba = Omit<LwbaResponseDataFields, 'Result'>
20+
1721
export type BaseEndpointTypes = {
1822
Parameters: typeof inputParameters.definition
1923
Settings: typeof config.settings
20-
Response: SingleNumberResultResponse
24+
Response: OmitResultFromLwba & SingleNumberResultResponse
2125
}
2226

2327
export const cryptoEndpoint = new CryptoPriceEndpoint({
2428
name: 'price',
25-
aliases: ['crypto'],
29+
aliases: ['crypto', ...DEFAULT_LWBA_ALIASES],
2630
inputParameters,
2731
transport,
2832
})

packages/sources/elwood/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { config } from './config'
55

66
export const adapter = new PriceAdapter({
77
name: 'ELWOOD',
8-
defaultEndpoint: 'crypto',
8+
defaultEndpoint: cryptoEndpoint.name,
99
config,
1010
endpoints: [cryptoEndpoint],
1111
})

packages/sources/elwood/src/transport/crypto.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export type PriceResponse = {
1919
type: 'Index'
2020
data: {
2121
price: string
22+
bid: string
23+
ask: string
2224
symbol: string
2325
timestamp: string
2426
}
@@ -76,8 +78,8 @@ export const transport: WebSocketTransport<WsTransportTypes> =
7678
return
7779
}
7880

79-
const value = Number(message.data.price)
80-
if (value < 0) {
81+
const result = Number(message.data.price)
82+
if (result < 0) {
8183
logger.warn(`Got invalid price "${message.data.price}" in WS message of type Index`)
8284
return
8385
}
@@ -89,8 +91,13 @@ export const transport: WebSocketTransport<WsTransportTypes> =
8991
quote,
9092
},
9193
response: {
92-
result: value,
93-
data: { result: value },
94+
result,
95+
data: {
96+
result,
97+
bid: Number(message.data.bid),
98+
ask: Number(message.data.ask),
99+
mid: result,
100+
},
94101
timestamps: {
95102
providerIndicatedTimeUnixMs: new Date(message.data.timestamp).getTime(),
96103
},
+12-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
2-
"requests": [{
3-
"from": "LINK",
4-
"to": "USD"
5-
}]
6-
}
2+
"requests": [
3+
{
4+
"from": "LINK",
5+
"to": "USD"
6+
},
7+
{
8+
"from": "ETH",
9+
"to": "USD",
10+
"endpoint": "crypto-lwba"
11+
}
12+
]
13+
}

packages/sources/elwood/test/integration/__snapshots__/adapter.test.ts.snap

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ exports[`websocket price endpoint should return cached subscribe error 1`] = `
1414
exports[`websocket price endpoint should return success 1`] = `
1515
{
1616
"data": {
17+
"ask": 10002,
18+
"bid": 10001,
19+
"mid": 10000,
1720
"result": 10000,
1821
},
1922
"result": 10000,

packages/sources/elwood/test/integration/fixtures.ts

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export const mockWebSocketServer = (URL: string) => {
5858
type: 'Index',
5959
data: {
6060
price: '10000',
61+
bid: '10001',
62+
ask: '10002',
6163
symbol: 'ETH-USD',
6264
timestamp: '2022-11-08T04:18:18.736534617Z',
6365
},

0 commit comments

Comments
 (0)