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

Development #181

Merged
merged 56 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
1cc83a1
Add safe-core-sdk-utils package
germartinez Feb 7, 2022
4975cd8
Update README files
germartinez Feb 7, 2022
e610d7e
Add eip-3770 network list
germartinez Feb 7, 2022
8bb2e61
Add support for eip-3770
germartinez Feb 7, 2022
9396bc8
Add tests for eip-3770
germartinez Feb 7, 2022
4edf32e
Update EthAdapters
germartinez Feb 7, 2022
3f97786
Update SafeServiceClient.ts
de33 Feb 11, 2022
129a614
Update Safe Core SDK guide
germartinez Feb 11, 2022
eb66643
Add initialization in EthAdapter README files
germartinez Feb 11, 2022
eb39440
Add license and contributors to README files
germartinez Feb 14, 2022
629ae8e
Add eip-3770 support to Safe Service Client
germartinez Feb 14, 2022
6a5bfb6
Refactor Service Client tests
germartinez Feb 14, 2022
528035e
Move Service Client tests
germartinez Feb 14, 2022
e83915d
Remove signerAddress from signMessage params
germartinez Feb 14, 2022
293a9bd
Fix EIP-3770 address validation
germartinez Feb 14, 2022
e1bca2d
Add tests for EIP-3770
germartinez Feb 15, 2022
8fc4be7
Fix calculation of data with EIP-3770
germartinez Feb 15, 2022
daf0eb5
Update Service Client test scripts
germartinez Feb 15, 2022
24f8c61
Update safe-deployments v1.9.0
germartinez Feb 21, 2022
9ae12cd
Merge pull request #177 from gnosis/safe-deployments-1.9.0
germartinez Feb 21, 2022
01e583e
Update github actions event triggers
germartinez Feb 21, 2022
cbb84c0
Merge pull request #180 from gnosis/github-actions
germartinez Feb 22, 2022
5486a10
Merge pull request #178 from gnosis/eip-3770
germartinez Feb 22, 2022
88b427a
Remove signerAddress from signMessage
germartinez Feb 22, 2022
afaa2e9
Update README files
germartinez Feb 22, 2022
ad494c1
Merge pull request #179 from gnosis/eip-3770-service-client
germartinez Feb 22, 2022
88cc70d
Update safe-deployments v1.10.0
germartinez Mar 8, 2022
501b931
Add local network prefix for hardhat and ganache tests
germartinez Mar 8, 2022
724eb5c
Add script to sync EIP-3770 config with safe-deployments
germartinez Mar 8, 2022
ebcad91
Add EIP-3770 missing networks
germartinez Mar 8, 2022
56ed067
Networks object formatting
germartinez Mar 8, 2022
eb20e41
Update dependencies
germartinez Mar 25, 2022
161855d
Sync networks config with safe-deployments
germartinez Mar 25, 2022
cf5eee9
Merge branch 'development' into getModuleTransactions-fix
jfschwarz Mar 29, 2022
20805ae
Merge pull request #173 from de33/getModuleTransactions-fix
germartinez Mar 29, 2022
9d3f6b4
Merge branch 'development' of github.com:gnosis/safe-core-sdk into de…
germartinez Mar 29, 2022
12e2498
Fix getModuleTransactions tests
germartinez Mar 29, 2022
3f6d5d5
Add SafeVersion missing type
germartinez Mar 29, 2022
32c221b
Merge pull request #184 from gnosis/safe-deployments-script
germartinez Mar 29, 2022
1c48c18
Merge pull request #187 from gnosis/update-deps
germartinez Mar 30, 2022
c0f50e3
Add callback to CreateProxyProps interface
germartinez Apr 1, 2022
b22dfe2
Add Safe deployment callback to safe-web3-lib
germartinez Apr 1, 2022
b5e44b0
Add Safe deployment callback to safe-ethers-lib
germartinez Apr 1, 2022
babccb6
Pass callback to SafeFactory class
germartinez Apr 1, 2022
8230c6c
Tests Safe deployment callback
germartinez Apr 1, 2022
787584b
safe-core-sdk-types v1.1.0
germartinez Apr 4, 2022
877e434
safe-ethers-lib v1.1.0
germartinez Apr 4, 2022
ebd2aca
safe-core-sdk v2.1.0
germartinez Apr 4, 2022
9f35d34
safe-service-client v1.1.2
germartinez Apr 4, 2022
2e8e890
sdk-core-sdk-utils v1.1.0
germartinez Apr 4, 2022
5ec0f26
safe-web3-lib v1.1.0
germartinez Apr 4, 2022
de0b818
safe-ethers-adapters v0.1.0-alpha.9
germartinez Apr 4, 2022
753229e
Merge pull request #188 from gnosis/fix-deployment
germartinez Apr 4, 2022
678743c
Add Safe deployment callback to the README
germartinez Apr 4, 2022
a94df06
Merge pull request #189 from gnosis/release
germartinez Apr 4, 2022
e5d4e53
Update yarn.lock
germartinez Apr 4, 2022
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
5 changes: 1 addition & 4 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: e2e Test
on:
pull_request:
push:
branches:
- development
- main
pull_request:
branches:
- development
- main
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
jobs:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Monorepo Test
on: [push, pull_request]
on:
pull_request:
push:
branches:
- main
- development
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
jobs:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test_ethers_V1_2_0.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Safe Core SDK Test - Ethers - Safe v1.2.0
on: [push, pull_request]
on:
pull_request:
push:
branches:
- main
- development
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
jobs:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test_ethers_V1_3_0.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Safe Core SDK Test - Ethers - Safe v1.3.0
on: [push, pull_request]
on:
pull_request:
push:
branches:
- main
- development
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
jobs:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test_web3_V1_2_0.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Safe Core SDK Test - Web3 - Safe v1.2.0
on: [push, pull_request]
on:
pull_request:
push:
branches:
- main
- development
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
jobs:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test_web3_V1_3_0.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Safe Core SDK Test - Web3 - Safe v1.3.0
on: [push, pull_request]
on:
pull_request:
push:
branches:
- main
- development
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
jobs:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Software developer tools that facilitate the interaction with the Gnosis Safe [c
| ------- | :-----: | ----------- |
| [safe-core-sdk](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-core-sdk) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-core-sdk.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-core-sdk) | TypeScript library that facilitates the interaction with the [Gnosis Safe contracts](https://github.com/gnosis/safe-contracts) |
[safe-core-sdk-types](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-core-sdk-types) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-core-sdk-types.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-core-sdk-types) | Common types extracted from the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk/tree/main/packages) packages |
[safe-core-sdk-utils](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-core-sdk-utils) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-core-sdk-utils.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-core-sdk-utils) | Utilities for the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk/tree/main/packages) packages |
[safe-ethers-lib](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-ethers-lib) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-ethers-lib.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-ethers-lib) | Ethers.js utilities and Safe contracts types (typechain ethers-v5) used to initialize the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-core-sdk) |
[safe-web3-lib](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-web3-lib) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-web3-lib.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-web3-lib) | Web3.js utilities and Safe contracts types (typechain web3-v1) used to initialize the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-core-sdk) |
[safe-service-client](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-service-client) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-service-client.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-service-client) | [Safe Transaction Service API](https://github.com/gnosis/safe-transaction-service) client library |
Expand Down
59 changes: 20 additions & 39 deletions packages/guides/integrating-the-safe-core-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,37 @@ To integrate the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk) into y
@gnosis.pm/safe-service-client
```

## <a name="initialize-sdks">2. Initialize the SDK’s</a>

### Initialize the Safe Service Client

As stated in the introduction, the [Safe Service Client](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-service-client) consumes the [Safe Transaction Service API](https://github.com/gnosis/safe-transaction-service). To start using this library, create a new instance of the class `SafeServiceClient` imported from `@gnosis.pm/safe-service-client` and pass the URL to its constructor of the Safe Transaction Service you want to use depending on the network.

```js
import SafeServiceClient from '@gnosis.pm/safe-service-client'

const transactionServiceUrl = 'https://safe-transaction.gnosis.io'
const safeService = new SafeServiceClient(transactionServiceUrl)
And one of these two:
```
@gnosis.pm/safe-web3-lib
@gnosis.pm/safe-ethers-lib
```

### Initialize the Safe Core SDK

The [Safe Core SDK](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-core-sdk) library only interacts with the [Safe contracts](https://github.com/gnosis/safe-contracts). Because of this, we need to select one Ethereum library: [web3.js](https://web3js.readthedocs.io/) or [ethers.js](https://docs.ethers.io/v5/).
## <a name="initialize-sdks">2. Initialize the SDK’s</a>

* **Using ethers.js**
### Instantiate an EthAdapter

We can use the class `EthersAdapter` from `@gnosis.pm/safe-ethers-lib` as the wrapper for `ethers.js`.
First of all, we need to create an `EthAdapter`, which contains all the required utilities for the SDKs to interact with the blockchain. It acts as a wrapper for [web3.js](https://web3js.readthedocs.io/) or [ethers.js](https://docs.ethers.io/v5/) Ethereum libraries.

```js
import EthersAdapter from '@gnosis.pm/safe-ethers-lib'
import { ethers } from 'ethers'
Depending on the library used by the Dapp, there are two options:

const web3Provider = // ...
const provider = new ethers.providers.Web3Provider(web3Provider)
const safeOwner = provider.getSigner(0)
- [Create an `EthersAdapter` instance](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-ethers-lib#initialization)
- [Create a `Web3Adapter` instance](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-web3-lib#initialization)

const ethAdapter = new EthersAdapter({
ethers,
signer: safeOwner
})
```
Once the instance of `EthersAdapter` or `Web3Adapter` is created, it can be used in the SDK initialization.

* **Using web3.js**
### Initialize the Safe Service Client

We can use the class `Web3Adapter` from `@gnosis.pm/safe-web3-lib` as the wrapper for `web3.js`.
As stated in the introduction, the [Safe Service Client](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-service-client) consumes the [Safe Transaction Service API](https://github.com/gnosis/safe-transaction-service). To start using this library, create a new instance of the `SafeServiceClient` class, imported from `@gnosis.pm/safe-service-client` and pass the URL to the constructor of the Safe Transaction Service you want to use depending on the network.

```js
import Web3Adapter from '@gnosis.pm/safe-web3-lib'
import Web3 from 'web3'
```js
import SafeServiceClient from '@gnosis.pm/safe-service-client'

const ethAdapter = new Web3Adapter({
web3,
signerAddress: safeOwnerAddress
})
```
const txServiceUrl = 'https://safe-transaction.gnosis.io'
const safeService = new SafeServiceClient({ txServiceUrl, ethAdapter })
```

Once we have an instance of `EthersAdapter` or `Web3Adapter` we are ready to instantiate the `SafeFactory` and `Safe` classes from `@gnosis.pm/safe-core-sdk`.
### Initialize the Safe Core SDK

```js
import Safe, { SafeFactory } from '@gnosis.pm/safe-core-sdk'
Expand Down Expand Up @@ -134,7 +115,7 @@ const safeAccountConfig: SafeAccountConfig = {
const safeSdk = await safeFactory.deploySafe({ safeAccountConfig })
```

Calling the method `deploySafe` will deploy the desired Safe and return a Safe Core SDK initialized instance ready to be used.
Calling the method `deploySafe` will deploy the desired Safe and return a Safe Core SDK initialized instance ready to be used. Check the [API Reference](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-core-sdk#deploysafe) for more details on additional configuration parameters and callbacks.

## <a name="create-transaction">4. Create a transaction</a>

Expand Down
24 changes: 12 additions & 12 deletions packages/safe-core-sdk-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/safe-core-sdk-types",
"version": "1.0.0",
"version": "1.1.0",
"description": "Safe Core SDK types",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -30,19 +30,19 @@
],
"homepage": "https://github.com/gnosis/safe-core-sdk#readme",
"devDependencies": {
"@types/node": "^17.0.13",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.5.1",
"typescript": "^4.5.5"
"prettier": "^2.6.2",
"typescript": "^4.6.3"
},
"dependencies": {
"@ethersproject/bignumber": "^5.5.0",
"@ethersproject/contracts": "^5.5.0",
"@gnosis.pm/safe-deployments": "^1.8.0",
"web3-core": "^1.7.0"
"@ethersproject/bignumber": "^5.6.0",
"@ethersproject/contracts": "^5.6.0",
"@gnosis.pm/safe-deployments": "^1.12.0",
"web3-core": "^1.7.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface CreateProxyProps {
initializer: string
saltNonce: number
options?: TransactionOptions
callback?: (txHash: string) => void
}

export interface GnosisSafeProxyFactoryContract {
Expand Down
5 changes: 3 additions & 2 deletions packages/safe-core-sdk-types/src/ethereumLibs/EthAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AbiItem } from 'web3-utils'
import { GnosisSafeContract } from '../contracts/GnosisSafeContract'
import { GnosisSafeProxyFactoryContract } from '../contracts/GnosisSafeProxyFactoryContract'
import { MultiSendContract } from '../contracts/MultiSendContract'
import { SafeVersion } from '../types'
import { Eip3770Address, SafeVersion } from '../types'

export interface EthAdapterTransaction {
to: string
Expand All @@ -25,6 +25,7 @@ export interface GetContractProps {

export interface EthAdapter {
isAddress(address: string): boolean
getEip3770Address(fullAddress: string): Promise<Eip3770Address>
getBalance(address: string): Promise<BigNumber>
getChainId(): Promise<number>
getSafeContract({
Expand Down Expand Up @@ -52,7 +53,7 @@ export interface EthAdapter {
isContractDeployed(address: string): Promise<boolean>
getTransaction(transactionHash: string): Promise<any>
getSignerAddress(): Promise<string>
signMessage(message: string, signerAddress: string): Promise<string>
signMessage(message: string): Promise<string>
estimateGas(
transaction: EthAdapterTransaction,
callback?: (error: Error, gas: number) => void
Expand Down
5 changes: 5 additions & 0 deletions packages/safe-core-sdk-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ export interface TransactionResult extends BaseTransactionResult {
transactionResponse?: ContractTransaction
options?: TransactionOptions
}

export interface Eip3770Address {
prefix: string
address: string
}
9 changes: 9 additions & 0 deletions packages/safe-core-sdk-utils/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2021-2022 Gnosis Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions packages/safe-core-sdk-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Safe Core SDK Utils

[![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-core-sdk-utils.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-core-sdk-utils)
[![GitHub Release](https://img.shields.io/github/release/gnosis/safe-core-sdk.svg?style=flat)](https://github.com/gnosis/safe-core-sdk/releases)
[![GitHub](https://img.shields.io/github/license/gnosis/safe-core-sdk)](https://github.com/gnosis/safe-core-sdk/blob/main/LICENSE.md)

Utilities for the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk) monorepo.

## Table of contents
* [Installation](#installation)
* [Build](#build)

## <a name="installation">Installation</a>

Install the package with yarn or npm:

```bash
yarn install
npm install
```

## <a name="build">Build</a>

Build the package with yarn or npm:

```bash
yarn build
npm build
```
57 changes: 57 additions & 0 deletions packages/safe-core-sdk-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@gnosis.pm/safe-core-sdk-utils",
"version": "1.1.0",
"description": "Safe Core SDK Utilities",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
"keywords": [
"Ethereum",
"Gnosis",
"Safe",
"SDK"
],
"scripts": {
"safe-deployments": "ts-node scripts/checkSafeDeployments.ts",
"unbuild": "rimraf dist *.tsbuildinfo",
"build": "rimraf dist && yarn safe-deployments && tsc",
"test": "nyc mocha -r ts-node/register tests/**/*.test.ts",
"format": "prettier --write \"{src,tests}/**/*.ts\"",
"lint": "tslint -p tsconfig.json"
},
"repository": {
"type": "git",
"url": "git+https://github.com/gnosis/safe-core-sdk.git"
},
"author": "Gnosis (https://gnosis.io)",
"license": "MIT",
"bugs": {
"url": "https://github.com/gnosis/safe-core-sdk/issues"
},
"files": [
"dist"
],
"homepage": "https://github.com/gnosis/safe-core-sdk#readme",
"devDependencies": {
"@gnosis.pm/safe-deployments": "^1.12.0",
"@types/chai": "^4.3.0",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"prettier": "^2.6.1",
"ts-node": "^10.7.0",
"typescript": "^4.6.3"
},
"dependencies": {
"@gnosis.pm/safe-core-sdk-types": "^1.1.0",
"web3-utils": "^1.7.1"
}
}
30 changes: 30 additions & 0 deletions packages/safe-core-sdk-utils/scripts/checkSafeDeployments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { SafeVersion } from '@gnosis.pm/safe-core-sdk-types'
import { DeploymentFilter, getSafeSingletonDeployment } from '@gnosis.pm/safe-deployments'
import { networks } from '../src/eip-3770/config'

const safeVersion: SafeVersion = '1.3.0'

function getSafeDeploymentNetworks(): string[] {
const filters: DeploymentFilter = { version: safeVersion, released: true }
const singletons = getSafeSingletonDeployment(filters)
if (!singletons) {
throw new Error('Empty Safe Deployments')
}
return Object.keys(singletons.networkAddresses)
}

function getLocalNetworksConfig(): string[] {
return networks.map(network => network.chainId.toString())
}

function checkConfigDiff() {
const safeDeployments = getSafeDeploymentNetworks()
const localNetworks = getLocalNetworksConfig()
if (safeDeployments.length !== localNetworks.length) {
const chainIdsDiff = safeDeployments.filter(chainId => !localNetworks.includes(chainId))
const errorMessage = `EIP-3770 local config is missing chainIds: ${chainIdsDiff}`
throw new Error(errorMessage)
}
}

checkConfigDiff()
Loading