Add sagas for OnRamp to AUDIO#1666
Conversation
…ruction generation to AudiusBackend, used typed version of AudiusBackend
Rewrites the buy-audio sagas to make them more coherent with the actual task at hand. With the previous design, it was difficult to add the proper calculations to ensure a successful transaction due to the disconnection between the USDC quote and the SOL quote. Now, w
piazzatron
left a comment
There was a problem hiding this comment.
Epic PR! Really just a few minor things - let's get this merged and test the heck out of it 🚀
| state.feesCache = initialState.feesCache | ||
| }, | ||
| restart: (state) => { | ||
| state.stage = BuyAudioStage.START |
There was a problem hiding this comment.
Do we need to restart the purchaseInfoStatus with these stage transitions? If so, would modeling these as a discrimated union help?
| DeletePlaylistConfirmation: false, | ||
| FeatureFlagOverride: false | ||
| FeatureFlagOverride: false, | ||
| BuyAudio: true |
There was a problem hiding this comment.
Any reason this is true by default?
There was a problem hiding this comment.
testing purposes 😅 (shouldn't even be in here oops)
| * Gets a quote from Jupiter for an exchange from inputTokenSymbol => outputTokenSymbol | ||
| * @returns the best quote including the RouteInfo | ||
| */ | ||
| function* getQuote({ |
There was a problem hiding this comment.
Maybe getQuote should take jup in as an argument to make this easier to test? Another approach would be to have a class encapsulating Jupiter and exposing this as a method on the class, but don't feel super strongly.
| ) | ||
|
|
||
| const estimatedLamports = | ||
| inSol + associatedAccountCreationFees + transactionFees - existingBalance |
There was a problem hiding this comment.
Safe to do this not using BN/JSBI?
| export const getRootSolanaAccount = async () => { | ||
| await waitForLibsInit() | ||
| return libs().solanaWeb3Manager.solanaWeb3.Keypair.fromSeed( | ||
| libs().Account.hedgehog.wallet.getPrivateKey() | ||
| ) as Keypair | ||
| } | ||
|
|
||
| export const getSolanaConnection = async () => { | ||
| await waitForLibsInit() | ||
| return libs().solanaWeb3Manager.connection as Connection | ||
| } |
There was a problem hiding this comment.
A few of these feel like general Solana utils rather than something that belongs specifically in BuyAudio.ts to me
There was a problem hiding this comment.
yeah where should those live?
There was a problem hiding this comment.
Maybe /services/audius-backend/Solana.ts?
| return tokenAccountInfo | ||
| } | ||
|
|
||
| export const pollForAudioBalanceChange = async ({ |
There was a problem hiding this comment.
Maybe include a comment that this throws (do we want it to throw?)
|
| GitGuardian id | Secret | Commit | Filename | |
|---|---|---|---|---|
| 688750 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.dev.tmpl | View secret |
| 2416684 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.dev.tmpl | View secret |
| 2416685 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.dev.tmpl | View secret |
| 2416686 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.dev.tmpl | View secret |
| 2858199 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.dev.tmpl | View secret |
| 688750 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.prod.tmpl | View secret |
| 2460749 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.prod.tmpl | View secret |
| 2460750 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.prod.tmpl | View secret |
| 2460751 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.prod.tmpl | View secret |
| 1606949 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.prod.tmpl | View secret |
| 2111319 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.prod.tmpl | View secret |
| 2858198 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.prod.tmpl | View secret |
| 688750 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.stage.tmpl | View secret |
| 2416684 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.stage.tmpl | View secret |
| 2416685 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.stage.tmpl | View secret |
| 2416686 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.stage.tmpl | View secret |
| 2858199 | Generic High Entropy Secret | ad9d272 | packages/mobile/.env.stage.tmpl | 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.
Our GitHub checks need improvements? Share your feedbacks!
|
Preview this change https://demo.audius.co/mjp-cb-onramp-sagas-v2 |
[0d2f211] [C-826] Move remote-config-instance to saga context (#1713) Dylan Jeffers [bcd68c7] Add sagas for OnRamp to AUDIO (#1666) Marcus Pasell [1ca2af2] Prevent showing file explorer on pressing enter (#1704) Saliou Diallo [0b6f0e4] [PAY-521] Add web dethroned notification (#1712) Michael Piazza [76b1b0e] [C-820] Move apiClient into saga context, Add WalletClient to context (#1711) Dylan Jeffers [2706cef] [C-807] Move audiusBackendInstance into context across all sagas (#1710) Dylan Jeffers [25c9433] [PAY-466] Display AAO emoji errors for failed reward claims (#1693) Reed [c2a79ff] [C-808] Don't show unnecessarily show profile option on overflow menu (#1708) Dylan Jeffers [94e188f] [C-801] Add tag search text to mobile (#1706) Dylan Jeffers [a47c2e2] [C-806] Prevent multiple overflow menus at a time (#1698) Saliou Diallo [dce8a58] [C-797] Fix track-remix-screen text color (#1705) Dylan Jeffers [1325829] Add extends null (#1707) Sebastian Klingler [51e38d6] [C-805] Fix artifact on small card (#1696) Raymond Jacobson [0a521b1] [C-798] Remove owned/created stamp from collectible tile (#1689) Sebastian Klingler [18ae0a0] [C-804] Show playlist count for non-artists in native (#1697) Dylan Jeffers [ffcf0da] Fix associated wallets (#1692) Raymond Jacobson [e287fb1] [PAY-267, C-753] Remove tipping feature flags, Fix mutuals icon (#1695) Dylan Jeffers [118102d] [C-794] Add typecheck to web ci (#1694) Sebastian Klingler [4f60a49] [C-803] Add common state and backend sagas to native (#1691) Dylan Jeffers [96d9cc8] [C-800] Add native saga context and update common sagas (#1690) Dylan Jeffers [12add4a] [C-799] Add saga context, refactor backend state (#1688) Dylan Jeffers [afdbe97] [C-796] Refactor AudiusAPIClient to work in native context (#1687) Dylan Jeffers [a185c09] [C-795] Fix user-list tag imports (#1686) Dylan Jeffers [3a8704c] [C-774] Move audius-backend to common, add native libs-instance (#1685) Dylan Jeffers
Description
Supercedes:
Main updates:
quoteactions for USDC and SOL, there is one action that providespurchaseInfo, strictly information regarding the purchase of SOL for a SOL => AUDIO transaction with an estimate for how much that costs in USD (using a quote from that amount of SOL to USD.computeRouteson Jupiter to get the swap transactions, then compile them and get associated fees via Solana's API (this is generally a constant per transaction of 0.000005 SOL, although the Jupiter transactions can vary from 1-3 depending on how large the swap transaction gets)BuyAudio.tsaudius-backend fileBuyAudioStageenum that indicates where in the flow we are (eg. are we waiting on the user to purchase SOL? For coinbase pay's funds to show up in the wallet? For the swap to complete?)Dragons
Is there anything the reviewer should be on the lookout for? Are there any dangerous changes?
JSBIwhich is used by Jupiter, there'sBNwhich is what we use, there'su64which is what some Solana stuff uses now (a wrapper around BN that annoyingly is lowercased so doingnew u64(..)triggers our linter), and there'snumberwhich is also used by Solana. I've mixed returning SOL and lamports in this PR to some degree... could use another pass on cleaning that up probably. Ideally I'd do everything in some sort of big int type to avoid any potential float precision stuff.How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide repro instructions & any configuration.
Tested E2E using a prototype BuyAudio modal as well as just by triggering sagas manually and using a phantom wallet. I also closed all my ATAs and ran it again to see the ATA fee estimate get higher and lower depending on if it was my first or second time onramping. So far have not seen any "Insufficient funds" errors.
How will this change be monitored?
For features that are critical or could fail silently please describe the monitoring/alerting being added.
Feature Flags
Are all new features properly feature flagged? Describe added feature flags.