@chainlink/external-adapter-framework 0.0.16 → 0.0.18

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.
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.batchEndpoint = void 0;
4
+ const adapter_1 = require("../../adapter");
5
+ const batch_warming_1 = require("../../transports/batch-warming");
6
+ const DEFAULT_URL = 'https://pro-api.coingecko.com/api/v3';
7
+ const inputParameters = {
8
+ coinid: {
9
+ description: 'The CoinGecko id or array of ids of the coin(s) to query (Note: because of current limitations to use a dummy base will need to be supplied)',
10
+ required: false,
11
+ },
12
+ base: {
13
+ aliases: ['from', 'coin'],
14
+ description: 'The symbol or array of symbols of the currency to query',
15
+ required: true,
16
+ },
17
+ quote: {
18
+ aliases: ['to', 'market'],
19
+ description: 'The symbol of the currency to convert to',
20
+ required: true,
21
+ },
22
+ };
23
+ const batchEndpointTransport = new batch_warming_1.BatchWarmingTransport({
24
+ prepareRequest: (params, context) => {
25
+ return {
26
+ baseURL: DEFAULT_URL,
27
+ url: '/simple/price',
28
+ method: 'GET',
29
+ params: {
30
+ ids: [...new Set(params.map((p) => p.base))].join(','),
31
+ vs_currencies: [...new Set(params.map((p) => p.quote))].join(','),
32
+ x_cg_pro_api_key: context.adapterConfig.API_KEY,
33
+ },
34
+ };
35
+ },
36
+ parseResponse: (res) => {
37
+ const entries = [];
38
+ for (const [base, entry] of Object.entries(res.data)) {
39
+ for (const [quote, price] of Object.entries(entry)) {
40
+ entries.push({
41
+ params: { base, quote },
42
+ value: price,
43
+ });
44
+ }
45
+ }
46
+ return entries;
47
+ },
48
+ });
49
+ exports.batchEndpoint = new adapter_1.AdapterEndpoint({
50
+ name: 'batch',
51
+ transport: batchEndpointTransport,
52
+ inputParameters,
53
+ });
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adapter = void 0;
4
+ const adapter_1 = require("../../adapter");
5
+ const batch_warming_1 = require("./batch-warming");
6
+ const rest_1 = require("./rest");
7
+ exports.adapter = new adapter_1.Adapter({
8
+ name: 'coingecko',
9
+ defaultEndpoint: 'batch',
10
+ endpoints: [rest_1.restEndpoint, batch_warming_1.batchEndpoint],
11
+ });
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.restEndpoint = void 0;
4
+ const adapter_1 = require("../../adapter");
5
+ const transports_1 = require("../../transports");
6
+ const DEFAULT_URL = 'https://api.coingecko.com/api/v3';
7
+ const inputParameters = {
8
+ coinid: {
9
+ description: 'The CoinGecko id or array of ids of the coin(s) to query (Note: because of current limitations to use a dummy base will need to be supplied)',
10
+ required: false,
11
+ },
12
+ base: {
13
+ aliases: ['from', 'coin'],
14
+ description: 'The symbol or array of symbols of the currency to query',
15
+ required: true,
16
+ },
17
+ quote: {
18
+ aliases: ['to', 'market'],
19
+ description: 'The symbol of the currency to convert to',
20
+ required: true,
21
+ },
22
+ };
23
+ const restEndpointTransport = new transports_1.RestTransport({
24
+ prepareRequest: (req) => {
25
+ return {
26
+ baseURL: DEFAULT_URL,
27
+ url: '/simple/price',
28
+ method: 'GET',
29
+ params: {
30
+ ids: req.requestContext.data.base,
31
+ vs_currencies: req.requestContext.data.quote,
32
+ },
33
+ };
34
+ },
35
+ parseResponse: (req, res) => {
36
+ return {
37
+ data: res.data,
38
+ statusCode: 200,
39
+ result: res.data[req.requestContext.data.base]?.[req.requestContext.data.quote],
40
+ };
41
+ },
42
+ options: {
43
+ coalescing: true,
44
+ },
45
+ });
46
+ exports.restEndpoint = new adapter_1.AdapterEndpoint({
47
+ name: 'rest',
48
+ aliases: ['qwe'],
49
+ transport: restEndpointTransport,
50
+ inputParameters,
51
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainlink/external-adapter-framework",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {