Skip to content
Draft
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
10 changes: 9 additions & 1 deletion packages/money-account-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,30 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@metamask/accounts-controller": "^37.2.0",
"@metamask/base-controller": "^9.0.1",
"@metamask/base-data-service": "^0.1.1",
"@metamask/controller-utils": "^11.20.0",
"@metamask/eth-money-keyring": "^2.0.0",
"@metamask/keyring-api": "^21.6.0",
"@metamask/keyring-controller": "^25.2.0",
"@metamask/messenger": "^1.1.1",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/network-controller": "^30.0.1",
"@metamask/superstruct": "^3.1.0",
"@metamask/utils": "^11.9.0",
"async-mutex": "^0.5.0"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/keyring-utils": "^3.1.0",
"@metamask/utils": "^11.9.0",
"@ts-bridge/cli": "^0.6.4",
"@types/jest": "^29.5.14",
"deepmerge": "^4.2.2",
"jest": "^29.7.0",
"nock": "^13.3.1",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
Expand Down
22 changes: 22 additions & 0 deletions packages/money-account-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,25 @@ export type {
MoneyAccountControllerCreateMoneyAccountAction,
MoneyAccountControllerGetMoneyAccountAction,
} from './MoneyAccountController-method-action-types';
export {
MoneyAccountBalanceService,
serviceName as moneyAccountBalanceServiceName,
} from './money-account-balance-service/money-account-balance-service';
export type {
MoneyAccountBalanceServiceActions,
MoneyAccountBalanceServiceEvents,
MoneyAccountBalanceServiceMessenger,
} from './money-account-balance-service/money-account-balance-service';
export type {
MoneyAccountBalanceServiceGetMusdBalanceAction,
MoneyAccountBalanceServiceGetMusdSHFvdBalanceAction,
MoneyAccountBalanceServiceGetExchangeRateAction,
MoneyAccountBalanceServiceGetMusdEquivalentValueAction,
MoneyAccountBalanceServiceGetVaultApyAction,
} from './money-account-balance-service/money-account-balance-service-method-action-types';
export type {
Erc20BalanceResponse,
ExchangeRateResponse,
MusdEquivalentValueResponse,
VaultApyResponse,
} from './money-account-balance-service/response.types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Hex } from '@metamask/utils';

export const VEDA_PERFORMANCE_API_BASE_URL = 'https://api.sevenseas.capital';

export const VEDA_API_NETWORK_NAMES: Record<Hex, string> = {
'0xa4b1': 'arbitrum',
};

export const DEFAULT_VEDA_API_NETWORK_NAME = VEDA_API_NETWORK_NAMES['0xa4b1'];

/**
* Minimal ABI for the Veda Accountant's `getRate()` function (selector 0x679aefce).
* Returns the exchange rate between vault shares (musdSHFvd) and the
* underlying asset (mUSD) as a uint256.
*/
export const ACCOUNTANT_ABI = [
{
inputs: [],
name: 'getRate',
outputs: [{ internalType: 'uint256', name: 'rate', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
] as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class VedaResponseValidationError extends Error {
constructor(message?: string) {
super(message ?? 'Malformed response received from Veda API');
this.name = 'VedaResponseValidationError';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// TODO: This file is supposed to be auto generated. Verify that this generates correctly. The first iteration (seen here) was generated by agent.
/**
* This file is auto generated.
* Do not edit manually.
*/

import type { MoneyAccountBalanceService } from './money-account-balance-service';

/**
* Fetches the mUSD ERC-20 balance for the given account address via RPC.
*
* @param accountAddress - The Money account's address.
* @returns The mUSD balance as a raw uint256 string.
*/
export type MoneyAccountBalanceServiceGetMusdBalanceAction = {
type: `MoneyAccountBalanceService:getMusdBalance`;
handler: MoneyAccountBalanceService['getMusdBalance'];
};

/**
* Fetches the musdSHFvd (Veda vault share) ERC-20 balance for the given
* account address via RPC.
*
* @param accountAddress - The Money account's address.
* @returns The musdSHFvd balance as a raw uint256 string.
*/
export type MoneyAccountBalanceServiceGetMusdSHFvdBalanceAction = {
type: `MoneyAccountBalanceService:getMusdSHFvdBalance`;
handler: MoneyAccountBalanceService['getMusdSHFvdBalance'];
};

/**
* Fetches the current exchange rate from the Veda Accountant contract via RPC.
*
* @returns The exchange rate as a raw uint256 string.
*/
export type MoneyAccountBalanceServiceGetExchangeRateAction = {
type: `MoneyAccountBalanceService:getExchangeRate`;
handler: MoneyAccountBalanceService['getExchangeRate'];
};

/**
* Computes the mUSD-equivalent value of the account's musdSHFvd holdings.
* Internally fetches the musdSHFvd balance and exchange rate (using cached
* values when available), then multiplies them.
*
* @param accountAddress - The Money account's address.
* @returns The musdSHFvd balance, exchange rate, and computed mUSD-equivalent value.
*/
export type MoneyAccountBalanceServiceGetMusdEquivalentValueAction = {
type: `MoneyAccountBalanceService:getMusdEquivalentValue`;
handler: MoneyAccountBalanceService['getMusdEquivalentValue'];
};

/**
* Fetches the vault's APY and fee breakdown from the Veda performance REST API.
*
* @returns The 7-day trailing net APY, fees, and per-position breakdown.
*/
export type MoneyAccountBalanceServiceGetVaultApyAction = {
type: `MoneyAccountBalanceService:getVaultApy`;
handler: MoneyAccountBalanceService['getVaultApy'];
};

/**
* Union of all MoneyAccountBalanceService action types.
*/
export type MoneyAccountBalanceServiceMethodActions =
| MoneyAccountBalanceServiceGetMusdBalanceAction
| MoneyAccountBalanceServiceGetMusdSHFvdBalanceAction
| MoneyAccountBalanceServiceGetExchangeRateAction
| MoneyAccountBalanceServiceGetMusdEquivalentValueAction
| MoneyAccountBalanceServiceGetVaultApyAction;
Loading
Loading