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

feat: call db to retrieve permits instead of parsing github comments #164

Merged
merged 12 commits into from
Feb 21, 2024
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
8 changes: 6 additions & 2 deletions static/scripts/audit-report/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import {
getGitHubUrlPartsArray,
getRandomAPIKey,
getRandomRpcUrl,
getOptimalRPC,
isValidUrl,
parseRepoUrl,
populateTable,
primaryRateLimitHandler,
RateLimitOptions,
secondaryRateLimitHandler,
} from "./helpers";
import { ChainScanResult, ElemInterface, GitHubUrlParts, GoDBSchema, ObserverKeys, QuickImport, SavedData, StandardInterface, TxData } from "./types";
=======
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you need to redo fixing the merge conflict

import { getTxInfo } from "./utils/getTransaction";

const supabase = createClient(process.env.SUPABASE_URL!, process.env.SUPABASE_KEY!);
Expand Down Expand Up @@ -468,8 +472,8 @@ const rpcFetcher = async () => {
const data = await rpcQueue.read();
if (data) {
const { hash, chain } = data;

const txInfo = await getTxInfo(hash, getRandomRpcUrl(chain), chain);
const providerUrl = await getOptimalRPC(chain);
const txInfo = await getTxInfo(hash, providerUrl, chain);

if (txInfo.input.startsWith(permitTransferFromSelector)) {
const decodedFunctionData = permit2Interface.decodeFunctionData(permitFunctionName, txInfo.input);
Expand Down
39 changes: 39 additions & 0 deletions static/scripts/audit-report/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,45 @@ export const getRandomRpcUrl = (chain: Chain): string => {
return urls[randomIndex];
};

const verifyBlock = (data: DataType) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to merge in the latest lint rules ASAP from ts-template. We normally use named functions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code got merged from the dev branch, not on me 😅

try {
const { jsonrpc, id, result } = data;
const { number, timestamp, hash } = result;
return jsonrpc === "2.0" && id === 1 && parseInt(number, 16) > 0 && parseInt(timestamp, 16) > 0 && hash.match(/[0-9|a-f|A-F|x]/gm)?.join("").length === 66;
} catch (error) {
return false;
}
};

export const getOptimalRPC = async (chain: Chain): Promise<string> => {
const promises = RPC_URLS[chain].map(async (baseURL: string) => {
try {
const startTime = performance.now();
const API = axios.create({
baseURL,
headers: RPC_HEADER,
});

const { data } = await API.post("", RPC_BODY);
const endTime = performance.now();
const latency = endTime - startTime;
if (await verifyBlock(data)) {
return Promise.resolve({
latency,
baseURL,
});
} else {
return Promise.reject();
}
} catch (error) {
return Promise.reject();
}
});

const { baseURL: optimalRPC } = await Promise.any(promises);
return optimalRPC;
};

export const parseRepoUrl = (issueUrl: string): [string, string] => {
const match = issueUrl.match(/github\.com\/([^/]+)\/([^/]+)\/issues\/\d+/i);
if (match) {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.