0

I have a question of tiered token price during ICO presale. Here is the Fightout presale segmant. enter image description here

As you can notice, after time passed, the token price raised. I understand presale contract need to include changeable rate for token. But not sure whether I set automatically time-based changing rate in contract itself, or should include setRate function only in contract and invoke it from presale site backend by using API to set new tiered prices for token. Can you please teach me which is the correct way?

2 Answers 2

1

Use OpenZeppelin 2.x: https://docs.openzeppelin.com/contracts/2.x/crowdsales

You can then override _getTokenAmount that will provide custom code

An example: https://etherscan.io/address/0xd006d2f23cdc9949727d482ec707a1c9d1d4abdb (1766 days ago)

  function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {

    // Floating point operations are too expensive: https://ethereum.stackexchange.com/questions/8674/how-can-i-perform-float-type-division-in-solidity
    // So instead rather than doing x3.5 we need to x14 and then /4 (YES, multiply by 14 and then divide by 4)

    uint16 multiply;
    uint16 divide = 4;

    if (weiRaised < 100 ether) {
      multiply = 16;
    } else if (weiRaised < 150 ether) {
      multiply = 15;
    } else if (weiRaised < 200 ether) {
      multiply = 14;
    } else if (weiRaised < 250 ether) {
      multiply = 13;    
    } else if (weiRaised < 300 ether) {
      multiply = 12;
    } else if (weiRaised < 350 ether) {
      multiply = 11;
    } else if (weiRaised < 400 ether) {
      multiply = 10;
    } else if (weiRaised < 450 ether) {
      multiply = 9;    
    } else {
      multiply = 8;
    } 

    return _weiAmount.mul(rate).mul(multiply).div(divide);
  }

Judging by your other question - ICO Site Development, When should I transfer tokens to investors - you might be better off using some already existing platform.

3
  • Though I don't want to use Openzeppelin 2.x instead of current 4.x, but your _getTokenAmount function inspired me a clue. :) Thank you! Feb 23, 2023 at 21:19
  • Btw, how did you inform your investors how many tokens they will get on frontend before invoking _getTokenAmount function? Did you make the frontend invokes _contract.getWeiAmount() functions to pre-calculate their receivable token amount? Feb 23, 2023 at 21:48
  • Use any version you want, the ICO contracts are only in 2.x: github.com/OpenZeppelin/openzeppelin-contracts/commit/… About the front end... "Judging by your other question you might be better off using some already existing platform." - maybe I can help you. Message me privately. Feb 24, 2023 at 14:09
0

function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) {

// Floating point operations are too expensive: https://ethereum.stackexchange.com/questions/8674/how-can-i-perform-float-type-division-in-solidity
// So instead rather than doing x3.5 we need to x14 and then /4 (YES, multiply by 14 and then divide by 4)

uint16 multiply;
uint16 divide = 4;

if (weiRaised < 100 ether) {
  multiply = 16;
} else if (weiRaised < 150 ether) {
  multiply = 15;
} else if (weiRaised < 200 ether) {
  multiply = 14;
} else if (weiRaised < 250 ether) {
  multiply = 13;    
} else if (weiRaised < 300 ether) {
  multiply = 12;
} else if (weiRaised < 350 ether) {
  multiply = 11;
} else if (weiRaised < 400 ether) {
  multiply = 10;
} else if (weiRaised < 450 ether) {
  multiply = 9;    
} else {
  multiply = 8;
} 

return _weiAmount.mul(rate).mul(multiply).div(divide);

}

Can anyone explain why we are dividing by 4 instead of 1,2,3,5,6 etc.. Thanks for considering this question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.