Skip to content
Open
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
14 changes: 14 additions & 0 deletions packages/money-account-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add Money Account transaction batch builders, ported from MetaMask Mobile ([#9680](https://github.com/MetaMask/core/pull/9680))
- `buildMoneyAccountDepositBatch` builds the approve + deposit call pair, deriving `minimumMint` from the vault lens' `previewDeposit` less a 0.2% slippage tolerance
- `buildMoneyAccountWithdrawBatch` builds the withdraw + transfer call pair, converting the asset amount to vault shares at the accountant's current rate
- Both take an `@ethersproject` `Provider` for their read calls and skip those reads for zero-amount batches
- `buildMoneyAccountDepositPlaceholderBatch` resolves the deposit call targets and types without calldata, for placeholder batches that MetaMask Pay re-encodes once the user picks an amount. It performs no vault reads, so it is synchronous and takes only `chainId` and `tellerAddress`
- `getMoneyAccountDepositAssetId` returns the CAIP-19 asset id of the deposit asset for a chain, or `undefined` if mUSD is not deployed there. Clients that want Money Account's Monad-only default apply it at the call site
- Supporting exports: `applySlippage`, `getSharesForWithdrawal`, `getMoneyAccountDepositAssetAddress`, `TELLER_ABI`, and the `MoneyAccountTxParams`, `MoneyAccountPlaceholderTxParams`, `MoneyAccountDepositBatchResult`, `MoneyAccountDepositPlaceholderBatchResult`, `MoneyAccountWithdrawBatchResult`, `BuildMoneyAccountDepositBatchOptions`, `BuildMoneyAccountDepositPlaceholderBatchOptions`, `BuildMoneyAccountWithdrawBatchOptions` types

### Changed

- Type the values of `MUSD_TOKEN_ASSET_ID_BY_CHAIN` as `CaipAssetType` rather than `string` ([#9680](https://github.com/MetaMask/core/pull/9680))

## [1.0.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/money-account-utils/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `@metamask/money-account-utils`

Shared money account utilities: activity parsing, classification, and mUSD constants.
Shared money account utilities: mUSD constants and vault transaction builders.

## Installation

Expand Down
5 changes: 4 additions & 1 deletion packages/money-account-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@metamask/money-account-utils",
"version": "1.0.0",
"description": "Shared money account utilities: activity parsing, classification, and mUSD constants",
"description": "Shared money account utilities: mUSD constants and vault transaction builders",
"keywords": [
"Ethereum",
"MetaMask"
Expand Down Expand Up @@ -55,6 +55,9 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@metamask/transaction-controller": "^69.3.0",
"@metamask/utils": "^11.11.0"
},
Expand Down
20 changes: 20 additions & 0 deletions packages/money-account-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,23 @@ export {
isMusdTokenOnChain,
isMusdOnMoneyAccountChain,
} from './musd.js';
export {
TELLER_ABI,
applySlippage,
buildMoneyAccountDepositBatch,
buildMoneyAccountDepositPlaceholderBatch,
buildMoneyAccountWithdrawBatch,
getMoneyAccountDepositAssetAddress,
getMoneyAccountDepositAssetId,
getSharesForWithdrawal,
} from './transactions.js';
export type {
BuildMoneyAccountDepositBatchOptions,
BuildMoneyAccountDepositPlaceholderBatchOptions,
BuildMoneyAccountWithdrawBatchOptions,
MoneyAccountDepositBatchResult,
MoneyAccountDepositPlaceholderBatchResult,
MoneyAccountPlaceholderTxParams,
MoneyAccountTxParams,
MoneyAccountWithdrawBatchResult,
} from './transactions.js';
4 changes: 2 additions & 2 deletions packages/money-account-utils/src/musd.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CHAIN_IDS } from '@metamask/transaction-controller';
import type { Hex } from '@metamask/utils';
import type { CaipAssetType, Hex } from '@metamask/utils';

/**
* The mUSD (MetaMask USD) token, minus any client-specific presentation
Expand Down Expand Up @@ -44,7 +44,7 @@ export const MUSD_TOKEN_ADDRESS_BY_CHAIN: Record<Hex, Hex> = {
/**
* The CAIP-19 asset id of the mUSD token on each chain where it is deployed.
*/
export const MUSD_TOKEN_ASSET_ID_BY_CHAIN: Record<Hex, string> = {
export const MUSD_TOKEN_ASSET_ID_BY_CHAIN: Record<Hex, CaipAssetType> = {
[CHAIN_IDS.MAINNET]:
'eip155:1/erc20:0xacA92E438df0B2401fF60dA7E4337B687a2435DA',
[CHAIN_IDS.LINEA_MAINNET]:
Expand Down
Loading