Skip to content

Commit

Permalink
Merge pull request #31 from aragon/develop
Browse files Browse the repository at this point in the history
Compare to audit branch for new changes
  • Loading branch information
Rekard0 authored Feb 3, 2025
2 parents c78361b + 9ae2c58 commit ae3cccd
Show file tree
Hide file tree
Showing 31 changed files with 6,046 additions and 368 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ packages/subgraph/imported
packages/subgraph/generated
packages/subgraph/tests/.bin

packages/contracts/.upgradable

# files
*.env
*.log
Expand All @@ -28,3 +30,8 @@ packages/subgraph/deploy-output.txt
packages/subgraph/subgraph.yaml
packages/subgraph/tests/.latest.json
packages/subgraph/tests/helpers/extended-schema.ts

artifacts-zk
cache-zk
deployments-zk
deployments
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ package-lock.json
pnpm-lock.yaml
yarn.lock
extended-schema.ts

deployments-zk
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,40 @@ Before deploying, you MUST also change the default hardhat private key (`PRIVATE

## Contracts

In `packages/contracts`, first run
This package is located in `packages/contracts`.

### Install Dependencies

```sh
yarn install
```

### Building

First build the contracts and
To build the contracts on EVM based networks:

```sh
yarn build
```

and generate the [typechain TypeScript bindings](https://github.com/dethcrypto/TypeChain) with
On Zksync:

```sh
yarn typechain
yarn build:zksync
```

During development of your smart contracts, changes can result in altered typechain bindings.
You can remove the outdated build- and typechain-related files with
### Testing

To test your contracts on EVM based networks, run

```sh
yarn clean
yarn test
```

which will execute `yarn typechain` again. For convenience, use `yarn clean && yarn build`.

### Testing

To test your contracts, run
On Zksync:

```sh
yarn test
yarn test:zksync
```

### Linting
Expand Down Expand Up @@ -224,6 +223,13 @@ This will upgrade your plugin repo to the latest Aragon OSx protocol version imp

Note, that if the deploying account doesn't own the repo anymore, this will create a `upgradeRepoProposalData-sepolia.json` containing the data for a management DAO signer to create a proposal upgrading the repo.

If you want to run deployments against zksync, you can use:

```sh
yarn deploy:zksync --network zksyncSepolia --tags ...
yarn deploy:zksync --network zksyncMainnet --tags ...
```

## Subgraph

### Installing
Expand Down
12 changes: 8 additions & 4 deletions packages/contracts/deploy/20_new_version/22_setup_conclude.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {PLUGIN_SETUP_CONTRACT_NAME} from '../../plugin-settings';
import {AdminSetup__factory, Admin__factory} from '../../typechain';
import {isZkSync} from '../../utils/zkSync';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';
Expand Down Expand Up @@ -29,10 +30,13 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
address: setup.address,
args: setupDeployment.args,
});
hre.aragonToVerifyContracts.push({
address: implementation.address,
args: [],
});
// for zkSync we deploy from the setup as new so we don't implementation address
if (!isZkSync(hre.network.name)) {
hre.aragonToVerifyContracts.push({
address: implementation.address,
args: [],
});
}
};

export default func;
Expand Down
110 changes: 81 additions & 29 deletions packages/contracts/deploy/20_new_version/23_publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,42 @@ import {
PLUGIN_SETUP_CONTRACT_NAME,
VERSION,
} from '../../plugin-settings';
import {PluginRepo} from '../../typechain';
import {
findPluginRepo,
getPastVersionCreatedEvents,
impersonatedManagementDaoSigner,
isLocal,
pluginEnsDomain,
} from '../../utils/helpers';
import {PLUGIN_REPO_PERMISSIONS, uploadToIPFS} from '@aragon/osx-commons-sdk';
import {getLatestContractAddress} from '../helpers';
import {PLUGIN_REPO_PERMISSIONS, uploadToPinata} from '@aragon/osx-commons-sdk';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {writeFile} from 'fs/promises';
import {ethers} from 'hardhat';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';

async function createVersion(
pluginRepo: PluginRepo,
release: number,
setup: string,
releaseMetadataURI: string,
buildMetadataURI: string,
signer: SignerWithAddress
) {
const tx = await pluginRepo
.connect(signer)
.createVersion(
release,
setup,
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(buildMetadataURI)),
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(releaseMetadataURI))
);
await tx.wait();
}

/**
* Publishes the plugin setup in the plugin repo as a new version as specified in the `./plugin-settings.ts` file.
* @param {HardhatRuntimeEnvironment} hre
Expand All @@ -31,14 +53,20 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployments} = hre;
const [deployer] = await hre.ethers.getSigners();

// Upload the metadata to IPFS
const releaseMetadataURI = `ipfs://${await uploadToIPFS(
JSON.stringify(METADATA.release, null, 2)
)}`;
const buildMetadataURI = `ipfs://${await uploadToIPFS(
JSON.stringify(METADATA.build, null, 2)
)}`;
let releaseMetadataURI = '0x';
let buildMetadataURI = '0x';

if (!isLocal(hre)) {
// Upload the metadata to IPFS
releaseMetadataURI = await uploadToPinata(
JSON.stringify(METADATA.release, null, 2),
`${PLUGIN_REPO_ENS_SUBDOMAIN_NAME}-release-metadata`
);
buildMetadataURI = await uploadToPinata(
JSON.stringify(METADATA.build, null, 2),
`${PLUGIN_REPO_ENS_SUBDOMAIN_NAME}-build-metadata`
);
}
console.log(`Uploaded release metadata: ${releaseMetadataURI}`);
console.log(`Uploaded build metadata: ${buildMetadataURI}`);

Expand All @@ -64,18 +92,25 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

// Check build number
const latestBuild = (await pluginRepo.buildCount(VERSION.release)).toNumber();
if (VERSION.build < latestBuild) {
throw Error(
`Publishing with build number ${VERSION.build} is not possible. The latest build is ${latestBuild}. Aborting publication...`
);
}
if (VERSION.build > latestBuild + 1) {
throw Error(
`Publishing with build number ${VERSION.build} is not possible.
The latest build is ${latestBuild} and the next release you can publish is release number ${
latestBuild + 1
}. Aborting publication...`
);

if (latestBuild == 0 && VERSION.build > 1) {
// it means there's no build yet on the repo on the specific VERSION.release
// and build version in the plugin settings is > 1, meaning that
// it must push placeholder contracts and as the last one, push the actual plugin setup.
} else {
if (VERSION.build < latestBuild) {
throw Error(
`Publishing with build number ${VERSION.build} is not possible. The latest build is ${latestBuild}. Aborting publication...`
);
}
if (VERSION.build > latestBuild + 1) {
throw Error(
`Publishing with build number ${VERSION.build} is not possible.
The latest build is ${latestBuild} and the next release you can publish is release number ${
latestBuild + 1
}. Aborting publication...`
);
}
}

if (setup == undefined || setup?.receipt == undefined) {
Expand Down Expand Up @@ -105,17 +140,34 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
[]
)
) {
// Create the new version
const tx = await pluginRepo
.connect(signer)
.createVersion(
VERSION.release,
setup.address,
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(buildMetadataURI)),
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(releaseMetadataURI))
const placeholderSetup = getLatestContractAddress('PlaceholderSetup', hre);
if (placeholderSetup == '') {
throw new Error(
'Aborting. Placeholder setup not present in this network'
);
}
if (latestBuild == 0 && VERSION.build > 1) {
for (let i = 0; i < VERSION.build - 1; i++) {
console.log('Publishing placeholder', i + 1);
await createVersion(
pluginRepo,
VERSION.release,
placeholderSetup,
`{}`,
'placeholder-setup-build',
signer
);
}
}

await tx.wait();
await createVersion(
pluginRepo,
VERSION.release,
setup.address,
releaseMetadataURI,
buildMetadataURI,
signer
);

const version = await pluginRepo['getLatestVersion(uint8)'](
VERSION.release
Expand Down
31 changes: 31 additions & 0 deletions packages/contracts/deploy/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {isLocal} from '../utils/helpers';
import {
getLatestNetworkDeployment,
getNetworkByNameOrAlias,
} from '@aragon/osx-commons-configs';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

export function getLatestContractAddress(
contractName: string,
hre: HardhatRuntimeEnvironment
): string {
const networkName = hre.network.name;

const osxNetworkName = getNetworkByNameOrAlias(networkName);
if (!osxNetworkName) {
if (isLocal(hre)) {
return '';
}
throw new Error(`Failed to find network ${networkName}`);
}

const latestNetworkDeployment = getLatestNetworkDeployment(
osxNetworkName.name
);
if (latestNetworkDeployment && contractName in latestNetworkDeployment) {
// safe cast due to conditional above, but we return the fallback string anyhow
const key = contractName as keyof typeof latestNetworkDeployment;
return latestNetworkDeployment[key]?.address ?? '';
}
return '';
}
Loading

0 comments on commit ae3cccd

Please sign in to comment.