@@ -42,6 +42,8 @@ export const useRepay = ({
4242 const { addStepsForType, upsertStepForType } = useManageDialogContext ( ) ;
4343 const { transactionSteps } = useTransactionSteps ( ) ;
4444
45+ const INTEREST_BUFFER_MULTIPLIER = 1.01 ;
46+
4547 const amountAsBInt = useMemo (
4648 ( ) =>
4749 parseUnits (
@@ -51,6 +53,17 @@ export const useRepay = ({
5153 [ amount , selectedMarketData . underlyingDecimals ]
5254 ) ;
5355
56+ const amountWithBufferAsBInt = useMemo ( ( ) => {
57+ const amountAsNumber = Number ( amount ) ;
58+ if ( isNaN ( amountAsNumber ) || amountAsNumber === 0 ) return 0n ;
59+
60+ const amountWithBuffer = amountAsNumber * INTEREST_BUFFER_MULTIPLIER ;
61+ return parseUnits (
62+ amountWithBuffer . toString ( ) ,
63+ selectedMarketData . underlyingDecimals
64+ ) ;
65+ } , [ amount , selectedMarketData . underlyingDecimals ] ) ;
66+
5467 const handleUtilization = useCallback (
5568 ( newUtilizationPercentage : number ) => {
5669 const maxAmountNumber = Number (
@@ -124,11 +137,12 @@ export const useRepay = ({
124137 selectedMarketData . cToken
125138 ] ) ;
126139
127- if ( currentAllowance < amountAsBInt ) {
140+ // Use buffered amount for allowance check and approval
141+ if ( currentAllowance < amountWithBufferAsBInt ) {
128142 const approveTx = await currentSdk . approve (
129143 selectedMarketData . cToken ,
130144 selectedMarketData . underlyingToken ,
131- amountAsBInt
145+ amountWithBufferAsBInt // Using buffered amount for approval
132146 ) ;
133147
134148 upsertStepForType ( TransactionType . REPAY , {
@@ -156,12 +170,12 @@ export const useRepay = ({
156170 amountAsBInt >= ( selectedMarketData . borrowBalance ?? 0n ) ;
157171 const repayAmount = isRepayingMax ? maxUint256 : amountAsBInt ;
158172
159- // Verify final allowance
173+ // Verify final allowance against buffered amount
160174 const finalAllowance = await token . read . allowance ( [
161175 address ,
162176 selectedMarketData . cToken
163177 ] ) ;
164- if ( finalAllowance < amountAsBInt ) {
178+ if ( finalAllowance < amountWithBufferAsBInt ) {
165179 throw new Error ( 'Insufficient allowance after approval' ) ;
166180 }
167181
@@ -244,6 +258,7 @@ export const useRepay = ({
244258 address ,
245259 amount ,
246260 amountAsBInt ,
261+ amountWithBufferAsBInt ,
247262 currentBorrowAmountAsFloat ,
248263 selectedMarketData ,
249264 addStepsForType ,
0 commit comments