From f4a1eefee1697913e327ca1541e4f13892f2578d Mon Sep 17 00:00:00 2001 From: Jordan Messina Date: Mon, 4 Dec 2023 22:24:37 -0500 Subject: [PATCH 1/3] Updated ENS and moved WETH constants --- src/helpers/constants.ts | 49 ++++------------------------------ src/protocol/ens/constants.ts | 35 ++++++++++++++++++++---- src/protocol/ens/registrar.ts | 36 ++++++++++++++----------- src/protocol/ens/reverse.ts | 22 ++++++++------- src/protocol/weth/constants.ts | 27 +++++++++++++++++++ src/protocol/weth/weth.ts | 4 +-- 6 files changed, 98 insertions(+), 75 deletions(-) create mode 100644 src/protocol/weth/constants.ts diff --git a/src/helpers/constants.ts b/src/helpers/constants.ts index 91ff8c6e..e9d8bb2d 100644 --- a/src/helpers/constants.ts +++ b/src/helpers/constants.ts @@ -1,52 +1,13 @@ import { InterfaceAbi } from '../types/Abi'; -export const TOKEN_SWAP_CONTRACTS = [ - '0xe592427a0aece92de3edee1f18e0157c05861564', // Uniswap V3 Router - '0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45', // Uniswap V3router2 - '0x7a250d5630b4cf539739df2c5dacb4c659f2488d', // Uniswap V2 Router2 - '0xef1c6e67703c7bd7107eed8303fbe6ec2554bf6b', // Uniswap Universal Router1 - '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad', // Uniswap Universal Router2 - '0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f', // Sushiswap Router - '0x1111111254fb6c44bac0bed2854e76f90643097d', // 1inch Router - '0x881d40237659c251811cec9c364ef91dc08d300c', // Metamask Swap Router - '0xe66b31678d6c16e9ebf358268a790b763c133750', // Coinbase Wallet Swapper - '0x00000000009726632680fb29d3f7a9734e3010e2', // Rainbow Router - '0xdef1c0ded9bec7f1a1670819833240f027b25eff', // 0x Exchange Proxy. NOTE - This is both an erc20 swap and erc721 swap contract. This address is in both contract lists. +export const WETH_ADDRESSES = [ + '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // Ethereum + '0x4200000000000000000000000000000000000006', // OP Stack + '0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f', // Linea + '0x0000000000a39bb272e79075ade125fd351887ac', // Blur ]; export const KNOWN_ADDRESSES = { NULL: '0x0000000000000000000000000000000000000000', WETH: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', }; - -export const WETH_ADDRESSES = [ - '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // Ethereum - '0x4200000000000000000000000000000000000006', // Optimism - '0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f', // Linea - '0x0000000000a39bb272e79075ade125fd351887ac', // Blur -]; -export const WETH_ABI: InterfaceAbi = [ - { - constant: false, - inputs: [], - name: 'deposit', - outputs: [], - payable: true, - stateMutability: 'payable', - type: 'function', - }, - { - constant: false, - inputs: [ - { - name: 'wad', - type: 'uint256', - }, - ], - name: 'withdraw', - outputs: [], - payable: false, - stateMutability: 'nonpayable', - type: 'function', - }, -]; diff --git a/src/protocol/ens/constants.ts b/src/protocol/ens/constants.ts index 45fedcf2..f1f709b8 100644 --- a/src/protocol/ens/constants.ts +++ b/src/protocol/ens/constants.ts @@ -1,7 +1,32 @@ export const ENSContracts = { - RegistrarV2: '0x283af0b28c62c092c9727f1ee09c02ca627eb7f5', - RegistrarV3: '0x253553366da8546fc250f225fe3d25d0c782303b', - ReverseRegistrar: '0x084b1c3c81545d370f3634392de611caabff8148', - Token: '0xc18360217d8f7ab5e7c516566761ea12ce7f9d72', - Reverse: '0x084b1c3c81545d370f3634392de611caabff8148', + RegistrarV2: { + address: '0x283af0b28c62c092c9727f1ee09c02ca627eb7f5', + abi: [ + 'commit(bytes32 commitment)', + 'register(string name, address owner, uint256 duration, bytes32 secret)', + 'registerWithConfig(string name, address owner, uint256 duration, bytes32 secret, address resolver, address addr)', + 'renew(string name, uint256 duration)', + ], + }, + RegistrarV3: { + address: '0x253553366da8546fc250f225fe3d25d0c782303b', + abi: [ + 'commit(bytes32 commitment)', + 'register(string name, address owner, uint256 duration, bytes32 secret)', + 'registerWithConfig(string name, address owner, uint256 duration, bytes32 secret, address resolver, address addr)', + 'renew(string name, uint256 duration)', + ], + }, + ReverseRegistrar: { + address: '0x084b1c3c81545d370f3634392de611caabff8148', + abi: [], + }, + Token: { + address: '0xc18360217d8f7ab5e7c516566761ea12ce7f9d72', + abi: [], + }, + Reverse: { + address: '0x084b1c3c81545d370f3634392de611caabff8148', + abi: ['setName(string name)'], + }, }; diff --git a/src/protocol/ens/registrar.ts b/src/protocol/ens/registrar.ts index 75dc5b47..6ef32978 100644 --- a/src/protocol/ens/registrar.ts +++ b/src/protocol/ens/registrar.ts @@ -1,5 +1,6 @@ import { Transaction } from '../../types'; import { ENSContracts } from './constants'; +import { decodeTransactionInput } from '../../helpers/utils'; export const ensContextualizer = (transaction: Transaction): Transaction => { const isENS = detectENS(transaction); @@ -9,22 +10,23 @@ export const ensContextualizer = (transaction: Transaction): Transaction => { }; export const detectENS = (transaction: Transaction): boolean => { - if (transaction.decode === null) { - return false; - } - if ( - transaction.to !== ENSContracts.RegistrarV2 && - transaction.to !== ENSContracts.RegistrarV3 + transaction.to !== ENSContracts.RegistrarV2.address && + transaction.to !== ENSContracts.RegistrarV3.address ) { return false; } + const decode = decodeTransactionInput( + transaction.input, + ENSContracts.RegistrarV2.abi, + ); + if ( - transaction.decode.name !== 'registerWithConfig' && - transaction.decode.name !== 'register' && - transaction.decode.name !== 'commit' && - transaction.decode.name !== 'renew' + decode.name !== 'registerWithConfig' && + decode.name !== 'register' && + decode.name !== 'commit' && + decode.name !== 'renew' ) { return false; } @@ -34,11 +36,15 @@ export const detectENS = (transaction: Transaction): boolean => { // Contextualize for mined txs export const generateENSContext = (transaction: Transaction): Transaction => { - switch (transaction.decode.name) { + const decode = decodeTransactionInput( + transaction.input, + ENSContracts.RegistrarV2.abi, + ); + switch (decode.name) { case 'registerWithConfig': case 'register': { - const name = transaction.decode.args[0]; - const duration = parseInt(transaction.decode.args[2]); + const name = decode.args[0]; + const duration = parseInt(decode.args[2]); const durationInDays = Math.trunc(duration / 60 / 60 / 24); transaction.context = { @@ -101,8 +107,8 @@ export const generateENSContext = (transaction: Transaction): Transaction => { } case 'renew': { - const name = transaction.decode.args[0]; - const duration = parseInt(transaction.decode.args[1]); + const name = decode.args[0]; + const duration = parseInt(decode.args[1]); const durationInDays = Math.trunc(duration / 60 / 60 / 24); transaction.context = { diff --git a/src/protocol/ens/reverse.ts b/src/protocol/ens/reverse.ts index f32b422b..08926f1c 100644 --- a/src/protocol/ens/reverse.ts +++ b/src/protocol/ens/reverse.ts @@ -1,5 +1,6 @@ import { Transaction } from '../../types'; import { ENSContracts } from './constants'; +import { decodeTransactionInput } from '../../helpers/utils'; export const ensReverseContextualizer = ( transaction: Transaction, @@ -11,29 +12,32 @@ export const ensReverseContextualizer = ( }; export const detectReverseENS = (transaction: Transaction): boolean => { - if (transaction.decode === null) { + if (transaction.to !== ENSContracts.Reverse.address) { return false; } - if (transaction.to !== ENSContracts.Reverse) { - return false; - } + const decode = decodeTransactionInput( + transaction.input, + ENSContracts.Reverse.abi, + ); - if (transaction.decode.name !== 'setName') { + if (decode.name !== 'setName') { return false; } return true; }; -// Contextualize for mined txs export const generateENSReverseContext = ( transaction: Transaction, ): Transaction => { - // Note: This isn't necessary now that we check for this in detect, but that's okay for now - switch (transaction.decode.name) { + const decode = decodeTransactionInput( + transaction.input, + ENSContracts.Reverse.abi, + ); + switch (decode.name) { case 'setName': { - const name = transaction.decode.args[0]; + const name = decode.args[0]; transaction.context = { summaries: { category: 'IDENTITY', diff --git a/src/protocol/weth/constants.ts b/src/protocol/weth/constants.ts new file mode 100644 index 00000000..8b7dcc56 --- /dev/null +++ b/src/protocol/weth/constants.ts @@ -0,0 +1,27 @@ +import { InterfaceAbi } from 'src/types/Abi'; + +export const WETH_ABI: InterfaceAbi = [ + { + constant: false, + inputs: [], + name: 'deposit', + outputs: [], + payable: true, + stateMutability: 'payable', + type: 'function', + }, + { + constant: false, + inputs: [ + { + name: 'wad', + type: 'uint256', + }, + ], + name: 'withdraw', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, +]; diff --git a/src/protocol/weth/weth.ts b/src/protocol/weth/weth.ts index 3499e72f..127663e4 100644 --- a/src/protocol/weth/weth.ts +++ b/src/protocol/weth/weth.ts @@ -1,6 +1,6 @@ -import { ethers } from 'ethers'; import { Transaction } from '../../types'; -import { WETH_ADDRESSES, WETH_ABI } from '../../helpers/constants'; +import { WETH_ADDRESSES } from '../../helpers/constants'; +import { WETH_ABI } from './constants'; import { decodeTransactionInput } from '../../helpers/utils'; export const wethContextualizer = (transaction: Transaction): Transaction => { From a6c4cd686ca04f3ba415e27d0471d6e535273422 Mon Sep 17 00:00:00 2001 From: Jordan Messina Date: Mon, 4 Dec 2023 22:27:58 -0500 Subject: [PATCH 2/3] Updated abi --- src/protocol/ens/constants.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/protocol/ens/constants.ts b/src/protocol/ens/constants.ts index f1f709b8..0e60248f 100644 --- a/src/protocol/ens/constants.ts +++ b/src/protocol/ens/constants.ts @@ -2,19 +2,19 @@ export const ENSContracts = { RegistrarV2: { address: '0x283af0b28c62c092c9727f1ee09c02ca627eb7f5', abi: [ - 'commit(bytes32 commitment)', - 'register(string name, address owner, uint256 duration, bytes32 secret)', - 'registerWithConfig(string name, address owner, uint256 duration, bytes32 secret, address resolver, address addr)', - 'renew(string name, uint256 duration)', + 'function commit(bytes32 commitment)', + 'function register(string name, address owner, uint256 duration, bytes32 secret)', + 'function registerWithConfig(string name, address owner, uint256 duration, bytes32 secret, address resolver, address addr)', + 'function renew(string name, uint256 duration)', ], }, RegistrarV3: { address: '0x253553366da8546fc250f225fe3d25d0c782303b', abi: [ - 'commit(bytes32 commitment)', - 'register(string name, address owner, uint256 duration, bytes32 secret)', - 'registerWithConfig(string name, address owner, uint256 duration, bytes32 secret, address resolver, address addr)', - 'renew(string name, uint256 duration)', + 'function commit(bytes32 commitment)', + 'function register(string name, address owner, uint256 duration, bytes32 secret)', + 'function registerWithConfig(string name, address owner, uint256 duration, bytes32 secret, address resolver, address addr)', + 'function renew(string name, uint256 duration)', ], }, ReverseRegistrar: { @@ -27,6 +27,6 @@ export const ENSContracts = { }, Reverse: { address: '0x084b1c3c81545d370f3634392de611caabff8148', - abi: ['setName(string name)'], + abi: ['function setName(string name)'], }, }; From 017e00662df7aa275c5c70f31e891dc3b60aaea4 Mon Sep 17 00:00:00 2001 From: Jordan Messina Date: Mon, 4 Dec 2023 22:36:23 -0500 Subject: [PATCH 3/3] catch errors --- src/protocol/ens/registrar.ts | 13 +++++++++---- src/protocol/ens/reverse.ts | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/protocol/ens/registrar.ts b/src/protocol/ens/registrar.ts index 6ef32978..41d395ad 100644 --- a/src/protocol/ens/registrar.ts +++ b/src/protocol/ens/registrar.ts @@ -17,10 +17,15 @@ export const detectENS = (transaction: Transaction): boolean => { return false; } - const decode = decodeTransactionInput( - transaction.input, - ENSContracts.RegistrarV2.abi, - ); + let decode; + try { + decode = decodeTransactionInput( + transaction.input, + ENSContracts.RegistrarV2.abi, + ); + } catch (e) { + return false; + } if ( decode.name !== 'registerWithConfig' && diff --git a/src/protocol/ens/reverse.ts b/src/protocol/ens/reverse.ts index 08926f1c..38e99db7 100644 --- a/src/protocol/ens/reverse.ts +++ b/src/protocol/ens/reverse.ts @@ -16,10 +16,15 @@ export const detectReverseENS = (transaction: Transaction): boolean => { return false; } - const decode = decodeTransactionInput( - transaction.input, - ENSContracts.Reverse.abi, - ); + let decode; + try { + decode = decodeTransactionInput( + transaction.input, + ENSContracts.Reverse.abi, + ); + } catch (e) { + return false; + } if (decode.name !== 'setName') { return false;