Skip to content

Commit

Permalink
Merge pull request #6 from matter-labs/vb-fmt-contracts
Browse files Browse the repository at this point in the history
Pressier on contracts
  • Loading branch information
vladbochok authored Jan 16, 2023
2 parents 279fb41 + 372f238 commit 4a659a6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 20 deletions.
7 changes: 5 additions & 2 deletions ethereum/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ async function main() {
await deployer.deployCreate2Factory({ gasPrice, nonce });
nonce++;
}

// Deploy diamond upgrade init contract if needed
const diamondUpgradeContractVersion = cmd.diamondUpgradeInit;
if (diamondUpgradeContractVersion) {
await deployer.deployDiamondUpgradeInit(create2Salt, diamondUpgradeContractVersion, { gasPrice, nonce });
await deployer.deployDiamondUpgradeInit(create2Salt, diamondUpgradeContractVersion, {
gasPrice,
nonce
});
nonce++;
}

Expand Down
3 changes: 2 additions & 1 deletion ethereum/scripts/diamond-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ async function main() {
print('Facets', facets);
});

program.command('legacy-prepare-upgrade-calldata <facetCuts>')
program
.command('legacy-prepare-upgrade-calldata <facetCuts>')
.option('--init-address <init-address>')
.option('--init-data <init-data>')
.action(async (facetCutsData: string, cmd) => {
Expand Down
15 changes: 10 additions & 5 deletions ethereum/scripts/upgrades/upgrade-3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ async function prepareCalldata(
diamondUpgradeAddress: string,
allowlist: string,
verifier: string,
prioirityTxMaxErgsLimit: string,
prioirityTxMaxErgsLimit: string
) {
const DiamondUpgradeInit3 = await ethers.getContractAt('DiamondUpgradeInit3', ZERO_ADDRESS);

// Prepare the diamond cut data
const upgradeInitData = await DiamondUpgradeInit3.interface.encodeFunctionData('upgrade', [
allowlist,
verifier,
prioirityTxMaxErgsLimit,
prioirityTxMaxErgsLimit
]);

return diamondCut([], diamondUpgradeAddress, upgradeInitData);
Expand Down Expand Up @@ -85,7 +85,7 @@ async function main() {
governorAddress: ZERO_ADDRESS,
verbose: true
});

const zkSyncContract = IOldDiamondCutFactory.connect(deployer.addresses.ZkSync.DiamondProxy, deployWallet);

// Get address of the diamond init contract
Expand All @@ -97,8 +97,13 @@ async function main() {
// Get the prioirity tx max ergs limit
const prioirityTxMaxErgsLimit = cmd.prioirityTxMaxErgsLimit;
// Get diamond cut data
const upgradeParam = await prepareCalldata(diamondUpgradeAddress, allowlist, verifier, prioirityTxMaxErgsLimit);

const upgradeParam = await prepareCalldata(
diamondUpgradeAddress,
allowlist,
verifier,
prioirityTxMaxErgsLimit
);

const proposeUpgradeTx = await zkSyncContract.proposeDiamondCut(
upgradeParam.facetCuts,
upgradeParam.initAddress
Expand Down
12 changes: 6 additions & 6 deletions ethereum/scripts/upgrades/upgrade-4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ async function prepareCalldata(
params: Array<ForceDeployment>
) {
const DiamondUpgradeInit4 = await ethers.getContractAt('DiamondUpgradeInit4', ZERO_ADDRESS);
const oldDeployerSystemContract = await ethers.getContractAt('cache/solpp-generated-contracts/zksync/upgrade-initializers/DiamondUpgradeInit4.sol:IOldContractDeployer', ZERO_ADDRESS);
const oldDeployerSystemContract = await ethers.getContractAt(
'cache/solpp-generated-contracts/zksync/upgrade-initializers/DiamondUpgradeInit4.sol:IOldContractDeployer',
ZERO_ADDRESS
);
const newDeployerSystemContract = await ethers.getContractAt('IContractDeployer', ZERO_ADDRESS);

const upgradeDeployerParams: ForceDeploymentOld = {
Expand Down Expand Up @@ -122,12 +125,9 @@ async function main() {
const params: Array<ForceDeployment> = JSON.parse(cmd.deploymentParams);
// Get diamond cut data
const upgradeParam = await prepareCalldata(diamondUpgradeAddress, deployerBytecodeHash, params);

const proposalId = cmd.proposalId ? cmd.proposalId : await zkSyncContract.getCurrentProposalId();
const proposeUpgradeTx = await zkSyncContract.proposeTransparentUpgrade(
upgradeParam,
proposalId
);
const proposeUpgradeTx = await zkSyncContract.proposeTransparentUpgrade(upgradeParam, proposalId);
await proposeUpgradeTx.wait();

const executeUpgradeTx = await zkSyncContract.executeUpgrade(upgradeParam, ethers.constants.HashZero);
Expand Down
15 changes: 12 additions & 3 deletions ethereum/src.ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,18 @@ export class Deployer {
this.addresses.ZkSync.DiamondInit = contractAddress;
}

public async deployDiamondUpgradeInit(create2Salt: string, contractVersion: number, ethTxOptions: ethers.providers.TransactionRequest) {
public async deployDiamondUpgradeInit(
create2Salt: string,
contractVersion: number,
ethTxOptions: ethers.providers.TransactionRequest
) {
ethTxOptions.gasLimit ??= 10_000_000;
const contractAddress = await this.deployViaCreate2(`DiamondUpgradeInit${contractVersion}`, [], create2Salt, ethTxOptions);
const contractAddress = await this.deployViaCreate2(
`DiamondUpgradeInit${contractVersion}`,
[],
create2Salt,
ethTxOptions
);

if (this.verbose) {
console.log(`CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=${contractAddress}`);
Expand Down Expand Up @@ -414,7 +423,7 @@ export class Deployer {
this.deployGovernanceFacet(create2Salt, { gasPrice, nonce: nonce + 3 }),
this.deployGettersFacet(create2Salt, { gasPrice, nonce: nonce + 4 }),
this.deployVerifier(create2Salt, { gasPrice, nonce: nonce + 5 }),
this.deployDiamondInit(create2Salt, { gasPrice, nonce: nonce + 6 }),
this.deployDiamondInit(create2Salt, { gasPrice, nonce: nonce + 6 })
];
await Promise.all(independentZkSyncDeployPromises);
nonce += 8;
Expand Down
20 changes: 17 additions & 3 deletions zksync/src/publish-bridge-preimages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,25 @@ async function main() {

const deployer = new Deployer({ deployWallet: wallet });
const zkSync = deployer.zkSyncContract(wallet);

const publishL2EthBridgeTx = await zkSync.requestL2Transaction(ethers.constants.AddressZero, 0, "0x", PRIORITY_TX_MAX_ERGS_LIMIT, [getContractBytecode("L2ETHBridge")], {nonce, gasPrice});

const publishL2EthBridgeTx = await zkSync.requestL2Transaction(
ethers.constants.AddressZero,
0,
'0x',
PRIORITY_TX_MAX_ERGS_LIMIT,
[getContractBytecode('L2ETHBridge')],
{ nonce, gasPrice }
);
await publishL2EthBridgeTx.wait();

const publishL2ERC20BridgeTx = await zkSync.requestL2Transaction(ethers.constants.AddressZero, 0, "0x", PRIORITY_TX_MAX_ERGS_LIMIT, [getContractBytecode("L2ERC20Bridge")], {nonce: nonce+1, gasPrice});
const publishL2ERC20BridgeTx = await zkSync.requestL2Transaction(
ethers.constants.AddressZero,
0,
'0x',
PRIORITY_TX_MAX_ERGS_LIMIT,
[getContractBytecode('L2ERC20Bridge')],
{ nonce: nonce + 1, gasPrice }
);
await publishL2ERC20BridgeTx.wait();
});

Expand Down

0 comments on commit 4a659a6

Please sign in to comment.