Skip to content

Commit

Permalink
Disallow permits for deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
yivlad committed Jun 13, 2024
1 parent 017daf9 commit 86e4064
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function useCreateApproveOrPermitHandler(
const chainId = useOriginChainId()
const supportsPermit = isPermitSupported(chainId, action.token)

const shouldUsePermit = permitStore !== undefined && !!supportsPermit
const shouldUsePermit = permitStore !== undefined && !!supportsPermit && !action.disallowPermit
const approveEnabled = enabled && !shouldUsePermit
const permitEnabled = enabled && shouldUsePermit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export interface ApproveAction {
token: Token
spender: Address
value: NormalizedUnitNumber
disallowPermit?: boolean // if true, permit is not allowed
requiredValue?: NormalizedUnitNumber // if reached, no action is needed. Useful when value is approximation (and constantly accrues debt)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useVaultDeposit } from '@/domain/tokenized-vault-operations/useVaultDeposit'

import { useSwapAndDeposit } from '@/domain/psm-actions/useSwapAndDeposit'
import { TokenSymbol } from '@/domain/types/TokenSymbol'
import { ActionHandler } from '../../logic/types'
import { mapWriteResultToActionState } from '../../logic/utils'
import { NativeSDaiDepositAction } from './types'
Expand All @@ -15,7 +16,7 @@ export function useCreateNativeSDaiDepositHandler(
options: UseCreateNativeSDaiDepositHandlerOptions,
): ActionHandler {
const { enabled, onFinish } = options
const isUSDCDeposit = action.token.symbol === 'USDC'
const isUSDCDeposit = action.token.symbol === TokenSymbol('USDC')

const daiDeposit = useVaultDeposit({
vault: action.sDai.address,
Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/features/actions/logic/useCreateActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useContractAddress } from '@/domain/hooks/useContractAddress'
import { useOriginChainId } from '@/domain/hooks/useOriginChainId'
import { BaseUnitNumber, NormalizedUnitNumber } from '@/domain/types/NumericValues'

import { TokenSymbol } from '@/domain/types/TokenSymbol'
import { mainnet } from 'viem/chains'
import { ApproveDelegationAction } from '../flavours/approve-delegation/types'
import { ApproveExchangeAction } from '../flavours/approve-exchange/types'
Expand Down Expand Up @@ -169,13 +170,14 @@ export function useCreateActions(objectives: Objective[]): Action[] {

case 'nativeSDaiDeposit': {
const spender =
objective.token.symbol === 'USDC' ? psmActionsConfig.address[mainnet.id] : objective.sDai.address
objective.token.symbol === TokenSymbol('USDC') ? psmActionsConfig.address[mainnet.id] : objective.sDai.address

const approveAction: ApproveAction = {
type: 'approve',
token: objective.token,
spender,
value: objective.value,
disallowPermit: true,
}

const depositAction: NativeSDaiDepositAction = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function MakerTransactionOverview({ txOverview, selectedToken }: MakerTra

assert(route.length > 0, 'Route must have at least one item')
const outcome = route.at(-1)!
const verticalRouteDisplay = Boolean(route.length > 2 && route[0]?.value?.gte(NormalizedUnitNumber(1_000_000)))
const displayRouteVertically = Boolean(route.length > 2 && route[0]?.value?.gte(NormalizedUnitNumber(1_000_000)))

return (
<DialogPanel>
Expand All @@ -33,14 +33,14 @@ export function MakerTransactionOverview({ txOverview, selectedToken }: MakerTra
<APYDetails APY={APY} daiEarnRate={daiEarnRate} />
</TransactionOverviewDetailsItem>
<TransactionOverviewDetailsItem label="Route">
<div className={cn('flex flex-col items-end gap-2', !verticalRouteDisplay && 'md:flex-row')}>
<div className={cn('flex flex-col items-end gap-2', !displayRouteVertically && 'md:flex-row')}>
{route.map((item, index) => (
<RouteItem
key={item.token.symbol}
item={item}
index={index}
isLast={index === route.length - 1}
verticalRouteDisplay={verticalRouteDisplay}
displayRouteVertically={displayRouteVertically}
/>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ export interface RouteItemProps {
item: RouteItemType
index: number
isLast: boolean
verticalRouteDisplay: boolean
displayRouteVertically: boolean
}
export function RouteItem({ item, index, isLast, verticalRouteDisplay }: RouteItemProps) {
export function RouteItem({ item, index, isLast, displayRouteVertically }: RouteItemProps) {
return (
<div
className={cn(
'grid grid-cols-1 items-center gap-x-2 gap-y-0.5',
!isLast && !verticalRouteDisplay && 'md:grid-cols-[auto_auto]',
!isLast && !displayRouteVertically && 'md:grid-cols-[auto_auto]',
)}
>
<div data-testid={testIds.dialog.savings.nativeRouteTransactionOverview.routeItem.tokenWithAmount(index)}>
{item.token.format(item.value, { style: 'auto' })} {item.token.symbol}
</div>
<div
className={cn('justify-self-end text-basics-dark-grey text-sm', !verticalRouteDisplay && 'md:order-last')}
className={cn('justify-self-end text-basics-dark-grey text-sm', !displayRouteVertically && 'md:order-last')}
data-testid={testIds.dialog.savings.nativeRouteTransactionOverview.routeItem.tokenUsdValue(index)}
>
{USD_MOCK_TOKEN.formatUSD(item.usdValue)}
Expand All @@ -32,7 +32,7 @@ export function RouteItem({ item, index, isLast, verticalRouteDisplay }: RouteIt
src={assets.arrowRight}
className={cn(
'mt-1.5 h-3.5 w-3.5 rotate-90 justify-self-end',
!verticalRouteDisplay && 'md:mt-0 md:rotate-0',
!displayRouteVertically && 'md:mt-0 md:rotate-0',
)}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function createMakerTxOverview({
APY: savingsInfo.apy,
daiEarnRate,
route,
makerBadgeToken: marketInfo.DAI,
makerBadgeToken: formValues.token,
outTokenAmount: sDAIValue,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AssetInputSchema, useDebouncedDialogFormValues } from '@/features/dialo
import { FormFieldsForDialog, PageState, PageStatus } from '@/features/dialogs/common/types'

import { useOriginChainId } from '@/domain/hooks/useOriginChainId'
import { TokenSymbol } from '@/domain/types/TokenSymbol'
import { mainnet } from 'viem/chains'
import { SavingsDialogTxOverview } from '../../common/types'
import { createMakerTxOverview, createTxOverview } from './createTxOverview'
Expand Down Expand Up @@ -78,7 +79,7 @@ export function useSavingsDepositDialog({
const useNativeRoutes =
originChainId === mainnet.id &&
((import.meta.env.VITE_DEV_DAI_NATIVE_ROUTES === '1' && formValues.token.address === marketInfo.DAI.address) ||
(import.meta.env.VITE_DEV_USDC_NATIVE_ROUTES === '1' && formValues.token.symbol === 'USDC'))
(import.meta.env.VITE_DEV_USDC_NATIVE_ROUTES === '1' && formValues.token.symbol === TokenSymbol('USDC')))

const { swapInfo, swapParams } = useDepositIntoSavings({
formValues,
Expand Down

0 comments on commit 86e4064

Please sign in to comment.