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

Event Scrapers API v2 - Save all Txns and Transfer events #147

Merged
merged 67 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
4ea59fb
Save all transactions.
May 23, 2024
189f558
Adds ERC20 Transfer events. Filters out ERC721 Transfers.
May 25, 2024
7c78d85
Prettier.
May 25, 2024
7bdb072
Filters transactions without calldata.
May 28, 2024
b4fb4ca
Reuses existing Transfer event function signature.
May 29, 2024
792d252
Bugfix: Start scraping Transfer events from 0xSettler deployment block.
May 29, 2024
890169c
Makes 0x EP an optional feature along with all events scraped from it.
May 29, 2024
7530f96
Restores filter for transactions with listened events.
May 29, 2024
ae7981c
Adds support for multiple ABIs for ERC20 Transfer events.
May 29, 2024
94c2c60
Adds env variables for all chains.
May 29, 2024
b13337a
Refactors how optional EP is managed.
May 30, 2024
3b3534d
Changes order of EP validations.
May 30, 2024
ec8ef3b
Optimization. Avoids parsing txns with empty calldata.
May 31, 2024
0b1d812
Adds support for any non-standard ERC20 Transfer event.
Jun 4, 2024
9c02e18
Optimization. Check if calldata is empty before parsing txn.
Jun 4, 2024
69b4164
Merge pull request #148 from 0xProject/andres/make-0xEP-optional
AndresElizondo Jun 4, 2024
0c9a424
Fix some env variables.
Jun 4, 2024
028985b
Adds optional Exchange Proxy flag
Jun 4, 2024
1e7577a
Bugfix. Don't modify original Standard ERC20 Transfer ABI.
Jun 5, 2024
a391759
Cleanup. Handle edge cases.
Jun 5, 2024
816bdce
Improves logging.
Jun 5, 2024
324590a
Adds support for 12 byte ZIDs.
Jun 7, 2024
13dde9e
Adds block filter for 12 byte zid's.
Jun 7, 2024
b614aed
Adds documentation comment.
Jun 7, 2024
84f25bc
Merge pull request #149 from 0xProject/andres/zid-12-bytes
AndresElizondo Jun 7, 2024
d885e49
Save all transactions.
May 23, 2024
8b78acd
Adds ERC20 Transfer events. Filters out ERC721 Transfers.
May 25, 2024
eac4511
Prettier.
May 25, 2024
1ed5647
Filters transactions without calldata.
May 28, 2024
e018a33
Reuses existing Transfer event function signature.
May 29, 2024
9226a2b
Bugfix: Start scraping Transfer events from 0xSettler deployment block.
May 29, 2024
d862ce7
Restores filter for transactions with listened events.
May 29, 2024
321a20c
Adds support for multiple ABIs for ERC20 Transfer events.
May 29, 2024
7f38f63
Adds env variables for all chains.
May 29, 2024
c3e4815
Optimization. Avoids parsing txns with empty calldata.
May 31, 2024
cbbe75a
Adds support for any non-standard ERC20 Transfer event.
Jun 4, 2024
71f3303
Optimization. Check if calldata is empty before parsing txn.
Jun 4, 2024
f1148ed
Makes 0x EP an optional feature along with all events scraped from it.
May 29, 2024
bde7403
Refactors how optional EP is managed.
May 30, 2024
01ec059
Changes order of EP validations.
May 30, 2024
b91542c
Fix some env variables.
Jun 4, 2024
f6361e5
Adds optional Exchange Proxy flag
Jun 4, 2024
606ca2f
Bugfix. Don't modify original Standard ERC20 Transfer ABI.
Jun 5, 2024
13f2dd6
Cleanup. Handle edge cases.
Jun 5, 2024
35c6717
Improves logging.
Jun 5, 2024
8f4b863
Merge branch 'andres/scrapers-save-all-txns' of github.com:0xProject/…
Jun 11, 2024
7658856
Adds support for parsing 0xSettler transactions.
Jun 12, 2024
5c1be42
Adds support for Settler ERC721 Transfer events.
Jun 14, 2024
93a666c
Adds new flags to docker-compose.
Jun 14, 2024
1117215
Initial working implementation of RFQ Event with dynamic loading of s…
Jun 21, 2024
128241c
Refactoring. Moves settler contracts into singleton.
Jun 22, 2024
8ed18d5
Adds auto-update when a Settler ERC721 Transfer event is detected.
Jun 22, 2024
bb212a8
Removes unused block numbers from SettlerContract type.
Jun 22, 2024
cb3ee5e
Fix comments.
Jun 22, 2024
7681d71
Adds isInitialized method to singleton. Prevents crashing.
Jun 22, 2024
460d511
Bugfix.
Jun 22, 2024
0c72bf1
Simplifies simpleton usability.
Jun 22, 2024
700b533
Moves auto-update to postprocess.
Jun 22, 2024
75c9ec6
prettier
Jun 22, 2024
007cdc6
Removes unused logs.
Jun 24, 2024
e7b4abc
Simplifies settler contract singleton.
Jun 24, 2024
27a5f11
Merge pull request #150 from 0xProject/andres/add-rfq-event-listener
AndresElizondo Jun 24, 2024
de3af5f
Adds warning when RPC responds without new blocks.
Jul 10, 2024
0f9e99c
Scrape all wrap/unwrap events belonging to 0x.
Jul 19, 2024
dc2ff3d
Filters ERC20 Transfer Events to only 0x transactions.
Jul 19, 2024
26039ed
Removes zid filters for wraps/unwraps and ERC20 transfers.
Jul 19, 2024
586c903
Revert "Removes zid filters for wraps/unwraps and ERC20 transfers."
Aug 8, 2024
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
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ services:
#KAFKA_AUTH_PASSWORD: '${KAFKA_AUTH_PASSWORD}'
SCRAPER_MODE: 'BLOCKS'
EP_DEPLOYMENT_BLOCK: 10247094
SETTLER_DEPLOYMENT_BLOCK: 19582253
MAX_BLOCKS_TO_SEARCH: 1000
MAX_BLOCKS_TO_PULL: 100
MAX_TX_TO_PULL: 1000
Expand Down Expand Up @@ -78,6 +79,7 @@ services:
FEAT_SOCKET_BRIDGE_EVENT: "true"
SOCKET_BRIDGE_CONTRACT_ADDRESS: "0x3a23f943181408eac424116af7b7790c94cb97a5"
SOCKET_BRIDGE_EVENT_START_BLOCK: 18473454
FEAT_ERC20_TRANSFER_ALL: "true"

event-pipeline-bsc:
depends_on:
Expand Down
26 changes: 26 additions & 0 deletions src/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1426,3 +1426,29 @@ export const STAKING_REWARDS_PAID_ABI = {
name: 'RewardsPaid',
type: 'event',
};

export const ERC20_TRANSFER_ABI = {
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'from',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'to',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'value',
type: 'uint256',
},
],
name: 'Transfer',
type: 'event',
};
8 changes: 8 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
DEFAULT_STAKING_POOLS_METADATA_JSON_URL,
DEFAULT_BLOCK_RECEIPTS_MODE,
BLOCK_RECEIPTS_MODE_ENDPOINT,
DEFAULT_FEAT_ERC20_TRANSFER_ALL,
} from './constants';
import { logger } from './utils';

Expand Down Expand Up @@ -105,6 +106,10 @@ export const EP_DEPLOYMENT_BLOCK = process.env.EP_DEPLOYMENT_BLOCK
? parseInt(process.env.EP_DEPLOYMENT_BLOCK, 10)
: throwError(`Must specify valid EP_DEPLOYMENT_BLOCK. Got: ${process.env.EP_DEPLOYMENT_BLOCK}`);

export const SETTLER_DEPLOYMENT_BLOCK = process.env.SETTLER_DEPLOYMENT_BLOCK
? parseInt(process.env.SETTLER_DEPLOYMENT_BLOCK, 10)
: throwError(`Must specify valid SETTLER_DEPLOYMENT_BLOCK. Got: ${process.env.SETTLER_DEPLOYMENT_BLOCK}`);

export const SCHEMA = process.env.SCHEMA
? process.env.SCHEMA
: throwError(`Must specify valid SCHEMA. Got: ${process.env.SCHEMA}`);
Expand Down Expand Up @@ -197,6 +202,7 @@ if (STAKING_PROXY_DEPLOYMENT_TRANSACTION === null && FEAT_STAKING) {
export const FIRST_SEARCH_BLOCK = Math.min(
EP_DEPLOYMENT_BLOCK,
STAKING_DEPLOYMENT_BLOCK === -1 ? Infinity : STAKING_DEPLOYMENT_BLOCK,
SETTLER_DEPLOYMENT_BLOCK === -1 ? Infinity : SETTLER_DEPLOYMENT_BLOCK,
Ktl-XV marked this conversation as resolved.
Show resolved Hide resolved
);

export const FEAT_TRANSFORMED_ERC20_EVENT = getBoolConfig(
Expand Down Expand Up @@ -482,6 +488,8 @@ export const BLOCKS_REORG_CHECK_INCREMENT = getIntConfig(
DEFAULT_BLOCKS_REORG_CHECK_INCREMENT,
);

export const FEAT_ERC20_TRANSFER_ALL = getBoolConfig('FEAT_ERC20_TRANSFER_ALL', DEFAULT_FEAT_ERC20_TRANSFER_ALL);

function getBoolConfig(env: string, defaultValue: boolean): boolean {
if (Object.prototype.hasOwnProperty.call(process.env, env)) {
return process.env[env] === 'true';
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const DEFAULT_ENABLE_PROMETHEUS_METRICS = false;
export const DEFAULT_FEAT_ONCHAIN_GOVERNANCE = false;
export const DEFAULT_FEAT_WRAP_UNWRAP_NATIVE_EVENT = false;
export const DEFAULT_FEAT_WRAP_UNWRAP_NATIVE_TRANSFER_EVENT = false;
export const DEFAULT_FEAT_ERC20_TRANSFER_ALL = false;

export const BRIDGEFILL_EVENT_TOPIC = ['0xe59e71a14fe90157eedc866c4f8c767d3943d6b6b2e8cd64dddcc92ab4c55af8'];
export const TRANSFORMEDERC20_EVENT_TOPIC = ['0x0f6672f78a59ba8e5e5b5d38df3ebc67f3c792e2c9259b8d97d7f00dd78ba1b3'];
Expand All @@ -60,6 +61,7 @@ export const DEFAULT_STAKING_PROXY_ADDRESS = '0xa26e80e7dea86279c6d778d702cc413e
export const V4_CANCEL_EVENT_TOPIC = ['0xa6eb7cdc219e1518ced964e9a34e61d68a94e4f1569db3e84256ba981ba52753'];
export const EXPIRED_RFQ_ORDER_EVENT_TOPIC = ['0xd9ee00a67daf7d99c37893015dc900862c9a02650ef2d318697e502e5fb8bbe2'];
export const OTC_ORDER_FILLED_EVENT_TOPIC = ['0xac75f773e3a92f1a02b12134d65e1f47f8a14eabe4eaf1e24624918e6a8b269f'];
export const ERC20_TRANSFER_EVENT_TOPIC = ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'];
Ktl-XV marked this conversation as resolved.
Show resolved Hide resolved

export const UNISWAP_V2_PAIR_CREATED_TOPIC = ['0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9'];
export const UNISWAP_V2_SYNC_TOPIC = ['0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1'];
Expand Down
16 changes: 16 additions & 0 deletions src/entities/erc20_transfer_event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { bigNumberTransformer } from '../transformers';
import { Event } from './event';
import { BigNumber } from '@0x/utils';
import { Column, Entity } from 'typeorm';

// These events come directly from the token's ERC20 contract and are fired whenever
// an ERC20 is transferred between two wallets.
@Entity({ name: 'erc20_transfer_events' })
export class ERC20TransferEvent extends Event {
@Column({ name: 'from', type: 'varchar' })
public from!: string;
@Column({ name: 'to', type: 'varchar' })
public to!: string | null;
@Column({ name: 'value', type: 'numeric', transformer: bigNumberTransformer })
public value!: BigNumber;
}
1 change: 1 addition & 0 deletions src/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ export { V4CancelEvent } from './v4_cancel_event';
export { V4LimitOrderFilledEvent } from './v4_limit_order_filled_event';
export { V4RfqOrderFilledEvent } from './v4_rfq_order_filled_event';
export { WrapNativeEvent } from './wrap_native_event';
export { ERC20TransferEvent } from './erc20_transfer_event';
16 changes: 16 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
EP_ADDRESS,
FEAT_STAKING,
EP_DEPLOYMENT_BLOCK,
SETTLER_DEPLOYMENT_BLOCK,
FEAT_ERC20_BRIDGE_TRANSFER_FLASHWALLET,
FEAT_LIMIT_ORDERS,
FEAT_META_TRANSACTION_EXECUTED_EVENT,
Expand Down Expand Up @@ -47,6 +48,7 @@ import {
V4_NATIVE_FILL_START_BLOCK,
WRAP_UNWRAP_NATIVE_CONTRACT_ADDRESS,
WRAP_UNWRAP_NATIVE_START_BLOCK,
FEAT_ERC20_TRANSFER_ALL,
} from './config';
import {
BRIDGEFILL_EVENT_TOPIC,
Expand Down Expand Up @@ -99,6 +101,7 @@ import {
STAKING_EPOCH_ENDED_TOPIC,
STAKING_EPOCH_FINALIZED_TOPIC,
STAKING_REWARDS_PAID_TOPIC,
ERC20_TRANSFER_EVENT_TOPIC,
} from './constants';
import { Web3Source } from './data_sources/events/web3';
import {
Expand Down Expand Up @@ -144,6 +147,7 @@ import {
StakingPoolEarnedRewardsInEpochEvent,
TransactionExecutionEvent,
UnstakeEvent,
ERC20TransferEvent,
} from './entities';
import {
filterSocketBridgeEventsGetContext,
Expand Down Expand Up @@ -189,6 +193,7 @@ import {
parseV4RfqOrderFilledEvent,
parseWrapNativeEvent,
parseWrapNativeTransferEvent,
parseERC20TransferEvent,
} from './parsers';
import {
parseEpochEndedEvent,
Expand Down Expand Up @@ -762,6 +767,17 @@ export const eventScrperProps: EventScraperProps[] = [
startBlock: V3_DEPLOYMENT_BLOCK,
parser: parseRewardsPaidEvent,
},
{
enabled: FEAT_ERC20_TRANSFER_ALL,
name: 'ERC20TransferEvent',
tType: ERC20TransferEvent,
table: 'erc20_transfer_events',
topics: ERC20_TRANSFER_EVENT_TOPIC,
contractAddress: null,
startBlock: FLASHWALLET_DEPLOYMENT_BLOCK,
Ktl-XV marked this conversation as resolved.
Show resolved Hide resolved
parser: parseERC20TransferEvent,
filterFunction: filterNulls,
},
];

for (const payment_recipient of POLYGON_RFQM_PAYMENTS_ADDRESSES) {
Expand Down
2 changes: 2 additions & 0 deletions src/ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
V4LimitOrderFilledEvent,
V4RfqOrderFilledEvent,
WrapNativeEvent,
ERC20TransferEvent,
} from './entities';
import { ConnectionOptions } from 'typeorm';

Expand Down Expand Up @@ -106,6 +107,7 @@ const entities = [
V4LimitOrderFilledEvent,
V4RfqOrderFilledEvent,
WrapNativeEvent,
ERC20TransferEvent,
];

const config: ConnectionOptions = {
Expand Down
29 changes: 29 additions & 0 deletions src/parsers/events/erc20_transfer_events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ERC20_TRANSFER_ABI } from '../../constants';
import { ERC20TransferEvent } from '../../entities';
import { parseEvent } from './parse_event';
import { BigNumber } from '@0x/utils';
import { LogEntry } from 'ethereum-types';

const abiCoder = require('web3-eth-abi');

const Web3Utils = require('web3-utils');

export function parseERC20TransferEvent(eventLog: LogEntry): ERC20TransferEvent | null {
const eRC20TransferEvent = new ERC20TransferEvent();

parseEvent(eventLog, eRC20TransferEvent);

// ERC20 Transfers have 3 topics and 32 bytes of data
AndresElizondo marked this conversation as resolved.
Show resolved Hide resolved
// ERC721 Transfers have 4 topics and no data
if (eventLog.topics.length !== 3) {
return null;
}

const decodedLog = abiCoder.decodeLog(ERC20_TRANSFER_ABI.inputs, eventLog.data, eventLog.topics.slice(1));

eRC20TransferEvent.from = decodedLog.from.toLowerCase();
eRC20TransferEvent.to = decodedLog.to.toLowerCase();
eRC20TransferEvent.value = new BigNumber(decodedLog.value);

return eRC20TransferEvent;
}
1 change: 1 addition & 0 deletions src/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ export {
parseWrapNativeTransferEvent,
parseUnwrapNativeTransferEvent,
} from './events/wrap_unwrap_native_events';
export { parseERC20TransferEvent } from './events/erc20_transfer_events';
11 changes: 7 additions & 4 deletions src/scripts/pull_and_save_block_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ function parseBlockTransactionsEvents(fullBlock: FullBlock): ParsedFullBlock {

function parseTransactionEvents(transaction: FullTransaction): ParsedTransaction {
const parsedTransaction = parseTransaction(transaction);
if (parsedTransaction.input === '0x') {
AndresElizondo marked this conversation as resolved.
Show resolved Hide resolved
return {
parsedTransaction: null,
parsedEvents: null,
};
}

const nestedParsedEvents: TypedEvents[] = eventScrperProps.map((props: EventScraperProps): TypedEvents => {
if (props.enabled) {
Expand Down Expand Up @@ -134,13 +140,10 @@ function parseTransactionEvents(transaction: FullTransaction): ParsedTransaction
};
});

const foundScrapedEventInTx = nestedParsedEvents.map((npe) => npe.events).flat().length > 0;

return {
// We need all reverted txs for joining with traces later
// toString is needed because we libraries do not match
parsedTransaction:
foundScrapedEventInTx || transaction.status!.toString() === 'false' ? parsedTransaction : null,
parsedTransaction: parsedTransaction,
AndresElizondo marked this conversation as resolved.
Show resolved Hide resolved
parsedEvents: nestedParsedEvents,
};
}
Expand Down
Loading