Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Relay): revert mandatory estimation of gasLimit #4801

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions apps/web/src/components/new-safe/create/logic/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getRedirect,
createNewUndeployedSafeWithoutSalt,
} from '@/components/new-safe/create/logic/index'
import * as relaying from '@/services/tx/relaying'
import { relayTransaction } from '@safe-global/safe-gateway-typescript-sdk'
import { toBeHex } from 'ethers'
import {
Gnosis_safe__factory,
Expand All @@ -21,6 +21,7 @@ import {
getReadOnlyGnosisSafeContract,
getReadOnlyProxyFactoryContract,
} from '@/services/contracts/safeContracts'
import * as gateway from '@safe-global/safe-gateway-typescript-sdk'
import { FEATURES, getLatestSafeVersion } from '@/utils/chains'
import { chainBuilder } from '@/tests/builders/chains'
import { type ReplayedSafeProps } from '@/store/slices'
Expand Down Expand Up @@ -64,14 +65,13 @@ describe('create/logic', () => {
})

it('returns taskId if create Safe successfully relayed', async () => {
const gasLimit = faker.string.numeric()
const mockSafeProvider = {
getExternalProvider: jest.fn(),
getExternalSigner: jest.fn(),
getChainId: jest.fn().mockReturnValue(BigInt(1)),
} as unknown as SafeProvider

jest.spyOn(relaying, 'relayTransaction').mockResolvedValue({ taskId: '0x123' })
jest.spyOn(gateway, 'relayTransaction').mockResolvedValue({ taskId: '0x123' })
jest.spyOn(sdkHelpers, 'getSafeProvider').mockImplementation(() => mockSafeProvider)

jest.spyOn(contracts, 'getReadOnlyFallbackHandlerContract').mockResolvedValue({
Expand Down Expand Up @@ -120,22 +120,20 @@ describe('create/logic', () => {
expectedSaltNonce,
])

const taskId = await relaySafeCreation(mockChainInfo, undeployedSafeProps, gasLimit)
const taskId = await relaySafeCreation(mockChainInfo, undeployedSafeProps)

expect(taskId).toEqual('0x123')
expect(relaying.relayTransaction).toHaveBeenCalledTimes(1)
expect(relaying.relayTransaction).toHaveBeenCalledWith('1', {
expect(relayTransaction).toHaveBeenCalledTimes(1)
expect(relayTransaction).toHaveBeenCalledWith('1', {
to: proxyFactoryAddress,
data: expectedCallData,
version: latestSafeVersion,
gasLimit,
})
})

it('should throw an error if relaying fails', () => {
const gasLimit = faker.string.numeric()
const relayFailedError = new Error('Relay failed')
jest.spyOn(relaying, 'relayTransaction').mockRejectedValue(relayFailedError)
jest.spyOn(gateway, 'relayTransaction').mockRejectedValue(relayFailedError)

const undeployedSafeProps: ReplayedSafeProps = {
safeAccountConfig: {
Expand All @@ -154,7 +152,7 @@ describe('create/logic', () => {
saltNonce: '69',
}

expect(relaySafeCreation(mockChainInfo, undeployedSafeProps, gasLimit)).rejects.toEqual(relayFailedError)
expect(relaySafeCreation(mockChainInfo, undeployedSafeProps)).rejects.toEqual(relayFailedError)
})
})
describe('getRedirect', () => {
Expand Down
10 changes: 2 additions & 8 deletions apps/web/src/components/new-safe/create/logic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type { SafeVersion } from '@safe-global/safe-core-sdk-types'
import { type Eip1193Provider, type Provider } from 'ethers'
import semverSatisfies from 'semver/functions/satisfies'

import { getSafeInfo, type SafeInfo, type ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { relayTransaction } from '@/services/tx/relaying'
import { getSafeInfo, type SafeInfo, type ChainInfo, relayTransaction } from '@safe-global/safe-gateway-typescript-sdk'
import { getReadOnlyProxyFactoryContract } from '@/services/contracts/safeContracts'
import type { UrlObject } from 'url'
import { AppRoutes } from '@/config/routes'
Expand Down Expand Up @@ -179,19 +178,14 @@ export const getRedirect = (
return redirectUrl + `${appendChar}safe=${address}`
}

export const relaySafeCreation = async (
chain: ChainInfo,
undeployedSafeProps: UndeployedSafeProps,
gasLimit: string | undefined,
) => {
export const relaySafeCreation = async (chain: ChainInfo, undeployedSafeProps: UndeployedSafeProps) => {
const replayedSafeProps = assertNewUndeployedSafeProps(undeployedSafeProps, chain)
const encodedSafeCreationTx = encodeSafeCreationTx(replayedSafeProps, chain)

const relayResponse = await relayTransaction(chain.chainId, {
to: replayedSafeProps.factoryAddress,
data: encodedSafeCreationTx,
version: replayedSafeProps.safeVersion,
gasLimit,
})

return relayResponse.taskId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ const ReviewStep = ({ data, onSubmit, onBack, setStep }: StepRenderProps<NewSafe
}

if (willRelay) {
const taskId = await relaySafeCreation(chain, props, gasLimit?.toString())
const taskId = await relaySafeCreation(chain, props)
onSubmitCallback(taskId)
} else {
await createNewSafe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const ActivateAccountFlow = () => {

try {
if (willRelay) {
const taskId = await relaySafeCreation(chain, undeployedSafe.props, options?.gasLimit?.toString())
const taskId = await relaySafeCreation(chain, undeployedSafe.props)
safeCreationDispatch(SafeCreationEvent.RELAYING, { groupKey: CF_TX_GROUP_KEY, taskId, safeAddress })

onSubmit()
Expand Down
66 changes: 0 additions & 66 deletions apps/web/src/services/tx/__tests__/relaying.test.ts

This file was deleted.

29 changes: 0 additions & 29 deletions apps/web/src/services/tx/relaying.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
type JsonRpcProvider,
type JsonRpcSigner,
} from 'ethers'
import { faker } from '@faker-js/faker'
import * as safeContracts from '@/services/contracts/safeContracts'

import * as web3 from '@/hooks/wallets/web3'
Expand Down Expand Up @@ -516,13 +515,6 @@ describe('txSender', () => {

describe('dispatchBatchExecutionRelay', () => {
it('should relay a batch execution', async () => {
const gasLimit = faker.number.bigInt()
jest.spyOn(web3, 'getWeb3ReadOnly').mockImplementation(() => {
return {
estimateGas: jest.fn(() => Promise.resolve(gasLimit)),
} as unknown as JsonRpcProvider
})

const mockMultisendAddress = zeroPadValue('0x1234', 20)
const safeAddress = toBeHex('0x567', 20)

Expand Down
10 changes: 6 additions & 4 deletions apps/web/src/services/tx/tx-sender/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import type { ConnectedWallet } from '@/hooks/wallets/useOnboard'
import { isMultisigExecutionInfo } from '@/utils/transaction-guards'
import { isHardwareWallet, isSmartContractWallet } from '@/utils/wallets'
import type { MultiSendCallOnlyContractImplementationType } from '@safe-global/protocol-kit'
import { type ChainInfo, type SafeInfo, type TransactionDetails } from '@safe-global/safe-gateway-typescript-sdk'
import { relayTransaction } from '@/services/tx/relaying'
import {
type ChainInfo,
relayTransaction,
type SafeInfo,
type TransactionDetails,
} from '@safe-global/safe-gateway-typescript-sdk'
import type {
SafeSignature,
SafeTransaction,
Expand Down Expand Up @@ -554,8 +558,6 @@ export const dispatchBatchExecutionRelay = async (
to,
data,
version: safeVersion,
// We have no estimation in place
gasLimit: undefined,
})
} catch (error) {
txs.forEach(({ txId }) => {
Expand Down
Loading