Skip to content

Commit

Permalink
Merge pull request safe-global#285 from safe-global/safe-v1.0.0-compa…
Browse files Browse the repository at this point in the history
…tibility

Safe v1.0.0 and v1.1.1 compatibility
  • Loading branch information
germartinez authored Jan 23, 2023
2 parents c05f20d + 089c9bd commit 40061de
Show file tree
Hide file tree
Showing 107 changed files with 4,850 additions and 995 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/test_ethers_V1_0_0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Safe Core SDK Test - Ethers - Safe v1.0.0
on:
pull_request:
push:
branches:
- main
- development
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: |
yarn install
yarn build
cd packages/safe-core-sdk
yarn test:hardhat:ethers:v1.0.0
26 changes: 26 additions & 0 deletions .github/workflows/test_ethers_V1_1_1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Safe Core SDK Test - Ethers - Safe v1.1.1
on:
pull_request:
push:
branches:
- main
- development
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: |
yarn install
yarn build
cd packages/safe-core-sdk
yarn test:hardhat:ethers:v1.1.1
26 changes: 26 additions & 0 deletions .github/workflows/test_web3_V1_0_0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Safe Core SDK Test - Web3 - Safe v1.0.0
on:
pull_request:
push:
branches:
- main
- development
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: |
yarn install
yarn build
cd packages/safe-core-sdk
yarn test:hardhat:web3:v1.0.0
26 changes: 26 additions & 0 deletions .github/workflows/test_web3_V1_1_1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Safe Core SDK Test - Web3 - Safe v1.1.1
on:
pull_request:
push:
branches:
- main
- development
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: |
yarn install
yarn build
cd packages/safe-core-sdk
yarn test:hardhat:web3:v1.1.1
2 changes: 1 addition & 1 deletion guides/integrating-the-safe-core-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const safeFactory = await SafeFactory.create({ ethAdapter, contractNetworks })
const safeSdk = await Safe.create({ ethAdapter, safeAddress, contractNetworks })
```

The `SafeFactory` constructor also accepts the property `safeVersion` to specify the Safe contract version that will deploy. This string can take the values `1.1.1`, `1.2.0` or `1.3.0`. If not specified, the most recent contract version will be used by default.
The `SafeFactory` constructor also accepts the property `safeVersion` to specify the Safe contract version that will deploy. This string can take the values `1.0.0`, `1.1.1`, `1.2.0` or `1.3.0`. If not specified, the most recent contract version will be used by default.

```js
const safeVersion = 'X.Y.Z'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"author": "Safe (https://safe.global)",
"license": "MIT",
"devDependencies": {
"lerna": "^6.0.3",
"lerna": "^6.4.1",
"rimraf": "^3.0.2",
"ts-node": "^10.9.1"
}
Expand Down
18 changes: 9 additions & 9 deletions packages/safe-core-sdk-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safe-global/safe-core-sdk-types",
"version": "1.8.0",
"version": "1.9.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/safe-global/safe-core-sdk#readme",
"devDependencies": {
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.0",
"typescript": "^4.9.3"
"prettier": "^2.8.3",
"typescript": "^4.9.4"
},
"dependencies": {
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@gnosis.pm/safe-deployments": "1.17.0",
"@gnosis.pm/safe-deployments": "1.19.0",
"web3-core": "^1.8.1",
"web3-utils": "^1.8.1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {
SafeTransaction,
SafeTransactionData,
SafeVersion,
SafeSetupConfig,
TransactionOptions,
TransactionResult
} from '../types'

export interface GnosisSafeContract {
setup(setupConfig: SafeSetupConfig, options?: TransactionOptions): Promise<TransactionResult>
getVersion(): Promise<SafeVersion>
getAddress(): string
getNonce(): Promise<number>
Expand Down
23 changes: 17 additions & 6 deletions packages/safe-core-sdk-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ import { BigNumber } from '@ethersproject/bignumber'
import { ContractTransaction } from '@ethersproject/contracts'
import { PromiEvent, TransactionReceipt } from 'web3-core/types'

export type SafeVersion = '1.3.0' | '1.2.0' | '1.1.1'
export type SafeVersion = '1.3.0' | '1.2.0' | '1.1.1' | '1.0.0'

export enum OperationType {
Call, // 0
DelegateCall // 1
}

export interface SafeSetupConfig {
owners: string[]
threshold: number
to?: string
data?: string
fallbackHandler?: string
paymentToken?: string
payment?: string
paymentReceiver?: string
}

export interface MetaTransactionData {
readonly to: string
readonly value: string
Expand Down Expand Up @@ -101,15 +112,15 @@ export interface GenerateTypedData {
primaryType: string
message: {
to: string
value: BigNumber
value: string
data: string
operation: OperationType
safeTxGas: BigNumber
baseGas: BigNumber
gasPrice: BigNumber
safeTxGas: number
baseGas: number
gasPrice: number
gasToken: string
refundReceiver: string
nonce: BigNumber
nonce: number
}
}

Expand Down
22 changes: 11 additions & 11 deletions packages/safe-core-sdk-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safe-global/safe-core-sdk-utils",
"version": "1.6.0",
"version": "1.7.0",
"description": "Safe Core SDK Utilities",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -32,26 +32,26 @@
],
"homepage": "https://github.com/safe-global/safe-core-sdk#readme",
"devDependencies": {
"@gnosis.pm/safe-deployments": "1.17.0",
"@gnosis.pm/safe-deployments": "1.19.0",
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^10.0.1",
"@types/node": "^18.11.9",
"@types/node": "^18.11.18",
"@types/semver": "^7.3.13",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"mocha": "^10.1.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "^2.8.0",
"typescript": "^4.9.3"
"prettier": "^2.8.3",
"typescript": "^4.9.4"
},
"dependencies": {
"@safe-global/safe-core-sdk-types": "^1.8.0",
"@safe-global/safe-core-sdk-types": "^1.9.0",
"semver": "^7.3.8",
"web3-utils": "^1.8.1"
}
Expand Down
9 changes: 9 additions & 0 deletions packages/safe-core-sdk-utils/src/eip-3770/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const networks: NetworkShortName[] = [
{ chainId: 40, shortName: 'telosevm' },
{ chainId: 41, shortName: 'telosevmtestnet' },
{ chainId: 42, shortName: 'kov' },
{ chainId: 50, shortName: 'xdc' },
{ chainId: 51, shortName: 'txdc' },
{ chainId: 56, shortName: 'bnb' },
{ chainId: 61, shortName: 'etc' },
{ chainId: 63, shortName: 'metc' },
Expand All @@ -42,6 +44,7 @@ export const networks: NetworkShortName[] = [
{ chainId: 588, shortName: 'metis-stardust' },
{ chainId: 592, shortName: 'astr' },
{ chainId: 595, shortName: 'maca' },
{ chainId: 599, shortName: 'metis-goerli' },
{ chainId: 686, shortName: 'kar' },
{ chainId: 787, shortName: 'aca' },
{ chainId: 1001, shortName: 'baobab' },
Expand Down Expand Up @@ -70,15 +73,21 @@ export const networks: NetworkShortName[] = [
{ chainId: 9001, shortName: 'evmos' },
{ chainId: 10000, shortName: 'smartbch' },
{ chainId: 10001, shortName: 'smartbchtest' },
{ chainId: 10200, shortName: 'chi' },
{ chainId: 11235, shortName: 'islm' },
{ chainId: 11437, shortName: 'shyftt' },
{ chainId: 12357, shortName: 'rei-testnet' },
{ chainId: 42161, shortName: 'arb1' },
{ chainId: 42170, shortName: 'arb-nova' },
{ chainId: 42220, shortName: 'celo' },
{ chainId: 43113, shortName: 'fuji' },
{ chainId: 43114, shortName: 'avax' },
{ chainId: 44787, shortName: 'alfa' },
{ chainId: 45000, shortName: 'autobahnnetwork' },
{ chainId: 47805, shortName: 'rei' },
{ chainId: 54211, shortName: 'islmt' },
{ chainId: 71401, shortName: 'gw-testnet-v1' },
{ chainId: 71402, shortName: 'gw-mainnet-v1' },
{ chainId: 73799, shortName: 'vt' },
{ chainId: 80001, shortName: 'maticmum' },
{ chainId: 200101, shortName: 'milktada' },
Expand Down
11 changes: 5 additions & 6 deletions packages/safe-core-sdk-utils/src/eip-712/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from '@ethersproject/bignumber'
import { GenerateTypedData, SafeTransactionEIP712Args } from '@safe-global/safe-core-sdk-types'
import semverSatisfies from 'semver/functions/satisfies'

Expand Down Expand Up @@ -60,11 +59,11 @@ export function generateTypedData({
primaryType: 'SafeTx',
message: {
...safeTransactionData,
value: BigNumber.from(safeTransactionData.value),
safeTxGas: BigNumber.from(safeTransactionData.safeTxGas),
baseGas: BigNumber.from(safeTransactionData.baseGas),
gasPrice: BigNumber.from(safeTransactionData.gasPrice),
nonce: BigNumber.from(safeTransactionData.nonce)
value: safeTransactionData.value,
safeTxGas: safeTransactionData.safeTxGas,
baseGas: safeTransactionData.baseGas,
gasPrice: safeTransactionData.gasPrice,
nonce: safeTransactionData.nonce
}
}
if (eip712WithChainId) {
Expand Down
36 changes: 34 additions & 2 deletions packages/safe-core-sdk-utils/tests/eip-712.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ const safeTransactionData: SafeTransactionData = {

describe('EIP-712 sign typed data', () => {
describe('getEip712MessageTypes', async () => {
it('should have the domain typed as EIP712_DOMAIN_BEFORE_V130 for Safes < v1.3.0', async () => {
it('should have the domain typed as EIP712_DOMAIN_BEFORE_V130 for Safes == v1.0.0', async () => {
const { EIP712Domain } = getEip712MessageTypes('1.0.0')
chai.expect(EIP712Domain).to.be.eq(EIP712_DOMAIN_BEFORE_V130)
})

it('should have the domain typed as EIP712_DOMAIN_BEFORE_V130 for Safes == v1.1.1', async () => {
const { EIP712Domain } = getEip712MessageTypes('1.1.1')
chai.expect(EIP712Domain).to.be.eq(EIP712_DOMAIN_BEFORE_V130)
})

it('should have the domain typed as EIP712_DOMAIN_BEFORE_V130 for Safes == v1.2.0', async () => {
const { EIP712Domain } = getEip712MessageTypes('1.2.0')
chai.expect(EIP712Domain).to.be.eq(EIP712_DOMAIN_BEFORE_V130)
})
Expand All @@ -35,7 +45,29 @@ describe('EIP-712 sign typed data', () => {
})

describe('generateTypedData', async () => {
it('should generate the typed data for Safes < v1.3.0', async () => {
it('should generate the typed data for Safes == v1.0.0', async () => {
const { domain } = generateTypedData({
safeAddress,
safeVersion: '1.0.0',
chainId: 4,
safeTransactionData
})
chai.expect(domain.verifyingContract).to.be.eq(safeAddress)
chai.expect(domain.chainId).to.be.undefined
})

it('should generate the typed data for Safes == v1.1.1', async () => {
const { domain } = generateTypedData({
safeAddress,
safeVersion: '1.1.1',
chainId: 4,
safeTransactionData
})
chai.expect(domain.verifyingContract).to.be.eq(safeAddress)
chai.expect(domain.chainId).to.be.undefined
})

it('should generate the typed data for Safes == v1.2.0', async () => {
const { domain } = generateTypedData({
safeAddress,
safeVersion: '1.2.0',
Expand Down
Loading

0 comments on commit 40061de

Please sign in to comment.