From bd1e2080e5fbd4f1d89bdd5cfb9cbac55f13386c Mon Sep 17 00:00:00 2001 From: Inokentii Mazhara Date: Mon, 23 Dec 2024 18:03:06 +0200 Subject: [PATCH 1/2] TW-1616: Fix failed estimation of confirmation for in wallet swaps (#1117) --- src/apis/liquidity-baking/index.ts | 6 ++-- src/config/swap.ts | 7 +++-- ...liquidity-baking-stake-transfers-params.ts | 6 ++-- .../create-stake-transfer-params.ts | 6 ++-- src/screens/swap/swap-form/swap-form.tsx | 30 +++++++++---------- src/utils/route3.util.ts | 10 +++++-- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/apis/liquidity-baking/index.ts b/src/apis/liquidity-baking/index.ts index 505d921b1..c3471b4b5 100644 --- a/src/apis/liquidity-baking/index.ts +++ b/src/apis/liquidity-baking/index.ts @@ -1,7 +1,7 @@ import { TezosToolkit } from '@taquito/taquito'; import { BigNumber } from 'bignumber.js'; -import { SINGLE_SIRS_SWAP_MAX_DEXES } from 'src/config/swap'; +import { MAIN_SIRS_SWAP_MAX_DEXES } from 'src/config/swap'; import { EarnOpportunityTokenStandardEnum } from 'src/enums/earn-opportunity-token-standard.enum'; import { EarnOpportunityTypeEnum } from 'src/enums/earn-opportunity-type.enum'; import { LiquidityBakingStorage } from 'src/op-params/liquidity-baking-storage.interface'; @@ -128,8 +128,8 @@ export const calculateUnstakeParams = async ( toTokenDecimals: threeRouteOutputToken.decimals, amount: mutezToTz(swapInputMinusFeeAtomic, SIRS_TOKEN_METADATA.decimals).toFixed(), // Such swap has either XTZ or tzBTC hops - xtzDexesLimit: SINGLE_SIRS_SWAP_MAX_DEXES, - tzbtcDexesLimit: SINGLE_SIRS_SWAP_MAX_DEXES, + xtzDexesLimit: MAIN_SIRS_SWAP_MAX_DEXES, + tzbtcDexesLimit: MAIN_SIRS_SWAP_MAX_DEXES, rpcUrl }); diff --git a/src/config/swap.ts b/src/config/swap.ts index b5cc8966a..01d9556c3 100644 --- a/src/config/swap.ts +++ b/src/config/swap.ts @@ -21,9 +21,10 @@ export const ATOMIC_INPUT_THRESHOLD_FOR_FEE_FROM_INPUT = Math.ceil( ); // These values have been set after some experimentation -export const SINGLE_SWAP_IN_BATCH_MAX_DEXES = 12; -const LB_OPERATION_DEXES_COST = 2; -export const SINGLE_SIRS_SWAP_MAX_DEXES = SINGLE_SWAP_IN_BATCH_MAX_DEXES - LB_OPERATION_DEXES_COST; +export const CASHBACK_SWAP_MAX_DEXES = 3; +// Actually, at most 2 dexes for each of underlying SIRS -> tzBTC -> X swap and SIRS -> XTZ -> X swap +export const MAIN_SIRS_SWAP_MAX_DEXES = 4; +export const MAIN_NON_SIRS_SWAP_MAX_DEXES = 3; export const TEMPLE_TOKEN: Route3Token = { id: 138, diff --git a/src/modals/manage-earn-opportunity-modal/stake-form/create-liquidity-baking-stake-transfers-params.ts b/src/modals/manage-earn-opportunity-modal/stake-form/create-liquidity-baking-stake-transfers-params.ts index 9d773a11c..11634e18f 100644 --- a/src/modals/manage-earn-opportunity-modal/stake-form/create-liquidity-baking-stake-transfers-params.ts +++ b/src/modals/manage-earn-opportunity-modal/stake-form/create-liquidity-baking-stake-transfers-params.ts @@ -1,7 +1,7 @@ import { TezosToolkit } from '@taquito/taquito'; import { BigNumber } from 'bignumber.js'; -import { ROUTING_FEE_ADDRESS, SINGLE_SIRS_SWAP_MAX_DEXES } from 'src/config/swap'; +import { MAIN_SIRS_SWAP_MAX_DEXES, ROUTING_FEE_ADDRESS } from 'src/config/swap'; import { THREE_ROUTE_SIRS_TOKEN, THREE_ROUTE_TZBTC_TOKEN, @@ -43,8 +43,8 @@ export const createLiquidityBakingStakeTransfersParams = async ( toTokenDecimals: THREE_ROUTE_SIRS_TOKEN.decimals, amount: mutezToTz(swapInputMinusFeeAtomic, inputToken.decimals).toFixed(), // Such swap has either XTZ or tzBTC hops - xtzDexesLimit: SINGLE_SIRS_SWAP_MAX_DEXES, - tzbtcDexesLimit: SINGLE_SIRS_SWAP_MAX_DEXES, + xtzDexesLimit: MAIN_SIRS_SWAP_MAX_DEXES, + tzbtcDexesLimit: MAIN_SIRS_SWAP_MAX_DEXES, rpcUrl }); const slippageRatio = calculateSlippageRatio(slippageTolerancePercentage); diff --git a/src/modals/manage-earn-opportunity-modal/stake-form/create-stake-transfer-params.ts b/src/modals/manage-earn-opportunity-modal/stake-form/create-stake-transfer-params.ts index e557cbf76..f936f76aa 100644 --- a/src/modals/manage-earn-opportunity-modal/stake-form/create-stake-transfer-params.ts +++ b/src/modals/manage-earn-opportunity-modal/stake-form/create-stake-transfer-params.ts @@ -1,14 +1,14 @@ import { TezosToolkit } from '@taquito/taquito'; import { BigNumber } from 'bignumber.js'; -import { ROUTING_FEE_ADDRESS, SINGLE_SWAP_IN_BATCH_MAX_DEXES } from 'src/config/swap'; +import { MAIN_NON_SIRS_SWAP_MAX_DEXES, MAIN_SIRS_SWAP_MAX_DEXES, ROUTING_FEE_ADDRESS } from 'src/config/swap'; import { SavingsItem } from 'src/interfaces/earn-opportunity/savings-item.interface'; import { Route3Token } from 'src/interfaces/route3.interface'; import { ToastError } from 'src/toast/error-toast.utils'; import { TokenInterface } from 'src/token/interfaces/token.interface'; import { getTokenSlug, toTokenSlug } from 'src/token/utils/token.utils'; import { isDefined } from 'src/utils/is-defined'; -import { fetchRoute3SwapParams } from 'src/utils/route3.util'; +import { fetchRoute3SwapParams, isSirsSwap } from 'src/utils/route3.util'; import { calculateSidePaymentsFromInput, calculateSlippageRatio, @@ -51,7 +51,7 @@ export const createStakeTransfersParams = async ( toSymbol: toRoute3Token.symbol, toTokenDecimals: toRoute3Token.decimals, amount: mutezToTz(swapInputMinusFeeAtomic, asset.decimals).toString(), - dexesLimit: SINGLE_SWAP_IN_BATCH_MAX_DEXES, + dexesLimit: isSirsSwap(fromRoute3Token, toRoute3Token) ? MAIN_SIRS_SWAP_MAX_DEXES : MAIN_NON_SIRS_SWAP_MAX_DEXES, rpcUrl: tezos.rpc.getRpcUrl() }); diff --git a/src/screens/swap/swap-form/swap-form.tsx b/src/screens/swap/swap-form/swap-form.tsx index f288e002d..0b5b15d45 100644 --- a/src/screens/swap/swap-form/swap-form.tsx +++ b/src/screens/swap/swap-form/swap-form.tsx @@ -15,11 +15,12 @@ import { tokenEqualityFn } from 'src/components/token-dropdown/token-equality-fn import { ATOMIC_INPUT_THRESHOLD_FOR_FEE_FROM_INPUT, CASHBACK_RATIO, + CASHBACK_SWAP_MAX_DEXES, + MAIN_NON_SIRS_SWAP_MAX_DEXES, + MAIN_SIRS_SWAP_MAX_DEXES, ROUTING_FEE_ADDRESS, ROUTING_FEE_RATIO, ROUTING_FEE_SLIPPAGE_RATIO, - SINGLE_SIRS_SWAP_MAX_DEXES, - SINGLE_SWAP_IN_BATCH_MAX_DEXES, SWAP_THRESHOLD_TO_GET_CASHBACK, TEMPLE_TOKEN } from 'src/config/swap'; @@ -49,7 +50,7 @@ import { import { useCurrentAccountPkhSelector, useCurrentAccountTezosBalance } from 'src/store/wallet/wallet-selectors'; import { formatSize } from 'src/styles/format-size'; import { showErrorToast } from 'src/toast/toast.utils'; -import { KNOWN_TOKENS_SLUGS, TEMPLE_TOKEN_SLUG } from 'src/token/data/token-slugs'; +import { TEMPLE_TOKEN_SLUG } from 'src/token/data/token-slugs'; import { TEZ_TOKEN_SLUG } from 'src/token/data/tokens-metadata'; import { emptyTezosLikeToken, TokenInterface } from 'src/token/interfaces/token.interface'; import { getTokenSlug } from 'src/token/utils/token.utils'; @@ -58,7 +59,7 @@ import { useAnalytics } from 'src/utils/analytics/use-analytics.hook'; import { isDefined } from 'src/utils/is-defined'; import { BURN_ADDRESS } from 'src/utils/known-addresses'; import { ZERO } from 'src/utils/number.util'; -import { fetchRoute3SwapParams, getRoute3TokenSymbol } from 'src/utils/route3.util'; +import { fetchRoute3SwapParams, getRoute3TokenSymbol, isSirsSwap } from 'src/utils/route3.util'; import { calculateSidePaymentsFromInput, calculateOutputFeeAtomic, @@ -115,19 +116,16 @@ export const SwapForm: FC = ({ inputToken, outputToken }) => { const isInputTokenTempleToken = inputAssetSlug === TEMPLE_TOKEN_SLUG; const isOutputTokenTempleToken = outputAssetSlug === TEMPLE_TOKEN_SLUG; - const isSirsSwap = inputAssetSlug === KNOWN_TOKENS_SLUGS.SIRS || outputAssetSlug === KNOWN_TOKENS_SLUGS.SIRS; const isSwapAmountMoreThreshold = inputAmountInUsd.isGreaterThanOrEqualTo(SWAP_THRESHOLD_TO_GET_CASHBACK); - const totalMaxDexes = isSirsSwap ? SINGLE_SIRS_SWAP_MAX_DEXES : SINGLE_SWAP_IN_BATCH_MAX_DEXES; - const cashbackSwapMaxDexes = Math.ceil(totalMaxDexes / (isSirsSwap ? 3 : 2)); - const mainSwapMaxDexes = - totalMaxDexes - (isSwapAmountMoreThreshold && !isInputTokenTempleToken ? cashbackSwapMaxDexes : 0); + const mainSwapMaxDexes = isSirsSwap(inputAsset, newOutputValue.asset) + ? MAIN_SIRS_SWAP_MAX_DEXES + : MAIN_NON_SIRS_SWAP_MAX_DEXES; return { isInputTokenTempleToken, isOutputTokenTempleToken, isSwapAmountMoreThreshold, - mainSwapMaxDexes, - cashbackSwapMaxDexes + mainSwapMaxDexes }; }, [usdExchangeRates] @@ -177,8 +175,10 @@ export const SwapForm: FC = ({ inputToken, outputToken }) => { swapParams.data ); - const { isInputTokenTempleToken, isOutputTokenTempleToken, isSwapAmountMoreThreshold, cashbackSwapMaxDexes } = - getSwapWithFeeParams(inputAssets, outputAssets); + const { isInputTokenTempleToken, isOutputTokenTempleToken, isSwapAmountMoreThreshold } = getSwapWithFeeParams( + inputAssets, + outputAssets + ); if (isInputTokenTempleToken && isSwapAmountMoreThreshold) { const routingInputFeeOpParams = await getRoutingFeeTransferParams( @@ -204,7 +204,7 @@ export const SwapForm: FC = ({ inputToken, outputToken }) => { toSymbol: TEMPLE_TOKEN.symbol, toTokenDecimals: TEMPLE_TOKEN.decimals, amount: mutezToTz(routingFeeFromInputAtomic, fromRoute3Token.decimals).toFixed(), - dexesLimit: cashbackSwapMaxDexes, + dexesLimit: CASHBACK_SWAP_MAX_DEXES, rpcUrl: tezos.rpc.getRpcUrl() }); @@ -244,7 +244,7 @@ export const SwapForm: FC = ({ inputToken, outputToken }) => { toSymbol: TEMPLE_TOKEN.symbol, toTokenDecimals: TEMPLE_TOKEN.decimals, amount: mutezToTz(routingFeeFromOutputAtomic, toRoute3Token.decimals).toFixed(), - dexesLimit: cashbackSwapMaxDexes, + dexesLimit: CASHBACK_SWAP_MAX_DEXES, rpcUrl: tezos.rpc.getRpcUrl() }); diff --git a/src/utils/route3.util.ts b/src/utils/route3.util.ts index af8eb0415..9c1e4064d 100644 --- a/src/utils/route3.util.ts +++ b/src/utils/route3.util.ts @@ -143,6 +143,12 @@ export const fetchRoute3LiquidityBakingParams = ( } }); +export const isSirsSwap = (from: string | Pick, to: string | Pick) => { + return [from, to] + .map(symbolOrToken => (typeof symbolOrToken === 'string' ? symbolOrToken : symbolOrToken.symbol)) + .includes(THREE_ROUTE_SIRS_TOKEN.symbol); +}; + export const fetchRoute3SwapParams = ({ fromSymbol, toSymbol, @@ -153,7 +159,7 @@ export const fetchRoute3SwapParams = ({ const isLbUnderlyingTokenSwap = intersection([fromSymbol, toSymbol], [THREE_ROUTE_TZBTC_TOKEN.symbol, THREE_ROUTE_XTZ_TOKEN.symbol]).length > 0; - return [fromSymbol, toSymbol].includes(THREE_ROUTE_SIRS_TOKEN.symbol) + return isSirsSwap(fromSymbol, toSymbol) ? fetchRoute3LiquidityBakingParams({ fromSymbol, toSymbol, @@ -187,7 +193,7 @@ export const mapToRoute3ExecuteHops = (hops: Route3Hop[]): MichelsonMap { if (token.symbol === TEZ_TOKEN_METADATA.symbol) { - return 'xtz'; + return 'XTZ'; } return token.symbol; From ab8138fe75de6bb23533f061c1320c5952e36a29 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 23 Dec 2024 18:05:48 +0200 Subject: [PATCH 2/2] Bump version to 1.36 --- .github/workflows/apk-build.yml | 2 +- .github/workflows/testapp-build.yml | 2 +- android/app/build.gradle | 2 +- ios/TempleWallet/Debug-Info.plist | 2 +- ios/TempleWallet/Info.plist | 2 +- ios/TempleWalletTests/Info.plist | 2 +- package.json | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/apk-build.yml b/.github/workflows/apk-build.yml index 7b290220a..84c0ae26e 100644 --- a/.github/workflows/apk-build.yml +++ b/.github/workflows/apk-build.yml @@ -7,7 +7,7 @@ on: inputs: version: description: Version - default: "1.35" + default: "1.36" required: true build-number: description: Build number diff --git a/.github/workflows/testapp-build.yml b/.github/workflows/testapp-build.yml index 4077376bf..678221927 100644 --- a/.github/workflows/testapp-build.yml +++ b/.github/workflows/testapp-build.yml @@ -7,7 +7,7 @@ on: inputs: version: description: Version - default: "1.35" + default: "1.36" required: true build-number: description: Build number diff --git a/android/app/build.gradle b/android/app/build.gradle index 3bcaa7b35..21cb66945 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -89,7 +89,7 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1027 - versionName "1.35" + versionName "1.36" missingDimensionStrategy 'react-native-camera', 'general' } diff --git a/ios/TempleWallet/Debug-Info.plist b/ios/TempleWallet/Debug-Info.plist index 387da7b21..c6510b82f 100644 --- a/ios/TempleWallet/Debug-Info.plist +++ b/ios/TempleWallet/Debug-Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.35 + 1.36 CFBundleSignature ???? CFBundleURLTypes diff --git a/ios/TempleWallet/Info.plist b/ios/TempleWallet/Info.plist index fadc8dd70..0c514c139 100644 --- a/ios/TempleWallet/Info.plist +++ b/ios/TempleWallet/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.35 + 1.36 CFBundleSignature ???? CFBundleURLTypes diff --git a/ios/TempleWalletTests/Info.plist b/ios/TempleWalletTests/Info.plist index 08160cf93..0c13a15ed 100644 --- a/ios/TempleWalletTests/Info.plist +++ b/ios/TempleWalletTests/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.35 + 1.36 CFBundleSignature ???? CFBundleVersion diff --git a/package.json b/package.json index d604136ee..90c920df9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "temple-wallet", - "version": "1.35", + "version": "1.36", "private": true, "scripts": { "postinstall": "rn-nodeify --install 'react-native-randombytes' --hack && bash postinstall.sh",