Skip to content

Commit

Permalink
revert zksync fixes as it break existing projects
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Oct 18, 2024
1 parent e1842a3 commit 145c285
Show file tree
Hide file tree
Showing 12 changed files with 4,888 additions and 4,100 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"match-all": "^1.2.6",
"murmur-128": "^0.2.1",
"qs": "^6.9.4",
"zksync-ethers": "^5.8.0"
"zksync-ethers": "^5.0.0"
},
"scripts": {
"prepare": "node ./.setup.js",
Expand All @@ -96,4 +96,4 @@
"publish:release": "npm publish",
"prepublishOnly": "npm run build"
}
}
}
8,393 changes: 4,846 additions & 3,547 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions src/DeploymentFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import {
TransactionRequest,
TransactionResponse,
} from '@ethersproject/providers';
import { ContractFactory, PayableOverrides, Signer } from 'ethers';
import { ContractFactory, PayableOverrides, Signer, ethers } from 'ethers';
import { Artifact } from 'hardhat/types';
import * as zk from 'zksync-ethers';
import { Address, Deployment, DeployOptions, ExtendedArtifact, ZksyncOverrides, } from '../types';
import { Address, Deployment, DeployOptions, ExtendedArtifact } from '../types';
import { getAddress } from '@ethersproject/address';
import { keccak256 as solidityKeccak256 } from '@ethersproject/solidity';
import { hexConcat, hexlify } from '@ethersproject/bytes';
import { hexConcat } from '@ethersproject/bytes';

export class DeploymentFactory {
private factory: ContractFactory;
private artifact: Artifact | ExtendedArtifact;
private isZkSync: boolean;
private getArtifact: (name: string) => Promise<Artifact>;
private overrides: PayableOverrides & ZksyncOverrides;
private overrides: PayableOverrides;
private args: any[];
constructor(
getArtifact: (name: string) => Promise<Artifact>,
artifact: Artifact | ExtendedArtifact,
args: any[],
network: any,
ethersSigner?: Signer | zk.Signer,
overrides: PayableOverrides & ZksyncOverrides = {}
overrides: PayableOverrides = {}
) {
this.overrides = overrides;
this.getArtifact = getArtifact;
Expand All @@ -34,8 +34,7 @@ export class DeploymentFactory {
this.factory = new zk.ContractFactory(
artifact.abi,
artifact.bytecode,
ethersSigner as zk.Signer,
overrides.deploymentType
ethersSigner as zk.Signer
);
} else {
this.factory = new ContractFactory(
Expand Down Expand Up @@ -86,20 +85,17 @@ export class DeploymentFactory {
public async getDeployTransaction(): Promise<TransactionRequest> {
let overrides = this.overrides;
if (this.isZkSync) {
const baseDeps = await this.extractFactoryDeps(this.artifact);
const additionalDeps = this.overrides.additionalFactoryDeps ? this.overrides.additionalFactoryDeps.map((val) => hexlify(val)) : [];
const factoryDeps = [...baseDeps, ...additionalDeps];
const { customData, ..._overrides } = overrides ?? {};
overrides = {
..._overrides,
const factoryDeps = await this.extractFactoryDeps(this.artifact);
const customData = {
customData: {
factoryDeps,
...customData,
feeToken: zk.utils.ETH_ADDRESS,
},
};

delete overrides.deploymentType;
delete overrides.additionalFactoryDeps;
overrides = {
...overrides,
...customData,
};
}

return this.factory.getDeployTransaction(...this.args, overrides);
Expand Down
5 changes: 0 additions & 5 deletions src/DeploymentsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,6 @@ export class DeploymentsManager {
obj.factoryDeps = deployment.factoryDeps;
}

if (deployment.zksync?.deploymentType) {
obj.zksync = {};
obj.zksync.deploymentType = deployment.zksync.deploymentType;
}

this.db.deployments[name] = obj;
if (obj.address === undefined && obj.transactionHash !== undefined) {
let receiptFetched;
Expand Down
93 changes: 26 additions & 67 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {AddressZero} from '@ethersproject/constants';
import {BigNumber} from '@ethersproject/bignumber';
import {Wallet} from '@ethersproject/wallet';
import {keccak256 as solidityKeccak256} from '@ethersproject/solidity';
import {zeroPad, hexlify} from '@ethersproject/bytes';
import {zeroPad, hexlify, hexConcat} from '@ethersproject/bytes';
import {Interface, FunctionFragment} from '@ethersproject/abi';
import {
Deployment,
Expand Down Expand Up @@ -65,8 +65,6 @@ import {
import {getDerivationPath} from './hdpath';
import {bnReplacer} from './internal/utils';
import {DeploymentFactory} from './DeploymentFactory';
import { HardhatZksyncProvider } from './zksync/hardhat-zksync-provider';
import { getSignerAccounts } from './zksync/utils';

let LedgerSigner: any; // TODO type
let ethersprojectHardwareWalletsModule: any | undefined;
Expand Down Expand Up @@ -281,33 +279,26 @@ export function addHelpers(
) => Promise<void>;
};
} {
let provider: Web3Provider | HardhatZksyncProvider;
let provider: Web3Provider | zk.Web3Provider;
const availableAccounts: {[name: string]: boolean} = {};

async function init(): Promise<Web3Provider | HardhatZksyncProvider> {
async function init(): Promise<Web3Provider | zk.Web3Provider> {
if (!provider) {
await deploymentManager.setupAccounts();
if (network.zksync) {
provider = new HardhatZksyncProvider(network, network.config.url);
provider = new zk.Web3Provider(fixProvider(network.provider));
} else {
provider = new Web3Provider(fixProvider(network.provider));
}
try {
let accounts: string[] = [];
if(network.zksync){
accounts = await getSignerAccounts(network, provider as HardhatZksyncProvider);
} else{
accounts = await provider.send('eth_accounts', []);
}

const accounts = await provider.send('eth_accounts', []);
for (const account of accounts) {
availableAccounts[account.toLowerCase()] = true;
}

for (const address of deploymentManager.impersonatedAccounts) {
availableAccounts[address.toLowerCase()] = true;
}

} catch (e) {}
}
return provider;
Expand Down Expand Up @@ -537,47 +528,36 @@ export function addHelpers(
options
);

const salt =
typeof options.deterministicDeployment === 'string'
? hexlify(zeroPad(options.deterministicDeployment, 32))
: '0x0000000000000000000000000000000000000000000000000000000000000000';

const overrides: PayableOverrides = {
gasLimit: options.gasLimit,
gasPrice: options.gasPrice,
maxFeePerGas: options.maxFeePerGas,
maxPriorityFeePerGas: options.maxPriorityFeePerGas,
value: options.value,
nonce: options.nonce,
customData: options.customData,
};

overrides.customData = overrides.customData ?? {};
overrides.customData.salt = salt;
gasLimit: options.gasLimit,
gasPrice: options.gasPrice,
maxFeePerGas: options.maxFeePerGas,
maxPriorityFeePerGas: options.maxPriorityFeePerGas,
value: options.value,
nonce: options.nonce,
};

const factory = new DeploymentFactory(
getArtifact,
linkedArtifact,
args,
network,
ethersSigner,
{
...overrides,
deploymentType: options.zksync?.deploymentType,
additionalFactoryDeps: options.zksync?.additionalFactoryDeps,
}
overrides
);

const unsignedTx = await factory.getDeployTransaction();

let create2Address;

if (options.deterministicDeployment && !network.zksync) {
if (options.deterministicDeployment) {
if (typeof unsignedTx.data === 'string') {
const create2DeployerAddress = await ensureCreate2DeployerReady(
options
);
const create2Salt = salt;
const create2Salt =
typeof options.deterministicDeployment === 'string'
? hexlify(zeroPad(options.deterministicDeployment, 32))
: '0x0000000000000000000000000000000000000000000000000000000000000000';
create2Address = await factory.getCreate2Address(
create2DeployerAddress,
create2Salt
Expand Down Expand Up @@ -661,9 +641,6 @@ export function addHelpers(
transactionHash: receipt.transactionHash,
libraries: options.libraries,
factoryDeps: unsignedTx.customData?.factoryDeps || [],
zksync:{
deploymentType:options.zksync?.deploymentType ?? 'create',
}
};

await saveDeployment(name, deployment);
Expand Down Expand Up @@ -856,25 +833,19 @@ export function addHelpers(

const {ethersSigner} = await getFrom(options.from);
const {artifact: linkedArtifact} = await getLinkedArtifact(name, options);

const salt =
typeof options.deterministicDeployment === 'string'
? hexlify(zeroPad(options.deterministicDeployment, 32))
: '0x0000000000000000000000000000000000000000000000000000000000000000';

const factory = new DeploymentFactory(
getArtifact,
linkedArtifact,
args,
network,
ethersSigner,
{
deploymentType: options.zksync?.deploymentType
}
ethersSigner
);

if (options.deterministicDeployment) {
const create2Salt = salt;
const create2Salt =
typeof options.deterministicDeployment === 'string'
? hexlify(zeroPad(options.deterministicDeployment, 32))
: '0x0000000000000000000000000000000000000000000000000000000000000000';
const create2DeployerAddress =
await deploymentManager.getDeterministicDeploymentFactoryAddress();
const create2Address = await factory.getCreate2Address(
Expand Down Expand Up @@ -965,9 +936,6 @@ export function addHelpers(
linkedData: options.linkedData,
libraries: options.libraries,
args: argsArray,
zksync:{
deploymentType:options.zksync?.deploymentType,
}
};
await saveDeployment(name, newDeployment, artifactName);
result = {
Expand Down Expand Up @@ -995,9 +963,6 @@ export function addHelpers(
linkedData: options.linkedData,
libraries: options.libraries,
args: argsArray,
zksync:{
deploymentType:options.zksync?.deploymentType,
}
};
await saveDeployment(name, newDeployment, artifactName);
result = {
Expand Down Expand Up @@ -1702,14 +1667,8 @@ Note that in this case, the contract deployment will not behave the same if depl
from = wallet.address;
} else {
if (availableAccounts[from.toLowerCase()]) {
if(network.zksync){
ethersSigner = provider.getSigner(from);
} else {
network.provider.getSignerFrom(from)
ethersSigner = provider.getSigner(from);
}
}
else {
ethersSigner = provider.getSigner(from);
} else {
// TODO register protocol based account as availableAccounts ? if so do not else here
const registeredProtocol =
deploymentManager.addressesToProtocol[from.toLowerCase()];
Expand Down Expand Up @@ -2798,7 +2757,7 @@ data: ${data}
if (typeof args === 'undefined') {
args = [];
}
let caller: Web3Provider | Signer | zk.Web3Provider | zk.Signer | zk.Provider = provider;
let caller: Web3Provider | Signer | zk.Web3Provider | zk.Signer = provider;
const {ethersSigner} = await getOptionalFrom(options.from);
if (ethersSigner) {
caller = ethersSigner;
Expand Down
8 changes: 0 additions & 8 deletions src/zksync/constants.ts

This file was deleted.

32 changes: 0 additions & 32 deletions src/zksync/hardhat-zksync-eip712-signer.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/zksync/hardhat-zksync-provider.ts

This file was deleted.

Loading

0 comments on commit 145c285

Please sign in to comment.