chore: configure prettier-solidity-plugin

This commit is contained in:
gitpusha 2020-10-15 20:04:08 +02:00 committed by Twin Fish
parent fc92050590
commit bb42fd15cf
13 changed files with 272 additions and 201 deletions

View File

@ -3,7 +3,3 @@
cache cache
assets assets
coverage coverage
# Solidity
contracts
#pre-compiles

View File

@ -1,11 +1,8 @@
{ {
"editor.defaultFormatter": "esbenp.prettier-vscode", "editor.defaultFormatter": "esbenp.prettier-vscode",
// Solidity // Solidity
"solidity.formatter": "none", "solidity.formatter": "prettier",
"solidity.linter": "solhint", "solidity.linter": "solhint",
"solidity.packageDefaultDependenciesContractsDirectory": "", "solidity.packageDefaultDependenciesContractsDirectory": "",
"solidity.packageDefaultDependenciesDirectory": "node_modules", "solidity.packageDefaultDependenciesDirectory": "node_modules"
"solidity.solhintRules": {
"quotes": ["error", "double"]
}
} }

View File

@ -25,34 +25,37 @@ contract ConditionCompareUintsFromTwoSources is GelatoConditionsStandard {
bytes calldata _sourceAData, bytes calldata _sourceAData,
bytes calldata _sourceBData, bytes calldata _sourceBData,
uint256 _minSpread uint256 _minSpread
) ) public pure virtual returns (bytes memory) {
public return
pure abi.encode(
virtual _sourceA,
returns (bytes memory) _sourceB,
{ _sourceAData,
return abi.encode(_sourceA, _sourceB, _sourceAData, _sourceBData, _minSpread); _sourceBData,
_minSpread
);
} }
/// @notice Gelato Standard Condition function. /// @notice Gelato Standard Condition function.
/// @dev Every Gelato Condition must have this function selector as entry point. /// @dev Every Gelato Condition must have this function selector as entry point.
/// @param _conditionData The encoded data from getConditionData() /// @param _conditionData The encoded data from getConditionData()
function ok(uint256, bytes calldata _conditionData, uint256) function ok(
public uint256,
view bytes calldata _conditionData,
virtual uint256
override ) public view virtual override returns (string memory) {
returns (string memory) (
{ address _sourceA,
(address _sourceA,
address _sourceB, address _sourceB,
bytes memory _sourceAData, bytes memory _sourceAData,
bytes memory _sourceBData, bytes memory _sourceBData,
uint256 _minSpread) = abi.decode( uint256 _minSpread
) = abi.decode(
_conditionData, _conditionData,
(address, address, bytes, bytes, uint256) (address, address, bytes, bytes, uint256)
); );
return compare(_sourceA, _sourceB, _sourceAData, _sourceBData, _minSpread); return
compare(_sourceA, _sourceB, _sourceAData, _sourceBData, _minSpread);
} }
/// @notice Compares 2 values from sourceA and sourceB to check if minSpread is there. /// @notice Compares 2 values from sourceA and sourceB to check if minSpread is there.
@ -72,16 +75,14 @@ contract ConditionCompareUintsFromTwoSources is GelatoConditionsStandard {
bytes memory _sourceAData, bytes memory _sourceAData,
bytes memory _sourceBData, bytes memory _sourceBData,
uint256 _minSpread uint256 _minSpread
) ) public view virtual returns (string memory) {
public
view
virtual
returns (string memory)
{
// Retrieve uint256 from sourceA // Retrieve uint256 from sourceA
(bool success, bytes memory returndata) = _sourceA.staticcall(_sourceAData); (bool success, bytes memory returndata) = _sourceA.staticcall(
_sourceAData
);
if (!success) { if (!success) {
return returndata.generateErrorString( return
returndata.generateErrorString(
"ConditionCompareTwoUints.compare._sourceA:" "ConditionCompareTwoUints.compare._sourceA:"
); );
} }
@ -90,7 +91,8 @@ contract ConditionCompareUintsFromTwoSources is GelatoConditionsStandard {
// Retrieve uint256 from sourceB // Retrieve uint256 from sourceB
(success, returndata) = _sourceB.staticcall(_sourceBData); (success, returndata) = _sourceB.staticcall(_sourceBData);
if (!success) { if (!success) {
return returndata.generateErrorString( return
returndata.generateErrorString(
"ConditionCompareTwoUints.compare._sourceB:" "ConditionCompareTwoUints.compare._sourceB:"
); );
} }

View File

@ -26,42 +26,57 @@ library GelatoBytes {
(bytes4(_bytes[3]) >> 24); (bytes4(_bytes[3]) >> 24);
} }
function revertWithErrorString(bytes memory _bytes, string memory _tracingInfo) function revertWithErrorString(
internal bytes memory _bytes,
pure string memory _tracingInfo
{ ) internal pure {
// 68: 32-location, 32-length, 4-ErrorSelector, UTF-8 err // 68: 32-location, 32-length, 4-ErrorSelector, UTF-8 err
if (_bytes.length % 32 == 4) { if (_bytes.length % 32 == 4) {
bytes4 selector; bytes4 selector;
assembly { selector := mload(add(0x20, _bytes)) } assembly {
if (selector == 0x08c379a0) { // Function selector for Error(string) selector := mload(add(0x20, _bytes))
assembly { _bytes := add(_bytes, 68) } }
if (selector == 0x08c379a0) {
// Function selector for Error(string)
assembly {
_bytes := add(_bytes, 68)
}
revert(string(abi.encodePacked(_tracingInfo, string(_bytes)))); revert(string(abi.encodePacked(_tracingInfo, string(_bytes))));
} else { } else {
revert(string(abi.encodePacked(_tracingInfo, "NoErrorSelector"))); revert(
string(abi.encodePacked(_tracingInfo, "NoErrorSelector"))
);
} }
} else { } else {
revert(string(abi.encodePacked(_tracingInfo, "UnexpectedReturndata"))); revert(
string(abi.encodePacked(_tracingInfo, "UnexpectedReturndata"))
);
} }
} }
function generateErrorString(bytes memory _bytes, string memory _tracingInfo) function generateErrorString(
internal bytes memory _bytes,
pure string memory _tracingInfo
returns (string memory) ) internal pure returns (string memory) {
{
// 68: 32-location, 32-length, 4-ErrorSelector, UTF-8 err // 68: 32-location, 32-length, 4-ErrorSelector, UTF-8 err
if (_bytes.length % 32 == 4) { if (_bytes.length % 32 == 4) {
bytes4 selector; bytes4 selector;
assembly { selector := mload(add(0x20, _bytes)) } assembly {
if (selector == 0x08c379a0) { // Function selector for Error(string) selector := mload(add(0x20, _bytes))
assembly { _bytes := add(_bytes, 68) } }
if (selector == 0x08c379a0) {
// Function selector for Error(string)
assembly {
_bytes := add(_bytes, 68)
}
return string(abi.encodePacked(_tracingInfo, string(_bytes))); return string(abi.encodePacked(_tracingInfo, string(_bytes)));
} else { } else {
return string(abi.encodePacked(_tracingInfo, "NoErrorSelector")); return
string(abi.encodePacked(_tracingInfo, "NoErrorSelector"));
} }
} else { } else {
return string(abi.encodePacked(_tracingInfo, "UnexpectedReturndata")); return
string(abi.encodePacked(_tracingInfo, "UnexpectedReturndata"));
} }
} }
} }

View File

@ -10,7 +10,10 @@ contract MockCDAI {
//uint256 public supplyRatePerSecond = 1000000000627937192491029810; // per second==2% annually //uint256 public supplyRatePerSecond = 1000000000627937192491029810; // per second==2% annually
uint256 public supplyRatePerSecond; uint256 public supplyRatePerSecond;
constructor(uint256 _sRPS) public { supplyRatePerSecond = _sRPS; }
constructor(uint256 _sRPS) public {
supplyRatePerSecond = _sRPS;
}
/// @dev Use this during tests to simulate changing CDAI.supplyRatePerBlock conditions /// @dev Use this during tests to simulate changing CDAI.supplyRatePerBlock conditions
/// @param _rate CDAI.supplyRatePerBlock but in seconds and 10**27 precision /// @param _rate CDAI.supplyRatePerBlock but in seconds and 10**27 precision

View File

@ -12,7 +12,10 @@ contract MockDSR {
/// uint256 public dsr = 1000000000627937192491029810; // per second==2% annually /// uint256 public dsr = 1000000000627937192491029810; // per second==2% annually
uint256 public dsr; uint256 public dsr;
constructor(uint256 _dsr) public { dsr = _dsr; }
constructor(uint256 _dsr) public {
dsr = _dsr;
}
/// @dev Use this during tests to simulate changing DSR conditions /// @dev Use this during tests to simulate changing DSR conditions
/// @param _dsr The dsr to set. /// @param _dsr The dsr to set.

View File

@ -27,17 +27,18 @@
"ethers": "5.0.17", "ethers": "5.0.17",
"husky": ">=4", "husky": ">=4",
"lint-staged": ">=10", "lint-staged": ">=10",
"prettier": "2.1.2" "prettier": "2.1.2",
"prettier-plugin-solidity": "1.0.0-alpha.59"
}, },
"dependencies": {}, "dependencies": {},
"husky": { "husky": {
"hooks": { "hooks": {
"pre-commit": "yarn compile; lint-staged;", "pre-commit": "yarn compile; lint-staged;",
"pre-push": "git fetch origin && HUSKY_SKIP_HOOKS=1 git rebase origin/master && yarn compile && lint-staged; yarn test" "pre-push": "git fetch origin && HUSKY_SKIP_HOOKS=1 git rebase origin/master && yarn compile && yarn format && yarn test"
} }
}, },
"lint-staged": { "lint-staged": {
"*.js": "eslint --cache --fix", "*.js": "eslint --cache --fix",
"*.{js,css,md}": "prettier --write" "*.{js,sol,css,md}": "prettier --write"
} }
} }

View File

@ -671,6 +671,11 @@
resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.5.2.tgz#4d74670ead39e4f4fdab605a393ba8ea2390a2c4" resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.5.2.tgz#4d74670ead39e4f4fdab605a393ba8ea2390a2c4"
integrity sha512-uRyvnvVYmgNmTBpWDbBsH/0kPESQhQpEc4KsvMRLVzFJ1o1s0uIv0Y6Y9IB5vI1Dwz2CbS4X/y4Wyw/75cTFnQ== integrity sha512-uRyvnvVYmgNmTBpWDbBsH/0kPESQhQpEc4KsvMRLVzFJ1o1s0uIv0Y6Y9IB5vI1Dwz2CbS4X/y4Wyw/75cTFnQ==
"@solidity-parser/parser@^0.8.1":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.8.1.tgz#1b606578af86b9ad10755409804a6ba83f9ce8a4"
integrity sha512-DF7H6T8I4lo2IZOE2NZwt3631T8j1gjpQLjmvY2xBNK50c4ltslR4XPKwT6RkeSd4+xCAK0GHC/k7sbRDBE4Yw==
"@szmarczak/http-timer@^1.1.2": "@szmarczak/http-timer@^1.1.2":
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421" resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421"
@ -2656,6 +2661,11 @@ diffie-hellman@^5.0.0:
miller-rabin "^4.0.0" miller-rabin "^4.0.0"
randombytes "^2.0.0" randombytes "^2.0.0"
dir-to-object@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/dir-to-object/-/dir-to-object-2.0.0.tgz#29723e9bd1c3e58e4f307bd04ff634c0370c8f8a"
integrity sha512-sXs0JKIhymON7T1UZuO2Ud6VTNAx/VTBXIl4+3mjb2RgfOpt+hectX0x04YqPOPdkeOAKoJuKqwqnXXURNPNEA==
doctrine@^3.0.0: doctrine@^3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961"
@ -2744,6 +2754,11 @@ emoji-regex@^8.0.0:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==
emoji-regex@^9.0.0:
version "9.1.1"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.1.1.tgz#1d5ffce26d8191e6c3f3a9d27987b1c5bba7d20a"
integrity sha512-AaWyDiNO9rbtMIcGl7tdxMcNu8SOLaDLxmQEFT5JhgKufOJzPPkYmgN2QwqTgw4doWMZZQttC6sUWVQjb+1VdA==
encodeurl@~1.0.2: encodeurl@~1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
@ -2880,6 +2895,11 @@ escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
escape-string-regexp@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==
eslint-config-prettier@6.12.0: eslint-config-prettier@6.12.0:
version "6.12.0" version "6.12.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.12.0.tgz#9eb2bccff727db1c52104f0b49e87ea46605a0d2" resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.12.0.tgz#9eb2bccff727db1c52104f0b49e87ea46605a0d2"
@ -2959,6 +2979,13 @@ espree@^7.3.0:
acorn-jsx "^5.2.0" acorn-jsx "^5.2.0"
eslint-visitor-keys "^1.3.0" eslint-visitor-keys "^1.3.0"
esprima-extract-comments@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/esprima-extract-comments/-/esprima-extract-comments-1.1.0.tgz#0dacab567a5900240de6d344cf18c33617becbc9"
integrity sha512-sBQUnvJwpeE9QnPrxh7dpI/dp67erYG4WXEAreAMoelPRpMR7NWb4YtwRPn9b+H1uLQKl/qS8WYmyaljTpjIsw==
dependencies:
esprima "^4.0.0"
esprima@^4.0.0: esprima@^4.0.0:
version "4.0.1" version "4.0.1"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
@ -3594,6 +3621,14 @@ extglob@^2.0.4:
snapdragon "^0.8.1" snapdragon "^0.8.1"
to-regex "^3.0.1" to-regex "^3.0.1"
extract-comments@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/extract-comments/-/extract-comments-1.1.0.tgz#b90bca033a056bd69b8ba1c6b6b120fc2ee95c18"
integrity sha512-dzbZV2AdSSVW/4E7Ti5hZdHWbA+Z80RJsJhr5uiL10oyjl/gy7/o+HI1HwK4/WSZhlq4SNKU3oUzXlM13Qx02Q==
dependencies:
esprima-extract-comments "^1.1.0"
parse-code-context "^1.0.0"
extsprintf@1.3.0: extsprintf@1.3.0:
version "1.3.0" version "1.3.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05" resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
@ -6075,6 +6110,11 @@ parse-asn1@^5.0.0, parse-asn1@^5.1.5:
pbkdf2 "^3.0.3" pbkdf2 "^3.0.3"
safe-buffer "^5.1.1" safe-buffer "^5.1.1"
parse-code-context@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/parse-code-context/-/parse-code-context-1.0.0.tgz#718c295c593d0d19a37f898473268cc75e98de1e"
integrity sha512-OZQaqKaQnR21iqhlnPfVisFjBWjhnMl5J9MgbP8xC+EwoVqbXrq78lp+9Zb3ahmLzrIX5Us/qbvBnaS3hkH6OA==
parse-headers@^2.0.0: parse-headers@^2.0.0:
version "2.0.3" version "2.0.3"
resolved "https://registry.yarnpkg.com/parse-headers/-/parse-headers-2.0.3.tgz#5e8e7512383d140ba02f0c7aa9f49b4399c92515" resolved "https://registry.yarnpkg.com/parse-headers/-/parse-headers-2.0.3.tgz#5e8e7512383d140ba02f0c7aa9f49b4399c92515"
@ -6288,7 +6328,21 @@ prepend-http@^2.0.0:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897" resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc= integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
prettier@2.1.2: prettier-plugin-solidity@1.0.0-alpha.59:
version "1.0.0-alpha.59"
resolved "https://registry.yarnpkg.com/prettier-plugin-solidity/-/prettier-plugin-solidity-1.0.0-alpha.59.tgz#b0cf82fb068537d152d0bc417588d08e952a56c6"
integrity sha512-6cE0SWaiYCBoJY4clCfsbWlEEOU4K42Ny6Tg4Jwprgts/q+AVfYnPQ5coRs7zIjYzc4RVspifYPeh+oAg8RpLw==
dependencies:
"@solidity-parser/parser" "^0.8.1"
dir-to-object "^2.0.0"
emoji-regex "^9.0.0"
escape-string-regexp "^4.0.0"
extract-comments "^1.1.0"
prettier "^2.0.5"
semver "^7.3.2"
string-width "^4.2.0"
prettier@2.1.2, prettier@^2.0.5:
version "2.1.2" version "2.1.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5" resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg== integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
@ -6875,7 +6929,7 @@ semver@^6.3.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
semver@^7.2.1: semver@^7.2.1, semver@^7.3.2:
version "7.3.2" version "7.3.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ== integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==