@orbs-network/twap 1.10.9 → 1.10.11

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.
@@ -1,11 +1,21 @@
1
- import { Paraswap } from "./paraswap";
2
- import { Odos } from "./odos";
3
1
  export interface TokenData {
4
2
  address: string;
5
3
  decimals: number;
6
4
  symbol: string;
7
5
  logoUrl?: string;
8
6
  }
7
+ export declare enum ParaswapOnlyDex {
8
+ UniSwapV2 = "Uniswap",
9
+ SushiSwap = "SushiSwap",
10
+ QuickSwap = "QuickSwap,QuickSwapV3",
11
+ SpiritSwap = "SpiritSwap,SpiritSwapV2",
12
+ SpookySwap = "SpookySwap",
13
+ Pangolin = "PangolinSwap",
14
+ TraderJoe = "TraderJoe"
15
+ }
16
+ export declare enum OdosOnlyDex {
17
+ Chronos = "Chronos Stable,Chronos Volatile,Wrapped Ether"
18
+ }
9
19
  export interface Config {
10
20
  chainId: number;
11
21
  chainName: string;
@@ -22,7 +32,7 @@ export interface Config {
22
32
  partner: string;
23
33
  exchangeAddress: string;
24
34
  exchangeType: "UniswapV2Exchange" | "ParaswapExchange" | "PangolinDaasExchange" | "OdosExchange";
25
- pathfinderKey: Paraswap.OnlyDex | Odos.OnlyDex;
35
+ pathfinderKey: ParaswapOnlyDex | OdosOnlyDex;
26
36
  }
27
37
  export declare const ChainConfigs: {
28
38
  eth: {
@@ -1109,8 +1119,6 @@ export declare const Configs: {
1109
1119
  QuickSwap: Config;
1110
1120
  Chronos: Config;
1111
1121
  };
1112
- export declare const nativeTokenAddresses: string[];
1113
- export declare const isNativeAddress: (address: string) => boolean;
1114
1122
  export declare const chainConfig: (chainId: number) => {
1115
1123
  twapAbi: ({
1116
1124
  inputs: {
@@ -3,15 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.chainConfig = exports.isNativeAddress = exports.nativeTokenAddresses = exports.Configs = exports.ChainConfigs = void 0;
6
+ exports.chainConfig = exports.Configs = exports.ChainConfigs = exports.OdosOnlyDex = exports.ParaswapOnlyDex = void 0;
7
7
  const web3_candies_1 = require("@defi.org/web3-candies");
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
- const paraswap_1 = require("./paraswap");
10
9
  const TWAP_json_1 = __importDefault(require("../artifacts/contracts/TWAP.sol/TWAP.json"));
11
10
  const Lens_json_1 = __importDefault(require("../artifacts/contracts/periphery/Lens.sol/Lens.json"));
12
11
  const Taker_json_1 = __importDefault(require("../artifacts/contracts/periphery/Taker.sol/Taker.json"));
13
12
  const legacy_abi_1 = require("./legacy-abi");
14
- const odos_1 = require("./odos");
13
+ var ParaswapOnlyDex;
14
+ (function (ParaswapOnlyDex) {
15
+ ParaswapOnlyDex["UniSwapV2"] = "Uniswap";
16
+ ParaswapOnlyDex["SushiSwap"] = "SushiSwap";
17
+ ParaswapOnlyDex["QuickSwap"] = "QuickSwap,QuickSwapV3";
18
+ ParaswapOnlyDex["SpiritSwap"] = "SpiritSwap,SpiritSwapV2";
19
+ ParaswapOnlyDex["SpookySwap"] = "SpookySwap";
20
+ ParaswapOnlyDex["Pangolin"] = "PangolinSwap";
21
+ ParaswapOnlyDex["TraderJoe"] = "TraderJoe";
22
+ })(ParaswapOnlyDex = exports.ParaswapOnlyDex || (exports.ParaswapOnlyDex = {}));
23
+ var OdosOnlyDex;
24
+ (function (OdosOnlyDex) {
25
+ OdosOnlyDex["Chronos"] = "Chronos Stable,Chronos Volatile,Wrapped Ether";
26
+ })(OdosOnlyDex = exports.OdosOnlyDex || (exports.OdosOnlyDex = {}));
15
27
  const defaultAbis = {
16
28
  twapAbi: TWAP_json_1.default.abi,
17
29
  lensAbi: Lens_json_1.default.abi,
@@ -88,20 +100,12 @@ exports.ChainConfigs = {
88
100
  } }, defaultAbis),
89
101
  };
90
102
  exports.Configs = {
91
- SpiritSwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpiritSwap", exchangeAddress: "0xAd19179201be5A51D1cBd3bB2fC651BB05822404", exchangeType: "ParaswapExchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.SpiritSwap }),
92
- SpookySwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpookySwap", exchangeAddress: "0x4b5815D263549Ff9b54a3838693C3DC0dbE7e597", exchangeType: "UniswapV2Exchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.SpookySwap }),
93
- Pangolin: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { partner: "Pangolin", exchangeAddress: "0xf2d96E7BE676153d202e1453804E2749923C7c5b", exchangeType: "UniswapV2Exchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.Pangolin }),
94
- PangolinDaas: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { partner: "PangolinDaas", exchangeAddress: "0x1579EED0527781B1A748043AA1f59a3858Ace4a7", exchangeType: "PangolinDaasExchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.Pangolin }),
95
- QuickSwap: Object.assign(Object.assign({}, exports.ChainConfigs.poly), { partner: "QuickSwap", exchangeAddress: "0x26D0ec4Be402BCE03AAa8aAf0CF67e9428ba54eF", exchangeType: "ParaswapExchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.QuickSwap }),
96
- Chronos: Object.assign(Object.assign({}, exports.ChainConfigs.arb), { partner: "Chronos", exchangeAddress: "0xA0b07F9a11dFb01388149abBdbc5B4f2196600AB", exchangeType: "OdosExchange", pathfinderKey: odos_1.Odos.OnlyDex.Chronos }),
103
+ SpiritSwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpiritSwap", exchangeAddress: "0xAd19179201be5A51D1cBd3bB2fC651BB05822404", exchangeType: "ParaswapExchange", pathfinderKey: ParaswapOnlyDex.SpiritSwap }),
104
+ SpookySwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpookySwap", exchangeAddress: "0x4b5815D263549Ff9b54a3838693C3DC0dbE7e597", exchangeType: "UniswapV2Exchange", pathfinderKey: ParaswapOnlyDex.SpookySwap }),
105
+ Pangolin: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { partner: "Pangolin", exchangeAddress: "0xf2d96E7BE676153d202e1453804E2749923C7c5b", exchangeType: "UniswapV2Exchange", pathfinderKey: ParaswapOnlyDex.Pangolin }),
106
+ PangolinDaas: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { partner: "PangolinDaas", exchangeAddress: "0x1579EED0527781B1A748043AA1f59a3858Ace4a7", exchangeType: "PangolinDaasExchange", pathfinderKey: ParaswapOnlyDex.Pangolin }),
107
+ QuickSwap: Object.assign(Object.assign({}, exports.ChainConfigs.poly), { partner: "QuickSwap", exchangeAddress: "0x26D0ec4Be402BCE03AAa8aAf0CF67e9428ba54eF", exchangeType: "ParaswapExchange", pathfinderKey: ParaswapOnlyDex.QuickSwap }),
108
+ Chronos: Object.assign(Object.assign({}, exports.ChainConfigs.arb), { partner: "Chronos", exchangeAddress: "0xA0b07F9a11dFb01388149abBdbc5B4f2196600AB", exchangeType: "OdosExchange", pathfinderKey: OdosOnlyDex.Chronos }),
97
109
  };
98
- exports.nativeTokenAddresses = [
99
- web3_candies_1.zeroAddress,
100
- "0x0000000000000000000000000000000000001010",
101
- "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
102
- "0x000000000000000000000000000000000000dEaD",
103
- ];
104
- const isNativeAddress = (address) => !!lodash_1.default.find(exports.nativeTokenAddresses, (a) => (0, web3_candies_1.eqIgnoreCase)(a, address));
105
- exports.isNativeAddress = isNativeAddress;
106
110
  const chainConfig = (chainId) => lodash_1.default.find(exports.ChainConfigs, (c) => c.chainId === chainId);
107
111
  exports.chainConfig = chainConfig;
package/dist/src/lib.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { Config, TokenData } from "./configs";
1
+ import { Config } from "./configs";
2
2
  import BN from "bignumber.js";
3
+ import { TokenData } from "@defi.org/web3-candies";
3
4
  import type { TWAP } from "../typechain-hardhat/contracts";
4
5
  import type { Lens } from "../typechain-hardhat/contracts/periphery";
5
6
  import { Paraswap } from "./paraswap";
@@ -43,11 +44,12 @@ export declare class TWAPLib {
43
44
  cancelOrder(id: number, maxPriorityFeePerGas?: BN.Value, maxFeePerGas?: BN.Value): Promise<void>;
44
45
  getAllOrders(): Promise<Order[]>;
45
46
  getAllOrdersWithTokens(): Promise<(Order & {
46
- srcToken: TokenData;
47
- dstToken: TokenData;
47
+ srcToken: import("./configs").TokenData;
48
+ dstToken: import("./configs").TokenData;
48
49
  })[]>;
49
50
  parseOrder(r: any): Order;
50
- getToken(address: string): Promise<TokenData>;
51
+ getToken(address: string): Promise<import("./configs").TokenData>;
52
+ priceUsd(token: TokenData): Promise<number>;
51
53
  findRoute(srcToken: TokenData, dstToken: TokenData, srcAmount: BN.Value): Promise<{
52
54
  data: string;
53
55
  srcToken: TokenData;
package/dist/src/lib.js CHANGED
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.TokensValidation = exports.OrderInputValidation = exports.Status = exports.TWAPLib = void 0;
16
- const configs_1 = require("./configs");
17
16
  const web3_1 = __importDefault(require("web3"));
18
17
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
19
18
  const web3_candies_1 = require("@defi.org/web3-candies");
@@ -26,7 +25,7 @@ class TWAPLib {
26
25
  this.maker = maker;
27
26
  this.provider = provider;
28
27
  this.dstAmount = (srcToken, dstToken, srcAmount, srcUsdMarket, dstUsdMarket, limitDstPriceFor1Src, isMarketOrder) => (0, web3_candies_1.convertDecimals)(isMarketOrder ? (0, bignumber_js_1.default)(srcAmount).times(srcUsdMarket).div(dstUsdMarket) : (0, bignumber_js_1.default)(srcAmount).times(limitDstPriceFor1Src), srcToken.decimals, dstToken.decimals).integerValue(bignumber_js_1.default.ROUND_FLOOR);
29
- this.isNativeToken = (token) => (0, configs_1.isNativeAddress)(token.address);
28
+ this.isNativeToken = (token) => (0, web3_candies_1.isNativeAddress)(token.address);
30
29
  this.isWrappedToken = (token) => (0, web3_candies_1.eqIgnoreCase)(token.address, this.config.wToken.address);
31
30
  this.isValidChain = (chainId) => chainId === this.config.chainId;
32
31
  this.maxPossibleChunks = (srcToken, srcAmount, srcUsd) => bignumber_js_1.default.max(1, (0, bignumber_js_1.default)(srcAmount).div((0, bignumber_js_1.default)(10).pow(srcToken.decimals).div(srcUsd).times(this.config.minChunkSizeUsd)))
@@ -231,7 +230,7 @@ class TWAPLib {
231
230
  }
232
231
  getToken(address) {
233
232
  return __awaiter(this, void 0, void 0, function* () {
234
- if ((0, configs_1.isNativeAddress)(address))
233
+ if ((0, web3_candies_1.isNativeAddress)(address))
235
234
  return this.config.nativeToken;
236
235
  if ((0, web3_candies_1.eqIgnoreCase)(address, this.config.wToken.address))
237
236
  return this.config.wToken;
@@ -241,6 +240,13 @@ class TWAPLib {
241
240
  return { address, decimals, symbol };
242
241
  });
243
242
  }
243
+ priceUsd(token) {
244
+ return __awaiter(this, void 0, void 0, function* () {
245
+ token = (0, web3_candies_1.isNativeAddress)(token.address) ? this.config.wToken : token;
246
+ 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));
247
+ return r.srcUsd.toNumber();
248
+ });
249
+ }
244
250
  findRoute(srcToken, dstToken, srcAmount) {
245
251
  return __awaiter(this, void 0, void 0, function* () {
246
252
  let route;
@@ -1,9 +1,6 @@
1
- import { BN } from "@defi.org/web3-candies";
2
- import { TokenData } from "./configs";
1
+ import { BN, TokenData } from "@defi.org/web3-candies";
2
+ import { OdosOnlyDex } from "./configs";
3
3
  export declare namespace Odos {
4
- enum OnlyDex {
5
- Chronos = "Chronos Stable,Chronos Volatile,Wrapped Ether"
6
- }
7
4
  interface Route {
8
5
  dstAmount: BN;
9
6
  srcUsd: BN;
@@ -12,5 +9,5 @@ export declare namespace Odos {
12
9
  path: string[];
13
10
  }
14
11
  function priceUsd(chainId: number, token: TokenData): Promise<BN>;
15
- function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: OnlyDex): Promise<Route>;
12
+ function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: OdosOnlyDex): Promise<Route>;
16
13
  }
package/dist/src/odos.js CHANGED
@@ -15,13 +15,9 @@ const configs_1 = require("./configs");
15
15
  var Odos;
16
16
  (function (Odos) {
17
17
  const URL = "https://api.odos.xyz";
18
- let OnlyDex;
19
- (function (OnlyDex) {
20
- OnlyDex["Chronos"] = "Chronos Stable,Chronos Volatile,Wrapped Ether";
21
- })(OnlyDex = Odos.OnlyDex || (Odos.OnlyDex = {}));
22
18
  function priceUsd(chainId, token) {
23
19
  return __awaiter(this, void 0, void 0, function* () {
24
- token = (0, configs_1.isNativeAddress)(token.address) ? (0, configs_1.chainConfig)(chainId).wToken : token;
20
+ token = (0, web3_candies_1.isNativeAddress)(token.address) ? (0, configs_1.chainConfig)(chainId).wToken : token;
25
21
  const r = yield findRoute(chainId, token, (0, configs_1.chainConfig)(chainId).nativeToken, (0, web3_candies_1.BN)(10).pow(token.decimals));
26
22
  return r.srcUsd;
27
23
  });
@@ -1,15 +1,7 @@
1
+ import { TokenData } from "@defi.org/web3-candies";
1
2
  import BN from "bignumber.js";
2
- import { TokenData } from "./configs";
3
+ import { ParaswapOnlyDex } from "./configs";
3
4
  export declare namespace Paraswap {
4
- enum OnlyDex {
5
- UniSwapV2 = "Uniswap",
6
- SushiSwap = "SushiSwap",
7
- QuickSwap = "QuickSwap,QuickSwapV3",
8
- SpiritSwap = "SpiritSwap,SpiritSwapV2",
9
- SpookySwap = "SpookySwap",
10
- Pangolin = "PangolinSwap",
11
- TraderJoe = "TraderJoe"
12
- }
13
5
  interface Route {
14
6
  dstAmount: BN;
15
7
  srcUsd: BN;
@@ -17,6 +9,5 @@ export declare namespace Paraswap {
17
9
  data: string;
18
10
  path: string[];
19
11
  }
20
- function priceUsd(chainId: number, token: TokenData): Promise<BN>;
21
- function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: OnlyDex): Promise<Route>;
12
+ function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: ParaswapOnlyDex): Promise<Route>;
22
13
  }
@@ -13,31 +13,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Paraswap = void 0;
16
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
17
16
  const web3_candies_1 = require("@defi.org/web3-candies");
18
- const configs_1 = require("./configs");
17
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
19
18
  const lodash_1 = __importDefault(require("lodash"));
20
19
  var Paraswap;
21
20
  (function (Paraswap) {
22
21
  const URL = "https://apiv5.paraswap.io";
23
- let OnlyDex;
24
- (function (OnlyDex) {
25
- OnlyDex["UniSwapV2"] = "Uniswap";
26
- OnlyDex["SushiSwap"] = "SushiSwap";
27
- OnlyDex["QuickSwap"] = "QuickSwap,QuickSwapV3";
28
- OnlyDex["SpiritSwap"] = "SpiritSwap,SpiritSwapV2";
29
- OnlyDex["SpookySwap"] = "SpookySwap";
30
- OnlyDex["Pangolin"] = "PangolinSwap";
31
- OnlyDex["TraderJoe"] = "TraderJoe";
32
- })(OnlyDex = Paraswap.OnlyDex || (Paraswap.OnlyDex = {}));
33
- function priceUsd(chainId, token) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- token = (0, configs_1.isNativeAddress)(token.address) ? (0, configs_1.chainConfig)(chainId).wToken : token;
36
- const r = yield findRoute(chainId, token, { address: configs_1.nativeTokenAddresses[2], symbol: "NATIVE", decimals: 18 }, (0, bignumber_js_1.default)(10).pow(token.decimals));
37
- return r.srcUsd;
38
- });
39
- }
40
- Paraswap.priceUsd = priceUsd;
41
22
  function findRoute(chainId, src, dst, amountIn, exchangeAdapter = web3_candies_1.zeroAddress, onlyDex) {
42
23
  var _a, _b;
43
24
  return __awaiter(this, void 0, void 0, function* () {
@@ -60,9 +41,13 @@ var Paraswap;
60
41
  const path = getDirectPath(route, onlyDex);
61
42
  let data = "";
62
43
  try {
63
- data = yield buildSwapData(route, exchangeAdapter);
44
+ if (exchangeAdapter !== web3_candies_1.zeroAddress) {
45
+ data = yield buildSwapData(route, exchangeAdapter);
46
+ }
47
+ }
48
+ catch (e) {
49
+ console.error(e);
64
50
  }
65
- catch (e) { }
66
51
  return { dstAmount: (0, bignumber_js_1.default)(route.destAmount), srcUsd: (0, bignumber_js_1.default)(route.srcUSD), dstUsd: (0, bignumber_js_1.default)(route.destUSD), data, path };
67
52
  });
68
53
  }
@@ -88,9 +73,7 @@ var Paraswap;
88
73
  return __awaiter(this, void 0, void 0, function* () {
89
74
  const response = yield fetch(`${URL}/transactions/${paraswapRoute.network}?ignoreChecks=true`, {
90
75
  method: "POST",
91
- headers: {
92
- "Content-Type": "application/json",
93
- },
76
+ headers: { "Content-Type": "application/json" },
94
77
  body: JSON.stringify({
95
78
  priceRoute: paraswapRoute,
96
79
  srcToken: paraswapRoute.srcToken,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbs-network/twap",
3
- "version": "1.10.9",
3
+ "version": "1.10.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/orbs-network/twap.git"