Skip to content

Commit

Permalink
chore: modify api resp + add chainid
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimi-io committed Sep 27, 2023
1 parent 1dcf247 commit c07f6c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 37 deletions.
17 changes: 8 additions & 9 deletions src/dex/dexalot/dexalot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ import {
DEXALOT_GAS_COST,
DEXALOT_PAIRS_CACHES_TTL_S,
DEXALOT_API_PAIRS_POLLING_INTERVAL_MS,
DEXALOT_API_TOKENS_POLLING_INTERVAL_MS,
DEXALOT_TOKENS_CACHES_TTL_S,
DEXALOT_API_BLACKLIST_POLLING_INTERVAL_MS,
DEXALOT_RATE_LIMITED_TTL_S,
} from './constants';
import { BI_MAX_UINT256 } from '../../bigint-constants';
import { TooStrictSlippageCheckError } from '../generic-rfq/types';
import { ethers } from 'ethers';
import BigNumber from 'bignumber.js';

Expand Down Expand Up @@ -111,24 +109,23 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
rateConfig: {
pairsIntervalMs: DEXALOT_API_PAIRS_POLLING_INTERVAL_MS,
pricesIntervalMs: DEXALOT_API_PRICES_POLLING_INTERVAL_MS,
tokensIntervalMs: DEXALOT_API_TOKENS_POLLING_INTERVAL_MS,
blacklistIntervalMs: DEXALOT_API_BLACKLIST_POLLING_INTERVAL_MS,
pairsReqParams: {
url: `${DEXALOT_API_URL}/api/rfq/pairs`,
headers: {
'x-apikey': this.dexalotAuthToken,
},
params: {
chainid: this.network,
},
},
pricesReqParams: {
url: `${DEXALOT_API_URL}/api/rfq/prices`,
headers: {
'x-apikey': this.dexalotAuthToken,
},
},
tokensReqParams: {
url: `${DEXALOT_API_URL}/api/rfq/tokens`,
headers: {
'x-apikey': this.dexalotAuthToken,
params: {
chainid: this.network,
},
},
blacklistReqParams: {
Expand Down Expand Up @@ -505,6 +502,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
takerAmount:
side === SwapSide.SELL ? optimalSwapExchange.srcAmount : undefined,
userAddress: options.txOrigin,
chainid: this.network,
};

const rfq: RFQResponse = await this.dexHelper.httpRequest.post(
Expand All @@ -518,9 +516,10 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
'Missing quote data',
`RFQ ${swapIdentifier} ${JSON.stringify(rfq)}`,
);
} else if (!rfq.order.signature) {
} else if (!rfq.signature) {
this.generateRFQError('Missing signature', swapIdentifier);
}
rfq.order.signature = rfq.signature;

const { order } = rfq;

Expand Down
36 changes: 13 additions & 23 deletions src/dex/dexalot/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ type RFQOrder = {
taker: string;
makerAmount: string;
takerAmount: string;
signature: string;
signature?: string;
};

export type RFQResponse = {
order: RFQOrder;
signature: string;
};

export type RFQResponseError = {
Expand Down Expand Up @@ -52,8 +53,18 @@ export type PairDataMap = {
[pair: string]: PairData;
};

export type PairDataResp = {
base: string;
quote: string;
liquidityUSD: number;
baseAddress: string;
quoteAddress: string;
baseDecimals: number;
quoteDecimals: number;
};

export type DexalotPairsResponse = {
pairs: PairDataMap;
[pair: string]: PairDataResp;
};

type PriceData = {
Expand All @@ -73,25 +84,10 @@ export type TokenAddrDataMap = {
[symbol: string]: string;
};

type TokenData = {
symbol: string;
name: string;
description: string;
address: any;
decimals: number;
type: string;
};

export type TokenDataMap = {
[address: string]: Token;
};

export type DexalotTokensResponse = {
tokens: {
[token: string]: TokenData;
};
};

export type DexalotBlacklistResponse = {
blacklist: string[];
};
Expand All @@ -108,19 +104,13 @@ export type DexalotRateFetcherConfig = {
headers?: RequestHeaders;
params?: any;
};
tokensReqParams: {
url: string;
headers?: RequestHeaders;
params?: any;
};
blacklistReqParams: {
url: string;
headers?: RequestHeaders;
params?: any;
};
pairsIntervalMs: number;
pricesIntervalMs: number;
tokensIntervalMs: number;
blacklistIntervalMs: number;
pairsCacheKey: string;
pricesCacheKey: string;
Expand Down
13 changes: 8 additions & 5 deletions src/dex/dexalot/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ const pairValidator = joi.object({
base: joi.string().min(1).required(),
quote: joi.string().min(1).required(),
liquidityUSD: joi.number().min(0).required(),
baseAddress: joi.string().min(1).required(),
quoteAddress: joi.string().min(1).required(),
baseDecimals: joi.number().min(0).required(),
quoteDecimals: joi.number().min(0).required(),
});

export const pairsResponseValidator = joi.object({
pairs: joi.object().pattern(joi.string(), pairValidator),
});
export const pairsResponseValidator = joi
.object()
.pattern(joi.string(), pairValidator);

const orderbookRecordValidator = joi
.array()
.items(joi.string().min(1))
.length(2)
.required();
.length(2);

const orderbookValidator = joi.object({
bids: joi.array().items(orderbookRecordValidator).required(),
Expand Down

0 comments on commit c07f6c7

Please sign in to comment.