Skip to content

Commit c2be0e3

Browse files
MoMannnshane-t
andauthored
feat: add transaction logic for veda depost and withdrawal (#28658)
## **Description** Adds the on-chain transaction layer for Money Account crypto deposits and withdrawals (MUSD-593). **What changed:** - Added `buildMoneyAccountDepositBatch` and `buildMoneyAccountWithdraw` utility functions (`moneyAccountTransactions.ts`) that encode the approve + deposit / withdraw calldata against the Veda vault contracts (Teller, Accountant, Lens). - Added `useMoneyAccountDeposit` and `useMoneyAccountWithdrawal` hooks (`useMoneyAccount.ts`) that read vault configuration from remote feature flags, derive the provider from the active network client, and submit the transactions via `addTransactionBatch` / `addTransaction`. - Added `selectMoneyAccountVaultConfig` selector and the `moneyAccountDepositConfig` remote feature flag registry entry, which holds chain ID and contract addresses for the vault. - Temporarily wired the "Add" button in `MoneyHomeView` to `initiateDeposit` with a hardcoded amount as a dev integration test; this will be replaced once the amount entry UI is built. **Deposit flow:** `approve(boringVault, amount)` + `deposit(asset, amount, minimumMint, 0x0)` submitted as an atomic batch. A 0.1% slippage tolerance is applied to the `previewDeposit` quote. **Withdrawal flow:** `getRate` → convert asset amount to vault shares → `withdraw(asset, shares, minimumAssets, to)`. ## **Changelog** CHANGELOG entry: null ## **TODO** Note that the code has 2 todos that should be address seperatly: - adding hook to get amount from MM pay - updating addresses for mUSD and veda vault once we have a testing one ready on monad ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I've included tests if applicable - [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Introduces new transaction-construction and submission code paths that interact with wallet confirmations and remote-configured contract addresses; mistakes could cause failed or incorrect on-chain calls. Risk is reduced by added unit tests and feature-flag gating, but still impacts critical transaction flow. > > **Overview** > Adds the on-chain transaction building/submission layer for Money Account deposits and withdrawals. > > Introduces `buildMoneyAccountDepositBatch` (approve + deposit batch with preview+slippage) and `buildMoneyAccountWithdraw` (rate-based share conversion + slippage) utilities, plus `useMoneyAccountDeposit`/`useMoneyAccountWithdrawal` hooks that fetch vault addresses from remote feature flags, resolve provider/network client, navigate to confirmations, and submit via `addTransactionBatch`/`addTransaction` with error logging. > > Adds a new `moneyAccountVaultConfig` remote flag (with a dev fallback gated by `MM_MONEY_DEPOSIT_CONFIG_DEV_ENABLED`) and corresponding selector/tests; updates test babel config to avoid inlining env vars for those selector files. The Money home view only adds an import and TODO scaffolding for wiring deposits later (no behavior change). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 46369dc. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Shane T <muldots@gmail.com>
1 parent dd60e41 commit c2be0e3

9 files changed

Lines changed: 1190 additions & 0 deletions

File tree

app/components/UI/Money/Views/MoneyHomeView/MoneyHomeView.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useCallback } from 'react';
2+
import { useMoneyAccountDeposit } from '../../hooks/useMoneyAccount';
23
import { ScrollView, Linking } from 'react-native';
34
import { useSafeAreaInsets } from 'react-native-safe-area-context';
45
import { useNavigation } from '@react-navigation/native';
@@ -45,6 +46,8 @@ const getMoneyHomeState = (transactionCount: number): MoneyHomeState => {
4546
const displayUnderConstructionAlert = () => alert('Under construction 🚧');
4647

4748
const MoneyHomeView = () => {
49+
// TODO: wire to initiateDeposit(amount) once the amount entry UI is ready
50+
// const { initiateDeposit } = useMoneyAccountDeposit();
4851
const navigation = useNavigation();
4952
const insets = useSafeAreaInsets();
5053
const { styles } = useStyles(styleSheet, {});
@@ -62,6 +65,7 @@ const MoneyHomeView = () => {
6265
navigation.goBack();
6366
}, [navigation]);
6467

68+
// // eslint-disable-next-line no-alert
6569
const handleMenuPress = displayUnderConstructionAlert;
6670

6771
const handleAddPress = displayUnderConstructionAlert;

0 commit comments

Comments
 (0)