-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(safe): Add helper functions to pull the fallback manager of a Sa…
…fe Wallet - Clean up the organization of safe related files - colocate the Networks in hardhat.config.ts
- Loading branch information
Showing
4 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
scripts/deploy/CREATE2/create2Safe.ts → lib/evm/safe-wallet/create2Safe.ts
This file contains 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 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,35 @@ | ||
import { Networks } from '../../../hardhat' | ||
import { geRpcUrlForNetwork } from '../../../hardhat.config' | ||
|
||
const FALLBACK_HANDLER_STORAGE_SLOT = '0x6c9a6c4a39284e37ed1cf53d337577d14212a4870fb976a4366c693b939918d5' | ||
|
||
export async function getFallbackManagerForSafe(networkName: Networks, address: string) { | ||
const networkUrl = geRpcUrlForNetwork(networkName) | ||
|
||
if (!networkUrl) { | ||
throw new Error('getFallbackManagerForSafe:: Network not found') | ||
} | ||
|
||
const data = JSON.stringify({ | ||
jsonrpc: '2.0', | ||
method: 'eth_getStorageAt', | ||
params: [address, FALLBACK_HANDLER_STORAGE_SLOT, 'latest'], | ||
id: 1, | ||
}) | ||
|
||
const response = await fetch(networkUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: data, | ||
}).then((res) => res.json()) | ||
|
||
if (!response.result) { | ||
throw new Error('Failed to get the storage from the network') | ||
} | ||
|
||
const fallbackManagerAddress = '0x' + response.result.slice(26) | ||
|
||
return { fallbackManagerAddress } | ||
} |
This file contains 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 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,38 @@ | ||
import { network } from 'hardhat' | ||
import { Networks } from '../../hardhat' | ||
import { getFallbackManagerForSafe } from '../../lib/evm/safe-wallet/getFallbackManagerForSafe' | ||
import { convertAddressesToExplorerLinksByNetwork } from '../../lib/evm/convertAddresses' | ||
|
||
// NOTE: Import deployment files | ||
// import { deployment } from '../../deployments/' | ||
|
||
async function script() { | ||
const currentNetwork = network.name as Networks | ||
|
||
const safeAddress = '0x-getFallbackManagerForSafe' | ||
|
||
const { fallbackManagerAddress } = await getFallbackManagerForSafe(currentNetwork, safeAddress) | ||
|
||
const output = convertAddressesToExplorerLinksByNetwork( | ||
{ | ||
safeAddress, | ||
fallbackManagerAddress, | ||
}, | ||
currentNetwork, | ||
true | ||
) | ||
|
||
console.dir(output, { depth: null }) | ||
} | ||
|
||
;(async function () { | ||
try { | ||
await script() | ||
console.log('🎉') | ||
process.exit(0) | ||
} catch (e) { | ||
console.error('Error running script.') | ||
console.dir(e) | ||
process.exit(1) | ||
} | ||
})() |