Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-1282 Use /prices 3route API entry #143

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { getSignedMoonPayUrl } from './utils/moonpay/get-signed-moonpay-url';
import { getSigningNonce } from './utils/signing-nonce';
import SingleQueryDataProvider from './utils/SingleQueryDataProvider';
import { tezExchangeRateProvider } from './utils/tezos';
import { getExchangeRatesFromDB } from './utils/tokens';
import { getExchangeRates } from './utils/tokens';

const PINO_LOGGER = {
logger: logger.child({ name: 'web' }),
Expand Down Expand Up @@ -172,7 +172,7 @@ app.get('/api/abtest', (_, res) => {
app.get('/api/exchange-rates/tez', makeProviderDataRequestHandler(tezExchangeRateProvider));

app.get('/api/exchange-rates', async (_req, res) => {
const tokensExchangeRates = await getExchangeRatesFromDB();
const tokensExchangeRates = await getExchangeRates();
const { data: tezExchangeRate, error: tezExchangeRateError } = await getProviderStateWithTimeout(
tezExchangeRateProvider
);
Expand Down
57 changes: 0 additions & 57 deletions src/utils/block-finder.ts

This file was deleted.

37 changes: 4 additions & 33 deletions src/utils/three-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ export interface ThreeRouteChain {
hops: ThreeRouteHop[];
}

// TODO: add axios adapter and change type if precision greater than of standard js number type is necessary
export interface ThreeRouteClassicSwapResponse {
input: number;
output: number;
chains: ThreeRouteChain[];
}

export interface ThreeRouteSirsSwapResponse {
input: number;
output: number;
tzbtcChain: ThreeRouteClassicSwapResponse;
xtzChain: ThreeRouteClassicSwapResponse;
}

interface ThreeRouteTokenCommon {
id: number;
symbol: string;
Expand Down Expand Up @@ -96,14 +82,10 @@ export interface ThreeRouteDex {
token2: ThreeRouteToken;
}

type ThreeRouteQueryParams = object | SwapQueryParams;
type ThreeRouteQueryResponse =
| ThreeRouteClassicSwapResponse
| ThreeRouteSirsSwapResponse
| ThreeRouteDex[]
| ThreeRouteToken[];
type ThreeRouteExchangeRates = Record<string, { ask: number; bid: number }>;

export type ThreeRouteSwapResponse = ThreeRouteClassicSwapResponse | ThreeRouteSirsSwapResponse;
type ThreeRouteQueryParams = object | SwapQueryParams;
type ThreeRouteQueryResponse = ThreeRouteExchangeRates | ThreeRouteToken[];

export const THREE_ROUTE_SIRS_SYMBOL = 'SIRS';

Expand All @@ -113,17 +95,6 @@ const threeRouteBuildQueryFn = makeBuildQueryFn<ThreeRouteQueryParams, ThreeRout
{ headers: { Authorization: `Basic ${EnvVars.THREE_ROUTE_API_AUTH_TOKEN}` } }
);

export const getThreeRouteSwap = threeRouteBuildQueryFn<SwapQueryParams, ThreeRouteSwapResponse>(
({ inputTokenSymbol, outputTokenSymbol, realAmount }) => {
const isSirsSwap = inputTokenSymbol === THREE_ROUTE_SIRS_SYMBOL || outputTokenSymbol === THREE_ROUTE_SIRS_SYMBOL;

return `/${isSirsSwap ? 'swap-sirs' : 'swap'}/${inputTokenSymbol}/${outputTokenSymbol}/${realAmount}`;
}
);

export const getThreeRouteDexes = threeRouteBuildQueryFn<object, ThreeRouteDex[]>('/dexes', []);

export const getThreeRouteTokens = threeRouteBuildQueryFn<object, ThreeRouteToken[]>('/tokens', []);

export const getChains = (response: ThreeRouteSwapResponse) =>
'chains' in response ? response.chains : [...response.xtzChain.chains, ...response.tzbtcChain.chains];
export const getThreeRouteExchangeRates = threeRouteBuildQueryFn<object, ThreeRouteExchangeRates>('/prices', []);
Loading
Loading