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
28 changes: 24 additions & 4 deletions api/swagger/swagger-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5266,6 +5266,7 @@ components:
required:
- mint
- ticker
- decimals
- balance
- balance_usd
type: object
Expand All @@ -5278,6 +5279,10 @@ components:
type: string
description: The coin symbol
example: "$AUDIO"
decimals:
type: integer
description: The number of decimals for the coin
example: 8
balance:
type: integer
description: The balance of the coin in the user's account (in wei)
Expand All @@ -5298,15 +5303,30 @@ components:
user_coin_with_accounts:
type: object
required:
- totalBalance
- totalBalanceUSD
- mint
- ticker
- decimals
- balance
- balance_usd
- accounts
properties:
totalBalance:
mint:
type: string
description: The coin mint address
example: "9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM"
ticker:
type: string
description: The coin symbol
example: "$AUDIO"
decimals:
type: integer
description: The number of decimals for the coin
example: 8
balance:
type: integer
description: The total balance of the coin in the user's account (in wei)
example: 1000000000
totalBalanceUSD:
balance_usd:
type: number
description: The total balance of the coin in the user's account in USD
example: 1.23
Expand Down
1 change: 1 addition & 0 deletions api/v1_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (app *ApiServer) v1Coin(c *fiber.Ctx) error {
SELECT
artist_coins.ticker,
artist_coins.mint,
artist_coins.decimals,
artist_coins.user_id,
artist_coins.created_at,
COALESCE(member_counts.members, 0) AS members,
Expand Down
6 changes: 4 additions & 2 deletions api/v1_coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ func TestGetCoin(t *testing.T) {

jsonAssert(t, body, map[string]any{
"data.ticker": "$USDC",
"data.owner_id": trashid.MustEncodeHashID(2),
"data.mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"data.decimals": 6,
"data.owner_id": trashid.MustEncodeHashID(2),
"data.members": 0,
"data.members_24h_change_percent": -100.0,
})
Expand All @@ -175,8 +176,9 @@ func TestGetCoin(t *testing.T) {

jsonAssert(t, body, map[string]any{
"data.ticker": "$AUDIO",
"data.owner_id": trashid.MustEncodeHashID(1),
"data.mint": "9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM",
"data.decimals": 8,
"data.owner_id": trashid.MustEncodeHashID(1),
"data.members": 2,
"data.members_24h_change_percent": 100.0,
})
Expand Down
2 changes: 2 additions & 0 deletions api/v1_coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type GetArtistCoinsQueryParams struct {
type ArtistCoin struct {
Ticker string `json:"ticker"`
Mint string `json:"mint"`
Decimals int `json:"decimals"`
OwnerId trashid.HashId `db:"user_id" json:"owner_id"`
Members int `json:"members"`
Members24hChangePercent *float64 `json:"members_24h_change_percent"`
Expand Down Expand Up @@ -104,6 +105,7 @@ func (app *ApiServer) v1Coins(c *fiber.Ctx) error {
SELECT
artist_coins.ticker,
artist_coins.mint,
artist_coins.decimals,
artist_coins.user_id,
artist_coins.created_at,
COALESCE(member_counts.members, 0) AS members,
Expand Down
15 changes: 10 additions & 5 deletions api/v1_coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ func TestGetCoins(t *testing.T) {

jsonAssert(t, body, map[string]any{
"data.0.ticker": "$AUDIO",
"data.0.owner_id": trashid.MustEncodeHashID(1),
"data.0.mint": "9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM",
"data.0.decimals": 8,
"data.0.owner_id": trashid.MustEncodeHashID(1),
"data.0.members": 2,
"data.0.members_24h_change_percent": 100.0,
"data.1.ticker": "$USDC",
"data.1.owner_id": trashid.MustEncodeHashID(2),
"data.1.mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"data.1.decimals": 6,
"data.1.owner_id": trashid.MustEncodeHashID(2),
"data.1.members": 0,
"data.1.members_24h_change_percent": -100.0,
})
Expand All @@ -139,8 +141,9 @@ func TestGetCoins(t *testing.T) {

jsonAssert(t, body, map[string]any{
"data.0.ticker": "$AUDIO",
"data.0.owner_id": trashid.MustEncodeHashID(1),
"data.0.mint": "9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM",
"data.0.decimals": 8,
"data.0.owner_id": trashid.MustEncodeHashID(1),
"data.0.members": 2,
"data.0.members_24h_change_percent": 100.0,
"data.1": nil,
Expand All @@ -154,8 +157,9 @@ func TestGetCoins(t *testing.T) {

jsonAssert(t, body, map[string]any{
"data.0.ticker": "$USDC",
"data.0.owner_id": trashid.MustEncodeHashID(2),
"data.0.decimals": 6,
"data.0.mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"data.0.owner_id": trashid.MustEncodeHashID(2),
"data.0.members": 0,
"data.0.members_24h_change_percent": -100.0,
"data.1": nil,
Expand All @@ -169,8 +173,9 @@ func TestGetCoins(t *testing.T) {

jsonAssert(t, body, map[string]any{
"data.0.ticker": "$USDC",
"data.0.owner_id": trashid.MustEncodeHashID(2),
"data.0.mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"data.0.decimals": 6,
"data.0.owner_id": trashid.MustEncodeHashID(2),
"data.0.members": 0,
"data.0.members_24h_change_percent": -100.0,
"data.1": nil,
Expand Down
1 change: 1 addition & 0 deletions api/v1_users_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (app *ApiServer) v1UsersCoin(c *fiber.Ctx) error {
SELECT
artist_coins.ticker,
balances_by_mint.mint,
artist_coins.decimals,
balances_by_mint.balance AS balance,
(balances_by_mint.balance * @price) / POWER(10, artist_coins.decimals) AS balance_usd,
JSON_AGG(
Expand Down
2 changes: 2 additions & 0 deletions api/v1_users_coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func TestUserCoin(t *testing.T) {
jsonAssert(t, body, map[string]any{
"data.ticker": "$AUDIO",
"data.mint": "9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM",
"data.decimals": 8,
"data.balance": 1800000000, // 18 AUDIO
"data.balance_usd": 180.0, // Assuming $10 per AUDIO
"data.accounts.#": 3,
Expand Down Expand Up @@ -151,6 +152,7 @@ func TestUserCoin(t *testing.T) {
jsonAssert(t, body, map[string]any{
"data.ticker": "$USDC",
"data.mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"data.decimals": 6,
"data.balance": 7000000, // 7 USDC
"data.balance_usd": 7.0,
"data.accounts.#": 1,
Expand Down
3 changes: 3 additions & 0 deletions api/v1_users_coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type GetUsersCoinsQueryParams struct {
type UserCoin struct {
Ticker string `json:"ticker"`
Mint string `json:"mint"`
Decimals int `json:"decimals"`
Balance float64 `json:"balance"`
BalanceUSD float64 `json:"balance_usd"`
}
Expand Down Expand Up @@ -96,6 +97,7 @@ func (app *ApiServer) v1UsersCoins(c *fiber.Ctx) error {
SELECT
artist_coins.ticker,
balances_by_mint.mint,
artist_coins.decimals,
balances_by_mint.balance AS balance,
(balances_by_mint.balance * prices.price) / POWER(10, artist_coins.decimals) AS balance_usd
FROM balances_by_mint
Expand All @@ -105,6 +107,7 @@ func (app *ApiServer) v1UsersCoins(c *fiber.Ctx) error {
SELECT
balances_with_prices.ticker,
balances_with_prices.mint,
balances_with_prices.decimals,
balances_with_prices.balance,
balances_with_prices.balance_usd
FROM balances_with_prices
Expand Down
1 change: 1 addition & 0 deletions api/v1_users_coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestUserCoins(t *testing.T) {
"data.#": 2,
"data.0.ticker": "$AUDIO",
"data.0.mint": "9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM",
"data.0.decimals": 8,
"data.0.balance": 1800000000, // 18 AUDIO
"data.0.balance_usd": 180.0, // Assuming $10 per AUDIO
"data.1.ticker": "$USDC",
Expand Down
Loading