This is an edge case - in practice if everyone sells their tokens its probably OK that the contract is dead. However it would be nice to have a work around for this.
Proposed solution:
if totalSupply and poolBalance are 0 use a function similar to calculatePurchaceReturn to compute the number of tokens you would need to sell if you reduce the poolBalance from intialPoolBalance (poolBalance the contract was initialized with) to msg.value.
psudo code:
if ( tokenSupply_ == 0 || poolBalance == 0 ) {
uint256 tokenDiff = calculateTokenSaleReturn(
initialSupply,
initialPoolBalance,
reserveRatio,
intialPoolBalance);
uint256 tokensToMint = initialSupply - tokenDiff;
}
additional note - should probably also do this if tokenSupply < minTokenSupply or poolsBalance < minPoolBalance because BancorFormula behaves unpredictably with very small amounts.
This is an edge case - in practice if everyone sells their tokens its probably OK that the contract is dead. However it would be nice to have a work around for this.
Proposed solution:
if
totalSupplyandpoolBalanceare 0 use a function similar tocalculatePurchaceReturnto compute the number of tokens you would need to sell if you reduce thepoolBalancefromintialPoolBalance(poolBalancethe contract was initialized with) tomsg.value.psudo code:
additional note - should probably also do this if
tokenSupply < minTokenSupplyorpoolsBalance < minPoolBalancebecause BancorFormula behaves unpredictably with very small amounts.