prettier-plugin-solidity 1.0.0-beta.6 → 1.0.0-dev.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +5 -0
- package/.github/FUNDING.yml +1 -0
- package/.github/dependabot.yml +23 -0
- package/.github/workflows/CI.yml +83 -0
- package/.nvmrc +1 -1
- package/.prettierignore +4 -1
- package/CODE_OF_CONDUCT.md +1 -1
- package/Foo.sol +404 -0
- package/HOW_TO_PUBLISH.md +2 -2
- package/LICENSE +1 -1
- package/README.md +220 -28
- package/jest.config.js +16 -4
- package/package.json +34 -22
- package/scripts/makeData.js +2 -1
- package/src/binary-operator-printers/arithmetic.js +9 -11
- package/src/binary-operator-printers/assignment.js +10 -11
- package/src/binary-operator-printers/bit.js +1 -1
- package/src/binary-operator-printers/comparison.js +8 -10
- package/src/binary-operator-printers/exponentiation.js +8 -10
- package/src/binary-operator-printers/index.js +8 -8
- package/src/binary-operator-printers/logical.js +8 -10
- package/src/binary-operator-printers/shift.js +1 -1
- package/src/clean.js +1 -1
- package/src/comments/handlers/ContractDefinition.js +8 -6
- package/src/comments/printer.js +6 -6
- package/src/index.js +8 -3
- package/src/loc.js +3 -3
- package/src/nodes/ArrayTypeName.js +6 -13
- package/src/nodes/AssemblyAssignment.js +1 -1
- package/src/nodes/AssemblyBlock.js +13 -14
- package/src/nodes/AssemblyCall.js +2 -8
- package/src/nodes/AssemblyCase.js +5 -12
- package/src/nodes/AssemblyFor.js +1 -1
- package/src/nodes/AssemblyFunctionDefinition.js +24 -25
- package/src/nodes/AssemblyIf.js +6 -13
- package/src/nodes/AssemblyLocalDefinition.js +3 -3
- package/src/nodes/AssemblyMemberAccess.js +5 -12
- package/src/nodes/AssemblySwitch.js +8 -14
- package/src/nodes/Block.js +10 -12
- package/src/nodes/Break.js +5 -0
- package/src/nodes/CatchClause.js +7 -10
- package/src/nodes/Conditional.js +12 -16
- package/src/nodes/ContractDefinition.js +17 -20
- package/src/nodes/CustomErrorDefinition.js +18 -0
- package/src/nodes/DoWhileStatement.js +9 -16
- package/src/nodes/ElementaryTypeName.js +2 -8
- package/src/nodes/EmitStatement.js +1 -8
- package/src/nodes/EnumDefinition.js +12 -14
- package/src/nodes/EventDefinition.js +9 -16
- package/src/nodes/ExpressionStatement.js +3 -3
- package/src/nodes/FileLevelConstant.js +8 -15
- package/src/nodes/ForStatement.js +24 -25
- package/src/nodes/FunctionCall.js +51 -32
- package/src/nodes/FunctionDefinition.js +70 -47
- package/src/nodes/FunctionTypeName.js +18 -21
- package/src/nodes/HexLiteral.js +1 -1
- package/src/nodes/IfStatement.js +10 -12
- package/src/nodes/ImportDirective.js +35 -12
- package/src/nodes/IndexAccess.js +29 -13
- package/src/nodes/IndexRangeAccess.js +8 -15
- package/src/nodes/InheritanceSpecifier.js +5 -9
- package/src/nodes/InlineAssemblyStatement.js +1 -7
- package/src/nodes/LabelDefinition.js +3 -3
- package/src/nodes/Mapping.js +7 -14
- package/src/nodes/MemberAccess.js +111 -14
- package/src/nodes/ModifierDefinition.js +29 -32
- package/src/nodes/ModifierInvocation.js +7 -9
- package/src/nodes/NameValueExpression.js +6 -13
- package/src/nodes/NameValueList.js +3 -3
- package/src/nodes/NewExpression.js +1 -7
- package/src/nodes/NumberLiteral.js +1 -7
- package/src/nodes/PragmaDirective.js +1 -20
- package/src/nodes/ReturnStatement.js +9 -6
- package/src/nodes/RevertStatement.js +5 -0
- package/src/nodes/SourceUnit.js +6 -4
- package/src/nodes/StateVariableDeclaration.js +9 -12
- package/src/nodes/StringLiteral.js +6 -8
- package/src/nodes/StructDefinition.js +13 -14
- package/src/nodes/TryStatement.js +5 -5
- package/src/nodes/TupleExpression.js +7 -9
- package/src/nodes/TypeDefinition.js +5 -0
- package/src/nodes/UnaryOperation.js +3 -9
- package/src/nodes/UncheckedStatement.js +3 -3
- package/src/nodes/UsingForDeclaration.js +7 -14
- package/src/nodes/VariableDeclaration.js +19 -23
- package/src/nodes/VariableDeclarationStatement.js +21 -15
- package/src/nodes/WhileStatement.js +8 -15
- package/src/nodes/index.js +72 -68
- package/src/nodes/print-comments.js +6 -3
- package/src/nodes/print-preserving-empty-lines.js +10 -4
- package/src/nodes/print-separated-item.js +3 -3
- package/src/nodes/print-separated-list.js +4 -11
- package/src/options.js +47 -3
- package/src/parser.js +70 -4
- package/src/prettier-comments/common/util.js +3 -4
- package/src/prettier-comments/language-js/comments.js +1 -1
- package/src/printer.js +18 -2
- package/tests/config/.prettierrc +5 -0
- package/tests/config/format-test.js +458 -0
- package/tests/config/require-prettier.js +5 -0
- package/tests/config/require-standalone.js +25 -0
- package/tests/config/setup.js +7 -0
- package/tests/config/utils/check-parsers.js +207 -0
- package/tests/config/utils/compile-contract.js +36 -0
- package/tests/config/utils/consistent-end-of-line.js +13 -0
- package/tests/config/utils/create-snapshot.js +98 -0
- package/tests/config/utils/stringify-options-for-title.js +15 -0
- package/tests/config/utils/visualize-end-of-line.js +18 -0
- package/tests/config/utils/visualize-range.js +40 -0
- package/tests/{AddressPayable → format/AddressPayable}/AddressPayable.sol +0 -0
- package/tests/{AddressPayable → format/AddressPayable}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/AddressPayable/jsfmt.spec.js +1 -0
- package/tests/{AllSolidityFeatures → format/AllSolidityFeatures}/AllSolidityFeatures.sol +10 -0
- package/tests/{AllSolidityFeatures → format/AllSolidityFeatures}/__snapshots__/jsfmt.spec.js.snap +49 -6
- package/tests/format/AllSolidityFeatures/jsfmt.spec.js +1 -0
- package/tests/{Arrays → format/Arrays}/Arrays.sol +8 -0
- package/tests/{Arrays → format/Arrays}/__snapshots__/jsfmt.spec.js.snap +29 -4
- package/tests/format/Arrays/jsfmt.spec.js +1 -0
- package/tests/{Assembly → format/Assembly}/Assembly.sol +9 -0
- package/tests/{Assembly → format/Assembly}/__snapshots__/jsfmt.spec.js.snap +42 -18
- package/tests/format/Assembly/jsfmt.spec.js +1 -0
- package/tests/{BasicIterator → format/BasicIterator}/BasicIterator.sol +0 -0
- package/tests/{BasicIterator → format/BasicIterator}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/BasicIterator/jsfmt.spec.js +1 -0
- package/tests/{BinaryOperators → format/BinaryOperators}/BinaryOperators.sol +0 -0
- package/tests/{BinaryOperators → format/BinaryOperators}/Parentheses.sol +0 -0
- package/tests/{BinaryOperators → format/BinaryOperators}/__snapshots__/jsfmt.spec.js.snap +19 -5
- package/tests/format/BinaryOperators/jsfmt.spec.js +1 -0
- package/tests/format/BreakingChangesV0.7.4/BreakingChangesV0.7.4.sol +9 -0
- package/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap +198 -0
- package/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js +14 -0
- package/tests/format/BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol +43 -0
- package/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap +815 -0
- package/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js +26 -0
- package/tests/{Comments → format/Comments}/Comments.sol +19 -0
- package/tests/{Comments → format/Comments}/__snapshots__/jsfmt.spec.js.snap +49 -2
- package/tests/format/Comments/jsfmt.spec.js +1 -0
- package/tests/{Conditional → format/Conditional}/Conditional.sol +0 -0
- package/tests/{Conditional → format/Conditional}/__snapshots__/jsfmt.spec.js.snap +12 -4
- package/tests/format/Conditional/jsfmt.spec.js +1 -0
- package/tests/{Constructors → format/Constructors}/Constructors.sol +0 -0
- package/tests/{Constructors → format/Constructors}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/Constructors/jsfmt.spec.js +1 -0
- package/tests/{ContractDefinitions → format/ContractDefinitions}/ContractDefinitions.sol +0 -0
- package/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap +22 -0
- package/tests/format/ContractDefinitions/jsfmt.spec.js +1 -0
- package/tests/format/CustomErrors/CustomErrors.sol +20 -0
- package/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap +50 -0
- package/tests/format/CustomErrors/jsfmt.spec.js +1 -0
- package/tests/{EnumDefinitions → format/EnumDefinitions}/EnumDefinitions.sol +0 -0
- package/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap +72 -0
- package/tests/format/EnumDefinitions/jsfmt.spec.js +2 -0
- package/tests/{Etc → format/Etc}/Etc.sol +0 -0
- package/tests/{Etc → format/Etc}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/Etc/jsfmt.spec.js +1 -0
- package/tests/format/ExplicitVariableTypes/ExplicitVariableTypes.sol +36 -0
- package/tests/format/ExplicitVariableTypes/__snapshots__/jsfmt.spec.js.snap +258 -0
- package/tests/format/ExplicitVariableTypes/jsfmt.spec.js +9 -0
- package/tests/{ForStatements → format/ForStatements}/ForStatements.sol +0 -0
- package/tests/{ForStatements → format/ForStatements}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/ForStatements/jsfmt.spec.js +1 -0
- package/tests/format/FunctionCalls/FunctionCalls.sol +40 -0
- package/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap +310 -0
- package/tests/format/FunctionCalls/jsfmt.spec.js +2 -0
- package/tests/{FunctionDefinitions → format/FunctionDefinitions}/FunctionDefinitions.sol +5 -2
- package/tests/{FunctionDefinitions → format/FunctionDefinitions}/__snapshots__/jsfmt.spec.js.snap +18 -4
- package/tests/format/FunctionDefinitions/jsfmt.spec.js +1 -0
- package/tests/format/HexLiteral/HexLiteral.sol +7 -0
- package/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap +57 -0
- package/tests/format/HexLiteral/jsfmt.spec.js +8 -0
- package/tests/{IfStatements → format/IfStatements}/IfStatements.sol +0 -0
- package/tests/{IfStatements → format/IfStatements}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/IfStatements/jsfmt.spec.js +1 -0
- package/tests/{Immutable → format/Immutable}/Immutable.sol +0 -0
- package/tests/{Immutable → format/Immutable}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/Immutable/jsfmt.spec.js +1 -0
- package/tests/{ImportDirective → format/ImportDirective}/ImportDirectives.sol +0 -0
- package/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap +46 -0
- package/tests/format/ImportDirective/jsfmt.spec.js +2 -0
- package/tests/{Inbox → format/Inbox}/Inbox.sol +0 -0
- package/tests/{Inbox → format/Inbox}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/Inbox/jsfmt.spec.js +1 -0
- package/tests/{IndexOf → format/IndexOf}/IndexOf.sol +0 -0
- package/tests/{IndexOf → format/IndexOf}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/IndexOf/jsfmt.spec.js +1 -0
- package/tests/{IndexRangeAccess → format/IndexRangeAccess}/IndexRangeAccess.sol +0 -0
- package/tests/{IndexRangeAccess → format/IndexRangeAccess}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/IndexRangeAccess/jsfmt.spec.js +1 -0
- package/tests/{InheritanceSpecifier → format/InheritanceSpecifier}/InheritanceSpecifier.sol +0 -0
- package/tests/{InheritanceSpecifier → format/InheritanceSpecifier}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/InheritanceSpecifier/jsfmt.spec.js +1 -0
- package/tests/{Issues → format/Issues}/Issue205.sol +0 -0
- package/tests/{Issues → format/Issues}/Issue289.sol +0 -0
- package/tests/{Issues → format/Issues}/Issue355.sol +0 -0
- package/tests/{Issues → format/Issues}/Issue385.sol +0 -0
- package/tests/format/Issues/Issue564.sol +9 -0
- package/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap +174 -0
- package/tests/format/Issues/jsfmt.spec.js +1 -0
- package/tests/format/MemberAccess/MemberAccess.sol +102 -0
- package/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap +243 -0
- package/tests/format/MemberAccess/jsfmt.spec.js +1 -0
- package/tests/{ModifierDefinitions → format/ModifierDefinitions}/ModifierDefinitions.sol +0 -0
- package/tests/{ModifierDefinitions → format/ModifierDefinitions}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/ModifierDefinitions/jsfmt.spec.js +1 -0
- package/tests/format/ModifierInvocations/ModifierInvocations.sol +17 -0
- package/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap +51 -0
- package/tests/format/ModifierInvocations/jsfmt.spec.js +1 -0
- package/tests/{MultipartStrings → format/MultipartStrings}/MultipartStrings.sol +0 -0
- package/tests/{MultipartStrings → format/MultipartStrings}/__snapshots__/jsfmt.spec.js.snap +12 -3
- package/tests/format/MultipartStrings/jsfmt.spec.js +1 -0
- package/tests/{NameValueExpression → format/NameValueExpression}/NameValueExpression.sol +0 -0
- package/tests/{NameValueExpression → format/NameValueExpression}/__snapshots__/jsfmt.spec.js.snap +21 -6
- package/tests/format/NameValueExpression/jsfmt.spec.js +2 -0
- package/tests/{Ownable → format/Ownable}/Ownable.sol +0 -0
- package/tests/{Ownable → format/Ownable}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/Ownable/jsfmt.spec.js +1 -0
- package/tests/format/Parentheses/AddNoParentheses.sol +92 -0
- package/tests/format/Parentheses/BitAndNoParentheses.sol +92 -0
- package/tests/format/Parentheses/BitOrNoParentheses.sol +92 -0
- package/tests/format/Parentheses/BitXorNoParentheses.sol +92 -0
- package/tests/format/Parentheses/DivNoParentheses.sol +92 -0
- package/tests/format/Parentheses/ExpNoParentheses.sol +92 -0
- package/tests/format/Parentheses/LogicNoParentheses.sol +20 -0
- package/tests/format/Parentheses/ModNoParentheses.sol +92 -0
- package/tests/format/Parentheses/MulNoParentheses.sol +92 -0
- package/tests/format/Parentheses/ShiftLNoParentheses.sol +92 -0
- package/tests/format/Parentheses/ShiftRNoParentheses.sol +92 -0
- package/tests/format/Parentheses/SubNoParentheses.sol +92 -0
- package/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap +2237 -0
- package/tests/format/Parentheses/jsfmt.spec.js +1 -0
- package/tests/{Pragma → format/Pragma}/Pragma.sol +1 -0
- package/tests/{Pragma → format/Pragma}/__snapshots__/jsfmt.spec.js.snap +11 -2
- package/tests/format/Pragma/jsfmt.spec.js +1 -0
- package/tests/{PrettierIgnore → format/PrettierIgnore}/PrettierIgnore.sol +0 -0
- package/tests/{PrettierIgnore → format/PrettierIgnore}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/PrettierIgnore/jsfmt.spec.js +1 -0
- package/tests/{Proxy → format/Proxy}/Proxy.sol +0 -0
- package/tests/{Proxy → format/Proxy}/__snapshots__/jsfmt.spec.js.snap +16 -9
- package/tests/format/Proxy/jsfmt.spec.js +1 -0
- package/tests/format/RespectDefaultOptions/__snapshots__/jsfmt.spec.js.snap +19 -0
- package/tests/format/RespectDefaultOptions/jsfmt.spec.js +5 -0
- package/tests/format/RespectDefaultOptions/respect-default-options.js +3 -0
- package/tests/{SampleCrowdsale → format/SampleCrowdsale}/SampleCrowdsale.sol +0 -0
- package/tests/{SampleCrowdsale → format/SampleCrowdsale}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/SampleCrowdsale/jsfmt.spec.js +1 -0
- package/tests/{SimpleAuction → format/SimpleAuction}/SimpleAuction.sol +0 -0
- package/tests/{SimpleAuction → format/SimpleAuction}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/SimpleAuction/jsfmt.spec.js +1 -0
- package/tests/{SimpleStorage → format/SimpleStorage}/SimpleStorage.sol +0 -0
- package/tests/{SimpleStorage → format/SimpleStorage}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/SimpleStorage/jsfmt.spec.js +1 -0
- package/tests/{SplittableCommodity → format/SplittableCommodity}/SplittableCommodity.sol +0 -0
- package/tests/{SplittableCommodity → format/SplittableCommodity}/__snapshots__/jsfmt.spec.js.snap +19 -13
- package/tests/format/SplittableCommodity/jsfmt.spec.js +1 -0
- package/tests/{StateVariableDeclarations → format/StateVariableDeclarations}/StateVariableDeclarations.sol +0 -0
- package/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap +20 -0
- package/tests/format/StateVariableDeclarations/jsfmt.spec.js +1 -0
- package/tests/format/StringLiteral/StringLiteral.sol +11 -0
- package/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap +36 -0
- package/tests/format/StringLiteral/jsfmt.spec.js +1 -0
- package/tests/{StyleGuide → format/StyleGuide}/BlankLines.sol +0 -0
- package/tests/{StyleGuide → format/StyleGuide}/ControlStructures.sol +0 -0
- package/tests/{StyleGuide → format/StyleGuide}/FunctionDeclaration.sol +0 -0
- package/tests/{StyleGuide → format/StyleGuide}/Mappings.sol +0 -0
- package/tests/{StyleGuide → format/StyleGuide}/MaximumLineLength.sol +0 -0
- package/tests/{StyleGuide → format/StyleGuide}/OtherRecommendations.sol +0 -0
- package/tests/{StyleGuide → format/StyleGuide}/VariableDeclarations.sol +0 -0
- package/tests/{StyleGuide → format/StyleGuide}/WhitespaceInExpressions.sol +0 -0
- package/tests/{StyleGuide → format/StyleGuide}/__snapshots__/jsfmt.spec.js.snap +72 -16
- package/tests/format/StyleGuide/jsfmt.spec.js +1 -0
- package/tests/{TryCatch → format/TryCatch}/TryCatch.sol +0 -0
- package/tests/{TryCatch → format/TryCatch}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/TryCatch/jsfmt.spec.js +1 -0
- package/tests/{Tupples → format/Tupples}/Tupples.sol +0 -0
- package/tests/{Tupples → format/Tupples}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/Tupples/jsfmt.spec.js +1 -0
- package/tests/format/TypeDefinition/TypeDefinition.sol +12 -0
- package/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap +74 -0
- package/tests/format/TypeDefinition/jsfmt.spec.js +1 -0
- package/tests/{WhileStatements → format/WhileStatements}/WhileStatements.sol +0 -0
- package/tests/{WhileStatements → format/WhileStatements}/__snapshots__/jsfmt.spec.js.snap +9 -2
- package/tests/format/WhileStatements/jsfmt.spec.js +1 -0
- package/tests/format/WrongCompiler/WrongCompiler.sol +3 -0
- package/tests/format/WrongCompiler/__snapshots__/jsfmt.spec.js.snap +55 -0
- package/tests/format/WrongCompiler/jsfmt.spec.js +10 -0
- package/tests/{quotes → format/quotes}/Quotes.sol +2 -2
- package/tests/{quotes → format/quotes}/__snapshots__/jsfmt.spec.js.snap +62 -34
- package/tests/format/quotes/jsfmt.spec.js +2 -0
- package/tests/{strings → format/strings}/__snapshots__/jsfmt.spec.js.snap +11 -5
- package/tests/format/strings/jsfmt.spec.js +1 -0
- package/tests/{strings → format/strings}/strings.sol +0 -0
- package/{__tests__ → tests/unit}/binary-operator-printers/__snapshots__/index.test.js.snap +0 -0
- package/{__tests__ → tests/unit}/binary-operator-printers/index.test.js +1 -1
- package/{__tests__ → tests/unit}/comments/printer.test.js +1 -1
- package/tests/unit/prettier-version.test.js +26 -0
- package/{__tests__ → tests/unit}/printer.test.js +1 -1
- package/.travis.yml +0 -10
- package/__tests__/nodes/__snapshots__/index.test.js.snap +0 -73
- package/__tests__/nodes/index.test.js +0 -5
- package/codecov.yml +0 -2
- package/scripts/__snapshots__/makeData.test.js.snap +0 -17
- package/scripts/makeData.test.js +0 -10
- package/tests/AddressPayable/jsfmt.spec.js +0 -1
- package/tests/AllSolidityFeatures/jsfmt.spec.js +0 -1
- package/tests/Arrays/jsfmt.spec.js +0 -1
- package/tests/Assembly/jsfmt.spec.js +0 -1
- package/tests/BasicIterator/jsfmt.spec.js +0 -1
- package/tests/BinaryOperators/jsfmt.spec.js +0 -1
- package/tests/Comments/jsfmt.spec.js +0 -1
- package/tests/Conditional/jsfmt.spec.js +0 -1
- package/tests/Constructors/jsfmt.spec.js +0 -1
- package/tests/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap +0 -15
- package/tests/ContractDefinitions/jsfmt.spec.js +0 -1
- package/tests/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap +0 -47
- package/tests/EnumDefinitions/jsfmt.spec.js +0 -2
- package/tests/Etc/jsfmt.spec.js +0 -1
- package/tests/ExplicitVariableTypes/ExplicitVariableTypes.sol +0 -30
- package/tests/ExplicitVariableTypes/__snapshots__/jsfmt.spec.js.snap +0 -242
- package/tests/ExplicitVariableTypes/jsfmt.spec.js +0 -3
- package/tests/ForStatements/jsfmt.spec.js +0 -1
- package/tests/FunctionCalls/FunctionCalls.sol +0 -19
- package/tests/FunctionCalls/__snapshots__/jsfmt.spec.js.snap +0 -77
- package/tests/FunctionCalls/jsfmt.spec.js +0 -2
- package/tests/FunctionDefinitions/jsfmt.spec.js +0 -1
- package/tests/IfStatements/jsfmt.spec.js +0 -1
- package/tests/Immutable/jsfmt.spec.js +0 -1
- package/tests/ImportDirective/__snapshots__/jsfmt.spec.js.snap +0 -41
- package/tests/ImportDirective/jsfmt.spec.js +0 -2
- package/tests/Inbox/jsfmt.spec.js +0 -1
- package/tests/IndexOf/jsfmt.spec.js +0 -1
- package/tests/IndexRangeAccess/jsfmt.spec.js +0 -1
- package/tests/InheritanceSpecifier/jsfmt.spec.js +0 -1
- package/tests/Issues/__snapshots__/jsfmt.spec.js.snap +0 -112
- package/tests/Issues/jsfmt.spec.js +0 -1
- package/tests/MemberAccess/MemberAccess.sol +0 -15
- package/tests/MemberAccess/__snapshots__/jsfmt.spec.js.snap +0 -56
- package/tests/MemberAccess/jsfmt.spec.js +0 -1
- package/tests/ModifierDefinitions/jsfmt.spec.js +0 -1
- package/tests/MultipartStrings/jsfmt.spec.js +0 -1
- package/tests/NameValueExpression/jsfmt.spec.js +0 -2
- package/tests/Ownable/jsfmt.spec.js +0 -1
- package/tests/Pragma/jsfmt.spec.js +0 -1
- package/tests/PrettierIgnore/jsfmt.spec.js +0 -1
- package/tests/Proxy/jsfmt.spec.js +0 -1
- package/tests/SampleCrowdsale/jsfmt.spec.js +0 -1
- package/tests/SimpleAuction/jsfmt.spec.js +0 -1
- package/tests/SimpleStorage/jsfmt.spec.js +0 -1
- package/tests/SplittableCommodity/jsfmt.spec.js +0 -1
- package/tests/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap +0 -13
- package/tests/StateVariableDeclarations/jsfmt.spec.js +0 -1
- package/tests/StyleGuide/jsfmt.spec.js +0 -1
- package/tests/TryCatch/jsfmt.spec.js +0 -1
- package/tests/Tupples/jsfmt.spec.js +0 -1
- package/tests/WhileStatements/jsfmt.spec.js +0 -1
- package/tests/quotes/jsfmt.spec.js +0 -2
- package/tests/strings/jsfmt.spec.js +0 -1
- package/tests_config/helpers.js +0 -44
- package/tests_config/raw-serializer.js +0 -15
- package/tests_config/run_spec.js +0 -79
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
custom: ['https://gitcoin.co/grants/1534/prettier-solidity']
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: npm
|
|
4
|
+
directory: '/'
|
|
5
|
+
schedule:
|
|
6
|
+
interval: daily
|
|
7
|
+
open-pull-requests-limit: 10
|
|
8
|
+
ignore:
|
|
9
|
+
- dependency-name: semver
|
|
10
|
+
versions:
|
|
11
|
+
- 7.3.5
|
|
12
|
+
- dependency-name: eslint
|
|
13
|
+
versions:
|
|
14
|
+
- 7.23.0
|
|
15
|
+
- dependency-name: '@solidity-parser/parser'
|
|
16
|
+
versions:
|
|
17
|
+
- 0.12.2
|
|
18
|
+
- dependency-name: emoji-regex
|
|
19
|
+
versions:
|
|
20
|
+
- 9.2.2
|
|
21
|
+
- dependency-name: string-width
|
|
22
|
+
versions:
|
|
23
|
+
- 4.2.1
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- '*'
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
lint:
|
|
13
|
+
name: Lint
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/setup-node@v1
|
|
17
|
+
with:
|
|
18
|
+
node-version: 14
|
|
19
|
+
- uses: actions/checkout@v2
|
|
20
|
+
- uses: actions/cache@v2
|
|
21
|
+
id: cache
|
|
22
|
+
with:
|
|
23
|
+
path: |
|
|
24
|
+
node_modules
|
|
25
|
+
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }}
|
|
26
|
+
- name: Install
|
|
27
|
+
run: npm install
|
|
28
|
+
- name: lint
|
|
29
|
+
run: npm run lint
|
|
30
|
+
|
|
31
|
+
test_linux:
|
|
32
|
+
name: Test on Linux with Node ${{ matrix.node }}
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
strategy:
|
|
35
|
+
matrix:
|
|
36
|
+
node: [14, 16]
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/setup-node@v1
|
|
39
|
+
with:
|
|
40
|
+
node-version: ${{ matrix.node }}
|
|
41
|
+
- uses: actions/checkout@v2
|
|
42
|
+
- uses: actions/cache@v2
|
|
43
|
+
id: cache
|
|
44
|
+
with:
|
|
45
|
+
path: |
|
|
46
|
+
node_modules
|
|
47
|
+
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('package-lock.json') }}
|
|
48
|
+
- name: Install
|
|
49
|
+
run: npm install
|
|
50
|
+
- name: Run tests
|
|
51
|
+
run: npm run test:all
|
|
52
|
+
|
|
53
|
+
test_macos:
|
|
54
|
+
name: Test on MacOS with Node 14
|
|
55
|
+
runs-on: macos-latest
|
|
56
|
+
steps:
|
|
57
|
+
- uses: actions/setup-node@v1
|
|
58
|
+
with:
|
|
59
|
+
node-version: 14
|
|
60
|
+
- uses: actions/checkout@v2
|
|
61
|
+
- uses: actions/cache@v2
|
|
62
|
+
id: cache
|
|
63
|
+
with:
|
|
64
|
+
path: |
|
|
65
|
+
node_modules
|
|
66
|
+
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }}
|
|
67
|
+
- name: Install
|
|
68
|
+
run: npm install
|
|
69
|
+
- name: Run tests
|
|
70
|
+
run: npm run test:all
|
|
71
|
+
|
|
72
|
+
test_windows:
|
|
73
|
+
name: Test on Windows with Node 14
|
|
74
|
+
runs-on: windows-latest
|
|
75
|
+
steps:
|
|
76
|
+
- uses: actions/setup-node@v1
|
|
77
|
+
with:
|
|
78
|
+
node-version: 14
|
|
79
|
+
- uses: actions/checkout@v2
|
|
80
|
+
- name: Install
|
|
81
|
+
run: npm install
|
|
82
|
+
- name: Run tests
|
|
83
|
+
run: npm run test:all
|
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
14
|
package/.prettierignore
CHANGED
package/CODE_OF_CONDUCT.md
CHANGED
|
@@ -6,7 +6,7 @@ In the interest of fostering an open and welcoming environment, we as
|
|
|
6
6
|
contributors and maintainers pledge to making participation in our project and
|
|
7
7
|
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
8
|
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
|
9
|
-
level of experience, education,
|
|
9
|
+
level of experience, education, socioeconomic status, nationality, personal
|
|
10
10
|
appearance, race, religion, or sexual identity and orientation.
|
|
11
11
|
|
|
12
12
|
## Our Standards
|
package/Foo.sol
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
// This program is free software: you can redistribute it and/or modify
|
|
3
|
+
// it under the terms of the GNU General Public License as published by
|
|
4
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
5
|
+
// (at your option) any later version.
|
|
6
|
+
|
|
7
|
+
// This program is distributed in the hope that it will be useful,
|
|
8
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10
|
+
// GNU General Public License for more details.
|
|
11
|
+
|
|
12
|
+
// You should have received a copy of the GNU General Public License
|
|
13
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
14
|
+
|
|
15
|
+
pragma solidity ^0.7.0;
|
|
16
|
+
|
|
17
|
+
import "@balancer-labs/v2-solidity-utils/contracts/helpers/Authentication.sol";
|
|
18
|
+
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ReentrancyGuard.sol";
|
|
19
|
+
import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol";
|
|
20
|
+
|
|
21
|
+
import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol";
|
|
22
|
+
|
|
23
|
+
import "./interfaces/IBalancerToken.sol";
|
|
24
|
+
|
|
25
|
+
// solhint-disable not-rely-on-time
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @title Balancer Token Admin
|
|
29
|
+
* @notice This contract holds all admin powers over the BAL token passing through calls
|
|
30
|
+
* while delegating access control to the Balancer Authorizer
|
|
31
|
+
*
|
|
32
|
+
* In addition, calls to the mint function must respect the inflation schedule as defined in this contract.
|
|
33
|
+
* As this contract is the only way to mint BAL tokens this ensures that the maximum allowed supply is enforced
|
|
34
|
+
* @dev This contract exists as a consequence of the gauge systems needing to know a fixed inflation schedule
|
|
35
|
+
* in order to know how much BAL a gauge is allowed to mint. As this does not exist within the BAL token itself
|
|
36
|
+
* it is defined here, we must then wrap the token's minting functionality in order for this to be meaningful.
|
|
37
|
+
*/
|
|
38
|
+
contract BalancerTokenAdmin is Authentication, ReentrancyGuard {
|
|
39
|
+
using Math for uint256;
|
|
40
|
+
|
|
41
|
+
// Initial inflation rate of 145k BAL per week.
|
|
42
|
+
uint256 public constant INITIAL_RATE = (145_000 * 1e18) / uint256(1 weeks); // BAL has 18 decimals
|
|
43
|
+
uint256 public constant RATE_REDUCTION_TIME = 365 days;
|
|
44
|
+
uint256 public constant RATE_REDUCTION_COEFFICIENT = 1189207115002721024; // 2 ** (1/4) * 1e18
|
|
45
|
+
uint256 public constant RATE_DENOMINATOR = 1e18;
|
|
46
|
+
|
|
47
|
+
IVault private immutable _vault;
|
|
48
|
+
IBalancerToken private immutable _balancerToken;
|
|
49
|
+
|
|
50
|
+
event MiningParametersUpdated(uint256 rate, uint256 supply);
|
|
51
|
+
|
|
52
|
+
// Supply Variables
|
|
53
|
+
uint256 private _miningEpoch;
|
|
54
|
+
uint256 private _startEpochTime = type(uint256).max; // Sentinel value for contract not being activated
|
|
55
|
+
uint256 private _startEpochSupply;
|
|
56
|
+
uint256 private _rate;
|
|
57
|
+
|
|
58
|
+
constructor(IVault vault, IERC20 token) Authentication(bytes32(uint256(address(this)))) {
|
|
59
|
+
// BalancerTokenAdmin is a singleton, so it simply uses its own address to disambiguate action identifiers
|
|
60
|
+
_balancerToken = IBalancerToken(address(token));
|
|
61
|
+
_vault = vault;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @dev Returns the Balancer token.
|
|
66
|
+
*/
|
|
67
|
+
function getBalancerToken() external view returns (IERC20) {
|
|
68
|
+
return _balancerToken;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @notice Returns the Balancer Vault.
|
|
73
|
+
*/
|
|
74
|
+
function getVault() public view returns (IVault) {
|
|
75
|
+
return _vault;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @notice Returns the Balancer Vault's current authorizer.
|
|
80
|
+
*/
|
|
81
|
+
function getAuthorizer() public view returns (IAuthorizer) {
|
|
82
|
+
return getVault().getAuthorizer();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @notice Initiate BAL token inflation schedule
|
|
87
|
+
* @dev Reverts if contract does not have sole minting powers over BAL (and no other minters can be added).
|
|
88
|
+
*/
|
|
89
|
+
function activate() external nonReentrant authenticate {
|
|
90
|
+
require(_startEpochTime == type(uint256).max, "Already activated");
|
|
91
|
+
|
|
92
|
+
// We need to check that this contract can't be bypassed to mint more BAL in the future.
|
|
93
|
+
// If other addresses had minting rights over the BAL token then this inflation schedule
|
|
94
|
+
// could be bypassed by minting new tokens directly on the BalancerGovernanceToken contract.
|
|
95
|
+
|
|
96
|
+
// On the BalancerGovernanceToken contract the minter role's admin is the DEFAULT_ADMIN_ROLE.
|
|
97
|
+
// No external function exists to change the minter role's admin so we cannot make the list of
|
|
98
|
+
// minters immutable without revoking all access to DEFAULT_ADMIN_ROLE.
|
|
99
|
+
bytes32 minterRole = _balancerToken.MINTER_ROLE();
|
|
100
|
+
bytes32 snapshotRole = _balancerToken.SNAPSHOT_ROLE();
|
|
101
|
+
bytes32 adminRole = _balancerToken.DEFAULT_ADMIN_ROLE();
|
|
102
|
+
|
|
103
|
+
require(_balancerToken.hasRole(adminRole, address(this)), "BalancerTokenAdmin is not an admin");
|
|
104
|
+
|
|
105
|
+
// All other minters must be removed to avoid inflation schedule enforcement being bypassed.
|
|
106
|
+
uint256 numberOfMinters = _balancerToken.getRoleMemberCount(minterRole);
|
|
107
|
+
for (uint256 i = 0; i < numberOfMinters; ++i) {
|
|
108
|
+
address minter = _balancerToken.getRoleMember(minterRole, 0);
|
|
109
|
+
_balancerToken.revokeRole(minterRole, minter);
|
|
110
|
+
}
|
|
111
|
+
// Give this contract minting rights over the BAL token
|
|
112
|
+
_balancerToken.grantRole(minterRole, address(this));
|
|
113
|
+
|
|
114
|
+
// BalancerGovernanceToken exposes a role-restricted `snapshot` function for performing onchain voting.
|
|
115
|
+
// We delegate control over this to the Balancer Authorizer by removing this role from all current addresses
|
|
116
|
+
// and exposing a function which defers to the Authorizer for access control.
|
|
117
|
+
uint256 numberOfSnapshotters = _balancerToken.getRoleMemberCount(snapshotRole);
|
|
118
|
+
for (uint256 i = 0; i < numberOfSnapshotters; ++i) {
|
|
119
|
+
address snapshotter = _balancerToken.getRoleMember(snapshotRole, 0);
|
|
120
|
+
_balancerToken.revokeRole(snapshotRole, snapshotter);
|
|
121
|
+
}
|
|
122
|
+
// Give this contract snapshotting rights over the BAL token
|
|
123
|
+
_balancerToken.grantRole(snapshotRole, address(this));
|
|
124
|
+
|
|
125
|
+
// BalancerTokenAdmin now is the only holder of MINTER_ROLE and SNAPSHOT_ROLE for BalancerGovernanceToken.
|
|
126
|
+
|
|
127
|
+
// We can't prevent any other admins from granting other addresses these roles however.
|
|
128
|
+
// This undermines the ability for BalancerTokenAdmin to enforce the correct inflation schedule.
|
|
129
|
+
// The only way to prevent this is for BalancerTokenAdmin to be the only admin. We then remove all other admins.
|
|
130
|
+
uint256 numberOfAdmins = _balancerToken.getRoleMemberCount(adminRole);
|
|
131
|
+
uint256 skipSelf = 0;
|
|
132
|
+
for (uint256 i = 0; i < numberOfAdmins; ++i) {
|
|
133
|
+
address admin = _balancerToken.getRoleMember(adminRole, skipSelf);
|
|
134
|
+
if (admin != address(this)) {
|
|
135
|
+
_balancerToken.revokeRole(adminRole, admin);
|
|
136
|
+
} else {
|
|
137
|
+
// This contract is now the admin with index 0, we now delete the address with index 1 instead
|
|
138
|
+
skipSelf = 1;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// BalancerTokenAdmin doesn't actually need admin rights any more and won't grant rights to any more addresses
|
|
143
|
+
// We then renounce our admin role to ensure that another address won't gain absolute minting powers.
|
|
144
|
+
_balancerToken.revokeRole(adminRole, address(this));
|
|
145
|
+
|
|
146
|
+
// Perform sanity checks to make sure we're not leaving the roles in a broken state
|
|
147
|
+
require(_balancerToken.getRoleMemberCount(adminRole) == 0, "Address exists with admin rights");
|
|
148
|
+
require(_balancerToken.hasRole(minterRole, address(this)), "BalancerTokenAdmin is not a minter");
|
|
149
|
+
require(_balancerToken.hasRole(snapshotRole, address(this)), "BalancerTokenAdmin is not a snapshotter");
|
|
150
|
+
require(_balancerToken.getRoleMemberCount(minterRole) == 1, "Multiple minters exist");
|
|
151
|
+
require(_balancerToken.getRoleMemberCount(snapshotRole) == 1, "Multiple snapshotters exist");
|
|
152
|
+
|
|
153
|
+
// As BAL inflation is now enforced by this contract we can initialise the relevant variables.
|
|
154
|
+
_startEpochSupply = _balancerToken.totalSupply();
|
|
155
|
+
_startEpochTime = block.timestamp;
|
|
156
|
+
_rate = INITIAL_RATE;
|
|
157
|
+
emit MiningParametersUpdated(INITIAL_RATE, _startEpochSupply);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @notice Mint BAL tokens subject to the defined inflation schedule
|
|
162
|
+
* @dev Callable only by addresses defined in the Balancer Authorizer contract
|
|
163
|
+
*/
|
|
164
|
+
function mint(address to, uint256 amount) external authenticate {
|
|
165
|
+
// Check if we've passed into a new epoch such that we should calculate available supply with a smaller rate.
|
|
166
|
+
if (block.timestamp >= _startEpochTime.add(RATE_REDUCTION_TIME)) {
|
|
167
|
+
_updateMiningParameters();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
require(
|
|
171
|
+
_balancerToken.totalSupply().add(amount) <= _availableSupply(),
|
|
172
|
+
"Mint amount exceeds remaining available supply"
|
|
173
|
+
);
|
|
174
|
+
_balancerToken.mint(to, amount);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @notice Perform a snapshot of BAL token balances
|
|
179
|
+
* @dev Callable only by addresses defined in the Balancer Authorizer contract
|
|
180
|
+
*/
|
|
181
|
+
function snapshot() external authenticate {
|
|
182
|
+
_balancerToken.snapshot();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @notice Returns the current epoch number.
|
|
187
|
+
*/
|
|
188
|
+
function getMiningEpoch() external view returns (uint256) {
|
|
189
|
+
return _miningEpoch;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* @notice Returns the start timestamp of the current epoch.
|
|
194
|
+
*/
|
|
195
|
+
function getStartEpochTime() external view returns (uint256) {
|
|
196
|
+
return _startEpochTime;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @notice Returns the start timestamp of the next epoch.
|
|
201
|
+
*/
|
|
202
|
+
function getFutureEpochTime() external view returns (uint256) {
|
|
203
|
+
return _startEpochTime.add(RATE_REDUCTION_TIME);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @notice Returns the available supply at the beginning of the current epoch.
|
|
208
|
+
*/
|
|
209
|
+
function getStartEpochSupply() external view returns (uint256) {
|
|
210
|
+
return _startEpochSupply;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @notice Returns the current inflation rate of BAL per second
|
|
215
|
+
*/
|
|
216
|
+
function getInflationRate() external view returns (uint256) {
|
|
217
|
+
return _rate;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @notice Maximum allowable number of tokens in existence (claimed or unclaimed)
|
|
222
|
+
*/
|
|
223
|
+
function getAvailableSupply() external view returns (uint256) {
|
|
224
|
+
return _availableSupply();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @notice Get timestamp of the current mining epoch start while simultaneously updating mining parameters
|
|
229
|
+
* @return Timestamp of the current epoch
|
|
230
|
+
*/
|
|
231
|
+
function startEpochTimeWrite() external returns (uint256) {
|
|
232
|
+
return _startEpochTimeWrite();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @notice Get timestamp of the next mining epoch start while simultaneously updating mining parameters
|
|
237
|
+
* @return Timestamp of the next epoch
|
|
238
|
+
*/
|
|
239
|
+
function futureEpochTimeWrite() external returns (uint256) {
|
|
240
|
+
return _startEpochTimeWrite().add(RATE_REDUCTION_TIME);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @notice Update mining rate and supply at the start of the epoch
|
|
245
|
+
* @dev Callable by any address, but only once per epoch
|
|
246
|
+
* Total supply becomes slightly larger if this function is called late
|
|
247
|
+
*/
|
|
248
|
+
function updateMiningParameters() external {
|
|
249
|
+
require(block.timestamp >= _startEpochTime.add(RATE_REDUCTION_TIME), "Epoch has not finished yet");
|
|
250
|
+
_updateMiningParameters();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @notice How much supply is mintable from start timestamp till end timestamp
|
|
255
|
+
* @param start Start of the time interval (timestamp)
|
|
256
|
+
* @param end End of the time interval (timestamp)
|
|
257
|
+
* @return Tokens mintable from `start` till `end`
|
|
258
|
+
*/
|
|
259
|
+
function mintableInTimeframe(uint256 start, uint256 end) external view returns (uint256) {
|
|
260
|
+
return _mintableInTimeframe(start, end);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Internal functions
|
|
264
|
+
|
|
265
|
+
function _canPerform(bytes32 actionId, address account) internal view override returns (bool) {
|
|
266
|
+
return getAuthorizer().canPerform(actionId, account, address(this));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @notice Maximum allowable number of tokens in existence (claimed or unclaimed)
|
|
271
|
+
*/
|
|
272
|
+
function _availableSupply() internal view returns (uint256) {
|
|
273
|
+
uint256 newSupplyFromCurrentEpoch = (block.timestamp.sub(_startEpochTime)).mul(_rate);
|
|
274
|
+
return _startEpochSupply.add(newSupplyFromCurrentEpoch);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @notice Get timestamp of the current mining epoch start while simultaneously updating mining parameters
|
|
279
|
+
* @return Timestamp of the current epoch
|
|
280
|
+
*/
|
|
281
|
+
function _startEpochTimeWrite() internal returns (uint256) {
|
|
282
|
+
uint256 startEpochTime = _startEpochTime;
|
|
283
|
+
if (block.timestamp >= startEpochTime.add(RATE_REDUCTION_TIME)) {
|
|
284
|
+
_updateMiningParameters();
|
|
285
|
+
return _startEpochTime;
|
|
286
|
+
}
|
|
287
|
+
return startEpochTime;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function _updateMiningParameters() internal {
|
|
291
|
+
uint256 inflationRate = _rate;
|
|
292
|
+
uint256 startEpochSupply = _startEpochSupply.add(inflationRate.mul(RATE_REDUCTION_TIME));
|
|
293
|
+
inflationRate = inflationRate.mul(RATE_DENOMINATOR).divDown(RATE_REDUCTION_COEFFICIENT);
|
|
294
|
+
|
|
295
|
+
_miningEpoch = _miningEpoch.add(1);
|
|
296
|
+
_startEpochTime = _startEpochTime.add(RATE_REDUCTION_TIME);
|
|
297
|
+
_rate = inflationRate;
|
|
298
|
+
_startEpochSupply = startEpochSupply;
|
|
299
|
+
|
|
300
|
+
emit MiningParametersUpdated(inflationRate, startEpochSupply);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* @notice How much supply is mintable from start timestamp till end timestamp
|
|
305
|
+
* @param start Start of the time interval (timestamp)
|
|
306
|
+
* @param end End of the time interval (timestamp)
|
|
307
|
+
* @return Tokens mintable from `start` till `end`
|
|
308
|
+
*/
|
|
309
|
+
function _mintableInTimeframe(uint256 start, uint256 end) internal view returns (uint256) {
|
|
310
|
+
require(start <= end, "start > end");
|
|
311
|
+
|
|
312
|
+
uint256 currentEpochTime = _startEpochTime;
|
|
313
|
+
uint256 currentRate = _rate;
|
|
314
|
+
|
|
315
|
+
// It shouldn't be possible to over/underflow in here but we add checked maths to be safe
|
|
316
|
+
|
|
317
|
+
// Special case if end is in future (not yet minted) epoch
|
|
318
|
+
if (end > currentEpochTime.add(RATE_REDUCTION_TIME)) {
|
|
319
|
+
currentEpochTime = currentEpochTime.add(RATE_REDUCTION_TIME);
|
|
320
|
+
currentRate = currentRate.mul(RATE_DENOMINATOR).divDown(RATE_REDUCTION_COEFFICIENT);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
require(end <= currentEpochTime.add(RATE_REDUCTION_TIME), "too far in future");
|
|
324
|
+
|
|
325
|
+
uint256 toMint = 0;
|
|
326
|
+
for (uint256 epoch = 0; epoch < 999; ++epoch) {
|
|
327
|
+
if (end >= currentEpochTime) {
|
|
328
|
+
uint256 currentEnd = end;
|
|
329
|
+
if (currentEnd > currentEpochTime.add(RATE_REDUCTION_TIME)) {
|
|
330
|
+
currentEnd = currentEpochTime.add(RATE_REDUCTION_TIME);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
uint256 currentStart = start;
|
|
334
|
+
if (currentStart >= currentEpochTime.add(RATE_REDUCTION_TIME)) {
|
|
335
|
+
// We should never get here but what if...
|
|
336
|
+
break;
|
|
337
|
+
} else if (currentStart < currentEpochTime) {
|
|
338
|
+
currentStart = currentEpochTime;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
toMint = toMint.add(currentRate.mul(currentEnd.sub(currentStart)));
|
|
342
|
+
|
|
343
|
+
if (start >= currentEpochTime) {
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
currentEpochTime = currentEpochTime.sub(RATE_REDUCTION_TIME);
|
|
349
|
+
// double-division with rounding made rate a bit less => good
|
|
350
|
+
currentRate = currentRate.mul(RATE_REDUCTION_COEFFICIENT).divDown(RATE_DENOMINATOR);
|
|
351
|
+
assert(currentRate <= INITIAL_RATE);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return toMint;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// The below functions are duplicates of functions available above.
|
|
358
|
+
// They are included for ABI compatibility with snake_casing as used in vyper contracts.
|
|
359
|
+
// solhint-disable func-name-mixedcase
|
|
360
|
+
|
|
361
|
+
function rate() external view returns (uint256) {
|
|
362
|
+
return _rate;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function available_supply() external view returns (uint256) {
|
|
366
|
+
return _availableSupply();
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* @notice Get timestamp of the current mining epoch start while simultaneously updating mining parameters
|
|
371
|
+
* @return Timestamp of the current epoch
|
|
372
|
+
*/
|
|
373
|
+
function start_epoch_time_write() external returns (uint256) {
|
|
374
|
+
return _startEpochTimeWrite();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* @notice Get timestamp of the next mining epoch start while simultaneously updating mining parameters
|
|
379
|
+
* @return Timestamp of the next epoch
|
|
380
|
+
*/
|
|
381
|
+
function future_epoch_time_write() external returns (uint256) {
|
|
382
|
+
return _startEpochTimeWrite().add(RATE_REDUCTION_TIME);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* @notice Update mining rate and supply at the start of the epoch
|
|
387
|
+
* @dev Callable by any address, but only once per epoch
|
|
388
|
+
* Total supply becomes slightly larger if this function is called late
|
|
389
|
+
*/
|
|
390
|
+
function update_mining_parameters() external {
|
|
391
|
+
require(block.timestamp >= _startEpochTime.add(RATE_REDUCTION_TIME), "Epoch has not finished yet");
|
|
392
|
+
_updateMiningParameters();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* @notice How much supply is mintable from start timestamp till end timestamp
|
|
397
|
+
* @param start Start of the time interval (timestamp)
|
|
398
|
+
* @param end End of the time interval (timestamp)
|
|
399
|
+
* @return Tokens mintable from `start` till `end`
|
|
400
|
+
*/
|
|
401
|
+
function mintable_in_timeframe(uint256 start, uint256 end) external view returns (uint256) {
|
|
402
|
+
return _mintableInTimeframe(start, end);
|
|
403
|
+
}
|
|
404
|
+
}
|
package/HOW_TO_PUBLISH.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
```bash
|
|
4
4
|
nvm use
|
|
5
5
|
|
|
6
|
-
git checkout
|
|
6
|
+
git checkout main
|
|
7
7
|
|
|
8
8
|
git pull
|
|
9
9
|
|
|
@@ -26,7 +26,7 @@ git commit -m 'bump version'
|
|
|
26
26
|
git push
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
- Once the PR is merged, then `git checkout
|
|
29
|
+
- Once the PR is merged, then `git checkout main` and `git pull`
|
|
30
30
|
|
|
31
31
|
- Uncomment the first line of the `.npmrc` file and comment the second line
|
|
32
32
|
|
package/LICENSE
CHANGED