-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into release/v0.2.0-rc.1
- Loading branch information
Showing
143 changed files
with
2,694 additions
and
1,533 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
module.exports = require('../.eslintrc.js') | ||
module.exports = { | ||
...require('../.eslintrc.ts.js'), | ||
} |
This file contains 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 |
---|---|---|
@@ -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 | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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,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()) | ||
} |
This file contains 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,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 | ||
} |
This file contains 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 * as price from './price' |
This file contains 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,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, | ||
}) | ||
} |
This file contains 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,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())) } |
This file contains 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
This file contains 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,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"typeRoots": ["../node_modules/@types", "../typings", "./typings"] | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["dist", "**/*.spec.ts", "**/*.test.ts"] | ||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.