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

Token mint #35

Merged
merged 3 commits into from
Dec 4, 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
34 changes: 29 additions & 5 deletions src/heuristics/tokenMint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ export function tokenMintContextualizer(transaction: Transaction): Transaction {
return generateTokenMintContext(transaction);
}

/**
* Detection criteria
*
* 1 address receives NFTs, all must be from the same contract. All nfts are minted (meaning they're sent from null address in netAssetTransfers).
* The from address can send ETH
* The only other parties in netAssetTransfers are receiving ETH
*/
export function detectTokenMint(transaction: Transaction): boolean {
if (
!transaction?.from ||
!transaction.assetTransfers?.length ||
transaction.netAssetTransfers === undefined // TODO: This is a hack because of an issue with netAssetTransfers transformer
) {
Expand All @@ -26,19 +34,35 @@ export function detectTokenMint(transaction: Transaction): boolean {
if (mints.length == 0) {
return false;
}

// check if there are 2 transaction parties other than null address
// check if all minted assets are from the same contract
const isSameContract = mints.every((ele) => ele.asset === mints[0].asset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isSameContract = mints.every((ele) => ele.asset === mints[0].asset);
const isSameContract = mints.every((ele) => ele?.asset === mints[0].asset);

if (!isSameContract) {
return false;
}
// transfer.from can send some eth
const assetTransfer = transaction.netAssetTransfers[transaction.from];
const assetSent = assetTransfer.sent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ponyjackal This is the line where the error was introduced

if (assetSent.length > 0 && assetSent[0].type !== 'eth') {
return false;
}
// check if other transaction parties received ether
const transactionParties: string[] = Object.keys(
transaction.netAssetTransfers,
)
.reduce((parties, address) => {
parties = [...new Set([...parties, address])];
return parties;
}, [])
.filter((address) => address !== KNOWN_ADDRESSES.NULL);
.filter(
(address) =>
address !== KNOWN_ADDRESSES.NULL && address !== transaction.from,
);

if (transactionParties.length > 2) {
return false;
for (const address of transactionParties) {
const assetReceived = transaction.netAssetTransfers[address]?.received;
if (assetReceived.length === 0 || assetReceived[0].type !== 'eth') {
return false;
}
}

return true;
Expand Down