Skip to content

Commit 62c911c

Browse files
Backed-Fi EA (#3929)
* Backed-Fi EA * Testing; Adding error message in response * Change: network as query param * Rework: code review fixes --------- Co-authored-by: mmcallister-cll <139181225+mmcallister-cll@users.noreply.github.com>
1 parent 652f6b9 commit 62c911c

File tree

19 files changed

+450
-0
lines changed

19 files changed

+450
-0
lines changed

.changeset/purple-cobras-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/backed-fi-adapter': major
3+
---
4+
5+
Version 1.0.0 of Backed-Fi EA

.pnp.cjs

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sources/backed-fi/CHANGELOG.md

Whitespace-only changes.

packages/sources/backed-fi/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# BACKED_FI
2+
3+
![0.0.0](https://img.shields.io/github/package-json/v/smartcontractkit/external-adapters-js?filename=packages/sources/backed-fi/package.json) ![v3](https://img.shields.io/badge/framework%20version-v3-blueviolet)
4+
5+
This document was generated automatically. Please see [README Generator](../../scripts#readme-generator) for more info.
6+
7+
## Environment Variables
8+
9+
| Required? | Name | Description | Type | Options | Default |
10+
| :-------: | :----------: | :---------------------------: | :----: | :-----: | :----------------------------------: |
11+
| | API_ENDPOINT | An API endpoint for Backed-Fi | string | | `https://api.backed.fi/api/v1/token` |
12+
13+
---
14+
15+
## Data Provider Rate Limits
16+
17+
There are no rate limits for this adapter.
18+
19+
---
20+
21+
## Input Parameters
22+
23+
| Required? | Name | Description | Type | Options | Default |
24+
| :-------: | :------: | :-----------------: | :----: | :--------------------------------: | :----------: |
25+
| | endpoint | The endpoint to use | string | [multiplier](#multiplier-endpoint) | `multiplier` |
26+
27+
## Multiplier Endpoint
28+
29+
`multiplier` is the only supported name for this endpoint.
30+
31+
### Input Params
32+
33+
| Required? | Name | Aliases | Description | Type | Options | Default | Depends On | Not Valid With |
34+
| :-------: | :---------: | :-----: | :--------------------------------: | :----: | :-----: | :-----: | :--------: | :------------: |
35+
|| tokenSymbol | | The symbol of token to query | string | | | | |
36+
|| network | | The symbol of the network to query | string | | | | |
37+
38+
### Example
39+
40+
Request:
41+
42+
```json
43+
{
44+
"data": {
45+
"endpoint": "multiplier",
46+
"tokenSymbol": "AMZNx",
47+
"network": "Solana"
48+
}
49+
}
50+
```
51+
52+
---
53+
54+
MIT License
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@chainlink/backed-fi-adapter",
3+
"version": "0.0.0",
4+
"description": "Chainlink backed-fi adapter.",
5+
"keywords": [
6+
"Chainlink",
7+
"LINK",
8+
"blockchain",
9+
"oracle",
10+
"backed-fi"
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+
"@types/jest": "29.5.14",
32+
"@types/node": "22.14.1",
33+
"nock": "13.5.6",
34+
"typescript": "5.8.3"
35+
},
36+
"dependencies": {
37+
"@chainlink/external-adapter-framework": "2.6.0",
38+
"tslib": "2.4.1"
39+
}
40+
}
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+
API_ENDPOINT: {
5+
description: 'An API endpoint for Backed-Fi',
6+
type: 'string',
7+
default: 'https://api.backed.fi/api/v1/token',
8+
},
9+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { endpoint as multiplier } from './multiplier'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { AdapterEndpoint } from '@chainlink/external-adapter-framework/adapter'
2+
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
3+
import { config } from '../config'
4+
import { httpTransport } from '../transport/multiplier'
5+
6+
export const inputParameters = new InputParameters(
7+
{
8+
tokenSymbol: {
9+
required: true,
10+
type: 'string',
11+
description: 'The symbol of token to query',
12+
},
13+
network: {
14+
required: true,
15+
type: 'string',
16+
description: 'The symbol of the network to query',
17+
},
18+
},
19+
[
20+
{
21+
tokenSymbol: 'AMZNx',
22+
network: 'Solana',
23+
},
24+
],
25+
)
26+
27+
export type GMCIResultResponse = {
28+
Result: number
29+
Data: {
30+
currentMultiplier: number
31+
newMultiplier: number
32+
activationDateTime: number
33+
reason: string | null
34+
}
35+
}
36+
37+
export type BaseEndpointTypes = {
38+
Parameters: typeof inputParameters.definition
39+
Response: GMCIResultResponse
40+
Settings: typeof config.settings
41+
}
42+
43+
export const endpoint = new AdapterEndpoint({
44+
name: 'multiplier',
45+
aliases: [],
46+
transport: httpTransport,
47+
inputParameters,
48+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 { multiplier } from './endpoint'
5+
6+
export const adapter = new Adapter({
7+
defaultEndpoint: multiplier.name,
8+
name: 'BACKED_FI',
9+
config,
10+
endpoints: [multiplier],
11+
rateLimiting: {
12+
tiers: {
13+
default: {
14+
rateLimit1m: 6,
15+
note: 'Setting reasonable default limits',
16+
},
17+
},
18+
},
19+
})
20+
21+
export const server = (): Promise<ServerInstance | undefined> => expose(adapter)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { HttpTransport } from '@chainlink/external-adapter-framework/transports'
2+
import { BaseEndpointTypes } from '../endpoint/multiplier'
3+
4+
export interface ResponseSchema {
5+
activationDateTime: number
6+
currentMultiplier: number
7+
newMultiplier: number
8+
reason: string | null
9+
error: string
10+
message: string
11+
}
12+
13+
export type HttpTransportTypes = BaseEndpointTypes & {
14+
Provider: {
15+
RequestBody: never
16+
ResponseBody: ResponseSchema
17+
}
18+
}
19+
export const httpTransport = new HttpTransport<HttpTransportTypes>({
20+
prepareRequests: (params, config) => {
21+
return params.map((param) => {
22+
return {
23+
params: [param],
24+
request: {
25+
baseURL: config.API_ENDPOINT,
26+
url: `${param.tokenSymbol}/multiplier`,
27+
params: {
28+
network: param.network,
29+
},
30+
},
31+
}
32+
})
33+
},
34+
parseResponse: (params, response) => {
35+
if (!response.data) {
36+
return params.map((param) => {
37+
return {
38+
params: param,
39+
response: {
40+
errorMessage: `The data provider didn't return any value for ${param.tokenSymbol} on network ${param.network}`,
41+
statusCode: 502,
42+
},
43+
}
44+
})
45+
}
46+
47+
if (response.data.error) {
48+
return params.map((param) => {
49+
return {
50+
params: param,
51+
response: {
52+
errorMessage: response.data.message,
53+
statusCode: 502,
54+
},
55+
}
56+
})
57+
}
58+
59+
return params.map((param) => {
60+
const result = response.data.currentMultiplier
61+
return {
62+
params: param,
63+
response: {
64+
result: result,
65+
data: response.data,
66+
},
67+
}
68+
})
69+
},
70+
})

0 commit comments

Comments
 (0)