Skip to content

Commit

Permalink
Merge pull request #181 from gnosis/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
germartinez authored Apr 4, 2022
2 parents b07915d + e5d4e53 commit 94374c8
Show file tree
Hide file tree
Showing 75 changed files with 3,387 additions and 3,130 deletions.
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

0 comments on commit 94374c8

Please sign in to comment.