Skip to content

Commit

Permalink
runs prettier against codebase (#38)
Browse files Browse the repository at this point in the history
* runs prettier against codebase

* runs prettier against all contracts
  • Loading branch information
Travis Mathis authored Jun 5, 2020
1 parent f8ae70f commit 844e723
Show file tree
Hide file tree
Showing 46 changed files with 2,790 additions and 2,092 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"tabWidth": 2,
"useTabs": false
"useTabs": false,
"printWidth": 100
}
96 changes: 40 additions & 56 deletions contracts/Math.sol
Original file line number Diff line number Diff line change
@@ -1,63 +1,47 @@
library Math {
uint256 internal constant BONE = 10**18;

uint internal constant BONE = 10**18;
// Add two numbers together checking for overflows
function badd(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "ERR_ADD_OVERFLOW");
return c;
}

// Add two numbers together checking for overflows
function badd(uint a, uint b)
internal pure
returns (uint)
{
uint c = a + b;
require(c >= a, "ERR_ADD_OVERFLOW");
return c;
// subtract two numbers and return diffecerence when it underflows
function bsubSign(uint256 a, uint256 b) internal pure returns (uint256, bool) {
if (a >= b) {
return (a - b, false);
} else {
return (b - a, true);
}
}

// subtract two numbers and return diffecerence when it underflows
function bsubSign(uint a, uint b)
internal pure
returns (uint, bool)
{
if (a >= b) {
return (a - b, false);
} else {
return (b - a, true);
}
}
// Subtract two numbers checking for underflows
function bsub(uint256 a, uint256 b) internal pure returns (uint256) {
(uint256 c, bool flag) = bsubSign(a, b);
require(!flag, "ERR_SUB_UNDERFLOW");
return c;
}

// Subtract two numbers checking for underflows
function bsub(uint a, uint b)
internal pure
returns (uint)
{
(uint c, bool flag) = bsubSign(a, b);
require(!flag, "ERR_SUB_UNDERFLOW");
return c;
}
// Multiply two 18 decimals numbers
function bmul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c0 = a * b;
require(a == 0 || c0 / a == b, "ERR_MUL_OVERFLOW");
uint256 c1 = c0 + (BONE / 2);
require(c1 >= c0, "ERR_MUL_OVERFLOW");
uint256 c2 = c1 / BONE;
return c2;
}

// Multiply two 18 decimals numbers
function bmul(uint a, uint b)
internal pure
returns (uint)
{
uint c0 = a * b;
require(a == 0 || c0 / a == b, "ERR_MUL_OVERFLOW");
uint c1 = c0 + (BONE / 2);
require(c1 >= c0, "ERR_MUL_OVERFLOW");
uint c2 = c1 / BONE;
return c2;
}

// Divide two 18 decimals numbers
function bdiv(uint a, uint b)
internal pure
returns (uint)
{
require(b != 0, "ERR_DIV_ZERO");
uint c0 = a * BONE;
require(a == 0 || c0 / a == BONE, "ERR_DIV_INTERNAL"); // bmul overflow
uint c1 = c0 + (b / 2);
require(c1 >= c0, "ERR_DIV_INTERNAL"); // badd require
uint c2 = c1 / b;
return c2;
}
}
// Divide two 18 decimals numbers
function bdiv(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "ERR_DIV_ZERO");
uint256 c0 = a * BONE;
require(a == 0 || c0 / a == BONE, "ERR_DIV_INTERNAL"); // bmul overflow
uint256 c1 = c0 + (b / 2);
require(c1 >= c0, "ERR_DIV_INTERNAL"); // badd require
uint256 c2 = c1 / b;
return c2;
}
}
55 changes: 27 additions & 28 deletions contracts/Ownable.sol
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
pragma solidity 0.6.4;


// TODO move this generic contract to a seperate repo with all generic smart contracts

contract Ownable {
bytes32 public constant oSlot = keccak256("Ownable.storage.location");

bytes32 constant public oSlot = keccak256("Ownable.storage.location");

event OwnerChanged(address indexed previousOwner, address indexed newOwner);
event OwnerChanged(address indexed previousOwner, address indexed newOwner);

// Ownable struct
struct os {
address owner;
}
// Ownable struct
struct os {
address owner;
}

modifier onlyOwner(){
require(msg.sender == los().owner, "Ownable.onlyOwner: msg.sender not owner");
_;
}
modifier onlyOwner() {
require(msg.sender == los().owner, "Ownable.onlyOwner: msg.sender not owner");
_;
}

/**
/**
@notice Transfer ownership to a new address
@param _newOwner Address of the new owner
*/
function transferOwnership(address _newOwner) onlyOwner external {
_setOwner(_newOwner);
}
function transferOwnership(address _newOwner) external onlyOwner {
_setOwner(_newOwner);
}

/**
/**
@notice Internal method to set the owner
@param _newOwner Address of the new owner
*/
function _setOwner(address _newOwner) internal {
emit OwnerChanged(los().owner, _newOwner);
los().owner = _newOwner;
}
function _setOwner(address _newOwner) internal {
emit OwnerChanged(los().owner, _newOwner);
los().owner = _newOwner;
}

/**
/**
@notice Load ownable storage
@return s Storage pointer to the Ownable storage struct
*/
function los() internal pure returns (os storage s) {
bytes32 loc = oSlot;
assembly {
s_slot := loc
}
function los() internal pure returns (os storage s) {
bytes32 loc = oSlot;
assembly {
s_slot := loc
}

}
}
}
Loading

0 comments on commit 844e723

Please sign in to comment.