Skip to content

Commit

Permalink
Merge pull request #93 from gnosisguild/fix-delegatecall
Browse files Browse the repository at this point in the history
Fix an edge case when submitting a delegatecall transactions
  • Loading branch information
jfschwarz authored Mar 5, 2024
2 parents 9c0d999 + 645e429 commit 53d7aff
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 24 deletions.
2 changes: 1 addition & 1 deletion extension/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './global.css'
import Browser from './browser'
import ConnectionsDrawer from './connections/ConnectionsDrawer'
import ProvideProvider from './browser/ProvideProvider'
import { ProvideState } from './browser/state'
import { ProvideState } from './state'
import ZodiacToastContainer from './components/Toast'
import { pushLocation } from './location'
import { ProvideMetaMask, ProvideTenderly } from './providers'
Expand Down
7 changes: 4 additions & 3 deletions extension/src/browser/Drawer/Remove.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'
import { RiDeleteBinLine } from 'react-icons/ri'
import { encodeSingle, TransactionInput } from 'react-multisend'
import { TransactionInput } from 'react-multisend'

import { IconButton } from '../../components'
import { ForkProvider } from '../../providers'
import { useProvider } from '../ProvideProvider'
import { useDispatch, useNewTransactions } from '../state'
import { useDispatch, useNewTransactions } from '../../state'

import classes from './style.module.css'
import { encodeTransaction } from '../../encodeTransaction'

type Props = {
transaction: TransactionInput
Expand Down Expand Up @@ -42,7 +43,7 @@ export const Remove: React.FC<Props> = ({ transaction, index }) => {

// re-simulate all transactions after the removed one
for (const transaction of laterTransactions) {
const encoded = encodeSingle(transaction.input)
const encoded = encodeTransaction(transaction)
await provider.sendMetaTransaction(encoded)
}
}
Expand Down
10 changes: 8 additions & 2 deletions extension/src/browser/Drawer/RolePermissionCheck.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useMemo } from 'react'
import { useEffect, useState } from 'react'
import { RiGroupLine } from 'react-icons/ri'
import { encodeSingle, TransactionInput } from 'react-multisend'
Expand Down Expand Up @@ -64,7 +64,13 @@ const RolePermissionCheck: React.FC<{
const { connection } = useConnection()
const tenderlyProvider = useTenderlyProvider()

const encodedTransaction = encodeSingle(transaction)
const encodedTransaction = useMemo(
() => ({
...encodeSingle(transaction),
operation: isDelegateCall ? 1 : 0,
}),
[transaction, isDelegateCall]
)

const translationAvailable = !!useApplicableTranslation(encodedTransaction)

Expand Down
2 changes: 1 addition & 1 deletion extension/src/browser/Drawer/Submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
decodeRolesV2Error,
} from '../../utils'
import { useSubmitTransactions } from '../ProvideProvider'
import { useDispatch, useNewTransactions } from '../state'
import { useDispatch, useNewTransactions } from '../../state'

import classes from './style.module.css'
import { getReadOnlyProvider } from '../../providers/readOnlyProvider'
Expand Down
2 changes: 1 addition & 1 deletion extension/src/browser/Drawer/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Box, Flex } from '../../components'
import ToggleButton from '../../components/Drawer/ToggleButton'
import { CHAIN_CURRENCY } from '../../chains'
import { useConnection } from '../../connections'
import { TransactionState } from '../state'
import { TransactionState } from '../../state'

import CallContract from './CallContract'
import ContractAddress from './ContractAddress'
Expand Down
5 changes: 3 additions & 2 deletions extension/src/browser/Drawer/Translate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { IconButton } from '../../components'
import { ForkProvider } from '../../providers'
import { useApplicableTranslation } from '../../transactionTranslations'
import { useProvider } from '../ProvideProvider'
import { useDispatch, useNewTransactions } from '../state'
import { useDispatch, useNewTransactions } from '../../state'

import classes from './style.module.css'
import { encodeTransaction } from '../../encodeTransaction'

type Props = {
transaction: TransactionInput
Expand Down Expand Up @@ -44,7 +45,7 @@ export const Translate: React.FC<Props> = ({
const handleTranslate = async () => {
const laterTransactions = transactions
.slice(index + 1)
.map((t) => encodeSingle(t.input))
.map(encodeTransaction)

// remove the transaction and all later ones from the store
dispatch({ type: 'REMOVE_TRANSACTION', payload: { id: transaction.id } })
Expand Down
13 changes: 9 additions & 4 deletions extension/src/browser/Drawer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import React, { useEffect, useRef, useState } from 'react'
import { RiFileCopy2Line, RiRefreshLine } from 'react-icons/ri'
import { encodeMulti, encodeSingle } from 'react-multisend'
import { encodeMulti } from 'react-multisend'
import { toast } from 'react-toastify'

import { BlockButton, Button, Drawer, Flex, IconButton } from '../../components'
import { ForkProvider } from '../../providers'
import { wrapRequest } from '../../providers/WrappingProvider'
import { useConnection } from '../../connections'
import { useProvider } from '../ProvideProvider'
import { useAllTransactions, useDispatch, useNewTransactions } from '../state'
import {
useAllTransactions,
useDispatch,
useNewTransactions,
} from '../../state'

import Submit from './Submit'
import { Transaction, TransactionBadge } from './Transaction'
import classes from './style.module.css'
import { MULTI_SEND_ADDRESS } from '../../chains'
import { encodeTransaction } from '../../encodeTransaction'

const TransactionsDrawer: React.FC = () => {
const [expanded, setExpanded] = useState(true)
Expand Down Expand Up @@ -53,14 +58,14 @@ const TransactionsDrawer: React.FC = () => {

// re-simulate all new transactions (assuming the already submitted ones have already been mined on the fresh fork)
for (const transaction of newTransactions) {
const encoded = encodeSingle(transaction.input)
const encoded = encodeTransaction(transaction)
await provider.sendMetaTransaction(encoded)
}
}

const copyTransactionData = () => {
if (!connection.chainId) throw new Error('chainId is undefined')
const metaTransactions = newTransactions.map((tx) => encodeSingle(tx.input))
const metaTransactions = newTransactions.map(encodeTransaction)
const batchTransaction =
metaTransactions.length === 1
? metaTransactions[0]
Expand Down
9 changes: 4 additions & 5 deletions extension/src/browser/ProvideProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, {
useContext,
useMemo,
} from 'react'
import { decodeSingle, encodeMulti, encodeSingle } from 'react-multisend'
import { decodeSingle, encodeMulti } from 'react-multisend'

import { MULTI_SEND_ADDRESS } from '../chains'
import {
Expand All @@ -18,7 +18,8 @@ import { useConnection } from '../connections'
import { Eip1193Provider } from '../types'

import fetchAbi from './fetchAbi'
import { useDispatch, useNewTransactions } from './state'
import { useDispatch, useNewTransactions } from '../state'
import { encodeTransaction } from '../encodeTransaction'

interface Props {
simulate: boolean
Expand Down Expand Up @@ -101,9 +102,7 @@ const ProvideProvider: React.FC<Props> = ({ simulate, children }) => {
)

const submitTransactions = useCallback(async () => {
const metaTransactions = transactions.map((txState) =>
encodeSingle(txState.input)
)
const metaTransactions = transactions.map(encodeTransaction)

console.log(
transactions.length === 1
Expand Down
2 changes: 1 addition & 1 deletion extension/src/connections/ConnectionsDrawer/Edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
useSelectedConnectionId,
} from '../../connectionHooks'
import useConnectionDryRun from '../../useConnectionDryRun'
import { useClearTransactions } from '../../../browser/state/transactionHooks'
import { useClearTransactions } from '../../../state/transactionHooks'

import classes from './style.module.css'
import { decodeRoleKey, encodeRoleKey } from '../../../utils'
Expand Down
2 changes: 1 addition & 1 deletion extension/src/connections/ConnectionsDrawer/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
useSelectedConnectionId,
} from '../../connectionHooks'
import { Connection, ProviderType } from '../../../types'
import { useClearTransactions } from '../../../browser/state/transactionHooks'
import { useClearTransactions } from '../../../state/transactionHooks'

import classes from './style.module.css'

Expand Down
9 changes: 9 additions & 0 deletions extension/src/encodeTransaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { encodeSingle } from 'react-multisend'
import { TransactionState } from './state'

export const encodeTransaction = (transaction: TransactionState) => {
return {
...encodeSingle(transaction.input),
operation: transaction.isDelegateCall ? 1 : 0,
}
}
4 changes: 3 additions & 1 deletion extension/src/providers/WrappingProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class WrappingProvider extends EventEmitter {
constructor(provider: Eip1193Provider, connection: Connection) {
super()
this.provider = provider
this.signer = new Web3Provider(provider).getSigner()
this.signer = new Web3Provider(this.provider).getUncheckedSigner(
connection.pilotAddress
)
this.connection = connection
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react'

import { ForkProvider } from '../../providers'
import { useProvider } from '../ProvideProvider'
import { ForkProvider } from '../providers'
import { useProvider } from '../browser/ProvideProvider'

import { useAllTransactions, useDispatch } from '.'

Expand Down

0 comments on commit 53d7aff

Please sign in to comment.