With the calculated values, we can now call the contract:
import { AddressZero } from '@ethersproject/constants'; // use null address if there is no referrer wallet address
const tx = await mintClubBondContract.buy(tokenAddress, buyAmount, minReward, referrerWalletAddress);
In order to calculate the minRefund, we utilize the getBurnRefund function from mintClubBondContract.
const contract = getMintClubBondContract();
const result = await contract.getBurnRefund(
tokenAddress,
new BigNumber(amount).times(BIG_TEN.pow(DEFAULT_TOKEN_DECIMAL)).toString(),
); // here amount is amount of token user is willing to sell
const outBN = new BigNumber(result[0].toString());
const minRefund = outBN
.times((100 - 2 /* slippage percentage */) / 100)
.toFixed(0, 1)
.toString(10);
With the calculated minRefund value, we can now call the sell function on mintClubBondContract.
import { AddressZero } from '@ethersproject/constants'; // use null address if there is no referrer wallet address
const tx = await mintClubBondContract.sell(tokenAddress, sellAmount, minRefund, referrerWalletAddress);