Skip to content

Commit a26f93b

Browse files
Update/df 21604 kaiko state wbtc quote as btc (#3937)
* DF-21604 cache wbtc quotes as /btc * add changeset
1 parent e2361b4 commit a26f93b

File tree

5 files changed

+74
-5
lines changed

5 files changed

+74
-5
lines changed

.changeset/hot-zebras-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/kaiko-state-adapter': minor
3+
---
4+
5+
Cache wbtc quotes as /btc

packages/sources/kaiko-state/src/transport/state.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import { EndpointContext } from '@chainlink/external-adapter-framework/adapter'
12
import { TransportDependencies } from '@chainlink/external-adapter-framework/transports'
2-
import { sleep, makeLogger } from '@chainlink/external-adapter-framework/util'
33
import { SubscriptionTransport } from '@chainlink/external-adapter-framework/transports/abstract/subscription'
4-
import { EndpointContext } from '@chainlink/external-adapter-framework/adapter'
4+
import { makeLogger, sleep } from '@chainlink/external-adapter-framework/util'
55
import { BaseEndpointTypes } from '../endpoint/state'
66

7-
import { generateCreds, getProviderIndicatedTimeUnixMs } from './utils'
87
import { ClientReadableStream, ServiceError } from '@grpc/grpc-js'
9-
import { BehaviorSubject, distinctUntilChanged, from, fromEvent, switchMap } from 'rxjs'
108
import { backOff } from 'exponential-backoff'
9+
import { BehaviorSubject, distinctUntilChanged, from, fromEvent, switchMap } from 'rxjs'
10+
import { generateCreds, getProviderIndicatedTimeUnixMs } from './utils'
1111

1212
import { StreamAggregatedStatePriceServiceV1Client } from '@kaiko-data/sdk-node/sdk/sdk_grpc_pb'
1313
import { StreamAggregatedStatePriceRequestV1 } from '@kaiko-data/sdk-node/sdk/stream/aggregated_state_price_v1/request_pb'
@@ -73,10 +73,17 @@ export class KaikoStateTransport extends SubscriptionTransport<KaikoStateTranspo
7373

7474
subscription.on('data', (response: StreamAggregatedStatePriceResponseV1) => {
7575
const cacheData = []
76+
7677
if (response.getAggregatedPriceLst().length > 0) {
78+
const quote =
79+
response.getLstQuote().toUpperCase() == 'WETH'
80+
? 'ETH'
81+
: response.getLstQuote().toUpperCase() == 'WBTC'
82+
? 'BTC'
83+
: response.getLstQuote()
7784
cacheData.push(
7885
this._generateResponse(
79-
response.getLstQuote().toUpperCase() == 'WETH' ? 'ETH' : response.getLstQuote(),
86+
quote,
8087
response.getAggregatedPriceLst(),
8188
providerDataRequestedUnixMs,
8289
response,

packages/sources/kaiko-state/test/integration/__snapshots__/adapter.test.ts.snap

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,30 @@ exports[`execute state endpoint should return success 1`] = `
1414
}
1515
`;
1616

17+
exports[`execute state endpoint should return success with BTC quote 1`] = `
18+
{
19+
"data": {
20+
"result": 100.5,
21+
},
22+
"result": 100.5,
23+
"statusCode": 200,
24+
"timestamps": {
25+
"providerDataReceivedUnixMs": 978347471111,
26+
"providerDataRequestedUnixMs": 978347471111,
27+
},
28+
}
29+
`;
30+
31+
exports[`execute state endpoint should return success with ETH quote 1`] = `
32+
{
33+
"data": {
34+
"result": 100.3,
35+
},
36+
"result": 100.3,
37+
"statusCode": 200,
38+
"timestamps": {
39+
"providerDataReceivedUnixMs": 978347471111,
40+
"providerDataRequestedUnixMs": 978347471111,
41+
},
42+
}
43+
`;

packages/sources/kaiko-state/test/integration/adapter.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,23 @@ describe('execute', () => {
4949
expect(response.statusCode).toBe(200)
5050
expect(response.json()).toMatchSnapshot()
5151
})
52+
it('should return success with ETH quote', async () => {
53+
const data = {
54+
base: 'RETH',
55+
quote: 'ETH',
56+
}
57+
const response = await testAdapter.request(data)
58+
expect(response.statusCode).toBe(200)
59+
expect(response.json()).toMatchSnapshot()
60+
})
61+
it('should return success with BTC quote', async () => {
62+
const data = {
63+
base: 'SOLVBTC',
64+
quote: 'BTC',
65+
}
66+
const response = await testAdapter.request(data)
67+
expect(response.statusCode).toBe(200)
68+
expect(response.json()).toMatchSnapshot()
69+
})
5270
})
5371
})

packages/sources/kaiko-state/test/integration/fixtures.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ export class MockClientReadableStream {
77
getLstQuote: jest.fn(() => 'WETH'),
88
getAggregatedPriceUsd: jest.fn(() => '100.2'),
99
})
10+
handler({
11+
getBase: jest.fn(() => 'RETH'),
12+
getAggregatedPriceLst: jest.fn(() => '100.3'),
13+
getLstQuote: jest.fn(() => 'WETH'),
14+
getAggregatedPriceUsd: jest.fn(() => '100.4'),
15+
})
16+
handler({
17+
getBase: jest.fn(() => 'SOLVBTC'),
18+
getAggregatedPriceLst: jest.fn(() => '100.5'),
19+
getLstQuote: jest.fn(() => 'WBTC'),
20+
getAggregatedPriceUsd: jest.fn(() => '100.6'),
21+
})
1022
}
1123
return this
1224
})

0 commit comments

Comments
 (0)