|
| 1 | +-- Address reputation processor (P0): transfer graph + bridge inflows + per-address score. |
| 2 | + |
| 3 | +-- One row per FA / coin transfer between two distinct Aptos addresses. |
| 4 | +CREATE TABLE IF NOT EXISTS address_transfer_edges ( |
| 5 | + transaction_version BIGINT NOT NULL, |
| 6 | + event_index BIGINT NOT NULL, |
| 7 | + from_address VARCHAR(66) NOT NULL, |
| 8 | + to_address VARCHAR(66) NOT NULL, |
| 9 | + asset_type VARCHAR(1100), |
| 10 | + amount NUMERIC NOT NULL, |
| 11 | + is_bridge_inflow BOOLEAN NOT NULL DEFAULT FALSE, |
| 12 | + bridge_name VARCHAR(64), |
| 13 | + transaction_timestamp TIMESTAMP NOT NULL, |
| 14 | + inserted_at TIMESTAMP NOT NULL DEFAULT NOW(), |
| 15 | + PRIMARY KEY (transaction_version, event_index) |
| 16 | +); |
| 17 | +CREATE INDEX IF NOT EXISTS idx_ate_to_ts ON address_transfer_edges (to_address, transaction_timestamp); |
| 18 | +CREATE INDEX IF NOT EXISTS idx_ate_from_ts ON address_transfer_edges (from_address, transaction_timestamp); |
| 19 | +CREATE INDEX IF NOT EXISTS idx_ate_bridge ON address_transfer_edges (bridge_name) WHERE is_bridge_inflow; |
| 20 | + |
| 21 | +-- (Bridge configuration lives in the processor's YAML config, not in the database. |
| 22 | +-- This keeps mainnet/testnet/devnet deploys swappable without a SQL migration. See |
| 23 | +-- AddressReputationConfig.bridges in processor/src/processors/address_reputation/address_reputation_config.rs.) |
| 24 | + |
| 25 | +-- Bridge deposit events on Aptos. The cross-chain EVM source is the "head" of any trace. |
| 26 | +CREATE TABLE IF NOT EXISTS bridge_inflows ( |
| 27 | + transaction_version BIGINT NOT NULL, |
| 28 | + event_index BIGINT NOT NULL, |
| 29 | + bridge_name VARCHAR(64) NOT NULL, |
| 30 | + aptos_recipient VARCHAR(66) NOT NULL, |
| 31 | + evm_source VARCHAR(66), |
| 32 | + src_chain_id INTEGER, |
| 33 | + asset_type VARCHAR(1100), |
| 34 | + amount NUMERIC NOT NULL, |
| 35 | + transaction_timestamp TIMESTAMP NOT NULL, |
| 36 | + inserted_at TIMESTAMP NOT NULL DEFAULT NOW(), |
| 37 | + PRIMARY KEY (transaction_version, event_index) |
| 38 | +); |
| 39 | +CREATE INDEX IF NOT EXISTS idx_bi_recipient ON bridge_inflows (aptos_recipient); |
| 40 | +CREATE INDEX IF NOT EXISTS idx_bi_evm_source ON bridge_inflows (evm_source); |
| 41 | + |
| 42 | +-- Risk scores for EVM addresses, populated by an external screening pipeline. |
| 43 | +CREATE TABLE IF NOT EXISTS evm_address_risk_scores ( |
| 44 | + evm_address VARCHAR(66) NOT NULL PRIMARY KEY, |
| 45 | + risk_score NUMERIC(5,4) NOT NULL, |
| 46 | + risk_label VARCHAR(32), |
| 47 | + source VARCHAR(64), |
| 48 | + fetched_at TIMESTAMP NOT NULL DEFAULT NOW(), |
| 49 | + inserted_at TIMESTAMP NOT NULL DEFAULT NOW() |
| 50 | +); |
| 51 | + |
| 52 | +-- Materialized per-address reputation. Updated on every new inbound edge. |
| 53 | +CREATE TABLE IF NOT EXISTS address_reputation ( |
| 54 | + address VARCHAR(66) NOT NULL PRIMARY KEY, |
| 55 | + score NUMERIC(5,4) NOT NULL DEFAULT 0, |
| 56 | + highest_seed NUMERIC(5,4) NOT NULL DEFAULT 0, |
| 57 | + nearest_seed_hop INTEGER, |
| 58 | + last_updated_version BIGINT NOT NULL, |
| 59 | + last_updated_timestamp TIMESTAMP NOT NULL, |
| 60 | + inserted_at TIMESTAMP NOT NULL DEFAULT NOW() |
| 61 | +); |
| 62 | +CREATE INDEX IF NOT EXISTS idx_ar_score ON address_reputation (score DESC); |
| 63 | + |
| 64 | +-- Seed: Circle USDCx bridge (Movement's bridged USDC, ../usdc-bridge/smart_contracts/sources/usdcx.move). |
| 65 | +-- The Mint event is emitted when funds arrive from a remote chain (USDC -> USDCx mint). |
| 66 | +-- Fields available in the event: |
| 67 | +-- recipient (address, Movement-side owner), amount (u64), fee_amount, relayer, |
| 68 | +-- remote_domain (u32, source chain id), remote_token (address, source-chain USDC), nonce. |
| 69 | +-- The EVM depositor address is NOT in the event payload -- it is carried inside the |
| 70 | +-- `intent_payload` entry function argument and would need BCS-decoding to recover. |
| 71 | +-- For P0 we record the inflow with NULL evm_source; downstream can backfill it. |
| 72 | +-- |
0 commit comments