Skip to content

Commit 94374c8

Browse files
authored
Merge pull request #181 from gnosis/development
Development
2 parents b07915d + e5d4e53 commit 94374c8

File tree

75 files changed

+3387
-3130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3387
-3130
lines changed

.github/workflows/e2e-test.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
name: e2e Test
22
on:
3+
pull_request:
34
push:
45
branches:
5-
- development
66
- main
7-
pull_request:
8-
branches:
97
- development
10-
- main
118
env:
129
INFURA_KEY: ${{ secrets.INFURA_KEY }}
1310
jobs:

.github/workflows/test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: Monorepo Test
2-
on: [push, pull_request]
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
- development
38
env:
49
INFURA_KEY: ${{ secrets.INFURA_KEY }}
510
jobs:

.github/workflows/test_ethers_V1_2_0.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: Safe Core SDK Test - Ethers - Safe v1.2.0
2-
on: [push, pull_request]
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
- development
38
env:
49
INFURA_KEY: ${{ secrets.INFURA_KEY }}
510
jobs:

.github/workflows/test_ethers_V1_3_0.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: Safe Core SDK Test - Ethers - Safe v1.3.0
2-
on: [push, pull_request]
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
- development
38
env:
49
INFURA_KEY: ${{ secrets.INFURA_KEY }}
510
jobs:

.github/workflows/test_web3_V1_2_0.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: Safe Core SDK Test - Web3 - Safe v1.2.0
2-
on: [push, pull_request]
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
- development
38
env:
49
INFURA_KEY: ${{ secrets.INFURA_KEY }}
510
jobs:

.github/workflows/test_web3_V1_3_0.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: Safe Core SDK Test - Web3 - Safe v1.3.0
2-
on: [push, pull_request]
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
- development
38
env:
49
INFURA_KEY: ${{ secrets.INFURA_KEY }}
510
jobs:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Software developer tools that facilitate the interaction with the Gnosis Safe [c
1414
| ------- | :-----: | ----------- |
1515
| [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) |
1616
[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 |
17+
[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 |
1718
[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) |
1819
[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) |
1920
[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 |

packages/guides/integrating-the-safe-core-sdk.md

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,56 +22,37 @@ To integrate the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk) into y
2222
@gnosis.pm/safe-service-client
2323
```
2424

25-
## <a name="initialize-sdks">2. Initialize the SDK’s</a>
26-
27-
### Initialize the Safe Service Client
28-
29-
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.
30-
31-
```js
32-
import SafeServiceClient from '@gnosis.pm/safe-service-client'
33-
34-
const transactionServiceUrl = 'https://safe-transaction.gnosis.io'
35-
const safeService = new SafeServiceClient(transactionServiceUrl)
25+
And one of these two:
26+
```
27+
@gnosis.pm/safe-web3-lib
28+
@gnosis.pm/safe-ethers-lib
3629
```
3730

38-
### Initialize the Safe Core SDK
39-
40-
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/).
31+
## <a name="initialize-sdks">2. Initialize the SDK’s</a>
4132

42-
* **Using ethers.js**
33+
### Instantiate an EthAdapter
4334

44-
We can use the class `EthersAdapter` from `@gnosis.pm/safe-ethers-lib` as the wrapper for `ethers.js`.
35+
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.
4536

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

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

54-
const ethAdapter = new EthersAdapter({
55-
ethers,
56-
signer: safeOwner
57-
})
58-
```
42+
Once the instance of `EthersAdapter` or `Web3Adapter` is created, it can be used in the SDK initialization.
5943

60-
* **Using web3.js**
44+
### Initialize the Safe Service Client
6145

62-
We can use the class `Web3Adapter` from `@gnosis.pm/safe-web3-lib` as the wrapper for `web3.js`.
46+
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.
6347

64-
```js
65-
import Web3Adapter from '@gnosis.pm/safe-web3-lib'
66-
import Web3 from 'web3'
48+
```js
49+
import SafeServiceClient from '@gnosis.pm/safe-service-client'
6750

68-
const ethAdapter = new Web3Adapter({
69-
web3,
70-
signerAddress: safeOwnerAddress
71-
})
72-
```
51+
const txServiceUrl = 'https://safe-transaction.gnosis.io'
52+
const safeService = new SafeServiceClient({ txServiceUrl, ethAdapter })
53+
```
7354

74-
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`.
55+
### Initialize the Safe Core SDK
7556

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

137-
Calling the method `deploySafe` will deploy the desired Safe and return a Safe Core SDK initialized instance ready to be used.
118+
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.
138119

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

packages/safe-core-sdk-types/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gnosis.pm/safe-core-sdk-types",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Safe Core SDK types",
55
"main": "dist/src/index.js",
66
"typings": "dist/src/index.d.ts",
@@ -30,19 +30,19 @@
3030
],
3131
"homepage": "https://github.com/gnosis/safe-core-sdk#readme",
3232
"devDependencies": {
33-
"@types/node": "^17.0.13",
34-
"@typescript-eslint/eslint-plugin": "^5.10.1",
35-
"@typescript-eslint/parser": "^5.10.1",
36-
"eslint": "^8.7.0",
37-
"eslint-config-prettier": "^8.3.0",
33+
"@types/node": "^17.0.23",
34+
"@typescript-eslint/eslint-plugin": "^5.17.0",
35+
"@typescript-eslint/parser": "^5.17.0",
36+
"eslint": "^8.12.0",
37+
"eslint-config-prettier": "^8.5.0",
3838
"eslint-plugin-prettier": "^4.0.0",
39-
"prettier": "^2.5.1",
40-
"typescript": "^4.5.5"
39+
"prettier": "^2.6.2",
40+
"typescript": "^4.6.3"
4141
},
4242
"dependencies": {
43-
"@ethersproject/bignumber": "^5.5.0",
44-
"@ethersproject/contracts": "^5.5.0",
45-
"@gnosis.pm/safe-deployments": "^1.8.0",
46-
"web3-core": "^1.7.0"
43+
"@ethersproject/bignumber": "^5.6.0",
44+
"@ethersproject/contracts": "^5.6.0",
45+
"@gnosis.pm/safe-deployments": "^1.12.0",
46+
"web3-core": "^1.7.1"
4747
}
4848
}

packages/safe-core-sdk-types/src/contracts/GnosisSafeProxyFactoryContract.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface CreateProxyProps {
55
initializer: string
66
saltNonce: number
77
options?: TransactionOptions
8+
callback?: (txHash: string) => void
89
}
910

1011
export interface GnosisSafeProxyFactoryContract {

packages/safe-core-sdk-types/src/ethereumLibs/EthAdapter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AbiItem } from 'web3-utils'
44
import { GnosisSafeContract } from '../contracts/GnosisSafeContract'
55
import { GnosisSafeProxyFactoryContract } from '../contracts/GnosisSafeProxyFactoryContract'
66
import { MultiSendContract } from '../contracts/MultiSendContract'
7-
import { SafeVersion } from '../types'
7+
import { Eip3770Address, SafeVersion } from '../types'
88

99
export interface EthAdapterTransaction {
1010
to: string
@@ -25,6 +25,7 @@ export interface GetContractProps {
2525

2626
export interface EthAdapter {
2727
isAddress(address: string): boolean
28+
getEip3770Address(fullAddress: string): Promise<Eip3770Address>
2829
getBalance(address: string): Promise<BigNumber>
2930
getChainId(): Promise<number>
3031
getSafeContract({
@@ -52,7 +53,7 @@ export interface EthAdapter {
5253
isContractDeployed(address: string): Promise<boolean>
5354
getTransaction(transactionHash: string): Promise<any>
5455
getSignerAddress(): Promise<string>
55-
signMessage(message: string, signerAddress: string): Promise<string>
56+
signMessage(message: string): Promise<string>
5657
estimateGas(
5758
transaction: EthAdapterTransaction,
5859
callback?: (error: Error, gas: number) => void

packages/safe-core-sdk-types/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,8 @@ export interface TransactionResult extends BaseTransactionResult {
6464
transactionResponse?: ContractTransaction
6565
options?: TransactionOptions
6666
}
67+
68+
export interface Eip3770Address {
69+
prefix: string
70+
address: string
71+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2021-2022 Gnosis Ltd
4+
5+
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:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
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.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Safe Core SDK Utils
2+
3+
[![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)
4+
[![GitHub Release](https://img.shields.io/github/release/gnosis/safe-core-sdk.svg?style=flat)](https://github.com/gnosis/safe-core-sdk/releases)
5+
[![GitHub](https://img.shields.io/github/license/gnosis/safe-core-sdk)](https://github.com/gnosis/safe-core-sdk/blob/main/LICENSE.md)
6+
7+
Utilities for the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk) monorepo.
8+
9+
## Table of contents
10+
* [Installation](#installation)
11+
* [Build](#build)
12+
13+
## <a name="installation">Installation</a>
14+
15+
Install the package with yarn or npm:
16+
17+
```bash
18+
yarn install
19+
npm install
20+
```
21+
22+
## <a name="build">Build</a>
23+
24+
Build the package with yarn or npm:
25+
26+
```bash
27+
yarn build
28+
npm build
29+
```
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "@gnosis.pm/safe-core-sdk-utils",
3+
"version": "1.1.0",
4+
"description": "Safe Core SDK Utilities",
5+
"main": "dist/src/index.js",
6+
"typings": "dist/src/index.d.ts",
7+
"keywords": [
8+
"Ethereum",
9+
"Gnosis",
10+
"Safe",
11+
"SDK"
12+
],
13+
"scripts": {
14+
"safe-deployments": "ts-node scripts/checkSafeDeployments.ts",
15+
"unbuild": "rimraf dist *.tsbuildinfo",
16+
"build": "rimraf dist && yarn safe-deployments && tsc",
17+
"test": "nyc mocha -r ts-node/register tests/**/*.test.ts",
18+
"format": "prettier --write \"{src,tests}/**/*.ts\"",
19+
"lint": "tslint -p tsconfig.json"
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "git+https://github.com/gnosis/safe-core-sdk.git"
24+
},
25+
"author": "Gnosis (https://gnosis.io)",
26+
"license": "MIT",
27+
"bugs": {
28+
"url": "https://github.com/gnosis/safe-core-sdk/issues"
29+
},
30+
"files": [
31+
"dist"
32+
],
33+
"homepage": "https://github.com/gnosis/safe-core-sdk#readme",
34+
"devDependencies": {
35+
"@gnosis.pm/safe-deployments": "^1.12.0",
36+
"@types/chai": "^4.3.0",
37+
"@types/chai-as-promised": "^7.1.5",
38+
"@types/mocha": "^9.1.0",
39+
"@types/node": "^17.0.23",
40+
"@typescript-eslint/eslint-plugin": "^5.17.0",
41+
"@typescript-eslint/parser": "^5.17.0",
42+
"chai": "^4.3.6",
43+
"chai-as-promised": "^7.1.1",
44+
"eslint": "^8.12.0",
45+
"eslint-config-prettier": "^8.5.0",
46+
"eslint-plugin-prettier": "^4.0.0",
47+
"mocha": "^9.2.2",
48+
"nyc": "^15.1.0",
49+
"prettier": "^2.6.1",
50+
"ts-node": "^10.7.0",
51+
"typescript": "^4.6.3"
52+
},
53+
"dependencies": {
54+
"@gnosis.pm/safe-core-sdk-types": "^1.1.0",
55+
"web3-utils": "^1.7.1"
56+
}
57+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { SafeVersion } from '@gnosis.pm/safe-core-sdk-types'
2+
import { DeploymentFilter, getSafeSingletonDeployment } from '@gnosis.pm/safe-deployments'
3+
import { networks } from '../src/eip-3770/config'
4+
5+
const safeVersion: SafeVersion = '1.3.0'
6+
7+
function getSafeDeploymentNetworks(): string[] {
8+
const filters: DeploymentFilter = { version: safeVersion, released: true }
9+
const singletons = getSafeSingletonDeployment(filters)
10+
if (!singletons) {
11+
throw new Error('Empty Safe Deployments')
12+
}
13+
return Object.keys(singletons.networkAddresses)
14+
}
15+
16+
function getLocalNetworksConfig(): string[] {
17+
return networks.map(network => network.chainId.toString())
18+
}
19+
20+
function checkConfigDiff() {
21+
const safeDeployments = getSafeDeploymentNetworks()
22+
const localNetworks = getLocalNetworksConfig()
23+
if (safeDeployments.length !== localNetworks.length) {
24+
const chainIdsDiff = safeDeployments.filter(chainId => !localNetworks.includes(chainId))
25+
const errorMessage = `EIP-3770 local config is missing chainIds: ${chainIdsDiff}`
26+
throw new Error(errorMessage)
27+
}
28+
}
29+
30+
checkConfigDiff()

0 commit comments

Comments
 (0)