Skip to content

Commit

Permalink
Fix: Encoding flow when updating plugin settings (#66)
Browse files Browse the repository at this point in the history
* add plugin address param

* add addres validation and test

* update tests

* update changelog

* fix test

* fix code smell
  • Loading branch information
josemarinas committed Sep 7, 2022
1 parent a199226 commit a0a2638
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 62 deletions.
3 changes: 2 additions & 1 deletion javascript/modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ TEMPLATE:
-->

## [UPCOMING]

### Fixed
- Encoding flow when updating plugin settings
## 0.4.2-alpha
On 2022-09-07 11:19:55

Expand Down
14 changes: 14 additions & 0 deletions javascript/modules/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,10 @@ const configActionPrarms: IProposalSettings = {
minTurnout: 0.5, // 50%
};

const pluginAddress = "0x1234567890123456789012345678901234567890";

const configAction = client.encoding.updatePluginSettingsAction(
pluginAddress,
configActionPrarms,
);

Expand Down Expand Up @@ -1180,7 +1183,10 @@ const configActionPrarms: IProposalSettings = {
minTurnout: 0.5, // 50%
};

const pluginAddress = "0x1234567890123456789012345678901234567890";

const configAction = client.encoding.updatePluginSettingsAction(
pluginAddress,
configActionPrarms,
);

Expand Down Expand Up @@ -1580,7 +1586,11 @@ const configActionPrarms: IProposalSettings = {
minSupport: 0.3, // 30%
minTurnout: 0.5, // 50%
};

const pluginAddress = "0x1234567890123456789012345678901234567890";

const configAction = client.encoding.updatePluginSettingsAction(
pluginAddress,
configActionPrarms,
);
```
Expand Down Expand Up @@ -1609,7 +1619,11 @@ const configActionPrarms: IProposalSettings = {
minSupport: 0.3, // 30%
minTurnout: 0.5, // 50%
};

const pluginAddress = "0x1234567890123456789012345678901234567890";

const configAction = client.encoding.updatePluginSettingsAction(
pluginAddress,
configActionPrarms,
);
```
Expand Down
2 changes: 1 addition & 1 deletion javascript/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": "0.4.2-alpha",
"version": "0.4.3-alpha",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client.esm.js",
Expand Down
20 changes: 15 additions & 5 deletions javascript/modules/client/src/client-addressList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { bytesToHex, Random } from "@aragon/sdk-common";
import { AddressZero } from "@ethersproject/constants";
import { ContextPlugin } from "./context-plugin";
import { ClientCore } from "./internal/core";
import {
Expand Down Expand Up @@ -36,6 +35,7 @@ import {
getDummyAddressListProposalListItem,
} from "./internal/temp-mock";
import { getProposalStatus } from "./internal/utils/plugins";
import { isAddress } from "@ethersproject/address";

// NOTE: This address needs to be set when the plugin has been published and the ID is known
const PLUGIN_ID = "0x1234567890123456789012345678901234567890";
Expand Down Expand Up @@ -132,12 +132,16 @@ export class ClientAddressList extends ClientCore
/**
* Computes the parameters to be given when creating a proposal that updates the governance configuration
*
* @param {string} pluginAddress
* @param {IPluginSettings} params
* @return {*} {DaoAction}
* @memberof ClientAddressList
*/
updatePluginSettingsAction: (params: IPluginSettings): DaoAction =>
this._buildUpdatePluginSettingsAction(params),
updatePluginSettingsAction: (
pluginAddress: string,
params: IPluginSettings,
): DaoAction =>
this._buildUpdatePluginSettingsAction(pluginAddress, params),
};
decoding = {
/**
Expand Down Expand Up @@ -348,10 +352,16 @@ export class ClientAddressList extends ClientCore
);
}

private _buildUpdatePluginSettingsAction(params: IPluginSettings): DaoAction {
private _buildUpdatePluginSettingsAction(
pluginAddress: string,
params: IPluginSettings,
): DaoAction {
if (!isAddress(pluginAddress)) {
throw new Error("Invalid plugin address");
}
// TODO: check if to and value are correct
return {
to: AddressZero,
to: pluginAddress,
value: BigInt(0),
data: encodeUpdatePluginSettingsAction(params),
};
Expand Down
20 changes: 15 additions & 5 deletions javascript/modules/client/src/client-erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
getDummyErc20Proposal,
getDummyErc20ProposalListItem,
} from "./internal/temp-mock";
import { AddressZero } from "@ethersproject/constants";
import { isAddress } from "@ethersproject/address";

// NOTE: This address needs to be set when the plugin has been published and the ID is known
const PLUGIN_ID = "0x1234567890123456789012345678901234567890";
Expand Down Expand Up @@ -141,13 +141,17 @@ export class ClientErc20 extends ClientCore implements IClientErc20 {
/**
* Computes the parameters to be given when creating a proposal that updates the governance configuration
*
* @param {string} pluginAddress
* @param {IPluginSettings} params
* @return {*} {DaoAction}
* @memberof ClientErc20
*/
// updatePluginSettings() not setConfig()
updatePluginSettingsAction: (params: IPluginSettings): DaoAction =>
this._buildUpdatePluginSettingsAction(params),
updatePluginSettingsAction: (
pluginAddress: string,
params: IPluginSettings,
): DaoAction =>
this._buildUpdatePluginSettingsAction(pluginAddress, params),
};
decoding = {
/**
Expand Down Expand Up @@ -322,10 +326,16 @@ export class ClientErc20 extends ClientCore implements IClientErc20 {
}

//// PRIVATE ACTION BUILDER HANDLERS
private _buildUpdatePluginSettingsAction(params: IPluginSettings): DaoAction {
private _buildUpdatePluginSettingsAction(
pluginAddress: string,
params: IPluginSettings,
): DaoAction {
if (!isAddress(pluginAddress)) {
throw new Error("Invalid plugin address")
}
// TODO: check if to and value are correct
return {
to: AddressZero,
to: pluginAddress,
value: BigInt(0),
data: encodeUpdatePluginSettingsAction(params),
};
Expand Down
Loading

0 comments on commit a0a2638

Please sign in to comment.