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

Fix zksync compatibility #494

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 11 additions & 9 deletions src/DeploymentFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ export class DeploymentFactory {
): Promise<boolean> {
const newTransaction = await this.getDeployTransaction();
const newData = newTransaction.data?.toString();
if (this.isZkSync) {
const deserialize = zk.utils.parseTransaction(transaction.data) as any;
const desFlattened = hexConcat(deserialize.customData.factoryDeps);
const factoryDeps = await this.extractFactoryDeps(this.artifact);
const newFlattened = hexConcat(factoryDeps);
// NOTE: (25 Oct) zksync-era client does not support factoryDeps in transaction.data
// if (this.isZkSync) {
// const deserialize = zk.utils.parseTransaction(transaction.data) as any;
// const desFlattened = hexConcat(deserialize.customData.factoryDeps);
// const factoryDeps = await this.extractFactoryDeps(this.artifact);
// const newFlattened = hexConcat(factoryDeps);

return deserialize.data !== newData || desFlattened != newFlattened;
} else {
return transaction.data !== newData;
}
// return deserialize.data !== newData || desFlattened != newFlattened;
// } else {
// return transaction.data !== newData;
// }
return transaction.data !== newData;
}
}
132 changes: 106 additions & 26 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ export function addHelpers(
options
);

let overrides: PayableOverrides = {
const overrides: PayableOverrides = {
gasLimit: options.gasLimit,
gasPrice: options.gasPrice,
maxFeePerGas: options.maxFeePerGas,
Expand Down Expand Up @@ -1493,8 +1493,8 @@ Note that in this case, the contract deployment will not behave the same if depl
upgradeArgsTemplate = ['{implementation}', '{data}'];
}

let proxyAddress = proxy.address;
let upgradeArgs = replaceTemplateArgs(upgradeArgsTemplate, {
const proxyAddress = proxy.address;
const upgradeArgs = replaceTemplateArgs(upgradeArgsTemplate, {
implementationAddress: implementation.address,
proxyAdmin,
data,
Expand Down Expand Up @@ -1829,31 +1829,103 @@ Note that in this case, the contract deployment will not behave the same if depl
// console.log({ oldFacets: JSON.stringify(oldFacets, null, " ") });

const facetsSet = [...options.facets];
if (options.defaultCutFacet === undefined || options.defaultCutFacet) {
const getContractNameAndArtifact = async (
defaultName: string,
defaultArtifactData: ArtifactData,
args?: boolean | string | {name: string; artifact?: string | ArtifactData}
): Promise<
| {
name: string;
artifact: ArtifactData;
}
| undefined
> => {
if (args === false) {
return undefined;
}

if (args === undefined || args === true) {
return {
name: defaultName,
artifact: defaultArtifactData,
};
}

if (typeof args === 'string') {
try {
return {
name: defaultName,
artifact: await partialExtension.getExtendedArtifact(args),
};
} catch (e) {}

if (args === defaultName) {
return {
name: defaultName,
artifact: defaultArtifactData,
};
} else {
throw new Error(`no contract found for ${args}`);
}
}

const name = args.name;
let artifact: ArtifactData | undefined;
if (args.artifact === undefined) {
artifact = defaultArtifactData;
} else if (typeof args.artifact === 'string') {
artifact = await partialExtension.getExtendedArtifact(args.artifact);
} else {
artifact = args.artifact;
}

return {
name: name,
artifact: artifact,
};
};

const diamondCutFacetNameAndArtifact = await getContractNameAndArtifact(
'_DefaultDiamondCutFacet',
diamondCutFacet,
options.defaultCutFacetContract
);
if (diamondCutFacetNameAndArtifact) {
facetsSet.push({
name: '_DefaultDiamondCutFacet',
contract: diamondCutFacet,
name: diamondCutFacetNameAndArtifact.name,
contract: diamondCutFacetNameAndArtifact.artifact,
args: [],
deterministic: true,
});
}
if (
options.defaultOwnershipFacet === undefined ||
options.defaultOwnershipFacet
) {

const ownershipFacetNameAndArtifact = await getContractNameAndArtifact(
'_DefaultDiamondOwnershipFacet',
ownershipFacet,
options.defaultOwnershipFacetContract
);
if (ownershipFacetNameAndArtifact) {
facetsSet.push({
name: '_DefaultDiamondOwnershipFacet',
contract: ownershipFacet,
name: ownershipFacetNameAndArtifact.name,
contract: ownershipFacetNameAndArtifact.artifact,
args: [],
deterministic: true,
});
}

const diamondLoupeFacetNameAndArtifact = await getContractNameAndArtifact(
'_DefaultDiamondLoupeFacet',
diamondLoupeFacet,
options.defaultLoupeFacetContract
);
if (diamondLoupeFacetNameAndArtifact) {
facetsSet.push({
name: diamondLoupeFacetNameAndArtifact.name,
contract: diamondLoupeFacetNameAndArtifact.artifact,
args: [],
deterministic: true,
});
}
facetsSet.push({
name: '_DefaultDiamondLoupeFacet',
contract: diamondLoupeFacet,
args: [],
deterministic: true,
});

let changesDetected = !oldDeployment;
let abi: any[] = diamondArtifact.abi.concat([]);
Expand Down Expand Up @@ -2201,20 +2273,30 @@ Note that in this case, the contract deployment will not behave the same if depl
// TODO option to add more to the list
// else mechanism to set it up differently ? LoupeFacet without supportsInterface
const interfaceList = ['0x48e2b093'];
if (options.defaultCutFacet) {
if (options.defaultCutFacetContract) {
interfaceList.push('0x1f931c1c');
}
if (options.defaultOwnershipFacet) {
if (options.defaultOwnershipFacetContract) {
interfaceList.push('0x7f5828d0');
}

if (initializationsArgIndex >= 0 || erc165InitArgIndex >= 0) {
const diamondERC165InitNameAndArtifact =
await getContractNameAndArtifact(
'_DefaultDiamondERC165Init',
diamondERC165Init,
options.defaultERC165InitContract
);
if (!diamondERC165InitNameAndArtifact) {
throw new Error('no DiamondERC165Init artifact found');
}

const diamondERC165InitDeployment = await _deployOne(
'_DefaultDiamondERC165Init',
diamondERC165InitNameAndArtifact.name,
{
from: options.from,
deterministicDeployment: true,
contract: diamondERC165Init,
contract: diamondERC165InitNameAndArtifact.artifact,
autoMine: options.autoMine,
estimateGasExtra: options.estimateGasExtra,
estimatedGasLimit: options.estimatedGasLimit,
Expand Down Expand Up @@ -2784,9 +2866,7 @@ data: ${data}
}
async function getSigner(address: string): Promise<Signer> {
await init();
const {
ethersSigner
} = await getFrom(address);
const {ethersSigner} = await getFrom(address);
return ethersSigner;
}

Expand All @@ -2802,7 +2882,7 @@ data: ${data}
rawTx,
read,
deterministic,
getSigner
getSigner,
};

const utils = {
Expand Down
30 changes: 27 additions & 3 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,33 @@ export interface DiamondOptions extends TxOptions {
diamondContract?: string | ArtifactData; // TODO
diamondContractArgs?: any[];
owner?: Address;
// defaultLoopeFacet?: boolean; // TODO // always there
defaultOwnershipFacet?: boolean;
defaultCutFacet?: boolean;
defaultLoupeFacetContract?:
| boolean
| string
| {
name: string;
artifact?: string | ArtifactData;
};
defaultOwnershipFacetContract?:
| boolean
| string
| {
name: string;
artifact?: string | ArtifactData;
};
defaultCutFacetContract?:
| boolean
| string
| {
name: string;
artifact?: string | ArtifactData;
};
defaultERC165InitContract?:
| string
| {
name: string;
artifact?: string | ArtifactData;
};
facets: DiamondFacets;
log?: boolean;
libraries?: Libraries;
Expand Down