@@ -3,6 +3,7 @@ import { adjustAmountByPercentage } from "@delvtech/hyperdrive-viem";
33import {
44 HyperdriveConfig ,
55 TokenConfig ,
6+ appConfig ,
67 findBaseToken ,
78 findToken ,
89} from "@hyperdrive/appconfig" ;
@@ -67,10 +68,6 @@ export function AddLiquidityForm2({
6768 tokenAddress : hyperdrive . poolConfig . vaultSharesToken ,
6869 } ) ;
6970
70- const { vaultRate, vaultRateStatus } = useYieldSourceRate ( {
71- hyperdriveAddress : hyperdrive . address ,
72- chainId : hyperdrive . chainId ,
73- } ) ;
7471 const { balance : baseTokenBalance } = useTokenBalance ( {
7572 account,
7673 tokenAddress : baseToken . address ,
@@ -108,12 +105,6 @@ export function AddLiquidityForm2({
108105 } ) ;
109106 }
110107
111- const { lpShares : lpSharesBalanceOf } = useLpShares ( {
112- account,
113- chainId : hyperdrive . chainId ,
114- hyperdriveAddress : hyperdrive . address ,
115- } ) ;
116-
117108 const { activeToken, activeTokenBalance, setActiveToken, isActiveTokenEth } =
118109 useActiveToken ( {
119110 account,
@@ -171,11 +162,6 @@ export function AddLiquidityForm2({
171162 ) . bigint
172163 : poolInfo ?. lpSharePrice || 0n ;
173164
174- const { lpApy } = useLpApy ( {
175- chainId : hyperdrive . chainId ,
176- hyperdriveAddress : hyperdrive . address ,
177- } ) ;
178-
179165 const minLpSharePriceAfterSlippage = adjustAmountByPercentage ( {
180166 amount : lpSharePrice ,
181167 percentage : slippageAsBigInt ,
@@ -215,19 +201,7 @@ export function AddLiquidityForm2({
215201 status : addLiquidityPreviewStatus ,
216202 previewAddLiquidityError,
217203 } = usePreviewAddLiquidity ( addLiquidityParams ) ;
218- const isNewPool = useIsNewPool ( { hyperdrive } ) ;
219204
220- const { lpSharesTotalSupply } = useLpSharesTotalSupply ( {
221- chainId : hyperdrive . chainId ,
222- hyperdriveAddress : hyperdrive . address ,
223- } ) ;
224- const poolShare = calculatePoolShare ( {
225- lpSharesBalanceOf,
226- lpSharesOut,
227- lpSharesTotalSupply,
228- hyperdrive,
229- baseToken,
230- } ) ;
231205 const { fiatPrice : activeTokenPrice } = useTokenFiatPrice ( {
232206 tokenAddress : activeToken . address ,
233207 chainId : activeToken . chainId ,
@@ -314,77 +288,13 @@ export function AddLiquidityForm2({
314288 }
315289 primaryStats = {
316290 < div className = "flex flex-row justify-between px-4 py-8" >
317- < PrimaryStat
318- label = "You receive"
319- subValue = {
320- addLiquidityPreviewStatus === "loading" ? (
321- < Skeleton width = { 100 } />
322- ) : (
323- < span
324- className = { classNames ( {
325- "text-base-content/80" : ! poolShare ,
326- } ) }
327- >
328- { poolShare
329- ? `${ fixed ( poolShare ) . format ( {
330- decimals : 4 ,
331- rounding : "trunc" ,
332- } ) } % of total liquidity`
333- : undefined }
334- </ span >
335- )
336- }
337- valueUnit = { `${ baseToken . symbol } -LP` }
338- valueClassName = "flex items-end"
339- unitClassName = "text-xs"
340- value = {
341- addLiquidityPreviewStatus === "loading" ? (
342- < Skeleton width = { 100 } />
343- ) : (
344- < p
345- className = { classNames ( {
346- "text-base-content/80" : ! lpSharesOut ,
347- "font-bold" : lpSharesOut ,
348- } ) }
349- >
350- { lpSharesOut
351- ? `${ formatBalance ( {
352- balance : lpSharesOut ,
353- decimals : hyperdrive . decimals ,
354- places : baseToken . places ,
355- } ) } `
356- : "0" }
357- </ p >
358- )
359- }
291+ < YouReceiveStat
292+ addLiquidityPreviewStatus = { addLiquidityPreviewStatus }
293+ lpSharesOut = { lpSharesOut }
294+ hyperdrive = { hyperdrive }
360295 />
361296 < div className = "daisy-divider daisy-divider-horizontal mx-0" />
362- < PrimaryStat
363- label = "LP APY"
364- value = {
365- isNewPool || lpApy === undefined ? (
366- < div className = "flex gap-2" > ✨New✨</ div >
367- ) : (
368- `${ lpApy . formatted === "-0.00" ? "0.00" : lpApy . formatted } `
369- )
370- }
371- tooltipContent = "The annual percentage yield projection for providing liquidity."
372- tooltipPosition = "left"
373- valueClassName = { classNames ( "flex items-end" , {
374- "bg-gradient-to-r from-accent to-primary bg-clip-text text-transparent" :
375- ! isNewPool , // Don't use gradient text when displaying NEW, the emojis give enough emphasis.
376- } ) }
377- subValue = {
378- vaultRateStatus === "success" && vaultRate ? (
379- < div >
380- { appConfig . yieldSources [ hyperdrive . yieldSource ] . shortName } @{ " " }
381- { vaultRate . formatted || 0 } APY
382- </ div >
383- ) : (
384- < Skeleton className = "w-42 h-8" />
385- )
386- }
387- />
297+ < LpApyStat hyperdrive = { hyperdrive } />
388298 </ div >
389299 }
390300 disclaimer = { ( ( ) => {
@@ -470,6 +380,132 @@ export function AddLiquidityForm2({
470380 />
471381 ) ;
472382}
383+
384+ function YouReceiveStat ( {
385+ addLiquidityPreviewStatus,
386+ lpSharesOut,
387+ hyperdrive,
388+ } : {
389+ addLiquidityPreviewStatus : string ;
390+ lpSharesOut : bigint | undefined ;
391+ hyperdrive : HyperdriveConfig ;
392+ } ) {
393+ const { address : account } = useAccount ( ) ;
394+ const { lpShares : lpSharesBalanceOf } = useLpShares ( {
395+ account,
396+ chainId : hyperdrive . chainId ,
397+ hyperdriveAddress : hyperdrive . address ,
398+ } ) ;
399+ const baseToken = findBaseToken ( {
400+ hyperdriveChainId : hyperdrive . chainId ,
401+ hyperdriveAddress : hyperdrive . address ,
402+ appConfig,
403+ } ) ;
404+ const { lpSharesTotalSupply } = useLpSharesTotalSupply ( {
405+ chainId : hyperdrive . chainId ,
406+ hyperdriveAddress : hyperdrive . address ,
407+ } ) ;
408+ const poolShare = calculatePoolShare ( {
409+ lpSharesBalanceOf,
410+ lpSharesOut,
411+ lpSharesTotalSupply,
412+ hyperdrive,
413+ baseToken,
414+ } ) ;
415+ return (
416+ < PrimaryStat
417+ label = "You receive"
418+ subValue = {
419+ addLiquidityPreviewStatus === "loading" ? (
420+ < Skeleton width = { 100 } />
421+ ) : (
422+ < span
423+ className = { classNames ( {
424+ "text-base-content/80" : ! poolShare ,
425+ } ) }
426+ >
427+ { poolShare
428+ ? `${ fixed ( poolShare ) . format ( {
429+ decimals : 4 ,
430+ rounding : "trunc" ,
431+ } ) } % of total liquidity`
432+ : undefined }
433+ </ span >
434+ )
435+ }
436+ valueUnit = { `${ baseToken . symbol } -LP` }
437+ valueClassName = "flex items-end "
438+ unitClassName = "text-xs mb-1"
439+ value = {
440+ addLiquidityPreviewStatus === "loading" ? (
441+ < Skeleton width = { 100 } />
442+ ) : (
443+ < p
444+ className = { classNames ( {
445+ "text-base-content/80" : ! lpSharesOut ,
446+ "font-bold" : lpSharesOut ,
447+ } ) }
448+ >
449+ { lpSharesOut
450+ ? `${ formatBalance ( {
451+ balance : lpSharesOut ,
452+ decimals : hyperdrive . decimals ,
453+ places : baseToken . places ,
454+ } ) } `
455+ : "0" }
456+ </ p >
457+ )
458+ }
459+ />
460+ ) ;
461+ }
462+
463+ function LpApyStat ( { hyperdrive } : { hyperdrive : HyperdriveConfig } ) {
464+ const isNewPool = useIsNewPool ( { hyperdrive } ) ;
465+ const { lpApy, lpApyStatus } = useLpApy ( {
466+ chainId : hyperdrive . chainId ,
467+ hyperdriveAddress : hyperdrive . address ,
468+ } ) ;
469+
470+ const { vaultRate, vaultRateStatus } = useYieldSourceRate ( {
471+ hyperdriveAddress : hyperdrive . address ,
472+ chainId : hyperdrive . chainId ,
473+ } ) ;
474+ const showSkeleton = ! lpApy && lpApyStatus === "loading" ;
475+
476+ return (
477+ < PrimaryStat
478+ label = "LP APY"
479+ value = { ( ( ) => {
480+ if ( showSkeleton ) {
481+ return < Skeleton /> ;
482+ }
483+ if ( isNewPool ) {
484+ return < div className = "flex gap-2" > ✨New✨</ div > ;
485+ }
486+
487+ return `${ lpApy ?. formatted === "-0.00" ? "0.00" : lpApy ?. formatted } ` ;
488+ } ) ( ) }
489+ tooltipContent = "The annual percentage yield projection for providing liquidity."
490+ tooltipPosition = "left"
491+ valueClassName = { classNames ( "" , {
492+ "bg-gradient-to-r from-accent to-primary bg-clip-text text-transparent" :
493+ ! isNewPool , // Don't use gradient text when displaying NEW, the emojis give enough emphasis.
494+ } ) }
495+ subValue = {
496+ vaultRateStatus === "success" && vaultRate ? (
497+ < div >
498+ { appConfig . yieldSources [ hyperdrive . yieldSource ] . shortName } @{ " " }
499+ { vaultRate . formatted || 0 } APY
500+ </ div >
501+ ) : (
502+ < Skeleton className = "w-42 h-8" />
503+ )
504+ }
505+ />
506+ ) ;
507+ }
508+
473509function calculatePoolShare ( {
474510 lpSharesBalanceOf,
475511 lpSharesOut,
0 commit comments