Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions api/dbv1/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions api/swagger/swagger-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5664,7 +5664,6 @@ components:
- ticker
- decimals
- name
- dbc_pool
properties:
mint:
type: string
Expand Down Expand Up @@ -5692,10 +5691,6 @@ components:
type: string
description: The description of the coin
example: "A majestic bear token for wildlife conservation"
dbc_pool:
type: string
description: The address of the dynamic bonding curve pool associated with the coin
example: "2AAsAwNPTNBk5N466xyPiwqdgbc5WLbDTdnn9gVuDKaN"
create_coin_response:
type: object
properties:
Expand Down
6 changes: 2 additions & 4 deletions api/v1_create_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type CreateCoinBody struct {
Name string `json:"name" validate:"required,min=1,max=32"`
LogoUri string `json:"logo_uri" validate:"omitempty,url"`
Description string `json:"description" validate:"max=2500"`
DbcPool string `json:"dbc_pool"`
}

func (app *ApiServer) v1CreateCoin(c *fiber.Ctx) error {
Expand Down Expand Up @@ -63,8 +62,8 @@ func (app *ApiServer) v1CreateCoin(c *fiber.Ctx) error {
}

sql := `
INSERT INTO artist_coins (mint, ticker, user_id, decimals, name, logo_uri, description, dbc_pool)
VALUES (@mint, @ticker, @user_id, @decimals, @name, @logo_uri, @description, @dbc_pool)
INSERT INTO artist_coins (mint, ticker, user_id, decimals, name, logo_uri, description)
VALUES (@mint, @ticker, @user_id, @decimals, @name, @logo_uri, @description)
RETURNING mint, ticker, user_id, decimals, name, logo_uri, description, created_at
`

Expand All @@ -76,7 +75,6 @@ func (app *ApiServer) v1CreateCoin(c *fiber.Ctx) error {
"name": body.Name,
"logo_uri": body.LogoUri,
"description": body.Description,

Copy link
Copy Markdown
Member

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

"dbc_pool": body.DbcPool,
})

var result struct {
Expand Down
2 changes: 1 addition & 1 deletion ddl/functions/calculate_artist_coin_fees.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RETURNS TABLE (
SELECT
base_mint AS mint,
total_trading_quote_fee / 2 AS total_dbc_fees,
creator_quote_fee / 2 AS unclaimed_dbc_fees
creator_quote_fee AS unclaimed_dbc_fees
FROM artist_coin_pools
WHERE base_mint = artist_coin_mint
)
Expand Down
7 changes: 0 additions & 7 deletions ddl/functions/handle_artist_coins.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ BEGIN
PERFORM pg_notify('artist_coins_mint_changed', JSON_BUILD_OBJECT('new', NEW.mint, 'old', OLD.mint)::TEXT);
END IF;

IF (OLD.dbc_pool IS NULL AND NEW.dbc_pool IS NOT NULL)
OR (OLD.dbc_pool IS NOT NULL AND NEW.dbc_pool IS NULL)
OR OLD.dbc_pool != NEW.dbc_pool
THEN
PERFORM pg_notify('artist_coins_dbc_pool_changed', JSON_BUILD_OBJECT('new', NEW.dbc_pool, 'old', OLD.dbc_pool)::TEXT);
END IF;

IF (OLD.damm_v2_pool IS NULL AND NEW.damm_v2_pool IS NOT NULL)
OR (OLD.damm_v2_pool IS NOT NULL AND NEW.damm_v2_pool IS NULL)
OR OLD.damm_v2_pool != NEW.damm_v2_pool
Expand Down
5 changes: 5 additions & 0 deletions ddl/migrations/0173_drop_dbc_pool_again.sql
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;
24 changes: 24 additions & 0 deletions ddl/migrations/0174_dbc_pool_substructs.sql
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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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;
28 changes: 28 additions & 0 deletions solana/indexer/common/artist_coins.go
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
}
91 changes: 91 additions & 0 deletions solana/indexer/dbc/dbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
}
Loading
Loading