|
| 1 | +import { |
| 2 | + Entity, |
| 3 | + PrimaryGeneratedColumn, |
| 4 | + Column, |
| 5 | + CreateDateColumn, |
| 6 | + Index, |
| 7 | +} from "typeorm"; |
| 8 | + |
| 9 | +export enum SupportedChain { |
| 10 | + ETHEREUM = "ethereum", |
| 11 | + BSC = "bsc", |
| 12 | + POLYGON = "polygon", |
| 13 | + ARBITRUM = "arbitrum", |
| 14 | + OPTIMISM = "optimism", |
| 15 | + AVALANCHE = "avalanche", |
| 16 | +} |
| 17 | + |
| 18 | +export enum PriceSource { |
| 19 | + CHAINLINK = "chainlink", |
| 20 | + BAND = "band", |
| 21 | + UNISWAP_TWAP = "uniswap_twap", |
| 22 | +} |
| 23 | + |
| 24 | +@Entity("price_records") |
| 25 | +@Index(["asset", "chain", "createdAt"]) |
| 26 | +@Index(["asset", "createdAt"]) |
| 27 | +export class PriceRecord { |
| 28 | + @PrimaryGeneratedColumn("uuid") |
| 29 | + id: string; |
| 30 | + |
| 31 | + /** Asset symbol, e.g. "ETH", "BTC" */ |
| 32 | + @Column({ type: "varchar", length: 20 }) |
| 33 | + asset: string; |
| 34 | + |
| 35 | + @Column({ type: "enum", enum: SupportedChain }) |
| 36 | + chain: SupportedChain; |
| 37 | + |
| 38 | + /** Canonical median price in USD */ |
| 39 | + @Column({ type: "decimal", precision: 30, scale: 8 }) |
| 40 | + price: number; |
| 41 | + |
| 42 | + /** Raw prices per source, e.g. { chainlink: 2000.5, band: 2001.0, uniswap_twap: 1999.8 } */ |
| 43 | + @Column({ type: "jsonb" }) |
| 44 | + sourcePrices: Record<PriceSource, number>; |
| 45 | + |
| 46 | + /** Whether a >5% deviation was detected between sources */ |
| 47 | + @Column({ type: "boolean", default: false }) |
| 48 | + deviationAlert: boolean; |
| 49 | + |
| 50 | + /** Max % deviation observed between sources */ |
| 51 | + @Column({ type: "decimal", precision: 8, scale: 4, default: 0 }) |
| 52 | + maxDeviationPercent: number; |
| 53 | + |
| 54 | + @CreateDateColumn() |
| 55 | + createdAt: Date; |
| 56 | +} |
0 commit comments