m10io / tokeninc-smart-contracts

Ethereum Solidity Smart Contracts for Token, Inc.
3 stars 6 forks source link

Short-cut expensive fee calculation when fees are zero; #47

Open Ryanmtate opened 5 years ago

Ryanmtate commented 5 years ago

In instances where the fees are calculated to equal 0, it would make sense to bypass the setting of the value for the fee contract, thereby saving 20k on the gas costs; It also allows us to simply the contract interface to a uniform erc20 interface without having a secondary interface when fees would not exist.

address feeContract = lib.getFeeContract(proxyInstance);
uint fees = calculateFees(feeContract, amount);

if (fees > 0) {
   // update the balance for the fee contract;
   // if this is not called, will not pay 20k gas for setting the same balance value (i.e. you didn't add any fees to the balance, so why set it again?)
}

// update sender, receiver balances;

https://github.com/tokenio/tokeninc-smart-contracts/blob/7346eb641930004853de791cbe650d9dd07e8285/contracts/TokenIOERC20FeesApply.sol#L198

RostyslavBortmanAdoria commented 5 years ago

Yes, you are right. Good point, thanks I will create pool request soon