From d1617275441297262d9d6a62392fe149edaf1056 Mon Sep 17 00:00:00 2001 From: jo-es Date: Fri, 18 Dec 2020 17:38:28 +0100 Subject: [PATCH 1/6] Update README.md --- packages/protocol/README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/protocol/README.md b/packages/protocol/README.md index 78b64ae1..1dc34b30 100755 --- a/packages/protocol/README.md +++ b/packages/protocol/README.md @@ -127,13 +127,13 @@ With the exception of Array types, ACTUS types are one to one mapped in Solidity ### Updating ACTUS types througout the project If the underlying ACTUS types change in [atpar/actus-dictionary](https://github.com/atpar/actus-dictionary) -the following files and directories may be affected and have to be updated manually: +, the following files and directories may be affected and have to be updated manually: - [ACTUSTypes.sol](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/contracts/ACTUS/Core/ACTUSTypes.sol) -- [Encoder libaries e.g. ANNEncoder](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/contracts/Core/ANN/ANNEncoder.sol) -- [ACTUS.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/types/ACTUS.ts) -- [AP.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/types/AP.ts) -- [Dictionary.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/types/dictionary/dictionary.json) -- [Constants.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/utils/Constants.ts) -- [Conversions.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/utils/Conversion.ts) -- [Schedule.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/utils/Schedule.ts) -- [Test helpers](https://github.com/atpar/ap-monorepo/tree/dev/packages/protocol/test/helper) +| [Encoder libaries e.g. ANNEncoder](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/contracts/Core/ANN/ANNEncoder.sol) +| [ACTUS.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/types/ACTUS.ts) +| [AP.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/types/AP.ts) +| [Dictionary.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/types/dictionary/dictionary.json) +| [Constants.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/utils/Constants.ts) +| [Conversions.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/utils/Conversion.ts) +| [Schedule.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/utils/Schedule.ts) +| [Test helpers](https://github.com/atpar/ap-monorepo/tree/dev/packages/protocol/test/helper) From e6fb277cb80377999ff2048296857d11e88a47f5 Mon Sep 17 00:00:00 2001 From: jo-es Date: Mon, 21 Dec 2020 12:44:05 +0100 Subject: [PATCH 2/6] Replace absolute links with relative links in README.md --- README.md | 2 +- packages/protocol/README.md | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7d3ecb51..a46a181e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ This is a monorepo containing all packages related to the ACTUS Protocol. | Package | Description | |----------------------------------------------------------------------------------|--------------------------------------------------------------------------------| -| [`protocol`](https://github.com/atpar/ap-monorepo/tree/master/packages/protocol) | Contains the Solidity implementation the ACTUS Protocol and the typescript sdk | +| [`protocol`](packages/protocol/README.md) | Contains the Solidity implementation the ACTUS Protocol and the typescript sdk | ## Development ### Requirements diff --git a/packages/protocol/README.md b/packages/protocol/README.md index 1dc34b30..e72f4d7e 100755 --- a/packages/protocol/README.md +++ b/packages/protocol/README.md @@ -28,7 +28,7 @@ const ap = await AP.init(web3, ADDRESS_BOOK); ## Development ### Requirements and Setup -See [README](https://github.com/atpar/ap-monorepo) in root directory. +See [README](../../README.md) in root directory. ### Testing ```sh @@ -128,12 +128,12 @@ With the exception of Array types, ACTUS types are one to one mapped in Solidity ### Updating ACTUS types througout the project If the underlying ACTUS types change in [atpar/actus-dictionary](https://github.com/atpar/actus-dictionary) , the following files and directories may be affected and have to be updated manually: -- [ACTUSTypes.sol](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/contracts/ACTUS/Core/ACTUSTypes.sol) -| [Encoder libaries e.g. ANNEncoder](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/contracts/Core/ANN/ANNEncoder.sol) -| [ACTUS.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/types/ACTUS.ts) -| [AP.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/types/AP.ts) -| [Dictionary.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/types/dictionary/dictionary.json) -| [Constants.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/utils/Constants.ts) -| [Conversions.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/utils/Conversion.ts) -| [Schedule.ts](https://github.com/atpar/ap-monorepo/blob/dev/packages/protocol/src/utils/Schedule.ts) -| [Test helpers](https://github.com/atpar/ap-monorepo/tree/dev/packages/protocol/test/helper) +- [ACTUSTypes.sol](contracts/ACTUS/Core/ACTUSTypes.sol) +| [Encoder libaries e.g. ANNEncoder](contracts/Core/ANN/ANNEncoder.sol) +| [ACTUS.ts](src/types/ACTUS.ts) +| [AP.ts](src/types/AP.ts) +| [Dictionary.ts](src/types/dictionary/dictionary.json) +| [Constants.ts](src/utils/Constants.ts) +| [Conversions.ts](src/utils/Conversion.ts) +| [Schedule.ts](src/utils/Schedule.ts) +| [Test helpers](test/helper) From 2b65b18727b22cb5d0e7ed967e9a7e663d6c3f78 Mon Sep 17 00:00:00 2001 From: jo-es Date: Wed, 23 Dec 2020 13:23:30 +0100 Subject: [PATCH 3/6] Fix STKTerms typeguard --- packages/protocol/src/types/ACTUS.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/src/types/ACTUS.ts b/packages/protocol/src/types/ACTUS.ts index 1d8b9b53..5c14467d 100644 --- a/packages/protocol/src/types/ACTUS.ts +++ b/packages/protocol/src/types/ACTUS.ts @@ -1014,7 +1014,7 @@ export function isSTKTerms (obj: any): obj is STKTerms { if (obj.settlementCurrency == undefined || typeof obj.settlementCurrency !== 'string') { return false; } if (obj.statusDate == undefined || typeof obj.statusDate !== 'number' && typeof obj.statusDate !== 'string') { return false; } - if (obj.initialExchangeDate == undefined || typeof obj.initialExchangeDate !== 'number' && typeof obj.initialExchangeDate !== 'string') { return false; } + if (obj.issueDate == undefined || typeof obj.issueDate !== 'number' && typeof obj.issueDate !== 'string') { return false; } if (obj.purchaseDate == undefined || typeof obj.purchaseDate !== 'number' && typeof obj.purchaseDate !== 'string') { return false; } if (obj.cycleAnchorDateOfDividend == undefined || typeof obj.cycleAnchorDateOfDividend !== 'number' && typeof obj.cycleAnchorDateOfDividend !== 'string') { return false; } @@ -1023,8 +1023,8 @@ export function isSTKTerms (obj: any): obj is STKTerms { if (obj.issuePrice == undefined || typeof obj.issuePrice !== 'number' && typeof obj.issuePrice !== 'string') { return false; } if (obj.quantity == undefined || typeof obj.quantity !== 'number' && typeof obj.quantity !== 'string') { return false; } if (obj.priceAtPurchaseDate == undefined || typeof obj.priceAtPurchaseDate !== 'number' && typeof obj.priceAtPurchaseDate !== 'string') { return false; } - if (obj.priceAtTerminationDate == undefined || typeof obj.priceAtTerminationDate !== 'number' && typeof obj.priceAtTerminationDate !== 'string') { return false; } if (obj.redemptionPrice == undefined || typeof obj.redemptionPrice !== 'number' && typeof obj.redemptionPrice !== 'string') { return false; } + if (obj.priceAtTerminationDate == undefined || typeof obj.priceAtTerminationDate !== 'number' && typeof obj.priceAtTerminationDate !== 'string') { return false; } if (!isIP(obj.redemptionRecordPeriod)) { return false; } if (!isIP(obj.redemptionPaymentPeriod)) { return false; } From 686640ccb6618878eb5671fc52556bb0aa5ccf21 Mon Sep 17 00:00:00 2001 From: jo-es Date: Sun, 27 Dec 2020 14:07:52 +0100 Subject: [PATCH 4/6] Update terminology for SignedMath to FixedPointMath --- packages/protocol/.solcover.js | 2 +- .../Core/Conventions/DayCountConventions.sol | 40 +++--- .../{SignedMath.sol => FixedPointMath.sol} | 31 ++-- .../contracts/ACTUS/Engines/ANN/ANNEngine.sol | 6 +- .../contracts/ACTUS/Engines/ANN/ANNPOF.sol | 26 ++-- .../contracts/ACTUS/Engines/ANN/ANNSTF.sol | 76 +++++----- .../contracts/ACTUS/Engines/CEC/CECEngine.sol | 6 +- .../contracts/ACTUS/Engines/CEC/CECSTF.sol | 10 +- .../contracts/ACTUS/Engines/CEG/CEGEngine.sol | 6 +- .../contracts/ACTUS/Engines/CEG/CEGPOF.sol | 10 +- .../contracts/ACTUS/Engines/CEG/CEGSTF.sol | 14 +- .../ACTUS/Engines/CERTF/CERTFEngine.sol | 6 +- .../ACTUS/Engines/CERTF/CERTFPOF.sol | 12 +- .../ACTUS/Engines/CERTF/CERTFSTF.sol | 12 +- .../ACTUS/Engines/COLLA/COLLAEngine.sol | 6 +- .../ACTUS/Engines/COLLA/COLLAPOF.sol | 12 +- .../ACTUS/Engines/COLLA/COLLASTF.sol | 20 +-- .../contracts/ACTUS/Engines/PAM/PAMEngine.sol | 6 +- .../contracts/ACTUS/Engines/PAM/PAMPOF.sol | 20 +-- .../contracts/ACTUS/Engines/PAM/PAMSTF.sol | 74 +++++----- .../contracts/ACTUS/Engines/STK/STKEngine.sol | 6 +- .../contracts/ACTUS/Engines/STK/STKPOF.sol | 8 +- .../contracts/ACTUS/Engines/STK/STKSTF.sol | 6 +- .../contracts/ACTUS/test/TestSignedMath.sol | 14 +- .../Core/Base/AssetActor/BaseActor.sol | 4 +- .../protocol/contracts/Core/CEC/CECActor.sol | 2 +- .../contracts/Core/CERTF/CERTFActor.sol | 4 +- .../protocol/contracts/Core/STK/STKActor.sol | 2 +- .../Extensions/Collateral/COLLACustodian.sol | 8 +- .../protocol/contracts/tokens/ICT/ICT.sol | 12 +- .../test/ACTUS/Core/TestSignedMath.js | 134 +++++++++--------- 31 files changed, 297 insertions(+), 298 deletions(-) rename packages/protocol/contracts/ACTUS/Core/{SignedMath.sol => FixedPointMath.sol} (56%) diff --git a/packages/protocol/.solcover.js b/packages/protocol/.solcover.js index a43d31c9..80a61054 100644 --- a/packages/protocol/.solcover.js +++ b/packages/protocol/.solcover.js @@ -14,7 +14,7 @@ module.exports = { 'ACTUS/test/STK/TestSTKPOF.sol', 'ACTUS/test/STK/TestSTKSTF.sol', 'ACTUS/test/TestCore.sol', - 'ACTUS/test/TestSignedMath.sol', + 'ACTUS/test/TestFixedPointMath.sol', 'SettlementToken.sol', 'NoSettlementToken.sol', 'ERC20Token.sol', diff --git a/packages/protocol/contracts/ACTUS/Core/Conventions/DayCountConventions.sol b/packages/protocol/contracts/ACTUS/Core/Conventions/DayCountConventions.sol index 5e5cbb84..a5ce2d9e 100755 --- a/packages/protocol/contracts/ACTUS/Core/Conventions/DayCountConventions.sol +++ b/packages/protocol/contracts/ACTUS/Core/Conventions/DayCountConventions.sol @@ -8,7 +8,7 @@ import "../../../external/BokkyPooBah/BokkyPooBahsDateTimeLibrary.sol"; import "../ACTUSTypes.sol"; import "../ACTUSConstants.sol"; -import "../SignedMath.sol"; +import "../FixedPointMath.sol"; /** @@ -19,7 +19,7 @@ contract DayCountConventions is ACTUSConstants { using SafeMath for uint; using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** * Returns the fraction of the year between two timestamps. @@ -76,7 +76,7 @@ contract DayCountConventions is ACTUSConstants { int256 firstBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(startTime)) ? 366 : 365; if (d1Year == d2Year) { - return int256(BokkyPooBahsDateTimeLibrary.diffDays(startTime, endTime)).floatDiv(firstBasis); + return int256(BokkyPooBahsDateTimeLibrary.diffDays(startTime, endTime)).fixedDiv(firstBasis); } int256 secondBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(endTime)) ? 366 : 365; @@ -84,11 +84,11 @@ contract DayCountConventions is ACTUSConstants { int256 firstFraction = int256(BokkyPooBahsDateTimeLibrary.diffDays( startTime, BokkyPooBahsDateTimeLibrary.timestampFromDate(d1Year.add(1), 1, 1) - )).floatDiv(firstBasis); + )).fixedDiv(firstBasis); int256 secondFraction = int256(BokkyPooBahsDateTimeLibrary.diffDays( BokkyPooBahsDateTimeLibrary.timestampFromDate(d2Year, 1, 1), endTime - )).floatDiv(secondBasis); + )).fixedDiv(secondBasis); return firstFraction.add(secondFraction).add(int256(d2Year.sub(d1Year).sub(1))); } @@ -101,7 +101,7 @@ contract DayCountConventions is ACTUSConstants { pure returns (int256) { - return (int256((endTime.sub(startTime)).div(86400)).floatDiv(360)); + return (int256((endTime.sub(startTime)).div(86400)).fixedDiv(360)); } /** @@ -112,7 +112,7 @@ contract DayCountConventions is ACTUSConstants { pure returns (int256) { - return (int256((endTime.sub(startTime)).div(86400)).floatDiv(365)); + return (int256((endTime.sub(startTime)).div(86400)).fixedDiv(365)); } /** @@ -146,7 +146,7 @@ contract DayCountConventions is ACTUSConstants { int256 delM = int256(d2Month).sub(int256(d1Month)); int256 delY = int256(d2Year).sub(int256(d1Year)); - return ((delY.mul(360).add(delM.mul(30)).add(delD)).floatDiv(360)); + return ((delY.mul(360).add(delM.mul(30)).add(delD)).fixedDiv(360)); } /** @@ -180,7 +180,7 @@ contract DayCountConventions is ACTUSConstants { int256 delM = int256(d2Month).sub(int256(d1Month)); int256 delY = int256(d2Year).sub(int256(d1Year)); - return ((delY.mul(360).add(delM.mul(30)).add(delD)).floatDiv(360)); + return ((delY.mul(360).add(delM.mul(30)).add(delD)).fixedDiv(360)); } /** @@ -207,7 +207,7 @@ contract DayCountConventions is ACTUSConstants { int256 delM = int256(d2Month).sub(int256(d1Month)); int256 delY = int256(d2Year).sub(int256(d1Year)); - return ((delY.mul(336).add(delM.mul(28)).add(delD)).floatDiv(336)); + return ((delY.mul(336).add(delM.mul(28)).add(delD)).fixedDiv(336)); } /** @@ -229,7 +229,7 @@ contract DayCountConventions is ACTUSConstants { pure returns (int256) { - return int256(ONE_POINT_ZERO).floatDiv(12 * ONE_POINT_ZERO); + return int256(ONE_POINT_ZERO).fixedDiv(12 * ONE_POINT_ZERO); } /** @@ -248,7 +248,7 @@ contract DayCountConventions is ACTUSConstants { int256 firstBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(startTime)) ? 8784 : 8760; if (d1Year == d2Year) { - return int256(BokkyPooBahsDateTimeLibrary.diffHours(startTime, endTime)).floatDiv(firstBasis); + return int256(BokkyPooBahsDateTimeLibrary.diffHours(startTime, endTime)).fixedDiv(firstBasis); } // no risk of overflow @@ -258,11 +258,11 @@ contract DayCountConventions is ACTUSConstants { int256 firstFraction = int256(BokkyPooBahsDateTimeLibrary.diffHours( startTime, BokkyPooBahsDateTimeLibrary.timestampFromDate(d1Year.add(1), 1, 1) - )).floatDiv(firstBasis); + )).fixedDiv(firstBasis); int256 secondFraction = int256(BokkyPooBahsDateTimeLibrary.diffHours( BokkyPooBahsDateTimeLibrary.timestampFromDate(d2Year, 1, 1), endTime - )).floatDiv(secondBasis); + )).fixedDiv(secondBasis); return firstFraction.add(secondFraction).add(int256(d2Year.sub(d1Year).sub(1))); } @@ -283,7 +283,7 @@ contract DayCountConventions is ACTUSConstants { int256 firstBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(startTime)) ? 527040 : 525600; if (d1Year == d2Year) { - return int256(BokkyPooBahsDateTimeLibrary.diffMinutes(startTime, endTime)).floatDiv(firstBasis); + return int256(BokkyPooBahsDateTimeLibrary.diffMinutes(startTime, endTime)).fixedDiv(firstBasis); } // no risk of overflow @@ -293,11 +293,11 @@ contract DayCountConventions is ACTUSConstants { int256 firstFraction = int256(BokkyPooBahsDateTimeLibrary.diffMinutes( startTime, BokkyPooBahsDateTimeLibrary.timestampFromDate(d1Year.add(1), 1, 1) - )).floatDiv(firstBasis); + )).fixedDiv(firstBasis); int256 secondFraction = int256(BokkyPooBahsDateTimeLibrary.diffMinutes( BokkyPooBahsDateTimeLibrary.timestampFromDate(d2Year, 1, 1), endTime - )).floatDiv(secondBasis); + )).fixedDiv(secondBasis); return firstFraction.add(secondFraction).add(int256(d2Year.sub(d1Year).sub(1))); } @@ -318,7 +318,7 @@ contract DayCountConventions is ACTUSConstants { int256 firstBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(startTime)) ? 31622400 : 31536000; if (d1Year == d2Year) { - return int256(BokkyPooBahsDateTimeLibrary.diffSeconds(startTime, endTime)).floatDiv(firstBasis); + return int256(BokkyPooBahsDateTimeLibrary.diffSeconds(startTime, endTime)).fixedDiv(firstBasis); } // no risk of overflow @@ -328,11 +328,11 @@ contract DayCountConventions is ACTUSConstants { int256 firstFraction = int256(BokkyPooBahsDateTimeLibrary.diffSeconds( startTime, BokkyPooBahsDateTimeLibrary.timestampFromDate(d1Year.add(1), 1, 1) - )).floatDiv(firstBasis); + )).fixedDiv(firstBasis); int256 secondFraction = int256(BokkyPooBahsDateTimeLibrary.diffSeconds( BokkyPooBahsDateTimeLibrary.timestampFromDate(d2Year, 1, 1), endTime - )).floatDiv(secondBasis); + )).fixedDiv(secondBasis); return firstFraction.add(secondFraction).add(int256(d2Year.sub(d1Year).sub(1))); } diff --git a/packages/protocol/contracts/ACTUS/Core/SignedMath.sol b/packages/protocol/contracts/ACTUS/Core/FixedPointMath.sol similarity index 56% rename from packages/protocol/contracts/ACTUS/Core/SignedMath.sol rename to packages/protocol/contracts/ACTUS/Core/FixedPointMath.sol index cf3f88fc..26668559 100644 --- a/packages/protocol/contracts/ACTUS/Core/SignedMath.sol +++ b/packages/protocol/contracts/ACTUS/Core/FixedPointMath.sol @@ -3,10 +3,9 @@ pragma solidity ^0.7.0; /** - * Advanced math library for signed integers - * (including floats which are represented as multiples of 10 ** 18) + * Fixed point math library for signed integers */ -library SignedMath { +library FixedPointMath { int256 constant private INT256_MIN = -2 ** 255; @@ -19,53 +18,53 @@ library SignedMath { * as devision (normalization) is performed after multiplication * Upper boundary would be (10 ** 58) * (MULTIPLICATOR) == ~10 ** 76 */ - function floatMult(int256 a, int256 b) + function fixedMul(int256 a, int256 b) internal pure returns (int256) { if (a == 0 || b == 0) return 0; - require(!(a == -1 && b == INT256_MIN), "SignedMath.floatMult: OVERFLOW_DETECTED"); + require(!(a == -1 && b == INT256_MIN), "FixedPointMath.fixedMul: OVERFLOW_DETECTED"); int256 c = a * b; - require(c / a == b, "SignedMath.floatMult: OVERFLOW_DETECTED"); + require(c / a == b, "FixedPointMath.fixedMul: OVERFLOW_DETECTED"); // normalize (divide by MULTIPLICATOR) int256 d = c / int256(MULTIPLICATOR); - require(d != 0, "SignedMath.floatMult: CANNOT_REPRESENT_GRANULARITY"); + require(d != 0, "FixedPointMath.fixedMul: CANNOT_REPRESENT_GRANULARITY"); return d; } - function floatDiv(int256 a, int256 b) + function fixedDiv(int256 a, int256 b) internal pure returns (int256) { - require(b != 0, "SignedMath.floatDiv: DIVIDED_BY_ZERO"); + require(b != 0, "FixedPointMath.fixedDiv: DIVIDED_BY_ZERO"); // normalize (multiply by MULTIPLICATOR) if (a == 0) return 0; int256 c = a * int256(MULTIPLICATOR); - require(c / a == int256(MULTIPLICATOR), "SignedMath.floatDiv: OVERFLOW_DETECTED"); + require(c / a == int256(MULTIPLICATOR), "FixedPointMath.fixedDiv: OVERFLOW_DETECTED"); - require(!(b == -1 && a == INT256_MIN), "SignedMath.floatDiv: OVERFLOW_DETECTED"); + require(!(b == -1 && a == INT256_MIN), "FixedPointMath.fixedDiv: OVERFLOW_DETECTED"); int256 d = c / b; - require(d != 0, "SignedMath.floatDiv: CANNOT_REPRESENT_GRANULARITY"); + require(d != 0, "FixedPointMath.fixedDiv: CANNOT_REPRESENT_GRANULARITY"); return d; } /** - * @dev Returns the smallest of two signed numbers. - */ + * @dev Returns the smallest of two signed numbers. + */ function min(int256 a, int256 b) internal pure returns (int256) { return a <= b ? a : b; } /** - * @dev Returns the largest of two signed numbers. - */ + * @dev Returns the largest of two signed numbers. + */ function max(int256 a, int256 b) internal pure returns (int256) { return a >= b ? a : b; } diff --git a/packages/protocol/contracts/ACTUS/Engines/ANN/ANNEngine.sol b/packages/protocol/contracts/ACTUS/Engines/ANN/ANNEngine.sol index 47f4911a..dc39fa65 100755 --- a/packages/protocol/contracts/ACTUS/Engines/ANN/ANNEngine.sol +++ b/packages/protocol/contracts/ACTUS/Engines/ANN/ANNEngine.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; import "./IANNEngine.sol"; import "./ANNSTF.sol"; import "./ANNPOF.sol"; @@ -19,7 +19,7 @@ import "./ANNPOF.sol"; contract ANNEngine is Core, ANNSTF, ANNPOF, IANNEngine { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; function contractType() external pure override returns (ContractType) { @@ -79,7 +79,7 @@ contract ANNEngine is Core, ANNSTF, ANNPOF, IANNEngine { state, _event, externalData - ).floatMult(abi.decode(externalData, (int256))); + ).fixedMul(abi.decode(externalData, (int256))); } return payoffFunction( diff --git a/packages/protocol/contracts/ACTUS/Engines/ANN/ANNPOF.sol b/packages/protocol/contracts/ACTUS/Engines/ANN/ANNPOF.sol index 384b0bf0..c9010ca8 100644 --- a/packages/protocol/contracts/ACTUS/Engines/ANN/ANNPOF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/ANN/ANNPOF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract ANNPOF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -54,8 +54,8 @@ contract ANNPOF is Core { state.feeAccrued .add( timeFromLastEvent - .floatMult(terms.feeRate) - .floatMult(state.notionalPrincipal) + .fixedMul(terms.feeRate) + .fixedMul(state.notionalPrincipal) ) ); } @@ -108,12 +108,12 @@ contract ANNPOF is Core { return ( state.interestScalingMultiplier - .floatMult( + .fixedMul( state.accruedInterest .add( timeFromLastEvent - .floatMult(state.nominalInterestRate) - .floatMult(state.notionalPrincipal) + .fixedMul(state.nominalInterestRate) + .fixedMul(state.notionalPrincipal) ) ) ); @@ -155,7 +155,7 @@ contract ANNPOF is Core { { return ( state.notionalScalingMultiplier - .floatMult(state.notionalPrincipal) + .fixedMul(state.notionalPrincipal) ); } @@ -189,8 +189,8 @@ contract ANNPOF is Core { .add(state.accruedInterest) .add( timeFromLastEvent - .floatMult(state.nominalInterestRate) - .floatMult(state.notionalPrincipal) + .fixedMul(state.nominalInterestRate) + .fixedMul(state.notionalPrincipal) ) ); } @@ -222,7 +222,7 @@ contract ANNPOF is Core { return ( (state.notionalScalingMultiplier * roleSign(terms.contractRole)) - .floatMult( + .fixedMul( (roleSign(terms.contractRole) * state.notionalPrincipal) .min( roleSign(terms.contractRole) @@ -230,8 +230,8 @@ contract ANNPOF is Core { state.nextPrincipalRedemptionPayment .sub(state.accruedInterest) .sub(timeFromLastEvent - .floatMult(state.nominalInterestRate) - .floatMult(state.notionalPrincipal)) + .fixedMul(state.nominalInterestRate) + .fixedMul(state.notionalPrincipal)) ) ) ) diff --git a/packages/protocol/contracts/ACTUS/Engines/ANN/ANNSTF.sol b/packages/protocol/contracts/ACTUS/Engines/ANN/ANNSTF.sol index 10fa8cd2..6205971d 100644 --- a/packages/protocol/contracts/ACTUS/Engines/ANN/ANNSTF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/ANN/ANNSTF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract ANNSTF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -63,14 +63,14 @@ contract ANNSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.statusDate = scheduleTime; @@ -123,8 +123,8 @@ contract ANNSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = 0; state.statusDate = scheduleTime; @@ -159,14 +159,14 @@ contract ANNSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); // state.notionalPrincipal -= 0; // riskFactor not supported state.statusDate = scheduleTime; @@ -201,14 +201,14 @@ contract ANNSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.nominalInterestRate = terms.nextResetRate; state.statusDate = scheduleTime; @@ -339,16 +339,16 @@ contract ANNSTF is Core { state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ) ); state.accruedInterest = 0; state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.statusDate = scheduleTime; @@ -378,8 +378,8 @@ contract ANNSTF is Core { state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.statusDate = scheduleTime; @@ -408,14 +408,14 @@ contract ANNSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.notionalPrincipal = state.notionalPrincipal .sub( @@ -460,14 +460,14 @@ contract ANNSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.notionalPrincipal = 0.0; state.contractPerformance = ContractPerformance.MD; @@ -487,8 +487,8 @@ contract ANNSTF is Core { returns (ANNState memory) { // riskFactor not supported - // int256 rate = int256(uint256(externalData)).floatMult(terms.rateMultiplier).add(terms.rateSpread); - int256 rate = abi.decode(externalData, (int256)).floatMult(terms.rateMultiplier).add(terms.rateSpread); + // int256 rate = int256(uint256(externalData)).fixedMul(terms.rateMultiplier).add(terms.rateSpread); + int256 rate = abi.decode(externalData, (int256)).fixedMul(terms.rateMultiplier).add(terms.rateSpread); int256 deltaRate = rate.sub(state.nominalInterestRate); // apply period cap/floor @@ -518,8 +518,8 @@ contract ANNSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.nominalInterestRate = rate; state.nextPrincipalRedemptionPayment = 0; // annuity calculator not supported @@ -550,14 +550,14 @@ contract ANNSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); if ((terms.scalingEffect == ScalingEffect.I00) || (terms.scalingEffect == ScalingEffect.IN0)) { diff --git a/packages/protocol/contracts/ACTUS/Engines/CEC/CECEngine.sol b/packages/protocol/contracts/ACTUS/Engines/CEC/CECEngine.sol index d0feae23..77541af5 100644 --- a/packages/protocol/contracts/ACTUS/Engines/CEC/CECEngine.sol +++ b/packages/protocol/contracts/ACTUS/Engines/CEC/CECEngine.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; import "./ICECEngine.sol"; import "./CECSTF.sol"; import "./CECPOF.sol"; @@ -20,7 +20,7 @@ import "./CECPOF.sol"; contract CECEngine is Core, CECSTF, CECPOF, ICECEngine { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; function contractType() external pure override returns (ContractType) { @@ -80,7 +80,7 @@ contract CECEngine is Core, CECSTF, CECPOF, ICECEngine { // state, // _event, // externalData - // ).floatMult(int256(externalData)); + // ).fixedMul(int256(externalData)); // } return payoffFunction( diff --git a/packages/protocol/contracts/ACTUS/Engines/CEC/CECSTF.sol b/packages/protocol/contracts/ACTUS/Engines/CEC/CECSTF.sol index d63ae773..44d99fb4 100644 --- a/packages/protocol/contracts/ACTUS/Engines/CEC/CECSTF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/CEC/CECSTF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract CECSTF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -73,7 +73,7 @@ contract CECSTF is Core { } // decode state.notionalPrincipal of underlying from externalData - int256 underlyingNotionalPrincipal = terms.coverageOfCreditEnhancement.floatMult( + int256 underlyingNotionalPrincipal = terms.coverageOfCreditEnhancement.fixedMul( abi.decode(externalData, (int256)) ); @@ -87,8 +87,8 @@ contract CECSTF is Core { state.feeAccrued = state.feeAccrued .add( timeFromLastEvent - .floatMult(terms.feeRate) - .floatMult(underlyingNotionalPrincipal) + .fixedMul(terms.feeRate) + .fixedMul(underlyingNotionalPrincipal) ); } diff --git a/packages/protocol/contracts/ACTUS/Engines/CEG/CEGEngine.sol b/packages/protocol/contracts/ACTUS/Engines/CEG/CEGEngine.sol index a58368fc..2adbbb07 100644 --- a/packages/protocol/contracts/ACTUS/Engines/CEG/CEGEngine.sol +++ b/packages/protocol/contracts/ACTUS/Engines/CEG/CEGEngine.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; import "./ICEGEngine.sol"; import "./CEGSTF.sol"; import "./CEGPOF.sol"; @@ -20,7 +20,7 @@ import "./CEGPOF.sol"; contract CEGEngine is Core, CEGSTF, CEGPOF, ICEGEngine { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; function contractType() external pure override returns (ContractType) { @@ -80,7 +80,7 @@ contract CEGEngine is Core, CEGSTF, CEGPOF, ICEGEngine { state, _event, externalData - ).floatMult(abi.decode(externalData, (int256))); + ).fixedMul(abi.decode(externalData, (int256))); } return payoffFunction( diff --git a/packages/protocol/contracts/ACTUS/Engines/CEG/CEGPOF.sol b/packages/protocol/contracts/ACTUS/Engines/CEG/CEGPOF.sol index 62c009e4..ab1574a8 100644 --- a/packages/protocol/contracts/ACTUS/Engines/CEG/CEGPOF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/CEG/CEGPOF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract CEGPOF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -69,14 +69,14 @@ contract CEGPOF is Core { int256 notionalPrincipal = (terms.notionalPrincipal > 0) ? terms.notionalPrincipal // decode state.notionalPrincipal of underlying from externalData - : terms.coverageOfCreditEnhancement.floatMult(abi.decode(externalData, (int256))); + : terms.coverageOfCreditEnhancement.fixedMul(abi.decode(externalData, (int256))); return ( state.feeAccrued .add( timeFromLastEvent - .floatMult(terms.feeRate) - .floatMult(notionalPrincipal) + .fixedMul(terms.feeRate) + .fixedMul(notionalPrincipal) ) ); } diff --git a/packages/protocol/contracts/ACTUS/Engines/CEG/CEGSTF.sol b/packages/protocol/contracts/ACTUS/Engines/CEG/CEGSTF.sol index e10c96de..0e1e69b6 100644 --- a/packages/protocol/contracts/ACTUS/Engines/CEG/CEGSTF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/CEG/CEGSTF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract CEGSTF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -116,7 +116,7 @@ contract CEGSTF is Core { state.notionalPrincipal = (terms.notionalPrincipal > 0) ? terms.notionalPrincipal // decode state.notionalPrincipal of underlying from externalData - : terms.coverageOfCreditEnhancement.floatMult(abi.decode(externalData, (int256))); + : terms.coverageOfCreditEnhancement.fixedMul(abi.decode(externalData, (int256))); state.exerciseAmount = state.notionalPrincipal; state.exerciseDate = scheduleTime; @@ -126,8 +126,8 @@ contract CEGSTF is Core { state.feeAccrued = state.feeAccrued .add( timeFromLastEvent - .floatMult(terms.feeRate) - .floatMult(state.notionalPrincipal) + .fixedMul(terms.feeRate) + .fixedMul(state.notionalPrincipal) ); } @@ -165,7 +165,7 @@ contract CEGSTF is Core { state.notionalPrincipal = (terms.notionalPrincipal > 0) ? terms.notionalPrincipal // decode state.notionalPrincipal of underlying from externalData - : terms.coverageOfCreditEnhancement.floatMult(abi.decode(externalData, (int256))); + : terms.coverageOfCreditEnhancement.fixedMul(abi.decode(externalData, (int256))); state.statusDate = scheduleTime; return state; @@ -184,7 +184,7 @@ contract CEGSTF is Core { state.notionalPrincipal = (terms.notionalPrincipal > 0) ? terms.notionalPrincipal // decode state.notionalPrincipal of underlying from externalData - : terms.coverageOfCreditEnhancement.floatMult(abi.decode(externalData, (int256))); + : terms.coverageOfCreditEnhancement.fixedMul(abi.decode(externalData, (int256))); state.feeAccrued = 0; state.statusDate = scheduleTime; diff --git a/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFEngine.sol b/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFEngine.sol index 54caa787..9d17ba13 100755 --- a/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFEngine.sol +++ b/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFEngine.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; import "./ICERTFEngine.sol"; import "./CERTFSTF.sol"; import "./CERTFPOF.sol"; @@ -19,7 +19,7 @@ import "./CERTFPOF.sol"; contract CERTFEngine is Core, CERTFSTF, CERTFPOF, ICERTFEngine { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; function contractType() external pure override returns (ContractType) { @@ -79,7 +79,7 @@ contract CERTFEngine is Core, CERTFSTF, CERTFPOF, ICERTFEngine { state, _event, externalData - ).floatMult(abi.decode(externalData, (int256))); + ).fixedMul(abi.decode(externalData, (int256))); } return payoffFunction( diff --git a/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFPOF.sol b/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFPOF.sol index ffdcd7f2..27121443 100644 --- a/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFPOF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFPOF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract CERTFPOF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -33,7 +33,7 @@ contract CERTFPOF is Core { returns(int256) { return ( - roleSign(terms.contractRole) * state.quantity.floatMult(terms.issuePrice) + roleSign(terms.contractRole) * state.quantity.fixedMul(terms.issuePrice) ); } @@ -52,7 +52,7 @@ contract CERTFPOF is Core { returns(int256) { return ( - roleSign(terms.contractRole) * state.quantity.floatMult(state.couponAmountFixed) + roleSign(terms.contractRole) * state.quantity.fixedMul(state.couponAmountFixed) ); } @@ -71,7 +71,7 @@ contract CERTFPOF is Core { returns(int256) { return ( - roleSign(terms.contractRole) * state.exerciseQuantity.floatMult(state.exerciseAmount) + roleSign(terms.contractRole) * state.exerciseQuantity.fixedMul(state.exerciseAmount) ); } @@ -90,7 +90,7 @@ contract CERTFPOF is Core { returns(int256) { return ( - roleSign(terms.contractRole) * state.quantity.floatMult(state.exerciseAmount) + roleSign(terms.contractRole) * state.quantity.fixedMul(state.exerciseAmount) ); } } diff --git a/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFSTF.sol b/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFSTF.sol index f3395996..9d2fd79f 100644 --- a/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFSTF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/CERTF/CERTFSTF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract CERTFSTF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -79,7 +79,7 @@ contract CERTFSTF is Core { shiftCalcTime(scheduleTime, terms.businessDayConvention, terms.calendar, terms.maturityDate), terms.dayCountConvention, terms.maturityDate - ).floatMult(terms.nominalPrice).floatMult(terms.couponRate); + ).fixedMul(terms.nominalPrice).fixedMul(terms.couponRate); } state.lastCouponFixingDate = scheduleTime; @@ -126,9 +126,9 @@ contract CERTFSTF is Core { returns (CERTFState memory) { state.exerciseAmount = abi.decode(externalData, (int256)) - .floatMult(terms.nominalPrice) - .floatMult(state.marginFactor) - .floatMult(state.adjustmentFactor); + .fixedMul(terms.nominalPrice) + .fixedMul(state.marginFactor) + .fixedMul(state.adjustmentFactor); state.statusDate = scheduleTime; diff --git a/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLAEngine.sol b/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLAEngine.sol index a8f5d6d4..094db571 100755 --- a/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLAEngine.sol +++ b/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLAEngine.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; import "./ICOLLAEngine.sol"; import "./COLLASTF.sol"; import "./COLLAPOF.sol"; @@ -19,7 +19,7 @@ import "./COLLAPOF.sol"; contract COLLAEngine is Core, COLLASTF, COLLAPOF, ICOLLAEngine { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; function contractType() external pure override returns (ContractType) { @@ -79,7 +79,7 @@ contract COLLAEngine is Core, COLLASTF, COLLAPOF, ICOLLAEngine { state, _event, externalData - ).floatMult(abi.decode(externalData, (int256))); + ).fixedMul(abi.decode(externalData, (int256))); } return payoffFunction( diff --git a/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLAPOF.sol b/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLAPOF.sol index e0e00179..a2bedef8 100644 --- a/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLAPOF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLAPOF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract COLLAPOF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -66,12 +66,12 @@ contract COLLAPOF is Core { return ( state.interestScalingMultiplier - .floatMult( + .fixedMul( state.accruedInterest .add( timeFromLastEvent - .floatMult(state.nominalInterestRate) - .floatMult(state.notionalPrincipal) + .fixedMul(state.nominalInterestRate) + .fixedMul(state.notionalPrincipal) ) ) ); @@ -93,7 +93,7 @@ contract COLLAPOF is Core { { return ( state.notionalScalingMultiplier - .floatMult(state.notionalPrincipal) + .fixedMul(state.notionalPrincipal) ); } } diff --git a/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLASTF.sol b/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLASTF.sol index dbad90e1..3d168090 100644 --- a/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLASTF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/COLLA/COLLASTF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract COLLASTF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -63,8 +63,8 @@ contract COLLASTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.statusDate = scheduleTime; @@ -123,8 +123,8 @@ contract COLLASTF is Core { state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ) ); state.accruedInterest = 0; @@ -190,8 +190,8 @@ contract COLLASTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.notionalPrincipal = 0; state.statusDate = scheduleTime; @@ -226,8 +226,8 @@ contract COLLASTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.notionalPrincipal = 0; state.contractPerformance = ContractPerformance.MD; diff --git a/packages/protocol/contracts/ACTUS/Engines/PAM/PAMEngine.sol b/packages/protocol/contracts/ACTUS/Engines/PAM/PAMEngine.sol index 38b92ff8..a53255f2 100755 --- a/packages/protocol/contracts/ACTUS/Engines/PAM/PAMEngine.sol +++ b/packages/protocol/contracts/ACTUS/Engines/PAM/PAMEngine.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; import "./IPAMEngine.sol"; import "./PAMSTF.sol"; import "./PAMPOF.sol"; @@ -19,7 +19,7 @@ import "./PAMPOF.sol"; contract PAMEngine is Core, PAMSTF, PAMPOF, IPAMEngine { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; function contractType() external pure override returns (ContractType) { @@ -79,7 +79,7 @@ contract PAMEngine is Core, PAMSTF, PAMPOF, IPAMEngine { state, _event, externalData - ).floatMult(abi.decode(externalData, (int256))); + ).fixedMul(abi.decode(externalData, (int256))); } return payoffFunction( diff --git a/packages/protocol/contracts/ACTUS/Engines/PAM/PAMPOF.sol b/packages/protocol/contracts/ACTUS/Engines/PAM/PAMPOF.sol index de4848ec..38e52e38 100644 --- a/packages/protocol/contracts/ACTUS/Engines/PAM/PAMPOF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/PAM/PAMPOF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract PAMPOF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -54,8 +54,8 @@ contract PAMPOF is Core { state.feeAccrued .add( timeFromLastEvent - .floatMult(terms.feeRate) - .floatMult(state.notionalPrincipal) + .fixedMul(terms.feeRate) + .fixedMul(state.notionalPrincipal) ) ); } @@ -108,12 +108,12 @@ contract PAMPOF is Core { return ( state.interestScalingMultiplier - .floatMult( + .fixedMul( state.accruedInterest .add( timeFromLastEvent - .floatMult(state.nominalInterestRate) - .floatMult(state.notionalPrincipal) + .fixedMul(state.nominalInterestRate) + .fixedMul(state.notionalPrincipal) ) ) ); @@ -155,7 +155,7 @@ contract PAMPOF is Core { { return ( state.notionalScalingMultiplier - .floatMult(state.notionalPrincipal) + .fixedMul(state.notionalPrincipal) ); } @@ -189,8 +189,8 @@ contract PAMPOF is Core { .add(state.accruedInterest) .add( timeFromLastEvent - .floatMult(state.nominalInterestRate) - .floatMult(state.notionalPrincipal) + .fixedMul(state.nominalInterestRate) + .fixedMul(state.notionalPrincipal) ) ); } diff --git a/packages/protocol/contracts/ACTUS/Engines/PAM/PAMSTF.sol b/packages/protocol/contracts/ACTUS/Engines/PAM/PAMSTF.sol index 76ebf4a1..8927a354 100644 --- a/packages/protocol/contracts/ACTUS/Engines/PAM/PAMSTF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/PAM/PAMSTF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract PAMSTF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -63,14 +63,14 @@ contract PAMSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.statusDate = scheduleTime; @@ -123,8 +123,8 @@ contract PAMSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = 0; state.statusDate = scheduleTime; @@ -184,16 +184,16 @@ contract PAMSTF is Core { state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ) ); state.accruedInterest = 0; state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.statusDate = scheduleTime; @@ -228,8 +228,8 @@ contract PAMSTF is Core { state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.statusDate = scheduleTime; @@ -263,14 +263,14 @@ contract PAMSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); // state.notionalPrincipal -= 0; // riskFactor not supported state.statusDate = scheduleTime; @@ -305,14 +305,14 @@ contract PAMSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.notionalPrincipal = 0; state.statusDate = scheduleTime; @@ -347,14 +347,14 @@ contract PAMSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.nominalInterestRate = terms.nextResetRate; state.statusDate = scheduleTime; @@ -379,7 +379,7 @@ contract PAMSTF is Core { { // apply external rate, multiply with rateMultiplier and add the spread // riskFactor not supported - int256 rate = abi.decode(externalData, (int256)).floatMult(terms.rateMultiplier).add(terms.rateSpread); + int256 rate = abi.decode(externalData, (int256)).fixedMul(terms.rateMultiplier).add(terms.rateSpread); // deltaRate is the difference between the rate that includes external data, spread and multiplier and the currently active rate from the state int256 deltaRate = rate.sub(state.nominalInterestRate); @@ -409,8 +409,8 @@ contract PAMSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.nominalInterestRate = rate; state.statusDate = scheduleTime; @@ -445,14 +445,14 @@ contract PAMSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); if ((terms.scalingEffect == ScalingEffect.I00) || (terms.scalingEffect == ScalingEffect.IN0)) { @@ -494,14 +494,14 @@ contract PAMSTF is Core { state.accruedInterest = state.accruedInterest .add( state.nominalInterestRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.feeAccrued = state.feeAccrued .add( terms.feeRate - .floatMult(state.notionalPrincipal) - .floatMult(timeFromLastEvent) + .fixedMul(state.notionalPrincipal) + .fixedMul(timeFromLastEvent) ); state.notionalPrincipal = 0; state.contractPerformance = ContractPerformance.MD; diff --git a/packages/protocol/contracts/ACTUS/Engines/STK/STKEngine.sol b/packages/protocol/contracts/ACTUS/Engines/STK/STKEngine.sol index 842eb291..ea2d309f 100755 --- a/packages/protocol/contracts/ACTUS/Engines/STK/STKEngine.sol +++ b/packages/protocol/contracts/ACTUS/Engines/STK/STKEngine.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; import "./ISTKEngine.sol"; import "./STKSTF.sol"; import "./STKPOF.sol"; @@ -19,7 +19,7 @@ import "./STKPOF.sol"; contract STKEngine is Core, STKSTF, STKPOF, ISTKEngine { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; function contractType() external pure override returns (ContractType) { @@ -79,7 +79,7 @@ contract STKEngine is Core, STKSTF, STKPOF, ISTKEngine { state, _event, externalData - ).floatMult(abi.decode(externalData, (int256))); + ).fixedMul(abi.decode(externalData, (int256))); } return payoffFunction( diff --git a/packages/protocol/contracts/ACTUS/Engines/STK/STKPOF.sol b/packages/protocol/contracts/ACTUS/Engines/STK/STKPOF.sol index bbcc97f5..3babe684 100644 --- a/packages/protocol/contracts/ACTUS/Engines/STK/STKPOF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/STK/STKPOF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract STKPOF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -54,7 +54,7 @@ contract STKPOF is Core { if (terms.redeemableByIssuer == RedeemableByIssuer.Y) { return ( roleSign(terms.contractRole) * state.exerciseQuantity - .floatMult(terms.redemptionPrice != 0 ? terms.redemptionPrice : abi.decode(externalData, (int256))) + .fixedMul(terms.redemptionPrice != 0 ? terms.redemptionPrice : abi.decode(externalData, (int256))) ); } @@ -76,7 +76,7 @@ contract STKPOF is Core { returns(int256) { return ( - roleSign(terms.contractRole) * state.quantity.floatMult(terms.priceAtTerminationDate) + roleSign(terms.contractRole) * state.quantity.fixedMul(terms.priceAtTerminationDate) ); } } diff --git a/packages/protocol/contracts/ACTUS/Engines/STK/STKSTF.sol b/packages/protocol/contracts/ACTUS/Engines/STK/STKSTF.sol index bb2af83a..0b4263a3 100644 --- a/packages/protocol/contracts/ACTUS/Engines/STK/STKSTF.sol +++ b/packages/protocol/contracts/ACTUS/Engines/STK/STKSTF.sol @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/math/SignedSafeMath.sol"; import "../../Core/Core.sol"; -import "../../Core/SignedMath.sol"; +import "../../Core/FixedPointMath.sol"; /** @@ -15,7 +15,7 @@ import "../../Core/SignedMath.sol"; contract STKSTF is Core { using SignedSafeMath for int; - using SignedMath for int; + using FixedPointMath for int; /** @@ -155,7 +155,7 @@ contract STKSTF is Core { pure returns (STKState memory) { - state.quantity = state.splitRatio.floatMult(state.quantity); + state.quantity = state.splitRatio.fixedMul(state.quantity); state.splitRatio = 0; state.statusDate = scheduleTime; return state; diff --git a/packages/protocol/contracts/ACTUS/test/TestSignedMath.sol b/packages/protocol/contracts/ACTUS/test/TestSignedMath.sol index 0b5d35c6..843a3de7 100644 --- a/packages/protocol/contracts/ACTUS/test/TestSignedMath.sol +++ b/packages/protocol/contracts/ACTUS/test/TestSignedMath.sol @@ -2,30 +2,30 @@ pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; -import "../Core/SignedMath.sol"; +import "../Core/FixedPointMath.sol"; /** * These helper contracts expose internal functions for unit testing. */ -contract TestSignedMath { +contract TestFixedPointMath { - using SignedMath for int; + using FixedPointMath for int; - function _floatMult(int256 a, int256 b) + function _fixedMul(int256 a, int256 b) public pure returns (int256) { - return int(a).floatMult(b); + return int(a).fixedMul(b); } - function _floatDiv(int256 a, int256 b) + function _fixedDiv(int256 a, int256 b) public pure returns (int256) { - return int(a).floatDiv(b); + return int(a).fixedDiv(b); } function _min(int256 a, int256 b) public pure returns (int256) { diff --git a/packages/protocol/contracts/Core/Base/AssetActor/BaseActor.sol b/packages/protocol/contracts/Core/Base/AssetActor/BaseActor.sol index f04208d0..4e21818c 100644 --- a/packages/protocol/contracts/Core/Base/AssetActor/BaseActor.sol +++ b/packages/protocol/contracts/Core/Base/AssetActor/BaseActor.sol @@ -7,7 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; -import "../../../ACTUS/Core/SignedMath.sol"; +import "../../../ACTUS/Core/FixedPointMath.sol"; import "../../../ACTUS/Core/Conventions/BusinessDayConventions.sol"; import "../../../ACTUS/Core/Utils/EventUtils.sol"; @@ -31,7 +31,7 @@ import "./IAssetActor.sol"; */ abstract contract BaseActor is Conversions, EventUtils, BusinessDayConventions, IAssetActor, Ownable, ReentrancyGuard { using SafeERC20 for IERC20; - using SignedMath for int; + using FixedPointMath for int; event InitializedAsset(bytes32 indexed assetId, ContractType contractType, address creator, address counterparty); event ProgressedAsset(bytes32 indexed assetId, EventType eventType, uint256 scheduleTime, int256 payoff); diff --git a/packages/protocol/contracts/Core/CEC/CECActor.sol b/packages/protocol/contracts/Core/CEC/CECActor.sol index b6ab5d20..5e3635a9 100644 --- a/packages/protocol/contracts/Core/CEC/CECActor.sol +++ b/packages/protocol/contracts/Core/CEC/CECActor.sol @@ -15,7 +15,7 @@ import "./ICECRegistry.sol"; */ contract CECActor is BaseActor { - using SignedMath for int; + using FixedPointMath for int; constructor( diff --git a/packages/protocol/contracts/Core/CERTF/CERTFActor.sol b/packages/protocol/contracts/Core/CERTF/CERTFActor.sol index d881ceb8..b1feb2ee 100644 --- a/packages/protocol/contracts/Core/CERTF/CERTFActor.sol +++ b/packages/protocol/contracts/Core/CERTF/CERTFActor.sol @@ -14,7 +14,7 @@ import "./ICERTFRegistry.sol"; */ contract CERTFActor is BaseActor { - using SignedMath for int; + using FixedPointMath for int; constructor( @@ -248,7 +248,7 @@ contract CERTFActor is BaseActor { assetRegistry.getUIntValueForTermsAttribute(assetId, "issueDate") ); if (isSetScheduleTime && isSetAnchorDate) { - return abi.encode(marketValueScheduleTime.floatDiv(marketValueAnchorDate)); + return abi.encode(marketValueScheduleTime.fixedDiv(marketValueAnchorDate)); } } } diff --git a/packages/protocol/contracts/Core/STK/STKActor.sol b/packages/protocol/contracts/Core/STK/STKActor.sol index 2216e83e..39cc1874 100644 --- a/packages/protocol/contracts/Core/STK/STKActor.sol +++ b/packages/protocol/contracts/Core/STK/STKActor.sol @@ -14,7 +14,7 @@ import "./ISTKRegistry.sol"; */ contract STKActor is BaseActor { - using SignedMath for int; + using FixedPointMath for int; enum STKExternalDataType {NA, DIP, SRA, REXA} diff --git a/packages/protocol/contracts/Extensions/Collateral/COLLACustodian.sol b/packages/protocol/contracts/Extensions/Collateral/COLLACustodian.sol index 0656a664..231eb265 100644 --- a/packages/protocol/contracts/Extensions/Collateral/COLLACustodian.sol +++ b/packages/protocol/contracts/Extensions/Collateral/COLLACustodian.sol @@ -8,7 +8,7 @@ import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import "../../ACTUS/Core/Utils/EventUtils.sol"; -import "../../ACTUS/Core/SignedMath.sol"; +import "../../ACTUS/Core/FixedPointMath.sol"; import "../../Core/Base/AssetRegistry/IAssetRegistry.sol"; import "../../Core/Base/OracleProxy/IPriceOracleProxy.sol"; @@ -23,7 +23,7 @@ import "../IExtension.sol"; contract COLLACustodian is EventUtils, Conversions, IExtension { using SafeERC20 for IERC20; using SafeMath for uint256; - using SignedMath for int256; + using FixedPointMath for int256; event AddedCollateral(bytes32 indexed assetId, address collateralizer, uint256 collateralAmount); event WithdrewCollateral(bytes32 indexed assetId, address collateralizer, uint256 withdrawnAmount); @@ -217,7 +217,7 @@ contract COLLACustodian is EventUtils, Conversions, IExtension { int256 coverage = assetRegistry.getIntValueForTermsAttribute(assetId, "coverageOfCollateral"); int256 principal = assetRegistry.getIntValueForTermsAttribute(assetId, "notionalPrincipal"); - int256 minCollateralAmount = principal.floatMult(coverage); + int256 minCollateralAmount = principal.fixedMul(coverage); // if collateral token != asset currency --> determine value if (currency != collateralCurrency) { @@ -228,7 +228,7 @@ contract COLLACustodian is EventUtils, Conversions, IExtension { isSet == true, "Collateral.computeMinCollateralAmount: NO_RATE_FOUND" ); - minCollateralAmount = minCollateralAmount.floatMult(rate); + minCollateralAmount = minCollateralAmount.fixedMul(rate); } return uint256(minCollateralAmount); diff --git a/packages/protocol/contracts/tokens/ICT/ICT.sol b/packages/protocol/contracts/tokens/ICT/ICT.sol index 3673e014..f99b316f 100644 --- a/packages/protocol/contracts/tokens/ICT/ICT.sol +++ b/packages/protocol/contracts/tokens/ICT/ICT.sol @@ -11,7 +11,7 @@ import "../../ACTUS/Core/ACTUSTypes.sol"; import "../../ACTUS/Core/Utils/EventUtils.sol"; import "../../ACTUS/Core/Utils/PeriodUtils.sol"; import "../../ACTUS/Core/Conventions/BusinessDayConventions.sol"; -import "../../ACTUS/Core/SignedMath.sol"; +import "../../ACTUS/Core/FixedPointMath.sol"; import "../../Core/Base/AssetRegistry/IAssetRegistry.sol"; import "../../Core/Base/OracleProxy/DataRegistryProxy/IDataRegistryProxy.sol"; import "./DepositAllocater.sol"; @@ -27,7 +27,7 @@ contract ICT is { using Address for address; using SafeMath for uint256; - using SignedMath for int256; + using FixedPointMath for int256; IAssetRegistry public assetRegistry; IDataRegistryProxy public dataRegistryProxy; @@ -155,8 +155,8 @@ contract ICT is // assuming number of decimals used for numbers in actus-solidity == number of decimals of ICT int256 quantity = assetRegistry.getIntValueForStateAttribute(assetId, "quantity"); int256 totalSupply = int256(totalSupplyAt(deposit.scheduledFor)); - int256 ratioSignaled = int256(deposit.totalAmountSignaled).floatDiv(totalSupply); - int256 exerciseQuantity = ratioSignaled.floatMult(quantity); + int256 ratioSignaled = int256(deposit.totalAmountSignaled).fixedDiv(totalSupply); + int256 exerciseQuantity = ratioSignaled.fixedMul(quantity); (EventType eventType, ) = decodeEvent(_event); @@ -188,8 +188,8 @@ contract ICT is // assuming number of decimals used for numbers in actus-solidity == number of decimals of ICT int256 quantity = assetRegistry.getIntValueForStateAttribute(assetId, "quantity"); int256 totalSupply = int256(totalSupplyAt(deposit.scheduledFor)); - int256 ratioSignaled = int256(deposit.totalAmountSignaled).floatDiv(totalSupply); - int256 exerciseQuantity = ratioSignaled.floatMult(quantity); + int256 ratioSignaled = int256(deposit.totalAmountSignaled).fixedDiv(totalSupply); + int256 exerciseQuantity = ratioSignaled.fixedMul(quantity); (EventType eventType, ) = decodeEvent(_event); diff --git a/packages/protocol/test/ACTUS/Core/TestSignedMath.js b/packages/protocol/test/ACTUS/Core/TestSignedMath.js index 71ca9707..4bc292b7 100644 --- a/packages/protocol/test/ACTUS/Core/TestSignedMath.js +++ b/packages/protocol/test/ACTUS/Core/TestSignedMath.js @@ -7,11 +7,11 @@ const { expectRevert } = require('@openzeppelin/test-helpers'); const { getSnapshotTaker, deployContract } = require('../../helper/setupTestEnvironment'); -describe('SignedMath', () => { +describe('FixedPointMath', () => { /** @param {any} self - `this` inside `before()`/`it()` */ const snapshotTaker = (self) => getSnapshotTaker(buidlerRuntime, self, async () => { // code bellow runs right before the EVM snapshot gets taken - self.TestSignedMath = await deployContract(buidlerRuntime, 'TestSignedMath'); + self.TestFixedPointMath = await deployContract(buidlerRuntime, 'TestFixedPointMath'); }); before(async () => { @@ -22,184 +22,184 @@ describe('SignedMath', () => { const INT_MAX = new BigNumber(2).pow(256).dividedBy(2).minus(1).toFixed(); const INT_MIN = new BigNumber(2).pow(256).dividedBy(2).multipliedBy(-1).toFixed(); - it('should test floatMult - no overflow', async () => { + it('should test fixedMul - no overflow', async () => { // multiplicand times Identity should be equal to the multiplicand assert.strictEqual( - (await this.TestSignedMath.methods._floatMult(new BigNumber(5).shiftedBy(18).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), + (await this.TestFixedPointMath.methods._fixedMul(new BigNumber(5).shiftedBy(18).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), new BigNumber(5).shiftedBy(18).toFixed(0, 3) ); - // FloatMult INT256_MAX times 1 should be equal to INT256_MAX divided by MULTIPLICATOR + // fixedMul INT256_MAX times 1 should be equal to INT256_MAX divided by MULTIPLICATOR assert.strictEqual( - (await this.TestSignedMath.methods._floatMult(INT_MAX, '1').call()).toString(), + (await this.TestFixedPointMath.methods._fixedMul(INT_MAX, '1').call()).toString(), new BigNumber(INT_MAX).shiftedBy(-18).toFixed(0, 3) ); - // FloatMult 10 ** 58 times Identity should be equal to the 10 ** 58 + // fixedMul 10 ** 58 times Identity should be equal to the 10 ** 58 assert.strictEqual( - (await this.TestSignedMath.methods._floatMult(new BigNumber(10).pow(58).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), + (await this.TestFixedPointMath.methods._fixedMul(new BigNumber(10).pow(58).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), new BigNumber(10).pow(58).toFixed(0, 3) ); - // FloatMult multiplicand times negative Identity should be equal to the negative multiplicand + // fixedMul multiplicand times negative Identity should be equal to the negative multiplicand assert.strictEqual( - (await this.TestSignedMath.methods._floatMult(new BigNumber(5).shiftedBy(18).toFixed(), new BigNumber(-1).shiftedBy(18).toFixed()).call()).toString(), + (await this.TestFixedPointMath.methods._fixedMul(new BigNumber(5).shiftedBy(18).toFixed(), new BigNumber(-1).shiftedBy(18).toFixed()).call()).toString(), new BigNumber(-5).shiftedBy(18).toFixed(0, 3) ); - // FloatMult INT256_MIN times 1 should be equal to INT256_MIN divided by MULTIPLICATOR + // fixedMul INT256_MIN times 1 should be equal to INT256_MIN divided by MULTIPLICATOR assert.strictEqual( - (await this.TestSignedMath.methods._floatMult(INT_MIN, '1').call()).toString(), + (await this.TestFixedPointMath.methods._fixedMul(INT_MIN, '1').call()).toString(), new BigNumber(INT_MIN).shiftedBy(-18).toFixed(0, 2) ); - // FloatMult -10 ** 58 times Identity should equal -10 ** 58 + // fixedMul -10 ** 58 times Identity should equal -10 ** 58 assert.strictEqual( - (await this.TestSignedMath.methods._floatMult(new BigNumber(-10).pow(58).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), + (await this.TestFixedPointMath.methods._fixedMul(new BigNumber(-10).pow(58).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), new BigNumber(-10).pow(58).toFixed(0, 3) ); }); - it('should test floatMult - overflow', async () => { - // FloatMult NT256_MAX times 10 should overflow and fail + it('should test fixedMul - overflow', async () => { + // fixedMul NT256_MAX times 10 should overflow and fail // INT256_MAX is mulitplied with 10 before getting divided (normalized) with MULTIPLIER await expectRevert( - this.TestSignedMath.methods._floatMult( + this.TestFixedPointMath.methods._fixedMul( INT_MAX, '10' ).call(), - 'SignedMath.floatMult: OVERFLOW_DETECTED' + 'FixedPointMath.fixedMul: OVERFLOW_DETECTED' ); - // FloatMult 10 ** 59 times Identity should overflow and fail + // fixedMul 10 ** 59 times Identity should overflow and fail await expectRevert( - this.TestSignedMath.methods._floatMult( + this.TestFixedPointMath.methods._fixedMul( new BigNumber(10).pow(59).toFixed(), new BigNumber(1).shiftedBy(18).toFixed() ).call(), - 'SignedMath.floatMult: OVERFLOW_DETECTED' + 'FixedPointMath.fixedMul: OVERFLOW_DETECTED' ); - // FloatMult INT256_MIN times 10 should underflow and fail + // fixedMul INT256_MIN times 10 should underflow and fail // ~ 0.0...01 await expectRevert( - this.TestSignedMath.methods._floatMult( + this.TestFixedPointMath.methods._fixedMul( INT_MIN, '10' ).call(), - 'SignedMath.floatMult: OVERFLOW_DETECTED' + 'FixedPointMath.fixedMul: OVERFLOW_DETECTED' ); - // FloatMult -10 ** 59 times Identity should underflow and fail + // fixedMul -10 ** 59 times Identity should underflow and fail await expectRevert( - this.TestSignedMath.methods._floatMult( + this.TestFixedPointMath.methods._fixedMul( new BigNumber(-10).pow(59).toFixed(), new BigNumber(1).shiftedBy(18).toFixed() ).call(), - 'SignedMath.floatMult: OVERFLOW_DETECTED' + 'FixedPointMath.fixedMul: OVERFLOW_DETECTED' ); }); - it('should test floatMult - granularity', async () => { - // FloatMult Identity times 1 should be equal to 1 + it('should test fixedMul - granularity', async () => { + // fixedMul Identity times 1 should be equal to 1 assert.strictEqual( - (await this.TestSignedMath.methods._floatMult(new BigNumber(1).shiftedBy(18).toFixed(), '1').call()).toString(), + (await this.TestFixedPointMath.methods._fixedMul(new BigNumber(1).shiftedBy(18).toFixed(), '1').call()).toString(), '1' ); - // FloatMult (Identity - 1) times 1 should fail + // fixedMul (Identity - 1) times 1 should fail await expectRevert( - this.TestSignedMath.methods._floatMult( + this.TestFixedPointMath.methods._fixedMul( new BigNumber(1).shiftedBy(18).minus(1).toFixed(), '1' ).call(), - 'SignedMath.floatMult: CANNOT_REPRESENT_GRANULARITY' + 'FixedPointMath.fixedMul: CANNOT_REPRESENT_GRANULARITY' ); }); - it('should test floatDiv - no overflow', async () => { - // FloatDiv dividend divided by Identity should be equal to the dividend + it('should test fixedDiv - no overflow', async () => { + // fixedDiv dividend divided by Identity should be equal to the dividend assert.strictEqual( - (await this.TestSignedMath.methods._floatDiv(new BigNumber(5).shiftedBy(18).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), + (await this.TestFixedPointMath.methods._fixedDiv(new BigNumber(5).shiftedBy(18).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), new BigNumber(5).shiftedBy(18).toFixed(0, 3) ); - // FloatDiv 10 ** 58 by Identity should equal 10 ** 58 + // fixedDiv 10 ** 58 by Identity should equal 10 ** 58 assert.strictEqual( - (await this.TestSignedMath.methods._floatDiv(new BigNumber(10).pow(58).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), + (await this.TestFixedPointMath.methods._fixedDiv(new BigNumber(10).pow(58).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), new BigNumber(10).pow(58).toFixed(0, 3) ); - // FloatDiv dividend by negative Identity should be equal to the negative dividend + // fixedDiv dividend by negative Identity should be equal to the negative dividend assert.strictEqual( - (await this.TestSignedMath.methods._floatDiv(new BigNumber(5).shiftedBy(18).toFixed(), new BigNumber(-1).shiftedBy(18).toFixed()).call()).toString(), + (await this.TestFixedPointMath.methods._fixedDiv(new BigNumber(5).shiftedBy(18).toFixed(), new BigNumber(-1).shiftedBy(18).toFixed()).call()).toString(), new BigNumber(-5).shiftedBy(18).toFixed(0, 3) ); - // FloatDiv -10 ** 58 divided by Identity should equal -10 ** 58 + // fixedDiv -10 ** 58 divided by Identity should equal -10 ** 58 assert.strictEqual( - (await this.TestSignedMath.methods._floatDiv(new BigNumber(-10).pow(58).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), + (await this.TestFixedPointMath.methods._fixedDiv(new BigNumber(-10).pow(58).toFixed(), new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), new BigNumber(-10).pow(58).toFixed(0, 3) ); }); - it('should test floatDiv - overflow', async () => { - // FloatDiv INT256_MAX by 1 should overflow and fail + it('should test fixedDiv - overflow', async () => { + // fixedDiv INT256_MAX by 1 should overflow and fail // ~ 0.0...01 await expectRevert( - this.TestSignedMath.methods._floatDiv( + this.TestFixedPointMath.methods._fixedDiv( INT_MAX, '1' ).call(), - 'SignedMath.floatDiv: OVERFLOW_DETECTED' + 'FixedPointMath.fixedDiv: OVERFLOW_DETECTED' ); - // FloatDiv 10 ** 59 by Identity should overflow and fail + // fixedDiv 10 ** 59 by Identity should overflow and fail await expectRevert( - this.TestSignedMath.methods._floatDiv( + this.TestFixedPointMath.methods._fixedDiv( new BigNumber(10).pow(59).toFixed(), new BigNumber(1).shiftedBy(18).toFixed() ).call(), - 'SignedMath.floatDiv: OVERFLOW_DETECTED' + 'FixedPointMath.fixedDiv: OVERFLOW_DETECTED' ); - // FloatDiv INT256_MIN by 1 should underflow and fail + // fixedDiv INT256_MIN by 1 should underflow and fail // ~ 0.0...01 await expectRevert( - this.TestSignedMath.methods._floatDiv( + this.TestFixedPointMath.methods._fixedDiv( INT_MIN, '1' ).call(), - 'SignedMath.floatDiv: OVERFLOW_DETECTED' + 'FixedPointMath.fixedDiv: OVERFLOW_DETECTED' ); - // FloatDiv -10 ** 59 by Identify should underflow and fail + // fixedDiv -10 ** 59 by Identify should underflow and fail await expectRevert( - this.TestSignedMath.methods._floatDiv( + this.TestFixedPointMath.methods._fixedDiv( new BigNumber(-10).pow(59).toFixed(), new BigNumber(1).shiftedBy(18).toFixed() ).call(), - 'SignedMath.floatDiv: OVERFLOW_DETECTED' + 'FixedPointMath.fixedDiv: OVERFLOW_DETECTED' ); }); - it('should test floatDiv - granularity', async () => { - // FloatDiv 1 by Identity should be equal to 1 + it('should test fixedDiv - granularity', async () => { + // fixedDiv 1 by Identity should be equal to 1 assert.strictEqual( - (await this.TestSignedMath.methods._floatDiv('1', new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), + (await this.TestFixedPointMath.methods._fixedDiv('1', new BigNumber(1).shiftedBy(18).toFixed()).call()).toString(), '1' ); - // FloatDiv 1 by (Identity + 1) should fail + // fixedDiv 1 by (Identity + 1) should fail // ~ 0.0...01 await expectRevert( - this.TestSignedMath.methods._floatDiv( + this.TestFixedPointMath.methods._fixedDiv( '1', new BigNumber(1).shiftedBy(18).plus(1).toFixed() ).call(), - 'SignedMath.floatDiv: CANNOT_REPRESENT_GRANULARITY' + 'FixedPointMath.fixedDiv: CANNOT_REPRESENT_GRANULARITY' ); }); it('should test min', async () => { // min of 1 and 2 should be 1 - assert.strictEqual(await this.TestSignedMath.methods._min(1, 2).call(), '1') + assert.strictEqual(await this.TestFixedPointMath.methods._min(1, 2).call(), '1') // min of 1 and 0 should be 0 - assert.strictEqual(await this.TestSignedMath.methods._min(1, 0).call(), '0') + assert.strictEqual(await this.TestFixedPointMath.methods._min(1, 0).call(), '0') // min of 1 and -1 should be -1 - assert.strictEqual(await this.TestSignedMath.methods._min(1, -1).call(), '-1') + assert.strictEqual(await this.TestFixedPointMath.methods._min(1, -1).call(), '-1') }); it('should test max', async () => { // max of 1 and 2 should be 2 - assert.strictEqual(await this.TestSignedMath.methods._max(1, 2).call(), '2') + assert.strictEqual(await this.TestFixedPointMath.methods._max(1, 2).call(), '2') // max of 1 and 0 should be 1 - assert.strictEqual(await this.TestSignedMath.methods._max(1, 0).call(), '1') + assert.strictEqual(await this.TestFixedPointMath.methods._max(1, 0).call(), '1') // max of 1 and -1 should be 1 - assert.strictEqual(await this.TestSignedMath.methods._max(1, -1).call(), '1') + assert.strictEqual(await this.TestFixedPointMath.methods._max(1, -1).call(), '1') }); }); From b1e3c88d09c564d0b32457594f0aab91b4fafb0d Mon Sep 17 00:00:00 2001 From: jo-es Date: Sun, 27 Dec 2020 14:37:18 +0100 Subject: [PATCH 5/6] Rename file and format code --- .../contracts/ACTUS/Core/FixedPointMath.sol | 56 ++++++++++++------- ...estSignedMath.js => TestFixedPointMath.js} | 0 2 files changed, 36 insertions(+), 20 deletions(-) rename packages/protocol/test/ACTUS/Core/{TestSignedMath.js => TestFixedPointMath.js} (100%) diff --git a/packages/protocol/contracts/ACTUS/Core/FixedPointMath.sol b/packages/protocol/contracts/ACTUS/Core/FixedPointMath.sol index 26668559..c2348680 100644 --- a/packages/protocol/contracts/ACTUS/Core/FixedPointMath.sol +++ b/packages/protocol/contracts/ACTUS/Core/FixedPointMath.sol @@ -18,39 +18,55 @@ library FixedPointMath { * as devision (normalization) is performed after multiplication * Upper boundary would be (10 ** 58) * (MULTIPLICATOR) == ~10 ** 76 */ - function fixedMul(int256 a, int256 b) - internal - pure - returns (int256) - { + function fixedMul(int256 a, int256 b) internal pure returns (int256) { if (a == 0 || b == 0) return 0; - require(!(a == -1 && b == INT256_MIN), "FixedPointMath.fixedMul: OVERFLOW_DETECTED"); + require( + !(a == -1 && b == INT256_MIN), + "FixedPointMath.fixedMul: OVERFLOW_DETECTED" + ); + int256 c = a * b; - require(c / a == b, "FixedPointMath.fixedMul: OVERFLOW_DETECTED"); + require( + c / a == b, + "FixedPointMath.fixedMul: OVERFLOW_DETECTED" + ); // normalize (divide by MULTIPLICATOR) int256 d = c / int256(MULTIPLICATOR); - require(d != 0, "FixedPointMath.fixedMul: CANNOT_REPRESENT_GRANULARITY"); + require( + d != 0, + "FixedPointMath.fixedMul: CANNOT_REPRESENT_GRANULARITY" + ); return d; } - function fixedDiv(int256 a, int256 b) - internal - pure - returns (int256) - { - require(b != 0, "FixedPointMath.fixedDiv: DIVIDED_BY_ZERO"); + function fixedDiv(int256 a, int256 b) internal pure returns (int256) { + require( + b != 0, + "FixedPointMath.fixedDiv: DIVIDED_BY_ZERO" + ); - // normalize (multiply by MULTIPLICATOR) if (a == 0) return 0; + + // normalize (multiply by MULTIPLICATOR) int256 c = a * int256(MULTIPLICATOR); - require(c / a == int256(MULTIPLICATOR), "FixedPointMath.fixedDiv: OVERFLOW_DETECTED"); + require( + c / a == int256(MULTIPLICATOR), + "FixedPointMath.fixedDiv: OVERFLOW_DETECTED" + ); + + require( + !(b == -1 && a == INT256_MIN), + "FixedPointMath.fixedDiv: OVERFLOW_DETECTED" + ); - require(!(b == -1 && a == INT256_MIN), "FixedPointMath.fixedDiv: OVERFLOW_DETECTED"); int256 d = c / b; - require(d != 0, "FixedPointMath.fixedDiv: CANNOT_REPRESENT_GRANULARITY"); + require( + d != 0, + "FixedPointMath.fixedDiv: CANNOT_REPRESENT_GRANULARITY" + ); return d; } @@ -59,13 +75,13 @@ library FixedPointMath { * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { - return a <= b ? a : b; + return a <= b ? a : b; } /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { - return a >= b ? a : b; + return a >= b ? a : b; } } diff --git a/packages/protocol/test/ACTUS/Core/TestSignedMath.js b/packages/protocol/test/ACTUS/Core/TestFixedPointMath.js similarity index 100% rename from packages/protocol/test/ACTUS/Core/TestSignedMath.js rename to packages/protocol/test/ACTUS/Core/TestFixedPointMath.js From a473a88416ec75636283d8d1d33dd2ddedba76f7 Mon Sep 17 00:00:00 2001 From: jo-es <45110941+jo-es@users.noreply.github.com> Date: Sun, 27 Dec 2020 21:06:59 +0100 Subject: [PATCH 6/6] Add inline docs for usages of fixedDiv in DayCountConventions --- .../Core/Conventions/DayCountConventions.sol | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/protocol/contracts/ACTUS/Core/Conventions/DayCountConventions.sol b/packages/protocol/contracts/ACTUS/Core/Conventions/DayCountConventions.sol index a5ce2d9e..87f5d9c5 100755 --- a/packages/protocol/contracts/ACTUS/Core/Conventions/DayCountConventions.sol +++ b/packages/protocol/contracts/ACTUS/Core/Conventions/DayCountConventions.sol @@ -22,7 +22,7 @@ contract DayCountConventions is ACTUSConstants { using FixedPointMath for int; /** - * Returns the fraction of the year between two timestamps. + * Returns the fraction of the year between two timestamps (as a fixed point number multiplied by 10 ** 18). */ function yearFraction( uint256 startTimestamp, @@ -76,11 +76,13 @@ contract DayCountConventions is ACTUSConstants { int256 firstBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(startTime)) ? 366 : 365; if (d1Year == d2Year) { + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) return int256(BokkyPooBahsDateTimeLibrary.diffDays(startTime, endTime)).fixedDiv(firstBasis); } int256 secondBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(endTime)) ? 366 : 365; + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) int256 firstFraction = int256(BokkyPooBahsDateTimeLibrary.diffDays( startTime, BokkyPooBahsDateTimeLibrary.timestampFromDate(d1Year.add(1), 1, 1) @@ -101,6 +103,7 @@ contract DayCountConventions is ACTUSConstants { pure returns (int256) { + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) return (int256((endTime.sub(startTime)).div(86400)).fixedDiv(360)); } @@ -112,6 +115,7 @@ contract DayCountConventions is ACTUSConstants { pure returns (int256) { + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) return (int256((endTime.sub(startTime)).div(86400)).fixedDiv(365)); } @@ -146,6 +150,7 @@ contract DayCountConventions is ACTUSConstants { int256 delM = int256(d2Month).sub(int256(d1Month)); int256 delY = int256(d2Year).sub(int256(d1Year)); + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) return ((delY.mul(360).add(delM.mul(30)).add(delD)).fixedDiv(360)); } @@ -180,6 +185,7 @@ contract DayCountConventions is ACTUSConstants { int256 delM = int256(d2Month).sub(int256(d1Month)); int256 delY = int256(d2Year).sub(int256(d1Year)); + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) return ((delY.mul(360).add(delM.mul(30)).add(delD)).fixedDiv(360)); } @@ -207,6 +213,7 @@ contract DayCountConventions is ACTUSConstants { int256 delM = int256(d2Month).sub(int256(d1Month)); int256 delY = int256(d2Year).sub(int256(d1Year)); + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) return ((delY.mul(336).add(delM.mul(28)).add(delD)).fixedDiv(336)); } @@ -218,6 +225,7 @@ contract DayCountConventions is ACTUSConstants { pure returns (int256) { + // as fixed point number (10 ** 18) return ONE_POINT_ZERO; } @@ -229,6 +237,7 @@ contract DayCountConventions is ACTUSConstants { pure returns (int256) { + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) return int256(ONE_POINT_ZERO).fixedDiv(12 * ONE_POINT_ZERO); } @@ -248,6 +257,7 @@ contract DayCountConventions is ACTUSConstants { int256 firstBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(startTime)) ? 8784 : 8760; if (d1Year == d2Year) { + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) return int256(BokkyPooBahsDateTimeLibrary.diffHours(startTime, endTime)).fixedDiv(firstBasis); } @@ -255,6 +265,7 @@ contract DayCountConventions is ACTUSConstants { // 366 * 24, 365 * 24 int256 secondBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(endTime)) ? 8784 : 8760; + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) int256 firstFraction = int256(BokkyPooBahsDateTimeLibrary.diffHours( startTime, BokkyPooBahsDateTimeLibrary.timestampFromDate(d1Year.add(1), 1, 1) @@ -283,6 +294,7 @@ contract DayCountConventions is ACTUSConstants { int256 firstBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(startTime)) ? 527040 : 525600; if (d1Year == d2Year) { + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) return int256(BokkyPooBahsDateTimeLibrary.diffMinutes(startTime, endTime)).fixedDiv(firstBasis); } @@ -290,6 +302,7 @@ contract DayCountConventions is ACTUSConstants { // 366 * 1440, 365 * 1440 int256 secondBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(endTime)) ? 527040 : 525600; + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) int256 firstFraction = int256(BokkyPooBahsDateTimeLibrary.diffMinutes( startTime, BokkyPooBahsDateTimeLibrary.timestampFromDate(d1Year.add(1), 1, 1) @@ -318,6 +331,7 @@ contract DayCountConventions is ACTUSConstants { int256 firstBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(startTime)) ? 31622400 : 31536000; if (d1Year == d2Year) { + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) return int256(BokkyPooBahsDateTimeLibrary.diffSeconds(startTime, endTime)).fixedDiv(firstBasis); } @@ -325,6 +339,7 @@ contract DayCountConventions is ACTUSConstants { // 366 * 86400, 365 * 86400 int256 secondBasis = (BokkyPooBahsDateTimeLibrary.isLeapYear(endTime)) ? 31622400 : 31536000; + // fixedDiv on two non fixed point integers returns the quotient in fixed point representation (10 ** 18) int256 firstFraction = int256(BokkyPooBahsDateTimeLibrary.diffSeconds( startTime, BokkyPooBahsDateTimeLibrary.timestampFromDate(d1Year.add(1), 1, 1)