Skip to content

Commit

Permalink
add ownership checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ezynda3 committed May 21, 2024
1 parent 435ab10 commit 14b2505
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
18 changes: 18 additions & 0 deletions config/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,23 @@
"sig": "0xd9caed12",
"name": "WithdrawFacet.withdraw"
}
],
"approvedSigsForDeployerWallet": [
{
"sig": "0xfcd8e49e",
"name": "DexManagerFacet.batchAddDex"
},
{
"sig": "0x9afc19c7",
"name": "DexManagerFacet.batchRemoveDex"
},
{
"sig": "0x44e2b18c",
"name": "DexManagerFacet.batchSetFunctionApprovalBySignature"
},
{
"sig": "0x5c2ed36a",
"name": "PeripheryRegistryFacet.registerPeripheryContract"
}
]
}
86 changes: 85 additions & 1 deletion script/deploy/healthCheck.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import * as chains from 'viem/chains'
import {
Address,
Chain,
PublicClient,
createPublicClient,
getAddress,
getContract,
http,
parseAbi,
zeroAddress,
} from 'viem'

const louperCmd = 'louper-cli'
Expand Down Expand Up @@ -62,6 +64,8 @@ const main = defineCommand({
network.toLowerCase()
] as Address[]

const globalConfig = await import('../../config/global.json')

const chain = chainMap[network]
const publicClient = createPublicClient({
batch: { multicall: true },
Expand Down Expand Up @@ -105,7 +109,9 @@ const main = defineCommand({

for (const facet of coreFacets) {
if (!resgisteredFacets.includes(facet)) {
logError(`Facet ${facet} not registered in Diamond`)
logError(
`Facet ${facet} not registered in Diamond or possibly unverified`
)
} else {
consola.success(`Facet ${facet} registered in Diamond`)
}
Expand Down Expand Up @@ -186,6 +192,76 @@ const main = defineCommand({
consola.info(
`Found ${numMissing} missing dex${numMissing === 1 ? '' : 's'}`
)

// Check contract ownership
consola.box('Checking ownership...')

let owner: Address = zeroAddress
let contractAddress: Address
const withdrawWallet = getAddress(globalConfig.withdrawWallet)
const rebalanceWallet = getAddress(globalConfig.lifuelRebalanceWallet)
const refundWallet = getAddress(globalConfig.refundWallet)

// FeeCollector
if (deployedContracts['FeeCollector']) {
contractAddress = deployedContracts['FeeCollector']
owner = await getOwnablContract(
contractAddress,
publicClient
).read.owner()
if (owner !== withdrawWallet) {
logError(`FeeCollector owner is ${owner}, expected ${withdrawWallet}`)
} else {
consola.success('FeeCollector owner is correct')
}
}

// LiFuelFeeCollector
if (deployedContracts['LiFuelFeeCollector']) {
contractAddress = deployedContracts['LiFuelFeeCollector']
owner = await getOwnablContract(
contractAddress,
publicClient
).read.owner()
if (owner !== rebalanceWallet) {
logError(
`LiFuelFeeCollector owner is ${owner}, expected ${rebalanceWallet}`
)
} else {
consola.success('LiFuelFeeCollector owner is correct')
}
}

// Receiver
if (deployedContracts['Receiver']) {
contractAddress = deployedContracts['Receiver']
owner = await getOwnablContract(
contractAddress,
publicClient
).read.owner()
if (owner !== refundWallet) {
logError(`Receiver owner is ${owner}, expected ${refundWallet}`)
} else {
consola.success('Receiver owner is correct')
}
}

// ServiceFeeCollector
if (deployedContracts['ServiceFeeCollector']) {
contractAddress = deployedContracts['ServiceFeeCollector']
owner = await getOwnablContract(
contractAddress,
publicClient
).read.owner()
if (owner !== withdrawWallet) {
logError(
`ServiceFeeCollector owner is ${owner}, expected ${withdrawWallet}`
)
} else {
consola.success('ServiceFeeCollector owner is correct')
}
}

finish()
}
},
Expand All @@ -196,6 +272,14 @@ const logError = (string: string) => {
errors.push(string)
}

const getOwnablContract = (address: Address, client: PublicClient) => {
return getContract({
address,
abi: parseAbi(['function owner() external view returns (address)']),
client,
})
}

const finish = () => {
if (errors.length) {
consola.error(`${errors.length} Errors found in deployment`)
Expand Down

0 comments on commit 14b2505

Please sign in to comment.