@solidstate/abdk-math-extensions 1.0.0

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/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2022 Nick Barry
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # SolidState Extensions for ABDK Libraries
2
+
3
+ SolidState extensions for the `abdk-libraries-solidity` [package](https://www.npmjs.com/package/abdk-libraries-solidity). Developed as a part of the [Premia Finance smart contracts](https://github.com/Premian-Labs/premia-contracts). SolidState, Premia, and this package are not affiliated with ABDK.
4
+
5
+ ## Installation
6
+
7
+ Install the package as well as the required ABDK package as development dependencies:
8
+
9
+ ```bash
10
+ yarn add --dev @solidstate/abdk-math-extensions abdk-libraries-solidity
11
+ ```
12
+
13
+ ## Development
14
+
15
+ Install dependencies via Yarn:
16
+
17
+ ```bash
18
+ yarn install
19
+ ```
20
+
21
+ Setup Husky to format code on commit:
22
+
23
+ ```bash
24
+ yarn prepare
25
+ ```
26
+
27
+ Compile contracts via Hardhat:
28
+
29
+ ```bash
30
+ yarn run hardhat compile
31
+ ```
32
+
33
+ The Hardhat environment relies on the following environment variables. The `dotenv` package will attempt to read them from the `.env` file, if it is present.
34
+
35
+ | Key | Description |
36
+ | ------------ | ------------------------------------------------------------- |
37
+ | `REPORT_GAS` | if `true`, a gas report will be generated after running tests |
38
+
39
+ ### Networks
40
+
41
+ By default, Hardhat uses the Hardhat Network in-process. Two additional networks, `mainnet` and `testnet` are available, and their behavior is determined by the configuration of environment variables.
42
+
43
+ ### Testing
44
+
45
+ Test contracts via Hardhat:
46
+
47
+ ```bash
48
+ yarn run hardhat test
49
+ ```
50
+
51
+ Activate gas usage reporting by setting the `REPORT_GAS` environment variable to `"true"`:
52
+
53
+ ```bash
54
+ REPORT_GAS=true yarn run hardhat test
55
+ ```
56
+
57
+ Generate a code coverage report using `solidity-coverage`:
58
+
59
+ ```bash
60
+ yarn run hardhat coverage
61
+ ```
@@ -0,0 +1,58 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ import { ABDKMath64x64 } from 'abdk-libraries-solidity/ABDKMath64x64.sol';
6
+
7
+ /**
8
+ * @title SolidState token extensions for ABDKMath64x64 library
9
+ */
10
+ library ABDKMath64x64Token {
11
+ using ABDKMath64x64 for int128;
12
+
13
+ /**
14
+ * @notice convert 64x64 fixed point representation of token amount to decimal
15
+ * @param value64x64 64x64 fixed point representation of token amount
16
+ * @param decimals token display decimals
17
+ * @return value decimal representation of token amount
18
+ */
19
+ function toDecimals(int128 value64x64, uint8 decimals)
20
+ internal
21
+ pure
22
+ returns (uint256 value)
23
+ {
24
+ value = value64x64.mulu(10**decimals);
25
+ }
26
+
27
+ /**
28
+ * @notice convert decimal representation of token amount to 64x64 fixed point
29
+ * @param value decimal representation of token amount
30
+ * @param decimals token display decimals
31
+ * @return value64x64 64x64 fixed point representation of token amount
32
+ */
33
+ function fromDecimals(uint256 value, uint8 decimals)
34
+ internal
35
+ pure
36
+ returns (int128 value64x64)
37
+ {
38
+ value64x64 = ABDKMath64x64.divu(value, 10**decimals);
39
+ }
40
+
41
+ /**
42
+ * @notice convert 64x64 fixed point representation of token amount to wei (18 decimals)
43
+ * @param value64x64 64x64 fixed point representation of token amount
44
+ * @return value wei representation of token amount
45
+ */
46
+ function toWei(int128 value64x64) internal pure returns (uint256 value) {
47
+ value = toDecimals(value64x64, 18);
48
+ }
49
+
50
+ /**
51
+ * @notice convert wei representation (18 decimals) of token amount to 64x64 fixed point
52
+ * @param value wei representation of token amount
53
+ * @return value64x64 64x64 fixed point representation of token amount
54
+ */
55
+ function fromWei(uint256 value) internal pure returns (int128 value64x64) {
56
+ value64x64 = fromDecimals(value, 18);
57
+ }
58
+ }
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@solidstate/abdk-math-extensions",
3
+ "version": "1.0.0",
4
+ "author": "Nick Barry",
5
+ "license": "MIT",
6
+ "description": "SolidState extensions for the ABDK Solidity libraries",
7
+ "repository": "github:solidstate-network/abdk-math-extensions",
8
+ "keywords": [
9
+ "solidity",
10
+ "smart-contracts",
11
+ "abdk",
12
+ "math",
13
+ "fixed-point",
14
+ "ethereum",
15
+ "ether",
16
+ "eth",
17
+ "cryptocurrency",
18
+ "crypto",
19
+ "wow",
20
+ "library",
21
+ "hardhat",
22
+ "buidler"
23
+ ],
24
+ "scripts": {
25
+ "prepare": "husky install",
26
+ "prettier": "prettier --write --ignore-path .gitignore ."
27
+ },
28
+ "devDependencies": {
29
+ "@nomiclabs/hardhat-ethers": "^2.0.5",
30
+ "@nomiclabs/hardhat-waffle": "^2.0.3",
31
+ "@typechain/ethers-v5": "^10.0.0",
32
+ "@typechain/hardhat": "^6.0.0",
33
+ "@types/chai": "^4.3.1",
34
+ "@types/mocha": "^9.1.1",
35
+ "@types/node": "^17.0.31",
36
+ "abdk-libraries-solidity": "^3.0.0",
37
+ "chai": "^4.3.6",
38
+ "dotenv": "^16.0.0",
39
+ "ethereum-waffle": "^3.4.4",
40
+ "ethers": "5.6.0",
41
+ "hardhat": "2.9.2",
42
+ "hardhat-exposed": "^0.2.3",
43
+ "hardhat-gas-reporter": "^1.0.8",
44
+ "hardhat-spdx-license-identifier": "^2.0.3",
45
+ "husky": "^7.0.4",
46
+ "lint-staged": "^12.4.1",
47
+ "prettier": "^2.6.2",
48
+ "prettier-plugin-solidity": "^1.0.0-beta.19",
49
+ "solidity-coverage": "^0.7.21",
50
+ "ts-node": "^10.7.0",
51
+ "typechain": "^8.0.0",
52
+ "typescript": "^4.6.4"
53
+ },
54
+ "peerDependencies": {
55
+ "abdk-libraries-solidity": "^3.0.0"
56
+ },
57
+ "files": [
58
+ "contracts/*.sol"
59
+ ],
60
+ "publishConfig": {
61
+ "access": "public"
62
+ }
63
+ }