From 2235021007a0061f67ce4088fe72573f831d2a62 Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Mon, 4 Nov 2024 21:22:46 +0530 Subject: [PATCH 1/4] fix: update productSupply prop type and add debug logs for payout calculation --- .../Bonding/Deposit/Deposit.jsx | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx b/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx index e011886f..f312967a 100644 --- a/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx +++ b/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx @@ -34,6 +34,7 @@ export const Deposit = ({ getProducts, closeModal, }) => { + console.log('Deposit -> productToken', productSupply); const { account } = useHelpers(); const [form] = Form.useForm(); const [isLoading, setIsLoading] = useState(false); @@ -135,10 +136,13 @@ export const Deposit = ({ return parseToEth(remainingLPSupply); }, [lpBalance, productSupply, productLpPriceAfterDiscount]); + // calculate the OLAS payout based on the token amount input const olasPayout = useMemo(() => { - if (!tokenAmountInputValue || tokenAmountInputValue > remainingLpSupplyInEth) { - return '--'; - } + console.log({ tokenAmountInputValue, remainingLpSupplyInEth, productLpPriceAfterDiscount }); + + // if (!tokenAmountInputValue || tokenAmountInputValue > remainingLpSupplyInEth) { + // return '--'; + // } const tokenAmountValue = isSvmProduct ? tokenAmountInputValue @@ -149,6 +153,14 @@ export const Deposit = ({ ? payoutInBg.dividedBy(BigNumber(`1${'0'.repeat(28)}`)).toFixed(2) : Number(payoutInBg.dividedBy(ONE_ETH_IN_STRING).dividedBy(ONE_ETH_IN_STRING).toFixed(2)); + console.log({ + tokenAmountInputValue, + remainingLpSupplyInEth, + productLpPriceAfterDiscount, + isSvmProduct, + payout, + }); + return getCommaSeparatedNumber(payout, 4); }, [tokenAmountInputValue, remainingLpSupplyInEth, productLpPriceAfterDiscount, isSvmProduct]); @@ -285,7 +297,7 @@ Deposit.propTypes = { productId: PropTypes.string, productToken: PropTypes.string, productLpTokenName: PropTypes.string, - productSupply: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(BigInt)]), + productSupply: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), productLpPriceAfterDiscount: PropTypes.oneOfType([ PropTypes.string, PropTypes.instanceOf(BigInt), From 1bbc3cdb33c515b19fc76e64ec7acc52d5c7df8c Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Mon, 4 Nov 2024 21:45:37 +0530 Subject: [PATCH 2/4] fix: add support for SOL in remaining LP supply calculation and clean up console logs --- .../BondingProducts/Bonding/Deposit/Deposit.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx b/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx index f312967a..d1225bab 100644 --- a/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx +++ b/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx @@ -14,6 +14,7 @@ import { ONE_ETH, ONE_ETH_IN_STRING } from 'common-util/constants/numbers'; import { notifyCustomErrors, parseToEth, + parseToSol, parseToSolDecimals, parseToWei, } from 'common-util/functions'; @@ -133,16 +134,15 @@ export const Deposit = ({ (totalProductSupplyInWei * ONE_ETH) / BigInt(productLpPriceAfterDiscount); const remainingLPSupply = maxRedeemableSupply < lpBalanceInWei ? maxRedeemableSupply : lpBalanceInWei; - return parseToEth(remainingLPSupply); - }, [lpBalance, productSupply, productLpPriceAfterDiscount]); + + return isSvmProduct ? parseToSol(remainingLPSupply) : parseToEth(remainingLPSupply); + }, [lpBalance, productSupply, productLpPriceAfterDiscount, isSvmProduct]); // calculate the OLAS payout based on the token amount input const olasPayout = useMemo(() => { - console.log({ tokenAmountInputValue, remainingLpSupplyInEth, productLpPriceAfterDiscount }); - - // if (!tokenAmountInputValue || tokenAmountInputValue > remainingLpSupplyInEth) { - // return '--'; - // } + if (!tokenAmountInputValue || tokenAmountInputValue > remainingLpSupplyInEth) { + return '--'; + } const tokenAmountValue = isSvmProduct ? tokenAmountInputValue From a29fd35a5340cef17325c538ee43567da48e5705 Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Mon, 4 Nov 2024 21:52:01 +0530 Subject: [PATCH 3/4] feat: add parseToSol function for converting amounts to SOL decimals --- apps/bond/common-util/functions/ethers.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/bond/common-util/functions/ethers.js b/apps/bond/common-util/functions/ethers.js index 6815cb67..0739ff28 100644 --- a/apps/bond/common-util/functions/ethers.js +++ b/apps/bond/common-util/functions/ethers.js @@ -16,6 +16,11 @@ export const parseToWei = (amount) => ethers.parseUnits(`${amount}`, 18).toStrin */ export const parseToSolDecimals = (amount) => ethers.parseUnits(`${amount}`, 8).toString(); +/** + * divides the amount by 10^8 + */ +export const parseToSol = (amount) => ethers.formatUnits(`${amount}`, 8); + /** * TODO: move to autonolas-library and figure out a better way * to fetch timestamp From f3e5e891ffe5aaf216b5807260d799de2434111d Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Mon, 4 Nov 2024 22:04:08 +0530 Subject: [PATCH 4/4] fix: remove debug console logs and update productSupply prop type to support BigInt --- .../BondingProducts/Bonding/Deposit/Deposit.jsx | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx b/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx index d1225bab..9b3db39d 100644 --- a/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx +++ b/apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx @@ -35,7 +35,6 @@ export const Deposit = ({ getProducts, closeModal, }) => { - console.log('Deposit -> productToken', productSupply); const { account } = useHelpers(); const [form] = Form.useForm(); const [isLoading, setIsLoading] = useState(false); @@ -152,15 +151,6 @@ export const Deposit = ({ const payout = isSvmProduct ? payoutInBg.dividedBy(BigNumber(`1${'0'.repeat(28)}`)).toFixed(2) : Number(payoutInBg.dividedBy(ONE_ETH_IN_STRING).dividedBy(ONE_ETH_IN_STRING).toFixed(2)); - - console.log({ - tokenAmountInputValue, - remainingLpSupplyInEth, - productLpPriceAfterDiscount, - isSvmProduct, - payout, - }); - return getCommaSeparatedNumber(payout, 4); }, [tokenAmountInputValue, remainingLpSupplyInEth, productLpPriceAfterDiscount, isSvmProduct]); @@ -297,7 +287,7 @@ Deposit.propTypes = { productId: PropTypes.string, productToken: PropTypes.string, productLpTokenName: PropTypes.string, - productSupply: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + productSupply: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(BigInt)]), productLpPriceAfterDiscount: PropTypes.oneOfType([ PropTypes.string, PropTypes.instanceOf(BigInt),