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

Featrue: Add initializeFrom encoders and decoders #226

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

## [UPCOMING]
### Added
- Added `initializeFrom` encoders and decoders
### Fixes
- Fix status calculation for token voting proposals
- Make the `network` parameter required on `getPluginInstallItem`
Expand Down
2 changes: 1 addition & 1 deletion modules/client/examples/01-client/01-create-dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
CreateDaoParams,
DaoCreationSteps,
DaoMetadata,
TokenVotingPluginInstall,
TokenVotingClient,
TokenVotingPluginInstall,
josemarinas marked this conversation as resolved.
Show resolved Hide resolved
VotingMode,
} from "@aragon/sdk-client";
import { GasFeeEstimation } from "@aragon/sdk-client-common";
Expand Down
2 changes: 1 addition & 1 deletion modules/client/examples/01-client/05-get-daos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Gets a list of DAOs from the Aragon OSx DAO registry.
import {
Client,
DaoListItem,
DaoSortBy,
DaoQueryParams,
DaoSortBy,
} from "@aragon/sdk-client";
import { SortDirection } from "@aragon/sdk-client-common";
import { context } from "../index";
Expand Down
2 changes: 1 addition & 1 deletion modules/client/examples/01-client/07-get-transfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ By default, retrieves ETH, DAI, USDC and USDT, on Mainnet).

import {
Client,
TransferQueryParams,
Transfer,
TransferQueryParams,
TransferSortBy,
TransferType,
} from "@aragon/sdk-client";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ title: Prepare Uninstallation

### Prepare the uninstallation of a plugin

The `prepareUninstallation` method performs the prior steps so that a DAO proposal can eventually apply the removal of a Plugin.
The proposal will need an Action calling the `applyUninstallation` function.
The `prepareUninstallation` method performs the prior steps so that a DAO proposal can eventually apply the removal of a Plugin.
The proposal will need an Action calling the `applyUninstallation` function.

For more details see https://devs.aragon.org/docs/sdk/examples/encoders-decoders/apply-uninstallation#encoding

Expand Down
1 change: 0 additions & 1 deletion modules/client/examples/03-tokenVoting-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { context } from "../index";

// Instantiate the ContextPlugin from the Aragon OSx SDK context.


// Create a TokenVoting client.
const tokenVotingClient = new TokenVotingClient(context);
console.log(tokenVotingClient);
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Revokes a permission to a given address (`who`) to perform an action on a contra

import {
Client,
Permissions,
RevokePermissionDecodedParams,
RevokePermissionParams,
Permissions,
} from "@aragon/sdk-client";
import { DaoAction } from "@aragon/sdk-client-common";
import { context } from "../index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ Register a new standard callback for the DAO.
### Encoding
*/

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

Expand Down
5 changes: 1 addition & 4 deletions modules/client/examples/05-encoders-decoders/06-withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ In order for a withdrawal to be successful, the address executing it must have `
#### Encoding
*/

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

Expand Down
19 changes: 10 additions & 9 deletions modules/client/examples/05-encoders-decoders/07-update-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const metadataParams: DaoMetadata = {
links: [
{
url: "https://discord.com/...",
name: "Discord"
name: "Discord",
},
{
url: "https://twitter.com/...",
name: "Twitter"
}
]
name: "Twitter",
},
],
};

const daoAddressOrEns: string = "0x123458235832745982839878932332423"; // or my-dao.dao.eth
Expand All @@ -41,7 +41,7 @@ const ipfsUri: string = await client.methods.pinMetadata(metadataParams);
// Update the metadata of a given DAO.
const action: DaoAction = await client.encoding.updateDaoMetadataAction(
daoAddressOrEns,
ipfsUri
ipfsUri,
);
console.log({ action });

Expand All @@ -62,9 +62,10 @@ Returns:
*/

// Decodes the update metadata action.
const decodedParams: DaoMetadata = await client.decoding.updateDaoMetadataAction(
action.data
);
const decodedParams: DaoMetadata = await client.decoding
.updateDaoMetadataAction(
action.data,
);
console.log({ decodedParams });

/* MARKDOWN
Expand Down Expand Up @@ -97,7 +98,7 @@ Decode an update metadata action and expect an IPFS URI containing the CID of th

// Decodes the parameters of an update metadata raw action.
const decodedParamsRaw: string = client.decoding.updateDaoMetadataRawAction(
action.data
action.data,
);
console.log({ decodedParamsRaw });

Expand Down
60 changes: 60 additions & 0 deletions modules/client/examples/05-encoders-decoders/14-initialize-from.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* MARKDOWN
---
title: Initialize From
---

## Upgrade a DAO to a new version

Encodes the action for upgrading the dao to a new version and passing initialization data of the new version.

### Encoding
*/

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

// Instantiates an Aragon OSx SDK client.
const client: Client = new Client(context);

// This variable contains the values received on the ininitializeFrom() method
const initializeFromParams: InitializeFromParams = {
previousVersion: [1, 0, 0],
initData: new Uint8Array([12, 34, 45, 85, 95, 45, 73]), // initialization data for the new version to be pased to upgradeToAndCall()
};

const daoAddressOrEns: string = "0x123123123123123123123123123123123123"; // "my-dao.eth"

const action: DaoAction = client.encoding.initializeFromAction(
daoAddressOrEns,
initializeFromParams,
);
console.log(action);

/* MARKDOWN
```json
{
to: "0x123123123...",
value: 0n,
data: Uint8Array[12,34,45...]
}
```

### Decoding
*/

// Decodes the initialize from action.
const decodedParams: InitializeFromParams = client.decoding
.initializeFromAction(action.data);
console.log({ decodedParams });

/* MARKDOWN
Returns:

```json
{
previousVersion: [1, 0, 0],
initData: Uint8Array[12,34,45...]
}
```
*/
6 changes: 5 additions & 1 deletion modules/client/src/addresslistVoting/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { AddresslistVotingClientDecoding } from "./internal/client/decoding";
import { AddresslistVotingClientEstimation } from "./internal/client/estimation";
import { Networkish } from "@ethersproject/providers";
import { AddresslistVotingPluginInstall } from "./types";
import { ClientCore, Context, PluginInstallItem } from "@aragon/sdk-client-common";
import {
ClientCore,
Context,
PluginInstallItem,
} from "@aragon/sdk-client-common";

/**
* Provider a generic client with high level methods to manage and interact an Address List Voting plugin installed in a DAO
Expand Down
3 changes: 0 additions & 3 deletions modules/client/src/client-common/types/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// This file contains common types, interfaces, and enumerations

export enum DaoRole {
Expand All @@ -9,12 +8,10 @@ export enum DaoRole {
SET_SIGNATURE_VALIDATOR_ROLE = "SET_SIGNATURE_VALIDATOR_ROLE",
}


/**
* Contains the general human readable information about the DAO
*/
export type DaoConfig = {
name: string;
metadataUri: string;
};

2 changes: 1 addition & 1 deletion modules/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
IClientEstimation,
IClientMethods,
} from "./internal/interfaces";
import { Context, ClientCore } from "@aragon/sdk-client-common";
import { ClientCore, Context } from "@aragon/sdk-client-common";

/**
* Provider a generic client with high level methods to manage and interact with DAO's
Expand Down
21 changes: 21 additions & 0 deletions modules/client/src/internal/client/decoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DecodedApplyUninstallationParams,
GrantPermissionDecodedParams,
GrantPermissionWithConditionParams,
InitializeFromParams,
RegisterStandardCallbackParams,
RevokePermissionDecodedParams,
UpgradeToAndCallParams,
Expand Down Expand Up @@ -278,6 +279,26 @@ export class ClientDecoding extends ClientCore implements IClientDecoding {
};
}

/**
* Decodes the initializeFrom params from an initializeFromAction
*
* @param {Uint8Array} data
* @return {*} {InitializeFromParams}
* @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]),
};
}

/**
* Returns the decoded function info given the encoded data of an action
*
Expand Down
25 changes: 25 additions & 0 deletions modules/client/src/internal/client/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ApplyUninstallationParams,
GrantPermissionParams,
GrantPermissionWithConditionParams,
InitializeFromParams,
RegisterStandardCallbackParams,
RevokePermissionParams,
UpgradeToAndCallParams,
Expand Down Expand Up @@ -414,4 +415,28 @@ export class ClientEncoding extends ClientCore implements IClientEncoding {
data: hexToBytes(hexBytes),
};
}

/**
* Computes an action to be passed to the upgradeToAndCallAction method when upgrading a DAO to a new version.
*
* @param {string} daoAddressOrEns
* @param {InitializeFromParams} params
* @return {*}
* @memberof ClientEncoding
*/
public initializeFromAction(
daoAddressOrEns: string,
params: InitializeFromParams,
) {
const daoInterface = DAO__factory.createInterface();
const hexBytes = daoInterface.encodeFunctionData("initializeFrom", [
params.previousVersion,
params.initData ?? new Uint8Array(),
]);
return {
to: daoAddressOrEns,
value: BigInt(0),
data: hexToBytes(hexBytes),
};
}
}
8 changes: 8 additions & 0 deletions modules/client/src/internal/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
GrantPermissionParams,
GrantPermissionWithConditionParams,
HasPermissionParams,
InitializeFromParams,
PluginQueryParams,
PluginRepo,
PluginRepoListItem,
Expand Down Expand Up @@ -127,6 +128,10 @@ export interface IClientEncoding {
daoAddressOrEns: string,
params: ApplyUninstallationParams,
) => DaoAction[];
initializeFromAction: (
daoAddressOrEns: string,
params: InitializeFromParams,
) => DaoAction;
}

export interface IClientDecoding {
Expand Down Expand Up @@ -156,6 +161,9 @@ export interface IClientDecoding {
applyUninstallationAction: (
data: Uint8Array,
) => DecodedApplyUninstallationParams;
initializeFromAction: (
data: Uint8Array,
) => InitializeFromParams;
}

export interface IClientEstimation {
Expand Down
6 changes: 5 additions & 1 deletion modules/client/src/tokenVoting/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ export function parseToken(
| SubgraphErc721Token
| SubgraphErc20WrapperToken,
): Erc20TokenDetails | Erc721TokenDetails | null {
let token: Erc721TokenDetails | Erc20TokenDetails| Erc20WrapperTokenDetails | null = null;
let token:
| Erc721TokenDetails
| Erc20TokenDetails
| Erc20WrapperTokenDetails
| null = null;
if (subgraphToken.__typename === SubgraphContractType.ERC20) {
token = {
address: subgraphToken.id,
Expand Down
5 changes: 5 additions & 0 deletions modules/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,8 @@ export type UpgradeToAndCallParams = {
implementationAddress: string;
data: Uint8Array;
};

export type InitializeFromParams = {
previousVersion: [number, number, number];
initData?: Uint8Array;
};
2 changes: 1 addition & 1 deletion modules/client/test/abi/ERC1967.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ export const ERC1967ABI = [
"stateMutability": "payable",
"type": "receive",
},
];
];
2 changes: 1 addition & 1 deletion modules/client/test/abi/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './ERC1967'
export * from "./ERC1967";
4 changes: 2 additions & 2 deletions modules/client/test/helpers/build-daos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
Client,
CreateDaoParams,
DaoCreationSteps,
TokenVotingPluginInstall,
MultisigClient,
TokenVotingClient,
TokenVotingPluginInstall,
VotingMode,
} from "../../src";
import {
Expand Down Expand Up @@ -112,7 +112,7 @@ export async function buildTokenVotingDAO(
plugin,
signer,
);
const tokenAddress = await tokenVotingContract.getVotingToken()
const tokenAddress = await tokenVotingContract.getVotingToken();

return {
dao,
Expand Down
Loading