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

Revert "Add detection criteria in ERC1155Purchase" #20

Merged
merged 1 commit into from
Nov 30, 2023
Merged
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
75 changes: 35 additions & 40 deletions src/heuristics/erc1155Purchase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ export function erc1155PurchaseContextualizer(
return generateERC1155PurchaseContext(transaction);
}

/**
* Detection criteria
*
* A tx is an ERC1155 purchase when the tx.from sends and receives exactly 1 asset (look at netAssetTransfers).
* The tx.from must receive exactly 1 ERC1155, where the value (special to 1155s) can be arbitrary
* The tx.from must send either ETH/WETH/Blur ETH
* There are no other recipients of ERC721/ERC20s/ERC1155s.
*/
export function detectERC1155Purchase(transaction: Transaction): boolean {
/**
* There is a degree of overlap between the 'detect' and 'generateContext' functions,
Expand All @@ -31,23 +23,26 @@ export function detectERC1155Purchase(transaction: Transaction): boolean {
const addresses = transaction.netAssetTransfers
? Object.keys(transaction.netAssetTransfers)
: [];
// check if transfer.from sent and received one asset
const transfers = transaction.netAssetTransfers[transaction.from];
const nftsReceived = transfers.received.filter((t) => t.type === 'erc1155');
const nftsSent = transfers.sent.filter((t) => t.type === 'erc1155');
const tokenSent = transfers.sent.filter(
(t) => t.type === 'eth' || t.type === 'erc20',
);
const tokenReceived = transfers.received.filter(
(t) => t.type === 'eth' || t.type === 'erc20',
);

if (nftsReceived.length > 0 && tokenSent.length > 0) {
return true;
}
for (const address of addresses) {
const transfers = transaction.netAssetTransfers[address];
const nftsReceived = transfers.received.filter((t) => t.type === 'erc1155');
const nftsSent = transfers.sent.filter((t) => t.type === 'erc1155');

const ethOrErc20Sent = transfers.sent.filter(
(t) => t.type === 'eth' || t.type === 'erc20',
);
const ethOrErc20Received = transfers.received.filter(
(t) => t.type === 'eth' || t.type === 'erc20',
);

if (nftsReceived.length > 0 && ethOrErc20Sent.length > 0) {
return true;
}

if (nftsSent.length > 0 && tokenReceived.length > 0) {
return true;
if (nftsSent.length > 0 && ethOrErc20Received.length > 0) {
return true;
}
}

return false;
Expand Down Expand Up @@ -112,30 +107,30 @@ function generateERC1155PurchaseContext(transaction: Transaction): Transaction {
value: receivedNfts[0].value,
}
: 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