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

Feature: Add support for base-goerli #263

Merged
merged 6 commits into from
Jul 31, 2023
Merged
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
3 changes: 3 additions & 0 deletions modules/client-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ TEMPLATE:
-->

## [UPCOMING]
### Added
- Support for baseGoerli network
## 1.2.1-rc0
### Fixed
- Default ipfs endpoints
## 1.2.0-rc0
Expand Down
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",
josemarinas marked this conversation as resolved.
Show resolved Hide resolved
"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
39 changes: 37 additions & 2 deletions modules/client-common/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { FunctionFragment, Interface } from "@ethersproject/abi";
import { id } from "@ethersproject/hash";
import { Log } from "@ethersproject/providers";
import {
getNetwork as ethersGetNetwork,
Log,
Networkish,
} from "@ethersproject/providers";
import { ContractReceipt } from "@ethersproject/contracts";
import {
bytesToHex,
InvalidAddressError,
PluginInstallationPreparationError,
UnsupportedNetworkError,
} from "@aragon/sdk-common";
import {
MetadataAbiInput,
Expand All @@ -19,9 +24,10 @@ 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";

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

export function getNetwork(networkish: Networkish): Network {
let network: Network | undefined;
for (const nw of ADDITIONAL_NETWORKS) {
switch (typeof networkish) {
case "string":
if (networkish === nw.name) {
network = nw;
}
break;
case "number":
if (networkish === nw.chainId) {
network = nw;
}
break;
case "object":
if (networkish.name === nw.name && networkish.chainId === nw.chainId) {
network = nw;
}
break;
default:
throw new UnsupportedNetworkError(networkish);
}
}
if (!network) {
network = ethersGetNetwork(networkish);
}
return network;
}
28 changes: 28 additions & 0 deletions modules/client-common/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,32 @@ describe("Test an extended client", () => {
expect(graphqlClient).toBeDefined();

});

it("Should create a client with baseGoerli context parameters", async () => {
const contextParams: ContextParams = {
network: "baseGoerli",
signer: new Wallet(TEST_WALLET),
web3Providers: "https://goerli.base.org"
}
const ctx = new TestContext(contextParams);
const client = new TestClient(ctx);
expect(client).toBeDefined();
expect(ctx).toBeDefined();
expect(client.web3).toBeDefined();
expect(client.ipfs).toBeDefined();
expect(client.graphql).toBeDefined();

const networkName = client.web3.getNetworkName()
expect(networkName).toBe("baseGoerli");
const signer = client.web3.getConnectedSigner();
expect(signer).toBeDefined();
expect(await signer.getAddress()).toBe(TEST_WALLET_ADDRESS);

const ipfsClient = client.ipfs.getClient();
expect(ipfsClient).toBeDefined();
expect(DEFAULT_IPFS_ENDPOINTS.includes(ipfsClient.url.toString())).toBe(true);

const graphqlClient = client.graphql.getClient();
expect(graphqlClient).toBeDefined();
})
});
1 change: 1 addition & 0 deletions modules/client-common/test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const web3endpoints = {

export const DEFAULT_IPFS_ENDPOINTS = [
"https://prod.ipfs.aragon.network/api/v0/",
"https://test.ipfs.aragon.network/api/v0/",
];

export const TEST_ABI: MetadataAbiInput[] = [
Expand Down
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", () => {
heueristik marked this conversation as resolved.
Show resolved Hide resolved
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);
});
}
});
});
1 change: 1 addition & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ TEMPLATE:
- Added `initializeFrom` encoders and decoders
- Support for ERC721 deposits and withdrawals
- Added `getProtocolVersion` function
- Support for baseGoerli network with the new client-common version
### Fixes
- Fix status calculation for token voting proposals
- Make the `network` parameter required on `getPluginInstallItem`
Expand Down
4 changes: 2 additions & 2 deletions modules/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
"typescript": "^4.6.2"
},
"dependencies": {
"@aragon/osx-ethers": "1.3.0-rc0",
"@aragon/sdk-client-common": "^1.2.1-rc0",
"@aragon/osx-ethers": "1.3.0-rc0.1",
"@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
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"@jridgewell/gen-mapping" "^0.1.0"
"@jridgewell/trace-mapping" "^0.3.9"

"@aragon/[email protected]", "@aragon/osx-ethers@^1.3.0-rc0":
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==
"@aragon/[email protected].1", "@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"

Expand Down
Loading