Skip to content

Commit

Permalink
add support for base-goerli
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarinas committed Jul 27, 2023
1 parent f29d8de commit 5627ea4
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 11 deletions.
4 changes: 2 additions & 2 deletions modules/client-common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aragon/sdk-client-common",
"author": "Aragon Association",
"version": "1.2.1-rc0",
"version": "1.3.0-rc0",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client-common.esm.js",
Expand Down Expand Up @@ -57,7 +57,7 @@
"typescript": "^4.6.2"
},
"dependencies": {
"@aragon/osx-ethers": "^1.3.0-rc0",
"@aragon/osx-ethers": "^1.3.0-rc0.1",
"@aragon/sdk-common": "^1.5.0",
"@aragon/sdk-ipfs": "^1.1.0",
"@ethersproject/abstract-signer": "^5.5.0",
Expand Down
35 changes: 34 additions & 1 deletion modules/client-common/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { activeContractsList } from "@aragon/osx-ethers";
import { ProposalMetadata, SupportedNetwork } from "./types";
import { NetworkDeployment } from "./internal";
import { Network } from "@ethersproject/networks";

/** Timeout that will be applied to operations involving
* many fetch requests that could take a long time */
export const MULTI_FETCH_TIMEOUT = 7 * 1000;

type GraphqlNetworks = "mainnet" | "goerli" | "polygon" | "mumbai";
type GraphqlNetworks =
| "mainnet"
| "goerli"
| "polygon"
| "mumbai"
| "baseTestnet";

const SupportedNetworksToGraphqlNetworks: {
[K in SupportedNetwork]: GraphqlNetworks;
Expand All @@ -15,6 +21,8 @@ const SupportedNetworksToGraphqlNetworks: {
[SupportedNetwork.GOERLI]: "goerli",
[SupportedNetwork.POLYGON]: "polygon",
[SupportedNetwork.MUMBAI]: "mumbai",
[SupportedNetwork.BASE_GOERLI]: "baseTestnet",
// [SupportedNetwork.LOCAL]: "" as GraphqlNetworks,
};

export const UNSUPPORTED_PROPOSAL_METADATA_LINK: ProposalMetadata = {
Expand Down Expand Up @@ -51,6 +59,9 @@ export const GRAPHQL_NODES: { [K in SupportedNetwork]: { url: string }[] } = {
url: getGraphqlNode(SupportedNetwork.POLYGON),
}],
[SupportedNetwork.MUMBAI]: [{ url: getGraphqlNode(SupportedNetwork.MUMBAI) }],
[SupportedNetwork.BASE_GOERLI]: [{
url: getGraphqlNode(SupportedNetwork.BASE_GOERLI),
}],
};

const IPFS_ENDPOINTS = {
Expand Down Expand Up @@ -82,6 +93,7 @@ export const IPFS_NODES: {
[SupportedNetwork.GOERLI]: IPFS_ENDPOINTS.test,
[SupportedNetwork.POLYGON]: IPFS_ENDPOINTS.prod,
[SupportedNetwork.MUMBAI]: IPFS_ENDPOINTS.test,
[SupportedNetwork.BASE_GOERLI]: IPFS_ENDPOINTS.test,
};

export const LIVE_CONTRACTS: { [K in SupportedNetwork]: NetworkDeployment } = {
Expand Down Expand Up @@ -139,4 +151,25 @@ export const LIVE_CONTRACTS: { [K in SupportedNetwork]: NetworkDeployment } = {
tokenVotingSetup: activeContractsList.polygon.TokenVotingSetup,
ensRegistry: activeContractsList.polygon.ENSRegistry,
},
[SupportedNetwork.BASE_GOERLI]: {
daoFactory: activeContractsList.baseGoerli.DAOFactory,
pluginSetupProcessor: activeContractsList.baseGoerli.PluginSetupProcessor,
multisigRepo: activeContractsList.baseGoerli["multisig-repo"],
adminRepo: activeContractsList.baseGoerli["admin-repo"],
addresslistVotingRepo:
activeContractsList.baseGoerli["address-list-voting-repo"],
tokenVotingRepo: activeContractsList.baseGoerli["token-voting-repo"],
multisigSetup: activeContractsList.baseGoerli.MultisigSetup,
adminSetup: activeContractsList.baseGoerli.AdminSetup,
addresslistVotingSetup:
activeContractsList.baseGoerli.AddresslistVotingSetup,
tokenVotingSetup: activeContractsList.baseGoerli.TokenVotingSetup,
ensRegistry: activeContractsList.baseGoerli.ENSRegistry,
},
};
export const ADDITIONAL_NETWORKS: Network[] = [
{
name: "baseGoerli",
chainId: 84531,
},
];
2 changes: 1 addition & 1 deletion modules/client-common/src/context-core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
getNetwork,
JsonRpcProvider,
Network,
Networkish,
Expand All @@ -22,6 +21,7 @@ import {
SupportedNetworksArray,
} from "./types";
import { GRAPHQL_NODES, IPFS_NODES, LIVE_CONTRACTS } from "./constants";
import { getNetwork } from "./utils";

const DEFAULT_GAS_FEE_ESTIMATION_FACTOR = 0.625;
const supportedProtocols = ["https:"];
Expand Down
1 change: 1 addition & 0 deletions modules/client-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum SupportedNetwork {
GOERLI = "goerli",
POLYGON = "matic",
MUMBAI = "maticmum",
BASE_GOERLI = "baseGoerli",
}

export const SupportedNetworksArray = Object.values(SupportedNetwork);
Expand Down
30 changes: 28 additions & 2 deletions modules/client-common/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FunctionFragment, Interface } from "@ethersproject/abi";
import { id } from "@ethersproject/hash";
import { Log } from "@ethersproject/providers";
import { Log, Networkish } from "@ethersproject/providers";
import { ContractReceipt } from "@ethersproject/contracts";
import {
bytesToHex,
Expand All @@ -19,9 +19,11 @@ import {
PluginRepo__factory,
PluginSetupProcessor__factory,
} from "@aragon/osx-ethers";
import { LIVE_CONTRACTS } from "./constants";
import { ADDITIONAL_NETWORKS, LIVE_CONTRACTS } from "./constants";
import { defaultAbiCoder } from "@ethersproject/abi";
import { isAddress } from "@ethersproject/address";
import { Network } from "@ethersproject/networks";
import { getNetwork as ethersGetNetwork } from "@ethersproject/providers";

export function findLog(
receipt: ContractReceipt,
Expand Down Expand Up @@ -195,3 +197,27 @@ export async function* prepareGenericInstallation(
helpers: preparedSetupData.helpers,
};
}

export function getNetwork(networkish: Networkish): Network {
let network: Network | undefined;
for (const nw of ADDITIONAL_NETWORKS) {
if (typeof networkish === "string") {
if (networkish === nw.name) {
network = nw;
}
} else if (typeof networkish === "number") {
if (networkish === nw.chainId) {
network = nw;
}
} else if (typeof networkish === "object") {
if (networkish.name === nw.name && networkish.chainId === nw.chainId) {
network = nw;
}
}
}
if(!network){
network = ethersGetNetwork(networkish);
}

return network;
}
27 changes: 27 additions & 0 deletions modules/client-common/test/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,31 @@ describe("Context instances", () => {
LIVE_CONTRACTS.matic.ensRegistry,
);
});
it("Should create a context with baseGoerli as network and have the correct values", () => {
const contextParams = {
network: "baseGoerli",
web3Providers: "https://goerli.base.org",
};
const context = new TestContext(contextParams);
expect(context).toBeInstanceOf(TestContext);
expect(context.network.name).toBe("baseGoerli");
expect(context.network.chainId).toBe(84531);
expect(context.daoFactoryAddress).toBe(
LIVE_CONTRACTS.baseGoerli.daoFactory,
);
expect(context.ensRegistryAddress).toBe(
LIVE_CONTRACTS.baseGoerli.ensRegistry,
);
expect(context.gasFeeEstimationFactor).toBe(0.625);
expect(context.web3Providers.length).toBe(1);
for (const provider of context.web3Providers) {
expect(provider).toBeInstanceOf(JsonRpcProvider);
expect(provider.connection.url).toBe("https://goerli.base.org/");
provider.getNetwork().then((nw) => {
expect(nw.chainId).toEqual(84531);
expect(nw.name).toEqual("baseGoerli");
expect(nw.ensAddress).toEqual(LIVE_CONTRACTS.baseGoerli.ensRegistry);
});
}
});
});
2 changes: 1 addition & 1 deletion modules/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"dependencies": {
"@aragon/osx-ethers": "1.3.0-rc0",
"@aragon/sdk-client-common": "^1.2.1-rc0",
"@aragon/sdk-client-common": "^1.3.0-rc0",
"@aragon/sdk-common": "^1.5.0",
"@aragon/sdk-ipfs": "^1.1.0",
"@ethersproject/abstract-signer": "^5.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {
import { IAddresslistVotingClientEncoding } from "../interfaces";
import { AddresslistVoting__factory } from "@aragon/osx-ethers";
import { defaultAbiCoder } from "@ethersproject/abi";
import { getNetwork, Networkish } from "@ethersproject/providers";
import { Networkish } from "@ethersproject/providers";
import { AddresslistVotingPluginInstall } from "../../types";
import {
ClientCore,
DaoAction,
getNamedTypesFromMetadata,
getNetwork,
LIVE_CONTRACTS,
PluginInstallItem,
SupportedNetwork,
Expand Down
3 changes: 2 additions & 1 deletion modules/client/src/multisig/internal/client/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import {
// todo fix new contracts-ethers
import { Multisig__factory } from "@aragon/osx-ethers";
import { defaultAbiCoder } from "@ethersproject/abi";
import { getNetwork, Networkish } from "@ethersproject/providers";
import { Networkish } from "@ethersproject/providers";
import { IMultisigClientEncoding } from "../interfaces";
import {
ClientCore,
DaoAction,
getNamedTypesFromMetadata,
getNetwork,
LIVE_CONTRACTS,
PluginInstallItem,
SupportedNetwork,
Expand Down
3 changes: 2 additions & 1 deletion modules/client/src/tokenVoting/internal/client/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import {
tokenVotingInitParamsToContract,
} from "../utils";
import { defaultAbiCoder } from "@ethersproject/abi";
import { getNetwork, Networkish } from "@ethersproject/providers";
import { Networkish } from "@ethersproject/providers";
import {
ClientCore,
DaoAction,
getNamedTypesFromMetadata,
getNetwork,
LIVE_CONTRACTS,
PluginInstallItem,
SupportedNetwork,
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
"@jridgewell/gen-mapping" "^0.1.0"
"@jridgewell/trace-mapping" "^0.3.9"

"@aragon/[email protected]", "@aragon/osx-ethers@^1.3.0-rc0":
"@aragon/[email protected]":
version "1.3.0-rc0"
resolved "https://registry.yarnpkg.com/@aragon/osx-ethers/-/osx-ethers-1.3.0-rc0.tgz#f706b007f8e3c95418f6ba8dab7bdeeb97858378"
integrity sha512-iPTkjnmIToVc6x+4xfBByMskX0VhYrNvHlolsewLHz3wuJONx08dUODAxnMgU17X9H8UXxuLcApTf+KvhUezxg==
dependencies:
ethers "^5.6.2"

"@aragon/osx-ethers@^1.3.0-rc0.1":
version "1.3.0-rc0.1"
resolved "https://registry.yarnpkg.com/@aragon/osx-ethers/-/osx-ethers-1.3.0-rc0.1.tgz#d8168205d76edfae42e961d5eab5e545c1bacb99"
integrity sha512-KjaEoIXG6+P6cxfX2FzmlTc+A67+l44FxpnSSW0GljyI5kcdFlXIrsgOeyj8iIcKo2iHsCkPibjjNgSc3sP6QA==
dependencies:
ethers "^5.6.2"

"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.18.6", "@babel/code-frame@^7.5.5":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.18.6.tgz#3b25d38c89600baa2dcc219edfa88a74eb2c427a"
Expand Down

0 comments on commit 5627ea4

Please sign in to comment.