@paraswap/dex-lib 3.8.38 → 3.8.39-bebop

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 (62) hide show
  1. package/build/abi/USDM.json +807 -0
  2. package/build/abi/bebop/BebopSettlement.abi.json +2137 -0
  3. package/build/abi/wUSDM.json +757 -0
  4. package/build/config.js +7 -0
  5. package/build/config.js.map +1 -1
  6. package/build/dex/bebop/bebop.d.ts +55 -0
  7. package/build/dex/bebop/bebop.js +524 -0
  8. package/build/dex/bebop/bebop.js.map +1 -0
  9. package/build/dex/bebop/config.d.ts +3 -0
  10. package/build/dex/bebop/config.js +38 -0
  11. package/build/dex/bebop/config.js.map +1 -0
  12. package/build/dex/bebop/constants.d.ts +9 -0
  13. package/build/dex/bebop/constants.js +13 -0
  14. package/build/dex/bebop/constants.js.map +1 -0
  15. package/build/dex/bebop/rate-fetcher.d.ts +22 -0
  16. package/build/dex/bebop/rate-fetcher.js +80 -0
  17. package/build/dex/bebop/rate-fetcher.js.map +1 -0
  18. package/build/dex/bebop/types.d.ts +76 -0
  19. package/build/dex/bebop/types.js +3 -0
  20. package/build/dex/bebop/types.js.map +1 -0
  21. package/build/dex/bebop/validators.d.ts +4 -0
  22. package/build/dex/bebop/validators.js +42 -0
  23. package/build/dex/bebop/validators.js.map +1 -0
  24. package/build/dex/bebop/websocket-fetcher.d.ts +35 -0
  25. package/build/dex/bebop/websocket-fetcher.js +87 -0
  26. package/build/dex/bebop/websocket-fetcher.js.map +1 -0
  27. package/build/dex/index.js +2 -0
  28. package/build/dex/index.js.map +1 -1
  29. package/build/dex/woo-fi-v2/woo-fi-v2-pool.d.ts +2 -2
  30. package/build/dex/woo-fi-v2/woo-fi-v2-pool.js +30 -9
  31. package/build/dex/woo-fi-v2/woo-fi-v2-pool.js.map +1 -1
  32. package/build/dex/woo-fi-v2/woo-fi-v2.js +1 -1
  33. package/build/dex/woo-fi-v2/woo-fi-v2.js.map +1 -1
  34. package/build/dex/wusdm/config.d.ts +3 -0
  35. package/build/dex/wusdm/config.js +29 -0
  36. package/build/dex/wusdm/config.js.map +1 -0
  37. package/build/dex/wusdm/types.d.ts +10 -0
  38. package/build/dex/wusdm/types.js +3 -0
  39. package/build/dex/wusdm/types.js.map +1 -0
  40. package/build/dex/wusdm/wusdm.d.ts +39 -0
  41. package/build/dex/wusdm/wusdm.js +212 -0
  42. package/build/dex/wusdm/wusdm.js.map +1 -0
  43. package/build/lib/fetcher/wsFetcher.d.ts +35 -0
  44. package/build/lib/fetcher/wsFetcher.js +87 -0
  45. package/build/lib/fetcher/wsFetcher.js.map +1 -0
  46. package/build/types.d.ts +1 -0
  47. package/package.json +4 -2
  48. package/src/abi/bebop/BebopSettlement.abi.json +2137 -0
  49. package/src/config.ts +8 -0
  50. package/src/dex/bebop/bebop-e2e.test.ts +195 -0
  51. package/src/dex/bebop/bebop-integration.test.ts +170 -0
  52. package/src/dex/bebop/bebop.ts +732 -0
  53. package/src/dex/bebop/config.ts +37 -0
  54. package/src/dex/bebop/constants.ts +9 -0
  55. package/src/dex/bebop/rate-fetcher.ts +138 -0
  56. package/src/dex/bebop/types.ts +81 -0
  57. package/src/dex/bebop/validators.ts +43 -0
  58. package/src/dex/index.ts +2 -0
  59. package/src/dex/woo-fi-v2/woo-fi-v2-pool.ts +58 -27
  60. package/src/dex/woo-fi-v2/woo-fi-v2.ts +1 -2
  61. package/src/lib/fetcher/wsFetcher.ts +126 -0
  62. package/src/types.ts +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/wusdm/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ import { AsyncOrSync } from 'ts-essentials';
2
+ import { Token, Address, ExchangePrices, PoolPrices, AdapterExchangeParam, PoolLiquidity, Logger, NumberAsString, DexExchangeParam } from '../../types';
3
+ import { SwapSide, Network } from '../../constants';
4
+ import { IDex } from '../../dex/idex';
5
+ import { IDexHelper } from '../../dex-helper/idex-helper';
6
+ import { WUSDMData, DexParams } from './types';
7
+ import { SimpleExchange } from '../simple-exchange';
8
+ import { Interface } from '@ethersproject/abi';
9
+ export declare class WUSDM extends SimpleExchange implements IDex<WUSDMData> {
10
+ readonly network: Network;
11
+ readonly dexKey: string;
12
+ readonly dexHelper: IDexHelper;
13
+ static readonly wUSDMIface: Interface;
14
+ static readonly USDMIface: Interface;
15
+ protected config: DexParams;
16
+ readonly hasConstantPriceLargeAmounts = true;
17
+ readonly needWrapNative = false;
18
+ readonly isFeeOnTransferSupported = true;
19
+ static dexKeysWithNetwork: {
20
+ key: string;
21
+ networks: Network[];
22
+ }[];
23
+ logger: Logger;
24
+ private state;
25
+ constructor(network: Network, dexKey: string, dexHelper: IDexHelper);
26
+ getAdapters(side: SwapSide): {
27
+ name: string;
28
+ index: number;
29
+ }[] | null;
30
+ getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
31
+ protected calcWrap: (amount: bigint) => bigint;
32
+ protected calcUnwrap: (amount: bigint) => bigint;
33
+ getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<WUSDMData>>;
34
+ getCalldataGasCost(poolPrices: PoolPrices<WUSDMData>): number | number[];
35
+ getDexParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: WUSDMData, side: SwapSide): Promise<DexExchangeParam>;
36
+ getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: WUSDMData, side: SwapSide): AdapterExchangeParam;
37
+ getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
38
+ releaseResources(): AsyncOrSync<void>;
39
+ }
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.WUSDM = void 0;
30
+ const constants_1 = require("../../constants");
31
+ const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
32
+ const utils_1 = require("../../utils");
33
+ const simple_exchange_1 = require("../simple-exchange");
34
+ const config_1 = require("./config");
35
+ const utils_2 = require("../../utils");
36
+ const abi_1 = require("@ethersproject/abi");
37
+ const wUSDM_json_1 = __importDefault(require("../../abi/wUSDM.json"));
38
+ const USDM_json_1 = __importDefault(require("../../abi/USDM.json"));
39
+ const utils_3 = require("../../executor/utils");
40
+ const decoders_1 = require("../../lib/decoders");
41
+ class WUSDM extends simple_exchange_1.SimpleExchange {
42
+ constructor(network, dexKey, dexHelper) {
43
+ super(dexHelper, dexKey);
44
+ this.network = network;
45
+ this.dexKey = dexKey;
46
+ this.dexHelper = dexHelper;
47
+ this.hasConstantPriceLargeAmounts = true;
48
+ // TODO: set true here if protocols works only with wrapped asset
49
+ this.needWrapNative = false;
50
+ this.isFeeOnTransferSupported = true;
51
+ this.state = {
52
+ blockNumber: 0,
53
+ totalAssets: 0n,
54
+ totalShares: 0n,
55
+ };
56
+ this.calcWrap = (amount) => (amount * this.state.totalShares) / this.state.totalAssets;
57
+ this.calcUnwrap = (amount) => (amount * this.state.totalAssets) / this.state.totalShares;
58
+ const config = config_1.WUSDMConfig[dexKey][network];
59
+ this.config = {
60
+ wUSDMAddress: config.wUSDMAddress.toLowerCase(),
61
+ USDMAddress: config.USDMAddress.toLowerCase(),
62
+ };
63
+ this.logger = dexHelper.getLogger(dexKey);
64
+ }
65
+ getAdapters(side) {
66
+ return null;
67
+ }
68
+ // Returns list of pool identifiers that can be used
69
+ // for a given swap. poolIdentifiers must be unique
70
+ // across DEXes. It is recommended to use
71
+ // ${dexKey}_${poolAddress} as a poolIdentifier
72
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
73
+ if (side === constants_1.SwapSide.BUY)
74
+ return [];
75
+ const srcTokenAddress = srcToken.address.toLowerCase();
76
+ const destTokenAddress = destToken.address.toLowerCase();
77
+ if (!((srcTokenAddress === this.config.wUSDMAddress &&
78
+ destTokenAddress === this.config.USDMAddress) ||
79
+ (srcTokenAddress === this.config.USDMAddress &&
80
+ destTokenAddress === this.config.wUSDMAddress))) {
81
+ return [];
82
+ }
83
+ return [this.dexKey];
84
+ }
85
+ // Returns pool prices for amounts.
86
+ // If limitPools is defined only pools in limitPools
87
+ // should be used. If limitPools is undefined then
88
+ // any pools can be used.
89
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
90
+ if (side === constants_1.SwapSide.BUY)
91
+ return null;
92
+ const srcTokenAddress = srcToken.address.toLowerCase();
93
+ const destTokenAddress = destToken.address.toLowerCase();
94
+ if (!((srcTokenAddress === this.config.wUSDMAddress &&
95
+ destTokenAddress === this.config.USDMAddress) ||
96
+ (srcTokenAddress === this.config.USDMAddress &&
97
+ destTokenAddress === this.config.wUSDMAddress))) {
98
+ return null;
99
+ }
100
+ const wrap = srcTokenAddress === this.config.USDMAddress;
101
+ if (blockNumber > this.state.blockNumber) {
102
+ const cached = await this.dexHelper.cache.get(this.dexKey, this.network, 'state');
103
+ if (cached) {
104
+ this.state = utils_2.Utils.Parse(cached);
105
+ }
106
+ if (blockNumber > this.state.blockNumber) {
107
+ const calls = [
108
+ {
109
+ target: this.config.wUSDMAddress,
110
+ callData: WUSDM.wUSDMIface.encodeFunctionData('totalSupply'),
111
+ decodeFunction: decoders_1.uint256ToBigInt,
112
+ },
113
+ {
114
+ target: this.config.wUSDMAddress,
115
+ callData: WUSDM.wUSDMIface.encodeFunctionData('totalAssets'),
116
+ decodeFunction: decoders_1.uint256ToBigInt,
117
+ },
118
+ ];
119
+ const results = await this.dexHelper.multiWrapper.tryAggregate(true, calls, blockNumber);
120
+ this.state = {
121
+ blockNumber,
122
+ totalShares: results[0].returnData,
123
+ totalAssets: results[1].returnData,
124
+ };
125
+ this.dexHelper.cache.setex(this.dexKey, this.network, 'state', 60, utils_2.Utils.Serialize(this.state));
126
+ }
127
+ }
128
+ const calc = wrap ? this.calcWrap : this.calcUnwrap;
129
+ return [
130
+ {
131
+ unit: calc(1000000000000000000n),
132
+ prices: amounts.map(calc),
133
+ data: {},
134
+ poolAddresses: [this.config.wUSDMAddress],
135
+ exchange: this.dexKey,
136
+ gasCost: wrap ? 60000 : 70000,
137
+ poolIdentifier: this.dexKey,
138
+ },
139
+ ];
140
+ }
141
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
142
+ getCalldataGasCost(poolPrices) {
143
+ // TODO: update if there is any payload in getAdapterParam
144
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
145
+ }
146
+ async getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side) {
147
+ const swapFunction = srcToken.toLowerCase() === this.config.wUSDMAddress
148
+ ? 'redeem'
149
+ : 'deposit';
150
+ const exchangeData = swapFunction === 'deposit'
151
+ ? WUSDM.wUSDMIface.encodeFunctionData('deposit', [srcAmount, recipient])
152
+ : WUSDM.wUSDMIface.encodeFunctionData('redeem', [
153
+ srcAmount,
154
+ recipient,
155
+ recipient,
156
+ ]);
157
+ return {
158
+ needWrapNative: this.needWrapNative,
159
+ dexFuncHasRecipient: false,
160
+ exchangeData,
161
+ targetExchange: this.config.wUSDMAddress,
162
+ returnAmountPos: side === constants_1.SwapSide.SELL
163
+ ? (0, utils_3.extractReturnAmountPosition)(WUSDM.wUSDMIface, swapFunction)
164
+ : undefined,
165
+ };
166
+ }
167
+ // Encode params required by the exchange adapter
168
+ // V5: Used for multiSwap, buy & megaSwap
169
+ // V6: Not used, can be left blank
170
+ // Hint: abiCoder.encodeParameter() could be useful
171
+ getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
172
+ return {
173
+ targetExchange: this.config.wUSDMAddress,
174
+ payload: '0x',
175
+ networkFee: '0',
176
+ };
177
+ }
178
+ // Returns list of top pools based on liquidity. Max
179
+ // limit number pools should be returned.
180
+ async getTopPoolsForToken(tokenAddress, limit) {
181
+ tokenAddress = tokenAddress.toLowerCase();
182
+ if (tokenAddress !== this.config.USDMAddress &&
183
+ tokenAddress !== this.config.wUSDMAddress) {
184
+ return [];
185
+ }
186
+ return [
187
+ {
188
+ exchange: this.dexKey,
189
+ address: this.config.wUSDMAddress,
190
+ connectorTokens: [
191
+ {
192
+ decimals: 18,
193
+ address: tokenAddress === this.config.USDMAddress
194
+ ? this.config.wUSDMAddress
195
+ : this.config.USDMAddress,
196
+ },
197
+ ],
198
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
199
+ },
200
+ ];
201
+ }
202
+ // This is optional function in case if your implementation has acquired any resources
203
+ // you need to release for graceful shutdown. For example, it may be any interval timer
204
+ releaseResources() {
205
+ // TODO: complete me!
206
+ }
207
+ }
208
+ exports.WUSDM = WUSDM;
209
+ WUSDM.wUSDMIface = new abi_1.Interface(wUSDM_json_1.default);
210
+ WUSDM.USDMIface = new abi_1.Interface(USDM_json_1.default);
211
+ WUSDM.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.WUSDMConfig);
212
+ //# sourceMappingURL=wusdm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wusdm.js","sourceRoot":"","sources":["../../../src/dex/wusdm/wusdm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,+CAAoD;AACpD,2EAA6D;AAC7D,uCAAoD;AAIpD,wDAAoD;AACpD,qCAAuC;AACvC,uCAAoC;AACpC,4CAA+C;AAC/C,sEAA6C;AAC7C,oEAA2C;AAC3C,gDAAmE;AACnE,iDAAqD;AAErD,MAAa,KAAM,SAAQ,gCAAc;IAuBvC,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB;QAE9B,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAJhB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QApBvB,iCAA4B,GAAG,IAAI,CAAC;QAC7C,iEAAiE;QACxD,mBAAc,GAAG,KAAK,CAAC;QAEvB,6BAAwB,GAAG,IAAI,CAAC;QAOjC,UAAK,GAAwC;YACnD,WAAW,EAAE,CAAC;YACd,WAAW,EAAE,EAAE;YACf,WAAW,EAAE,EAAE;SAChB,CAAC;QA8CQ,aAAQ,GAAG,CAAC,MAAc,EAAU,EAAE,CAC9C,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;QAEnD,eAAU,GAAG,CAAC,MAAc,EAAU,EAAE,CAChD,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;QA1C3D,MAAM,MAAM,GAAG,oBAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG;YACZ,YA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Ae,EAAE;oBACf;wBACE,QAAQ,EAAE,EAAE;wBACZ,OAAO,EACL,YAAY,KAAK,IAAI,CAAC,MAAM,CAAC,WAAW;4BACtC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY;4BAC1B,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW;qBAC9B;iBACF;gBACD,YAAY,EAAE,UAAU,EAAE,4DAA4D;aACvF;SACF,CAAC;IACJ,CAAC;IAED,sFAAsF;IACtF,uFAAuF;IACvF,gBAAgB;QACd,qBAAqB;IACvB,CAAC;;AA1PH,sBA2PC;AA1PiB,gBAAU,GAAG,IAAI,eAAS,CAAC,oBAAS,CAAC,CAAC;AACtC,eAAS,GAAG,IAAI,eAAS,CAAC,mBAAQ,CAAC,CAAC;AAUtC,wBAAkB,GAC9B,IAAA,6BAAqB,EAAC,oBAAW,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { Logger } from 'log4js';
2
+ import { RequestConfig, Response } from '../../dex-helper/irequest-wrapper';
3
+ export declare class SkippingRequest {
4
+ message: string;
5
+ constructor(message?: string);
6
+ }
7
+ export declare type RequestInfo<T> = {
8
+ requestFunc?: (options: RequestConfig) => Promise<Response<T> | SkippingRequest>;
9
+ requestOptions: RequestConfig;
10
+ caster: (data: unknown) => T;
11
+ authenticate?: (options: RequestConfig) => RequestConfig;
12
+ excludedFieldsCaching?: string[];
13
+ };
14
+ export declare type RequestInfoWithHandler<T> = {
15
+ info: RequestInfo<T>;
16
+ handler: (data: T) => void;
17
+ };
18
+ export declare class WebSocketFetcher<T> {
19
+ private logger;
20
+ private requests;
21
+ lastFetchSucceeded: boolean;
22
+ private stop;
23
+ private ws;
24
+ private connection;
25
+ constructor(requestsInfo: RequestInfoWithHandler<T>, logger: Logger);
26
+ private connected;
27
+ private connectFailed;
28
+ private onClose;
29
+ private onError;
30
+ private onMessage;
31
+ private connect;
32
+ startPolling(): void;
33
+ stopPolling(): void;
34
+ isPolling(): boolean;
35
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebSocketFetcher = exports.SkippingRequest = void 0;
4
+ const websocket_1 = require("websocket");
5
+ class SkippingRequest {
6
+ constructor(message = '') {
7
+ this.message = message;
8
+ }
9
+ }
10
+ exports.SkippingRequest = SkippingRequest;
11
+ class WebSocketFetcher {
12
+ constructor(requestsInfo, logger) {
13
+ this.logger = logger;
14
+ this.lastFetchSucceeded = false;
15
+ this.stop = true;
16
+ this.ws = new websocket_1.client();
17
+ this.connection = null;
18
+ this.requests = requestsInfo;
19
+ this.ws.on('connect', this.connected.bind(this));
20
+ this.ws.on('connectFailed', this.connectFailed.bind(this));
21
+ }
22
+ connected(connection) {
23
+ this.connection = connection;
24
+ this.logger.info(`Connected to ${this.requests.info.requestOptions.url}`);
25
+ this.connection.on('error', this.onError.bind(this));
26
+ this.connection.on('close', this.onClose.bind(this));
27
+ this.connection.on('message', this.onMessage.bind(this));
28
+ }
29
+ connectFailed(error) {
30
+ this.logger.error(`Connect Error: ${error.toString()}`);
31
+ }
32
+ onClose() {
33
+ this.logger.info(`Connection closed`);
34
+ }
35
+ onError(error) {
36
+ this.logger.error(`Connection Error: ${error.toString()}`);
37
+ }
38
+ onMessage(message) {
39
+ if (message.type === 'utf8') {
40
+ const response = JSON.parse(message.utf8Data);
41
+ const reqInfo = this.requests;
42
+ const info = reqInfo.info;
43
+ const options = reqInfo.info.requestOptions;
44
+ this.logger.debug(`(${options.url}) received new data`);
45
+ try {
46
+ const parsedData = info.caster(response);
47
+ reqInfo.handler(parsedData);
48
+ }
49
+ catch (e) {
50
+ this.logger.info(e);
51
+ this.logger.info(`(${options.url}) received incorrect data ${JSON.stringify(response).replace(/(?:\r\n|\r|\n)/g, ' ')}`, e);
52
+ return;
53
+ }
54
+ }
55
+ }
56
+ connect() {
57
+ const authorization = this.requests.info.requestOptions.headers.authorization;
58
+ const name = this.requests.info.requestOptions.headers.name;
59
+ if (typeof authorization !== 'string') {
60
+ throw new Error('Authorization header is not a string');
61
+ }
62
+ if (typeof name !== 'string') {
63
+ throw new Error('Name header is not a string');
64
+ }
65
+ this.ws.connect(this.requests.info.requestOptions.url, undefined, undefined, {
66
+ Authorization: authorization,
67
+ name: name,
68
+ });
69
+ }
70
+ startPolling() {
71
+ this.stop = false;
72
+ this.connect();
73
+ this.logger.info(`Connection started for ${this.requests.info.requestOptions.url}`);
74
+ }
75
+ stopPolling() {
76
+ if (this.connection) {
77
+ this.connection.close();
78
+ }
79
+ this.stop = true;
80
+ this.logger.info(`Connection stopped for ${this.requests.info.requestOptions.url}`);
81
+ }
82
+ isPolling() {
83
+ return !this.stop;
84
+ }
85
+ }
86
+ exports.WebSocketFetcher = WebSocketFetcher;
87
+ //# sourceMappingURL=wsFetcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wsFetcher.js","sourceRoot":"","sources":["../../../src/lib/fetcher/wsFetcher.ts"],"names":[],"mappings":";;;AAEA,yCAGmB;AAEnB,MAAa,eAAe;IAC1B,YAAmB,UAAU,EAAE;QAAZ,YAAO,GAAP,OAAO,CAAK;IAAG,CAAC;CACpC;AAFD,0CAEC;AAiBD,MAAa,gBAAgB;IAO3B,YAAY,YAAuC,EAAU,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QALpE,uBAAkB,GAAY,KAAK,CAAC;QACnC,SAAI,GAAY,IAAI,CAAC;QACrB,OAAE,GAAoB,IAAI,kBAAe,EAAE,CAAC;QAC5C,eAAU,GAA+B,IAAI,CAAC;QAGpD,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC;QAC7B,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7D,C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M,CAAC,IAAI,CACd,0BAA0B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,CAClE,CAAC;IACJ,CAAC;IAED,WAAW;QACT,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;SACzB;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,0BAA0B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,CAClE,CAAC;IACJ,CAAC;IAED,SAAS;QACP,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IACpB,CAAC;CACF;AAnGD,4CAmGC"}
package/build/types.d.ts CHANGED
@@ -263,6 +263,7 @@ export declare type Config = {
263
263
  uniswapV3EventLoggingSampleRate?: number;
264
264
  swaapV2AuthToken?: string;
265
265
  dexalotAuthToken?: string;
266
+ bebopAuthToken?: string;
266
267
  idleDaoAuthToken?: string;
267
268
  forceRpcFallbackDexs: string[];
268
269
  apiKeyTheGraph: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraswap/dex-lib",
3
- "version": "3.8.38",
3
+ "version": "3.8.39-bebop",
4
4
  "main": "build/index.js",
5
5
  "types": "build/index.d.ts",
6
6
  "repository": "https://github.com/paraswap/paraswap-dex-lib",
@@ -19,6 +19,7 @@
19
19
  "@types/lodash": "4.14.178",
20
20
  "@types/node": "^17.0.21",
21
21
  "@types/uuid": "^9.0.1",
22
+ "@types/websocket": "^1.0.10",
22
23
  "@typescript-eslint/eslint-plugin": "^5.47.0",
23
24
  "@typescript-eslint/parser": "^5.47.0",
24
25
  "change-case": "^4.1.2",
@@ -75,7 +76,8 @@
75
76
  "web3-eth": "1.6.0",
76
77
  "web3-eth-abi": "1.4.0",
77
78
  "web3-eth-contract": "1.6.0",
78
- "web3-utils": "1.6.0"
79
+ "web3-utils": "1.6.0",
80
+ "websocket": "^1.0.35"
79
81
  },
80
82
  "sideEffects": false
81
83
  }