Skip to content

Commit

Permalink
Revert "Merge pull request #1610 from AmbireTech/resstrict-typed-mess…
Browse files Browse the repository at this point in the history
…ages"

This reverts commit 29d8399, reversing
changes made to 73b19e4.
  • Loading branch information
JIOjosBG committed Jun 24, 2024
1 parent fdc2e66 commit 633442a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 47 deletions.
76 changes: 46 additions & 30 deletions src/hooks/walletConnect/walletConnectV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import { Web3Wallet } from '@walletconnect/web3wallet'
import { formatJsonRpcError, formatJsonRpcResult } from '@json-rpc-tools/utils'

import {
UNISWAP_PERMIT_EXCEPTIONS,
DEFAULT_EIP155_EVENTS,
WC2_SUPPORTED_METHODS,
PERMIT_2_ADDRESS,
UNISWAP_UNIVERSAL_ROUTERS
WC2_SUPPORTED_METHODS
} from 'hooks/walletConnect/wcConsts'
import networks from 'consts/networks'
import { ethers } from 'ethers'
Expand Down Expand Up @@ -368,33 +367,50 @@ export default function useWalletConnectV2({
} else if (method === 'eth_signTypedData_v4') {
requestAccount = wcRequest.params[0]
txn = JSON.parse(wcRequest.params[1])
const isSnapshot = (_dappName, _txn) => _dappName && _dappName.toLowerCase().includes('snapshot') && _txn.domain && _txn.domain.name === 'snapshot'
const isOkPermit2 = (_txn) =>
_txn.primaryType &&
_txn.primaryType.toLowerCase().includes('permit') &&
_txn.message && _txn.message.spender &&
_txn.message.spender.toLowerCase() === UNISWAP_UNIVERSAL_ROUTERS[requestChainId].toLowerCase() &&
_txn.domain && _txn.domain.verifyingContract &&
_txn.domain.verifyingContract.toLowerCase() === PERMIT_2_ADDRESS.toLowerCase()
const isSigTool = (_connection) => _connection && _connection.peer && _connection.peer.metadata && _connection.peer.metadata.url === 'https://sigtool.ambire.com/'

if (!isSigTool(connection) && !isSnapshot(dappName, txn) && !isOkPermit2(txn)) {
const response = formatJsonRpcError(id, {
message: `Signing this eip-712 message is disallowed as it does not contain the smart account address and therefore deemed unsafe: ${method}`,
code: -32003
})
web3wallet
.respondSessionRequest({ topic, response })
.catch((err) => {
addToast(err.message, { error: true })

// Dealing with Erc20 Permits
if (txn.primaryType === 'Permit') {
// If Uniswap, reject the permit and expect a graceful fallback (receiving approve eth_sendTransaction afterwards)
if (
UNISWAP_PERMIT_EXCEPTIONS.some((ex) =>
dappName.toLowerCase().includes(ex.toLowerCase())
)
) {
const response = formatJsonRpcError(id, {
message: `Method not found: ${method}`,
code: -32601
})
web3wallet
.respondSessionRequest({
topic,
response
})
.catch((err) => {
addToast(err.message, { error: true })
})

return
}
// Regular Permit (EIP-2612) is not supported by SCWs, because it requires a signature from the wallet
// and ERC-20 token contracts don't implement EIP-1271.
addToast(
'We\'re not yet able to sign this message. Please use the Ambire Extension.',
{ warning: true }
'Please, change the approval type to "Transaction" from the dApp, as the currently selected method doesn\'t support Smart Wallets.',
{
error: true
}
)
// return err to the dapp so it doesnt infinitely load
web3wallet.respondSessionRequest({
topic,
response: formatJsonRpcError(id, {
message:
'Please, change the approval type to "Transaction" from the dApp, as the currently selected method doesn\'t support Smart Wallets.',
// Internal JSON-RPC error
code: -32603
})
})
return
}

} else if (
method === 'wallet_switchEthereumChain' ||
method === 'wallet_addEthereumChain'
Expand Down Expand Up @@ -445,11 +461,11 @@ export default function useWalletConnectV2({
notification: true,
dapp: connection.peer.metadata
? {
name: connection.peer.metadata.name,
description: connection.peer.metadata.description,
icons: connection.peer.metadata.icons,
url: connection.peer.metadata.url
}
name: connection.peer.metadata.name,
description: connection.peer.metadata.description,
icons: connection.peer.metadata.icons,
url: connection.peer.metadata.url
}
: null
}
setWalletRequests((prev) => [...prev, request])
Expand Down
24 changes: 7 additions & 17 deletions src/hooks/walletConnect/wcConsts.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
export const PERMIT_2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3'

export const UNISWAP_UNIVERSAL_ROUTERS = {
1: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
11155111: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
8453: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
42161: '0x5E325eDA8064b456f4781070C0738d849c824258',
421614: '0x4A7b5Da61326A6379179b40d00F57E5bbDC962c2',
10: '0xCb1355ff08Ab38bBCE60111F1bb2B7845384bE25D7e8',
11155420: '0xD5bBa708b39537d33F2812E5Ea032622456F1A95',
137: '0xec7BE89e9d109e7e3Fec59c222CF297125FEFda2',
84532: '0x050E797f3625EC8785265e1d9BDd4799b97528A1',
56: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
43114: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
42220: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
81457: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4'
}
export const UNISWAP_PERMIT_EXCEPTIONS = [
// based on PeerMeta
// 'Uniswap', // Uniswap Interface - already using UniversalRouter that supports permit form sc wallets, and uniswap interface will not fallback to old routers if we reject the tx
'Sushi',
'QuickSwap', // QuickSwap Interface
'PancakeSwap' // 🥞 PancakeSwap - A next evolution DeFi exchange on BNB Smart Chain (BSC)
]

export const DEFAULT_EIP155_EVENTS = ['chainChanged', 'accountsChanged']

Expand Down

0 comments on commit 633442a

Please sign in to comment.