Skip to content

Commit

Permalink
fix: Update gnosis safe scripts (#518)
Browse files Browse the repository at this point in the history
* deploy base diamond

* fix outdated scripts

* revert to main

* Add comments
  • Loading branch information
ezynda3 authored Sep 4, 2023
1 parent aeca49d commit 0a10265
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 74 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@nomiclabs/hardhat-waffle": "2.0.5",
"@typechain/ethers-v5": "10.2.0",
"@typechain/hardhat": "^6.1.5",
"@types/inquirer": "^8.2.0",
"@types/node": "^17.0.23",
"@types/pino": "^7.0.5",
"@typescript-eslint/eslint-plugin": "^5.16.0",
Expand Down Expand Up @@ -88,8 +87,8 @@
"@uniswap/sdk": "^3.0.3",
"chalk": "4.1.2",
"defender-relay-client": "^1.26.0",
"enquirer": "^2.4.1",
"hardhat-ethers": "^1.0.1",
"inquirer": "^8.2.1",
"light-spinner": "^1.0.4",
"notify-send": "^0.1.2",
"pino": "^7.9.2",
Expand Down
8 changes: 5 additions & 3 deletions script/deploy/deployUpgradesToSAFE.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ deployUpgradesToSAFE() {
source script/config.sh
source script/helperFunctions.sh

ENVIRONMENT="production"
ENVIRONMENT=$1
FILE_SUFFIX=$(getFileSuffix $ENVIRONMENT)
NETWORK=$(getUserSelectedNetwork)
DIAMOND_CONTRACT_NAME=$(userDialogSelectDiamondType)
if [ "$DIAMOND_CONTRACT_NAME" == "LiFiDiamond" ]; then
Expand All @@ -24,8 +25,9 @@ deployUpgradesToSAFE() {
declare -a CUTS
for script in $SCRIPTS; do
UPDATE_SCRIPT=$(echo "$DEPLOY_SCRIPT_DIRECTORY"Update"$script".s.sol)
PRIVATE_KEY=$(getPrivateKey $NETWORK $ENVIRONMENT)
echo "Calculating facet cuts for $script..."
RAW_RETURN_DATA=$(NO_BROADCAST=true NETWORK=$NETWORK FILE_SUFFIX=$FILE_SUFFIX USE_DEF_DIAMOND=$USE_MUTABLE_DIAMOND PRIVATE_KEY=$(getPrivateKey "$ENVIRONMENT") forge script "$UPDATE_SCRIPT" -f $NETWORK -vvvv --json --silent --skip-simulation --legacy)
RAW_RETURN_DATA=$(NO_BROADCAST=true NETWORK=$NETWORK FILE_SUFFIX=$FILE_SUFFIX USE_DEF_DIAMOND=$USE_MUTABLE_DIAMOND PRIVATE_KEY=$PRIVATE_KEY forge script "$UPDATE_SCRIPT" -f $NETWORK -vvvv --json --silent --skip-simulation --legacy)
CLEAN_RETURN_DATA=$(echo $RAW_RETURN_DATA | sed 's/^.*{\"logs/{\"logs/')
FACET_CUT=$(echo $CLEAN_RETURN_DATA | jq -r '.returns.cutData.value')
if [ "$FACET_CUT" != "0x" ]; then
Expand All @@ -45,7 +47,7 @@ deployUpgradesToSAFE() {
DIAMOND_ADDRESS=$(getContractAddressFromDeploymentLogs "$NETWORK" "$ENVIRONMENT" "$DIAMOND_CONTRACT_NAME")

# Call the proposeTx script ts-node proposeTx.ts diamondAddress cuts network rpcUrl
ts-node script/deploy/gnosisSAFE/proposeTx.ts "$DIAMOND_ADDRESS" "$CUTS_JSON" "$NETWORK" $(getRPCUrl $NETWORK)
ts-node script/deploy/gnosisSAFE/proposeTx.ts "$DIAMOND_ADDRESS" "$CUTS_JSON" "$NETWORK" $(getRPCUrl $NETWORK) "$PRIVATE_KEY"
exit 0
}

Expand Down
28 changes: 1 addition & 27 deletions script/deploy/facets/UpdateCalldataVerificationFacet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,6 @@ contract DeployScript is UpdateScriptBase {
public
returns (address[] memory facets, bytes memory cutData)
{
address facet = json.readAddress(".CalldataVerificationFacet");

// CalldataVerificationFacet
bytes4[] memory exclude;
buildDiamondCut(
getSelectors("CalldataVerificationFacet", exclude),
facet
);
if (noBroadcast) {
if (cut.length > 0) {
cutData = abi.encodeWithSelector(
DiamondCutFacet.diamondCut.selector,
cut,
address(0),
""
);
}
return (facets, cutData);
}

vm.startBroadcast(deployerPrivateKey);
if (cut.length > 0) {
cutter.diamondCut(cut, address(0), "");
}
facets = loupe.facetAddresses();

vm.stopBroadcast();
return update("CalldataVerificationFacet");
}
}
25 changes: 1 addition & 24 deletions script/deploy/facets/UpdateStandardizedCallFacet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,6 @@ contract DeployScript is UpdateScriptBase {
public
returns (address[] memory facets, bytes memory cutData)
{
address facet = json.readAddress(".StandardizedCallFacet");

// StandardizedCallFacet
bytes4[] memory exclude;
buildDiamondCut(getSelectors("StandardizedCallFacet", exclude), facet);
if (noBroadcast) {
if (cut.length > 0) {
cutData = abi.encodeWithSelector(
DiamondCutFacet.diamondCut.selector,
cut,
address(0),
""
);
}
return (facets, cutData);
}

vm.startBroadcast(deployerPrivateKey);
if (cut.length > 0) {
cutter.diamondCut(cut, address(0), "");
}
facets = loupe.facetAddresses();

vm.stopBroadcast();
return update("StandardizedCallFacet");
}
}
38 changes: 29 additions & 9 deletions script/deploy/gnosisSAFE/proposeTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import SafeApiKit, {
OwnerResponse,
ProposeTransactionProps,
} from '@safe-global/api-kit'
import dotenv from 'dotenv'
import { SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types'
import { safeApiUrls } from './config'
import { exit } from 'process'
dotenv.config()
import { argv, exit } from 'process'
import enquirer from 'enquirer'

const [, , diamondAddress, rawCuts, network, rpcUrl] = process.argv
// Parse incoming arguments
const [, , diamondAddress, rawCuts, network, rpcUrl, privateKey] = argv

let safeOwner = new ethers.Wallet(process.env.PRIVATE_KEY_PRODUCTION as string)
// Create ethers provider and signer from private key
let safeOwner = new ethers.Wallet(privateKey as string)
const provider = new ethers.providers.JsonRpcProvider(rpcUrl)
safeOwner = safeOwner.connect(provider)

// Initialize the Safe API
const ethAdapter = new EthersAdapter({
ethers,
signerOrProvider: safeOwner,
Expand All @@ -29,25 +31,42 @@ const safeService = new SafeApiKit({

const main = async () => {
console.info('Building SAFE TX Proposal..')

// Get owned SAFE addresses
const res: OwnerResponse = await safeService.getSafesByOwner(
await safeOwner.getAddress()
)
const safeAddress = res.safes[0]
console.info('SAFE Address: ', res.safes[0])

// Prompt the user to choose a SAFE address
const choice = await enquirer.prompt({
type: 'select',
name: 'safeAddress',
message: 'Choose the SAFE address you would like to use.',
choices: res.safes,
})

const safeAddress = (<{ safeAddress: string }>choice).safeAddress
console.info('SAFE Address: ', safeAddress)
console.info('Diamond Address: ', diamondAddress)

// Instantiate a SAFE instance
const safeSdk: Safe = await Safe.create({
ethAdapter,
safeAddress,
})

// Parse the raw diamond cuts
const cuts = JSON.parse(rawCuts)

// Get the latest nonce from the SAFE
let nonce = await safeSdk.getNonce()

// Broadcast each cut as a SAFE transaction proposal
console.info(`Proposing ${cuts.length} transactions...`)
let i = 1
for (const cut of cuts) {
const safeTransactionData: SafeTransactionDataPartial = {
to: '0x9FcB9Aaa138DBb2Cbf484Ba43285ca4b60b56D09',
to: diamondAddress,
value: '0',
data: cut,
nonce,
Expand All @@ -63,12 +82,13 @@ const main = async () => {
senderSignature: txHashSignature.data,
}
console.info(`Sending proposal [${i}]...`)
// await safeService.proposeTransaction(proposal)
await safeService.proposeTransaction(proposal)
nonce++
i++
}
}

// Main entry point
main()
.then(() => {
console.info('Done!')
Expand Down
3 changes: 2 additions & 1 deletion script/scriptMaster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ scriptMaster() {
source script/deploy/deployFacetAndAddToDiamond.sh
source script/deploy/deployPeripheryContracts.sh
source script/config.sh
source script/deploy/deployUpgradesToSAFE.sh
for script in script/tasks/*.sh; do [ -f "$script" ] && source "$script"; done # sources all script in folder script/tasks/

# make sure that all compiled artifacts are current
Expand Down Expand Up @@ -488,7 +489,7 @@ scriptMaster() {
#---------------------------------------------------------------------------------------------------------------------
# use case 11: Propose upgrade TX to Gnosis SAFE
elif [[ "$SELECTION" == "11)"* ]]; then
deployUpgradesToSAFE
deployUpgradesToSAFE $ENVIRONMENT
else
error "invalid use case selected ('$SELECTION') - exiting script"
cleanup
Expand Down
17 changes: 9 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1249,13 +1249,6 @@
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz#0ea7b61496902b95890dc4c3a116b60cb8dae812"
integrity sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==

"@types/inquirer@^8.2.0":
version "8.2.5"
resolved "https://registry.yarnpkg.com/@types/inquirer/-/inquirer-8.2.5.tgz#c508423bcc11126db278170ab07347783ac2300c"
integrity sha512-QXlzybid60YtAwfgG3cpykptRYUx2KomzNutMlWsQC64J/WG/gQSl+P4w7A21sGN0VIxRVava4rgnT7FQmFCdg==
dependencies:
"@types/through" "*"

"@types/inquirer@^8.2.1":
version "8.2.6"
resolved "https://registry.yarnpkg.com/@types/inquirer/-/inquirer-8.2.6.tgz#abd41a5fb689c7f1acb12933d787d4262a02a0ab"
Expand Down Expand Up @@ -3296,6 +3289,14 @@ enquirer@^2.3.0, enquirer@^2.3.6:
dependencies:
ansi-colors "^4.1.1"

enquirer@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.4.1.tgz#93334b3fbd74fc7097b224ab4a8fb7e40bf4ae56"
integrity sha512-rRqJg/6gd538VHvR3PSrdRBb/1Vy2YfzHqzvbhGIQpDRKIa4FgV/54b5Q1xYSxOOwKvjXweS26E0Q+nAMwp2pQ==
dependencies:
ansi-colors "^4.1.1"
strip-ansi "^6.0.1"

env-paths@^2.2.0:
version "2.2.1"
resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-2.2.1.tgz#420399d416ce1fbe9bc0a07c62fa68d67fd0f8f2"
Expand Down Expand Up @@ -5158,7 +5159,7 @@ inquirer@^6.2.2:
strip-ansi "^5.1.0"
through "^2.3.6"

inquirer@^8.2.1, inquirer@^8.2.2:
inquirer@^8.2.2:
version "8.2.5"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.5.tgz#d8654a7542c35a9b9e069d27e2df4858784d54f8"
integrity sha512-QAgPDQMEgrDssk1XiwwHoOGYF9BAbUcc1+j+FhEvaOt8/cKRqyLn0U5qA6F74fGhTMGxf92pOvPBeh29jQJDTQ==
Expand Down

0 comments on commit 0a10265

Please sign in to comment.