Skip to content

Commit e24a9d1

Browse files
authored
Release everything to prod (#131)
Merge pull request #131 from madfish-solutions/development
2 parents db0f5e0 + 1fa0f20 commit e24a9d1

File tree

11 files changed

+219
-158
lines changed

11 files changed

+219
-158
lines changed

.env.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ THREE_ROUTE_API_AUTH_TOKEN=
1010
REDIS_URL=
1111
ADD_NOTIFICATION_USERNAME=
1212
ADD_NOTIFICATION_PASSWORD=
13-
TZPRO_API_KEY=

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"bignumber.js": "^9.1.0",
1616
"body-parser": "^1.20.2",
1717
"cors": "^2.8.5",
18-
"cross-fetch": "^3.1.5",
1918
"dotenv": "^9.0.2",
2019
"express": "^4.18.2",
2120
"firebase-admin": "^10.0.2",
2221
"ioredis": "^5.3.2",
22+
"lodash": "^4.17.21",
2323
"memoizee": "^0.4.15",
2424
"pino": "^6.11.2",
2525
"pino-http": "^5.5.0",

src/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ export const EnvVars = {
1212
THREE_ROUTE_API_AUTH_TOKEN: getEnv('THREE_ROUTE_API_AUTH_TOKEN'),
1313
REDIS_URL: getEnv('REDIS_URL'),
1414
ADD_NOTIFICATION_USERNAME: getEnv('ADD_NOTIFICATION_USERNAME'),
15-
ADD_NOTIFICATION_PASSWORD: getEnv('ADD_NOTIFICATION_PASSWORD'),
16-
TZPRO_API_KEY: getEnv('TZPRO_API_KEY')
15+
ADD_NOTIFICATION_PASSWORD: getEnv('ADD_NOTIFICATION_PASSWORD')
1716
};
1817

1918
for (const name in EnvVars) {

src/index.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import logger from './utils/logger';
3131
import { getSignedMoonPayUrl } from './utils/moonpay/get-signed-moonpay-url';
3232
import SingleQueryDataProvider from './utils/SingleQueryDataProvider';
3333
import { tezExchangeRateProvider } from './utils/tezos';
34-
import { tokensExchangeRatesProvider } from './utils/tokens';
34+
import { getExchangeRatesFromDB } from './utils/tokens';
3535

3636
const PINO_LOGGER = {
3737
logger: logger.child({ name: 'web' }),
@@ -150,7 +150,7 @@ app.post('/api/notifications', basicAuth, async (req, res) => {
150150

151151
await redisClient.lpush('notifications', JSON.stringify(newNotification));
152152

153-
res.status(200).send({ message: 'Notification added successfully' });
153+
res.status(200).send({ message: 'Notification added successfully', notification: newNotification });
154154
} catch (error: any) {
155155
res.status(500).send({ error: error.message });
156156
}
@@ -166,28 +166,18 @@ app.get('/api/abtest', (_, res) => {
166166
app.get('/api/exchange-rates/tez', makeProviderDataRequestHandler(tezExchangeRateProvider));
167167

168168
app.get('/api/exchange-rates', async (_req, res) => {
169-
const { data: tokensExchangeRates, error: tokensExchangeRatesError } = await getProviderStateWithTimeout(
170-
tokensExchangeRatesProvider
171-
);
169+
const tokensExchangeRates = await getExchangeRatesFromDB();
172170
const { data: tezExchangeRate, error: tezExchangeRateError } = await getProviderStateWithTimeout(
173171
tezExchangeRateProvider
174172
);
175-
if (tokensExchangeRatesError !== undefined) {
176-
return res.status(500).send({
177-
error: tokensExchangeRatesError.message
178-
});
179-
} else if (tezExchangeRateError !== undefined) {
173+
174+
if (tezExchangeRateError !== undefined) {
180175
return res.status(500).send({
181176
error: tezExchangeRateError.message
182177
});
183-
} else {
184-
if (tokensExchangeRates !== undefined && tezExchangeRate !== undefined) {
185-
return res.json([
186-
...tokensExchangeRates.map(({ ...restProps }) => restProps),
187-
{ exchangeRate: tezExchangeRate.toString() }
188-
]);
189-
}
190178
}
179+
180+
res.json([...tokensExchangeRates, { exchangeRate: tezExchangeRate.toString() }]);
191181
});
192182

193183
app.get('/api/moonpay-sign', async (_req, res) => {

src/interfaces/ticker.interface.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/utils/dapp-list-constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const dappList: DappList[] = [
2727
},
2828
{
2929
name: 'Yupana',
30-
dappUrl: 'https://yupana.finance',
30+
dappUrl: 'https://app.yupana.finance',
3131
type: DappType.DeFi,
3232
logo: 'https://pbs.twimg.com/profile_images/1450382829062393859/NSu06S5C_400x400.png',
3333
slug: 'yupana',

src/utils/fetch.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/utils/tezos.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { compose, MichelCodecPacker, Signer, TezosToolkit } from '@taquito/taquito';
22
import { tzip12 } from '@taquito/tzip12';
33
import { tzip16 } from '@taquito/tzip16';
4+
import { AxiosError } from 'axios';
45
import memoizee from 'memoizee';
56

6-
import { EnvVars } from '../config';
7-
import { ITicker } from '../interfaces/ticker.interface';
8-
import fetch from './fetch';
7+
import { getMarketsBySymbols } from './coingecko';
8+
import { isDefined } from './helpers';
9+
import logger from './logger';
910
import SingleQueryDataProvider from './SingleQueryDataProvider';
1011
import { BcdTokenData } from './tzkt';
1112

@@ -54,18 +55,28 @@ export const getStorage = memoizee(
5455
);
5556

5657
const getTezExchangeRate = async () => {
57-
const marketTickers = await fetch<Array<ITicker>>(
58-
`https://api.tzpro.io/markets/tickers?api_key=${EnvVars.TZPRO_API_KEY}`
59-
);
60-
const usdTickers = marketTickers.filter(e => e.quote === 'USD' && e.base === 'XTZ');
61-
// price index: use all USD ticker last prices with equal weight
62-
const vol = usdTickers.reduce((s, t) => s + t.volume_base, 0) || null;
63-
const price = vol === null ? 1 : usdTickers.reduce((s, t) => s + (t.last * t.volume_base) / vol, 0);
64-
65-
return price;
58+
try {
59+
const [xtzMarket] = await getMarketsBySymbols(['xtz']);
60+
61+
return xtzMarket.current_price;
62+
} catch (e) {
63+
if (!(e instanceof AxiosError)) {
64+
logger.error('Request for TEZ exchange rate failed with unknown error');
65+
} else if (isDefined(e.response) && isDefined(e.response.data)) {
66+
logger.error(
67+
`Request for TEZ exchange rate failed with status ${e.response.status} and message ${e.response.data}`
68+
);
69+
} else if (isDefined(e.response) && isDefined(e.response.status)) {
70+
logger.error(`Request for TEZ exchange rate failed with status ${e.response.status}`);
71+
} else {
72+
logger.error('Request for TEZ exchange rate failed without response');
73+
}
74+
75+
throw e;
76+
}
6677
};
6778

68-
export const tezExchangeRateProvider = new SingleQueryDataProvider(30000, getTezExchangeRate);
79+
export const tezExchangeRateProvider = new SingleQueryDataProvider(60000, getTezExchangeRate);
6980

7081
export class MetadataParseError extends Error {}
7182

src/utils/three-route.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface ThreeRouteChain {
2525
}
2626

2727
// TODO: add axios adapter and change type if precision greater than of standard js number type is necessary
28-
export interface ThreeRouteSwapResponse {
28+
export interface ThreeRouteClassicSwapResponse {
2929
input: number;
3030
output: number;
3131
chains: ThreeRouteChain[];
@@ -34,8 +34,8 @@ export interface ThreeRouteSwapResponse {
3434
export interface ThreeRouteSirsSwapResponse {
3535
input: number;
3636
output: number;
37-
tzbtcChain: ThreeRouteSwapResponse;
38-
xtzChain: ThreeRouteSwapResponse;
37+
tzbtcChain: ThreeRouteClassicSwapResponse;
38+
xtzChain: ThreeRouteClassicSwapResponse;
3939
}
4040

4141
interface ThreeRouteTokenCommon {
@@ -98,11 +98,13 @@ export interface ThreeRouteDex {
9898

9999
type ThreeRouteQueryParams = object | SwapQueryParams;
100100
type ThreeRouteQueryResponse =
101-
| ThreeRouteSwapResponse
101+
| ThreeRouteClassicSwapResponse
102102
| ThreeRouteSirsSwapResponse
103103
| ThreeRouteDex[]
104104
| ThreeRouteToken[];
105105

106+
export type ThreeRouteSwapResponse = ThreeRouteClassicSwapResponse | ThreeRouteSirsSwapResponse;
107+
106108
export const THREE_ROUTE_SIRS_SYMBOL = 'SIRS';
107109

108110
const threeRouteBuildQueryFn = makeBuildQueryFn<ThreeRouteQueryParams, ThreeRouteQueryResponse>(
@@ -111,18 +113,17 @@ const threeRouteBuildQueryFn = makeBuildQueryFn<ThreeRouteQueryParams, ThreeRout
111113
{ headers: { Authorization: `Basic ${EnvVars.THREE_ROUTE_API_AUTH_TOKEN}` } }
112114
);
113115

114-
export const getThreeRouteSwap = threeRouteBuildQueryFn<
115-
SwapQueryParams,
116-
ThreeRouteSwapResponse | ThreeRouteSirsSwapResponse
117-
>(({ inputTokenSymbol, outputTokenSymbol, realAmount }) => {
118-
const isSirsSwap = inputTokenSymbol === THREE_ROUTE_SIRS_SYMBOL || outputTokenSymbol === THREE_ROUTE_SIRS_SYMBOL;
116+
export const getThreeRouteSwap = threeRouteBuildQueryFn<SwapQueryParams, ThreeRouteSwapResponse>(
117+
({ inputTokenSymbol, outputTokenSymbol, realAmount }) => {
118+
const isSirsSwap = inputTokenSymbol === THREE_ROUTE_SIRS_SYMBOL || outputTokenSymbol === THREE_ROUTE_SIRS_SYMBOL;
119119

120-
return `/${isSirsSwap ? 'swap-sirs' : 'swap'}/${inputTokenSymbol}/${outputTokenSymbol}/${realAmount}`;
121-
});
120+
return `/${isSirsSwap ? 'swap-sirs' : 'swap'}/${inputTokenSymbol}/${outputTokenSymbol}/${realAmount}`;
121+
}
122+
);
122123

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

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

127-
export const getChains = (response: ThreeRouteSwapResponse | ThreeRouteSirsSwapResponse) =>
128+
export const getChains = (response: ThreeRouteSwapResponse) =>
128129
'chains' in response ? response.chains : [...response.xtzChain.chains, ...response.tzbtcChain.chains];

0 commit comments

Comments
 (0)