Skip to content

Commit

Permalink
Ready
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Nov 8, 2023
1 parent 9251ec3 commit 833f1ae
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 64 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ See `SpacePluginSetup`, `PersonalSpaceAdminPluginSetup`, `MemberAccessPluginSetu

[Learn more about plugin setup's](https://devs.aragon.org/docs/osx/how-it-works/framework/plugin-management/plugin-setup/) and [preparing installations](https://devs.aragon.org/docs/sdk/examples/client/prepare-installation).

### Passing install parameters
### Plugin Setup install parameters

In both of the cases described above, a call to `prepareInstallation()` will be made by the `PluginSetupProcessor` from OSx.

Expand All @@ -456,20 +456,25 @@ function prepareInstallation(
```

- The first parameter (dao address) will be provided by the PSP.
- The second parameter allows to pass an arbitrary array of bytes, encoding any set of custom settings that the plugin needs to receive.
- The second parameter contains an arbitrary array of bytes, with the ABI encoded custom settings that the plugin setup needs to operate.

The first step for `prepareInstallation()` is to decode them and use them on the deployment script as needed:
Convenience functions are provided within the plugin setup contracts:

```solidity
// Decode incoming params
(
// SpacePluginSetup.sol
function encodeInstallationParams(
string memory _firstBlockContentUri,
address _predecessorAddress,
address _pluginUpgrader
) = abi.decode(_data, (string, address, address));
) public pure returns (bytes memory);
function encodeUninstallationParams(
address _pluginUpgrader
) public pure returns (bytes memory)
```

The JSON encoded ABI definition can be found at the corresponding `<name>-build-metadata.json` file:
The JSON encoded ABI definition can also be found at the corresponding `<name>-build-metadata.json` file:

```json
{
Expand Down
53 changes: 51 additions & 2 deletions packages/contracts/src/GovernancePluginsSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract GovernancePluginsSetup is PluginSetup {
address[] memory _initialEditors,
uint64 _memberAccessProposalDuration,
address _pluginUpgrader
) = abi.decode(_data, (MajorityVotingBase.VotingSettings, address[], uint64, address));
) = decodeInstallationParams(_data);

// Deploy the main voting plugin
mainVotingPlugin = createERC1967Proxy(
Expand Down Expand Up @@ -168,7 +168,7 @@ contract GovernancePluginsSetup is PluginSetup {
}

// Decode incoming params
address _pluginUpgrader = abi.decode(_payload.data, (address));
address _pluginUpgrader = decodeUninstallationParams(_payload.data);
address _memberAccessPlugin = _payload.currentHelpers[0];

permissionChanges = new PermissionLib.MultiTargetPermission[](
Expand Down Expand Up @@ -267,4 +267,53 @@ contract GovernancePluginsSetup is PluginSetup {
function implementation() external view returns (address) {
return mainVotingPluginImplementation;
}

/// @notice Encodes the given installation parameters into a byte array
function encodeInstallationParams(
MajorityVotingBase.VotingSettings calldata _votingSettings,
address[] calldata _initialEditors,
uint64 _memberAccessProposalDuration,
address _pluginUpgrader
) public pure returns (bytes memory) {
return
abi.encode(
_votingSettings,
_initialEditors,
_memberAccessProposalDuration,
_pluginUpgrader
);
}

/// @notice Decodes the given byte array into the original installation parameters
function decodeInstallationParams(
bytes memory _data
)
public
pure
returns (
MajorityVotingBase.VotingSettings memory votingSettings,
address[] memory initialEditors,
uint64 memberAccessProposalDuration,
address pluginUpgrader
)
{
(votingSettings, initialEditors, memberAccessProposalDuration, pluginUpgrader) = abi.decode(
_data,
(MajorityVotingBase.VotingSettings, address[], uint64, address)
);
}

/// @notice Encodes the given uninstallation parameters into a byte array
function encodeUninstallationParams(
address _pluginUpgrader
) public pure returns (bytes memory) {
return abi.encode(_pluginUpgrader);
}

/// @notice Decodes the given byte array into the original uninstallation parameters
function decodeUninstallationParams(
bytes memory _data
) public pure returns (address pluginUpgrader) {
(pluginUpgrader) = abi.decode(_data, (address));
}
}
14 changes: 13 additions & 1 deletion packages/contracts/src/PersonalSpaceAdminPluginSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract PersonalSpaceAdminPluginSetup is PluginSetup {
bytes calldata _data
) external returns (address plugin, PreparedSetupData memory preparedSetupData) {
// Decode `_data` to extract the params needed for cloning and initializing the `PersonalSpaceAdminPlugin` plugin.
address editor = abi.decode(_data, (address));
address editor = decodeInstallationParams(_data);

if (editor == address(0)) {
revert EditorAddressInvalid({editor: editor});
Expand Down Expand Up @@ -95,4 +95,16 @@ contract PersonalSpaceAdminPluginSetup is PluginSetup {
function implementation() external view returns (address) {
return implementation_;
}

/// @notice Encodes the given installation parameters into a byte array
function encodeInstallationParams(address _initialEditor) public pure returns (bytes memory) {
return abi.encode(_initialEditor);
}

/// @notice Decodes the given byte array into the original installation parameters
function decodeInstallationParams(
bytes memory _data
) public pure returns (address initialEditor) {
(initialEditor) = abi.decode(_data, (address));
}
}
45 changes: 43 additions & 2 deletions packages/contracts/src/SpacePluginSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract SpacePluginSetup is PluginSetup {
string memory _firstBlockContentUri,
address _predecessorAddress,
address _pluginUpgrader
) = abi.decode(_data, (string, address, address));
) = decodeInstallationParams(_data);

// Deploy new plugin instance
plugin = createERC1967Proxy(
Expand Down Expand Up @@ -90,7 +90,7 @@ contract SpacePluginSetup is PluginSetup {
SetupPayload calldata _payload
) external view returns (PermissionLib.MultiTargetPermission[] memory permissionChanges) {
// Decode incoming params
address _pluginUpgrader = abi.decode(_payload.data, (address));
address _pluginUpgrader = decodeUninstallationParams(_payload.data);

permissionChanges = new PermissionLib.MultiTargetPermission[](
_pluginUpgrader == address(0x0) ? 3 : 4
Expand Down Expand Up @@ -134,4 +134,45 @@ contract SpacePluginSetup is PluginSetup {
function implementation() external view returns (address) {
return pluginImplementation;
}

/// @notice Encodes the given installation parameters into a byte array
function encodeInstallationParams(
string memory _firstBlockContentUri,
address _predecessorAddress,
address _pluginUpgrader
) public pure returns (bytes memory) {
return abi.encode(_firstBlockContentUri, _predecessorAddress, _pluginUpgrader);
}

/// @notice Decodes the given byte array into the original installation parameters
function decodeInstallationParams(
bytes memory _data
)
public
pure
returns (
string memory firstBlockContentUri,
address predecessorAddress,
address pluginUpgrader
)
{
(firstBlockContentUri, predecessorAddress, pluginUpgrader) = abi.decode(
_data,
(string, address, address)
);
}

/// @notice Encodes the given uninstallation parameters into a byte array
function encodeUninstallationParams(
address _pluginUpgrader
) public pure returns (bytes memory) {
return abi.encode(_pluginUpgrader);
}

/// @notice Decodes the given byte array into the original uninstallation parameters
function decodeUninstallationParams(
bytes memory _data
) public pure returns (address pluginUpgrader) {
(pluginUpgrader) = abi.decode(_data, (address));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,11 @@ describe("GovernancePluginsSetup processing", function () {
const minMemberAccessProposalDuration = 60 * 60 * 24;

// Install build 1.
const data = ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
GovernancePluginsSetupParams.METADATA.build.pluginSetup
.prepareInstallation
.inputs,
),
[
settings,
[alice.address],
minMemberAccessProposalDuration,
pluginUpgrader,
],
const data = await setup.encodeInstallationParams(
settings,
[alice.address],
minMemberAccessProposalDuration,
pluginUpgrader,
);
const installation = await installPlugin(psp, dao, pluginSetupRef, data);

Expand Down Expand Up @@ -158,14 +151,7 @@ describe("GovernancePluginsSetup processing", function () {
expect(await memberAccessPlugin.dao()).to.be.eq(dao.address);

// Uninstall build 1.
const data = ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
GovernancePluginsSetupParams.METADATA.build.pluginSetup
.prepareUninstallation
.inputs,
),
[pluginUpgrader],
);
const data = await setup.encodeUninstallationParams(pluginUpgrader);
await uninstallPlugin(
psp,
dao,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { BigNumber } from "ethers";
import { ethers } from "hardhat";
import { toHex } from "../../utils/ipfs";

describe("PersonalSpaceAdmin processing", function () {
let alice: SignerWithAddress;
Expand Down Expand Up @@ -88,6 +87,12 @@ describe("PersonalSpaceAdmin processing", function () {
before(async () => {
const release = 1;

// Deploy setup.
setup = PersonalSpaceAdminPluginSetup__factory.connect(
(await pluginRepo["getLatestVersion(uint8)"](release)).pluginSetup,
alice,
);

pluginSetupRef = {
versionTag: {
release: BigNumber.from(release),
Expand All @@ -101,14 +106,7 @@ describe("PersonalSpaceAdmin processing", function () {
const initialEditor = alice.address;

// Install build 1.
const data = ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
PersonalSpaceAdminPluginSetupParams.METADATA.build.pluginSetup
.prepareInstallation
.inputs,
),
[initialEditor],
);
const data = await setup.encodeInstallationParams(initialEditor);
const results = await installPlugin(psp, dao, pluginSetupRef, data);

plugin = PersonalSpaceAdminPlugin__factory.connect(
Expand All @@ -121,14 +119,7 @@ describe("PersonalSpaceAdmin processing", function () {
expect(await plugin.dao()).to.be.eq(dao.address);

// Uninstall build 1.
const data = ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
PersonalSpaceAdminPluginSetupParams.METADATA.build.pluginSetup
.prepareUninstallation
.inputs,
),
[],
);
const data = "0x"; // no parameters
await uninstallPlugin(psp, dao, plugin, pluginSetupRef, data, []);
});
});
Expand Down
20 changes: 5 additions & 15 deletions packages/contracts/test/integration-testing/space-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,10 @@ describe("SpacePluginSetup processing", function () {

beforeEach(async () => {
// Install build 1.
const data = ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
SpacePluginSetupParams.METADATA.build.pluginSetup
.prepareInstallation
.inputs,
),
[toHex("ipfs://1234"), ADDRESS_ZERO, pluginUpgrader],
const data = await setup.encodeInstallationParams(
toHex("ipfs://1234"),
ADDRESS_ZERO,
pluginUpgrader,
);
const results = await installPlugin(psp, dao, pluginSetupRef, data);

Expand All @@ -130,14 +127,7 @@ describe("SpacePluginSetup processing", function () {
expect(await plugin.dao()).to.be.eq(dao.address);

// Uninstall build 1.
const data = ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
SpacePluginSetupParams.METADATA.build.pluginSetup
.prepareUninstallation
.inputs,
),
[pluginUpgrader],
);
const data = await setup.encodeUninstallationParams(pluginUpgrader);
await uninstallPlugin(psp, dao, plugin, pluginSetupRef, data, []);
});
});
Expand Down

0 comments on commit 833f1ae

Please sign in to comment.