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

Adds fix for short zid incident with Coinbase. #146

Merged
merged 7 commits into from
May 7, 2024
Merged
Changes from 4 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
32 changes: 31 additions & 1 deletion src/parsers/web3/parse_web3_objects.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CHAIN_ID } from '../../config';
import { ZEROEX_API_AFFILIATE_SELECTOR } from '../../constants';
import {
BlockWithoutTransactionData,
Expand All @@ -7,6 +8,31 @@ import {
import { Block, Transaction, TransactionLogs, TransactionReceipt } from '../../entities';
import { BigNumber } from '@0x/utils';

function isCoinbaseShortZidTransaction(blockNumber: Number, affiliateAddress: String): Boolean {
// Coinbase's affiliateAddress used during this period
if (affiliateAddress !== '0x382ffce2287252f930e1c8dc9328dac5bf282ba1') {
return false;
}

switch (CHAIN_ID) {
case 1: // Ethereum
return blockNumber >= 19764710 && blockNumber <= 19790423;
case 10: // Optimism
return blockNumber >= 119425202 && blockNumber <= 119573152;
case 56: // BSC
return blockNumber >= 38300237 && blockNumber <= 38401538;
case 137: // Polygon
return blockNumber >= 56403824 && blockNumber <= 56533849;
case 8453: // Base
return blockNumber >= 13824760 && blockNumber <= 13980098;
case 42161: // Arbitrum
return blockNumber >= 206219946 && blockNumber <= 207442546;
case 43114: // Avalanche
return blockNumber >= 44854448 && blockNumber <= 44963247;
}
return false;
}

/**
* Converts a raw tx into a Transaction entity
* @param rawTx Raw transaction returned from JSON RPC
Expand Down Expand Up @@ -35,8 +61,12 @@ export function parseTransaction(rawTx: EVMTransaction): Transaction {
const bytesPos = rawTx.input.indexOf(ZEROEX_API_AFFILIATE_SELECTOR);
transaction.affiliateAddress = '0x'.concat(rawTx.input.slice(bytesPos + 32, bytesPos + 72));
const quoteId = rawTx.input.slice(bytesPos + 104, bytesPos + 136);
if (quoteId.slice(0, 14) === '00000000000000') {
if (
quoteId.slice(0, 14) === '00000000000000' &&
!isCoinbaseShortZidTransaction(transaction.blockNumber, transaction.affiliateAddress)
) {
// Pre ZID QR ID
// Excludes short-zid incident (2024-04-30 - 2024-05-04)
const parsedQuoteTimestamp = parseInt(rawTx.input.slice(bytesPos + 128, bytesPos + 136), 16);
transaction.quoteTimestamp = isNaN(parsedQuoteTimestamp) ? null : parsedQuoteTimestamp;
transaction.quoteId = rawTx.input.slice(bytesPos + 118, bytesPos + 128);
Expand Down
Loading