Skip to content

Commit e93bc76

Browse files
authored
Create EA for Mobula for state pricing (#3437)
1 parent 9a4d510 commit e93bc76

File tree

19 files changed

+355
-6
lines changed

19 files changed

+355
-6
lines changed

.changeset/ten-ravens-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/mobula-state-adapter': major
3+
---
4+
5+
Create EA for Mobula for state pricing

.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/mobula-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 mobula-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 mobula-state`.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "@chainlink/mobula-state-adapter",
3+
"version": "0.0.0",
4+
"description": "Chainlink mobula-state adapter.",
5+
"keywords": [
6+
"Chainlink",
7+
"LINK",
8+
"blockchain",
9+
"oracle",
10+
"mobula-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": "27.5.2",
33+
"@types/node": "16.11.68",
34+
"@types/sinonjs__fake-timers": "8.1.5",
35+
"nock": "13.5.4",
36+
"typescript": "5.0.4"
37+
},
38+
"dependencies": {
39+
"@chainlink/external-adapter-framework": "1.3.2",
40+
"tslib": "2.4.1"
41+
}
42+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { AdapterConfig } from '@chainlink/external-adapter-framework/config'
2+
3+
export const config = new AdapterConfig({
4+
WS_API_ENDPOINT: {
5+
description: 'WS endpoint for Data Provider',
6+
type: 'string',
7+
default: 'wss://feed.zobula.xyz',
8+
},
9+
})
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { AdapterEndpoint } from '@chainlink/external-adapter-framework/adapter'
2+
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
3+
import { SingleNumberResultResponse } from '@chainlink/external-adapter-framework/util'
4+
import { config } from '../config'
5+
import { wsTransport } from '../transport/price'
6+
7+
export const inputParameters = new InputParameters(
8+
{
9+
base: {
10+
aliases: ['from', 'coin', 'symbol', 'market'],
11+
required: true,
12+
type: 'string',
13+
description: 'The symbol of symbols of the currency to query',
14+
},
15+
quote: {
16+
aliases: ['to', 'convert'],
17+
required: true,
18+
type: 'string',
19+
description: 'The symbol of the currency to convert to',
20+
},
21+
},
22+
[
23+
{
24+
base: 'ETH',
25+
quote: 'USD',
26+
},
27+
],
28+
)
29+
30+
export type BaseEndpointTypes = {
31+
Parameters: typeof inputParameters.definition
32+
Response: SingleNumberResultResponse
33+
Settings: typeof config.settings
34+
}
35+
36+
export const endpoint = new AdapterEndpoint({
37+
name: 'price',
38+
aliases: ['state'],
39+
transport: wsTransport,
40+
inputParameters,
41+
})
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: 'MOBULA_STATE',
9+
config,
10+
endpoints: [price],
11+
})
12+
13+
export const server = (): Promise<ServerInstance | undefined> => expose(adapter)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { WebSocketTransport } from '@chainlink/external-adapter-framework/transports'
2+
import { BaseEndpointTypes } from '../endpoint/price'
3+
4+
export interface WSResponse {
5+
timestamp: number
6+
price: number
7+
marketDepthUSDUp: number
8+
marketDepthUSDDown: number
9+
volume24h: number
10+
baseSymbol: string
11+
quoteSymbol: string
12+
}
13+
14+
export type WsTransportTypes = BaseEndpointTypes & {
15+
Provider: {
16+
WsMessage: WSResponse
17+
}
18+
}
19+
export const wsTransport = new WebSocketTransport<WsTransportTypes>({
20+
url: (context) => context.adapterSettings.WS_API_ENDPOINT,
21+
handlers: {
22+
open: (connection) => {
23+
connection.send(JSON.stringify({ type: 'feed' }))
24+
},
25+
message(message) {
26+
if (!message.price) {
27+
return [
28+
{
29+
params: {
30+
base: message.baseSymbol,
31+
quote: message.quoteSymbol,
32+
},
33+
response: {
34+
errorMessage: 'No price in message',
35+
statusCode: 500,
36+
},
37+
},
38+
]
39+
}
40+
41+
return [
42+
{
43+
params: { base: message.baseSymbol, quote: message.quoteSymbol },
44+
response: {
45+
result: message.price,
46+
data: {
47+
result: message.price,
48+
},
49+
timestamps: {
50+
providerIndicatedTimeUnixMs: message.timestamp,
51+
},
52+
},
53+
},
54+
]
55+
},
56+
},
57+
})

0 commit comments

Comments
 (0)