@orbs-network/twap 1.20.0 → 1.21.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.
package/dist/src/lib.d.ts CHANGED
@@ -59,6 +59,7 @@ export declare class TWAPLib {
59
59
  dstUsd: BN;
60
60
  path: string[];
61
61
  }>;
62
+ private solverRoute;
62
63
  findRouteForNextBid(order: Order): Promise<{
63
64
  data: string;
64
65
  srcToken: TokenData;
package/dist/src/lib.js CHANGED
@@ -244,37 +244,26 @@ class TWAPLib {
244
244
  priceUsd(token) {
245
245
  return __awaiter(this, void 0, void 0, function* () {
246
246
  token = (0, web3_candies_1.isNativeAddress)(token.address) ? this.config.wToken : token;
247
- try {
248
- const r = yield paraswap_1.Paraswap.findRoute(this.config.chainId, token, { address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", symbol: "NATIVE", decimals: 18 }, (0, bignumber_js_1.default)(10).pow(token.decimals));
249
- return r.srcUsd.toNumber();
250
- }
251
- catch (e) {
252
- try {
253
- const r = yield odos_1.Odos.findRoute(this.config.chainId, token, this.config.nativeToken, (0, bignumber_js_1.default)(10).pow(token.decimals));
254
- return r.srcUsd.toNumber();
255
- }
256
- catch (e) {
257
- const r = yield openocean_1.OpenOcean.findRoute(this.config.chainId, token, this.config.nativeToken, (0, bignumber_js_1.default)(10).pow(token.decimals));
258
- return r.srcUsd.toNumber();
259
- }
260
- }
247
+ const r = yield this.solverRoute(token, this.config.nativeToken, (0, bignumber_js_1.default)(10).pow(token.decimals));
248
+ return r.srcUsd.toNumber();
261
249
  });
262
250
  }
263
251
  findRoute(srcToken, dstToken, srcAmount) {
264
252
  return __awaiter(this, void 0, void 0, function* () {
265
- let route;
266
- if (this.config.exchangeType === "OdosExchange") {
267
- route = yield odos_1.Odos.findRoute(this.config.chainId, srcToken, dstToken, srcAmount, this.config.exchangeAddress, this.config.pathfinderKey, this.config.partner);
268
- }
269
- else if (this.config.exchangeType === "OpenOceanExchange") {
270
- route = yield openocean_1.OpenOcean.findRoute(this.config.chainId, srcToken, dstToken, srcAmount, this.config.exchangeAddress, this.config.pathfinderKey, this.config.partner);
271
- }
272
- else {
273
- route = yield paraswap_1.Paraswap.findRoute(this.config.chainId, srcToken, dstToken, srcAmount, this.config.exchangeAddress, this.config.pathfinderKey, this.config.partner);
274
- }
253
+ const route = yield this.solverRoute(srcToken, dstToken, srcAmount);
275
254
  return Object.assign(Object.assign({}, route), { data: this.encodeBidData(route), srcToken, dstToken, srcAmount });
276
255
  });
277
256
  }
257
+ solverRoute(srcToken, dstToken, srcAmount) {
258
+ switch (this.config.exchangeType) {
259
+ case "OdosExchange":
260
+ return odos_1.Odos.findRoute(this.config.chainId, srcToken, dstToken, srcAmount, this.config.exchangeAddress, this.config.pathfinderKey, this.config.partner);
261
+ case "OpenOceanExchange":
262
+ return openocean_1.OpenOcean.findRoute(this.config.chainId, srcToken, dstToken, srcAmount, this.config.exchangeAddress, this.config.pathfinderKey, this.config.partner);
263
+ default:
264
+ return paraswap_1.Paraswap.findRoute(this.config.chainId, srcToken, dstToken, srcAmount, this.config.exchangeAddress, this.config.pathfinderKey, this.config.partner);
265
+ }
266
+ }
278
267
  findRouteForNextBid(order) {
279
268
  return __awaiter(this, void 0, void 0, function* () {
280
269
  if (order.ask.exchange !== web3_candies_1.zeroAddress && !(0, web3_candies_1.eqIgnoreCase)(order.ask.exchange, this.config.exchangeAddress))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbs-network/twap",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/orbs-network/twap.git"