Skip to content

Commit c7dc430

Browse files
authored
Fix duplicate rows in /coins if multiple reward pool accounts (#577)
- I accidentally created a non-ATA account on the authority of PHUTURES - Later created the ATA - `/v1/coins` was giving duplicate rows for PHUTURES - Fix by only selecting earliest-created account for that owner - as a proxy for the ATA, assuming we'd create it as part of the reward pool creation process. - But technically the PHUTURES response is still showing the wrong account (since I created the non-ATA before the ATA). Not a huge issue bc we don't use that value anywhere. But maybe I can just delete that row for this case? Tested on prod
1 parent c0aba3e commit c7dc430

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

api/v1_coins.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,13 @@ const sharedSelectCoinSql = `
202202
ON artist_coin_pools.base_mint = artist_coins.mint
203203
LEFT JOIN sol_reward_manager_inits
204204
ON sol_reward_manager_inits.mint = artist_coins.mint
205-
LEFT JOIN sol_token_account_balances AS reward_pool
206-
ON reward_pool.owner = sol_reward_manager_inits.authority
207-
AND reward_pool.account != sol_reward_manager_inits.token_source
205+
LEFT JOIN LATERAL (
206+
SELECT * FROM sol_token_account_balances
207+
WHERE owner = sol_reward_manager_inits.authority
208+
AND account != sol_reward_manager_inits.token_source
209+
ORDER BY created_at ASC
210+
LIMIT 1
211+
) AS reward_pool ON true
208212
`
209213

210214
type GetArtistCoinsQueryParams struct {

0 commit comments

Comments
 (0)