Skip to content

chore: tracking txs usd amounts to amplitude #2564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2025
Merged
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
4 changes: 4 additions & 0 deletions src/components/transactions/Borrow/BorrowActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MAX_UINT_AMOUNT,
ProtocolAction,
} from '@aave/contract-helpers';
import { valueToBigNumber } from '@aave/math-utils';
import { Trans } from '@lingui/macro';
import { BoxProps } from '@mui/material';
import { useQueryClient } from '@tanstack/react-query';
Expand Down Expand Up @@ -126,6 +127,9 @@ export const BorrowActions = React.memo(
asset: poolAddress,
amount: amountToBorrow,
assetName: poolReserve.name,
amountUsd: valueToBigNumber(amountToBorrow)
.multipliedBy(poolReserve.priceInUSD)
.toString(),
});

queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });
Expand Down
9 changes: 9 additions & 0 deletions src/components/transactions/DebtSwitch/DebtSwitchActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
gasLimitRecommendations,
ProtocolAction,
} from '@aave/contract-helpers';
import { valueToBigNumber } from '@aave/math-utils';
import { SignatureLike } from '@ethersproject/bytes';
import { Trans } from '@lingui/macro';
import { BoxProps } from '@mui/material';
Expand Down Expand Up @@ -194,6 +195,14 @@ export const DebtSwitchActions = ({
txState: 'success',
previousState: `${route.outputAmount} variable ${poolReserve.symbol}`,
newState: `${route.inputAmount} variable ${targetReserve.symbol}`,
amountUsd: valueToBigNumber(parseUnits(amountToSwap, poolReserve.decimals).toString())
.multipliedBy(poolReserve.priceInUSD)
.toString(),
outAmountUsd: valueToBigNumber(
parseUnits(amountToReceive, targetReserve.decimals).toString()
)
.multipliedBy(targetReserve.priceInUSD)
.toString(),
});

queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });
Expand Down
8 changes: 7 additions & 1 deletion src/components/transactions/Repay/RepayActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { gasLimitRecommendations, InterestRate, ProtocolAction } from '@aave/contract-helpers';
import { valueToBigNumber } from '@aave/math-utils';
import { TransactionResponse } from '@ethersproject/providers';
import { Trans } from '@lingui/macro';
import { BoxProps } from '@mui/material';
Expand Down Expand Up @@ -29,6 +30,7 @@ export interface RepayActionProps extends BoxProps {
repayWithATokens: boolean;
blocked?: boolean;
maxApproveNeeded: string;
maxAmountToRepay: string;
}

export const RepayActions = ({
Expand All @@ -41,6 +43,7 @@ export const RepayActions = ({
repayWithATokens,
blocked,
maxApproveNeeded,
maxAmountToRepay,
...props
}: RepayActionProps) => {
const [
Expand Down Expand Up @@ -197,8 +200,11 @@ export const RepayActions = ({
action,
txState: 'success',
asset: poolAddress,
amount: amountToRepay,
amount: amountToRepay === '-1' ? maxAmountToRepay : amountToRepay,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgrabina should this change?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we just care about the amountUsd for that value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we currently have the same issue in amount sending -1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but is it changing anything in the actual transaction or is it just information sent to amplitude

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope transaction is sent just above
image
(whatsmore addTransaction only executed if tx was successful)

and addTransaction just 'saves' the tx in the state, which are used only in TransactionEventHandler just for tracking

assetName: symbol,
amountUsd: valueToBigNumber(amountToRepay === '-1' ? maxAmountToRepay : amountToRepay)
.multipliedBy(poolReserve.priceInUSD)
.toString(),
});

queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });
Expand Down
1 change: 1 addition & 0 deletions src/components/transactions/Repay/RepayModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export const RepayModalContent = ({
isWrongNetwork={isWrongNetwork}
symbol={modalSymbol}
repayWithATokens={repayWithATokens}
maxAmountToRepay={maxAmountToRepay.toString(10)}
/>
</>
);
Expand Down
9 changes: 9 additions & 0 deletions src/components/transactions/Supply/SupplyActions.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { gasLimitRecommendations, ProtocolAction } from '@aave/contract-helpers';
import { valueToBigNumber } from '@aave/math-utils';
import { TransactionResponse } from '@ethersproject/providers';
import { Trans } from '@lingui/macro';
import { BoxProps } from '@mui/material';
import { useQueryClient } from '@tanstack/react-query';
import { parseUnits } from 'ethers/lib/utils';
import React, { useEffect, useState } from 'react';
import { useAppDataContext } from 'src/hooks/app-data-provider/useAppDataProvider';
import { SignedParams, useApprovalTx } from 'src/hooks/useApprovalTx';
import { usePoolApprovedAmount } from 'src/hooks/useApprovedAmount';
import { useModalContext } from 'src/hooks/useModal';
Expand Down Expand Up @@ -60,6 +62,7 @@ export const SupplyActions = React.memo(
state.currentMarketData,
])
);
const { reserves } = useAppDataContext();
const {
approvalTxState,
mainTxState,
Expand Down Expand Up @@ -181,6 +184,12 @@ export const SupplyActions = React.memo(
asset: poolAddress,
amount: amountToSupply,
assetName: symbol,
amountUsd: (() => {
const reserve = reserves.find((r) => r.underlyingAsset === poolAddress);
return reserve
? valueToBigNumber(amountToSupply).multipliedBy(reserve.priceInUSD).toString()
: undefined;
})(),
});

queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });
Expand Down
1 change: 1 addition & 0 deletions src/components/transactions/Supply/SupplyModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ export const SupplyWrappedTokenModalContent = ({
decimals={18}
symbol={wrappedTokenConfig.tokenIn.symbol}
isWrongNetwork={isWrongNetwork}
reserve={poolReserve}
/>
) : (
<SupplyActions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { gasLimitRecommendations, ProtocolAction } from '@aave/contract-helpers';
import { valueToBigNumber } from '@aave/math-utils';
import { SignatureLike } from '@ethersproject/bytes';
import { TransactionResponse } from '@ethersproject/providers';
import { Trans } from '@lingui/macro';
import { BoxProps } from '@mui/material';
import { useQueryClient } from '@tanstack/react-query';
import { parseUnits } from 'ethers/lib/utils';
import { useState } from 'react';
import { ComputedReserveData } from 'src/hooks/app-data-provider/useAppDataProvider';
import { useApprovalTx } from 'src/hooks/useApprovalTx';
import { useApprovedAmount } from 'src/hooks/useApprovedAmount';
import { useModalContext } from 'src/hooks/useModal';
Expand All @@ -32,6 +34,7 @@ interface SupplyWrappedTokenActionProps extends BoxProps {
symbol: string;
tokenWrapperAddress: string;
isWrongNetwork: boolean;
reserve: ComputedReserveData;
}
export const SupplyWrappedTokenActions = ({
tokenIn,
Expand All @@ -41,7 +44,8 @@ export const SupplyWrappedTokenActions = ({
tokenWrapperAddress,
isWrongNetwork,
sx,
...props
reserve,
...propsx
}: SupplyWrappedTokenActionProps) => {
const [user, estimateGasLimit, addTransaction, marketData] = useRootStore(
useShallow((state) => [
Expand Down Expand Up @@ -174,6 +178,7 @@ export const SupplyWrappedTokenActions = ({
asset: tokenIn,
amount: amountToSupply,
assetName: symbol,
amountUsd: valueToBigNumber(amountToSupply).multipliedBy(reserve.priceInUSD).toString(),
});

queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });
Expand Down Expand Up @@ -212,7 +217,7 @@ export const SupplyWrappedTokenActions = ({
requiresApproval={requiresApproval}
tryPermit={usePermit}
sx={sx}
{...props}
{...propsx}
/>
);
};
4 changes: 4 additions & 0 deletions src/components/transactions/Withdraw/WithdrawActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ProtocolAction } from '@aave/contract-helpers';
import { valueToBigNumber } from '@aave/math-utils';
import { Trans } from '@lingui/macro';
import { BoxProps } from '@mui/material';
import { useTransactionHandler } from 'src/helpers/useTransactionHandler';
Expand Down Expand Up @@ -42,6 +43,9 @@ export const WithdrawActions = ({
amount: amountToWithdraw,
assetName: poolReserve.name,
asset: poolReserve.underlyingAsset,
amountUsd: valueToBigNumber(amountToWithdraw)
.multipliedBy(poolReserve.priceInUSD)
.toString(),
},
protocolAction: ProtocolAction.withdraw,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ERC20Service, gasLimitRecommendations, ProtocolAction } from '@aave/contract-helpers';
import { valueToBigNumber } from '@aave/math-utils';
import { SignatureLike } from '@ethersproject/bytes';
import { Trans } from '@lingui/macro';
import { BoxProps } from '@mui/material';
Expand Down Expand Up @@ -148,6 +149,14 @@ export const WithdrawAndSwitchActions = ({
outAsset: targetReserve.underlyingAsset,
outAssetName: targetReserve.name,
outAmount: parseUnits(route.outputAmount, targetReserve.decimals).toString(),
amountUsd: valueToBigNumber(parseUnits(route.inputAmount, poolReserve.decimals).toString())
.multipliedBy(poolReserve.priceInUSD)
.toString(),
outAmountUsd: valueToBigNumber(
parseUnits(route.outputAmount, targetReserve.decimals).toString()
)
.multipliedBy(targetReserve.priceInUSD)
.toString(),
});
} catch (error) {
const parsedError = getErrorTextFromError(error, TxAction.GAS_ESTIMATION, false);
Expand Down
5 changes: 5 additions & 0 deletions src/modules/umbrella/UmbrellaActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
StakeTokenService,
UmbrellaBatchHelperService,
} from '@aave/contract-helpers';
import { valueToBigNumber } from '@aave/math-utils';
import { Trans } from '@lingui/macro';
import { BoxProps } from '@mui/material';
import { useQueryClient } from '@tanstack/react-query';
Expand All @@ -13,6 +14,7 @@ import { parseUnits } from 'ethers/lib/utils';
import { useEffect, useState } from 'react';
import { TxActionsWrapper } from 'src/components/transactions/TxActionsWrapper';
import { APPROVAL_GAS_LIMIT, checkRequiresApproval } from 'src/components/transactions/utils';
import { ComputedReserveData } from 'src/hooks/app-data-provider/useAppDataProvider';
import { MergedStakeData } from 'src/hooks/stake/useUmbrellaSummary';
import { SignedParams, useApprovalTx } from 'src/hooks/useApprovalTx';
import { useApprovedAmount } from 'src/hooks/useApprovedAmount';
Expand All @@ -37,6 +39,7 @@ export interface StakeActionProps extends BoxProps {
selectedToken: StakeInputAsset;
event: string;
isMaxSelected: boolean;
reserve: ComputedReserveData;
}

export const UmbrellaActions = ({
Expand All @@ -49,6 +52,7 @@ export const UmbrellaActions = ({
event,
stakeData,
isMaxSelected,
reserve,
...props
}: StakeActionProps) => {
const queryClient = useQueryClient();
Expand Down Expand Up @@ -193,6 +197,7 @@ export const UmbrellaActions = ({
action: ProtocolAction.umbrellaStake,
amount: amountToStake,
assetName: selectedToken.symbol,
amountUsd: valueToBigNumber(amountToStake).multipliedBy(reserve.priceInUSD).toString(),
});

queryClient.invalidateQueries({ queryKey: queryKeysFactory.umbrella });
Expand Down
1 change: 1 addition & 0 deletions src/modules/umbrella/UmbrellaModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export const UmbrellaModalContent = ({ stakeData, user, userReserve, poolReserve
amountToStake={amount || '0'}
isWrongNetwork={isWrongNetwork}
symbol={''}
reserve={poolReserve}
blocked={
displayBlockingStake !== undefined || (displayRiskCheckbox && !riskCheckboxAccepted)
}
Expand Down
5 changes: 5 additions & 0 deletions src/modules/umbrella/UnstakeModalActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ProtocolAction,
UmbrellaBatchHelperService,
} from '@aave/contract-helpers';
import { valueToBigNumber } from '@aave/math-utils';
import { Trans } from '@lingui/macro';
import { BoxProps } from '@mui/material';
import { useQueryClient } from '@tanstack/react-query';
Expand All @@ -11,6 +12,7 @@ import { parseUnits } from 'ethers/lib/utils';
import { useEffect } from 'react';
import { TxActionsWrapper } from 'src/components/transactions/TxActionsWrapper';
import { APPROVAL_GAS_LIMIT, checkRequiresApproval } from 'src/components/transactions/utils';
import { ComputedReserveData } from 'src/hooks/app-data-provider/useAppDataProvider';
import { MergedStakeData } from 'src/hooks/stake/useUmbrellaSummary';
import { useApprovalTx } from 'src/hooks/useApprovalTx';
import { useApprovedAmount } from 'src/hooks/useApprovedAmount';
Expand All @@ -32,6 +34,7 @@ export interface UnStakeActionProps extends BoxProps {
blocked: boolean;
stakeData: MergedStakeData;
redeemType: RedeemType;
reserve: ComputedReserveData;
}

export const UnStakeActions = ({
Expand All @@ -42,6 +45,7 @@ export const UnStakeActions = ({
blocked,
stakeData,
redeemType,
reserve,
}: UnStakeActionProps) => {
const queryClient = useQueryClient();
const [currentChainId, user, currentMarket, estimateGasLimit, addTransaction] = useRootStore(
Expand Down Expand Up @@ -171,6 +175,7 @@ export const UnStakeActions = ({
: ProtocolAction.umbrellaStakeGatewayRedeem,
amount: amountToUnStake,
assetName: stakeData.symbol,
amountUsd: valueToBigNumber(amountToUnStake).multipliedBy(reserve.priceInUSD).toString(),
});

queryClient.invalidateQueries({ queryKey: queryKeysFactory.umbrella });
Expand Down
1 change: 1 addition & 0 deletions src/modules/umbrella/UnstakeModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export const UnStakeModalContent = ({
symbol={symbolFormatted}
blocked={false}
stakeData={stakeData}
reserve={poolReserve}
redeemType={redeemType}
/>
</>
Expand Down
Loading