Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@
"resolutions": {
"ethereum-cryptography@^1.1.2": "patch:ethereum-cryptography@npm%3A1.1.2#./.yarn/patches/ethereum-cryptography-npm-1.1.2-c16cfd7e8a.patch",
"ethereum-cryptography@^1.0.3": "patch:ethereum-cryptography@npm%3A1.1.2#./.yarn/patches/ethereum-cryptography-npm-1.1.2-c16cfd7e8a.patch"
},
"dependenciesMeta": {
"@chainlink/external-adapter-framework@2.9.0": {
"unplugged": true
}
}
}
Empty file.
3 changes: 3 additions & 0 deletions packages/sources/accountable/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Chainlink External Adapter for example-adapter

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 example-adapter`.
42 changes: 42 additions & 0 deletions packages/sources/accountable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@chainlink/accountable-adapter",
"version": "0.0.0",
"description": "Chainlink accountable adapter.",
"keywords": [
"Chainlink",
"LINK",
"blockchain",
"oracle",
"accountable"
],
"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": {
"@sinonjs/fake-timers": "9.1.2",
"@types/jest": "^29.5.14",
"@types/node": "22.14.1",
"@types/sinonjs__fake-timers": "8.1.5",
"nock": "13.5.6",
"typescript": "5.8.3"
},
"dependencies": {
"@chainlink/external-adapter-framework": "2.11.4",
"tslib": "2.4.1"
}
}
15 changes: 15 additions & 0 deletions packages/sources/accountable/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AdapterConfig } from '@chainlink/external-adapter-framework/config'

export const config = new AdapterConfig({
ACCOUNTABLE_BEARER_TOKEN: {
description: 'Bearer token for Accountable API authentication',
type: 'string',
required: true,
sensitive: true,
},
API_ENDPOINT: {
description: 'API endpoint for Accountable',
type: 'string',
default: 'https://dvn.accountable.capital/v1',
},
})
3 changes: 3 additions & 0 deletions packages/sources/accountable/src/config/overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"example-adapter": {}
}
1 change: 1 addition & 0 deletions packages/sources/accountable/src/endpoint/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { endpoint as reserves } from './reserves'
32 changes: 32 additions & 0 deletions packages/sources/accountable/src/endpoint/reserves.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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/reserves'

export const inputParameters = new InputParameters(
{
client: {
required: true,
type: 'string',
description: 'The client identifier (e.g. syrupusdt, syrupusdc)',
},
},
[
{
client: 'syrupusdc',
},
],
)

export type BaseEndpointTypes = {
Parameters: typeof inputParameters.definition
Response: SingleNumberResultResponse
Settings: typeof config.settings
}

export const endpoint = new AdapterEndpoint({
name: 'reserves',
transport: httpTransport,
inputParameters,
})
21 changes: 21 additions & 0 deletions packages/sources/accountable/src/index.ts
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 { reserves } from './endpoint'

export const adapter = new Adapter({
defaultEndpoint: reserves.name,
name: 'ACCOUNTABLE',
config,
endpoints: [reserves],
rateLimiting: {
tiers: {
default: {
rateLimit1s: 10,
note: 'Setting rate limit based on API spec of 10 requests per second',
},
},
},
})

export const server = (): Promise<ServerInstance | undefined> => expose(adapter)
90 changes: 90 additions & 0 deletions packages/sources/accountable/src/transport/reserves.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { HttpTransport } from '@chainlink/external-adapter-framework/transports'
import { BaseEndpointTypes } from '../endpoint/reserves'

export interface ResponseSchema {
client: string
totalReserve: number
totalSupply: number
underlyingAssets: {
name: string
value: number
}[]
collateralization: number
}

export type HttpTransportTypes = BaseEndpointTypes & {
Provider: {
RequestBody: never
ResponseBody: ResponseSchema
}
}

export interface RequestParams {
client: string
}

export interface AdapterConfig {
API_ENDPOINT: string
ACCOUNTABLE_BEARER_TOKEN: string
}

/**
* Builds a single request configuration for a given parameter
*/
export const buildRequestConfig = (param: RequestParams, config: AdapterConfig) => {
return {
params: [param],
request: {
baseURL: config.API_ENDPOINT,
url: '/reserves',
headers: {
accept: 'application/json',
Authorization: `Bearer ${config.ACCOUNTABLE_BEARER_TOKEN}`,
},
params: {
client: param.client,
},
},
}
}

/**
* Builds an error response for a parameter when no data is returned
*/
export const buildErrorResponse = (param: RequestParams) => {
return {
params: param,
response: {
errorMessage: `The data provider didn't return any value for client: ${param.client}`,
statusCode: 502,
},
}
}

/**
* Builds a success response from the API data
*/
export const buildSuccessResponse = (param: RequestParams, totalReserve: number) => {
return {
params: param,
response: {
result: totalReserve,
data: {
result: totalReserve,
},
},
}
}

export const httpTransport = new HttpTransport<HttpTransportTypes>({
prepareRequests: (params, config) => {
return params.map((param) => buildRequestConfig(param, config))
},
parseResponse: (params, response) => {
if (!response.data) {
return params.map((param) => buildErrorResponse(param))
}

return params.map((param) => buildSuccessResponse(param, response.data.totalReserve))
},
})
7 changes: 7 additions & 0 deletions packages/sources/accountable/test-payload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"requests": [
{
"client": "syrupusdc"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`execute reserves endpoint happy path should return success for syrupusdc client 1`] = `
{
"data": {
"result": 39869034.71,
},
"result": 39869034.71,
"statusCode": 200,
"timestamps": {
"providerDataReceivedUnixMs": 978347471111,
"providerDataRequestedUnixMs": 978347471111,
},
}
`;

exports[`execute reserves endpoint happy path should return success for syrupusdt client 1`] = `
{
"data": {
"result": 15000000.5,
},
"result": 15000000.5,
"statusCode": 200,
"timestamps": {
"providerDataReceivedUnixMs": 978347471111,
"providerDataRequestedUnixMs": 978347471111,
},
}
`;

exports[`execute reserves endpoint happy path should use reserves as default endpoint 1`] = `
{
"data": {
"result": 39869034.71,
},
"result": 39869034.71,
"statusCode": 200,
"timestamps": {
"providerDataReceivedUnixMs": 978347471111,
"providerDataRequestedUnixMs": 978347471111,
},
}
`;

exports[`execute reserves endpoint upstream failures should handle empty data response from upstream 1`] = `
{
"errorMessage": "The data provider didn't return any value for client: invalidclient",
"statusCode": 502,
"timestamps": {
"providerDataReceivedUnixMs": 978347471111,
"providerDataRequestedUnixMs": 978347471111,
},
}
`;

exports[`execute reserves endpoint validation errors should fail on empty request body 1`] = `
{
"error": {
"message": "[Param: client] param is required but no value was provided",
"name": "AdapterError",
},
"status": "errored",
"statusCode": 400,
}
`;

exports[`execute reserves endpoint validation errors should fail when client parameter is missing 1`] = `
{
"error": {
"message": "[Param: client] param is required but no value was provided",
"name": "AdapterError",
},
"status": "errored",
"statusCode": 400,
}
`;
Loading
Loading