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
5 changes: 5 additions & 0 deletions .changeset/better-buses-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@venusprotocol/evm": minor
---

Added account transactions tab
1 change: 1 addition & 0 deletions apps/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"stylelint": "^15.10.3",
"tailwindcss": "^3.3.3",
"tailwindcss-animate": "^1.0.7",
"tailwind-scrollbar": "3.1.0",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.1.2",
"typescript": "^5.1.6",
Expand Down
109 changes: 109 additions & 0 deletions apps/evm/src/__mocks__/models/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import BigNumber from 'bignumber.js';
import { usdt } from './tokens';
import { vUsdt } from './vTokens';

export const transactions = {
transactions: [
{
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
amountCents: new BigNumber('2406931.018168454893468167206'),
amountTokens: new BigNumber('24066181578079398.612862'),
blockNumber: '41604850',
blockTimestamp: new Date('2024-08-23T04:17:09.000Z'),
chainId: 97,
contractAddress: '0xb7526572FFE56AB9D7489838Bf2E18e3323b441A',
hash: '0xda13a0f45b10dabd21b863b6b602c6d8776edd4c6b10fe65a0881d491f468f35',
poolName: 'Metaverse',
vTokenSymbol: vUsdt.symbol,
token: usdt,
txType: 'redeem',
},
{
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
amountCents: new BigNumber('2401121.576132434220587935367386'),
amountTokens: new BigNumber('24001813290985731.455439'),
blockNumber: '41114054',
blockTimestamp: new Date('2024-08-06T02:18:03.000Z'),
chainId: 97,
contractAddress: '0xb7526572FFE56AB9D7489838Bf2E18e3323b441A',
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
poolName: 'Metaverse',
vTokenSymbol: vUsdt.symbol,
token: usdt,
txType: 'mint',
},
{
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
amountCents: new BigNumber('2401121.576132434220587935367386'),
amountTokens: new BigNumber('24001813290985731.455439'),
blockNumber: '41114053',
blockTimestamp: new Date('2024-08-05T02:18:03.000Z'),
chainId: 97,
contractAddress: '0xb7526572FFE56AB9D7489838Bf2E18e3323b441A',
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
poolName: 'Metaverse',
vTokenSymbol: vUsdt.symbol,
token: usdt,
txType: 'borrow',
},
{
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
amountCents: new BigNumber('2401121.576132434220587935367386'),
amountTokens: new BigNumber('24001813290985731.455439'),
blockNumber: '41114052',
blockTimestamp: new Date('2024-08-04T02:18:03.000Z'),
chainId: 97,
contractAddress: '0xb7526572FFE56AB9D7489838Bf2E18e3323b441A',
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
poolName: 'Metaverse',
vTokenSymbol: vUsdt.symbol,
token: usdt,
txType: 'repay',
},
{
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
amountCents: new BigNumber('2401121.576132434220587935367386'),
amountTokens: new BigNumber('24001813290985731.455439'),
blockNumber: '41114051',
blockTimestamp: new Date('2024-08-03T02:18:03.000Z'),
chainId: 97,
contractAddress: '0xb7526572FFE56AB9D7489838Bf2E18e3323b441A',
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
poolName: 'Metaverse',
vTokenSymbol: vUsdt.symbol,
token: usdt,
txType: 'enter_market',
},
{
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
amountCents: new BigNumber('2401121.576132434220587935367386'),
amountTokens: new BigNumber('24001813290985731.455439'),
blockNumber: '41114050',
blockTimestamp: new Date('2024-08-03T02:18:00.000Z'),
chainId: 97,
contractAddress: '0xb7526572FFE56AB9D7489838Bf2E18e3323b441A',
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
poolName: 'Metaverse',
vTokenSymbol: vUsdt.symbol,
token: usdt,
txType: 'exit_market',
},
{
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
amountCents: new BigNumber('0'),
amountTokens: new BigNumber(
'115792089237316195423570985008687907853269984665640564039457584007913129639935',
),
blockNumber: '41114008',
blockTimestamp: new Date('2024-08-02T02:18:00.000Z'),
chainId: 97,
contractAddress: '0xb7526572FFE56AB9D7489838Bf2E18e3323b441A',
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
poolName: 'Metaverse',
vTokenSymbol: vUsdt.symbol,
token: vUsdt,
txType: 'approve',
},
],
count: 7,
};
9 changes: 9 additions & 0 deletions apps/evm/src/clients/api/__mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { assetData } from '__mocks__/models/asset';
import { importablePositions } from '__mocks__/models/importablePositions';
import { poolData } from '__mocks__/models/pools';
import { primeEstimationData } from '__mocks__/models/primeEstimation';
import { transactions } from '__mocks__/models/transactions';
import vTokens from '__mocks__/models/vTokens';
import { vaults } from '__mocks__/models/vaults';
import voters from '__mocks__/models/voters';
Expand Down Expand Up @@ -634,6 +635,14 @@ export const useGetAccountPerformanceHistory = vi.fn(() =>
}),
);

export const getAccountTransactionHistory = vi.fn(async () => transactions);
export const useGetAccountTransactionHistory = vi.fn(() =>
useQuery({
queryKey: [FunctionKey.GET_ACCOUNT_TRANSACTION_HISTORY],
queryFn: getAccountTransactionHistory,
}),
);

// Mutations
export const useApproveToken = vi.fn((_variables: never, options?: MutationObserverOptions) =>
useMutation({
Expand Down
3 changes: 3 additions & 0 deletions apps/evm/src/clients/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,6 @@ export * from './queries/getImportablePositions/useGetImportablePositions';

export * from './queries/getAccountPerformanceHistory';
export * from './queries/getAccountPerformanceHistory/useGetAccountPerformanceHistory';

export * from './queries/getAccountTransactionHistory';
export * from './queries/getAccountTransactionHistory/useGetAccountTransactionHistory';
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`getAccountTransactionHistory > returns transactions formatted 1`] = `
{
"count": 2,
"transactions": [
{
"accountAddress": "0x3d759121234cd36F8124C21aFe1c6852d2bEd848",
"amountCents": "2406931.018168454893468167206",
"amountTokens": "24066181578079398.612862",
"blockNumber": "41604851",
"blockTimestamp": 2024-08-23T04:17:09.000Z,
"chainId": 97,
"contractAddress": "0xb7526572ffe56ab9d7489838bf2e18e3323b441a",
"hash": "0xda13a0f45b10dabd21b863b6b602c6d8776edd4c6b10fe65a0881d491f468f35",
"poolName": "Metaverse",
"token": {
"address": "0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c",
"asset": "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20fill='none'%20xmlns:v='https://vecta.io/nano'%3e%3cg%20clip-path='url(%23A)'%3e%3cpath%20d='M24%2012c0%206.628-5.372%2012-12%2012S0%2018.628%200%2012%205.373%200%2012%200s12%205.373%2012%2012z'%20fill='%231ba27a'/%3e%3cg%20fill='%23fff'%3e%3cpath%20d='M17.629%206.051H6.267v2.743h4.31v4.032h2.743V8.794h4.31V6.051z'/%3e%3cpath%20d='M11.973%2013.256c-3.565%200-6.456-.564-6.456-1.26s2.89-1.26%206.456-1.26%206.455.564%206.455%201.26-2.89%201.26-6.455%201.26zm7.249-1.05c0-.898-3.245-1.625-7.249-1.625s-7.249.727-7.249%201.625c0%20.79%202.517%201.449%205.851%201.595v5.788h2.743v-5.786c3.36-.141%205.903-.803%205.903-1.597z'/%3e%3c/g%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='A'%3e%3cpath%20fill='%23fff'%20d='M0%200h24v24H0z'/%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",
"decimals": 6,
"symbol": "USDT",
},
"txType": "redeem",
"vTokenSymbol": "vUSDT",
},
{
"accountAddress": "0x3d759121234cd36F8124C21aFe1c6852d2bEd848",
"amountCents": "2401121.576132434220587935367386",
"amountTokens": "24001813290985731.455439",
"blockNumber": "41114058",
"blockTimestamp": 2024-08-06T02:18:03.000Z,
"chainId": 97,
"contractAddress": "0xb7526572ffe56ab9d7489838bf2e18e3323b441a",
"hash": "0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e",
"poolName": "Metaverse",
"token": {
"address": "0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c",
"asset": "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20fill='none'%20xmlns:v='https://vecta.io/nano'%3e%3cg%20clip-path='url(%23A)'%3e%3cpath%20d='M24%2012c0%206.628-5.372%2012-12%2012S0%2018.628%200%2012%205.373%200%2012%200s12%205.373%2012%2012z'%20fill='%231ba27a'/%3e%3cg%20fill='%23fff'%3e%3cpath%20d='M17.629%206.051H6.267v2.743h4.31v4.032h2.743V8.794h4.31V6.051z'/%3e%3cpath%20d='M11.973%2013.256c-3.565%200-6.456-.564-6.456-1.26s2.89-1.26%206.456-1.26%206.455.564%206.455%201.26-2.89%201.26-6.455%201.26zm7.249-1.05c0-.898-3.245-1.625-7.249-1.625s-7.249.727-7.249%201.625c0%20.79%202.517%201.449%205.851%201.595v5.788h2.743v-5.786c3.36-.141%205.903-.803%205.903-1.597z'/%3e%3c/g%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='A'%3e%3cpath%20fill='%23fff'%20d='M0%200h24v24H0z'/%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",
"decimals": 6,
"symbol": "USDT",
},
"txType": "mint",
"vTokenSymbol": "vUSDT",
},
],
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { ChainId } from '@venusprotocol/chains';
import fakeAddress from '__mocks__/models/address';
import { poolData } from '__mocks__/models/pools';
import { TxType } from 'types';
import { restService } from 'utilities';
import { type Mock, vi } from 'vitest';
import { type ApiAccountHistoricalTransaction, getAccountTransactionHistory } from '..';

vi.mock('utilities/restService');

const fakeInput = {
accountAddress: fakeAddress,
chainId: ChainId.BSC_TESTNET,
getPoolsData: { pools: poolData },
contractAddress: 'all',
page: 1,
};

describe('getAccountTransactionHistory', () => {
it('returns transactions formatted', async () => {
(restService as Mock).mockImplementation(() => {
const txs: ApiAccountHistoricalTransaction[] = [
{
id: 'da13a0f45b10dabd21b863b6b602c6d8776edd4c6b10fe65a0881d491f468f35-207-56',
txHash: '0xda13a0f45b10dabd21b863b6b602c6d8776edd4c6b10fe65a0881d491f468f35',
txIndex: 207,
txTimestamp: new Date('2024-08-23T04:17:09.000Z'),
blockNumber: '41604851',
txType: TxType.Redeem,
accountAddress: fakeAddress,
contractAddress: '0xb7526572ffe56ab9d7489838bf2e18e3323b441a',
amountVTokenMantissa: '99319379197734',
amountUnderlyingMantissa: '24066181578079398612862',
chainId: ChainId.BSC_TESTNET,
underlyingAddress: '0xa11c8d9dc9b66e209ef60f0c8d969d3Cd988782c',
underlyingTokenPriceMantissa: '1000130000000000000',
},
{
id: 'b0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e-119-56',
txHash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
txIndex: 119,
txTimestamp: new Date('2024-08-06T02:18:03.000Z'),
blockNumber: '41114058',
txType: TxType.Mint,
accountAddress: fakeAddress,
contractAddress: '0xb7526572ffe56ab9d7489838bf2e18e3323b441a',
amountVTokenMantissa: '99319377752025',
amountUnderlyingMantissa: '24001813290985731455439',
chainId: ChainId.BSC_TESTNET,
underlyingAddress: '0xa11c8d9dc9b66e209ef60f0c8d969d3Cd988782c',
underlyingTokenPriceMantissa: '1000391740000000000',
},
];

return {
data: {
count: '2',
results: txs,
},
};
});

const response = await getAccountTransactionHistory(fakeInput);
expect(response).toMatchSnapshot();
});

it('throws on error in payload', async () => {
(restService as Mock).mockResolvedValue({ data: { error: 'Some error' } });

await expect(getAccountTransactionHistory(fakeInput)).rejects.toMatchObject({
code: 'somethingWentWrong',
});
});

it('throws on undefined payload', async () => {
(restService as Mock).mockResolvedValue({ data: undefined });

await expect(getAccountTransactionHistory(fakeInput)).rejects.toMatchObject({
code: 'somethingWentWrong',
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { TxType, type VToken } from 'types';
import {
convertDollarsToCents,
convertMantissaToTokens,
convertPriceMantissaToDollars,
} from 'utilities';
import type { Address } from 'viem';
import type { AmountTransaction, ApiAccountHistoricalTransaction } from './types';

export const formatApiTransaction = ({
contractToTokenMap,
apiTransaction,
}: {
contractToTokenMap: Record<
Address,
{
vToken: VToken;
poolName: string;
}
>;
apiTransaction: ApiAccountHistoricalTransaction;
}): AmountTransaction => {
const {
txType,
txHash: hash,
txTimestamp,
blockNumber,
accountAddress,
contractAddress,
chainId,
amountUnderlyingMantissa,
underlyingTokenPriceMantissa,
} = apiTransaction;

const { poolName, vToken } = contractToTokenMap[contractAddress];

const isApproval = txType === TxType.Approve;

const vTokenSymbol = vToken.symbol;
const token = isApproval
? {
...vToken,
asset: vToken.asset ?? vToken.underlyingToken.asset,
}
: vToken.underlyingToken;

const canCalculateUsdAmount =
!isApproval && txType !== TxType.EnterMarket && txType !== TxType.ExitMarket;

const amountTokens = amountUnderlyingMantissa
? convertMantissaToTokens({
value: BigInt(amountUnderlyingMantissa),
token,
})
: undefined;

const tokenPriceDollars =
canCalculateUsdAmount && underlyingTokenPriceMantissa
? convertPriceMantissaToDollars({
priceMantissa: underlyingTokenPriceMantissa,
decimals: token.decimals,
})
: undefined;
const tokenPriceCents = tokenPriceDollars ? convertDollarsToCents(tokenPriceDollars) : undefined;
const amountCents =
amountTokens && tokenPriceCents ? amountTokens.multipliedBy(tokenPriceCents) : undefined;

return {
txType,
hash,
blockTimestamp: txTimestamp,
blockNumber,
accountAddress,
contractAddress,
chainId,
poolName,
vTokenSymbol,
amountTokens,
amountCents,
token,
};
};
Loading