Skip to content

Commit

Permalink
Merge pull request #20 from Once-Upon/revert-13-benguyen0214/ou-1150-…
Browse files Browse the repository at this point in the history
…erc1155-purchase

Revert "Add detection criteria in ERC1155Purchase"
  • Loading branch information
pcowgill committed Nov 30, 2023
2 parents 0da2099 + 82aa6a3 commit 418fc4f
Showing 1 changed file with 35 additions and 40 deletions.
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

0 comments on commit 418fc4f

Please sign in to comment.