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 1 commit
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 { 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 @@ -157,7 +157,7 @@
await redisClient.lpush('notifications', JSON.stringify(newNotification));

res.status(200).send({ message: 'Notification added successfully', notification: newNotification });
} catch (error: any) {

Check warning on line 160 in src/index.ts

View workflow job for this annotation

GitHub Actions / Checks if ts and lint works

Unexpected any. Specify a different type
res.status(500).send({ error: error.message });
}
});
Expand All @@ -172,7 +172,7 @@
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 Expand Up @@ -335,7 +335,7 @@
await startMagicSquareQuest(req.body);

res.status(200).send({ message: 'Quest successfully started' });
} catch (error: any) {

Check warning on line 338 in src/index.ts

View workflow job for this annotation

GitHub Actions / Checks if ts and lint works

Unexpected any. Specify a different type
console.error(error);

if (error instanceof CodedError) {
Expand All @@ -349,7 +349,7 @@
app.get('/api/magic-square-quest/participants', basicAuth, async (req, res) => {
try {
res.status(200).send(await getMagicSquareQuestParticipants());
} catch (error: any) {

Check warning on line 352 in src/index.ts

View workflow job for this annotation

GitHub Actions / Checks if ts and lint works

Unexpected any. Specify a different type
console.error(error);

if (error instanceof CodedError) {
Expand All @@ -363,10 +363,10 @@
app.get('/api/signing-nonce', (req, res) => {
try {
const pkh = req.query.pkh;
if (!pkh || typeof pkh !== 'string') throw new Error('PKH is not a string');

Check warning on line 366 in src/index.ts

View workflow job for this annotation

GitHub Actions / Checks if ts and lint works

Unexpected value in conditional. A boolean expression is required

res.status(200).send(getSigningNonce(pkh));
} catch (error: any) {

Check warning on line 369 in src/index.ts

View workflow job for this annotation

GitHub Actions / Checks if ts and lint works

Unexpected any. Specify a different type
console.error(error);

if (error instanceof CodedError) {
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