Skip to content

Commit

Permalink
Optimise errors to lower gas burning.
Browse files Browse the repository at this point in the history
Errors returned from reverted transactions still burn gas proportionally to the error message length. Optimised error messages save gas from failed transactions lowering the wasted cost.
  • Loading branch information
Jiri Malek committed Aug 10, 2020
1 parent 033a9d4 commit 309e7fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -11,3 +11,6 @@ to conform with the EVM implemented in the Opera block chain.
Consult the [Truffle](https://www.trufflesuite.com)
documents to find out how to build and deploy
the smart contract implemented here.

In general, all you should need to do is to call `truffle build`
to get the deployable contract code and ABI inside `build/` folder.
6 changes: 3 additions & 3 deletions contracts/FantomCollateral.sol
Expand Up @@ -255,7 +255,7 @@ contract FantomCollateral is Ownable, ReentrancyGuard {
} else {
// on native tokens, the designated amount deposited must match
// the native tokens attached to this transaction
require(msg.value == _amount, "invalid native tokens amount received");
require(msg.value == _amount, "invalid amount received");
}

// update the collateral value storage
Expand Down Expand Up @@ -299,7 +299,7 @@ contract FantomCollateral is Ownable, ReentrancyGuard {
_collateralByTokens[_token][msg.sender].sub(_amount, "withdraw exceeds balance");

_collateralByUsers[msg.sender][_token] =
_collateralByUsers[msg.sender][_token].sub(_amount, "withdraw amount exceeds balance");
_collateralByUsers[msg.sender][_token].sub(_amount, "withdraw exceeds balance");

// calculate the collateral and debt values in ref. denomination
// for the current exchange rate and balance amounts
Expand All @@ -314,7 +314,7 @@ contract FantomCollateral is Ownable, ReentrancyGuard {

// does the new state obey the enforced minimal collateral to debt ratio?
// if the check fails, the collateral withdraw is rejected
require(cCollateralValue >= minCollateralValue, "collateral value below allowed ratio");
require(cCollateralValue >= minCollateralValue, "value below allowed ratio");

// the new collateral value is ok; update the stored collateral and debt values
_collateralValue[msg.sender] = cCollateralValue;
Expand Down
6 changes: 3 additions & 3 deletions contracts/FantomFMint.sol
Expand Up @@ -92,12 +92,12 @@ contract FantomFMint is Ownable, ReentrancyGuard, FantomCollateral {
require(_amount > 0, "non-zero amount expected");

// native tokens can not be minted
require(_token != fMintNativeToken(), "native token is not mintable");
require(_token != fMintNativeToken(), "native tokens not mintable");

// make sure there is some collateral established by this user
// we still need to re-calculate the current value though, since the value
// could have changed due to exchange rate fluctuation
require(_collateralValue[msg.sender] > 0, "collateral must be built");
require(_collateralValue[msg.sender] > 0, "missing collateral");

// what is the value of the borrowed token?
uint256 tokenValue = IPriceOracle(fMintPriceOracle()).getPrice(_token);
Expand Down Expand Up @@ -159,7 +159,7 @@ contract FantomFMint is Ownable, ReentrancyGuard, FantomCollateral {

// native tokens can not be minted through this contract
// so there can not be any debt to be repaid on them
require(_token != fMintNativeToken(), "native token not mintable");
require(_token != fMintNativeToken(), "native tokens not mintable");

// subtract the returned amount from the user debt
_debtByTokens[_token][msg.sender] = _debtByTokens[_token][msg.sender].sub(_amount, "insufficient debt outstanding");
Expand Down

0 comments on commit 309e7fe

Please sign in to comment.