I am trying to add a price pool in bnb for my token and I did the following code:

function swap(uint256 amount, address destination) private {
    uint256 bnbBalance = address(this).balance;
    uint256 prizePool = _calculatePercentage(amount, percentage_prize_pool);

    // Don't exchange those tokens I want to keep for the prize pool
    amount = amount.sub(prizePool);
    // call the swap in pancakeswap api using the amount - prizePool
    // ....

    // Time for prize pool
    uint256 bnbPrizePool = xxxxxx;

So this arises a few questions for me.

  1. Let's suppose that I want to buy 0.1 BNB and I want to do 10% of that to the price pool, how do I handle that in a system that does not allow floating point? I read that in ETH you use wei so you multiply that x 1000, but I haven't found documentation for BNB.
  2. How do I identify the value of the bnbPrizePool? I kept the tokens I don't want to exchange but now I need the value of them in BNB so I send the prize. Is that possible? Do I need to do a multiplication with the exchangeRate? How do I calculate that exchange rate? My understanding is for selling they are not bnb yet, so do I need to swap them?
  3. Is it necessary to differentiate between buys and sells? I understand that when you buy you have an increase of bnb balance after swapping, which is good because I want to do the prize in bnb, but what happens with sells? The difference is going to be negative, how do I convert that back into my token? Should I identify that is a sell and then retain the amount of bnb I don't want to pay and use them for the pool? Is there any better mechanism?
  4. I am finding incredibly hard to debug this in testnet (remix debugger is not starting and truffle is throwing ProviderError: the method debug_traceTransaction does not exist/is not available). Is there any trick to do so? I am trying with events but I haven't found how to read that info in testnet

Sorry for the amount of questions, but the documentation in internet is not great and I don't feel comportable copying and pasting Safemoon without understanding how this works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.