@solidstate/abdk-math-extensions 1.0.0 → 1.1.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/README.md +12 -10
- package/contracts/ABDKMath64x64Constants.sol +14 -0
- package/contracts/ABDKMath64x64Token.sol +11 -13
- package/package.json +36 -37
package/README.md
CHANGED
@@ -1,33 +1,35 @@
|
|
1
|
-
#
|
1
|
+
# Solidstate Extensions for ABDK Libraries
|
2
2
|
|
3
|
-
|
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).
|
4
|
+
|
5
|
+
> **Note**: Solidstate, Premia, and this package are not affiliated with ABDK.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Install the package as well as the required ABDK package as development dependencies:
|
8
10
|
|
9
11
|
```bash
|
10
|
-
|
12
|
+
pnpm add -D @solidstate/abdk-math-extensions abdk-libraries-solidity
|
11
13
|
```
|
12
14
|
|
13
15
|
## Development
|
14
16
|
|
15
|
-
Install dependencies
|
17
|
+
Install dependencies:
|
16
18
|
|
17
19
|
```bash
|
18
|
-
|
20
|
+
pnpm install
|
19
21
|
```
|
20
22
|
|
21
23
|
Setup Husky to format code on commit:
|
22
24
|
|
23
25
|
```bash
|
24
|
-
|
26
|
+
pnpm prepare
|
25
27
|
```
|
26
28
|
|
27
29
|
Compile contracts via Hardhat:
|
28
30
|
|
29
31
|
```bash
|
30
|
-
|
32
|
+
pnpm hardhat compile
|
31
33
|
```
|
32
34
|
|
33
35
|
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.
|
@@ -45,17 +47,17 @@ By default, Hardhat uses the Hardhat Network in-process. Two additional networks
|
|
45
47
|
Test contracts via Hardhat:
|
46
48
|
|
47
49
|
```bash
|
48
|
-
|
50
|
+
pnpm hardhat test
|
49
51
|
```
|
50
52
|
|
51
53
|
Activate gas usage reporting by setting the `REPORT_GAS` environment variable to `"true"`:
|
52
54
|
|
53
55
|
```bash
|
54
|
-
REPORT_GAS=true
|
56
|
+
REPORT_GAS=true pnpm hardhat test
|
55
57
|
```
|
56
58
|
|
57
59
|
Generate a code coverage report using `solidity-coverage`:
|
58
60
|
|
59
61
|
```bash
|
60
|
-
|
62
|
+
pnpm hardhat coverage
|
61
63
|
```
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
|
3
|
+
pragma solidity ^0.8.0;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @title 64x64 fixed-point constants compatible with ABDKMath64x64 library
|
7
|
+
*/
|
8
|
+
library ABDKMath64x64Constants {
|
9
|
+
int128 internal constant MIN_64x64 = type(int128).min;
|
10
|
+
int128 internal constant MAX_64x64 = type(int128).max;
|
11
|
+
int128 internal constant ONE_64x64 = 0x10000000000000000;
|
12
|
+
int128 internal constant E_64x64 = 0x2b7e151628aed1975;
|
13
|
+
int128 internal constant PI_64x64 = 0x3243f6a8885a2f7a4;
|
14
|
+
}
|
@@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
|
|
5
5
|
import { ABDKMath64x64 } from 'abdk-libraries-solidity/ABDKMath64x64.sol';
|
6
6
|
|
7
7
|
/**
|
8
|
-
* @title
|
8
|
+
* @title Solidstate token extensions for ABDKMath64x64 library
|
9
9
|
*/
|
10
10
|
library ABDKMath64x64Token {
|
11
11
|
using ABDKMath64x64 for int128;
|
@@ -16,12 +16,11 @@ library ABDKMath64x64Token {
|
|
16
16
|
* @param decimals token display decimals
|
17
17
|
* @return value decimal representation of token amount
|
18
18
|
*/
|
19
|
-
function toDecimals(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
value = value64x64.mulu(10**decimals);
|
19
|
+
function toDecimals(
|
20
|
+
int128 value64x64,
|
21
|
+
uint8 decimals
|
22
|
+
) internal pure returns (uint256 value) {
|
23
|
+
value = value64x64.mulu(10 ** decimals);
|
25
24
|
}
|
26
25
|
|
27
26
|
/**
|
@@ -30,12 +29,11 @@ library ABDKMath64x64Token {
|
|
30
29
|
* @param decimals token display decimals
|
31
30
|
* @return value64x64 64x64 fixed point representation of token amount
|
32
31
|
*/
|
33
|
-
function fromDecimals(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
value64x64 = ABDKMath64x64.divu(value, 10**decimals);
|
32
|
+
function fromDecimals(
|
33
|
+
uint256 value,
|
34
|
+
uint8 decimals
|
35
|
+
) internal pure returns (int128 value64x64) {
|
36
|
+
value64x64 = ABDKMath64x64.divu(value, 10 ** decimals);
|
39
37
|
}
|
40
38
|
|
41
39
|
/**
|
package/package.json
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@solidstate/abdk-math-extensions",
|
3
|
-
"version": "1.
|
4
|
-
"
|
5
|
-
"license": "MIT",
|
6
|
-
"description": "SolidState extensions for the ABDK Solidity libraries",
|
7
|
-
"repository": "github:solidstate-network/abdk-math-extensions",
|
3
|
+
"version": "1.1.0",
|
4
|
+
"description": "Solidstate extensions for the ABDK Solidity libraries",
|
8
5
|
"keywords": [
|
9
6
|
"solidity",
|
10
7
|
"smart-contracts",
|
@@ -21,43 +18,45 @@
|
|
21
18
|
"hardhat",
|
22
19
|
"buidler"
|
23
20
|
],
|
24
|
-
"
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
"repository": "github:solidstate-network/abdk-math-extensions",
|
22
|
+
"license": "MIT",
|
23
|
+
"author": "Nick Barry",
|
24
|
+
"files": [
|
25
|
+
"contracts/*.sol"
|
26
|
+
],
|
28
27
|
"devDependencies": {
|
29
|
-
"@
|
30
|
-
"@
|
31
|
-
"@
|
32
|
-
"@typechain/
|
33
|
-
"@
|
34
|
-
"@types/
|
35
|
-
"@types/
|
36
|
-
"
|
37
|
-
"
|
38
|
-
"
|
39
|
-
"
|
40
|
-
"ethers": "
|
41
|
-
"hardhat": "2.
|
42
|
-
"hardhat-exposed": "^0.
|
43
|
-
"hardhat-gas-reporter": "^
|
44
|
-
"hardhat-spdx-license-identifier": "^2.
|
45
|
-
"husky": "^
|
46
|
-
"lint-staged": "^
|
47
|
-
"prettier": "^
|
48
|
-
"prettier-plugin-
|
49
|
-
"solidity
|
50
|
-
"
|
51
|
-
"typechain": "^8.
|
52
|
-
"typescript": "^
|
28
|
+
"@nomicfoundation/hardhat-chai-matchers": "^2.0.9",
|
29
|
+
"@nomicfoundation/hardhat-ethers": "^3.0.9",
|
30
|
+
"@tsconfig/node22": "^22.0.2",
|
31
|
+
"@typechain/ethers-v6": "^0.5.1",
|
32
|
+
"@typechain/hardhat": "^9.1.0",
|
33
|
+
"@types/chai": "^5.2.2",
|
34
|
+
"@types/mocha": "^10.0.10",
|
35
|
+
"@types/node": "^24.0.10",
|
36
|
+
"abdk-libraries-solidity": "^3.2.0",
|
37
|
+
"chai": "^4.5.0",
|
38
|
+
"dotenv": "^17.0.1",
|
39
|
+
"ethers": "^6.15.0",
|
40
|
+
"hardhat": "^2.25.0",
|
41
|
+
"hardhat-exposed": "^0.3.19",
|
42
|
+
"hardhat-gas-reporter": "^2.3.0",
|
43
|
+
"hardhat-spdx-license-identifier": "^2.3.1",
|
44
|
+
"husky": "^9.1.7",
|
45
|
+
"lint-staged": "^16.1.2",
|
46
|
+
"prettier": "^3.6.2",
|
47
|
+
"prettier-plugin-packagejson": "^2.5.18",
|
48
|
+
"prettier-plugin-solidity": "^2.0.0",
|
49
|
+
"solidity-coverage": "^0.8.16",
|
50
|
+
"typechain": "^8.3.2",
|
51
|
+
"typescript": "^5.8.3"
|
53
52
|
},
|
54
53
|
"peerDependencies": {
|
55
54
|
"abdk-libraries-solidity": "^3.0.0"
|
56
55
|
},
|
57
|
-
"files": [
|
58
|
-
"contracts/*.sol"
|
59
|
-
],
|
60
56
|
"publishConfig": {
|
61
57
|
"access": "public"
|
58
|
+
},
|
59
|
+
"scripts": {
|
60
|
+
"prettier": "prettier --write --ignore-path .gitignore ."
|
62
61
|
}
|
63
|
-
}
|
62
|
+
}
|