-
Notifications
You must be signed in to change notification settings - Fork 8
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
Token mint #35
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
) { | ||
|
@@ -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); | ||
if (!isSameContract) { | ||
return false; | ||
} | ||
// transfer.from can send some eth | ||
const assetTransfer = transaction.netAssetTransfers[transaction.from]; | ||
const assetSent = assetTransfer.sent; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.