Skip to content

Commit

Permalink
Merge pull request #210 from safe-global/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
germartinez authored Jul 12, 2022
2 parents 399dbfc + 3282a9b commit 06d9505
Show file tree
Hide file tree
Showing 35 changed files with 2,480 additions and 4,310 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Safe Core SDK Monorepo

Software developer tools that facilitate the interaction with the Gnosis Safe [contracts](https://github.com/gnosis/safe-contracts) and [services](https://github.com/gnosis/safe-transaction-service).
Software developer tools that facilitate the interaction with the Gnosis Safe [contracts](https://github.com/safe-global/safe-contracts) and [services](https://github.com/safe-global/safe-transaction-service).

## Guides

| Title | Description |
| ------- | ----------- |
| [Integrating the Safe Core SDK](https://github.com/gnosis/safe-core-sdk/blob/main/packages/guides/integrating-the-safe-core-sdk.md) | This guide shows how to use the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-core-sdk) and [Safe Service Client](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-service-client). |
| [Integrating the Safe Core SDK](https://github.com/safe-global/safe-core-sdk/blob/main/packages/guides/integrating-the-safe-core-sdk.md) | This guide shows how to use the [Safe Core SDK](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-core-sdk) and [Safe Service Client](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-service-client). |

## Packages

| Package | Release | Description |
| ------- | :-----: | ----------- |
| [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 |
[safe-ethers-adapters](https://github.com/gnosis/safe-core-sdk/tree/main/packages/safe-ethers-adapters) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-ethers-adapters.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-ethers-adapters) | [Ethers](https://docs.ethers.io/v5/single-page/) adapter that facilitates the interaction with the [Gnosis Safe Services](https://github.com/gnosis/safe-transaction-service) |
| [safe-core-sdk](https://github.com/safe-global/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/safe-global/safe-contracts) |
[safe-core-sdk-types](https://github.com/safe-global/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/safe-global/safe-core-sdk/tree/main/packages) packages |
[safe-core-sdk-utils](https://github.com/safe-global/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/safe-global/safe-core-sdk/tree/main/packages) packages |
[safe-ethers-lib](https://github.com/safe-global/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/safe-global/safe-core-sdk/tree/main/packages/safe-core-sdk) |
[safe-web3-lib](https://github.com/safe-global/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/safe-global/safe-core-sdk/tree/main/packages/safe-core-sdk) |
[safe-service-client](https://github.com/safe-global/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/safe-global/safe-transaction-service) client library |
[safe-ethers-adapters](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-ethers-adapters) | [![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-ethers-adapters.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-ethers-adapters) | [Ethers](https://docs.ethers.io/v5/single-page/) adapter that facilitates the interaction with the [Gnosis Safe Services](https://github.com/safe-global/safe-transaction-service) |
4 changes: 2 additions & 2 deletions packages/guides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Read about the basics of Gnosis Safe and how it compares to other solutions [her

## Safe Core SDK

The [Safe Core SDK](https://github.com/gnosis/safe-core-sdk) is a monorepo that contains software developer tools that allows interaction with the [Safe contracts](https://github.com/gnosis/safe-contracts) and the [Safe Transaction Service](https://github.com/gnosis/safe-transaction-service).
The [Safe Core SDK](https://github.com/safe-global/safe-core-sdk) is a monorepo that contains software developer tools that allows interaction with the [Safe contracts](https://github.com/safe-global/safe-contracts) and the [Safe Transaction Service](https://github.com/safe-global/safe-transaction-service).

In this guide we will use the following packages to deploy new Safes, create transactions, collect off-chain signatures and execute transactions:
* **safe-core-sdk-types**
Expand Down Expand Up @@ -41,6 +41,6 @@ We'll assume that you are familiar with TypeScript (JavaScript), Ethereum and ha

## Help

If you need help, you can reach Gnosis Safe developers in the #safe-developers channel at https://chat.gnosis.io/ or create a discussion at https://github.com/gnosis/safe-core-sdk/discussions.
If you need help, you can reach Gnosis Safe developers in the #safe-developers channel at https://chat.gnosis.io/ or create a discussion at https://github.com/safe-global/safe-core-sdk/discussions.

Let's jump into the guide: [Integrating the Safe Core SDK](/packages/guides/integrating-the-safe-core-sdk.md)
22 changes: 12 additions & 10 deletions packages/guides/integrating-the-safe-core-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

## <a name="install-dependencies">1. Install the dependencies</a>

To integrate the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk) into your Dapp or script you will need to install these dependencies:
To integrate the [Safe Core SDK](https://github.com/safe-global/safe-core-sdk) into your Dapp or script you will need to install these dependencies:

```
@gnosis.pm/safe-core-sdk-types
Expand All @@ -36,14 +36,14 @@ First of all, we need to create an `EthAdapter`, which contains all the required

Depending on the library used by the Dapp, there are two options:

- [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)
- [Create an `EthersAdapter` instance](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-ethers-lib#initialization)
- [Create a `Web3Adapter` instance](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-web3-lib#initialization)

Once the instance of `EthersAdapter` or `Web3Adapter` is created, it can be used in the SDK initialization.

### 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 `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.
As stated in the introduction, the [Safe Service Client](https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-service-client) consumes the [Safe Transaction Service API](https://github.com/safe-global/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 SafeServiceClient from '@gnosis.pm/safe-service-client'
Expand All @@ -62,7 +62,7 @@ const safeFactory = await SafeFactory.create({ ethAdapter })
const safeSdk = await Safe.create({ ethAdapter, safeAddress })
```

There are two versions of the Safe contracts: [GnosisSafe.sol](https://github.com/gnosis/safe-contracts/blob/v1.3.0/contracts/GnosisSafe.sol) that does not trigger events in order to save gas and [GnosisSafeL2.sol](https://github.com/gnosis/safe-contracts/blob/v1.3.0/contracts/GnosisSafeL2.sol) that does, which is more appropriate for L2 networks.
There are two versions of the Safe contracts: [GnosisSafe.sol](https://github.com/safe-global/safe-contracts/blob/v1.3.0/contracts/GnosisSafe.sol) that does not trigger events in order to save gas and [GnosisSafeL2.sol](https://github.com/safe-global/safe-contracts/blob/v1.3.0/contracts/GnosisSafeL2.sol) that does, which is more appropriate for L2 networks.

By default `GnosisSafe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `GnosisSafeL2.sol` contract will be used unless you add the property `isL1SafeMasterCopy` to force the use of the `GnosisSafe.sol` contract.

Expand Down Expand Up @@ -115,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. 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.
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/safe-global/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 Expand Up @@ -191,19 +191,21 @@ const nonce = await safeService.getNextNonce(safeAddress)

Once we have the Safe transaction object we can share it with the other owners of the Safe so they can sign it. To send the transaction to the Safe Transaction Service we need to call the method `proposeTransaction` from the Safe Service Client instance and pass an object with the properties:
- `safeAddress`: The Safe address.
- `safeTransaction`: The Safe transaction object returned from the method `createTransaction`. Make sure that this object includes the signature of the owner which is proposing it.
- `safeTransactionData`: The `data` object inside the Safe transaction object returned from the method `createTransaction`.
- `safeTxHash`: The Safe transaction hash, calculated by calling the method `getTransactionHash` from the Safe Core SDK.
- `senderAddress`: The Safe owner proposing the transaction.
- `senderAddress`: The Safe owner or delegate proposing the transaction.
- `senderSignature`: The signature generated by signing the `safeTxHash` with the `senderAddress`.
- `origin`: Optional string that allows to provide more information about the app proposing the transaction.

```js
await safeSdk.signTransaction(safeTransaction)
const safeTxHash = await safeSdk.getTransactionHash(safeTransaction)
const senderSignature = await safeSdk.signTransactionHash(safeTxHash)
await safeService.proposeTransaction({
safeAddress,
safeTransaction,
safeTransactionData: safeTransaction.data,
safeTxHash,
senderAddress,
senderSignature: senderSignature.data,
origin
})
```
Expand Down
2 changes: 1 addition & 1 deletion packages/safe-core-sdk-types/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Safe Core SDK Types

Common types in the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk)
Common types in the [Safe Core SDK](https://github.com/safe-global/safe-core-sdk)
8 changes: 4 additions & 4 deletions packages/safe-core-sdk-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/gnosis/safe-core-sdk.git"
"url": "git+https://github.com/safe-global/safe-core-sdk.git"
},
"author": "Gnosis Safe (https://gnosis-safe.io)",
"license": "MIT",
"bugs": {
"url": "https://github.com/gnosis/safe-core-sdk/issues"
"url": "https://github.com/safe-global/safe-core-sdk/issues"
},
"files": [
"dist"
],
"homepage": "https://github.com/gnosis/safe-core-sdk#readme",
"homepage": "https://github.com/safe-global/safe-core-sdk#readme",
"devDependencies": {
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.17.0",
Expand All @@ -42,7 +42,7 @@
"dependencies": {
"@ethersproject/bignumber": "^5.6.0",
"@ethersproject/contracts": "^5.6.0",
"@gnosis.pm/safe-deployments": "^1.12.0",
"@gnosis.pm/safe-deployments": "1.12.0",
"web3-core": "^1.7.1"
}
}
6 changes: 5 additions & 1 deletion 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 { Eip3770Address, SafeVersion } from '../types'
import { Eip3770Address, SafeTransactionEIP712Args, SafeVersion } from '../types'

export interface EthAdapterTransaction {
to: string
Expand Down Expand Up @@ -54,6 +54,10 @@ export interface EthAdapter {
getTransaction(transactionHash: string): Promise<any>
getSignerAddress(): Promise<string>
signMessage(message: string): Promise<string>
signTypedData(
safeTransactionEIP712Args: SafeTransactionEIP712Args,
signTypedDataVersion?: string
): Promise<string>
estimateGas(
transaction: EthAdapterTransaction,
callback?: (error: Error, gas: number) => void
Expand Down
40 changes: 40 additions & 0 deletions packages/safe-core-sdk-types/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BigNumber } from '@ethersproject/bignumber'
import { ContractTransaction } from '@ethersproject/contracts'
import { PromiEvent, TransactionReceipt } from 'web3-core/types'

Expand Down Expand Up @@ -69,3 +70,42 @@ export interface Eip3770Address {
prefix: string
address: string
}

export interface SafeTransactionEIP712Args {
safeAddress: string
safeVersion: string
chainId: number
safeTransactionData: SafeTransactionData
}

export interface Eip712MessageTypes {
EIP712Domain: {
type: string
name: string
}[]
SafeTx: {
type: string
name: string
}[]
}

export interface GenerateTypedData {
types: Eip712MessageTypes
domain: {
chainId: number | undefined
verifyingContract: string
}
primaryType: string
message: {
to: string
value: BigNumber
data: string
operation: OperationType
safeTxGas: BigNumber
baseGas: BigNumber
gasPrice: BigNumber
gasToken: string
refundReceiver: string
nonce: BigNumber
}
}
6 changes: 3 additions & 3 deletions packages/safe-core-sdk-utils/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 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)
[![GitHub Release](https://img.shields.io/github/release/safe-global/safe-core-sdk.svg?style=flat)](https://github.com/safe-global/safe-core-sdk/releases)
[![GitHub](https://img.shields.io/github/license/safe-global/safe-core-sdk)](https://github.com/safe-global/safe-core-sdk/blob/main/LICENSE.md)

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

## Table of contents
* [Installation](#installation)
Expand Down
10 changes: 6 additions & 4 deletions packages/safe-core-sdk-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/gnosis/safe-core-sdk.git"
"url": "git+https://github.com/safe-global/safe-core-sdk.git"
},
"author": "Gnosis Safe (https://gnosis-safe.io)",
"license": "MIT",
"bugs": {
"url": "https://github.com/gnosis/safe-core-sdk/issues"
"url": "https://github.com/safe-global/safe-core-sdk/issues"
},
"files": [
"dist"
],
"homepage": "https://github.com/gnosis/safe-core-sdk#readme",
"homepage": "https://github.com/safe-global/safe-core-sdk#readme",
"devDependencies": {
"@gnosis.pm/safe-deployments": "^1.12.0",
"@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",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"chai": "^4.3.6",
Expand All @@ -52,6 +53,7 @@
},
"dependencies": {
"@gnosis.pm/safe-core-sdk-types": "^1.1.0",
"semver": "^7.3.7",
"web3-utils": "^1.7.1"
}
}
Loading

0 comments on commit 06d9505

Please sign in to comment.