Skip to content

Commit

Permalink
Merge branch 'develop' into release/v0.2.0-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
krebernisak committed Feb 4, 2021
2 parents 0c2b976 + 9cfa19b commit 5ec72c2
Show file tree
Hide file tree
Showing 143 changed files with 2,694 additions and 1,533 deletions.
1 change: 0 additions & 1 deletion .github/strategy/adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"blockcypher",
"bootstrap",
"bravenewcoin",
"bravenewcoin-vwap",
"coinapi",
"coinbase",
"coincodex",
Expand Down
4 changes: 3 additions & 1 deletion 1forge/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = require('../.eslintrc.js')
module.exports = {
...require('../.eslintrc.ts.js'),
}
24 changes: 13 additions & 11 deletions 1forge/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# Chainlink 1Forge External Adapter

## Input Params
## Price Endpoint

### Input Params

- `base` or `to`: The target currency to query (required)
- `quote` or `from`: The currency to convert to (required)
- `endpoint`: The endpoint to call (optional)

## Output
### Output

```json
{
"jobRunID": "1",
"data": {
"value": 1.22687,
"text": "1.0 GBP is worth 1.22687 USD",
"timestamp": 1587489920,
"result": 1.22687
},
"result": 1.22687,
"statusCode": 200
"jobRunID": "1",
"data": {
"value": 1.22687,
"text": "1.0 GBP is worth 1.22687 USD",
"timestamp": 1587489920,
"result": 1.22687
},
"result": 1.22687,
"statusCode": 200
}
```
43 changes: 0 additions & 43 deletions 1forge/adapter.js

This file was deleted.

4 changes: 0 additions & 4 deletions 1forge/index.js

This file was deleted.

29 changes: 24 additions & 5 deletions 1forge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,33 @@
"name": "@chainlink/1forge-adapter",
"version": "0.0.3",
"license": "MIT",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"server": "node -e 'require(\"./index.js\").server()'",
"prepublishOnly": "yarn build && yarn test:unit",
"setup": "yarn build",
"build": "tsc -b",
"lint": "eslint --ignore-path ../.eslintignore . --ext .js,.jsx,.ts,.tsx",
"lint:fix": "eslint --ignore-path ../.eslintignore . --ext .js,.jsx,.ts,.tsx --fix",
"test": "yarn _mocha --timeout 0",
"test:unit": "yarn _mocha --grep @integration --invert --timeout 0",
"test:integration": "yarn _mocha --grep @integration --timeout 0"
"test": "mocha --exit --timeout 15000 -r ts-node/register 'test/**/*.test.ts'",
"test:unit": "mocha --exit --grep @integration --invert -r ts-node/register 'test/**/*.test.ts'",
"test:integration": "mocha --exit --timeout 15000 --grep @integration -r ts-node/register 'test/**/*.test.ts'",
"server": "node -e 'require(\"./index.js\").server()'",
"server:dist": "node -e 'require(\"./dist/index.js\").server()'",
"start": "yarn server:dist"
},
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/express": "^4.17.6",
"@types/mocha": "^7.0.2",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"ts-node": "^8.10.2",
"typescript": "^3.9.7"
},
"dependencies": {}
}
35 changes: 35 additions & 0 deletions 1forge/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Requester, Validator, AdapterError } from '@chainlink/external-adapter'
import { Config, ExecuteWithConfig, ExecuteFactory } from '@chainlink/types'
import { makeConfig, DEFAULT_ENDPOINT } from './config'
import { price } from './endpoint'

const inputParams = {
endpoint: false,
}

export const execute: ExecuteWithConfig<Config> = async (request, config) => {
const validator = new Validator(request, inputParams)
if (validator.error) throw validator.error

Requester.logConfig(config)

const jobRunID = validator.validated.id
const endpoint = validator.validated.data.endpoint || DEFAULT_ENDPOINT

switch (endpoint) {
case price.NAME: {
return await price.execute(request, config)
}
default: {
throw new AdapterError({
jobRunID,
message: `Endpoint ${endpoint} not supported.`,
statusCode: 400,
})
}
}
}

export const makeExecute: ExecuteFactory<Config> = (config) => {
return async (request) => execute(request, config || makeConfig())
}
17 changes: 17 additions & 0 deletions 1forge/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Requester } from '@chainlink/external-adapter'
import { Config } from '@chainlink/types'

export const DEFAULT_ENDPOINT = 'price'
export const DEFAULT_API_ENDPOINT = 'https://api.1forge.com/'

export const makeConfig = (prefix?: string): Config => {
const config = Requester.getDefaultConfig(prefix, true)
config.api = {
...config.api,
baseURL: config.api.baseUrl || DEFAULT_API_ENDPOINT,
params: {
api_key: config.apiKey,
},
}
return config
}
1 change: 1 addition & 0 deletions 1forge/src/endpoint/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as price from './price'
43 changes: 43 additions & 0 deletions 1forge/src/endpoint/price.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Requester, Validator } from '@chainlink/external-adapter'
import { ExecuteWithConfig, Config } from '@chainlink/types'

export const NAME = 'price'

const customParams = {
base: ['base', 'from'],
quote: ['quote', 'to'],
quantity: false,
}

export const execute: ExecuteWithConfig<Config> = async (request, config) => {
const validator = new Validator(request, customParams)
if (validator.error) throw validator.error

const jobRunID = validator.validated.id
const url = `/convert`
const from = validator.validated.data.base.toUpperCase()
const to = validator.validated.data.quote.toUpperCase()
const quantity = validator.validated.data.quantity || 1

const params = {
...config.api.params,
from,
to,
quantity,
}

const options = {
...config.api,
url,
params,
}

const response = await Requester.request(options)
const result = Requester.validateResultNumber(response.data, ['value'])

return Requester.success(jobRunID, {
data: config.verbose ? { ...response.data, result } : { result },
result,
status: 200,
})
}
7 changes: 7 additions & 0 deletions 1forge/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expose, util } from '@chainlink/ea-bootstrap'
import { makeExecute } from './adapter'
import { makeConfig } from './config'

const NAME = '1FORGE'

export = { NAME, makeExecute, makeConfig, ...expose(util.wrapExecute(makeExecute())) }
46 changes: 26 additions & 20 deletions 1forge/test/adapter_test.js → 1forge/test/adapter.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const { assert } = require('chai')
const { assertSuccess, assertError } = require('@chainlink/adapter-test-helpers')
const { execute } = require('../adapter')
import { assert } from 'chai'
import { Requester } from '@chainlink/external-adapter'
import { assertSuccess, assertError } from '@chainlink/adapter-test-helpers'
import { makeExecute } from '../src/adapter'
import { AdapterRequest } from '@chainlink/types'

describe('execute', () => {
const jobID = '1'
const execute = makeExecute()
process.env.API_KEY = process.env.API_KEY ?? 'test_api_key'

context('successful calls @integration', () => {
const requests = [
Expand All @@ -22,13 +26,11 @@ describe('execute', () => {
]

requests.forEach((req) => {
it(`${req.name}`, (done) => {
execute(req.testData, (statusCode, data) => {
assertSuccess({ expected: 200, actual: statusCode }, data, jobID)
assert.isAbove(Number(data.result), 0)
assert.isAbove(Number(data.data.result), 0)
done()
})
it(`${req.name}`, async () => {
const data = await execute(req.testData as AdapterRequest)
assertSuccess({ expected: 200, actual: data.statusCode }, data, jobID)
assert.isAbove(data.result, 0)
assert.isAbove(data.data.result, 0)
})
})
})
Expand All @@ -48,11 +50,13 @@ describe('execute', () => {
]

requests.forEach((req) => {
it(`${req.name}`, (done) => {
execute(req.testData, (statusCode, data) => {
assertError({ expected: 400, actual: statusCode }, data, jobID)
done()
})
it(`${req.name}`, async () => {
try {
await execute(req.testData as AdapterRequest)
} catch (error) {
const errorResp = Requester.errored(jobID, error)
assertError({ expected: 400, actual: errorResp.statusCode }, errorResp, jobID)
}
})
})
})
Expand All @@ -70,11 +74,13 @@ describe('execute', () => {
]

requests.forEach((req) => {
it(`${req.name}`, (done) => {
execute(req.testData, (statusCode, data) => {
assertError({ expected: 500, actual: statusCode }, data, jobID)
done()
})
it(`${req.name}`, async () => {
try {
await execute(req.testData as AdapterRequest)
} catch (error) {
const errorResp = Requester.errored(jobID, error)
assertError({ expected: 500, actual: errorResp.statusCode }, errorResp, jobID)
}
})
})
})
Expand Down
10 changes: 10 additions & 0 deletions 1forge/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"typeRoots": ["../node_modules/@types", "../typings", "./typings"]
},
"include": ["src/**/*"],
"exclude": ["dist", "**/*.spec.ts", "**/*.test.ts"]
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- `polygon`
- `nomics`
- `openexchangerates`
- `coinmarketcap`

### Removed

Expand Down
1 change: 0 additions & 1 deletion alphavantage-sdr/.eslintrc.js

This file was deleted.

Loading

0 comments on commit 5ec72c2

Please sign in to comment.