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

chore: prepare release #990

Merged
merged 16 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 2 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ Please describe concisely the bug you have found.
- Safe Core SDK versions:
<!-- Please leave empty or delete those that you don't use. -->
- api-kit:
- auth-kit:
- onramp-kit
- protocol-kit:
- relay-kit:
- safe-core-sdk-types:
- types-kit:
- sdk-starter-kit:
- Safe contract version:
- Environment:
- browser
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/sdk-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,5 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
files: packages/api-kit/coverage/lcov.info
packages/auth-kit/coverage/lcov.info
packages/onramp-kit/coverage/lcov.info
packages/relay-kit/coverage/lcov.info
packages/sdk-starter-kit/coverage/lcov.info
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ If you want to develop using Safe Smart Accounts in a Javascript/Typescript app,
| [protocol-kit](https://github.com/safe-global/safe-core-sdk/tree/main/packages/protocol-kit) | [![npm Version](https://badge.fury.io/js/%40safe-global%2Fprotocol-kit.svg)](https://badge.fury.io/js/%40safe-global%2Fprotocol-kit) | TypeScript library that facilitates the interaction with [Safe Smart Accounts](https://github.com/safe-global/safe-smart-account). Can be used to create new Safe accounts, update the configuration of existing Safes, create and execute transactions, among other features. |
| [api-kit](https://github.com/safe-global/safe-core-sdk/tree/main/packages/api-kit) | [![npm Version](https://badge.fury.io/js/%40safe-global%2Fapi-kit.svg)](https://badge.fury.io/js/%40safe-global%2Fapi-kit) | [Safe Transaction Service API](https://github.com/safe-global/safe-transaction-service) typescript library. Allows to propose and share transactions with the other signers of a Safe, sending the signatures to the service to collect them, and getting information about a Safe, among other features. |
| [relay-kit](https://github.com/safe-global/safe-core-sdk/tree/main/packages/relay-kit) | ​​​[​![npm Version](https://badge.fury.io/js/%40safe-global%2Frelay-kit.svg)​](https://badge.fury.io/js/%40safe-global%2Frelay-kit)​ | Typescript library that enables ERC-4337 with Safe and allows users to pay for the transaction fees from their Safe account balance using the blockchain native token or ERC-20 tokens, or to get their transactions sponsored. |
| [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/%40safe-global%2Fsafe-core-sdk-types.svg)](https://badge.fury.io/js/%40safe-global%2Fsafe-core-sdk-types) | Common types used in the [Safe Core SDK](https://github.com/safe-global/safe-core-sdk/tree/main/packages) packages. |
| [auth-kit](https://github.com/safe-global/safe-core-sdk/tree/main/packages/auth-kit) | [![npm Version](https://badge.fury.io/js/%40safe-global%2Fauth-kit.svg)](https://badge.fury.io/js/%40safe-global%2Fauth-kit) | Typescript library to create an Ethereum address and authenticating a blockchain account using an email address, social media account, or traditional crypto wallets like Metamask. |
| [onramp-kit](https://github.com/safe-global/safe-core-sdk/tree/main/packages/onramp-kit) | [![npm Version](https://badge.fury.io/js/%40safe-global%2Fonramp-kit.svg)](https://badge.fury.io/js/%40safe-global%2Fonramp-kit) | Typescript library that allows users to buy cryptocurrencies using a credit card and other payment options. |
| [types-kit](https://github.com/safe-global/safe-core-sdk/tree/main/packages/types-kit) | [![npm Version](https://badge.fury.io/js/%40safe-global%2Ftypes-kit.svg)](https://badge.fury.io/js/%40safe-global%2Ftypes-kit) | Common types used in the [Safe Core SDK](https://github.com/safe-global/safe-core-sdk/tree/main/packages) packages. |

## Guides

Expand Down
2 changes: 1 addition & 1 deletion guides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Read about the basics of Safe and [how it compares to other solutions](https://h
The [Safe Core SDK](https://github.com/safe-global/safe-core-sdk) is a monorepo that contains software developer tools that allows interaction with [Safe Smart Accounts](https://github.com/safe-global/safe-smart-account) and the [Safe Transaction Service API](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**
* **types-kit**

Contains the types that are shared among the different packages inside the monorepo.

Expand Down
79 changes: 57 additions & 22 deletions guides/integrating-the-safe-core-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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:

```
@safe-global/safe-core-sdk-types
@safe-global/types-kit
@safe-global/protocol-kit
@safe-global/api-kit
```
Expand Down Expand Up @@ -55,9 +55,7 @@ const apiKit = new SafeApiKit({
### Initialize the Protocol Kit

```js
import Safe, { SafeFactory } from '@safe-global/protocol-kit'

const safeFactory = await SafeFactory.init({ provider, signer })
import Safe from '@safe-global/protocol-kit'

const protocolKit = await Safe.init({ provider, signer, safeAddress })
```
Expand All @@ -67,7 +65,6 @@ There are two versions of the Safe contracts: [Safe.sol](https://github.com/safe
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the property `isL1SafeSingleton` to force the use of the `Safe.sol` contract.

```js
const safeFactory = await SafeFactory.init({ provider, signer, isL1SafeSingleton: true })

const protocolKit = await Safe.init({ provider, signer, safeAddress, isL1SafeSingleton: true })
```
Expand Down Expand Up @@ -102,36 +99,74 @@ const contractNetworks: ContractNetworksConfig = {
}
}

const safeFactory = await SafeFactory.init({ provider, signer, contractNetworks })

const protocolKit = await Safe.init({ provider, signer, safeAddress, contractNetworks })
```

The `SafeFactory` constructor also accepts the property `safeVersion` to specify the Safe contract version that will be deployed. This string can take the values `1.0.0`, `1.1.1`, `1.2.0`, `1.3.0` or `1.4.1`. If not specified, the `DEFAULT_SAFE_VERSION` value will be used.

```js
const safeVersion = 'X.Y.Z'
const safeFactory = await SafeFactory.init({ provider, signer, safeVersion })
```

## <a name="deploy-safe">3. Deploy a new Safe</a>

The Protocol Kit library allows the deployment of new Safes using the `safeFactory` instance we just created.
The Protocol Kit library now simplifies the creation of new Safes by providing the `createSafeDeploymentTransaction` method. This method returns an Ethereum transaction object ready for execution, which includes the deployment of a Safe.

Here, for example, we can create a new Safe account with 3 owners and 2 required signatures.
Here is an example of how to create a new Safe account with 3 owners and 2 required signatures:

```js
import { SafeAccountConfig } from '@safe-global/protocol-kit'

const safeAccountConfig: SafeAccountConfig = {
owners: ['0x...', '0x...', '0x...']
threshold: 2,
// ... (optional params)
owners: ['0x...', '0x...', '0x...'],
threshold: 2
// Additional optional parameters can be included here
}
const protocolKit = await safeFactory.deploySafe({ safeAccountConfig })

const predictSafe = {
safeAccountConfig,
safeDeploymentConfig: {
saltNonce, // optional parameter
safeVersion // optional parameter
}
}

const protocolKit = await Safe.init({ provider, signer, predictSafe })

const deploymentTransaction = await protocolKit.createSafeDeploymentTransaction()

// Execute this transaction using the Ethereum client of your choice
const txHash = await client.sendTransaction({
to: deploymentTransaction.to,
value: BigInt(deploymentTransaction.value),
data: `0x${deploymentTransaction.data}`
})

```

Calling the method `deploySafe` will deploy the desired Safe and return a Protocol Kit initialized instance ready to be used. Check the [API Reference](https://github.com/safe-global/safe-core-sdk/tree/main/packages/protocol-kit#deploysafe) for more details on additional configuration parameters and callbacks.
Once you obtain the `deploymentTransaction` object, you will have an Ethereum transaction object containing the `to`, `value`, and `data` fields. You can execute this transaction using the Ethereum client of your choice. Check the [API Reference](https://github.com/safe-global/safe-core-sdk/tree/main/packages/protocol-kit#deploysafe) for more details on additional configuration parameters.

After successfully executing the transaction and confirming that the Safe has been deployed, you will need to reconnect to the new Safe address. Use the `connect` method to reinitialize the protocol-kit instance with the deployed Safe address:

```js
// Execute this transaction using the Ethereum client of your choice
const txHash = await client.sendTransaction({
to: deploymentTransaction.to,
value: BigInt(deploymentTransaction.value),
data: `0x${deploymentTransaction.data}`
})

console.log('Transaction hash:', txHash)

const txReceipt = await waitForTransactionReceipt(client, { hash: txHash })

// Extract the Safe address from the deployment transaction receipt
const safeAddress = getSafeAddressFromDeploymentTx(txReceipt, safeVersion)

console.log('safeAddress:', safeAddress)

// Reinitialize the instance of protocol-kit using the obtained Safe address
protocolKit.connect({ safeAddress })

console.log('is Safe deployed:', await protocolKit.isSafeDeployed())
console.log('Safe Address:', await protocolKit.getAddress())
console.log('Safe Owners:', await protocolKit.getOwners())
console.log('Safe Threshold:', await protocolKit.getThreshold())
```

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

Expand All @@ -143,7 +178,7 @@ When the array contains only one transaction, it is not wrapped in the MultiSend

```js
import { SafeTransactionOptionalProps } from '@safe-global/protocol-kit'
import { MetaTransactionData } from '@safe-global/safe-core-sdk-types'
import { MetaTransactionData } from '@safe-global/types-kit'

const transactions: MetaTransactionData[] = [
{
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
"author": "Safe (https://safe.global)",
"license": "MIT",
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/jest": "^29.5.13",
"@types/node": "^20.14.5",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"eslint-plugin-prettier": "^5.2.1",
"husky": "^9.1.6",
"jest": "^29.7.0",
"lerna": "^8.1.3",
"lint-staged": "^15.2.7",
"prettier": "^3.3.2",
"lerna": "^8.1.8",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
Expand Down
2 changes: 0 additions & 2 deletions packages/api-kit/.env.example

This file was deleted.

52 changes: 0 additions & 52 deletions packages/api-kit/hardhat.config.ts

This file was deleted.

41 changes: 20 additions & 21 deletions packages/api-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safe-global/api-kit",
"version": "2.4.6",
"version": "2.5.0",
"description": "SDK that facilitates the interaction with the Safe Transaction Service API",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand All @@ -12,14 +12,14 @@
"API"
],
"scripts": {
"test:web3": "export TESTS_PATH=tests/endpoint && export ETH_LIB=web3 && nyc hardhat test",
"test:ethers": "export TESTS_PATH=tests/endpoint && export ETH_LIB=ethers && nyc --reporter=lcov hardhat test",
"test:viem": "export TESTS_PATH=tests/endpoint && export ETH_LIB=viem && nyc hardhat test",
"test": "yarn test:ethers",
"test:ci:web3": "export TESTS_PATH=tests/e2e && export ETH_LIB=web3 && nyc hardhat test",
"test:ci:ethers": "export TESTS_PATH=tests/e2e && export ETH_LIB=ethers && nyc --reporter=lcov hardhat test",
"test:ci:viem": "export TESTS_PATH=tests/e2e && export ETH_LIB=viem && nyc --reporter=lcov hardhat test",
"test:ci": "yarn test:ci:ethers",
"test:web3": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=web3 && nyc --reporter=lcov testing-kit test 'tests/endpoint/*.test.*'",
"test:ethers": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=ethers && nyc --reporter=lcov testing-kit test 'tests/endpoint/*.test.*'",
"test:viem": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=viem && nyc --reporter=lcov testing-kit test 'tests/endpoint/*.test.*'",
"test": "yarn test:viem",
"test:ci:web3": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=web3 && nyc --reporter=lcov testing-kit test 'tests/e2e/*.test.*'",
"test:ci:ethers": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=ethers && nyc --reporter=lcov testing-kit test 'tests/e2e/*.test.*'",
"test:ci:viem": "export HARDHAT_NETWORK=sepolia && export ETH_LIB=viem && nyc --reporter=lcov testing-kit test 'tests/e2e/*.test.*'",
"test:ci": "yarn test:ci:viem",
"format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"",
"format": "prettier --write \"*/**/*.{js,json,md,ts}\"",
"unbuild": "rimraf dist .nyc_output cache",
Expand All @@ -39,29 +39,28 @@
],
"homepage": "https://github.com/safe-global/safe-core-sdk#readme",
"devDependencies": {
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@types/chai": "^4.3.16",
"@safe-global/relay-kit": "^3.2.0",
"@safe-global/testing-kit": "^0.1.0",
"@types/chai": "^4.3.19",
"@types/chai-as-promised": "^7.1.8",
"@types/mocha": "^10.0.6",
"@types/mocha": "^10.0.8",
"@types/node-fetch": "^2.6.11",
"@types/sinon-chai": "^3.2.11",
"@types/yargs": "^17.0.32",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"hardhat": "2.20.1",
"ethers": "^6.13.2",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"semver": "^7.6.1",
"sinon": "^14.0.2",
"sinon-chai": "^3.7.0",
"tsconfig-paths": "^4.2.0",
"viem": "^2.15.1",
"web3": "^4.7.0",
"yargs": "^17.7.2"
"web3": "^4.12.1"
},
"dependencies": {
"@safe-global/protocol-kit": "^4.1.1",
"@safe-global/safe-core-sdk-types": "^5.1.0",
"ethers": "^6.13.1",
"node-fetch": "^2.7.0"
"@safe-global/protocol-kit": "^5.0.0",
"@safe-global/types-kit": "^1.0.0",
"node-fetch": "^2.7.0",
"viem": "^2.21.8"
}
}
2 changes: 1 addition & 1 deletion packages/api-kit/src/SafeApiKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
SafeOperation,
SafeOperationConfirmationListResponse,
SafeOperationResponse
} from '@safe-global/safe-core-sdk-types'
} from '@safe-global/types-kit'
import { TRANSACTION_SERVICE_URLS } from './utils/config'
import { isEmptyData } from './utils'
import { getAddSafeOperationProps } from './utils/safeOperation'
Expand Down Expand Up @@ -120,7 +120,7 @@
* @throws "Not Found"
* @throws "Ensure this field has at least 1 hexadecimal chars (not counting 0x)."
*/
async decodeData(data: string): Promise<any> {

Check warning on line 123 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
if (data === '') {
throw new Error('Invalid data')
}
Expand Down Expand Up @@ -330,7 +330,7 @@
const { address: delegator } = this.#getEip3770Address(delegatorAddress)
const signature = await signDelegate(signer, delegate, this.#chainId)

const body: any = {

Check warning on line 333 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
safe: safeAddress ? this.#getEip3770Address(safeAddress).address : null,
delegate,
delegator,
Expand Down
6 changes: 6 additions & 0 deletions packages/api-kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ import SafeApiKit, { SafeApiKitConfig } from './SafeApiKit'
export * from './types/safeTransactionServiceTypes'
export { SafeApiKitConfig }
export default SafeApiKit

declare module 'abitype' {
export interface Register {
AddressType: string
}
}
13 changes: 7 additions & 6 deletions packages/api-kit/src/types/safeTransactionServiceTypes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Signer, TypedDataDomain, TypedDataField } from 'ethers'
import { Account, Chain, Transport, TypedDataDomain, TypedDataParameter, WalletClient } from 'viem'
import {
SafeMultisigTransactionResponse,
SafeTransactionData,
UserOperation,
SafeOperationResponse,
ListResponse
} from '@safe-global/safe-core-sdk-types'
} from '@safe-global/types-kit'

export type ListOptions = {
/** Maximum number of results to return per page */
Expand Down Expand Up @@ -77,14 +77,14 @@ export type AddSafeDelegateProps = {
safeAddress?: string
delegateAddress: string
delegatorAddress: string
signer: Signer
signer: WalletClient<Transport, Chain, Account>
label: string
}

export type DeleteSafeDelegateProps = {
delegateAddress: string
delegatorAddress: string
signer: Signer
signer: WalletClient<Transport, Chain, Account>
}

export type SafeDelegateResponse = {
Expand Down Expand Up @@ -248,19 +248,20 @@ export type AddMessageProps = {
}

export type GetSafeMessageListProps = {
/** Which field to use when ordering the results. It can be: `created`, `modified` (default: `-created`) */
ordering?: string
} & ListOptions

export type EIP712TypedData = {
domain: TypedDataDomain
types: TypedDataField
types: TypedDataParameter
message: Record<string, unknown>
}

export type GetSafeOperationListProps = {
/** Address of the Safe to get SafeOperations for */
safeAddress: string
/** Which field to use when ordering the results */
/** Which field to use when ordering the results. It can be: `user_operation__nonce`, `created` (default: `-user_operation__nonce`) */
ordering?: string
} & ListOptions

Expand Down
Loading
Loading