Skip to content

Commit

Permalink
[APR] chore: run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesfracari committed May 20, 2024
1 parent 49d65d9 commit e947baa
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion apps/chainlink-datafeeds-api/app/api/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function GET() {
const rawHTML = await res.text();

const match = rawHTML.match(
/<script id="__NEXT_DATA__" type="application\/json">(.*?)<\/script>/
/<script id="__NEXT_DATA__" type="application\/json">(.*?)<\/script>/,
);

if (!match?.length) return Response.json({ error: "No data found" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const extractTokenDecimals = async () => {
and(
isNull(tokens.decimals),
isNotNull(tokens.address),
isNotNull(tokens.networkSlug)
)
isNotNull(tokens.networkSlug),
),
);

if (tokensWithoutDecimals.length === 0) return;
Expand All @@ -58,7 +58,7 @@ export const extractTokenDecimals = async () => {
logIfVerbose(`Error fetching decimals for ${address} on ${network}`);
return null;
}
})
}),
)
).filter(Boolean) as {
address: Address;
Expand Down
24 changes: 12 additions & 12 deletions packages/balancer-apr/src/lib/etl/extract/fetchTokenPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,34 @@ export async function fetchTokenPrices() {
t.network_slug) sq
WHERE
sq.timestamp < now() - interval '1 day';
`)
`),
);

const allTokenPrices = await Promise.all(
tokenList.map(({ network_slug: networkSlug, address, timestamp }, idx) => {
return throttle(async () => {
logIfVerbose(
`${networkSlug}:${address}:${dateToEpoch(
timestamp
)} Fetching prices: ${idx + 1}/${tokenList.length}`
timestamp,
)} Fetching prices: ${idx + 1}/${tokenList.length}`,
);
try {
const prices = await fetchTokenPrice(
networkSlug,
address!,
timestamp!
timestamp!,
);
return prices;
} catch (error) {
logIfVerbose(
`${networkSlug}:${address}:${dateToEpoch(
timestamp
timestamp,
// @ts-expect-error
)} Failed fetching price: ${error.message}`
)} Failed fetching price: ${error.message}`,
);
}
})();
})
}),
);

await addToTable(tokenPrices, allTokenPrices.filter(Boolean).flat());
Expand Down Expand Up @@ -122,25 +122,25 @@ function adjustTimestamp(entryTimestamp: number) {
export async function fetchTokenPrice(
network: string,
tokenAddress: string,
start: Date
start: Date,
) {
if (!tokenAddress || !network || !start) return [];

let prices;
try {
logIfVerbose(
`${network}:${tokenAddress}:${dateToEpoch(start)} Fetching price`
`${network}:${tokenAddress}:${dateToEpoch(start)} Fetching price`,
);
prices = await DefiLlamaAPI.getHistoricalPrice(
start,
`${getNetworkSlug(network)}:${tokenAddress}`
`${getNetworkSlug(network)}:${tokenAddress}`,
);
} catch (error) {
logIfVerbose(
`${network}:${tokenAddress}:${dateToEpoch(
start
start,
// @ts-expect-error
)} Failed fetching price: ${error.message}`
)} Failed fetching price: ${error.message}`,
);
// @ts-expect-error
if (error?.message?.includes?.("No price data available")) return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const throttle = pThrottle({
const WEEK = 86400n * 7n;

export const getGaugeWorkingSupply = async (
gaugeAddressNetworkTimestampBlockTuples: [Address, string, number, number][]
gaugeAddressNetworkTimestampBlockTuples: [Address, string, number, number][],
) => {
if (gaugeAddressNetworkTimestampBlockTuples.length === 0) return [];

Expand All @@ -63,7 +63,7 @@ export const getGaugeWorkingSupply = async (
logIfVerbose(
`${network}:${address}:${timestamp} Fetching working supply, ${
idx + 1
}/${gaugeAddressNetworkTimestampBlockTuples.length}`
}/${gaugeAddressNetworkTimestampBlockTuples.length}`,
);

const publicClient = publicClients[network];
Expand All @@ -83,7 +83,7 @@ export const getGaugeWorkingSupply = async (

if (network !== "ethereum") {
promises.push(
gauge.read.inflation_rate([BigInt(timestamp) / WEEK])
gauge.read.inflation_rate([BigInt(timestamp) / WEEK]),
);
}

Expand All @@ -94,23 +94,23 @@ export const getGaugeWorkingSupply = async (

if (results[0].status === "rejected") {
logIfVerbose(
`${network}:${address}:${timestamp} Error: ${results[0].reason.shortMessage}`
`${network}:${address}:${timestamp} Error: ${results[0].reason.shortMessage}`,
);
} else if (results[0]) {
workingSupply = formatUnits(results[0].value, 18);
}

if (results[1].status === "rejected") {
logIfVerbose(
`${network}:${address}:${timestamp} Error: ${results[1].reason.shortMessage}`
`${network}:${address}:${timestamp} Error: ${results[1].reason.shortMessage}`,
);
} else if (results[1]) {
totalSupply = formatUnits(results[1].value, 18);
}

if (results[2] && results[2].status === "rejected") {
logIfVerbose(
`${network}:${address}:${timestamp} Error: ${results[2]?.reason?.shortMessage}`
`${network}:${address}:${timestamp} Error: ${results[2]?.reason?.shortMessage}`,
);
} else if (results[2]) {
inflationRate = formatUnits(results[2].value, 18);
Expand All @@ -124,13 +124,13 @@ export const getGaugeWorkingSupply = async (
logIfVerbose(
`Error fetching working supply ${network}:${address}:${timestamp}`,
// @ts-expect-error
e
e,
);
return [null, null, null, null];
}
})();
}
)
},
),
);

return responses.map(([_, workingSupply, totalSupply, inflationRate]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const throttle = pThrottle({
});

export const getPoolRelativeWeights = async (
gaugeAddressTimestampTuples: [Address, number][]
gaugeAddressTimestampTuples: [Address, number][],
) => {
if (gaugeAddressTimestampTuples.length === 0) return [];

Expand All @@ -61,7 +61,7 @@ export const getPoolRelativeWeights = async (
logIfVerbose(
`${address}:${timestamp} Fetching pool relative weight, ${
idx + 1
}/${gaugeAddressTimestampTuples.length}`
}/${gaugeAddressTimestampTuples.length}`,
);
return await gaugesController.read.gauge_relative_weight([
address,
Expand All @@ -71,12 +71,12 @@ export const getPoolRelativeWeights = async (
logIfVerbose(
`Error fetching relative weight ${address}:${timestamp}`,
// @ts-expect-error
e
e,
);
return null;
}
})();
})
}),
);

return responses.map((response, index) => {
Expand Down
22 changes: 11 additions & 11 deletions packages/balancer-apr/src/lib/etl/extract/getRates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const throttle = pThrottle({
});

export const getRates = async (
rateProviderAddressBlocksTuples: [Address, string, number, Date][]
rateProviderAddressBlocksTuples: [Address, string, number, Date][],
) => {
if (rateProviderAddressBlocksTuples.length === 0) return [];

Expand Down Expand Up @@ -50,39 +50,39 @@ export const getRates = async (
} else if (message.includes(`returned no data ("0x")`)) {
logIfVerbose(
`${network}:${block}(${dateToEpoch(
timestamp
)}):${address}.getRate - error: returned no data ("0x")`
timestamp,
)}):${address}.getRate - error: returned no data ("0x")`,
);
return null;
} else if (
message.includes(`The contract function "getRate" reverted`)
) {
logIfVerbose(
`${network}:${block}(${dateToEpoch(
timestamp
)}):${address}.getRate - error: The contract function "getRate" reverted`
timestamp,
)}):${address}.getRate - error: The contract function "getRate" reverted`,
);
return null;
} else if (
message.includes(
`Cannot decode zero data ("0x") with ABI parameters.`
`Cannot decode zero data ("0x") with ABI parameters.`,
)
) {
logIfVerbose(
`${network}:${block}(${dateToEpoch(
timestamp
)}):${address}.getRate - error: Cannot decode zero data ("0x") with ABI parameters.`
timestamp,
)}):${address}.getRate - error: Cannot decode zero data ("0x") with ABI parameters.`,
);
return null;
}
logIfVerbose(
`Error getting rate for ${address} on ${network}:${block}: ${message}`
`Error getting rate for ${address} on ${network}:${block}: ${message}`,
);
return null;
}
})();
}
)
},
),
);

return responses.map((response, index) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/balancer-apr/src/lib/etl/load/loadAPRs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "dotenv/config";

import { sql } from "drizzle-orm";
import { blockListRateProvider } from "lib/balancer/data/blockListRateProvider";
import { logIfVerbose } from "lib/logIfVerbose";

import { db } from "../../../db/index";
import { blockListRateProvider } from "lib/balancer/data/blockListRateProvider";

export async function loadAPRs() {
await Promise.all([
Expand Down Expand Up @@ -222,9 +222,9 @@ async function loadTokenYieldNonWeightedAPR() {
blockListRateProvider
.map(
(item: { rateProviderAddress: unknown }) =>
`'${item.rateProviderAddress}'`
`'${item.rateProviderAddress}'`,
)
.join(", ")
.join(", "),
)})
) AS subquery ON subquery.timestamp = pool_snapshots.timestamp
AND subquery.token_address = pool_tokens.token_address
Expand Down Expand Up @@ -289,9 +289,9 @@ async function loadTokenYieldWeightedAPR() {
blockListRateProvider
.map(
(item: { rateProviderAddress: unknown }) =>
`'${item.rateProviderAddress}'`
`'${item.rateProviderAddress}'`,
)
.join(", ")
.join(", "),
)})
) AS subquery ON subquery.timestamp = pool_snapshots.timestamp
AND subquery.token_address = pool_tokens.token_address
Expand Down

0 comments on commit e947baa

Please sign in to comment.