Skip to content

Commit

Permalink
Merge pull request #370 from paraswap/aburkut/back-1015-generic-rfq-a…
Browse files Browse the repository at this point in the history
…bnormal-flow-of-reqs

BACK-1015: fix generic rfq abnormal flow of requests
  • Loading branch information
aburkut authored Apr 19, 2023
2 parents c13c305 + dad9c71 commit 6dea5d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paraswap/dex-lib",
"version": "2.16.0",
"version": "2.16.1",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
6 changes: 6 additions & 0 deletions src/dex/generic-rfq/generic-rfq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,10 @@ export class GenericRFQ extends ParaSwapLimitOrders {
);
return true;
}

releaseResources(): void {
if (this.rateFetcher) {
this.rateFetcher.stop();
}
}
}
12 changes: 7 additions & 5 deletions src/dex/generic-rfq/rate-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BigNumber from 'bignumber.js';
import { isEmpty } from 'lodash';
import { SwapSide } from '@paraswap/core';
import { BN_1 } from '../../bignumber-constants';
import { IDexHelper } from '../../dex-helper';
Expand Down Expand Up @@ -164,6 +165,7 @@ export class RateFetcher {

start() {
this.tokensFetcher.startPolling();
this.rateFetcher.startPolling();
this.pairsFetcher.startPolling();
if (this.blackListFetcher) {
this.blackListFetcher.startPolling();
Expand Down Expand Up @@ -200,17 +202,12 @@ export class RateFetcher {
private handlePairsResponse(resp: PairsResponse) {
this.pairs = {};

if (this.rateFetcher.isPolling()) {
this.rateFetcher.stopPolling();
}

const pairs: PairMap = {};
for (const pairName of Object.keys(resp.pairs)) {
pairs[pairName] = resp.pairs[pairName];
}

this.pairs = pairs;
this.rateFetcher.startPolling();
}

private handleBlackListResponse(resp: BlackListResponse) {
Expand All @@ -228,6 +225,9 @@ export class RateFetcher {

private handleRatesResponse(resp: RatesResponse) {
const pairs = this.pairs;

if(isEmpty(pairs)) return;

Object.keys(resp.prices).forEach(pairName => {
const pair = pairs[pairName];
if (!pair) {
Expand All @@ -239,6 +239,8 @@ export class RateFetcher {
return;
}

if(isEmpty(this.tokens)) return;

const baseToken = this.tokens[pair.base];
const quoteToken = this.tokens[pair.quote];

Expand Down

0 comments on commit 6dea5d3

Please sign in to comment.