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

TW-1615 Make limits for dexes amount in a swap stricter #1240

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
26 changes: 12 additions & 14 deletions src/app/templates/SwapForm/SwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ import { slippageToleranceInputValidationFn } from './SwapFormInput/SlippageTole
import { SwapFormInput } from './SwapFormInput/SwapFormInput';
import { SwapMinimumReceived } from './SwapMinimumReceived/SwapMinimumReceived';

// These values have been set after some experimentation. They are different to the respective values in
// templewallet-mobile because the mobile app still uses taquito v19.0.0, which has a different gas estimation algorithm.
const SINGLE_SWAP_IN_BATCH_MAX_DEXES = 12;
const LB_OPERATION_DEXES_COST = 3;
const CASHBACK_SWAP_MAX_DEXES = 3;
// Actually, at most 2 dexes for each of underlying SIRS -> tzBTC -> X swap and SIRS -> XTZ -> X swap
const MAIN_SIRS_SWAP_MAX_DEXES = 4;
const MAIN_NON_SIRS_SWAP_MAX_DEXES = 3;

export const SwapForm: FC = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -134,17 +134,13 @@ export const SwapForm: FC = () => {
const isOutputTokenTempleToken = outputAssetSlug === KNOWN_TOKENS_SLUGS.TEMPLE;
const isSirsSwap = inputAssetSlug === KNOWN_TOKENS_SLUGS.SIRS || outputAssetSlug === KNOWN_TOKENS_SLUGS.SIRS;
const isSwapAmountMoreThreshold = inputAmountInUsd.isGreaterThanOrEqualTo(SWAP_THRESHOLD_TO_GET_CASHBACK);
const totalMaxDexes = SINGLE_SWAP_IN_BATCH_MAX_DEXES - (isSirsSwap ? LB_OPERATION_DEXES_COST : 0);
const cashbackSwapMaxDexes = Math.ceil(totalMaxDexes / (isSirsSwap ? 3 : 2));
const mainSwapMaxDexes =
totalMaxDexes - (isSwapAmountMoreThreshold && !isInputTokenTempleToken ? cashbackSwapMaxDexes : 0);
const mainSwapMaxDexes = isSirsSwap ? MAIN_SIRS_SWAP_MAX_DEXES : MAIN_NON_SIRS_SWAP_MAX_DEXES;

return {
isInputTokenTempleToken,
isOutputTokenTempleToken,
isSwapAmountMoreThreshold,
mainSwapMaxDexes,
cashbackSwapMaxDexes
mainSwapMaxDexes
};
},
[allUsdToTokenRates]
Expand Down Expand Up @@ -321,8 +317,10 @@ export const SwapForm: FC = () => {
return;
}

const { isInputTokenTempleToken, isOutputTokenTempleToken, isSwapAmountMoreThreshold, cashbackSwapMaxDexes } =
getSwapWithFeeParams(inputValue, outputValue);
const { isInputTokenTempleToken, isOutputTokenTempleToken, isSwapAmountMoreThreshold } = getSwapWithFeeParams(
inputValue,
outputValue
);

if (isInputTokenTempleToken && isSwapAmountMoreThreshold) {
const routingInputFeeOpParams = await getRoutingFeeTransferParams(
Expand All @@ -348,7 +346,7 @@ export const SwapForm: FC = () => {
toSymbol: TEMPLE_TOKEN.symbol,
toTokenDecimals: TEMPLE_TOKEN.decimals,
amount: atomsToTokens(routingFeeFromInputAtomic, fromRoute3Token.decimals).toFixed(),
dexesLimit: cashbackSwapMaxDexes,
dexesLimit: CASHBACK_SWAP_MAX_DEXES,
rpcUrl: tezos.rpc.getRpcUrl()
});

Expand Down Expand Up @@ -393,7 +391,7 @@ export const SwapForm: FC = () => {
toSymbol: TEMPLE_TOKEN.symbol,
toTokenDecimals: TEMPLE_TOKEN.decimals,
amount: atomsToTokens(routingFeeFromOutputAtomic, toRoute3Token.decimals).toFixed(),
dexesLimit: cashbackSwapMaxDexes,
dexesLimit: CASHBACK_SWAP_MAX_DEXES,
rpcUrl: tezos.rpc.getRpcUrl()
});

Expand Down
Loading