From 371be061ac34c7e4364e654868659da56383431d Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Thu, 19 Dec 2024 19:03:14 +0100 Subject: [PATCH] Fix: rm circular dependency (#4697) * Fix: rm circular dependency * Rm GPT bot --- .github/workflows/code-review-gpt.yml | 25 --------------- .../UnknownContractError.tsx | 2 +- .../MigrateToL2Information/index.tsx | 2 +- .../utils/extract-migration-data.ts | 32 +++++++++++++++++++ src/utils/__tests__/safe-migrations.test.ts | 3 +- src/utils/safe-migrations.ts | 28 +--------------- src/utils/transaction-guards.ts | 2 +- 7 files changed, 38 insertions(+), 56 deletions(-) delete mode 100644 .github/workflows/code-review-gpt.yml create mode 100644 src/features/multichain/utils/extract-migration-data.ts diff --git a/.github/workflows/code-review-gpt.yml b/.github/workflows/code-review-gpt.yml deleted file mode 100644 index 4d8d03cfd9..0000000000 --- a/.github/workflows/code-review-gpt.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: AI code review - -permissions: - contents: read - pull-requests: write - -on: - pull_request: - types: [opened] - -jobs: - review: - # Don't run on draft PRs - if: ${{ github.event.pull_request.draft == false }} - runs-on: ubuntu-latest - steps: - - uses: anc95/ChatGPT-CodeReview@main - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - # Optional - MODEL: gpt-4o # https://platform.openai.com/docs/models - PROMPT: | - Find potential bugs in these code changes. - If you cannot find any bugs, say nothing, just write a funny haiku summarizing the code changes and post ONLY that. diff --git a/src/components/tx/SignOrExecuteForm/UnknownContractError.tsx b/src/components/tx/SignOrExecuteForm/UnknownContractError.tsx index 47b4de55cd..126010382d 100644 --- a/src/components/tx/SignOrExecuteForm/UnknownContractError.tsx +++ b/src/components/tx/SignOrExecuteForm/UnknownContractError.tsx @@ -6,7 +6,7 @@ import useSafeInfo from '@/hooks/useSafeInfo' import { getExplorerLink } from '@/utils/gateway' import ErrorMessage from '../ErrorMessage' import { isValidMasterCopy } from '@/services/contracts/safeContracts' -import { extractMigrationL2MasterCopyAddress } from '@/utils/safe-migrations' +import { extractMigrationL2MasterCopyAddress } from '@/features/multichain/utils/extract-migration-data' const UnknownContractError = ({ txData }: { txData: TransactionData | undefined }): ReactElement | null => { const { safe, safeAddress } = useSafeInfo() diff --git a/src/components/tx/confirmation-views/MigrateToL2Information/index.tsx b/src/components/tx/confirmation-views/MigrateToL2Information/index.tsx index 431b862c83..594300fb2c 100644 --- a/src/components/tx/confirmation-views/MigrateToL2Information/index.tsx +++ b/src/components/tx/confirmation-views/MigrateToL2Information/index.tsx @@ -3,7 +3,7 @@ import { Alert, AlertTitle, Box, SvgIcon, Typography } from '@mui/material' import type { TransactionData } from '@safe-global/safe-gateway-typescript-sdk' import InfoOutlinedIcon from '@/public/images/notifications/info.svg' import NamedAddressInfo from '@/components/common/NamedAddressInfo' -import { extractMigrationL2MasterCopyAddress } from '@/utils/safe-migrations' +import { extractMigrationL2MasterCopyAddress } from '@/features/multichain/utils/extract-migration-data' export const MigrateToL2Information = ({ variant, diff --git a/src/features/multichain/utils/extract-migration-data.ts b/src/features/multichain/utils/extract-migration-data.ts new file mode 100644 index 0000000000..3a8a0efa19 --- /dev/null +++ b/src/features/multichain/utils/extract-migration-data.ts @@ -0,0 +1,32 @@ +import type { TransactionData } from '@safe-global/safe-gateway-typescript-sdk' +import { Safe_to_l2_migration__factory } from '@/types/contracts' +import { sameAddress } from '@/utils/addresses' +import { isMultiSendCalldata } from '@/utils/transaction-calldata' +import { decodeMultiSendData } from '@safe-global/protocol-kit/dist/src/utils' +import { getSafeToL2MigrationDeployment } from '@safe-global/safe-deployments' + +export const extractMigrationL2MasterCopyAddress = (txData: TransactionData): string | undefined => { + if (!isMultiSendCalldata(txData.hexData || '')) { + return undefined + } + + const innerTxs = decodeMultiSendData(txData.hexData || '') + const firstInnerTx = innerTxs[0] + if (!firstInnerTx) { + return undefined + } + + const safeToL2MigrationDeployment = getSafeToL2MigrationDeployment() + const safeToL2MigrationAddress = safeToL2MigrationDeployment?.defaultAddress + const safeToL2MigrationInterface = Safe_to_l2_migration__factory.createInterface() + + if ( + firstInnerTx.data.startsWith(safeToL2MigrationInterface.getFunction('migrateToL2').selector) && + sameAddress(firstInnerTx.to, safeToL2MigrationAddress) + ) { + const callParams = safeToL2MigrationInterface.decodeFunctionData('migrateToL2', firstInnerTx.data) + return callParams[0] + } + + return undefined +} diff --git a/src/utils/__tests__/safe-migrations.test.ts b/src/utils/__tests__/safe-migrations.test.ts index 6ebdc3330b..73a447d5aa 100644 --- a/src/utils/__tests__/safe-migrations.test.ts +++ b/src/utils/__tests__/safe-migrations.test.ts @@ -4,7 +4,8 @@ import { type TransactionData, } from '@safe-global/safe-gateway-typescript-sdk' import { OperationType } from '@safe-global/safe-core-sdk-types' -import { extractMigrationL2MasterCopyAddress, prependSafeToL2Migration } from '../safe-migrations' +import { prependSafeToL2Migration } from '../safe-migrations' +import { extractMigrationL2MasterCopyAddress } from '@/features/multichain/utils/extract-migration-data' import { extendedSafeInfoBuilder } from '@/tests/builders/safe' import { chainBuilder } from '@/tests/builders/chains' import { safeSignatureBuilder, safeTxBuilder, safeTxDataBuilder } from '@/tests/builders/safeTx' diff --git a/src/utils/safe-migrations.ts b/src/utils/safe-migrations.ts index 10fd10df5f..beffec8694 100644 --- a/src/utils/safe-migrations.ts +++ b/src/utils/safe-migrations.ts @@ -4,7 +4,7 @@ import { getSafeContractDeployment } from '@/services/contracts/deployments' import { sameAddress } from './addresses' import { getSafeToL2MigrationDeployment, getSafeMigrationDeployment } from '@safe-global/safe-deployments' import { type MetaTransactionData, OperationType, type SafeTransaction } from '@safe-global/safe-core-sdk-types' -import type { ChainInfo, TransactionData } from '@safe-global/safe-gateway-typescript-sdk' +import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk' import { isValidMasterCopy } from '@/services/contracts/safeContracts' import { isMultiSendCalldata } from './transaction-calldata' import { decodeMultiSendData } from '@safe-global/protocol-kit/dist/src/utils' @@ -95,32 +95,6 @@ export const prependSafeToL2Migration = ( return __unsafe_createMultiSendTx(newTxs) } -export const extractMigrationL2MasterCopyAddress = (txData: TransactionData): string | undefined => { - if (!isMultiSendCalldata(txData.hexData || '')) { - return undefined - } - - const innerTxs = decodeMultiSendData(txData.hexData || '') - const firstInnerTx = innerTxs[0] - if (!firstInnerTx) { - return undefined - } - - const safeToL2MigrationDeployment = getSafeToL2MigrationDeployment() - const safeToL2MigrationAddress = safeToL2MigrationDeployment?.defaultAddress - const safeToL2MigrationInterface = Safe_to_l2_migration__factory.createInterface() - - if ( - firstInnerTx.data.startsWith(safeToL2MigrationInterface.getFunction('migrateToL2').selector) && - sameAddress(firstInnerTx.to, safeToL2MigrationAddress) - ) { - const callParams = safeToL2MigrationInterface.decodeFunctionData('migrateToL2', firstInnerTx.data) - return callParams[0] - } - - return undefined -} - export const createUpdateMigration = (chain: ChainInfo): MetaTransactionData => { const interfce = Safe_migration__factory.createInterface() diff --git a/src/utils/transaction-guards.ts b/src/utils/transaction-guards.ts index 7e63765c4e..2a70804895 100644 --- a/src/utils/transaction-guards.ts +++ b/src/utils/transaction-guards.ts @@ -69,7 +69,7 @@ import { isMultiSendCalldata } from './transaction-calldata' import { decodeMultiSendData } from '@safe-global/protocol-kit/dist/src/utils' import { OperationType } from '@safe-global/safe-core-sdk-types' import { LATEST_SAFE_VERSION } from '@/config/constants' -import { extractMigrationL2MasterCopyAddress } from './safe-migrations' +import { extractMigrationL2MasterCopyAddress } from '@/features/multichain/utils/extract-migration-data' export const isTxQueued = (value: TransactionStatus): boolean => { return [TransactionStatus.AWAITING_CONFIRMATIONS, TransactionStatus.AWAITING_EXECUTION].includes(value)