* abis

* update
This commit is contained in:
Austin 2025-08-27 14:32:18 -04:00 committed by GitHub
parent 2f73c52458
commit d5af47634f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 315 additions and 1 deletions

View File

@ -0,0 +1,148 @@
{% docs dim_contract_abis_table_doc %}
## What
This table contains Application Binary Interfaces (ABIs) for smart contracts deployed on EVM blockchains. ABIs define the contract's functions, events, and data structures, enabling the decoding of raw blockchain data into human-readable format.
## Key Use Cases
- Decoding raw event logs into human-readable format
- Identifying contract functions and their parameters
- Enabling interaction with smart contracts programmatically
- Analyzing contract patterns and implementations across chains
- Supporting automated contract verification and bytecode matching
## Important Relationships
- **Powers ez_decoded_event_logs**: ABIs enable event decoding
- **Join with dim_contracts**: Use `contract_address` for contract metadata
- **Enables fact_decoded_event_logs**: Raw to decoded transformation
## Commonly-used Fields
- `contract_address`: The contract's blockchain address
- `abi`: The contract's Application Binary Interface in JSON format
- `abi_source`: The origin of the ABI data (explorer verified, user submitted, bytecode matched)
- `bytecode`: The compiled contract code deployed on-chain
- `created_timestamp`: When the ABI was added to the database
## Sample queries
**Find Contracts Without ABIs**
```sql
-- Identify popular contracts needing ABIs
WITH contract_activity AS (
SELECT
contract_address,
COUNT(*) AS event_count
FROM <blockchain_name>.core.fact_event_logs
WHERE block_timestamp >= CURRENT_DATE - 7
GROUP BY 1
)
SELECT
ca.contract_address,
c.name AS contract_name,
ca.event_count,
c.created_block_timestamp
FROM contract_activity ca
LEFT JOIN <blockchain_name>.core.dim_contract_abis abi ON ca.contract_address = abi.contract_address
LEFT JOIN <blockchain_name>.core.dim_contracts c ON ca.contract_address = c.address
WHERE abi.abi IS NULL
OR abi.abi = '[]'
ORDER BY ca.event_count DESC
LIMIT 100;
```
**Analyze ABI Functions and Events**
```sql
-- Extract event signatures from ABIs
WITH abi_events AS (
SELECT
contract_address,
abi_source,
f.value:name::string AS event_name,
f.value:type::string AS entry_type
FROM <blockchain_name>.core.dim_contract_abis,
LATERAL FLATTEN(input => PARSE_JSON(abi)) f
WHERE f.value:type::string = 'event'
AND abi IS NOT NULL
)
SELECT
event_name,
COUNT(DISTINCT contract_address) AS contracts_with_event,
ARRAY_AGG(DISTINCT abi_source) AS sources
FROM abi_events
GROUP BY 1
ORDER BY 2 DESC
LIMIT 50;
```
**Bytecode Matching Effectiveness**
```sql
-- Analyze bytecode matching success
SELECT
DATE_TRUNC('week', created_timestamp) AS week,
COUNT(CASE WHEN abi_source = 'bytecode_matched' THEN 1 END) AS bytecode_matched,
COUNT(CASE WHEN abi_source = 'user_submitted' THEN 1 END) AS user_submitted,
COUNT(CASE WHEN abi_source LIKE '%explorer%' THEN 1 END) AS explorer_verified,
COUNT(*) AS total_new_abis
FROM <blockchain_name>.core.dim_contract_abis
WHERE created_timestamp >= CURRENT_DATE - 90
GROUP BY 1
ORDER BY 1 DESC;
```
**Common Contract Patterns**
```sql
-- Find contracts sharing bytecode (proxy patterns, clones)
WITH bytecode_groups AS (
SELECT
bytecode,
COUNT(DISTINCT contract_address) AS contract_count,
ARRAY_AGG(DISTINCT contract_address) AS contracts,
MAX(abi) AS sample_abi
FROM <blockchain_name>.core.dim_contract_abis
WHERE bytecode IS NOT NULL
AND LENGTH(bytecode) > 100 -- Exclude minimal contracts
GROUP BY 1
HAVING COUNT(DISTINCT contract_address) > 5
)
SELECT
contract_count,
ARRAY_SIZE(contracts) AS unique_addresses,
LEFT(bytecode, 20) || '...' AS bytecode_prefix,
CASE
WHEN sample_abi LIKE '%proxy%' THEN 'Likely Proxy'
WHEN sample_abi LIKE '%clone%' THEN 'Likely Clone'
ELSE 'Standard Pattern'
END AS pattern_type
FROM bytecode_groups
ORDER BY contract_count DESC
LIMIT 20;
```
{% enddocs %}
{% docs dim_contract_abis_abi %}
The contract's Application Binary Interface in JSON format, containing function and event definitions that enable interaction with the smart contract.
Example: '[{"name":"transfer","type":"function","inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"outputs":[{"name":"","type":"bool"}]}]'
{% enddocs %}
{% docs dim_contract_abis_abi_source %}
The origin of the ABI data, indicating trust level and collection method.
Example: 'etherscan'
{% enddocs %}
{% docs dim_contract_abis_bytecode %}
The compiled contract code deployed on-chain, used for bytecode matching and identifying identical contracts.
Example: '0x608060405234801561001057600080fd5b50...'
{% enddocs %}

View File

@ -0,0 +1,124 @@
{% docs dim_contracts_table_doc %}
## What
This table provides comprehensive metadata for all smart contracts deployed on EVM blockchains. It includes contract names, symbols, decimals, and deployment details read directly from the blockchain.
## Key Use Cases
- Identifying contracts by name, symbol, or address
- Understanding token properties (decimals, symbols)
- Tracking contract deployment patterns and trends
- Finding contracts deployed by specific factories or deployers
- Filtering protocol-specific data across other tables
## Important Relationships
- **Join with fact_transactions**: Use `address = to_address` for contract interactions
- **Join with fact_event_logs**: Use `address = contract_address` for contract events
- **Join with ez_token_transfers**: Use `address = contract_address` for token movements
## Commonly-used Fields
- `address`: The deployed contract's blockchain address (lowercase)
- `name`: Human-readable contract name from the name() function
- `symbol`: Token/contract symbol from the symbol() function
- `decimals`: Number of decimal places for token amounts
- `creator_address`: Address that deployed this contract
- `created_block_timestamp`: When the contract was created
## Sample queries
**Find All Uniswap V3 Pool Contracts**
```sql
SELECT
address,
name,
created_block_number,
created_block_timestamp,
creator_address
FROM <blockchain_name>.core.dim_contracts
WHERE creator_address = LOWER('0x1F98431c8aD98523631AE4a59f267346ea31F984') -- Uniswap V3 Factory
ORDER BY created_block_number DESC
LIMIT 100;
```
**Analyze Contract Deployment Trends**
```sql
SELECT
DATE_TRUNC('week', created_block_timestamp) AS week,
COUNT(*) AS contracts_deployed,
COUNT(DISTINCT creator_address) AS unique_deployers
FROM <blockchain_name>.core.dim_contracts
WHERE created_block_timestamp >= CURRENT_DATE - 90
GROUP BY 1, 2
ORDER BY 1 DESC, 3 DESC;
```
{% enddocs %}
{% docs dim_contracts_created_block_number %}
Block number when contract was created.
Example: 17500000
{% enddocs %}
{% docs dim_contracts_created_block_timestamp %}
Timestamp when contract was created.
Example: 2023-06-15 14:30:00.000
{% enddocs %}
{% docs dim_contracts_address %}
Unique identifier - the deployed contract's blockchain address.
Example: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
{% enddocs %}
{% docs dim_contracts_name %}
Human-readable contract name from the name() function.
Example: 'USD Coin'
{% enddocs %}
{% docs dim_contracts_symbol %}
Token/contract symbol from the symbol() function.
Example: 'USDC'
{% enddocs %}
{% docs dim_contracts_creator_address %}
Address that deployed this contract (transaction from_address).
Example: '0x95ba4cf87d6723ad9c0db21737d862be80e93911'
{% enddocs %}
{% docs dim_contracts_decimals %}
Number of decimal places for token amounts, read directly from the contract code.
Example: 6
{% enddocs %}
{% docs dim_contracts_created_tx_hash %}
Transaction hash of the contract deployment.
Example: '0x4f01db1f857e711af502ad6fa8b5b3ccd9e36b5f8c8a7b2c1d3e4f5a6b7c8d9e'
{% enddocs %}

View File

@ -0,0 +1,28 @@
{{ config (
materialized = "incremental",
unique_key = "contract_address",
merge_exclude_columns = ["inserted_timestamp"],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(contract_address,bytecode)",
tags = ['abis']
) }}
SELECT
contract_address,
DATA AS abi,
abi_source,
bytecode,
abis_id AS dim_contract_abis_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp
FROM
{{ ref('silver_evm__abis') }}
{% if is_incremental() %}
WHERE
modified_timestamp > (
SELECT
COALESCE(MAX(modified_timestamp),'1970-01-01' :: TIMESTAMP)
FROM
{{ this }}
)
{% endif %}

View File

@ -0,0 +1,14 @@
version: 2
models:
- name: core_evm__dim_contract_abis
description: '{{ doc("dim_contract_abis_table_doc") }}'
columns:
- name: CONTRACT_ADDRESS
description: '{{ doc("dim_contracts_address") }}'
- name: ABI
description: '{{ doc("dim_contract_abis_abi") }}'
- name: ABI_SOURCE
description: '{{ doc("dim_contract_abis_abi_source") }}'
- name: BYTECODE
description: '{{ doc("dim_contract_abis_bytecode") }}'

View File

@ -16,7 +16,7 @@ SELECT
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
{{ ref('silver_evm__transactions') }}
{{ ref('core_evm__fact_transactions') }}
{% if is_incremental() %}
WHERE