Skip to content

Commit

Permalink
feat: Integrate partial functionalities with Snowtrace.io, disable tr…
Browse files Browse the repository at this point in the history
…ansaction explanation by default, and enable decompilation through bytecode MD5 in Dedaub
  • Loading branch information
0xbe37e committed Dec 21, 2023
1 parent a59a379 commit 511cb96
Show file tree
Hide file tree
Showing 41 changed files with 767 additions and 135 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### v4.3.0

- [feat] Integrated selected functionalities with Snowtrace.io
- [update] Set transaction explanation feature to be off by default
- [feat] Enabled support for decompilation via bytecode MD5 in Dedaub

### v4.2.0

- [feat] Adaptation to Tronscan implemented
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For up to the minute news, follow our [Twitter](https://twitter.com/MetaDockTeam

## Building

- Install [Node.js](https://nodejs.org) version 16 or later
- Install [Node.js](https://nodejs.org) version 18.12.0 or later
- If you are using [nvm](https://github.com/nvm-sh/nvm#installing-and-updating) (recommended) running `nvm use` will automatically choose the right node version for you.
- Install [Yarn](https://yarnpkg.com/en/docs/install)
- Xcode (for building the Safari package)
Expand Down Expand Up @@ -107,8 +107,6 @@ Whenever you change dependencies (adding, removing, or updating, either in `pack
- [x] Show evm.storage shortcut
- [x] Show transaction simulator
- [x] Show Variable Logs
- [ ] Show token marketplaces
- [ ] Sandwich Attack Risk Detection

## Supported Websites List

Expand All @@ -123,6 +121,7 @@ Whenever you change dependencies (adding, removing, or updating, either in `pack
- snowtrace.io
- optimistic.etherscan.io
- opensea.io
- tronscan.org

## Changelog

Expand Down
6 changes: 3 additions & 3 deletions manifest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineManifest((env: ConfigEnv) => {
return {
name: "MetaDock - Builders' Swiss Army Knife",
description:
'Improve the usability of blockchain explorers, including BTC.com, Etherscan, BscScan, and *scans of most EVM-compatible chains.',
'Integrating 30+ popular Web3 and AI Tools, 300M+ Address Labels, and the Fund Flow Map into a single extension.',
version: version,
manifest_version: 3,
icons: {
Expand All @@ -27,7 +27,6 @@ export default defineManifest((env: ConfigEnv) => {
'*://*.etherscan.com/*',
'*://*.bscscan.com/*',
'*://*.polygonscan.com/*',
'*://*.snowtrace.io/*',
'*://optimistic.etherscan.io/*',
'*://*.arbiscan.io/*',
'*://*.ftmscan.com/*',
Expand All @@ -49,7 +48,8 @@ export default defineManifest((env: ConfigEnv) => {
? [
'*://explorer.btc.com/*',
'*://*.opensea.io/*',
'*://*.tronscan.org/*'
'*://*.tronscan.org/*',
'*://*.snowtrace.io/*'
]
: ['<all_urls>'],
js: ['src/content/index.ts'],
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "metadock",
"version": "4.2.0",
"version": "4.3.0",
"repository": {
"type": "git",
"url": "https://github.com/blocksecteam/metadock.git"
},
"engines": {
"node": ">=18.12.0"
},
"type": "module",
"scripts": {
"dev": "vite --mode development",
Expand Down
23 changes: 11 additions & 12 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
EXECUTE_BTC_CONTENT_SCRIPT,
GET_TOKEN_APPROVAL_DATATABLE,
GET_TOKEN_APPROVAL_ERC20_FILTER,
EXECUTE_TRON_CONTENT_SCRIPT,
TRONSCAN_TABS_CHANGED,
LOAD_TRON_APPROVALS,
TRONSCAN_MULTI_SEARCH
TRONSCAN_MULTI_SEARCH,
URL_UPDATED
} from '@common/constants'

import { initBackgroundRequest } from './listeners'
Expand All @@ -20,6 +20,15 @@ chromeEvent.on(REFRESH, () => {
reloadCurrentTab()
})

/** url updated (spa) */
browser.tabs.onUpdated.addListener(function (tabId, changeInfo) {
if (changeInfo.url) {
if (tabId) {
browser.tabs.sendMessage(tabId, URL_UPDATED).catch(() => void 0)
}
}
})

/** reload BTC content script */
browser.webRequest.onCompleted.addListener(
async details => {
Expand Down Expand Up @@ -77,16 +86,6 @@ browser.webRequest.onCompleted.addListener(
}
)

browser.tabs.onUpdated.addListener(function (tabId, changeInfo) {
if (changeInfo.url) {
if (tabId) {
browser.tabs
.sendMessage(tabId, EXECUTE_TRON_CONTENT_SCRIPT)
.catch(() => void 0)
}
}
})

browser.webRequest.onCompleted.addListener(
async details => {
const { tabId, method } = details
Expand Down
8 changes: 7 additions & 1 deletion src/common/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,11 @@ export default {
.post('api/v1/variable/list', {
json: params
})
.json<BscResponse<ContractVariableListItem[]>>()
.json<BscResponse<ContractVariableListItem[]>>(),
getSourceCodeMD5: (code: string) =>
request
.post('api/v1/source-code/hash', {
json: { code }
})
.json<BscResponse<string>>()
}
42 changes: 16 additions & 26 deletions src/common/components/CopyButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ interface Props extends BaseComponent {
mr?: number
hover?: boolean
placement?: 'left' | 'right'
theme?: string
}

const CopyButton: FC<PropsWithChildren<Props>> = ({
theme,
text = '',
size = 16,
ml,
Expand Down Expand Up @@ -86,12 +84,6 @@ const CopyButton: FC<PropsWithChildren<Props>> = ({
isPureComponent ? style : {}
)

const _theme = theme
? theme
: window.location.host.includes('etherscan')
? 'var(--bs-primary)'
: 'var(--primary)'

const containerStyle: CSSProperties = Object.assign(
{
display: !isPureComponent ? 'inline-block' : 'contents'
Expand All @@ -118,40 +110,38 @@ const CopyButton: FC<PropsWithChildren<Props>> = ({
style={iconContainerStyle}
>
<svg
className={styles.iconCopy}
// @ts-ignore
t="1669358941076"
viewBox="0 0 1024 1024"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
p-id="1754"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className={styles.iconCopy}
width={size}
height={size}
// @ts-ignore
onClick={onCopy}
>
<path
fill={_theme}
d="M832 64H296a8 8 0 0 0-8 8V128c0 4.416 3.584 8 8 8h496v688c0 4.416 3.584 8 8 8h56a8 8 0 0 0 8-8V96A32 32 0 0 0 832 64z m-128 128H192a32 32 0 0 0-32 32v530.688a32 32 0 0 0 9.408 22.592l173.312 173.312a33.088 33.088 0 0 0 7.36 5.504v1.92h4.224c3.52 1.28 7.168 1.984 11.008 1.984H704a32 32 0 0 0 32-32v-704A32 32 0 0 0 704 192zM382.016 896h-0.192l-149.824-149.76v-0.256h150.016V896z"
p-id="1755"
strokeLinecap="round"
strokeLinejoin="round"
d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 0 1-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 0 1 1.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 0 0-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 0 1-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H9.75"
/>
</svg>

<svg
className={styles.iconSuccess}
// @ts-ignore
t="1669359261894"
viewBox="0 0 1024 1024"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
p-id="1900"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className={styles.iconSuccess}
width={size}
height={size}
>
<path
fill={_theme}
d="M512 64a448 448 0 1 0 0 896A448 448 0 0 0 512 64z m193.472 301.696l-210.56 292.032a31.808 31.808 0 0 1-51.712 0l-124.672-172.8a8 8 0 0 1 6.464-12.736h46.912c10.24 0 19.84 4.928 25.92 13.312L468.992 584.32l157.184-218.048a32 32 0 0 1 25.92-13.248h46.912c6.464 0 10.24 7.36 6.464 12.672z"
p-id="1901"
strokeLinecap="round"
strokeLinejoin="round"
d="m4.5 12.75 6 6 9-13.5"
/>
</svg>
</div>
Expand Down
2 changes: 0 additions & 2 deletions src/common/components/DrawerSimulation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ const DrawerSimulation: FC<Props> = ({
}}
>
<CopyButton
theme="#1677ff"
text={() =>
form.getFieldValue([
'parameters',
Expand All @@ -631,7 +630,6 @@ const DrawerSimulation: FC<Props> = ({
}
)}
<CopyButton
theme="#1677ff"
ml={4}
className={styles.copyCallDataBtn}
text={() =>
Expand Down
4 changes: 2 additions & 2 deletions src/common/config/allowlist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export default {
ETHERSCAN_V1_MATCHES: [
'*://zkevm.polygonscan.com/*',
'*://*.snowtrace.io/*',
'*://optimistic.etherscan.io/*',
'*://*.arbiscan.io/*',
'*://testnet.ftmscan.com/*',
Expand Down Expand Up @@ -35,5 +34,6 @@ export default {
BTC_EXPLORER_MATCHES: ['*://explorer.btc.com/*'],
BLOCKSEC_MATCHES: ['*://*.blocksec.com/*'],
OPENSEA_MATCHES: ['*://*.opensea.io/*'],
TRONSCAN_MATCHES: ['*://*.tronscan.org/*']
TRONSCAN_MATCHES: ['*://*.tronscan.org/*'],
SNOWTRACE_MATCHES: ['*://*.snowtrace.io/*']
}
2 changes: 1 addition & 1 deletion src/common/constants/event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const REFRESH = 'refresh'
export const URL_UPDATED = 'urlUpdated'
export const GET_ADDRESS_RISK_SCORE = 'getAddressRiskScore'
export const GET_ADDRESS_LABELS = 'getAddressLabels'
export const GET_ADDRESS_METHODS = 'getAddressMethods'
Expand Down Expand Up @@ -31,7 +32,6 @@ export const GET_LATEST_BLOCK = 'getLatestBlock'
export const GET_CONTRACT_VARIABLE_LOGS = 'getContractVariableLogs'
export const GET_CREATION_BLOCK = 'getCreationBlock'
export const GET_CONTRACT_VARIABLE_LIST = 'getContractVariableList'
export const EXECUTE_TRON_CONTENT_SCRIPT = 'executeTronContentScript'
export const LOAD_TRON_APPROVALS = 'loadTronApprovals'
export const TRONSCAN_TABS_CHANGED = 'tronscanTabsChanged'
export const TRONSCAN_MULTI_SEARCH = 'tronscanMultiSearch'
22 changes: 11 additions & 11 deletions src/common/constants/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ export const EXT_SUPPORT_WEB_LIST: ExtSupportWebsite[] = [
chain: 'avalanche',
domains: ['snowtrace.io'],
siteName: 'ETHERSCAN',
logo: 'https://assets.blocksec.com/image/1671777583236-3.png',
testNets: [
{
name: 'Avalanche Fuji',
chainID: 43_113,
chain: 'fuji.avalanche',
domains: ['testnet.snowtrace.io'],
siteName: 'ETHERSCAN',
logo: 'https://assets.blocksec.com/image/1671777583236-3.png'
}
]
logo: 'https://assets.blocksec.com/image/1671777583236-3.png'
// testNets: [
// {
// name: 'Avalanche Fuji',
// chainID: 43_113,
// chain: 'fuji.avalanche',
// domains: ['testnet.snowtrace.io'],
// siteName: 'ETHERSCAN',
// logo: 'https://assets.blocksec.com/image/1671777583236-3.png'
// }
// ]
},
{
name: 'Optimism',
Expand Down
28 changes: 20 additions & 8 deletions src/content/etherscan/components/DecompileInDedaubBtn/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { type FC } from 'react'
import { type FC, useState } from 'react'
import $ from 'jquery'

import { DEDAUB_SUPPORT_DIRECT_LIST } from '@common/constants'
import { getImageUrl } from '@common/utils'
import { LoadingOutlined } from '@common/components'

import Button from '../Button'

Expand All @@ -11,6 +13,8 @@ interface Props {
}

const DecompileInDedaubBtn: FC<Props> = ({ mainAddress, chain }) => {
const [loading, setLoading] = useState(false)

const toDedaub = () => {
const item = DEDAUB_SUPPORT_DIRECT_LIST.find(item => item.chain === chain)

Expand All @@ -20,14 +24,15 @@ const DecompileInDedaubBtn: FC<Props> = ({ mainAddress, chain }) => {
)
} else {
const url = 'https://library.dedaub.com/api/on_demand'
const bytecode = document.getElementById('dividcode')
if (bytecode == null) {
const bytecode = $('#dividcode').text().trim()
if (!bytecode) {
window.open('https://library.dedaub.com/decompile')
return
}
const data = {
hex_bytecode: bytecode.innerText
hex_bytecode: bytecode
}
setLoading(true)
fetch(url, {
method: 'POST',
headers: {
Expand All @@ -41,15 +46,16 @@ const DecompileInDedaubBtn: FC<Props> = ({ mainAddress, chain }) => {
})
.then(response => response.text())
.then(data => {
console.log('Success:', data)
window.open(
'https://library.dedaub.com/decompile?md5=' + data.replace(/"/g, '')
)
})
.catch(error => {
console.error('Error:', error)
.catch(() => {
window.open('https://library.dedaub.com/decompile')
})
.finally(() => {
setLoading(false)
})
}
}

Expand All @@ -58,7 +64,13 @@ const DecompileInDedaubBtn: FC<Props> = ({ mainAddress, chain }) => {
style={{ width: 'fit-content' }}
theme="#EFE6DA"
fontColor="#000"
icon={<img src={getImageUrl('dedaub')} alt="" />}
icon={
loading ? (
<LoadingOutlined />
) : (
<img src={getImageUrl('dedaub')} alt="" />
)
}
onClick={toDedaub}
>
Decompile in Dedaub
Expand Down
28 changes: 28 additions & 0 deletions src/content/etherscan/components/ExplainBtn/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { type FC, useState } from 'react'
import cls from 'classnames'

import { TokenSymbol } from '@common/components'

interface Props {
onClick: () => void
}

const ExplainBtn: FC<Props> = ({ onClick }) => {
const [visible, setVisible] = useState(true)

return (
<button
className={cls('nav-link md-btn-primary')}
style={{ color: 'white', display: visible ? 'block' : 'none' }}
onClick={() => {
onClick()
setVisible(false)
}}
>
<TokenSymbol color="#fff" />
Explain with GPT
</button>
)
}

export default ExplainBtn
Loading

0 comments on commit 511cb96

Please sign in to comment.