Skip to content

Commit 38b4a1b

Browse files
committed
Initial commit
0 parents  commit 38b4a1b

21 files changed

+12150
-0
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
node_modules
3+
coverage

.eslintrc.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
👋 Hi! This file was autogenerated by tslint-to-eslint-config.
3+
https://github.com/typescript-eslint/tslint-to-eslint-config
4+
5+
It represents the closest reasonable ESLint configuration to this
6+
project's original TSLint configuration.
7+
8+
We recommend eventually switching this configuration to extend from
9+
the recommended rulesets in typescript-eslint.
10+
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
11+
12+
Happy linting! 💖
13+
*/
14+
module.exports = {
15+
"env": {
16+
"es6": true,
17+
"node": true
18+
},
19+
"extends": [
20+
"plugin:@typescript-eslint/recommended",
21+
"plugin:@typescript-eslint/recommended-requiring-type-checking"
22+
],
23+
"parser": "@typescript-eslint/parser",
24+
"parserOptions": {
25+
"project": "tsconfig.json",
26+
"sourceType": "module"
27+
},
28+
"plugins": [
29+
"@typescript-eslint"
30+
]
31+
};

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.sol linguist-language=Solidity

.gitignore

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# documentation
4+
docs/
5+
6+
# truffle build directory
7+
build/
8+
9+
# misc
10+
.DS_Store
11+
.env.local
12+
.env.development.local
13+
.env.test.local
14+
.env.production.local
15+
16+
# Logs
17+
*.log
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
logs/
22+
23+
# lol macs
24+
.DS_Store/
25+
26+
# Runtime data
27+
pids
28+
*.pid
29+
*.seed
30+
*.pid.lock
31+
32+
# Coverage directory used by tools like istanbul
33+
coverage/
34+
coverage.json
35+
coverageEnv
36+
37+
# Directory for instrumented libs generated by jscoverage/JSCover
38+
lib-cov
39+
40+
# Coverage directory used by tools like istanbul
41+
coverage
42+
coverage.json
43+
44+
# nyc test coverage
45+
.nyc_output
46+
47+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
48+
.grunt
49+
50+
# Bower dependency directory (https://bower.io/)
51+
bower_components
52+
53+
# node-waf configuration
54+
.lock-wscript
55+
56+
# Compiled binary addons (https://nodejs.org/api/addons.html)
57+
build/Release
58+
59+
# Dependency directories
60+
node_modules/
61+
jspm_packages/
62+
63+
# TypeScript v1 declaration files
64+
typings/
65+
66+
# Optional npm cache directory
67+
.npm
68+
69+
# Optional eslint cache
70+
.eslintcache
71+
72+
# Optional REPL history
73+
.node_repl_history
74+
75+
# Output of 'npm pack'
76+
*.tgz
77+
78+
# Yarn Integrity file
79+
.yarn-integrity
80+
81+
# dotenv environment variables file
82+
.env
83+
.env.test
84+
85+
# parcel-bundler cache (https://parceljs.org/)
86+
.cache
87+
88+
# next.js build output
89+
.next
90+
91+
# nuxt.js build output
92+
.nuxt
93+
94+
# vuepress build output
95+
.vuepress/dist
96+
97+
# Serverless directories
98+
.serverless/
99+
100+
# FuseBox cache
101+
.fusebox/
102+
103+
# DynamoDB Local files
104+
.dynamodb/
105+
106+
# the .secret
107+
.secret
108+
109+
# oz session
110+
.openzeppelin/.session
111+
112+
# coverage
113+
.coverage_artifacts/
114+
.coverage_contracts/
115+
116+
# network
117+
**/db/geth
118+
**/db/history
119+
**/db_ganache/
120+
121+
# ignore types
122+
types/
123+
124+
geth/

.solcover.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
skipFiles: [
3+
]
4+
}

.soliumignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/*
2+
contracts/Migrations.sol

.soliumrc.json

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"extends": "solium:all",
3+
"plugins": [
4+
"security"
5+
],
6+
"rules": {
7+
"error-reason": "off",
8+
"indentation": [
9+
"error",
10+
4
11+
],
12+
"lbrace": "off",
13+
"linebreak-style": [
14+
"error",
15+
"unix"
16+
],
17+
"max-len": [
18+
"error",
19+
79
20+
],
21+
"no-constant": [
22+
"error"
23+
],
24+
"no-empty-blocks": "off",
25+
"quotes": [
26+
"error",
27+
"double"
28+
],
29+
"uppercase": "off",
30+
"visibility-first": "error",
31+
"security/enforce-explicit-visibility": [
32+
"error"
33+
],
34+
"security/no-block-members": [
35+
"warning"
36+
],
37+
"security/no-inline-assembly": [
38+
"warning"
39+
],
40+
"imports-on-top": "warning",
41+
"variable-declarations": "warning",
42+
"array-declarations": "warning",
43+
"operator-whitespace": "warning",
44+
"function-whitespace": "warning",
45+
"semicolon-whitespace": "warning",
46+
"comma-whitespace": "warning",
47+
"conditionals-whitespace": "warning",
48+
"arg-overflow": [
49+
"warning",
50+
3
51+
]
52+
}
53+
}

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# DecimalMath
2+
3+
Smart contract implementing fixed point math operations using structs for type checking.
4+
5+
## Contributing
6+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
7+
8+
Please make sure to update tests as appropriate.
9+
10+
## License
11+
[GPL-3.0](LICENSE)

codechecks.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
checks:
2+
- name: eth-gas-reporter/codechecks

contracts/DecimalMath.sol

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity ^0.6.10;
3+
pragma experimental ABIEncoderV2;
4+
import "@openzeppelin/contracts/math/SafeMath.sol";
5+
6+
7+
/// @dev Implements simple fixed point math mul and div operations for 27 decimals.
8+
contract DecimalMath {
9+
using SafeMath for uint256;
10+
11+
uint256 constant public UNIT = 1000000000000000000000000000;
12+
13+
struct UFixed {
14+
uint256 value;
15+
}
16+
17+
/// @dev Creates a fixed point number from an unsigend integer. `toUFixed(1) = 10^-27`
18+
/// Converting from fixed point to integer
19+
function toUFixed(uint256 x) public pure returns (UFixed memory) {
20+
return UFixed({
21+
value: x
22+
});
23+
}
24+
25+
/// @dev Multiplies x and y.
26+
/// @param x A fixed point number.
27+
/// @param y An unsigned integer.
28+
/// @return A fixed point number.
29+
function muld(UFixed memory x, uint256 y) public pure returns (UFixed memory) {
30+
return UFixed({
31+
value: x.value.mul(y).div(UNIT)
32+
});
33+
}
34+
35+
/// @dev Multiplies x and y.
36+
/// @param x A fixed point number.
37+
/// @param y A fixed point number.
38+
/// @return A fixed point number.
39+
function muld(UFixed memory x, UFixed memory y) public pure returns (UFixed memory) {
40+
return muld(x, y.value);
41+
}
42+
43+
/// @dev Divides x by y.
44+
/// @param x A fixed point number.
45+
/// @param y An unsigned integer.
46+
/// @return A fixed point number.
47+
function divd(UFixed memory x, uint256 y) public pure returns (UFixed memory) {
48+
return UFixed({
49+
value: x.value.mul(UNIT).div(y)
50+
});
51+
}
52+
53+
/// @dev Divides x by y.
54+
/// @param x A fixed point number.
55+
/// @param y A fixed point number.
56+
/// @return A fixed point number.
57+
function divd(UFixed memory x, UFixed memory y) public pure returns (UFixed memory) {
58+
return divd(x, y.value);
59+
}
60+
61+
/// @dev Adds x and y.
62+
/// @param x A fixed point number.
63+
/// @param y A fixed point number.
64+
/// @return A fixed point number.
65+
function addd(UFixed memory x, UFixed memory y) public pure returns (UFixed memory) {
66+
return UFixed({
67+
value: x.value.add(y.value)
68+
});
69+
}
70+
71+
/// @dev Subtracts x and y.
72+
/// @param x A fixed point number.
73+
/// @param y A fixed point number.
74+
/// @return A fixed point number.
75+
function subd(UFixed memory x, UFixed memory y) public pure returns (UFixed memory) {
76+
return UFixed({
77+
value: x.value.sub(y.value)
78+
});
79+
}
80+
81+
/// @dev Divides x between y, rounding up to the closest representable number.
82+
/// @param x A fixed point number.
83+
/// @param y An unsigned integer.
84+
/// @return A fixed point number.
85+
function divdrup(UFixed memory x, uint256 y) public pure returns (UFixed memory)
86+
{
87+
uint256 z = x.value.mul(10000000000000000000000000000).div(y); // RAY * 10
88+
if (z % 10 > 0) return UFixed({ value: z / 10 + 1 });
89+
else return UFixed({ value: z / 10 });
90+
}
91+
92+
/// @dev Divides x between y, rounding up to the closest representable number.
93+
/// @param x A fixed point number.
94+
/// @param y A fixed point number.
95+
/// @return A fixed point number.
96+
function divdrup(UFixed memory x, UFixed memory y) public pure returns (UFixed memory)
97+
{
98+
return divdrup(x, y.value);
99+
}
100+
}

contracts/Migrations.sol

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity ^0.6.10;
3+
4+
contract Migrations {
5+
address public owner;
6+
uint public last_completed_migration;
7+
8+
constructor() public {
9+
owner = msg.sender;
10+
}
11+
12+
modifier restricted() {
13+
if (msg.sender == owner)
14+
_;
15+
}
16+
17+
function setCompleted(uint completed) public restricted {
18+
last_completed_migration = completed;
19+
}
20+
21+
function upgrade(address new_address) public restricted {
22+
Migrations upgraded = Migrations(new_address);
23+
upgraded.setCompleted(last_completed_migration);
24+
}
25+
}

migrations/1_initial_migration.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const Migrations = artifacts.require('./Migrations.sol');
2+
3+
module.exports = (deployer) => {
4+
deployer.deploy(Migrations);
5+
};

migrations/2_deploy_contracts.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const DecimalMath = artifacts.require('./DecimalMath.sol');
2+
3+
module.exports = async (deployer, network, accounts) => {
4+
await deployer.deploy(DecimalMath);
5+
}

0 commit comments

Comments
 (0)