feat: Add comprehensive BONK token support with multi-token swap func…#12502
Conversation
…tionality This combined PR includes all frontend, API, and core logic updates needed for BONK token support and dynamic token swapping. Originally planned as separate PRs 4, 5, and 6, but combined due to tight coupling between components. ## Core Logic Updates (PR 4 scope): - Update buy/sell constants and types for dynamic token pairs - Enhance useBuySellSwap hook with selectedPair support - Add token amount formatting for multiple tokens - Update AudiusBackend and Solana services for BONK support - Add decimal utility functions for token calculations ## API & Jupiter Integration (PR 5 scope): - Add Jupiter API constants, types, and utilities - Implement useTokenBalance hook for multi-token support - Update API index with new token balance exports ## Frontend UI Updates (PR 6 scope): - Update mobile BuySellFlow and ConfirmSwapScreen for dynamic tokens - Update web buy-sell modal components (BuyTab, SellTab, SwapTab) - Add TokenAmountSection component updates - Update buy-sell modal constants for new token support ## SDK & Dependencies: - Add BONK support to SDK configurations (dev/prod/stage) - Update ClaimableTokensClient for BONK token handling - Add mintFixedDecimalMap utilities - Update fixed-decimal package to export BONK currency ## Key Features: - Dynamic token pair creation using environment configuration - Support for AUDIO/USDC, AUDIO/BONK, and USDC/BONK pairs - Comprehensive error handling and validation - Mobile and web UI consistency - Type-safe token operations throughout Depends on: PR 1 (token registry infrastructure) being merged first. Related to: PR 2 (backend/SDK support) - some files overlap for completeness.
|
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 9412812 | Triggered | Generic Password | 71fdbc2 | packages/discovery-provider/ddl/local-test-replicas.sh | View secret |
| 18250942 | Triggered | Generic High Entropy Secret | 9c4a513 | packages/sdk/src/sdk/config/development.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
There was a problem hiding this comment.
Bug: Redundant Conversion in Token Balance Handling
The tokenBalanceData returned by useTokenBalance is already a FixedDecimal object. In both BuyTab.tsx and SellTab.tsx, the code Number(new FixedDecimal(tokenBalanceData.toString())) performs a redundant conversion of this FixedDecimal to a string and then back to a new FixedDecimal. This unnecessary double conversion is inefficient and can lead to precision loss. The conversion should be simplified to Number(tokenBalanceData.toString()) or tokenBalanceData.toNumber().
packages/web/src/components/buy-sell-modal/BuyTab.tsx#L60-L61
packages/web/src/components/buy-sell-modal/SellTab.tsx#L65-L66
Bug: Token Dropdown Filters Incorrectly Inverted
The token filtering logic for availableInputTokens and availableOutputTokens in the Buy and Sell tabs is incorrect. For the input token dropdown, the current implementation filters out the output token instead of the input token. Similarly, for the output token dropdown, it filters out the input token instead of the output token. This inversion applies to both Buy and Sell tabs.
packages/web/src/components/buy-sell-modal/BuySellFlow.tsx#L354-L378
Was this report helpful? Give feedback by reacting with 👍 or 👎
| import { UserBankManagedTokenInfo } from './types' | ||
|
|
||
| const CLAIMABLE_TOKEN_MINTS = ['wAUDIO', 'USDC', 'BONK'] as const | ||
| type ClaimableTokenMint = (typeof CLAIMABLE_TOKEN_MINTS)[number] |
| // Convert registry tokens to UserBankManagedTokenInfo format | ||
| userbankTokens.forEach((token: TokenConfig) => { | ||
| if (isClaimableTokenMint(token.symbol)) { | ||
| managedTokens[token.address.toUpperCase()] = { |
There was a problem hiding this comment.
i think solana addresses are case sensitive?
| // TanStack Query's built-in polling - only poll when isPolling is true | ||
| refetchInterval: isPolling ? pollingInterval : false, | ||
| // Prevent refetching when window regains focus during polling to avoid conflicts | ||
| refetchOnWindowFocus: !isPolling, |
| ...queryOptions | ||
| }) | ||
|
|
||
| // Map TanStack Query states to the Status enum for API compatibility |
There was a problem hiding this comment.
damn is this another migration we need to do
| import { QUERY_KEYS } from '../queryKeys' | ||
| import { QueryOptions, type QueryKey } from '../types' | ||
|
|
||
| const createTokenBalance = ( |
There was a problem hiding this comment.
nit: is this rly the cleanest way? can we not do something like:
return !!amount ? new FixedDecimal(BigInt(amount.toString()), decimals) : null
There was a problem hiding this comment.
idk i guess that's kind of annoying too..
| @@ -89,7 +88,7 @@ const StackedBalanceSection = ({ | |||
| </Text> | |||
| </Flex> | |||
| {/* We need the border radius to be circle here because the AUDIO icon is a square image */} | |||
There was a problem hiding this comment.
nit: comment still says circle
dharit-tan
left a comment
There was a problem hiding this comment.
seems good but check out the solana case-sensitive bit
[280d9db] Add track tile carousel skeleton and fix width (#12565) Isaac Solo [5dd5f50] Search/explore mobile web pass (#12562) Isaac Solo [b49cb22] [PE-6505] Update in-app notif navigation for comments to highlight comment (#12554) KJ [cad4bfc] [PE-6509] Add web coin leaderboard modal (#12556) Dylan Jeffers [308a773] Fix setting USDC payout wallet (#12563) Marcus Pasell [3c174c1] [PE-6539] Fix artist coin badge showing when 0 balance (#12560) Reed [0d0c089] [PE-6530] Conditionally show chat message artist coin header (#12559) Reed [179b457] Update eth rpc urls (#12552) KJ [bd3f3cf] Fix mobile image fallback logic (#12549) Ray Jacobson [1a752dd] Speed up mobile app warm start by another ~75% (#12555) JD Francis [a96174d] [QA-2220] Fix mobile user-links with badge-v2 (#12557) Dylan Jeffers [e9c0c3d] Add msw for coin endpoints (#12551) Dylan Jeffers [3dcf5d3] Fix styling for chat message unfurls (#12550) KJ [b343ac0] Add asset detail pages (#12430) Farid Salau [5d6c245] Add non-native conversion to buy/sell modal (#12536) Farid Salau [4c09e50] [PE-6537] Add comment_id to notification action data (#12548) Dylan Jeffers [013f7f5] [PE-6524] Add scroll to comment section on comment link (#12545) KJ [69f3ca0] [PE-6519] Send artist coin holder blast UI (#12538) Reed [cfd654e] Fix misc mobile tile layout issues (#12542) JD Francis [bee3f90] [PE-6516] YourCoins supports BONK on web (#12528) Reed [2e51d03] [QA-2218] Fix artist popover badge (#12543) Ray Jacobson [cabbd73] [PE-2215] Adjust share button size (#12533) Dylan Jeffers [99238c5] Add feature flag to search explore milestone and optimize search fetches (#12541) Isaac Solo [6f3a511] [PE-6502, PE-6504] Add comment highlighting for mobile (#12540) KJ [ba3fcd0] [QA-2212] Improve bottom bar haptics (#12535) Dylan Jeffers [3f1758e] [QA-2223] Fix ActionDrawer text color in dark mode (#12537) KJ [a018dd1] Mobile web search explore fixes (#12534) Isaac Solo [b3474b2] Improve mobile app refocus rerenders (#12532) JD Francis [72c05be] Mobile web top right menu (#12521) Reed [6c45c92] [PE-6515] Border for hex token icons (#12526) Reed [2a762b4] Clicking on token badges shows hover card too (#12527) Reed [d07fbb0] [PE-6420] Improve useCurrentAccount local-storage perf (#12524) Dylan Jeffers [fd8574f] Add examples to @packages/fixed-decimal (#12531) Ray Jacobson [e34f4bf] Aggregate AUDIO amount for X shares (#12530) Dylan Jeffers [81b1709] Fix incorrect comment display (#12529) KJ [d74a7bf] Fix TOKEN_ACCOUNT_NOT_FOUND events (#12523) Dylan Jeffers [0467b88] [PE-6500] Add timezone to remix contest details (#12515) Dylan Jeffers [df4e489] Add feeling lucky, recently played, active discussions explore sections (#12498) Isaac Solo [923f09a] useTokenBalance with fake amounts (#12525) Reed [28adbeb] feat: Add comprehensive BONK token support with multi-token swap func… (#12502) Farid Salau
Overview
This pull request introduces a new generic
useTokenBalancehook that can fetch balances for any supported token, replacing token-specific implementations with a more scalable approach. It also refactors existing token management code to use the token registry system for better maintainability.Key Changes
New Generic Token Balance Hook
useTokenBalancehook (packages/common/src/api/tan-query/wallets/useTokenBalance.ts)FixedDecimalconstructor with dynamic decimal places from token registryToken Registry Integration
packages/common/src/services/audius-backend/AudiusBackend.ts)getMintAddressfunctionJupiter Integration Improvements
packages/common/src/api/tan-query/jupiter/constants.ts)createUserBankManagedTokensto use token registry instead of hardcoded mappingsBuy/Sell Flow Enhancements
Improved buy/sell swap logic (
packages/common/src/store/ui/buy-sell/useBuySellSwap.ts)Dynamic token constants (
packages/common/src/store/ui/buy-sell/constants.ts)Type System Updates
Extended MintName type (
packages/common/src/services/audius-backend/solana.ts)MintNametypeClaimableTokenMinttype in Jupiter typesEnhanced token types (
packages/common/src/store/ui/buy-sell/types.ts)TokenTypeunionQuery Infrastructure
Added tokenBalance to query keys (
packages/common/src/api/tan-query/queryKeys.ts)Exported new hook (
packages/common/src/api/index.ts)useTokenBalanceavailable for consumptionTechnical Improvements
Better Null Handling
createTokenBalanceto avoid complex ternary logicScalable Architecture
Performance Optimizations
How Has This Been Tested?
npm run web:prodand go to buy/sell flow