-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/custom fork id #438
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: dev
Are you sure you want to change the base?
Feat/custom fork id #438
Changes from 9 commits
1b3e136
eeb2696
710b246
1f122fe
9370b19
7654947
72937d7
f826f1e
1368446
2ee059e
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import SettingsContext from '@/contexts/SettingsContext'; | ||
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'; | ||
import { useContext } from 'react'; | ||
|
||
const ForkStatus = () => { | ||
const { settings } = useContext(SettingsContext); | ||
const { isForkedEnv } = settings; | ||
|
||
return ( | ||
<> | ||
{isForkedEnv ? ( | ||
<div> | ||
<div className={`flex flex-col justify-between text-xs text-orange-500`}> | ||
<div /> | ||
<div className="flex gap-2 items-center"> | ||
<span className='w-3 h-3' > <ExclamationTriangleIcon /> </span> | ||
<span>Test Environemnt</span> | ||
</div> | ||
</div> | ||
</div> | ||
) : null} | ||
</> | ||
|
||
|
||
); | ||
}; | ||
|
||
|
||
export default ForkStatus; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
// use the appropriate chain id depending on the network and if using a fork | ||
import { useMemo } from 'react'; | ||
import { useContext, useMemo } from 'react'; | ||
import { useNetwork } from 'wagmi'; | ||
import SettingsContext from '@/contexts/SettingsContext'; | ||
|
||
const DEFAULT_CHAIN_ID = 1; | ||
|
||
const useChainId = () => { | ||
const useChainId = (returnForkId?: boolean) => { | ||
const { chain } = useNetwork(); | ||
return useMemo(() => (chain ? chain.id : DEFAULT_CHAIN_ID), [chain]); | ||
const { | ||
settings: { isForkedEnv }, | ||
} = useContext(SettingsContext); | ||
|
||
return useMemo(() => { | ||
/* if required, we use the *base* chain id for the forked env | ||
because most contracts will require the chain id to match | ||
eg. chainID 1 etc even though we are using a forked env with custom id | ||
*/ | ||
if (isForkedEnv && !returnForkId) { | ||
return chain ? +chain.id.toString().slice(6) : DEFAULT_CHAIN_ID; | ||
} | ||
return chain ? chain.id : DEFAULT_CHAIN_ID; | ||
}, [chain]); | ||
}; | ||
|
||
export default useChainId; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,7 @@ const useForkTools = (id?: string): ForkTools => { | |
const { settings } = useContext(SettingsContext); | ||
const { isForkedEnv, forkId } = settings; | ||
|
||
const forkUrl = id | ||
? `https://rpc.tenderly.co/fork/${id}` | ||
: `https://rpc.tenderly.co/fork/${forkId}`; | ||
const forkUrl = `https://rpc.tenderly.co/fork/${ id ?? forkId }` | ||
|
||
/* parameters from wagmi */ | ||
const { address: account } = useAccount(); | ||
|
@@ -40,7 +38,12 @@ const useForkTools = (id?: string): ForkTools => { | |
const currentBlockNumber = await provider.getBlockNumber(); | ||
const resp = await axios.post( | ||
forkAPI, | ||
{ network_id: 1, block_number: currentBlockNumber }, | ||
{ network_id: 1, | ||
block_number: currentBlockNumber, | ||
chain_config: { | ||
chain_id: 1277971 | ||
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. can we or should we make the fork chain id an env variable? 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. Could do so, I think better would be to simply append 127797.. to the current netwrok_id in this case. |
||
} | ||
}, | ||
{ | ||
headers: { | ||
'X-Access-Key': process.env.NEXT_PUBLIC_TENDERLY_ACCESS_KEY as string, | ||
|
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.
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.
what does
returnForkId
mean?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.
UseChainId will return the ID of the forked network ( eg. 1 if we forked mainnet). However, that might not be the id returned by getNetwork().id .... there will likely be a need to have access to both. (For example, some deployed contracts might reference the id 1 , when the id returned by the network will be different ) .