@xchainjs/xchain-aggregator 2.0.35 → 2.2.0

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.
Files changed (3) hide show
  1. package/lib/index.esm.js +360 -68
  2. package/lib/index.js +360 -68
  3. package/package.json +6 -6
package/lib/index.esm.js CHANGED
@@ -65,6 +65,15 @@ const xAssetToCAsset = (asset) => {
65
65
  return asset.ticker;
66
66
  };
67
67
 
68
+ const networkToChainflip = (network) => {
69
+ switch (network) {
70
+ case Network.Stagenet:
71
+ return 'perseverance';
72
+ case Network.Mainnet:
73
+ default:
74
+ return 'mainnet';
75
+ }
76
+ };
68
77
  /**
69
78
  * Chainflip protocol
70
79
  */
@@ -72,7 +81,7 @@ class ChainflipProtocol {
72
81
  constructor(configuration) {
73
82
  this.name = 'Chainflip';
74
83
  this.sdk = new SwapSDK({
75
- network: 'mainnet',
84
+ network: networkToChainflip(configuration === null || configuration === void 0 ? void 0 : configuration.network),
76
85
  enabledFeatures: {
77
86
  dca: true,
78
87
  },
@@ -155,25 +164,7 @@ class ChainflipProtocol {
155
164
  // User wants regular quotes - prioritize DCA > REGULAR (ignore boost quotes)
156
165
  selectedQuote = quotes.find((quote) => quote.type === 'DCA') || quotes.find((quote) => quote.type === 'REGULAR');
157
166
  }
158
- if (params.destinationAddress && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.type) === 'DCA' && params.fromAddress) {
159
- // Use boost quote only if user enabled boost and it's available
160
- const quoteToUse = params.enableBoost && selectedQuote.boostQuote ? selectedQuote.boostQuote : selectedQuote;
161
- const resp = yield this.sdk.requestDepositAddressV2({
162
- quote: quoteToUse,
163
- destAddress: params.destinationAddress,
164
- srcAddress: params.fromAddress,
165
- fillOrKillParams: {
166
- slippageTolerancePercent: selectedQuote.recommendedSlippageTolerancePercent,
167
- refundAddress: params.fromAddress,
168
- retryDurationBlocks: 100,
169
- },
170
- affiliateBrokers: this.affiliateBrokers,
171
- });
172
- toAddress = resp.depositAddress;
173
- depositChannelId = resp.depositChannelId;
174
- }
175
- else if (params.destinationAddress && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.type) === 'REGULAR' && params.fromAddress) {
176
- // Use boost quote only if user enabled boost and it's available
167
+ if (params.destinationAddress && selectedQuote && params.fromAddress) {
177
168
  const quoteToUse = params.enableBoost && selectedQuote.boostQuote ? selectedQuote.boostQuote : selectedQuote;
178
169
  const resp = yield this.sdk.requestDepositAddressV2({
179
170
  quote: quoteToUse,
@@ -6081,36 +6072,36 @@ function requireIsRetryAllowed () {
6081
6072
  var isRetryAllowedExports = requireIsRetryAllowed();
6082
6073
  var isRetryAllowed = /*@__PURE__*/getDefaultExportFromCjs(isRetryAllowedExports);
6083
6074
 
6084
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6075
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6085
6076
 
6086
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6077
+ function _asyncToGenerator$1(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6087
6078
 
6088
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6079
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6089
6080
 
6090
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6081
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6091
6082
 
6092
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6093
- var namespace = 'axios-retry';
6083
+ function _defineProperty$1(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6084
+ var namespace$1 = 'axios-retry';
6094
6085
  /**
6095
6086
  * @param {Error} error
6096
6087
  * @return {boolean}
6097
6088
  */
6098
6089
 
6099
- function isNetworkError(error) {
6090
+ function isNetworkError$1(error) {
6100
6091
  var CODE_EXCLUDE_LIST = ['ERR_CANCELED', 'ECONNABORTED'];
6101
6092
  return !error.response && Boolean(error.code) && // Prevents retrying cancelled requests
6102
6093
  !CODE_EXCLUDE_LIST.includes(error.code) && // Prevents retrying timed out & cancelled requests
6103
6094
  isRetryAllowed(error) // Prevents retrying unsafe errors
6104
6095
  ;
6105
6096
  }
6106
- var SAFE_HTTP_METHODS = ['get', 'head', 'options'];
6107
- var IDEMPOTENT_HTTP_METHODS = SAFE_HTTP_METHODS.concat(['put', 'delete']);
6097
+ var SAFE_HTTP_METHODS$1 = ['get', 'head', 'options'];
6098
+ var IDEMPOTENT_HTTP_METHODS$1 = SAFE_HTTP_METHODS$1.concat(['put', 'delete']);
6108
6099
  /**
6109
6100
  * @param {Error} error
6110
6101
  * @return {boolean}
6111
6102
  */
6112
6103
 
6113
- function isRetryableError(error) {
6104
+ function isRetryableError$1(error) {
6114
6105
  return error.code !== 'ECONNABORTED' && (!error.response || error.response.status >= 500 && error.response.status <= 599);
6115
6106
  }
6116
6107
  /**
@@ -6118,40 +6109,40 @@ function isRetryableError(error) {
6118
6109
  * @return {boolean}
6119
6110
  */
6120
6111
 
6121
- function isSafeRequestError(error) {
6112
+ function isSafeRequestError$1(error) {
6122
6113
  if (!error.config) {
6123
6114
  // Cannot determine if the request can be retried
6124
6115
  return false;
6125
6116
  }
6126
6117
 
6127
- return isRetryableError(error) && SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
6118
+ return isRetryableError$1(error) && SAFE_HTTP_METHODS$1.indexOf(error.config.method) !== -1;
6128
6119
  }
6129
6120
  /**
6130
6121
  * @param {Error} error
6131
6122
  * @return {boolean}
6132
6123
  */
6133
6124
 
6134
- function isIdempotentRequestError(error) {
6125
+ function isIdempotentRequestError$1(error) {
6135
6126
  if (!error.config) {
6136
6127
  // Cannot determine if the request can be retried
6137
6128
  return false;
6138
6129
  }
6139
6130
 
6140
- return isRetryableError(error) && IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
6131
+ return isRetryableError$1(error) && IDEMPOTENT_HTTP_METHODS$1.indexOf(error.config.method) !== -1;
6141
6132
  }
6142
6133
  /**
6143
6134
  * @param {Error} error
6144
6135
  * @return {boolean}
6145
6136
  */
6146
6137
 
6147
- function isNetworkOrIdempotentRequestError(error) {
6148
- return isNetworkError(error) || isIdempotentRequestError(error);
6138
+ function isNetworkOrIdempotentRequestError$1(error) {
6139
+ return isNetworkError$1(error) || isIdempotentRequestError$1(error);
6149
6140
  }
6150
6141
  /**
6151
6142
  * @return {number} - delay in milliseconds, always 0
6152
6143
  */
6153
6144
 
6154
- function noDelay() {
6145
+ function noDelay$1() {
6155
6146
  return 0;
6156
6147
  }
6157
6148
  /**
@@ -6164,7 +6155,7 @@ function noDelay() {
6164
6155
  */
6165
6156
 
6166
6157
 
6167
- function exponentialDelay() {
6158
+ function exponentialDelay$1() {
6168
6159
  var retryNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
6169
6160
  var delayFactor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;
6170
6161
  var delay = Math.pow(2, retryNumber) * delayFactor;
@@ -6174,10 +6165,10 @@ function exponentialDelay() {
6174
6165
  }
6175
6166
  /** @type {IAxiosRetryConfig} */
6176
6167
 
6177
- var DEFAULT_OPTIONS = {
6168
+ var DEFAULT_OPTIONS$1 = {
6178
6169
  retries: 3,
6179
- retryCondition: isNetworkOrIdempotentRequestError,
6180
- retryDelay: noDelay,
6170
+ retryCondition: isNetworkOrIdempotentRequestError$1,
6171
+ retryDelay: noDelay$1,
6181
6172
  shouldResetTimeout: false,
6182
6173
  onRetry: () => {}
6183
6174
  };
@@ -6188,8 +6179,8 @@ var DEFAULT_OPTIONS = {
6188
6179
  * @return {IAxiosRetryConfigExtended}
6189
6180
  */
6190
6181
 
6191
- function getRequestOptions(config, defaultOptions) {
6192
- return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), defaultOptions), config[namespace]);
6182
+ function getRequestOptions$1(config, defaultOptions) {
6183
+ return _objectSpread$1(_objectSpread$1(_objectSpread$1({}, DEFAULT_OPTIONS$1), defaultOptions), config[namespace$1]);
6193
6184
  }
6194
6185
  /**
6195
6186
  * Initializes and returns the retry state for the given request/config
@@ -6199,10 +6190,10 @@ function getRequestOptions(config, defaultOptions) {
6199
6190
  */
6200
6191
 
6201
6192
 
6202
- function getCurrentState(config, defaultOptions) {
6203
- var currentState = getRequestOptions(config, defaultOptions);
6193
+ function getCurrentState$1(config, defaultOptions) {
6194
+ var currentState = getRequestOptions$1(config, defaultOptions);
6204
6195
  currentState.retryCount = currentState.retryCount || 0;
6205
- config[namespace] = currentState;
6196
+ config[namespace$1] = currentState;
6206
6197
  return currentState;
6207
6198
  }
6208
6199
  /**
@@ -6211,7 +6202,7 @@ function getCurrentState(config, defaultOptions) {
6211
6202
  */
6212
6203
 
6213
6204
 
6214
- function fixConfig(axios, config) {
6205
+ function fixConfig$1(axios, config) {
6215
6206
  if (axios.defaults.agent === config.agent) {
6216
6207
  delete config.agent;
6217
6208
  }
@@ -6232,8 +6223,8 @@ function fixConfig(axios, config) {
6232
6223
  */
6233
6224
 
6234
6225
 
6235
- function shouldRetry(_x, _x2) {
6236
- return _shouldRetry.apply(this, arguments);
6226
+ function shouldRetry$1(_x, _x2) {
6227
+ return _shouldRetry$1.apply(this, arguments);
6237
6228
  }
6238
6229
  /**
6239
6230
  * Adds response interceptors to an axios instance to retry requests failed due to network issues
@@ -6293,8 +6284,8 @@ function shouldRetry(_x, _x2) {
6293
6284
  */
6294
6285
 
6295
6286
 
6296
- function _shouldRetry() {
6297
- _shouldRetry = _asyncToGenerator(function* (currentState, error) {
6287
+ function _shouldRetry$1() {
6288
+ _shouldRetry$1 = _asyncToGenerator$1(function* (currentState, error) {
6298
6289
  var {
6299
6290
  retries,
6300
6291
  retryCondition
@@ -6313,17 +6304,17 @@ function _shouldRetry() {
6313
6304
 
6314
6305
  return shouldRetryOrPromise;
6315
6306
  });
6316
- return _shouldRetry.apply(this, arguments);
6307
+ return _shouldRetry$1.apply(this, arguments);
6317
6308
  }
6318
6309
 
6319
- function axiosRetry(axios, defaultOptions) {
6310
+ function axiosRetry$1(axios, defaultOptions) {
6320
6311
  var requestInterceptorId = axios.interceptors.request.use(config => {
6321
- var currentState = getCurrentState(config, defaultOptions);
6312
+ var currentState = getCurrentState$1(config, defaultOptions);
6322
6313
  currentState.lastRequestTime = Date.now();
6323
6314
  return config;
6324
6315
  });
6325
6316
  var responseInterceptorId = axios.interceptors.response.use(null, /*#__PURE__*/function () {
6326
- var _ref = _asyncToGenerator(function* (error) {
6317
+ var _ref = _asyncToGenerator$1(function* (error) {
6327
6318
  var {
6328
6319
  config
6329
6320
  } = error; // If we have no information to retry the request
@@ -6332,9 +6323,9 @@ function axiosRetry(axios, defaultOptions) {
6332
6323
  return Promise.reject(error);
6333
6324
  }
6334
6325
 
6335
- var currentState = getCurrentState(config, defaultOptions);
6326
+ var currentState = getCurrentState$1(config, defaultOptions);
6336
6327
 
6337
- if (yield shouldRetry(currentState, error)) {
6328
+ if (yield shouldRetry$1(currentState, error)) {
6338
6329
  currentState.retryCount += 1;
6339
6330
  var {
6340
6331
  retryDelay,
@@ -6344,7 +6335,7 @@ function axiosRetry(axios, defaultOptions) {
6344
6335
  var delay = retryDelay(currentState.retryCount, error); // Axios fails merging this configuration to the default configuration because it has an issue
6345
6336
  // with circular structures: https://github.com/mzabriskie/axios/issues/370
6346
6337
 
6347
- fixConfig(axios, config);
6338
+ fixConfig$1(axios, config);
6348
6339
 
6349
6340
  if (!shouldResetTimeout && config.timeout && currentState.lastRequestTime) {
6350
6341
  var lastRequestDuration = Date.now() - currentState.lastRequestTime;
@@ -6375,12 +6366,12 @@ function axiosRetry(axios, defaultOptions) {
6375
6366
  };
6376
6367
  } // Compatibility with CommonJS
6377
6368
 
6378
- axiosRetry.isNetworkError = isNetworkError;
6379
- axiosRetry.isSafeRequestError = isSafeRequestError;
6380
- axiosRetry.isIdempotentRequestError = isIdempotentRequestError;
6381
- axiosRetry.isNetworkOrIdempotentRequestError = isNetworkOrIdempotentRequestError;
6382
- axiosRetry.exponentialDelay = exponentialDelay;
6383
- axiosRetry.isRetryableError = isRetryableError;
6369
+ axiosRetry$1.isNetworkError = isNetworkError$1;
6370
+ axiosRetry$1.isSafeRequestError = isSafeRequestError$1;
6371
+ axiosRetry$1.isIdempotentRequestError = isIdempotentRequestError$1;
6372
+ axiosRetry$1.isNetworkOrIdempotentRequestError = isNetworkOrIdempotentRequestError$1;
6373
+ axiosRetry$1.exponentialDelay = exponentialDelay$1;
6374
+ axiosRetry$1.isRetryableError = isRetryableError$1;
6384
6375
 
6385
6376
  /******************************************************************************
6386
6377
  Copyright (c) Microsoft Corporation.
@@ -6444,7 +6435,7 @@ let MidgardApi$1 = class MidgardApi {
6444
6435
  constructor(network = Network.Mainnet, config) {
6445
6436
  this.network = network;
6446
6437
  this.config = config !== null && config !== void 0 ? config : defaultMidgardConfig$1[this.network];
6447
- axiosRetry(axios, { retries: this.config.apiRetries, retryDelay: axiosRetry.exponentialDelay });
6438
+ axiosRetry$1(axios, { retries: this.config.apiRetries, retryDelay: axiosRetry$1.exponentialDelay });
6448
6439
  this.midgardClients = this.config.midgardBaseUrls.map((url) => new MidgardApi$2(new Configuration$1({ basePath: url })));
6449
6440
  }
6450
6441
  /**
@@ -6861,7 +6852,7 @@ class MayachainProtocol {
6861
6852
  expectedAmount: estimatedSwap.expectedAmount,
6862
6853
  dustThreshold: estimatedSwap.dustThreshold,
6863
6854
  fees: estimatedSwap.fees,
6864
- totalSwapSeconds: estimatedSwap.inboundConfirmationSeconds || 0 + estimatedSwap.outboundDelaySeconds,
6855
+ totalSwapSeconds: (estimatedSwap.inboundConfirmationSeconds || 0) + estimatedSwap.outboundDelaySeconds,
6865
6856
  slipBasisPoints: estimatedSwap.slipBasisPoints,
6866
6857
  maxStreamingQuantity: estimatedSwap.maxStreamingQuantity,
6867
6858
  canSwap: estimatedSwap.canSwap,
@@ -8871,6 +8862,307 @@ class MidgardApi extends DefaultApi {
8871
8862
  }
8872
8863
  }
8873
8864
 
8865
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8866
+
8867
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
8868
+
8869
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
8870
+
8871
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8872
+
8873
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8874
+ var namespace = 'axios-retry';
8875
+ /**
8876
+ * @param {Error} error
8877
+ * @return {boolean}
8878
+ */
8879
+
8880
+ function isNetworkError(error) {
8881
+ var CODE_EXCLUDE_LIST = ['ERR_CANCELED', 'ECONNABORTED'];
8882
+ return !error.response && Boolean(error.code) && // Prevents retrying cancelled requests
8883
+ !CODE_EXCLUDE_LIST.includes(error.code) && // Prevents retrying timed out & cancelled requests
8884
+ isRetryAllowed(error) // Prevents retrying unsafe errors
8885
+ ;
8886
+ }
8887
+ var SAFE_HTTP_METHODS = ['get', 'head', 'options'];
8888
+ var IDEMPOTENT_HTTP_METHODS = SAFE_HTTP_METHODS.concat(['put', 'delete']);
8889
+ /**
8890
+ * @param {Error} error
8891
+ * @return {boolean}
8892
+ */
8893
+
8894
+ function isRetryableError(error) {
8895
+ return error.code !== 'ECONNABORTED' && (!error.response || error.response.status >= 500 && error.response.status <= 599);
8896
+ }
8897
+ /**
8898
+ * @param {Error} error
8899
+ * @return {boolean}
8900
+ */
8901
+
8902
+ function isSafeRequestError(error) {
8903
+ if (!error.config) {
8904
+ // Cannot determine if the request can be retried
8905
+ return false;
8906
+ }
8907
+
8908
+ return isRetryableError(error) && SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
8909
+ }
8910
+ /**
8911
+ * @param {Error} error
8912
+ * @return {boolean}
8913
+ */
8914
+
8915
+ function isIdempotentRequestError(error) {
8916
+ if (!error.config) {
8917
+ // Cannot determine if the request can be retried
8918
+ return false;
8919
+ }
8920
+
8921
+ return isRetryableError(error) && IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
8922
+ }
8923
+ /**
8924
+ * @param {Error} error
8925
+ * @return {boolean}
8926
+ */
8927
+
8928
+ function isNetworkOrIdempotentRequestError(error) {
8929
+ return isNetworkError(error) || isIdempotentRequestError(error);
8930
+ }
8931
+ /**
8932
+ * @return {number} - delay in milliseconds, always 0
8933
+ */
8934
+
8935
+ function noDelay() {
8936
+ return 0;
8937
+ }
8938
+ /**
8939
+ * Set delayFactor 1000 for an exponential delay to occur on the order
8940
+ * of seconds
8941
+ * @param {number} [retryNumber=0]
8942
+ * @param {Error} error - unused; for existing API of retryDelay callback
8943
+ * @param {number} [delayFactor=100] milliseconds
8944
+ * @return {number} - delay in milliseconds
8945
+ */
8946
+
8947
+
8948
+ function exponentialDelay() {
8949
+ var retryNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
8950
+ var delayFactor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;
8951
+ var delay = Math.pow(2, retryNumber) * delayFactor;
8952
+ var randomSum = delay * 0.2 * Math.random(); // 0-20% of the delay
8953
+
8954
+ return delay + randomSum;
8955
+ }
8956
+ /** @type {IAxiosRetryConfig} */
8957
+
8958
+ var DEFAULT_OPTIONS = {
8959
+ retries: 3,
8960
+ retryCondition: isNetworkOrIdempotentRequestError,
8961
+ retryDelay: noDelay,
8962
+ shouldResetTimeout: false,
8963
+ onRetry: () => {}
8964
+ };
8965
+ /**
8966
+ * Returns the axios-retry options for the current request
8967
+ * @param {AxiosRequestConfig} config
8968
+ * @param {IAxiosRetryConfig} defaultOptions
8969
+ * @return {IAxiosRetryConfigExtended}
8970
+ */
8971
+
8972
+ function getRequestOptions(config, defaultOptions) {
8973
+ return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), defaultOptions), config[namespace]);
8974
+ }
8975
+ /**
8976
+ * Initializes and returns the retry state for the given request/config
8977
+ * @param {AxiosRequestConfig} config
8978
+ * @param {IAxiosRetryConfig} defaultOptions
8979
+ * @return {IAxiosRetryConfigExtended}
8980
+ */
8981
+
8982
+
8983
+ function getCurrentState(config, defaultOptions) {
8984
+ var currentState = getRequestOptions(config, defaultOptions);
8985
+ currentState.retryCount = currentState.retryCount || 0;
8986
+ config[namespace] = currentState;
8987
+ return currentState;
8988
+ }
8989
+ /**
8990
+ * @param {Axios} axios
8991
+ * @param {AxiosRequestConfig} config
8992
+ */
8993
+
8994
+
8995
+ function fixConfig(axios, config) {
8996
+ if (axios.defaults.agent === config.agent) {
8997
+ delete config.agent;
8998
+ }
8999
+
9000
+ if (axios.defaults.httpAgent === config.httpAgent) {
9001
+ delete config.httpAgent;
9002
+ }
9003
+
9004
+ if (axios.defaults.httpsAgent === config.httpsAgent) {
9005
+ delete config.httpsAgent;
9006
+ }
9007
+ }
9008
+ /**
9009
+ * Checks retryCondition if request can be retried. Handles it's returning value or Promise.
9010
+ * @param {IAxiosRetryConfigExtended} currentState
9011
+ * @param {Error} error
9012
+ * @return {Promise<boolean>}
9013
+ */
9014
+
9015
+
9016
+ function shouldRetry(_x, _x2) {
9017
+ return _shouldRetry.apply(this, arguments);
9018
+ }
9019
+ /**
9020
+ * Adds response interceptors to an axios instance to retry requests failed due to network issues
9021
+ *
9022
+ * @example
9023
+ *
9024
+ * import axios from 'axios';
9025
+ *
9026
+ * axiosRetry(axios, { retries: 3 });
9027
+ *
9028
+ * axios.get('http://example.com/test') // The first request fails and the second returns 'ok'
9029
+ * .then(result => {
9030
+ * result.data; // 'ok'
9031
+ * });
9032
+ *
9033
+ * // Exponential back-off retry delay between requests
9034
+ * axiosRetry(axios, { retryDelay : axiosRetry.exponentialDelay});
9035
+ *
9036
+ * // Custom retry delay
9037
+ * axiosRetry(axios, { retryDelay : (retryCount) => {
9038
+ * return retryCount * 1000;
9039
+ * }});
9040
+ *
9041
+ * // Also works with custom axios instances
9042
+ * const client = axios.create({ baseURL: 'http://example.com' });
9043
+ * axiosRetry(client, { retries: 3 });
9044
+ *
9045
+ * client.get('/test') // The first request fails and the second returns 'ok'
9046
+ * .then(result => {
9047
+ * result.data; // 'ok'
9048
+ * });
9049
+ *
9050
+ * // Allows request-specific configuration
9051
+ * client
9052
+ * .get('/test', {
9053
+ * 'axios-retry': {
9054
+ * retries: 0
9055
+ * }
9056
+ * })
9057
+ * .catch(error => { // The first request fails
9058
+ * error !== undefined
9059
+ * });
9060
+ *
9061
+ * @param {Axios} axios An axios instance (the axios object or one created from axios.create)
9062
+ * @param {Object} [defaultOptions]
9063
+ * @param {number} [defaultOptions.retries=3] Number of retries
9064
+ * @param {boolean} [defaultOptions.shouldResetTimeout=false]
9065
+ * Defines if the timeout should be reset between retries
9066
+ * @param {Function} [defaultOptions.retryCondition=isNetworkOrIdempotentRequestError]
9067
+ * A function to determine if the error can be retried
9068
+ * @param {Function} [defaultOptions.retryDelay=noDelay]
9069
+ * A function to determine the delay between retry requests
9070
+ * @param {Function} [defaultOptions.onRetry=()=>{}]
9071
+ * A function to get notified when a retry occurs
9072
+ * @return {{ requestInterceptorId: number, responseInterceptorId: number }}
9073
+ * The ids of the interceptors added to the request and to the response (so they can be ejected at a later time)
9074
+ */
9075
+
9076
+
9077
+ function _shouldRetry() {
9078
+ _shouldRetry = _asyncToGenerator(function* (currentState, error) {
9079
+ var {
9080
+ retries,
9081
+ retryCondition
9082
+ } = currentState;
9083
+ var shouldRetryOrPromise = currentState.retryCount < retries && retryCondition(error); // This could be a promise
9084
+
9085
+ if (typeof shouldRetryOrPromise === 'object') {
9086
+ try {
9087
+ var shouldRetryPromiseResult = yield shouldRetryOrPromise; // keep return true unless shouldRetryPromiseResult return false for compatibility
9088
+
9089
+ return shouldRetryPromiseResult !== false;
9090
+ } catch (_err) {
9091
+ return false;
9092
+ }
9093
+ }
9094
+
9095
+ return shouldRetryOrPromise;
9096
+ });
9097
+ return _shouldRetry.apply(this, arguments);
9098
+ }
9099
+
9100
+ function axiosRetry(axios, defaultOptions) {
9101
+ var requestInterceptorId = axios.interceptors.request.use(config => {
9102
+ var currentState = getCurrentState(config, defaultOptions);
9103
+ currentState.lastRequestTime = Date.now();
9104
+ return config;
9105
+ });
9106
+ var responseInterceptorId = axios.interceptors.response.use(null, /*#__PURE__*/function () {
9107
+ var _ref = _asyncToGenerator(function* (error) {
9108
+ var {
9109
+ config
9110
+ } = error; // If we have no information to retry the request
9111
+
9112
+ if (!config) {
9113
+ return Promise.reject(error);
9114
+ }
9115
+
9116
+ var currentState = getCurrentState(config, defaultOptions);
9117
+
9118
+ if (yield shouldRetry(currentState, error)) {
9119
+ currentState.retryCount += 1;
9120
+ var {
9121
+ retryDelay,
9122
+ shouldResetTimeout,
9123
+ onRetry
9124
+ } = currentState;
9125
+ var delay = retryDelay(currentState.retryCount, error); // Axios fails merging this configuration to the default configuration because it has an issue
9126
+ // with circular structures: https://github.com/mzabriskie/axios/issues/370
9127
+
9128
+ fixConfig(axios, config);
9129
+
9130
+ if (!shouldResetTimeout && config.timeout && currentState.lastRequestTime) {
9131
+ var lastRequestDuration = Date.now() - currentState.lastRequestTime;
9132
+ var timeout = config.timeout - lastRequestDuration - delay;
9133
+
9134
+ if (timeout <= 0) {
9135
+ return Promise.reject(error);
9136
+ }
9137
+
9138
+ config.timeout = timeout;
9139
+ }
9140
+
9141
+ config.transformRequest = [data => data];
9142
+ yield onRetry(currentState.retryCount, error, config);
9143
+ return new Promise(resolve => setTimeout(() => resolve(axios(config)), delay));
9144
+ }
9145
+
9146
+ return Promise.reject(error);
9147
+ });
9148
+
9149
+ return function (_x3) {
9150
+ return _ref.apply(this, arguments);
9151
+ };
9152
+ }());
9153
+ return {
9154
+ requestInterceptorId,
9155
+ responseInterceptorId
9156
+ };
9157
+ } // Compatibility with CommonJS
9158
+
9159
+ axiosRetry.isNetworkError = isNetworkError;
9160
+ axiosRetry.isSafeRequestError = isSafeRequestError;
9161
+ axiosRetry.isIdempotentRequestError = isIdempotentRequestError;
9162
+ axiosRetry.isNetworkOrIdempotentRequestError = isNetworkOrIdempotentRequestError;
9163
+ axiosRetry.exponentialDelay = exponentialDelay;
9164
+ axiosRetry.isRetryableError = isRetryableError;
9165
+
8874
9166
  /******************************************************************************
8875
9167
  Copyright (c) Microsoft Corporation.
8876
9168
 
@@ -9402,7 +9694,7 @@ class ThorchainProtocol {
9402
9694
  expectedAmount: estimatedSwap.txEstimate.netOutput,
9403
9695
  dustThreshold: estimatedSwap.dustThreshold,
9404
9696
  fees: estimatedSwap.txEstimate.totalFees,
9405
- totalSwapSeconds: estimatedSwap.txEstimate.inboundConfirmationSeconds || 0 + estimatedSwap.txEstimate.outboundDelaySeconds,
9697
+ totalSwapSeconds: (estimatedSwap.txEstimate.inboundConfirmationSeconds || 0) + estimatedSwap.txEstimate.outboundDelaySeconds,
9406
9698
  slipBasisPoints: estimatedSwap.txEstimate.slipBasisPoints,
9407
9699
  maxStreamingQuantity: estimatedSwap.txEstimate.maxStreamingQuantity,
9408
9700
  canSwap: estimatedSwap.txEstimate.canSwap,
@@ -9529,7 +9821,7 @@ class Aggregator {
9529
9821
  successfulQuotes.push(result.value);
9530
9822
  }
9531
9823
  });
9532
- if (!successfulQuotes)
9824
+ if (successfulQuotes.length === 0)
9533
9825
  throw Error(`Can not estimate swap from ${assetToString(params.fromAsset)} to ${assetToString(params.destinationAsset)}`);
9534
9826
  return successfulQuotes;
9535
9827
  });
package/lib/index.js CHANGED
@@ -67,6 +67,15 @@ const xAssetToCAsset = (asset) => {
67
67
  return asset.ticker;
68
68
  };
69
69
 
70
+ const networkToChainflip = (network) => {
71
+ switch (network) {
72
+ case xchainClient.Network.Stagenet:
73
+ return 'perseverance';
74
+ case xchainClient.Network.Mainnet:
75
+ default:
76
+ return 'mainnet';
77
+ }
78
+ };
70
79
  /**
71
80
  * Chainflip protocol
72
81
  */
@@ -74,7 +83,7 @@ class ChainflipProtocol {
74
83
  constructor(configuration) {
75
84
  this.name = 'Chainflip';
76
85
  this.sdk = new swap.SwapSDK({
77
- network: 'mainnet',
86
+ network: networkToChainflip(configuration === null || configuration === void 0 ? void 0 : configuration.network),
78
87
  enabledFeatures: {
79
88
  dca: true,
80
89
  },
@@ -157,25 +166,7 @@ class ChainflipProtocol {
157
166
  // User wants regular quotes - prioritize DCA > REGULAR (ignore boost quotes)
158
167
  selectedQuote = quotes.find((quote) => quote.type === 'DCA') || quotes.find((quote) => quote.type === 'REGULAR');
159
168
  }
160
- if (params.destinationAddress && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.type) === 'DCA' && params.fromAddress) {
161
- // Use boost quote only if user enabled boost and it's available
162
- const quoteToUse = params.enableBoost && selectedQuote.boostQuote ? selectedQuote.boostQuote : selectedQuote;
163
- const resp = yield this.sdk.requestDepositAddressV2({
164
- quote: quoteToUse,
165
- destAddress: params.destinationAddress,
166
- srcAddress: params.fromAddress,
167
- fillOrKillParams: {
168
- slippageTolerancePercent: selectedQuote.recommendedSlippageTolerancePercent,
169
- refundAddress: params.fromAddress,
170
- retryDurationBlocks: 100,
171
- },
172
- affiliateBrokers: this.affiliateBrokers,
173
- });
174
- toAddress = resp.depositAddress;
175
- depositChannelId = resp.depositChannelId;
176
- }
177
- else if (params.destinationAddress && (selectedQuote === null || selectedQuote === void 0 ? void 0 : selectedQuote.type) === 'REGULAR' && params.fromAddress) {
178
- // Use boost quote only if user enabled boost and it's available
169
+ if (params.destinationAddress && selectedQuote && params.fromAddress) {
179
170
  const quoteToUse = params.enableBoost && selectedQuote.boostQuote ? selectedQuote.boostQuote : selectedQuote;
180
171
  const resp = yield this.sdk.requestDepositAddressV2({
181
172
  quote: quoteToUse,
@@ -6083,36 +6074,36 @@ function requireIsRetryAllowed () {
6083
6074
  var isRetryAllowedExports = requireIsRetryAllowed();
6084
6075
  var isRetryAllowed = /*@__PURE__*/getDefaultExportFromCjs(isRetryAllowedExports);
6085
6076
 
6086
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6077
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6087
6078
 
6088
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6079
+ function _asyncToGenerator$1(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6089
6080
 
6090
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6081
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6091
6082
 
6092
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6083
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6093
6084
 
6094
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6095
- var namespace = 'axios-retry';
6085
+ function _defineProperty$1(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6086
+ var namespace$1 = 'axios-retry';
6096
6087
  /**
6097
6088
  * @param {Error} error
6098
6089
  * @return {boolean}
6099
6090
  */
6100
6091
 
6101
- function isNetworkError(error) {
6092
+ function isNetworkError$1(error) {
6102
6093
  var CODE_EXCLUDE_LIST = ['ERR_CANCELED', 'ECONNABORTED'];
6103
6094
  return !error.response && Boolean(error.code) && // Prevents retrying cancelled requests
6104
6095
  !CODE_EXCLUDE_LIST.includes(error.code) && // Prevents retrying timed out & cancelled requests
6105
6096
  isRetryAllowed(error) // Prevents retrying unsafe errors
6106
6097
  ;
6107
6098
  }
6108
- var SAFE_HTTP_METHODS = ['get', 'head', 'options'];
6109
- var IDEMPOTENT_HTTP_METHODS = SAFE_HTTP_METHODS.concat(['put', 'delete']);
6099
+ var SAFE_HTTP_METHODS$1 = ['get', 'head', 'options'];
6100
+ var IDEMPOTENT_HTTP_METHODS$1 = SAFE_HTTP_METHODS$1.concat(['put', 'delete']);
6110
6101
  /**
6111
6102
  * @param {Error} error
6112
6103
  * @return {boolean}
6113
6104
  */
6114
6105
 
6115
- function isRetryableError(error) {
6106
+ function isRetryableError$1(error) {
6116
6107
  return error.code !== 'ECONNABORTED' && (!error.response || error.response.status >= 500 && error.response.status <= 599);
6117
6108
  }
6118
6109
  /**
@@ -6120,40 +6111,40 @@ function isRetryableError(error) {
6120
6111
  * @return {boolean}
6121
6112
  */
6122
6113
 
6123
- function isSafeRequestError(error) {
6114
+ function isSafeRequestError$1(error) {
6124
6115
  if (!error.config) {
6125
6116
  // Cannot determine if the request can be retried
6126
6117
  return false;
6127
6118
  }
6128
6119
 
6129
- return isRetryableError(error) && SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
6120
+ return isRetryableError$1(error) && SAFE_HTTP_METHODS$1.indexOf(error.config.method) !== -1;
6130
6121
  }
6131
6122
  /**
6132
6123
  * @param {Error} error
6133
6124
  * @return {boolean}
6134
6125
  */
6135
6126
 
6136
- function isIdempotentRequestError(error) {
6127
+ function isIdempotentRequestError$1(error) {
6137
6128
  if (!error.config) {
6138
6129
  // Cannot determine if the request can be retried
6139
6130
  return false;
6140
6131
  }
6141
6132
 
6142
- return isRetryableError(error) && IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
6133
+ return isRetryableError$1(error) && IDEMPOTENT_HTTP_METHODS$1.indexOf(error.config.method) !== -1;
6143
6134
  }
6144
6135
  /**
6145
6136
  * @param {Error} error
6146
6137
  * @return {boolean}
6147
6138
  */
6148
6139
 
6149
- function isNetworkOrIdempotentRequestError(error) {
6150
- return isNetworkError(error) || isIdempotentRequestError(error);
6140
+ function isNetworkOrIdempotentRequestError$1(error) {
6141
+ return isNetworkError$1(error) || isIdempotentRequestError$1(error);
6151
6142
  }
6152
6143
  /**
6153
6144
  * @return {number} - delay in milliseconds, always 0
6154
6145
  */
6155
6146
 
6156
- function noDelay() {
6147
+ function noDelay$1() {
6157
6148
  return 0;
6158
6149
  }
6159
6150
  /**
@@ -6166,7 +6157,7 @@ function noDelay() {
6166
6157
  */
6167
6158
 
6168
6159
 
6169
- function exponentialDelay() {
6160
+ function exponentialDelay$1() {
6170
6161
  var retryNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
6171
6162
  var delayFactor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;
6172
6163
  var delay = Math.pow(2, retryNumber) * delayFactor;
@@ -6176,10 +6167,10 @@ function exponentialDelay() {
6176
6167
  }
6177
6168
  /** @type {IAxiosRetryConfig} */
6178
6169
 
6179
- var DEFAULT_OPTIONS = {
6170
+ var DEFAULT_OPTIONS$1 = {
6180
6171
  retries: 3,
6181
- retryCondition: isNetworkOrIdempotentRequestError,
6182
- retryDelay: noDelay,
6172
+ retryCondition: isNetworkOrIdempotentRequestError$1,
6173
+ retryDelay: noDelay$1,
6183
6174
  shouldResetTimeout: false,
6184
6175
  onRetry: () => {}
6185
6176
  };
@@ -6190,8 +6181,8 @@ var DEFAULT_OPTIONS = {
6190
6181
  * @return {IAxiosRetryConfigExtended}
6191
6182
  */
6192
6183
 
6193
- function getRequestOptions(config, defaultOptions) {
6194
- return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), defaultOptions), config[namespace]);
6184
+ function getRequestOptions$1(config, defaultOptions) {
6185
+ return _objectSpread$1(_objectSpread$1(_objectSpread$1({}, DEFAULT_OPTIONS$1), defaultOptions), config[namespace$1]);
6195
6186
  }
6196
6187
  /**
6197
6188
  * Initializes and returns the retry state for the given request/config
@@ -6201,10 +6192,10 @@ function getRequestOptions(config, defaultOptions) {
6201
6192
  */
6202
6193
 
6203
6194
 
6204
- function getCurrentState(config, defaultOptions) {
6205
- var currentState = getRequestOptions(config, defaultOptions);
6195
+ function getCurrentState$1(config, defaultOptions) {
6196
+ var currentState = getRequestOptions$1(config, defaultOptions);
6206
6197
  currentState.retryCount = currentState.retryCount || 0;
6207
- config[namespace] = currentState;
6198
+ config[namespace$1] = currentState;
6208
6199
  return currentState;
6209
6200
  }
6210
6201
  /**
@@ -6213,7 +6204,7 @@ function getCurrentState(config, defaultOptions) {
6213
6204
  */
6214
6205
 
6215
6206
 
6216
- function fixConfig(axios, config) {
6207
+ function fixConfig$1(axios, config) {
6217
6208
  if (axios.defaults.agent === config.agent) {
6218
6209
  delete config.agent;
6219
6210
  }
@@ -6234,8 +6225,8 @@ function fixConfig(axios, config) {
6234
6225
  */
6235
6226
 
6236
6227
 
6237
- function shouldRetry(_x, _x2) {
6238
- return _shouldRetry.apply(this, arguments);
6228
+ function shouldRetry$1(_x, _x2) {
6229
+ return _shouldRetry$1.apply(this, arguments);
6239
6230
  }
6240
6231
  /**
6241
6232
  * Adds response interceptors to an axios instance to retry requests failed due to network issues
@@ -6295,8 +6286,8 @@ function shouldRetry(_x, _x2) {
6295
6286
  */
6296
6287
 
6297
6288
 
6298
- function _shouldRetry() {
6299
- _shouldRetry = _asyncToGenerator(function* (currentState, error) {
6289
+ function _shouldRetry$1() {
6290
+ _shouldRetry$1 = _asyncToGenerator$1(function* (currentState, error) {
6300
6291
  var {
6301
6292
  retries,
6302
6293
  retryCondition
@@ -6315,17 +6306,17 @@ function _shouldRetry() {
6315
6306
 
6316
6307
  return shouldRetryOrPromise;
6317
6308
  });
6318
- return _shouldRetry.apply(this, arguments);
6309
+ return _shouldRetry$1.apply(this, arguments);
6319
6310
  }
6320
6311
 
6321
- function axiosRetry(axios, defaultOptions) {
6312
+ function axiosRetry$1(axios, defaultOptions) {
6322
6313
  var requestInterceptorId = axios.interceptors.request.use(config => {
6323
- var currentState = getCurrentState(config, defaultOptions);
6314
+ var currentState = getCurrentState$1(config, defaultOptions);
6324
6315
  currentState.lastRequestTime = Date.now();
6325
6316
  return config;
6326
6317
  });
6327
6318
  var responseInterceptorId = axios.interceptors.response.use(null, /*#__PURE__*/function () {
6328
- var _ref = _asyncToGenerator(function* (error) {
6319
+ var _ref = _asyncToGenerator$1(function* (error) {
6329
6320
  var {
6330
6321
  config
6331
6322
  } = error; // If we have no information to retry the request
@@ -6334,9 +6325,9 @@ function axiosRetry(axios, defaultOptions) {
6334
6325
  return Promise.reject(error);
6335
6326
  }
6336
6327
 
6337
- var currentState = getCurrentState(config, defaultOptions);
6328
+ var currentState = getCurrentState$1(config, defaultOptions);
6338
6329
 
6339
- if (yield shouldRetry(currentState, error)) {
6330
+ if (yield shouldRetry$1(currentState, error)) {
6340
6331
  currentState.retryCount += 1;
6341
6332
  var {
6342
6333
  retryDelay,
@@ -6346,7 +6337,7 @@ function axiosRetry(axios, defaultOptions) {
6346
6337
  var delay = retryDelay(currentState.retryCount, error); // Axios fails merging this configuration to the default configuration because it has an issue
6347
6338
  // with circular structures: https://github.com/mzabriskie/axios/issues/370
6348
6339
 
6349
- fixConfig(axios, config);
6340
+ fixConfig$1(axios, config);
6350
6341
 
6351
6342
  if (!shouldResetTimeout && config.timeout && currentState.lastRequestTime) {
6352
6343
  var lastRequestDuration = Date.now() - currentState.lastRequestTime;
@@ -6377,12 +6368,12 @@ function axiosRetry(axios, defaultOptions) {
6377
6368
  };
6378
6369
  } // Compatibility with CommonJS
6379
6370
 
6380
- axiosRetry.isNetworkError = isNetworkError;
6381
- axiosRetry.isSafeRequestError = isSafeRequestError;
6382
- axiosRetry.isIdempotentRequestError = isIdempotentRequestError;
6383
- axiosRetry.isNetworkOrIdempotentRequestError = isNetworkOrIdempotentRequestError;
6384
- axiosRetry.exponentialDelay = exponentialDelay;
6385
- axiosRetry.isRetryableError = isRetryableError;
6371
+ axiosRetry$1.isNetworkError = isNetworkError$1;
6372
+ axiosRetry$1.isSafeRequestError = isSafeRequestError$1;
6373
+ axiosRetry$1.isIdempotentRequestError = isIdempotentRequestError$1;
6374
+ axiosRetry$1.isNetworkOrIdempotentRequestError = isNetworkOrIdempotentRequestError$1;
6375
+ axiosRetry$1.exponentialDelay = exponentialDelay$1;
6376
+ axiosRetry$1.isRetryableError = isRetryableError$1;
6386
6377
 
6387
6378
  /******************************************************************************
6388
6379
  Copyright (c) Microsoft Corporation.
@@ -6446,7 +6437,7 @@ let MidgardApi$1 = class MidgardApi {
6446
6437
  constructor(network = xchainClient.Network.Mainnet, config) {
6447
6438
  this.network = network;
6448
6439
  this.config = config !== null && config !== void 0 ? config : defaultMidgardConfig$1[this.network];
6449
- axiosRetry(axios, { retries: this.config.apiRetries, retryDelay: axiosRetry.exponentialDelay });
6440
+ axiosRetry$1(axios, { retries: this.config.apiRetries, retryDelay: axiosRetry$1.exponentialDelay });
6450
6441
  this.midgardClients = this.config.midgardBaseUrls.map((url) => new MidgardApi$2(new Configuration$1({ basePath: url })));
6451
6442
  }
6452
6443
  /**
@@ -6863,7 +6854,7 @@ class MayachainProtocol {
6863
6854
  expectedAmount: estimatedSwap.expectedAmount,
6864
6855
  dustThreshold: estimatedSwap.dustThreshold,
6865
6856
  fees: estimatedSwap.fees,
6866
- totalSwapSeconds: estimatedSwap.inboundConfirmationSeconds || 0 + estimatedSwap.outboundDelaySeconds,
6857
+ totalSwapSeconds: (estimatedSwap.inboundConfirmationSeconds || 0) + estimatedSwap.outboundDelaySeconds,
6867
6858
  slipBasisPoints: estimatedSwap.slipBasisPoints,
6868
6859
  maxStreamingQuantity: estimatedSwap.maxStreamingQuantity,
6869
6860
  canSwap: estimatedSwap.canSwap,
@@ -8873,6 +8864,307 @@ class MidgardApi extends DefaultApi {
8873
8864
  }
8874
8865
  }
8875
8866
 
8867
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8868
+
8869
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
8870
+
8871
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
8872
+
8873
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8874
+
8875
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8876
+ var namespace = 'axios-retry';
8877
+ /**
8878
+ * @param {Error} error
8879
+ * @return {boolean}
8880
+ */
8881
+
8882
+ function isNetworkError(error) {
8883
+ var CODE_EXCLUDE_LIST = ['ERR_CANCELED', 'ECONNABORTED'];
8884
+ return !error.response && Boolean(error.code) && // Prevents retrying cancelled requests
8885
+ !CODE_EXCLUDE_LIST.includes(error.code) && // Prevents retrying timed out & cancelled requests
8886
+ isRetryAllowed(error) // Prevents retrying unsafe errors
8887
+ ;
8888
+ }
8889
+ var SAFE_HTTP_METHODS = ['get', 'head', 'options'];
8890
+ var IDEMPOTENT_HTTP_METHODS = SAFE_HTTP_METHODS.concat(['put', 'delete']);
8891
+ /**
8892
+ * @param {Error} error
8893
+ * @return {boolean}
8894
+ */
8895
+
8896
+ function isRetryableError(error) {
8897
+ return error.code !== 'ECONNABORTED' && (!error.response || error.response.status >= 500 && error.response.status <= 599);
8898
+ }
8899
+ /**
8900
+ * @param {Error} error
8901
+ * @return {boolean}
8902
+ */
8903
+
8904
+ function isSafeRequestError(error) {
8905
+ if (!error.config) {
8906
+ // Cannot determine if the request can be retried
8907
+ return false;
8908
+ }
8909
+
8910
+ return isRetryableError(error) && SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
8911
+ }
8912
+ /**
8913
+ * @param {Error} error
8914
+ * @return {boolean}
8915
+ */
8916
+
8917
+ function isIdempotentRequestError(error) {
8918
+ if (!error.config) {
8919
+ // Cannot determine if the request can be retried
8920
+ return false;
8921
+ }
8922
+
8923
+ return isRetryableError(error) && IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
8924
+ }
8925
+ /**
8926
+ * @param {Error} error
8927
+ * @return {boolean}
8928
+ */
8929
+
8930
+ function isNetworkOrIdempotentRequestError(error) {
8931
+ return isNetworkError(error) || isIdempotentRequestError(error);
8932
+ }
8933
+ /**
8934
+ * @return {number} - delay in milliseconds, always 0
8935
+ */
8936
+
8937
+ function noDelay() {
8938
+ return 0;
8939
+ }
8940
+ /**
8941
+ * Set delayFactor 1000 for an exponential delay to occur on the order
8942
+ * of seconds
8943
+ * @param {number} [retryNumber=0]
8944
+ * @param {Error} error - unused; for existing API of retryDelay callback
8945
+ * @param {number} [delayFactor=100] milliseconds
8946
+ * @return {number} - delay in milliseconds
8947
+ */
8948
+
8949
+
8950
+ function exponentialDelay() {
8951
+ var retryNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
8952
+ var delayFactor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;
8953
+ var delay = Math.pow(2, retryNumber) * delayFactor;
8954
+ var randomSum = delay * 0.2 * Math.random(); // 0-20% of the delay
8955
+
8956
+ return delay + randomSum;
8957
+ }
8958
+ /** @type {IAxiosRetryConfig} */
8959
+
8960
+ var DEFAULT_OPTIONS = {
8961
+ retries: 3,
8962
+ retryCondition: isNetworkOrIdempotentRequestError,
8963
+ retryDelay: noDelay,
8964
+ shouldResetTimeout: false,
8965
+ onRetry: () => {}
8966
+ };
8967
+ /**
8968
+ * Returns the axios-retry options for the current request
8969
+ * @param {AxiosRequestConfig} config
8970
+ * @param {IAxiosRetryConfig} defaultOptions
8971
+ * @return {IAxiosRetryConfigExtended}
8972
+ */
8973
+
8974
+ function getRequestOptions(config, defaultOptions) {
8975
+ return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), defaultOptions), config[namespace]);
8976
+ }
8977
+ /**
8978
+ * Initializes and returns the retry state for the given request/config
8979
+ * @param {AxiosRequestConfig} config
8980
+ * @param {IAxiosRetryConfig} defaultOptions
8981
+ * @return {IAxiosRetryConfigExtended}
8982
+ */
8983
+
8984
+
8985
+ function getCurrentState(config, defaultOptions) {
8986
+ var currentState = getRequestOptions(config, defaultOptions);
8987
+ currentState.retryCount = currentState.retryCount || 0;
8988
+ config[namespace] = currentState;
8989
+ return currentState;
8990
+ }
8991
+ /**
8992
+ * @param {Axios} axios
8993
+ * @param {AxiosRequestConfig} config
8994
+ */
8995
+
8996
+
8997
+ function fixConfig(axios, config) {
8998
+ if (axios.defaults.agent === config.agent) {
8999
+ delete config.agent;
9000
+ }
9001
+
9002
+ if (axios.defaults.httpAgent === config.httpAgent) {
9003
+ delete config.httpAgent;
9004
+ }
9005
+
9006
+ if (axios.defaults.httpsAgent === config.httpsAgent) {
9007
+ delete config.httpsAgent;
9008
+ }
9009
+ }
9010
+ /**
9011
+ * Checks retryCondition if request can be retried. Handles it's returning value or Promise.
9012
+ * @param {IAxiosRetryConfigExtended} currentState
9013
+ * @param {Error} error
9014
+ * @return {Promise<boolean>}
9015
+ */
9016
+
9017
+
9018
+ function shouldRetry(_x, _x2) {
9019
+ return _shouldRetry.apply(this, arguments);
9020
+ }
9021
+ /**
9022
+ * Adds response interceptors to an axios instance to retry requests failed due to network issues
9023
+ *
9024
+ * @example
9025
+ *
9026
+ * import axios from 'axios';
9027
+ *
9028
+ * axiosRetry(axios, { retries: 3 });
9029
+ *
9030
+ * axios.get('http://example.com/test') // The first request fails and the second returns 'ok'
9031
+ * .then(result => {
9032
+ * result.data; // 'ok'
9033
+ * });
9034
+ *
9035
+ * // Exponential back-off retry delay between requests
9036
+ * axiosRetry(axios, { retryDelay : axiosRetry.exponentialDelay});
9037
+ *
9038
+ * // Custom retry delay
9039
+ * axiosRetry(axios, { retryDelay : (retryCount) => {
9040
+ * return retryCount * 1000;
9041
+ * }});
9042
+ *
9043
+ * // Also works with custom axios instances
9044
+ * const client = axios.create({ baseURL: 'http://example.com' });
9045
+ * axiosRetry(client, { retries: 3 });
9046
+ *
9047
+ * client.get('/test') // The first request fails and the second returns 'ok'
9048
+ * .then(result => {
9049
+ * result.data; // 'ok'
9050
+ * });
9051
+ *
9052
+ * // Allows request-specific configuration
9053
+ * client
9054
+ * .get('/test', {
9055
+ * 'axios-retry': {
9056
+ * retries: 0
9057
+ * }
9058
+ * })
9059
+ * .catch(error => { // The first request fails
9060
+ * error !== undefined
9061
+ * });
9062
+ *
9063
+ * @param {Axios} axios An axios instance (the axios object or one created from axios.create)
9064
+ * @param {Object} [defaultOptions]
9065
+ * @param {number} [defaultOptions.retries=3] Number of retries
9066
+ * @param {boolean} [defaultOptions.shouldResetTimeout=false]
9067
+ * Defines if the timeout should be reset between retries
9068
+ * @param {Function} [defaultOptions.retryCondition=isNetworkOrIdempotentRequestError]
9069
+ * A function to determine if the error can be retried
9070
+ * @param {Function} [defaultOptions.retryDelay=noDelay]
9071
+ * A function to determine the delay between retry requests
9072
+ * @param {Function} [defaultOptions.onRetry=()=>{}]
9073
+ * A function to get notified when a retry occurs
9074
+ * @return {{ requestInterceptorId: number, responseInterceptorId: number }}
9075
+ * The ids of the interceptors added to the request and to the response (so they can be ejected at a later time)
9076
+ */
9077
+
9078
+
9079
+ function _shouldRetry() {
9080
+ _shouldRetry = _asyncToGenerator(function* (currentState, error) {
9081
+ var {
9082
+ retries,
9083
+ retryCondition
9084
+ } = currentState;
9085
+ var shouldRetryOrPromise = currentState.retryCount < retries && retryCondition(error); // This could be a promise
9086
+
9087
+ if (typeof shouldRetryOrPromise === 'object') {
9088
+ try {
9089
+ var shouldRetryPromiseResult = yield shouldRetryOrPromise; // keep return true unless shouldRetryPromiseResult return false for compatibility
9090
+
9091
+ return shouldRetryPromiseResult !== false;
9092
+ } catch (_err) {
9093
+ return false;
9094
+ }
9095
+ }
9096
+
9097
+ return shouldRetryOrPromise;
9098
+ });
9099
+ return _shouldRetry.apply(this, arguments);
9100
+ }
9101
+
9102
+ function axiosRetry(axios, defaultOptions) {
9103
+ var requestInterceptorId = axios.interceptors.request.use(config => {
9104
+ var currentState = getCurrentState(config, defaultOptions);
9105
+ currentState.lastRequestTime = Date.now();
9106
+ return config;
9107
+ });
9108
+ var responseInterceptorId = axios.interceptors.response.use(null, /*#__PURE__*/function () {
9109
+ var _ref = _asyncToGenerator(function* (error) {
9110
+ var {
9111
+ config
9112
+ } = error; // If we have no information to retry the request
9113
+
9114
+ if (!config) {
9115
+ return Promise.reject(error);
9116
+ }
9117
+
9118
+ var currentState = getCurrentState(config, defaultOptions);
9119
+
9120
+ if (yield shouldRetry(currentState, error)) {
9121
+ currentState.retryCount += 1;
9122
+ var {
9123
+ retryDelay,
9124
+ shouldResetTimeout,
9125
+ onRetry
9126
+ } = currentState;
9127
+ var delay = retryDelay(currentState.retryCount, error); // Axios fails merging this configuration to the default configuration because it has an issue
9128
+ // with circular structures: https://github.com/mzabriskie/axios/issues/370
9129
+
9130
+ fixConfig(axios, config);
9131
+
9132
+ if (!shouldResetTimeout && config.timeout && currentState.lastRequestTime) {
9133
+ var lastRequestDuration = Date.now() - currentState.lastRequestTime;
9134
+ var timeout = config.timeout - lastRequestDuration - delay;
9135
+
9136
+ if (timeout <= 0) {
9137
+ return Promise.reject(error);
9138
+ }
9139
+
9140
+ config.timeout = timeout;
9141
+ }
9142
+
9143
+ config.transformRequest = [data => data];
9144
+ yield onRetry(currentState.retryCount, error, config);
9145
+ return new Promise(resolve => setTimeout(() => resolve(axios(config)), delay));
9146
+ }
9147
+
9148
+ return Promise.reject(error);
9149
+ });
9150
+
9151
+ return function (_x3) {
9152
+ return _ref.apply(this, arguments);
9153
+ };
9154
+ }());
9155
+ return {
9156
+ requestInterceptorId,
9157
+ responseInterceptorId
9158
+ };
9159
+ } // Compatibility with CommonJS
9160
+
9161
+ axiosRetry.isNetworkError = isNetworkError;
9162
+ axiosRetry.isSafeRequestError = isSafeRequestError;
9163
+ axiosRetry.isIdempotentRequestError = isIdempotentRequestError;
9164
+ axiosRetry.isNetworkOrIdempotentRequestError = isNetworkOrIdempotentRequestError;
9165
+ axiosRetry.exponentialDelay = exponentialDelay;
9166
+ axiosRetry.isRetryableError = isRetryableError;
9167
+
8876
9168
  /******************************************************************************
8877
9169
  Copyright (c) Microsoft Corporation.
8878
9170
 
@@ -9404,7 +9696,7 @@ class ThorchainProtocol {
9404
9696
  expectedAmount: estimatedSwap.txEstimate.netOutput,
9405
9697
  dustThreshold: estimatedSwap.dustThreshold,
9406
9698
  fees: estimatedSwap.txEstimate.totalFees,
9407
- totalSwapSeconds: estimatedSwap.txEstimate.inboundConfirmationSeconds || 0 + estimatedSwap.txEstimate.outboundDelaySeconds,
9699
+ totalSwapSeconds: (estimatedSwap.txEstimate.inboundConfirmationSeconds || 0) + estimatedSwap.txEstimate.outboundDelaySeconds,
9408
9700
  slipBasisPoints: estimatedSwap.txEstimate.slipBasisPoints,
9409
9701
  maxStreamingQuantity: estimatedSwap.txEstimate.maxStreamingQuantity,
9410
9702
  canSwap: estimatedSwap.txEstimate.canSwap,
@@ -9531,7 +9823,7 @@ class Aggregator {
9531
9823
  successfulQuotes.push(result.value);
9532
9824
  }
9533
9825
  });
9534
- if (!successfulQuotes)
9826
+ if (successfulQuotes.length === 0)
9535
9827
  throw Error(`Can not estimate swap from ${xchainUtil.assetToString(params.fromAsset)} to ${xchainUtil.assetToString(params.destinationAsset)}`);
9536
9828
  return successfulQuotes;
9537
9829
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-aggregator",
3
3
  "description": "Protocol aggregator to make actions in different protocols",
4
- "version": "2.0.35",
4
+ "version": "2.2.0",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
7
7
  "module": "lib/index.esm.js",
@@ -29,21 +29,21 @@
29
29
  "directory": "release/package"
30
30
  },
31
31
  "dependencies": {
32
- "@chainflip/sdk": "1.11.2",
32
+ "@chainflip/sdk": "2.0.3",
33
33
  "@xchainjs/xchain-client": "2.0.10",
34
34
  "@xchainjs/xchain-mayachain": "4.1.1",
35
- "@xchainjs/xchain-mayachain-amm": "4.1.9",
35
+ "@xchainjs/xchain-mayachain-amm": "4.1.11",
36
36
  "@xchainjs/xchain-mayachain-query": "2.1.6",
37
37
  "@xchainjs/xchain-thorchain": "3.0.14",
38
- "@xchainjs/xchain-thorchain-amm": "3.0.27",
38
+ "@xchainjs/xchain-thorchain-amm": "3.0.29",
39
39
  "@xchainjs/xchain-thorchain-query": "2.0.16",
40
40
  "@xchainjs/xchain-util": "2.0.5",
41
- "@xchainjs/xchain-wallet": "2.0.20"
41
+ "@xchainjs/xchain-wallet": "2.0.22"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@xchainjs/xchain-avax": "2.0.14",
45
45
  "@xchainjs/xchain-base": "1.0.14",
46
- "@xchainjs/xchain-bitcoin": "2.0.10",
46
+ "@xchainjs/xchain-bitcoin": "2.2.0",
47
47
  "@xchainjs/xchain-bsc": "2.0.15",
48
48
  "@xchainjs/xchain-ethereum": "2.0.15",
49
49
  "@xchainjs/xchain-kujira": "2.0.10",