-
Notifications
You must be signed in to change notification settings - Fork 327
R25 EA #4346
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
Open
cl-mayowa
wants to merge
7
commits into
main
Choose a base branch
from
feat/OPDATA-5148-r25-ea
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+721
−0
Open
R25 EA #4346
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
968a7b9
add r25 ea
cl-mayowa 0251fa7
add dependecy locks
cl-mayowa f879e1e
add changeset
cl-mayowa 3b089e3
update deps
cl-mayowa e2480b0
update ea deps
cl-mayowa eab3972
refactor ea to the easier to read
cl-mayowa 5d717ef
refactor ea
cl-mayowa 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,97 @@ | ||
| # Chainlink R25 External Adapter | ||
|
|
||
| This adapter fetches the latest NAV (Net Asset Value) via R25's REST API and returns a single numeric result with timestamps for both Data Feeds and Data Streams. | ||
|
|
||
| ## Configuration | ||
|
|
||
| The adapter takes the following environment variables: | ||
|
|
||
| | Required? | Name | Description | Type | Options | Default | | ||
| | :-------: | :------------: | :-----------------------------------------: | :----: | :-----: | :-------------------: | | ||
| | ✅ | `API_KEY` | An API key for R25 | string | | | | ||
| | ✅ | `API_SECRET` | An API secret for R25 used to sign requests | string | | | | ||
| | | `API_ENDPOINT` | An API endpoint for R25 | string | | `https://app.r25.xyz` | | ||
|
|
||
| ## Input Parameters | ||
|
|
||
| ### `nav` endpoint | ||
|
|
||
| Supported names for this endpoint are: `nav`, `price`. | ||
|
|
||
| #### Input Params | ||
|
|
||
| | Required? | Name | Description | Type | Options | Default | | ||
| | :-------: | :---------: | :---------------------------------: | :----: | :-----: | :-----: | | ||
| | ✅ | `chainType` | The chain type (e.g., polygon, sui) | string | | | | ||
| | ✅ | `tokenName` | The token name (e.g., rcusdp) | string | | | | ||
|
|
||
| ### Example | ||
|
|
||
| Request: | ||
|
|
||
| ```json | ||
| { | ||
| "data": { | ||
| "endpoint": "nav", | ||
| "chainType": "polygon", | ||
| "tokenName": "rcusdp" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Response: | ||
|
|
||
| ```json | ||
| { | ||
| "data": { | ||
| "result": 1.020408163265306 | ||
| }, | ||
| "result": 1.020408163265306, | ||
| "timestamps": { | ||
| "providerIndicatedTimeUnixMs": 1731344153448 | ||
| }, | ||
| "statusCode": 200 | ||
| } | ||
| ``` | ||
|
|
||
| ## Rate Limiting | ||
|
|
||
| The adapter implements rate limiting of 5 requests/second per IP as specified in the R25 API documentation. | ||
|
|
||
| ## Authentication | ||
|
|
||
| The adapter automatically generates the following headers for authentication: | ||
|
|
||
| - `x-api-key`: API key | ||
| - `x-utc-timestamp`: Current timestamp in milliseconds | ||
| - `x-signature`: HMAC-SHA256 signature | ||
|
|
||
| ### Signature Algorithm | ||
|
|
||
| The signature is generated using the HMAC-SHA256 algorithm. The signature string is constructed as follows: | ||
|
|
||
| ``` | ||
| {method}\n{path}\n{sorted_params}\n{timestamp}\n{api_key} | ||
| ``` | ||
|
|
||
| Where: | ||
|
|
||
| - `method`: HTTP method in lowercase (e.g., "get") | ||
| - `path`: Request path (e.g., "/api/public/current/nav") | ||
| - `sorted_params`: Query parameters sorted by key in lexicographical order, formatted as key=value, joined with & | ||
| - `timestamp`: Current UTC timestamp in milliseconds | ||
| - `api_key`: API key | ||
|
|
||
| The HMAC-SHA256 hash is computed using the `API_SECRET` as the secret key, and the result is hex-encoded. | ||
|
|
||
| ## API Response Mapping | ||
|
|
||
| ### Data Feeds mapping | ||
|
|
||
| - `answer` = `currentNav` (from API response) | ||
|
|
||
| ### Data Streams mapping | ||
|
|
||
| - `navPerShare` = `currentNav` | ||
| - `aum` = `totalAsset` | ||
| - `navDate` = `lastUpdate` | ||
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/r25-adapter", | ||
| "version": "1.0.0", | ||
cl-mayowa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "description": "Chainlink r25 adapter.", | ||
| "keywords": [ | ||
| "Chainlink", | ||
| "LINK", | ||
| "blockchain", | ||
| "oracle", | ||
| "r25" | ||
| ], | ||
| "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" | ||
| }, | ||
| "dependencies": { | ||
| "@chainlink/external-adapter-framework": "2.8.0", | ||
| "crypto-js": "4.2.0", | ||
| "tslib": "2.4.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/crypto-js": "4.2.2", | ||
| "@types/jest": "^29.5.14", | ||
| "@types/node": "22.14.1", | ||
| "nock": "13.5.6", | ||
| "typescript": "5.8.3" | ||
| } | ||
| } | ||
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,21 @@ | ||
| import { AdapterConfig } from '@chainlink/external-adapter-framework/config' | ||
|
|
||
| export const config = new AdapterConfig({ | ||
| API_KEY: { | ||
| description: 'An API key for R25', | ||
| type: 'string', | ||
| required: true, | ||
| sensitive: true, | ||
| }, | ||
| API_SECRET: { | ||
| description: 'An API secret for R25 used to sign requests', | ||
| type: 'string', | ||
| required: true, | ||
| sensitive: true, | ||
| }, | ||
| API_ENDPOINT: { | ||
| description: 'An API endpoint for R25', | ||
| type: 'string', | ||
| default: 'https://app.r25.xyz', | ||
| }, | ||
| }) |
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 * as nav from './nav' | ||
cl-mayowa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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,39 @@ | ||
| import { AdapterEndpoint } 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 { httpTransport } from '../transport/nav' | ||
|
|
||
| export const inputParameters = new InputParameters( | ||
| { | ||
| chainType: { | ||
| type: 'string', | ||
| description: 'The chain type (e.g., polygon, sui)', | ||
| required: true, | ||
| }, | ||
| tokenName: { | ||
| type: 'string', | ||
| description: 'The token name (e.g., rcusdp)', | ||
| required: true, | ||
| }, | ||
| }, | ||
| [ | ||
| { | ||
| chainType: 'polygon', | ||
| tokenName: 'rcusdp', | ||
| }, | ||
| ], | ||
| ) | ||
|
|
||
| export type BaseEndpointTypes = { | ||
| Parameters: typeof inputParameters.definition | ||
| Response: SingleNumberResultResponse | ||
| Settings: typeof config.settings | ||
| } | ||
|
|
||
| export const endpoint = new AdapterEndpoint({ | ||
| name: 'nav', | ||
| aliases: ['price'], | ||
cl-mayowa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| transport: httpTransport, | ||
| 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,20 @@ | ||
| import { expose, ServerInstance } from '@chainlink/external-adapter-framework' | ||
| import { Adapter } from '@chainlink/external-adapter-framework/adapter' | ||
| import { config } from './config' | ||
| import { endpoint as navEndpoint } from './endpoint/nav' | ||
|
|
||
| export const adapter = new Adapter({ | ||
| defaultEndpoint: navEndpoint.name, | ||
| name: 'R25', | ||
| config, | ||
| endpoints: [navEndpoint], | ||
| rateLimiting: { | ||
| tiers: { | ||
| default: { | ||
| rateLimit1s: 5, //5 requests per second | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| export const server = (): Promise<ServerInstance | undefined> => expose(adapter) |
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,52 @@ | ||
| import CryptoJS from 'crypto-js' | ||
|
|
||
| /** | ||
| * Generate the HMAC-SHA256 signature for R25 API requests. | ||
| * | ||
| * The signature string is constructed as: | ||
| * {method}\n{path}\n{sorted_params}\n{timestamp}\n{api_key} | ||
| * | ||
| * Where: | ||
| * - method: HTTP method in lowercase (e.g., "get") | ||
| * - path: Request path (e.g., "/api/public/current/nav") | ||
| * - sorted_params: Query parameters sorted by key, formatted as key=value, joined with & | ||
| * - timestamp: Current UTC timestamp in milliseconds | ||
| * - api_key: API key | ||
| */ | ||
| export const getRequestHeaders = ({ | ||
cl-mayowa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| method, | ||
| path, | ||
| params, | ||
| apiKey, | ||
| secret, | ||
| timestamp, | ||
| }: { | ||
cl-mayowa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| method: string | ||
| path: string | ||
| params: Record<string, string> | ||
| apiKey: string | ||
| secret: string | ||
| timestamp: number | ||
| }): Record<string, string> => { | ||
| // Sort parameters by key in lexicographical order and format as key=value | ||
| const sortedParams = Object.keys(params) | ||
| .sort() | ||
| .map((key) => `${key}=${params[key]}`) | ||
| .join('&') | ||
|
|
||
| const stringToSign = [ | ||
| method.toLowerCase(), | ||
| path, | ||
| sortedParams, | ||
| timestamp.toString(), | ||
| apiKey, | ||
| ].join('\n') | ||
|
|
||
| const signature = CryptoJS.HmacSHA256(stringToSign, secret).toString(CryptoJS.enc.Hex) | ||
cl-mayowa marked this conversation as resolved.
Dismissed
Show dismissed
Hide dismissed
|
||
|
|
||
| return { | ||
| 'x-api-key': apiKey, | ||
| 'x-utc-timestamp': timestamp.toString(), | ||
| 'x-signature': signature, | ||
| } | ||
| } | ||
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,87 @@ | ||
| import { HttpTransport } from '@chainlink/external-adapter-framework/transports' | ||
| import { BaseEndpointTypes } from '../endpoint/nav' | ||
| import { getRequestHeaders } from './authentication' | ||
|
|
||
| export interface ResponseSchema { | ||
| code: string | ||
| success: boolean | ||
| message: string | ||
| data: { | ||
| lastUpdate: string | ||
| tokenName: string | ||
| chainType: string | ||
| totalSupply: number | ||
| totalAsset: number | ||
| currentNav: string | ||
| } | ||
| } | ||
|
|
||
| export type HttpTransportTypes = BaseEndpointTypes & { | ||
| Provider: { | ||
| RequestBody: never | ||
| ResponseBody: ResponseSchema | ||
| } | ||
| } | ||
|
|
||
| export const httpTransport = new HttpTransport<HttpTransportTypes>({ | ||
| prepareRequests: (params, config) => { | ||
| return params.map((param) => { | ||
| const method = 'GET' | ||
| const path = '/api/public/current/nav' | ||
| const timestamp = Date.now() | ||
|
|
||
| const queryParams = { | ||
| chainType: param.chainType, | ||
| tokenName: param.tokenName, | ||
| } | ||
|
|
||
| const headers = getRequestHeaders({ | ||
| method, | ||
| path, | ||
| params: queryParams, | ||
| apiKey: config.API_KEY, | ||
| secret: config.API_SECRET, | ||
| timestamp, | ||
| }) | ||
|
|
||
| return { | ||
| params: [param], | ||
| request: { | ||
| baseURL: config.API_ENDPOINT, | ||
| url: path, | ||
| params: queryParams, | ||
| headers, | ||
| }, | ||
| } | ||
| }) | ||
| }, | ||
| parseResponse: (params, response) => { | ||
| return params.map((param) => { | ||
| if (!response.data.success) { | ||
cl-mayowa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return { | ||
| params: param, | ||
| response: { | ||
| errorMessage: response.data.message || 'Request failed', | ||
| statusCode: 502, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| const currentNav = Number(response.data.data.currentNav) | ||
cl-mayowa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const lastUpdate = response.data.data.lastUpdate | ||
|
|
||
| return { | ||
| params: param, | ||
| response: { | ||
| result: currentNav, | ||
| data: { | ||
| result: currentNav, | ||
| }, | ||
| timestamps: { | ||
| providerIndicatedTimeUnixMs: new Date(lastUpdate).getTime(), | ||
| }, | ||
| }, | ||
| } | ||
| }) | ||
| }, | ||
| }) | ||
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.