-
Notifications
You must be signed in to change notification settings - Fork 317
Backed-Fi EA #3929
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
Merged
+450
−0
Merged
Backed-Fi EA #3929
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba05323
Backed-Fi EA
Subarna-Singh 5c5554c
Testing; Adding error message in response
Subarna-Singh 704ae82
Merge branch 'main' into OPDATA-2381-BackedFi-EA
Subarna-Singh ae81683
Change: network as query param
Subarna-Singh fa4799f
Merge branch 'OPDATA-2381-BackedFi-EA' of github.com:smartcontractkit…
Subarna-Singh a0d4d32
Rework: code review fixes
Subarna-Singh adb1632
Merge branch 'main' into OPDATA-2381-BackedFi-EA
mmcallister-cll 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,5 @@ | ||
--- | ||
'@chainlink/backed-fi-adapter': major | ||
--- | ||
|
||
Version 1.0.0 of Backed-Fi EA |
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 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,54 @@ | ||
# BACKED_FI | ||
|
||
  | ||
|
||
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 Backed-Fi | string | | `https://api.backed.fi/api/v1/token` | | ||
|
||
--- | ||
|
||
## Data Provider Rate Limits | ||
|
||
There are no rate limits for this adapter. | ||
|
||
--- | ||
|
||
## Input Parameters | ||
|
||
| Required? | Name | Description | Type | Options | Default | | ||
| :-------: | :------: | :-----------------: | :----: | :--------------------------------: | :----------: | | ||
| | endpoint | The endpoint to use | string | [multiplier](#multiplier-endpoint) | `multiplier` | | ||
|
||
## Multiplier Endpoint | ||
|
||
`multiplier` is the only supported name for this endpoint. | ||
|
||
### Input Params | ||
|
||
| Required? | Name | Aliases | Description | Type | Options | Default | Depends On | Not Valid With | | ||
| :-------: | :---------: | :-----: | :--------------------------------: | :----: | :-----: | :-----: | :--------: | :------------: | | ||
| ✅ | tokenSymbol | | The symbol of token to query | string | | | | | | ||
| ✅ | network | | The symbol of the network to query | string | | | | | | ||
|
||
### Example | ||
|
||
Request: | ||
|
||
```json | ||
{ | ||
"data": { | ||
"endpoint": "multiplier", | ||
"tokenSymbol": "AMZNx", | ||
"network": "Solana" | ||
} | ||
} | ||
``` | ||
|
||
--- | ||
|
||
MIT License |
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,40 @@ | ||
{ | ||
"name": "@chainlink/backed-fi-adapter", | ||
"version": "0.0.0", | ||
"description": "Chainlink backed-fi adapter.", | ||
"keywords": [ | ||
"Chainlink", | ||
"LINK", | ||
"blockchain", | ||
"oracle", | ||
"backed-fi" | ||
], | ||
"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": "29.5.14", | ||
"@types/node": "22.14.1", | ||
"nock": "13.5.6", | ||
"typescript": "5.8.3" | ||
}, | ||
"dependencies": { | ||
"@chainlink/external-adapter-framework": "2.6.0", | ||
"tslib": "2.4.1" | ||
} | ||
} |
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,9 @@ | ||
import { AdapterConfig } from '@chainlink/external-adapter-framework/config' | ||
|
||
export const config = new AdapterConfig({ | ||
API_ENDPOINT: { | ||
description: 'An API endpoint for Backed-Fi', | ||
type: 'string', | ||
default: 'https://api.backed.fi/api/v1/token', | ||
}, | ||
}) |
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 { endpoint as multiplier } from './multiplier' |
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,48 @@ | ||
import { AdapterEndpoint } from '@chainlink/external-adapter-framework/adapter' | ||
import { InputParameters } from '@chainlink/external-adapter-framework/validation' | ||
import { config } from '../config' | ||
import { httpTransport } from '../transport/multiplier' | ||
|
||
export const inputParameters = new InputParameters( | ||
{ | ||
tokenSymbol: { | ||
required: true, | ||
type: 'string', | ||
description: 'The symbol of token to query', | ||
}, | ||
network: { | ||
required: true, | ||
type: 'string', | ||
description: 'The symbol of the network to query', | ||
}, | ||
}, | ||
[ | ||
{ | ||
tokenSymbol: 'AMZNx', | ||
network: 'Solana', | ||
}, | ||
], | ||
) | ||
|
||
export type GMCIResultResponse = { | ||
Result: number | ||
Data: { | ||
currentMultiplier: number | ||
newMultiplier: number | ||
activationDateTime: number | ||
reason: string | null | ||
} | ||
} | ||
|
||
export type BaseEndpointTypes = { | ||
Parameters: typeof inputParameters.definition | ||
Response: GMCIResultResponse | ||
Settings: typeof config.settings | ||
} | ||
|
||
export const endpoint = new AdapterEndpoint({ | ||
name: 'multiplier', | ||
aliases: [], | ||
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,21 @@ | ||
import { expose, ServerInstance } from '@chainlink/external-adapter-framework' | ||
import { Adapter } from '@chainlink/external-adapter-framework/adapter' | ||
import { config } from './config' | ||
import { multiplier } from './endpoint' | ||
|
||
export const adapter = new Adapter({ | ||
defaultEndpoint: multiplier.name, | ||
name: 'BACKED_FI', | ||
config, | ||
endpoints: [multiplier], | ||
mmcallister-cll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rateLimiting: { | ||
tiers: { | ||
default: { | ||
rateLimit1m: 6, | ||
note: 'Setting reasonable default limits', | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
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,70 @@ | ||
import { HttpTransport } from '@chainlink/external-adapter-framework/transports' | ||
import { BaseEndpointTypes } from '../endpoint/multiplier' | ||
|
||
export interface ResponseSchema { | ||
activationDateTime: number | ||
currentMultiplier: number | ||
newMultiplier: number | ||
reason: string | null | ||
mmcallister-cll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
error: string | ||
message: 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: `${param.tokenSymbol}/multiplier`, | ||
params: { | ||
network: param.network, | ||
}, | ||
}, | ||
} | ||
}) | ||
}, | ||
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.tokenSymbol} on network ${param.network}`, | ||
statusCode: 502, | ||
}, | ||
} | ||
}) | ||
} | ||
|
||
if (response.data.error) { | ||
mmcallister-cll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return params.map((param) => { | ||
return { | ||
params: param, | ||
response: { | ||
errorMessage: response.data.message, | ||
statusCode: 502, | ||
}, | ||
} | ||
}) | ||
} | ||
|
||
return params.map((param) => { | ||
const result = response.data.currentMultiplier | ||
return { | ||
params: param, | ||
response: { | ||
result: result, | ||
data: response.data, | ||
}, | ||
} | ||
}) | ||
}, | ||
}) |
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,6 @@ | ||
{ | ||
"requests": [{ | ||
"tokenSymbol": "METAx", | ||
"network": "Arbitrum" | ||
}] | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/sources/backed-fi/test/integration/__snapshots__/adapter.test.ts.snap
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,29 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`execute multiplier endpoint should return failure - invalid network 1`] = ` | ||
{ | ||
"errorMessage": "Cannot read properties of undefined (reading 'multiplier')", | ||
"statusCode": 502, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 978347471111, | ||
"providerDataRequestedUnixMs": 978347471111, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`execute multiplier endpoint should return success 1`] = ` | ||
{ | ||
"data": { | ||
"activationDateTime": 0, | ||
"currentMultiplier": 1, | ||
"newMultiplier": 0, | ||
"reason": null, | ||
}, | ||
"result": 1, | ||
"statusCode": 200, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 978347471111, | ||
"providerDataRequestedUnixMs": 978347471111, | ||
}, | ||
} | ||
`; |
59 changes: 59 additions & 0 deletions
59
packages/sources/backed-fi/test/integration/adapter.test.ts
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,59 @@ | ||
import { | ||
TestAdapter, | ||
setEnvVariables, | ||
} from '@chainlink/external-adapter-framework/util/testing-utils' | ||
import * as nock from 'nock' | ||
import { mockResponseFailure, mockResponseSuccess } from './fixtures' | ||
|
||
describe('execute', () => { | ||
let spy: jest.SpyInstance | ||
let testAdapter: TestAdapter | ||
let oldEnv: NodeJS.ProcessEnv | ||
|
||
beforeAll(async () => { | ||
oldEnv = JSON.parse(JSON.stringify(process.env)) | ||
|
||
const mockDate = new Date('2001-01-01T11:11:11.111Z') | ||
spy = jest.spyOn(Date, 'now').mockReturnValue(mockDate.getTime()) | ||
|
||
const adapter = (await import('./../../src')).adapter | ||
adapter.rateLimiting = undefined | ||
testAdapter = await TestAdapter.startWithMockedCache(adapter, { | ||
testAdapter: {} as TestAdapter<never>, | ||
}) | ||
}) | ||
|
||
afterAll(async () => { | ||
setEnvVariables(oldEnv) | ||
await testAdapter.api.close() | ||
nock.restore() | ||
nock.cleanAll() | ||
spy.mockRestore() | ||
}) | ||
|
||
describe('multiplier endpoint', () => { | ||
it('should return success', async () => { | ||
const data = { | ||
tokenSymbol: 'METAx', | ||
network: 'Arbitrum', | ||
endpoint: 'multiplier', | ||
} | ||
mockResponseSuccess() | ||
const response = await testAdapter.request(data) | ||
expect(response.statusCode).toBe(200) | ||
expect(response.json()).toMatchSnapshot() | ||
}) | ||
|
||
it('should return failure - invalid network', async () => { | ||
const data = { | ||
tokenSymbol: 'METAx', | ||
network: 'Ethereum', | ||
endpoint: 'multiplier', | ||
} | ||
mockResponseFailure() | ||
const response = await testAdapter.request(data) | ||
expect(response.statusCode).toBe(502) | ||
expect(response.json()).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
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.