Skip to content

Commit

Permalink
Merge pull request #221 from safe-global/development
Browse files Browse the repository at this point in the history
v2.2.1
  • Loading branch information
germartinez authored Jul 14, 2022
2 parents 3756318 + ad8697f commit 50dd9e3
Show file tree
Hide file tree
Showing 19 changed files with 527 additions and 56 deletions.
4 changes: 2 additions & 2 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.2.0",
"version": "1.2.1",
"description": "Safe Core SDK types",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -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.15.0",
"web3-core": "^1.7.1"
}
}
2 changes: 1 addition & 1 deletion packages/safe-core-sdk-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export interface Eip712MessageTypes {
export interface GenerateTypedData {
types: Eip712MessageTypes
domain: {
chainId: number | undefined
chainId?: number
verifyingContract: string
}
primaryType: string
Expand Down
6 changes: 3 additions & 3 deletions packages/safe-core-sdk-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/safe-core-sdk-utils",
"version": "1.2.0",
"version": "1.2.1",
"description": "Safe Core SDK Utilities",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -32,7 +32,7 @@
],
"homepage": "https://github.com/safe-global/safe-core-sdk#readme",
"devDependencies": {
"@gnosis.pm/safe-deployments": "1.12.0",
"@gnosis.pm/safe-deployments": "1.15.0",
"@types/chai": "^4.3.0",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^9.1.0",
Expand All @@ -52,7 +52,7 @@
"typescript": "^4.6.3"
},
"dependencies": {
"@gnosis.pm/safe-core-sdk-types": "^1.2.0",
"@gnosis.pm/safe-core-sdk-types": "^1.2.1",
"semver": "^7.3.7",
"web3-utils": "^1.7.1"
}
Expand Down
12 changes: 10 additions & 2 deletions packages/safe-core-sdk-utils/src/eip-3770/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const networks: NetworkShortName[] = [
{ chainId: 42, shortName: 'kov' },
{ chainId: 56, shortName: 'bnb' },
{ chainId: 69, shortName: 'okov' },
{ chainId: 82, shortName: 'meter' },
{ chainId: 83, shortName: 'meter-test' },
{ chainId: 100, shortName: 'gno' },
{ chainId: 106, shortName: 'vlx' },
{ chainId: 111, shortName: 'etl' },
Expand All @@ -24,14 +26,18 @@ export const networks: NetworkShortName[] = [
{ chainId: 137, shortName: 'matic' },
{ chainId: 246, shortName: 'ewt' },
{ chainId: 288, shortName: 'boba' },
{ chainId: 300, shortName: 'ogn' },
{ chainId: 588, shortName: 'metis-stardust' },
{ chainId: 1008, shortName: 'eun' },
{ chainId: 1088, shortName: 'metis-andromeda' },
{ chainId: 1284, shortName: 'mbeam' },
{ chainId: 1285, shortName: 'mriver' },
{ chainId: 1287, shortName: 'mbase' },
{ chainId: 1984, shortName: 'euntest' },
{ chainId: 4002, shortName: 'tftm' },
{ chainId: 7341, shortName: 'shyft' },
{ chainId: 9000, shortName: 'evmos' },
{ chainId: 9000, shortName: 'evmos-testnet' },
{ chainId: 9001, shortName: 'evmos' },
{ chainId: 11437, shortName: 'shyftt' },
{ chainId: 12357, shortName: 'rei-testnet' },
{ chainId: 42161, shortName: 'arb1' },
Expand All @@ -45,7 +51,9 @@ export const networks: NetworkShortName[] = [
{ chainId: 1313161554, shortName: 'aurora' },
{ chainId: 1313161555, shortName: 'aurora-testnet' },
{ chainId: 1666600000, shortName: 'hmy-s0' },
{ chainId: 1666700000, shortName: 'hmy-b-s0' }
{ chainId: 1666700000, shortName: 'hmy-b-s0' },
{ chainId: 11297108099, shortName: 'tpalm' },
{ chainId: 11297108109, shortName: 'palm' }
]

if (process.env.TEST_NETWORK === 'hardhat') {
Expand Down
10 changes: 6 additions & 4 deletions packages/safe-core-sdk-utils/src/eip-712/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import semverSatisfies from 'semver/functions/satisfies'

const EQ_OR_GT_1_3_0 = '>=1.3.0'

const EIP712_DOMAIN_BEFORE_V130 = [
export const EIP712_DOMAIN_BEFORE_V130 = [
{
type: 'address',
name: 'verifyingContract'
}
]

const EIP712_DOMAIN = [
export const EIP712_DOMAIN = [
{
type: 'uint256',
name: 'chainId'
Expand All @@ -23,7 +23,7 @@ const EIP712_DOMAIN = [
]

// This function returns the types structure for signing off-chain messages according to EIP-712
function getEip712MessageTypes(safeVersion: string): {
export function getEip712MessageTypes(safeVersion: string): {
EIP712Domain: typeof EIP712_DOMAIN | typeof EIP712_DOMAIN_BEFORE_V130
SafeTx: Array<{ type: string; name: string }>
} {
Expand Down Expand Up @@ -55,7 +55,6 @@ export function generateTypedData({
const typedData: GenerateTypedData = {
types: getEip712MessageTypes(safeVersion),
domain: {
chainId: eip712WithChainId ? chainId : undefined,
verifyingContract: safeAddress
},
primaryType: 'SafeTx',
Expand All @@ -68,5 +67,8 @@ export function generateTypedData({
nonce: BigNumber.from(safeTransactionData.nonce)
}
}
if (eip712WithChainId) {
typedData.domain.chainId = chainId
}
return typedData
}
61 changes: 61 additions & 0 deletions packages/safe-core-sdk-utils/tests/eip-712.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { SafeTransactionData } from '@gnosis.pm/safe-core-sdk-types'
import chai from 'chai'
import {
EIP712_DOMAIN,
EIP712_DOMAIN_BEFORE_V130,
generateTypedData,
getEip712MessageTypes
} from '../src'

const safeAddress = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1'
const safeTransactionData: SafeTransactionData = {
to: '0x000',
value: '111',
data: '0x222',
operation: 333,
safeTxGas: 444,
baseGas: 555,
gasPrice: 666,
gasToken: '0x777',
refundReceiver: '0x888',
nonce: 999
}

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 () => {
const { EIP712Domain } = getEip712MessageTypes('1.2.0')
chai.expect(EIP712Domain).to.be.eq(EIP712_DOMAIN_BEFORE_V130)
})

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

describe('generateTypedData', async () => {
it('should generate the typed data for Safes < v1.3.0', async () => {
const { domain } = generateTypedData({
safeAddress,
safeVersion: '1.2.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 for Safes >= v1.3.0', async () => {
const chainId = 4
const { domain } = generateTypedData({
safeAddress,
safeVersion: '1.3.0',
chainId,
safeTransactionData
})
chai.expect(domain.verifyingContract).to.be.eq(safeAddress)
chai.expect(domain.chainId).to.be.eq(chainId)
})
})
})
10 changes: 5 additions & 5 deletions packages/safe-core-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/safe-core-sdk",
"version": "2.2.0",
"version": "2.2.1",
"description": "Safe Core SDK",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -41,8 +41,8 @@
"devDependencies": {
"@gnosis.pm/safe-contracts-v1.2.0": "npm:@gnosis.pm/[email protected]",
"@gnosis.pm/safe-contracts-v1.3.0": "npm:@gnosis.pm/[email protected]",
"@gnosis.pm/safe-ethers-lib": "^1.2.0",
"@gnosis.pm/safe-web3-lib": "^1.2.0",
"@gnosis.pm/safe-ethers-lib": "^1.2.1",
"@gnosis.pm/safe-web3-lib": "^1.2.1",
"@nomiclabs/hardhat-ethers": "^2.0.5",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@nomiclabs/hardhat-web3": "^2.0.0",
Expand Down Expand Up @@ -89,8 +89,8 @@
},
"dependencies": {
"@ethersproject/solidity": "^5.6.0",
"@gnosis.pm/safe-core-sdk-types": "^1.2.0",
"@gnosis.pm/safe-deployments": "1.12.0",
"@gnosis.pm/safe-core-sdk-types": "^1.2.1",
"@gnosis.pm/safe-deployments": "1.15.0",
"ethereumjs-util": "^7.1.4",
"semver": "^7.3.5",
"web3-utils": "^1.7.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/safe-core-sdk/src/utils/signatures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ export async function generateEIP712Signature(
): Promise<EthSignSignature> {
const signerAddress = await ethAdapter.getSignerAddress()
let signature = await ethAdapter.signTypedData(safeTransactionEIP712Args, methodVersion)
signature = adjustVInSignature('eth_signTypedData', signature.replace('0x', ''))
signature = adjustVInSignature('eth_signTypedData', signature)
return new EthSignSignature(signerAddress, signature)
}
2 changes: 1 addition & 1 deletion packages/safe-ethers-adapters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"dependencies": {
"@gnosis.pm/safe-core-sdk": "^2.1.0",
"@gnosis.pm/safe-core-sdk-types": "^1.1.0",
"@gnosis.pm/safe-deployments": "1.12.0",
"@gnosis.pm/safe-deployments": "1.15.0",
"axios": "^0.26.1"
}
}
6 changes: 3 additions & 3 deletions packages/safe-ethers-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/safe-ethers-lib",
"version": "1.2.0",
"version": "1.2.1",
"description": "Ethers library adapter to be used by Safe Core SDK",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -50,8 +50,8 @@
"typescript": "^4.6.3"
},
"dependencies": {
"@gnosis.pm/safe-core-sdk-types": "^1.2.0",
"@gnosis.pm/safe-core-sdk-utils": "^1.2.0"
"@gnosis.pm/safe-core-sdk-types": "^1.2.1",
"@gnosis.pm/safe-core-sdk-utils": "^1.2.1"
},
"peerDependencies": {
"ethers": "^5.6.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/safe-ethers-lib/src/EthersAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class EthersAdapter implements EthAdapter {
async signTypedData(safeTransactionEIP712Args: SafeTransactionEIP712Args): Promise<string> {
if (isTypedDataSigner(this.#signer)) {
const typedData = generateTypedData(safeTransactionEIP712Args)
const signature = this.#signer._signTypedData(
const signature = await this.#signer._signTypedData(
typedData.domain,
{ SafeTx: typedData.types.SafeTx },
typedData.message
Expand Down
8 changes: 8 additions & 0 deletions packages/safe-service-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ Returns the list of Safes where the address provided is an owner.
const safes: OwnerResponse = await safeService.getSafesByOwner(ownerAddress)
```

### getSafesByModule

Returns the list of Safes where the module address provided is enabled.

```js
const safes: ModulesResponse = await getSafesByModule(moduleAddress)
```

### getTransaction

Returns all the information of a Safe transaction.
Expand Down
34 changes: 17 additions & 17 deletions packages/safe-service-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,31 @@
],
"homepage": "https://github.com/safe-global/safe-core-sdk#readme",
"devDependencies": {
"@gnosis.pm/safe-ethers-lib": "^1.2.0",
"@gnosis.pm/safe-web3-lib": "^1.2.0",
"@gnosis.pm/safe-ethers-lib": "^1.2.1",
"@gnosis.pm/safe-web3-lib": "^1.2.1",
"@nomiclabs/hardhat-ethers": "^2.0.5",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@types/chai": "^4.3.0",
"@types/chai": "^4.3.1",
"@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",
"@types/mocha": "^9.1.1",
"@types/node": "^18.0.3",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"eslint": "^8.12.0",
"eslint": "^8.19.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^4.2.1",
"hardhat": "^2.9.2",
"husky": "^7.0.4",
"lint-staged": "^12.3.7",
"mocha": "^9.2.2",
"prettier": "^2.6.2",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"mocha": "^10.0.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"ts-generator": "^0.1.1",
"ts-node": "^10.7.0",
"typescript": "^4.6.3"
"ts-node": "^10.8.2",
"typescript": "^4.7.4"
},
"lint-staged": {
"src/**/!(*test).ts": [
Expand All @@ -74,8 +74,8 @@
}
},
"dependencies": {
"@ethersproject/abstract-signer": "^5.6.0",
"@gnosis.pm/safe-core-sdk-types": "^1.2.0",
"@ethersproject/abstract-signer": "^5.6.2",
"@gnosis.pm/safe-core-sdk-types": "^1.2.1",
"node-fetch": "^2.6.6"
}
}
20 changes: 20 additions & 0 deletions packages/safe-service-client/src/SafeServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AllTransactionsListResponse,
AllTransactionsOptions,
MasterCopyResponse,
ModulesResponse,
OwnerResponse,
ProposeTransactionProps,
SafeBalanceResponse,
Expand Down Expand Up @@ -113,6 +114,25 @@ class SafeServiceClient implements SafeTransactionService {
})
}

/**
* Returns the list of Safes where the module address provided is enabled.
*
* @param moduleAddress - The Safe module address
* @returns The list of Safe addresses where the module provided is enabled
* @throws "Invalid module address"
* @throws "Module address checksum not valid"
*/
async getSafesByModule(moduleAddress: string): Promise<ModulesResponse> {
if (moduleAddress === '') {
throw new Error('Invalid module address')
}
const { address } = await this.#ethAdapter.getEip3770Address(moduleAddress)
return sendRequest({
url: `${this.#txServiceBaseUrl}/modules/${address}/safes/`,
method: HttpMethod.Get
})
}

/**
* Returns all the information of a Safe transaction.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,7 @@ export type AllTransactionsListResponse = {
| EthereumTxWithTransfersResponse
>
}

export type ModulesResponse = {
safes: string[]
}
Loading

0 comments on commit 50dd9e3

Please sign in to comment.