All files / src/parsers looksrare.v2.parser.ts

100% Statements 17/17
79.31% Branches 23/29
100% Functions 6/6
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 311x   1x   1x 1x   1x   1x     43x 810x 100x     810x   100x 100x   43x 10x 10x 10x   33x      
import { Log, TransactionResponse, ethers } from "ethers";
import { LogParser } from "./parser.definition";
import looksRareABIv2 from '../abi/looksRareABIv2.json';
 
const looksRareContractAddressV2 = '0x0000000000e655fae4d56241588680f86e3b2377'; // Don't change unless deprecated
const looksInterfaceV2 = new ethers.Interface(looksRareABIv2);
 
export class LooksRareV2Parser implements LogParser {
    
    platform: string = 'looksrare';
    
    parseLogs(transaction:TransactionResponse, logs: Log[], tokenId: string): number {
        const result = logs.map((log: any) => {
            if (log.address.toLowerCase() === looksRareContractAddressV2.toLowerCase()) {  
              return looksInterfaceV2.parseLog(log);
            }
          })
          .filter(log => log !== undefined)
          .filter((log: any) => {
            return (log?.name === 'TakerAsk' || log?.name === 'TakerBid') &&
            log?.args.itemIds.map(i => i.toString()).indexOf(tokenId) > -1
          });
        if (result.length) {
          const weiValue = (result[0]?.args?.feeAmounts[0])?.toString();
          const value = ethers.formatEther(weiValue);
          return parseFloat(value)
        }
        return undefined
    }
 
}