forked from lidofinance/lido-l2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add deployment script for Swellchain (modified copy of Optimism deplo…
…yment)
- Loading branch information
1 parent
d8b68db
commit 06160e0
Showing
16 changed files
with
1,625 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
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
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
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,80 @@ | ||
import env from "../../utils/env"; | ||
import prompt from "../../utils/prompt"; | ||
import network from "../../utils/network"; | ||
import deployment from "../../utils/deployment"; | ||
import { BridgingManagement } from "../../utils/bridging-management"; | ||
import swellchain from "../../utils/swellchain"; | ||
|
||
|
||
async function main() { | ||
const networkName = env.network(); | ||
const ethOptNetwork = network.multichain(["eth", "swe"], networkName); | ||
|
||
const [ethDeployer] = ethOptNetwork.getSigners(env.privateKey(), { | ||
forking: env.forking(), | ||
}); | ||
const [, sweDeployer] = ethOptNetwork.getSigners( | ||
env.string("SWE_DEPLOYER_PRIVATE_KEY"), | ||
{ | ||
forking: env.forking(), | ||
} | ||
); | ||
|
||
const deploymentConfig = deployment.loadMultiChainDeploymentConfig(); | ||
|
||
const [l1DeployScript, l2DeployScript] = await swellchain | ||
.deployment(networkName, { logger: console }) | ||
.erc20TokenBridgeDeployScript( | ||
deploymentConfig.token, | ||
{ | ||
deployer: ethDeployer, | ||
admins: { | ||
proxy: deploymentConfig.l1.proxyAdmin, | ||
bridge: ethDeployer.address, | ||
}, | ||
}, | ||
{ | ||
deployer: sweDeployer, | ||
admins: { | ||
proxy: deploymentConfig.l2.proxyAdmin, | ||
bridge: sweDeployer.address, | ||
}, | ||
} | ||
); | ||
|
||
await deployment.printMultiChainDeploymentConfig( | ||
"Deploy Swellchain Bridge", | ||
ethDeployer, | ||
sweDeployer, | ||
deploymentConfig, | ||
l1DeployScript, | ||
l2DeployScript | ||
); | ||
|
||
await prompt.proceed(); | ||
|
||
await l1DeployScript.run(); | ||
await l2DeployScript.run(); | ||
|
||
const l1ERC20TokenBridgeProxyDeployStepIndex = 1; | ||
const l1BridgingManagement = new BridgingManagement( | ||
l1DeployScript.getContractAddress(l1ERC20TokenBridgeProxyDeployStepIndex), | ||
ethDeployer, | ||
{ logger: console } | ||
); | ||
|
||
const l2ERC20TokenBridgeProxyDeployStepIndex = 3; | ||
const l2BridgingManagement = new BridgingManagement( | ||
l2DeployScript.getContractAddress(l2ERC20TokenBridgeProxyDeployStepIndex), | ||
sweDeployer, | ||
{ logger: console } | ||
); | ||
|
||
await l1BridgingManagement.setup(deploymentConfig.l1); | ||
await l2BridgingManagement.setup(deploymentConfig.l2); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
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,34 @@ | ||
import { CrossChainMessenger, MessageStatus } from "@eth-optimism/sdk"; | ||
import env from "../../utils/env"; | ||
import network from "../../utils/network"; | ||
|
||
async function main() { | ||
const networkName = env.network(); | ||
const [l1Signer, l2Signer] = network | ||
.multichain(["eth", "swe"], networkName) | ||
.getSigners(env.privateKey(), { forking: false }); | ||
|
||
const txHash = env.string("TX_HASH"); | ||
|
||
const crossDomainMessenger = new CrossChainMessenger({ | ||
l1ChainId: network.chainId("eth", networkName), | ||
l2ChainId: network.chainId("swe", networkName), | ||
l1SignerOrProvider: l1Signer, | ||
l2SignerOrProvider: l2Signer, | ||
}); | ||
|
||
const status = await crossDomainMessenger.getMessageStatus(txHash); | ||
|
||
if (status !== MessageStatus.READY_FOR_RELAY) { | ||
throw new Error(`Invalid tx status: ${status}`); | ||
} | ||
|
||
console.log("Finalizing the L2 -> L1 message"); | ||
await crossDomainMessenger.finalizeMessage(txHash); | ||
console.log("Message successfully finalized!"); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
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,37 @@ | ||
import { CrossChainMessenger, MessageStatus } from "@eth-optimism/sdk"; | ||
import env from "../../utils/env"; | ||
import network from "../../utils/network"; | ||
|
||
async function main() { | ||
const networkName = env.network(); | ||
const [l1Signer, l2Signer] = network | ||
.multichain(["eth", "swe"], networkName) | ||
.getSigners(env.privateKey(), { forking: false }); | ||
|
||
const txHash = env.string("TX_HASH"); | ||
|
||
const crossChainMessenger = new CrossChainMessenger({ | ||
l1ChainId: network.chainId("eth", networkName), | ||
l2ChainId: network.chainId("swe", networkName), | ||
l1SignerOrProvider: l1Signer, | ||
l2SignerOrProvider: l2Signer, | ||
bedrock: true, | ||
}); | ||
|
||
const status = await crossChainMessenger.getMessageStatus(txHash); | ||
|
||
if (status !== MessageStatus.READY_TO_PROVE) { | ||
throw new Error(`Invalid tx status: ${status}`); | ||
} | ||
|
||
console.log("Prove the L2 -> L1 message"); | ||
const tx = await crossChainMessenger.proveMessage(txHash); | ||
console.log(`Waiting for the prove tx ${tx.hash}...`); | ||
await tx.wait(); | ||
console.log(`Message was proved successfully!`); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
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,149 @@ | ||
import { assert } from "chai"; | ||
import { ethers } from "hardhat"; | ||
import { GovBridgeExecutor__factory } from "../../typechain"; | ||
import env from "../../utils/env"; | ||
import lido from "../../utils/lido"; | ||
import network from "../../utils/network"; | ||
import swellchain from "../../utils/swellchain"; | ||
import prompt from "../../utils/prompt"; | ||
|
||
// Set address of the bridge executor to run the script | ||
const GOV_BRIDGE_EXECUTOR = ""; | ||
|
||
async function main() { | ||
const isForking = env.forking(); | ||
const networkName = env.network(); | ||
const ethSweNetwork = network.multichain(["eth", "swe"], networkName); | ||
|
||
const [l1LDOHolder] = ethSweNetwork.getSigners( | ||
env.string("TESTING_SWE_LDO_HOLDER_PRIVATE_KEY"), | ||
{ forking: isForking } | ||
); | ||
const [, sweRunner] = ethSweNetwork.getSigners(env.privateKey(), { | ||
forking: isForking, | ||
}); | ||
|
||
const govBridgeExecutor = GovBridgeExecutor__factory.connect( | ||
GOV_BRIDGE_EXECUTOR, | ||
sweRunner | ||
); | ||
|
||
const newEthExecutorLidoDAO = lido(networkName, l1LDOHolder); | ||
const oldEthExecutorLidoDAO = lido( | ||
networkName === "mainnet" ? "mainnet_test" : networkName, | ||
l1LDOHolder | ||
); | ||
const prevEthGovExecutorAddress = | ||
await govBridgeExecutor.getEthereumGovernanceExecutor(); | ||
|
||
assert.equal( | ||
oldEthExecutorLidoDAO.agent.address.toLocaleLowerCase(), | ||
prevEthGovExecutorAddress.toLowerCase(), | ||
`${oldEthExecutorLidoDAO.agent.address} is not current ethereumGovernanceExecutor` | ||
); | ||
|
||
console.log(` · Is forking: ${isForking}`); | ||
console.log(` · Network Name: ${networkName}`); | ||
console.log( | ||
` · Prev Ethereum Governance Executor: ${prevEthGovExecutorAddress}` | ||
); | ||
console.log( | ||
` · New Ethereum Governance Executor: ${newEthExecutorLidoDAO.agent.address}` | ||
); | ||
console.log(` · LDO Holder: ${l1LDOHolder.address}`); | ||
console.log(` · LDO Holder ETH balance: ${await l1LDOHolder.getBalance()}`); | ||
console.log(` · L2 tx runner: ${sweRunner.address}`); | ||
console.log(` · L2 tx runner ETH balance: ${await sweRunner.getBalance()}`); | ||
|
||
await prompt.proceed(); | ||
|
||
console.log(`Preparing the voting tx...`); | ||
|
||
const sweAddresses = swellchain.addresses(networkName); | ||
|
||
// Prepare data for Governance Bridge Executor | ||
const executorCalldata = await govBridgeExecutor.interface.encodeFunctionData( | ||
"queue", | ||
[ | ||
[GOV_BRIDGE_EXECUTOR], | ||
[0], | ||
["updateEthereumGovernanceExecutor(address)"], | ||
[ | ||
ethers.utils.defaultAbiCoder.encode( | ||
["address"], | ||
[newEthExecutorLidoDAO.agent.address] | ||
), | ||
], | ||
[false], | ||
] | ||
); | ||
|
||
const { callvalue, calldata } = await swellchain | ||
.messaging(networkName, { forking: isForking }) | ||
.prepareL2Message({ | ||
calldata: executorCalldata, | ||
recipient: GOV_BRIDGE_EXECUTOR, | ||
sender: oldEthExecutorLidoDAO.agent.address, | ||
}); | ||
|
||
const createVoteTx = await oldEthExecutorLidoDAO.createVote( | ||
l1LDOHolder, | ||
"Update ethereumGovernanceExecutor on Swellchain Governance Bridge Executor", | ||
{ | ||
address: oldEthExecutorLidoDAO.agent.address, | ||
signature: "execute(address,uint256,bytes)", | ||
decodedCallData: [ | ||
sweAddresses.L1CrossDomainMessenger, | ||
callvalue, | ||
calldata, | ||
], | ||
} | ||
); | ||
|
||
console.log("Creating voting to update ethereumGovernanceExecutor..."); | ||
await createVoteTx.wait(); | ||
console.log(`Vote was created!`); | ||
|
||
const votesCount = await oldEthExecutorLidoDAO.voting.votesLength(); | ||
const voteId = votesCount.sub(1); | ||
|
||
console.log(`New vote id ${voteId.toString()}`); | ||
console.log(`Voting for and executing the vote...`); | ||
|
||
const voteAndExecuteTx = await oldEthExecutorLidoDAO.voteAndExecute( | ||
l1LDOHolder, | ||
voteId, | ||
true | ||
); | ||
const executeTxReceipt = await voteAndExecuteTx.wait(); | ||
|
||
console.log(`Vote ${voteId.toString()} was executed!`); | ||
|
||
console.log(`Waiting for L2 transaction...`); | ||
await swellchain | ||
.messaging(networkName, { forking: isForking }) | ||
.waitForL2Message(executeTxReceipt.transactionHash); | ||
|
||
console.log(`Message delivered to L2`); | ||
|
||
console.log("Executing the queued task..."); | ||
// execute task on L2 | ||
const tasksCount = await govBridgeExecutor.getActionsSetCount(); | ||
const targetTaskId = tasksCount.toNumber() - 1; | ||
|
||
const tx = await govBridgeExecutor.execute(targetTaskId); | ||
await tx.wait(); | ||
console.log(`Task executed on L2!`); | ||
|
||
const ethereumGovernanceExecutor = | ||
await govBridgeExecutor.getEthereumGovernanceExecutor(); | ||
|
||
console.log( | ||
`New ethereum governance executor is: ${ethereumGovernanceExecutor}` | ||
); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
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
Oops, something went wrong.