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

Add in slippage parameter Uniswap #457

Merged
merged 3 commits into from
Sep 26, 2023
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
2 changes: 2 additions & 0 deletions src/components/current/MessageTranslator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export const Widget = (props: WidgetProps) => {
tokenInSymbol={parsedArgs[0]}
tokenOutSymbol={parsedArgs[1]}
inputAmount={parsedArgs[3]}
transactionKeyword={parsedArgs[2]} // BUYAMOUNT or SELLAMOUNT
slippage={parsedArgs[4]}
/>
);

Expand Down
13 changes: 9 additions & 4 deletions src/components/current/widgets/uniswap/Uniswap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,26 @@ interface UniswapProps {
tokenInSymbol: string;
tokenOutSymbol: string;
inputAmount: string;
slippage: string;
transactionKeyword: 'BUYAMOUNT' | 'SELLAMOUNT';
}

const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount }: UniswapProps) => {
const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount, slippage, transactionKeyword }: UniswapProps) => {
const chainId = useChainId();
const isBuying = transactionKeyword === 'BUYAMOUNT';

const { address: recipient } = useAccount();
const { data: tokenIn, isETH: tokenInIsETH } = useToken(tokenInSymbol);
const { isETH: tokenOutIsETH } = useToken(tokenOutSymbol);
const { data: tokenInChecked } = useToken(tokenInIsETH ? 'WETH' : tokenInSymbol);
const { data: tokenOutChecked } = useToken(tokenOutIsETH ? 'WETH' : tokenOutSymbol);
const input = useInput(inputAmount, tokenInChecked?.symbol!);
const slippage = 2.0; // in percentage terms

const slippage_ = +slippage || 0.5; // in percentage terms

const getSlippageAdjustedAmount = (amount: BigNumber) =>
BigNumber.from(amount)
.mul(10000 - slippage * 100)
.mul(10000 - slippage_ * 100)
.div(10000);

// token out quote for amount in
Expand Down Expand Up @@ -250,7 +255,7 @@ const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount }: UniswapProps) =
<ListResponse
title="Breakdown"
data={[
['Slippage', `${slippage}%`],
['Slippage', `${slippage_}%`],
['Minimum swap', cleanValue(amountOutMinimum_, 2)],
['Route', `${tokenInSymbol}-${tokenOutSymbol}`],
]}
Expand Down