Skip to content

Commit

Permalink
remove ethereumjs-abi dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
germartinez committed Jul 27, 2022
1 parent f7f5230 commit a11801b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ export interface EthAdapter {
callback?: (error: Error, gas: number) => void
): Promise<number>
call(transaction: EthAdapterTransaction): Promise<string>
encodeParameter(type: string, value: any): string
}
1 change: 0 additions & 1 deletion packages/safe-core-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"@ethersproject/solidity": "^5.6.0",
"@gnosis.pm/safe-core-sdk-types": "^1.2.1",
"@gnosis.pm/safe-deployments": "1.15.0",
"ethereumjs-abi": "^0.6.8",
"ethereumjs-util": "^7.1.4",
"semver": "^7.3.5",
"web3-utils": "^1.7.1"
Expand Down
23 changes: 12 additions & 11 deletions packages/safe-core-sdk/src/safeFactory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
SafeVersion,
TransactionOptions
} from '@gnosis.pm/safe-core-sdk-types'
import abi from 'ethereumjs-abi'
import { generateAddress2, keccak256, toBuffer } from 'ethereumjs-util'
import { SAFE_LAST_VERSION } from '../contracts/config'
import { getProxyFactoryContract, getSafeContract } from '../contracts/safeDeploymentContracts'
Expand All @@ -26,7 +25,7 @@ export interface SafeAccountConfig {
}

export interface SafeDeploymentConfig {
saltNonce: number
saltNonce: string
}

export interface PredictSafeProps {
Expand Down Expand Up @@ -152,23 +151,24 @@ class SafeFactory {
safeDeploymentConfig
}: PredictSafeProps): Promise<string> {
validateSafeAccountConfig(safeAccountConfig)
if (safeDeploymentConfig) {
validateSafeDeploymentConfig(safeDeploymentConfig)
}
validateSafeDeploymentConfig(safeDeploymentConfig)

const from = this.#safeProxyFactoryContract.getAddress()

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

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

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

const proxyAddress =
Expand All @@ -189,7 +189,8 @@ class SafeFactory {
const signerAddress = await this.#ethAdapter.getSignerAddress()
const initializer = await this.encodeSetupCallData(safeAccountConfig)
const saltNonce =
safeDeploymentConfig?.saltNonce ?? Date.now() * 1000 + Math.floor(Math.random() * 1000)
safeDeploymentConfig?.saltNonce ??
(Date.now() * 1000 + Math.floor(Math.random() * 1000)).toString()

if (options?.gas && options?.gasLimit) {
throw new Error('Cannot specify gas and gasLimit together in transaction options')
Expand Down
4 changes: 4 additions & 0 deletions packages/safe-ethers-lib/src/EthersAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ class EthersAdapter implements EthAdapter {
call(transaction: EthAdapterTransaction): Promise<string> {
return this.#provider.call(transaction)
}

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

export default EthersAdapter
4 changes: 4 additions & 0 deletions packages/safe-web3-lib/src/Web3Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ class Web3Adapter implements EthAdapter {
call(transaction: EthAdapterTransaction): Promise<string> {
return this.#web3.eth.call(transaction)
}

encodeParameter(type: string, value: any): string {
return this.#web3.eth.abi.encodeParameter(type, value)
}
}

export default Web3Adapter

0 comments on commit a11801b

Please sign in to comment.