Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nft purchase bulk not detected #12

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/heuristics/erc721Purchase.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Transaction } from '../types';
import { detectERC721Purchase } from './erc721Purchase';
import {
detectERC721Purchase,
generateERC21PurchaseContext,
} from './erc721Purchase';
import erc721Purchase0x2558f104 from '../test/transactions/erc721Purchase-0x2558f104.json';
import erc721Purchase0x05b8cee6 from '../test/transactions/erc721Purchase-0x05b8cee6.json';
import erc721Purchase0xdeba4248 from '../test/transactions/erc721Purchase-0xdeba4248.json';

describe('ERC721 Purchase', () => {
it('Should detect ERC721 Purchase transaction', () => {
Expand All @@ -14,5 +18,16 @@ describe('ERC721 Purchase', () => {
erc721Purchase0x05b8cee6 as Transaction,
);
expect(isERC721Purchase2).toBe(true);
const isERC721Purchase3 = detectERC721Purchase(
erc721Purchase0xdeba4248 as Transaction,
);
expect(isERC721Purchase3).toBe(true);
});

it('Should create ERC721 Purchase context', () => {
const result1 = generateERC21PurchaseContext(
erc721Purchase0xdeba4248 as Transaction,
);
expect(result1.context.summaries.en.title).toBe('NFT Purchase');
});
});
38 changes: 20 additions & 18 deletions src/heuristics/erc721Purchase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export function detectERC721Purchase(transaction: Transaction): boolean {
return false;
}

function generateERC21PurchaseContext(transaction: Transaction): Transaction {
export function generateERC21PurchaseContext(
transaction: Transaction,
): Transaction {
const receivingAddresses: string[] = [];
const receivedNfts: Asset[] = [];
const sentPayments: { type: string; asset: string; value: string }[] = [];
Expand Down Expand Up @@ -106,30 +108,30 @@ function generateERC21PurchaseContext(transaction: Transaction): Transaction {
tokenId: receivedNfts[0].tokenId,
}
: receivedNftContracts.length === 1
? {
type: 'address',
value: receivedNftContracts[0],
}
: {
type: 'emphasis',
value: `${receivedNfts.length} NFTs`,
},
? {
type: 'address',
value: receivedNftContracts[0],
}
: {
type: 'emphasis',
value: `${receivedNfts.length} NFTs`,
},
price:
totalPayments.length > 1
? {
type: 'emphasis',
value: `${totalPayments.length} Assets`,
}
: totalPayments[0].type === 'eth'
? {
type: 'eth',
value: totalPayments[0].value,
}
: {
type: 'erc20',
token: totalPayments[0].asset,
value: totalPayments[0].value,
},
? {
type: 'eth',
value: totalPayments[0].value,
}
: {
type: 'erc20',
token: totalPayments[0].asset,
value: totalPayments[0].value,
},
},
summaries: {
category: 'NFT',
Expand Down
5 changes: 4 additions & 1 deletion src/heuristics/tokenAirdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ function generateTokenAirdropContext(transaction: Transaction): Transaction {
value: firstAssetTransfer.value,
};

const category =
firstAssetTransfer.type === 'erc721' ? 'NFT' : 'FUNGIBLE_TOKEN';

transaction.context = {
variables: {
recipient:
Expand Down Expand Up @@ -103,7 +106,7 @@ function generateTokenAirdropContext(transaction: Transaction): Transaction {
},
},
summaries: {
category: 'FUNGIBLE_TOKEN',
category,
en: {
title: 'Token Airdrop',
default: `[[recipient]] [[receivedAirdrop]] [[token]]${
Expand Down
1,345 changes: 1,345 additions & 0 deletions src/test/transactions/erc721Purchase-0xdeba4248.json

Large diffs are not rendered by default.