-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/tenderly simulations #13
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c0d1d62
feat(web): tenderly-simulations
tractorss 424c1ab
chore(web): rename-context-file
tractorss ff9ddb2
fix(web): separate-simulations-link-per-list
tractorss d267938
feat(web): contract-abi-fetching
tractorss d9ad34b
chore(web): rabbit-review
tractorss 89466c6
chore(web): update-ui-lib
tractorss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,11 @@ | ||
| export NEXT_PUBLIC_APP_DEPLOYMENT=devnet | ||
| export NEXT_PUBLIC_REOWN_PROJECT_ID="abcabcabcabcabcabc" | ||
| export NEXT_PUBLIC_ALCHEMY_API_KEY="abcabcabcabcabcabc" | ||
| export NEXT_PUBLIC_COURT_SITE="https://dev--kleros-v2-testnet.netlify.app/#" | ||
| export NEXT_PUBLIC_COURT_SITE="https://dev--kleros-v2-testnet.netlify.app/#" | ||
|
|
||
| # tenderly simulations | ||
| export TENDERLY_ACCOUNT_NAME="test" | ||
| export TENDERLY_PROJECT_NAME="governor-test" | ||
| export TENDERLY_ACCESS_KEY="abcabcabcabcabcabc" | ||
| export ALLOWED_ORIGINS="http://localhost:3000" | ||
| export ETHERSCAN_API_KEY="abcabcabcabcabcabc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
web/src/app/(main)/governor/[governorAddress]/MyLists/Header.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { isAddress } from "viem"; | ||
|
|
||
| import { isUndefined } from "@/utils"; | ||
| import { checkRateLimit } from "@/utils/simulateRouteUtils"; | ||
|
|
||
| export async function GET(request: NextRequest) { | ||
| const ip = request.ip || request.headers.get("x-forwarded-for") || "unknown"; | ||
|
|
||
| const rateLimitCheck = checkRateLimit(ip); | ||
| if (!rateLimitCheck.allowed) { | ||
| return NextResponse.json( | ||
| { error: "Rate limit exceeded. Try again later." }, | ||
| { | ||
| status: 429, | ||
| headers: { | ||
| "Retry-After": Math.ceil((rateLimitCheck.resetTime || 0 - Date.now()) / 1000).toString(), | ||
| }, | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| const searchParams = request.nextUrl.searchParams; | ||
| const networkId = searchParams.get("networkId"); | ||
| const contractAddress = searchParams.get("contractAddress"); | ||
|
|
||
| if (!networkId || !contractAddress) { | ||
| return NextResponse.json({ error: "Missing required parameters: networkId and contractAddress" }, { status: 400 }); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!isAddress(contractAddress)) { | ||
| return NextResponse.json({ error: "Invalid contract address format" }, { status: 400 }); | ||
| } | ||
|
|
||
| try { | ||
| if (isUndefined(process.env.TENDERLY_ACCESS_KEY)) { | ||
| throw new Error("Failed to fetch contract details: Environment variables not configured."); | ||
| } | ||
|
|
||
| // Fetch contract details from Tenderly API | ||
| const tenderlyApiUrl = `https://api.tenderly.co/api/v1/public-contracts/${networkId}/${contractAddress}`; | ||
|
|
||
| const response = await fetch(tenderlyApiUrl, { | ||
| method: "GET", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "X-Access-Key": process.env.TENDERLY_ACCESS_KEY, | ||
| }, | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| // If Tenderly fails, try Etherscan as fallback | ||
| return await tryEtherscanFallback(networkId, contractAddress); | ||
| } | ||
|
|
||
| const tenderlyData = await response.json(); | ||
|
|
||
| // If contract is unverified in Tenderly, try Etherscan | ||
| if (tenderlyData?.type === "unverified_contract" || isUndefined(tenderlyData?.data?.abi)) { | ||
| return await tryEtherscanFallback(networkId, contractAddress); | ||
| } | ||
|
|
||
| // Return formatted data for verified contract from Tenderly | ||
| return NextResponse.json({ | ||
| address: contractAddress, | ||
| name: tenderlyData.contract_name, | ||
| abi: tenderlyData.data.abi, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Contract fetch error:", error instanceof Error ? error.message : "Unknown error"); | ||
|
|
||
| return NextResponse.json( | ||
| { | ||
| error: error instanceof Error ? error.message : "Failed to fetch contract details", | ||
| }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| async function tryEtherscanFallback(networkId: string, contractAddress: string) { | ||
| try { | ||
| const etherscanApiKey = process.env.ETHERSCAN_API_KEY; | ||
|
|
||
| if (isUndefined(etherscanApiKey)) { | ||
| return NextResponse.json({ error: "Etherscan API key not configured" }, { status: 500 }); | ||
| } | ||
|
|
||
| const baseUrl = "https://api.etherscan.io/v2/api"; | ||
| // eslint-disable-next-line max-len | ||
| const url = `${baseUrl}?chainid=${networkId}&module=contract&action=getabi&address=${contractAddress}&apikey=${etherscanApiKey}`; | ||
| const response = await fetch(url); | ||
|
|
||
| if (!response.ok) { | ||
| return NextResponse.json( | ||
| { error: `Failed to fetch from Etherscan: ${response.status}` }, | ||
| { status: response.status } | ||
| ); | ||
| } | ||
|
|
||
| const arbiscanData = await response.json(); | ||
|
|
||
| if (arbiscanData.status !== "1" || !arbiscanData.result) { | ||
| return NextResponse.json({ error: "Contract not verified on Etherscan" }, { status: 404 }); | ||
| } | ||
|
|
||
| const abi = JSON.parse(arbiscanData.result); | ||
|
|
||
| return NextResponse.json({ | ||
| address: contractAddress, | ||
| name: null, // Etherscan doesn't provide contract name in this API | ||
| abi, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Etherscan fallback error:", error instanceof Error ? error.message : "Unknown error"); | ||
| return NextResponse.json( | ||
| { | ||
| error: error instanceof Error ? error.message : "Failed to fetch from Etherscan", | ||
| }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.