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 support for 12 byte ZIDs. #149

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Changes from all 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
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
Loading