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 isDaoUpdateProposal #283

Merged
merged 5 commits into from
Oct 5, 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
1 change: 1 addition & 0 deletions modules/client-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ TEMPLATE:

- Add generic prepare update function
- Add generic prepare update estimation function
- Support for multiple versions on `LIVE_CONTRACTS`

## 1.5.0-rc0

Expand Down
5 changes: 3 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.5.0-rc0",
"version": "1.6.0",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client-common.esm.js",
Expand Down Expand Up @@ -57,8 +57,9 @@
"typescript": "^4.6.2"
},
"dependencies": {
"@aragon/osx-ethers-v1.0.0": "npm:@aragon/[email protected]",
"@aragon/osx-ethers": "^1.3.0-rc0.2",
"@aragon/sdk-common": "^1.5.0",
"@aragon/sdk-common": "^1.7.0",
"@aragon/sdk-ipfs": "^1.1.0",
"@ethersproject/abstract-signer": "^5.5.0",
"@ethersproject/bignumber": "^5.6.0",
Expand Down
332 changes: 225 additions & 107 deletions modules/client-common/src/constants.ts

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions modules/client-common/src/context-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
OverriddenState,
SupportedNetwork,
SupportedNetworksArray,
SupportedVersion,
} from "./types";
import { GRAPHQL_NODES, IPFS_NODES, LIVE_CONTRACTS } from "./constants";
import { getNetwork } from "./utils";
Expand Down Expand Up @@ -110,7 +111,7 @@ export abstract class ContextCore {
if (
!GRAPHQL_NODES[networkName]?.length ||
!IPFS_NODES[networkName]?.length ||
!LIVE_CONTRACTS[networkName]
!LIVE_CONTRACTS[SupportedVersion.LATEST][networkName]
) {
throw new UnsupportedNetworkError(networkName);
}
Expand All @@ -127,7 +128,8 @@ export abstract class ContextCore {

for (const address of DeployedAddressesArray) {
if (!this.overriden[address]) {
let defaultAddress = LIVE_CONTRACTS[networkName][address];
let defaultAddress =
LIVE_CONTRACTS[SupportedVersion.LATEST][networkName][address];
// custom check for ensRegistryAddress
if (address === "ensRegistryAddress" && !defaultAddress) {
defaultAddress = this.network.ensAddress;
Expand Down Expand Up @@ -360,7 +362,8 @@ export abstract class ContextCore {
}

if (!network.ensAddress) {
const ensAddress = LIVE_CONTRACTS[networkName].ensRegistryAddress;
const ensAddress =
LIVE_CONTRACTS[SupportedVersion.LATEST][networkName].ensRegistryAddress;
if (!ensAddress) {
throw new UnsupportedNetworkError(networkName);
}
Expand Down
5 changes: 5 additions & 0 deletions modules/client-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,8 @@ export type ApplyUpdateParams = ApplyUpdateParamsBase & {
export type DecodedApplyUpdateParams = ApplyUpdateParamsBase & {
helpersHash: string;
};
export enum SupportedVersion {
V1_0_0 = "1.0.0",
V1_3_0 = "1.3.0",
LATEST = "1.3.0",
}
4 changes: 3 additions & 1 deletion modules/client-common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
PrepareUpdateStep,
PrepareUpdateStepValue,
SupportedNetwork,
SupportedVersion,
} from "./types";
import {
IClientGraphQLCore,
Expand Down Expand Up @@ -123,7 +124,8 @@ export async function prepareGenericInstallationEstimation(
);
// connect to psp contract
const pspContract = PluginSetupProcessor__factory.connect(
LIVE_CONTRACTS[networkName].pluginSetupProcessorAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST][networkName]
.pluginSetupProcessorAddress,
provider,
);

Expand Down
27 changes: 14 additions & 13 deletions modules/client-common/test/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GRAPHQL_NODES,
IPFS_NODES,
LIVE_CONTRACTS,
SupportedVersion,
} from "../src";
import { ADDRESS_ONE, TEST_WALLET, web3endpoints } from "./constants";
import { Client as IpfsClient } from "@aragon/sdk-ipfs";
Expand Down Expand Up @@ -37,7 +38,7 @@ describe("Context instances", () => {
expect(context.network.name).toBe("homestead");
expect(context.network.chainId).toBe(1);
expect(context.daoFactoryAddress).toBe(
LIVE_CONTRACTS.homestead.daoFactoryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].homestead.daoFactoryAddress,
);
expect(context.ensRegistryAddress).toBe(context.network.ensAddress);
expect(context.gasFeeEstimationFactor).toBe(0.625);
Expand Down Expand Up @@ -113,7 +114,7 @@ describe("Context instances", () => {
expect(context.network.name).toBe("goerli");
expect(context.network.chainId).toBe(5);
expect(context.daoFactoryAddress).toBe(
LIVE_CONTRACTS.goerli.daoFactoryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].goerli.daoFactoryAddress,
);
expect(context.ensRegistryAddress).toBe(context.network.ensAddress);
expect(context.gasFeeEstimationFactor).toBe(0.625);
Expand All @@ -136,10 +137,10 @@ describe("Context instances", () => {
expect(context.network.name).toBe("matic");
expect(context.network.chainId).toBe(137);
expect(context.daoFactoryAddress).toBe(
LIVE_CONTRACTS.matic.daoFactoryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].matic.daoFactoryAddress,
);
expect(context.ensRegistryAddress).toBe(
LIVE_CONTRACTS.matic.ensRegistryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].matic.ensRegistryAddress,
);
expect(context.gasFeeEstimationFactor).toBe(0.625);
expect(context.web3Providers.length).toBe(1);
Expand All @@ -165,10 +166,10 @@ describe("Context instances", () => {
expect(context.network.name).toBe("matic");
expect(context.network.chainId).toBe(137);
expect(context.daoFactoryAddress).toBe(
LIVE_CONTRACTS.matic.daoFactoryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].matic.daoFactoryAddress,
);
expect(context.ensRegistryAddress).toBe(
LIVE_CONTRACTS.matic.ensRegistryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].matic.ensRegistryAddress,
);
expect(context.gasFeeEstimationFactor).toBe(0.625);
expect(context.web3Providers.length).toBe(1);
Expand Down Expand Up @@ -208,7 +209,7 @@ describe("Context instances", () => {
expect(context.network.name).toBe("matic");
expect(context.network.chainId).toBe(137);
expect(context.daoFactoryAddress).toBe(
LIVE_CONTRACTS.matic.daoFactoryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].matic.daoFactoryAddress,
);
expect(context.ensRegistryAddress).toBe(ADDRESS_ONE);
expect(context.gasFeeEstimationFactor).toBe(0.625);
Expand Down Expand Up @@ -250,14 +251,14 @@ describe("Context instances", () => {
provider.getNetwork().then((nw) => {
expect(nw.chainId).toEqual(137);
expect(nw.name).toEqual("matic");
expect(nw.ensAddress).toEqual(LIVE_CONTRACTS.matic.ensRegistryAddress);
expect(nw.ensAddress).toEqual(LIVE_CONTRACTS[SupportedVersion.LATEST].matic.ensRegistryAddress);
})
);
expect(context.daoFactoryAddress).toEqual(
LIVE_CONTRACTS.matic.daoFactoryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].matic.daoFactoryAddress,
);
expect(context.ensRegistryAddress).toEqual(
LIVE_CONTRACTS.matic.ensRegistryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].matic.ensRegistryAddress,
);
});
it("Should create a context with baseGoerli as network and have the correct values", () => {
Expand All @@ -270,10 +271,10 @@ describe("Context instances", () => {
expect(context.network.name).toBe("baseGoerli");
expect(context.network.chainId).toBe(84531);
expect(context.daoFactoryAddress).toBe(
LIVE_CONTRACTS.baseGoerli.daoFactoryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].baseGoerli.daoFactoryAddress,
);
expect(context.ensRegistryAddress).toBe(
LIVE_CONTRACTS.baseGoerli.ensRegistryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].baseGoerli.ensRegistryAddress,
);
expect(context.gasFeeEstimationFactor).toBe(0.625);
expect(context.web3Providers.length).toBe(1);
Expand All @@ -284,7 +285,7 @@ describe("Context instances", () => {
expect(nw.chainId).toEqual(84531);
expect(nw.name).toEqual("baseGoerli");
expect(nw.ensAddress).toEqual(
LIVE_CONTRACTS.baseGoerli.ensRegistryAddress,
LIVE_CONTRACTS[SupportedVersion.LATEST].baseGoerli.ensRegistryAddress,
);
});
}
Expand Down
1 change: 1 addition & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ TEMPLATE:

- Add prepareUpdate function to all clients
- Plugin update check function
- Dao update check function

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Check proposal is a plugin update proposal

### Check if a proposal contains the actions required to update a plugin

Goes though the actions of an `IProposal` compatible proposal and checks that the actions are valid for updating a plugin
Goes though a list of actions and checks that contains the necessary actions for updating a plugin
*/

import { Client } from "@aragon/sdk-client";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* MARKDOWN
---
title: Check dao update proposal
---

### Check if a dap update proposal is valid

Goes though the actions of an `IProposal` compatible proposal and checks that the actions are valid for updating a dao

*/

import { Client } from "@aragon/sdk-client";
import { context } from "../index";

// Instantiate the general purpose client from the Aragon OSx SDK context.
const client: Client = new Client(context);

const proposalId =
"0x1234567890123456789012345678901234567890123456789012345678901234";

// check if a dap update proposal is valid
const isValid = client.methods.isDaoUpdateProposalValid({ proposalId });

console.log(isValid);

/* MARKDOWN
Returns:
```tsx
{
isValid: false,
causes: [
"invalidImplementation",
]
}
```
*/
36 changes: 36 additions & 0 deletions modules/client/examples/01-client/19-is-dao-update-proposal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* MARKDOWN
---
title: Check proposal is a dao update proposal
---

### Check if a proposal contains the actions required to update a dao

Goes though a list of actions and checks that contains the necessary actions for updating a dao
*/

import { Client } from "@aragon/sdk-client";
import { context } from "../index";
import { DaoAction } from "@aragon/sdk-client-common";

// Instantiate the general purpose client from the Aragon OSx SDK context.
const client: Client = new Client(context);

const actions: DaoAction[] = [
{
to: "0x1234567890123456789012345678901234567890",
value: BigInt(0),
data: new Uint8Array([10, 20, 30]),
},
];

// check if a plugin update proposal is valid
const isValid = client.methods.isDaoUpdateProposal(actions);

console.log(isValid);

/* MARKDOWN
Returns:
```tsx
false
```
*/
6 changes: 3 additions & 3 deletions modules/client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aragon/sdk-client",
"author": "Aragon Association",
"version": "1.13.1-rc1",
"version": "1.14.0",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client.esm.js",
Expand Down Expand Up @@ -62,8 +62,8 @@
},
"dependencies": {
"@aragon/osx-ethers": "1.3.0-rc0.2",
"@aragon/sdk-client-common": "^1.5.0-rc0",
"@aragon/sdk-common": "^1.6.0",
"@aragon/sdk-client-common": "^1.6.0",
"@aragon/sdk-common": "^1.7.0",
"@aragon/sdk-ipfs": "^1.1.0",
"@ethersproject/abstract-signer": "^5.5.0",
"@ethersproject/bignumber": "^5.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
PluginInstallItem,
SupportedNetwork,
SupportedNetworksArray,
SupportedVersion,
} from "@aragon/sdk-client-common";
import { INSTALLATION_ABI } from "../constants";

Expand Down Expand Up @@ -57,7 +58,8 @@ export class AddresslistVotingClientEncoding extends ClientCore
);

return {
id: LIVE_CONTRACTS[networkName].addresslistVotingRepoAddress,
id: LIVE_CONTRACTS[SupportedVersion.LATEST][networkName]
.addresslistVotingRepoAddress,
data: hexToBytes(hexBytes),
};
}
Expand Down
25 changes: 4 additions & 21 deletions modules/client/src/internal/client/decoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import {
applyInstallatonParamsFromContract,
decodeApplyUpdateAction,
decodeGrantAction,
decodeInitializeFromAction,
decodeUpgradeToAndCallAction,
findInterface,
permissionParamsFromContract,
permissionParamsWitConditionFromContract,
withdrawParamsFromContract,
} from "../utils";
import {
bytesToHex,
hexToBytes,
InvalidActionError,
IpfsError,
resolveIpfsCid,
Expand Down Expand Up @@ -310,16 +311,7 @@ export class ClientDecoding extends ClientCore implements IClientDecoding {
public upgradeToAndCallAction(
data: Uint8Array,
): UpgradeToAndCallParams {
const daoInterface = DAO__factory.createInterface();
const hexBytes = bytesToHex(data);
const expectedFunction = daoInterface.getFunction(
"upgradeToAndCall",
);
const result = daoInterface.decodeFunctionData(expectedFunction, hexBytes);
return {
implementationAddress: result[0],
data: hexToBytes(result[1]),
};
return decodeUpgradeToAndCallAction(data);
}

/**
Expand All @@ -330,16 +322,7 @@ export class ClientDecoding extends ClientCore implements IClientDecoding {
* @memberof ClientDecoding
*/
public initializeFromAction(data: Uint8Array): InitializeFromParams {
const daoInterface = DAO__factory.createInterface();
const hexBytes = bytesToHex(data);
const expectedFunction = daoInterface.getFunction(
"initializeFrom",
);
const result = daoInterface.decodeFunctionData(expectedFunction, hexBytes);
return {
previousVersion: result[0],
initData: hexToBytes(result[1]),
};
return decodeInitializeFromAction(data);
}

/**
Expand Down
Loading