From 9422a99116379f5341d952b785f8c308676654af Mon Sep 17 00:00:00 2001 From: BowTiedHeron Date: Tue, 16 May 2023 14:39:50 +0200 Subject: [PATCH 1/8] test new lens --- constants/NFTCollections.tsx | 4 +-- hooks/useHtokenHelper.tsx | 6 ++--- public/dev/abi/htokenHelper.json | 44 +++++++++++-------------------- public/prod/abi/htokenHelper.json | 44 +++++++++++-------------------- 4 files changed, 35 insertions(+), 63 deletions(-) diff --git a/constants/NFTCollections.tsx b/constants/NFTCollections.tsx index 36e3893..aea112e 100644 --- a/constants/NFTCollections.tsx +++ b/constants/NFTCollections.tsx @@ -120,7 +120,7 @@ function getCollections() { function getHelperContract() { if (envName == 'dev') { const contract: helperContract = { - htokenHelperContractAddress: '0xBdB3F78722DC37C864bFB5787F2A7D62bcb29Fbb', + htokenHelperContractAddress: '0xEa56f01f7a9CDe56e00d2b24Cb9A8F4735299954', hivemindContractAddress: '0x9a1EDb903B058298dd0b06f52876d9D45358B7cB', oracleContractAddress: '0xe236c45c8C3B0065F96cA62Dc5fd4759974161BC', marketContractAddress: '0xf7AC7E1fF22cc0e71964A2730d4e2835146F5aBE' @@ -128,7 +128,7 @@ function getHelperContract() { return contract; } else if (envName == 'prod') { const contract: helperContract = { - htokenHelperContractAddress: '0xBdB3F78722DC37C864bFB5787F2A7D62bcb29Fbb', + htokenHelperContractAddress: '0xEa56f01f7a9CDe56e00d2b24Cb9A8F4735299954', hivemindContractAddress: '0x9a1EDb903B058298dd0b06f52876d9D45358B7cB', oracleContractAddress: '0xe236c45c8C3B0065F96cA62Dc5fd4759974161BC', marketContractAddress: '0xf7AC7E1fF22cc0e71964A2730d4e2835146F5aBE' diff --git a/hooks/useHtokenHelper.tsx b/hooks/useHtokenHelper.tsx index ff1f818..affa5bf 100644 --- a/hooks/useHtokenHelper.tsx +++ b/hooks/useHtokenHelper.tsx @@ -558,9 +558,9 @@ export async function getMarketData( // @ts-ignore const response = await Moralis.EvmApi.utils.runContractFunction(options); const result: any = response.result; - const interestRate = result[0] as number; - const supplied = result[1] as string; - const available = result[2] as string; + const interestRate = result[3] as number; + const supplied = result[4] as string; + const available = result[5] as string; const resultData: marketData = { HERC20ContractAddress: HERC20ContractAddress, interestRate: interestRate / 1000.0, diff --git a/public/dev/abi/htokenHelper.json b/public/dev/abi/htokenHelper.json index b413e64..8976fb7 100644 --- a/public/dev/abi/htokenHelper.json +++ b/public/dev/abi/htokenHelper.json @@ -1,9 +1,4 @@ [ - { - "inputs": [], - "name": "WrongParams", - "type": "error" - }, { "inputs": [], "name": "DENOMINATOR", @@ -354,6 +349,21 @@ ], "name": "getFrontendMarketData", "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, { "internalType": "uint256", "name": "", @@ -568,30 +578,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_id", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_hTokenAddress", - "type": "address" - } - ], - "name": "uri", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "version", diff --git a/public/prod/abi/htokenHelper.json b/public/prod/abi/htokenHelper.json index b413e64..8976fb7 100644 --- a/public/prod/abi/htokenHelper.json +++ b/public/prod/abi/htokenHelper.json @@ -1,9 +1,4 @@ [ - { - "inputs": [], - "name": "WrongParams", - "type": "error" - }, { "inputs": [], "name": "DENOMINATOR", @@ -354,6 +349,21 @@ ], "name": "getFrontendMarketData", "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, { "internalType": "uint256", "name": "", @@ -568,30 +578,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_id", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_hTokenAddress", - "type": "address" - } - ], - "name": "uri", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "version", From e2d0be9904bf9f7631fe04c090bd80e9190d7302 Mon Sep 17 00:00:00 2001 From: BowTiedHeron Date: Tue, 16 May 2023 14:49:27 +0200 Subject: [PATCH 2/8] update lens --- constants/NFTCollections.tsx | 88 ++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/constants/NFTCollections.tsx b/constants/NFTCollections.tsx index aea112e..ca92952 100644 --- a/constants/NFTCollections.tsx +++ b/constants/NFTCollections.tsx @@ -3,27 +3,27 @@ import { envName } from './service'; function getCollections() { if (envName == 'dev') { return [ - { - name: 'Y00TS', - icon: '/nfts/y00ts.png', - erc20Name: 'WETH', - erc20Icon: '/erc20/EthIcon.png', - formatDecimals: 2, - unit: 'ether', - ERC721ContractAddress: '0x670fd103b1a08628e9557cD66B87DeD841115190', - ERC20ContractAddress: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', - HERC20ContractAddress: '0x13e3b746e89fd9693222fd377521d874e0e1ae5b' - }, - { - name: 'LAND', - icon: '/nfts/sandbox.png', - erc20Name: 'WETH', - erc20Icon: '/erc20/EthIcon.png', - unit: 'ether', - ERC721ContractAddress: '0x9d305a42A3975Ee4c1C57555BeD5919889DCE63F', - ERC20ContractAddress: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', - HERC20ContractAddress: '0x9e826d1427c15ff6f41521e9811fd526f7717a2a' - }, + // { + // name: 'Y00TS', + // icon: '/nfts/y00ts.png', + // erc20Name: 'WETH', + // erc20Icon: '/erc20/EthIcon.png', + // formatDecimals: 2, + // unit: 'ether', + // ERC721ContractAddress: '0x670fd103b1a08628e9557cD66B87DeD841115190', + // ERC20ContractAddress: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', + // HERC20ContractAddress: '0x13e3b746e89fd9693222fd377521d874e0e1ae5b' + // }, + // { + // name: 'LAND', + // icon: '/nfts/sandbox.png', + // erc20Name: 'WETH', + // erc20Icon: '/erc20/EthIcon.png', + // unit: 'ether', + // ERC721ContractAddress: '0x9d305a42A3975Ee4c1C57555BeD5919889DCE63F', + // ERC20ContractAddress: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', + // HERC20ContractAddress: '0x9e826d1427c15ff6f41521e9811fd526f7717a2a' + // }, { name: 'Chicken-Derby', icon: '/nfts/derby.png', @@ -59,27 +59,27 @@ function getCollections() { } else if (envName == 'prod') { // change this prod market when we go to prod return [ - { - name: 'Y00TS', - icon: '/nfts/y00ts.png', - erc20Name: 'WETH', - erc20Icon: '/erc20/EthIcon.png', - formatDecimals: 2, - unit: 'ether', - ERC721ContractAddress: '0x670fd103b1a08628e9557cD66B87DeD841115190', - ERC20ContractAddress: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', - HERC20ContractAddress: '0x13e3b746e89fd9693222fd377521d874e0e1ae5b' - }, - { - name: 'LAND', - icon: '/nfts/sandbox.png', - erc20Name: 'WETH', - erc20Icon: '/erc20/EthIcon.png', - unit: 'ether', - ERC721ContractAddress: '0x9d305a42A3975Ee4c1C57555BeD5919889DCE63F', - ERC20ContractAddress: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', - HERC20ContractAddress: '0x9e826d1427c15ff6f41521e9811fd526f7717a2a' - }, + // { + // name: 'Y00TS', + // icon: '/nfts/y00ts.png', + // erc20Name: 'WETH', + // erc20Icon: '/erc20/EthIcon.png', + // formatDecimals: 2, + // unit: 'ether', + // ERC721ContractAddress: '0x670fd103b1a08628e9557cD66B87DeD841115190', + // ERC20ContractAddress: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', + // HERC20ContractAddress: '0x13e3b746e89fd9693222fd377521d874e0e1ae5b' + // }, + // { + // name: 'LAND', + // icon: '/nfts/sandbox.png', + // erc20Name: 'WETH', + // erc20Icon: '/erc20/EthIcon.png', + // unit: 'ether', + // ERC721ContractAddress: '0x9d305a42A3975Ee4c1C57555BeD5919889DCE63F', + // ERC20ContractAddress: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', + // HERC20ContractAddress: '0x9e826d1427c15ff6f41521e9811fd526f7717a2a' + // }, { name: 'Chicken-Derby', icon: '/nfts/derby.png', @@ -120,7 +120,7 @@ function getCollections() { function getHelperContract() { if (envName == 'dev') { const contract: helperContract = { - htokenHelperContractAddress: '0xEa56f01f7a9CDe56e00d2b24Cb9A8F4735299954', + htokenHelperContractAddress: '0x80478086f9fb2462e7a35eec6e9a683b25153b37', hivemindContractAddress: '0x9a1EDb903B058298dd0b06f52876d9D45358B7cB', oracleContractAddress: '0xe236c45c8C3B0065F96cA62Dc5fd4759974161BC', marketContractAddress: '0xf7AC7E1fF22cc0e71964A2730d4e2835146F5aBE' @@ -128,7 +128,7 @@ function getHelperContract() { return contract; } else if (envName == 'prod') { const contract: helperContract = { - htokenHelperContractAddress: '0xEa56f01f7a9CDe56e00d2b24Cb9A8F4735299954', + htokenHelperContractAddress: '0x80478086f9fb2462e7a35eec6e9a683b25153b37', hivemindContractAddress: '0x9a1EDb903B058298dd0b06f52876d9D45358B7cB', oracleContractAddress: '0xe236c45c8C3B0065F96cA62Dc5fd4759974161BC', marketContractAddress: '0xf7AC7E1fF22cc0e71964A2730d4e2835146F5aBE' From 4021f5715b555edce09d30f0919779786215a6f5 Mon Sep 17 00:00:00 2001 From: BowTiedHeron Date: Tue, 16 May 2023 14:58:40 +0200 Subject: [PATCH 3/8] fetch interest --- hooks/useHtokenHelper.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hooks/useHtokenHelper.tsx b/hooks/useHtokenHelper.tsx index affa5bf..70d9971 100644 --- a/hooks/useHtokenHelper.tsx +++ b/hooks/useHtokenHelper.tsx @@ -558,12 +558,13 @@ export async function getMarketData( // @ts-ignore const response = await Moralis.EvmApi.utils.runContractFunction(options); const result: any = response.result; - const interestRate = result[3] as number; + const supplyInterestRate = result[2] as number; + const borrowInterestRate = result[3] as number; const supplied = result[4] as string; const available = result[5] as string; const resultData: marketData = { HERC20ContractAddress: HERC20ContractAddress, - interestRate: interestRate / 1000.0, + interestRate: borrowInterestRate / 1000000000000000000.0, supplied: fromWei(supplied, unit), available: fromWei(available, unit) }; From f8bfe8e51c57675252bb0d80bff45ae4ee01e8a5 Mon Sep 17 00:00:00 2001 From: BowTiedHeron Date: Tue, 16 May 2023 16:36:12 +0200 Subject: [PATCH 4/8] update interest fetch draft --- helpers/utils.tsx | 19 ++++++++++--------- hooks/useCollection.tsx | 14 ++++++++++---- hooks/useHtokenHelper.tsx | 8 ++++---- types/markets.ts | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/helpers/utils.tsx b/helpers/utils.tsx index c43bb4f..83ae13c 100644 --- a/helpers/utils.tsx +++ b/helpers/utils.tsx @@ -37,15 +37,6 @@ export const formatAddress = (address: any) => { export const RoundHalfDown = (val: number, decimals: number = 2): number => { return Math.floor(val * 10 ** decimals) / 10 ** decimals; }; -/** - * @description calculates interest rate for lend market - * @params baserate which is default rate provided by contract | total market supplied | total market available - * @returns interest rate for lend market - */ -export const interestRateLend = (baseRate: number, supplied: string, available: string) => { - const rate = baseRate * ((parseFloat(supplied) - parseFloat(available)) / parseFloat(supplied)); - return rate > 0 ? rate : 0; -}; /** * @description filter selected position from positions array @@ -61,6 +52,16 @@ export const fetchAllowance = (positions: MarketTablePosition[], NFTId: string) } }; +// TODO: no calculation needed, can now be fetched from lens/helper contract [2] +/** + * @description calculates interest rate for lend market + * @params baserate which is default rate provided by contract | total market supplied | total market available + * @returns interest rate for lend market + */ +export const interestRateLend = (baseRate: number, supplied: string, available: string) => { + const rate = baseRate * ((parseFloat(supplied) - parseFloat(available)) / parseFloat(supplied)); + return rate > 0 ? rate : 0; +}; /** * @description return interest rate for specific collection * @params positions diff --git a/hooks/useCollection.tsx b/hooks/useCollection.tsx index 87cec00..883ed2c 100644 --- a/hooks/useCollection.tsx +++ b/hooks/useCollection.tsx @@ -40,7 +40,9 @@ const defaultMarketData: MarketTableRow = { icon: '', erc20Icon: '', formatDecimals: 0, - rate: 0, + rate: '0', + // supplyRate: '0', + // borrowRate: '0', available: 0, supplied: 0 }; @@ -59,7 +61,9 @@ const defaultLiquidationData: LiquidateTableRow = { const defaultMarket: marketData = { HERC20ContractAddress: '', - interestRate: 0, + interestRate: '0', + // supplyInterestRate: '0', + // borrowInterestRate: '0', supplied: '0', available: '0' }; @@ -88,6 +92,8 @@ export function useMarket( erc20Icon: collection.erc20Icon, formatDecimals: collection.formatDecimals, rate: marketData.interestRate, + // supplyRate: marketData.supplyInterestRate, + // borrowRate: marketData.borrowInterestRate, available: parseFloat(marketData.available), supplied: parseFloat(marketData.supplied) }; @@ -101,7 +107,7 @@ export function useMarket( icon: collection.icon, erc20Icon: collection.erc20Icon, formatDecimals: collection.formatDecimals, - rate: 0, + rate: '0', available: 0, supplied: 0 }; @@ -357,7 +363,7 @@ export function useLend( console.error(e); const result: marketData = { HERC20ContractAddress: collection.HERC20ContractAddress, - interestRate: 0, + interestRate: '0', supplied: '0', available: '0' }; diff --git a/hooks/useHtokenHelper.tsx b/hooks/useHtokenHelper.tsx index 70d9971..00a7ce3 100644 --- a/hooks/useHtokenHelper.tsx +++ b/hooks/useHtokenHelper.tsx @@ -536,7 +536,7 @@ export function useGetUserCoupons( export interface marketData { HERC20ContractAddress: string; - interestRate: number; + interestRate: string; supplied: string; available: string; } @@ -558,13 +558,13 @@ export async function getMarketData( // @ts-ignore const response = await Moralis.EvmApi.utils.runContractFunction(options); const result: any = response.result; - const supplyInterestRate = result[2] as number; - const borrowInterestRate = result[3] as number; + const supplyInterestRate = result[2] as string; + const borrowInterestRate = result[3] as string; const supplied = result[4] as string; const available = result[5] as string; const resultData: marketData = { HERC20ContractAddress: HERC20ContractAddress, - interestRate: borrowInterestRate / 1000000000000000000.0, + interestRate: fromWei(borrowInterestRate, unit), supplied: fromWei(supplied, unit), available: fromWei(available, unit) }; diff --git a/types/markets.ts b/types/markets.ts index 1543b8f..cc82092 100644 --- a/types/markets.ts +++ b/types/markets.ts @@ -5,7 +5,7 @@ export type MarketTableRow = { name: string; icon: string; erc20Icon: string; - rate: number; + rate: string; available: number; supplied: number; formatDecimals: number; From 441c918f4ca97e36dcc2bd412917135c7c86a1a9 Mon Sep 17 00:00:00 2001 From: daan Date: Tue, 16 May 2023 17:42:36 +0100 Subject: [PATCH 5/8] separate borrow and lend interest rates --- hooks/useCollection.tsx | 27 +++++++++++++++------------ hooks/useDashBoard.tsx | 12 +++++++++--- hooks/useHtokenHelper.tsx | 6 ++++-- pages/borrow/index.tsx | 10 +++++----- types/markets.ts | 3 ++- 5 files changed, 35 insertions(+), 23 deletions(-) diff --git a/hooks/useCollection.tsx b/hooks/useCollection.tsx index 883ed2c..369150b 100644 --- a/hooks/useCollection.tsx +++ b/hooks/useCollection.tsx @@ -40,9 +40,8 @@ const defaultMarketData: MarketTableRow = { icon: '', erc20Icon: '', formatDecimals: 0, - rate: '0', - // supplyRate: '0', - // borrowRate: '0', + lendRate: 0, + borrowRate: 0, available: 0, supplied: 0 }; @@ -61,9 +60,8 @@ const defaultLiquidationData: LiquidateTableRow = { const defaultMarket: marketData = { HERC20ContractAddress: '', - interestRate: '0', - // supplyInterestRate: '0', - // borrowInterestRate: '0', + supplyInterestRate: '0', + borrowInterestRate: '0', supplied: '0', available: '0' }; @@ -91,9 +89,8 @@ export function useMarket( icon: collection.icon, erc20Icon: collection.erc20Icon, formatDecimals: collection.formatDecimals, - rate: marketData.interestRate, - // supplyRate: marketData.supplyInterestRate, - // borrowRate: marketData.borrowInterestRate, + lendRate: parseFloat(marketData.supplyInterestRate), + borrowRate: parseFloat(marketData.borrowInterestRate), available: parseFloat(marketData.available), supplied: parseFloat(marketData.supplied) }; @@ -107,7 +104,8 @@ export function useMarket( icon: collection.icon, erc20Icon: collection.erc20Icon, formatDecimals: collection.formatDecimals, - rate: '0', + borrowRate: 0, + lendRate: 0, available: 0, supplied: 0 }; @@ -363,7 +361,8 @@ export function useLend( console.error(e); const result: marketData = { HERC20ContractAddress: collection.HERC20ContractAddress, - interestRate: '0', + borrowInterestRate: '0', + supplyInterestRate: '0', supplied: '0', available: '0' }; @@ -395,7 +394,11 @@ export function useLend( formatDecimals: formatDecimals ?? 3, available: parseFloat(marketData.available), supplied: parseFloat(marketData.supplied), - rate: interestRateLend(marketData.interestRate, marketData.supplied, marketData.available) + rate: interestRateLend( + Number(marketData.supplyInterestRate), + marketData.supplied, + marketData.available + ) }; return result; }); diff --git a/hooks/useDashBoard.tsx b/hooks/useDashBoard.tsx index f74eb73..ff95168 100644 --- a/hooks/useDashBoard.tsx +++ b/hooks/useDashBoard.tsx @@ -142,7 +142,8 @@ export function useLendUserPositions( const walletPublicKey: string = user?.address || ''; const defaultMarket: marketData = { HERC20ContractAddress: '', - interestRate: 0, + borrowInterestRate: '0', + supplyInterestRate: '0', supplied: '0', available: '0' }; @@ -203,7 +204,8 @@ export function useLendUserPositions( console.error(e); const result: marketData = { HERC20ContractAddress: HERC20ContractAddress, - interestRate: 0, + borrowInterestRate: '0', + supplyInterestRate: '0', supplied: '0', available: '0' }; @@ -229,7 +231,11 @@ export function useLendUserPositions( const data = lendData[0]; position.supplied = parseFloat(data.supplied); position.available = parseFloat(data.available); - position.rate = interestRateLend(data.interestRate, data.supplied, data.available); + position.rate = interestRateLend( + parseFloat(data.supplyInterestRate), + data.supplied, + data.available + ); } return position; }); diff --git a/hooks/useHtokenHelper.tsx b/hooks/useHtokenHelper.tsx index 00a7ce3..958e6aa 100644 --- a/hooks/useHtokenHelper.tsx +++ b/hooks/useHtokenHelper.tsx @@ -536,7 +536,8 @@ export function useGetUserCoupons( export interface marketData { HERC20ContractAddress: string; - interestRate: string; + borrowInterestRate: string; + supplyInterestRate: string; supplied: string; available: string; } @@ -564,7 +565,8 @@ export async function getMarketData( const available = result[5] as string; const resultData: marketData = { HERC20ContractAddress: HERC20ContractAddress, - interestRate: fromWei(borrowInterestRate, unit), + borrowInterestRate: fromWei(borrowInterestRate, unit), + supplyInterestRate: fromWei(supplyInterestRate, unit), supplied: fromWei(supplied, unit), available: fromWei(available, unit) }; diff --git a/pages/borrow/index.tsx b/pages/borrow/index.tsx index 672cc99..ed6105b 100644 --- a/pages/borrow/index.tsx +++ b/pages/borrow/index.tsx @@ -207,13 +207,13 @@ const Markets: NextPage = () => { ); }, - dataIndex: 'rate', + dataIndex: 'borrowRate', hidden: windowWidth < TABLET_BP, - sorter: (a: MarketTableRow, b: MarketTableRow) => a.rate - b.rate, - render: (rate: number) => { + sorter: (a: MarketTableRow, b: MarketTableRow) => a.borrowRate - b.borrowRate, + render: (borrowRate: number, row: MarketTableRow) => { return (
- {fp(rate / (showWeeklyRates ? 52 : 1), showWeeklyRates ? 3 : 2)} + {fp(borrowRate / (showWeeklyRates ? 52 : 1), showWeeklyRates ? 3 : 2)}
); } @@ -313,7 +313,7 @@ const Markets: NextPage = () => {
- {fp(row.rate / (showWeeklyRates ? 52 : 1), showWeeklyRates ? 3 : 2)} + {fp(row.borrowRate / (showWeeklyRates ? 52 : 1), showWeeklyRates ? 3 : 2)}
{fs(row.supplied)}
{fs(row.available)}
diff --git a/types/markets.ts b/types/markets.ts index cc82092..aae2b1e 100644 --- a/types/markets.ts +++ b/types/markets.ts @@ -5,7 +5,8 @@ export type MarketTableRow = { name: string; icon: string; erc20Icon: string; - rate: string; + borrowRate: number; + lendRate: number; available: number; supplied: number; formatDecimals: number; From 27739c6a38efcd32ce2f55c28f3259f3544ed59f Mon Sep 17 00:00:00 2001 From: daan Date: Tue, 16 May 2023 17:43:15 +0100 Subject: [PATCH 6/8] use correct borrow rate in borrow form --- components/BorrowForm/BorrowForm.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/BorrowForm/BorrowForm.tsx b/components/BorrowForm/BorrowForm.tsx index 7ec3b52..7174bfd 100644 --- a/components/BorrowForm/BorrowForm.tsx +++ b/components/BorrowForm/BorrowForm.tsx @@ -32,8 +32,9 @@ import { import { useGetBorrowAmount } from '../../hooks/useCoupon'; import { borrow } from '../../hooks/useHerc20'; import { queryKeys } from '../../helpers/queryHelper'; -import { usePositions } from '../../hooks/useCollection'; +import { useMarket, usePositions } from '../../hooks/useCollection'; import { fetchAllowance } from 'helpers/utils'; +import { collections } from '../../constants/NFTCollections'; const { format: f, @@ -116,6 +117,17 @@ const BorrowForm = (props: BorrowProps) => { HERC20ContractAddress, unit ); + + const collection = collections.find( + (collection) => collection.HERC20ContractAddress === HERC20ContractAddress + ); + + const [marketData, isLoadingMarketData] = useMarket( + currentUser, + collection ? [collection] : [], + htokenHelperContractAddress + ); + const newAdditionalDebt = valueUnderlying * (1 + borrowFee); const newTotalDebt = newAdditionalDebt ? borrowedValue + newAdditionalDebt : borrowedValue; /* end initial all financial value here */ @@ -387,7 +399,7 @@ const BorrowForm = (props: BorrowProps) => { } - value={fp(5, 2)} + value={fp(marketData[0].borrowRate, 2)} />
From c8823fa2690e2b53e0463982d49a1a6afd3ebcc7 Mon Sep 17 00:00:00 2001 From: daan Date: Tue, 16 May 2023 17:55:19 +0100 Subject: [PATCH 7/8] add correct borrow rate --- .../BorrowPositionCard/BorrowPositionCard.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/components/HoneyCardsGrid/BorrowPositionCard/BorrowPositionCard.tsx b/components/HoneyCardsGrid/BorrowPositionCard/BorrowPositionCard.tsx index f731289..0e6d01b 100644 --- a/components/HoneyCardsGrid/BorrowPositionCard/BorrowPositionCard.tsx +++ b/components/HoneyCardsGrid/BorrowPositionCard/BorrowPositionCard.tsx @@ -1,4 +1,4 @@ -import { FC } from 'react'; +import { FC, useContext } from 'react'; import { BorrowPositionCardProps } from '../types'; import * as styles from './BorrowPositionCard.css'; import HexaBoxContainer from '../../HexaBoxContainer/HexaBoxContainer'; @@ -13,11 +13,15 @@ import { useGetMaxBorrowableAmount, useGetNFTPrice } from 'hooks/useHtokenHelper import { getContractsByHTokenAddr } from 'helpers/generalHelper'; import { useGetCollateralFactor } from 'hooks/useHivemind'; import { useGetBorrowAmount } from 'hooks/useCoupon'; +import { collections } from 'constants/NFTCollections'; +import { useMarket } from 'hooks/useCollection'; +import { UserContext } from 'contexts/userContext'; const { formatShortName: fsn, formatPercent: fp } = formatNumber; export const BorrowPositionCard: FC = ({ position, onSelect }) => { const selectedNFTId = useLoanFlowStore((state) => state.NFTId); + const { currentUser } = useContext(UserContext); const { nftContractAddress, @@ -53,6 +57,16 @@ export const BorrowPositionCard: FC = ({ position, onSe const nftValue = nftPrice.price; const MAX_LTV = maxBorrow / nftValue; + const collection = collections.find( + (collection) => collection.HERC20ContractAddress === position.HERC20ContractAddr + ); + + const [marketData, isLoadingMarketData] = useMarket( + currentUser, + collection ? [collection] : [], + htokenHelperContractAddress + ); + return (
= ({ position, onSe
} /> - +
Date: Tue, 16 May 2023 17:55:29 +0100 Subject: [PATCH 8/8] fix decimal places --- .../HoneyCardsGrid/LendPositionCard/LendPositionCard.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/HoneyCardsGrid/LendPositionCard/LendPositionCard.tsx b/components/HoneyCardsGrid/LendPositionCard/LendPositionCard.tsx index fd8e183..0afcd65 100644 --- a/components/HoneyCardsGrid/LendPositionCard/LendPositionCard.tsx +++ b/components/HoneyCardsGrid/LendPositionCard/LendPositionCard.tsx @@ -52,7 +52,10 @@ export const LendPositionCard: FC = ({ position, onSelect
- {fp(position.rate)}} /> + {fp(position.rate, 2)}} + />