Skip to content

Commit

Permalink
feat: handle univeral router
Browse files Browse the repository at this point in the history
  • Loading branch information
ponyjackal committed May 21, 2024
1 parent 5eed152 commit b55065b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 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',
],
};
4 changes: 2 additions & 2 deletions src/contextualizers/protocol/uniswapV3/uniswapV3Pair.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
});
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

0 comments on commit b55065b

Please sign in to comment.