Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-cities-enter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/mobula-state-adapter': minor
---

Revert protocol changes
5 changes: 0 additions & 5 deletions packages/sources/mobula-state/src/endpoint/funding-rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ export const inputParameters = new InputParameters(
type: 'string',
description: 'Which exchange to return the funding rate for',
},
protocol: {
required: false,
type: 'string',
description: 'The protocol to query funding rates for',
},
},
[
{
Expand Down
2 changes: 0 additions & 2 deletions packages/sources/mobula-state/src/endpoint/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export const endpoint = new CryptoPriceEndpoint({
transport: wsTransport,
inputParameters,
requestTransforms: [
// Uppercase base/quote for case-insensitive lookups
// Framework will then apply includes.json transformations
(req) => {
req.requestContext.data.base = req.requestContext.data.base.toUpperCase()
req.requestContext.data.quote = req.requestContext.data.quote.toUpperCase()
Expand Down
11 changes: 1 addition & 10 deletions packages/sources/mobula-state/src/transport/funding-rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const wsTransport = new WebSocketTransport<WsTransportTypes>({
payload: {
symbol: params.base,
quote: params.quote,
...(params.protocol && { protocol: params.protocol }),
},
}
},
Expand Down Expand Up @@ -94,16 +93,8 @@ const getFundingRateResult = (
queryDetails: WSResponse['queryDetails'],
fundingRate: FundingRateResponse,
): ProviderResult<WsTransportTypes> => {
// Symbol may contain protocol prefix, e.g. "xyz:SILVER"
const symbolParts = String(fundingRate.symbol).split(':')
const protocol = symbolParts.length > 1 ? symbolParts[0] : undefined
return {
params: {
base: queryDetails.base,
quote: queryDetails.quote ?? '',
exchange,
...(protocol && { protocol }),
},
params: { base: queryDetails.base, quote: queryDetails.quote ?? '', exchange },
response: {
result: null,
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@ exports[`websocket funding rate endpoint no data should return failure 1`] = `
}
`;

exports[`websocket funding rate endpoint with protocol param should return success 1`] = `
{
"data": {
"epochDuration": 3600,
"fundingRate": 0.00000625,
"fundingTimestamp": 1773788400,
},
"result": null,
"statusCode": 200,
"timestamps": {
"providerDataReceivedUnixMs": 18188,
"providerDataStreamEstablishedUnixMs": 16160,
},
}
`;

exports[`websocket graceful error handling and case-insensitive requests should continue working after receiving invalid symbol requests 1`] = `
{
"data": {
Expand Down
56 changes: 42 additions & 14 deletions packages/sources/mobula-state/test/integration/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ describe('websocket', () => {
endpoint: 'funding-rate',
}

const dataFundingRateProtocol = {
base: 'SILVER',
quote: 'USDC',
exchange: 'hyperliquid',
protocol: 'xyz',
endpoint: 'funding-rate',
}

beforeAll(async () => {
oldEnv = JSON.parse(JSON.stringify(process.env))
process.env['WS_API_ENDPOINT'] = wsEndpoint
Expand Down Expand Up @@ -102,6 +94,21 @@ describe('websocket', () => {
endpoint: 'price',
transport: 'ws',
})
// Prime cache for protocol:asset instrument format tests
await testAdapter.request({
base: 'xyz:EZETH',
quote: 'USD',
endpoint: 'price',
transport: 'ws',
overrides: { MOBULA_STATE: { 'XYZ:EZETH': '102478632' } },
})
await testAdapter.request({
base: 'abc:GHO',
quote: 'USD',
endpoint: 'price',
transport: 'ws',
overrides: { MOBULA_STATE: { 'ABC:GHO': '2921' } },
})
// Prime cache for graceful error handling tests
await testAdapter.request({
base: 'gho', // Lowercase test - should get uppercased to GHO
Expand All @@ -115,7 +122,7 @@ describe('websocket', () => {
endpoint: 'price',
transport: 'ws',
})
await testAdapter.waitForCache(8) // Wait for all primed pairs to be cached (7 new + 1 initial = 8 total, gho/usd doesn't create a new entry since it uppercases to GHO/USD)
await testAdapter.waitForCache(10) // 8 previous + 2 protocol-prefixed pairs
}, 30000)

afterAll(async () => {
Expand Down Expand Up @@ -298,11 +305,6 @@ describe('websocket', () => {
expect(response.json()).toMatchSnapshot()
})

it('with protocol param should return success', async () => {
const response = await testAdapter.request(dataFundingRateProtocol)
expect(response.json()).toMatchSnapshot()
})

it('no data should return failure', async () => {
const response = await testAdapter.request({
base: 'ETH',
Expand All @@ -314,6 +316,32 @@ describe('websocket', () => {
})
})

describe('protocol:asset instrument input format', () => {
it('should resolve {protocol}:{asset} via overrides (xyz:EZETH/USD)', async () => {
const response = await testAdapter.request({
base: 'xyz:EZETH',
quote: 'USD',
endpoint: 'price',
transport: 'ws',
overrides: { MOBULA_STATE: { 'XYZ:EZETH': '102478632' } },
})
expect(response.statusCode).toBe(200)
expect(response.json()).toMatchSnapshot()
})

it('should resolve {protocol}:{asset} with different protocol (abc:GHO/USD)', async () => {
const response = await testAdapter.request({
base: 'abc:GHO',
quote: 'USD',
endpoint: 'price',
transport: 'ws',
overrides: { MOBULA_STATE: { 'ABC:GHO': '2921' } },
})
expect(response.statusCode).toBe(200)
expect(response.json()).toMatchSnapshot()
})
})

describe('graceful error handling and case-insensitive requests', () => {
it('should handle lowercase symbols (case-insensitive)', async () => {
const response = await testAdapter.request({
Expand Down
12 changes: 0 additions & 12 deletions packages/sources/mobula-state/test/integration/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,6 @@ export const mockWebsocketServer = (URL: string): MockWebsocketServer => {
queryDetails: { base: 'AERGO', quote: null },
}),
)
} else if (symbol === 'SILVER' && parsed.payload.protocol === 'xyz') {
socket.send(
JSON.stringify({
hyperliquidFundingRate: {
symbol: 'xyz:SILVER',
fundingTime: 1773788400011,
fundingRate: 0.00000625,
epochDurationMs: 3600000,
},
queryDetails: { base: 'SILVER', quote: 'USDC' },
}),
)
}
}
})
Expand Down
Loading