Skip to content

Commit

Permalink
chore: add support for zkSync
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarinas committed May 21, 2024
1 parent 18353ce commit 5817641
Show file tree
Hide file tree
Showing 22 changed files with 194 additions and 111 deletions.
17 changes: 13 additions & 4 deletions modules/client-common/src/context-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ import {
UnsupportedProtocolError,
} from "./errors";
import {
ContractNames,
FrameworkContractsNames,
getNetworkDeploymentForVersion,
getNetworkNameByAlias,
NonFrameworkContractsNames,
SupportedVersions,
} from "@aragon/osx-commons-configs";

const DEFAULT_GAS_FEE_ESTIMATION_FACTOR = 0.625;
const supportedProtocols = ["https:"];
const contractNames = Object.values(ContractNames);
const contractNames = [
...Object.values(FrameworkContractsNames),
...Object.values(NonFrameworkContractsNames),
] as (FrameworkContractsNames | NonFrameworkContractsNames)[];
if (typeof process !== "undefined" && process?.env?.TESTING) {
supportedProtocols.push("http:");
}
Expand Down Expand Up @@ -130,7 +134,10 @@ export abstract class ContextCore {
}
// custom check for ensRegistryAddress
// set the ensRegistryAddress to the network.ensAddress
if (contractName === ContractNames.ENS_REGISTRY && !contractAddress) {
if (
contractName === NonFrameworkContractsNames.ENS_REGISTRY &&
!contractAddress
) {
contractAddress = this.network.ensAddress;
}
if (contractAddress) {
Expand Down Expand Up @@ -225,7 +232,9 @@ export abstract class ContextCore {
return this.state.graphql;
}

public getAddress(contractName: ContractNames): string {
public getAddress(
contractName: FrameworkContractsNames | NonFrameworkContractsNames,
): string | undefined {
return this.state[contractName];
}

Expand Down
10 changes: 8 additions & 2 deletions modules/client-common/src/internal/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { JsonRpcProvider } from "@ethersproject/providers";
import { Client as IpfsClient, PinResponse } from "@aragon/sdk-ipfs";
import { GraphQLClient } from "graphql-request";
import { GasFeeEstimation } from "../types";
import { ContractNames, SupportedNetworks } from "@aragon/osx-commons-configs";
import {
FrameworkContractsNames,
NonFrameworkContractsNames,
SupportedNetworks,
} from "@aragon/osx-commons-configs";

export interface IClientWeb3Core {
shiftProvider: () => void;
Expand All @@ -21,7 +25,9 @@ export interface IClientWeb3Core {
address: string,
abi: ContractInterface,
) => Contract & T;
getAddress: (addressName: ContractNames) => string;
getAddress: (
addressName: FrameworkContractsNames | NonFrameworkContractsNames,
) => string;
getApproximateGasFee: (estimatedFee: bigint) => Promise<GasFeeEstimation>;
}
export interface IClientIpfsCore {
Expand Down
7 changes: 5 additions & 2 deletions modules/client-common/src/internal/modules/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import {
UnsupportedNetworkError,
} from "../../errors";
import {
ContractNames,
FrameworkContractsNames,
getNetworkByAlias,
NonFrameworkContractsNames,
SupportedNetworks,
} from "@aragon/osx-commons-configs";
export class Web3Module implements IClientWeb3Core {
Expand Down Expand Up @@ -139,7 +140,9 @@ export class Web3Module implements IClientWeb3Core {
}

/** FRAMEWORK ADDRESSES */
public getAddress(addressName: ContractNames): string {
public getAddress(
addressName: FrameworkContractsNames | NonFrameworkContractsNames,
): string {
const address = this.context.getAddress(addressName);
if (!address || !isAddress(address)) {
throw new InvalidAddressError();
Expand Down
15 changes: 12 additions & 3 deletions modules/client-common/src/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { Signer } from "@ethersproject/abstract-signer";
import { JsonRpcProvider, Network, Networkish } from "@ethersproject/providers";
import { Client as IpfsClient } from "@aragon/sdk-ipfs";
import { GraphQLClient } from "graphql-request";
import { ContractNames } from "@aragon/osx-commons-configs";
import {
FrameworkContractsNames,
NonFrameworkContractsNames,
} from "@aragon/osx-commons-configs";

export type Web3ContextParams =
& {
[index in ContractNames]?: string;
[index in FrameworkContractsNames]?: string;
}
& {
[index in NonFrameworkContractsNames]?: string;
}
& {
/** Defaults to mainnet */
Expand All @@ -28,7 +34,10 @@ export type GraphQLContextParams = {

export type Web3ContextState =
& {
[index in ContractNames]: string;
[index in FrameworkContractsNames]: string;
}
& {
[index in NonFrameworkContractsNames]?: string;
}
& {
network: Network;
Expand Down
10 changes: 8 additions & 2 deletions modules/client-common/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ContractNames } from "@aragon/osx-commons-configs";
import {
FrameworkContractsNames,
NonFrameworkContractsNames,
} from "@aragon/osx-commons-configs";
import {
GraphQLContextParams,
GraphQLContextState,
Expand All @@ -20,7 +23,10 @@ export type ContextState =

export type OverriddenState =
& {
[key in ContractNames]: boolean;
[key in FrameworkContractsNames]: boolean;
}
& {
[key in NonFrameworkContractsNames]: boolean;
}
& {
gasFeeEstimationFactor: boolean;
Expand Down
4 changes: 2 additions & 2 deletions modules/client-common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
} from "./errors";
import { Zero } from "@ethersproject/constants";
import {
ContractNames,
FrameworkContractsNames,
getNetworkAlias,
getNetworkByChainId,
getNetworkByNameOrAlias,
Expand Down Expand Up @@ -180,7 +180,7 @@ export async function prepareGenericInstallationEstimation(
throw new UnsupportedNetworkError(networkName);
}
const pspContract = PluginSetupProcessor__factory.connect(
deployment[ContractNames.PLUGIN_SETUP_PROCESSOR].address,
deployment[FrameworkContractsNames.PLUGIN_SETUP_PROCESSOR].address,
provider,
);

Expand Down
49 changes: 30 additions & 19 deletions modules/client-common/test/unit/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { Client as IpfsClient } from "@aragon/sdk-ipfs";
import { JsonRpcProvider } from "@ethersproject/providers";
import { GraphQLClient } from "graphql-request";
import {
ContractNames,
contracts,
FrameworkContractsNames,
NonFrameworkContractsNames,
SupportedNetworks,
} from "@aragon/osx-commons-configs";

Expand Down Expand Up @@ -40,10 +41,12 @@ describe("Context instances", () => {
expect(context).toBeInstanceOf(TestContext);
expect(context.network.name).toBe("homestead");
expect(context.network.chainId).toBe(1);
expect(context.getAddress(ContractNames.DAO_FACTORY)).toBe(
expect(context.getAddress(FrameworkContractsNames.DAO_FACTORY)).toBe(
contracts.mainnet["v1.3.0"]?.DAOFactory.address,
);
expect(context.getAddress(ContractNames.ENS_REGISTRY)).toBe(context.network.ensAddress);
expect(context.getAddress(NonFrameworkContractsNames.ENS_REGISTRY)).toBe(
context.network.ensAddress,
);
expect(context.gasFeeEstimationFactor).toBe(0.625);
expect(context.web3Providers.length).toBe(0);
expect(context.ipfs.length).toBe(
Expand All @@ -68,10 +71,12 @@ describe("Context instances", () => {
expect(context).toBeInstanceOf(TestContext);
expect(context.network.name).toBe("homestead");
expect(context.network.chainId).toBe(1);
expect(context.getAddress(ContractNames.DAO_FACTORY)).toBe(
expect(context.getAddress(FrameworkContractsNames.DAO_FACTORY)).toBe(
contextParams.DAOFactory,
);
expect(context.getAddress(ContractNames.ENS_REGISTRY)).toBe(context.network.ensAddress);
expect(context.getAddress(NonFrameworkContractsNames.ENS_REGISTRY)).toBe(
context.network.ensAddress,
);
expect(context.gasFeeEstimationFactor).toBe(
contextParams.gasFeeEstimationFactor,
);
Expand Down Expand Up @@ -102,7 +107,9 @@ describe("Context instances", () => {
expect(context.network.name).toEqual("goerli");
expect(context.network.chainId).toEqual(5);
expect(context.signer).toBeInstanceOf(Wallet);
expect(context.getAddress(ContractNames.DAO_FACTORY)).toEqual("0x2345");
expect(context.getAddress(FrameworkContractsNames.DAO_FACTORY)).toEqual(
"0x2345",
);
context.web3Providers?.map((provider) =>
expect(provider).toBeInstanceOf(JsonRpcProvider)
);
Expand All @@ -122,10 +129,12 @@ describe("Context instances", () => {
expect(context).toBeInstanceOf(TestContext);
expect(context.network.name).toBe("goerli");
expect(context.network.chainId).toBe(5);
expect(context.getAddress(ContractNames.DAO_FACTORY)).toBe(
expect(context.getAddress(FrameworkContractsNames.DAO_FACTORY)).toBe(
contracts.goerli["v1.3.0"]?.DAOFactory.address,
);
expect(context.getAddress(ContractNames.ENS_REGISTRY)).toBe(context.network.ensAddress);
expect(context.getAddress(NonFrameworkContractsNames.ENS_REGISTRY)).toBe(
context.network.ensAddress,
);
expect(context.gasFeeEstimationFactor).toBe(0.625);
expect(context.web3Providers.length).toBe(1);
expect(context.ipfs.length).toBe(
Expand All @@ -149,10 +158,10 @@ describe("Context instances", () => {
});
expect(context.network.name).toBe("matic");
expect(context.network.chainId).toBe(137);
expect(context.getAddress(ContractNames.DAO_FACTORY)).toBe(
expect(context.getAddress(FrameworkContractsNames.DAO_FACTORY)).toBe(
contracts.polygon["v1.3.0"]?.DAOFactory.address,
);
expect(context.getAddress(ContractNames.ENS_REGISTRY)).toBe(
expect(context.getAddress(NonFrameworkContractsNames.ENS_REGISTRY)).toBe(
contracts.polygon["v1.3.0"]?.ENSRegistry?.address,
);
expect(context.gasFeeEstimationFactor).toBe(0.625);
Expand Down Expand Up @@ -182,10 +191,10 @@ describe("Context instances", () => {
});
expect(context.network.name).toBe("matic");
expect(context.network.chainId).toBe(137);
expect(context.getAddress(ContractNames.DAO_FACTORY)).toBe(
expect(context.getAddress(FrameworkContractsNames.DAO_FACTORY)).toBe(
contracts.polygon["v1.3.0"]?.DAOFactory.address,
);
expect(context.getAddress(ContractNames.ENS_REGISTRY)).toBe(
expect(context.getAddress(NonFrameworkContractsNames.ENS_REGISTRY)).toBe(
contracts.polygon["v1.3.0"]?.ENSRegistry?.address,
);
expect(context.gasFeeEstimationFactor).toBe(0.625);
Expand Down Expand Up @@ -229,10 +238,12 @@ describe("Context instances", () => {
expect(context).toBeInstanceOf(TestContext);
expect(context.network.name).toBe("matic");
expect(context.network.chainId).toBe(137);
expect(context.getAddress(ContractNames.DAO_FACTORY)).toBe(
expect(context.getAddress(FrameworkContractsNames.DAO_FACTORY)).toBe(
contracts.polygon["v1.3.0"]?.DAOFactory.address,
);
expect(context.getAddress(ContractNames.ENS_REGISTRY)).toBe(ADDRESS_ONE);
expect(context.getAddress(NonFrameworkContractsNames.ENS_REGISTRY)).toBe(
ADDRESS_ONE,
);
expect(context.gasFeeEstimationFactor).toBe(0.625);
expect(context.web3Providers.length).toBe(0);
expect(context.ipfs.length).toBe(
Expand Down Expand Up @@ -280,10 +291,10 @@ describe("Context instances", () => {
);
})
);
expect(context.getAddress(ContractNames.DAO_FACTORY)).toEqual(
expect(context.getAddress(FrameworkContractsNames.DAO_FACTORY)).toEqual(
contracts.polygon["v1.3.0"]?.DAOFactory.address,
);
expect(context.getAddress(ContractNames.ENS_REGISTRY)).toEqual(
expect(context.getAddress(NonFrameworkContractsNames.ENS_REGISTRY)).toEqual(
contracts.polygon["v1.3.0"]?.ENSRegistry?.address,
);
});
Expand All @@ -296,10 +307,10 @@ describe("Context instances", () => {
expect(context).toBeInstanceOf(TestContext);
expect(context.network.name).toBe("baseGoerli");
expect(context.network.chainId).toBe(84531);
expect(context.getAddress(ContractNames.DAO_FACTORY)).toBe(
expect(context.getAddress(FrameworkContractsNames.DAO_FACTORY)).toBe(
contracts.baseGoerli["v1.3.0"]?.DAOFactory.address,
);
expect(context.getAddress(ContractNames.ENS_REGISTRY)).toBe(
expect(context.getAddress(NonFrameworkContractsNames.ENS_REGISTRY)).toBe(
contracts.baseGoerli["v1.3.0"]?.ENSRegistry?.address,
);
expect(context.gasFeeEstimationFactor).toBe(0.625);
Expand All @@ -312,7 +323,7 @@ describe("Context instances", () => {
expect(nw.name).toEqual("baseGoerli");
expect(nw.ensAddress).toEqual(
contracts.baseGoerli["v1.3.0"]?.ENSRegistry?.address,
);
);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class AddresslistVotingClientEncoding extends ClientCore
],
);
const repoAddress = contracts[aragonNetwork][SupportedVersions.V1_3_0]
?.AddresslistVotingRepoProxy.address;
?.AddresslistVotingRepoProxy?.address;
if (!repoAddress) {
throw new Error("AddresslistVotingRepoProxy address not found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import {
import { IAddresslistVotingClientEstimation } from "../interfaces";
import { toUtf8Bytes } from "@ethersproject/strings";
import {
boolArrayToBitmap,
ClientCore,
decodeProposalId,
GasFeeEstimation,
prepareGenericUpdateEstimation,
SizeMismatchError,
boolArrayToBitmap,
} from "@aragon/sdk-client-common";
import { AddresslistVotingPluginPrepareUpdateParams } from "../../types";
import { ContractNames } from "@aragon/osx-commons-configs";
import {
FrameworkContractsNames,
NonFrameworkContractsNames,
} from "@aragon/osx-commons-configs";

/**
* Estimation module the SDK Address List Client
Expand Down Expand Up @@ -129,10 +132,10 @@ export class AddresslistVotingClientEstimation extends ClientCore
return await prepareGenericUpdateEstimation(this.web3, this.graphql, {
...params,
pluginSetupProcessorAddress: this.web3.getAddress(
ContractNames.PLUGIN_SETUP_PROCESSOR,
FrameworkContractsNames.PLUGIN_SETUP_PROCESSOR,
),
pluginRepo: this.web3.getAddress(
ContractNames.ADDRESSLIST_VOTING_REPO_PROXY,
NonFrameworkContractsNames.ADDRESSLIST_VOTING_REPO_PROXY,
),
});
}
Expand Down
Loading

0 comments on commit 5817641

Please sign in to comment.