-
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.
* PDI-2301 moore-hk adapter for trueusd PoR * add changeset * cleanup * review fixes * update readme
- Loading branch information
1 parent
134ce71
commit 5bb4038
Showing
19 changed files
with
490 additions
and
0 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 @@ | ||
--- | ||
'@chainlink/moore-hk-adapter': major | ||
--- | ||
|
||
moore-hk initial EA release |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,54 @@ | ||
# MOORE-HK | ||
|
||
![0.0.0](https://img.shields.io/github/package-json/v/smartcontractkit/external-adapters-js?filename=packages/sources/moore-hk/package.json) ![v3](https://img.shields.io/badge/framework%20version-v3-blueviolet) | ||
|
||
This document was generated automatically. Please see [README Generator](../../scripts#readme-generator) for more info. | ||
|
||
## Environment Variables | ||
|
||
| Required? | Name | Description | Type | Options | Default | | ||
| :-------: | :----------: | :-----------------------------------: | :----: | :-----: | :-----------------------------------------------: | | ||
| | API_ENDPOINT | An API endpoint for the Data Provider | string | | `https://api.real-time-reserves.verinumus.io/v1/` | | ||
|
||
--- | ||
|
||
## Data Provider Rate Limits | ||
|
||
| Name | Requests/credits per second | Requests/credits per minute | Requests/credits per hour | Note | | ||
| :-----: | :-------------------------: | :-------------------------: | :-----------------------: | :--: | | ||
| default | | 6 | | | | ||
|
||
--- | ||
|
||
## Input Parameters | ||
|
||
| Required? | Name | Description | Type | Options | Default | | ||
| :-------: | :------: | :-----------------: | :----: | :--------------------------: | :-------: | | ||
| | endpoint | The endpoint to use | string | [trueusd](#trueusd-endpoint) | `trueusd` | | ||
|
||
## Trueusd Endpoint | ||
|
||
`trueusd` is the only supported name for this endpoint. | ||
|
||
### Input Params | ||
|
||
| Required? | Name | Aliases | Description | Type | Options | Default | Depends On | Not Valid With | | ||
| :-------: | :---: | :-----: | :------------------------------------------------------: | :----: | :-----: | :----------: | :--------: | :------------: | | ||
| | field | | The object-path string to parse a single `result` value. | string | | `totalTrust` | | | | ||
|
||
### Example | ||
|
||
Request: | ||
|
||
```json | ||
{ | ||
"data": { | ||
"endpoint": "trueusd", | ||
"field": "totalTrust" | ||
} | ||
} | ||
``` | ||
|
||
--- | ||
|
||
MIT License |
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,40 @@ | ||
{ | ||
"name": "@chainlink/moore-hk-adapter", | ||
"version": "0.0.0", | ||
"description": "Chainlink moore-hk adapter.", | ||
"keywords": [ | ||
"Chainlink", | ||
"LINK", | ||
"blockchain", | ||
"oracle", | ||
"moore-hk" | ||
], | ||
"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.11.68", | ||
"nock": "13.2.9", | ||
"typescript": "5.0.4" | ||
}, | ||
"dependencies": { | ||
"@chainlink/external-adapter-framework": "0.33.2", | ||
"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,9 @@ | ||
import { AdapterConfig } from '@chainlink/external-adapter-framework/config' | ||
|
||
export const config = new AdapterConfig({ | ||
API_ENDPOINT: { | ||
description: 'An API endpoint for the Data Provider', | ||
type: 'string', | ||
default: 'https://api.real-time-reserves.verinumus.io/v1/', | ||
}, | ||
}) |
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 trueusd } from './trueusd' |
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 { config } from '../config' | ||
import { httpTransport } from '../transport/trueusd' | ||
|
||
export const inputParameters = new InputParameters( | ||
{ | ||
field: { | ||
default: 'totalTrust', | ||
description: 'The object-path string to parse a single `result` value.', | ||
type: 'string', | ||
}, | ||
}, | ||
[ | ||
{ | ||
field: 'totalTrust', | ||
}, | ||
], | ||
) | ||
|
||
export type BaseEndpointTypes = { | ||
Parameters: typeof inputParameters.definition | ||
Response: SingleNumberResultResponse | ||
Settings: typeof config.settings | ||
} | ||
|
||
export const endpoint = new AdapterEndpoint({ | ||
name: 'trueusd', | ||
transport: httpTransport, | ||
inputParameters, | ||
}) |
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 { trueusd } from './endpoint' | ||
|
||
export const adapter = new Adapter({ | ||
defaultEndpoint: trueusd.name, | ||
name: 'MOORE-HK', | ||
config, | ||
endpoints: [trueusd], | ||
rateLimiting: { | ||
tiers: { | ||
default: { | ||
rateLimit1m: 6, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
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,83 @@ | ||
import { HttpTransport } from '@chainlink/external-adapter-framework/transports' | ||
import { BaseEndpointTypes } from '../endpoint/trueusd' | ||
|
||
interface ResponseSchema { | ||
accountName: string | ||
totalTrust: number | ||
totalToken: number | ||
updatedAt: string | ||
token: { | ||
tokenName: string | ||
totalTokenByChain: number | ||
}[] | ||
ripcord: boolean | ||
ripcordDetails: 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_ENDPOINT, | ||
url: '/chainlink/proof-of-reserves/TrueUSD', | ||
}, | ||
} | ||
}) | ||
}, | ||
parseResponse: (params, response) => { | ||
return params.map((param) => { | ||
// Return error if ripcord indicator true | ||
const providerIndicatedTimeUnixMs = new Date(response.data.updatedAt).getTime() | ||
if (response.data.ripcord) { | ||
const message = `Ripcord indicator true. Details: ${response.data.ripcordDetails.join( | ||
', ', | ||
)}` | ||
return { | ||
params: param, | ||
response: { | ||
errorMessage: message, | ||
statusCode: 502, | ||
timestamps: { | ||
providerIndicatedTimeUnixMs, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
const resultPath = param.field || '' | ||
const result = response.data[resultPath as keyof typeof response.data] | ||
|
||
if (isNaN(result as number)) { | ||
return { | ||
params: param, | ||
response: { | ||
errorMessage: `Value for '${resultPath}' is not a number.`, | ||
statusCode: 502, | ||
}, | ||
} | ||
} | ||
|
||
return { | ||
params: param, | ||
response: { | ||
result: result as number, | ||
data: { | ||
result: result as number, | ||
}, | ||
timestamps: { | ||
providerIndicatedTimeUnixMs, | ||
}, | ||
}, | ||
} | ||
}) | ||
}, | ||
}) |
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 @@ | ||
{ | ||
"requests": [{ | ||
"field": "totalTrust" | ||
}] | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/sources/moore-hk/test/integration/__snapshots__/adapter.test.ts.snap
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,39 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`execute trueusd endpoint should return 502 when field dne 1`] = ` | ||
{ | ||
"errorMessage": "Value for 'invalidField' is not a number.", | ||
"statusCode": 502, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 978347471111, | ||
"providerDataRequestedUnixMs": 978347471111, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`execute trueusd endpoint should return 502 when ripcord: true 1`] = ` | ||
{ | ||
"errorMessage": "Ripcord indicator true. Details: Details1, Details2", | ||
"statusCode": 502, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 978347471111, | ||
"providerDataRequestedUnixMs": 978347471111, | ||
"providerIndicatedTimeUnixMs": 1706162197155, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`execute trueusd endpoint should return success 1`] = ` | ||
{ | ||
"data": { | ||
"result": 1888313215.57, | ||
}, | ||
"result": 1888313215.57, | ||
"statusCode": 200, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 978347471111, | ||
"providerDataRequestedUnixMs": 978347471111, | ||
"providerIndicatedTimeUnixMs": 1706162197155, | ||
}, | ||
} | ||
`; |
Oops, something went wrong.