Skip to content
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

[APP-860]: Add debug logs for cross-chain bug discovery #5246

Merged
merged 1 commit into from
Dec 14, 2023
Merged
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
52 changes: 46 additions & 6 deletions src/hooks/useSwapDerivedOutputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
updatePrecisionToDisplay,
} from '@/helpers/utilities';
import { ethereumUtils } from '@/utils';
import Logger from '@/utils/logger';
import { logger } from '@/logger';

const SWAP_POLLING_INTERVAL = 5000;

Expand Down Expand Up @@ -96,6 +96,19 @@ const getInputAmount = async (
convertNumberToString(outputAmount),
outputToken.decimals
);

logger.info(`[getInputAmount]: `, {
outputToken,
outputChainId,
outputNetwork,
outputTokenAddress,
inputToken,
inputChainId,
inputNetwork,
inputTokenAddress,
isCrosschainSwap,
});

const quoteSource = getSource(source);
const quoteParams: QuoteParams = {
buyAmount,
Expand All @@ -110,7 +123,7 @@ const getInputAmount = async (
};

const rand = Math.floor(Math.random() * 100);
Logger.debug('Getting quote ', rand, { quoteParams });
logger.debug('[getInputAmount]: Getting quote', { rand, quoteParams });
// Do not deleeeet the comment below 😤
// @ts-ignore About to get quote
const quote = await getQuote(quoteParams);
Expand All @@ -119,7 +132,7 @@ const getInputAmount = async (
if (!quote || (quote as QuoteError).error || !(quote as Quote).sellAmount) {
if ((quote as QuoteError).error) {
const quoteError = (quote as unknown) as QuoteError;
Logger.log('Quote Error', {
logger.log('[getInputAmount]: Quote error', {
code: quoteError.error_code,
msg: quoteError.message,
});
Expand Down Expand Up @@ -196,6 +209,17 @@ const getOutputAmount = async (
inputToken.decimals
);
const isCrosschainSwap = outputNetwork !== inputNetwork;

logger.info(`[getOutputAmount]: `, {
outputToken,
outputChainId,
outputNetwork,
inputToken,
inputChainId,
inputNetwork,
isCrosschainSwap,
});

const quoteSource = getSource(source);
const quoteParams: QuoteParams = {
buyTokenAddress,
Expand All @@ -212,7 +236,7 @@ const getOutputAmount = async (
};

const rand = Math.floor(Math.random() * 100);
Logger.debug('Getting quote ', rand, { quoteParams });
logger.debug('[getOutputAmount]: Getting quote', { rand, quoteParams });
// Do not deleeeet the comment below 😤
// @ts-ignore About to get quote
const quote:
Expand All @@ -222,7 +246,7 @@ const getOutputAmount = async (
| null = await (isCrosschainSwap ? getCrosschainQuote : getQuote)(
quoteParams
);
Logger.debug('Got quote', rand, quote);
logger.debug('[getOutputAmount]: Got quote', { rand, quote });

if (
!quote ||
Expand All @@ -231,7 +255,7 @@ const getOutputAmount = async (
) {
const quoteError = quote as QuoteError;
if (quoteError.error) {
Logger.log('Quote Error', {
logger.log('[getOutputAmount]: Quote error', {
code: quoteError.error_code,
msg: quoteError.message,
});
Expand Down Expand Up @@ -378,6 +402,18 @@ export default function useSwapDerivedOutputs(type: string) {
};
}

logger.log('[getTradeDetails]: Getting trade details', {
independentField,
independentValue,
inputCurrency,
outputCurrency,
inputPrice,
outputPrice,
slippageInBips,
source,
refuel,
});

let tradeDetails = null;
const slippagePercentage = slippageInBips / 100;
let quoteError: QuoteError | undefined;
Expand Down Expand Up @@ -532,6 +568,10 @@ export default function useSwapDerivedOutputs(type: string) {
tradeDetails,
};

logger.log('[getTradeDetails]: Got trade details', {
data,
});

dispatch(
updateSwapQuote({
derivedValues: data.derivedValues,
Expand Down
Loading