-
Notifications
You must be signed in to change notification settings - Fork 308
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
Peregrine Data External Adapter Submission #3590
base: main
Are you sure you want to change the base?
Changes from all commits
e28136e
d1b0993
0b7838f
3a60293
199a8a3
82605d8
6898571
3cecc24
5a77e40
53d98b9
c15ec77
63dc9d6
b4fa6e2
909072c
732fd7f
481efb8
9526713
ddae225
0ef17bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chainlink/peregrine-fund-admin-adapter': patch | ||
--- | ||
|
||
Peregrine Fund Admin Init |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chainlink/peregrine-fund-admin-adapter': patch | ||
--- | ||
|
||
Peregrine PR refactor and testing |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Chainlink External Adapter for peregrine-fund-admin | ||
|
||
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 peregrine-fund-admin`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@chainlink/peregrine-fund-admin-adapter", | ||
"version": "0.0.1", | ||
"description": "Chainlink peregrine-fund-admin adapter.", | ||
"keywords": [ | ||
"Chainlink", | ||
"LINK", | ||
"blockchain", | ||
"oracle", | ||
"peregrine-fund-admin" | ||
], | ||
"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.115", | ||
"nock": "13.5.4", | ||
"typescript": "5.6.3" | ||
}, | ||
"dependencies": { | ||
"@chainlink/external-adapter-framework": "1.7.3", | ||
"tslib": "2.4.1" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||
import { AdapterConfig } from '@chainlink/external-adapter-framework/config' | ||||||
droconnel22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
export const config = new AdapterConfig({ | ||||||
API_KEY: { | ||||||
description: 'An API key for Data Provider', | ||||||
type: 'string', | ||||||
required: true, | ||||||
sensitive: true, | ||||||
default: '', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this line |
||||||
}, | ||||||
API_BASE_URL: { | ||||||
droconnel22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
description: 'Base URL to Fund Admin Server Endpoint', | ||||||
type: 'string', | ||||||
default: '', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
API_NAV_ENDPOINT: { | ||||||
description: | ||||||
'An API endpoint for the latest Net Asset Value (NAV) calculation for a given asset', | ||||||
type: 'string', | ||||||
default: '', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
API_RESERVE_ENDPOINT: { | ||||||
description: 'API Endpoint to get the latest Proof of Reserves for a given asset', | ||||||
type: 'string', | ||||||
droconnel22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
default: '', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { endpoint as nav } from './nav' | ||
export { endpoint as reserve } from './reserve' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { AdapterEndpoint } from '@chainlink/external-adapter-framework/adapter' | ||
import { httpTransport } from '../transport/nav' | ||
import { InputParameters } from '@chainlink/external-adapter-framework/validation' | ||
import { SingleNumberResultResponse } from '@chainlink/external-adapter-framework/util' | ||
import { config } from '../config' | ||
|
||
export const inputParameters = new InputParameters( | ||
{ | ||
assetId: { | ||
required: true, | ||
type: 'string', | ||
description: 'The identifying number for the requested asset', | ||
}, | ||
}, | ||
[ | ||
{ | ||
assetId: '100', | ||
}, | ||
], | ||
) | ||
|
||
export type BaseEndpointTypes = { | ||
Parameters: typeof inputParameters.definition | ||
Response: SingleNumberResultResponse | ||
Settings: typeof config.settings | ||
} | ||
|
||
export const endpoint = new AdapterEndpoint({ | ||
name: 'nav', | ||
transport: httpTransport, | ||
inputParameters, | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { AdapterEndpoint } from '@chainlink/external-adapter-framework/adapter' | ||
import { httpTransport } from '../transport/reserve' | ||
import { InputParameters } from '@chainlink/external-adapter-framework/validation' | ||
import { SingleNumberResultResponse } from '@chainlink/external-adapter-framework/util' | ||
import { config } from '../config' | ||
|
||
export const inputParameters = new InputParameters( | ||
{ | ||
assetId: { | ||
required: true, | ||
type: 'string', | ||
description: 'The identifying number for the requested asset', | ||
}, | ||
}, | ||
[ | ||
{ | ||
assetId: '100', | ||
}, | ||
], | ||
) | ||
|
||
export type BaseEndpointTypes = { | ||
Parameters: typeof inputParameters.definition | ||
Response: SingleNumberResultResponse | ||
Settings: typeof config.settings | ||
} | ||
|
||
export const endpoint = new AdapterEndpoint({ | ||
name: 'reserve', | ||
inputParameters, | ||
transport: httpTransport, | ||
}) |
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 { nav, reserve } from './endpoint' | ||
|
||
export const adapter = new Adapter({ | ||
defaultEndpoint: nav.name, | ||
name: 'PEREGRINE_FUND_ADMIN', | ||
config, | ||
endpoints: [nav, reserve], | ||
droconnel22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rateLimiting: { | ||
tiers: { | ||
default: { | ||
rateLimit1m: 30, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
export const server = (): Promise<ServerInstance | undefined> => expose(adapter) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,76 @@ | ||||||
import { HttpTransport } from '@chainlink/external-adapter-framework/transports' | ||||||
import { BaseEndpointTypes } from '../endpoint/nav' | ||||||
|
||||||
export interface ResponseSchema { | ||||||
equityNav: number | ||||||
seniorNav: number | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this changed on your side in the API response? |
||||||
juniorNav: number | ||||||
totalCollateral: number | ||||||
totalAccounts: number | ||||||
totalLiability: number | ||||||
updateDateTime: string | ||||||
assetId: string | ||||||
} | ||||||
|
||||||
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_BASE_URL, | ||||||
url: config.API_NAV_ENDPOINT, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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`, | ||||||
statusCode: 502, | ||||||
}, | ||||||
} | ||||||
}) | ||||||
} | ||||||
|
||||||
return params.map((param) => { | ||||||
const equityNav = response.data.equityNav | ||||||
if (equityNav) { | ||||||
return { | ||||||
params: param, | ||||||
response: { | ||||||
result: Number(response.data.equityNav), | ||||||
droconnel22 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
data: { | ||||||
result: Number(response.data.equityNav), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
timestamps: { | ||||||
providerIndicatedTimeUnixMs: Number(response.data.updateDateTime) * 1000, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updateDateTime returns a formatted string, not a number that can be cast. Please use a proper conversion here. |
||||||
}, | ||||||
}, | ||||||
}, | ||||||
} | ||||||
} else { | ||||||
return { | ||||||
params: param, | ||||||
response: { | ||||||
errorMessage: `The data provider didn't return any value for asset id: ${param}`, | ||||||
statusCode: 502, | ||||||
}, | ||||||
} | ||||||
} | ||||||
}) | ||||||
}, | ||||||
}) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make the same changes as above |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { HttpTransport } from '@chainlink/external-adapter-framework/transports' | ||
import { BaseEndpointTypes } from '../endpoint/reserve' | ||
|
||
export interface ResponseSchema { | ||
assetId: string | ||
totalValue: number | ||
currencyBase: string | ||
accountIds: number[] | ||
updateDateTime: string | ||
} | ||
|
||
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_BASE_URL, | ||
url: config.API_RESERVE_ENDPOINT, | ||
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`, | ||
statusCode: 502, | ||
}, | ||
} | ||
}) | ||
} | ||
return params.map((param) => { | ||
const totalValue = response.data.totalValue | ||
if (totalValue) { | ||
return { | ||
params: param, | ||
response: { | ||
result: Number(response.data.totalValue), | ||
data: { | ||
result: Number(response.data.totalValue), | ||
}, | ||
timestamps: { | ||
providerIndicatedTimeUnixMs: Number(response.data.updateDateTime) * 1000, | ||
}, | ||
}, | ||
} | ||
} else { | ||
return { | ||
params: param, | ||
response: { | ||
errorMessage: `The data provider didn't return any value for asset id: ${param}`, | ||
statusCode: 502, | ||
}, | ||
} | ||
} | ||
}) | ||
}, | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`execute nav endpoint should return success 1`] = ` | ||
{ | ||
"data": { | ||
"result": 4.377e+21, | ||
"timestamps": { | ||
"providerIndicatedTimeUnixMs": null, | ||
}, | ||
}, | ||
"result": 4.377e+21, | ||
"statusCode": 200, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 978347471111, | ||
"providerDataRequestedUnixMs": 978347471111, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`execute reserve endpoint should return success 1`] = ` | ||
{ | ||
"data": { | ||
"result": 1e+23, | ||
}, | ||
"result": 1e+23, | ||
"statusCode": 200, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 978347471111, | ||
"providerDataRequestedUnixMs": 978347471111, | ||
"providerIndicatedTimeUnixMs": null, | ||
}, | ||
} | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.