Skip to content

Commit

Permalink
Detect ERC-1167 Minimal Proxy contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Sep 12, 2024
1 parent 19ea54a commit e14c0ff
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changelog/1538.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Detect ERC-1167 Minimal Proxy contracts
10 changes: 10 additions & 0 deletions src/app/components/Account/RuntimeAccountDetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { calculateFiatValue } from '../Balance/hooks'
import { FiatMoneyAmount } from '../Balance/FiatMoneyAmount'
import { getFiatCurrencyForScope, showFiatValues } from '../../../config'
import { CardEmptyState } from '../CardEmptyState'
import { extractMinimalProxyERC1167 } from '../ContractVerificationIcon/extractMinimalProxyERC1167'

type RuntimeAccountDetailsViewProps = {
isLoading?: boolean
Expand Down Expand Up @@ -103,6 +104,15 @@ export const RuntimeAccountDetailsView: FC<RuntimeAccountDetailsViewProps> = ({
</>
)}

{extractMinimalProxyERC1167(account) && (
<>
<dt>{t('contract.verification.proxyERC1167')}</dt>
<dd>
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)!} />
</dd>
</>
)}

{contract && (
<>
<dt>{t('contract.creator')}</dt>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { RuntimeAccount } from '../../../oasis-nexus/api'
import { base64ToHex } from '../../utils/helpers'
import { toChecksumAddress } from '@ethereumjs/util'

/** https://eips.ethereum.org/EIPS/eip-1167 */
export function extractMinimalProxyERC1167(account: RuntimeAccount) {
if (!account?.evm_contract?.runtime_bytecode) return undefined

const hexBytecode = base64ToHex(account.evm_contract.runtime_bytecode)

const proxyToAddress1 = hexBytecode.match(
/^0x363d3d373d3d3d363d73([0-9a-fA-F]{40})5af43d82803e903d91602b57fd5bf3$/,
)?.[1]
if (proxyToAddress1) return toChecksumAddress(`0x${proxyToAddress1}`)

// Optimized version
const proxyToAddress2 = hexBytecode.match(
/^0x363d3d373d3d3d363d6f([0-9a-fA-F]{32})5af43d82803e903d91602757fd5bf3$/,
)?.[1]
if (proxyToAddress2) return toChecksumAddress(`0x00000000${proxyToAddress2}`)

return undefined
}
10 changes: 10 additions & 0 deletions src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { tokenHoldersContainerId } from '../../pages/TokenDashboardPage/TokenHol
import { RoundedBalance } from 'app/components/RoundedBalance'
import { HighlightedText } from '../../components/HighlightedText'
import { RuntimeBalanceDisplay } from '../../components/Balance/RuntimeBalanceDisplay'
import { extractMinimalProxyERC1167 } from '../../components/ContractVerificationIcon/extractMinimalProxyERC1167'

export const TokenDetailsCard: FC<{ scope: SearchScope; address: string; searchTerm: string }> = ({
scope,
Expand Down Expand Up @@ -66,6 +67,15 @@ export const TokenDetailsCard: FC<{ scope: SearchScope; address: string; searchT
/>
</dd>

{extractMinimalProxyERC1167(account) && (
<>
<dt>{t('contract.verification.proxyERC1167')}</dt>
<dd>
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)!} />
</dd>
</>
)}

<dt>{t('common.type')} </dt>
<dd>
<TokenTypeTag tokenType={token.type} />
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@
"openInAbiPlayground": "Interact in <AbiPlaygroundLink>ABI Playground</AbiPlaygroundLink>",
"openInSourcify": "Open in <SourcifyLink>Sourcify</SourcifyLink>",
"verifyInSourcify": "Verify through <SourcifyLink>Sourcify</SourcifyLink>",
"explainVerificationDelay": "If you have just verified a contract, it should take a few minutes to update here."
"explainVerificationDelay": "If you have just verified a contract, it should take a few minutes to update here.",
"proxyERC1167": "ERC-1167 proxy to"
}
},
"consensusSnapshot": {
Expand Down

0 comments on commit e14c0ff

Please sign in to comment.