@shapeshiftoss/swapper 15.0.2 → 15.0.3

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.
@@ -5,11 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.cowService = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const utils_1 = require("../../../utils");
9
+ const maxAge = 5 * 1000; // 5 seconds
10
+ const cachedUrls = ['/mainnet/api/v1/quote'];
11
+ const cache = (0, utils_1.createCache)(maxAge, cachedUrls);
8
12
  const axiosConfig = {
9
13
  timeout: 10000,
10
14
  headers: {
11
15
  Accept: 'application/json',
12
16
  'Content-Type': 'application/json',
13
17
  },
18
+ adapter: cache.adapter,
14
19
  };
15
20
  exports.cowService = axios_1.default.create(axiosConfig);
@@ -5,11 +5,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.thorService = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const utils_1 = require("../../../utils");
9
+ // Important: maxAge should be small because inbound address info must be recent
10
+ const maxAge = 5 * 1000; // 5 seconds
11
+ const cachedUrls = [
12
+ '/lcd/thorchain/pools',
13
+ '/lcd/thorchain/inbound_addresses',
14
+ '/lcd/thorchain/pool/',
15
+ ];
16
+ const cache = (0, utils_1.createCache)(maxAge, cachedUrls);
8
17
  const axiosConfig = {
9
18
  timeout: 10000,
10
19
  headers: {
11
20
  Accept: 'application/json',
12
21
  'Content-Type': 'application/json',
13
22
  },
23
+ adapter: cache.adapter,
14
24
  };
15
25
  exports.thorService = axios_1.default.create(axiosConfig);
@@ -5,12 +5,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.zrxServiceFactory = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const utils_1 = require("../../../utils");
9
+ const maxAge = 5 * 1000; // 5 seconds
10
+ const cachedUrls = ['/swap/v1/price'];
11
+ const cache = (0, utils_1.createCache)(maxAge, cachedUrls);
8
12
  const axiosConfig = {
9
13
  timeout: 10000,
10
14
  headers: {
11
15
  Accept: 'application/json',
12
16
  'Content-Type': 'application/json',
13
17
  },
18
+ adapter: cache.adapter,
14
19
  };
15
20
  const zrxServiceFactory = (baseUrl) => axios_1.default.create({ ...axiosConfig, baseURL: baseUrl });
16
21
  exports.zrxServiceFactory = zrxServiceFactory;
package/dist/utils.d.ts CHANGED
@@ -1 +1,3 @@
1
+ import { ISetupCache } from 'axios-cache-adapter';
1
2
  export declare function assertIsDefined<T>(val: T): asserts val is NonNullable<T>;
3
+ export declare const createCache: (maxAge: number, cachedUrls: string[]) => ISetupCache;
package/dist/utils.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertIsDefined = void 0;
3
+ exports.createCache = exports.assertIsDefined = void 0;
4
4
  const assert_1 = require("assert");
5
+ const axios_cache_adapter_1 = require("axios-cache-adapter");
5
6
  // asserts x is type doesn't work when using arrow functions
6
7
  function assertIsDefined(val) {
7
8
  if (val === undefined || val === null) {
@@ -9,3 +10,15 @@ function assertIsDefined(val) {
9
10
  }
10
11
  }
11
12
  exports.assertIsDefined = assertIsDefined;
13
+ const getRequestFilter = (cachedUrls) => (request) => !cachedUrls.some((url) => request.url.includes(url));
14
+ const createCache = (maxAge, cachedUrls) => {
15
+ const filter = getRequestFilter(cachedUrls);
16
+ return (0, axios_cache_adapter_1.setupCache)({
17
+ maxAge,
18
+ exclude: { filter, query: false },
19
+ clearOnStale: true,
20
+ readOnError: false,
21
+ readHeaders: false,
22
+ });
23
+ };
24
+ exports.createCache = createCache;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "15.0.2",
3
+ "version": "15.0.3",
4
4
  "description": "An interface and implementations to trade coins via various protocols",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "axios": "^0.26.1",
27
+ "axios-cache-adapter": "^2.7.3",
27
28
  "bignumber.js": "^9.0.2",
28
29
  "lodash": "^4.17.21",
29
30
  "retry-axios": "^2.6.0",
@@ -44,9 +45,9 @@
44
45
  "@shapeshiftoss/errors": "^1.1.2",
45
46
  "@shapeshiftoss/hdwallet-core": "^1.41.0",
46
47
  "@shapeshiftoss/types": "^8.1.0",
48
+ "@shapeshiftoss/unchained-client": "^10.0.1",
47
49
  "@types/readline-sync": "^1.4.4",
48
50
  "readline-sync": "^1.4.10",
49
- "web3-utils": "1.7.4",
50
- "@shapeshiftoss/unchained-client": "^10.0.1"
51
+ "web3-utils": "1.7.4"
51
52
  }
52
53
  }