-
Notifications
You must be signed in to change notification settings - Fork 325
OPDATA-4086: Build Blocksize Capital DEX State EA #4026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
paul-chain
merged 2 commits into
main
from
OPDATA-4086-EA-Build-Blocksize-Capital-DEX-State-EA
Oct 17, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chainlink/blocksize-capital-state-adapter': major | ||
--- | ||
|
||
Add Blocksize Capital State adapter with WebSocket support for real-time aggregated price feeds | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# BLOCKSIZE_CAPITAL_STATE | ||
|
||
  | ||
|
||
This document was generated automatically. Please see [README Generator](../../scripts#readme-generator) for more info. | ||
|
||
## Environment Variables | ||
|
||
| Required? | Name | Description | Type | Options | Default | | ||
| :-------: | :-------------: | :-------------------------------------: | :----: | :-----: | :---------------------------------------------: | | ||
| ✅ | API_KEY | The Blocksize Capital API key to use | string | | | | ||
| | WS_API_ENDPOINT | WS endpoint for Blocksize-Capital state | string | | `wss://data.blocksize.capital/marketdata/v1/ws` | | ||
|
||
--- | ||
|
||
## Data Provider Rate Limits | ||
|
||
There are no rate limits for this adapter. | ||
|
||
--- | ||
|
||
## Input Parameters | ||
|
||
| Required? | Name | Description | Type | Options | Default | | ||
| :-------: | :------: | :-----------------: | :----: | :---------------------------------------------------------------------------: | :-----: | | ||
| | endpoint | The endpoint to use | string | [crypto](#price-endpoint), [price](#price-endpoint), [state](#price-endpoint) | `price` | | ||
|
||
## Price Endpoint | ||
|
||
Supported names for this endpoint are: `crypto`, `price`, `state`. | ||
|
||
### Input Params | ||
|
||
| Required? | Name | Aliases | Description | Type | Options | Default | Depends On | Not Valid With | | ||
| :-------: | :---: | :------------: | :--------------------------------------------: | :----: | :-----: | :-----: | :--------: | :------------: | | ||
| ✅ | base | `coin`, `from` | The symbol of symbols of the currency to query | string | | | | | | ||
| ✅ | quote | `market`, `to` | The symbol of the currency to convert to | string | | | | | | ||
|
||
### Example | ||
|
||
Request: | ||
|
||
```json | ||
{ | ||
"data": { | ||
"endpoint": "price", | ||
"base": "CBBTC", | ||
"quote": "USD" | ||
} | ||
} | ||
``` | ||
|
||
--- | ||
|
||
MIT License |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "@chainlink/blocksize-capital-state-adapter", | ||
"version": "0.0.0", | ||
"description": "Chainlink blocksize-capital-state adapter.", | ||
"keywords": [ | ||
"Chainlink", | ||
"LINK", | ||
"blockchain", | ||
"oracle", | ||
"blocksize-capital-state" | ||
], | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"repository": { | ||
"url": "https://github.com/smartcontractkit/external-adapters-js", | ||
"type": "git" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"clean": "rm -rf dist && rm -f tsconfig.tsbuildinfo", | ||
"prepack": "yarn build", | ||
"build": "tsc -b", | ||
"server": "node -e 'require(\"./index.js\").server()'", | ||
"server:dist": "node -e 'require(\"./dist/index.js\").server()'", | ||
"start": "yarn server:dist" | ||
}, | ||
"devDependencies": { | ||
"@sinonjs/fake-timers": "9.1.2", | ||
"@types/jest": "^29.5.14", | ||
"@types/node": "22.14.1", | ||
"@types/sinonjs__fake-timers": "8.1.5", | ||
"nock": "13.5.6", | ||
"typescript": "5.8.3" | ||
}, | ||
"dependencies": { | ||
"@chainlink/external-adapter-framework": "2.7.2", | ||
"tslib": "2.4.1" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/sources/blocksize-capital-state/src/config/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { AdapterConfig } from '@chainlink/external-adapter-framework/config' | ||
|
||
export const config = new AdapterConfig({ | ||
API_KEY: { | ||
description: 'The Blocksize Capital API key to use', | ||
type: 'string', | ||
required: true, | ||
sensitive: true, | ||
}, | ||
WS_API_ENDPOINT: { | ||
description: 'WS endpoint for Blocksize-Capital state', | ||
type: 'string', | ||
default: 'wss://data.blocksize.capital/marketdata/v1/ws', | ||
}, | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { endpoint as state } from './state' |
28 changes: 28 additions & 0 deletions
28
packages/sources/blocksize-capital-state/src/endpoint/state.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
PriceEndpoint, | ||
priceEndpointInputParametersDefinition, | ||
mmcallister-cll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} from '@chainlink/external-adapter-framework/adapter' | ||
import { SingleNumberResultResponse } from '@chainlink/external-adapter-framework/util' | ||
import { InputParameters } from '@chainlink/external-adapter-framework/validation' | ||
import { config } from '../config' | ||
import { stateTransport } from '../transport/state' | ||
|
||
export const inputParameters = new InputParameters(priceEndpointInputParametersDefinition, [ | ||
{ | ||
base: 'CBBTC', | ||
quote: 'USD', | ||
}, | ||
]) | ||
|
||
export type BaseEndpointTypes = { | ||
Parameters: typeof inputParameters.definition | ||
Response: SingleNumberResultResponse | ||
Settings: typeof config.settings | ||
} | ||
|
||
export const endpoint = new PriceEndpoint({ | ||
name: 'price', | ||
aliases: ['crypto', 'state'], | ||
transport: stateTransport, | ||
inputParameters, | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { expose, ServerInstance } from '@chainlink/external-adapter-framework' | ||
import { PriceAdapter } from '@chainlink/external-adapter-framework/adapter' | ||
import { config } from './config' | ||
import { state } from './endpoint' | ||
|
||
export const adapter = new PriceAdapter({ | ||
name: 'BLOCKSIZE_CAPITAL_STATE', | ||
defaultEndpoint: state.name, | ||
config, | ||
endpoints: [state], | ||
}) | ||
|
||
export const server = (): Promise<ServerInstance | undefined> => expose(adapter) |
116 changes: 116 additions & 0 deletions
116
packages/sources/blocksize-capital-state/src/transport/state.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { EndpointContext } from '@chainlink/external-adapter-framework/adapter' | ||
import { WebSocketTransport } from '@chainlink/external-adapter-framework/transports' | ||
import { makeLogger } from '@chainlink/external-adapter-framework/util' | ||
import { BaseEndpointTypes } from '../endpoint/state' | ||
import { | ||
blocksizeStateWebsocketOpenHandler, | ||
buildBlocksizeWebsocketTickersMessage, | ||
processStateData, | ||
StateData, | ||
} from './utils' | ||
|
||
const logger = makeLogger('StateTransport') | ||
|
||
// JSON-RPC 2.0 message structure used by Blocksize Capital WebSocket API | ||
// Used for both authentication and subscription/streaming messages | ||
interface BlocksizeMessage { | ||
jsonrpc: string | ||
id?: number | ||
method?: string | ||
params?: any | ||
result?: any | ||
error?: any | ||
paul-chain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
interface StateMessage extends BlocksizeMessage { | ||
method: 'state' | ||
params: { | ||
states: StateData[] | ||
} | ||
} | ||
|
||
type WSMessage = BlocksizeMessage | StateMessage | ||
|
||
export interface TransportTypes extends BaseEndpointTypes { | ||
Provider: { | ||
WsMessage: WSMessage | ||
} | ||
} | ||
|
||
type RequestParams = { base: string; quote: string } | ||
|
||
// Handle subscription snapshot response | ||
// Provider sends initial snapshot upon successful subscription | ||
function handleSubscriptionSnapshot(message: BlocksizeMessage): any[] { | ||
// Validate snapshot structure | ||
if (!message.result?.snapshot || !Array.isArray(message.result.snapshot)) { | ||
logger.warn(`Invalid snapshot structure for subscription ${message.id}`) | ||
return [] | ||
} | ||
|
||
logger.info( | ||
`Subscription snapshot received (request ${message.id}): ${message.result.snapshot.length} items`, | ||
) | ||
|
||
if (message.result.snapshot.length === 0) { | ||
logger.warn( | ||
`Pair does not exist for subscription ${message.id}. Verify ticker format matches provider requirements or check if asset is supported`, | ||
) | ||
return [] | ||
} | ||
|
||
// Validate each state data item in snapshot | ||
const validStates = message.result.snapshot.filter((state: any) => { | ||
if (!state || typeof state !== 'object' || !state.base_symbol || !state.quote_symbol) { | ||
logger.warn(`Invalid state data in snapshot: ${JSON.stringify(state)}`) | ||
return false | ||
} | ||
return true | ||
}) | ||
|
||
return validStates.flatMap((state: StateData) => processStateData(state)) | ||
} | ||
|
||
// Handle streaming state updates | ||
function handleStreamingUpdates(message: StateMessage): any[] { | ||
logger.debug(JSON.stringify(message)) | ||
return message.params.states.flatMap((state: StateData) => processStateData(state)) | ||
} | ||
|
||
export const stateTransport = new WebSocketTransport<TransportTypes>({ | ||
url: (context: EndpointContext<TransportTypes>) => context.adapterSettings.WS_API_ENDPOINT, | ||
|
||
handlers: { | ||
message(message: WSMessage) { | ||
if (!message || typeof message !== 'object') return [] | ||
|
||
// Subscription snapshot | ||
if (message.id !== undefined && message.result?.snapshot) { | ||
mmcallister-cll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return handleSubscriptionSnapshot(message) | ||
} | ||
|
||
// Streaming state updates | ||
if (message.method === 'state' && message.params?.states) { | ||
return handleStreamingUpdates(message as StateMessage) | ||
} | ||
|
||
return [] | ||
}, | ||
|
||
open: (connection, context) => | ||
blocksizeStateWebsocketOpenHandler(connection, { | ||
api_key: context.adapterSettings.API_KEY, | ||
}), | ||
}, | ||
|
||
builders: { | ||
subscribeMessage: (params: RequestParams) => { | ||
const ticker = `${params.base}${params.quote}`.toUpperCase() | ||
return buildBlocksizeWebsocketTickersMessage('state_subscribe', { tickers: [ticker] }) | ||
}, | ||
unsubscribeMessage: (params: RequestParams) => { | ||
const ticker = `${params.base}${params.quote}`.toUpperCase() | ||
return buildBlocksizeWebsocketTickersMessage('state_unsubscribe', { tickers: [ticker] }) | ||
}, | ||
}, | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.