Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Fix for OpenSea lazy minting bullshit
Browse files Browse the repository at this point in the history
  • Loading branch information
lambertkevin committed Apr 5, 2022
1 parent 5bba7e2 commit 81b872c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/nft/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ export const nftsFromOperations = (ops: Operation[]): ProtoNFT[] => {
}) as ProtoNFT;

if (nftOp.type === "NFT_IN") {
// Because of how OpenSea is working with its "lazy minting" paradigm
// they can send an event pretending that you sent x NFT to an address
// while you actually never received it in the first place.
//
// E.g.: You create an NFT on OpenSea and "lazy mint" 2 ERC1155.
// You will not actually receive anything, it's off-chain and no one can actually
// know that you own those 2 NFTs except OpenSea itselft.
// Then you decide to send those 2 NFTs to someone (kvn).
// OpenSea will then mint and transfer 2 NFTs to kvn and fire an even saying that
// you sent 2 NFts to kvn. But since you never "received" them first, you had 0 NFT
// and you sent 2, therefore you now have -2 NFTs.
//
// We prevent that by setting the minimum amount of an NFT to 0 when a new "IN" transaction
// is incoming for it.
if (nft.amount.isNegative()) {
nft.amount = new BigNumber(0);
}

nft.amount = nft.amount.plus(nftOp.value);
} else if (nftOp.type === "NFT_OUT") {
nft.amount = nft.amount.minus(nftOp.value);
Expand Down

0 comments on commit 81b872c

Please sign in to comment.