-
Notifications
You must be signed in to change notification settings - Fork 1
Solana Indexer DBC pool improvements #485
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
Changes from all commits
98628df
cbb628f
8ca5871
5fba7c1
b1a766b
c103dda
a497302
d2f3d7f
4d6ce96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| BEGIN; | ||
|
|
||
| ALTER TABLE artist_coins DROP COLUMN IF EXISTS dbc_pool; | ||
|
|
||
| COMMIT; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| BEGIN; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS sol_meteora_dbc_pool_metrics ( | ||
| pool TEXT PRIMARY KEY, | ||
| slot BIGINT NOT NULL, | ||
| total_protocol_base_fee BIGINT NOT NULL, | ||
| total_protocol_quote_fee BIGINT NOT NULL, | ||
| total_trading_base_fee BIGINT NOT NULL, | ||
| total_trading_quote_fee BIGINT NOT NULL, | ||
| created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS sol_meteora_dbc_pool_volatility_trackers ( | ||
| pool TEXT PRIMARY KEY, | ||
| slot BIGINT NOT NULL, | ||
| last_update_timestamp BIGINT NOT NULL, | ||
| volatility_accumulator NUMERIC NOT NULL, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't use dynamic fees, but i guess we can track this |
||
| volatility_reference NUMERIC NOT NULL, | ||
| created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
| ); | ||
|
|
||
| COMMIT; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "api.audius.co/database" | ||
| "github.com/jackc/pgx/v5" | ||
| ) | ||
|
|
||
| func GetArtistCoinMints(ctx context.Context, db database.DBTX, limit int, offset int) ([]string, error) { | ||
| sqlMints := `SELECT mint FROM artist_coins LIMIT @limit OFFSET @offset` | ||
| rows, err := db.Query(ctx, sqlMints, pgx.NamedArgs{ | ||
| "limit": limit, | ||
| "offset": offset, | ||
| }) | ||
| if err != nil { | ||
| if err == pgx.ErrNoRows { | ||
| return nil, nil // No mints found, return empty slice | ||
| } | ||
| return nil, fmt.Errorf("failed to query mints: %w", err) | ||
| } | ||
| mintAddresses, err := pgx.CollectRows(rows, pgx.RowTo[string]) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to collect mints: %w", err) | ||
| } | ||
| return mintAddresses, nil | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,6 +279,7 @@ func upsertDbcPool( | |
| creator_base_fee = EXCLUDED.creator_base_fee, | ||
| creator_quote_fee = EXCLUDED.creator_quote_fee, | ||
| updated_at = NOW() | ||
| WHERE EXCLUDED.slot > sol_meteora_dbc_pools.slot | ||
| ;` | ||
| _, err := db.Exec(ctx, sql, pgx.NamedArgs{ | ||
| "account": account.String(), | ||
|
|
@@ -310,3 +311,93 @@ func upsertDbcPool( | |
| }) | ||
| return err | ||
| } | ||
|
|
||
| func upsertDbcPoolMetrics( | ||
| ctx context.Context, | ||
| db database.DBTX, | ||
| slot uint64, | ||
| account solana.PublicKey, | ||
| metrics *meteora_dbc.PoolMetrics, | ||
| ) error { | ||
| sql := ` | ||
| INSERT INTO sol_meteora_dbc_pool_metrics ( | ||
| pool, | ||
| slot, | ||
| total_protocol_base_fee, | ||
| total_protocol_quote_fee, | ||
| total_trading_base_fee, | ||
| total_trading_quote_fee, | ||
| created_at, | ||
| updated_at | ||
| ) VALUES ( | ||
| @pool, | ||
| @slot, | ||
| @total_protocol_base_fee, | ||
| @total_protocol_quote_fee, | ||
| @total_trading_base_fee, | ||
| @total_trading_quote_fee, | ||
| NOW(), | ||
| NOW() | ||
| ) ON CONFLICT (pool) DO UPDATE SET | ||
| slot = EXCLUDED.slot, | ||
| total_protocol_base_fee = EXCLUDED.total_protocol_base_fee, | ||
| total_protocol_quote_fee = EXCLUDED.total_protocol_quote_fee, | ||
| total_trading_base_fee = EXCLUDED.total_trading_base_fee, | ||
| total_trading_quote_fee = EXCLUDED.total_trading_quote_fee, | ||
| updated_at = NOW() | ||
| WHERE EXCLUDED.slot > sol_meteora_dbc_pool_metrics.slot | ||
| ;` | ||
|
|
||
| _, err := db.Exec(ctx, sql, pgx.NamedArgs{ | ||
| "pool": account.String(), | ||
| "slot": slot, | ||
| "total_protocol_base_fee": metrics.TotalProtocolBaseFee, | ||
| "total_protocol_quote_fee": metrics.TotalProtocolQuoteFee, | ||
| "total_trading_base_fee": metrics.TotalTradingBaseFee, | ||
| "total_trading_quote_fee": metrics.TotalTradingQuoteFee, | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| func upsertDbcPoolVolatilityTracker( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also not necessary, but doesn't hurt |
||
| ctx context.Context, | ||
| db database.DBTX, | ||
| slot uint64, | ||
| account solana.PublicKey, | ||
| volatilityTracker *meteora_dbc.VolatilityTracker, | ||
| ) error { | ||
| sql := ` | ||
| INSERT INTO sol_meteora_dbc_pool_volatility_trackers ( | ||
| pool, | ||
| slot, | ||
| last_update_timestamp, | ||
| volatility_accumulator, | ||
| volatility_reference, | ||
| created_at, | ||
| updated_at | ||
| ) VALUES ( | ||
| @pool, | ||
| @slot, | ||
| @last_update_timestamp, | ||
| @volatility_accumulator, | ||
| @volatility_reference, | ||
| NOW(), | ||
| NOW() | ||
| ) ON CONFLICT (pool) DO UPDATE SET | ||
| slot = EXCLUDED.slot, | ||
| last_update_timestamp = EXCLUDED.last_update_timestamp, | ||
| volatility_accumulator = EXCLUDED.volatility_accumulator, | ||
| volatility_reference = EXCLUDED.volatility_reference, | ||
| updated_at = NOW() | ||
| WHERE EXCLUDED.slot > sol_meteora_dbc_pool_volatility_trackers.slot | ||
| ;` | ||
|
|
||
| _, err := db.Exec(ctx, sql, pgx.NamedArgs{ | ||
| "pool": account.String(), | ||
| "slot": slot, | ||
| "last_update_timestamp": volatilityTracker.LastUpdateTimestamp, | ||
| "volatility_accumulator": volatilityTracker.VolatilityAccumulator.String(), | ||
| "volatility_reference": volatilityTracker.VolatilityReference.String(), | ||
| }) | ||
| return err | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ill open a PR to remove FE