Skip to content

Commit

Permalink
feat(safe): Add helper functions to pull the fallback manager of a Sa…
Browse files Browse the repository at this point in the history
…fe Wallet

- Clean up the organization of safe related files
- colocate the Networks in hardhat.config.ts
  • Loading branch information
DeFiFoFum committed Jun 19, 2024
1 parent 55456f6 commit 3e3fe71
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { CREATE2_DEPLOYER } from '.'
import { CREATE2_DEPLOYER } from '../../../scripts/deploy/CREATE2'

import GnosisSafeProxyFactory_1_3_0 from '../../../artifacts-external/GnosisSafeProxyFactory_1.3.0.json'
import { GnosisSafeL2, GnosisSafeProxyFactory_130 } from '../../../typechain-types'
Expand Down
35 changes: 35 additions & 0 deletions lib/evm/safe-wallet/getFallbackManagerForSafe.ts
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 }
}
3 changes: 2 additions & 1 deletion scripts/deploy/deployCreate2Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { writeObjectToTsFile } from '../../lib/node/files'
import { logger } from '../../hardhat/utils'
import { Networks } from '../../hardhat'
import { convertToExplorerUrlForNetwork } from '../../hardhat.config'
import { getCREATE2SafeInitializer } from './CREATE2/create2Safe'
import { getCREATE2SafeInitializer } from '../../lib/evm/safe-wallet/create2Safe'
import { CREATE2_DEPLOYER } from './CREATE2'
import { getErrorMessage } from '../../lib/node/getErrorMessage'
import GnosisSafeL2_Artifact from '../../artifacts-external/GnosisSafeL2.json'
Expand Down Expand Up @@ -59,6 +59,7 @@ async function deployCreate2Safe(salt: number, name?: string) {
logger.log('Attempting to setup newly created Gnosis Safe', '🛠️')
// NOTE: Pulling in abi manually as these artifacts are in a `/artifacts-external` directory
const gnosisSafe = new ethers.Contract(gnosisSafeAddress, GnosisSafeL2_Artifact.abi, deployer) as GnosisSafeL2
// TODO: Can probably pass in the proper ownership data here instead of needing to send another tx.
await gnosisSafe.setup(...initializerParams)
logger.log('Successfully setup Gnosis Safe', '🚀')
} catch (e) {
Expand Down
38 changes: 38 additions & 0 deletions scripts/monitor/getFallbackManagerForSafe.ts
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)
}
})()

0 comments on commit 3e3fe71

Please sign in to comment.