Skip to content

Commit

Permalink
NPM artifacts generation (#642)
Browse files Browse the repository at this point in the history
* Preparing the ABI package for NPM

* Removing the redundant rollup config

* Yarn.lock update

* Updated package.json definition

* Minor edit

* Ingoring NPM postinstall scripts

* Scaffolding the addresses file

* Exporting artifacts with a deprecation warning

* Amending the readme using the intended  import usage

* Prepopulating the upgradeable protocol contracts

* Minor edit

* Adding the existing PSP addresses (v1.3)

* Version edit

* Improved readme

* Minor edit

* Minor edit

* Adding PUB_PINATA_JWT to .env.example

* add artifacts publish github flow

* Adding a placeholder for Pinata JWT in .env.example

* add alpha

* Removing a non relevant command on contract-tests.yml

---------

Co-authored-by: Rekard0 <[email protected]>
  • Loading branch information
brickpop and Rekard0 authored Feb 12, 2025
1 parent fc7403f commit 1f91ce0
Show file tree
Hide file tree
Showing 25 changed files with 439 additions and 123 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/artifacts-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Publish Artifacts

on:
workflow_dispatch:

jobs:
publish-artifacts-to-npm:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org/'

- name: Configure NPM for Scoped Package
run: |
cd packages/artifacts
SCOPE=$(jq -r '.name' package.json | cut -d'/' -f1)
echo "$SCOPE:registry=https://registry.npmjs.org/" > ~/.npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
- name: Get Version from package.json
id: get_version
run: |
cd packages/artifacts
VERSION=$(jq -r '.version' package.json)
TAG_VERSION="v$VERSION"
echo "VERSION=$TAG_VERSION" >> $GITHUB_ENV
- name: Create Git Tag
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git tag $VERSION
git push origin $VERSION
- name: Install Dependencies
run: |
cd packages/artifacts
yarn install
- name: Build Package
env:
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
run: |
cd packages/artifacts
yarn build
- name: Publish to NPM
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd packages/artifacts
if [[ "$VERSION" == *"-alpha"* ]]; then
npm publish --tag alpha --access public
else
npm publish --tag latest --access public
fi
4 changes: 2 additions & 2 deletions .github/workflows/contract-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
cache: 'yarn'
node-version: 18
- name: Install dependencies
run: cd ../../ && yarn install --pure-lockfile
run: cd ../../ && yarn install --pure-lockfile --ignore-scripts
- name: Compile contracts
run: yarn run build && yarn run build:npm
run: yarn run build
- name: Run Hardhat Tests
env:
REPORT_GAS: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
cache: 'yarn'
node-version: 18
- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn install --frozen-lockfile --ignore-scripts
- name: Clean the contracts directory
run: yarn clean
working-directory: packages/contracts/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-release-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
node-version: 18
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: yarn install --pure-lockfile
run: yarn install --pure-lockfile --ignore-scripts
working-directory: packages/${{ matrix.package }}
- name: Version bump
working-directory: packages/${{ matrix.package }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/style-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
cache: 'yarn'
node-version: 18
- name: Install dependencies
run: yarn install --pure-lockfile
run: yarn install --pure-lockfile --ignore-scripts
- name: Check with prettier
run: yarn run prettier:check
2 changes: 1 addition & 1 deletion .github/workflows/subgraph-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
cache: 'yarn'
node-version: 18
- name: Install dependencies
run: yarn install --pure-lockfile
run: yarn install --pure-lockfile --ignore-scripts
- name: Build Contracts
run: cd ./packages/contracts/ && yarn run build
- name: Deploy Subgraph
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/subgraph-documentation-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
cache: 'yarn'
node-version: 18
- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn install --frozen-lockfile --ignore-scripts
- name: Generate partial introspection query results for documentation
run: yarn generate:introspection:partial
working-directory: packages/subgraph/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/subgraph-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
cache: 'yarn'
node-version: 18
- name: Install dependencies
run: yarn install --pure-lockfile
run: yarn install --pure-lockfile --ignore-scripts
- name: Build manifest
run: yarn run manifest
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ deployed_contracts.json
managementDAOTX.json

# generated
packages/artifacts/src/abi.ts
generated
subgraph.yaml
.bin
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Ensure you have Node and Yarn installed.

The latest Node version officially supported by OSx and Hardhat is 16. Node >=19 also works, but is technically unsupported by Hardhat. It's recommended to use a tool such as [nvm](https://github.com/nvm-sh/nvm) to manage different node environments. Please see the relevant documentation for details.

Start by running `yarn install` in the project root in your terminal.
Start by running `yarn --ignore-scripts` in the project root in your terminal.

### Dependencies

Expand Down
18 changes: 18 additions & 0 deletions packages/artifacts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Aragon OSx artifacts

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v1.4.0

### Changed

- Shipping the ABI and addresses for OSx v1.4
- Marking `ContractName.abi` and `ContractName.bytecode` as deprecated
- Note: certain contracts that were previously exported and were not really related to OSx are no longer present.

## v1.3.0

### Added

- Shipping the artifacts for OSx v1.3
67 changes: 67 additions & 0 deletions packages/artifacts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Aragon OSx artifacts

This package contains the ABI definitions of the OSx contracts, as well as the address of the protocol instances deployed on each network. Install it with:

```sh
yarn add @aragon/osx-artifacts
```

## Usage

```typescript
// ABI definitions
import {
DAOABI,
IDAOABI,
DAOFactoryABI,
DAORegistryABI,
PluginRepoABI,
PluginRepoFactoryABI,
PluginRepoRegistryABI,
PluginSetupProcessorABI,
PermissionManagerABI
} from "@aragon/osx-artifacts";

console.log("DAO ABI", DAOABI);

// Protocol addresses per-network
import { addresses } from "@aragon/osx-artifacts";

console.log(addresses.daoFactory.mainnet);
```

You can also open [addresses.json](./src/addresses.json) directly.

## Development

### Building the package

Install the dependencies and generate the local ABI definitions.

```sh
yarn --ignore-scripts
yarn build
```

The `build` script will:
1. Move to `packages/contracts`.
2. Install its dependencies.
3. Compile the contracts using Hardhat.
4. Generate their ABI.
5. Extract their ABI and embed it into on `src/abi.ts`.

## Documentation

You can find all documentation regarding how to use this plugin in [Aragon's documentation here](https://docs.aragon.org/osx-contracts/1.x/index.html).

## Contributing

If you like what we're doing and would love to support, please review our `CONTRIBUTING_GUIDE.md` [here](https://github.com/aragon/osx/blob/main/CONTRIBUTION_GUIDE.md). We'd love to build with you.

## Security

If you believe you've found a security issue, we encourage you to notify us. We welcome working with you to resolve the issue promptly.

Security Contact Email: [email protected]

Please do not use the issue tracker for security issues.
31 changes: 31 additions & 0 deletions packages/artifacts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@aragon/osx-artifacts",
"version": "1.4.0-alpha",
"description": "The ABI definitions and addresses for Aragon OSx",
"typings": "dist/index.d.ts",
"main": "dist/index.js",
"publishConfig": {
"access": "public"
},
"files": [
"dist"
],
"scripts": {
"build": "yarn prepare-abi && rm -Rf dist && tsc -p tsconfig.json",
"prepare-abi": "bash prepare-abi.sh",
"prepublishOnly": "yarn build"
},
"repository": {
"type": "git",
"url": "https://github.com/aragon/osx"
},
"author": "Aragon X",
"license": "AGPL-3.0-or-later",
"bugs": {
"url": "https://github.com/aragon/osx/issues"
},
"homepage": "https://github.com/aragon/osx#readme",
"devDependencies": {
"typescript": "^5.7.3"
}
}
114 changes: 114 additions & 0 deletions packages/artifacts/prepare-abi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env bash

# Exit on error
set -e

# Constants
CONTRACTS_FOLDER="../contracts"
TARGET_ABI_FILE="./src/abi.ts"

# Move into contracts package and install dependencies
cd $CONTRACTS_FOLDER

yarn --ignore-scripts && yarn build

# Move back to artifacts package
cd - > /dev/null

# Wipe the destination file
echo "// NOTE: Do not edit this file. It is generated automatically." > $TARGET_ABI_FILE

# Extract the abi field and create a TS file
CONTRACT_ARTIFACTS=$(ls \
$CONTRACTS_FOLDER/artifacts/src/core/*/*/*.json \
$CONTRACTS_FOLDER/artifacts/src/framework/*/*/*.json \
$CONTRACTS_FOLDER/artifacts/src/framework/*/*/*/*.json \
| grep -v ".dbg." \
| grep -v utils
)
for FILE in $CONTRACT_ARTIFACTS
do
SRC_FILE_NAME=$(basename $FILE)

# Backwards compatible exports with abi and bytecode
ABI=$(node -e "console.log(JSON.stringify(JSON.parse(fs.readFileSync('$FILE').toString()).abi))")
BYTECODE=$(node -e "console.log(JSON.parse(fs.readFileSync('$FILE').toString()).bytecode || '')")
CONTRACT_NAME=${SRC_FILE_NAME%".json"}

echo "export const ${CONTRACT_NAME}ABI = $ABI as const;" >> $TARGET_ABI_FILE

if [ "$BYTECODE" == "0x" -o "$BYTECODE" == "" ]; then
echo "const ${CONTRACT_NAME}Bytecode = null;" >> $TARGET_ABI_FILE
else
echo "const ${CONTRACT_NAME}Bytecode = \"$BYTECODE\";" >> $TARGET_ABI_FILE
fi

echo "
export class ${CONTRACT_NAME} {
/** @deprecated Use \`${CONTRACT_NAME}ABI\` instead. */
static get abi() {
console.warn('Warning: \`${CONTRACT_NAME}.abi\` is deprecated. Use \`${CONTRACT_NAME}ABI\` instead.');
return ${CONTRACT_NAME}ABI;
}
/** @deprecated Use the bytecode deployed on the target network. See addresses.json */
static get bytecode(): \`0x\${string}\` | null {
console.warn('Warning: \`${CONTRACT_NAME}.bytecode\` is deprecated and may be removed in future versions.');
return ${CONTRACT_NAME}Bytecode;
}
}
" >> $TARGET_ABI_FILE

echo "" >> $TARGET_ABI_FILE
done

# Common interfaces JSON ABI
EXTRA_CONTRACT_ABI_FILES=$(ls \
$CONTRACTS_FOLDER/artifacts/@aragon/osx-commons-contracts/src/dao/*.sol/*.json \
$CONTRACTS_FOLDER/artifacts/@aragon/osx-commons-contracts/src/executors/*.sol/*.json \
$CONTRACTS_FOLDER/artifacts/@aragon/osx-commons-contracts/src/permission/*/*.sol/*.json \
$CONTRACTS_FOLDER/artifacts/@aragon/osx-commons-contracts/src/plugin/*.sol/*.json \
$CONTRACTS_FOLDER/artifacts/@aragon/osx-commons-contracts/src/plugin/setup/*.sol/*.json \
$CONTRACTS_FOLDER/artifacts/@aragon/osx-commons-contracts/src/utils/versioning/*.sol/*.json \
| grep -v ".dbg."
)

# Shipping the common interfaces as well
for FILE in $EXTRA_CONTRACT_ABI_FILES
do
SRC_FILE_NAME=$(basename $FILE)

ABI=$(node -e "console.log(JSON.stringify(JSON.parse(fs.readFileSync('$FILE').toString()).abi))")
BYTECODE=$(node -e "console.log(JSON.parse(fs.readFileSync('$FILE').toString()).bytecode || '')")
CONTRACT_NAME=${SRC_FILE_NAME%".json"}

echo "export const ${CONTRACT_NAME}ABI = $ABI as const;" >> $TARGET_ABI_FILE

if [ "$BYTECODE" == "0x" -o "$BYTECODE" == "" ]; then
echo "const ${CONTRACT_NAME}Bytecode = null;" >> $TARGET_ABI_FILE
else
echo "const ${CONTRACT_NAME}Bytecode = \"$BYTECODE\";" >> $TARGET_ABI_FILE
fi

echo "
export class ${CONTRACT_NAME} {
/** @deprecated Use \`${CONTRACT_NAME}ABI\` instead. */
static get abi() {
console.warn('Warning: \`${CONTRACT_NAME}.abi\` is deprecated. Use \`${CONTRACT_NAME}ABI\` instead.');
return ${CONTRACT_NAME}ABI;
}
/** @deprecated Use the bytecode deployed on the target network. See addresses.json */
static get bytecode(): \`0x\${string}\` | null {
console.warn('Warning: \`${CONTRACT_NAME}.bytecode\` is deprecated and may be removed in future versions.');
return ${CONTRACT_NAME}Bytecode;
}
}
" >> $TARGET_ABI_FILE

echo "" >> $TARGET_ABI_FILE
done

echo "ABI prepared: $TARGET_ABI_FILE"
Loading

0 comments on commit 1f91ce0

Please sign in to comment.