@chainlink/external-adapter-framework 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.c8rc.json +3 -0
- package/.eslintignore +9 -0
- package/.eslintrc.js +96 -0
- package/.github/README.MD +17 -0
- package/.github/actions/setup/action.yaml +13 -0
- package/.github/workflows/main.yaml +39 -0
- package/.github/workflows/publish.yaml +20 -0
- package/.prettierignore +13 -0
- package/.yarnrc +0 -0
- package/README.md +103 -0
- package/dist/src/adapter.d.ts +135 -0
- package/dist/src/adapter.js +145 -0
- package/dist/src/background-executor.d.ts +11 -0
- package/{background-executor.js → dist/src/background-executor.js} +0 -0
- package/{cache → dist/src/cache}/factory.d.ts +0 -0
- package/dist/src/cache/factory.js +55 -0
- package/dist/src/cache/index.d.ts +94 -0
- package/dist/src/cache/index.js +173 -0
- package/{cache → dist/src/cache}/local.d.ts +0 -0
- package/{cache → dist/src/cache}/local.js +0 -0
- package/{cache → dist/src/cache}/metrics.d.ts +0 -0
- package/{cache → dist/src/cache}/metrics.js +0 -0
- package/{cache → dist/src/cache}/redis.d.ts +0 -0
- package/dist/src/cache/redis.js +100 -0
- package/dist/src/chainlink-external-adapter-framework-0.0.6.tgz +0 -0
- package/dist/src/config/index.d.ts +214 -0
- package/dist/src/config/index.js +380 -0
- package/{config → dist/src/config}/provider-limits.d.ts +0 -0
- package/{config → dist/src/config}/provider-limits.js +1 -1
- package/dist/src/examples/bank-frick/accounts.d.ts +39 -0
- package/dist/src/examples/bank-frick/accounts.js +192 -0
- package/dist/src/examples/bank-frick/config/index.d.ts +4 -0
- package/dist/src/examples/bank-frick/config/index.js +54 -0
- package/dist/src/examples/bank-frick/index.d.ts +2 -0
- package/dist/src/examples/bank-frick/index.js +15 -0
- package/dist/src/examples/bank-frick/util.d.ts +4 -0
- package/dist/src/examples/bank-frick/util.js +39 -0
- package/dist/src/examples/coingecko/batch-warming.d.ts +7 -0
- package/dist/src/examples/coingecko/batch-warming.js +53 -0
- package/dist/src/examples/coingecko/index.d.ts +2 -0
- package/dist/src/examples/coingecko/index.js +11 -0
- package/dist/src/examples/coingecko/rest.d.ts +12 -0
- package/dist/src/examples/coingecko/rest.js +51 -0
- package/{examples → dist/src/examples}/ncfx/config/index.d.ts +0 -0
- package/{examples → dist/src/examples}/ncfx/config/index.js +0 -0
- package/dist/src/examples/ncfx/index.d.ts +13 -0
- package/dist/src/examples/ncfx/index.js +11 -0
- package/dist/src/examples/ncfx/websocket.d.ts +47 -0
- package/dist/src/examples/ncfx/websocket.js +73 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +128 -0
- package/{metrics → dist/src/metrics}/constants.d.ts +0 -0
- package/{metrics → dist/src/metrics}/constants.js +0 -0
- package/{metrics → dist/src/metrics}/index.d.ts +0 -0
- package/dist/src/metrics/index.js +122 -0
- package/dist/src/metrics/util.d.ts +7 -0
- package/dist/src/metrics/util.js +9 -0
- package/{adapter.d.ts → dist/src/package/adapter.d.ts} +0 -0
- package/{adapter.js → dist/src/package/adapter.js} +0 -0
- package/{background-executor.d.ts → dist/src/package/background-executor.d.ts} +0 -0
- package/dist/src/package/background-executor.js +45 -0
- package/dist/src/package/cache/factory.d.ts +6 -0
- package/{cache → dist/src/package/cache}/factory.js +0 -0
- package/{cache → dist/src/package/cache}/index.d.ts +0 -0
- package/{cache → dist/src/package/cache}/index.js +0 -0
- package/dist/src/package/cache/local.d.ts +23 -0
- package/dist/src/package/cache/local.js +83 -0
- package/dist/src/package/cache/metrics.d.ts +27 -0
- package/dist/src/package/cache/metrics.js +120 -0
- package/dist/src/package/cache/redis.d.ts +16 -0
- package/{cache → dist/src/package/cache}/redis.js +0 -0
- package/{config → dist/src/package/config}/index.d.ts +0 -0
- package/{config → dist/src/package/config}/index.js +0 -0
- package/dist/src/package/config/provider-limits.d.ts +31 -0
- package/dist/src/package/config/provider-limits.js +76 -0
- package/{examples → dist/src/package/examples}/coingecko/batch-warming.d.ts +0 -0
- package/{examples → dist/src/package/examples}/coingecko/batch-warming.js +0 -0
- package/{examples → dist/src/package/examples}/coingecko/index.d.ts +0 -0
- package/{examples → dist/src/package/examples}/coingecko/index.js +0 -0
- package/{examples → dist/src/package/examples}/coingecko/rest.d.ts +0 -0
- package/{examples → dist/src/package/examples}/coingecko/rest.js +0 -0
- package/dist/src/package/examples/ncfx/config/index.d.ts +12 -0
- package/dist/src/package/examples/ncfx/config/index.js +15 -0
- package/{examples → dist/src/package/examples}/ncfx/index.d.ts +0 -0
- package/{examples → dist/src/package/examples}/ncfx/index.js +0 -0
- package/{examples → dist/src/package/examples}/ncfx/websocket.d.ts +0 -0
- package/{examples → dist/src/package/examples}/ncfx/websocket.js +0 -0
- package/{index.d.ts → dist/src/package/index.d.ts} +0 -0
- package/{index.js → dist/src/package/index.js} +0 -0
- package/dist/src/package/metrics/constants.d.ts +16 -0
- package/dist/src/package/metrics/constants.js +25 -0
- package/dist/src/package/metrics/index.d.ts +15 -0
- package/{metrics → dist/src/package/metrics}/index.js +0 -0
- package/{metrics → dist/src/package/metrics}/util.d.ts +0 -0
- package/{metrics → dist/src/package/metrics}/util.js +0 -0
- package/dist/src/package/package.json +72 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/background/fixed-frequency.d.ts +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/background/fixed-frequency.js +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/index.d.ts +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/index.js +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/metrics.d.ts +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/metrics.js +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/request/simple-counting.d.ts +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/request/simple-counting.js +0 -0
- package/{test.d.ts → dist/src/package/test.d.ts} +0 -0
- package/{test.js → dist/src/package/test.js} +0 -0
- package/{transports → dist/src/package/transports}/batch-warming.d.ts +0 -0
- package/{transports → dist/src/package/transports}/batch-warming.js +0 -0
- package/{transports → dist/src/package/transports}/index.d.ts +0 -0
- package/{transports → dist/src/package/transports}/index.js +0 -0
- package/{transports → dist/src/package/transports}/metrics.d.ts +0 -0
- package/{transports → dist/src/package/transports}/metrics.js +0 -0
- package/{transports → dist/src/package/transports}/rest.d.ts +0 -0
- package/{transports → dist/src/package/transports}/rest.js +0 -0
- package/{transports → dist/src/package/transports}/util.d.ts +0 -0
- package/{transports → dist/src/package/transports}/util.js +0 -0
- package/{transports → dist/src/package/transports}/websocket.d.ts +0 -0
- package/{transports → dist/src/package/transports}/websocket.js +0 -0
- package/{util → dist/src/package/util}/expiring-sorted-set.d.ts +0 -0
- package/{util → dist/src/package/util}/expiring-sorted-set.js +0 -0
- package/{util → dist/src/package/util}/index.d.ts +0 -0
- package/{util → dist/src/package/util}/index.js +0 -0
- package/{util → dist/src/package/util}/logger.d.ts +0 -0
- package/{util → dist/src/package/util}/logger.js +0 -0
- package/{util → dist/src/package/util}/request.d.ts +0 -0
- package/{util → dist/src/package/util}/request.js +0 -0
- package/{validation → dist/src/package/validation}/error.d.ts +0 -0
- package/{validation → dist/src/package/validation}/error.js +0 -0
- package/{validation → dist/src/package/validation}/index.d.ts +0 -0
- package/{validation → dist/src/package/validation}/index.js +0 -0
- package/{validation → dist/src/package/validation}/input-params.d.ts +0 -0
- package/{validation → dist/src/package/validation}/input-params.js +0 -0
- package/{validation → dist/src/package/validation}/override-functions.d.ts +0 -0
- package/{validation → dist/src/package/validation}/override-functions.js +0 -0
- package/{validation → dist/src/package/validation}/preset-tokens.json +0 -0
- package/{validation → dist/src/package/validation}/validator.d.ts +0 -0
- package/{validation → dist/src/package/validation}/validator.js +0 -0
- package/dist/src/package.json +72 -0
- package/dist/src/rate-limiting/background/fixed-frequency.d.ts +11 -0
- package/dist/src/rate-limiting/background/fixed-frequency.js +35 -0
- package/dist/src/rate-limiting/index.d.ts +55 -0
- package/dist/src/rate-limiting/index.js +63 -0
- package/dist/src/rate-limiting/metrics.d.ts +3 -0
- package/dist/src/rate-limiting/metrics.js +44 -0
- package/dist/src/rate-limiting/request/simple-counting.d.ts +21 -0
- package/dist/src/rate-limiting/request/simple-counting.js +62 -0
- package/dist/src/test.d.ts +1 -0
- package/dist/src/test.js +6 -0
- package/dist/src/transports/batch-warming.d.ts +35 -0
- package/dist/src/transports/batch-warming.js +101 -0
- package/dist/src/transports/index.d.ts +70 -0
- package/dist/src/transports/index.js +87 -0
- package/dist/src/transports/metrics.d.ts +22 -0
- package/dist/src/transports/metrics.js +105 -0
- package/dist/src/transports/rest.d.ts +44 -0
- package/dist/src/transports/rest.js +131 -0
- package/dist/src/transports/util.d.ts +8 -0
- package/dist/src/transports/util.js +85 -0
- package/dist/src/transports/websocket.d.ts +80 -0
- package/dist/src/transports/websocket.js +166 -0
- package/dist/src/util/expiring-sorted-set.d.ts +21 -0
- package/dist/src/util/expiring-sorted-set.js +47 -0
- package/dist/src/util/index.d.ts +12 -0
- package/dist/src/util/index.js +35 -0
- package/dist/src/util/logger.d.ts +42 -0
- package/dist/src/util/logger.js +62 -0
- package/dist/src/util/request.d.ts +57 -0
- package/dist/src/util/request.js +2 -0
- package/dist/src/util/subscription-set/expiring-sorted-set.d.ts +22 -0
- package/dist/src/util/subscription-set/expiring-sorted-set.js +47 -0
- package/dist/src/util/subscription-set/subscription-set.d.ts +18 -0
- package/dist/src/util/subscription-set/subscription-set.js +19 -0
- package/dist/src/util/test-payload-loader.d.ts +25 -0
- package/dist/src/util/test-payload-loader.js +83 -0
- package/dist/src/validation/error.d.ts +50 -0
- package/dist/src/validation/error.js +79 -0
- package/dist/src/validation/index.d.ts +5 -0
- package/dist/src/validation/index.js +91 -0
- package/dist/src/validation/input-params.d.ts +15 -0
- package/dist/src/validation/input-params.js +30 -0
- package/dist/src/validation/override-functions.d.ts +3 -0
- package/dist/src/validation/override-functions.js +40 -0
- package/dist/src/validation/preset-tokens.json +23 -0
- package/dist/src/validation/validator.d.ts +47 -0
- package/dist/src/validation/validator.js +303 -0
- package/docker-compose.yaml +35 -0
- package/env.sh +54 -0
- package/env2.sh +55 -0
- package/package.json +5 -3
- package/publish.sh +0 -0
- package/src/adapter.ts +263 -0
- package/src/background-executor.ts +52 -0
- package/src/cache/factory.ts +26 -0
- package/src/cache/index.ts +258 -0
- package/src/cache/local.ts +73 -0
- package/src/cache/metrics.ts +112 -0
- package/src/cache/redis.ts +93 -0
- package/src/config/index.ts +517 -0
- package/src/config/provider-limits.ts +130 -0
- package/src/examples/bank-frick/README.MD +10 -0
- package/src/examples/bank-frick/accounts.ts +246 -0
- package/src/examples/bank-frick/config/index.ts +53 -0
- package/src/examples/bank-frick/index.ts +13 -0
- package/src/examples/bank-frick/types.d.ts +38 -0
- package/src/examples/bank-frick/util.ts +55 -0
- package/src/examples/coingecko/batch-warming.ts +78 -0
- package/src/examples/coingecko/index.ts +9 -0
- package/src/examples/coingecko/rest.ts +77 -0
- package/src/examples/ncfx/config/index.ts +12 -0
- package/src/examples/ncfx/index.ts +9 -0
- package/src/examples/ncfx/websocket.ts +99 -0
- package/src/index.ts +149 -0
- package/src/metrics/constants.ts +23 -0
- package/src/metrics/index.ts +115 -0
- package/src/metrics/util.ts +18 -0
- package/src/rate-limiting/background/fixed-frequency.ts +45 -0
- package/src/rate-limiting/index.ts +100 -0
- package/src/rate-limiting/metrics.ts +18 -0
- package/src/rate-limiting/request/simple-counting.ts +76 -0
- package/src/test.ts +5 -0
- package/src/transports/batch-warming.ts +122 -0
- package/src/transports/index.ts +152 -0
- package/src/transports/metrics.ts +95 -0
- package/src/transports/rest.ts +164 -0
- package/src/transports/util.ts +63 -0
- package/src/transports/websocket.ts +245 -0
- package/src/util/index.ts +22 -0
- package/src/util/logger.ts +69 -0
- package/src/util/request.ts +117 -0
- package/src/util/subscription-set/expiring-sorted-set.ts +54 -0
- package/src/util/subscription-set/subscription-set.ts +35 -0
- package/src/util/test-payload-loader.ts +87 -0
- package/src/validation/error.ts +116 -0
- package/src/validation/index.ts +110 -0
- package/src/validation/input-params.ts +45 -0
- package/src/validation/override-functions.ts +44 -0
- package/src/validation/preset-tokens.json +23 -0
- package/src/validation/validator.ts +384 -0
- package/test/adapter.test.ts +27 -0
- package/test/background-executor.test.ts +108 -0
- package/test/cache/cache-key.test.ts +114 -0
- package/test/cache/helper.ts +100 -0
- package/test/cache/local.test.ts +54 -0
- package/test/cache/redis.test.ts +89 -0
- package/test/correlation.test.ts +114 -0
- package/test/index.test.ts +37 -0
- package/test/metrics/feed-id.test.ts +38 -0
- package/test/metrics/helper.ts +14 -0
- package/test/metrics/labels.test.ts +36 -0
- package/test/metrics/metrics.test.ts +267 -0
- package/test/metrics/redis-metrics.test.ts +113 -0
- package/test/metrics/warmer-metrics.test.ts +192 -0
- package/test/metrics/ws-metrics.test.ts +225 -0
- package/test/rate-limit-config.test.ts +242 -0
- package/test/smoke.test.ts +166 -0
- package/test/transports/batch.test.ts +465 -0
- package/test/transports/rest.test.ts +242 -0
- package/test/transports/websocket.test.ts +183 -0
- package/test/tsconfig.json +5 -0
- package/test/util.ts +77 -0
- package/test/validation.test.ts +178 -0
- package/test-payload-fail.json +3 -0
- package/test-payload.js +22 -0
- package/test-payload.json +7 -0
- package/test.sh +20 -0
- package/test2.sh +2 -0
- package/tsconfig.json +25 -0
- package/typedoc.json +6 -0
- package/webpack.config.js +23 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { HttpRequestType } from '../metrics/constants'
|
|
2
|
+
|
|
3
|
+
type ErrorBasic = {
|
|
4
|
+
name: string
|
|
5
|
+
message: string
|
|
6
|
+
}
|
|
7
|
+
type ErrorFull = ErrorBasic & {
|
|
8
|
+
stack: string
|
|
9
|
+
cause: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type AdapterErrorResponse = {
|
|
13
|
+
jobRunID: string
|
|
14
|
+
status: string
|
|
15
|
+
statusCode: number
|
|
16
|
+
providerStatusCode?: number
|
|
17
|
+
error: ErrorBasic | ErrorFull
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class AdapterError extends Error {
|
|
21
|
+
jobRunID: string
|
|
22
|
+
status: string
|
|
23
|
+
statusCode: number
|
|
24
|
+
cause: any
|
|
25
|
+
url?: string
|
|
26
|
+
errorResponse: any
|
|
27
|
+
feedID?: string
|
|
28
|
+
providerStatusCode?: number
|
|
29
|
+
metricsLabel?: HttpRequestType
|
|
30
|
+
|
|
31
|
+
override name: string
|
|
32
|
+
override message: string
|
|
33
|
+
|
|
34
|
+
constructor({
|
|
35
|
+
jobRunID = '1',
|
|
36
|
+
status = 'errored',
|
|
37
|
+
statusCode = 500,
|
|
38
|
+
name = 'AdapterError',
|
|
39
|
+
message = 'An error occurred.',
|
|
40
|
+
cause,
|
|
41
|
+
url,
|
|
42
|
+
errorResponse,
|
|
43
|
+
feedID,
|
|
44
|
+
providerStatusCode,
|
|
45
|
+
metricsLabel = HttpRequestType.ADAPTER_ERROR,
|
|
46
|
+
}: Partial<AdapterError>) {
|
|
47
|
+
super(message)
|
|
48
|
+
|
|
49
|
+
this.jobRunID = jobRunID
|
|
50
|
+
this.status = status
|
|
51
|
+
this.statusCode = statusCode
|
|
52
|
+
this.name = name
|
|
53
|
+
this.message = message
|
|
54
|
+
this.cause = cause
|
|
55
|
+
if (url) {
|
|
56
|
+
this.url = url
|
|
57
|
+
}
|
|
58
|
+
if (feedID) {
|
|
59
|
+
this.feedID = feedID
|
|
60
|
+
}
|
|
61
|
+
this.errorResponse = errorResponse
|
|
62
|
+
this.providerStatusCode = providerStatusCode
|
|
63
|
+
this.metricsLabel = metricsLabel
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
toJSONResponse(): AdapterErrorResponse {
|
|
67
|
+
const showDebugInfo =
|
|
68
|
+
process.env['NODE_ENV'] === 'development' || process.env['DEBUG'] === 'true'
|
|
69
|
+
const errorBasic = {
|
|
70
|
+
name: this.name,
|
|
71
|
+
message: this.message,
|
|
72
|
+
url: this.url,
|
|
73
|
+
errorResponse: this.errorResponse,
|
|
74
|
+
feedID: this.feedID,
|
|
75
|
+
}
|
|
76
|
+
const errorFull = { ...errorBasic, stack: this.stack, cause: this.cause }
|
|
77
|
+
return {
|
|
78
|
+
jobRunID: this.jobRunID,
|
|
79
|
+
status: this.status,
|
|
80
|
+
statusCode: this.statusCode,
|
|
81
|
+
providerStatusCode: this.providerStatusCode,
|
|
82
|
+
error: showDebugInfo ? errorFull : errorBasic,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export class AdapterInputError extends AdapterError {
|
|
88
|
+
constructor(input: Partial<AdapterError>) {
|
|
89
|
+
super({ ...input, metricsLabel: HttpRequestType.INPUT_ERROR })
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export class AdapterRateLimitError extends AdapterError {
|
|
93
|
+
constructor(input: Partial<AdapterError>) {
|
|
94
|
+
super({ ...input, metricsLabel: HttpRequestType.RATE_LIMIT_ERROR })
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export class AdapterTimeoutError extends AdapterError {
|
|
98
|
+
constructor(input: Partial<AdapterError>) {
|
|
99
|
+
super({ ...input, metricsLabel: HttpRequestType.TIMEOUT_ERROR })
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export class AdapterDataProviderError extends AdapterError {
|
|
103
|
+
constructor(input: Partial<AdapterError>) {
|
|
104
|
+
super({ ...input, metricsLabel: HttpRequestType.DP_ERROR })
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export class AdapterConnectionError extends AdapterError {
|
|
108
|
+
constructor(input: Partial<AdapterError>) {
|
|
109
|
+
super({ ...input, metricsLabel: HttpRequestType.CONNECTION_ERROR })
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export class AdapterCustomError extends AdapterError {
|
|
113
|
+
constructor(input: Partial<AdapterError>) {
|
|
114
|
+
super({ ...input, metricsLabel: HttpRequestType.CUSTOM_ERROR })
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from 'fastify'
|
|
2
|
+
import { InitializedAdapter } from '../adapter'
|
|
3
|
+
import { calculateCacheKey } from '../cache'
|
|
4
|
+
import { getMetricsMeta } from '../metrics/util'
|
|
5
|
+
import { makeLogger } from '../util'
|
|
6
|
+
import { AdapterMiddlewareBuilder, AdapterRequest } from '../util/request'
|
|
7
|
+
import { AdapterError, AdapterInputError } from './error'
|
|
8
|
+
import { Validator } from './validator'
|
|
9
|
+
import { performSymbolOverrides } from './override-functions'
|
|
10
|
+
export { InputParameters } from './input-params'
|
|
11
|
+
|
|
12
|
+
const errorCatcherLogger = makeLogger('ErrorCatchingMiddleware')
|
|
13
|
+
|
|
14
|
+
export const validatorMiddleware: AdapterMiddlewareBuilder =
|
|
15
|
+
(adapter: InitializedAdapter) =>
|
|
16
|
+
(req: AdapterRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => {
|
|
17
|
+
if (req.headers['content-type'] !== 'application/json') {
|
|
18
|
+
throw new AdapterInputError({
|
|
19
|
+
message: 'Content type not "application/json", returning 400',
|
|
20
|
+
statusCode: 400,
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!req.body) {
|
|
25
|
+
throw new AdapterInputError({
|
|
26
|
+
message: 'Body not present in adapter request, returning 400',
|
|
27
|
+
statusCode: 400,
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Make endpoints case insensitive
|
|
32
|
+
const endpointParam =
|
|
33
|
+
req.body.endpoint?.toLowerCase() ||
|
|
34
|
+
req.body.data?.endpoint?.toLowerCase() ||
|
|
35
|
+
adapter.defaultEndpoint
|
|
36
|
+
if (!endpointParam) {
|
|
37
|
+
throw new AdapterInputError({
|
|
38
|
+
message: `Request body does not specify an endpoint, and there is no default endpoint configured for this adapter.`,
|
|
39
|
+
statusCode: 400,
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const endpoint = adapter.endpointsMap[endpointParam]
|
|
44
|
+
if (!endpoint) {
|
|
45
|
+
throw new AdapterInputError({
|
|
46
|
+
message: `Adapter does not have a "${endpointParam}" endpoint.`,
|
|
47
|
+
statusCode: 404,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Validate data using validator from v2
|
|
52
|
+
// TODO: See if we want to change this whole thing
|
|
53
|
+
const validator = new Validator(req.body, endpoint.inputParameters)
|
|
54
|
+
|
|
55
|
+
req.requestContext = {
|
|
56
|
+
id: req.body.id || '1',
|
|
57
|
+
cacheKey: '',
|
|
58
|
+
data: validator.validated.data,
|
|
59
|
+
endpointName: endpoint.name,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (adapter.config.METRICS_ENABLED && adapter.config.EXPERIMENTAL_METRICS_ENABLED) {
|
|
63
|
+
// Add metrics meta which includes feedId to the request
|
|
64
|
+
// Perform prior to overrides to maintain consistent Feed IDs across adapters
|
|
65
|
+
const metrics = getMetricsMeta(
|
|
66
|
+
{
|
|
67
|
+
adapterEndpoint: endpoint,
|
|
68
|
+
adapterConfig: adapter.config,
|
|
69
|
+
},
|
|
70
|
+
validator.validated.data,
|
|
71
|
+
)
|
|
72
|
+
req.requestContext = { ...req.requestContext, meta: { metrics } }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// TODO: Support `includes` and `tokenOverrides` overrides as needed
|
|
76
|
+
const requestParams = req.requestContext.data ?? {}
|
|
77
|
+
if (requestParams['tokenOverrides']) {
|
|
78
|
+
throw new Error('Token overrides not yet supported')
|
|
79
|
+
}
|
|
80
|
+
if (requestParams['includes']) {
|
|
81
|
+
throw new Error('Includes not yet supported')
|
|
82
|
+
}
|
|
83
|
+
// Swaps the 'base' parameter if any overrides are found in the request or the adapter configuration
|
|
84
|
+
// Supports 'base' input as string or string[]
|
|
85
|
+
performSymbolOverrides(adapter, req)
|
|
86
|
+
|
|
87
|
+
req.requestContext.cacheKey = calculateCacheKey(
|
|
88
|
+
{
|
|
89
|
+
adapterEndpoint: endpoint,
|
|
90
|
+
adapterConfig: adapter.config,
|
|
91
|
+
},
|
|
92
|
+
req.requestContext.data,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
done()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const errorCatchingMiddleware = (err: Error, req: FastifyRequest, res: FastifyReply) => {
|
|
99
|
+
// Add adapter or generic error to request meta for metrics use
|
|
100
|
+
req.requestContext.meta = { ...req.requestContext.meta, error: err }
|
|
101
|
+
if (err instanceof AdapterError) {
|
|
102
|
+
// We want to log these as warn, because although they are to be expected, NOPs should
|
|
103
|
+
// Only use "correct" job specs and therefore not hit adapters with invalid requests.
|
|
104
|
+
errorCatcherLogger.warn(err)
|
|
105
|
+
res.status(err.statusCode).send(err.toJSONResponse())
|
|
106
|
+
} else {
|
|
107
|
+
errorCatcherLogger.error(err)
|
|
108
|
+
res.status(200).send('There was an unexpected error in the adapter.')
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* INPUT TYPE VALIDATIONS */
|
|
2
|
+
export type Override = Map<string, Map<string, string>>
|
|
3
|
+
|
|
4
|
+
export type InputParameter = {
|
|
5
|
+
aliases?: string[]
|
|
6
|
+
description?: string
|
|
7
|
+
type?: 'bigint' | 'boolean' | 'array' | 'number' | 'object' | 'string'
|
|
8
|
+
required?: boolean
|
|
9
|
+
options?: unknown[] // Enumerated options, ex. ['ADA', 'BTC', 'ETH']
|
|
10
|
+
default?: unknown
|
|
11
|
+
dependsOn?: string[] // Other inputs this one depends on
|
|
12
|
+
exclusive?: string[] // Other inputs that cannot be present with this one
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type InputParameters = {
|
|
16
|
+
[name: string]: InputParameter | boolean | string[]
|
|
17
|
+
}
|
|
18
|
+
export const baseInputParameters: InputParameters = {
|
|
19
|
+
endpoint: {
|
|
20
|
+
description: 'The External Adapter "endpoint" name to use.',
|
|
21
|
+
required: false,
|
|
22
|
+
type: 'string',
|
|
23
|
+
},
|
|
24
|
+
resultPath: {
|
|
25
|
+
description: 'The path to key into the API response the retrieve the result',
|
|
26
|
+
required: false,
|
|
27
|
+
// Type: 'string', TODO: Once multiple types are supported this could be string or array of strings
|
|
28
|
+
},
|
|
29
|
+
overrides: {
|
|
30
|
+
description: 'Override the mapping of token symbols to another token symbol',
|
|
31
|
+
required: false,
|
|
32
|
+
// Type: 'string', TODO: Once complex types are supported this could be { [adapter: string]: { [token: string]: string } }
|
|
33
|
+
},
|
|
34
|
+
tokenOverrides: {
|
|
35
|
+
description: 'Override the mapping of token symbols to smart contract address',
|
|
36
|
+
required: false,
|
|
37
|
+
// Type: 'string', TODO: Once complex types are supported this could be { [network: string]: { [token: string]: string } }
|
|
38
|
+
},
|
|
39
|
+
includes: {
|
|
40
|
+
description:
|
|
41
|
+
'Override the array of includes that holds additional input parameters when matching a pair of symbols',
|
|
42
|
+
required: false,
|
|
43
|
+
// Type: 'string', TODO: Once complex types are supported this could be { from: string, to: string, includes: [{ from: string, to: string, adapters: string[], inverse: boolean, tokens: boolean }] } }[]
|
|
44
|
+
},
|
|
45
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { InitializedAdapter } from '../adapter'
|
|
2
|
+
import { AdapterRequest } from '../util/request'
|
|
3
|
+
|
|
4
|
+
type Overrides = Record<string, Record<string, string>>
|
|
5
|
+
|
|
6
|
+
export const performSymbolOverrides = (adapter: InitializedAdapter, req: AdapterRequest) => {
|
|
7
|
+
let adapterOverrides = {} as Record<string, string>
|
|
8
|
+
if (
|
|
9
|
+
req.requestContext.data &&
|
|
10
|
+
req.requestContext.data['overrides'] &&
|
|
11
|
+
(req.requestContext.data['overrides'] as Overrides)[adapter.name]
|
|
12
|
+
) {
|
|
13
|
+
adapterOverrides = (req.requestContext.data['overrides'] as Overrides)[adapter.name]
|
|
14
|
+
}
|
|
15
|
+
if (!Array.isArray(req.requestContext.data['base'])) {
|
|
16
|
+
// Perform overrides specified in the request payload
|
|
17
|
+
req.requestContext.data['base'] =
|
|
18
|
+
adapterOverrides[req.requestContext.data['base'] as string] ?? req.requestContext.data['base']
|
|
19
|
+
// Perform hardcoded overrides
|
|
20
|
+
if (adapter.overrides) {
|
|
21
|
+
req.requestContext.data['base'] =
|
|
22
|
+
adapter.overrides[req.requestContext.data['base'] as string] ??
|
|
23
|
+
req.requestContext.data['base']
|
|
24
|
+
}
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
let requestedSymbols = req.requestContext.data['base']
|
|
28
|
+
for (let i = 0; i < requestedSymbols.length; i++) {
|
|
29
|
+
const symbol = requestedSymbols[i]
|
|
30
|
+
// Perform overrides specified in the request payload
|
|
31
|
+
let overriddenSymbol =
|
|
32
|
+
adapterOverrides[symbol.toUpperCase()] ?? adapterOverrides[symbol.toLowerCase()]
|
|
33
|
+
// Perform hardcoded overrides
|
|
34
|
+
if (adapter.overrides) {
|
|
35
|
+
overriddenSymbol =
|
|
36
|
+
adapter.overrides[symbol.toUpperCase()] ??
|
|
37
|
+
adapter.overrides[symbol.toLowerCase()] ??
|
|
38
|
+
overriddenSymbol
|
|
39
|
+
}
|
|
40
|
+
requestedSymbols[i] = overriddenSymbol ?? requestedSymbols[i]
|
|
41
|
+
}
|
|
42
|
+
requestedSymbols = requestedSymbols.length > 1 ? requestedSymbols : requestedSymbols[1]
|
|
43
|
+
req.requestContext.data['base'] = requestedSymbols
|
|
44
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ethereum": {
|
|
3
|
+
"LINK": "0x514910771af9ca656af840dff83e8264ecf986ca",
|
|
4
|
+
"WETH": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
5
|
+
"ETH": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
6
|
+
"stETH": "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
|
|
7
|
+
"DIGG": "0x798d1be841a82a273720ce31c822c61a67a601c3",
|
|
8
|
+
"WBTC": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
|
9
|
+
"RAI": "0x03ab458634910aad20ef5f1c8ee96f1d6ac54919",
|
|
10
|
+
"RGT": "0xD291E7a03283640FDc51b121aC401383A46cC623",
|
|
11
|
+
"RARI": "0xFca59Cd816aB1eaD66534D82bc21E7515cE441CF",
|
|
12
|
+
"SFI": "0xb753428af26e81097e7fd17f40c88aaa3e04902c",
|
|
13
|
+
"LDO": "0x5a98fcbea516cf06857215779fd812ca3bef1b32",
|
|
14
|
+
"VSP": "0x1b40183EFB4Dd766f11bDa7A7c3AD8982e998421",
|
|
15
|
+
"USDC": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
16
|
+
"USDT": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
17
|
+
"DAI": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
|
18
|
+
"FRAX": "0x853d955aCEf822Db058eb8505911ED77F175b99e",
|
|
19
|
+
"BOND": "0x0391d2021f89dc339f60fff84546ea23e337750f",
|
|
20
|
+
"FEI": "0x956f47f50a910163d8bf957cf5846d573e7f87ca",
|
|
21
|
+
"TRIBE": "0xc7283b66Eb1EB5FB86327f08e1B5816b0720212B"
|
|
22
|
+
}
|
|
23
|
+
}
|