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

Compare to audit branch for new changes #31

Merged
merged 26 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5e77c1e
feat: use new upload to pinata function from sdk
clauBv23 Dec 2, 2024
0bf7f4a
feat: update test to no need upload to pinnata function in the tests
clauBv23 Dec 2, 2024
ec3ca0b
ci: format
clauBv23 Dec 2, 2024
3b90eb8
Update packages/contracts/deploy/20_new_version/23_publish.ts
clauBv23 Dec 2, 2024
0bd973e
fix: remove .only
clauBv23 Dec 2, 2024
546cfa2
add missing permission
Rekard0 Dec 6, 2024
e02806e
added zksync config & compiled
Rekard0 Jan 17, 2025
d0835a7
add zksync contracts, refactor plugin.ts tests
Rekard0 Jan 17, 2025
84d0109
refactor plugin setup tests
Rekard0 Jan 17, 2025
73e53c1
skip integrations test
Rekard0 Jan 17, 2025
f033f0f
deployment ready
novaknole Jan 17, 2025
0d6e999
update readme
Rekard0 Jan 17, 2025
021a78c
deploy on testnet
Rekard0 Jan 17, 2025
67d968a
fix isZkSync func
Rekard0 Jan 19, 2025
efecd50
partial fix linting issues
Rekard0 Jan 19, 2025
b11064f
fix eslint errors
novaknole Jan 20, 2025
f511b4e
Merge pull request #26 from aragon/feat/update-to-use-upload-to-pinnata
novaknole Jan 20, 2025
4f82aff
fix all errors
novaknole Jan 20, 2025
01d8404
undo work for testing repo verification
Rekard0 Jan 20, 2025
b6d73e9
Merge pull request #28 from aragon/feature/add-missing-permission-to-…
novaknole Jan 20, 2025
e60086e
Merge branch 'develop' into feature/zksync
novaknole Jan 20, 2025
ccac769
add permission
novaknole Jan 20, 2025
a255707
Merge branch 'feature/zksync' of https://github.com/aragon/admin-plug…
novaknole Jan 20, 2025
5a37c56
placeholder
novaknole Jan 20, 2025
f0053ad
linter fixed
novaknole Jan 21, 2025
9ae2c58
Merge pull request #30 from aragon/feature/zksync
novaknole Jan 21, 2025
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
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
Loading