Skip to content

Commit

Permalink
Merge pull request #147 from madfish-solutions/development
Browse files Browse the repository at this point in the history
TW-1282: Use /prices 3route API entry (#143)
  • Loading branch information
lourenc authored Feb 20, 2024
2 parents e292940 + 805ba10 commit d42b77e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 369 deletions.
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

0 comments on commit d42b77e

Please sign in to comment.