Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihal committed Dec 2, 2020
1 parent e7da910 commit 246674a
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 150 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"semi": false,
"semi": true,
"printWidth": 100,
"singleQuote": true
}
31 changes: 22 additions & 9 deletions components/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ interface ListProps {
const sortByDaily = (a: FeeData, b: FeeData) => b.oneDay - a.oneDay;
const sortByWeekly = (a: FeeData, b: FeeData) => b.sevenDayMA - a.sevenDayMA;


const List: React.FC<ListProps> = ({ data }) => {
const [sort, setSort] = useState('daily');

Expand All @@ -32,11 +31,23 @@ const List: React.FC<ListProps> = ({ data }) => {
<div
className={`item ${protocol.category}`}
key={protocol.id}
style={{ backgroundImage: icons[protocol.id] ? `url('${icons[protocol.id]}')` : undefined }}
style={{
backgroundImage: icons[protocol.id] ? `url('${icons[protocol.id]}')` : undefined,
}}
>
<div className="name">{protocol.name || protocolNames[protocol.id]}</div>
<div className="amount">{protocol.oneDay.toLocaleString('en-US', { style: 'currency', currency: 'USD' })}</div>
<div className="amount">{protocol.sevenDayMA.toLocaleString('en-US', { style: 'currency', currency: 'USD' })}</div>
<div className="amount">
{protocol.oneDay.toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
})}
</div>
<div className="amount">
{protocol.sevenDayMA.toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
})}
</div>
</div>
))}

Expand Down Expand Up @@ -74,10 +85,11 @@ const List: React.FC<ListProps> = ({ data }) => {
}
.item.app {
background-color: #FAD3F6;
background-color: #fad3f6;
}
.item > div, .header > div {
.item > div,
.header > div {
padding: 16px 32px;
}
Expand Down Expand Up @@ -111,13 +123,14 @@ const List: React.FC<ListProps> = ({ data }) => {
background-position: 6px center;
}
.item > div, .header > div {
.item > div,
.header > div {
padding: 8px 2px;
}
}
`}</style>
</div>
)
}
);
};

export default List;
6 changes: 3 additions & 3 deletions data/balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export async function getBalancerData(): Promise<FeeData> {
const yesterdayBlock = getBlockDaysAgo(1);
const weekAgoBlock = getBlockDaysAgo(7);

const request = await fetch("https://api.thegraph.com/subgraphs/name/bonustrack/balancer", {
const request = await fetch('https://api.thegraph.com/subgraphs/name/bonustrack/balancer', {
headers: {
"content-type": "application/json",
'content-type': 'application/json',
},
body: JSON.stringify({
query: `{
Expand All @@ -24,7 +24,7 @@ export async function getBalancerData(): Promise<FeeData> {
}`,
variables: null,
}),
method: "POST",
method: 'POST',
});

const { data } = await request.json();
Expand Down
20 changes: 13 additions & 7 deletions data/curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,30 @@ const priceCache: { [symbol: string]: number } = { usd: 1 };

const getPrice = async (name: string): Promise<number> => {
if (!priceCache[name]) {
const request = await fetch(`https://api.coingecko.com/api/v3/simple/price?ids=${name}&vs_currencies=usd`);
const request = await fetch(
`https://api.coingecko.com/api/v3/simple/price?ids=${name}&vs_currencies=usd`
);
const response = await request.json();
priceCache[name] = response[name].usd;
}

return priceCache[name];
}
};

export async function getCurveData(): Promise<FeeData> {
const todayBlock = getBlockDaysAgo(0);
const yesterdayBlock = getBlockDaysAgo(1);
const weekAgoBlock = getBlockDaysAgo(7);

const request = await fetch("https://api.thegraph.com/subgraphs/name/blocklytics/curve", {
const request = await fetch('https://api.thegraph.com/subgraphs/name/blocklytics/curve', {
headers: {
"content-type": "application/json",
'content-type': 'application/json',
},
body: JSON.stringify({
query: `{
${pools.map((pool: Pool) => `
${pools
.map(
(pool: Pool) => `
${pool.name}_current: exchange(id: "${pool.address}", block: {number: ${todayBlock}}) {
totalUnderlyingVolumeDecimal
}
Expand All @@ -73,11 +77,13 @@ export async function getCurveData(): Promise<FeeData> {
${pool.name}_week_ago: exchange(id: "${pool.address}", block: {number: ${weekAgoBlock}}) {
totalUnderlyingVolumeDecimal
}
`).join('')}
`
)
.join('')}
}`,
variables: null,
}),
method: "POST",
method: 'POST',
});

const { data } = await request.json();
Expand Down
93 changes: 62 additions & 31 deletions data/feeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ export interface FeeData {
}

export async function getFeeData(id: string): Promise<FeeData> {
const startDate = new Date(Date.now() - (86400 * 1000 * 7));
const startDateString = `${startDate.getFullYear()}-${(startDate.getMonth() + 1).toString().padStart(2, '0')}-${startDate.getDate().toString().padStart(2, '0')}`;
const request = await fetch(`https://community-api.coinmetrics.io/v2/assets/${id}/metricdata?metrics=FeeTotUSD&start=${startDateString}`);
const startDate = new Date(Date.now() - 86400 * 1000 * 7);
const startDateString = `${startDate.getFullYear()}-${(startDate.getMonth() + 1)
.toString()
.padStart(2, '0')}-${startDate.getDate().toString().padStart(2, '0')}`;
const request = await fetch(
`https://community-api.coinmetrics.io/v2/assets/${id}/metricdata?metrics=FeeTotUSD&start=${startDateString}`
);
const { metricData } = await request.json();
const sevenDayMA = metricData.series.reduce((total: number, value: any) => total + parseFloat(value.values[0]), 0) / metricData.series.length;
const sevenDayMA =
metricData.series.reduce(
(total: number, value: any) => total + parseFloat(value.values[0]),
0
) / metricData.series.length;

return {
id,
Expand All @@ -26,41 +34,51 @@ export async function getFeeData(id: string): Promise<FeeData> {
};
}

const last7Days = () => [...new Array(7)].map((_, num) => Math.floor(Date.now() / 1000 / 86400 - num - 1) * 86400);

const last7Days = () =>
[...new Array(7)].map((_, num) => Math.floor(Date.now() / 1000 / 86400 - num - 1) * 86400);

export async function getSushiswapData(): Promise<FeeData> {
const request = await fetch("https://api.thegraph.com/subgraphs/name/zippoxer/sushiswap-subgraph-fork", {
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
query: `{
const request = await fetch(
'https://api.thegraph.com/subgraphs/name/zippoxer/sushiswap-subgraph-fork',
{
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
query: `{
uniswapDayDatas(where:{date_in: ${JSON.stringify(last7Days())}}) {
date
dailyVolumeUSD
}
}`,
variables: null
}),
"method": "POST",
});
variables: null,
}),
method: 'POST',
}
);
const { data } = await request.json();

const sevenDayMA = data.uniswapDayDatas.reduce((total: number, { dailyVolumeUSD }: any) => total + parseFloat(dailyVolumeUSD), 0) * 0.003 / data.uniswapDayDatas.length;
const sevenDayMA =
(data.uniswapDayDatas.reduce(
(total: number, { dailyVolumeUSD }: any) => total + parseFloat(dailyVolumeUSD),
0
) *
0.003) /
data.uniswapDayDatas.length;

return {
id: 'sushiswap',
category: 'app',
sevenDayMA,
oneDay: parseFloat(data.uniswapDayDatas[data.uniswapDayDatas.length - 1].dailyVolumeUSD) * 0.003,
oneDay:
parseFloat(data.uniswapDayDatas[data.uniswapDayDatas.length - 1].dailyVolumeUSD) * 0.003,
};
}

export async function getUniswapV2Data(): Promise<FeeData> {
const request = await fetch("https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2", {
const request = await fetch('https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2', {
headers: {
"content-type": "application/json",
'content-type': 'application/json',
},
body: JSON.stringify({
query: `{
Expand All @@ -69,27 +87,33 @@ export async function getUniswapV2Data(): Promise<FeeData> {
dailyVolumeUSD
}
}`,
variables: null
variables: null,
}),
"method": "POST",
method: 'POST',
});
const { data } = await request.json();

const sevenDayMA = data.uniswapDayDatas.reduce((total: number, { dailyVolumeUSD }: any) => total + parseFloat(dailyVolumeUSD), 0) * 0.003 / data.uniswapDayDatas.length;
const sevenDayMA =
(data.uniswapDayDatas.reduce(
(total: number, { dailyVolumeUSD }: any) => total + parseFloat(dailyVolumeUSD),
0
) *
0.003) /
data.uniswapDayDatas.length;

return {
id: 'uniswap-v2',
category: 'app',
sevenDayMA,
oneDay: parseFloat(data.uniswapDayDatas[data.uniswapDayDatas.length - 1].dailyVolumeUSD) * 0.003,
oneDay:
parseFloat(data.uniswapDayDatas[data.uniswapDayDatas.length - 1].dailyVolumeUSD) * 0.003,
};
}


export async function getUniswapV1Data(): Promise<FeeData> {
const request = await fetch("https://api.thegraph.com/subgraphs/name/graphprotocol/uniswap", {
const request = await fetch('https://api.thegraph.com/subgraphs/name/graphprotocol/uniswap', {
headers: {
"content-type": "application/json",
'content-type': 'application/json',
},
body: JSON.stringify({
query: `{
Expand All @@ -98,18 +122,25 @@ export async function getUniswapV1Data(): Promise<FeeData> {
dailyVolumeInUSD
}
}`,
variables: null
variables: null,
}),
"method": "POST",
method: 'POST',
});
const { data } = await request.json();

const sevenDayMA = data.uniswapDayDatas.reduce((total: number, { dailyVolumeInUSD }: any) => total + parseFloat(dailyVolumeInUSD), 0) * 0.003 / data.uniswapDayDatas.length;
const sevenDayMA =
(data.uniswapDayDatas.reduce(
(total: number, { dailyVolumeInUSD }: any) => total + parseFloat(dailyVolumeInUSD),
0
) *
0.003) /
data.uniswapDayDatas.length;

return {
id: 'uniswap-v1',
category: 'app',
sevenDayMA,
oneDay: parseFloat(data.uniswapDayDatas[data.uniswapDayDatas.length - 1].dailyVolumeInUSD) * 0.003,
oneDay:
parseFloat(data.uniswapDayDatas[data.uniswapDayDatas.length - 1].dailyVolumeInUSD) * 0.003,
};
}
34 changes: 25 additions & 9 deletions data/omen.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FeeData} from './feeData';
import { FeeData } from './feeData';
import { getBlockDaysAgo } from './time-lib';

export async function getOmenData(): Promise<FeeData> {
const request = await fetch('https://api.thegraph.com/subgraphs/name/gnosis/omen', {
headers: {
"content-type": "application/json",
'content-type': 'application/json',
},
"body": JSON.stringify({
body: JSON.stringify({
query: `query volumeOverTime($today: Int!, $yesterday: Int!, $weekAgo: Int!){
today: fixedProductMarketMakers(block: {number: $today}, first: 1000) {
id
Expand All @@ -29,22 +29,38 @@ export async function getOmenData(): Promise<FeeData> {
yesterday: getBlockDaysAgo(1),
weekAgo: getBlockDaysAgo(7),
},
operationName: "volumeOverTime"
operationName: 'volumeOverTime',
}),
method: "POST",
method: 'POST',
});

const { data } = await request.json();

const markets: { [id: string]: { today?: number; yesterday?: number; weekAgo?: number; fee?: number } } = {};
const markets: {
[id: string]: {
today?: number;
yesterday?: number;
weekAgo?: number;
fee?: number;
};
} = {};
for (const market of data.today) {
markets[market.id] = { today: parseFloat(market.usdVolume), fee: parseInt(market.fee) / 1000000000000000000 };
markets[market.id] = {
today: parseFloat(market.usdVolume),
fee: parseInt(market.fee) / 1000000000000000000,
};
}
for (const market of data.yesterday) {
markets[market.id] = { ...markets[market.id], yesterday: parseFloat(market.usdVolume) };
markets[market.id] = {
...markets[market.id],
yesterday: parseFloat(market.usdVolume),
};
}
for (const market of data.weekAgo) {
markets[market.id] = { ...markets[market.id], weekAgo: parseFloat(market.usdVolume) };
markets[market.id] = {
...markets[market.id],
weekAgo: parseFloat(market.usdVolume),
};
}

let oneDay = 0;
Expand Down
Loading

0 comments on commit 246674a

Please sign in to comment.