mirror of
				https://github.com/cerc-io/mars-interface.git
				synced 2025-10-31 12:34:06 +00:00 
			
		
		
		
	Merge pull request #14 from mars-protocol/hofix/farm-apr
fix: fixed the farm borrowing apr
This commit is contained in:
		
						commit
						193bb0f2d6
					
				| @ -91,7 +91,9 @@ export const useAvailableVaultsColumns = () => { | |||||||
|           const borrowAsset = redBankAssets.find( |           const borrowAsset = redBankAssets.find( | ||||||
|             (asset) => asset.denom === row.original.denoms.secondary, |             (asset) => asset.denom === row.original.denoms.secondary, | ||||||
|           ) |           ) | ||||||
|           const maxBorrowRate = Number(borrowAsset?.borrowRate ?? 0) * row.original.ltv.max |           const maxBorrowRate = | ||||||
|  |             Number(borrowAsset?.borrowRate ?? 0) * (ltvToLeverage(row.original.ltv.max) - 1) | ||||||
|  | 
 | ||||||
|           const minAPY = new BigNumber(row.original.apy).toNumber() |           const minAPY = new BigNumber(row.original.apy).toNumber() | ||||||
| 
 | 
 | ||||||
|           const maxAPY = new BigNumber(minAPY).times(maxLeverage).toNumber() - maxBorrowRate |           const maxAPY = new BigNumber(minAPY).times(maxLeverage).toNumber() - maxBorrowRate | ||||||
|  | |||||||
| @ -209,7 +209,8 @@ export const BreakdownTable = (props: Props) => { | |||||||
|   const currentLeverage = props.newPosition.currentLeverage |   const currentLeverage = props.newPosition.currentLeverage | ||||||
| 
 | 
 | ||||||
|   const trueBorrowRate = |   const trueBorrowRate = | ||||||
|     (Number(secondaryRedBankAsset?.borrowRate ?? 0) / 2) * (Number(currentLeverage) - 1) |     Number(secondaryRedBankAsset?.borrowRate ?? 0) * (Number(currentLeverage) - 1) | ||||||
|  | 
 | ||||||
|   const apy = (props.vault.apy || 0) * currentLeverage - trueBorrowRate |   const apy = (props.vault.apy || 0) * currentLeverage - trueBorrowRate | ||||||
| 
 | 
 | ||||||
|   const apyData = { |   const apyData = { | ||||||
|  | |||||||
| @ -1,24 +1,18 @@ | |||||||
| @import 'src/styles/master'; | @import 'src/styles/master'; | ||||||
|  | .primary, | ||||||
|  | .secondary { | ||||||
|  |   position: absolute; | ||||||
|  |   top: 50%; | ||||||
|  |   transform: translateY(-50%); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| .primary { | .primary { | ||||||
|   position: absolute; |   margin-top: space(-1); | ||||||
|   left: 20%; |   left: 20%; | ||||||
|   z-index: 1; |   z-index: 1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| .secondary { | .secondary { | ||||||
|   position: absolute; |   margin-top: space(1); | ||||||
|   right: 20%; |   right: 20%; | ||||||
|   top: 20%; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| @media only screen and (min-width: $bpMediumLow) { |  | ||||||
|   .primary { |  | ||||||
|     top: 20%; |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   .secondary { |  | ||||||
|     top: unset; |  | ||||||
|     bottom: 20%; |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -154,28 +154,32 @@ export const vaultsSlice = (set: NamedSet<Store>, get: GetState<Store>): VaultsS | |||||||
|     const networkConfig = get().networkConfig |     const networkConfig = get().networkConfig | ||||||
|     if (!networkConfig) return null |     if (!networkConfig) return null | ||||||
| 
 | 
 | ||||||
|     const response = await fetch(networkConfig!.apolloAprUrl) |     try { | ||||||
|  |       const response = await fetch(networkConfig!.apolloAprUrl) | ||||||
| 
 | 
 | ||||||
|     if (response.ok) { |       if (response.ok) { | ||||||
|       const data: AprResponse[] = await response.json() |         const data: AprResponse[] = await response.json() | ||||||
| 
 | 
 | ||||||
|       const newAprs = data.map((aprData) => { |         const newAprs = data.map((aprData) => { | ||||||
|         const aprTotal = aprData.apr.reduce((prev, curr) => Number(curr.value) + prev, 0) |           const aprTotal = aprData.apr.reduce((prev, curr) => Number(curr.value) + prev, 0) | ||||||
|         const feeTotal = aprData.fees.reduce((prev, curr) => Number(curr.value) + prev, 0) |           const feeTotal = aprData.fees.reduce((prev, curr) => Number(curr.value) + prev, 0) | ||||||
| 
 | 
 | ||||||
|         const finalApr = aprTotal + feeTotal |           const finalApr = aprTotal + feeTotal | ||||||
| 
 | 
 | ||||||
|         return { contractAddress: aprData.contract_address, apr: finalApr } |           return { contractAddress: aprData.contract_address, apr: finalApr } | ||||||
|       }) |         }) | ||||||
| 
 | 
 | ||||||
|       set({ |         set({ | ||||||
|         aprs: newAprs, |           aprs: newAprs, | ||||||
|       }) |         }) | ||||||
| 
 | 
 | ||||||
|       get().addAprToVaults(newAprs) |         get().addAprToVaults(newAprs) | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       return null | ||||||
|  |     } catch { | ||||||
|  |       return null | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|     return null |  | ||||||
|   }, |   }, | ||||||
|   getCaps: async (options?: Options) => { |   getCaps: async (options?: Options) => { | ||||||
|     const caps = get().caps |     const caps = get().caps | ||||||
| @ -360,7 +364,7 @@ export const vaultsSlice = (set: NamedSet<Store>, get: GetState<Store>): VaultsS | |||||||
|             const borrowRate = |             const borrowRate = | ||||||
|               redBankAssets.find((asset) => asset.denom === curr.denoms.secondary)?.borrowRate || 0 |               redBankAssets.find((asset) => asset.denom === curr.denoms.secondary)?.borrowRate || 0 | ||||||
| 
 | 
 | ||||||
|             const trueBorrowRate = (borrowRate / 2) * (leverage - 1) |             const trueBorrowRate = (leverage - 1) * borrowRate | ||||||
| 
 | 
 | ||||||
|             const getPositionStatus = (unlockTime?: number) => { |             const getPositionStatus = (unlockTime?: number) => { | ||||||
|               if (!unlockTime) return 'active' |               if (!unlockTime) return 'active' | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user