From 5eed15299591ae32dab3494564ad85327111e91b Mon Sep 17 00:00:00 2001 From: ponyjackal Date: Tue, 21 May 2024 03:47:50 -0700 Subject: [PATCH 1/2] feat: add failing unit test for uniswapV3Pair --- .../protocol/uniswapV3/uniswapV3Pair.spec.ts | 13 + .../uniswapV3Pair-0xcc883774.json | 739 ++++++++++++++++++ 2 files changed, 752 insertions(+) create mode 100644 src/contextualizers/test/transactions/uniswapV3Pair-0xcc883774.json diff --git a/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.spec.ts b/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.spec.ts index ced25f8c..53ba0541 100644 --- a/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.spec.ts +++ b/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.spec.ts @@ -3,6 +3,7 @@ import { detect, generate } from './uniswapV3Pair'; import { containsBigInt, contextSummary } from '../../../helpers/utils'; import uniswapV30xc5a57ee5 from '../../test/transactions/uniswapV3-0xc5a57ee5.json'; import uniswapV3Pair0x6953c36b from '../../test/transactions/uniswapV3Pair-0x6953c36b.json'; +import uniswapV3Pair0xcc883774 from '../../test/transactions/uniswapV3Pair-0xcc883774.json'; import catchall0xc35c01ac from '../../test/transactions/catchall-0xc35c01ac.json'; describe('Uniswap', () => { @@ -12,6 +13,9 @@ describe('Uniswap', () => { const swap2 = detect(uniswapV3Pair0x6953c36b as unknown as Transaction); expect(swap2).toBe(true); + + const swap3 = detect(uniswapV3Pair0xcc883774 as unknown as Transaction); + expect(swap3).toBe(true); }); it('Should generate context for uniswap v3 swap', () => { @@ -32,6 +36,15 @@ describe('Uniswap', () => { '0x6f1cdbbb4d53d226cf4b917bf768b94acbab6168 swapped 56625778127422422604 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 for 198805648076 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', ); expect(containsBigInt(swap2.context)).toBe(false); + + const swap3 = generate(uniswapV3Pair0xcc883774 as unknown as Transaction); + expect(swap3.context?.summaries?.category).toBe('PROTOCOL_1'); + expect(swap3.context?.summaries?.en.title).toBe('Uniswap'); + const desc3 = contextSummary(swap3.context); + expect(desc3).toBe( + '0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4 swapped 50000000000000000 0x4200000000000000000000000000000000000006 for 9670369113186014800347 0x4ed4e862860bed51a9570b96d89af5e1b0efefed', + ); + expect(containsBigInt(swap3.context)).toBe(false); }); it('Should not detect as UniswapV3', () => { diff --git a/src/contextualizers/test/transactions/uniswapV3Pair-0xcc883774.json b/src/contextualizers/test/transactions/uniswapV3Pair-0xcc883774.json new file mode 100644 index 00000000..e3189a23 --- /dev/null +++ b/src/contextualizers/test/transactions/uniswapV3Pair-0xcc883774.json @@ -0,0 +1,739 @@ +{ + "_id": "664be1fc461e9f749280d051", + "blockHash": "0x288b353222c96edbff7730ad1120d8881a12edc77eaba390aebd854530603a68", + "blockNumber": 14729866, + "from": "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8", + "gas": 500000, + "gasPrice": "53170612", + "maxFeePerGas": "2000000000", + "maxPriorityFeePerGas": "100", + "hash": "0xcc88018f41daeea44774dd0ea38d3aa11213843d09e099a6f7f849ab60ca3774", + "input": "0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000664be23200000000000000000000000000000000000000000000000000000000000000020b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000b1a2bc2ec500000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000b1a2bc2ec50000000000000000000000000000000000000000000000000205844006b70f80000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002b4200000000000000000000000000000000000006000bb84ed4e862860bed51a9570b96d89af5e1b0efefed000000000000000000000000000000000000000000", + "nonce": 1722, + "to": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "transactionIndex": 56, + "value": "50000000000000000", + "type": 2, + "accessList": [], + "chainId": 8453, + "v": "0x0", + "r": "0x6833a6bffa3d761dcb9ab5dd9b03a5bb450b0e67ade0dc094d9e7cb07307d3a", + "s": "0x78cf0a7194b486a1206b451832d3451e3dec3b6837eeecf48ec88e098f5384a1", + "yParity": "0x0", + "receipt": { + "blockHash": "0x288b353222c96edbff7730ad1120d8881a12edc77eaba390aebd854530603a68", + "blockNumber": 14729866, + "contractAddress": null, + "cumulativeGasUsed": 10475715, + "effectiveGasPrice": 53170612, + "from": "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8", + "gasUsed": 114010, + "l1Fee": "0x157238713e", + "l1GasPrice": "0x3bc03f074", + "l1GasUsed": "0x1460", + "logsBloom": "0x00400000000000000000008000000000040000000000000000040000000000000000000000000000000000100000000000000000000020000000000004000400000000000000000800000008000000000000000000010000000000008000000000000000000000000008000000000000000001000000000000000010000800000000000000000000000000000000000000000005002000000000000000004008000000000000000000000100000040000000000020000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000400000000000000000", + "status": true, + "to": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "transactionHash": "0xcc88018f41daeea44774dd0ea38d3aa11213843d09e099a6f7f849ab60ca3774", + "transactionIndex": 56, + "type": "0x2", + "logs": [ + { + "_id": "664be1fc461e9f749280cf40", + "address": "0x4200000000000000000000000000000000000006", + "data": "0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000", + "blockNumber": 14729866, + "transactionHash": "0xcc88018f41daeea44774dd0ea38d3aa11213843d09e099a6f7f849ab60ca3774", + "transactionIndex": 56, + "blockHash": "0x288b353222c96edbff7730ad1120d8881a12edc77eaba390aebd854530603a68", + "logIndex": 248, + "removed": false, + "id": "log_41e11ac8", + "decoded": { + "signature": "Deposit(address,uint256)", + "signature_with_arg_names": "Deposit(address indexed user,uint256 amount)", + "name": "Deposit", + "decoded": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address", + "decoded": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256", + "decoded": "50000000000000000" + } + ] + }, + "topic0": "0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c", + "topic1": "0x000000000000000000000000ec8b0f7ffe3ae75d7ffab09429e3675bb63503e4" + }, + { + "_id": "664be1fc461e9f749280cf41", + "address": "0x4ed4e862860bed51a9570b96d89af5e1b0efefed", + "data": "0x00000000000000000000000000000000000000000000020c3b54a0a199ab29db", + "blockNumber": 14729866, + "transactionHash": "0xcc88018f41daeea44774dd0ea38d3aa11213843d09e099a6f7f849ab60ca3774", + "transactionIndex": 56, + "blockHash": "0x288b353222c96edbff7730ad1120d8881a12edc77eaba390aebd854530603a68", + "logIndex": 249, + "removed": false, + "id": "log_0ef7125c", + "decoded": { + "signature": "Transfer(address,address,uint256)", + "signature_with_arg_names": "Transfer(address indexed from,address indexed to,uint256 value)", + "name": "Transfer", + "decoded": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address", + "decoded": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address", + "decoded": "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256", + "decoded": "9670369113186014800347" + } + ] + }, + "topic0": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "topic1": "0x000000000000000000000000c9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "topic2": "0x0000000000000000000000001e474b50bdc2b39dccaa2b8ddf37b3f022b128a8" + }, + { + "_id": "664be1fc461e9f749280cf42", + "address": "0x4200000000000000000000000000000000000006", + "data": "0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000", + "blockNumber": 14729866, + "transactionHash": "0xcc88018f41daeea44774dd0ea38d3aa11213843d09e099a6f7f849ab60ca3774", + "transactionIndex": 56, + "blockHash": "0x288b353222c96edbff7730ad1120d8881a12edc77eaba390aebd854530603a68", + "logIndex": 250, + "removed": false, + "id": "log_3a4d3cd2", + "decoded": { + "signature": "Transfer(address,address,uint256)", + "signature_with_arg_names": "Transfer(address indexed from,address indexed to,uint256 value)", + "name": "Transfer", + "decoded": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address", + "decoded": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address", + "decoded": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256", + "decoded": "50000000000000000" + } + ] + }, + "topic0": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "topic1": "0x000000000000000000000000ec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "topic2": "0x000000000000000000000000c9034c3e7f58003e6ae0c8438e7c8f4598d5acaa" + }, + { + "_id": "664be1fc461e9f749280cf43", + "address": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "data": "0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000fffffffffffffffffffffffffffffffffffffffffffffdf3c4ab5f5e6654d62500000000000000000000000000000000000001b8704a49489c186f5f80535d62000000000000000000000000000000000000000000011d615fdd9891a40d4162000000000000000000000000000000000000000000000000000000000001dba1", + "blockNumber": 14729866, + "transactionHash": "0xcc88018f41daeea44774dd0ea38d3aa11213843d09e099a6f7f849ab60ca3774", + "transactionIndex": 56, + "blockHash": "0x288b353222c96edbff7730ad1120d8881a12edc77eaba390aebd854530603a68", + "logIndex": 251, + "removed": false, + "id": "log_ccf1c7b3", + "decoded": { + "signature": "Swap(address,address,int256,int256,uint160,uint128,int24)", + "signature_with_arg_names": "Swap(address indexed sender,address indexed recipient,int256 amount0,int256 amount1,uint160 sqrtPriceX96,uint128 liquidity,int24 tick)", + "name": "Swap", + "decoded": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address", + "decoded": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4" + }, + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address", + "decoded": "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8" + }, + { + "indexed": false, + "internalType": "int256", + "name": "amount0", + "type": "int256", + "decoded": "50000000000000000" + }, + { + "indexed": false, + "internalType": "int256", + "name": "amount1", + "type": "int256", + "decoded": "-9670369113186014800347" + }, + { + "indexed": false, + "internalType": "uint160", + "name": "sqrtPriceX96", + "type": "uint160", + "decoded": "34895143633959117356731953536354" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "liquidity", + "type": "uint128", + "decoded": "1347670689638153458631010" + }, + { + "indexed": false, + "internalType": "int24", + "name": "tick", + "type": "int24", + "decoded": "121761" + } + ] + }, + "topic0": "0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67", + "topic1": "0x000000000000000000000000ec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "topic2": "0x0000000000000000000000001e474b50bdc2b39dccaa2b8ddf37b3f022b128a8" + } + ] + }, + "decoded": null, + "pseudoTransactions": [], + "assetTransfers": [ + { + "from": "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8", + "to": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "type": "eth", + "value": "50000000000000000" + }, + { + "from": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "to": "0x4200000000000000000000000000000000000006", + "type": "eth", + "value": "50000000000000000" + }, + { + "contract": "0x4200000000000000000000000000000000000006", + "from": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "to": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "value": "50000000000000000", + "type": "erc20" + }, + { + "contract": "0x4ed4e862860bed51a9570b96d89af5e1b0efefed", + "from": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "to": "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8", + "value": "9670369113186014800347", + "type": "erc20" + } + ], + "delegateCalls": [], + "errors": [], + "parties": [ + "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8", + "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "0x4200000000000000000000000000000000000006", + "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "0x4ed4e862860bed51a9570b96d89af5e1b0efefed" + ], + "sigHash": "0x3593564c", + "internalSigHashes": [ + { + "from": "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8", + "to": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "sigHash": "0x3593564c" + }, + { + "from": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "to": "0x4200000000000000000000000000000000000006", + "sigHash": "0xd0e30db0" + }, + { + "from": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "to": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "sigHash": "0x128acb08" + }, + { + "from": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "to": "0x4ed4e862860bed51a9570b96d89af5e1b0efefed", + "sigHash": "0xa9059cbb" + }, + { + "from": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "to": "0x4200000000000000000000000000000000000006", + "sigHash": "0x70a08231" + }, + { + "from": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "to": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "sigHash": "0xfa461e33" + }, + { + "from": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "to": "0x4200000000000000000000000000000000000006", + "sigHash": "0xa9059cbb" + }, + { + "from": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "to": "0x4200000000000000000000000000000000000006", + "sigHash": "0x70a08231" + } + ], + "timestamp": 1716249079, + "baseFeePerGas": 53170512, + "transactionFee": "6061981474120", + "logs": [ + { + "_id": "664be1fc461e9f749280cf40", + "address": "0x4200000000000000000000000000000000000006", + "data": "0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000", + "blockNumber": 14729866, + "transactionHash": "0xcc88018f41daeea44774dd0ea38d3aa11213843d09e099a6f7f849ab60ca3774", + "transactionIndex": 56, + "blockHash": "0x288b353222c96edbff7730ad1120d8881a12edc77eaba390aebd854530603a68", + "logIndex": 248, + "removed": false, + "id": "log_41e11ac8", + "decoded": { + "signature": "Deposit(address,uint256)", + "signature_with_arg_names": "Deposit(address indexed user,uint256 amount)", + "name": "Deposit", + "decoded": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address", + "decoded": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256", + "decoded": "50000000000000000" + } + ] + }, + "topic0": "0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c", + "topic1": "0x000000000000000000000000ec8b0f7ffe3ae75d7ffab09429e3675bb63503e4" + }, + { + "_id": "664be1fc461e9f749280cf41", + "address": "0x4ed4e862860bed51a9570b96d89af5e1b0efefed", + "data": "0x00000000000000000000000000000000000000000000020c3b54a0a199ab29db", + "blockNumber": 14729866, + "transactionHash": "0xcc88018f41daeea44774dd0ea38d3aa11213843d09e099a6f7f849ab60ca3774", + "transactionIndex": 56, + "blockHash": "0x288b353222c96edbff7730ad1120d8881a12edc77eaba390aebd854530603a68", + "logIndex": 249, + "removed": false, + "id": "log_0ef7125c", + "decoded": { + "signature": "Transfer(address,address,uint256)", + "signature_with_arg_names": "Transfer(address indexed from,address indexed to,uint256 value)", + "name": "Transfer", + "decoded": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address", + "decoded": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address", + "decoded": "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256", + "decoded": "9670369113186014800347" + } + ] + }, + "topic0": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "topic1": "0x000000000000000000000000c9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "topic2": "0x0000000000000000000000001e474b50bdc2b39dccaa2b8ddf37b3f022b128a8" + }, + { + "_id": "664be1fc461e9f749280cf42", + "address": "0x4200000000000000000000000000000000000006", + "data": "0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000", + "blockNumber": 14729866, + "transactionHash": "0xcc88018f41daeea44774dd0ea38d3aa11213843d09e099a6f7f849ab60ca3774", + "transactionIndex": 56, + "blockHash": "0x288b353222c96edbff7730ad1120d8881a12edc77eaba390aebd854530603a68", + "logIndex": 250, + "removed": false, + "id": "log_3a4d3cd2", + "decoded": { + "signature": "Transfer(address,address,uint256)", + "signature_with_arg_names": "Transfer(address indexed from,address indexed to,uint256 value)", + "name": "Transfer", + "decoded": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address", + "decoded": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address", + "decoded": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256", + "decoded": "50000000000000000" + } + ] + }, + "topic0": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "topic1": "0x000000000000000000000000ec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "topic2": "0x000000000000000000000000c9034c3e7f58003e6ae0c8438e7c8f4598d5acaa" + }, + { + "_id": "664be1fc461e9f749280cf43", + "address": "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa", + "data": "0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000fffffffffffffffffffffffffffffffffffffffffffffdf3c4ab5f5e6654d62500000000000000000000000000000000000001b8704a49489c186f5f80535d62000000000000000000000000000000000000000000011d615fdd9891a40d4162000000000000000000000000000000000000000000000000000000000001dba1", + "blockNumber": 14729866, + "transactionHash": "0xcc88018f41daeea44774dd0ea38d3aa11213843d09e099a6f7f849ab60ca3774", + "transactionIndex": 56, + "blockHash": "0x288b353222c96edbff7730ad1120d8881a12edc77eaba390aebd854530603a68", + "logIndex": 251, + "removed": false, + "id": "log_ccf1c7b3", + "decoded": { + "signature": "Swap(address,address,int256,int256,uint160,uint128,int24)", + "signature_with_arg_names": "Swap(address indexed sender,address indexed recipient,int256 amount0,int256 amount1,uint160 sqrtPriceX96,uint128 liquidity,int24 tick)", + "name": "Swap", + "decoded": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address", + "decoded": "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4" + }, + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address", + "decoded": "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8" + }, + { + "indexed": false, + "internalType": "int256", + "name": "amount0", + "type": "int256", + "decoded": "50000000000000000" + }, + { + "indexed": false, + "internalType": "int256", + "name": "amount1", + "type": "int256", + "decoded": "-9670369113186014800347" + }, + { + "indexed": false, + "internalType": "uint160", + "name": "sqrtPriceX96", + "type": "uint160", + "decoded": "34895143633959117356731953536354" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "liquidity", + "type": "uint128", + "decoded": "1347670689638153458631010" + }, + { + "indexed": false, + "internalType": "int24", + "name": "tick", + "type": "int24", + "decoded": "121761" + } + ] + }, + "topic0": "0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67", + "topic1": "0x000000000000000000000000ec8b0f7ffe3ae75d7ffab09429e3675bb63503e4", + "topic2": "0x0000000000000000000000001e474b50bdc2b39dccaa2b8ddf37b3f022b128a8" + } + ], + "netAssetTransfers": { + "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8": { + "received": [ + { + "contract": "0x4ed4e862860bed51a9570b96d89af5e1b0efefed", + "type": "erc20", + "value": "9670369113186014800347" + } + ], + "sent": [ + { + "type": "eth", + "value": "50000000000000000" + } + ] + }, + "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4": { + "received": [], + "sent": [ + { + "contract": "0x4200000000000000000000000000000000000006", + "type": "erc20", + "value": "50000000000000000" + } + ] + }, + "0x4200000000000000000000000000000000000006": { + "received": [ + { + "type": "eth", + "value": "50000000000000000" + } + ], + "sent": [] + }, + "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa": { + "received": [ + { + "contract": "0x4200000000000000000000000000000000000006", + "type": "erc20", + "value": "50000000000000000" + } + ], + "sent": [ + { + "contract": "0x4ed4e862860bed51a9570b96d89af5e1b0efefed", + "type": "erc20", + "value": "9670369113186014800347" + } + ] + } + }, + "pseudotransactions": [], + "contractsCreated": [], + "enrichedParties": { + "0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8": [ + { + "chainId": 0, + "isContract": false, + "ensNew": { + "handle": null, + "avatar": null + }, + "bns": { + "handle": null, + "avatar": null + }, + "farcaster": { + "handle": "bayardo", + "avatar": "https://i.imgur.com/iheCc5U.jpg", + "fid": 6394 + } + } + ], + "0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4": [ + { + "chainId": 10, + "label": { + "public": "" + }, + "isContract": true, + "imgUrl": "", + "decimals": 0, + "symbol": "", + "ensNew": { + "handle": null, + "avatar": null + }, + "bns": { + "handle": null, + "avatar": null + }, + "farcaster": { + "handle": null, + "avatar": null, + "fid": null + } + }, + { + "chainId": 8453, + "label": { + "public": "" + }, + "isContract": true, + "imgUrl": "", + "decimals": 0, + "symbol": "", + "ensNew": { + "handle": null, + "avatar": null + }, + "bns": { + "handle": null, + "avatar": null + }, + "farcaster": { + "handle": null, + "avatar": null, + "fid": null + } + } + ], + "0x4200000000000000000000000000000000000006": [ + { + "chainId": 10, + "label": { + "public": "WETH" + }, + "isContract": true, + "tokenStandard": "erc20", + "imgUrl": "", + "decimals": 18, + "symbol": "WETH", + "ensNew": { + "handle": null, + "avatar": null + }, + "bns": { + "handle": null, + "avatar": null + }, + "farcaster": { + "handle": null, + "avatar": null, + "fid": null + } + } + ], + "0xc9034c3e7f58003e6ae0c8438e7c8f4598d5acaa": [ + { + "chainId": 8453, + "label": { + "public": "" + }, + "isContract": true, + "imgUrl": "", + "decimals": 0, + "symbol": "", + "ensNew": { + "handle": null, + "avatar": null + }, + "bns": { + "handle": null, + "avatar": null + }, + "farcaster": { + "handle": null, + "avatar": null, + "fid": null + } + } + ], + "0x4ed4e862860bed51a9570b96d89af5e1b0efefed": [ + { + "chainId": 8453, + "label": { + "public": "Degen" + }, + "isContract": true, + "tokenStandard": "erc20", + "imgUrl": "", + "decimals": 18, + "symbol": "DEGEN", + "ensNew": { + "handle": null, + "avatar": null + }, + "bns": { + "handle": null, + "avatar": null + }, + "farcaster": { + "handle": null, + "avatar": null, + "fid": null + } + }, + { + "chainId": 84532, + "label": { + "public": "Degen" + }, + "isContract": true, + "tokenStandard": "erc20", + "imgUrl": "", + "decimals": "18", + "symbol": "DEGEN", + "ensNew": { + "handle": null, + "avatar": null + }, + "bns": { + "handle": null, + "avatar": null + }, + "farcaster": { + "handle": null, + "avatar": null, + "fid": null + } + } + ] + }, + "assetsEnriched": {} +} \ No newline at end of file From b55065bda03e4a9c67cc9a0c9257d22e7b6050de Mon Sep 17 00:00:00 2001 From: ponyjackal Date: Tue, 21 May 2024 05:03:36 -0700 Subject: [PATCH 2/2] feat: handle univeral router --- .../protocol/uniswapV3/constants.ts | 80 +++++++++++++++++++ .../protocol/uniswapV3/uniswapV3Pair.spec.ts | 4 +- .../protocol/uniswapV3/uniswapV3Pair.ts | 13 ++- 3 files changed, 92 insertions(+), 5 deletions(-) diff --git a/src/contextualizers/protocol/uniswapV3/constants.ts b/src/contextualizers/protocol/uniswapV3/constants.ts index 0160eaab..f2609118 100644 --- a/src/contextualizers/protocol/uniswapV3/constants.ts +++ b/src/contextualizers/protocol/uniswapV3/constants.ts @@ -1,3 +1,83 @@ import uniswapV3PairAbi from './abis/UniswapV3Pair'; export const UNISWAP_V3_PAIR_ABI = uniswapV3PairAbi; + +export const UNIVERSAL_ROUTERS = { + 42161: [ + '0x4c60051384bd2d3c01bfc845cf5f4b44bcbe9de5', + '0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4', + '0x5e325eda8064b456f4781070c0738d849c824258', + '0xef1c6e67703c7bd7107eed8303fbe6ec2554bf6b', + ], + 421613: [ + '0x4648a43b2c14da09fdf82b161150d3f634f40491', + '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad', + '0x5302086a3a25d473aabbd0356eff8dd811a4d89b', + ], + 43114: [ + '0x82635af6146972cd6601161c4472ffe97237d292', + '0x4dae2f939acf50408e13d58534ff8c2776d45265', + '0x5302086a3a25d473aabbd0356eff8dd811a4d89b', + ], + 8453: [ + '0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4', + '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad', + '0x9e18efb3be848940b0c92d300504fb08c287fe85', + ], + 84531: [ + '0xd0872d928672ae2ff74bdb2f5130ac12229cafaf', + '0x7b46ee9bab49bd5b37117494689a035b0f187b59', + ], + 56: [ + '0x5dc88340e1c5c6366864ee415d6034cadd1a9897', + '0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4', + '0x4dae2f939acf50408e13d58534ff8c2776d45265', + '0x5302086a3a25d473aabbd0356eff8dd811a4d89b', + ], + 44787: [ + '0x4648a43b2c14da09fdf82b161150d3f634f40491', + '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad', + '0x5302086a3a25d473aabbd0356eff8dd811a4d89b', + ], + 42220: [ + '0xc73d61d192fb994157168fb56730fdec64c9cb8f', + '0x643770e279d5d0733f21d6dc03a8efbabf3255b4', + '0x5dc88340e1c5c6366864ee415d6034cadd1a9897', + ], + 5: [ + '0x4648a43b2c14da09fdf82b161150d3f634f40491', + '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad', + '0x5302086a3a25d473aabbd0356eff8dd811a4d89b', + ], + 1: [ + '0xef1c6e67703c7bd7107eed8303fbe6ec2554bf6b', + '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad', + '0x76d631990d505e4e5b432eedb852a60897824d68', + ], + 420: [ + '0x4648a43b2c14da09fdf82b161150d3f634f40491', + '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad', + '0x5302086a3a25d473aabbd0356eff8dd811a4d89b', + ], + 10: [ + '0xb555edf5dcf85f42ceef1f3630a52a108e55a654', + '0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4', + '0xcb1355ff08ab38bbce60111f1bb2b784be25d7e8', + '0x40d51104da22e3e77b683894e7e3e12e8fc61e65', + ], + 80001: [ + '0x4648a43b2c14da09fdf82b161150d3f634f40491', + '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad', + '0x5302086a3a25d473aabbd0356eff8dd811a4d89b', + ], + 137: [ + '0x4c60051384bd2d3c01bfc845cf5f4b44bcbe9de5', + '0x643770e279d5d0733f21d6dc03a8efbabf3255b4', + '0xec7be89e9d109e7e3fec59c222cf297125fefda2', + '0xef1c6e67703c7bd7107eed8303fbe6ec2554bf6b', + ], + 11155111: [ + '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad', + '0x5302086a3a25d473aabbd0356eff8dd811a4d89b', + ], +}; diff --git a/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.spec.ts b/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.spec.ts index 53ba0541..333dfdea 100644 --- a/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.spec.ts +++ b/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.spec.ts @@ -24,7 +24,7 @@ describe('Uniswap', () => { expect(swap1.context?.summaries?.en.title).toBe('Uniswap'); const desc1 = contextSummary(swap1.context); expect(desc1).toBe( - '0xcb1355ff08ab38bbce60111f1bb2b784be25d7e8 swapped 1412595572402230 0x4200000000000000000000000000000000000006 for 1372743836828975471 0x4200000000000000000000000000000000000042', + '0xf70da97812cb96acdf810712aa562db8dfa3dbef swapped 1412595572402230 0x4200000000000000000000000000000000000006 for 1372743836828975471 0x4200000000000000000000000000000000000042', ); expect(containsBigInt(swap1.context)).toBe(false); @@ -42,7 +42,7 @@ describe('Uniswap', () => { expect(swap3.context?.summaries?.en.title).toBe('Uniswap'); const desc3 = contextSummary(swap3.context); expect(desc3).toBe( - '0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4 swapped 50000000000000000 0x4200000000000000000000000000000000000006 for 9670369113186014800347 0x4ed4e862860bed51a9570b96d89af5e1b0efefed', + '0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8 swapped 50000000000000000 0x4200000000000000000000000000000000000006 for 9670369113186014800347 0x4ed4e862860bed51a9570b96d89af5e1b0efefed', ); expect(containsBigInt(swap3.context)).toBe(false); }); diff --git a/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.ts b/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.ts index c2a1b483..549bc3f1 100644 --- a/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.ts +++ b/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.ts @@ -6,7 +6,7 @@ import { HeuristicContextActionEnum, Transaction, } from '../../../types'; -import { UNISWAP_V3_PAIR_ABI } from './constants'; +import { UNISWAP_V3_PAIR_ABI, UNIVERSAL_ROUTERS } from './constants'; import { decodeLog } from '../../../helpers/utils'; export const contextualize = (transaction: Transaction): Transaction => { @@ -35,7 +35,12 @@ export const detect = (transaction: Transaction): boolean => { // Contextualize for mined txs export const generate = (transaction: Transaction): Transaction => { - if (!transaction.netAssetTransfers || !transaction.logs) return transaction; + if ( + !transaction.netAssetTransfers || + !transaction.logs || + !transaction.chainId + ) + return transaction; let decoded; for (const log of transaction.logs) { decoded = decodeLog( @@ -51,6 +56,8 @@ export const generate = (transaction: Transaction): Transaction => { const sender: string = decoded.args['sender'].toLowerCase(); const recipient: string = decoded.args['recipient'].toLowerCase(); + const isUniversalRouter = + UNIVERSAL_ROUTERS[transaction.chainId].includes(sender); if ( !transaction.netAssetTransfers[sender] || !transaction.netAssetTransfers[sender].sent?.length || @@ -73,7 +80,7 @@ export const generate = (transaction: Transaction): Transaction => { variables: { sender: { type: 'address', - value: sender, + value: isUniversalRouter ? transaction.from : sender, }, recipient: { type: 'address',