From 766718fcd6997cd312a0c5d4d83f7c0f857ea08b Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Tue, 16 Dec 2025 13:10:08 -0800 Subject: [PATCH] Improve user_balance naming --- api/dbv1/models.go | 41 +++++++++++++++++++++++++++----- api/v1_users_coin.go | 8 +++---- api/v1_users_coins.go | 4 ++-- api/v1_wallet_coins.go | 4 ++-- ddl/views/artist_coin_prices.sql | 6 +---- sql/01_schema.sql | 10 ++++---- 6 files changed, 50 insertions(+), 23 deletions(-) diff --git a/api/dbv1/models.go b/api/dbv1/models.go index bf629728..ac9f75cd 100644 --- a/api/dbv1/models.go +++ b/api/dbv1/models.go @@ -882,13 +882,14 @@ type ArtistCoinPool struct { CreatorWalletAddress pgtype.Text `json:"creator_wallet_address"` } -// View that provides artist coin prices using DAMM V2 pool if available, DBC pools if not and still applicable, and stats table if nothing else. Makes use of the price of the quote token (AUDIO) from Birdeye if using a pool. +// View that provides artist coin prices using DAMM V2 pool if available, DBC pools if not and still applicable, stats table if available, and artist_coin_pools.price_usd as final fallback. Makes use of the price of the quote token (AUDIO) from Birdeye if using a pool. type ArtistCoinPrice struct { - Mint string `json:"mint"` - DammV2Price pgtype.Int4 `json:"damm_v2_price"` - DbcPrice pgtype.Int4 `json:"dbc_price"` - StatsPrice pgtype.Float8 `json:"stats_price"` - Price int32 `json:"price"` + Mint string `json:"mint"` + DammV2Price pgtype.Int4 `json:"damm_v2_price"` + DbcPrice pgtype.Int4 `json:"dbc_price"` + StatsPrice pgtype.Float8 `json:"stats_price"` + PoolsPriceUsd pgtype.Float8 `json:"pools_price_usd"` + Price int32 `json:"price"` } type ArtistCoinStat struct { @@ -1092,6 +1093,21 @@ type CidDatum struct { Data []byte `json:"data"` } +// Stores claimed prizes where users pay tokens to claim and win prizes. +type ClaimedPrize struct { + ID int32 `json:"id"` + Wallet string `json:"wallet"` + Signature string `json:"signature"` + Mint string `json:"mint"` + Amount int64 `json:"amount"` + PrizeID string `json:"prize_id"` + PrizeName string `json:"prize_name"` + PrizeType pgtype.Text `json:"prize_type"` + ActionData []byte `json:"action_data"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + // Stores collectibles data for users type Collectible struct { // User ID of the person who owns the collectibles @@ -1440,6 +1456,19 @@ type PlaylistTrendingScore struct { CreatedAt time.Time `json:"created_at"` } +// Defines prizes available for claiming. Prizes are selected randomly based on weight. +type Prize struct { + ID int32 `json:"id"` + PrizeID string `json:"prize_id"` + Name string `json:"name"` + Description pgtype.Text `json:"description"` + Weight int32 `json:"weight"` + IsActive bool `json:"is_active"` + Metadata []byte `json:"metadata"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + type Pubkey struct { Wallet string `json:"wallet"` Pubkey pgtype.Text `json:"pubkey"` diff --git a/api/v1_users_coin.go b/api/v1_users_coin.go index 2e3b5803..3fdea805 100644 --- a/api/v1_users_coin.go +++ b/api/v1_users_coin.go @@ -83,21 +83,21 @@ func (app *ApiServer) v1UsersCoin(c *fiber.Ctx) error { artist_coins.logo_uri, artist_coins.banner_image_url, COALESCE(balances_by_mint.balance, 0) AS balance, - COALESCE((balances_by_mint.balance * COALESCE(acp.price, 0)) / POWER(10, artist_coins.decimals), 0) AS balance_usd, + COALESCE((balances_by_mint.balance * COALESCE(coin_prices.price, 0)) / POWER(10, artist_coins.decimals), 0) AS balance_usd, COALESCE( JSON_AGG( JSON_BUILD_OBJECT( 'account', balances.account, 'owner', balances.owner, 'balance', balances.balance, - 'balance_usd', (balances.balance * COALESCE(acp.price, 0)) / POWER(10, artist_coins.decimals), + 'balance_usd', (balances.balance * COALESCE(coin_prices.price, 0)) / POWER(10, artist_coins.decimals), 'is_in_app_wallet', balances.is_in_app_wallet ) ) FILTER (WHERE balances.account IS NOT NULL), '[]'::json ) AS accounts FROM artist_coins - LEFT JOIN artist_coin_prices acp ON acp.mint = artist_coins.mint + LEFT JOIN artist_coin_prices coin_prices ON coin_prices.mint = artist_coins.mint LEFT JOIN balances_by_mint ON artist_coins.mint = balances_by_mint.mint LEFT JOIN ( SELECT * @@ -113,7 +113,7 @@ func (app *ApiServer) v1UsersCoin(c *fiber.Ctx) error { artist_coins.logo_uri, artist_coins.banner_image_url, balances_by_mint.balance, - acp.price + coin_prices.price ;` rows, err := app.pool.Query(c.Context(), sql, pgx.NamedArgs{ diff --git a/api/v1_users_coins.go b/api/v1_users_coins.go index 03631ca7..ed0b3ac7 100644 --- a/api/v1_users_coins.go +++ b/api/v1_users_coins.go @@ -73,10 +73,10 @@ func (app *ApiServer) v1UsersCoins(c *fiber.Ctx) error { artist_coins.logo_uri, artist_coins.banner_image_url, COALESCE(balances_by_mint.balance, 0) AS balance, - (COALESCE(balances_by_mint.balance, 0) * COALESCE(acp.price, 0)) / POWER(10, artist_coins.decimals) AS balance_usd + (COALESCE(balances_by_mint.balance, 0) * COALESCE(coin_prices.price, 0)) / POWER(10, artist_coins.decimals) AS balance_usd FROM artist_coins LEFT JOIN balances_by_mint ON balances_by_mint.mint = artist_coins.mint - LEFT JOIN artist_coin_prices acp ON acp.mint = artist_coins.mint + LEFT JOIN artist_coin_prices coin_prices ON coin_prices.mint = artist_coins.mint WHERE artist_coins.user_id = @user_id -- Show owned coins OR balance > 0 -- Show coins with positive balance OR ticker = 'AUDIO' -- Always show AUDIO diff --git a/api/v1_wallet_coins.go b/api/v1_wallet_coins.go index f556a87b..d8052bc4 100644 --- a/api/v1_wallet_coins.go +++ b/api/v1_wallet_coins.go @@ -43,10 +43,10 @@ func (app *ApiServer) v1WalletCoins(c *fiber.Ctx) error { artist_coins.logo_uri, artist_coins.banner_image_url, COALESCE(balances_by_mint.balance, 0) AS balance, - (COALESCE(balances_by_mint.balance, 0) * COALESCE(acp.price, 0)) / POWER(10, artist_coins.decimals) AS balance_usd + (COALESCE(balances_by_mint.balance, 0) * COALESCE(coin_prices.price, 0)) / POWER(10, artist_coins.decimals) AS balance_usd FROM artist_coins LEFT JOIN balances_by_mint ON balances_by_mint.mint = artist_coins.mint - LEFT JOIN artist_coin_prices acp ON acp.mint = artist_coins.mint + LEFT JOIN artist_coin_prices coin_prices ON coin_prices.mint = artist_coins.mint WHERE balance > 0 -- Show coins with positive balance ORDER BY -- Prioritize AUDIO diff --git a/ddl/views/artist_coin_prices.sql b/ddl/views/artist_coin_prices.sql index 9648a195..afbaddc5 100644 --- a/ddl/views/artist_coin_prices.sql +++ b/ddl/views/artist_coin_prices.sql @@ -29,20 +29,16 @@ CREATE VIEW artist_coin_prices AS artist_coins.mint, damm_v2.price AS damm_v2_price, dbc.price AS dbc_price, - stats.price AS stats_price, pools.price_usd AS pools_price_usd, COALESCE( damm_v2.price, dbc.price, - stats.price, pools.price_usd ) AS price FROM artist_coins LEFT JOIN dbc ON artist_coins.mint = dbc.mint LEFT JOIN damm_v2 ON artist_coins.mint = damm_v2.mint - LEFT JOIN artist_coin_stats AS stats - ON stats.mint = artist_coins.mint LEFT JOIN artist_coin_pools AS pools ON pools.base_mint = artist_coins.mint; -COMMENT ON VIEW artist_coin_prices IS 'View that provides artist coin prices using DAMM V2 pool if available, DBC pools if not and still applicable, stats table if available, and artist_coin_pools.price_usd as final fallback. Makes use of the price of the quote token (AUDIO) from Birdeye if using a pool.'; \ No newline at end of file +COMMENT ON VIEW artist_coin_prices IS 'View that provides artist coin prices using DAMM V2 pool if available, DBC pools if not and still applicable, and artist_coin_pools.price_usd as final fallback. Makes use of the price of the quote token (AUDIO) from Birdeye if using a pool.'; \ No newline at end of file diff --git a/sql/01_schema.sql b/sql/01_schema.sql index f42b24c1..5b052d37 100644 --- a/sql/01_schema.sql +++ b/sql/01_schema.sql @@ -6233,18 +6233,20 @@ CREATE VIEW public.artist_coin_prices AS damm_v2.price AS damm_v2_price, dbc.price AS dbc_price, stats.price AS stats_price, - COALESCE(damm_v2.price, dbc.price, stats.price) AS price - FROM (((public.artist_coins + pools.price_usd AS pools_price_usd, + COALESCE(damm_v2.price, dbc.price, stats.price, pools.price_usd) AS price + FROM ((((public.artist_coins LEFT JOIN dbc ON (((artist_coins.mint)::text = (dbc.mint)::text))) LEFT JOIN damm_v2 ON (((artist_coins.mint)::text = (damm_v2.mint)::text))) - JOIN public.artist_coin_stats stats ON ((stats.mint = (artist_coins.mint)::text))); + LEFT JOIN public.artist_coin_stats stats ON ((stats.mint = (artist_coins.mint)::text))) + LEFT JOIN public.artist_coin_pools pools ON ((pools.base_mint = (artist_coins.mint)::text))); -- -- Name: VIEW artist_coin_prices; Type: COMMENT; Schema: public; Owner: - -- -COMMENT ON VIEW public.artist_coin_prices IS 'View that provides artist coin prices using DAMM V2 pool if available, DBC pools if not and still applicable, and stats table if nothing else. Makes use of the price of the quote token (AUDIO) from Birdeye if using a pool.'; +COMMENT ON VIEW public.artist_coin_prices IS 'View that provides artist coin prices using DAMM V2 pool if available, DBC pools if not and still applicable, stats table if available, and artist_coin_pools.price_usd as final fallback. Makes use of the price of the quote token (AUDIO) from Birdeye if using a pool.'; --