Skip to content

Commit

Permalink
(bond) fix: bond issue on Solana product (#130)
Browse files Browse the repository at this point in the history
* fix: update productSupply prop type and add debug logs for payout calculation

* fix: add support for SOL in remaining LP supply calculation and clean up console logs

* feat: add parseToSol function for converting amounts to SOL decimals

* fix: remove debug console logs and update productSupply prop type to support BigInt
  • Loading branch information
mohandast52 authored Nov 4, 2024
1 parent 40b0d19 commit f218f17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions apps/bond/common-util/functions/ethers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -132,9 +133,11 @@ 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(() => {
if (!tokenAmountInputValue || tokenAmountInputValue > remainingLpSupplyInEth) {
return '--';
Expand All @@ -148,7 +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));

return getCommaSeparatedNumber(payout, 4);
}, [tokenAmountInputValue, remainingLpSupplyInEth, productLpPriceAfterDiscount, isSvmProduct]);

Expand Down

0 comments on commit f218f17

Please sign in to comment.