Skip to content

Commit

Permalink
Merge pull request #149 from 0xProject/andres/zid-12-bytes
Browse files Browse the repository at this point in the history
Adds support for 12 byte ZIDs.
  • Loading branch information
AndresElizondo committed Jun 7, 2024
2 parents a8ef0b9 + b614aed commit 84f25bc
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/parsers/web3/parse_web3_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@ function isCoinbaseShortZidTransaction(blockNumber: Number, affiliateAddress: St
return false;
}

function isAfterZidBytesReduction(blockNumber: Number): Boolean {
// Approximate block numbers after ZID reduction from 16 to 12 bytes.
switch (CHAIN_ID) {
case 1: // Ethereum
return blockNumber >= 20040654;
case 10: // Optimism
return blockNumber >= 121086482;
case 56: // BSC
return blockNumber >= 39406978;
case 137: // Polygon
return blockNumber >= 57877548;
case 250: // Fantom
return blockNumber >= 82443443;
case 8453: // Base
return blockNumber >= 15491223;
case 42161: // Arbitrum
return blockNumber >= 219382805;
case 42220: // Celo
return blockNumber >= 26019714;
case 43114: // Avalanche
return blockNumber >= 46421607;
}
return false;
}

/**
* Converts a raw tx into a Transaction entity
* @param rawTx Raw transaction returned from JSON RPC
Expand Down Expand Up @@ -62,16 +87,25 @@ export function parseTransaction(rawTx: EVMTransaction): Transaction {
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' &&
!isCoinbaseShortZidTransaction(transaction.blockNumber, transaction.affiliateAddress)
quoteId.slice(0, 16) === '0000000000000000' &&
isCoinbaseShortZidTransaction(transaction.blockNumber, transaction.affiliateAddress)
) {
// Coinbase short-zid incident (2024-04-30 - 2024-05-04)
// (8 bytes data, 8 bytes padding)
transaction.quoteTimestamp = null;
transaction.quoteId = '0x' + quoteId;
} else if (quoteId.slice(0, 14) === '00000000000000') {
// 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);
} else if (quoteId.slice(0, 8) === '00000000' && isAfterZidBytesReduction(transaction.blockNumber)) {
// 12-byte ZID (~2024-06-07)
// (12 bytes data, ignore first 4 bytes of padding)
transaction.quoteTimestamp = null;
transaction.quoteId = '0x' + quoteId.slice(8);
} else {
// ZID
// 16-byte ZID - Original
transaction.quoteTimestamp = null;
transaction.quoteId = '0x' + quoteId;
}
Expand Down

0 comments on commit 84f25bc

Please sign in to comment.