Skip to content

Commit

Permalink
Replace encodeParameter with encodeParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
germartinez committed Jul 29, 2022
1 parent ddd88c7 commit 6f1b2e5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ export interface EthAdapter {
callback?: (error: Error, gas: number) => void
): Promise<number>
call(transaction: EthAdapterTransaction): Promise<string>
encodeParameter(type: string, value: any): string
encodeParameters(types: string[], values: any[]): string
}
4 changes: 2 additions & 2 deletions packages/safe-core-sdk/src/safeFactory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class SafeFactory {

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

Expand All @@ -167,7 +167,7 @@ class SafeFactory {

const proxyCreationCode = await this.#safeProxyFactoryContract.proxyCreationCode()
const constructorData = toBuffer(
this.#ethAdapter.encodeParameter('address', this.#gnosisSafeContract.getAddress())
this.#ethAdapter.encodeParameters(['address'], [this.#gnosisSafeContract.getAddress()])
).toString('hex')
const initCode = proxyCreationCode + constructorData

Expand Down
34 changes: 17 additions & 17 deletions packages/safe-core-sdk/tests/safeFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ describe('Safe Proxy Factory', () => {
const owners: string[] = []
const threshold = 2
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: 1 }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: '1' }
const predictSafeProps: PredictSafeProps = { safeAccountConfig, safeDeploymentConfig }
chai
await chai
.expect(safeFactory.predictSafeAddress(predictSafeProps))
.rejectedWith('Owner list must have at least one owner')
})
Expand All @@ -120,9 +120,9 @@ describe('Safe Proxy Factory', () => {
const owners = [account1.address, account2.address]
const threshold = 0
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: 1 }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: '1' }
const predictSafeProps: PredictSafeProps = { safeAccountConfig, safeDeploymentConfig }
chai
await chai
.expect(safeFactory.predictSafeAddress(predictSafeProps))
.rejectedWith('Threshold must be greater than or equal to 1')
})
Expand All @@ -135,9 +135,9 @@ describe('Safe Proxy Factory', () => {
const owners = [account1.address, account2.address]
const threshold = 3
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: 1 }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: '1' }
const predictSafeProps: PredictSafeProps = { safeAccountConfig, safeDeploymentConfig }
chai
await chai
.expect(safeFactory.predictSafeAddress(predictSafeProps))
.rejectedWith('Threshold must be lower than or equal to owners length')
})
Expand All @@ -154,11 +154,11 @@ describe('Safe Proxy Factory', () => {
const owners = [account1.address, account2.address]
const threshold = 2
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: -1 }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: '-1' }
const predictSafeProps: PredictSafeProps = { safeAccountConfig, safeDeploymentConfig }
chai
await chai
.expect(safeFactory.predictSafeAddress(predictSafeProps))
.rejectedWith('saltNonce must be greater than 0')
.rejectedWith('saltNonce must be greater than or equal to 0')
})

it('should predict a new Safe with saltNonce', async () => {
Expand All @@ -173,7 +173,7 @@ describe('Safe Proxy Factory', () => {
const owners = [account1.address, account2.address]
const threshold = 2
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: 12345 }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: '12345' }
const predictSafeProps: PredictSafeProps = { safeAccountConfig, safeDeploymentConfig }
const counterfactualSafeAddress = await safeFactory.predictSafeAddress(predictSafeProps)
const deploySafeProps: DeploySafeProps = { safeAccountConfig, safeDeploymentConfig }
Expand All @@ -193,7 +193,7 @@ describe('Safe Proxy Factory', () => {
const threshold = 2
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const safeDeployProps: DeploySafeProps = { safeAccountConfig }
chai
await chai
.expect(safeFactory.deploySafe(safeDeployProps))
.rejectedWith('Owner list must have at least one owner')
})
Expand All @@ -207,7 +207,7 @@ describe('Safe Proxy Factory', () => {
const threshold = 0
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const safeDeployProps: DeploySafeProps = { safeAccountConfig }
chai
await chai
.expect(safeFactory.deploySafe(safeDeployProps))
.rejectedWith('Threshold must be greater than or equal to 1')
})
Expand All @@ -221,7 +221,7 @@ describe('Safe Proxy Factory', () => {
const threshold = 3
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const deploySafeProps: DeploySafeProps = { safeAccountConfig }
chai
await chai
.expect(safeFactory.deploySafe(deploySafeProps))
.rejectedWith('Threshold must be lower than or equal to owners length')
})
Expand All @@ -238,11 +238,11 @@ describe('Safe Proxy Factory', () => {
const owners = [account1.address, account2.address]
const threshold = 2
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: -1 }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: '-1' }
const safeDeployProps: DeploySafeProps = { safeAccountConfig, safeDeploymentConfig }
chai
await chai
.expect(safeFactory.deploySafe(safeDeployProps))
.rejectedWith('saltNonce must be greater than 0')
.rejectedWith('saltNonce must be greater than or equal to 0')
})

it('should deploy a new Safe without saltNonce', async () => {
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('Safe Proxy Factory', () => {
const owners = [account1.address, account2.address]
const threshold = 2
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: 1 }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: '1' }
const deploySafeProps: DeploySafeProps = { safeAccountConfig, safeDeploymentConfig }
const safe = await safeFactory.deploySafe(deploySafeProps)
const deployedSafeOwners = await safe.getOwners()
Expand Down
4 changes: 2 additions & 2 deletions packages/safe-ethers-lib/src/EthersAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ class EthersAdapter implements EthAdapter {
return this.#provider.call(transaction)
}

encodeParameter(type: string, value: any) {
return new this.#ethers.utils.AbiCoder().encode([type], [value])
encodeParameters(types: string[], values: any[]) {
return new this.#ethers.utils.AbiCoder().encode(types, values)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/safe-web3-lib/src/Web3Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ class Web3Adapter implements EthAdapter {
return this.#web3.eth.call(transaction)
}

encodeParameter(type: string, value: any): string {
return this.#web3.eth.abi.encodeParameter(type, value)
encodeParameters(types: string[], values: any[]): string {
return this.#web3.eth.abi.encodeParameters(types, values)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BigNumber } from '@ethersproject/bignumber'
import { GnosisSafeProxyFactoryContract } from '@gnosis.pm/safe-core-sdk-types'
import { TransactionReceipt } from 'web3-core/types'
import { ProxyFactory as ProxyFactory_V1_1_1 } from '../../../typechain/src/web3-v1/v1.1.1/proxy_factory'
Expand Down Expand Up @@ -31,9 +32,8 @@ class GnosisSafeProxyFactoryWeb3Contract implements GnosisSafeProxyFactoryContra
options,
callback
}: CreateProxyProps): Promise<string> {
//if (saltNonce < 0) {
// throw new Error('saltNonce must be greater than or equal to 0')
//}
if (BigNumber.from(saltNonce).lt(0))
throw new Error('saltNonce must be greater than or equal to 0')
if (options && !options.gas) {
options.gas = await this.estimateGas(
'createProxyWithNonce',
Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2538,13 +2538,6 @@
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.12.tgz#6b2c510a7ad7039e98e7b8d3d6598f4359e5c080"
integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==

"@types/ethereumjs-abi@^0.6.3":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@types/ethereumjs-abi/-/ethereumjs-abi-0.6.3.tgz#eb5ed09fd86b9e2b1c0eb75d1e9bc29c50715c86"
integrity sha512-DnHvqPkrJS5w4yZexTa5bdPNb8IyKPYciou0+zZCIg5fpzvGtyptTvshy0uZKzti2/k/markwjlxWRBWt7Mjuw==
dependencies:
"@types/node" "*"

"@types/express-serve-static-core@4.17.29", "@types/express-serve-static-core@^4.17.18":
version "4.17.29"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.29.tgz#2a1795ea8e9e9c91b4a4bbe475034b20c1ec711c"
Expand Down

0 comments on commit 6f1b2e5

Please sign in to comment.