Skip to content

Commit

Permalink
Merge pull request #235 from safe-global/development
Browse files Browse the repository at this point in the history
v2.4.0
  • Loading branch information
germartinez authored Aug 2, 2022
2 parents 57f7a0a + 46fb375 commit ea3181e
Show file tree
Hide file tree
Showing 35 changed files with 297 additions and 174 deletions.
2 changes: 2 additions & 0 deletions packages/safe-core-sdk-types/src/ethereumLibs/EthAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface EthAdapterTransaction {
value?: string
gasPrice?: number
gasLimit?: number
maxFeePerGas?: number | string
maxPriorityFeePerGas?: number | string
}

export interface GetContractProps {
Expand Down
2 changes: 2 additions & 0 deletions packages/safe-core-sdk-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export interface TransactionOptions {
gas?: number | string
gasLimit?: number | string
gasPrice?: number | string
maxFeePerGas?: number | string
maxPriorityFeePerGas?: number | string
}

export interface BaseTransactionResult {
Expand Down
6 changes: 3 additions & 3 deletions packages/safe-core-sdk-utils/tests/eip-3770.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ describe('EIP-3770 chain-specific addresses', () => {
})

it('should return false if prefix is invalid', async () => {
const prefix = 'RIN'
const prefix = 'GOR'
chai.expect(isValidEip3770NetworkPrefix(prefix)).to.be.false
})

it('should return true if prefix is valid', async () => {
const prefix = 'rin'
const prefix = 'gor'
chai.expect(isValidEip3770NetworkPrefix(prefix)).to.be.true
})
})
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('EIP-3770 chain-specific addresses', () => {

it('should fail validating a full address with address and prefix of different chainId', async () => {
const testChainId = 100
const testPrefix = 'rin'
const testPrefix = 'gor'
const testAddress = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1'
chai
.expect(() => validateEip3770Address(`${testPrefix}:${testAddress}`, testChainId))
Expand Down
38 changes: 25 additions & 13 deletions packages/safe-core-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ Before executing this transaction, it must be signed by the owners and this can
The `owner1` account signs the transaction off-chain.

```js
const owner1Signature = await safeSdk.signTransaction(safeTransaction)
const signedSafeTransaction = await safeSdk.signTransaction(safeTransaction)
```

Because the signature is off-chain, there is no interaction with the contract and the signature becomes available at `safeTransaction.signatures`.
Because the signature is off-chain, there is no interaction with the contract and the signature becomes available at `signedSafeTransaction.signatures`.

### 3.b. On-chain signatures

Expand Down Expand Up @@ -231,14 +231,18 @@ Optionally, some properties can be passed as execution options:
const options: Web3TransactionOptions = {
from, // Optional
gas, // Optional
gasPrice // Optional
gasPrice, // Optional
maxFeePerGas, // Optional
maxPriorityFeePerGas // Optional
}
```
```js
const options: EthersTransactionOptions = {
from, // Optional
gasLimit, // Optional
gasPrice // Optional
gasPrice, // Optional
maxFeePerGas, // Optional
maxPriorityFeePerGas // Optional
}
```
```js
Expand Down Expand Up @@ -550,24 +554,24 @@ const signature = await safeSdk.signTypedData(safeTransaction)
### signTransaction
Adds the signature of the current owner to the Safe transaction object. `eth_sign` will be used by default to generate the signature.
Returns a new `SafeTransaction` object that includes the signature of the current owner. `eth_sign` will be used by default to generate the signature.
```js
const transaction: SafeTransactionDataPartial = {
// ...
}
const safeTransaction = await safeSdk.createTransaction(transaction)
await safeSdk.signTransaction(safeTransaction)
const safeTransaction = await safeSdk.createTransaction(transaction)
const signedSafeTransaction = await safeSdk.signTransaction(safeTransaction)
```
Optionally, an additional parameter can be passed to specify a different way of signing:
```js
await safeSdk.signTransaction(safeTransaction, 'eth_signTypedData')
const signedSafeTransaction = await safeSdk.signTransaction(safeTransaction, 'eth_signTypedData')
```
```js
await safeSdk.signTransaction(safeTransaction, 'eth_sign') // default option.
const signedSafeTransaction = await safeSdk.signTransaction(safeTransaction, 'eth_sign') // default option.
```
### approveTransactionHash
Expand All @@ -590,14 +594,18 @@ Optionally, some properties can be passed as execution options:
const options: Web3TransactionOptions = {
from, // Optional
gas, // Optional
gasPrice // Optional
gasPrice, // Optional
maxFeePerGas, // Optional
maxPriorityFeePerGas // Optional
}
```
```js
const options: EthersTransactionOptions = {
from, // Optional
gasLimit, // Optional
gasPrice // Optional
gasPrice, // Optional
maxFeePerGas, // Optional
maxPriorityFeePerGas // Optional
}
```
```js
Expand Down Expand Up @@ -757,14 +765,18 @@ Optionally, some properties can be passed as execution options:
const options: Web3TransactionOptions = {
from, // Optional
gas, // Optional
gasPrice // Optional
gasPrice, // Optional
maxFeePerGas, // Optional
maxPriorityFeePerGas // Optional
}
```
```js
const options: EthersTransactionOptions = {
from, // Optional
gasLimit, // Optional
gasPrice // Optional
gasPrice, // Optional
maxFeePerGas, // Optional
maxPriorityFeePerGas // Optional
}
```
```js
Expand Down
6 changes: 3 additions & 3 deletions packages/safe-core-sdk/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (PK) {
}
}

if (['rinkeby'].includes(argv.network) && INFURA_KEY === undefined) {
if (['goerli'].includes(argv.network) && INFURA_KEY === undefined) {
throw new Error(
`Could not find Infura key in env, unable to connect to network ${argv.network}`,
)
Expand Down Expand Up @@ -70,9 +70,9 @@ const config: HardhatUserConfig = {
{ balance: '100000000000000000000', privateKey: '0xb0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773' },
]
},
rinkeby: {
goerli: {
...sharedNetworkConfig,
url: `https://rinkeby.infura.io/v3/${INFURA_KEY}`,
url: `https://goerli.infura.io/v3/${INFURA_KEY}`,
}
},
namedAccounts: {
Expand Down
1 change: 1 addition & 0 deletions packages/safe-core-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"scripts": {
"unbuild": "rimraf dist artifacts deployments cache .nyc_output",
"build": "hardhat compile && tsc",
"postinstall": "ts-node scripts/postinstall.ts",
"test:ganache:web3:v1.2.0": "export TEST_NETWORK=ganache && export ETH_LIB=web3 && export SAFE_VERSION=1.2.0 && hardhat --network localhost deploy && nyc hardhat --network localhost test",
"test:ganache:web3:v1.3.0": "export TEST_NETWORK=ganache && export ETH_LIB=web3 && export SAFE_VERSION=1.3.0 && hardhat --network localhost deploy && nyc hardhat --network localhost test",
"test:ganache:ethers:v1.2.0": "export TEST_NETWORK=ganache && export ETH_LIB=ethers && export SAFE_VERSION=1.2.0 && hardhat --network localhost deploy && nyc hardhat --network localhost test",
Expand Down
7 changes: 7 additions & 0 deletions packages/safe-core-sdk/scripts/postinstall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function postInstall() {
console.warn(
`⚠️ the "signTransaction" method now returns a signed Safe transaction. Please update your code according to the new documentation: https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-core-sdk#signtransaction. In >=v3.0.0, the signature will be added only to the return transaction object, and not to the one passed as an argument.`
)
}

postInstall()
21 changes: 18 additions & 3 deletions packages/safe-core-sdk/src/Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,14 @@ class Safe {
* Adds the signature of the current signer to the Safe transaction object.
*
* @param safeTransaction - The Safe transaction to be signed
* @param signingMethod - Method followed to sign a transaction. Optional. Default value is eth_sign
* @param signingMethod - Method followed to sign a transaction. Optional. Default value is "eth_sign"
* @returns The signed Safe transaction
* @throws "Transactions can only be signed by Safe owners"
*/
async signTransaction(
safeTransaction: SafeTransaction,
signingMethod: 'eth_sign' | 'eth_signTypedData' = 'eth_sign'
): Promise<void> {
): Promise<SafeTransaction> {
const owners = await this.getOwners()
const signerAddress = await this.#ethAdapter.getSignerAddress()
const addressIsOwner = owners.find(
Expand All @@ -388,13 +389,27 @@ class Safe {
const txHash = await this.getTransactionHash(safeTransaction)
signature = await this.signTransactionHash(txHash)
}
const signedSafeTransaction = await this.createTransaction(safeTransaction.data)
safeTransaction.signatures.forEach((signature) => {
signedSafeTransaction.addSignature(signature)
})
signedSafeTransaction.addSignature(signature)

// TO-DO: Remove in v3.0.0 {
console.warn(
`⚠️ the "signTransaction" method now returns a signed Safe transaction. Please update your code according to the new documentation: https://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-core-sdk#signtransaction. In >=v3.0.0, the signature will be added only to the return transaction object, and not to the one passed as an argument.`
)
safeTransaction.addSignature(signature)
// }

return signedSafeTransaction
}

/**
* Approves on-chain a hash using the current signer account.
*
* @param hash - The hash to approve
* @param options - The Safe transaction execution options. Optional
* @returns The Safe transaction response
* @throws "Transaction hashes can only be approved by Safe owners"
* @throws "Cannot specify gas and gasLimit together in transaction options"
Expand Down Expand Up @@ -580,7 +595,7 @@ class Safe {
* Executes a Safe transaction.
*
* @param safeTransaction - The Safe transaction to execute
* @param options - The Safe transaction execution options (gasLimit, gasPrice)
* @param options - The Safe transaction execution options. Optional
* @returns The Safe transaction response
* @throws "No signer provided"
* @throws "There are X signatures missing"
Expand Down
6 changes: 3 additions & 3 deletions packages/safe-core-sdk/src/safeFactory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ class SafeFactory {

const initializer = await this.encodeSetupCallData(safeAccountConfig)
const saltNonce = safeDeploymentConfig.saltNonce
const encodedNonce = toBuffer(this.#ethAdapter.encodeParameters(['uint256'], [saltNonce])).toString(
'hex'
)
const encodedNonce = toBuffer(
this.#ethAdapter.encodeParameters(['uint256'], [saltNonce])
).toString('hex')

const salt = keccak256(
toBuffer('0x' + keccak256(toBuffer(initializer)).toString('hex') + encodedNonce)
Expand Down
Loading

0 comments on commit ea3181e

Please sign in to comment.