Skip to content

Commit 18df82f

Browse files
authored
creating new allium-state ea for OPDATA-4235 (#4061)
* creating new allium-state ea for OPDATA-4235 * add changeset * adjust date.new and timestamp inclusion * adjust timestamp field as it was still marked as optional * adjust timestamp field as it was still marked as optional * removing the additional changesets
1 parent 3c75243 commit 18df82f

File tree

18 files changed

+380
-0
lines changed

18 files changed

+380
-0
lines changed

.changeset/selfish-apes-exist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/allium-state-adapter': major
3+
---
4+
5+
allium-state initial release

.pnp.cjs

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sources/allium-state/CHANGELOG.md

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Chainlink External Adapter for allium-state
2+
3+
This README will be generated automatically when code is merged to `main`. If you would like to generate a preview of the README, please run `yarn generate:readme allium-state`.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "@chainlink/allium-state-adapter",
3+
"version": "0.0.0",
4+
"description": "Chainlink allium-state adapter.",
5+
"keywords": [
6+
"Chainlink",
7+
"LINK",
8+
"blockchain",
9+
"oracle",
10+
"allium-state"
11+
],
12+
"main": "dist/index.js",
13+
"types": "dist/index.d.ts",
14+
"files": [
15+
"dist"
16+
],
17+
"repository": {
18+
"url": "https://github.com/smartcontractkit/external-adapters-js",
19+
"type": "git"
20+
},
21+
"license": "MIT",
22+
"scripts": {
23+
"clean": "rm -rf dist && rm -f tsconfig.tsbuildinfo",
24+
"prepack": "yarn build",
25+
"build": "tsc -b",
26+
"server": "node -e 'require(\"./index.js\").server()'",
27+
"server:dist": "node -e 'require(\"./dist/index.js\").server()'",
28+
"start": "yarn server:dist"
29+
},
30+
"devDependencies": {
31+
"@sinonjs/fake-timers": "9.1.2",
32+
"@types/jest": "^29.5.14",
33+
"@types/node": "22.14.1",
34+
"@types/sinonjs__fake-timers": "8.1.5",
35+
"nock": "13.5.6",
36+
"typescript": "5.8.3"
37+
},
38+
"dependencies": {
39+
"@chainlink/external-adapter-framework": "2.7.0",
40+
"tslib": "2.4.1"
41+
}
42+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { AdapterConfig } from '@chainlink/external-adapter-framework/config'
2+
3+
export const config = new AdapterConfig({
4+
WS_API_ENDPOINT: {
5+
description: 'The WebSocket endpoint for Allium state prices',
6+
type: 'string',
7+
default: 'wss://api.allium.so/api/v1/developer/state-prices/ws',
8+
},
9+
API_KEY: {
10+
description: 'API key for Allium',
11+
type: 'string',
12+
required: true,
13+
sensitive: true,
14+
},
15+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { endpoint as price } from './price'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {
2+
AdapterEndpoint,
3+
priceEndpointInputParametersDefinition,
4+
} from '@chainlink/external-adapter-framework/adapter'
5+
import { SingleNumberResultResponse } from '@chainlink/external-adapter-framework/util'
6+
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
7+
import { config } from '../config'
8+
import { wsTransport } from '../transport/price'
9+
10+
export const inputParameters = new InputParameters(priceEndpointInputParametersDefinition, [
11+
{
12+
base: 'BTC',
13+
quote: 'USD',
14+
},
15+
])
16+
17+
export type BaseEndpointTypes = {
18+
Parameters: typeof inputParameters.definition
19+
Response: SingleNumberResultResponse
20+
Settings: typeof config.settings
21+
}
22+
23+
export const endpoint = new AdapterEndpoint({
24+
name: 'price',
25+
aliases: ['crypto', 'state'],
26+
transport: wsTransport,
27+
inputParameters,
28+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expose, ServerInstance } from '@chainlink/external-adapter-framework'
2+
import { Adapter } from '@chainlink/external-adapter-framework/adapter'
3+
import { config } from './config'
4+
import { price } from './endpoint'
5+
6+
export const adapter = new Adapter({
7+
defaultEndpoint: price.name,
8+
name: 'ALLIUM_STATE',
9+
config,
10+
endpoints: [price],
11+
})
12+
13+
export const server = (): Promise<ServerInstance | undefined> => expose(adapter)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { WebSocketTransport } from '@chainlink/external-adapter-framework/transports'
2+
import { BaseEndpointTypes } from '../endpoint/price'
3+
4+
export interface AlliumMessage {
5+
type: string
6+
subscription_id?: string
7+
subscription_details?: {
8+
base: string
9+
quote: string
10+
}
11+
error?: string
12+
timestamp: string
13+
data?: {
14+
base: string
15+
quote: string
16+
state_price: number
17+
}
18+
}
19+
20+
export type WsTransportTypes = BaseEndpointTypes & {
21+
Provider: {
22+
WsMessage: AlliumMessage
23+
}
24+
}
25+
26+
export const wsTransport = new WebSocketTransport<WsTransportTypes>({
27+
url: (context) => {
28+
return context.adapterSettings.WS_API_ENDPOINT
29+
},
30+
31+
options: (context) => ({
32+
headers: {
33+
'X-API-Key': context.adapterSettings.API_KEY,
34+
},
35+
}),
36+
37+
handlers: {
38+
message(message) {
39+
if (message?.type !== 'aggregated_state_price_update' || !message?.data?.state_price) {
40+
return []
41+
}
42+
43+
const { base, quote, state_price } = message.data
44+
const providerDataReceivedUnixMs = Date.now()
45+
const providerIndicatedTimeUnixMs = new Date(message.timestamp).getTime()
46+
47+
return [
48+
{
49+
params: { base, quote },
50+
response: {
51+
data: {
52+
result: state_price,
53+
},
54+
result: state_price,
55+
timestamps: {
56+
providerDataReceivedUnixMs,
57+
providerIndicatedTimeUnixMs,
58+
},
59+
},
60+
},
61+
]
62+
},
63+
},
64+
65+
builders: {
66+
subscribeMessage: (params) => {
67+
return {
68+
type: 'subscribe',
69+
base: params.base,
70+
quote: params.quote,
71+
}
72+
},
73+
74+
unsubscribeMessage: (params) => {
75+
return {
76+
type: 'unsubscribe',
77+
base: params.base,
78+
quote: params.quote,
79+
}
80+
},
81+
},
82+
})

0 commit comments

Comments
 (0)