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 dynamic ETH offset for swaps/limits #3221

Merged
merged 2 commits into from
Nov 13, 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
17 changes: 9 additions & 8 deletions src/components/Form/TokenInputWithWalletBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface propsIF {
tokenDexBalance?: string;
isWithdraw?: boolean;
disabledContent?: React.ReactNode;
amountToReduceEth?: number;
}

function TokenInputWithWalletBalance(props: propsIF) {
Expand All @@ -52,19 +53,21 @@ function TokenInputWithWalletBalance(props: propsIF) {
handleToggleDexSelection,
parseTokenInput,
handleRefresh,
amountToReduceEth,
} = props;

const {
chainData: { chainId },
} = useContext(CrocEnvContext);

const amountToReduceEthMainnet = 0.005; // .005 ETH
const amountToReduceEthMainnet = 0.01; // .01 ETH
const amountToReduceEthScroll = 0.0003; // .0003 ETH

const amountToReduceEth =
chainId === '0x82750' || chainId === '0x8274f'
? amountToReduceEthScroll
: amountToReduceEthMainnet;
const ethOffset = amountToReduceEth
? amountToReduceEth
: chainId === '0x82750' || chainId === '0x8274f'
? amountToReduceEthScroll
: amountToReduceEthMainnet;

const [usdValueForDom, setUsdValueForDom] = useState<string | undefined>();

Expand Down Expand Up @@ -115,9 +118,7 @@ function TokenInputWithWalletBalance(props: propsIF) {
});

const subtractBuffer = (balance: string) =>
isTokenEth
? (parseFloat(balance) - amountToReduceEth).toFixed(18)
: balance;
isTokenEth ? (parseFloat(balance) - ethOffset).toFixed(18) : balance;

const balanceWithBuffer = balance ? subtractBuffer(balance) : '...';

Expand Down
3 changes: 3 additions & 0 deletions src/components/Swap/SwapTokenInput/SwapTokenInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface propsIF {
isLiquidityInsufficient: boolean;
setIsLiquidityInsufficient: Dispatch<SetStateAction<boolean>>;
toggleDexSelection: (tokenAorB: 'A' | 'B') => void;
amountToReduceEth: number;
}

function SwapTokenInput(props: propsIF) {
Expand All @@ -62,6 +63,7 @@ function SwapTokenInput(props: propsIF) {
isLiquidityInsufficient,
setIsLiquidityInsufficient,
toggleDexSelection,
amountToReduceEth,
} = props;

const {
Expand Down Expand Up @@ -328,6 +330,7 @@ function SwapTokenInput(props: propsIF) {
parseTokenInput={(val: string, isMax?: boolean) => {
setSellQtyString(formatTokenInput(val, tokenA, isMax));
}}
amountToReduceEth={amountToReduceEth}
/>
<FlexContainer
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface propsIF {
isSaveAsDexSurplusChecked: boolean;
handleLimitButtonMessage: (val: number) => void;
toggleDexSelection: (tokenAorB: 'A' | 'B') => void;
amountToReduceEth: number;
}

function LimitTokenInput(props: propsIF) {
Expand All @@ -46,6 +47,7 @@ function LimitTokenInput(props: propsIF) {
isSaveAsDexSurplusChecked,
handleLimitButtonMessage,
toggleDexSelection,
amountToReduceEth,
} = props;

const {
Expand Down Expand Up @@ -222,6 +224,7 @@ function LimitTokenInput(props: propsIF) {
setTokenAInputQty(formatTokenInput(val, tokenA, isMax));
}}
showWallet={isUserConnected}
amountToReduceEth={amountToReduceEth}
/>
<FlexContainer
fullWidth
Expand Down
11 changes: 10 additions & 1 deletion src/pages/Trade/Limit/Limit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ export default function Limit() {
? 120000
: 150000
: 150000;

const costOfMainnetLimitInETH =
gasPriceInGwei * averageLimitCostInGasDrops * 1e-9;

setAmountToReduceEthMainnet(1.75 * costOfMainnetLimitInETH);

const gasPriceInDollarsNum =
gasPriceInGwei *
averageLimitCostInGasDrops *
Expand Down Expand Up @@ -538,7 +544,9 @@ export default function Limit() {
}
};

const amountToReduceEthMainnet = 0.005; // .005 ETH
const [amountToReduceEthMainnet, setAmountToReduceEthMainnet] =
useState<number>(0.01);

const amountToReduceEthScroll = 0.0003; // .0003 ETH

const amountToReduceEth =
Expand Down Expand Up @@ -653,6 +661,7 @@ export default function Limit() {
limitTickDisplayPrice={middleDisplayPrice}
handleLimitButtonMessage={handleLimitButtonMessage}
toggleDexSelection={toggleDexSelection}
amountToReduceEth={amountToReduceEth}
/>
}
inputOptions={
Expand Down
10 changes: 9 additions & 1 deletion src/pages/Trade/Swap/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ function Swap(props: propsIF) {

const isSellTokenNativeToken = tokenA.address === ZERO_ADDRESS;

const amountToReduceEthMainnet = 0.005; // .005 ETH
// const amountToReduceEthMainnet = 0.01; // .01 ETH
const [amountToReduceEthMainnet, setAmountToReduceEthMainnet] =
useState<number>(0.01);
const amountToReduceEthScroll = 0.0003; // .0003 ETH

const amountToReduceEth =
Expand Down Expand Up @@ -269,6 +271,11 @@ function Swap(props: propsIF) {
? 105000
: 110000;

const costOfMainnetSwapInETH =
gasPriceInGwei * averageSwapCostInGasDrops * 1e-9;

setAmountToReduceEthMainnet(1.75 * costOfMainnetSwapInETH);

const gasPriceInDollarsNum =
gasPriceInGwei *
averageSwapCostInGasDrops *
Expand Down Expand Up @@ -505,6 +512,7 @@ function Swap(props: propsIF) {
isSaveAsDexSurplusChecked={isSaveAsDexSurplusChecked}
setSwapAllowed={setSwapAllowed}
toggleDexSelection={toggleDexSelection}
amountToReduceEth={amountToReduceEth}
/>
}
transactionDetails={
Expand Down