-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(governance): script to deploy contract from a Safe multisig (#14112
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
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,77 @@ | ||
/** | ||
* This script is used to submit a contract deployment to a Safe multisig | ||
* | ||
* Usage: | ||
* | ||
* // import this script | ||
* const submitContractDeployment = require('.') | ||
* | ||
* const Dummy = await ethers.getContractFactory('Dummy') | ||
* const { data: deploymentData } = await Dummy.getDeployTransaction(12n) | ||
* | ||
* // submit contract creation tx to multisig | ||
* await submitContractDeployment({ deploymentData }) | ||
*/ | ||
const { ethers } = require('hardhat') | ||
const { SafeProvider } = require('@safe-global/protocol-kit') | ||
const { getNetwork } = require('@unlock-protocol/hardhat-helpers') | ||
const { getSafeVersion } = require('../../helpers/multisig') | ||
const submitTx = require('./submitTx') | ||
|
||
async function main({ deploymentData } = {}) { | ||
const { provider, multisig } = await getNetwork() | ||
console.log({ multisig }) | ||
const safeProvider = new SafeProvider({ | ||
provider, | ||
signer: process.env.DEPLOYER_PRIVATE_KEY, | ||
}) | ||
const safeVersion = await getSafeVersion(multisig) | ||
const createCallContract = await safeProvider.getCreateCallContract({ | ||
safeVersion, | ||
}) | ||
|
||
// get deployed tx | ||
const createCallInterface = new ethers.Interface( | ||
createCallContract.contractAbi | ||
) | ||
const callData = createCallInterface.encodeFunctionData('performCreate', [ | ||
'0', | ||
deploymentData, | ||
]) | ||
|
||
const calls = [ | ||
{ | ||
calldata: callData, | ||
contractAddress: createCallContract.contractAddress, | ||
value: 0, | ||
}, | ||
] | ||
|
||
// submit the calls to the multisig | ||
const txArgs = { | ||
safeAddress: multisig, | ||
tx: calls, | ||
} | ||
console.log(txArgs) | ||
|
||
const transactionId = await submitTx(txArgs) | ||
console.log( | ||
`TRANSFER > Submitted bump tx to multisig (id: ${transactionId}).` | ||
) | ||
|
||
// function performCreate2(uint256 value, bytes memory deploymentData, bytes32 salt) public returns(address newContract) | ||
// function performCreate(uint256 value, bytes memory deploymentData) public returns(address newContract) | ||
// console.log(createCallContract) | ||
// const tx = await createCallContract.performCreate([0, deploymentData]) | ||
// console.log(tx) | ||
} | ||
|
||
// execute as standalone | ||
if (require.main === module) { | ||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error) | ||
process.exit(1) | ||
}) | ||
} |