@orbs-network/twap 1.22.1 → 1.23.1

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.
@@ -2,7 +2,6 @@
2
2
  "chainId": 1284,
3
3
  "chainName": "Moonbeam",
4
4
  "lens": "",
5
- "taker": "",
6
5
  "treasury": "0xf8105F11D917eB386Ddf7C447Aba1eC67Dd0684F",
7
6
  "twap": "0x4CeAebD7e83ed1563aca2557f2c8b20CBF92E65f",
8
7
  "weth": "0xAcc15dC74880C9944775448304B263D191c6077F"
@@ -2,7 +2,6 @@
2
2
  "chainId": 59144,
3
3
  "chainName": "Linea",
4
4
  "lens": "0x740BAD3Cb737612110b6E7Fe0DAE040A3eec1597",
5
- "taker": "0xdB73422dbd0155B48C9F55d90C6eF47ABAB234AA",
6
5
  "treasury": "0x2B6b06E352730f1d783526fBE847169Ff5a5Bf76",
7
6
  "twap": "0xbE7984eb48E2102549338B533dcF68035e413F66",
8
7
  "weth": "0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f"
@@ -5,28 +5,6 @@ export interface TokenData {
5
5
  symbol: string;
6
6
  logoUrl?: string;
7
7
  }
8
- export declare enum ParaswapOnlyDex {
9
- UniSwap = "Uniswap,UniswapV2,UniswapV3",
10
- SushiSwap = "SushiSwap",
11
- QuickSwap = "QuickSwap,QuickSwapV3",
12
- SpiritSwap = "SpiritSwap,SpiritSwapV2,SpiritSwapV3",
13
- SpookySwap = "SpookySwap",
14
- Pangolin = "PangolinSwap",
15
- TraderJoe = "TraderJoe,TraderJoeV2,TraderJoeV2.1",
16
- Thena = "Thena,ThenaFusion",
17
- PancakeSwap = "PancakeSwap,PancakeSwapV2,PancakeswapV3",
18
- Chronos = "Chronos"
19
- }
20
- export declare enum OdosOnlyDex {
21
- Chronos = "Chronos Stable,Chronos Volatile,Chronos V3",
22
- BaseSwap = "BaseSwap,BaseSwapX",
23
- Arbidex = "Arbidex Classic,Arbidex Quantum"
24
- }
25
- export declare enum OpenOceanOnlyDex {
26
- Thena = "43,47",
27
- Lynex = "10",
28
- SyncSwap = "2,3"
29
- }
30
8
  export interface Config {
31
9
  chainId: number;
32
10
  chainName: string;
@@ -43,8 +21,8 @@ export interface Config {
43
21
  name: string;
44
22
  partner: string;
45
23
  exchangeAddress: string;
46
- exchangeType: "UniswapV2Exchange" | "ParaswapExchange" | "PangolinDaasExchange" | "OdosExchange" | "OpenOceanExchange" | "KyberExchange";
47
- pathfinderKey: ParaswapOnlyDex | OdosOnlyDex | OpenOceanOnlyDex | string;
24
+ exchangeType: "RouterExchange" | "UniswapV2Exchange" | "ParaswapExchange" | "PangolinDaasExchange" | "OdosExchange" | "OpenOceanExchange" | "KyberExchange";
25
+ pathfinderKey: string;
48
26
  }
49
27
  export declare const ChainConfigs: {
50
28
  eth: {
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.chainConfig = exports.Configs = exports.ChainConfigs = exports.OpenOceanOnlyDex = exports.OdosOnlyDex = exports.ParaswapOnlyDex = exports.zeroAddress = exports.nativeTokenAddresses = void 0;
29
+ exports.chainConfig = exports.Configs = exports.ChainConfigs = exports.zeroAddress = exports.nativeTokenAddresses = void 0;
30
30
  const web3_candies_1 = require("@defi.org/web3-candies");
31
31
  const lodash_1 = __importDefault(require("lodash"));
32
32
  const TWAP_json_1 = __importDefault(require("../artifacts/contracts/TWAP.sol/TWAP.json"));
@@ -37,31 +37,6 @@ const lineaConfig = __importStar(require("../script/input/59144/config.json"));
37
37
  var web3_candies_2 = require("@defi.org/web3-candies");
38
38
  Object.defineProperty(exports, "nativeTokenAddresses", { enumerable: true, get: function () { return web3_candies_2.nativeTokenAddresses; } });
39
39
  Object.defineProperty(exports, "zeroAddress", { enumerable: true, get: function () { return web3_candies_2.zeroAddress; } });
40
- var ParaswapOnlyDex;
41
- (function (ParaswapOnlyDex) {
42
- ParaswapOnlyDex["UniSwap"] = "Uniswap,UniswapV2,UniswapV3";
43
- ParaswapOnlyDex["SushiSwap"] = "SushiSwap";
44
- ParaswapOnlyDex["QuickSwap"] = "QuickSwap,QuickSwapV3";
45
- ParaswapOnlyDex["SpiritSwap"] = "SpiritSwap,SpiritSwapV2,SpiritSwapV3";
46
- ParaswapOnlyDex["SpookySwap"] = "SpookySwap";
47
- ParaswapOnlyDex["Pangolin"] = "PangolinSwap";
48
- ParaswapOnlyDex["TraderJoe"] = "TraderJoe,TraderJoeV2,TraderJoeV2.1";
49
- ParaswapOnlyDex["Thena"] = "Thena,ThenaFusion";
50
- ParaswapOnlyDex["PancakeSwap"] = "PancakeSwap,PancakeSwapV2,PancakeswapV3";
51
- ParaswapOnlyDex["Chronos"] = "Chronos";
52
- })(ParaswapOnlyDex = exports.ParaswapOnlyDex || (exports.ParaswapOnlyDex = {}));
53
- var OdosOnlyDex;
54
- (function (OdosOnlyDex) {
55
- OdosOnlyDex["Chronos"] = "Chronos Stable,Chronos Volatile,Chronos V3";
56
- OdosOnlyDex["BaseSwap"] = "BaseSwap,BaseSwapX";
57
- OdosOnlyDex["Arbidex"] = "Arbidex Classic,Arbidex Quantum";
58
- })(OdosOnlyDex = exports.OdosOnlyDex || (exports.OdosOnlyDex = {}));
59
- var OpenOceanOnlyDex;
60
- (function (OpenOceanOnlyDex) {
61
- OpenOceanOnlyDex["Thena"] = "43,47";
62
- OpenOceanOnlyDex["Lynex"] = "10";
63
- OpenOceanOnlyDex["SyncSwap"] = "2,3";
64
- })(OpenOceanOnlyDex = exports.OpenOceanOnlyDex || (exports.OpenOceanOnlyDex = {}));
65
40
  const abis = {
66
41
  twapAbi: TWAP_json_1.default.abi,
67
42
  lensAbi: Lens_json_1.default.abi,
@@ -79,18 +54,18 @@ exports.ChainConfigs = {
79
54
  zkSync: Object.assign({ chainName: "zkSync", chainId: 324, twapVersion: 4, twapAddress: "0x971f855C98f45fcdD2782f03bD80Cf6C146Cf123", lensAddress: "0x3a661ACA20Cb9Ff8551D1F100cBCE4683fa31Af7", bidDelaySeconds: 60, minChunkSizeUsd: 100, nativeToken: web3_candies_1.networks.zksync.native, wToken: web3_candies_1.networks.zksync.wToken }, abis),
80
55
  };
81
56
  exports.Configs = {
82
- SpiritSwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { twapVersion: 3, twapAddress: "0xBb9F828E34A1327607c3e4eA3dD35891398DD5EE", lensAddress: "0x042799657E971855eD619046aeDf7F30DB56d2D6", twapAbi: legacyAbis.twapAbiV3, lensAbi: legacyAbis.lensAbiV3, takerAbi: legacyAbis.takerAbiV3, name: "SpiritSwap", partner: "Orbs:TWAP:SpiritSwap", exchangeAddress: "0xAd19179201be5A51D1cBd3bB2fC651BB05822404", exchangeType: "ParaswapExchange", pathfinderKey: ParaswapOnlyDex.SpiritSwap }),
83
- SpookySwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { name: "SpookySwap", partner: "Orbs:TWAP:SpookySwap", exchangeAddress: "0x704b9764cb36B8856f3097845dcc594d82192638", exchangeType: "UniswapV2Exchange", pathfinderKey: ParaswapOnlyDex.SpookySwap }),
84
- Pangolin: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { name: "Pangolin", partner: "Orbs:TWAP:Pangolin", exchangeAddress: "0xf2d96E7BE676153d202e1453804E2749923C7c5b", exchangeType: "UniswapV2Exchange", pathfinderKey: ParaswapOnlyDex.Pangolin }),
85
- PangolinDaas: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { name: "PangolinDaas", partner: "Orbs:TWAP:PangolinDaas", exchangeAddress: "0x1579EED0527781B1A748043AA1f59a3858Ace4a7", exchangeType: "PangolinDaasExchange", pathfinderKey: ParaswapOnlyDex.Pangolin }),
86
- QuickSwap: Object.assign(Object.assign({}, exports.ChainConfigs.poly), { name: "QuickSwap", partner: "Orbs:TWAP:QuickSwap", exchangeAddress: "0x26D0ec4Be402BCE03AAa8aAf0CF67e9428ba54eF", exchangeType: "ParaswapExchange", pathfinderKey: ParaswapOnlyDex.QuickSwap }),
87
- Chronos: Object.assign(Object.assign({}, exports.ChainConfigs.arb), { name: "Chronos", partner: "Orbs:TWAP:Chronos", exchangeAddress: "0xceFf098C9199c5d9cf24078dc14Eb8F787631cC0", exchangeType: "OdosExchange", pathfinderKey: OdosOnlyDex.Chronos }),
88
- BaseSwap: Object.assign(Object.assign({}, exports.ChainConfigs.base), { name: "BaseSwap", partner: "Orbs:TWAP:BaseSwap", exchangeAddress: "0xeFE1B6096838949156e5130604434A2a13c68C68", exchangeType: "OdosExchange", pathfinderKey: OdosOnlyDex.BaseSwap }),
89
- Arbidex: Object.assign(Object.assign({}, exports.ChainConfigs.arb), { name: "Arbidex", partner: "Orbs:TWAP:Arbidex", exchangeAddress: "0x8ffde23Fba2d7Aea9C3CBf2d5B7B533BB46754a8", exchangeType: "OdosExchange", pathfinderKey: OdosOnlyDex.Arbidex }),
90
- Thena: Object.assign(Object.assign({}, exports.ChainConfigs.bsc), { name: "Thena", partner: "Orbs:TWAP:Thena", exchangeAddress: "0xc2aBC02acd77Bb2407efA22348dA9afC8B375290", exchangeType: "OpenOceanExchange", pathfinderKey: OpenOceanOnlyDex.Thena }),
91
- PancakeSwap: Object.assign(Object.assign({}, exports.ChainConfigs.bsc), { name: "PancakeSwap", partner: "Orbs:TWAP:PancakeSwap", exchangeAddress: "0x3dD428151c697Aa1a3E5d0ee6A52768E70D85daE", exchangeType: "ParaswapExchange", pathfinderKey: ParaswapOnlyDex.PancakeSwap }),
92
- Lynex: Object.assign(Object.assign({}, exports.ChainConfigs.linea), { name: "Lynex", partner: "Orbs:TWAP:Lynex", exchangeAddress: "0x72e3e1fD5D2Ee2F1C2Eb695206D490a1D45C3835", exchangeType: "OpenOceanExchange", pathfinderKey: OpenOceanOnlyDex.Lynex }),
93
- SyncSwap: Object.assign(Object.assign({}, exports.ChainConfigs.zkSync), { name: "SyncSwap", partner: "Orbs:TWAP:SyncSwap", exchangeAddress: "0x5D96A072B2854d9a9D56C68806b0Bbcf7Db60b6d", exchangeType: "OpenOceanExchange", pathfinderKey: OpenOceanOnlyDex.SyncSwap }),
57
+ SpiritSwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { twapVersion: 3, twapAddress: "0xBb9F828E34A1327607c3e4eA3dD35891398DD5EE", lensAddress: "0x042799657E971855eD619046aeDf7F30DB56d2D6", twapAbi: legacyAbis.twapAbiV3, lensAbi: legacyAbis.lensAbiV3, takerAbi: legacyAbis.takerAbiV3, name: "SpiritSwap", partner: "Orbs:TWAP:SpiritSwap", exchangeAddress: "0xAd19179201be5A51D1cBd3bB2fC651BB05822404", exchangeType: "ParaswapExchange", pathfinderKey: "SpiritSwap,SpiritSwapV2,SpiritSwapV3" }),
58
+ SpookySwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { name: "SpookySwap", partner: "Orbs:TWAP:SpookySwap", exchangeAddress: "0x704b9764cb36B8856f3097845dcc594d82192638", exchangeType: "UniswapV2Exchange", pathfinderKey: "SpookySwap" }),
59
+ Pangolin: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { name: "Pangolin", partner: "Orbs:TWAP:Pangolin", exchangeAddress: "0xf2d96E7BE676153d202e1453804E2749923C7c5b", exchangeType: "UniswapV2Exchange", pathfinderKey: "PangolinSwap" }),
60
+ PangolinDaas: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { name: "PangolinDaas", partner: "Orbs:TWAP:PangolinDaas", exchangeAddress: "0x1579EED0527781B1A748043AA1f59a3858Ace4a7", exchangeType: "PangolinDaasExchange", pathfinderKey: "PangolinSwap" }),
61
+ QuickSwap: Object.assign(Object.assign({}, exports.ChainConfigs.poly), { name: "QuickSwap", partner: "Orbs:TWAP:QuickSwap", exchangeAddress: "0x26D0ec4Be402BCE03AAa8aAf0CF67e9428ba54eF", exchangeType: "ParaswapExchange", pathfinderKey: "QuickSwap,QuickSwapV3" }),
62
+ Chronos: Object.assign(Object.assign({}, exports.ChainConfigs.arb), { name: "Chronos", partner: "Orbs:TWAP:Chronos", exchangeAddress: "0xceFf098C9199c5d9cf24078dc14Eb8F787631cC0", exchangeType: "OdosExchange", pathfinderKey: "Chronos Stable,Chronos Volatile,Chronos V3" }),
63
+ BaseSwap: Object.assign(Object.assign({}, exports.ChainConfigs.base), { name: "BaseSwap", partner: "Orbs:TWAP:BaseSwap", exchangeAddress: "0xeFE1B6096838949156e5130604434A2a13c68C68", exchangeType: "OdosExchange", pathfinderKey: "BaseSwap,BaseSwapX" }),
64
+ Arbidex: Object.assign(Object.assign({}, exports.ChainConfigs.arb), { name: "Arbidex", partner: "Orbs:TWAP:Arbidex", exchangeAddress: "0x8ffde23Fba2d7Aea9C3CBf2d5B7B533BB46754a8", exchangeType: "OdosExchange", pathfinderKey: "Arbidex Classic,Arbidex Quantum" }),
65
+ Thena: Object.assign(Object.assign({}, exports.ChainConfigs.bsc), { name: "Thena", partner: "Orbs:TWAP:Thena", exchangeAddress: "0xc2aBC02acd77Bb2407efA22348dA9afC8B375290", exchangeType: "OpenOceanExchange", pathfinderKey: "43,47" }),
66
+ PancakeSwap: Object.assign(Object.assign({}, exports.ChainConfigs.bsc), { name: "PancakeSwap", partner: "Orbs:TWAP:PancakeSwap", exchangeAddress: "0xb2BAFe188faD927240038cC4FfF2d771d8A58905", exchangeType: "RouterExchange", pathfinderKey: "" }),
67
+ Lynex: Object.assign(Object.assign({}, exports.ChainConfigs.linea), { name: "Lynex", partner: "Orbs:TWAP:Lynex", exchangeAddress: "0x72e3e1fD5D2Ee2F1C2Eb695206D490a1D45C3835", exchangeType: "OpenOceanExchange", pathfinderKey: "10" }),
68
+ SyncSwap: Object.assign(Object.assign({}, exports.ChainConfigs.zkSync), { name: "SyncSwap", partner: "Orbs:TWAP:SyncSwap", exchangeAddress: "0x5D96A072B2854d9a9D56C68806b0Bbcf7Db60b6d", exchangeType: "OpenOceanExchange", pathfinderKey: "2,3" }),
94
69
  Retro: Object.assign(Object.assign({}, exports.ChainConfigs.poly), { name: "Retro", partner: "Orbs:TWAP:Retro", exchangeAddress: "0xC454Abb5b0CA974a4397139764478C736327d2B0", exchangeType: "KyberExchange", pathfinderKey: "retro,retro-v3" }),
95
70
  };
96
71
  const chainConfig = (chainId) => lodash_1.default.find(exports.ChainConfigs, (c) => c.chainId === chainId);
@@ -1,5 +1,2 @@
1
1
  export * from "./lib";
2
2
  export * from "./configs";
3
- export * from "./paraswap";
4
- export * from "./odos";
5
- export * from "./openocean";
package/dist/src/index.js CHANGED
@@ -16,6 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./lib"), exports);
18
18
  __exportStar(require("./configs"), exports);
19
- __exportStar(require("./paraswap"), exports);
20
- __exportStar(require("./odos"), exports);
21
- __exportStar(require("./openocean"), exports);
package/dist/src/lib.d.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  import { Config } from "./configs";
2
2
  import BN from "bignumber.js";
3
3
  import { TokenData } from "@defi.org/web3-candies";
4
- import { Paraswap } from "./paraswap";
5
- import { Odos } from "./odos";
6
- import { OpenOcean } from "./openocean";
7
4
  export declare class TWAPLib {
8
5
  config: Config;
9
6
  maker: string;
@@ -48,29 +45,6 @@ export declare class TWAPLib {
48
45
  })[]>;
49
46
  parseOrder(r: any): Order;
50
47
  getToken(address: string): Promise<import("./configs").TokenData>;
51
- priceUsd(token: TokenData): Promise<number>;
52
- findRoute(srcToken: TokenData, dstToken: TokenData, srcAmount: BN.Value): Promise<{
53
- data: string;
54
- srcToken: TokenData;
55
- dstToken: TokenData;
56
- srcAmount: BN.Value;
57
- dstAmount: BN;
58
- srcUsd: BN;
59
- dstUsd: BN;
60
- path: string[];
61
- }>;
62
- private solverRoute;
63
- findRouteForNextBid(order: Order): Promise<{
64
- data: string;
65
- srcToken: TokenData;
66
- dstToken: TokenData;
67
- srcAmount: BN.Value;
68
- dstAmount: BN;
69
- srcUsd: BN;
70
- dstUsd: BN;
71
- path: string[];
72
- }>;
73
- encodeBidData(route: Paraswap.Route | Odos.Route | OpenOcean.Route): string;
74
48
  }
75
49
  export interface Order {
76
50
  id: number;
package/dist/src/lib.js CHANGED
@@ -16,15 +16,13 @@ exports.TokensValidation = exports.OrderInputValidation = exports.Status = expor
16
16
  const web3_1 = __importDefault(require("web3"));
17
17
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
18
18
  const web3_candies_1 = require("@defi.org/web3-candies");
19
- const paraswap_1 = require("./paraswap");
20
19
  const lodash_1 = __importDefault(require("lodash"));
21
- const odos_1 = require("./odos");
22
- const openocean_1 = require("./openocean");
23
20
  class TWAPLib {
24
21
  constructor(config, maker, provider) {
25
22
  this.config = config;
26
23
  this.maker = maker;
27
24
  this.provider = provider;
25
+ // TODO: REMOVE
28
26
  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
27
  this.isNativeToken = (token) => (0, web3_candies_1.isNativeAddress)(token.address);
30
28
  this.isWrappedToken = (token) => (0, web3_candies_1.eqIgnoreCase)(token.address, this.config.wToken.address);
@@ -43,6 +41,7 @@ class TWAPLib {
43
41
  this.dstMinAmountOut = (srcToken, dstToken, srcChunkAmount, limitDstPriceFor1Src, isMarketOrder) => isMarketOrder
44
42
  ? (0, bignumber_js_1.default)(1)
45
43
  : bignumber_js_1.default.max(1, (0, web3_candies_1.convertDecimals)((0, bignumber_js_1.default)(srcChunkAmount).times(limitDstPriceFor1Src), srcToken.decimals, dstToken.decimals).integerValue(bignumber_js_1.default.ROUND_FLOOR));
44
+ // TODO: REMOVE
46
45
  this.dstPriceFor1Src = (srcToken, dstToken, srcUsdMarket, dstUsdMarket, srcChunkAmount, dstMinAmountOut) => (0, bignumber_js_1.default)(dstMinAmountOut).eq(1)
47
46
  ? (0, bignumber_js_1.default)(srcUsdMarket).div(dstUsdMarket)
48
47
  : (0, bignumber_js_1.default)(dstMinAmountOut).div((0, web3_candies_1.convertDecimals)((0, bignumber_js_1.default)(srcChunkAmount), srcToken.decimals, dstToken.decimals));
@@ -241,54 +240,6 @@ class TWAPLib {
241
240
  return { address, decimals, symbol };
242
241
  });
243
242
  }
244
- priceUsd(token) {
245
- return __awaiter(this, void 0, void 0, function* () {
246
- token = (0, web3_candies_1.isNativeAddress)(token.address) ? this.config.wToken : token;
247
- const r = yield this.solverRoute(token, this.config.nativeToken, (0, bignumber_js_1.default)(10).pow(token.decimals));
248
- return r.srcUsd.toNumber();
249
- });
250
- }
251
- findRoute(srcToken, dstToken, srcAmount) {
252
- return __awaiter(this, void 0, void 0, function* () {
253
- const route = yield this.solverRoute(srcToken, dstToken, srcAmount);
254
- return Object.assign(Object.assign({}, route), { data: this.encodeBidData(route), srcToken, dstToken, srcAmount });
255
- });
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
- }
267
- findRouteForNextBid(order) {
268
- return __awaiter(this, void 0, void 0, function* () {
269
- if (order.ask.exchange !== web3_candies_1.zeroAddress && !(0, web3_candies_1.eqIgnoreCase)(order.ask.exchange, this.config.exchangeAddress))
270
- throw new Error(`mismatched exchange and config`);
271
- const srcNextChunkAmountIn = bignumber_js_1.default.min(order.ask.srcBidAmount, order.ask.srcAmount.minus(order.srcFilledAmount));
272
- const [srcToken, dstToken] = yield Promise.all([
273
- this.getToken(order.ask.srcToken),
274
- this.getToken(order.ask.dstToken),
275
- ]);
276
- return yield this.findRoute(srcToken, dstToken, srcNextChunkAmountIn);
277
- });
278
- }
279
- encodeBidData(route) {
280
- switch (this.config.exchangeType) {
281
- case "UniswapV2Exchange":
282
- case "PangolinDaasExchange":
283
- return (0, web3_candies_1.web3)().eth.abi.encodeParameters(["bool", "address[]"], [true, route.path]);
284
- case "ParaswapExchange":
285
- case "OdosExchange":
286
- case "OpenOceanExchange":
287
- return (0, web3_candies_1.web3)().eth.abi.encodeParameters(["uint256", "bytes"], [route.dstAmount.toFixed(0), route.data]);
288
- default:
289
- throw new Error(`unknown exchange type ${this.config.exchangeType}`);
290
- }
291
- }
292
243
  }
293
244
  exports.TWAPLib = TWAPLib;
294
245
  TWAPLib.VERSION = 4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbs-network/twap",
3
- "version": "1.22.1",
3
+ "version": "1.23.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/orbs-network/twap.git"
@@ -1,13 +0,0 @@
1
- import { TokenData } from "@defi.org/web3-candies";
2
- import { OdosOnlyDex } from "./configs";
3
- import BN from "bignumber.js";
4
- export declare namespace Odos {
5
- interface Route {
6
- dstAmount: BN;
7
- srcUsd: BN;
8
- dstUsd: BN;
9
- data: string;
10
- path: string[];
11
- }
12
- function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: OdosOnlyDex, partner?: string): Promise<Route>;
13
- }
package/dist/src/odos.js DELETED
@@ -1,70 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Odos = void 0;
13
- const web3_candies_1 = require("@defi.org/web3-candies");
14
- var Odos;
15
- (function (Odos) {
16
- const URL = "https://api.odos.xyz";
17
- function findRoute(chainId, src, dst, amountIn, exchangeAdapter = web3_candies_1.zeroAddress, onlyDex, partner) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const response = yield fetch(`${URL}/sor/quote/v2`, {
20
- method: "POST",
21
- headers: { "Content-Type": "application/json", accept: "application/json" },
22
- body: JSON.stringify({
23
- chainId,
24
- inputTokens: [{ tokenAddress: src.address, amount: amountIn.toString() }],
25
- outputTokens: [{ tokenAddress: dst.address, proportion: 1 }],
26
- slippageLimitPercent: 50,
27
- userAddr: exchangeAdapter,
28
- sourceWhitelist: (onlyDex === null || onlyDex === void 0 ? void 0 : onlyDex.split(",")) || [],
29
- simulate: false,
30
- partner: partner || "",
31
- }),
32
- });
33
- if (response.status < 200 || response.status >= 400)
34
- throw new Error(`${response.statusText}`);
35
- const j = yield response.json();
36
- const srcUsd = (0, web3_candies_1.bn)(j.inValues[0]);
37
- const dstUsd = (0, web3_candies_1.bn)(j.outValues[0]);
38
- const dstAmount = (0, web3_candies_1.bn)(j.outAmounts[0]);
39
- const data = yield buildSwapData(j.pathId, dstAmount, exchangeAdapter);
40
- return {
41
- dstAmount,
42
- srcUsd,
43
- dstUsd,
44
- data,
45
- path: [],
46
- };
47
- });
48
- }
49
- Odos.findRoute = findRoute;
50
- function buildSwapData(pathId, dstAmountOut, exchangeAdapter) {
51
- var _a, _b;
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const response = yield fetch(`${URL}/sor/assemble`, {
54
- method: "POST",
55
- headers: { accept: "application/json", "Content-Type": "application/json" },
56
- body: JSON.stringify({
57
- pathId,
58
- userAddr: exchangeAdapter,
59
- simulate: false,
60
- }),
61
- });
62
- if (response.status < 200 || response.status >= 400)
63
- throw new Error(`${response.statusText}`);
64
- const swapData = (_b = (_a = ((yield response.json()))) === null || _a === void 0 ? void 0 : _a.transaction) === null || _b === void 0 ? void 0 : _b.data;
65
- if (!swapData)
66
- throw new Error(`invalid swap data from Odos`);
67
- return swapData;
68
- });
69
- }
70
- })(Odos = exports.Odos || (exports.Odos = {}));
@@ -1,13 +0,0 @@
1
- import { TokenData } from "@defi.org/web3-candies";
2
- import BN from "bignumber.js";
3
- import { OpenOceanOnlyDex } from "./configs";
4
- export declare namespace OpenOcean {
5
- interface Route {
6
- dstAmount: BN;
7
- srcUsd: BN;
8
- dstUsd: BN;
9
- data: string;
10
- path: string[];
11
- }
12
- function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: OpenOceanOnlyDex, partner?: string): Promise<Route>;
13
- }
@@ -1,93 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.OpenOcean = void 0;
16
- const web3_candies_1 = require("@defi.org/web3-candies");
17
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
18
- const lodash_1 = __importDefault(require("lodash"));
19
- var OpenOcean;
20
- (function (OpenOcean) {
21
- const URL = "https://open-api.openocean.finance/v3";
22
- const chainNames = {
23
- [web3_candies_1.networks.eth.id]: "eth",
24
- [web3_candies_1.networks.bsc.id]: "bsc",
25
- [web3_candies_1.networks.arb.id]: "arbitrum",
26
- [web3_candies_1.networks.poly.id]: "polygon",
27
- [web3_candies_1.networks.ftm.id]: "fantom",
28
- [web3_candies_1.networks.avax.id]: "avax",
29
- [web3_candies_1.networks.linea.id]: "linea",
30
- [web3_candies_1.networks.zksync.id]: "zksync",
31
- [web3_candies_1.networks.base.id]: "base",
32
- [web3_candies_1.networks.glmr.id]: "moonbeam",
33
- [web3_candies_1.networks.oeth.id]: "op",
34
- };
35
- function findRoute(chainId, src, dst, amountIn, exchangeAdapter = web3_candies_1.zeroAddress, onlyDex, partner) {
36
- var _a, _b;
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const response = yield fetch(`${URL}/${chainNames[chainId]}/swap_quote?${new URLSearchParams({
39
- chain: chainNames[chainId],
40
- inTokenAddress: src.address,
41
- outTokenAddress: dst.address,
42
- amount: (0, bignumber_js_1.default)(amountIn)
43
- .div(Math.pow(10, src.decimals))
44
- .toString(),
45
- slippage: "5",
46
- gasPrice: "5",
47
- account: exchangeAdapter,
48
- enabledDexIds: onlyDex || "",
49
- referrer: partner || "",
50
- connectors: "", //0xf4c8e32eadec4bfe97e0f595add0f4450a863a11,0x52f24a5e03aee338da5fd9df68d2b6fae1178827,0x90c97f71e18723b0cf0dfa30ee176ab653e89f40
51
- })}`);
52
- if (response.status < 200 || response.status >= 400)
53
- throw new Error(`${response.statusText}`);
54
- const tokens = yield fetchTokens(chainId);
55
- const j = yield response.json();
56
- const srcUsd = (0, web3_candies_1.bn)(((_a = tokens[(0, web3_candies_1.web3)().utils.toChecksumAddress(src.address)]) === null || _a === void 0 ? void 0 : _a.usd) || 0);
57
- const dstUsd = (0, web3_candies_1.bn)(((_b = tokens[(0, web3_candies_1.web3)().utils.toChecksumAddress(dst.address)]) === null || _b === void 0 ? void 0 : _b.usd) || 0);
58
- const dstAmount = (0, web3_candies_1.bn)(j.data.outAmount);
59
- const data = j.data.data || "0x";
60
- return {
61
- dstAmount,
62
- srcUsd,
63
- dstUsd,
64
- data,
65
- path: [],
66
- };
67
- });
68
- }
69
- OpenOcean.findRoute = findRoute;
70
- const tokens = {};
71
- function fetchTokens(chainId) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- if (lodash_1.default.size(tokens[chainId]))
74
- return tokens[chainId];
75
- const response = yield fetch(`${URL}/${chainNames[chainId]}/tokenList`);
76
- if (response.status < 200 || response.status >= 400)
77
- throw new Error(`${response.statusText}`);
78
- const t = (yield response.json()).data;
79
- const parsed = lodash_1.default.map(t, (token) => ({
80
- token: {
81
- address: (0, web3_candies_1.web3)().utils.toChecksumAddress(token.address),
82
- decimals: parseInt(token.decimals),
83
- symbol: token.symbol || "",
84
- name: token.name || token.symbol || "",
85
- logoUrl: token.icon || "",
86
- },
87
- usd: parseFloat(token.usd),
88
- }));
89
- tokens[chainId] = lodash_1.default.mapKeys(parsed, (t) => t.token.address);
90
- return tokens[chainId];
91
- });
92
- }
93
- })(OpenOcean = exports.OpenOcean || (exports.OpenOcean = {}));
@@ -1,13 +0,0 @@
1
- import { TokenData } from "@defi.org/web3-candies";
2
- import BN from "bignumber.js";
3
- import { ParaswapOnlyDex } from "./configs";
4
- export declare namespace Paraswap {
5
- interface Route {
6
- dstAmount: BN;
7
- srcUsd: BN;
8
- dstUsd: BN;
9
- data: string;
10
- path: string[];
11
- }
12
- function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: ParaswapOnlyDex, partner?: string): Promise<Route>;
13
- }
@@ -1,90 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Paraswap = void 0;
16
- const web3_candies_1 = require("@defi.org/web3-candies");
17
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
18
- const lodash_1 = __importDefault(require("lodash"));
19
- var Paraswap;
20
- (function (Paraswap) {
21
- const URL = "https://apiv5.paraswap.io";
22
- function findRoute(chainId, src, dst, amountIn, exchangeAdapter = web3_candies_1.zeroAddress, onlyDex, partner) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const params = new URLSearchParams({
25
- srcToken: src.address,
26
- destToken: dst.address,
27
- srcDecimals: src.decimals.toString(),
28
- destDecimals: dst.decimals.toString(),
29
- amount: amountIn.toString(),
30
- network: chainId.toString(),
31
- side: "SELL",
32
- maxImpact: "100",
33
- includeDEXS: onlyDex || "",
34
- partner: partner || "",
35
- });
36
- const response = yield fetch(`${URL}/prices/?${params}`);
37
- if (response.status < 200 || response.status >= 400)
38
- throw new Error(`${response.statusText}`);
39
- const route = (yield response.json()).priceRoute;
40
- const path = getDirectPath(route, onlyDex);
41
- let data = "0x";
42
- try {
43
- if (exchangeAdapter !== web3_candies_1.zeroAddress) {
44
- data = yield buildSwapData(route, exchangeAdapter);
45
- }
46
- }
47
- catch (e) { }
48
- 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 };
49
- });
50
- }
51
- Paraswap.findRoute = findRoute;
52
- function getDirectPath(route, onlyDex) {
53
- if (!onlyDex || !route.bestRoute.length)
54
- return [];
55
- const bestRoute = lodash_1.default.sortBy(route.bestRoute, (r) => r.percent).reverse()[0];
56
- if (bestRoute.swaps.length > 1)
57
- return []; // invalid direct path more than 1 path
58
- if (!(0, web3_candies_1.eqIgnoreCase)(bestRoute.swaps[0].srcToken, route.srcToken) ||
59
- !(0, web3_candies_1.eqIgnoreCase)(bestRoute.swaps[0].destToken, route.destToken))
60
- return []; //invalid direct path tokens
61
- const bestSwap = lodash_1.default.sortBy(bestRoute.swaps[0].swapExchanges, (s) => s.percent).reverse()[0];
62
- if (!onlyDex.split(",").includes(bestSwap.exchange))
63
- return []; // invalid direct path exchange
64
- const path = bestSwap.data.path;
65
- if (!path || path.length < 2)
66
- return []; // invalid direct path
67
- return path;
68
- }
69
- function buildSwapData(paraswapRoute, exchangeAdapter) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const response = yield fetch(`${URL}/transactions/${paraswapRoute.network}?ignoreChecks=true`, {
72
- method: "POST",
73
- headers: { "Content-Type": "application/json" },
74
- body: JSON.stringify({
75
- priceRoute: paraswapRoute,
76
- srcToken: paraswapRoute.srcToken,
77
- destToken: paraswapRoute.destToken,
78
- srcDecimals: paraswapRoute.srcDecimals,
79
- destDecimals: paraswapRoute.destDecimals,
80
- srcAmount: paraswapRoute.srcAmount,
81
- destAmount: "1",
82
- userAddress: exchangeAdapter,
83
- }),
84
- });
85
- if (response.status < 200 || response.status >= 400)
86
- throw new Error(`${response.statusText}`);
87
- return (yield response.json()).data;
88
- });
89
- }
90
- })(Paraswap = exports.Paraswap || (exports.Paraswap = {}));