Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(governance): migrate mainnet DAO's UDT and ETH to Base #15263

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions governance/proposals/udt/019-migrate-udt-eth-to-base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const { ethers } = require('hardhat')
const {
getNetwork,
getERC20Contract,
getBalance,
} = require('@unlock-protocol/hardhat-helpers')
const l1BridgeAbi = require('../../helpers/abi/l1standardbridge.json')

// chains
const srcChainId = 1 // mainnet
const destChainId = 8453 // base
const defaultGasAmount = '200000'

module.exports = async ({
mainnetTimelockAddress = '0x17EEDFb0a6E6e06E95B3A1F928dc4024240BC76B',
baseTimelockAddress = '0xB34567C4cA697b39F72e1a8478f285329A98ed1b',
bridgeAddress = '0x3154Cf16ccdb4C6d922629664174b904d80F2C35',
} = {}) => {
const {
name: srcName,
unlockDaoToken: { address: udtMainnetAddress },
} = await getNetwork(srcChainId)
const {
name: destName,
unlockDaoToken: { address: udtBaseAddress },
} = await getNetwork(destChainId)
console.log(
`Submitting proposal to bridge UDT from ${srcName} to ${destName} (${srcChainId} > ${destChainId})`
)

// get current UDT balance
const udt = await getERC20Contract(udtMainnetAddress)
const mainnetUDTBalance = await udt.balanceOf(mainnetTimelockAddress)

// get mainnet ETH balance
const mainnetETHBalance = await getBalance(mainnetTimelockAddress)

// get base bridge contract
const bridgeContract = new ethers.Contract(bridgeAddress, l1BridgeAbi)

const calls = [
// set allowance for the bridge to spend udt
{
contractAddress: udtMainnetAddress,
calldata: udt.interface.encodeFunctionData('approve', [
bridgeAddress, // dest
mainnetUDTBalance, // amount
]),
},
// call to bridge ETH
{
contractAddress: bridgeAddress,
calldata: bridgeContract.interface.encodeFunctionData('bridgeETHTo', [
baseTimelockAddress, // _to
defaultGasAmount, // _minGasLimit,
'0x', // _extraData
]),
value: mainnetETHBalance,
},
// call to bridge UDT
{
contractAddress: bridgeAddress,
calldata: bridgeContract.interface.encodeFunctionData('bridgeERC20To', [
udtMainnetAddress, // _localToken,
udtBaseAddress, // _remoteToken,
baseTimelockAddress, // _to
mainnetUDTBalance, // amount,
defaultGasAmount, // _minGasLimit,
'0x', // _extraData
]),
},
]

// parse calls for Safe
const proposalName = `# Transfer UDT and ETH to Base

This proposal will bridge the UDT and native ETH owned by the DAO to Base and transfer them to the new UP Governor.
`

Comment on lines +75 to +79
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here goes the text of this proposal. Any improvements to make ? Show the balances maybe ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear and concise! that works for me!

return {
proposalName,
calls,
}
}
22 changes: 18 additions & 4 deletions governance/scripts/gov/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
UnlockDiscountTokenV2,
UniswapOracleV3,
} = require('@unlock-protocol/contracts')
const l1BridgeAbi = require('../../helpers/abi/l1standardbridge.json')

// workflow
const submit = require('./submit')
Expand All @@ -20,27 +21,40 @@ const execute = require('./execute')
// parse logs
const parseLogs = (
logs,
abi = [...Unlock.abi, ...PublicLock.abi, ...UniswapOracleV3.abi]
showAll = false,
abi = [
...Unlock.abi,
...PublicLock.abi,
...UniswapOracleV3.abi,
...l1BridgeAbi,
]
) => {
const interface = new ethers.Interface(abi)

// parse logs
const parsedLogs = logs.map((log, i) => {
try {
const parsed = interface.parseLog(log)
log = parsed || log
log = parsed || { ...log, decodedError: true }
} catch (error) {
log.decodedError = true
}
return log
})
return parsedLogs
const toShow = showAll
? parsedLogs
: parsedLogs.filter(({ decodedError }) => !decodedError)

console.log(toShow)
console.log(`Logs not decoded: ${parsedLogs.length - toShow.length}`)
return toShow
}

async function main({ proposal, proposalId, govAddress, txId }) {
const [signer] = await ethers.getSigners()
const { chainId } = await ethers.provider.getNetwork()

console.log(proposal.proposalName)
const quorum = await getQuorum(govAddress)
const udtAddress = await getGovTokenAddress(govAddress)

Expand Down Expand Up @@ -105,7 +119,7 @@ async function main({ proposal, proposalId, govAddress, txId }) {
const { logs } = await execute({ proposalId, txId, proposal, govAddress })

// log all events
console.log(parseLogs(logs))
parseLogs(logs)

// simulate bridge calls
const xCalled = await parseXCalledEvents(logs)
Expand Down
Loading