Skip to content

Commit

Permalink
Merge pull request #375 from Once-Upon/feature/ou-2398-transaction-co…
Browse files Browse the repository at this point in the history
…ntextualization-is-wrong-bayardo-is-the

Transaction contextualization is wrong bayardo is the
  • Loading branch information
pcowgill authored May 21, 2024
2 parents fd30001 + b55065b commit c1a6e3a
Show file tree
Hide file tree
Showing 4 changed files with 843 additions and 4 deletions.
80 changes: 80 additions & 0 deletions src/contextualizers/protocol/uniswapV3/constants.ts
Original file line number Diff line number Diff line change
@@ -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',
],
};
15 changes: 14 additions & 1 deletion src/contextualizers/protocol/uniswapV3/uniswapV3Pair.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -20,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);

Expand All @@ -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(
'0x1e474b50bdc2b39dccaa2b8ddf37b3f022b128a8 swapped 50000000000000000 0x4200000000000000000000000000000000000006 for 9670369113186014800347 0x4ed4e862860bed51a9570b96d89af5e1b0efefed',
);
expect(containsBigInt(swap3.context)).toBe(false);
});

it('Should not detect as UniswapV3', () => {
Expand Down
13 changes: 10 additions & 3 deletions src/contextualizers/protocol/uniswapV3/uniswapV3Pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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(
Expand All @@ -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 ||
Expand All @@ -73,7 +80,7 @@ export const generate = (transaction: Transaction): Transaction => {
variables: {
sender: {
type: 'address',
value: sender,
value: isUniversalRouter ? transaction.from : sender,
},
recipient: {
type: 'address',
Expand Down
Loading

0 comments on commit c1a6e3a

Please sign in to comment.