Skip to content

Commit

Permalink
Merge branch 'develop' into fix_fiat_ramps_perf
Browse files Browse the repository at this point in the history
  • Loading branch information
NeOMakinG authored Aug 23, 2024
2 parents dbbe985 + c418be7 commit fed4411
Show file tree
Hide file tree
Showing 26 changed files with 196 additions and 240 deletions.
45 changes: 24 additions & 21 deletions src/components/FeeModal/FeeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalOverlay,
Expand Down Expand Up @@ -34,27 +35,29 @@ export const FeeModal = ({
<Modal isOpen={isOpen} onClose={handleClose} size='lg'>
<ModalOverlay />
<ModalContent>
<ModalCloseButton />
<Tabs variant='button'>
<TabList px={6} py={4} borderBottomWidth={1} borderColor='border.base'>
<Tab color='text.subtle'>{translate('foxDiscounts.feeSummary')}</Tab>
<Tab color='text.subtle'>{translate('foxDiscounts.simulateFee')}</Tab>
</TabList>
<TabPanels>
<TabPanel p={0}>
<FeeBreakdown feeModel={feeModel} inputAmountUsd={inputAmountUsd} />
</TabPanel>
<TabPanel px={0} py={0}>
<FeeExplainer
inputAmountUsd={inputAmountUsd}
borderRadius='none'
bg='transparent'
boxShadow='none'
feeModel={feeModel}
/>
</TabPanel>
</TabPanels>
</Tabs>
<ModalCloseButton zIndex='1' />
<ModalBody p={0}>
<Tabs variant='button'>
<TabList px={6} py={4} borderBottomWidth={1} borderColor='border.base'>
<Tab color='text.subtle'>{translate('foxDiscounts.feeSummary')}</Tab>
<Tab color='text.subtle'>{translate('foxDiscounts.simulateFee')}</Tab>
</TabList>
<TabPanels>
<TabPanel p={0}>
<FeeBreakdown feeModel={feeModel} inputAmountUsd={inputAmountUsd} />
</TabPanel>
<TabPanel px={0} py={0}>
<FeeExplainer
inputAmountUsd={inputAmountUsd}
borderRadius='none'
bg='transparent'
boxShadow='none'
feeModel={feeModel}
/>
</TabPanel>
</TabPanels>
</Tabs>
</ModalBody>
</ModalContent>
</Modal>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ export const approveTrade = async ({
tradeQuoteStep,
wallet,
allowanceType,
from,
}: {
tradeQuoteStep: TradeQuote['steps'][number]
wallet: HDWallet
from: string
allowanceType: AllowanceType
}): Promise<string> => {
const txHash = await approve({
assetId: tradeQuoteStep.sellAsset.assetId,
accountNumber: tradeQuoteStep.accountNumber,
from,
amountCryptoBaseUnit: getApprovalAmountCryptoBaseUnit(
tradeQuoteStep.sellAmountIncludingProtocolFeesCryptoBaseUnit,
allowanceType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const useAllowanceApproval = (
const isReset = useMemo(() => allowanceType === AllowanceType.Reset, [allowanceType])

const { allowanceCryptoBaseUnitResult, evmFeesResult, isApprovalRequired } = useApprovalFees({
accountNumber: tradeQuoteStep.accountNumber,
amountCryptoBaseUnit: tradeQuoteStep.sellAmountIncludingProtocolFeesCryptoBaseUnit,
assetId: tradeQuoteStep.sellAsset.assetId,
from: sellAssetAccountId ? fromAccountId(sellAssetAccountId).account : undefined,
Expand All @@ -63,6 +62,7 @@ export const useAllowanceApproval = (
),
assetId: tradeQuoteStep.sellAsset.assetId,
spender: tradeQuoteStep.allowanceContract,
from: sellAssetAccountId ? fromAccountId(sellAssetAccountId).account : undefined,
wallet,
}),
onMutate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ export const useArbitrumClaimTx = (
})

const evmFeesResult = useEvmFees({
accountNumber: bip44Params?.accountNumber,
pubKey: destinationAccountId ? fromAccountId(destinationAccountId).account : undefined,
from: destinationAccountId ? fromAccountId(destinationAccountId).account : undefined,
chainId: claim.destinationChainId,
data: executeTransactionDataResult.data,
refetchInterval: 15_000,
Expand All @@ -84,11 +83,13 @@ export const useArbitrumClaimTx = (
if (!wallet) return
if (!bip44Params) return
if (!executeTransactionDataResult.data) return
if (!destinationAccountId) return

const adapter = assertGetEvmChainAdapter(claim.destinationChainId)

const buildCustomTxInput = await createBuildCustomTxInput({
accountNumber: bip44Params.accountNumber,
from: fromAccountId(destinationAccountId).account,
adapter,
data: executeTransactionDataResult.data,
to: ARBITRUM_OUTBOX,
Expand Down
70 changes: 37 additions & 33 deletions src/features/defi/providers/fox-farming/hooks/useFoxFarming.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ethAssetId, fromAccountId, fromAssetId } from '@shapeshiftoss/caip'
import { CONTRACT_INTERACTION } from '@shapeshiftoss/chain-adapters'
import { supportsETH } from '@shapeshiftoss/hdwallet-core'
import { isLedger } from '@shapeshiftoss/hdwallet-ledger'
import { getFees } from '@shapeshiftoss/utils/dist/evm'
import { ETH_FOX_POOL_CONTRACT_ADDRESS } from 'contracts/constants'
import { getOrCreateContractByAddress } from 'contracts/contractManager'
Expand All @@ -15,7 +14,7 @@ import {
assertGetEvmChainAdapter,
buildAndBroadcast,
createBuildCustomTxInput,
getFeesWithWallet,
getFeesWithWalletEIP1559Support,
} from 'lib/utils/evm'
import type { FoxEthStakingContractAddress } from 'state/slices/opportunitiesSlice/constants'
import { foxEthLpAssetId } from 'state/slices/opportunitiesSlice/constants'
Expand Down Expand Up @@ -57,10 +56,15 @@ export const useFoxFarming = (
[contractAddress],
)

const userAddress = useMemo(
() => (farmingAccountId ? getAddress(fromAccountId(farmingAccountId).account) : undefined),
[farmingAccountId],
)

const stake = useCallback(
async (lpAmount: string) => {
try {
if (skip || !isValidAccountNumber(accountNumber) || !wallet) return
if (skip || !isValidAccountNumber(accountNumber) || !wallet || !userAddress) return

const data = encodeFunctionData({
abi: foxFarmingContract.abi,
Expand All @@ -70,6 +74,7 @@ export const useFoxFarming = (

const buildCustomTxInput = await createBuildCustomTxInput({
accountNumber,
from: userAddress,
adapter,
data,
to: contractAddress,
Expand All @@ -92,17 +97,18 @@ export const useFoxFarming = (
skip,
accountNumber,
wallet,
adapter,
userAddress,
foxFarmingContract.abi,
lpAsset.precision,
adapter,
contractAddress,
],
)

const unstake = useCallback(
async (lpAmount: string, isExiting: boolean) => {
try {
if (skip || !isValidAccountNumber(accountNumber) || !wallet) return
if (skip || !isValidAccountNumber(accountNumber) || !wallet || !userAddress) return

const data = encodeFunctionData({
abi: foxFarmingContract.abi,
Expand All @@ -112,6 +118,7 @@ export const useFoxFarming = (

const buildCustomTxInput = await createBuildCustomTxInput({
accountNumber,
from: userAddress,
adapter,
data,
to: contractAddress,
Expand All @@ -130,17 +137,16 @@ export const useFoxFarming = (
console.error(err)
}
},
[adapter, accountNumber, contractAddress, foxFarmingContract, lpAsset.precision, wallet, skip],
)

const userAddress = useMemo(
() => (farmingAccountId ? getAddress(fromAccountId(farmingAccountId).account) : undefined),
[farmingAccountId],
)

const pubKey = useMemo(
() => (wallet && isLedger(wallet) && userAddress ? userAddress : undefined),
[userAddress, wallet],
[
skip,
accountNumber,
wallet,
userAddress,
foxFarmingContract.abi,
lpAsset.precision,
adapter,
contractAddress,
],
)

const allowance = useCallback(async () => {
Expand All @@ -152,41 +158,39 @@ export const useFoxFarming = (
}, [skip, userAddress, contractAddress])

const getApproveFees = useCallback(() => {
if (!isValidAccountNumber(accountNumber) || !wallet) return
if (!isValidAccountNumber(accountNumber) || !wallet || !userAddress) return

const data = encodeFunctionData({
abi: uniV2LPContract.abi,
functionName: 'approve',
args: [contractAddress, maxUint256],
})

return getFeesWithWallet({
accountNumber,
return getFeesWithWalletEIP1559Support({
adapter,
data,
to: uniV2LPContract.address,
pubKey,
from: userAddress,
value: '0',
wallet,
})
}, [accountNumber, wallet, contractAddress, adapter, pubKey])
}, [accountNumber, wallet, userAddress, contractAddress, adapter])

const getStakeFees = useCallback(
(lpAmount: string) => {
if (skip || !isValidAccountNumber(accountNumber) || !wallet) return
if (skip || !isValidAccountNumber(accountNumber) || !wallet || !userAddress) return

const data = encodeFunctionData({
abi: foxFarmingContract.abi,
functionName: 'stake',
args: [BigInt(toBaseUnit(lpAmount, lpAsset.precision))],
})

return getFeesWithWallet({
accountNumber,
return getFeesWithWalletEIP1559Support({
adapter,
data,
to: contractAddress,
pubKey,
from: userAddress,
value: '0',
wallet,
})
Expand All @@ -195,30 +199,29 @@ export const useFoxFarming = (
skip,
accountNumber,
wallet,
userAddress,
foxFarmingContract.abi,
lpAsset.precision,
adapter,
contractAddress,
pubKey,
],
)

const getUnstakeFees = useCallback(
(lpAmount: string, isExiting: boolean) => {
if (skip || !isValidAccountNumber(accountNumber) || !wallet) return
if (skip || !isValidAccountNumber(accountNumber) || !wallet || !userAddress) return

const data = encodeFunctionData({
abi: foxFarmingContract.abi,
functionName: isExiting ? 'exit' : 'withdraw',
...(isExiting ? {} : { args: [BigInt(toBaseUnit(lpAmount, lpAsset.precision))] }),
})

return getFeesWithWallet({
accountNumber,
return getFeesWithWalletEIP1559Support({
adapter,
data,
to: contractAddress,
pubKey,
from: userAddress,
value: '0',
wallet,
})
Expand All @@ -231,7 +234,7 @@ export const useFoxFarming = (
lpAsset.precision,
adapter,
contractAddress,
pubKey,
userAddress,
],
)

Expand Down Expand Up @@ -285,7 +288,7 @@ export const useFoxFarming = (
}, [accountNumber, adapter, contractAddress, getApproveFees, wallet])

const claimRewards = useCallback(async () => {
if (skip || !isValidAccountNumber(accountNumber) || !wallet) return
if (skip || !isValidAccountNumber(accountNumber) || !wallet || !userAddress) return

const data = encodeFunctionData({
abi: foxFarmingContract.abi,
Expand All @@ -294,6 +297,7 @@ export const useFoxFarming = (

const buildCustomTxInput = await createBuildCustomTxInput({
accountNumber,
from: userAddress,
adapter,
data,
to: contractAddress,
Expand All @@ -308,7 +312,7 @@ export const useFoxFarming = (
})

return txid
}, [accountNumber, adapter, contractAddress, foxFarmingContract, skip, wallet])
}, [accountNumber, adapter, contractAddress, foxFarmingContract.abi, skip, userAddress, wallet])

return {
allowance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const Approve: React.FC<ApproveProps> = ({ accountId, onNext }) => {
const adapter = assertGetEvmChainAdapter(chainId)
const buildCustomTxInput = await createBuildCustomTxInput({
accountNumber,
from: fromAccountId(accountId).account,
adapter,
data,
value: '0',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Skeleton, useToast } from '@chakra-ui/react'
import type { AccountId } from '@shapeshiftoss/caip'
import { fromAccountId, fromAssetId, thorchainAssetId, toAssetId } from '@shapeshiftoss/caip'
import { isLedger } from '@shapeshiftoss/hdwallet-ledger'
import type { Asset } from '@shapeshiftoss/types'
import { useQueryClient } from '@tanstack/react-query'
import { getOrCreateContractByType } from 'contracts/contractManager'
Expand Down Expand Up @@ -32,7 +31,11 @@ import { fromBaseUnit, toBaseUnit } from 'lib/math'
import { trackOpportunityEvent } from 'lib/mixpanel/helpers'
import { MixPanelEvent } from 'lib/mixpanel/types'
import { isToken } from 'lib/utils'
import { assertGetEvmChainAdapter, getErc20Allowance, getFeesWithWallet } from 'lib/utils/evm'
import {
assertGetEvmChainAdapter,
getErc20Allowance,
getFeesWithWalletEIP1559Support,
} from 'lib/utils/evm'
import { fetchHasEnoughBalanceForTxPlusFeesPlusSweep } from 'lib/utils/thorchain/balance'
import { BASE_BPS_POINTS, RUNEPOOL_DEPOSIT_MEMO } from 'lib/utils/thorchain/constants'
import { useGetThorchainSaversDepositQuoteQuery } from 'lib/utils/thorchain/hooks/useGetThorchainSaversDepositQuoteQuery'
Expand Down Expand Up @@ -296,11 +299,6 @@ export const Deposit: React.FC<DepositProps> = ({
const { data: isSweepNeeded, isLoading: isSweepNeededLoading } =
useIsSweepNeededQuery(isSweepNeededArgs)

const pubKey = useMemo(
() => (wallet && isLedger(wallet) && userAddress ? userAddress : undefined),
[userAddress, wallet],
)

const handleContinue = useCallback(
async (formValues: DepositValues) => {
if (!feeAsset) return
Expand Down Expand Up @@ -348,12 +346,11 @@ export const Deposit: React.FC<DepositProps> = ({

const adapter = assertGetEvmChainAdapter(chainId)

return getFeesWithWallet({
accountNumber,
return getFeesWithWalletEIP1559Support({
adapter,
data,
to: fromAssetId(assetId).assetReference,
pubKey,
from: userAddress,
value: '0',
wallet,
})
Expand Down Expand Up @@ -413,7 +410,6 @@ export const Deposit: React.FC<DepositProps> = ({
wallet,
asset.chainId,
chainId,
pubKey,
toast,
translate,
],
Expand Down
Loading

0 comments on commit fed4411

Please sign in to comment.