Merge pull request #131 from agnosticeng/feat/instance-id
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
select
|
||||
date_trunc('hour', timestamp) as "datetime",
|
||||
quantile (0.5) (reinterpretAsUInt256 (effective_gas_price) / 1e9) as "average",
|
||||
quantile (0.9) (reinterpretAsUInt256 (effective_gas_price) / 1e9) as "fast"
|
||||
from
|
||||
agnostic__blockchain__ethereum_mainnet__transactions
|
||||
where
|
||||
date = yesterday ()
|
||||
group by
|
||||
"datetime"
|
||||
order by
|
||||
"datetime"
|
||||
@@ -1,29 +0,0 @@
|
||||
with
|
||||
evm_hex_decode ('0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8') as usdc_weth_03_pool_address,
|
||||
18 as weth_decimals,
|
||||
6 as usdc_decimals,
|
||||
prices as (
|
||||
select
|
||||
timestamp,
|
||||
1 / (
|
||||
pow (1.0001, JSONExtract (inputs, 'arg6', 'Int32')) / pow (10, weth_decimals - usdc_decimals)
|
||||
) as price
|
||||
from
|
||||
agnostic__blockchain__ethereum_mainnet__decoded_logs
|
||||
where
|
||||
date >= '2025-01-01'
|
||||
and address = usdc_weth_03_pool_address
|
||||
and signature = 'Swap(address,address,int256,int256,uint160,uint128,int24)'
|
||||
)
|
||||
select
|
||||
date_trunc('day', timestamp) as "datetime",
|
||||
argMin (price, timestamp) as "open",
|
||||
argMax (price, timestamp) as "close",
|
||||
min(price) as "low",
|
||||
max(price) as "high"
|
||||
from
|
||||
prices
|
||||
group by
|
||||
"datetime"
|
||||
order by
|
||||
"datetime" asc
|
||||
@@ -1,14 +0,0 @@
|
||||
import GAS_PRICE from './example1.sql?raw';
|
||||
import TOKEN_PRICE from './example2.sql?raw';
|
||||
|
||||
const AGX = location.hostname === 'agx.app' || location.hostname.endsWith('agx-80h.pages.dev');
|
||||
|
||||
export const EXAMPLES_TABS = AGX
|
||||
? [GAS_PRICE, TOKEN_PRICE].map((example: string, index: number) => [
|
||||
crypto.randomUUID(),
|
||||
`Example ${index + 1}`,
|
||||
example,
|
||||
index,
|
||||
null
|
||||
])
|
||||
: [];
|
||||
@@ -10,22 +10,25 @@ const CACHE_KEY = 'db';
|
||||
export class Database {
|
||||
private db = new SQLite();
|
||||
private cache = new IndexedDBCache({ dbName: DB_NAME, storeName: STORE_NAME });
|
||||
private cache_key: string;
|
||||
|
||||
private init_promise: Promise<void>;
|
||||
|
||||
constructor() {
|
||||
const instanceID = new URLSearchParams(window.location.search).get('instance-id');
|
||||
this.cache_key = instanceID ? `${CACHE_KEY}-${instanceID}` : CACHE_KEY;
|
||||
this.init_promise = this.init();
|
||||
}
|
||||
|
||||
private async init() {
|
||||
const snapshot = await this.cache.get(CACHE_KEY);
|
||||
const snapshot = await this.cache.get(this.cache_key);
|
||||
if (snapshot) await this.db.load_db(snapshot);
|
||||
|
||||
this.db.on('exec', debounce(this.snapshot.bind(this), 1000));
|
||||
}
|
||||
|
||||
private async snapshot() {
|
||||
await this.cache.set(CACHE_KEY, await this.db.export_db());
|
||||
await this.cache.set(this.cache_key, await this.db.export_db());
|
||||
}
|
||||
|
||||
async exec(sql: string, bind?: BindingSpec) {
|
||||
|
||||
@@ -6,14 +6,12 @@
|
||||
import { store } from '$lib/store';
|
||||
import { MigrationManager } from '@agnosticeng/migrate';
|
||||
|
||||
import { createAuthService, checkLoginState, type AuthService } from '$lib/auth';
|
||||
import { detectRuntime, type Runtime } from '$lib/env/runtime';
|
||||
import { checkLoginState, createAuthService, type AuthService } from '$lib/auth';
|
||||
import { detectRuntime } from '$lib/env/runtime';
|
||||
|
||||
import { ContextMenu, ContextMenuState } from '$lib/components/ContextMenu';
|
||||
import { setAppContext } from '$lib/context';
|
||||
|
||||
import { EXAMPLES_TABS } from '$lib/onboarding';
|
||||
|
||||
let { children } = $props();
|
||||
let mounted = $state(false);
|
||||
let authenticated = $state(false);
|
||||
@@ -42,13 +40,14 @@
|
||||
}
|
||||
});
|
||||
|
||||
async function displayOnboarding() {
|
||||
for (const example of EXAMPLES_TABS) {
|
||||
async function displayExample() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const example = params.get('example');
|
||||
if (example)
|
||||
await store.exec(
|
||||
`INSERT INTO tabs (id, name, content, tab_index, active) VALUES (?, ?, ?, ?, ?)`,
|
||||
example
|
||||
'INSERT INTO tabs (id, name, content, tab_index, active) VALUES (?, ?, ?, ?, ?)',
|
||||
[crypto.randomUUID(), 'Preview', example, 0, null]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
@@ -60,14 +59,11 @@
|
||||
checkLoginState(runtime, authService);
|
||||
authenticated = !!(await authService.getSession());
|
||||
|
||||
const m = new MigrationManager(store);
|
||||
await m.migrate(MIGRATIONS);
|
||||
const migration = new MigrationManager(store);
|
||||
await migration.migrate(MIGRATIONS);
|
||||
|
||||
const [{ count }] = await store.exec('SELECT COUNT(*) as count FROM tabs');
|
||||
|
||||
if (count === 0) {
|
||||
await displayOnboarding();
|
||||
}
|
||||
if (count === 0) await displayExample();
|
||||
|
||||
mounted = true;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user