-
Notifications
You must be signed in to change notification settings - Fork 94
Adding tenderly simulation #49
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
9cb9315
b637643
cb1ac3e
dd164e9
f3625c2
d511ea0
276ad83
41f1041
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import axios from 'axios'; | ||
| import { PropsWithChildren, ReactNode, useState } from 'react'; | ||
|
|
||
| import { Spinner } from '../../../components/animations/Spinner'; | ||
|
|
@@ -70,7 +71,7 @@ export function DestinationTransactionCard({ | |
| {debugResult.description} | ||
| </div> | ||
| )} | ||
| <CallDataModal debugResult={debugResult} /> | ||
| <CallDataModal debugResult={debugResult} chainId={chainId} /> | ||
| </DeliveryStatus> | ||
| ); | ||
| } else if (status === MessageStatus.Pending) { | ||
|
|
@@ -84,7 +85,7 @@ export function DestinationTransactionCard({ | |
| </div> | ||
| )} | ||
| <Spinner classes="my-4 scale-75" /> | ||
| <CallDataModal debugResult={debugResult} /> | ||
| <CallDataModal debugResult={debugResult} chainId={chainId} /> | ||
| </div> | ||
| </DeliveryStatus> | ||
| ); | ||
|
|
@@ -207,10 +208,15 @@ function DeliveryStatus({ children }: PropsWithChildren<unknown>) { | |
| ); | ||
| } | ||
|
|
||
| function CallDataModal({ debugResult }: { debugResult?: MessageDebugResult }) { | ||
| function CallDataModal({ debugResult,chainId }: { debugResult?: MessageDebugResult,chainId:ChainId }) { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const disabled=false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you have a var here if it never changes? |
||
| const [buttonText,setButtonText]=useState<string>("Simulate Handle Call") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to |
||
| if (!debugResult?.calldataDetails) return null; | ||
| const { contract, handleCalldata } = debugResult.calldataDetails; | ||
| function handleClick() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. event handlers (like click) should use lambda (arrow fn) syntax to be bound correctly. |
||
| setButtonText('Simulating'); | ||
|
jmrossy marked this conversation as resolved.
|
||
| } | ||
| return ( | ||
| <> | ||
| <button onClick={() => setIsOpen(true)} className={`mt-5 ${styles.textLink}`}> | ||
|
|
@@ -236,11 +242,64 @@ function CallDataModal({ debugResult }: { debugResult?: MessageDebugResult }) { | |
| </p> | ||
| <LabelAndCodeBlock label="Recipient contract address:" value={contract} /> | ||
| <LabelAndCodeBlock label="Handle function input calldata:" value={handleCalldata} /> | ||
| <button onClick={async()=>{ | ||
| handleClick() | ||
| await simulateCall({contract,handleCalldata,chainId}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this line to the click handler |
||
| }} | ||
| disabled={disabled} | ||
| className='underline text-blue-400' | ||
| > | ||
| {buttonText} | ||
| </button> | ||
|
|
||
| </div> | ||
| </Modal> | ||
| </> | ||
| ); | ||
| } | ||
| const simulateCall=async({contract,handleCalldata,chainId}:{contract:string,handleCalldata:string,chainId:ChainId})=>{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Root-level functions should use |
||
| const TENDERLY_USER='' | ||
| const TENDERLY_PROJECT='' | ||
| const TENDERLY_ACCESS_KEY='' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you intend these to be env vars? How would a user get their tenderly key used here? |
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap the function contents here in a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't wrap this in |
||
| console.time('Simulation') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you timing this? |
||
|
|
||
| const resp = await axios.post( | ||
| `https://api.tenderly.co/api/v1/account/${TENDERLY_USER}/project/${TENDERLY_PROJECT}/simulate`, | ||
| { | ||
| save: true, | ||
| save_if_fails: true, | ||
| simulation_type: 'full', | ||
| network_id: chainId, | ||
| from: '0xdc6bdc37b2714ee601734cf55a05625c9e512461',//can be any address, doesn't matter | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the 0 address if you just need a placeholder (ethers.constants.zeroAddress) |
||
| to: contract, | ||
| input:handleCalldata, | ||
| gas: 8000000, | ||
| gas_price: 0, | ||
| value: 0, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll need to use the real values from the message for an accurate simulation. |
||
| }, | ||
| { | ||
| headers: { | ||
| 'X-Access-Key': TENDERLY_ACCESS_KEY as string, | ||
| }, | ||
| } | ||
| ); | ||
| console.timeEnd('Simulation'); | ||
| console.log(resp.data) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the |
||
| const share = await axios.post( | ||
| `https://api.tenderly.co/api/v1/account/${TENDERLY_USER}/project/${TENDERLY_PROJECT}/simulations/${resp.data.simulation.id}/share`, | ||
| { | ||
|
|
||
| }, | ||
| { | ||
| headers: { | ||
| 'X-Access-Key': TENDERLY_ACCESS_KEY, | ||
| } | ||
| } | ||
| ) | ||
| console.log(share) | ||
| window.location.assign(`https://dashboard.tenderly.co/shared/simulation/${resp.data.simulation.id}`) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please open the tenderly window in a new tab |
||
| } | ||
|
|
||
| const helpText = { | ||
| origin: 'Info about the transaction that initiated the message placement into the outbox.', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the browser native
fetchAPI, no need to add a new library just for a POST request :)