Skip to content

Commit

Permalink
WIP: parse multicall
Browse files Browse the repository at this point in the history
  • Loading branch information
clemsos committed Apr 3, 2024
1 parent b0ef6d2 commit 60cb756
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 26 deletions.
22 changes: 22 additions & 0 deletions governance/helpers/multisig.js
Expand Up @@ -4,6 +4,7 @@ const { getNetwork } = require('@unlock-protocol/hardhat-helpers')
const multisigABI = require('@unlock-protocol/hardhat-helpers/dist/ABIs/multisig2.json')
const multisigOldABI = require('@unlock-protocol/hardhat-helpers/dist/ABIs/multisig.json')
const SafeApiKit = require('@safe-global/api-kit').default
const { encodeMultiSendData } = require('@safe-global/protocol-kit')

// custom services URL for network not supported by Safe
const safeServiceURLs = {
Expand Down Expand Up @@ -190,6 +191,26 @@ const submitTxOldMultisig = async ({ safeAddress, tx, signer }) => {
return nonce
}

// pack multiple calls in a single multicall
const parseSafeMulticall = async (calls) => {
console.log(calls)
const metaTxs = calls.map(
({ contractAddress, calldata = '0x', value = 0, operation = 0 }) => ({
to: contractAddress,
value,
data: calldata,
// TODO? need to fetch if proxy or not ?
operation, // operation: 0 for CALL, 1 for DELEGATECALL
})
)

const multicall = await encodeMultiSendData(metaTxs)

// TODO: how to get multicall address (without a provider)
const multicallAddress = ''
return multicall
}

module.exports = {
getProvider,
getSafeAddress,
Expand All @@ -202,4 +223,5 @@ module.exports = {
getExpectedSigners,
logError,
getSafeService,
parseSafeMulticall,
}
21 changes: 3 additions & 18 deletions governance/proposals/009-protocol-upgrade.js
Expand Up @@ -5,7 +5,6 @@
const { ethers } = require('hardhat')
const { UnlockV13 } = require('@unlock-protocol/contracts')
const { networks } = require('@unlock-protocol/networks')
const { encodeMultiSendData } = require('@safe-global/protocol-kit')

const {
getProxyAdminAddress,
Expand All @@ -16,6 +15,8 @@ const {
abi: proxyAdminABI,
} = require('@unlock-protocol/hardhat-helpers/dist/ABIs/ProxyAdmin.json')

const { parseSafeMulticall } = require('../helpers/multisig')

// TODO: move to hardhat-helpers
const abiIConnext = [
{
Expand Down Expand Up @@ -165,22 +166,6 @@ const parseCalls = async ({ unlockAddress, name, id }) => {
return calls
}

//
const parseForSafe = async (calls) => {
console.log(calls)
const metaTxs = calls.map(({ contractAddress, calldata }) => ({
to: contractAddress,
value: 0,
data: calldata,
// TODO? need to fetch if proxy or not ?
operation: 0, // operation: 0 for CALL, 1 for DELEGATECALL
}))

// pack calls in a single multicall
const multicall = await encodeMultiSendData(metaTxs)
return multicall
}

module.exports = async () => {
const targetChains = Object.keys(networks)
.filter((id) => Object.keys(deployedContracts).includes(id.toString()))
Expand Down Expand Up @@ -229,7 +214,7 @@ module.exports = async () => {
explainers[destChainId] = destCalls

// parse calls for Safe
const moduleData = await parseForSafe(destCalls)
const moduleData = await parseSafeMulticall(destCalls)

// add to the list of calls to be passed to the bridge
bridgeCalls.push({
Expand Down
23 changes: 23 additions & 0 deletions governance/proposals/010-test-multicall.js
@@ -0,0 +1,23 @@
const { ethers, ZeroAddress } = require('ethers')
const { parseSafeMulticall } = require('../helpers/multisig')

module.exports = async () => {
const calls = [
{
contractAddress: ZeroAddress,
value: ethers.parseEther('0.0001'),
},
{
contractAddress: ZeroAddress,
value: ethers.parseEther('0.0001'),
},
]

// parse calls for Safe
const packedData = await parseSafeMulticall(calls)
console.log(packedData)
return {
proposalName: 'Test a multicall',
calls: { calldata: packedData },
}
}
21 changes: 13 additions & 8 deletions governance/scripts/multisig/submitTx.js
Expand Up @@ -46,14 +46,19 @@ async function main({ safeAddress, tx, signer }) {
const safeSdk = await Safe.create({ ethAdapter, safeAddress })
const txs = !Array.isArray(tx) ? [tx] : tx

const explainer = txs
.map(({ functionName, functionArgs, explainer }) =>
explainer
? explainer
: `'${functionName}(${Object.values(functionArgs).toString()})'`
)
.join(', ')
console.log(`Submitting txs: ${explainer}`)
let explainer = ''
try {
explainer = txs
.map(({ functionName, functionArgs, explainer }) =>
explainer
? explainer
: `'${functionName}(${Object.values(functionArgs).toString()})'`
)
.join(', ')
console.log(`Submitting txs: ${explainer}`)
} catch (error) {
console.log(`Missing explainers...`)
}

// parse transactions
const transactions = await Promise.all(
Expand Down

0 comments on commit 60cb756

Please sign in to comment.