Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
remedcu authored Jul 4, 2024
2 parents 83cab62 + 542b2ef commit d016ac1
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 208 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ on:

permissions:
contents: write
pull-requests: write

jobs:
release:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- run: |
Expand All @@ -21,3 +20,5 @@ jobs:
- run: |
npm ci
bash bin/github-release.sh --verbose
env:
GH_TOKEN: ${{ github.token }}
84 changes: 56 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,115 @@
[![npm version](https://badge.fury.io/js/%40safe-global%2Fsafe-deployments.svg)](https://badge.fury.io/js/%40safe-global%2Fsafe-deployments)
[![CI](https://github.com/safe-global/safe-deployments/actions/workflows/test.yml/badge.svg)](https://github.com/safe-global/safe-deployments/actions/workflows/test.yml)

This contract contains a collection of deployments of the contract of the [Safe contracts repository](https://github.com/safe-global/safe-contracts).
This contract contains a collection of deployments of the contract of the [Safe contracts repository](https://github.com/safe-global/safe-smart-account).

For each deployment the address on the different networks and the abi files are available. To get an overview of the available versions check the available [json assets](./src/assets/).
The addresses on the different networks and the abi files are available for each deployment. To get an overview of the available versions, check the available [json assets](./src/assets/).

To add additional deployments please follow the [deployment steps in the Safe contract repository](https://github.com/safe-global/safe-contracts#deployments).
## Adding additional deployments:

1. Follow the [deployment steps in the Safe contract repository](https://github.com/safe-global/safe-smart-contracts#deployments).
2. Verify that the addresses match the expected address for each contract. You can find them under the "addresses" mapping in the respective JSON file in the [assets folder](./src/assets/).
3. Create a PR adding the new deployment. Example PR can be found [here](https://github.com/safe-global/safe-deployments/pull/676).

## Install

- npm - `npm i @safe-global/safe-deployments`
- yarn - `yarn add @safe-global/safe-deployments`

## Usage

It is possible to directly use the json files in the [assets folder](./src/assets/) that contain the addresses and abi definitions.
It is possible to directly use the JSON files in the [assets folder](./src/assets/) that contain the addresses and abi definitions.

An alternative is to use the JavaScript library methods to query the correct deployment. The library supports different methods to get the deployment of a specific contract.
An alternative is using JavaScript library methods to query the correct deployment. The library supports different methods to get the deployment of a specific contract.

Each of the method takes an optional `DeploymentFilter` as a parameter.
Each of the methods takes an optional `DeploymentFilter` as a parameter.

```ts
interface DeploymentFilter {
version?: string,
released?: boolean, // Defaults to true if no filter is specified
network?: string // Chain id of the network
version?: string;
released?: boolean; // Defaults to true if no filter is specified
network?: string; // Chain id of the network
}
```

The method will return a `SingletonDeployment` object or `undefined` if no deployment was found for the specified filter.

```ts
interface SingletonDeployment {
defaultAddress: string, // Address the contract was deployed to by the Safe team
version: string,
abi: any[],
networkAddresses: Record<string, string>, // Address of the contract by network
contractName: string,
released: boolean // A released version was audited and has a running bug bounty
// The default address of the deployment.
defaultAddress: string;

// Indicates if the deployment is released.
released: boolean;

// The name of the contract.
contractName: string;

// The version of the deployment.
version: string;

// The hash of the contract code.
codeHash: string;

// A record of addresses, where the key is the address type and the value is the address.
addresses: Record<string, string>;

// A record of network addresses, where the key is the network identifier and the value is the address.
networkAddresses: Record<string, string>;

// The ABI (Application Binary Interface) of the contract.
abi: any[];
}
```

- Safe

```ts
const safeSingleton = getSafeSingletonDeployment()
const safeSingleton = getSafeSingletonDeployment();

// Returns latest contract version, even if not finally released yet
const safeSingletonNightly = getSafeSingletonDeployment({ released: undefined })
const safeSingletonNightly = getSafeSingletonDeployment({ released: undefined });

// Returns released contract version for specific network
const safeSingletonGörli = getSafeSingletonDeployment({ network: "5" })
const safeSingletonGörli = getSafeSingletonDeployment({ network: '5' });

// Returns released contract version for specific version
const safeSingleton100 = getSafeSingletonDeployment({ version: "1.0.0" })
const safeSingleton100 = getSafeSingletonDeployment({ version: '1.0.0' });

// Version with additional events used on L2 networks
const safeL2Singleton = getSafeL2SingletonDeployment()
const safeL2Singleton = getSafeL2SingletonDeployment();
```

- Factories

```ts
const proxyFactory = getProxyFactoryDeployment()
const proxyFactory = getProxyFactoryDeployment();
```

- Libraries

```ts
const multiSendLib = getMultiSendDeployment()
const multiSendLib = getMultiSendDeployment();

const multiSendCallOnlyLib = getMultiSendCallOnlyDeployment()
const multiSendCallOnlyLib = getMultiSendCallOnlyDeployment();

const createCallLib = getCreateCallDeployment()
const createCallLib = getCreateCallDeployment();
```

- Handler

```ts
// Returns recommended handler
const fallbackHandler = getFallbackHandlerDeployment()
const fallbackHandler = getFallbackHandlerDeployment();

const callbackHandler = getDefaultCallbackHandlerDeployment()
const callbackHandler = getDefaultCallbackHandlerDeployment();

const compatHandler = getCompatibilityFallbackHandlerDeployment()
const compatHandler = getCompatibilityFallbackHandlerDeployment();
```

## Release cycle
`safe-deployments` release cycle is once per month, except urgent issues that require immediate attention.

`safe-deployments` release cycle is once per month, except for urgent issues that require immediate attention.

## Notes

Expand Down
125 changes: 88 additions & 37 deletions bin/github-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ set -euo pipefail

usage() {
cat <<EOF
This script creates a draft GitHub release on the current commit.
Script for managing the GitHub release process.
It provides functionality for automatically:
• Creating GitHub pull requests for bumping version numbers
• Drafting new GitHub releases
• Publishing GitHub releases once the version lands on NPM
USAGE
bash bin/github-release.sh [-v|--verbose] [--no-push]
bash bin/github-release.sh [-v|--verbose] [-n|--dry-run]
OPTIONS
-v | --verbose Verbose output
Expand All @@ -19,15 +24,15 @@ EXAMPLES
EOF
}

verbose=n
dryrun=n
verbose="n"
dryrun="n"
while [[ $# -gt 0 ]]; do
case "$1" in
-v|--verbose)
verbose=y
verbose="y"
;;
-n|--dry-run)
dryrun=y
dryrun="y"
;;
*)
usage
Expand All @@ -45,47 +50,93 @@ log() {

if [[ -n "$(git status --porcelain)" ]]; then
echo "ERROR: Dirty Git index, please commit all changes before continuing" 1>&2
#exit 1
if [[ "$dryrun" == "n" ]]; then
exit 1
fi
fi
if ! command -v gh &> /dev/null; then
echo "ERROR: Please install the 'gh' GitHub CLI" 1>&2
exit 1
fi

name=$(jq -r '.name' package.json)
current=$(jq -r '.version' package.json)
latest=$(npm view "$name" version)

if [[ -n "$(git tag -l --points-at HEAD | awk '$1 == "v'$latest'"')" ]]; then
log "no changes since latest release"
exit 0
elif [[ "$current" == "$latest" ]]; then
log "bumping version"
bump="patch"
else
log "reusing current version"
bump="$current"
name="$(jq -r '.name' package.json)"
current="$(jq -r '.version' package.json)"
latest="$(npm view "$name" version)"

log "current: v$current"
log "latest: v$latest"

if ! printf "%s\n" "$latest" "$current" | sort -C -V; then
echo "ERROR: Latest NPM version is newer than current version" 1>&2
exit 1
fi
tag=$(npm version "$bump" --allow-same-version --no-git-tag-version)

if [[ "$dryrun" == "n" ]]; then
log "updating repository to $tag"
if [[ -n "$(git status --porcelain)" ]]; then
git commit -am "$tag"
git push origin
tag="v$current"
commit="$(git rev-parse HEAD)"
draft="$(gh release view "$tag" --json isDraft,targetCommitish --jq 'if(.isDraft) then .targetCommitish else "" end' 2>/dev/null || true)"

log "commit: ${commit}"
log "draft: ${draft:-none}"

if [[ -z "$draft" ]] && [[ "$current" == "$latest" ]]; then
# In this case, we have no existing draft, and the current version is
# the same as the latest release, so we need to create a new PR to bump
# the package version.
log "==> Bumping Version"

git fetch --tags --force --quiet
if [[ -n "$(git tag -l --points-at HEAD | awk '$1 == "'$tag'"')" ]]; then
log "no changes since latest release"
exit 0
fi
fi

log "generating NPM packaging"
npm pack
package="${name#@}-${tag#v}.tgz"
package="${package//\//-}"
newtag="$(npm version patch --no-git-tag-version)"
log "bumping to $newtag"

if [[ "$dryrun" == "n" ]]; then
log "creating draft release"
gh release delete "$tag" --yes &>/dev/null || true
gh release create "$tag" --draft --generate-notes --target "$(git rev-parse HEAD)" --title "$tag"
branch="bump/$newtag"
if git ls-remote --heads origin | grep "refs/heads/$branch\$" >/dev/null; then
log "version bump PR already exists"
exit 0
fi
if [[ "$dryrun" == "n" ]]; then
log "creating PR bumping version"
git checkout -b "$branch"
git commit -am "Bump Version to $newtag"
git push -u origin "$branch"
gh pr create --fill
fi
elif [[ "$current" != "$latest" ]]; then
# In this case, the current version is newer that the latest released
# version on NPM, so we create or update the draft release to ensure it
# includes the latest version.
log "==> Drafting Release"

if [[ "$commit" == "$draft" ]]; then
log "draft is already at latest commit"
exit 0
fi

log "uploading ${package}"
gh release upload "$tag" "${package}"
log "generating NPM package"
npm pack
package="${name#@}-$current.tgz"
package="${package//\//-}"

if [[ "$dryrun" == "n" ]]; then
log "drafting release with NPM tarball"
if [[ -n "$draft" ]]; then
log "cleaning up existing draft"
gh release delete "$tag" --yes
fi
gh release create "$tag" --draft --generate-notes --target "$commit" --title "$tag" "$package"
fi
else # if [[ -n "$draft" ]] && [[ "$current" == "$latest" ]]; then
# In this case, there is an existing draft, and the latest version is
# equal to it. Publish the draft release!
log "==> Publishing Release"

tag="v$current"
if [[ "$dryrun" == "n" ]]; then
log "publishing draft release"
gh release edit "$tag" --draft=false
fi
fi
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safe-global/safe-deployments",
"version": "1.37.0",
"version": "1.37.1",
"description": "Collection of Safe singleton deployments",
"homepage": "https://github.com/safe-global/safe-deployments/",
"license": "MIT",
Expand Down
Loading

0 comments on commit d016ac1

Please sign in to comment.