diff --git a/.changeset/remove-get-wallet-balances.md b/.changeset/remove-get-wallet-balances.md new file mode 100644 index 00000000..07513502 --- /dev/null +++ b/.changeset/remove-get-wallet-balances.md @@ -0,0 +1,5 @@ +--- +"@lifi/sdk": minor +--- + +Remove the `getWalletBalances` action and client method — the underlying `/wallets/{address}/balances` API endpoint is deprecated. Use `getTokenBalances`/`getTokenBalancesByChain` to fetch balances directly from RPCs instead. diff --git a/packages/sdk/src/actions/getWalletBalances.ts b/packages/sdk/src/actions/getWalletBalances.ts deleted file mode 100644 index 776788b0..00000000 --- a/packages/sdk/src/actions/getWalletBalances.ts +++ /dev/null @@ -1,36 +0,0 @@ -import type { - GetWalletBalanceExtendedResponse, - RequestOptions, - WalletTokenExtended, -} from '@lifi/types' -import { ValidationError } from '../errors/errors.js' -import type { SDKClient } from '../types/core.js' -import { request } from '../utils/request.js' - -/** - * Returns the balances of tokens a wallet holds across EVM chains. - * @param client - The SDK client. - * @param walletAddress - A wallet address. - * @param options - Optional request options. - * @returns An object containing the tokens and the amounts organized by chain ids. - * @throws {ValidationError} Throws a ValidationError if parameters are invalid. - */ -export const getWalletBalances = async ( - client: SDKClient, - walletAddress: string, - options?: RequestOptions -): Promise> => { - if (!walletAddress) { - throw new ValidationError('Missing walletAddress.') - } - - const response = await request( - client.config, - `${client.config.apiUrl}/wallets/${walletAddress}/balances?extended=true`, - { - signal: options?.signal, - } - ) - - return (response?.balances || {}) as Record -} diff --git a/packages/sdk/src/actions/getWalletBalances.unit.spec.ts b/packages/sdk/src/actions/getWalletBalances.unit.spec.ts deleted file mode 100644 index 05a9c635..00000000 --- a/packages/sdk/src/actions/getWalletBalances.unit.spec.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { findDefaultToken } from '@lifi/data-types' -import type { WalletTokenExtended } from '@lifi/types' -import { ChainId, CoinKey } from '@lifi/types' -import { beforeEach, describe, expect, it, vi } from 'vitest' -import { client } from './actions.unit.handlers.js' -import { getWalletBalances } from './getWalletBalances.js' - -const mockedGetWalletBalances = vi.spyOn( - await import('./getWalletBalances.js'), - 'getWalletBalances' -) - -describe('getWalletBalances', () => { - beforeEach(() => { - vi.clearAllMocks() - }) - - const SOME_TOKEN = { - ...findDefaultToken(CoinKey.USDC, ChainId.DAI), - priceUSD: '', - } - const SOME_WALLET_ADDRESS = 'some wallet address' - - describe('user input is invalid', () => { - it('should throw Error because of missing walletAddress', async () => { - await expect(getWalletBalances(client, '')).rejects.toThrow( - 'Missing walletAddress.' - ) - }) - }) - - describe('user input is valid', () => { - it('should call the balance service without options', async () => { - const balanceResponse: Record = { - [ChainId.DAI]: [ - { - ...SOME_TOKEN, - amount: '123', - marketCapUSD: 1000000, - volumeUSD24H: 50000, - fdvUSD: 2000000, - }, - ], - } - - mockedGetWalletBalances.mockReturnValue(Promise.resolve(balanceResponse)) - - const result = await getWalletBalances(client, SOME_WALLET_ADDRESS) - - expect(mockedGetWalletBalances).toHaveBeenCalledTimes(1) - expect(mockedGetWalletBalances).toHaveBeenCalledWith( - client, - SOME_WALLET_ADDRESS - ) - expect(result).toEqual(balanceResponse) - }) - - it('should call the balance service with options', async () => { - const balanceResponse: Record = { - [ChainId.DAI]: [ - { - ...SOME_TOKEN, - amount: '123', - marketCapUSD: 1000000, - volumeUSD24H: 50000, - fdvUSD: 2000000, - }, - ], - } - - const options = { signal: new AbortController().signal } - - mockedGetWalletBalances.mockReturnValue(Promise.resolve(balanceResponse)) - - const result = await getWalletBalances( - client, - SOME_WALLET_ADDRESS, - options - ) - - expect(mockedGetWalletBalances).toHaveBeenCalledTimes(1) - expect(mockedGetWalletBalances).toHaveBeenCalledWith( - client, - SOME_WALLET_ADDRESS, - options - ) - expect(result).toEqual(balanceResponse) - }) - }) -}) diff --git a/packages/sdk/src/actions/index.ts b/packages/sdk/src/actions/index.ts index adf95240..5e84ea34 100644 --- a/packages/sdk/src/actions/index.ts +++ b/packages/sdk/src/actions/index.ts @@ -28,7 +28,6 @@ import type { ToolsResponse, TransactionAnalyticsRequest, TransactionAnalyticsResponse, - WalletTokenExtended, } from '@lifi/types' import type { GetStatusRequestExtended, @@ -55,7 +54,6 @@ import { getTokenBalancesByChain } from './getTokenBalancesByChain.js' import { getTokens } from './getTokens.js' import { getTools } from './getTools.js' import { getTransactionHistory } from './getTransactionHistory.js' -import { getWalletBalances } from './getWalletBalances.js' import { type PatchContractCallsResponse, patchContractCalls, @@ -274,17 +272,6 @@ export type Actions = { options?: RequestOptions ) => Promise - /** - * Get wallet balances - * @param params - The configuration of the requested wallet balances - * @param options - Request options - * @returns Wallet balances - */ - getWalletBalances: ( - walletAddress: string, - options?: RequestOptions - ) => Promise> - /** * Relay a transaction through the relayer service * @param params - The configuration for the relay request @@ -340,8 +327,6 @@ export function actions(client: SDKClient): Actions { getTokenBalancesByChain(client, walletAddress, tokensByChain), getTransactionHistory: (params, options) => getTransactionHistory(client, params, options), - getWalletBalances: (walletAddress, options) => - getWalletBalances(client, walletAddress, options), relayTransaction: (params, options) => relayTransaction(client, params, options), patchContractCalls: (params, options) => diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index b26df206..42dd467b 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -19,7 +19,6 @@ export { getTokenBalancesByChain } from './actions/getTokenBalancesByChain.js' export { getTokens } from './actions/getTokens.js' export { getTools } from './actions/getTools.js' export { getTransactionHistory } from './actions/getTransactionHistory.js' -export { getWalletBalances } from './actions/getWalletBalances.js' export { actions } from './actions/index.js' export { patchContractCalls } from './actions/patchContractCalls.js' export { relayTransaction } from './actions/relayTransaction.js'