-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aleno Base State Price Adapter - http price endpoint (#3571)
* Aleno Base State Price Adpater - http price endpoint Changeset added; Changes as per review update package.json fix PR deps socket.io transport remove custome test socket.io transport pnp.cjs file updated tsconfig files updated test payload updated socket.io handlers updated * Adjust soak test * changes as per review * remove comment * fix integration test * fix listeners --------- Co-authored-by: Michael Xiao <michael.xiao@smartcontract.com>
- Loading branch information
1 parent
88b3002
commit b7bd1ca
Showing
27 changed files
with
656 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
--- | ||
'k6': patch | ||
--- | ||
|
||
Accept 1% failure |
This file contains 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/aleno-adapter': major | ||
--- | ||
|
||
Aleno Base State Adapter |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+2.77 KB
.yarn/cache/@types-component-emitter-npm-1.2.14-517c2e4bd7-4cf41df13b.zip
Binary file not shown.
Binary file not shown.
This file contains 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
This file contains 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
Empty file.
This file contains 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,3 @@ | ||
# Chainlink External Adapter for aleno | ||
|
||
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 aleno`. |
This file contains 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/aleno-adapter", | ||
"version": "0.0.0", | ||
"description": "Chainlink aleno adapter.", | ||
"keywords": [ | ||
"Chainlink", | ||
"LINK", | ||
"blockchain", | ||
"oracle", | ||
"aleno" | ||
], | ||
"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": { | ||
"@types/jest": "27.5.2", | ||
"@types/node": "16.18.119", | ||
"nock": "13.5.5", | ||
"socket.io-mock-ts": "1.0.2", | ||
"typescript": "5.6.3" | ||
}, | ||
"dependencies": { | ||
"@chainlink/external-adapter-framework": "1.7.1", | ||
"socket.io-client": "^4.8.1", | ||
"tslib": "2.4.1" | ||
} | ||
} |
This file contains 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,27 @@ | ||
import { AdapterConfig } from '@chainlink/external-adapter-framework/config' | ||
|
||
export const config = new AdapterConfig({ | ||
API_KEY: { | ||
description: 'An API key for Aleno', | ||
type: 'string', | ||
required: true, | ||
sensitive: true, | ||
}, | ||
API_ENDPOINT: { | ||
description: 'An API endpoint for Data Provider', | ||
type: 'string', | ||
default: 'https://state-price.aleno.ai', | ||
}, | ||
WS_API_ENDPOINT: { | ||
description: 'WS endpoint for Aleno', | ||
type: 'string', | ||
default: 'https://ws-state-price.aleno.ai', | ||
}, | ||
|
||
BACKGROUND_EXECUTE_MS: { | ||
description: | ||
'The amount of time the background execute should sleep before performing the next request', | ||
type: 'number', | ||
default: 10_000, | ||
}, | ||
}) |
This file contains 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 price } from './price' |
This file contains 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,32 @@ | ||
import { AdapterEndpoint } from '@chainlink/external-adapter-framework/adapter' | ||
import { InputParameters } from '@chainlink/external-adapter-framework/validation' | ||
import { SingleNumberResultResponse } from '@chainlink/external-adapter-framework/util' | ||
import { TransportRoutes } from '@chainlink/external-adapter-framework/transports' | ||
import { priceEndpointInputParametersDefinition } from '@chainlink/external-adapter-framework/adapter' | ||
import { config } from '../config' | ||
|
||
import { httpTransport } from '../transport/price-http' | ||
import { socketioTransport } from '../transport/price-socketio' | ||
|
||
export const inputParameters = new InputParameters(priceEndpointInputParametersDefinition, [ | ||
{ | ||
base: 'FRAX', | ||
quote: 'USD', | ||
}, | ||
]) | ||
|
||
export type BaseEndpointTypes = { | ||
Parameters: typeof inputParameters.definition | ||
Response: SingleNumberResultResponse | ||
Settings: typeof config.settings | ||
} | ||
|
||
export const endpoint = new AdapterEndpoint({ | ||
name: 'price', | ||
aliases: ['crypto', 'state'], | ||
transportRoutes: new TransportRoutes<BaseEndpointTypes>() | ||
.register('rest', httpTransport) | ||
.register('socketio', socketioTransport), | ||
inputParameters, | ||
defaultTransport: 'socketio', | ||
}) |
This file contains 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,20 @@ | ||
import { expose, ServerInstance } from '@chainlink/external-adapter-framework' | ||
import { Adapter } from '@chainlink/external-adapter-framework/adapter' | ||
import { config } from './config' | ||
import { price } from './endpoint' | ||
|
||
export const adapter = new Adapter({ | ||
defaultEndpoint: price.name, | ||
name: 'ALENO', | ||
config, | ||
endpoints: [price], | ||
rateLimiting: { | ||
tiers: { | ||
default: { | ||
rateLimit1m: 30, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
export const server = (): Promise<ServerInstance | undefined> => expose(adapter) |
This file contains 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,94 @@ | ||
import { HttpTransport } from '@chainlink/external-adapter-framework/transports' | ||
import { BaseEndpointTypes } from '../endpoint/price' | ||
|
||
export interface ResponseSchema { | ||
[index: number]: { | ||
id: string | ||
baseSymbol: string | ||
quoteSymbol: string | ||
processTimestamp: number | ||
processBlockChainId: string | ||
processBlockNumber: number | ||
processBlockTimestamp: number | ||
aggregatedLast7DaysBaseVolume: number | ||
price: number | ||
aggregatedMarketDepthMinusOnePercentUsdAmount: number | ||
aggregatedMarketDepthPlusOnePercentUsdAmount: number | ||
aggregatedMarketDepthUsdAmount: number | ||
aggregatedLast7DaysUsdVolume: number | ||
} | ||
} | ||
|
||
export type HttpTransportTypes = BaseEndpointTypes & { | ||
Provider: { | ||
RequestBody: never | ||
ResponseBody: ResponseSchema | ||
} | ||
} | ||
|
||
export const httpTransport = new HttpTransport<HttpTransportTypes>({ | ||
prepareRequests: (params, config) => { | ||
return params.map((param) => { | ||
return { | ||
params: [param], | ||
request: { | ||
baseURL: config.API_ENDPOINT, | ||
url: 'baseTokenStates/latest', | ||
headers: { | ||
'x-api-key': config.API_KEY, | ||
}, | ||
}, | ||
} | ||
}) | ||
}, | ||
|
||
parseResponse: (params, response) => { | ||
if (!response.data) { | ||
return params.map((param) => { | ||
return { | ||
params: param, | ||
response: { | ||
errorMessage: `The data provider didn't return any value for ${param.base}/${param.quote}`, | ||
statusCode: 502, | ||
}, | ||
} | ||
}) | ||
} | ||
|
||
return params.map((param) => { | ||
let result | ||
let processTimestamp | ||
|
||
Object.values(response.data).forEach((row) => { | ||
if (row.baseSymbol === param.base && row.quoteSymbol === param.quote) { | ||
result = Number(row.price) | ||
processTimestamp = row.processTimestamp | ||
} | ||
}) | ||
|
||
if (result === undefined || processTimestamp === undefined) { | ||
return { | ||
params: param, | ||
response: { | ||
errorMessage: `The data provider didn't return any value for ${param.base}/${param.quote}`, | ||
statusCode: 502, | ||
}, | ||
} | ||
} | ||
|
||
return { | ||
params: param, | ||
response: { | ||
result, | ||
data: { | ||
result, | ||
}, | ||
timestamps: { | ||
providerDataReceivedUnixMs: Date.now(), | ||
providerIndicatedTimeUnixMs: processTimestamp * 1000, | ||
}, | ||
}, | ||
} | ||
}) | ||
}, | ||
}) |
Oops, something went wrong.