@orbs-network/twap 1.12.0 → 1.12.2

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.
@@ -35,7 +35,7 @@ export interface Config {
35
35
  takerAbi: any;
36
36
  partner: string;
37
37
  exchangeAddress: string;
38
- exchangeType: "UniswapV2Exchange" | "ParaswapExchange" | "PangolinDaasExchange" | "OdosExchange";
38
+ exchangeType: "UniswapV2Exchange" | "ParaswapExchange" | "PangolinDaasExchange" | "OdosExchange" | "OpenOceanExchange";
39
39
  pathfinderKey: ParaswapOnlyDex | OdosOnlyDex | OpenOceanOnlyDex;
40
40
  }
41
41
  export declare const ChainConfigs: {
@@ -59,12 +59,12 @@ exports.ChainConfigs = {
59
59
  };
60
60
  exports.Configs = {
61
61
  SpiritSwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpiritSwap", exchangeAddress: "0xAd19179201be5A51D1cBd3bB2fC651BB05822404", exchangeType: "ParaswapExchange", pathfinderKey: ParaswapOnlyDex.SpiritSwap }),
62
- SpookySwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpookySwap", exchangeAddress: "0x4b5815D263549Ff9b54a3838693C3DC0dbE7e597", exchangeType: "UniswapV2Exchange", pathfinderKey: ParaswapOnlyDex.SpookySwap }),
63
- Pangolin: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { partner: "Pangolin", exchangeAddress: "0xf2d96E7BE676153d202e1453804E2749923C7c5b", exchangeType: "UniswapV2Exchange", pathfinderKey: ParaswapOnlyDex.Pangolin }),
64
- PangolinDaas: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { partner: "PangolinDaas", exchangeAddress: "0x1579EED0527781B1A748043AA1f59a3858Ace4a7", exchangeType: "PangolinDaasExchange", pathfinderKey: ParaswapOnlyDex.Pangolin }),
65
- QuickSwap: Object.assign(Object.assign({}, exports.ChainConfigs.poly), { partner: "QuickSwap", exchangeAddress: "0x26D0ec4Be402BCE03AAa8aAf0CF67e9428ba54eF", exchangeType: "ParaswapExchange", pathfinderKey: ParaswapOnlyDex.QuickSwap }),
66
- Chronos: Object.assign(Object.assign({}, exports.ChainConfigs.arb), { partner: "Chronos", exchangeAddress: "0xA0b07F9a11dFb01388149abBdbc5B4f2196600AB", exchangeType: "OdosExchange", pathfinderKey: OdosOnlyDex.Chronos }),
67
- Thena: Object.assign(Object.assign({}, exports.ChainConfigs.bsc), { partner: "Thena", exchangeAddress: "0xD63430c74C8E70D9dbdCA04C6a9E6E9E929028DA", exchangeType: "ParaswapExchange", pathfinderKey: OpenOceanOnlyDex.Thena }),
62
+ SpookySwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "Orbs:TWAP:SpookySwap", exchangeAddress: "0x4b5815D263549Ff9b54a3838693C3DC0dbE7e597", exchangeType: "UniswapV2Exchange", pathfinderKey: ParaswapOnlyDex.SpookySwap }),
63
+ Pangolin: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { partner: "Orbs:TWAP:Pangolin", exchangeAddress: "0xf2d96E7BE676153d202e1453804E2749923C7c5b", exchangeType: "UniswapV2Exchange", pathfinderKey: ParaswapOnlyDex.Pangolin }),
64
+ PangolinDaas: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { partner: "Orbs:TWAP:PangolinDaas", exchangeAddress: "0x1579EED0527781B1A748043AA1f59a3858Ace4a7", exchangeType: "PangolinDaasExchange", pathfinderKey: ParaswapOnlyDex.Pangolin }),
65
+ QuickSwap: Object.assign(Object.assign({}, exports.ChainConfigs.poly), { partner: "Orbs:TWAP:QuickSwap", exchangeAddress: "0x26D0ec4Be402BCE03AAa8aAf0CF67e9428ba54eF", exchangeType: "ParaswapExchange", pathfinderKey: ParaswapOnlyDex.QuickSwap }),
66
+ Chronos: Object.assign(Object.assign({}, exports.ChainConfigs.arb), { partner: "Orbs:TWAP:Chronos", exchangeAddress: "0xA0b07F9a11dFb01388149abBdbc5B4f2196600AB", exchangeType: "OdosExchange", pathfinderKey: OdosOnlyDex.Chronos }),
67
+ Thena: Object.assign(Object.assign({}, exports.ChainConfigs.bsc), { partner: "Orbs:TWAP:Thena", exchangeAddress: "0xc2aBC02acd77Bb2407efA22348dA9afC8B375290", exchangeType: "OpenOceanExchange", pathfinderKey: OpenOceanOnlyDex.Thena }),
68
68
  };
69
69
  const chainConfig = (chainId) => lodash_1.default.find(exports.ChainConfigs, (c) => c.chainId === chainId);
70
70
  exports.chainConfig = chainConfig;
@@ -2,3 +2,4 @@ export * from "./lib";
2
2
  export * from "./configs";
3
3
  export * from "./paraswap";
4
4
  export * from "./odos";
5
+ export * from "./openocean";
package/dist/src/index.js CHANGED
@@ -18,3 +18,4 @@ __exportStar(require("./lib"), exports);
18
18
  __exportStar(require("./configs"), exports);
19
19
  __exportStar(require("./paraswap"), exports);
20
20
  __exportStar(require("./odos"), exports);
21
+ __exportStar(require("./openocean"), exports);
package/dist/src/lib.d.ts CHANGED
@@ -5,6 +5,7 @@ import type { TWAP } from "../typechain-hardhat/contracts";
5
5
  import type { Lens } from "../typechain-hardhat/contracts/periphery";
6
6
  import { Paraswap } from "./paraswap";
7
7
  import { Odos } from "./odos";
8
+ import { OpenOcean } from "./openocean";
8
9
  export declare class TWAPLib {
9
10
  config: Config;
10
11
  maker: string;
@@ -70,7 +71,7 @@ export declare class TWAPLib {
70
71
  dstUsd: BN;
71
72
  path: string[];
72
73
  }>;
73
- encodeBidData(route: Paraswap.Route | Odos.Route): string;
74
+ encodeBidData(route: Paraswap.Route | Odos.Route | OpenOcean.Route): string;
74
75
  }
75
76
  export interface Order {
76
77
  id: number;
package/dist/src/lib.js CHANGED
@@ -278,6 +278,7 @@ class TWAPLib {
278
278
  return (0, web3_candies_1.web3)().eth.abi.encodeParameters(["bool", "address[]"], [true, route.path]);
279
279
  case "ParaswapExchange":
280
280
  case "OdosExchange":
281
+ case "OpenOceanExchange":
281
282
  return (0, web3_candies_1.web3)().eth.abi.encodeParameters(["uint256", "bytes"], [route.dstAmount.toFixed(0), route.data]);
282
283
  default:
283
284
  throw new Error(`unknown exchange type ${this.config.exchangeType}`);
@@ -9,5 +9,5 @@ export declare namespace Odos {
9
9
  data: string;
10
10
  path: string[];
11
11
  }
12
- function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: OdosOnlyDex): Promise<Route>;
12
+ function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: OdosOnlyDex, partner?: string): Promise<Route>;
13
13
  }
package/dist/src/odos.js CHANGED
@@ -14,7 +14,7 @@ const web3_candies_1 = require("@defi.org/web3-candies");
14
14
  var Odos;
15
15
  (function (Odos) {
16
16
  const URL = "https://api.odos.xyz";
17
- function findRoute(chainId, src, dst, amountIn, exchangeAdapter = web3_candies_1.zeroAddress, onlyDex) {
17
+ function findRoute(chainId, src, dst, amountIn, exchangeAdapter = web3_candies_1.zeroAddress, onlyDex, partner) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
19
  const response = yield fetch(`${URL}/sor/quote`, {
20
20
  method: "POST",
@@ -27,6 +27,7 @@ var Odos;
27
27
  userAddr: exchangeAdapter,
28
28
  sourceWhitelist: (onlyDex === null || onlyDex === void 0 ? void 0 : onlyDex.split(",")) || [],
29
29
  simulate: false,
30
+ partner: partner || "",
30
31
  }),
31
32
  });
32
33
  if (response.status < 200 || response.status >= 400)
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,87 @@
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
+ };
30
+ function findRoute(chainId, src, dst, amountIn, exchangeAdapter = web3_candies_1.zeroAddress, onlyDex, partner) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const response = yield fetch(`${URL}/${chainNames[chainId]}/swap_quote?${new URLSearchParams({
33
+ chain: chainNames[chainId],
34
+ inTokenAddress: src.address,
35
+ outTokenAddress: dst.address,
36
+ amount: (0, bignumber_js_1.default)(amountIn)
37
+ .div(Math.pow(10, src.decimals))
38
+ .toString(),
39
+ slippage: "5",
40
+ gasPrice: "5",
41
+ account: exchangeAdapter,
42
+ enabledDexIds: onlyDex || "",
43
+ referrer: partner || "",
44
+ connectors: "", //0xf4c8e32eadec4bfe97e0f595add0f4450a863a11,0x52f24a5e03aee338da5fd9df68d2b6fae1178827,0x90c97f71e18723b0cf0dfa30ee176ab653e89f40
45
+ })}`);
46
+ if (response.status < 200 || response.status >= 400)
47
+ throw new Error(`${response.statusText}`);
48
+ const tokens = yield fetchTokens(chainId);
49
+ const j = yield response.json();
50
+ const srcUsd = (0, web3_candies_1.bn)(tokens[(0, web3_candies_1.web3)().utils.toChecksumAddress(src.address)].usd);
51
+ const dstUsd = (0, web3_candies_1.bn)(tokens[(0, web3_candies_1.web3)().utils.toChecksumAddress(dst.address)].usd);
52
+ const dstAmount = (0, web3_candies_1.bn)(j.data.outAmount);
53
+ const data = j.data.data || "";
54
+ return {
55
+ dstAmount,
56
+ srcUsd,
57
+ dstUsd,
58
+ data,
59
+ path: [],
60
+ };
61
+ });
62
+ }
63
+ OpenOcean.findRoute = findRoute;
64
+ const tokens = {};
65
+ function fetchTokens(chainId) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ if (lodash_1.default.size(tokens[chainId]))
68
+ return tokens[chainId];
69
+ const response = yield fetch(`${URL}/${chainNames[chainId]}/tokenList`);
70
+ if (response.status < 200 || response.status >= 400)
71
+ throw new Error(`${response.statusText}`);
72
+ const t = (yield response.json()).data;
73
+ const parsed = lodash_1.default.map(t, (token) => ({
74
+ token: {
75
+ address: (0, web3_candies_1.web3)().utils.toChecksumAddress(token.address),
76
+ decimals: parseInt(token.decimals),
77
+ symbol: token.symbol || "",
78
+ name: token.name || token.symbol || "",
79
+ logoUrl: token.icon || "",
80
+ },
81
+ usd: parseFloat(token.usd),
82
+ }));
83
+ tokens[chainId] = lodash_1.default.mapKeys(parsed, (t) => t.token.address);
84
+ return tokens[chainId];
85
+ });
86
+ }
87
+ })(OpenOcean = exports.OpenOcean || (exports.OpenOcean = {}));
@@ -9,5 +9,5 @@ export declare namespace Paraswap {
9
9
  data: string;
10
10
  path: string[];
11
11
  }
12
- function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: ParaswapOnlyDex): Promise<Route>;
12
+ function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, exchangeAdapter?: string, onlyDex?: ParaswapOnlyDex, partner?: string): Promise<Route>;
13
13
  }
@@ -19,8 +19,7 @@ const lodash_1 = __importDefault(require("lodash"));
19
19
  var Paraswap;
20
20
  (function (Paraswap) {
21
21
  const URL = "https://apiv5.paraswap.io";
22
- function findRoute(chainId, src, dst, amountIn, exchangeAdapter = web3_candies_1.zeroAddress, onlyDex) {
23
- var _a, _b;
22
+ function findRoute(chainId, src, dst, amountIn, exchangeAdapter = web3_candies_1.zeroAddress, onlyDex, partner) {
24
23
  return __awaiter(this, void 0, void 0, function* () {
25
24
  const params = new URLSearchParams({
26
25
  srcToken: src.address,
@@ -32,7 +31,7 @@ var Paraswap;
32
31
  side: "SELL",
33
32
  maxImpact: "50",
34
33
  includeDEXS: onlyDex || "",
35
- partner: ((_b = (_a = onlyDex === null || onlyDex === void 0 ? void 0 : onlyDex.toLowerCase()) === null || _a === void 0 ? void 0 : _a.split(",")) === null || _b === void 0 ? void 0 : _b[0]) || "",
34
+ partner: partner || "",
36
35
  });
37
36
  const response = yield fetch(`${URL}/prices/?${params}`);
38
37
  if (response.status < 200 || response.status >= 400)
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ import type BigNumber from "bignumber.js";
3
+ import type { ContractOptions } from "web3-eth-contract";
4
+ import type { EventLog } from "web3-core";
5
+ import type { EventEmitter } from "events";
6
+ import type { Callback, NonPayableTransactionObject, BlockType, BaseContract } from "../../types";
7
+ export interface EventOptions {
8
+ filter?: object;
9
+ fromBlock?: BlockType;
10
+ topics?: string[];
11
+ }
12
+ export interface OpenOceanExchange extends BaseContract {
13
+ constructor(jsonInterface: any[], address?: string, options?: ContractOptions): OpenOceanExchange;
14
+ clone(): OpenOceanExchange;
15
+ methods: {
16
+ getAmountOut(arg0: string, arg1: string, arg2: number | string | BigNumber, arg3: string | number[], bidData: string | number[]): NonPayableTransactionObject<string>;
17
+ openocean(): NonPayableTransactionObject<string>;
18
+ swap(_srcToken: string, _dstToken: string, amountIn: number | string | BigNumber, amountOutMin: number | string | BigNumber, arg4: string | number[], bidData: string | number[]): NonPayableTransactionObject<void>;
19
+ };
20
+ events: {
21
+ allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
22
+ };
23
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /* Autogenerated file. Do not edit manually. */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -5,3 +5,4 @@ export type { paraswapExchangeSol };
5
5
  import type * as uniswapV2ExchangeSol from "./UniswapV2Exchange.sol";
6
6
  export type { uniswapV2ExchangeSol };
7
7
  export type { OdosExchange } from "./OdosExchange";
8
+ export type { OpenOceanExchange } from "./OpenOceanExchange";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbs-network/twap",
3
- "version": "1.12.0",
3
+ "version": "1.12.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/orbs-network/twap.git"