All files / src/parsers x2y2.parser.ts

90% Statements 18/20
50% Branches 2/4
100% Functions 4/4
94.73% Lines 18/19

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 31 321x   1x   1x 1x   1x   1x     32x 507x 1x 1x   1x 1x 1x     1x   507x 32x 1x   31x      
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 X2Y2Parser implements LogParser {
    
    platform: string = 'x2y2';
    
    parseLogs(transaction:TransactionResponse, logs: Log[], tokenId: string): number {
        const result = logs.map((log: any, index:number) => {
          if (log.topics[0].toLowerCase() === '0x3cbb63f144840e5b1b0a38a7c19211d2e89de4d7c5faf8b2d3c1776c302d1d33') {
            const data = log.data.substring(2);
            const dataSlices = data.match(/.{1,64}/g);
            // find the right token
            Iif (BigInt(`0x${dataSlices[18]}`).toString() !== tokenId) return;
            let amount = BigInt(`0x${dataSlices[12]}`) / BigInt('1000000000000000');
            Iif (amount === BigInt(0)) {
              amount = BigInt(`0x${dataSlices[26]}`) / BigInt('1000000000000000');
            }
            return amount
          }
        }).filter(n => n !== undefined)  
        if (result.length) {
          return parseFloat(result[0].toString())/1000;
        }
        return undefined
    }
 
}