@@ -10,14 +10,13 @@ import { useToastController } from "@tamagui/toast";
1010import { ScrollView , Separator , Spinner , XStack , YStack } from "tamagui" ;
1111
1212import { nonEmpty , pipe , safeParse , string } from "valibot" ;
13- import { ContractFunctionExecutionError , encodeAbiParameters } from "viem" ;
14- import { useBytecode , useWriteContract } from "wagmi" ;
13+ import { ContractFunctionExecutionError } from "viem" ;
14+ import { useWriteContract } from "wagmi" ;
1515
1616import { exaPreviewerAddress , marketUSDCAddress , previewerAddress } from "@exactly/common/generated/chain" ;
1717import {
1818 useReadExaPreviewerPendingProposals ,
1919 useReadPreviewerPreviewBorrowAtMaturity ,
20- useSimulateExaPluginPropose ,
2120} from "@exactly/common/generated/hooks" ;
2221import ProposalType from "@exactly/common/ProposalType" ;
2322import { MATURITY_INTERVAL , WAD } from "@exactly/lib" ;
@@ -28,6 +27,7 @@ import View from "../../components/shared/View";
2827import reportError from "../../utils/reportError" ;
2928import useAccount from "../../utils/useAccount" ;
3029import useAsset from "../../utils/useAsset" ;
30+ import useSimulateProposal from "../../utils/useSimulateProposal" ;
3131import Button from "../shared/Button" ;
3232import Skeleton from "../shared/Skeleton" ;
3333
@@ -51,12 +51,10 @@ export default function Pay() {
5151 const borrow = exaUSDC ?. fixedBorrowPositions . find ( ( b ) => b . maturity === BigInt ( success ? repayMaturity : 0 ) ) ;
5252 const rolloverMaturityBorrow = exaUSDC ?. fixedBorrowPositions . find ( ( b ) => b . maturity === BigInt ( borrowMaturity ) ) ;
5353
54- const { data : bytecode } = useBytecode ( { address, query : { enabled : ! ! address } } ) ;
55-
5654 const { data : borrowPreview } = useReadPreviewerPreviewBorrowAtMaturity ( {
5755 address : previewerAddress ,
5856 args : [ marketUSDCAddress , BigInt ( borrowMaturity ) , borrow ?. previewValue ?? 0n ] ,
59- query : { enabled : ! ! bytecode && ! ! exaUSDC && ! ! borrow && ! ! address && ! ! borrowMaturity } ,
57+ query : { enabled : ! ! exaUSDC && ! ! borrow && ! ! address && ! ! borrowMaturity } ,
6058 } ) ;
6159
6260 if ( ! success || ! exaUSDC || ! borrow ) return null ;
@@ -228,35 +226,22 @@ function RolloverButton({
228226 const { t } = useTranslation ( ) ;
229227 const { address } = useAccount ( ) ;
230228 const router = useRouter ( ) ;
231- const { data : bytecode } = useBytecode ( { address, query : { enabled : ! ! address } } ) ;
232229 const toast = useToastController ( ) ;
233230
234231 const slippage = ( WAD * 105n ) / 100n ;
235232 const maxRepayAssets = ( borrow . previewValue * slippage ) / WAD ;
236233 const percentage = WAD ;
237234
238- const { data : proposeSimulation } = useSimulateExaPluginPropose ( {
239- address,
240- args : [
241- marketUSDCAddress ,
242- maxRepayAssets ,
243- ProposalType . RollDebt ,
244- encodeAbiParameters (
245- [
246- {
247- type : "tuple" ,
248- components : [
249- { name : "repayMaturity" , type : "uint256" } ,
250- { name : "borrowMaturity" , type : "uint256" } ,
251- { name : "maxRepayAssets" , type : "uint256" } ,
252- { name : "percentage" , type : "uint256" } ,
253- ] ,
254- } ,
255- ] ,
256- [ { repayMaturity, borrowMaturity, maxRepayAssets, percentage } ] ,
257- ) ,
258- ] ,
259- query : { enabled : ! ! address && ! ! bytecode } ,
235+ const { request : proposeSimulation , error : executeProposalError } = useSimulateProposal ( {
236+ account : address ,
237+ amount : maxRepayAssets ,
238+ market : marketUSDCAddress ,
239+ proposalType : ProposalType . RollDebt ,
240+ borrowMaturity,
241+ maxRepayAssets,
242+ percentage,
243+ repayMaturity,
244+ enabled : ! ! address ,
260245 } ) ;
261246
262247 const {
@@ -266,7 +251,7 @@ function RolloverButton({
266251 } = useReadExaPreviewerPendingProposals ( {
267252 address : exaPreviewerAddress ,
268253 args : address ? [ address ] : undefined ,
269- query : { enabled : ! ! address && ! ! bytecode , gcTime : 0 , refetchInterval : 30_000 } ,
254+ query : { enabled : ! ! address , gcTime : 0 , refetchInterval : 30_000 } ,
270255 } ) ;
271256
272257 const {
@@ -281,7 +266,7 @@ function RolloverButton({
281266 duration : 1000 ,
282267 burntOptions : { haptic : "success" , preset : "done" } ,
283268 } ) ;
284- if ( address && bytecode ) refetchPendingProposals ( ) . catch ( reportError ) ;
269+ if ( address ) refetchPendingProposals ( ) . catch ( reportError ) ;
285270 router . dismissTo ( "/activity" ) ;
286271 } ,
287272 onError : ( error ) => {
@@ -298,7 +283,7 @@ function RolloverButton({
298283 const proposeRollDebt = useCallback ( ( ) => {
299284 if ( ! address ) throw new Error ( "no address" ) ;
300285 if ( ! proposeSimulation ) throw new Error ( "no propose roll debt simulation" ) ;
301- mutate ( proposeSimulation . request ) ;
286+ mutate ( proposeSimulation ) ;
302287 } , [ address , proposeSimulation , mutate ] ) ;
303288
304289 const hasProposed = pendingProposals ?. some (
@@ -316,7 +301,12 @@ function RolloverButton({
316301 ) ;
317302
318303 const disabled =
319- ! ! isError || isProposeRollDebtPending || isPendingProposalsPending || ! proposeSimulation || hasProposed ;
304+ ! ! isError ||
305+ ! ! executeProposalError ||
306+ isProposeRollDebtPending ||
307+ isPendingProposalsPending ||
308+ ! proposeSimulation ||
309+ hasProposed ;
320310 return (
321311 < Button
322312 onPress = { proposeRollDebt }
0 commit comments