Skip to content

Commit

Permalink
Merge pull request #378 from Once-Upon/feature/ou-2431-context-should…
Browse files Browse the repository at this point in the history
…-not-be-an-empty-object-should-be-an-erc20

Context should not be an empty object should be an erc20
  • Loading branch information
pcowgill authored May 22, 2024
2 parents c288d51 + 00af4c4 commit eeaa6af
Show file tree
Hide file tree
Showing 4 changed files with 1,315 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/commands/detectContextualizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export function registerDetectContextualizersCommand() {

const txResult = contextualizer.contextualize(transaction, true);
if (!txResult.from) {
console.error(
`No matching protocol contextualizer on ${transaction.hash}`,
);
console.error(`No matching contextualizer on ${transaction.hash}`);
}

console.log('Successfully ran contextualizers');
Expand Down
10 changes: 10 additions & 0 deletions src/contextualizers/heuristics/erc20Swap/erc20Swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import erc20SwapNot0xb376ca2f from '../../test/transactions/erc20Swap-not-0xb376
import erc20Swap0xd55dc9b2 from '../../test/transactions/erc20Swap-0xd55dc9b2.json';
import erc20Swap0x6ef80cce from '../../test/transactions/erc20Swap-0x6ef80cce.json';
import erc20swap0x2c631258 from '../../test/transactions/erc20swap-0x2c631258.json';
import erc20Swap0x96f5e3fb from '../../test/transactions/erc20Swap-0x96f5e3fb.json';
import catchall0xc35c01ac from '../../test/transactions/catchall-0xc35c01ac.json';

describe('ERC20 Swap', () => {
Expand All @@ -21,6 +22,9 @@ describe('ERC20 Swap', () => {

const isERC20Swap3 = detect(erc20swap0x2c631258 as unknown as Transaction);
expect(isERC20Swap3).toBe(true);

const isERC20Swap4 = detect(erc20Swap0x96f5e3fb as unknown as Transaction);
expect(isERC20Swap4).toBe(true);
});

it('Should generate context', () => {
Expand All @@ -47,6 +51,12 @@ describe('ERC20 Swap', () => {
expect(desc3).toBe(
'0x6e947ba373a53bd41139d68e8dfb4fb0472767b6 SWAPPED 300000000000000000 0x4200000000000000000000000000000000000006 for 79907887473934231137403 0x4ed4e862860bed51a9570b96d89af5e1b0efefed',
);

const generated4 = generate(erc20Swap0x96f5e3fb as unknown as Transaction);
const desc4 = contextSummary(generated4.context);
expect(desc4).toBe(
'0x605e05bf092ebd18e06d1b0f699df5b9dd85d452 SWAPPED 20398910132192029774490 0xeb1c32ea4e392346795aed3607f37646e2a9c13f for 2748.521373404267795478 ETH',
);
});

it('Should not detect as ERC20 Swap transaction', () => {
Expand Down
1 change: 1 addition & 0 deletions src/contextualizers/protocol/uniswapV3/uniswapV3Pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ 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] &&
UNIVERSAL_ROUTERS[transaction.chainId].includes(sender);
if (
!transaction.netAssetTransfers[sender] ||
Expand Down
Loading

0 comments on commit eeaa6af

Please sign in to comment.