From bbec9d74acf30a3b037c9e313d67b465f258f350 Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Mon, 25 Sep 2023 11:03:24 +0100 Subject: [PATCH 1/3] Add in slippage parameter Uniswap --- src/components/current/MessageTranslator.tsx | 1 + src/components/current/widgets/uniswap/Uniswap.tsx | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/current/MessageTranslator.tsx b/src/components/current/MessageTranslator.tsx index bc8772bd..9933fbbf 100644 --- a/src/components/current/MessageTranslator.tsx +++ b/src/components/current/MessageTranslator.tsx @@ -186,6 +186,7 @@ export const Widget = (props: WidgetProps) => { tokenInSymbol={parsedArgs[0]} tokenOutSymbol={parsedArgs[1]} inputAmount={parsedArgs[3]} + slippage={parsedArgs[4]} /> ); diff --git a/src/components/current/widgets/uniswap/Uniswap.tsx b/src/components/current/widgets/uniswap/Uniswap.tsx index 698d2fc1..8c70cfa1 100644 --- a/src/components/current/widgets/uniswap/Uniswap.tsx +++ b/src/components/current/widgets/uniswap/Uniswap.tsx @@ -25,9 +25,10 @@ interface UniswapProps { tokenInSymbol: string; tokenOutSymbol: string; inputAmount: string; + slippage: string; } -const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount }: UniswapProps) => { +const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount, slippage }: UniswapProps) => { const chainId = useChainId(); const { address: recipient } = useAccount(); @@ -36,10 +37,10 @@ const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount }: UniswapProps) = 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; // 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 From 8d6803031248b4c9ce2b6f0f2f8a644f2266e1f5 Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Mon, 25 Sep 2023 11:32:39 +0100 Subject: [PATCH 2/3] WIP: buyvsSell --- src/components/current/MessageTranslator.tsx | 1 + src/components/current/widgets/uniswap/Uniswap.tsx | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/current/MessageTranslator.tsx b/src/components/current/MessageTranslator.tsx index 9933fbbf..692d2358 100644 --- a/src/components/current/MessageTranslator.tsx +++ b/src/components/current/MessageTranslator.tsx @@ -186,6 +186,7 @@ export const Widget = (props: WidgetProps) => { tokenInSymbol={parsedArgs[0]} tokenOutSymbol={parsedArgs[1]} inputAmount={parsedArgs[3]} + buyOrSellAmount={parsedArgs[2]} // BUYAMOUNT or SELLAMOUNT slippage={parsedArgs[4]} /> ); diff --git a/src/components/current/widgets/uniswap/Uniswap.tsx b/src/components/current/widgets/uniswap/Uniswap.tsx index 8c70cfa1..89efd3c8 100644 --- a/src/components/current/widgets/uniswap/Uniswap.tsx +++ b/src/components/current/widgets/uniswap/Uniswap.tsx @@ -26,11 +26,14 @@ interface UniswapProps { tokenOutSymbol: string; inputAmount: string; slippage: string; + buyOrSellAmount: 'BUYAMOUNT' | 'SELLAMOUNT'; } -const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount, slippage }: UniswapProps) => { +const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount, slippage, buyOrSellAmount }: UniswapProps) => { const chainId = useChainId(); + const isBuying = buyOrSellAmount === 'BUYAMOUNT'; + const { address: recipient } = useAccount(); const { data: tokenIn, isETH: tokenInIsETH } = useToken(tokenInSymbol); const { isETH: tokenOutIsETH } = useToken(tokenOutSymbol); From c1b3b16baaa36f373c533fecf9651aeee4e0ca14 Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Tue, 26 Sep 2023 08:59:09 +0100 Subject: [PATCH 3/3] rename to transactionKeyword --- src/components/current/MessageTranslator.tsx | 2 +- .../current/widgets/uniswap/Uniswap.tsx | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/components/current/MessageTranslator.tsx b/src/components/current/MessageTranslator.tsx index 692d2358..bedf30cb 100644 --- a/src/components/current/MessageTranslator.tsx +++ b/src/components/current/MessageTranslator.tsx @@ -186,7 +186,7 @@ export const Widget = (props: WidgetProps) => { tokenInSymbol={parsedArgs[0]} tokenOutSymbol={parsedArgs[1]} inputAmount={parsedArgs[3]} - buyOrSellAmount={parsedArgs[2]} // BUYAMOUNT or SELLAMOUNT + transactionKeyword={parsedArgs[2]} // BUYAMOUNT or SELLAMOUNT slippage={parsedArgs[4]} /> ); diff --git a/src/components/current/widgets/uniswap/Uniswap.tsx b/src/components/current/widgets/uniswap/Uniswap.tsx index 89efd3c8..40232b84 100644 --- a/src/components/current/widgets/uniswap/Uniswap.tsx +++ b/src/components/current/widgets/uniswap/Uniswap.tsx @@ -26,13 +26,12 @@ interface UniswapProps { tokenOutSymbol: string; inputAmount: string; slippage: string; - buyOrSellAmount: 'BUYAMOUNT' | 'SELLAMOUNT'; + transactionKeyword: 'BUYAMOUNT' | 'SELLAMOUNT'; } -const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount, slippage, buyOrSellAmount }: UniswapProps) => { +const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount, slippage, transactionKeyword }: UniswapProps) => { const chainId = useChainId(); - - const isBuying = buyOrSellAmount === 'BUYAMOUNT'; + const isBuying = transactionKeyword === 'BUYAMOUNT'; const { address: recipient } = useAccount(); const { data: tokenIn, isETH: tokenInIsETH } = useToken(tokenInSymbol); @@ -40,10 +39,12 @@ const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount, slippage, buyOrSe const { data: tokenInChecked } = useToken(tokenInIsETH ? 'WETH' : tokenInSymbol); const { data: tokenOutChecked } = useToken(tokenOutIsETH ? 'WETH' : tokenOutSymbol); const input = useInput(inputAmount, tokenInChecked?.symbol!); - // const slippage_ = +slippage; // 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 @@ -254,7 +255,7 @@ const Uniswap = ({ tokenInSymbol, tokenOutSymbol, inputAmount, slippage, buyOrSe